LLVM API Documentation
00001 //===- RegionPass.h - RegionPass 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 the RegionPass class. All region based analysis, 00011 // optimization and transformation passes are derived from RegionPass. 00012 // This class is implemented following the some ideas of the LoopPass.h class. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_ANALYSIS_REGIONPASS_H 00017 #define LLVM_ANALYSIS_REGIONPASS_H 00018 00019 #include "llvm/Analysis/RegionInfo.h" 00020 #include "llvm/IR/Function.h" 00021 #include "llvm/Pass.h" 00022 #include "llvm/PassManagers.h" 00023 #include <deque> 00024 00025 namespace llvm { 00026 00027 class RGPassManager; 00028 class Function; 00029 00030 //===----------------------------------------------------------------------===// 00031 /// @brief A pass that runs on each Region in a function. 00032 /// 00033 /// RegionPass is managed by RGPassManager. 00034 class RegionPass : public Pass { 00035 public: 00036 explicit RegionPass(char &pid) : Pass(PT_Region, pid) {} 00037 00038 //===--------------------------------------------------------------------===// 00039 /// @name To be implemented by every RegionPass 00040 /// 00041 //@{ 00042 /// @brief Run the pass on a specific Region 00043 /// 00044 /// Accessing regions not contained in the current region is not allowed. 00045 /// 00046 /// @param R The region this pass is run on. 00047 /// @param RGM The RegionPassManager that manages this Pass. 00048 /// 00049 /// @return True if the pass modifies this Region. 00050 virtual bool runOnRegion(Region *R, RGPassManager &RGM) = 0; 00051 00052 /// @brief Get a pass to print the LLVM IR in the region. 00053 /// 00054 /// @param O The output stream to print the Region. 00055 /// @param Banner The banner to separate different printed passes. 00056 /// 00057 /// @return The pass to print the LLVM IR in the region. 00058 Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const; 00059 00060 using llvm::Pass::doInitialization; 00061 using llvm::Pass::doFinalization; 00062 00063 virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; } 00064 virtual bool doFinalization() { return false; } 00065 //@} 00066 00067 //===--------------------------------------------------------------------===// 00068 /// @name PassManager API 00069 /// 00070 //@{ 00071 void preparePassManager(PMStack &PMS); 00072 00073 virtual void assignPassManager(PMStack &PMS, 00074 PassManagerType PMT = PMT_RegionPassManager); 00075 00076 virtual PassManagerType getPotentialPassManagerType() const { 00077 return PMT_RegionPassManager; 00078 } 00079 //@} 00080 }; 00081 00082 /// @brief The pass manager to schedule RegionPasses. 00083 class RGPassManager : public FunctionPass, public PMDataManager { 00084 std::deque<Region*> RQ; 00085 bool skipThisRegion; 00086 bool redoThisRegion; 00087 RegionInfo *RI; 00088 Region *CurrentRegion; 00089 00090 public: 00091 static char ID; 00092 explicit RGPassManager(); 00093 00094 /// @brief Execute all of the passes scheduled for execution. 00095 /// 00096 /// @return True if any of the passes modifies the function. 00097 bool runOnFunction(Function &F); 00098 00099 /// Pass Manager itself does not invalidate any analysis info. 00100 /// RGPassManager needs RegionInfo. 00101 void getAnalysisUsage(AnalysisUsage &Info) const; 00102 00103 virtual const char *getPassName() const { 00104 return "Region Pass Manager"; 00105 } 00106 00107 virtual PMDataManager *getAsPMDataManager() { return this; } 00108 virtual Pass *getAsPass() { return this; } 00109 00110 /// @brief Print passes managed by this manager. 00111 void dumpPassStructure(unsigned Offset); 00112 00113 /// @brief Get passes contained by this manager. 00114 Pass *getContainedPass(unsigned N) { 00115 assert(N < PassVector.size() && "Pass number out of range!"); 00116 Pass *FP = static_cast<Pass *>(PassVector[N]); 00117 return FP; 00118 } 00119 00120 virtual PassManagerType getPassManagerType() const { 00121 return PMT_RegionPassManager; 00122 } 00123 }; 00124 00125 } // End llvm namespace 00126 00127 #endif