[llvm-commits] [llvm] r135249 - in /llvm/trunk: include/llvm/Constant.h include/llvm/Constants.h lib/VMCore/Constants.cpp

Chris Lattner sabre at nondot.org
Thu Jul 14 22:58:04 PDT 2011


Author: lattner
Date: Fri Jul 15 00:58:04 2011
New Revision: 135249

URL: http://llvm.org/viewvc/llvm-project?rev=135249&view=rev
Log:
add CFP::isNegative() and ConstnatInt::isNegative() methods.

Devirtualize the isNegativeZeroValue method.


Modified:
    llvm/trunk/include/llvm/Constant.h
    llvm/trunk/include/llvm/Constants.h
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/include/llvm/Constant.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constant.h?rev=135249&r1=135248&r2=135249&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constant.h (original)
+++ llvm/trunk/include/llvm/Constant.h Fri Jul 15 00:58:04 2011
@@ -54,7 +54,7 @@
 
   /// 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.

Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=135249&r1=135248&r2=135249&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Fri Jul 15 00:58:04 2011
@@ -156,6 +156,8 @@
   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 @@
   
   /// 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(); }
 

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=135249&r1=135248&r2=135249&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Fri Jul 15 00:58:04 2011
@@ -40,6 +40,15 @@
 //                              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()) {





More information about the llvm-commits mailing list