diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2007-04-07 15:41:33 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2007-04-07 15:41:33 +0000 |
| commit | b89804f2465ba4da71600a7d92e038abdf411a86 (patch) | |
| tree | 851750134570b115a7f5320fd143e9c19624ba86 /llvm/lib/Support/ConstantRange.cpp | |
| parent | d3f4283b4086bf5f526e7efacb6f70c8e2fd2392 (diff) | |
| download | llvm-b89804f2465ba4da71600a7d92e038abdf411a86.zip llvm-b89804f2465ba4da71600a7d92e038abdf411a86.tar.gz llvm-b89804f2465ba4da71600a7d92e038abdf411a86.tar.bz2 | |
Add signExtend to ConstantRange, to complement zeroExtend and truncate.
llvm-svn: 35733
Diffstat (limited to 'llvm/lib/Support/ConstantRange.cpp')
| -rw-r--r-- | llvm/lib/Support/ConstantRange.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Support/ConstantRange.cpp b/llvm/lib/Support/ConstantRange.cpp index dd3e44e..79a85b8 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 |
