aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-02-28 19:57:34 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-02-28 19:57:34 +0000
commit581b0d453a63f7f657248f80317976995262be11 (patch)
treeeb1a0259be67fdad03b5708f43ba80107d378380 /lib/Analysis
parentf57fc81faebf3eb81fb30fe17c4295d46060e03f (diff)
downloadexternal_llvm-581b0d453a63f7f657248f80317976995262be11.zip
external_llvm-581b0d453a63f7f657248f80317976995262be11.tar.gz
external_llvm-581b0d453a63f7f657248f80317976995262be11.tar.bz2
For PR1205:
Remove ConstantInt from ConstantRange interface and adjust its users to compensate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34758 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ConstantRange.cpp27
-rw-r--r--lib/Analysis/ScalarEvolution.cpp48
2 files changed, 30 insertions, 45 deletions
diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp
index c000c73..f419edc 100644
--- a/lib/Analysis/ConstantRange.cpp
+++ b/lib/Analysis/ConstantRange.cpp
@@ -22,7 +22,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ConstantRange.h"
-#include "llvm/Constants.h"
#include "llvm/Instruction.h"
#include "llvm/Instructions.h"
#include "llvm/Type.h"
@@ -107,14 +106,6 @@ const Type *ConstantRange::getType() const {
return IntegerType::get(Lower.getBitWidth());
}
-ConstantInt *ConstantRange::getLower() const {
- return ConstantInt::get(getType(), Lower);
-}
-
-ConstantInt *ConstantRange::getUpper() const {
- return ConstantInt::get(getType(), Upper);
-}
-
/// isFullSet - Return true if this set contains all of the elements possible
/// for this data-type
bool ConstantRange::isFullSet() const {
@@ -136,14 +127,6 @@ bool ConstantRange::isWrappedSet(bool isSigned) const {
return Lower.ugt(Upper);
}
-/// getSingleElement - If this set contains a single element, return it,
-/// otherwise return null.
-ConstantInt *ConstantRange::getSingleElement() const {
- if (Upper == Lower + 1) // Is it a single element range?
- return ConstantInt::get(getType(), Lower);
- return 0;
-}
-
/// getSetSize - Return the number of elements in this set.
///
APInt ConstantRange::getSetSize() const {
@@ -161,14 +144,13 @@ APInt ConstantRange::getSetSize() const {
/// contains - Return true if the specified value is in the set.
///
-bool ConstantRange::contains(ConstantInt *Val, bool isSigned) const {
+bool ConstantRange::contains(const APInt &V, bool isSigned) const {
if (Lower == Upper) {
if (isFullSet())
return true;
return false;
}
- const APInt &V = Val->getValue();
if (!isWrappedSet(isSigned))
if (isSigned)
return Lower.sle(V) && V.slt(Upper);
@@ -182,14 +164,11 @@ bool ConstantRange::contains(ConstantInt *Val, bool isSigned) const {
/// subtract - Subtract the specified constant from the endpoints of this
/// constant range.
-ConstantRange ConstantRange::subtract(ConstantInt *CI) const {
- assert(CI->getType() == getType() &&
- "Cannot subtract from different type range or non-integer!");
+ConstantRange ConstantRange::subtract(const APInt &Val) const {
+ assert(Val.getBitWidth() == Lower.getBitWidth() && "Wrong bit width");
// If the set is empty or full, don't modify the endpoints.
if (Lower == Upper)
return *this;
-
- const APInt &Val = CI->getValue();
return ConstantRange(Lower - Val, Upper - Val);
}
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 0507b39..364e122 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -127,6 +127,12 @@ ConstantRange SCEV::getValueRange() const {
return ConstantRange(getType());
}
+uint32_t SCEV::getBitWidth() const {
+ if (const IntegerType* ITy = dyn_cast<IntegerType>(getType()))
+ return ITy->getBitWidth();
+ return 0;
+}
+
SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {}
@@ -2320,7 +2326,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
SCEVHandle Shifted = SCEVAddRecExpr::get(Operands, getLoop());
if (SCEVAddRecExpr *ShiftedAddRec = dyn_cast<SCEVAddRecExpr>(Shifted))
return ShiftedAddRec->getNumIterationsInRange(
- Range.subtract(SC->getValue()),isSigned);
+ Range.subtract(SC->getValue()->getValue()),isSigned);
// This is strange and shouldn't happen.
return new SCEVCouldNotCompute();
}
@@ -2337,8 +2343,8 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// First check to see if the range contains zero. If not, the first
// iteration exits.
- ConstantInt *Zero = ConstantInt::get(getType(), 0);
- if (!Range.contains(Zero, isSigned)) return SCEVConstant::get(Zero);
+ if (!Range.contains(APInt(getBitWidth(),0), isSigned))
+ return SCEVConstant::get(ConstantInt::get(getType(),0));
if (isAffine()) {
// If this is an affine expression then we have this situation:
@@ -2347,29 +2353,27 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// Since we know that zero is in the range, we know that the upper value of
// the range must be the first possible exit value. Also note that we
// already checked for a full range.
- ConstantInt *Upper = cast<ConstantInt>(Range.getUpper());
- ConstantInt *A = cast<SCEVConstant>(getOperand(1))->getValue();
- ConstantInt *One = ConstantInt::get(getType(), 1);
+ const APInt &Upper = Range.getUpper();
+ APInt A = cast<SCEVConstant>(getOperand(1))->getValue()->getValue();
+ APInt One(getBitWidth(),1);
// The exit value should be (Upper+A-1)/A.
- Constant *ExitValue = Upper;
- if (A != One) {
- ExitValue = ConstantExpr::getSub(ConstantExpr::getAdd(Upper, A), One);
- ExitValue = ConstantExpr::getSDiv(ExitValue, A);
- }
- assert(isa<ConstantInt>(ExitValue) &&
- "Constant folding of integers not implemented?");
+ APInt ExitVal(Upper);
+ if (A != One)
+ ExitVal = (Upper + A - One).sdiv(A);
+ ConstantInt *ExitValue = ConstantInt::get(getType(), ExitVal);
// Evaluate at the exit value. If we really did fall out of the valid
// range, then we computed our trip count, otherwise wrap around or other
// things must have happened.
ConstantInt *Val = EvaluateConstantChrecAtConstant(this, ExitValue);
- if (Range.contains(Val, isSigned))
+ if (Range.contains(Val->getValue(), isSigned))
return new SCEVCouldNotCompute(); // Something strange happened
// Ensure that the previous value is in the range. This is a sanity check.
- assert(Range.contains(EvaluateConstantChrecAtConstant(this,
- ConstantExpr::getSub(ExitValue, One)), isSigned) &&
+ assert(Range.contains(
+ EvaluateConstantChrecAtConstant(this,
+ ConstantInt::get(getType(), ExitVal - One))->getValue(), isSigned) &&
"Linear scev computation is off in a bad way!");
return SCEVConstant::get(cast<ConstantInt>(ExitValue));
} else if (isQuadratic()) {
@@ -2378,7 +2382,8 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// terms of figuring out when zero is crossed, instead of when
// Range.getUpper() is crossed.
std::vector<SCEVHandle> NewOps(op_begin(), op_end());
- NewOps[0] = SCEV::getNegativeSCEV(SCEVUnknown::get(Range.getUpper()));
+ NewOps[0] = SCEV::getNegativeSCEV(SCEVUnknown::get(
+ ConstantInt::get(getType(), Range.getUpper())));
SCEVHandle NewAddRec = SCEVAddRecExpr::get(NewOps, getLoop());
// Next, solve the constructed addrec
@@ -2399,14 +2404,14 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// for "X*X < 5", for example, we should not return a root of 2.
ConstantInt *R1Val = EvaluateConstantChrecAtConstant(this,
R1->getValue());
- if (Range.contains(R1Val, isSigned)) {
+ if (Range.contains(R1Val->getValue(), isSigned)) {
// The next iteration must be out of the range...
Constant *NextVal =
ConstantExpr::getAdd(R1->getValue(),
ConstantInt::get(R1->getType(), 1));
R1Val = EvaluateConstantChrecAtConstant(this, NextVal);
- if (!Range.contains(R1Val, isSigned))
+ if (!Range.contains(R1Val->getValue(), isSigned))
return SCEVUnknown::get(NextVal);
return new SCEVCouldNotCompute(); // Something strange happened
}
@@ -2417,7 +2422,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
ConstantExpr::getSub(R1->getValue(),
ConstantInt::get(R1->getType(), 1));
R1Val = EvaluateConstantChrecAtConstant(this, NextVal);
- if (Range.contains(R1Val, isSigned))
+ if (Range.contains(R1Val->getValue(), isSigned))
return R1;
return new SCEVCouldNotCompute(); // Something strange happened
}
@@ -2439,7 +2444,8 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
return new SCEVCouldNotCompute();
// Check to see if we found the value!
- if (!Range.contains(cast<SCEVConstant>(Val)->getValue(), isSigned))
+ if (!Range.contains(cast<SCEVConstant>(Val)->getValue()->getValue(),
+ isSigned))
return SCEVConstant::get(TestVal);
// Increment to test the next index.