#ifndef CONSTANTRANGESSET_H_
#define CONSTANTRANGESSET_H_
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/LLVMContext.h"
#include <list>
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/LLVMContext.h"
-
namespace llvm {
// The IntItem is a wrapper for APInt.
IntType Low;
IntType High;
bool IsEmpty : 1;
- enum Type {
- SINGLE_NUMBER,
- RANGE,
- UNKNOWN
- };
- Type RangeType;
+ bool IsSingleNumber : 1;
public:
typedef IntRange<IntType> self;
IntRange() : IsEmpty(true) {}
IntRange(const self &RHS) :
Low(RHS.Low), High(RHS.High),
- IsEmpty(RHS.IsEmpty), RangeType(RHS.RangeType) {}
+ IsEmpty(RHS.IsEmpty), IsSingleNumber(RHS.IsSingleNumber) {}
IntRange(const IntType &C) :
- Low(C), High(C), IsEmpty(false), RangeType(SINGLE_NUMBER) {}
+ Low(C), High(C), IsEmpty(false), IsSingleNumber(true) {}
IntRange(const IntType &L, const IntType &H) : Low(L), High(H),
- IsEmpty(false), RangeType(UNKNOWN) {}
+ IsEmpty(false), IsSingleNumber(Low == High) {}
bool isEmpty() const { return IsEmpty; }
- bool isSingleNumber() const {
- switch (RangeType) {
- case SINGLE_NUMBER:
- return true;
- case RANGE:
- return false;
- default: // UNKNOWN
- if (Low == High) {
- const_cast<Type&>(RangeType) = SINGLE_NUMBER;
- return true;
- }
- const_cast<Type&>(RangeType) = RANGE;
- return false;
- }
- }
+ bool isSingleNumber() const { return IsSingleNumber; }
const IntType& getLow() const {
assert(!IsEmpty && "Range is empty.");
bool operator<(const self &RHS) const {
assert(!IsEmpty && "Left range is empty.");
assert(!RHS.IsEmpty && "Right range is empty.");
- if (Low < RHS.Low)
- return true;
if (Low == RHS.Low) {
if (High > RHS.High)
return true;
return false;
}
+ if (Low < RHS.Low)
+ return true;
return false;
}
unsigned getSize() const {
APInt sz(((const APInt&)getItem(0).getLow()).getBitWidth(), 0);
for (unsigned i = 0, e = getNumItems(); i != e; ++i) {
- const APInt &Low = getItem(i).getLow();
- const APInt &High = getItem(i).getHigh();
+ const APInt Low = getItem(i).getLow();
+ const APInt High = getItem(i).getHigh();
APInt S = High - Low + 1;
sz += S;
}
APInt getSingleValue(unsigned idx) const {
APInt sz(((const APInt&)getItem(0).getLow()).getBitWidth(), 0);
for (unsigned i = 0, e = getNumItems(); i != e; ++i) {
- const APInt &Low = getItem(i).getLow();
- const APInt &High = getItem(i).getHigh();
+ const APInt Low = getItem(i).getLow();
+ const APInt High = getItem(i).getHigh();
APInt S = High - Low + 1;
APInt oldSz = sz;
sz += S;
e = Src.end(); i != e; ++i) {
const Range &R = *i;
std::vector<Constant*> r;
- if (!R.isSingleNumber()) {
+ if (R.isSingleNumber()) {
r.reserve(2);
// FIXME: Since currently we have ConstantInt based numbers
// use hack-conversion of IntItem to ConstantInt