aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2020-09-22 15:17:24 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2020-09-22 21:37:29 +0300
commit2ed9c4c70bbb36fa12d48a73abc2d89c0af80060 (patch)
tree393aedd22222ea26e47866d085c0d9cfa38c6615 /llvm/lib/IR/ConstantRange.cpp
parentb38d897e802664034c7e6e4654328256ed370a61 (diff)
downloadllvm-2ed9c4c70bbb36fa12d48a73abc2d89c0af80060.zip
llvm-2ed9c4c70bbb36fa12d48a73abc2d89c0af80060.tar.gz
llvm-2ed9c4c70bbb36fa12d48a73abc2d89c0af80060.tar.bz2
[ConstantRange] Introduce getActiveBits() method
Much like APInt::getActiveBits(), computes how many bits are needed to be able to represent every value in this constant range, treating the values as unsigned.
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 7b8dd66..d213258 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -413,6 +413,13 @@ bool ConstantRange::contains(const ConstantRange &Other) const {
return Other.getUpper().ule(Upper) && Lower.ule(Other.getLower());
}
+unsigned ConstantRange::getActiveBits() const {
+ if (isEmptySet())
+ return 0;
+
+ return getUnsignedMax().getActiveBits();
+}
+
ConstantRange ConstantRange::subtract(const APInt &Val) const {
assert(Val.getBitWidth() == getBitWidth() && "Wrong bit width");
// If the set is empty or full, don't modify the endpoints.