Eliminate ConstantBool::True and ConstantBool::False.  Instead, provide
ConstantBool::getTrue() and ConstantBool::getFalse().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30666 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 289297c..2f8edd9 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -1689,7 +1689,7 @@
     // 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()
@@ -2168,7 +2168,7 @@
       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
@@ -2198,7 +2198,7 @@
   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.
   }
@@ -2386,7 +2386,7 @@
       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
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 3308b9a..d187125 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -26,10 +26,6 @@
 #include <iostream>
 using namespace llvm;
 
-ConstantBool *ConstantBool::True  = new ConstantBool(true);
-ConstantBool *ConstantBool::False = new ConstantBool(false);
-
-
 //===----------------------------------------------------------------------===//
 //                              Constant Class
 //===----------------------------------------------------------------------===//
@@ -128,7 +124,7 @@
 // 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:
@@ -152,7 +148,7 @@
 // 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:
@@ -176,7 +172,7 @@
 // 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:
@@ -877,6 +873,20 @@
   };
 }
 
+
+//---- 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;
@@ -1380,7 +1390,7 @@
     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);