LoopPass.h revision d0e6e33043aa8cca678face8dce205155e2a69b3
1//===- LoopPass.h - LoopPass class ----------------------------------------===// 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 defines LoopPass class. All loop optimization 11// and transformation passes are derived from LoopPass. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_LOOP_PASS_H 16#define LLVM_LOOP_PASS_H 17 18#include "llvm/Analysis/LoopInfo.h" 19#include "llvm/Pass.h" 20#include "llvm/PassManagers.h" 21#include "llvm/Function.h" 22 23namespace llvm { 24 25class LPPassManager; 26class Loop; 27class Function; 28class LoopQueue; 29 30class LoopPass : public Pass { 31 32 public: 33 // runOnLoop - THis method should be implemented by the subclass to perform 34 // whatever action is necessary for the specfied Loop. 35 virtual bool runOnLoop (Loop &L, LPPassManager &LPM) = 0; 36 virtual bool runOnFunctionBody (Function &F, LPPassManager &LPM) { 37 return false; 38 } 39 40}; 41 42class LPPassManager : public FunctionPass, public PMDataManager { 43 44public: 45 LPPassManager(int Depth); 46 ~LPPassManager(); 47 48 /// run - Execute all of the passes scheduled for execution. Keep track of 49 /// whether any of the passes modifies the module, and if so, return true. 50 bool runOnFunction(Function &F); 51 52 /// Pass Manager itself does not invalidate any analysis info. 53 void getAnalysisUsage(AnalysisUsage &Info) const { 54 // LPPassManager needs LoopInfo. In the long term LoopInfo class will 55 // be consumed by LPPassManager. 56 Info.addRequired<LoopInfo>(); 57 Info.setPreservesAll(); 58 } 59 60 virtual const char *getPassName() const { 61 return "Loop Pass Manager"; 62 } 63 64 // Print passes managed by this manager 65 void dumpPassStructure(unsigned Offset) { 66 llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n"; 67 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { 68 Pass *P = getContainedPass(Index); 69 P->dumpPassStructure(Offset + 1); 70 dumpLastUses(P, Offset+1); 71 } 72 } 73 74 Pass *getContainedPass(unsigned N) { 75 assert ( N < PassVector.size() && "Pass number out of range!"); 76 Pass *FP = static_cast<Pass *>(PassVector[N]); 77 return FP; 78 } 79 80 virtual PassManagerType getPassManagerType() { 81 return PMT_LoopPassManager; 82 } 83 84 private: 85 LoopQueue *LQ; 86 87}; 88 89} // End llvm namespace 90 91#endif 92