aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/ConstantRange.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2009-11-09 15:36:28 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2009-11-09 15:36:28 +0000
commit95a3be0ba44e96308c65c28ee859acc36149ddd8 (patch)
tree1eaf3e241f96d3c2a582f94c1d3a0f6837bf9587 /lib/Support/ConstantRange.cpp
parent43cca695a81ddc4a8a1f98d959047ba16edc3d72 (diff)
downloadexternal_llvm-95a3be0ba44e96308c65c28ee859acc36149ddd8.zip
external_llvm-95a3be0ba44e96308c65c28ee859acc36149ddd8.tar.gz
external_llvm-95a3be0ba44e96308c65c28ee859acc36149ddd8.tar.bz2
add zextOrTrunc and sextOrTrunc methods, that are similar to the ones in APInt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86549 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/ConstantRange.cpp')
-rw-r--r--lib/Support/ConstantRange.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index 423e90d..a194ac4 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -492,6 +492,30 @@ ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
return ConstantRange(L, U);
}
+/// zextOrTrunc - make this range have the bit width given by \p DstTySize. The
+/// value is zero extended, truncated, or left alone to make it that width.
+ConstantRange ConstantRange::zextOrTrunc(uint32_t DstTySize) const {
+ unsigned SrcTySize = getBitWidth();
+ if (SrcTySize > DstTySize)
+ return truncate(DstTySize);
+ else if (SrcTySize < DstTySize)
+ return zeroExtend(DstTySize);
+ else
+ return *this;
+}
+
+/// sextOrTrunc - make this range have the bit width given by \p DstTySize. The
+/// value is sign extended, truncated, or left alone to make it that width.
+ConstantRange ConstantRange::sextOrTrunc(uint32_t DstTySize) const {
+ unsigned SrcTySize = getBitWidth();
+ if (SrcTySize > DstTySize)
+ return truncate(DstTySize);
+ else if (SrcTySize < DstTySize)
+ return signExtend(DstTySize);
+ else
+ return *this;
+}
+
ConstantRange
ConstantRange::add(const ConstantRange &Other) const {
if (isEmptySet() || Other.isEmptySet())