diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-06 20:45:15 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-06 20:45:15 +0000 |
commit | c6bf4bfc351c11b49e8f0d5df010f40877646e63 (patch) | |
tree | ac2cb17a83188ad0dd51f8a28a4aab877e58d6ee /lib/Analysis/ConstantRange.cpp | |
parent | 62700f250fc23d02a1c9350586ae803a430f0878 (diff) |
Adjust to new ConstantIntegral interface for Max/Min tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32289 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ConstantRange.cpp')
-rw-r--r-- | lib/Analysis/ConstantRange.cpp | 66 |
1 files changed, 56 insertions, 10 deletions
diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp index 309edb3f50..1f1a1b5757 100644 --- a/lib/Analysis/ConstantRange.cpp +++ b/lib/Analysis/ConstantRange.cpp @@ -29,6 +29,52 @@ #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 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 *Next(ConstantIntegral *CI) { if (ConstantBool *CB = dyn_cast<ConstantBool>(CI)) return ConstantBool::get(!CB->getValue()); @@ -65,9 +111,9 @@ ConstantRange::ConstantRange(const Type *Ty, bool Full) { assert(Ty->isIntegral() && "Cannot make constant range of non-integral type!"); if (Full) - Lower = Upper = ConstantIntegral::getMaxValue(Ty); + Lower = Upper = getMaxValue(Ty); else - Lower = Upper = ConstantIntegral::getMinValue(Ty); + Lower = Upper = getMinValue(Ty); } /// Initialize a range to hold the single specified value. @@ -86,8 +132,8 @@ ConstantRange::ConstantRange(Constant *L, Constant *U) "Incompatible types for ConstantRange!"); // Make sure that if L & U are equal that they are either Min or Max... - assert((L != U || (L == ConstantIntegral::getMaxValue(L->getType()) || - L == ConstantIntegral::getMinValue(L->getType()))) && + assert((L != U || (L == getMaxValue(L->getType()) || + L == getMinValue(L->getType()))) && "Lower == Upper, but they aren't min or max for type!"); } @@ -99,20 +145,20 @@ ConstantRange::ConstantRange(unsigned SetCCOpcode, ConstantIntegral *C) { case Instruction::SetEQ: Lower = C; Upper = Next(C); return; case Instruction::SetNE: Upper = C; Lower = Next(C); return; case Instruction::SetLT: - Lower = ConstantIntegral::getMinValue(C->getType()); + Lower = getMinValue(C->getType()); Upper = C; return; case Instruction::SetGT: Lower = Next(C); - Upper = ConstantIntegral::getMinValue(C->getType()); // Min = Next(Max) + Upper = getMinValue(C->getType()); // Min = Next(Max) return; case Instruction::SetLE: - Lower = ConstantIntegral::getMinValue(C->getType()); + Lower = getMinValue(C->getType()); Upper = Next(C); return; case Instruction::SetGE: Lower = C; - Upper = ConstantIntegral::getMinValue(C->getType()); // Min = Next(Max) + Upper = getMinValue(C->getType()); // Min = Next(Max) return; } } @@ -124,13 +170,13 @@ const Type *ConstantRange::getType() const { return Lower->getType(); } /// isFullSet - Return true if this set contains all of the elements possible /// for this data-type bool ConstantRange::isFullSet() const { - return Lower == Upper && Lower == ConstantIntegral::getMaxValue(getType()); + return Lower == Upper && Lower == getMaxValue(getType()); } /// isEmptySet - Return true if this set contains no members. /// bool ConstantRange::isEmptySet() const { - return Lower == Upper && Lower == ConstantIntegral::getMinValue(getType()); + return Lower == Upper && Lower == getMinValue(getType()); } /// isWrappedSet - Return true if this set wraps around the top of the range, |