blob: 378ae767ff245ea2ccbefa8dd36b8f668169f2e5 [file] [log] [blame]
Chris Lattner645e00d2002-09-01 23:53:36 +00001//===-- ConstantRange.cpp - ConstantRange implementation ------------------===//
Misha Brukmanfd939082005-04-21 23:48:37 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanfd939082005-04-21 23:48:37 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner645e00d2002-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
24#include "llvm/Support/ConstantRange.h"
Chris Lattner67bb7602004-01-12 20:13:04 +000025#include "llvm/Constants.h"
Chris Lattner645e00d2002-09-01 23:53:36 +000026#include "llvm/Instruction.h"
Reid Spencere4d87aa2006-12-23 06:05:41 +000027#include "llvm/Instructions.h"
Chris Lattner67bb7602004-01-12 20:13:04 +000028#include "llvm/Type.h"
Bill Wendling6f81b512006-11-28 22:46:12 +000029#include "llvm/Support/Streams.h"
30#include <ostream>
Chris Lattner2cdd21c2003-12-14 21:35:53 +000031using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000032
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000033static ConstantInt *getMaxValue(const Type *Ty, bool isSigned = false) {
Chris Lattner07627052007-01-15 01:02:34 +000034 if (Ty->isIntegral()) {
Reid Spencere4d87aa2006-12-23 06:05:41 +000035 if (isSigned) {
36 // Calculate 011111111111111...
Reid Spencere7ca0422007-01-08 01:26:33 +000037 unsigned TypeBits = Ty->getPrimitiveSizeInBits();
Reid Spencere4d87aa2006-12-23 06:05:41 +000038 int64_t Val = INT64_MAX; // All ones
39 Val >>= 64-TypeBits; // Shift out unwanted 1 bits...
40 return ConstantInt::get(Ty, Val);
41 }
42 return ConstantInt::getAllOnesValue(Ty);
Reid Spencerc6bf4bf2006-12-06 20:45:15 +000043 }
Reid Spencere4d87aa2006-12-23 06:05:41 +000044 return 0;
Reid Spencerc6bf4bf2006-12-06 20:45:15 +000045}
46
47// Static constructor to create the minimum constant for an integral type...
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000048static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) {
Chris Lattner07627052007-01-15 01:02:34 +000049 if (Ty->isIntegral()) {
Reid Spencere4d87aa2006-12-23 06:05:41 +000050 if (isSigned) {
51 // Calculate 1111111111000000000000
Reid Spencere7ca0422007-01-08 01:26:33 +000052 unsigned TypeBits = Ty->getPrimitiveSizeInBits();
Reid Spencere4d87aa2006-12-23 06:05:41 +000053 int64_t Val = -1; // All ones
54 Val <<= TypeBits-1; // Shift over to the right spot
55 return ConstantInt::get(Ty, Val);
56 }
57 return ConstantInt::get(Ty, 0);
Reid Spencerc6bf4bf2006-12-06 20:45:15 +000058 }
Reid Spencere4d87aa2006-12-23 06:05:41 +000059 return 0;
Reid Spencerc6bf4bf2006-12-06 20:45:15 +000060}
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000061static ConstantInt *Next(ConstantInt *CI) {
Chris Lattnerfc33d302004-03-30 00:20:08 +000062 Constant *Result = ConstantExpr::getAdd(CI,
63 ConstantInt::get(CI->getType(), 1));
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000064 return cast<ConstantInt>(Result);
Chris Lattnerfc33d302004-03-30 00:20:08 +000065}
66
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000067static bool LT(ConstantInt *A, ConstantInt *B, bool isSigned) {
Reid Spencere4d87aa2006-12-23 06:05:41 +000068 Constant *C = ConstantExpr::getICmp(
69 (isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000070 assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
Reid Spencer579dca12007-01-12 04:24:46 +000071 return cast<ConstantInt>(C)->getZExtValue();
Chris Lattner67bb7602004-01-12 20:13:04 +000072}
73
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000074static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) {
Reid Spencere4d87aa2006-12-23 06:05:41 +000075 Constant *C = ConstantExpr::getICmp(
76 (isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000077 assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
Reid Spencer579dca12007-01-12 04:24:46 +000078 return cast<ConstantInt>(C)->getZExtValue();
Chris Lattner67bb7602004-01-12 20:13:04 +000079}
80
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000081static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) {
Reid Spencere4d87aa2006-12-23 06:05:41 +000082 return LT(B, A, isSigned); }
Chris Lattnerfc33d302004-03-30 00:20:08 +000083
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000084static ConstantInt *Min(ConstantInt *A, ConstantInt *B,
Reid Spencere4d87aa2006-12-23 06:05:41 +000085 bool isSigned) {
86 return LT(A, B, isSigned) ? A : B;
Chris Lattner67bb7602004-01-12 20:13:04 +000087}
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +000088static ConstantInt *Max(ConstantInt *A, ConstantInt *B,
Reid Spencere4d87aa2006-12-23 06:05:41 +000089 bool isSigned) {
90 return GT(A, B, isSigned) ? A : B;
Chris Lattner67bb7602004-01-12 20:13:04 +000091}
92
Chris Lattner645e00d2002-09-01 23:53:36 +000093/// Initialize a full (the default) or empty set for the specified type.
94///
95ConstantRange::ConstantRange(const Type *Ty, bool Full) {
96 assert(Ty->isIntegral() &&
97 "Cannot make constant range of non-integral type!");
98 if (Full)
Reid Spencerc6bf4bf2006-12-06 20:45:15 +000099 Lower = Upper = getMaxValue(Ty);
Chris Lattner645e00d2002-09-01 23:53:36 +0000100 else
Reid Spencerc6bf4bf2006-12-06 20:45:15 +0000101 Lower = Upper = getMinValue(Ty);
Chris Lattner645e00d2002-09-01 23:53:36 +0000102}
103
Chris Lattnerfc33d302004-03-30 00:20:08 +0000104/// Initialize a range to hold the single specified value.
105///
Reid Spencere4d87aa2006-12-23 06:05:41 +0000106ConstantRange::ConstantRange(Constant *V)
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +0000107 : Lower(cast<ConstantInt>(V)), Upper(Next(cast<ConstantInt>(V))) { }
Chris Lattnerfc33d302004-03-30 00:20:08 +0000108
Chris Lattner645e00d2002-09-01 23:53:36 +0000109/// Initialize a range of values explicitly... this will assert out if
110/// Lower==Upper and Lower != Min or Max for its type (or if the two constants
111/// have different types)
112///
Reid Spencere4d87aa2006-12-23 06:05:41 +0000113ConstantRange::ConstantRange(Constant *L, Constant *U)
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +0000114 : Lower(cast<ConstantInt>(L)), Upper(cast<ConstantInt>(U)) {
Chris Lattner645e00d2002-09-01 23:53:36 +0000115 assert(Lower->getType() == Upper->getType() &&
116 "Incompatible types for ConstantRange!");
Misha Brukmanfd939082005-04-21 23:48:37 +0000117
Chris Lattner645e00d2002-09-01 23:53:36 +0000118 // Make sure that if L & U are equal that they are either Min or Max...
Reid Spencerc6bf4bf2006-12-06 20:45:15 +0000119 assert((L != U || (L == getMaxValue(L->getType()) ||
Reid Spencere4d87aa2006-12-23 06:05:41 +0000120 L == getMinValue(L->getType())))
121 && "Lower == Upper, but they aren't min or max for type!");
Chris Lattner645e00d2002-09-01 23:53:36 +0000122}
123
Chris Lattner645e00d2002-09-01 23:53:36 +0000124/// Initialize a set of values that all satisfy the condition with C.
125///
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +0000126ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantInt *C) {
Reid Spencere4d87aa2006-12-23 06:05:41 +0000127 switch (ICmpOpcode) {
128 default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!");
129 case ICmpInst::ICMP_EQ: Lower = C; Upper = Next(C); return;
130 case ICmpInst::ICMP_NE: Upper = C; Lower = Next(C); return;
131 case ICmpInst::ICMP_ULT:
Reid Spencerc6bf4bf2006-12-06 20:45:15 +0000132 Lower = getMinValue(C->getType());
Chris Lattner645e00d2002-09-01 23:53:36 +0000133 Upper = C;
134 return;
Reid Spencere4d87aa2006-12-23 06:05:41 +0000135 case ICmpInst::ICMP_SLT:
136 Lower = getMinValue(C->getType(), true);
137 Upper = C;
Chris Lattner645e00d2002-09-01 23:53:36 +0000138 return;
Reid Spencere4d87aa2006-12-23 06:05:41 +0000139 case ICmpInst::ICMP_UGT:
140 Lower = Next(C);
141 Upper = getMinValue(C->getType()); // Min = Next(Max)
142 return;
143 case ICmpInst::ICMP_SGT:
144 Lower = Next(C);
145 Upper = getMinValue(C->getType(), true); // Min = Next(Max)
146 return;
147 case ICmpInst::ICMP_ULE:
Reid Spencerc6bf4bf2006-12-06 20:45:15 +0000148 Lower = getMinValue(C->getType());
Chris Lattner645e00d2002-09-01 23:53:36 +0000149 Upper = Next(C);
150 return;
Reid Spencere4d87aa2006-12-23 06:05:41 +0000151 case ICmpInst::ICMP_SLE:
152 Lower = getMinValue(C->getType(), true);
153 Upper = Next(C);
154 return;
155 case ICmpInst::ICMP_UGE:
Chris Lattner645e00d2002-09-01 23:53:36 +0000156 Lower = C;
Reid Spencere4d87aa2006-12-23 06:05:41 +0000157 Upper = getMinValue(C->getType()); // Min = Next(Max)
158 return;
159 case ICmpInst::ICMP_SGE:
160 Lower = C;
161 Upper = getMinValue(C->getType(), true); // Min = Next(Max)
Chris Lattner645e00d2002-09-01 23:53:36 +0000162 return;
163 }
164}
165
166/// getType - Return the LLVM data type of this range.
167///
168const Type *ConstantRange::getType() const { return Lower->getType(); }
169
170/// isFullSet - Return true if this set contains all of the elements possible
171/// for this data-type
172bool ConstantRange::isFullSet() const {
Reid Spencerc6bf4bf2006-12-06 20:45:15 +0000173 return Lower == Upper && Lower == getMaxValue(getType());
Chris Lattner645e00d2002-09-01 23:53:36 +0000174}
Misha Brukmanfd939082005-04-21 23:48:37 +0000175
Chris Lattner645e00d2002-09-01 23:53:36 +0000176/// isEmptySet - Return true if this set contains no members.
177///
178bool ConstantRange::isEmptySet() const {
Reid Spencerc6bf4bf2006-12-06 20:45:15 +0000179 return Lower == Upper && Lower == getMinValue(getType());
Chris Lattner645e00d2002-09-01 23:53:36 +0000180}
181
182/// isWrappedSet - Return true if this set wraps around the top of the range,
183/// for example: [100, 8)
184///
Reid Spencere4d87aa2006-12-23 06:05:41 +0000185bool ConstantRange::isWrappedSet(bool isSigned) const {
186 return GT(Lower, Upper, isSigned);
Chris Lattner645e00d2002-09-01 23:53:36 +0000187}
188
Chris Lattner645e00d2002-09-01 23:53:36 +0000189/// getSingleElement - If this set contains a single element, return it,
190/// otherwise return null.
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +0000191ConstantInt *ConstantRange::getSingleElement() const {
Chris Lattner645e00d2002-09-01 23:53:36 +0000192 if (Upper == Next(Lower)) // Is it a single element range?
193 return Lower;
194 return 0;
195}
196
197/// getSetSize - Return the number of elements in this set.
198///
199uint64_t ConstantRange::getSetSize() const {
200 if (isEmptySet()) return 0;
Reid Spencer4fe16d62007-01-11 18:21:29 +0000201 if (getType() == Type::Int1Ty) {
Chris Lattner645e00d2002-09-01 23:53:36 +0000202 if (Lower != Upper) // One of T or F in the set...
203 return 1;
204 return 2; // Must be full set...
205 }
Misha Brukmanfd939082005-04-21 23:48:37 +0000206
Chris Lattner645e00d2002-09-01 23:53:36 +0000207 // Simply subtract the bounds...
Chris Lattnerfc33d302004-03-30 00:20:08 +0000208 Constant *Result = ConstantExpr::getSub(Upper, Lower);
Reid Spencerb83eb642006-10-20 07:07:24 +0000209 return cast<ConstantInt>(Result)->getZExtValue();
Chris Lattner645e00d2002-09-01 23:53:36 +0000210}
211
Chris Lattnerfc33d302004-03-30 00:20:08 +0000212/// contains - Return true if the specified value is in the set.
213///
Reid Spencere4d87aa2006-12-23 06:05:41 +0000214bool ConstantRange::contains(ConstantInt *Val, bool isSigned) const {
Chris Lattnerfc33d302004-03-30 00:20:08 +0000215 if (Lower == Upper) {
216 if (isFullSet()) return true;
217 return false;
218 }
Chris Lattner645e00d2002-09-01 23:53:36 +0000219
Reid Spencere4d87aa2006-12-23 06:05:41 +0000220 if (!isWrappedSet(isSigned))
221 return LTE(Lower, Val, isSigned) && LT(Val, Upper, isSigned);
222 return LTE(Lower, Val, isSigned) || LT(Val, Upper, isSigned);
Chris Lattnerfc33d302004-03-30 00:20:08 +0000223}
224
Chris Lattnerfc33d302004-03-30 00:20:08 +0000225/// subtract - Subtract the specified constant from the endpoints of this
226/// constant range.
227ConstantRange ConstantRange::subtract(ConstantInt *CI) const {
228 assert(CI->getType() == getType() && getType()->isInteger() &&
229 "Cannot subtract from different type range or non-integer!");
230 // If the set is empty or full, don't modify the endpoints.
231 if (Lower == Upper) return *this;
232 return ConstantRange(ConstantExpr::getSub(Lower, CI),
233 ConstantExpr::getSub(Upper, CI));
234}
Chris Lattner645e00d2002-09-01 23:53:36 +0000235
236
237// intersect1Wrapped - This helper function is used to intersect two ranges when
238// it is known that LHS is wrapped and RHS isn't.
239//
240static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000241 const ConstantRange &RHS,
242 bool isSigned) {
243 assert(LHS.isWrappedSet(isSigned) && !RHS.isWrappedSet(isSigned));
Chris Lattner645e00d2002-09-01 23:53:36 +0000244
Chris Lattner645e00d2002-09-01 23:53:36 +0000245 // Check to see if we overlap on the Left side of RHS...
246 //
Reid Spencere4d87aa2006-12-23 06:05:41 +0000247 if (LT(RHS.getLower(), LHS.getUpper(), isSigned)) {
Chris Lattner645e00d2002-09-01 23:53:36 +0000248 // We do overlap on the left side of RHS, see if we overlap on the right of
249 // RHS...
Reid Spencere4d87aa2006-12-23 06:05:41 +0000250 if (GT(RHS.getUpper(), LHS.getLower(), isSigned)) {
Chris Lattner645e00d2002-09-01 23:53:36 +0000251 // Ok, the result overlaps on both the left and right sides. See if the
252 // resultant interval will be smaller if we wrap or not...
253 //
254 if (LHS.getSetSize() < RHS.getSetSize())
255 return LHS;
256 else
257 return RHS;
258
259 } else {
260 // No overlap on the right, just on the left.
261 return ConstantRange(RHS.getLower(), LHS.getUpper());
262 }
Chris Lattner645e00d2002-09-01 23:53:36 +0000263 } else {
264 // We don't overlap on the left side of RHS, see if we overlap on the right
265 // of RHS...
Reid Spencere4d87aa2006-12-23 06:05:41 +0000266 if (GT(RHS.getUpper(), LHS.getLower(), isSigned)) {
Chris Lattner645e00d2002-09-01 23:53:36 +0000267 // Simple overlap...
268 return ConstantRange(LHS.getLower(), RHS.getUpper());
269 } else {
270 // No overlap...
271 return ConstantRange(LHS.getType(), false);
272 }
273 }
274}
275
Chris Lattner645e00d2002-09-01 23:53:36 +0000276/// intersect - Return the range that results from the intersection of this
277/// range with another range.
278///
Reid Spencere4d87aa2006-12-23 06:05:41 +0000279ConstantRange ConstantRange::intersectWith(const ConstantRange &CR,
280 bool isSigned) const {
Chris Lattner645e00d2002-09-01 23:53:36 +0000281 assert(getType() == CR.getType() && "ConstantRange types don't agree!");
Chris Lattnerd122f4b2002-09-02 20:49:27 +0000282 // Handle common special cases
283 if (isEmptySet() || CR.isFullSet()) return *this;
284 if (isFullSet() || CR.isEmptySet()) return CR;
Chris Lattner645e00d2002-09-01 23:53:36 +0000285
Reid Spencere4d87aa2006-12-23 06:05:41 +0000286 if (!isWrappedSet(isSigned)) {
287 if (!CR.isWrappedSet(isSigned)) {
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +0000288 ConstantInt *L = Max(Lower, CR.Lower, isSigned);
289 ConstantInt *U = Min(Upper, CR.Upper, isSigned);
Chris Lattner645e00d2002-09-01 23:53:36 +0000290
Reid Spencere4d87aa2006-12-23 06:05:41 +0000291 if (LT(L, U, isSigned)) // If range isn't empty...
Chris Lattnerd122f4b2002-09-02 20:49:27 +0000292 return ConstantRange(L, U);
Chris Lattner645e00d2002-09-01 23:53:36 +0000293 else
294 return ConstantRange(getType(), false); // Otherwise, return empty set
295 } else
Reid Spencere4d87aa2006-12-23 06:05:41 +0000296 return intersect1Wrapped(CR, *this, isSigned);
Chris Lattner645e00d2002-09-01 23:53:36 +0000297 } else { // We know "this" is wrapped...
Reid Spencere4d87aa2006-12-23 06:05:41 +0000298 if (!CR.isWrappedSet(isSigned))
299 return intersect1Wrapped(*this, CR, isSigned);
Chris Lattner645e00d2002-09-01 23:53:36 +0000300 else {
301 // Both ranges are wrapped...
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +0000302 ConstantInt *L = Max(Lower, CR.Lower, isSigned);
303 ConstantInt *U = Min(Upper, CR.Upper, isSigned);
Chris Lattnerd122f4b2002-09-02 20:49:27 +0000304 return ConstantRange(L, U);
Chris Lattner645e00d2002-09-01 23:53:36 +0000305 }
306 }
307 return *this;
308}
309
310/// union - Return the range that results from the union of this range with
311/// another range. The resultant range is guaranteed to include the elements of
312/// both sets, but may contain more. For example, [3, 9) union [12,15) is [3,
313/// 15), which includes 9, 10, and 11, which were not included in either set
314/// before.
315///
Reid Spencere4d87aa2006-12-23 06:05:41 +0000316ConstantRange ConstantRange::unionWith(const ConstantRange &CR,
317 bool isSigned) const {
Chris Lattner645e00d2002-09-01 23:53:36 +0000318 assert(getType() == CR.getType() && "ConstantRange types don't agree!");
319
320 assert(0 && "Range union not implemented yet!");
321
322 return *this;
323}
Chris Lattner96f9d722002-09-02 00:18:22 +0000324
Chris Lattnerfc33d302004-03-30 00:20:08 +0000325/// zeroExtend - Return a new range in the specified integer type, which must
326/// be strictly larger than the current type. The returned range will
Reid Spencere4d87aa2006-12-23 06:05:41 +0000327/// correspond to the possible range of values as if the source range had been
Chris Lattnerfc33d302004-03-30 00:20:08 +0000328/// zero extended.
329ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
Reid Spencere7ca0422007-01-08 01:26:33 +0000330 unsigned SrcTySize = getLower()->getType()->getPrimitiveSizeInBits();
331 assert(SrcTySize < Ty->getPrimitiveSizeInBits() && "Not a value extension");
Chris Lattnerfc33d302004-03-30 00:20:08 +0000332 if (isFullSet()) {
333 // Change a source full set into [0, 1 << 8*numbytes)
Chris Lattnerfc33d302004-03-30 00:20:08 +0000334 return ConstantRange(Constant::getNullValue(Ty),
Reid Spencere7ca0422007-01-08 01:26:33 +0000335 ConstantInt::get(Ty, 1ULL << SrcTySize));
Chris Lattnerfc33d302004-03-30 00:20:08 +0000336 }
337
338 Constant *Lower = getLower();
339 Constant *Upper = getUpper();
Chris Lattnerfc33d302004-03-30 00:20:08 +0000340
Reid Spencerd977d862006-12-12 23:36:14 +0000341 return ConstantRange(ConstantExpr::getZExt(Lower, Ty),
342 ConstantExpr::getZExt(Upper, Ty));
Chris Lattnerfc33d302004-03-30 00:20:08 +0000343}
344
345/// truncate - Return a new range in the specified integer type, which must be
346/// strictly smaller than the current type. The returned range will
Reid Spencere4d87aa2006-12-23 06:05:41 +0000347/// correspond to the possible range of values as if the source range had been
Chris Lattnerfc33d302004-03-30 00:20:08 +0000348/// truncated to the specified type.
349ConstantRange ConstantRange::truncate(const Type *Ty) const {
Reid Spencere7ca0422007-01-08 01:26:33 +0000350 unsigned SrcTySize = getLower()->getType()->getPrimitiveSizeInBits();
Reid Spencerca7ad892007-01-08 05:34:39 +0000351 assert(SrcTySize > Ty->getPrimitiveSizeInBits() && "Not a value truncation");
Reid Spencere7ca0422007-01-08 01:26:33 +0000352 uint64_t Size = 1ULL << Ty->getPrimitiveSizeInBits();
Chris Lattnerfc33d302004-03-30 00:20:08 +0000353 if (isFullSet() || getSetSize() >= Size)
354 return ConstantRange(getType());
355
Reid Spencer575d95c2006-12-04 02:46:44 +0000356 return ConstantRange(
Reid Spencerd977d862006-12-12 23:36:14 +0000357 ConstantExpr::getTrunc(getLower(), Ty),
358 ConstantExpr::getTrunc(getUpper(), Ty));
Chris Lattnerfc33d302004-03-30 00:20:08 +0000359}
360
Chris Lattner96f9d722002-09-02 00:18:22 +0000361/// print - Print out the bounds to a stream...
362///
363void ConstantRange::print(std::ostream &OS) const {
Chris Lattnerce36d552004-07-15 01:29:12 +0000364 OS << "[" << *Lower << "," << *Upper << " )";
Chris Lattner96f9d722002-09-02 00:18:22 +0000365}
366
367/// dump - Allow printing from a debugger easily...
368///
369void ConstantRange::dump() const {
Bill Wendlinge8156192006-12-07 01:30:32 +0000370 print(cerr);
Chris Lattner96f9d722002-09-02 00:18:22 +0000371}