blob: 91095cfe9eec97b035c1a6e4ba223aa9b8e6cd13 [file] [log] [blame]
Chris Lattner113f2ae2002-09-01 23:53:36 +00001//===-- ConstantRange.cpp - ConstantRange implementation ------------------===//
Misha Brukmanb1c93172005-04-21 23:48:37 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb1c93172005-04-21 23:48:37 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner113f2ae2002-09-01 23:53:36 +00009//
10// Represent a range of possible values that may occur when the program is run
11// for an integral value. This keeps track of a lower and upper bound for the
12// constant, which MAY wrap around the end of the numeric range. To do this, it
13// keeps track of a [lower, upper) bound, which specifies an interval just like
14// STL iterators. When used with boolean values, the following are important
15// ranges (other integral ranges use min/max values for special range values):
16//
17// [F, F) = {} = Empty set
18// [T, F) = {T}
19// [F, T) = {F}
20// [T, T) = {F, T} = Full set
21//
22//===----------------------------------------------------------------------===//
23
Chandler Carruth9fb823b2013-01-02 11:36:10 +000024#include "llvm/IR/InstrTypes.h"
Chandler Carruth8cd041e2014-03-04 12:24:34 +000025#include "llvm/IR/ConstantRange.h"
David Greenede7b3532010-01-05 01:28:32 +000026#include "llvm/Support/Debug.h"
Chris Lattner0c19df42008-08-23 22:23:09 +000027#include "llvm/Support/raw_ostream.h"
Chris Lattnerc9499b62003-12-14 21:35:53 +000028using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000029
Chris Lattner113f2ae2002-09-01 23:53:36 +000030/// Initialize a full (the default) or empty set for the specified type.
31///
Dan Gohmandc33ae22009-07-09 23:16:10 +000032ConstantRange::ConstantRange(uint32_t BitWidth, bool Full) {
Chris Lattner113f2ae2002-09-01 23:53:36 +000033 if (Full)
Reid Spencere1f3f192007-02-28 17:36:23 +000034 Lower = Upper = APInt::getMaxValue(BitWidth);
Chris Lattner113f2ae2002-09-01 23:53:36 +000035 else
Reid Spencere1f3f192007-02-28 17:36:23 +000036 Lower = Upper = APInt::getMinValue(BitWidth);
Chris Lattner113f2ae2002-09-01 23:53:36 +000037}
38
Chris Lattner55481f72004-03-30 00:20:08 +000039/// Initialize a range to hold the single specified value.
40///
Benjamin Kramercce97be2013-07-11 15:37:27 +000041ConstantRange::ConstantRange(APIntMoveTy V)
Chandler Carruth002da5d2014-03-02 04:08:41 +000042 : Lower(std::move(V)), Upper(Lower + 1) {}
Chris Lattner113f2ae2002-09-01 23:53:36 +000043
Benjamin Kramercce97be2013-07-11 15:37:27 +000044ConstantRange::ConstantRange(APIntMoveTy L, APIntMoveTy U)
Chandler Carruth002da5d2014-03-02 04:08:41 +000045 : Lower(std::move(L)), Upper(std::move(U)) {
Benjamin Kramercce97be2013-07-11 15:37:27 +000046 assert(Lower.getBitWidth() == Upper.getBitWidth() &&
Dan Gohmandc33ae22009-07-09 23:16:10 +000047 "ConstantRange with unequal bit widths");
Benjamin Kramercce97be2013-07-11 15:37:27 +000048 assert((Lower != Upper || (Lower.isMaxValue() || Lower.isMinValue())) &&
Reid Spencere1f3f192007-02-28 17:36:23 +000049 "Lower == Upper, but they aren't min or max value!");
50}
51
Sanjoy Das7182d362015-03-18 00:41:24 +000052ConstantRange ConstantRange::makeAllowedICmpRegion(CmpInst::Predicate Pred,
53 const ConstantRange &CR) {
Nick Lewycky5154ee02010-09-28 18:18:36 +000054 if (CR.isEmptySet())
55 return CR;
56
Nick Lewyckydcfdce92009-07-11 06:15:39 +000057 uint32_t W = CR.getBitWidth();
58 switch (Pred) {
Sanjoy Das7182d362015-03-18 00:41:24 +000059 default:
60 llvm_unreachable("Invalid ICmp predicate to makeAllowedICmpRegion()");
Frits van Bommelec9cd832011-07-27 15:20:06 +000061 case CmpInst::ICMP_EQ:
Nick Lewycky9c5fc412009-07-11 17:04:01 +000062 return CR;
Frits van Bommelec9cd832011-07-27 15:20:06 +000063 case CmpInst::ICMP_NE:
Nick Lewyckydcfdce92009-07-11 06:15:39 +000064 if (CR.isSingleElement())
65 return ConstantRange(CR.getUpper(), CR.getLower());
66 return ConstantRange(W);
Frits van Bommelec9cd832011-07-27 15:20:06 +000067 case CmpInst::ICMP_ULT: {
Nick Lewycky5154ee02010-09-28 18:18:36 +000068 APInt UMax(CR.getUnsignedMax());
69 if (UMax.isMinValue())
70 return ConstantRange(W, /* empty */ false);
71 return ConstantRange(APInt::getMinValue(W), UMax);
72 }
Frits van Bommelec9cd832011-07-27 15:20:06 +000073 case CmpInst::ICMP_SLT: {
Nick Lewycky5154ee02010-09-28 18:18:36 +000074 APInt SMax(CR.getSignedMax());
75 if (SMax.isMinSignedValue())
76 return ConstantRange(W, /* empty */ false);
77 return ConstantRange(APInt::getSignedMinValue(W), SMax);
78 }
Frits van Bommelec9cd832011-07-27 15:20:06 +000079 case CmpInst::ICMP_ULE: {
Nick Lewyckydcfdce92009-07-11 06:15:39 +000080 APInt UMax(CR.getUnsignedMax());
81 if (UMax.isMaxValue())
82 return ConstantRange(W);
83 return ConstantRange(APInt::getMinValue(W), UMax + 1);
84 }
Frits van Bommelec9cd832011-07-27 15:20:06 +000085 case CmpInst::ICMP_SLE: {
Nick Lewyckydcfdce92009-07-11 06:15:39 +000086 APInt SMax(CR.getSignedMax());
Nick Lewycky5154ee02010-09-28 18:18:36 +000087 if (SMax.isMaxSignedValue())
Nick Lewyckydcfdce92009-07-11 06:15:39 +000088 return ConstantRange(W);
89 return ConstantRange(APInt::getSignedMinValue(W), SMax + 1);
90 }
Frits van Bommelec9cd832011-07-27 15:20:06 +000091 case CmpInst::ICMP_UGT: {
Nick Lewycky5154ee02010-09-28 18:18:36 +000092 APInt UMin(CR.getUnsignedMin());
93 if (UMin.isMaxValue())
94 return ConstantRange(W, /* empty */ false);
95 return ConstantRange(UMin + 1, APInt::getNullValue(W));
96 }
Frits van Bommelec9cd832011-07-27 15:20:06 +000097 case CmpInst::ICMP_SGT: {
Nick Lewycky5154ee02010-09-28 18:18:36 +000098 APInt SMin(CR.getSignedMin());
99 if (SMin.isMaxSignedValue())
100 return ConstantRange(W, /* empty */ false);
101 return ConstantRange(SMin + 1, APInt::getSignedMinValue(W));
102 }
Frits van Bommelec9cd832011-07-27 15:20:06 +0000103 case CmpInst::ICMP_UGE: {
Nick Lewyckydcfdce92009-07-11 06:15:39 +0000104 APInt UMin(CR.getUnsignedMin());
105 if (UMin.isMinValue())
106 return ConstantRange(W);
107 return ConstantRange(UMin, APInt::getNullValue(W));
108 }
Frits van Bommelec9cd832011-07-27 15:20:06 +0000109 case CmpInst::ICMP_SGE: {
Nick Lewyckydcfdce92009-07-11 06:15:39 +0000110 APInt SMin(CR.getSignedMin());
111 if (SMin.isMinSignedValue())
112 return ConstantRange(W);
113 return ConstantRange(SMin, APInt::getSignedMinValue(W));
114 }
115 }
116}
117
Sanjoy Das7182d362015-03-18 00:41:24 +0000118ConstantRange ConstantRange::makeSatisfyingICmpRegion(CmpInst::Predicate Pred,
119 const ConstantRange &CR) {
120 // Follows from De-Morgan's laws:
121 //
122 // ~(~A union ~B) == A intersect B.
123 //
124 return makeAllowedICmpRegion(CmpInst::getInversePredicate(Pred), CR)
125 .inverse();
126}
127
Chris Lattner113f2ae2002-09-01 23:53:36 +0000128/// isFullSet - Return true if this set contains all of the elements possible
129/// for this data-type
130bool ConstantRange::isFullSet() const {
Zhou Sheng31787362007-04-26 16:42:07 +0000131 return Lower == Upper && Lower.isMaxValue();
Chris Lattner113f2ae2002-09-01 23:53:36 +0000132}
Misha Brukmanb1c93172005-04-21 23:48:37 +0000133
Chris Lattner113f2ae2002-09-01 23:53:36 +0000134/// isEmptySet - Return true if this set contains no members.
135///
136bool ConstantRange::isEmptySet() const {
Zhou Sheng31787362007-04-26 16:42:07 +0000137 return Lower == Upper && Lower.isMinValue();
Chris Lattner113f2ae2002-09-01 23:53:36 +0000138}
139
140/// isWrappedSet - Return true if this set wraps around the top of the range,
141/// for example: [100, 8)
142///
Reid Spencer6a440332007-03-01 07:54:15 +0000143bool ConstantRange::isWrappedSet() const {
Reid Spencere1f3f192007-02-28 17:36:23 +0000144 return Lower.ugt(Upper);
Chris Lattner113f2ae2002-09-01 23:53:36 +0000145}
146
Nick Lewyckya35462d2010-09-06 23:52:49 +0000147/// isSignWrappedSet - Return true if this set wraps around the INT_MIN of
148/// its bitwidth, for example: i8 [120, 140).
149///
150bool ConstantRange::isSignWrappedSet() const {
151 return contains(APInt::getSignedMaxValue(getBitWidth())) &&
152 contains(APInt::getSignedMinValue(getBitWidth()));
153}
154
Chris Lattner113f2ae2002-09-01 23:53:36 +0000155/// getSetSize - Return the number of elements in this set.
156///
Reid Spencere1f3f192007-02-28 17:36:23 +0000157APInt ConstantRange::getSetSize() const {
Nuno Lopes216d5712012-07-17 15:43:59 +0000158 if (isFullSet()) {
159 APInt Size(getBitWidth()+1, 0);
160 Size.setBit(getBitWidth());
161 return Size;
Chris Lattner113f2ae2002-09-01 23:53:36 +0000162 }
Misha Brukmanb1c93172005-04-21 23:48:37 +0000163
Nuno Lopes216d5712012-07-17 15:43:59 +0000164 // This is also correct for wrapped sets.
Nuno Lopes99504c52012-07-16 18:08:12 +0000165 return (Upper - Lower).zext(getBitWidth()+1);
Chris Lattner113f2ae2002-09-01 23:53:36 +0000166}
167
Nick Lewyckye4559372007-03-10 15:54:12 +0000168/// getUnsignedMax - Return the largest unsigned value contained in the
169/// ConstantRange.
170///
171APInt ConstantRange::getUnsignedMax() const {
172 if (isFullSet() || isWrappedSet())
173 return APInt::getMaxValue(getBitWidth());
Nick Lewycky228f5b42012-01-03 20:33:00 +0000174 return getUpper() - 1;
Nick Lewyckye4559372007-03-10 15:54:12 +0000175}
176
177/// getUnsignedMin - Return the smallest unsigned value contained in the
178/// ConstantRange.
179///
180APInt ConstantRange::getUnsignedMin() const {
181 if (isFullSet() || (isWrappedSet() && getUpper() != 0))
182 return APInt::getMinValue(getBitWidth());
Nick Lewycky228f5b42012-01-03 20:33:00 +0000183 return getLower();
Nick Lewyckye4559372007-03-10 15:54:12 +0000184}
185
186/// getSignedMax - Return the largest signed value contained in the
187/// ConstantRange.
188///
189APInt ConstantRange::getSignedMax() const {
Zhou Sheng01c175e2007-04-13 05:57:32 +0000190 APInt SignedMax(APInt::getSignedMaxValue(getBitWidth()));
Nick Lewyckye4559372007-03-10 15:54:12 +0000191 if (!isWrappedSet()) {
Nick Lewyckyd18b1602007-06-09 04:20:33 +0000192 if (getLower().sle(getUpper() - 1))
Nick Lewyckye4559372007-03-10 15:54:12 +0000193 return getUpper() - 1;
Nick Lewycky228f5b42012-01-03 20:33:00 +0000194 return SignedMax;
Nick Lewyckye4559372007-03-10 15:54:12 +0000195 }
Nick Lewycky228f5b42012-01-03 20:33:00 +0000196 if (getLower().isNegative() == getUpper().isNegative())
197 return SignedMax;
198 return getUpper() - 1;
Nick Lewyckye4559372007-03-10 15:54:12 +0000199}
200
201/// getSignedMin - Return the smallest signed value contained in the
202/// ConstantRange.
203///
204APInt ConstantRange::getSignedMin() const {
Zhou Sheng01c175e2007-04-13 05:57:32 +0000205 APInt SignedMin(APInt::getSignedMinValue(getBitWidth()));
Nick Lewyckye4559372007-03-10 15:54:12 +0000206 if (!isWrappedSet()) {
Nick Lewyckyd18b1602007-06-09 04:20:33 +0000207 if (getLower().sle(getUpper() - 1))
Nick Lewyckye4559372007-03-10 15:54:12 +0000208 return getLower();
Nick Lewycky228f5b42012-01-03 20:33:00 +0000209 return SignedMin;
Nick Lewyckye4559372007-03-10 15:54:12 +0000210 }
Nick Lewycky228f5b42012-01-03 20:33:00 +0000211 if ((getUpper() - 1).slt(getLower())) {
212 if (getUpper() != SignedMin)
213 return SignedMin;
214 }
215 return getLower();
Nick Lewyckye4559372007-03-10 15:54:12 +0000216}
217
Chris Lattner55481f72004-03-30 00:20:08 +0000218/// contains - Return true if the specified value is in the set.
219///
Reid Spencer6a440332007-03-01 07:54:15 +0000220bool ConstantRange::contains(const APInt &V) const {
221 if (Lower == Upper)
222 return isFullSet();
Chris Lattner113f2ae2002-09-01 23:53:36 +0000223
Reid Spencer6a440332007-03-01 07:54:15 +0000224 if (!isWrappedSet())
225 return Lower.ule(V) && V.ult(Upper);
Nick Lewycky228f5b42012-01-03 20:33:00 +0000226 return Lower.ule(V) || V.ult(Upper);
Chris Lattner55481f72004-03-30 00:20:08 +0000227}
228
Nick Lewyckydcfdce92009-07-11 06:15:39 +0000229/// contains - Return true if the argument is a subset of this range.
Nick Lewyckyd385c222010-08-11 22:04:36 +0000230/// Two equal sets contain each other. The empty set contained by all other
231/// sets.
Nick Lewyckydcfdce92009-07-11 06:15:39 +0000232///
233bool ConstantRange::contains(const ConstantRange &Other) const {
Nick Lewyckyd385c222010-08-11 22:04:36 +0000234 if (isFullSet() || Other.isEmptySet()) return true;
235 if (isEmptySet() || Other.isFullSet()) return false;
Nick Lewyckydcfdce92009-07-11 06:15:39 +0000236
237 if (!isWrappedSet()) {
238 if (Other.isWrappedSet())
239 return false;
240
241 return Lower.ule(Other.getLower()) && Other.getUpper().ule(Upper);
242 }
243
244 if (!Other.isWrappedSet())
245 return Other.getUpper().ule(Upper) ||
246 Lower.ule(Other.getLower());
247
248 return Other.getUpper().ule(Upper) && Lower.ule(Other.getLower());
249}
250
Chris Lattner55481f72004-03-30 00:20:08 +0000251/// subtract - Subtract the specified constant from the endpoints of this
252/// constant range.
Reid Spencer3a7e9d82007-02-28 19:57:34 +0000253ConstantRange ConstantRange::subtract(const APInt &Val) const {
Reid Spencer9b3d6ec2007-02-28 22:02:48 +0000254 assert(Val.getBitWidth() == getBitWidth() && "Wrong bit width");
Chris Lattner55481f72004-03-30 00:20:08 +0000255 // If the set is empty or full, don't modify the endpoints.
Reid Spencere1f3f192007-02-28 17:36:23 +0000256 if (Lower == Upper)
257 return *this;
Reid Spencere1f3f192007-02-28 17:36:23 +0000258 return ConstantRange(Lower - Val, Upper - Val);
Chris Lattner55481f72004-03-30 00:20:08 +0000259}
Chris Lattner113f2ae2002-09-01 23:53:36 +0000260
Nuno Lopes5020db22012-06-28 16:10:13 +0000261/// \brief Subtract the specified range from this range (aka relative complement
262/// of the sets).
263ConstantRange ConstantRange::difference(const ConstantRange &CR) const {
264 return intersectWith(CR.inverse());
265}
266
Nick Lewycky63f11082007-02-11 00:58:49 +0000267/// intersectWith - Return the range that results from the intersection of this
Nick Lewycky0d139032009-07-18 06:34:42 +0000268/// range with another range. The resultant range is guaranteed to include all
269/// elements contained in both input ranges, and to have the smallest possible
270/// set size that does so. Because there may be two intersections with the
271/// same set size, A.intersectWith(B) might not be equal to B.intersectWith(A).
Reid Spencer6a440332007-03-01 07:54:15 +0000272ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
Reid Spencer9b3d6ec2007-02-28 22:02:48 +0000273 assert(getBitWidth() == CR.getBitWidth() &&
274 "ConstantRange types don't agree!");
Nick Lewycky61b4a262007-07-14 02:51:34 +0000275
276 // Handle common cases.
277 if ( isEmptySet() || CR.isFullSet()) return *this;
278 if (CR.isEmptySet() || isFullSet()) return CR;
279
280 if (!isWrappedSet() && CR.isWrappedSet())
Nick Lewycky0d139032009-07-18 06:34:42 +0000281 return CR.intersectWith(*this);
Nick Lewycky61b4a262007-07-14 02:51:34 +0000282
283 if (!isWrappedSet() && !CR.isWrappedSet()) {
284 if (Lower.ult(CR.Lower)) {
285 if (Upper.ule(CR.Lower))
286 return ConstantRange(getBitWidth(), false);
287
288 if (Upper.ult(CR.Upper))
289 return ConstantRange(CR.Lower, Upper);
290
291 return CR;
Nick Lewycky61b4a262007-07-14 02:51:34 +0000292 }
Nick Lewycky228f5b42012-01-03 20:33:00 +0000293 if (Upper.ult(CR.Upper))
294 return *this;
295
296 if (Lower.ult(CR.Upper))
297 return ConstantRange(Lower, CR.Upper);
298
299 return ConstantRange(getBitWidth(), false);
Nick Lewycky61b4a262007-07-14 02:51:34 +0000300 }
301
302 if (isWrappedSet() && !CR.isWrappedSet()) {
303 if (CR.Lower.ult(Upper)) {
304 if (CR.Upper.ult(Upper))
305 return CR;
306
Nuno Lopes63afc082012-05-18 00:14:36 +0000307 if (CR.Upper.ule(Lower))
Nick Lewycky61b4a262007-07-14 02:51:34 +0000308 return ConstantRange(CR.Lower, Upper);
309
310 if (getSetSize().ult(CR.getSetSize()))
311 return *this;
Nick Lewycky228f5b42012-01-03 20:33:00 +0000312 return CR;
313 }
314 if (CR.Lower.ult(Lower)) {
Nick Lewycky61b4a262007-07-14 02:51:34 +0000315 if (CR.Upper.ule(Lower))
316 return ConstantRange(getBitWidth(), false);
317
318 return ConstantRange(Lower, CR.Upper);
319 }
320 return CR;
321 }
322
323 if (CR.Upper.ult(Upper)) {
324 if (CR.Lower.ult(Upper)) {
325 if (getSetSize().ult(CR.getSetSize()))
326 return *this;
Nick Lewycky228f5b42012-01-03 20:33:00 +0000327 return CR;
Nick Lewycky61b4a262007-07-14 02:51:34 +0000328 }
329
330 if (CR.Lower.ult(Lower))
331 return ConstantRange(Lower, CR.Upper);
332
333 return CR;
Nick Lewycky228f5b42012-01-03 20:33:00 +0000334 }
Nuno Lopesebb0c942012-06-28 00:59:33 +0000335 if (CR.Upper.ule(Lower)) {
Nick Lewycky61b4a262007-07-14 02:51:34 +0000336 if (CR.Lower.ult(Lower))
337 return *this;
338
339 return ConstantRange(CR.Lower, Upper);
340 }
341 if (getSetSize().ult(CR.getSetSize()))
342 return *this;
Nick Lewycky228f5b42012-01-03 20:33:00 +0000343 return CR;
Nick Lewycky61b4a262007-07-14 02:51:34 +0000344}
345
346
Nick Lewycky63f11082007-02-11 00:58:49 +0000347/// unionWith - Return the range that results from the union of this range with
Chris Lattner113f2ae2002-09-01 23:53:36 +0000348/// another range. The resultant range is guaranteed to include the elements of
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000349/// both sets, but may contain more. For example, [3, 9) union [12,15) is
350/// [3, 15), which includes 9, 10, and 11, which were not included in either
351/// set before.
Chris Lattner113f2ae2002-09-01 23:53:36 +0000352///
Reid Spencer6a440332007-03-01 07:54:15 +0000353ConstantRange ConstantRange::unionWith(const ConstantRange &CR) const {
Reid Spencer9b3d6ec2007-02-28 22:02:48 +0000354 assert(getBitWidth() == CR.getBitWidth() &&
355 "ConstantRange types don't agree!");
Chris Lattner113f2ae2002-09-01 23:53:36 +0000356
Nick Lewyckycf87f9e2007-03-02 03:33:05 +0000357 if ( isFullSet() || CR.isEmptySet()) return *this;
358 if (CR.isFullSet() || isEmptySet()) return CR;
Chris Lattner113f2ae2002-09-01 23:53:36 +0000359
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000360 if (!isWrappedSet() && CR.isWrappedSet()) return CR.unionWith(*this);
361
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000362 if (!isWrappedSet() && !CR.isWrappedSet()) {
Nick Lewycky567daf32009-07-19 03:44:35 +0000363 if (CR.Upper.ult(Lower) || Upper.ult(CR.Lower)) {
364 // If the two ranges are disjoint, find the smaller gap and bridge it.
365 APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
366 if (d1.ult(d2))
367 return ConstantRange(Lower, CR.Upper);
Nick Lewycky228f5b42012-01-03 20:33:00 +0000368 return ConstantRange(CR.Lower, Upper);
Nick Lewycky567daf32009-07-19 03:44:35 +0000369 }
370
371 APInt L = Lower, U = Upper;
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000372 if (CR.Lower.ult(L))
373 L = CR.Lower;
Nick Lewycky567daf32009-07-19 03:44:35 +0000374 if ((CR.Upper - 1).ugt(U - 1))
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000375 U = CR.Upper;
Nick Lewycky567daf32009-07-19 03:44:35 +0000376
377 if (L == 0 && U == 0)
378 return ConstantRange(getBitWidth());
379
380 return ConstantRange(L, U);
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000381 }
382
Nick Lewycky567daf32009-07-19 03:44:35 +0000383 if (!CR.isWrappedSet()) {
384 // ------U L----- and ------U L----- : this
385 // L--U L--U : CR
386 if (CR.Upper.ule(Upper) || CR.Lower.uge(Lower))
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000387 return *this;
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000388
Nick Lewycky567daf32009-07-19 03:44:35 +0000389 // ------U L----- : this
390 // L---------U : CR
391 if (CR.Lower.ule(Upper) && Lower.ule(CR.Upper))
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000392 return ConstantRange(getBitWidth());
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000393
Nick Lewycky567daf32009-07-19 03:44:35 +0000394 // ----U L---- : this
395 // L---U : CR
396 // <d1> <d2>
397 if (Upper.ule(CR.Lower) && CR.Upper.ule(Lower)) {
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000398 APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
Nick Lewycky567daf32009-07-19 03:44:35 +0000399 if (d1.ult(d2))
400 return ConstantRange(Lower, CR.Upper);
Nick Lewycky228f5b42012-01-03 20:33:00 +0000401 return ConstantRange(CR.Lower, Upper);
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000402 }
403
Nick Lewycky567daf32009-07-19 03:44:35 +0000404 // ----U L----- : this
405 // L----U : CR
406 if (Upper.ult(CR.Lower) && Lower.ult(CR.Upper))
407 return ConstantRange(CR.Lower, Upper);
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000408
Nick Lewycky567daf32009-07-19 03:44:35 +0000409 // ------U L---- : this
410 // L-----U : CR
Nick Lewycky228f5b42012-01-03 20:33:00 +0000411 assert(CR.Lower.ult(Upper) && CR.Upper.ult(Lower) &&
412 "ConstantRange::unionWith missed a case with one range wrapped");
413 return ConstantRange(Lower, CR.Upper);
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000414 }
415
Nick Lewycky567daf32009-07-19 03:44:35 +0000416 // ------U L---- and ------U L---- : this
417 // -U L----------- and ------------U L : CR
418 if (CR.Lower.ule(Upper) || Lower.ule(CR.Upper))
419 return ConstantRange(getBitWidth());
Nick Lewyckyf22938a2007-04-01 03:47:44 +0000420
Nick Lewycky567daf32009-07-19 03:44:35 +0000421 APInt L = Lower, U = Upper;
422 if (CR.Upper.ugt(U))
423 U = CR.Upper;
424 if (CR.Lower.ult(L))
425 L = CR.Lower;
Nick Lewyckycf87f9e2007-03-02 03:33:05 +0000426
427 return ConstantRange(L, U);
Chris Lattner113f2ae2002-09-01 23:53:36 +0000428}
Chris Lattnere0bb9eb2002-09-02 00:18:22 +0000429
Chris Lattner55481f72004-03-30 00:20:08 +0000430/// zeroExtend - Return a new range in the specified integer type, which must
431/// be strictly larger than the current type. The returned range will
Reid Spencer266e42b2006-12-23 06:05:41 +0000432/// correspond to the possible range of values as if the source range had been
Chris Lattner55481f72004-03-30 00:20:08 +0000433/// zero extended.
Reid Spencer9b3d6ec2007-02-28 22:02:48 +0000434ConstantRange ConstantRange::zeroExtend(uint32_t DstTySize) const {
Nick Lewyckya35462d2010-09-06 23:52:49 +0000435 if (isEmptySet()) return ConstantRange(DstTySize, /*isFullSet=*/false);
436
Reid Spencer9b3d6ec2007-02-28 22:02:48 +0000437 unsigned SrcTySize = getBitWidth();
Reid Spencere1f3f192007-02-28 17:36:23 +0000438 assert(SrcTySize < DstTySize && "Not a value extension");
Nuno Lopeseb9d2752012-07-23 20:33:29 +0000439 if (isFullSet() || isWrappedSet()) {
Nick Lewyckya35462d2010-09-06 23:52:49 +0000440 // Change into [0, 1 << src bit width)
Nuno Lopeseb9d2752012-07-23 20:33:29 +0000441 APInt LowerExt(DstTySize, 0);
442 if (!Upper) // special case: [X, 0) -- not really wrapping around
443 LowerExt = Lower.zext(DstTySize);
Benjamin Kramerfc3ea6f2013-07-11 16:05:50 +0000444 return ConstantRange(LowerExt, APInt::getOneBitSet(DstTySize, SrcTySize));
Nuno Lopeseb9d2752012-07-23 20:33:29 +0000445 }
Chris Lattner55481f72004-03-30 00:20:08 +0000446
Jay Foad583abbc2010-12-07 08:25:19 +0000447 return ConstantRange(Lower.zext(DstTySize), Upper.zext(DstTySize));
Chris Lattner55481f72004-03-30 00:20:08 +0000448}
449
Nick Lewyckyb89804f2007-04-07 15:41:33 +0000450/// signExtend - Return a new range in the specified integer type, which must
451/// be strictly larger than the current type. The returned range will
452/// correspond to the possible range of values as if the source range had been
453/// sign extended.
454ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {
Nick Lewyckya35462d2010-09-06 23:52:49 +0000455 if (isEmptySet()) return ConstantRange(DstTySize, /*isFullSet=*/false);
456
Nick Lewyckyb89804f2007-04-07 15:41:33 +0000457 unsigned SrcTySize = getBitWidth();
458 assert(SrcTySize < DstTySize && "Not a value extension");
Nuno Lopes1112eca2013-10-30 15:36:50 +0000459
460 // special case: [X, INT_MIN) -- not really wrapping around
Nuno Lopes14d4b0c2013-10-31 19:53:53 +0000461 if (Upper.isMinSignedValue())
Nuno Lopes1112eca2013-10-30 15:36:50 +0000462 return ConstantRange(Lower.sext(DstTySize), Upper.zext(DstTySize));
463
Nick Lewyckya35462d2010-09-06 23:52:49 +0000464 if (isFullSet() || isSignWrappedSet()) {
Nick Lewyckyb89804f2007-04-07 15:41:33 +0000465 return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
Nick Lewycky5edc4592009-07-13 04:17:23 +0000466 APInt::getLowBitsSet(DstTySize, SrcTySize-1) + 1);
Nick Lewyckyb89804f2007-04-07 15:41:33 +0000467 }
468
Jay Foad583abbc2010-12-07 08:25:19 +0000469 return ConstantRange(Lower.sext(DstTySize), Upper.sext(DstTySize));
Nick Lewyckyb89804f2007-04-07 15:41:33 +0000470}
471
Chris Lattner55481f72004-03-30 00:20:08 +0000472/// truncate - Return a new range in the specified integer type, which must be
473/// strictly smaller than the current type. The returned range will
Reid Spencer266e42b2006-12-23 06:05:41 +0000474/// correspond to the possible range of values as if the source range had been
Chris Lattner55481f72004-03-30 00:20:08 +0000475/// truncated to the specified type.
Reid Spencer9b3d6ec2007-02-28 22:02:48 +0000476ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
Benjamin Kramer6709e052011-11-24 17:24:33 +0000477 assert(getBitWidth() > DstTySize && "Not a value truncation");
Nuno Lopesc14776d2012-07-19 16:27:45 +0000478 if (isEmptySet())
479 return ConstantRange(DstTySize, /*isFullSet=*/false);
480 if (isFullSet())
Nick Lewyckyd385c222010-08-11 22:04:36 +0000481 return ConstantRange(DstTySize, /*isFullSet=*/true);
Chris Lattner55481f72004-03-30 00:20:08 +0000482
Nuno Lopesc14776d2012-07-19 16:27:45 +0000483 APInt MaxValue = APInt::getMaxValue(DstTySize).zext(getBitWidth());
484 APInt MaxBitValue(getBitWidth(), 0);
485 MaxBitValue.setBit(DstTySize);
486
487 APInt LowerDiv(Lower), UpperDiv(Upper);
488 ConstantRange Union(DstTySize, /*isFullSet=*/false);
489
490 // Analyze wrapped sets in their two parts: [0, Upper) \/ [Lower, MaxValue]
491 // We use the non-wrapped set code to analyze the [Lower, MaxValue) part, and
492 // then we do the union with [MaxValue, Upper)
493 if (isWrappedSet()) {
494 // if Upper is greater than Max Value, it covers the whole truncated range.
495 if (Upper.uge(MaxValue))
496 return ConstantRange(DstTySize, /*isFullSet=*/true);
497
498 Union = ConstantRange(APInt::getMaxValue(DstTySize),Upper.trunc(DstTySize));
499 UpperDiv = APInt::getMaxValue(getBitWidth());
500
501 // Union covers the MaxValue case, so return if the remaining range is just
502 // MaxValue.
503 if (LowerDiv == UpperDiv)
504 return Union;
505 }
506
507 // Chop off the most significant bits that are past the destination bitwidth.
508 if (LowerDiv.uge(MaxValue)) {
509 APInt Div(getBitWidth(), 0);
510 APInt::udivrem(LowerDiv, MaxBitValue, Div, LowerDiv);
511 UpperDiv = UpperDiv - MaxBitValue * Div;
512 }
513
514 if (UpperDiv.ule(MaxValue))
515 return ConstantRange(LowerDiv.trunc(DstTySize),
516 UpperDiv.trunc(DstTySize)).unionWith(Union);
517
518 // The truncated value wrapps around. Check if we can do better than fullset.
519 APInt UpperModulo = UpperDiv - MaxBitValue;
520 if (UpperModulo.ult(LowerDiv))
521 return ConstantRange(LowerDiv.trunc(DstTySize),
522 UpperModulo.trunc(DstTySize)).unionWith(Union);
523
524 return ConstantRange(DstTySize, /*isFullSet=*/true);
Chris Lattner55481f72004-03-30 00:20:08 +0000525}
526
Nuno Lopes640eb702009-11-09 15:36:28 +0000527/// zextOrTrunc - make this range have the bit width given by \p DstTySize. The
528/// value is zero extended, truncated, or left alone to make it that width.
529ConstantRange ConstantRange::zextOrTrunc(uint32_t DstTySize) const {
530 unsigned SrcTySize = getBitWidth();
531 if (SrcTySize > DstTySize)
532 return truncate(DstTySize);
Nick Lewycky228f5b42012-01-03 20:33:00 +0000533 if (SrcTySize < DstTySize)
Nuno Lopes640eb702009-11-09 15:36:28 +0000534 return zeroExtend(DstTySize);
Nick Lewycky228f5b42012-01-03 20:33:00 +0000535 return *this;
Nuno Lopes640eb702009-11-09 15:36:28 +0000536}
537
538/// sextOrTrunc - make this range have the bit width given by \p DstTySize. The
539/// value is sign extended, truncated, or left alone to make it that width.
540ConstantRange ConstantRange::sextOrTrunc(uint32_t DstTySize) const {
541 unsigned SrcTySize = getBitWidth();
542 if (SrcTySize > DstTySize)
543 return truncate(DstTySize);
Nick Lewycky228f5b42012-01-03 20:33:00 +0000544 if (SrcTySize < DstTySize)
Nuno Lopes640eb702009-11-09 15:36:28 +0000545 return signExtend(DstTySize);
Nick Lewycky228f5b42012-01-03 20:33:00 +0000546 return *this;
Nuno Lopes640eb702009-11-09 15:36:28 +0000547}
548
Dan Gohman5035fbf2009-07-09 22:07:27 +0000549ConstantRange
550ConstantRange::add(const ConstantRange &Other) const {
551 if (isEmptySet() || Other.isEmptySet())
552 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
Nick Lewycky73b704d2009-07-13 02:49:08 +0000553 if (isFullSet() || Other.isFullSet())
554 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
Dan Gohman5035fbf2009-07-09 22:07:27 +0000555
556 APInt Spread_X = getSetSize(), Spread_Y = Other.getSetSize();
557 APInt NewLower = getLower() + Other.getLower();
558 APInt NewUpper = getUpper() + Other.getUpper() - 1;
559 if (NewLower == NewUpper)
560 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
561
562 ConstantRange X = ConstantRange(NewLower, NewUpper);
563 if (X.getSetSize().ult(Spread_X) || X.getSetSize().ult(Spread_Y))
564 // We've wrapped, therefore, full set.
565 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
566
567 return X;
Chris Lattnere0bb9eb2002-09-02 00:18:22 +0000568}
569
Dan Gohman5035fbf2009-07-09 22:07:27 +0000570ConstantRange
Nick Lewyckyd385c222010-08-11 22:04:36 +0000571ConstantRange::sub(const ConstantRange &Other) const {
572 if (isEmptySet() || Other.isEmptySet())
573 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
574 if (isFullSet() || Other.isFullSet())
575 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
576
577 APInt Spread_X = getSetSize(), Spread_Y = Other.getSetSize();
Nick Lewycky5dc6b792011-06-22 21:13:46 +0000578 APInt NewLower = getLower() - Other.getUpper() + 1;
579 APInt NewUpper = getUpper() - Other.getLower();
Nick Lewyckyd385c222010-08-11 22:04:36 +0000580 if (NewLower == NewUpper)
581 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
582
583 ConstantRange X = ConstantRange(NewLower, NewUpper);
584 if (X.getSetSize().ult(Spread_X) || X.getSetSize().ult(Spread_Y))
585 // We've wrapped, therefore, full set.
586 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
587
588 return X;
589}
590
591ConstantRange
Dan Gohman5035fbf2009-07-09 22:07:27 +0000592ConstantRange::multiply(const ConstantRange &Other) const {
Dan Gohman3f8ed9e2010-01-26 15:56:18 +0000593 // TODO: If either operand is a single element and the multiply is known to
594 // be non-wrapping, round the result min and max value to the appropriate
595 // multiple of that element. If wrapping is possible, at least adjust the
596 // range according to the greatest power-of-two factor of the single element.
Dan Gohman5325efc2010-01-26 04:13:15 +0000597
Nick Lewycky2951c992009-07-12 02:19:05 +0000598 if (isEmptySet() || Other.isEmptySet())
599 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
Nuno Lopes986cc182012-07-16 20:47:16 +0000600
James Molloydcc78ec2015-03-06 15:50:47 +0000601 // Multiplication is signedness-independent. However different ranges can be
602 // obtained depending on how the input ranges are treated. These different
603 // ranges are all conservatively correct, but one might be better than the
604 // other. We calculate two ranges; one treating the inputs as unsigned
605 // and the other signed, then return the smallest of these ranges.
606
607 // Unsigned range first.
Nick Lewycky53023892009-07-13 03:27:41 +0000608 APInt this_min = getUnsignedMin().zext(getBitWidth() * 2);
609 APInt this_max = getUnsignedMax().zext(getBitWidth() * 2);
610 APInt Other_min = Other.getUnsignedMin().zext(getBitWidth() * 2);
611 APInt Other_max = Other.getUnsignedMax().zext(getBitWidth() * 2);
Nick Lewycky2951c992009-07-12 02:19:05 +0000612
Nick Lewycky53023892009-07-13 03:27:41 +0000613 ConstantRange Result_zext = ConstantRange(this_min * Other_min,
614 this_max * Other_max + 1);
James Molloydcc78ec2015-03-06 15:50:47 +0000615 ConstantRange UR = Result_zext.truncate(getBitWidth());
616
617 // Now the signed range. Because we could be dealing with negative numbers
618 // here, the lower bound is the smallest of the cartesian product of the
619 // lower and upper ranges; for example:
620 // [-1,4) * [-2,3) = min(-1*-2, -1*2, 3*-2, 3*2) = -6.
621 // Similarly for the upper bound, swapping min for max.
622
623 this_min = getSignedMin().sext(getBitWidth() * 2);
624 this_max = getSignedMax().sext(getBitWidth() * 2);
625 Other_min = Other.getSignedMin().sext(getBitWidth() * 2);
626 Other_max = Other.getSignedMax().sext(getBitWidth() * 2);
627
628 auto L = {this_min * Other_min, this_min * Other_max,
629 this_max * Other_min, this_max * Other_max};
630 auto Compare = [](const APInt &A, const APInt &B) { return A.slt(B); };
631 ConstantRange Result_sext(std::min(L, Compare), std::max(L, Compare) + 1);
632 ConstantRange SR = Result_sext.truncate(getBitWidth());
633
634 return UR.getSetSize().ult(SR.getSetSize()) ? UR : SR;
Dan Gohman5035fbf2009-07-09 22:07:27 +0000635}
636
637ConstantRange
638ConstantRange::smax(const ConstantRange &Other) const {
Dan Gohmandc33ae22009-07-09 23:16:10 +0000639 // X smax Y is: range(smax(X_smin, Y_smin),
640 // smax(X_smax, Y_smax))
641 if (isEmptySet() || Other.isEmptySet())
642 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
Dan Gohmandc33ae22009-07-09 23:16:10 +0000643 APInt NewL = APIntOps::smax(getSignedMin(), Other.getSignedMin());
644 APInt NewU = APIntOps::smax(getSignedMax(), Other.getSignedMax()) + 1;
645 if (NewU == NewL)
646 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
647 return ConstantRange(NewL, NewU);
Dan Gohman5035fbf2009-07-09 22:07:27 +0000648}
649
650ConstantRange
651ConstantRange::umax(const ConstantRange &Other) const {
652 // X umax Y is: range(umax(X_umin, Y_umin),
653 // umax(X_umax, Y_umax))
654 if (isEmptySet() || Other.isEmptySet())
655 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
Dan Gohman5035fbf2009-07-09 22:07:27 +0000656 APInt NewL = APIntOps::umax(getUnsignedMin(), Other.getUnsignedMin());
657 APInt NewU = APIntOps::umax(getUnsignedMax(), Other.getUnsignedMax()) + 1;
658 if (NewU == NewL)
659 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
660 return ConstantRange(NewL, NewU);
661}
662
663ConstantRange
Nick Lewyckyf1b8cb32009-07-12 05:18:18 +0000664ConstantRange::udiv(const ConstantRange &RHS) const {
665 if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax() == 0)
666 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
667 if (RHS.isFullSet())
668 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
669
670 APInt Lower = getUnsignedMin().udiv(RHS.getUnsignedMax());
671
672 APInt RHS_umin = RHS.getUnsignedMin();
673 if (RHS_umin == 0) {
674 // We want the lowest value in RHS excluding zero. Usually that would be 1
675 // except for a range in the form of [X, 1) in which case it would be X.
676 if (RHS.getUpper() == 1)
677 RHS_umin = RHS.getLower();
678 else
679 RHS_umin = APInt(getBitWidth(), 1);
680 }
681
682 APInt Upper = getUnsignedMax().udiv(RHS_umin) + 1;
683
684 // If the LHS is Full and the RHS is a wrapped interval containing 1 then
685 // this could occur.
686 if (Lower == Upper)
687 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
688
689 return ConstantRange(Lower, Upper);
Dan Gohman5035fbf2009-07-09 22:07:27 +0000690}
691
Nuno Lopes60d5b1c2009-11-12 14:53:53 +0000692ConstantRange
Nick Lewyckyad48e012010-09-07 05:39:02 +0000693ConstantRange::binaryAnd(const ConstantRange &Other) const {
694 if (isEmptySet() || Other.isEmptySet())
695 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
696
697 // TODO: replace this with something less conservative
698
699 APInt umin = APIntOps::umin(Other.getUnsignedMax(), getUnsignedMax());
700 if (umin.isAllOnesValue())
701 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
702 return ConstantRange(APInt::getNullValue(getBitWidth()), umin + 1);
703}
704
705ConstantRange
706ConstantRange::binaryOr(const ConstantRange &Other) const {
707 if (isEmptySet() || Other.isEmptySet())
708 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
709
710 // TODO: replace this with something less conservative
711
712 APInt umax = APIntOps::umax(getUnsignedMin(), Other.getUnsignedMin());
713 if (umax.isMinValue())
714 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
715 return ConstantRange(umax, APInt::getNullValue(getBitWidth()));
716}
717
718ConstantRange
Nick Lewyckyd385c222010-08-11 22:04:36 +0000719ConstantRange::shl(const ConstantRange &Other) const {
720 if (isEmptySet() || Other.isEmptySet())
721 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
Nuno Lopes60d5b1c2009-11-12 14:53:53 +0000722
Nick Lewyckyd385c222010-08-11 22:04:36 +0000723 APInt min = getUnsignedMin().shl(Other.getUnsignedMin());
724 APInt max = getUnsignedMax().shl(Other.getUnsignedMax());
Nuno Lopes60d5b1c2009-11-12 14:53:53 +0000725
726 // there's no overflow!
Nuno Lopesf8fcac72009-11-12 15:10:33 +0000727 APInt Zeros(getBitWidth(), getUnsignedMax().countLeadingZeros());
Nick Lewyckyd385c222010-08-11 22:04:36 +0000728 if (Zeros.ugt(Other.getUnsignedMax()))
729 return ConstantRange(min, max + 1);
Nuno Lopes60d5b1c2009-11-12 14:53:53 +0000730
731 // FIXME: implement the other tricky cases
Nick Lewyckyd385c222010-08-11 22:04:36 +0000732 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
Nuno Lopes60d5b1c2009-11-12 14:53:53 +0000733}
734
735ConstantRange
Nick Lewyckyd385c222010-08-11 22:04:36 +0000736ConstantRange::lshr(const ConstantRange &Other) const {
737 if (isEmptySet() || Other.isEmptySet())
738 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
Nuno Lopes60d5b1c2009-11-12 14:53:53 +0000739
Nick Lewyckyd385c222010-08-11 22:04:36 +0000740 APInt max = getUnsignedMax().lshr(Other.getUnsignedMin());
741 APInt min = getUnsignedMin().lshr(Other.getUnsignedMax());
742 if (min == max + 1)
743 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
744
745 return ConstantRange(min, max + 1);
Nuno Lopes60d5b1c2009-11-12 14:53:53 +0000746}
747
Owen Anderson1a9078b2010-08-07 05:47:46 +0000748ConstantRange ConstantRange::inverse() const {
Nick Lewycky228f5b42012-01-03 20:33:00 +0000749 if (isFullSet())
Nick Lewyckyd385c222010-08-11 22:04:36 +0000750 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
Nick Lewycky228f5b42012-01-03 20:33:00 +0000751 if (isEmptySet())
Nick Lewyckyd385c222010-08-11 22:04:36 +0000752 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
Owen Anderson1a9078b2010-08-07 05:47:46 +0000753 return ConstantRange(Upper, Lower);
754}
755
Dan Gohmandc33ae22009-07-09 23:16:10 +0000756/// print - Print out the bounds to a stream...
Chris Lattnere0bb9eb2002-09-02 00:18:22 +0000757///
Dan Gohmandc33ae22009-07-09 23:16:10 +0000758void ConstantRange::print(raw_ostream &OS) const {
Dan Gohman837ada72010-01-26 04:12:55 +0000759 if (isFullSet())
760 OS << "full-set";
761 else if (isEmptySet())
762 OS << "empty-set";
763 else
764 OS << "[" << Lower << "," << Upper << ")";
Dan Gohman5035fbf2009-07-09 22:07:27 +0000765}
766
Dan Gohmandc33ae22009-07-09 23:16:10 +0000767/// dump - Allow printing from a debugger easily...
Dan Gohman5035fbf2009-07-09 22:07:27 +0000768///
Dan Gohmandc33ae22009-07-09 23:16:10 +0000769void ConstantRange::dump() const {
David Greenede7b3532010-01-05 01:28:32 +0000770 print(dbgs());
Dan Gohman5035fbf2009-07-09 22:07:27 +0000771}