LLVM  10.0.0svn
RegionPass.h
Go to the documentation of this file.
1 //===- RegionPass.h - RegionPass class --------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the RegionPass class. All region based analysis,
10 // optimization and transformation passes are derived from RegionPass.
11 // This class is implemented following the some ideas of the LoopPass.h class.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_ANALYSIS_REGIONPASS_H
16 #define LLVM_ANALYSIS_REGIONPASS_H
17 
19 #include "llvm/IR/Function.h"
21 #include "llvm/Pass.h"
22 #include <deque>
23 
24 namespace llvm {
25 
26 class RGPassManager;
27 class Function;
28 
29 //===----------------------------------------------------------------------===//
30 /// A pass that runs on each Region in a function.
31 ///
32 /// RegionPass is managed by RGPassManager.
33 class RegionPass : public Pass {
34 public:
35  explicit RegionPass(char &pid) : Pass(PT_Region, pid) {}
36 
37  //===--------------------------------------------------------------------===//
38  /// @name To be implemented by every RegionPass
39  ///
40  //@{
41  /// Run the pass on a specific Region
42  ///
43  /// Accessing regions not contained in the current region is not allowed.
44  ///
45  /// @param R The region this pass is run on.
46  /// @param RGM The RegionPassManager that manages this Pass.
47  ///
48  /// @return True if the pass modifies this Region.
49  virtual bool runOnRegion(Region *R, RGPassManager &RGM) = 0;
50 
51  /// Get a pass to print the LLVM IR in the region.
52  ///
53  /// @param O The output stream to print the Region.
54  /// @param Banner The banner to separate different printed passes.
55  ///
56  /// @return The pass to print the LLVM IR in the region.
58  const std::string &Banner) const override;
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) override;
72 
73  void assignPassManager(PMStack &PMS,
74  PassManagerType PMT = PMT_RegionPassManager) override;
75 
77  return PMT_RegionPassManager;
78  }
79  //@}
80 
81 protected:
82  /// Optional passes call this function to check whether the pass should be
83  /// skipped. This is the case when optimization bisect is over the limit.
84  bool skipRegion(Region &R) const;
85 };
86 
87 /// The pass manager to schedule RegionPasses.
88 class RGPassManager : public FunctionPass, public PMDataManager {
89  std::deque<Region*> RQ;
90  bool skipThisRegion;
91  bool redoThisRegion;
92  RegionInfo *RI;
93  Region *CurrentRegion;
94 
95 public:
96  static char ID;
97  explicit RGPassManager();
98 
99  /// Execute all of the passes scheduled for execution.
100  ///
101  /// @return True if any of the passes modifies the function.
102  bool runOnFunction(Function &F) override;
103 
104  /// Pass Manager itself does not invalidate any analysis info.
105  /// RGPassManager needs RegionInfo.
106  void getAnalysisUsage(AnalysisUsage &Info) const override;
107 
108  StringRef getPassName() const override { return "Region Pass Manager"; }
109 
110  PMDataManager *getAsPMDataManager() override { return this; }
111  Pass *getAsPass() override { return this; }
112 
113  /// Print passes managed by this manager.
114  void dumpPassStructure(unsigned Offset) override;
115 
116  /// Get passes contained by this manager.
117  Pass *getContainedPass(unsigned N) {
118  assert(N < PassVector.size() && "Pass number out of range!");
119  Pass *FP = static_cast<Pass *>(PassVector[N]);
120  return FP;
121  }
122 
124  return PMT_RegionPassManager;
125  }
126 };
127 
128 } // End llvm namespace
129 
130 #endif
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
PassManagerType getPassManagerType() const override
Definition: RegionPass.h:123
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:53
This class represents lattice values for constants.
Definition: AllocatorList.h:23
virtual void dumpPassStructure(unsigned Offset=0)
Definition: Pass.cpp:72
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:276
bool skipRegion(Region &R) const
Optional passes call this function to check whether the pass should be skipped.
Definition: RegionPass.cpp:285
F(f)
The pass manager to schedule RegionPasses.
Definition: RegionPass.h:88
virtual bool doInitialization(Region *R, RGPassManager &RGM)
Definition: RegionPass.h:63
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:109
static char ID
Definition: RegionPass.h:96
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
PMDataManager * getAsPMDataManager() override
Definition: RegionPass.h:110
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:96
virtual bool doFinalization()
Definition: RegionPass.h:64
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:105
static bool runOnFunction(Function &F, bool PostInlining)
void assignPassManager(PMStack &PMS, PassManagerType PMT=PMT_RegionPassManager) override
Assign pass manager to manage this pass.
Definition: RegionPass.cpp:239
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: RegionPass.cpp:222
A pass that runs on each Region in a function.
Definition: RegionPass.h:33
Pass * getAsPass() override
Definition: RegionPass.h:111
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
Pass * getContainedPass(unsigned N)
Get passes contained by this manager.
Definition: RegionPass.h:117
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: RegionPass.h:76
#define N
RGPassManager.
Definition: Pass.h:59
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:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
RegionPass(char &pid)
Definition: RegionPass.h:35
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: RegionPass.h:108