summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorZhou Sheng <zhousheng00@gmail.com>2007-03-11 07:16:10 +0000
committerZhou Sheng <zhousheng00@gmail.com>2007-03-11 07:16:10 +0000
commite8e618a6ffcd2f04b4def681e1118cb8341e2e87 (patch)
tree0d31369a4d535fbaf594b87a4c8941b136fa2f0e /llvm
parentd9bd0bc3e2eb0a54903702647029735eacbdf009 (diff)
downloadbcm5719-llvm-e8e618a6ffcd2f04b4def681e1118cb8341e2e87.tar.gz
bcm5719-llvm-e8e618a6ffcd2f04b4def681e1118cb8341e2e87.zip
Add getSignBit() and operator<<= into APInt for convenience.
llvm-svn: 35059
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/ADT/APInt.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 80221f2880a..5c8e0ee553d 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/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) {
OpenPOWER on IntegriCloud