diff options
author | Zhou Sheng <zhousheng00@gmail.com> | 2007-01-11 12:24:14 +0000 |
---|---|---|
committer | Zhou Sheng <zhousheng00@gmail.com> | 2007-01-11 12:24:14 +0000 |
commit | 6b6b6ef1677fa71b1072c2911b4c1f9524a558c9 (patch) | |
tree | 480ecf010ac5facd1bc29ab57441253691bb42d6 /lib/Analysis | |
parent | 057809ac1c78c3456e8f1481330fa2bcd2b85029 (diff) | |
download | external_llvm-6b6b6ef1677fa71b1072c2911b4c1f9524a558c9.tar.gz external_llvm-6b6b6ef1677fa71b1072c2911b4c1f9524a558c9.tar.bz2 external_llvm-6b6b6ef1677fa71b1072c2911b4c1f9524a558c9.zip |
For PR1043:
Merge ConstantIntegral and ConstantBool into ConstantInt.
Remove ConstantIntegral and ConstantBool from LLVM.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33073 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/BasicAliasAnalysis.cpp | 15 | ||||
-rw-r--r-- | lib/Analysis/ConstantRange.cpp | 50 | ||||
-rw-r--r-- | lib/Analysis/ScalarEvolution.cpp | 28 | ||||
-rw-r--r-- | lib/Analysis/ScalarEvolutionExpander.cpp | 2 |
4 files changed, 50 insertions, 45 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index caabc86f3f..179f069716 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -434,7 +434,8 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, if (cast<PointerType>( BasePtr->getType())->getElementType()->isSized()) { for (unsigned i = 0; i != GEPOperands.size(); ++i) - if (!isa<ConstantInt>(GEPOperands[i])) + if (!isa<ConstantInt>(GEPOperands[i]) || + GEPOperands[i]->getType() == Type::BoolTy) GEPOperands[i] = Constant::getNullValue(GEPOperands[i]->getType()); int64_t Offset = @@ -584,8 +585,8 @@ BasicAliasAnalysis::CheckGEPInstructions( if (G1OC) { Constant *Compare = ConstantExpr::getICmp(ICmpInst::ICMP_SGT, G1OC, G2OC); - if (ConstantBool *CV = dyn_cast<ConstantBool>(Compare)) { - if (CV->getValue()) // If they are comparable and G2 > G1 + if (ConstantInt *CV = dyn_cast<ConstantInt>(Compare)) { + if (CV->getBoolValue()) // If they are comparable and G2 > G1 std::swap(GEP1Ops, GEP2Ops); // Make GEP1 < GEP2 break; } @@ -608,13 +609,15 @@ BasicAliasAnalysis::CheckGEPInstructions( // Is there anything to check? if (GEP1Ops.size() > MinOperands) { for (unsigned i = FirstConstantOper; i != MaxOperands; ++i) - if (isa<ConstantInt>(GEP1Ops[i]) && + if (isa<ConstantInt>(GEP1Ops[i]) && + GEP1Ops[i]->getType() != Type::BoolTy && !cast<Constant>(GEP1Ops[i])->isNullValue()) { // Yup, there's a constant in the tail. Set all variables to // constants in the GEP instruction to make it suiteable for // TargetData::getIndexedOffset. for (i = 0; i != MaxOperands; ++i) - if (!isa<ConstantInt>(GEP1Ops[i])) + if (!isa<ConstantInt>(GEP1Ops[i]) || + GEP1Ops[i]->getType() == Type::BoolTy) GEP1Ops[i] = Constant::getNullValue(GEP1Ops[i]->getType()); // Okay, now get the offset. This is the relative offset for the full // instruction. @@ -667,7 +670,7 @@ BasicAliasAnalysis::CheckGEPInstructions( const Value *Op2 = i < GEP2Ops.size() ? GEP2Ops[i] : 0; // If they are equal, use a zero index... if (Op1 == Op2 && BasePtr1Ty == BasePtr2Ty) { - if (!isa<ConstantInt>(Op1)) + if (!isa<ConstantInt>(Op1) || Op1->getType() == Type::BoolTy) GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Op1->getType()); // Otherwise, just keep the constants we have. } else { diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp index a8ffa5813e..1d49e22472 100644 --- a/lib/Analysis/ConstantRange.cpp +++ b/lib/Analysis/ConstantRange.cpp @@ -30,9 +30,9 @@ #include <ostream> using namespace llvm; -static ConstantIntegral *getMaxValue(const Type *Ty, bool isSigned = false) { +static ConstantInt *getMaxValue(const Type *Ty, bool isSigned = false) { if (Ty == Type::BoolTy) - return ConstantBool::getTrue(); + return ConstantInt::getTrue(); if (Ty->isInteger()) { if (isSigned) { // Calculate 011111111111111... @@ -47,9 +47,9 @@ static ConstantIntegral *getMaxValue(const Type *Ty, bool isSigned = false) { } // Static constructor to create the minimum constant for an integral type... -static ConstantIntegral *getMinValue(const Type *Ty, bool isSigned = false) { +static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) { if (Ty == Type::BoolTy) - return ConstantBool::getFalse(); + return ConstantInt::getFalse(); if (Ty->isInteger()) { if (isSigned) { // Calculate 1111111111000000000000 @@ -62,37 +62,37 @@ static ConstantIntegral *getMinValue(const Type *Ty, bool isSigned = false) { } return 0; } -static ConstantIntegral *Next(ConstantIntegral *CI) { - if (ConstantBool *CB = dyn_cast<ConstantBool>(CI)) - return ConstantBool::get(!CB->getValue()); +static ConstantInt *Next(ConstantInt *CI) { + if (CI->getType() == Type::BoolTy) + return ConstantInt::get(!CI->getBoolValue()); Constant *Result = ConstantExpr::getAdd(CI, ConstantInt::get(CI->getType(), 1)); - return cast<ConstantIntegral>(Result); + return cast<ConstantInt>(Result); } -static bool LT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) { +static bool LT(ConstantInt *A, ConstantInt *B, bool isSigned) { Constant *C = ConstantExpr::getICmp( (isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B); - assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??"); - return cast<ConstantBool>(C)->getValue(); + assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??"); + return cast<ConstantInt>(C)->getBoolValue(); } -static bool LTE(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) { +static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) { Constant *C = ConstantExpr::getICmp( (isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B); - assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??"); - return cast<ConstantBool>(C)->getValue(); + assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??"); + return cast<ConstantInt>(C)->getBoolValue(); } -static bool GT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) { +static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) { return LT(B, A, isSigned); } -static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B, +static ConstantInt *Min(ConstantInt *A, ConstantInt *B, bool isSigned) { return LT(A, B, isSigned) ? A : B; } -static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B, +static ConstantInt *Max(ConstantInt *A, ConstantInt *B, bool isSigned) { return GT(A, B, isSigned) ? A : B; } @@ -111,14 +111,14 @@ ConstantRange::ConstantRange(const Type *Ty, bool Full) { /// Initialize a range to hold the single specified value. /// ConstantRange::ConstantRange(Constant *V) - : Lower(cast<ConstantIntegral>(V)), Upper(Next(cast<ConstantIntegral>(V))) { } + : Lower(cast<ConstantInt>(V)), Upper(Next(cast<ConstantInt>(V))) { } /// 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<ConstantIntegral>(L)), Upper(cast<ConstantIntegral>(U)) { + : Lower(cast<ConstantInt>(L)), Upper(cast<ConstantInt>(U)) { assert(Lower->getType() == Upper->getType() && "Incompatible types for ConstantRange!"); @@ -130,7 +130,7 @@ ConstantRange::ConstantRange(Constant *L, Constant *U) /// Initialize a set of values that all satisfy the condition with C. /// -ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantIntegral *C) { +ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantInt *C) { switch (ICmpOpcode) { default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!"); case ICmpInst::ICMP_EQ: Lower = C; Upper = Next(C); return; @@ -195,7 +195,7 @@ bool ConstantRange::isWrappedSet(bool isSigned) const { /// getSingleElement - If this set contains a single element, return it, /// otherwise return null. -ConstantIntegral *ConstantRange::getSingleElement() const { +ConstantInt *ConstantRange::getSingleElement() const { if (Upper == Next(Lower)) // Is it a single element range? return Lower; return 0; @@ -292,8 +292,8 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR, if (!isWrappedSet(isSigned)) { if (!CR.isWrappedSet(isSigned)) { - ConstantIntegral *L = Max(Lower, CR.Lower, isSigned); - ConstantIntegral *U = Min(Upper, CR.Upper, isSigned); + ConstantInt *L = Max(Lower, CR.Lower, isSigned); + ConstantInt *U = Min(Upper, CR.Upper, isSigned); if (LT(L, U, isSigned)) // If range isn't empty... return ConstantRange(L, U); @@ -306,8 +306,8 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR, return intersect1Wrapped(*this, CR, isSigned); else { // Both ranges are wrapped... - ConstantIntegral *L = Max(Lower, CR.Lower, isSigned); - ConstantIntegral *U = Min(Upper, CR.Upper, isSigned); + ConstantInt *L = Max(Lower, CR.Lower, isSigned); + ConstantInt *U = Min(Upper, CR.Upper, isSigned); return ConstantRange(L, U); } } diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 55036a45c5..9fcbf8c75e 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -1721,8 +1721,8 @@ ComputeLoadConstantCompareIterationCount(LoadInst *LI, Constant *RHS, // Evaluate the condition for this iteration. Result = ConstantExpr::getICmp(predicate, Result, RHS); - if (!isa<ConstantBool>(Result)) break; // Couldn't decide for sure - if (cast<ConstantBool>(Result)->getValue() == false) { + if (!isa<ConstantInt>(Result)) break; // Couldn't decide for sure + if (cast<ConstantInt>(Result)->getBoolValue() == false) { #if 0 cerr << "\n***\n*** Computed loop count " << *ItCst << "\n*** From global " << *GV << "*** BB: " << *L->getHeader() @@ -1926,11 +1926,13 @@ ComputeIterationCountExhaustively(const Loop *L, Value *Cond, bool ExitWhen) { unsigned MaxIterations = MaxBruteForceIterations; // Limit analysis. for (Constant *PHIVal = StartCST; IterationNum != MaxIterations; ++IterationNum) { - ConstantBool *CondVal = - dyn_cast_or_null<ConstantBool>(EvaluateExpression(Cond, PHIVal)); - if (!CondVal) return UnknownValue; // Couldn't symbolically evaluate. + ConstantInt *CondVal = + dyn_cast_or_null<ConstantInt>(EvaluateExpression(Cond, PHIVal)); - if (CondVal->getValue() == ExitWhen) { + // Couldn't symbolically evaluate. + if (!CondVal || CondVal->getType() != Type::BoolTy) return UnknownValue; + + if (CondVal->getBoolValue() == ExitWhen) { ConstantEvolutionLoopExitValue[PN] = PHIVal; ++NumBruteForceTripCountsComputed; return SCEVConstant::get(ConstantInt::get(Type::Int32Ty, IterationNum)); @@ -2199,10 +2201,10 @@ SCEVHandle ScalarEvolutionsImpl::HowFarToZero(SCEV *V, const Loop *L) { << " sol#2: " << *R2 << "\n"; #endif // Pick the smallest positive root value. - if (ConstantBool *CB = - dyn_cast<ConstantBool>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, + if (ConstantInt *CB = + dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, R1->getValue(), R2->getValue()))) { - if (CB->getValue() == false) + if (CB->getBoolValue() == false) std::swap(R1, R2); // R1 is the minimum root now. // We can only use this value if the chrec ends up with an exact zero @@ -2233,7 +2235,7 @@ SCEVHandle ScalarEvolutionsImpl::HowFarToNonZero(SCEV *V, const Loop *L) { Constant *Zero = Constant::getNullValue(C->getValue()->getType()); Constant *NonZero = ConstantExpr::getICmp(ICmpInst::ICMP_NE, C->getValue(), Zero); - if (NonZero == ConstantBool::getTrue()) + if (NonZero == ConstantInt::getTrue()) return getSCEV(Zero); return UnknownValue; // Otherwise it will loop infinitely. } @@ -2424,10 +2426,10 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, SCEVConstant *R2 = dyn_cast<SCEVConstant>(Roots.second); if (R1) { // Pick the smallest positive root value. - if (ConstantBool *CB = - dyn_cast<ConstantBool>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, + if (ConstantInt *CB = + dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, R1->getValue(), R2->getValue()))) { - if (CB->getValue() == false) + if (CB->getBoolValue() == false) std::swap(R1, R2); // R1 is the minimum root now. // Make sure the root is not off by one. The returned iteration should diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index 5e395db5e2..6bc113e0bc 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -143,7 +143,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) { Value *F = expandInTy(S->getOperand(1), Ty); // IF the step is by one, just return the inserted IV. - if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(F)) + if (ConstantInt *CI = dyn_cast<ConstantInt>(F)) if (CI->getZExtValue() == 1) return I; |