Add an isUnitValue method for comparison against 1. This just follows a
authorReid Spencer <rspencer@reidspencer.com>
Thu, 1 Mar 2007 21:50:41 +0000 (21:50 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Thu, 1 Mar 2007 21:50:41 +0000 (21:50 +0000)
common pattern with isNullValue, isAllOnesValue, etc. It also helps to
prevent things like getZExtValue() == 1, which could assert for large
bitwidths.

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

include/llvm/Constants.h

index 21d9dca7a7e808d3e99dcfc077bb547563a715c0..7257d2645a7c8259ad58b5a73f68ef99bfd8c8cc 100644 (file)
@@ -127,6 +127,13 @@ public:
     return Val == 0; 
   }
 
+  /// This is just a convenience method to make client code smaller for a 
+  /// common case.
+  /// @brief Determine if the value is one.
+  virtual bool isUnitValue() const {
+    return Val == 1;
+  }
+
   /// This function will return true iff every bit in this constant is set
   /// to true.
   /// @returns true iff this constant's bits are all set to true.