Sort the #include lines for the include/... tree with the script.
[oota-llvm.git] / include / llvm / Analysis / RegionPass.h
1 //===- RegionPass.h - RegionPass class ------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the RegionPass class. All region based analysis,
11 // optimization and transformation passes are derived from RegionPass.
12 // This class is implemented following the some ideas of the LoopPass.h class.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_REGION_PASS_H
17 #define LLVM_REGION_PASS_H
18
19 #include "llvm/Analysis/RegionInfo.h"
20 #include "llvm/Function.h"
21 #include "llvm/Pass.h"
22 #include "llvm/PassManagers.h"
23 #include <deque>
24
25 namespace llvm {
26
27 class RGPassManager;
28 class Function;
29
30 //===----------------------------------------------------------------------===//
31 /// @brief A pass that runs on each Region in a function.
32 ///
33 /// RegionPass is managed by RGPassManager.
34 class RegionPass : public Pass {
35 public:
36   explicit RegionPass(char &pid) : Pass(PT_Region, pid) {}
37
38   //===--------------------------------------------------------------------===//
39   /// @name To be implemented by every RegionPass
40   ///
41   //@{
42   /// @brief Run the pass on a specific Region
43   ///
44   /// Accessing regions not contained in the current region is not allowed.
45   ///
46   /// @param R The region this pass is run on.
47   /// @param RGM The RegionPassManager that manages this Pass.
48   ///
49   /// @return True if the pass modifies this Region.
50   virtual bool runOnRegion(Region *R, RGPassManager &RGM) = 0;
51
52   /// @brief Get a pass to print the LLVM IR in the region.
53   ///
54   /// @param O      The ouput stream to print the Region.
55   /// @param Banner The banner to separate different printed passes.
56   ///
57   /// @return The pass to print the LLVM IR in the region.
58   Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const;
59
60   virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; }
61   virtual bool doFinalization() { return false; }
62   //@}
63
64   //===--------------------------------------------------------------------===//
65   /// @name PassManager API
66   ///
67   //@{
68   void preparePassManager(PMStack &PMS);
69
70   virtual void assignPassManager(PMStack &PMS,
71     PassManagerType PMT = PMT_RegionPassManager);
72
73   virtual PassManagerType getPotentialPassManagerType() const {
74     return PMT_RegionPassManager;
75   }
76   //@}
77 };
78
79 /// @brief The pass manager to schedule RegionPasses.
80 class RGPassManager : public FunctionPass, public PMDataManager {
81   std::deque<Region*> RQ;
82   bool skipThisRegion;
83   bool redoThisRegion;
84   RegionInfo *RI;
85   Region *CurrentRegion;
86
87 public:
88   static char ID;
89   explicit RGPassManager();
90
91   /// @brief Execute all of the passes scheduled for execution.
92   ///
93   /// @return True if any of the passes modifies the function.
94   bool runOnFunction(Function &F);
95
96   /// Pass Manager itself does not invalidate any analysis info.
97   /// RGPassManager needs RegionInfo.
98   void getAnalysisUsage(AnalysisUsage &Info) const;
99
100   virtual const char *getPassName() const {
101     return "Region Pass Manager";
102   }
103
104   virtual PMDataManager *getAsPMDataManager() { return this; }
105   virtual Pass *getAsPass() { return this; }
106
107   /// @brief Print passes managed by this manager.
108   void dumpPassStructure(unsigned Offset);
109
110   /// @brief Get passes contained by this manager.
111   Pass *getContainedPass(unsigned N) {
112     assert(N < PassVector.size() && "Pass number out of range!");
113     Pass *FP = static_cast<Pass *>(PassVector[N]);
114     return FP;
115   }
116
117   virtual PassManagerType getPassManagerType() const {
118     return PMT_RegionPassManager;
119   }
120 };
121
122 } // End llvm namespace
123
124 #endif