1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

- Added a new superclass of ConstantBool/ConstantInt: ConstantGenericIntegral

- Moved InstCombine: isMaxValue, isMinValue, isAllOnesValue to Constants.h

llvm-svn: 3293
This commit is contained in:
Chris Lattner 2002-08-12 21:21:21 +00:00
parent 1bbd2eadb6
commit 4fbca59155
2 changed files with 88 additions and 10 deletions

View File

@ -15,10 +15,49 @@ class ArrayType;
class StructType;
class PointerType;
//===---------------------------------------------------------------------------
// ConstantGenericIntegral - Shared superclass of boolean and integer constants.
//
// This class just defines some common interfaces to be implemented.
//
class ConstantGenericIntegral : public Constant {
protected:
ConstantGenericIntegral(const Type *Ty) : Constant(Ty) {}
public:
// isNullValue - Return true if this is the value that would be returned by
// getNullValue.
//
virtual bool isNullValue() const = 0;
// isMaxValue - Return true if this is the largest value that may be
// represented by this type.
//
virtual bool isMaxValue() const = 0;
// isMinValue - Return true if this is the smallest value that may be
// represented by this type.
//
virtual bool isMinValue() const = 0;
// isAllOnesValue - Return true if every bit in this constant is set to true.
//
virtual bool isAllOnesValue() const = 0;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantGenericIntegral *) { return true; }
static bool classof(const Constant *CPV); // defined in Constants.cpp
static inline bool classof(const Value *V) {
return isa<Constant>(V) && classof(cast<Constant>(V));
}
};
//===---------------------------------------------------------------------------
// ConstantBool - Boolean Values
//
class ConstantBool : public Constant {
class ConstantBool : public ConstantGenericIntegral {
bool Val;
ConstantBool(bool V);
~ConstantBool() {}
@ -36,7 +75,11 @@ public:
// isNullValue - Return true if this is the value that would be returned by
// getNullValue.
//
virtual bool isNullValue() const { return this == False; }
virtual bool isMaxValue() const { return this == True; }
virtual bool isMinValue() const { return this == False; }
virtual bool isAllOnesValue() const { return this == True; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantBool *) { return true; }
@ -53,7 +96,7 @@ public:
// ConstantInt - Superclass of ConstantSInt & ConstantUInt, to make dealing
// with integral constants easier.
//
class ConstantInt : public Constant {
class ConstantInt : public ConstantGenericIntegral {
protected:
union {
int64_t Signed;
@ -81,10 +124,13 @@ public:
// isNullValue - Return true if this is the value that would be returned by
// getNullValue.
virtual bool isNullValue() const { return Val.Unsigned == 0; }
virtual bool isAllOnesValue() const { return Val.Signed == -1; }
virtual bool isMaxValue() const = 0;
virtual bool isMinValue() const = 0;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantInt *) { return true; }
static bool classof(const Constant *CPV); // defined in CPV.cpp
static bool classof(const Constant *CPV); // defined in Constants.cpp
static inline bool classof(const Value *V) {
return isa<Constant>(V) && classof(cast<Constant>(V));
}
@ -105,9 +151,29 @@ public:
static bool isValueValidForType(const Type *Ty, int64_t V);
inline int64_t getValue() const { return Val.Signed; }
// isMaxValue - Return true if this is the largest value that may be
// represented by this type.
//
virtual bool isMaxValue() const {
int64_t V = getValue();
if (V < 0) return false; // Be careful about wrap-around on 'long's
++V;
return !isValueValidForType(getType(), V) || V < 0;
}
// isMinValue - Return true if this is the smallest value that may be
// represented by this type.
//
virtual bool isMinValue() const {
int64_t V = getValue();
if (V > 0) return false; // Be careful about wrap-around on 'long's
--V;
return !isValueValidForType(getType(), V) || V > 0;
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantSInt *) { return true; }
static bool classof(const Constant *CPV); // defined in CPV.cpp
static bool classof(const Constant *CPV); // defined in Constants.cpp
static inline bool classof(const Value *V) {
return isa<Constant>(V) && classof(cast<Constant>(V));
}
@ -127,9 +193,15 @@ public:
static bool isValueValidForType(const Type *Ty, uint64_t V);
inline uint64_t getValue() const { return Val.Unsigned; }
// isMaxValue - Return true if this is the largest value that may be
// represented by this type.
//
virtual bool isMaxValue() const { return isAllOnesValue(); }
virtual bool isMinValue() const { return getValue() == 0; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantUInt *) { return true; }
static bool classof(const Constant *CPV); // defined in CPV.cpp
static bool classof(const Constant *CPV); // defined in Constants.cpp
static inline bool classof(const Value *V) {
return isa<Constant>(V) && classof(cast<Constant>(V));
}
@ -157,7 +229,7 @@ public:
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantFP *) { return true; }
static bool classof(const Constant *CPV); // defined in CPV.cpp
static bool classof(const Constant *CPV); // defined in Constants.cpp
static inline bool classof(const Value *V) {
return isa<Constant>(V) && classof(cast<Constant>(V));
}
@ -190,7 +262,7 @@ public:
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantArray *) { return true; }
static bool classof(const Constant *CPV); // defined in CPV.cpp
static bool classof(const Constant *CPV); // defined in Constants.cpp
static inline bool classof(const Value *V) {
return isa<Constant>(V) && classof(cast<Constant>(V));
}
@ -223,7 +295,7 @@ public:
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantStruct *) { return true; }
static bool classof(const Constant *CPV); // defined in CPV.cpp
static bool classof(const Constant *CPV); // defined in Constants.cpp
static inline bool classof(const Value *V) {
return isa<Constant>(V) && classof(cast<Constant>(V));
}

View File

@ -93,11 +93,12 @@ void Constant::destroyConstantImpl() {
//===----------------------------------------------------------------------===//
// Normal Constructors
ConstantBool::ConstantBool(bool V) : Constant(Type::BoolTy) {
ConstantBool::ConstantBool(bool V) : ConstantGenericIntegral(Type::BoolTy) {
Val = V;
}
ConstantInt::ConstantInt(const Type *Ty, uint64_t V) : Constant(Ty) {
ConstantInt::ConstantInt(const Type *Ty, uint64_t V)
: ConstantGenericIntegral(Ty) {
Val.Unsigned = V;
}
@ -163,6 +164,11 @@ ConstantExpr::ConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
//===----------------------------------------------------------------------===//
// classof implementations
bool ConstantGenericIntegral::classof(const Constant *CPV) {
return (CPV->getType()->isIntegral() || CPV->getType() == Type::BoolTy) &&
!isa<ConstantExpr>(CPV);
}
bool ConstantInt::classof(const Constant *CPV) {
return CPV->getType()->isIntegral() && !isa<ConstantExpr>(CPV);
}