Now IndVarSimplify is a LoopPass.
authorDevang Patel <dpatel@apple.com>
Wed, 7 Mar 2007 06:39:01 +0000 (06:39 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 7 Mar 2007 06:39:01 +0000 (06:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35003 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Scalar.h
lib/Analysis/LoopPass.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp

index 4da6c99024d10e21c2c61543f2115d6ca419ab2d..a675730326392c1d8716206e07b971d9a35f83c8 100644 (file)
@@ -92,7 +92,7 @@ FunctionPass *createGCSEPass();
 // InductionVariableSimplify - Transform induction variables in a program to all
 // use a single canonical induction variable per loop.
 //
-FunctionPass *createIndVarSimplifyPass();
+LoopPass *createIndVarSimplifyPass();
 
 //===----------------------------------------------------------------------===//
 //
index ac2e32c51cfe08bfeea19dda8f13bdf461d671c1..fc431035c0729db33510b35707f04f389f0c6d98 100644 (file)
@@ -14,6 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/ScalarEvolutionExpander.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
@@ -148,6 +149,8 @@ void LPPassManager::getAnalysisUsage(AnalysisUsage &Info) const {
   // LPPassManager needs LoopInfo. In the long term LoopInfo class will 
   // become part of LPPassManager.
   Info.addRequired<LoopInfo>();
+  // Used by IndVar doInitialization.
+  Info.addRequired<ScalarEvolution>();
   Info.setPreservesAll();
 }
 
index c75627e3152c123d7e26f1e4f8524a048eda5b0b..aad6cc9a5e828e57774fcdfbf64a6f522641217b 100644 (file)
@@ -45,6 +45,7 @@
 #include "llvm/Type.h"
 #include "llvm/Analysis/ScalarEvolutionExpander.h"
 #include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/LoopPass.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
@@ -62,33 +63,26 @@ STATISTIC(NumReplaced, "Number of exit values replaced");
 STATISTIC(NumLFTR    , "Number of loop exit tests replaced");
 
 namespace {
-  class VISIBILITY_HIDDEN IndVarSimplify : public FunctionPass {
+  class VISIBILITY_HIDDEN IndVarSimplify : public LoopPass {
     LoopInfo        *LI;
     ScalarEvolution *SE;
     bool Changed;
   public:
-    virtual bool runOnFunction(Function &) {
-      LI = &getAnalysis<LoopInfo>();
-      SE = &getAnalysis<ScalarEvolution>();
-      Changed = false;
-
-      // Induction Variables live in the header nodes of loops
-      for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
-        runOnLoop(*I);
-      return Changed;
-    }
+    
+   bool runOnLoop(Loop *L, LPPassManager &LPM);
+   bool doInitialization(Loop *L, LPPassManager &LPM);
+   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+     AU.addRequiredID(LCSSAID);
+     AU.addRequiredID(LoopSimplifyID);
+     AU.addRequired<ScalarEvolution>();
+     AU.addRequired<LoopInfo>();
+     AU.addPreservedID(LoopSimplifyID);
+     AU.addPreservedID(LCSSAID);
+     AU.setPreservesCFG();
+   }
 
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequiredID(LCSSAID);
-      AU.addRequiredID(LoopSimplifyID);
-      AU.addRequired<ScalarEvolution>();
-      AU.addRequired<LoopInfo>();
-      AU.addPreservedID(LoopSimplifyID);
-      AU.addPreservedID(LCSSAID);
-      AU.setPreservesCFG();
-    }
   private:
-    void runOnLoop(Loop *L);
+
     void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader,
                                     std::set<Instruction*> &DeadInsts);
     Instruction *LinearFunctionTestReplace(Loop *L, SCEV *IterationCount,
@@ -100,7 +94,7 @@ namespace {
   RegisterPass<IndVarSimplify> X("indvars", "Canonicalize Induction Variables");
 }
 
-FunctionPass *llvm::createIndVarSimplifyPass() {
+LoopPass *llvm::createIndVarSimplifyPass() {
   return new IndVarSimplify();
 }
 
@@ -410,14 +404,16 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
   DeleteTriviallyDeadInstructions(InstructionsToDelete);
 }
 
+bool IndVarSimplify::doInitialization(Loop *L, LPPassManager &LPM) {
 
-void IndVarSimplify::runOnLoop(Loop *L) {
+  Changed = false;
   // First step.  Check to see if there are any trivial GEP pointer recurrences.
   // If there are, change them into integer recurrences, permitting analysis by
   // the SCEV routines.
   //
   BasicBlock *Header    = L->getHeader();
   BasicBlock *Preheader = L->getLoopPreheader();
+  SE = &LPM.getAnalysis<ScalarEvolution>();
 
   std::set<Instruction*> DeadInsts;
   for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
@@ -429,11 +425,19 @@ void IndVarSimplify::runOnLoop(Loop *L) {
   if (!DeadInsts.empty())
     DeleteTriviallyDeadInstructions(DeadInsts);
 
+  return Changed;
+}
+
+bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
+
 
-  // Next, transform all loops nesting inside of this loop.
-  for (LoopInfo::iterator I = L->begin(), E = L->end(); I != E; ++I)
-    runOnLoop(*I);
+  LI = &getAnalysis<LoopInfo>();
+  SE = &getAnalysis<ScalarEvolution>();
 
+  Changed = false;
+  BasicBlock *Header    = L->getHeader();
+  std::set<Instruction*> DeadInsts;
+  
   // Verify the input to the pass in already in LCSSA form.
   assert(L->isLCSSAForm());
 
@@ -483,7 +487,7 @@ void IndVarSimplify::runOnLoop(Loop *L) {
         DeleteTriviallyDeadInstructions(InstructionsToDelete);
       }
     }
-    return;
+    return Changed;
   }
 
   // Compute the type of the largest recurrence expression.
@@ -585,4 +589,5 @@ void IndVarSimplify::runOnLoop(Loop *L) {
   DeleteTriviallyDeadInstructions(DeadInsts);
   
   assert(L->isLCSSAForm());
+  return Changed;
 }