Add a ScalarEvolution::getCouldNotCompute() function, and use it
instead of allocating and leaking new SCEVCouldNotCompute objects.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69452 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index a3a6ff3..6f9905d 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -569,7 +569,7 @@
   // Protection from insane SCEVs; this bound is conservative,
   // but it probably doesn't matter.
   if (K > 1000)
-    return new SCEVCouldNotCompute();
+    return SE.getCouldNotCompute();
 
   unsigned W = SE.getTargetData().getTypeSizeInBits(ResultTy);
 
@@ -1337,7 +1337,6 @@
   return Result;
 }
 
-
 //===----------------------------------------------------------------------===//
 //             ScalarEvolutionsImpl Definition and Implementation
 //===----------------------------------------------------------------------===//
@@ -1386,6 +1385,8 @@
                          TargetData &td)
       : SE(se), F(f), LI(li), TD(td), UnknownValue(new SCEVCouldNotCompute()) {}
 
+    SCEVHandle getCouldNotCompute();
+
     /// getIntegerSCEV - Given an integer or FP type, create a constant for the
     /// specified signed integer value and return a SCEV for the constant.
     SCEVHandle getIntegerSCEV(int Val, const Type *Ty);
@@ -1577,6 +1578,10 @@
   return TD;
 }
 
+SCEVHandle ScalarEvolutionsImpl::getCouldNotCompute() {
+  return UnknownValue;
+}
+
 /// getSCEV - Return an existing SCEV if it exists, otherwise analyze the
 /// expression and create a new one.
 SCEVHandle ScalarEvolutionsImpl::getSCEV(Value *V) {
@@ -2732,7 +2737,7 @@
   // B is divisible by D if and only if the multiplicity of prime factor 2 for B
   // is not less than multiplicity of this prime factor for D.
   if (B.countTrailingZeros() < Mult2)
-    return new SCEVCouldNotCompute();
+    return SE.getCouldNotCompute();
 
   // 3. Compute I: the multiplicative inverse of (A / D) in arithmetic
   // modulo (N / D).
@@ -2766,7 +2771,7 @@
 
   // We currently can only solve this if the coefficients are constants.
   if (!LC || !MC || !NC) {
-    SCEV *CNC = new SCEVCouldNotCompute();
+    SCEV *CNC = SE.getCouldNotCompute();
     return std::make_pair(CNC, CNC);
   }
 
@@ -2802,7 +2807,7 @@
     APInt NegB(-B);
     APInt TwoA( A << 1 );
     if (TwoA.isMinValue()) {
-      SCEV *CNC = new SCEVCouldNotCompute();
+      SCEV *CNC = SE.getCouldNotCompute();
       return std::make_pair(CNC, CNC);
     }
 
@@ -3093,7 +3098,7 @@
 SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
                                                    ScalarEvolution &SE) const {
   if (Range.isFullSet())  // Infinite loop.
-    return new SCEVCouldNotCompute();
+    return SE.getCouldNotCompute();
 
   // If the start is a non-zero constant, shift the range to simplify things.
   if (SCEVConstant *SC = dyn_cast<SCEVConstant>(getStart()))
@@ -3105,14 +3110,14 @@
         return ShiftedAddRec->getNumIterationsInRange(
                            Range.subtract(SC->getValue()->getValue()), SE);
       // This is strange and shouldn't happen.
-      return new SCEVCouldNotCompute();
+      return SE.getCouldNotCompute();
     }
 
   // The only time we can solve this is when we have all constant indices.
   // Otherwise, we cannot determine the overflow conditions.
   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
     if (!isa<SCEVConstant>(getOperand(i)))
-      return new SCEVCouldNotCompute();
+      return SE.getCouldNotCompute();
 
 
   // Okay at this point we know that all elements of the chrec are constants and
@@ -3145,7 +3150,7 @@
     // things must have happened.
     ConstantInt *Val = EvaluateConstantChrecAtConstant(this, ExitValue, SE);
     if (Range.contains(Val->getValue()))
-      return new SCEVCouldNotCompute();  // Something strange happened
+      return SE.getCouldNotCompute();  // Something strange happened
 
     // Ensure that the previous value is in the range.  This is a sanity check.
     assert(Range.contains(
@@ -3188,7 +3193,7 @@
           R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE);
           if (!Range.contains(R1Val->getValue()))
             return SE.getConstant(NextVal);
-          return new SCEVCouldNotCompute();  // Something strange happened
+          return SE.getCouldNotCompute();  // Something strange happened
         }
 
         // If R1 was not in the range, then it is a good return value.  Make
@@ -3197,12 +3202,12 @@
         R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE);
         if (Range.contains(R1Val->getValue()))
           return R1;
-        return new SCEVCouldNotCompute();  // Something strange happened
+        return SE.getCouldNotCompute();  // Something strange happened
       }
     }
   }
 
-  return new SCEVCouldNotCompute();
+  return SE.getCouldNotCompute();
 }
 
 
@@ -3233,6 +3238,10 @@
   return ((ScalarEvolutionsImpl*)Impl)->getTargetData();
 }
 
+SCEVHandle ScalarEvolution::getCouldNotCompute() {
+  return ((ScalarEvolutionsImpl*)Impl)->getCouldNotCompute();
+}
+
 SCEVHandle ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) {
   return ((ScalarEvolutionsImpl*)Impl)->getIntegerSCEV(Val, Ty);
 }