diff options
author | Eric Christopher <echristo@apple.com> | 2012-07-15 00:23:36 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2012-07-15 00:23:36 +0000 |
commit | 5449a1db40b75586c1daf70a14396295e7b3fe24 (patch) | |
tree | 2e9b9b583a6e0b661cd3754f294dc6a6cfbc1ebd /include/llvm/ADT/APInt.h | |
parent | 65f489fd7d876c3e624938cd46d2475c7f365a8a (diff) | |
download | llvm-5449a1db40b75586c1daf70a14396295e7b3fe24.tar.gz llvm-5449a1db40b75586c1daf70a14396295e7b3fe24.tar.bz2 llvm-5449a1db40b75586c1daf70a14396295e7b3fe24.tar.xz |
Move IsSameValue from clang's ASTImporter to be methods on the
APInt/APSInt classes.
Part of rdar://11875995
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160223 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/APInt.h')
-rw-r--r-- | include/llvm/ADT/APInt.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 75c1d576a6..cacfb5d4c4 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -511,6 +511,18 @@ public: return getAllOnesValue(numBits).lshr(numBits - loBitsSet); } + /// \brief Determine if two APInts have the same value, after zero-extending + /// one of them (if needed!) to ensure that the bit-widths match. + static bool isSameValue(const APInt &I1, const APInt &I2) { + if (I1.getBitWidth() == I2.getBitWidth()) + return I1 == I2; + + if (I1.getBitWidth() > I2.getBitWidth()) + return I1 == I2.zext(I1.getBitWidth()); + + return I1.zext(I2.getBitWidth()) == I2; + } + /// \brief Overload to compute a hash_code for an APInt value. friend hash_code hash_value(const APInt &Arg); |