summaryrefslogtreecommitdiff
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
parentf57fc81faebf3eb81fb30fe17c4295d46060e03f (diff)
downloadllvm-581b0d453a63f7f657248f80317976995262be11.tar.gz
llvm-581b0d453a63f7f657248f80317976995262be11.tar.bz2
llvm-581b0d453a63f7f657248f80317976995262be11.tar.xz
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
-rw-r--r--include/llvm/Analysis/ScalarEvolution.h4
-rw-r--r--include/llvm/Support/ConstantRange.h15
-rw-r--r--lib/Analysis/ConstantRange.cpp27
-rw-r--r--lib/Analysis/ScalarEvolution.cpp48
-rw-r--r--lib/Support/ConstantRange.cpp27
-rw-r--r--lib/Transforms/Scalar/CorrelatedExprs.cpp5
6 files changed, 50 insertions, 76 deletions
diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h
index 4aac284ee0..b950ca48c6 100644
--- a/include/llvm/Analysis/ScalarEvolution.h
+++ b/include/llvm/Analysis/ScalarEvolution.h
@@ -85,6 +85,10 @@ namespace llvm {
///
virtual const Type *getType() const = 0;
+ /// getBitWidth - Get the bit width of the type, if it has one, 0 otherwise.
+ ///
+ uint32_t getBitWidth() const;
+
/// replaceSymbolicValuesWithConcrete - If this SCEV internally references
/// the symbolic value "Sym", construct and return a new SCEV that produces
/// the same value, but which uses the concrete value Conc instead of the
diff --git a/include/llvm/Support/ConstantRange.h b/include/llvm/Support/ConstantRange.h
index b7e98181b3..ae36f42e12 100644
--- a/include/llvm/Support/ConstantRange.h
+++ b/include/llvm/Support/ConstantRange.h
@@ -37,7 +37,6 @@
namespace llvm {
class Constant;
-class ConstantInt;
class Type;
class ConstantRange {
@@ -66,11 +65,11 @@ class ConstantRange {
/// getLower - Return the lower value for this range...
///
- ConstantInt *getLower() const;
+ const APInt &getLower() const { return Lower; }
/// getUpper - Return the upper value for this range...
///
- ConstantInt *getUpper() const;
+ const APInt &getUpper() const { return Upper; }
/// getType - Return the LLVM data type of this range.
///
@@ -94,12 +93,16 @@ class ConstantRange {
/// The isSigned parameter indicates whether the comparisons should be
/// performed as if the values are signed or not.
///
- bool contains(ConstantInt *Val, bool isSigned) const;
+ bool contains(const APInt &Val, bool isSigned) const;
/// getSingleElement - If this set contains a single element, return it,
/// otherwise return null.
///
- ConstantInt *getSingleElement() const;
+ const APInt *getSingleElement() const {
+ if (Upper == Lower + 1)
+ return &Lower;
+ return 0;
+ }
/// isSingleElement - Return true if this set contains exactly one member.
///
@@ -120,7 +123,7 @@ class ConstantRange {
/// subtract - Subtract the specified constant from the endpoints of this
/// constant range.
- ConstantRange subtract(ConstantInt *CI) const;
+ ConstantRange subtract(const APInt &CI) const;
/// intersectWith - Return the range that results from the intersection of
/// this range with another range. The resultant range is pruned as much as
diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp
index c000c73e8b..f419edcf9b 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 0507b39b7d..364e1223ba 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.
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index c000c73e8b..f419edcf9b 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/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/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp
index 7942636da7..277a1284ea 100644
--- a/lib/Transforms/Scalar/CorrelatedExprs.cpp
+++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp
@@ -1018,7 +1018,10 @@ void CEE::ComputeReplacements(RegionInfo &RI) {
// If we know that this value is a particular constant, set Replacement to
// the constant...
- Value *Replacement = VI.getBounds().getSingleElement();
+ Value *Replacement = 0;
+ const APInt * Rplcmnt = VI.getBounds().getSingleElement();
+ if (Rplcmnt)
+ Replacement = ConstantInt::get(*Rplcmnt);
// If this value is not known to be some constant, figure out the lowest
// rank value that it is known to be equal to (if anything).