]> granicus.if.org Git - llvm/commitdiff
[APInt] Add a isOneValue method that can determine if a number is 1 by only using...
authorCraig Topper <craig.topper@gmail.com>
Wed, 7 Jun 2017 00:57:57 +0000 (00:57 +0000)
committerCraig Topper <craig.topper@gmail.com>
Wed, 7 Jun 2017 00:57:57 +0000 (00:57 +0000)
Previously you would have to use operator==(uint64_t) which does the getActiveBits call and a uint64_t comparison. But we can get all we need to know from the getActiveBits call.

This method will be used in another commit.

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

include/llvm/ADT/APInt.h

index fe75e25bd8d297fe89888a7df3d0b2dba4392eb6..b45f0601b0a0a0ff7732eaddcff4efa49961416d 100644 (file)
@@ -392,6 +392,12 @@ public:
   /// not.
   bool isNullValue() const { return !*this; }
 
+  /// \brief Determine if all bits are clear
+  ///
+  /// This checks to see if the value has all bits of the APInt are clear or
+  /// not.
+  bool isOneValue() const { return getActiveBits() == 1; }
+
   /// \brief Determine if this is the largest unsigned value.
   ///
   /// This checks to see if the value of this APInt is the maximum unsigned