[llvm-commits] [llvm] r110504 - in /llvm/trunk: include/llvm/Support/ConstantRange.h lib/Support/ConstantRange.cpp unittests/Support/ConstantRangeTest.cpp
Owen Anderson
resistor at mac.com
Fri Aug 6 22:47:46 PDT 2010
Author: resistor
Date: Sat Aug 7 00:47:46 2010
New Revision: 110504
URL: http://llvm.org/viewvc/llvm-project?rev=110504&view=rev
Log:
Add an inverse() method to ConstantRange.
Modified:
llvm/trunk/include/llvm/Support/ConstantRange.h
llvm/trunk/lib/Support/ConstantRange.cpp
llvm/trunk/unittests/Support/ConstantRangeTest.cpp
Modified: llvm/trunk/include/llvm/Support/ConstantRange.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ConstantRange.h?rev=110504&r1=110503&r2=110504&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ConstantRange.h (original)
+++ llvm/trunk/include/llvm/Support/ConstantRange.h Sat Aug 7 00:47:46 2010
@@ -232,6 +232,9 @@
/// 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;
Modified: llvm/trunk/lib/Support/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ConstantRange.cpp?rev=110504&r1=110503&r2=110504&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ConstantRange.cpp (original)
+++ llvm/trunk/lib/Support/ConstantRange.cpp Sat Aug 7 00:47:46 2010
@@ -655,6 +655,17 @@
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 {
Modified: llvm/trunk/unittests/Support/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ConstantRangeTest.cpp?rev=110504&r1=110503&r2=110504&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ConstantRangeTest.cpp (original)
+++ llvm/trunk/unittests/Support/ConstantRangeTest.cpp Sat Aug 7 00:47:46 2010
@@ -33,6 +33,7 @@
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 @@
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 @@
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());
More information about the llvm-commits
mailing list