diff options
author | Zhou Sheng <zhousheng00@gmail.com> | 2007-03-11 07:16:10 +0000 |
---|---|---|
committer | Zhou Sheng <zhousheng00@gmail.com> | 2007-03-11 07:16:10 +0000 |
commit | 8db6a445e679817d9972c44d2bc366732388c7b0 (patch) | |
tree | 9139d8dde5a971e974af9f1fe94a4d3ab9d935e6 | |
parent | e677a0b0993210385e53bdd435446d6b496d272f (diff) |
Add getSignBit() and operator<<= into APInt for convenience.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35059 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/APInt.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 80221f2880..5c8e0ee553 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -386,6 +386,14 @@ public: /// @brief Left-shift function. APInt shl(uint32_t shiftAmt) const; + /// Left-shift this APInt by shiftAmt and + /// assigns the result to this APInt. + /// @brief Lef-shift assignment function. + inline APInt& operator<<=(uint32_t shiftAmt) { + *this = shl(shiftAmt); + return *this; + } + /// Signed divide this APInt by APInt RHS. /// @brief Signed division function for APInt. inline APInt sdiv(const APInt& RHS) const { @@ -464,6 +472,14 @@ public: /// @brief Toggles a given bit to its opposite value. APInt& flip(uint32_t bitPosition); + inline void setWordToValue(uint32_t idx, uint64_t Val) { + assert(idx < getNumWords() && "Invalid word array index"); + if (isSingleWord()) + VAL = Val; + else + pVal[idx] = Val; + } + /// This function returns the number of active bits which is defined as the /// bit width minus the number of leading zeros. This is used in several /// computations to see how "wide" the value is. @@ -551,6 +567,13 @@ public: return APInt(numBits, 0).set(numBits - 1); } + /// getSignBit - This is just a wrapper function of getSignedMinValue(), and + /// it helps code readability when we want to get a SignBit. + /// @brief Get the SignBit for a specific bit width. + inline static APInt getSignBit(uint32_t BitWidth) { + return getSignedMinValue(BitWidth); + } + /// @returns the all-ones value for an APInt of the specified bit-width. /// @brief Get the all-ones value. static APInt getAllOnesValue(uint32_t numBits) { |