LLVM API Documentation

LoopPass.h

Go to the documentation of this file.
00001 //===- LoopPass.h - LoopPass class ----------------------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines LoopPass class. All loop optimization
00011 // and transformation passes are derived from LoopPass.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_LOOP_PASS_H
00016 #define LLVM_LOOP_PASS_H
00017 
00018 #include "llvm/Analysis/LoopInfo.h"
00019 #include "llvm/Pass.h"
00020 #include "llvm/PassManagers.h"
00021 #include "llvm/Function.h"
00022 
00023 namespace llvm {
00024 
00025 class LPPassManager;
00026 class Function;
00027 class PMStack;
00028 
00029 class LoopPass : public Pass {
00030 public:
00031   explicit LoopPass(intptr_t pid) : Pass(pid) {}
00032   explicit LoopPass(void *pid) : Pass(pid) {}
00033 
00034   // runOnLoop - This method should be implemented by the subclass to perform
00035   // whatever action is necessary for the specified Loop.
00036   virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
00037 
00038   // Initialization and finalization hooks.
00039   virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
00040     return false;
00041   }
00042 
00043   // Finalization hook does not supply Loop because at this time
00044   // loop nest is completely different.
00045   virtual bool doFinalization() { return false; }
00046 
00047   // Check if this pass is suitable for the current LPPassManager, if
00048   // available. This pass P is not suitable for a LPPassManager if P
00049   // is not preserving higher level analysis info used by other
00050   // LPPassManager passes. In such case, pop LPPassManager from the
00051   // stack. This will force assignPassManager() to create new
00052   // LPPassManger as expected.
00053   void preparePassManager(PMStack &PMS);
00054 
00055   /// Assign pass manager to manager this pass
00056   virtual void assignPassManager(PMStack &PMS,
00057                                  PassManagerType PMT = PMT_LoopPassManager);
00058 
00059   ///  Return what kind of Pass Manager can manage this pass.
00060   virtual PassManagerType getPotentialPassManagerType() const {
00061     return PMT_LoopPassManager;
00062   }
00063 
00064   //===--------------------------------------------------------------------===//
00065   /// SimpleAnalysis - Provides simple interface to update analysis info
00066   /// maintained by various passes. Note, if required this interface can
00067   /// be extracted into a separate abstract class but it would require
00068   /// additional use of multiple inheritance in Pass class hierarchy, something
00069   /// we are trying to avoid.
00070 
00071   /// Each loop pass can override these simple analysis hooks to update
00072   /// desired analysis information.
00073   /// cloneBasicBlockAnalysis - Clone analysis info associated with basic block.
00074   virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L) {}
00075 
00076   /// deletekAnalysisValue - Delete analysis info associated with value V.
00077   virtual void deleteAnalysisValue(Value *V, Loop *L) {}
00078 };
00079 
00080 class LPPassManager : public FunctionPass, public PMDataManager {
00081 public:
00082   static char ID;
00083   explicit LPPassManager(int Depth);
00084 
00085   /// run - Execute all of the passes scheduled for execution.  Keep track of
00086   /// whether any of the passes modifies the module, and if so, return true.
00087   bool runOnFunction(Function &F);
00088 
00089   /// Pass Manager itself does not invalidate any analysis info.
00090   // LPPassManager needs LoopInfo.
00091   void getAnalysisUsage(AnalysisUsage &Info) const;
00092 
00093   virtual const char *getPassName() const {
00094     return "Loop Pass Manager";
00095   }
00096 
00097   /// Print passes managed by this manager
00098   void dumpPassStructure(unsigned Offset);
00099 
00100   Pass *getContainedPass(unsigned N) {
00101     assert(N < PassVector.size() && "Pass number out of range!");
00102     Pass *FP = static_cast<Pass *>(PassVector[N]);
00103     return FP;
00104   }
00105 
00106   virtual PassManagerType getPassManagerType() const {
00107     return PMT_LoopPassManager;
00108   }
00109 
00110 public:
00111   // Delete loop from the loop queue and loop nest (LoopInfo).
00112   void deleteLoopFromQueue(Loop *L);
00113 
00114   // Insert loop into the loop nest(LoopInfo) and loop queue(LQ).
00115   void insertLoop(Loop *L, Loop *ParentLoop);
00116 
00117   // Reoptimize this loop. LPPassManager will re-insert this loop into the
00118   // queue. This allows LoopPass to change loop nest for the loop. This
00119   // utility may send LPPassManager into infinite loops so use caution.
00120   void redoLoop(Loop *L);
00121 
00122   //===--------------------------------------------------------------------===//
00123   /// SimpleAnalysis - Provides simple interface to update analysis info
00124   /// maintained by various passes. Note, if required this interface can
00125   /// be extracted into a separate abstract class but it would require
00126   /// additional use of multiple inheritance in Pass class hierarchy, something
00127   /// we are trying to avoid.
00128 
00129   /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
00130   /// all passes that implement simple analysis interface.
00131   void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L);
00132 
00133   /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
00134   /// that implement simple analysis interface.
00135   void deleteSimpleAnalysisValue(Value *V, Loop *L);
00136 
00137 private:
00138   std::deque<Loop *> LQ;
00139   bool skipThisLoop;
00140   bool redoThisLoop;
00141   LoopInfo *LI;
00142   Loop *CurrentLoop;
00143 };
00144 
00145 } // End llvm namespace
00146 
00147 #endif