class ConstantBool : public ConstantIntegral {
ConstantBool(bool V);
public:
- static ConstantBool *True, *False; ///< The True & False values
+ /// getTrue/getFalse - Return the singleton true/false values.
+ static ConstantBool *getTrue();
+ static ConstantBool *getFalse();
/// This method is provided mostly for compatibility with the other
/// ConstantIntegral subclasses.
/// @brief Static factory method for getting a ConstantBool instance.
- static ConstantBool *get(bool Value) { return Value ? True : False; }
+ static ConstantBool *get(bool Value) { return Value ? getTrue() : getFalse();}
/// This method is provided mostly for compatibility with the other
/// ConstantIntegral subclasses.
/// Returns the opposite value of this ConstantBool value.
/// @brief Get inverse value.
- inline ConstantBool *inverted() const { return (this==True) ? False : True; }
+ inline ConstantBool *inverted() const {
+ return getValue() ? getFalse() : getTrue();
+ }
/// @returns the value of this ConstantBool
/// @brief return the boolean value of this constant.
/// @see ConstantIntegral for details
/// @brief Implement overrides
- 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; }
+ virtual bool isNullValue() const { return getValue() == false; }
+ virtual bool isMaxValue() const { return getValue() == true; }
+ virtual bool isMinValue() const { return getValue() == false; }
+ virtual bool isAllOnesValue() const { return getValue() == true; }
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantBool *) { return true; }
// Evaluate the condition for this iteration.
Result = ConstantExpr::get(SetCCOpcode, Result, RHS);
if (!isa<ConstantBool>(Result)) break; // Couldn't decide for sure
- if (Result == ConstantBool::False) {
+ if (cast<ConstantBool>(Result)->getValue() == false) {
#if 0
std::cerr << "\n***\n*** Computed loop count " << *ItCst
<< "\n*** From global " << *GV << "*** BB: " << *L->getHeader()
if (ConstantBool *CB =
dyn_cast<ConstantBool>(ConstantExpr::getSetLT(R1->getValue(),
R2->getValue()))) {
- if (CB != ConstantBool::True)
+ if (CB->getValue() == false)
std::swap(R1, R2); // R1 is the minimum root now.
// We can only use this value if the chrec ends up with an exact zero
if (SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
Constant *Zero = Constant::getNullValue(C->getValue()->getType());
Constant *NonZero = ConstantExpr::getSetNE(C->getValue(), Zero);
- if (NonZero == ConstantBool::True)
+ if (NonZero == ConstantBool::getTrue())
return getSCEV(Zero);
return UnknownValue; // Otherwise it will loop infinitely.
}
if (ConstantBool *CB =
dyn_cast<ConstantBool>(ConstantExpr::getSetLT(R1->getValue(),
R2->getValue()))) {
- if (CB != ConstantBool::True)
+ if (CB->getValue() == false)
std::swap(R1, R2); // R1 is the minimum root now.
// Make sure the root is not off by one. The returned iteration should
#include <iostream>
using namespace llvm;
-ConstantBool *ConstantBool::True = new ConstantBool(true);
-ConstantBool *ConstantBool::False = new ConstantBool(false);
-
-
//===----------------------------------------------------------------------===//
// Constant Class
//===----------------------------------------------------------------------===//
// Static constructor to create the maximum constant of an integral type...
ConstantIntegral *ConstantIntegral::getMaxValue(const Type *Ty) {
switch (Ty->getTypeID()) {
- case Type::BoolTyID: return ConstantBool::True;
+ case Type::BoolTyID: return ConstantBool::getTrue();
case Type::SByteTyID:
case Type::ShortTyID:
case Type::IntTyID:
// Static constructor to create the minimum constant for an integral type...
ConstantIntegral *ConstantIntegral::getMinValue(const Type *Ty) {
switch (Ty->getTypeID()) {
- case Type::BoolTyID: return ConstantBool::False;
+ case Type::BoolTyID: return ConstantBool::getFalse();
case Type::SByteTyID:
case Type::ShortTyID:
case Type::IntTyID:
// Static constructor to create an integral constant with all bits set
ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) {
switch (Ty->getTypeID()) {
- case Type::BoolTyID: return ConstantBool::True;
+ case Type::BoolTyID: return ConstantBool::getTrue();
case Type::SByteTyID:
case Type::ShortTyID:
case Type::IntTyID:
};
}
+
+//---- ConstantBool::get*() implementation.
+
+ConstantBool *ConstantBool::getTrue() {
+ static ConstantBool *T = 0;
+ if (T) return T;
+ return T = new ConstantBool(true);
+}
+ConstantBool *ConstantBool::getFalse() {
+ static ConstantBool *F = 0;
+ if (F) return F;
+ return F = new ConstantBool(false);
+}
+
//---- ConstantUInt::get() and ConstantSInt::get() implementations...
//
static ManagedStatic<ValueMap< int64_t, Type, ConstantSInt> > SIntConstants;
C = ConstantExpr::getCast(C, C->getType()->getSignedVersion());
return ConstantExpr::getCast(C, Ty);
} else {
- if (C == ConstantBool::True)
+ if (C == ConstantBool::getTrue())
return ConstantIntegral::getAllOnesValue(Ty);
else
return ConstantIntegral::getNullValue(Ty);