forked from OSchip/llvm-project
For PR950:
Remove the getMaxValue and getMinValue functions from ConstantIntegral. They don't make sense for a signless type. Also, for isMaxValue and isMinValue, have the caller provided the signedness rather than obtaining it from the constant's type. llvm-svn: 32287
This commit is contained in:
parent
b95504d8f5
commit
e51700983a
|
@ -75,14 +75,14 @@ public:
|
||||||
/// constant's type.
|
/// constant's type.
|
||||||
/// @returns true if the constant's value is maximal.
|
/// @returns true if the constant's value is maximal.
|
||||||
/// @brief Determine if the value is maximal.
|
/// @brief Determine if the value is maximal.
|
||||||
virtual bool isMaxValue() const = 0;
|
virtual bool isMaxValue(bool isSigned) const = 0;
|
||||||
|
|
||||||
/// This function is implemented by subclasses and will return true iff this
|
/// This function is implemented by subclasses and will return true iff this
|
||||||
/// constant represents the smallest value that may be represented by this
|
/// constant represents the smallest value that may be represented by this
|
||||||
/// constant's type.
|
/// constant's type.
|
||||||
/// @returns true if the constant's value is minimal
|
/// @returns true if the constant's value is minimal
|
||||||
/// @brief Determine if the value is minimal.
|
/// @brief Determine if the value is minimal.
|
||||||
virtual bool isMinValue() const = 0;
|
virtual bool isMinValue(bool isSigned) const = 0;
|
||||||
|
|
||||||
/// This function is implemented by subclasses and will return true iff every
|
/// This function is implemented by subclasses and will return true iff every
|
||||||
/// bit in this constant is set to true.
|
/// bit in this constant is set to true.
|
||||||
|
@ -90,14 +90,6 @@ public:
|
||||||
/// @brief Determine if the value is all ones.
|
/// @brief Determine if the value is all ones.
|
||||||
virtual bool isAllOnesValue() const = 0;
|
virtual bool isAllOnesValue() const = 0;
|
||||||
|
|
||||||
/// @returns the largest value for an integer constant of the given type
|
|
||||||
/// @brief Get the maximal value
|
|
||||||
static ConstantIntegral *getMaxValue(const Type *Ty);
|
|
||||||
|
|
||||||
/// @returns the smallest value for an integer constant of the given type
|
|
||||||
/// @brief Get the minimal value
|
|
||||||
static ConstantIntegral *getMinValue(const Type *Ty);
|
|
||||||
|
|
||||||
/// @returns the value for an integer constant of the given type that has all
|
/// @returns the value for an integer constant of the given type that has all
|
||||||
/// its bits set to true.
|
/// its bits set to true.
|
||||||
/// @brief Get the all ones value
|
/// @brief Get the all ones value
|
||||||
|
@ -147,8 +139,8 @@ public:
|
||||||
/// @see ConstantIntegral for details
|
/// @see ConstantIntegral for details
|
||||||
/// @brief Implement overrides
|
/// @brief Implement overrides
|
||||||
virtual bool isNullValue() const { return getValue() == false; }
|
virtual bool isNullValue() const { return getValue() == false; }
|
||||||
virtual bool isMaxValue() const { return getValue() == true; }
|
virtual bool isMaxValue(bool isSigned) const { return getValue() == true; }
|
||||||
virtual bool isMinValue() const { return getValue() == false; }
|
virtual bool isMinValue(bool isSigned) const { return getValue() == false; }
|
||||||
virtual bool isAllOnesValue() const { return getValue() == true; }
|
virtual bool isAllOnesValue() const { return getValue() == true; }
|
||||||
|
|
||||||
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
|
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
|
||||||
|
@ -208,8 +200,8 @@ public:
|
||||||
/// by this type.
|
/// by this type.
|
||||||
/// @see ConstantIntegeral
|
/// @see ConstantIntegeral
|
||||||
/// @brief Override implementation
|
/// @brief Override implementation
|
||||||
virtual bool isMaxValue() const {
|
virtual bool isMaxValue(bool isSigned) const {
|
||||||
if (getType()->isSigned()) {
|
if (isSigned) {
|
||||||
int64_t V = getSExtValue();
|
int64_t V = getSExtValue();
|
||||||
if (V < 0) return false; // Be careful about wrap-around on 'long's
|
if (V < 0) return false; // Be careful about wrap-around on 'long's
|
||||||
++V;
|
++V;
|
||||||
|
@ -222,8 +214,8 @@ public:
|
||||||
/// this type.
|
/// this type.
|
||||||
/// @see ConstantIntegral
|
/// @see ConstantIntegral
|
||||||
/// @brief Override implementation
|
/// @brief Override implementation
|
||||||
virtual bool isMinValue() const {
|
virtual bool isMinValue(bool isSigned) const {
|
||||||
if (getType()->isSigned()) {
|
if (isSigned) {
|
||||||
int64_t V = getSExtValue();
|
int64_t V = getSExtValue();
|
||||||
if (V > 0) return false; // Be careful about wrap-around on 'long's
|
if (V > 0) return false; // Be careful about wrap-around on 'long's
|
||||||
--V;
|
--V;
|
||||||
|
|
|
@ -152,53 +152,6 @@ Constant *Constant::getNullValue(const Type *Ty) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static constructor to create the maximum constant of an integral type...
|
|
||||||
ConstantIntegral *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 getAllOnesValue(Ty);
|
|
||||||
|
|
||||||
default: return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Static constructor to create the minimum constant for an integral type...
|
|
||||||
ConstantIntegral *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 constructor to create an integral constant with all bits set
|
// Static constructor to create an integral constant with all bits set
|
||||||
ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) {
|
ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) {
|
||||||
|
|
Loading…
Reference in New Issue