Remove use of ConstantHandling itf

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10800 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-01-12 20:13:04 +00:00
parent 7822c2ae07
commit 67bb7603ea
3 changed files with 93 additions and 72 deletions

View File

@ -22,11 +22,31 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Support/ConstantRange.h" #include "llvm/Support/ConstantRange.h"
#include "llvm/Type.h" #include "llvm/Constants.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include "llvm/ConstantHandling.h" #include "llvm/Type.h"
using namespace llvm; using namespace llvm;
static bool LT(ConstantIntegral *A, ConstantIntegral *B) {
Constant *C = ConstantExpr::get(Instruction::SetLT, A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
}
static bool GT(ConstantIntegral *A, ConstantIntegral *B) {
Constant *C = ConstantExpr::get(Instruction::SetGT, A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
}
static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) {
return LT(A, B) ? A : B;
}
static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) {
return GT(A, B) ? A : B;
}
/// Initialize a full (the default) or empty set for the specified type. /// Initialize a full (the default) or empty set for the specified type.
/// ///
ConstantRange::ConstantRange(const Type *Ty, bool Full) { ConstantRange::ConstantRange(const Type *Ty, bool Full) {
@ -57,9 +77,8 @@ static ConstantIntegral *Next(ConstantIntegral *CI) {
if (CI->getType() == Type::BoolTy) if (CI->getType() == Type::BoolTy)
return CI == ConstantBool::True ? ConstantBool::False : ConstantBool::True; return CI == ConstantBool::True ? ConstantBool::False : ConstantBool::True;
// Otherwise use operator+ in the ConstantHandling Library. Constant *Result = ConstantExpr::get(Instruction::Add, CI,
Constant *Result = *ConstantInt::get(CI->getType(), 1) + *CI; ConstantInt::get(CI->getType(), 1));
assert(Result && "ConstantHandling not implemented for integral plus!?");
return cast<ConstantIntegral>(Result); return cast<ConstantIntegral>(Result);
} }
@ -109,7 +128,7 @@ bool ConstantRange::isEmptySet() const {
/// for example: [100, 8) /// for example: [100, 8)
/// ///
bool ConstantRange::isWrappedSet() const { bool ConstantRange::isWrappedSet() const {
return (*(Constant*)Lower > *(Constant*)Upper)->getValue(); return GT(Lower, Upper);
} }
@ -132,8 +151,8 @@ uint64_t ConstantRange::getSetSize() const {
} }
// Simply subtract the bounds... // Simply subtract the bounds...
Constant *Result = *(Constant*)Upper - *(Constant*)Lower; Constant *Result =
assert(Result && "Subtraction of constant integers not implemented?"); ConstantExpr::get(Instruction::Sub, (Constant*)Upper, (Constant*)Lower);
return cast<ConstantInt>(Result)->getRawValue(); return cast<ConstantInt>(Result)->getRawValue();
} }
@ -149,10 +168,10 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
// Check to see if we overlap on the Left side of RHS... // Check to see if we overlap on the Left side of RHS...
// //
if ((*(Constant*)RHS.getLower() < *(Constant*)LHS.getUpper())->getValue()) { if (LT(RHS.getLower(), LHS.getUpper())) {
// We do overlap on the left side of RHS, see if we overlap on the right of // We do overlap on the left side of RHS, see if we overlap on the right of
// RHS... // RHS...
if ((*(Constant*)RHS.getUpper() > *(Constant*)LHS.getLower())->getValue()) { if (GT(RHS.getUpper(), LHS.getLower())) {
// Ok, the result overlaps on both the left and right sides. See if the // Ok, the result overlaps on both the left and right sides. See if the
// resultant interval will be smaller if we wrap or not... // resultant interval will be smaller if we wrap or not...
// //
@ -169,7 +188,7 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
} else { } else {
// We don't overlap on the left side of RHS, see if we overlap on the right // We don't overlap on the left side of RHS, see if we overlap on the right
// of RHS... // of RHS...
if ((*(Constant*)RHS.getUpper() > *(Constant*)LHS.getLower())->getValue()) { if (GT(RHS.getUpper(), LHS.getLower())) {
// Simple overlap... // Simple overlap...
return ConstantRange(LHS.getLower(), RHS.getUpper()); return ConstantRange(LHS.getLower(), RHS.getUpper());
} else { } else {
@ -179,18 +198,6 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
} }
} }
static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) {
if ((*(Constant*)A < *(Constant*)B)->getValue())
return A;
return B;
}
static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) {
if ((*(Constant*)A > *(Constant*)B)->getValue())
return A;
return B;
}
/// intersect - Return the range that results from the intersection of this /// intersect - Return the range that results from the intersection of this
/// range with another range. /// range with another range.
/// ///
@ -205,7 +212,7 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
ConstantIntegral *L = Max(Lower, CR.Lower); ConstantIntegral *L = Max(Lower, CR.Lower);
ConstantIntegral *U = Min(Upper, CR.Upper); ConstantIntegral *U = Min(Upper, CR.Upper);
if ((*L < *U)->getValue()) // If range isn't empty... if (LT(L, U)) // If range isn't empty...
return ConstantRange(L, U); return ConstantRange(L, U);
else else
return ConstantRange(getType(), false); // Otherwise, return empty set return ConstantRange(getType(), false); // Otherwise, return empty set

View File

@ -22,11 +22,31 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Support/ConstantRange.h" #include "llvm/Support/ConstantRange.h"
#include "llvm/Type.h" #include "llvm/Constants.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include "llvm/ConstantHandling.h" #include "llvm/Type.h"
using namespace llvm; using namespace llvm;
static bool LT(ConstantIntegral *A, ConstantIntegral *B) {
Constant *C = ConstantExpr::get(Instruction::SetLT, A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
}
static bool GT(ConstantIntegral *A, ConstantIntegral *B) {
Constant *C = ConstantExpr::get(Instruction::SetGT, A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
}
static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) {
return LT(A, B) ? A : B;
}
static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) {
return GT(A, B) ? A : B;
}
/// Initialize a full (the default) or empty set for the specified type. /// Initialize a full (the default) or empty set for the specified type.
/// ///
ConstantRange::ConstantRange(const Type *Ty, bool Full) { ConstantRange::ConstantRange(const Type *Ty, bool Full) {
@ -57,9 +77,8 @@ static ConstantIntegral *Next(ConstantIntegral *CI) {
if (CI->getType() == Type::BoolTy) if (CI->getType() == Type::BoolTy)
return CI == ConstantBool::True ? ConstantBool::False : ConstantBool::True; return CI == ConstantBool::True ? ConstantBool::False : ConstantBool::True;
// Otherwise use operator+ in the ConstantHandling Library. Constant *Result = ConstantExpr::get(Instruction::Add, CI,
Constant *Result = *ConstantInt::get(CI->getType(), 1) + *CI; ConstantInt::get(CI->getType(), 1));
assert(Result && "ConstantHandling not implemented for integral plus!?");
return cast<ConstantIntegral>(Result); return cast<ConstantIntegral>(Result);
} }
@ -109,7 +128,7 @@ bool ConstantRange::isEmptySet() const {
/// for example: [100, 8) /// for example: [100, 8)
/// ///
bool ConstantRange::isWrappedSet() const { bool ConstantRange::isWrappedSet() const {
return (*(Constant*)Lower > *(Constant*)Upper)->getValue(); return GT(Lower, Upper);
} }
@ -132,8 +151,8 @@ uint64_t ConstantRange::getSetSize() const {
} }
// Simply subtract the bounds... // Simply subtract the bounds...
Constant *Result = *(Constant*)Upper - *(Constant*)Lower; Constant *Result =
assert(Result && "Subtraction of constant integers not implemented?"); ConstantExpr::get(Instruction::Sub, (Constant*)Upper, (Constant*)Lower);
return cast<ConstantInt>(Result)->getRawValue(); return cast<ConstantInt>(Result)->getRawValue();
} }
@ -149,10 +168,10 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
// Check to see if we overlap on the Left side of RHS... // Check to see if we overlap on the Left side of RHS...
// //
if ((*(Constant*)RHS.getLower() < *(Constant*)LHS.getUpper())->getValue()) { if (LT(RHS.getLower(), LHS.getUpper())) {
// We do overlap on the left side of RHS, see if we overlap on the right of // We do overlap on the left side of RHS, see if we overlap on the right of
// RHS... // RHS...
if ((*(Constant*)RHS.getUpper() > *(Constant*)LHS.getLower())->getValue()) { if (GT(RHS.getUpper(), LHS.getLower())) {
// Ok, the result overlaps on both the left and right sides. See if the // Ok, the result overlaps on both the left and right sides. See if the
// resultant interval will be smaller if we wrap or not... // resultant interval will be smaller if we wrap or not...
// //
@ -169,7 +188,7 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
} else { } else {
// We don't overlap on the left side of RHS, see if we overlap on the right // We don't overlap on the left side of RHS, see if we overlap on the right
// of RHS... // of RHS...
if ((*(Constant*)RHS.getUpper() > *(Constant*)LHS.getLower())->getValue()) { if (GT(RHS.getUpper(), LHS.getLower())) {
// Simple overlap... // Simple overlap...
return ConstantRange(LHS.getLower(), RHS.getUpper()); return ConstantRange(LHS.getLower(), RHS.getUpper());
} else { } else {
@ -179,18 +198,6 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
} }
} }
static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) {
if ((*(Constant*)A < *(Constant*)B)->getValue())
return A;
return B;
}
static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) {
if ((*(Constant*)A > *(Constant*)B)->getValue())
return A;
return B;
}
/// intersect - Return the range that results from the intersection of this /// intersect - Return the range that results from the intersection of this
/// range with another range. /// range with another range.
/// ///
@ -205,7 +212,7 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
ConstantIntegral *L = Max(Lower, CR.Lower); ConstantIntegral *L = Max(Lower, CR.Lower);
ConstantIntegral *U = Min(Upper, CR.Upper); ConstantIntegral *U = Min(Upper, CR.Upper);
if ((*L < *U)->getValue()) // If range isn't empty... if (LT(L, U)) // If range isn't empty...
return ConstantRange(L, U); return ConstantRange(L, U);
else else
return ConstantRange(getType(), false); // Otherwise, return empty set return ConstantRange(getType(), false); // Otherwise, return empty set

View File

@ -22,11 +22,31 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Support/ConstantRange.h" #include "llvm/Support/ConstantRange.h"
#include "llvm/Type.h" #include "llvm/Constants.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include "llvm/ConstantHandling.h" #include "llvm/Type.h"
using namespace llvm; using namespace llvm;
static bool LT(ConstantIntegral *A, ConstantIntegral *B) {
Constant *C = ConstantExpr::get(Instruction::SetLT, A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
}
static bool GT(ConstantIntegral *A, ConstantIntegral *B) {
Constant *C = ConstantExpr::get(Instruction::SetGT, A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
}
static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) {
return LT(A, B) ? A : B;
}
static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) {
return GT(A, B) ? A : B;
}
/// Initialize a full (the default) or empty set for the specified type. /// Initialize a full (the default) or empty set for the specified type.
/// ///
ConstantRange::ConstantRange(const Type *Ty, bool Full) { ConstantRange::ConstantRange(const Type *Ty, bool Full) {
@ -57,9 +77,8 @@ static ConstantIntegral *Next(ConstantIntegral *CI) {
if (CI->getType() == Type::BoolTy) if (CI->getType() == Type::BoolTy)
return CI == ConstantBool::True ? ConstantBool::False : ConstantBool::True; return CI == ConstantBool::True ? ConstantBool::False : ConstantBool::True;
// Otherwise use operator+ in the ConstantHandling Library. Constant *Result = ConstantExpr::get(Instruction::Add, CI,
Constant *Result = *ConstantInt::get(CI->getType(), 1) + *CI; ConstantInt::get(CI->getType(), 1));
assert(Result && "ConstantHandling not implemented for integral plus!?");
return cast<ConstantIntegral>(Result); return cast<ConstantIntegral>(Result);
} }
@ -109,7 +128,7 @@ bool ConstantRange::isEmptySet() const {
/// for example: [100, 8) /// for example: [100, 8)
/// ///
bool ConstantRange::isWrappedSet() const { bool ConstantRange::isWrappedSet() const {
return (*(Constant*)Lower > *(Constant*)Upper)->getValue(); return GT(Lower, Upper);
} }
@ -132,8 +151,8 @@ uint64_t ConstantRange::getSetSize() const {
} }
// Simply subtract the bounds... // Simply subtract the bounds...
Constant *Result = *(Constant*)Upper - *(Constant*)Lower; Constant *Result =
assert(Result && "Subtraction of constant integers not implemented?"); ConstantExpr::get(Instruction::Sub, (Constant*)Upper, (Constant*)Lower);
return cast<ConstantInt>(Result)->getRawValue(); return cast<ConstantInt>(Result)->getRawValue();
} }
@ -149,10 +168,10 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
// Check to see if we overlap on the Left side of RHS... // Check to see if we overlap on the Left side of RHS...
// //
if ((*(Constant*)RHS.getLower() < *(Constant*)LHS.getUpper())->getValue()) { if (LT(RHS.getLower(), LHS.getUpper())) {
// We do overlap on the left side of RHS, see if we overlap on the right of // We do overlap on the left side of RHS, see if we overlap on the right of
// RHS... // RHS...
if ((*(Constant*)RHS.getUpper() > *(Constant*)LHS.getLower())->getValue()) { if (GT(RHS.getUpper(), LHS.getLower())) {
// Ok, the result overlaps on both the left and right sides. See if the // Ok, the result overlaps on both the left and right sides. See if the
// resultant interval will be smaller if we wrap or not... // resultant interval will be smaller if we wrap or not...
// //
@ -169,7 +188,7 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
} else { } else {
// We don't overlap on the left side of RHS, see if we overlap on the right // We don't overlap on the left side of RHS, see if we overlap on the right
// of RHS... // of RHS...
if ((*(Constant*)RHS.getUpper() > *(Constant*)LHS.getLower())->getValue()) { if (GT(RHS.getUpper(), LHS.getLower())) {
// Simple overlap... // Simple overlap...
return ConstantRange(LHS.getLower(), RHS.getUpper()); return ConstantRange(LHS.getLower(), RHS.getUpper());
} else { } else {
@ -179,18 +198,6 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
} }
} }
static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) {
if ((*(Constant*)A < *(Constant*)B)->getValue())
return A;
return B;
}
static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) {
if ((*(Constant*)A > *(Constant*)B)->getValue())
return A;
return B;
}
/// intersect - Return the range that results from the intersection of this /// intersect - Return the range that results from the intersection of this
/// range with another range. /// range with another range.
/// ///
@ -205,7 +212,7 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
ConstantIntegral *L = Max(Lower, CR.Lower); ConstantIntegral *L = Max(Lower, CR.Lower);
ConstantIntegral *U = Min(Upper, CR.Upper); ConstantIntegral *U = Min(Upper, CR.Upper);
if ((*L < *U)->getValue()) // If range isn't empty... if (LT(L, U)) // If range isn't empty...
return ConstantRange(L, U); return ConstantRange(L, U);
else else
return ConstantRange(getType(), false); // Otherwise, return empty set return ConstantRange(getType(), false); // Otherwise, return empty set