[llvm-commits] CVS: llvm/lib/Analysis/ConstantRange.cpp ScalarEvolution.cpp
Reid Spencer
reid at x10sys.com
Wed Feb 28 11:57:59 PST 2007
Changes in directory llvm/lib/Analysis:
ConstantRange.cpp updated: 1.36 -> 1.37
ScalarEvolution.cpp updated: 1.94 -> 1.95
---
Log message:
For PR1205: http://llvm.org/PR1205 :
Remove ConstantInt from ConstantRange interface and adjust its users to
compensate.
---
Diffs of the changes: (+30 -45)
ConstantRange.cpp | 27 +++------------------------
ScalarEvolution.cpp | 48 +++++++++++++++++++++++++++---------------------
2 files changed, 30 insertions(+), 45 deletions(-)
Index: llvm/lib/Analysis/ConstantRange.cpp
diff -u llvm/lib/Analysis/ConstantRange.cpp:1.36 llvm/lib/Analysis/ConstantRange.cpp:1.37
--- llvm/lib/Analysis/ConstantRange.cpp:1.36 Wed Feb 28 12:57:32 2007
+++ llvm/lib/Analysis/ConstantRange.cpp Wed Feb 28 13:57:34 2007
@@ -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 @@
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 @@
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 @@
/// 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 @@
/// 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);
}
Index: llvm/lib/Analysis/ScalarEvolution.cpp
diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.94 llvm/lib/Analysis/ScalarEvolution.cpp:1.95
--- llvm/lib/Analysis/ScalarEvolution.cpp:1.94 Wed Feb 28 12:57:32 2007
+++ llvm/lib/Analysis/ScalarEvolution.cpp Wed Feb 28 13:57:34 2007
@@ -127,6 +127,12 @@
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 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 @@
// 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 @@
// 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 @@
// 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 @@
// 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 @@
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 @@
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.
More information about the llvm-commits
mailing list