summaryrefslogtreecommitdiff
path: root/lib/Support/ConstantRange.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2007-04-07 15:41:33 +0000
committerNick Lewycky <nicholas@mxc.ca>2007-04-07 15:41:33 +0000
commite32157c6098ee7536315e9793eed98d21bf71fd0 (patch)
tree9845f84301447c9a35a9c84b73dbf01189fc2c43 /lib/Support/ConstantRange.cpp
parent8aaa40610cb327ff4568cf839a6b2d7c18aaa89b (diff)
downloadllvm-e32157c6098ee7536315e9793eed98d21bf71fd0.tar.gz
llvm-e32157c6098ee7536315e9793eed98d21bf71fd0.tar.bz2
llvm-e32157c6098ee7536315e9793eed98d21bf71fd0.tar.xz
Add signExtend to ConstantRange, to complement zeroExtend and truncate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35733 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/ConstantRange.cpp')
-rw-r--r--lib/Support/ConstantRange.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index dd3e44e4e9..79a85b80d7 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -346,6 +346,23 @@ ConstantRange ConstantRange::zeroExtend(uint32_t DstTySize) const {
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