[llvm-commits] [llvm] r86986 - in /llvm/trunk: include/llvm/Support/ConstantRange.h lib/Support/ConstantRange.cpp
Nuno Lopes
nunoplopes at sapo.pt
Thu Nov 12 06:53:53 PST 2009
Author: nlopes
Date: Thu Nov 12 08:53:53 2009
New Revision: 86986
URL: http://llvm.org/viewvc/llvm-project?rev=86986&view=rev
Log:
implement shl, ashr, and lshr methods. shl is not fully implemented as it is quite tricky.
Modified:
llvm/trunk/include/llvm/Support/ConstantRange.h
llvm/trunk/lib/Support/ConstantRange.cpp
Modified: llvm/trunk/include/llvm/Support/ConstantRange.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ConstantRange.h?rev=86986&r1=86985&r2=86986&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ConstantRange.h (original)
+++ llvm/trunk/include/llvm/Support/ConstantRange.h Thu Nov 12 08:53:53 2009
@@ -217,6 +217,18 @@
/// TODO: This isn't fully implemented yet.
ConstantRange udiv(const ConstantRange &Other) const;
+ /// shl - Return a new range representing the possible values resulting
+ /// from a left shift of a value in this range by the Amount value.
+ ConstantRange shl(const ConstantRange &Amount) const;
+
+ /// ashr - Return a new range representing the possible values resulting from
+ /// an arithmetic right shift of a value in this range by the Amount value.
+ ConstantRange ashr(const ConstantRange &Amount) const;
+
+ /// shr - Return a new range representing the possible values resulting
+ /// from a logical right shift of a value in this range by the Amount value.
+ ConstantRange lshr(const ConstantRange &Amount) const;
+
/// print - Print out the bounds to a stream...
///
void print(raw_ostream &OS) const;
Modified: llvm/trunk/lib/Support/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ConstantRange.cpp?rev=86986&r1=86985&r2=86986&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ConstantRange.cpp (original)
+++ llvm/trunk/lib/Support/ConstantRange.cpp Thu Nov 12 08:53:53 2009
@@ -609,6 +609,43 @@
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 {
More information about the llvm-commits
mailing list