add CFP::isNegative() and ConstnatInt::isNegative() methods.
authorChris Lattner <sabre@nondot.org>
Fri, 15 Jul 2011 05:58:04 +0000 (05:58 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 15 Jul 2011 05:58:04 +0000 (05:58 +0000)
Devirtualize the isNegativeZeroValue method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135249 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Constant.h
include/llvm/Constants.h
lib/VMCore/Constants.cpp

index 5f32ce0ac5e2cd7532820c08b2b08e0bce690138..95da9fc20c327357818dcf40896d54cb41601183 100644 (file)
@@ -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.
index 462d7f01b0a187e8a3a4fc1d57cb8ccf61a8958f..e6ead6d96d22e59b5e371c36a39347fedf240f0b 100644 (file)
@@ -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 APFloatgetValueAPF() 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(); }
 
index c043a8a4e7a9f45c196cf4a327f831521ed05b0d..019a590f412d9c23675aec5a092080f64b6c3118 100644 (file)
@@ -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()) {