From c6bf4bfc351c11b49e8f0d5df010f40877646e63 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Wed, 6 Dec 2006 20:45:15 +0000 Subject: [PATCH] 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 --- lib/Analysis/ConstantRange.cpp | 66 +++++++++++++++++++++++++++----- lib/Support/ConstantRange.cpp | 66 +++++++++++++++++++++++++++----- lib/Target/CBackend/CBackend.cpp | 2 +- lib/Target/CBackend/Writer.cpp | 2 +- 4 files changed, 114 insertions(+), 22 deletions(-) diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp index 309edb3f50b..1f1a1b5757f 100644 --- a/lib/Analysis/ConstantRange.cpp +++ b/lib/Analysis/ConstantRange.cpp @@ -29,6 +29,52 @@ #include 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(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, diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp index 309edb3f50b..1f1a1b5757f 100644 --- a/lib/Support/ConstantRange.cpp +++ b/lib/Support/ConstantRange.cpp @@ -29,6 +29,52 @@ #include 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(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, diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 6d83aeb85db..53adc49f8e9 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -753,7 +753,7 @@ void CWriter::printConstant(Constant *CPV) { break; case Type::LongTyID: - if (cast(CPV)->isMinValue()) + if (cast(CPV)->isMinValue(CPV->getType()->isSigned())) Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)"; else Out << cast(CPV)->getSExtValue() << "ll"; diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 6d83aeb85db..53adc49f8e9 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -753,7 +753,7 @@ void CWriter::printConstant(Constant *CPV) { break; case Type::LongTyID: - if (cast(CPV)->isMinValue()) + if (cast(CPV)->isMinValue(CPV->getType()->isSigned())) Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)"; else Out << cast(CPV)->getSExtValue() << "ll"; -- 2.34.1