[llvm-branch-commits] [llvm-branch] r73302 - in /llvm/branches/Apple/Bender: include/llvm/Analysis/ScalarEvolution.h lib/Analysis/ScalarEvolution.cpp

Bill Wendling isanbard at gmail.com
Sat Jun 13 13:27:09 PDT 2009


Author: void
Date: Sat Jun 13 15:27:09 2009
New Revision: 73302

URL: http://llvm.org/viewvc/llvm-project?rev=73302&view=rev
Log:
Apply r71259 to Bender branch.


Modified:
    llvm/branches/Apple/Bender/include/llvm/Analysis/ScalarEvolution.h
    llvm/branches/Apple/Bender/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/branches/Apple/Bender/include/llvm/Analysis/ScalarEvolution.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender/include/llvm/Analysis/ScalarEvolution.h?rev=73302&r1=73301&r2=73302&view=diff

==============================================================================
--- llvm/branches/Apple/Bender/include/llvm/Analysis/ScalarEvolution.h (original)
+++ llvm/branches/Apple/Bender/include/llvm/Analysis/ScalarEvolution.h Sat Jun 13 15:27:09 2009
@@ -228,6 +228,11 @@
     /// exit value.
     std::map<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
 
+    /// ValuesAtScopes - This map contains entries for all the instructions
+    /// that we attempt to compute getSCEVAtScope information for without
+    /// using SCEV techniques, which can be expensive.
+    std::map<Instruction *, std::map<const Loop *, Constant *> > ValuesAtScopes;
+
     /// createSCEV - We know that there is no SCEV for the specified value.
     /// Analyze the expression.
     SCEVHandle createSCEV(Value *V);

Modified: llvm/branches/Apple/Bender/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender/lib/Analysis/ScalarEvolution.cpp?rev=73302&r1=73301&r2=73302&view=diff

==============================================================================
--- llvm/branches/Apple/Bender/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/branches/Apple/Bender/lib/Analysis/ScalarEvolution.cpp Sat Jun 13 15:27:09 2009
@@ -1482,6 +1482,8 @@
   if (Scalars.erase(V)) {
     if (PHINode *PN = dyn_cast<PHINode>(V))
       ConstantEvolutionLoopExitValue.erase(PN);
+    if (Instruction *I = dyn_cast<Instruction>(V))
+      ValuesAtScopes.erase(I);
     Worklist.push_back(V);
   }
 
@@ -1495,6 +1497,8 @@
       if (Scalars.erase(Inst)) {
         if (PHINode *PN = dyn_cast<PHINode>(VV))
           ConstantEvolutionLoopExitValue.erase(PN);
+        if (Instruction *I = dyn_cast<Instruction>(VV))
+          ValuesAtScopes.erase(I);
         Worklist.push_back(Inst);
       }
     }
@@ -2607,6 +2611,13 @@
       // the arguments into constants, and if so, try to constant propagate the
       // result.  This is particularly useful for computing loop exit values.
       if (CanConstantFold(I)) {
+        // Check to see if we've folded this instruction at this loop before.
+        std::map<const Loop *, Constant *> &Values = ValuesAtScopes[I];
+        std::pair<std::map<const Loop *, Constant *>::iterator, bool> Pair =
+          Values.insert(std::make_pair(L, static_cast<Constant *>(0)));
+        if (!Pair.second)
+          return Pair.first->second ? &*getUnknown(Pair.first->second) : V;
+
         std::vector<Constant*> Operands;
         Operands.reserve(I->getNumOperands());
         for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
@@ -2646,6 +2657,7 @@
         else
           C = ConstantFoldInstOperands(I->getOpcode(), I->getType(),
                                        &Operands[0], Operands.size());
+        Pair.first->second = C;
         return getUnknown(C);
       }
     }
@@ -3275,6 +3287,7 @@
   Scalars.clear();
   BackedgeTakenCounts.clear();
   ConstantEvolutionLoopExitValue.clear();
+  ValuesAtScopes.clear();
 }
 
 void ScalarEvolution::getAnalysisUsage(AnalysisUsage &AU) const {





More information about the llvm-branch-commits mailing list