//===-- ConstantRange.cpp - ConstantRange implementation ------------------===//
-//
+//
// 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.
-//
+//
//===----------------------------------------------------------------------===//
//
// Represent a range of possible values that may occur when the program is run
using namespace llvm;
static ConstantIntegral *Next(ConstantIntegral *CI) {
- if (CI->getType() == Type::BoolTy)
- return CI == ConstantBool::True ? ConstantBool::False : ConstantBool::True;
-
+ if (ConstantBool *CB = dyn_cast<ConstantBool>(CI))
+ return ConstantBool::get(!CB->getValue());
+
Constant *Result = ConstantExpr::getAdd(CI,
ConstantInt::get(CI->getType(), 1));
return cast<ConstantIntegral>(Result);
: Lower(cast<ConstantIntegral>(L)), Upper(cast<ConstantIntegral>(U)) {
assert(Lower->getType() == Upper->getType() &&
"Incompatible types for ConstantRange!");
-
+
// Make sure that if L & U are equal that they are either Min or Max...
assert((L != U || (L == ConstantIntegral::getMaxValue(L->getType()) ||
L == ConstantIntegral::getMinValue(L->getType()))) &&
bool ConstantRange::isFullSet() const {
return Lower == Upper && Lower == ConstantIntegral::getMaxValue(getType());
}
-
+
/// isEmptySet - Return true if this set contains no members.
///
bool ConstantRange::isEmptySet() const {
return GT(Lower, Upper);
}
-
+
/// getSingleElement - If this set contains a single element, return it,
/// otherwise return null.
ConstantIntegral *ConstantRange::getSingleElement() const {
return 1;
return 2; // Must be full set...
}
-
+
// Simply subtract the bounds...
Constant *Result = ConstantExpr::getSub(Upper, Lower);
- return cast<ConstantInt>(Result)->getRawValue();
+ return cast<ConstantInt>(Result)->getZExtValue();
}
/// contains - Return true if the specified value is in the set.
// Change a source full set into [0, 1 << 8*numbytes)
unsigned SrcTySize = getLower()->getType()->getPrimitiveSize();
return ConstantRange(Constant::getNullValue(Ty),
- ConstantUInt::get(Ty, 1ULL << SrcTySize*8));
+ ConstantInt::get(Ty, 1ULL << SrcTySize*8));
}
Constant *Lower = getLower();