summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-07-15 05:58:04 +0000
committerChris Lattner <sabre@nondot.org>2011-07-15 05:58:04 +0000
commitb447387726ff94ddb2a23408f39e22714c42f79b (patch)
tree0025f862364fb3bd08c5de1a9d415280bef1e950
parentba3ddf391f5149b8fca073adc3cbca361353929c (diff)
downloadllvm-b447387726ff94ddb2a23408f39e22714c42f79b.tar.gz
llvm-b447387726ff94ddb2a23408f39e22714c42f79b.tar.bz2
llvm-b447387726ff94ddb2a23408f39e22714c42f79b.tar.xz
add CFP::isNegative() and ConstnatInt::isNegative() methods.
Devirtualize the isNegativeZeroValue method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135249 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Constant.h2
-rw-r--r--include/llvm/Constants.h13
-rw-r--r--lib/VMCore/Constants.cpp9
3 files changed, 16 insertions, 8 deletions
diff --git a/include/llvm/Constant.h b/include/llvm/Constant.h
index 5f32ce0ac5..95da9fc20c 100644
--- a/include/llvm/Constant.h
+++ b/include/llvm/Constant.h
@@ -54,7 +54,7 @@ public:
/// isNegativeZeroValue - Return true if the value is what would be returned
/// by getZeroValueForNegation.
- virtual bool isNegativeZeroValue() const { return isNullValue(); }
+ bool isNegativeZeroValue() const;
/// canTrap - Return true if evaluation of this constant could trap. This is
/// true for things like constant expressions that could divide by zero.
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 462d7f01b0..e6ead6d96d 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -156,6 +156,8 @@ public:
virtual bool isNullValue() const {
return Val == 0;
}
+
+ bool isNegative() const { return Val.isNegative(); }
/// This is just a convenience method to make client code smaller for a
/// common code. It also correctly performs the comparison without the
@@ -263,22 +265,19 @@ public:
/// isValueValidForType - return true if Ty is big enough to represent V.
static bool isValueValidForType(const Type *Ty, const APFloat &V);
- inline const APFloat& getValueAPF() const { return Val; }
+ inline const APFloat &getValueAPF() const { return Val; }
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue. For ConstantFP, this is +0.0, but not -0.0. To handle the
/// two the same, use isZero().
virtual bool isNullValue() const;
- /// isNegativeZeroValue - Return true if the value is what would be returned
- /// by getZeroValueForNegation.
- virtual bool isNegativeZeroValue() const {
- return Val.isZero() && Val.isNegative();
- }
-
/// isZero - Return true if the value is positive or negative zero.
bool isZero() const { return Val.isZero(); }
+ /// isNegative - Return true if the sign bit is set.
+ bool isNegative() const { return Val.isNegative(); }
+
/// isNaN - Return true if the value is a NaN.
bool isNaN() const { return Val.isNaN(); }
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index c043a8a4e7..019a590f41 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -40,6 +40,15 @@ using namespace llvm;
// Constant Class
//===----------------------------------------------------------------------===//
+bool Constant::isNegativeZeroValue() const {
+ // Floating point values have an explicit -0.0 value.
+ if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
+ return CFP->isZero() && CFP->isNegative();
+
+ // Otherwise, just use +0.0.
+ return isNullValue();
+}
+
// Constructor to create a '0' constant of arbitrary type...
Constant *Constant::getNullValue(const Type *Ty) {
switch (Ty->getTypeID()) {