aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorJay Foad <jay.foad@amd.com>2020-09-02 16:14:58 +0100
committerJay Foad <jay.foad@amd.com>2020-09-02 21:40:31 +0100
commit099c089d4b4117fd654aa6e4dd544d7680fa80b9 (patch)
treeadfcb9c576fd926f4ca87e994131c270b0a6d4d9 /llvm/lib/Support/APInt.cpp
parenta27398a8151dc553dae85ede12f966e5b981b64b (diff)
downloadllvm-099c089d4b4117fd654aa6e4dd544d7680fa80b9.zip
llvm-099c089d4b4117fd654aa6e4dd544d7680fa80b9.tar.gz
llvm-099c089d4b4117fd654aa6e4dd544d7680fa80b9.tar.bz2
[APInt] New member function setBitVal
Differential Revision: https://reviews.llvm.org/D87033
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 9a6f93f..fc339de 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -338,8 +338,7 @@ void APInt::flipAllBitsSlowCase() {
/// Toggles a given bit to its opposite value.
void APInt::flipBit(unsigned bitPosition) {
assert(bitPosition < BitWidth && "Out of the bit-width range!");
- if ((*this)[bitPosition]) clearBit(bitPosition);
- else setBit(bitPosition);
+ setBitVal(bitPosition, !(*this)[bitPosition]);
}
void APInt::insertBits(const APInt &subBits, unsigned bitPosition) {
@@ -393,12 +392,8 @@ void APInt::insertBits(const APInt &subBits, unsigned bitPosition) {
// General case - set/clear individual bits in dst based on src.
// TODO - there is scope for optimization here, but at the moment this code
// path is barely used so prefer readability over performance.
- for (unsigned i = 0; i != subBitWidth; ++i) {
- if (subBits[i])
- setBit(bitPosition + i);
- else
- clearBit(bitPosition + i);
- }
+ for (unsigned i = 0; i != subBitWidth; ++i)
+ setBitVal(bitPosition + i, subBits[i]);
}
void APInt::insertBits(uint64_t subBits, unsigned bitPosition, unsigned numBits) {