aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-02-28 18:57:32 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-02-28 18:57:32 +0000
commitdc5c1597014fa5c47c94db2b9fd424d2266053db (patch)
tree9167714e90ee780fc0aabd5ccbfe73eadcf41ef0
parentf1b214d3ca12f2d85f0d092b4920172bcc797bac (diff)
downloadexternal_llvm-dc5c1597014fa5c47c94db2b9fd424d2266053db.zip
external_llvm-dc5c1597014fa5c47c94db2b9fd424d2266053db.tar.gz
external_llvm-dc5c1597014fa5c47c94db2b9fd424d2266053db.tar.bz2
For PR1205:
First round of ConstantRange changes. This makes all CR constructors use only APInt and not use ConstantInt. Clients are adjusted accordingly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34756 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/ConstantRange.h14
-rw-r--r--lib/Analysis/ConstantRange.cpp61
-rw-r--r--lib/Analysis/ScalarEvolution.cpp11
-rw-r--r--lib/Support/ConstantRange.cpp61
-rw-r--r--lib/Transforms/Scalar/CorrelatedExprs.cpp9
5 files changed, 51 insertions, 105 deletions
diff --git a/include/llvm/Support/ConstantRange.h b/include/llvm/Support/ConstantRange.h
index 65b17f5..b7e9818 100644
--- a/include/llvm/Support/ConstantRange.h
+++ b/include/llvm/Support/ConstantRange.h
@@ -51,22 +51,18 @@ class ConstantRange {
/// Initialize a range to hold the single specified value.
///
- ConstantRange(Constant *Value);
+ ConstantRange(const APInt &Value);
- /// Initialize a range of values explicitly... this will assert out if
- /// Lower==Upper and Lower != Min or Max for its type, if the two constants
- /// have different types, or if the constant are not integral values.
- ///
- ConstantRange(Constant *Lower, Constant *Upper);
-
- /// @brief Initialize a range of values explicitly.
+ /// @brief Initialize a range of values explicitly. This will assert out if
+ /// Lower==Upper and Lower != Min or Max value for its type. It will also
+ /// assert out if the two APInt's are not the same bit width.
ConstantRange(const APInt& Lower, const APInt& Upper);
/// Initialize a set of values that all satisfy the predicate with C. The
/// predicate should be either an ICmpInst::Predicate or FCmpInst::Predicate
/// value.
/// @brief Get a range for a relation with a constant integral.
- ConstantRange(unsigned short predicate, ConstantInt *C);
+ ConstantRange(unsigned short predicate, const APInt &C);
/// getLower - Return the lower value for this range...
///
diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp
index 876ade2..c000c73 100644
--- a/lib/Analysis/ConstantRange.cpp
+++ b/lib/Analysis/ConstantRange.cpp
@@ -45,28 +45,7 @@ ConstantRange::ConstantRange(const Type *Ty, bool Full) :
/// Initialize a range to hold the single specified value.
///
-ConstantRange::ConstantRange(Constant *V)
- : Lower(cast<ConstantInt>(V)->getValue()),
- Upper(cast<ConstantInt>(V)->getValue() + 1) { }
-
-/// Initialize a range of values explicitly... this will assert out if
-/// Lower==Upper and Lower != Min or Max for its type (or if the two constants
-/// have different types)
-///
-ConstantRange::ConstantRange(Constant *L, Constant *U)
- : Lower(cast<ConstantInt>(L)->getValue()),
- Upper(cast<ConstantInt>(U)->getValue()) {
- assert(L->getType() == U->getType() && "Invalid ConstantRange types!");
- assert(L->getType()->isInteger() && "Invalid ConstantRange types!");
-
- // Make sure that if L & U are equal that they are either Min or Max...
-
- uint32_t BitWidth = cast<IntegerType>(L->getType())->getBitWidth();
- const IntegerType *Ty = cast<IntegerType>(L->getType());
- assert((L != U || (L == ConstantInt::get(Ty, APInt::getMaxValue(BitWidth))
- || L == ConstantInt::get(Ty, APInt::getMinValue(BitWidth))))
- && "Lower == Upper, but they aren't min or max for type!");
-}
+ConstantRange::ConstantRange(const APInt & V) : Lower(V), Upper(V + 1) { }
ConstantRange::ConstantRange(const APInt &L, const APInt &U) :
Lower(L), Upper(U) {
@@ -80,45 +59,43 @@ ConstantRange::ConstantRange(const APInt &L, const APInt &U) :
/// Initialize a set of values that all satisfy the condition with C.
///
-ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantInt *C)
- : Lower(cast<IntegerType>(C->getType())->getBitWidth(), 0),
- Upper(cast<IntegerType>(C->getType())->getBitWidth(), 0) {
- const APInt& Val = C->getValue();
- uint32_t BitWidth = cast<IntegerType>(C->getType())->getBitWidth();
+ConstantRange::ConstantRange(unsigned short ICmpOpcode, const APInt &C)
+ : Lower(C.getBitWidth(), 0), Upper(C.getBitWidth(), 0) {
+ uint32_t BitWidth = C.getBitWidth();
switch (ICmpOpcode) {
default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!");
- case ICmpInst::ICMP_EQ: Lower = Val; Upper = Val + 1; return;
- case ICmpInst::ICMP_NE: Upper = Val; Lower = Val + 1; return;
+ case ICmpInst::ICMP_EQ: Lower = C; Upper = C + 1; return;
+ case ICmpInst::ICMP_NE: Upper = C; Lower = C + 1; return;
case ICmpInst::ICMP_ULT:
Lower = APInt::getMinValue(BitWidth);
- Upper = Val;
+ Upper = C;
return;
case ICmpInst::ICMP_SLT:
Lower = APInt::getSignedMinValue(BitWidth);
- Upper = Val;
+ Upper = C;
return;
case ICmpInst::ICMP_UGT:
- Lower = Val + 1;
+ Lower = C + 1;
Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
return;
case ICmpInst::ICMP_SGT:
- Lower = Val + 1;
+ Lower = C + 1;
Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
return;
case ICmpInst::ICMP_ULE:
Lower = APInt::getMinValue(BitWidth);
- Upper = Val + 1;
+ Upper = C + 1;
return;
case ICmpInst::ICMP_SLE:
Lower = APInt::getSignedMinValue(BitWidth);
- Upper = Val + 1;
+ Upper = C + 1;
return;
case ICmpInst::ICMP_UGE:
- Lower = Val;
+ Lower = C;
Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
return;
case ICmpInst::ICMP_SGE:
- Lower = Val;
+ Lower = C;
Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
return;
}
@@ -243,14 +220,14 @@ ConstantRange::intersect1Wrapped(const ConstantRange &LHS,
} else {
// No overlap on the right, just on the left.
- return ConstantRange(RHS.getLower(), LHS.getUpper());
+ return ConstantRange(RHS.Lower, LHS.Upper);
}
} else {
// We don't overlap on the left side of RHS, see if we overlap on the right
// of RHS...
if (GT) {
// Simple overlap...
- return ConstantRange(LHS.getLower(), RHS.getUpper());
+ return ConstantRange(LHS.Lower, RHS.Upper);
} else {
// No overlap...
return ConstantRange(LHS.getType(), false);
@@ -319,11 +296,9 @@ ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
unsigned SrcTySize = Lower.getBitWidth();
unsigned DstTySize = Ty->getPrimitiveSizeInBits();
assert(SrcTySize < DstTySize && "Not a value extension");
- if (isFullSet()) {
+ if (isFullSet())
// Change a source full set into [0, 1 << 8*numbytes)
- return ConstantRange(Constant::getNullValue(Ty),
- ConstantInt::get(Ty, 1ULL << SrcTySize));
- }
+ return ConstantRange(APInt(DstTySize,0), APInt(DstTySize,1).shl(SrcTySize));
APInt L = Lower; L.zext(DstTySize);
APInt U = Upper; U.zext(DstTySize);
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index a81f24f..0507b39 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -177,7 +177,7 @@ SCEVHandle SCEVConstant::get(ConstantInt *V) {
}
ConstantRange SCEVConstant::getValueRange() const {
- return ConstantRange(V);
+ return ConstantRange(V->getValue());
}
const Type *SCEVConstant::getType() const { return V->getType(); }
@@ -490,12 +490,11 @@ static SCEVHandle PartialFact(SCEVHandle V, unsigned NumSteps) {
// Handle this case efficiently, it is common to have constant iteration
// counts while computing loop exit values.
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V)) {
- uint64_t Val = SC->getValue()->getZExtValue();
- uint64_t Result = 1;
+ APInt Val = SC->getValue()->getValue();
+ APInt Result(Val.getBitWidth(), 1);
for (; NumSteps; --NumSteps)
Result *= Val-(NumSteps-1);
- Constant *Res = ConstantInt::get(Type::Int64Ty, Result);
- return SCEVUnknown::get(ConstantExpr::getTruncOrBitCast(Res, V->getType()));
+ return SCEVUnknown::get(ConstantInt::get(V->getType(), Result));
}
const Type *Ty = V->getType();
@@ -1567,7 +1566,7 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) {
ConstantExpr::getBitCast(CompVal, RealTy));
if (CompVal) {
// Form the constant range.
- ConstantRange CompRange(Cond, CompVal);
+ ConstantRange CompRange(Cond, CompVal->getValue());
SCEVHandle Ret = AddRec->getNumIterationsInRange(CompRange,
false /*Always treat as unsigned range*/);
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index 876ade2..c000c73 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -45,28 +45,7 @@ ConstantRange::ConstantRange(const Type *Ty, bool Full) :
/// Initialize a range to hold the single specified value.
///
-ConstantRange::ConstantRange(Constant *V)
- : Lower(cast<ConstantInt>(V)->getValue()),
- Upper(cast<ConstantInt>(V)->getValue() + 1) { }
-
-/// Initialize a range of values explicitly... this will assert out if
-/// Lower==Upper and Lower != Min or Max for its type (or if the two constants
-/// have different types)
-///
-ConstantRange::ConstantRange(Constant *L, Constant *U)
- : Lower(cast<ConstantInt>(L)->getValue()),
- Upper(cast<ConstantInt>(U)->getValue()) {
- assert(L->getType() == U->getType() && "Invalid ConstantRange types!");
- assert(L->getType()->isInteger() && "Invalid ConstantRange types!");
-
- // Make sure that if L & U are equal that they are either Min or Max...
-
- uint32_t BitWidth = cast<IntegerType>(L->getType())->getBitWidth();
- const IntegerType *Ty = cast<IntegerType>(L->getType());
- assert((L != U || (L == ConstantInt::get(Ty, APInt::getMaxValue(BitWidth))
- || L == ConstantInt::get(Ty, APInt::getMinValue(BitWidth))))
- && "Lower == Upper, but they aren't min or max for type!");
-}
+ConstantRange::ConstantRange(const APInt & V) : Lower(V), Upper(V + 1) { }
ConstantRange::ConstantRange(const APInt &L, const APInt &U) :
Lower(L), Upper(U) {
@@ -80,45 +59,43 @@ ConstantRange::ConstantRange(const APInt &L, const APInt &U) :
/// Initialize a set of values that all satisfy the condition with C.
///
-ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantInt *C)
- : Lower(cast<IntegerType>(C->getType())->getBitWidth(), 0),
- Upper(cast<IntegerType>(C->getType())->getBitWidth(), 0) {
- const APInt& Val = C->getValue();
- uint32_t BitWidth = cast<IntegerType>(C->getType())->getBitWidth();
+ConstantRange::ConstantRange(unsigned short ICmpOpcode, const APInt &C)
+ : Lower(C.getBitWidth(), 0), Upper(C.getBitWidth(), 0) {
+ uint32_t BitWidth = C.getBitWidth();
switch (ICmpOpcode) {
default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!");
- case ICmpInst::ICMP_EQ: Lower = Val; Upper = Val + 1; return;
- case ICmpInst::ICMP_NE: Upper = Val; Lower = Val + 1; return;
+ case ICmpInst::ICMP_EQ: Lower = C; Upper = C + 1; return;
+ case ICmpInst::ICMP_NE: Upper = C; Lower = C + 1; return;
case ICmpInst::ICMP_ULT:
Lower = APInt::getMinValue(BitWidth);
- Upper = Val;
+ Upper = C;
return;
case ICmpInst::ICMP_SLT:
Lower = APInt::getSignedMinValue(BitWidth);
- Upper = Val;
+ Upper = C;
return;
case ICmpInst::ICMP_UGT:
- Lower = Val + 1;
+ Lower = C + 1;
Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
return;
case ICmpInst::ICMP_SGT:
- Lower = Val + 1;
+ Lower = C + 1;
Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
return;
case ICmpInst::ICMP_ULE:
Lower = APInt::getMinValue(BitWidth);
- Upper = Val + 1;
+ Upper = C + 1;
return;
case ICmpInst::ICMP_SLE:
Lower = APInt::getSignedMinValue(BitWidth);
- Upper = Val + 1;
+ Upper = C + 1;
return;
case ICmpInst::ICMP_UGE:
- Lower = Val;
+ Lower = C;
Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
return;
case ICmpInst::ICMP_SGE:
- Lower = Val;
+ Lower = C;
Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
return;
}
@@ -243,14 +220,14 @@ ConstantRange::intersect1Wrapped(const ConstantRange &LHS,
} else {
// No overlap on the right, just on the left.
- return ConstantRange(RHS.getLower(), LHS.getUpper());
+ return ConstantRange(RHS.Lower, LHS.Upper);
}
} else {
// We don't overlap on the left side of RHS, see if we overlap on the right
// of RHS...
if (GT) {
// Simple overlap...
- return ConstantRange(LHS.getLower(), RHS.getUpper());
+ return ConstantRange(LHS.Lower, RHS.Upper);
} else {
// No overlap...
return ConstantRange(LHS.getType(), false);
@@ -319,11 +296,9 @@ ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
unsigned SrcTySize = Lower.getBitWidth();
unsigned DstTySize = Ty->getPrimitiveSizeInBits();
assert(SrcTySize < DstTySize && "Not a value extension");
- if (isFullSet()) {
+ if (isFullSet())
// Change a source full set into [0, 1 << 8*numbytes)
- return ConstantRange(Constant::getNullValue(Ty),
- ConstantInt::get(Ty, 1ULL << SrcTySize));
- }
+ return ConstantRange(APInt(DstTySize,0), APInt(DstTySize,1).shl(SrcTySize));
APInt L = Lower; L.zext(DstTySize);
APInt U = Upper; U.zext(DstTySize);
diff --git a/lib/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp
index fe122c4..7942636 100644
--- a/lib/Transforms/Scalar/CorrelatedExprs.cpp
+++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp
@@ -1150,7 +1150,7 @@ Relation::KnownResult CEE::getCmpResult(CmpInst *CI,
//
if (ConstantInt *C = dyn_cast<ConstantInt>(Op1)) {
// Check to see if we already know the result of this comparison...
- ConstantRange R = ConstantRange(predicate, C);
+ ConstantRange R = ConstantRange(predicate, C->getValue());
ConstantRange Int = R.intersectWith(Op0VI->getBounds(),
ICmpInst::isSignedPredicate(ICmpInst::Predicate(predicate)));
@@ -1197,7 +1197,7 @@ bool Relation::contradicts(unsigned Op,
if (ConstantInt *C = dyn_cast<ConstantInt>(Val))
if (Op >= ICmpInst::FIRST_ICMP_PREDICATE &&
Op <= ICmpInst::LAST_ICMP_PREDICATE)
- if (ConstantRange(Op, C).intersectWith(VI.getBounds(),
+ if (ConstantRange(Op, C->getValue()).intersectWith(VI.getBounds(),
ICmpInst::isSignedPredicate(ICmpInst::Predicate(Op))).isEmptySet())
return true;
@@ -1255,8 +1255,9 @@ bool Relation::incorporate(unsigned Op, ValueInfo &VI) {
if (ConstantInt *C = dyn_cast<ConstantInt>(Val))
if (Op >= ICmpInst::FIRST_ICMP_PREDICATE &&
Op <= ICmpInst::LAST_ICMP_PREDICATE)
- VI.getBounds() = ConstantRange(Op, C).intersectWith(VI.getBounds(),
- ICmpInst::isSignedPredicate(ICmpInst::Predicate(Op)));
+ VI.getBounds() =
+ ConstantRange(Op, C->getValue()).intersectWith(VI.getBounds(),
+ ICmpInst::isSignedPredicate(ICmpInst::Predicate(Op)));
switch (Rel) {
default: assert(0 && "Unknown prior value!");