add zextOrTrunc and sextOrTrunc methods, that are similar to the ones in APInt

llvm-svn: 86549
This commit is contained in:
Nuno Lopes 2009-11-09 15:36:28 +00:00
parent ad95414c26
commit 640eb70bee
2 changed files with 32 additions and 0 deletions

View File

@ -187,6 +187,14 @@ public:
/// truncated to the specified type.
ConstantRange truncate(uint32_t BitWidth) const;
/// zextOrTrunc - make this range have the bit width given by \p BitWidth. The
/// value is zero extended, truncated, or left alone to make it that width.
ConstantRange zextOrTrunc(uint32_t BitWidth) const;
/// sextOrTrunc - make this range have the bit width given by \p BitWidth. The
/// value is sign extended, truncated, or left alone to make it that width.
ConstantRange sextOrTrunc(uint32_t BitWidth) const;
/// add - Return a new range representing the possible values resulting
/// from an addition of a value in this range and a value in Other.
ConstantRange add(const ConstantRange &Other) const;

View File

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