LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RegionPass.h
Go to the documentation of this file.
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_ANALYSIS_REGIONPASS_H
17 #define LLVM_ANALYSIS_REGIONPASS_H
18 
20 #include "llvm/IR/Function.h"
22 #include "llvm/Pass.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 output 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 
62 
63  virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; }
64  virtual bool doFinalization() { return false; }
65  //@}
66 
67  //===--------------------------------------------------------------------===//
68  /// @name PassManager API
69  ///
70  //@{
71  void preparePassManager(PMStack &PMS);
72 
73  virtual void assignPassManager(PMStack &PMS,
75 
77  return PMT_RegionPassManager;
78  }
79  //@}
80 };
81 
82 /// @brief The pass manager to schedule RegionPasses.
83 class RGPassManager : public FunctionPass, public PMDataManager {
84  std::deque<Region*> RQ;
85  bool skipThisRegion;
86  bool redoThisRegion;
87  RegionInfo *RI;
88  Region *CurrentRegion;
89 
90 public:
91  static char ID;
92  explicit RGPassManager();
93 
94  /// @brief Execute all of the passes scheduled for execution.
95  ///
96  /// @return True if any of the passes modifies the function.
97  bool runOnFunction(Function &F);
98 
99  /// Pass Manager itself does not invalidate any analysis info.
100  /// RGPassManager needs RegionInfo.
101  void getAnalysisUsage(AnalysisUsage &Info) const;
102 
103  virtual const char *getPassName() const {
104  return "Region Pass Manager";
105  }
106 
107  virtual PMDataManager *getAsPMDataManager() { return this; }
108  virtual Pass *getAsPass() { return this; }
109 
110  /// @brief Print passes managed by this manager.
111  void dumpPassStructure(unsigned Offset);
112 
113  /// @brief Get passes contained by this manager.
114  Pass *getContainedPass(unsigned N) {
115  assert(N < PassVector.size() && "Pass number out of range!");
116  Pass *FP = static_cast<Pass *>(PassVector[N]);
117  return FP;
118  }
119 
121  return PMT_RegionPassManager;
122  }
123 };
124 
125 } // End llvm namespace
126 
127 #endif
void getAnalysisUsage(AnalysisUsage &Info) const
Pass Manager itself does not invalidate any analysis info.
Definition: RegionPass.cpp:46
PassManagerType
Definition: Pass.h:55
F(f)
The pass manager to schedule RegionPasses.
Definition: RegionPass.h:83
virtual bool doInitialization(Region *R, RGPassManager &RGM)
Definition: RegionPass.h:63
virtual bool doFinalization(Module &)
Definition: Pass.h:115
static char ID
Definition: RegionPass.h:91
virtual PassManagerType getPotentialPassManagerType() const
Return what kind of Pass Manager can manage this pass.
Definition: RegionPass.h:76
virtual void assignPassManager(PMStack &PMS, PassManagerType PMT=PMT_RegionPassManager)
Assign pass manager to manage this pass.
Definition: RegionPass.cpp:235
virtual const char * getPassName() const
Definition: RegionPass.h:103
virtual bool doFinalization()
Definition: RegionPass.h:64
virtual bool doInitialization(Module &)
Definition: Pass.h:110
A pass that runs on each Region in a function.
Definition: RegionPass.h:34
virtual PassManagerType getPassManagerType() const
Definition: RegionPass.h:120
A single entry single exit Region.
Definition: RegionInfo.h:202
Pass * getContainedPass(unsigned N)
Get passes contained by this manager.
Definition: RegionPass.h:114
void dumpPassStructure(unsigned Offset)
Print passes managed by this manager.
Definition: RegionPass.cpp:169
virtual Pass * getAsPass()
Definition: RegionPass.h:108
virtual PMDataManager * getAsPMDataManager()
Definition: RegionPass.h:107
bool runOnFunction(Function &F)
Execute all of the passes scheduled for execution.
Definition: RegionPass.cpp:53
SmallVector< Pass *, 16 > PassVector
#define N
RGPassManager.
Definition: Pass.h:61
virtual bool runOnRegion(Region *R, RGPassManager &RGM)=0
Run the pass on a specific Region.
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const
Get a pass to print the LLVM IR in the region.
Definition: RegionPass.cpp:272
void preparePassManager(PMStack &PMS)
Check if available pass managers are suitable for this pass or not.
Definition: RegionPass.cpp:218
RegionPass(char &pid)
Definition: RegionPass.h:36
Analysis that detects all canonical Regions.
Definition: RegionInfo.h:577