Add Loop Pass Manager.
[oota-llvm.git] / lib / Analysis / LoopPass.cpp
1 //===- LoopPass.cpp - Loop Pass and Loop Pass Manager ---------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Devang Patel and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements LoopPass and LPPassManager. All loop optimization
11 // and transformation passes are derived from LoopPass. LPPassManager is
12 // responsible for managing LoopPasses.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "llvm/Analysis/LoopPass.h"
17 using namespace llvm;
18
19 //===----------------------------------------------------------------------===//
20 // LPPassManager
21 //
22 /// LPPassManager manages FPPassManagers and CalLGraphSCCPasses.
23
24 /// run - Execute all of the passes scheduled for execution.  Keep track of
25 /// whether any of the passes modifies the function, and if so, return true.
26 bool LPPassManager::runOnFunction(Function &F) {
27   LoopInfo &LI = getAnalysis<LoopInfo>();
28   bool Changed = false;
29
30   std::string Msg1 = "Executing Pass '";
31   std::string Msg3 = "' Made Modification '";
32
33   // Walk Loops
34   for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I) {
35
36     Loop *L  = *I;
37     // Run all passes on current SCC
38     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {  
39
40       Pass *P = getContainedPass(Index);
41       AnalysisUsage AnUsage;
42       P->getAnalysisUsage(AnUsage);
43
44       std::string Msg2 = "' on Loop ...\n'";
45       dumpPassInfo(P, Msg1, Msg2);
46       dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet());
47
48       initializeAnalysisImpl(P);
49
50       StartPassTimer(P);
51       LoopPass *LP = dynamic_cast<LoopPass *>(P);
52       assert (LP && "Invalid LPPassManager member");
53       LP->runOnLoop(*L, *this);
54       StopPassTimer(P);
55
56       if (Changed)
57         dumpPassInfo(P, Msg3, Msg2);
58       dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet());
59       
60       removeNotPreservedAnalysis(P);
61       recordAvailableAnalysis(P);
62       removeDeadPasses(P, Msg2);
63     }
64   }
65
66   return Changed;
67 }
68
69