1 //===- LoopPass.h - LoopPass class ----------------------------------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines LoopPass class. All loop optimization
11 // and transformation passes are derived from LoopPass.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LOOP_PASS_H
16 #define LLVM_LOOP_PASS_H
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Pass.h"
20 #include "llvm/PassManagers.h"
21 #include "llvm/Function.h"
29 class LoopPass : public Pass {
32 // runOnLoop - THis method should be implemented by the subclass to perform
33 // whatever action is necessary for the specfied Loop.
34 virtual bool runOnLoop (Loop *L, LPPassManager &LPM) = 0;
35 virtual bool runOnFunctionBody (Function &F, LPPassManager &LPM) {
39 /// Assign pass manager to manager this pass
40 virtual void assignPassManager(PMStack &PMS,
41 PassManagerType PMT = PMT_LoopPassManager);
45 class LPPassManager : public FunctionPass, public PMDataManager {
48 LPPassManager(int Depth);
50 /// run - Execute all of the passes scheduled for execution. Keep track of
51 /// whether any of the passes modifies the module, and if so, return true.
52 bool runOnFunction(Function &F);
54 /// Pass Manager itself does not invalidate any analysis info.
55 void getAnalysisUsage(AnalysisUsage &Info) const {
56 // LPPassManager needs LoopInfo. In the long term LoopInfo class will
57 // be consumed by LPPassManager.
58 Info.addRequired<LoopInfo>();
59 Info.setPreservesAll();
62 virtual const char *getPassName() const {
63 return "Loop Pass Manager";
66 // Print passes managed by this manager
67 void dumpPassStructure(unsigned Offset) {
68 llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n";
69 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
70 Pass *P = getContainedPass(Index);
71 P->dumpPassStructure(Offset + 1);
72 dumpLastUses(P, Offset+1);
76 Pass *getContainedPass(unsigned N) {
77 assert ( N < PassVector.size() && "Pass number out of range!");
78 Pass *FP = static_cast<Pass *>(PassVector[N]);
82 virtual PassManagerType getPassManagerType() const {
83 return PMT_LoopPassManager;
87 // Delete loop from the loop queue. This is used by Loop pass to inform
88 // Loop Pass Manager that it should skip rest of the passes for this loop.
89 void deleteLoopFromQueue(Loop *L);
91 // Reoptimize this loop. LPPassManager will re-insert this loop into the
92 // queue. This allows LoopPass to change loop nest for the loop. This
93 // utility may send LPPassManager into infinite loops so use caution.
94 void redoLoop(Loop *L);
96 std::deque<Loop *> LQ;
101 } // End llvm namespace