2002-09-01 23:53:36 +00:00
|
|
|
//===-- ConstantRange.cpp - ConstantRange implementation ------------------===//
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-09-01 23:53:36 +00:00
|
|
|
//
|
|
|
|
// Represent a range of possible values that may occur when the program is run
|
|
|
|
// for an integral value. This keeps track of a lower and upper bound for the
|
|
|
|
// constant, which MAY wrap around the end of the numeric range. To do this, it
|
|
|
|
// keeps track of a [lower, upper) bound, which specifies an interval just like
|
|
|
|
// STL iterators. When used with boolean values, the following are important
|
|
|
|
// ranges (other integral ranges use min/max values for special range values):
|
|
|
|
//
|
|
|
|
// [F, F) = {} = Empty set
|
|
|
|
// [T, F) = {T}
|
|
|
|
// [F, T) = {F}
|
|
|
|
// [T, T) = {F, T} = Full set
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/ConstantRange.h"
|
2004-01-12 20:13:04 +00:00
|
|
|
#include "llvm/Constants.h"
|
2002-09-01 23:53:36 +00:00
|
|
|
#include "llvm/Instruction.h"
|
2006-12-23 06:05:41 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2004-01-12 20:13:04 +00:00
|
|
|
#include "llvm/Type.h"
|
2006-11-28 22:46:12 +00:00
|
|
|
#include "llvm/Support/Streams.h"
|
|
|
|
#include <ostream>
|
2003-12-14 21:35:53 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2007-01-11 12:24:14 +00:00
|
|
|
static ConstantInt *getMaxValue(const Type *Ty, bool isSigned = false) {
|
2006-12-23 06:05:41 +00:00
|
|
|
if (Ty == Type::BoolTy)
|
2007-01-11 12:24:14 +00:00
|
|
|
return ConstantInt::getTrue();
|
2006-12-23 06:05:41 +00:00
|
|
|
if (Ty->isInteger()) {
|
|
|
|
if (isSigned) {
|
|
|
|
// Calculate 011111111111111...
|
2007-01-08 01:26:33 +00:00
|
|
|
unsigned TypeBits = Ty->getPrimitiveSizeInBits();
|
2006-12-23 06:05:41 +00:00
|
|
|
int64_t Val = INT64_MAX; // All ones
|
|
|
|
Val >>= 64-TypeBits; // Shift out unwanted 1 bits...
|
|
|
|
return ConstantInt::get(Ty, Val);
|
|
|
|
}
|
|
|
|
return ConstantInt::getAllOnesValue(Ty);
|
2006-12-06 20:45:15 +00:00
|
|
|
}
|
2006-12-23 06:05:41 +00:00
|
|
|
return 0;
|
2006-12-06 20:45:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Static constructor to create the minimum constant for an integral type...
|
2007-01-11 12:24:14 +00:00
|
|
|
static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) {
|
2006-12-23 06:05:41 +00:00
|
|
|
if (Ty == Type::BoolTy)
|
2007-01-11 12:24:14 +00:00
|
|
|
return ConstantInt::getFalse();
|
2006-12-23 06:05:41 +00:00
|
|
|
if (Ty->isInteger()) {
|
|
|
|
if (isSigned) {
|
|
|
|
// Calculate 1111111111000000000000
|
2007-01-08 01:26:33 +00:00
|
|
|
unsigned TypeBits = Ty->getPrimitiveSizeInBits();
|
2006-12-23 06:05:41 +00:00
|
|
|
int64_t Val = -1; // All ones
|
|
|
|
Val <<= TypeBits-1; // Shift over to the right spot
|
|
|
|
return ConstantInt::get(Ty, Val);
|
|
|
|
}
|
|
|
|
return ConstantInt::get(Ty, 0);
|
2006-12-06 20:45:15 +00:00
|
|
|
}
|
2006-12-23 06:05:41 +00:00
|
|
|
return 0;
|
2006-12-06 20:45:15 +00:00
|
|
|
}
|
2007-01-11 12:24:14 +00:00
|
|
|
static ConstantInt *Next(ConstantInt *CI) {
|
|
|
|
if (CI->getType() == Type::BoolTy)
|
|
|
|
return ConstantInt::get(!CI->getBoolValue());
|
2005-04-21 23:48:37 +00:00
|
|
|
|
2004-03-30 00:20:08 +00:00
|
|
|
Constant *Result = ConstantExpr::getAdd(CI,
|
|
|
|
ConstantInt::get(CI->getType(), 1));
|
2007-01-11 12:24:14 +00:00
|
|
|
return cast<ConstantInt>(Result);
|
2004-03-30 00:20:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 12:24:14 +00:00
|
|
|
static bool LT(ConstantInt *A, ConstantInt *B, bool isSigned) {
|
2006-12-23 06:05:41 +00:00
|
|
|
Constant *C = ConstantExpr::getICmp(
|
|
|
|
(isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
|
2007-01-11 12:24:14 +00:00
|
|
|
assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
|
|
|
|
return cast<ConstantInt>(C)->getBoolValue();
|
2004-01-12 20:13:04 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 12:24:14 +00:00
|
|
|
static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) {
|
2006-12-23 06:05:41 +00:00
|
|
|
Constant *C = ConstantExpr::getICmp(
|
|
|
|
(isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
|
2007-01-11 12:24:14 +00:00
|
|
|
assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
|
|
|
|
return cast<ConstantInt>(C)->getBoolValue();
|
2004-01-12 20:13:04 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 12:24:14 +00:00
|
|
|
static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) {
|
2006-12-23 06:05:41 +00:00
|
|
|
return LT(B, A, isSigned); }
|
2004-03-30 00:20:08 +00:00
|
|
|
|
2007-01-11 12:24:14 +00:00
|
|
|
static ConstantInt *Min(ConstantInt *A, ConstantInt *B,
|
2006-12-23 06:05:41 +00:00
|
|
|
bool isSigned) {
|
|
|
|
return LT(A, B, isSigned) ? A : B;
|
2004-01-12 20:13:04 +00:00
|
|
|
}
|
2007-01-11 12:24:14 +00:00
|
|
|
static ConstantInt *Max(ConstantInt *A, ConstantInt *B,
|
2006-12-23 06:05:41 +00:00
|
|
|
bool isSigned) {
|
|
|
|
return GT(A, B, isSigned) ? A : B;
|
2004-01-12 20:13:04 +00:00
|
|
|
}
|
|
|
|
|
2002-09-01 23:53:36 +00:00
|
|
|
/// Initialize a full (the default) or empty set for the specified type.
|
|
|
|
///
|
|
|
|
ConstantRange::ConstantRange(const Type *Ty, bool Full) {
|
|
|
|
assert(Ty->isIntegral() &&
|
|
|
|
"Cannot make constant range of non-integral type!");
|
|
|
|
if (Full)
|
2006-12-06 20:45:15 +00:00
|
|
|
Lower = Upper = getMaxValue(Ty);
|
2002-09-01 23:53:36 +00:00
|
|
|
else
|
2006-12-06 20:45:15 +00:00
|
|
|
Lower = Upper = getMinValue(Ty);
|
2002-09-01 23:53:36 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 00:20:08 +00:00
|
|
|
/// Initialize a range to hold the single specified value.
|
|
|
|
///
|
2006-12-23 06:05:41 +00:00
|
|
|
ConstantRange::ConstantRange(Constant *V)
|
2007-01-11 12:24:14 +00:00
|
|
|
: Lower(cast<ConstantInt>(V)), Upper(Next(cast<ConstantInt>(V))) { }
|
2004-03-30 00:20:08 +00:00
|
|
|
|
2002-09-01 23:53:36 +00:00
|
|
|
/// Initialize a range of values explicitly... this will assert out if
|
|
|
|
/// Lower==Upper and Lower != Min or Max for its type (or if the two constants
|
|
|
|
/// have different types)
|
|
|
|
///
|
2006-12-23 06:05:41 +00:00
|
|
|
ConstantRange::ConstantRange(Constant *L, Constant *U)
|
2007-01-11 12:24:14 +00:00
|
|
|
: Lower(cast<ConstantInt>(L)), Upper(cast<ConstantInt>(U)) {
|
2002-09-01 23:53:36 +00:00
|
|
|
assert(Lower->getType() == Upper->getType() &&
|
|
|
|
"Incompatible types for ConstantRange!");
|
2005-04-21 23:48:37 +00:00
|
|
|
|
2002-09-01 23:53:36 +00:00
|
|
|
// Make sure that if L & U are equal that they are either Min or Max...
|
2006-12-06 20:45:15 +00:00
|
|
|
assert((L != U || (L == getMaxValue(L->getType()) ||
|
2006-12-23 06:05:41 +00:00
|
|
|
L == getMinValue(L->getType())))
|
|
|
|
&& "Lower == Upper, but they aren't min or max for type!");
|
2002-09-01 23:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Initialize a set of values that all satisfy the condition with C.
|
|
|
|
///
|
2007-01-11 12:24:14 +00:00
|
|
|
ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantInt *C) {
|
2006-12-23 06:05:41 +00:00
|
|
|
switch (ICmpOpcode) {
|
|
|
|
default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!");
|
|
|
|
case ICmpInst::ICMP_EQ: Lower = C; Upper = Next(C); return;
|
|
|
|
case ICmpInst::ICMP_NE: Upper = C; Lower = Next(C); return;
|
|
|
|
case ICmpInst::ICMP_ULT:
|
2006-12-06 20:45:15 +00:00
|
|
|
Lower = getMinValue(C->getType());
|
2002-09-01 23:53:36 +00:00
|
|
|
Upper = C;
|
|
|
|
return;
|
2006-12-23 06:05:41 +00:00
|
|
|
case ICmpInst::ICMP_SLT:
|
|
|
|
Lower = getMinValue(C->getType(), true);
|
|
|
|
Upper = C;
|
|
|
|
return;
|
|
|
|
case ICmpInst::ICMP_UGT:
|
|
|
|
Lower = Next(C);
|
|
|
|
Upper = getMinValue(C->getType()); // Min = Next(Max)
|
|
|
|
return;
|
|
|
|
case ICmpInst::ICMP_SGT:
|
2002-09-01 23:53:36 +00:00
|
|
|
Lower = Next(C);
|
2006-12-23 06:05:41 +00:00
|
|
|
Upper = getMinValue(C->getType(), true); // Min = Next(Max)
|
2002-09-01 23:53:36 +00:00
|
|
|
return;
|
2006-12-23 06:05:41 +00:00
|
|
|
case ICmpInst::ICMP_ULE:
|
2006-12-06 20:45:15 +00:00
|
|
|
Lower = getMinValue(C->getType());
|
2002-09-01 23:53:36 +00:00
|
|
|
Upper = Next(C);
|
|
|
|
return;
|
2006-12-23 06:05:41 +00:00
|
|
|
case ICmpInst::ICMP_SLE:
|
|
|
|
Lower = getMinValue(C->getType(), true);
|
|
|
|
Upper = Next(C);
|
|
|
|
return;
|
|
|
|
case ICmpInst::ICMP_UGE:
|
|
|
|
Lower = C;
|
|
|
|
Upper = getMinValue(C->getType()); // Min = Next(Max)
|
|
|
|
return;
|
|
|
|
case ICmpInst::ICMP_SGE:
|
2002-09-01 23:53:36 +00:00
|
|
|
Lower = C;
|
2006-12-23 06:05:41 +00:00
|
|
|
Upper = getMinValue(C->getType(), true); // Min = Next(Max)
|
2002-09-01 23:53:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getType - Return the LLVM data type of this range.
|
|
|
|
///
|
|
|
|
const Type *ConstantRange::getType() const { return Lower->getType(); }
|
|
|
|
|
|
|
|
/// isFullSet - Return true if this set contains all of the elements possible
|
|
|
|
/// for this data-type
|
|
|
|
bool ConstantRange::isFullSet() const {
|
2006-12-06 20:45:15 +00:00
|
|
|
return Lower == Upper && Lower == getMaxValue(getType());
|
2002-09-01 23:53:36 +00:00
|
|
|
}
|
2005-04-21 23:48:37 +00:00
|
|
|
|
2002-09-01 23:53:36 +00:00
|
|
|
/// isEmptySet - Return true if this set contains no members.
|
|
|
|
///
|
|
|
|
bool ConstantRange::isEmptySet() const {
|
2006-12-06 20:45:15 +00:00
|
|
|
return Lower == Upper && Lower == getMinValue(getType());
|
2002-09-01 23:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isWrappedSet - Return true if this set wraps around the top of the range,
|
|
|
|
/// for example: [100, 8)
|
|
|
|
///
|
2006-12-23 06:05:41 +00:00
|
|
|
bool ConstantRange::isWrappedSet(bool isSigned) const {
|
|
|
|
return GT(Lower, Upper, isSigned);
|
2002-09-01 23:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getSingleElement - If this set contains a single element, return it,
|
|
|
|
/// otherwise return null.
|
2007-01-11 12:24:14 +00:00
|
|
|
ConstantInt *ConstantRange::getSingleElement() const {
|
2002-09-01 23:53:36 +00:00
|
|
|
if (Upper == Next(Lower)) // Is it a single element range?
|
|
|
|
return Lower;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSetSize - Return the number of elements in this set.
|
|
|
|
///
|
|
|
|
uint64_t ConstantRange::getSetSize() const {
|
|
|
|
if (isEmptySet()) return 0;
|
|
|
|
if (getType() == Type::BoolTy) {
|
|
|
|
if (Lower != Upper) // One of T or F in the set...
|
|
|
|
return 1;
|
|
|
|
return 2; // Must be full set...
|
|
|
|
}
|
2005-04-21 23:48:37 +00:00
|
|
|
|
2002-09-01 23:53:36 +00:00
|
|
|
// Simply subtract the bounds...
|
2004-03-30 00:20:08 +00:00
|
|
|
Constant *Result = ConstantExpr::getSub(Upper, Lower);
|
2006-10-20 07:07:24 +00:00
|
|
|
return cast<ConstantInt>(Result)->getZExtValue();
|
2002-09-01 23:53:36 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 00:20:08 +00:00
|
|
|
/// contains - Return true if the specified value is in the set.
|
|
|
|
///
|
2006-12-23 06:05:41 +00:00
|
|
|
bool ConstantRange::contains(ConstantInt *Val, bool isSigned) const {
|
2004-03-30 00:20:08 +00:00
|
|
|
if (Lower == Upper) {
|
|
|
|
if (isFullSet()) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-12-23 06:05:41 +00:00
|
|
|
if (!isWrappedSet(isSigned))
|
|
|
|
return LTE(Lower, Val, isSigned) && LT(Val, Upper, isSigned);
|
|
|
|
return LTE(Lower, Val, isSigned) || LT(Val, Upper, isSigned);
|
2004-03-30 00:20:08 +00:00
|
|
|
}
|
2002-09-01 23:53:36 +00:00
|
|
|
|
2004-03-30 00:20:08 +00:00
|
|
|
/// subtract - Subtract the specified constant from the endpoints of this
|
|
|
|
/// constant range.
|
|
|
|
ConstantRange ConstantRange::subtract(ConstantInt *CI) const {
|
|
|
|
assert(CI->getType() == getType() && getType()->isInteger() &&
|
|
|
|
"Cannot subtract from different type range or non-integer!");
|
|
|
|
// If the set is empty or full, don't modify the endpoints.
|
|
|
|
if (Lower == Upper) return *this;
|
|
|
|
return ConstantRange(ConstantExpr::getSub(Lower, CI),
|
|
|
|
ConstantExpr::getSub(Upper, CI));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-01 23:53:36 +00:00
|
|
|
// intersect1Wrapped - This helper function is used to intersect two ranges when
|
|
|
|
// it is known that LHS is wrapped and RHS isn't.
|
|
|
|
//
|
|
|
|
static ConstantRange intersect1Wrapped(const ConstantRange &LHS,
|
2006-12-23 06:05:41 +00:00
|
|
|
const ConstantRange &RHS,
|
|
|
|
bool isSigned) {
|
|
|
|
assert(LHS.isWrappedSet(isSigned) && !RHS.isWrappedSet(isSigned));
|
2002-09-01 23:53:36 +00:00
|
|
|
|
|
|
|
// Check to see if we overlap on the Left side of RHS...
|
|
|
|
//
|
2006-12-23 06:05:41 +00:00
|
|
|
if (LT(RHS.getLower(), LHS.getUpper(), isSigned)) {
|
2002-09-01 23:53:36 +00:00
|
|
|
// We do overlap on the left side of RHS, see if we overlap on the right of
|
|
|
|
// RHS...
|
2006-12-23 06:05:41 +00:00
|
|
|
if (GT(RHS.getUpper(), LHS.getLower(), isSigned)) {
|
2002-09-01 23:53:36 +00:00
|
|
|
// Ok, the result overlaps on both the left and right sides. See if the
|
|
|
|
// resultant interval will be smaller if we wrap or not...
|
|
|
|
//
|
|
|
|
if (LHS.getSetSize() < RHS.getSetSize())
|
|
|
|
return LHS;
|
|
|
|
else
|
|
|
|
return RHS;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// No overlap on the right, just on the left.
|
|
|
|
return ConstantRange(RHS.getLower(), LHS.getUpper());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We don't overlap on the left side of RHS, see if we overlap on the right
|
|
|
|
// of RHS...
|
2006-12-23 06:05:41 +00:00
|
|
|
if (GT(RHS.getUpper(), LHS.getLower(), isSigned)) {
|
2002-09-01 23:53:36 +00:00
|
|
|
// Simple overlap...
|
|
|
|
return ConstantRange(LHS.getLower(), RHS.getUpper());
|
|
|
|
} else {
|
|
|
|
// No overlap...
|
|
|
|
return ConstantRange(LHS.getType(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// intersect - Return the range that results from the intersection of this
|
|
|
|
/// range with another range.
|
|
|
|
///
|
2006-12-23 06:05:41 +00:00
|
|
|
ConstantRange ConstantRange::intersectWith(const ConstantRange &CR,
|
|
|
|
bool isSigned) const {
|
2002-09-01 23:53:36 +00:00
|
|
|
assert(getType() == CR.getType() && "ConstantRange types don't agree!");
|
2002-09-02 20:49:27 +00:00
|
|
|
// Handle common special cases
|
|
|
|
if (isEmptySet() || CR.isFullSet()) return *this;
|
|
|
|
if (isFullSet() || CR.isEmptySet()) return CR;
|
2002-09-01 23:53:36 +00:00
|
|
|
|
2006-12-23 06:05:41 +00:00
|
|
|
if (!isWrappedSet(isSigned)) {
|
|
|
|
if (!CR.isWrappedSet(isSigned)) {
|
2007-01-11 12:24:14 +00:00
|
|
|
ConstantInt *L = Max(Lower, CR.Lower, isSigned);
|
|
|
|
ConstantInt *U = Min(Upper, CR.Upper, isSigned);
|
2002-09-01 23:53:36 +00:00
|
|
|
|
2006-12-23 06:05:41 +00:00
|
|
|
if (LT(L, U, isSigned)) // If range isn't empty...
|
2002-09-02 20:49:27 +00:00
|
|
|
return ConstantRange(L, U);
|
2002-09-01 23:53:36 +00:00
|
|
|
else
|
|
|
|
return ConstantRange(getType(), false); // Otherwise, return empty set
|
|
|
|
} else
|
2006-12-23 06:05:41 +00:00
|
|
|
return intersect1Wrapped(CR, *this, isSigned);
|
2002-09-01 23:53:36 +00:00
|
|
|
} else { // We know "this" is wrapped...
|
2006-12-23 06:05:41 +00:00
|
|
|
if (!CR.isWrappedSet(isSigned))
|
|
|
|
return intersect1Wrapped(*this, CR, isSigned);
|
2002-09-01 23:53:36 +00:00
|
|
|
else {
|
|
|
|
// Both ranges are wrapped...
|
2007-01-11 12:24:14 +00:00
|
|
|
ConstantInt *L = Max(Lower, CR.Lower, isSigned);
|
|
|
|
ConstantInt *U = Min(Upper, CR.Upper, isSigned);
|
2002-09-02 20:49:27 +00:00
|
|
|
return ConstantRange(L, U);
|
2002-09-01 23:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// union - Return the range that results from the union of this range with
|
|
|
|
/// another range. The resultant range is guaranteed to include the elements of
|
|
|
|
/// both sets, but may contain more. For example, [3, 9) union [12,15) is [3,
|
|
|
|
/// 15), which includes 9, 10, and 11, which were not included in either set
|
|
|
|
/// before.
|
|
|
|
///
|
2006-12-23 06:05:41 +00:00
|
|
|
ConstantRange ConstantRange::unionWith(const ConstantRange &CR,
|
|
|
|
bool isSigned) const {
|
2002-09-01 23:53:36 +00:00
|
|
|
assert(getType() == CR.getType() && "ConstantRange types don't agree!");
|
|
|
|
|
|
|
|
assert(0 && "Range union not implemented yet!");
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2002-09-02 00:18:22 +00:00
|
|
|
|
2004-03-30 00:20:08 +00:00
|
|
|
/// zeroExtend - Return a new range in the specified integer type, which must
|
|
|
|
/// be strictly larger than the current type. The returned range will
|
2006-12-23 06:05:41 +00:00
|
|
|
/// correspond to the possible range of values as if the source range had been
|
2004-03-30 00:20:08 +00:00
|
|
|
/// zero extended.
|
|
|
|
ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
|
2007-01-08 01:26:33 +00:00
|
|
|
unsigned SrcTySize = getLower()->getType()->getPrimitiveSizeInBits();
|
|
|
|
assert(SrcTySize < Ty->getPrimitiveSizeInBits() && "Not a value extension");
|
2004-03-30 00:20:08 +00:00
|
|
|
if (isFullSet()) {
|
|
|
|
// Change a source full set into [0, 1 << 8*numbytes)
|
|
|
|
return ConstantRange(Constant::getNullValue(Ty),
|
2007-01-08 01:26:33 +00:00
|
|
|
ConstantInt::get(Ty, 1ULL << SrcTySize));
|
2004-03-30 00:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Constant *Lower = getLower();
|
|
|
|
Constant *Upper = getUpper();
|
|
|
|
|
2006-12-12 23:36:14 +00:00
|
|
|
return ConstantRange(ConstantExpr::getZExt(Lower, Ty),
|
|
|
|
ConstantExpr::getZExt(Upper, Ty));
|
2004-03-30 00:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// truncate - Return a new range in the specified integer type, which must be
|
|
|
|
/// strictly smaller than the current type. The returned range will
|
2006-12-23 06:05:41 +00:00
|
|
|
/// correspond to the possible range of values as if the source range had been
|
2004-03-30 00:20:08 +00:00
|
|
|
/// truncated to the specified type.
|
|
|
|
ConstantRange ConstantRange::truncate(const Type *Ty) const {
|
2007-01-08 01:26:33 +00:00
|
|
|
unsigned SrcTySize = getLower()->getType()->getPrimitiveSizeInBits();
|
2007-01-08 05:34:39 +00:00
|
|
|
assert(SrcTySize > Ty->getPrimitiveSizeInBits() && "Not a value truncation");
|
2007-01-08 01:26:33 +00:00
|
|
|
uint64_t Size = 1ULL << Ty->getPrimitiveSizeInBits();
|
2004-03-30 00:20:08 +00:00
|
|
|
if (isFullSet() || getSetSize() >= Size)
|
|
|
|
return ConstantRange(getType());
|
|
|
|
|
2006-12-04 02:46:44 +00:00
|
|
|
return ConstantRange(
|
2006-12-12 23:36:14 +00:00
|
|
|
ConstantExpr::getTrunc(getLower(), Ty),
|
|
|
|
ConstantExpr::getTrunc(getUpper(), Ty));
|
2004-03-30 00:20:08 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 00:18:22 +00:00
|
|
|
/// print - Print out the bounds to a stream...
|
|
|
|
///
|
|
|
|
void ConstantRange::print(std::ostream &OS) const {
|
2004-07-15 01:29:12 +00:00
|
|
|
OS << "[" << *Lower << "," << *Upper << " )";
|
2002-09-02 00:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// dump - Allow printing from a debugger easily...
|
|
|
|
///
|
|
|
|
void ConstantRange::dump() const {
|
2006-12-07 01:30:32 +00:00
|
|
|
print(cerr);
|
2002-09-02 00:18:22 +00:00
|
|
|
}
|