LLVM  4.0.0
RegionPass.h
Go to the documentation of this file.
1 //===- RegionPass.h - RegionPass class --------------------------*- C++ -*-===//
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.
59  const std::string &Banner) const override;
60 
63 
64  virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; }
65  virtual bool doFinalization() { return false; }
66  //@}
67 
68  //===--------------------------------------------------------------------===//
69  /// @name PassManager API
70  ///
71  //@{
72  void preparePassManager(PMStack &PMS) override;
73 
74  void assignPassManager(PMStack &PMS,
75  PassManagerType PMT = PMT_RegionPassManager) override;
76 
78  return PMT_RegionPassManager;
79  }
80  //@}
81 };
82 
83 /// @brief The pass manager to schedule RegionPasses.
84 class RGPassManager : public FunctionPass, public PMDataManager {
85  std::deque<Region*> RQ;
86  bool skipThisRegion;
87  bool redoThisRegion;
88  RegionInfo *RI;
89  Region *CurrentRegion;
90 
91 public:
92  static char ID;
93  explicit RGPassManager();
94 
95  /// @brief Execute all of the passes scheduled for execution.
96  ///
97  /// @return True if any of the passes modifies the function.
98  bool runOnFunction(Function &F) override;
99 
100  /// Pass Manager itself does not invalidate any analysis info.
101  /// RGPassManager needs RegionInfo.
102  void getAnalysisUsage(AnalysisUsage &Info) const override;
103 
104  StringRef getPassName() const override { return "Region Pass Manager"; }
105 
106  PMDataManager *getAsPMDataManager() override { return this; }
107  Pass *getAsPass() override { return this; }
108 
109  /// @brief Print passes managed by this manager.
110  void dumpPassStructure(unsigned Offset) override;
111 
112  /// @brief Get passes contained by this manager.
113  Pass *getContainedPass(unsigned N) {
114  assert(N < PassVector.size() && "Pass number out of range!");
115  Pass *FP = static_cast<Pass *>(PassVector[N]);
116  return FP;
117  }
118 
120  return PMT_RegionPassManager;
121  }
122 };
123 
124 } // End llvm namespace
125 
126 #endif
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
PassManagerType getPassManagerType() const override
Definition: RegionPass.h:119
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:54
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
Get a pass to print the LLVM IR in the region.
Definition: RegionPass.cpp:277
The pass manager to schedule RegionPasses.
Definition: RegionPass.h:84
virtual bool doInitialization(Region *R, RGPassManager &RGM)
Definition: RegionPass.h:64
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:115
static char ID
Definition: RegionPass.h:92
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
PMDataManager * getAsPMDataManager() override
Definition: RegionPass.h:106
#define F(x, y, z)
Definition: MD5.cpp:51
virtual bool doFinalization()
Definition: RegionPass.h:65
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:110
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
Definition: RegionPass.cpp:172
void assignPassManager(PMStack &PMS, PassManagerType PMT=PMT_RegionPassManager) override
Assign pass manager to manage this pass.
Definition: RegionPass.cpp:240
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: RegionPass.cpp:223
A pass that runs on each Region in a function.
Definition: RegionPass.h:34
Pass * getAsPass() override
Definition: RegionPass.h:107
Represent the analysis usage information of a pass.
bool runOnFunction(Function &F) override
Execute all of the passes scheduled for execution.
Definition: RegionPass.cpp:54
uint32_t Offset
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
Pass * getContainedPass(unsigned N)
Get passes contained by this manager.
Definition: RegionPass.h:113
SmallVector< Pass *, 16 > PassVector
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: RegionPass.h:77
#define N
RGPassManager.
Definition: Pass.h:60
virtual bool runOnRegion(Region *R, RGPassManager &RGM)=0
Run the pass on a specific Region.
PMDataManager provides the common place to manage the analysis data used by pass managers.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition: RegionPass.cpp:47
RegionPass(char &pid)
Definition: RegionPass.h:36
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: RegionPass.h:104