diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2009-11-09 15:36:28 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2009-11-09 15:36:28 +0000 |
commit | 640eb70bee922fa58488185a0b3645b2952da28e (patch) | |
tree | 78e7a1f6fa271ac6bf736e4b05218ae08a9cdb19 /llvm/lib/Support/ConstantRange.cpp | |
parent | ad95414c264d3496fc29b635bd1404ebe80c5b30 (diff) | |
download | bcm5719-llvm-640eb70bee922fa58488185a0b3645b2952da28e.tar.gz bcm5719-llvm-640eb70bee922fa58488185a0b3645b2952da28e.zip |
add zextOrTrunc and sextOrTrunc methods, that are similar to the ones in APInt
llvm-svn: 86549
Diffstat (limited to 'llvm/lib/Support/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/Support/ConstantRange.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Support/ConstantRange.cpp b/llvm/lib/Support/ConstantRange.cpp index 423e90d9935..a194ac4ff55 100644 --- a/llvm/lib/Support/ConstantRange.cpp +++ b/llvm/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()) |