aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-08-07 05:47:46 +0000
committerOwen Anderson <resistor@mac.com>2010-08-07 05:47:46 +0000
commitc9723388045268d8275883fd53997f7a48467112 (patch)
treedb9e2c980a9a3b752b6bb1e93e4cdd3877cbeefc
parentb7294f50051dcb3ac9619514a0e8c18acfa15b22 (diff)
downloadexternal_llvm-c9723388045268d8275883fd53997f7a48467112.zip
external_llvm-c9723388045268d8275883fd53997f7a48467112.tar.gz
external_llvm-c9723388045268d8275883fd53997f7a48467112.tar.bz2
Add an inverse() method to ConstantRange.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110504 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/ConstantRange.h3
-rw-r--r--lib/Support/ConstantRange.cpp11
-rw-r--r--unittests/Support/ConstantRangeTest.cpp3
3 files changed, 17 insertions, 0 deletions
diff --git a/include/llvm/Support/ConstantRange.h b/include/llvm/Support/ConstantRange.h
index d767bd3..c3a6dd0 100644
--- a/include/llvm/Support/ConstantRange.h
+++ b/include/llvm/Support/ConstantRange.h
@@ -232,6 +232,9 @@ public:
/// from a logical right shift of a value in this range by the Amount value.
ConstantRange lshr(const ConstantRange &Amount) const;
+ /// inverse - Return a new range that is the logical not of the current set.
+ ConstantRange inverse() const;
+
/// print - Print out the bounds to a stream...
///
void print(raw_ostream &OS) const;
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index fb04428..26a23ef 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -655,6 +655,17 @@ ConstantRange::lshr(const ConstantRange &Amount) const {
return ConstantRange(min, max);
}
+ConstantRange ConstantRange::inverse() const {
+ if (isFullSet()) {
+ return ConstantRange(APInt::getNullValue(Lower.getBitWidth()),
+ APInt::getNullValue(Lower.getBitWidth()));
+ } else if (isEmptySet()) {
+ return ConstantRange(APInt::getAllOnesValue(Lower.getBitWidth()),
+ APInt::getAllOnesValue(Lower.getBitWidth()));
+ }
+ return ConstantRange(Upper, Lower);
+}
+
/// print - Print out the bounds to a stream...
///
void ConstantRange::print(raw_ostream &OS) const {
diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp
index 6b8d01d..fc1f5b8 100644
--- a/unittests/Support/ConstantRangeTest.cpp
+++ b/unittests/Support/ConstantRangeTest.cpp
@@ -33,6 +33,7 @@ ConstantRange ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa));
TEST_F(ConstantRangeTest, Basics) {
EXPECT_TRUE(Full.isFullSet());
EXPECT_FALSE(Full.isEmptySet());
+ EXPECT_TRUE(Full.inverse().isEmptySet());
EXPECT_FALSE(Full.isWrappedSet());
EXPECT_TRUE(Full.contains(APInt(16, 0x0)));
EXPECT_TRUE(Full.contains(APInt(16, 0x9)));
@@ -42,6 +43,7 @@ TEST_F(ConstantRangeTest, Basics) {
EXPECT_FALSE(Empty.isFullSet());
EXPECT_TRUE(Empty.isEmptySet());
+ EXPECT_TRUE(Empty.inverse().isFullSet());
EXPECT_FALSE(Empty.isWrappedSet());
EXPECT_FALSE(Empty.contains(APInt(16, 0x0)));
EXPECT_FALSE(Empty.contains(APInt(16, 0x9)));
@@ -57,6 +59,7 @@ TEST_F(ConstantRangeTest, Basics) {
EXPECT_TRUE(One.contains(APInt(16, 0xa)));
EXPECT_FALSE(One.contains(APInt(16, 0xaa9)));
EXPECT_FALSE(One.contains(APInt(16, 0xaaa)));
+ EXPECT_FALSE(One.inverse().contains(APInt(16, 0xa)));
EXPECT_FALSE(Some.isFullSet());
EXPECT_FALSE(Some.isEmptySet());