diff options
| author | Nuno Lopes <nunoplopes@sapo.pt> | 2009-11-12 14:53:53 +0000 |
|---|---|---|
| committer | Nuno Lopes <nunoplopes@sapo.pt> | 2009-11-12 14:53:53 +0000 |
| commit | 60d5b1cfdbfff556492282317bfaf8cc5aa44920 (patch) | |
| tree | bbf407f9ee9502840ee853f76ac14ee832ac7a57 /llvm/lib/Support/ConstantRange.cpp | |
| parent | 5218176bc62836cbe17e3f8d3dcc5d208cc9314e (diff) | |
| download | llvm-60d5b1cfdbfff556492282317bfaf8cc5aa44920.zip llvm-60d5b1cfdbfff556492282317bfaf8cc5aa44920.tar.gz llvm-60d5b1cfdbfff556492282317bfaf8cc5aa44920.tar.bz2 | |
implement shl, ashr, and lshr methods. shl is not fully implemented as it is quite tricky.
llvm-svn: 86986
Diffstat (limited to 'llvm/lib/Support/ConstantRange.cpp')
| -rw-r--r-- | llvm/lib/Support/ConstantRange.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/lib/Support/ConstantRange.cpp b/llvm/lib/Support/ConstantRange.cpp index a194ac4..4593eb9 100644 --- a/llvm/lib/Support/ConstantRange.cpp +++ b/llvm/lib/Support/ConstantRange.cpp @@ -609,6 +609,43 @@ ConstantRange::udiv(const ConstantRange &RHS) const { return ConstantRange(Lower, Upper); } +ConstantRange +ConstantRange::shl(const ConstantRange &Amount) const { + if (isEmptySet()) + return *this; + + APInt min = getUnsignedMin() << Amount.getUnsignedMin(); + APInt max = getUnsignedMax() << Amount.getUnsignedMax(); + + // there's no overflow! + APInt Zeros(sizeof(unsigned)*8, getUnsignedMax().countLeadingZeros()); + if (Zeros.uge(Amount.getUnsignedMax())) + return ConstantRange(min, max); + + // FIXME: implement the other tricky cases + return ConstantRange(getBitWidth()); +} + +ConstantRange +ConstantRange::ashr(const ConstantRange &Amount) const { + if (isEmptySet()) + return *this; + + APInt min = getUnsignedMax().ashr(Amount.getUnsignedMin()); + APInt max = getUnsignedMin().ashr(Amount.getUnsignedMax()); + return ConstantRange(min, max); +} + +ConstantRange +ConstantRange::lshr(const ConstantRange &Amount) const { + if (isEmptySet()) + return *this; + + APInt min = getUnsignedMax().lshr(Amount.getUnsignedMin()); + APInt max = getUnsignedMin().lshr(Amount.getUnsignedMax()); + return ConstantRange(min, max); +} + /// print - Print out the bounds to a stream... /// void ConstantRange::print(raw_ostream &OS) const { |
