diff options
Diffstat (limited to 'lib')
52 files changed, 6666 insertions, 5542 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index b1ea1969f3..d37a4b176f 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -590,7 +590,8 @@ BasicAliasAnalysis::CheckGEPInstructions( // Make sure they are comparable (ie, not constant expressions), and // make sure the GEP with the smaller leading constant is GEP1. if (G1OC) { - Constant *Compare = ConstantExpr::getSetGT(G1OC, G2OC); + 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 std::swap(GEP1Ops, GEP2Ops); // Make GEP1 < GEP2 diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp index 762d5c358a..69d85c2e38 100644 --- a/lib/Analysis/ConstantRange.cpp +++ b/lib/Analysis/ConstantRange.cpp @@ -24,56 +24,43 @@ #include "llvm/Support/ConstantRange.h" #include "llvm/Constants.h" #include "llvm/Instruction.h" +#include "llvm/Instructions.h" #include "llvm/Type.h" #include "llvm/Support/Streams.h" #include <ostream> using namespace llvm; -static ConstantIntegral *getMaxValue(const Type *Ty) { - switch (Ty->getTypeID()) { - case Type::BoolTyID: return ConstantBool::getTrue(); - case Type::SByteTyID: - case Type::ShortTyID: - case Type::IntTyID: - case Type::LongTyID: { - // Calculate 011111111111111... - unsigned TypeBits = Ty->getPrimitiveSize()*8; - int64_t Val = INT64_MAX; // All ones - Val >>= 64-TypeBits; // Shift out unwanted 1 bits... - return ConstantInt::get(Ty, Val); - } - - case Type::UByteTyID: - case Type::UShortTyID: - case Type::UIntTyID: - case Type::ULongTyID: return ConstantInt::getAllOnesValue(Ty); - - default: return 0; +static ConstantIntegral *getMaxValue(const Type *Ty, bool isSigned = false) { + if (Ty == Type::BoolTy) + return ConstantBool::getTrue(); + if (Ty->isInteger()) { + if (isSigned) { + // Calculate 011111111111111... + unsigned TypeBits = Ty->getPrimitiveSize()*8; + int64_t Val = INT64_MAX; // All ones + Val >>= 64-TypeBits; // Shift out unwanted 1 bits... + return ConstantInt::get(Ty, Val); + } + return ConstantInt::getAllOnesValue(Ty); } + return 0; } // Static constructor to create the minimum constant for an integral type... -static ConstantIntegral *getMinValue(const Type *Ty) { - switch (Ty->getTypeID()) { - case Type::BoolTyID: return ConstantBool::getFalse(); - case Type::SByteTyID: - case Type::ShortTyID: - case Type::IntTyID: - case Type::LongTyID: { - // Calculate 1111111111000000000000 - unsigned TypeBits = Ty->getPrimitiveSize()*8; - int64_t Val = -1; // All ones - Val <<= TypeBits-1; // Shift over to the right spot - return ConstantInt::get(Ty, Val); - } - - case Type::UByteTyID: - case Type::UShortTyID: - case Type::UIntTyID: - case Type::ULongTyID: return ConstantInt::get(Ty, 0); - - default: return 0; +static ConstantIntegral *getMinValue(const Type *Ty, bool isSigned = false) { + if (Ty == Type::BoolTy) + return ConstantBool::getFalse(); + if (Ty->isInteger()) { + if (isSigned) { + // Calculate 1111111111000000000000 + unsigned TypeBits = Ty->getPrimitiveSize()*8; + int64_t Val = -1; // All ones + Val <<= TypeBits-1; // Shift over to the right spot + return ConstantInt::get(Ty, Val); + } + return ConstantInt::get(Ty, 0); } + return 0; } static ConstantIntegral *Next(ConstantIntegral *CI) { if (ConstantBool *CB = dyn_cast<ConstantBool>(CI)) @@ -84,25 +71,30 @@ static ConstantIntegral *Next(ConstantIntegral *CI) { return cast<ConstantIntegral>(Result); } -static bool LT(ConstantIntegral *A, ConstantIntegral *B) { - Constant *C = ConstantExpr::getSetLT(A, B); +static bool LT(ConstantIntegral *A, ConstantIntegral *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(); } -static bool LTE(ConstantIntegral *A, ConstantIntegral *B) { - Constant *C = ConstantExpr::getSetLE(A, B); +static bool LTE(ConstantIntegral *A, ConstantIntegral *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(); } -static bool GT(ConstantIntegral *A, ConstantIntegral *B) { return LT(B, A); } +static bool GT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) { + return LT(B, A, isSigned); } -static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) { - return LT(A, B) ? A : B; +static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B, + bool isSigned) { + return LT(A, B, isSigned) ? A : B; } -static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) { - return GT(A, B) ? A : B; +static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B, + bool isSigned) { + return GT(A, B, isSigned) ? A : B; } /// Initialize a full (the default) or empty set for the specified type. @@ -118,47 +110,62 @@ 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))) { -} +ConstantRange::ConstantRange(Constant *V) + : Lower(cast<ConstantIntegral>(V)), Upper(Next(cast<ConstantIntegral>(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) +ConstantRange::ConstantRange(Constant *L, Constant *U) : Lower(cast<ConstantIntegral>(L)), Upper(cast<ConstantIntegral>(U)) { assert(Lower->getType() == Upper->getType() && "Incompatible types for ConstantRange!"); // Make sure that if L & U are equal that they are either Min or Max... assert((L != U || (L == getMaxValue(L->getType()) || - L == getMinValue(L->getType()))) && - "Lower == Upper, but they aren't min or max for type!"); + L == getMinValue(L->getType()))) + && "Lower == Upper, but they aren't min or max for type!"); } /// Initialize a set of values that all satisfy the condition with C. /// -ConstantRange::ConstantRange(unsigned SetCCOpcode, ConstantIntegral *C) { - switch (SetCCOpcode) { - default: assert(0 && "Invalid SetCC opcode to ConstantRange ctor!"); - case Instruction::SetEQ: Lower = C; Upper = Next(C); return; - case Instruction::SetNE: Upper = C; Lower = Next(C); return; - case Instruction::SetLT: +ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantIntegral *C) { + switch (ICmpOpcode) { + default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!"); + case ICmpInst::ICMP_EQ: Lower = C; Upper = Next(C); return; + case ICmpInst::ICMP_NE: Upper = C; Lower = Next(C); return; + case ICmpInst::ICMP_ULT: Lower = getMinValue(C->getType()); Upper = C; return; - case Instruction::SetGT: + case ICmpInst::ICMP_SLT: + Lower = getMinValue(C->getType(), true); + Upper = C; + return; + case ICmpInst::ICMP_UGT: + Lower = Next(C); + Upper = getMinValue(C->getType()); // Min = Next(Max) + return; + case ICmpInst::ICMP_SGT: Lower = Next(C); - Upper = getMinValue(C->getType()); // Min = Next(Max) + Upper = getMinValue(C->getType(), true); // Min = Next(Max) return; - case Instruction::SetLE: + case ICmpInst::ICMP_ULE: Lower = getMinValue(C->getType()); Upper = Next(C); return; - case Instruction::SetGE: + case ICmpInst::ICMP_SLE: + Lower = getMinValue(C->getType(), true); + Upper = Next(C); + return; + case ICmpInst::ICMP_UGE: + Lower = C; + Upper = getMinValue(C->getType()); // Min = Next(Max) + return; + case ICmpInst::ICMP_SGE: Lower = C; - Upper = getMinValue(C->getType()); // Min = Next(Max) + Upper = getMinValue(C->getType(), true); // Min = Next(Max) return; } } @@ -182,11 +189,10 @@ bool ConstantRange::isEmptySet() const { /// isWrappedSet - Return true if this set wraps around the top of the range, /// for example: [100, 8) /// -bool ConstantRange::isWrappedSet() const { - return GT(Lower, Upper); +bool ConstantRange::isWrappedSet(bool isSigned) const { + return GT(Lower, Upper, isSigned); } - /// getSingleElement - If this set contains a single element, return it, /// otherwise return null. ConstantIntegral *ConstantRange::getSingleElement() const { @@ -212,19 +218,17 @@ uint64_t ConstantRange::getSetSize() const { /// contains - Return true if the specified value is in the set. /// -bool ConstantRange::contains(ConstantInt *Val) const { +bool ConstantRange::contains(ConstantInt *Val, bool isSigned) const { if (Lower == Upper) { if (isFullSet()) return true; return false; } - if (!isWrappedSet()) - return LTE(Lower, Val) && LT(Val, Upper); - return LTE(Lower, Val) || LT(Val, Upper); + if (!isWrappedSet(isSigned)) + return LTE(Lower, Val, isSigned) && LT(Val, Upper, isSigned); + return LTE(Lower, Val, isSigned) || LT(Val, Upper, isSigned); } - - /// subtract - Subtract the specified constant from the endpoints of this /// constant range. ConstantRange ConstantRange::subtract(ConstantInt *CI) const { @@ -241,15 +245,16 @@ ConstantRange ConstantRange::subtract(ConstantInt *CI) const { // it is known that LHS is wrapped and RHS isn't. // static ConstantRange intersect1Wrapped(const ConstantRange &LHS, - const ConstantRange &RHS) { - assert(LHS.isWrappedSet() && !RHS.isWrappedSet()); + const ConstantRange &RHS, + bool isSigned) { + assert(LHS.isWrappedSet(isSigned) && !RHS.isWrappedSet(isSigned)); // Check to see if we overlap on the Left side of RHS... // - if (LT(RHS.getLower(), LHS.getUpper())) { + if (LT(RHS.getLower(), LHS.getUpper(), isSigned)) { // We do overlap on the left side of RHS, see if we overlap on the right of // RHS... - if (GT(RHS.getUpper(), LHS.getLower())) { + if (GT(RHS.getUpper(), LHS.getLower(), isSigned)) { // Ok, the result overlaps on both the left and right sides. See if the // resultant interval will be smaller if we wrap or not... // @@ -262,11 +267,10 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, // No overlap on the right, just on the left. return ConstantRange(RHS.getLower(), LHS.getUpper()); } - } else { // We don't overlap on the left side of RHS, see if we overlap on the right // of RHS... - if (GT(RHS.getUpper(), LHS.getLower())) { + if (GT(RHS.getUpper(), LHS.getLower(), isSigned)) { // Simple overlap... return ConstantRange(LHS.getLower(), RHS.getUpper()); } else { @@ -279,30 +283,31 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, /// intersect - Return the range that results from the intersection of this /// range with another range. /// -ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { +ConstantRange ConstantRange::intersectWith(const ConstantRange &CR, + bool isSigned) const { assert(getType() == CR.getType() && "ConstantRange types don't agree!"); // Handle common special cases if (isEmptySet() || CR.isFullSet()) return *this; if (isFullSet() || CR.isEmptySet()) return CR; - if (!isWrappedSet()) { - if (!CR.isWrappedSet()) { - ConstantIntegral *L = Max(Lower, CR.Lower); - ConstantIntegral *U = Min(Upper, CR.Upper); + if (!isWrappedSet(isSigned)) { + if (!CR.isWrappedSet(isSigned)) { + ConstantIntegral *L = Max(Lower, CR.Lower, isSigned); + ConstantIntegral *U = Min(Upper, CR.Upper, isSigned); - if (LT(L, U)) // If range isn't empty... + if (LT(L, U, isSigned)) // If range isn't empty... return ConstantRange(L, U); else return ConstantRange(getType(), false); // Otherwise, return empty set } else - return intersect1Wrapped(CR, *this); + return intersect1Wrapped(CR, *this, isSigned); } else { // We know "this" is wrapped... - if (!CR.isWrappedSet()) - return intersect1Wrapped(*this, CR); + if (!CR.isWrappedSet(isSigned)) + return intersect1Wrapped(*this, CR, isSigned); else { // Both ranges are wrapped... - ConstantIntegral *L = Max(Lower, CR.Lower); - ConstantIntegral *U = Min(Upper, CR.Upper); + ConstantIntegral *L = Max(Lower, CR.Lower, isSigned); + ConstantIntegral *U = Min(Upper, CR.Upper, isSigned); return ConstantRange(L, U); } } @@ -315,7 +320,8 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { /// 15), which includes 9, 10, and 11, which were not included in either set /// before. /// -ConstantRange ConstantRange::unionWith(const ConstantRange &CR) const { +ConstantRange ConstantRange::unionWith(const ConstantRange &CR, + bool isSigned) const { assert(getType() == CR.getType() && "ConstantRange types don't agree!"); assert(0 && "Range union not implemented yet!"); @@ -325,7 +331,7 @@ ConstantRange ConstantRange::unionWith(const ConstantRange &CR) const { /// zeroExtend - Return a new range in the specified integer type, which must /// be strictly larger than the current type. The returned range will -/// correspond to the possible range of values if the source range had been +/// correspond to the possible range of values as if the source range had been /// zero extended. ConstantRange ConstantRange::zeroExtend(const Type *Ty) const { assert(getLower()->getType()->getPrimitiveSize() < Ty->getPrimitiveSize() && @@ -346,7 +352,7 @@ ConstantRange ConstantRange::zeroExtend(const Type *Ty) const { /// truncate - Return a new range in the specified integer type, which must be /// strictly smaller than the current type. The returned range will -/// correspond to the possible range of values if the source range had been +/// correspond to the possible range of values as if the source range had been /// truncated to the specified type. ConstantRange ConstantRange::truncate(const Type *Ty) const { assert(getLower()->getType()->getPrimitiveSize() > Ty->getPrimitiveSize() && @@ -360,7 +366,6 @@ ConstantRange ConstantRange::truncate(const Type *Ty) const { ConstantExpr::getTrunc(getUpper(), Ty)); } - /// print - Print out the bounds to a stream... /// void ConstantRange::print(std::ostream &OS) const { diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp index 5d2841187a..805e771e54 100644 --- a/lib/Analysis/IPA/Andersens.cpp +++ b/lib/Analysis/IPA/Andersens.cpp @@ -325,7 +325,8 @@ namespace { void visitGetElementPtrInst(GetElementPtrInst &GEP); void visitPHINode(PHINode &PN); void visitCastInst(CastInst &CI); - void visitSetCondInst(SetCondInst &SCI) {} // NOOP! + void visitICmpInst(ICmpInst &ICI) {} // NOOP! + void visitFCmpInst(FCmpInst &ICI) {} // NOOP! void visitSelectInst(SelectInst &SI); void visitVAArg(VAArgInst &I); void visitInstruction(Instruction &I); @@ -778,6 +779,8 @@ void Andersens::visitInstruction(Instruction &I) { case Instruction::Shl: case Instruction::LShr: case Instruction::AShr: + case Instruction::ICmp: + case Instruction::FCmp: return; default: // Is this something we aren't handling yet? diff --git a/lib/Analysis/IPA/GlobalsModRef.cpp b/lib/Analysis/IPA/GlobalsModRef.cpp index 7c305b7a5e..e34d03bbdd 100644 --- a/lib/Analysis/IPA/GlobalsModRef.cpp +++ b/lib/Analysis/IPA/GlobalsModRef.cpp @@ -251,8 +251,8 @@ bool GlobalsModRef::AnalyzeUsesOfPointer(Value *V, } else { return true; } - } else if (SetCondInst *SCI = dyn_cast<SetCondInst>(*UI)) { - if (!isa<ConstantPointerNull>(SCI->getOperand(1))) + } else if (ICmpInst *ICI = dyn_cast<ICmpInst>(*UI)) { + if (!isa<ConstantPointerNull>(ICI->getOperand(1))) return true; // Allow comparison against null. } else if (FreeInst *F = dyn_cast<FreeInst>(*UI)) { Writers.push_back(F->getParent()->getParent()); diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index b33e414bf0..27f175058f 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/lib/Analysis/LoopInfo.cpp @@ -536,7 +536,7 @@ Instruction *Loop::getCanonicalInductionVariableIncrement() const { /// returns null. /// Value *Loop::getTripCount() const { - // Canonical loops will end with a 'setne I, V', where I is the incremented + // Canonical loops will end with a 'cmp ne I, V', where I is the incremented // canonical induction variable and V is the trip count of the loop. Instruction *Inc = getCanonicalInductionVariableIncrement(); if (Inc == 0) return 0; @@ -546,15 +546,17 @@ Value *Loop::getTripCount() const { IV->getIncomingBlock(contains(IV->getIncomingBlock(1))); if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator())) - if (BI->isConditional()) - if (SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition())) - if (SCI->getOperand(0) == Inc) + if (BI->isConditional()) { + if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) { + if (ICI->getOperand(0) == Inc) if (BI->getSuccessor(0) == getHeader()) { - if (SCI->getOpcode() == Instruction::SetNE) - return SCI->getOperand(1); - } else if (SCI->getOpcode() == Instruction::SetEQ) { - return SCI->getOperand(1); + if (ICI->getPredicate() == ICmpInst::ICMP_NE) + return ICI->getOperand(1); + } else if (ICI->getPredicate() == ICmpInst::ICMP_EQ) { + return ICI->getOperand(1); } + } + } return 0; } diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index bc1f9a0d30..fcfab9e1c9 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -177,8 +177,7 @@ SCEVHandle SCEVConstant::get(ConstantInt *V) { // are signless. There won't be a need to bitcast then. if (V->getType()->isSigned()) { const Type *NewTy = V->getType()->getUnsignedVersion(); - V = cast<ConstantInt>( - ConstantExpr::getBitCast(V, NewTy)); + V = cast<ConstantInt>(ConstantExpr::getBitCast(V, NewTy)); } SCEVConstant *&R = (*SCEVConstants)[V]; @@ -461,15 +460,8 @@ SCEVHandle SCEVUnknown::getIntegerSCEV(int Val, const Type *Ty) { C = Constant::getNullValue(Ty); else if (Ty->isFloatingPoint()) C = ConstantFP::get(Ty, Val); - /// FIXME:Signless. when integer types are signless, just change this to: - /// else - /// C = ConstantInt::get(Ty, Val); - else if (Ty->isSigned()) + else C = ConstantInt::get(Ty, Val); - else { - C = ConstantInt::get(Ty->getSignedVersion(), Val); - C = ConstantExpr::getBitCast(C, Ty); - } return SCEVUnknown::get(C); } @@ -514,8 +506,7 @@ static SCEVHandle PartialFact(SCEVHandle V, unsigned NumSteps) { for (; NumSteps; --NumSteps) Result *= Val-(NumSteps-1); Constant *Res = ConstantInt::get(Type::ULongTy, Result); - return SCEVUnknown::get( - ConstantExpr::getTruncOrBitCast(Res, V->getType())); + return SCEVUnknown::get(ConstantExpr::getTruncOrBitCast(Res, V->getType())); } const Type *Ty = V->getType(); @@ -1162,7 +1153,7 @@ namespace { SCEVHandle ComputeLoadConstantCompareIterationCount(LoadInst *LI, Constant *RHS, const Loop *L, - unsigned SetCCOpcode); + ICmpInst::Predicate p); /// ComputeIterationCountExhaustively - If the trip is known to execute a /// constant number of times (the condition evolves only from constants), @@ -1521,17 +1512,21 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { BranchInst *ExitBr = dyn_cast<BranchInst>(ExitingBlock->getTerminator()); if (ExitBr == 0) return UnknownValue; assert(ExitBr->isConditional() && "If unconditional, it can't be in loop!"); - SetCondInst *ExitCond = dyn_cast<SetCondInst>(ExitBr->getCondition()); - if (ExitCond == 0) // Not a setcc + ICmpInst *ExitCond = dyn_cast<ICmpInst>(ExitBr->getCondition()); + + // If its not an integer comparison then compute it the hard way. + // Note that ICmpInst deals with pointer comparisons too so we must check + // the type of the operand. + if (ExitCond == 0 || !ExitCond->getOperand(0)->getType()->isIntegral()) return ComputeIterationCountExhaustively(L, ExitBr->getCondition(), ExitBr->getSuccessor(0) == ExitBlock); - // If the condition was exit on true, convert the condition to exit on false. - Instruction::BinaryOps Cond; + // If the condition was exit on true, convert the condition to exit on false + ICmpInst::Predicate Cond; if (ExitBr->getSuccessor(1) == ExitBlock) - Cond = ExitCond->getOpcode(); + Cond = ExitCond->getPredicate(); else - Cond = ExitCond->getInverseCondition(); + Cond = ExitCond->getInversePredicate(); // Handle common loops like: for (X = "string"; *X; ++X) if (LoadInst *LI = dyn_cast<LoadInst>(ExitCond->getOperand(0))) @@ -1550,12 +1545,12 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { Tmp = getSCEVAtScope(RHS, L); if (!isa<SCEVCouldNotCompute>(Tmp)) RHS = Tmp; - // At this point, we would like to compute how many iterations of the loop the - // predicate will return true for these inputs. + // At this point, we would like to compute how many iterations of the + // loop the predicate will return true for these inputs. if (isa<SCEVConstant>(LHS) && !isa<SCEVConstant>(RHS)) { // If there is a constant, force it into the RHS. std::swap(LHS, RHS); |