summaryrefslogtreecommitdiff
path: root/include/llvm/Support/KnownBits.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Support/KnownBits.h')
-rw-r--r--include/llvm/Support/KnownBits.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/include/llvm/Support/KnownBits.h b/include/llvm/Support/KnownBits.h
index 3d38cf878538..2c77d40559b9 100644
--- a/include/llvm/Support/KnownBits.h
+++ b/include/llvm/Support/KnownBits.h
@@ -133,6 +133,66 @@ public:
KnownBits zextOrTrunc(unsigned BitWidth) {
return KnownBits(Zero.zextOrTrunc(BitWidth), One.zextOrTrunc(BitWidth));
}
+
+ /// Returns the minimum number of trailing zero bits.
+ unsigned countMinTrailingZeros() const {
+ return Zero.countTrailingOnes();
+ }
+
+ /// Returns the minimum number of trailing one bits.
+ unsigned countMinTrailingOnes() const {
+ return One.countTrailingOnes();
+ }
+
+ /// Returns the minimum number of leading zero bits.
+ unsigned countMinLeadingZeros() const {
+ return Zero.countLeadingOnes();
+ }
+
+ /// Returns the minimum number of leading one bits.
+ unsigned countMinLeadingOnes() const {
+ return One.countLeadingOnes();
+ }
+
+ /// Returns the number of times the sign bit is replicated into the other
+ /// bits.
+ unsigned countMinSignBits() const {
+ if (isNonNegative())
+ return countMinLeadingZeros();
+ if (isNegative())
+ return countMinLeadingOnes();
+ return 0;
+ }
+
+ /// Returns the maximum number of trailing zero bits possible.
+ unsigned countMaxTrailingZeros() const {
+ return One.countTrailingZeros();
+ }
+
+ /// Returns the maximum number of trailing one bits possible.
+ unsigned countMaxTrailingOnes() const {
+ return Zero.countTrailingZeros();
+ }
+
+ /// Returns the maximum number of leading zero bits possible.
+ unsigned countMaxLeadingZeros() const {
+ return One.countLeadingZeros();
+ }
+
+ /// Returns the maximum number of leading one bits possible.
+ unsigned countMaxLeadingOnes() const {
+ return Zero.countLeadingZeros();
+ }
+
+ /// Returns the number of bits known to be one.
+ unsigned countMinPopulation() const {
+ return One.countPopulation();
+ }
+
+ /// Returns the maximum number of bits that could be one.
+ unsigned countMaxPopulation() const {
+ return getBitWidth() - Zero.countPopulation();
+ }
};
} // end namespace llvm