[llvm-commits] CVS: llvm/lib/Support/ConstantRange.cpp
Nick Lewycky
nicholas at mxc.ca
Sat Apr 7 08:41:55 PDT 2007
Changes in directory llvm/lib/Support:
ConstantRange.cpp updated: 1.42 -> 1.43
---
Log message:
Add signExtend to ConstantRange, to complement zeroExtend and truncate.
---
Diffs of the changes: (+17 -0)
ConstantRange.cpp | 17 +++++++++++++++++
1 files changed, 17 insertions(+)
Index: llvm/lib/Support/ConstantRange.cpp
diff -u llvm/lib/Support/ConstantRange.cpp:1.42 llvm/lib/Support/ConstantRange.cpp:1.43
--- llvm/lib/Support/ConstantRange.cpp:1.42 Sat Mar 31 22:47:44 2007
+++ llvm/lib/Support/ConstantRange.cpp Sat Apr 7 10:41:33 2007
@@ -346,6 +346,23 @@
return ConstantRange(L, U);
}
+/// signExtend - Return a new range in the specified integer type, which must
+/// be strictly larger than the current type. The returned range will
+/// correspond to the possible range of values as if the source range had been
+/// sign extended.
+ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {
+ unsigned SrcTySize = getBitWidth();
+ assert(SrcTySize < DstTySize && "Not a value extension");
+ if (isFullSet()) {
+ return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
+ APInt::getLowBitsSet(DstTySize, SrcTySize-1));
+ }
+
+ APInt L = Lower; L.sext(DstTySize);
+ APInt U = Upper; U.sext(DstTySize);
+ return ConstantRange(L, U);
+}
+
/// truncate - Return a new range in the specified integer type, which must be
/// strictly smaller than the current type. The returned range will
/// correspond to the possible range of values as if the source range had been
More information about the llvm-commits
mailing list