summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
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
commitb89804f2465ba4da71600a7d92e038abdf411a86 (patch)
tree851750134570b115a7f5320fd143e9c19624ba86 /llvm/lib/Support
parentd3f4283b4086bf5f526e7efacb6f70c8e2fd2392 (diff)
downloadbcm5719-llvm-b89804f2465ba4da71600a7d92e038abdf411a86.tar.gz
bcm5719-llvm-b89804f2465ba4da71600a7d92e038abdf411a86.zip
Add signExtend to ConstantRange, to complement zeroExtend and truncate.
llvm-svn: 35733
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/ConstantRange.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Support/ConstantRange.cpp b/llvm/lib/Support/ConstantRange.cpp
index dd3e44e4e92..79a85b80d7e 100644
--- a/llvm/lib/Support/ConstantRange.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud