diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2007-03-10 15:54:12 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2007-03-10 15:54:12 +0000 |
commit | e455937fae575838ab1d39a4957a746a604e2369 (patch) | |
tree | 51f91442ac21561c87b12a0191211d7126addc59 /llvm/lib/Support | |
parent | e9b81f5366fe631a91147473d3b9503be5ea94fe (diff) | |
download | bcm5719-llvm-e455937fae575838ab1d39a4957a746a604e2369.tar.gz bcm5719-llvm-e455937fae575838ab1d39a4957a746a604e2369.zip |
Add getter methods for the extremes of a ConstantRange.
llvm-svn: 35056
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/ConstantRange.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/llvm/lib/Support/ConstantRange.cpp b/llvm/lib/Support/ConstantRange.cpp index 410c351890c..becb8b61f78 100644 --- a/llvm/lib/Support/ConstantRange.cpp +++ b/llvm/lib/Support/ConstantRange.cpp @@ -84,6 +84,70 @@ APInt ConstantRange::getSetSize() const { return Upper - Lower; } +/// getUnsignedMax - Return the largest unsigned value contained in the +/// ConstantRange. +/// +APInt ConstantRange::getUnsignedMax() const { + if (isFullSet() || isWrappedSet()) + return APInt::getMaxValue(getBitWidth()); + else + return getUpper() - 1; +} + +/// getUnsignedMin - Return the smallest unsigned value contained in the +/// ConstantRange. +/// +APInt ConstantRange::getUnsignedMin() const { + if (isFullSet() || (isWrappedSet() && getUpper() != 0)) + return APInt::getMinValue(getBitWidth()); + else + return getLower(); +} + +/// getSignedMax - Return the largest signed value contained in the +/// ConstantRange. +/// +APInt ConstantRange::getSignedMax() const { + APInt SignedMax = APInt::getSignedMaxValue(getBitWidth()); + if (!isWrappedSet()) { + if (getLower().slt(getUpper() - 1)) + return getUpper() - 1; + else + return SignedMax; + } else { + if ((getUpper() - 1).slt(getLower())) { + if (getLower() != SignedMax) + return SignedMax; + else + return getUpper() - 1; + } else { + return getUpper() - 1; + } + } +} + +/// getSignedMin - Return the smallest signed value contained in the +/// ConstantRange. +/// +APInt ConstantRange::getSignedMin() const { + APInt SignedMin = APInt::getSignedMinValue(getBitWidth()); + if (!isWrappedSet()) { + if (getLower().slt(getUpper() - 1)) + return getLower(); + else + return SignedMin; + } else { + if ((getUpper() - 1).slt(getLower())) { + if (getUpper() != SignedMin) + return SignedMin; + else + return getLower(); + } else { + return getLower(); + } + } +} + /// contains - Return true if the specified value is in the set. /// bool ConstantRange::contains(const APInt &V) const { |