diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2020-09-22 15:51:25 +0300 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2020-09-22 21:37:30 +0300 |
commit | 7465da2077c2b8def7440094e15ac1199226bc25 (patch) | |
tree | f5eaea5aabfd7146e93691447fa3b045101d1e93 /llvm/lib/IR/ConstantRange.cpp | |
parent | b85395f309890bac5f2d3296ce08dc46c24ef77f (diff) | |
download | llvm-7465da2077c2b8def7440094e15ac1199226bc25.zip llvm-7465da2077c2b8def7440094e15ac1199226bc25.tar.gz llvm-7465da2077c2b8def7440094e15ac1199226bc25.tar.bz2 |
[ConstantRange] Introduce getMinSignedBits() method
Similar to the ConstantRange::getActiveBits(), and to similarly-named
methods in APInt, returns the bitwidth needed to represent
the given signed constant range
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index d213258..4b0ad1b 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -420,6 +420,14 @@ unsigned ConstantRange::getActiveBits() const { return getUnsignedMax().getActiveBits(); } +unsigned ConstantRange::getMinSignedBits() const { + if (isEmptySet()) + return 0; + + return std::max(getSignedMin().getMinSignedBits(), + getSignedMax().getMinSignedBits()); +} + 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. |