1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Add signExtend to ConstantRange, to complement zeroExtend and truncate.

llvm-svn: 35733
This commit is contained in:
Nick Lewycky 2007-04-07 15:41:33 +00:00
parent b1e6eab93e
commit ec51e934ef
2 changed files with 23 additions and 0 deletions

View File

@ -157,6 +157,12 @@ class ConstantRange {
/// zero extended to BitWidth.
ConstantRange zeroExtend(uint32_t BitWidth) const;
/// 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 if the source range had been
/// sign extended to BitWidth.
ConstantRange signExtend(uint32_t BitWidth) const;
/// 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 if the source range had been

View File

@ -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