From 5c14a1bcb006c09ab6a06f96e09e62f6dc168a27 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Wed, 6 Dec 2006 20:30:17 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32287 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Constants.h | 24 +++++++------------- lib/VMCore/Constants.cpp | 47 ---------------------------------------- 2 files changed, 8 insertions(+), 63 deletions(-) diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index b4db582ea63..8c31ba32759 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -75,14 +75,14 @@ public: /// constant's type. /// @returns true if the constant's 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 /// constant represents the smallest value that may be represented by this /// constant's type. /// @returns true if the constant's 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 /// bit in this constant is set to true. @@ -90,14 +90,6 @@ public: /// @brief Determine if the value is all ones. 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 /// its bits set to true. /// @brief Get the all ones value @@ -147,8 +139,8 @@ public: /// @see ConstantIntegral for details /// @brief Implement overrides virtual bool isNullValue() const { return getValue() == false; } - virtual bool isMaxValue() const { return getValue() == true; } - virtual bool isMinValue() const { return getValue() == false; } + virtual bool isMaxValue(bool isSigned) const { return getValue() == true; } + virtual bool isMinValue(bool isSigned) const { return getValue() == false; } virtual bool isAllOnesValue() const { return getValue() == true; } /// @brief Methods to support type inquiry through isa, cast, and dyn_cast: @@ -208,8 +200,8 @@ public: /// by this type. /// @see ConstantIntegeral /// @brief Override implementation - virtual bool isMaxValue() const { - if (getType()->isSigned()) { + virtual bool isMaxValue(bool isSigned) const { + if (isSigned) { int64_t V = getSExtValue(); if (V < 0) return false; // Be careful about wrap-around on 'long's ++V; @@ -222,8 +214,8 @@ public: /// this type. /// @see ConstantIntegral /// @brief Override implementation - virtual bool isMinValue() const { - if (getType()->isSigned()) { + virtual bool isMinValue(bool isSigned) const { + if (isSigned) { int64_t V = getSExtValue(); if (V > 0) return false; // Be careful about wrap-around on 'long's --V; diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index f52504298e1..f9271178a4d 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -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 ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) { -- 2.34.1