LLVM  14.0.0git
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 
20 #include "llvm/Pass.h"
21 #include <deque>
22 
23 namespace llvm {
24 class Function;
25 class RGPassManager;
26 
27 //===----------------------------------------------------------------------===//
28 /// A pass that runs on each Region in a function.
29 ///
30 /// RegionPass is managed by RGPassManager.
31 class RegionPass : public Pass {
32 public:
33  explicit RegionPass(char &pid) : Pass(PT_Region, pid) {}
34 
35  //===--------------------------------------------------------------------===//
36  /// @name To be implemented by every RegionPass
37  ///
38  //@{
39  /// Run the pass on a specific Region
40  ///
41  /// Accessing regions not contained in the current region is not allowed.
42  ///
43  /// @param R The region this pass is run on.
44  /// @param RGM The RegionPassManager that manages this Pass.
45  ///
46  /// @return True if the pass modifies this Region.
47  virtual bool runOnRegion(Region *R, RGPassManager &RGM) = 0;
48 
49  /// Get a pass to print the LLVM IR in the region.
50  ///
51  /// @param O The output stream to print the Region.
52  /// @param Banner The banner to separate different printed passes.
53  ///
54  /// @return The pass to print the LLVM IR in the region.
56  const std::string &Banner) const override;
57 
60 
61  virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; }
62  virtual bool doFinalization() { return false; }
63  //@}
64 
65  //===--------------------------------------------------------------------===//
66  /// @name PassManager API
67  ///
68  //@{
69  void preparePassManager(PMStack &PMS) override;
70 
71  void assignPassManager(PMStack &PMS,
72  PassManagerType PMT = PMT_RegionPassManager) override;
73 
75  return PMT_RegionPassManager;
76  }
77  //@}
78 
79 protected:
80  /// Optional passes call this function to check whether the pass should be
81  /// skipped. This is the case when optimization bisect is over the limit.
82  bool skipRegion(Region &R) const;
83 };
84 
85 /// The pass manager to schedule RegionPasses.
86 class RGPassManager : public FunctionPass, public PMDataManager {
87  std::deque<Region*> RQ;
88  RegionInfo *RI;
89  Region *CurrentRegion;
90 
91 public:
92  static char ID;
93  explicit RGPassManager();
94 
95  /// 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  /// Print passes managed by this manager.
110  void dumpPassStructure(unsigned Offset) override;
111 
112  /// 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
RegionInfo.h
llvm::RGPassManager::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition: RegionPass.cpp:46
CmpMode::FP
@ FP
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::RegionPass::skipRegion
bool skipRegion(Region &R) const
Optional passes call this function to check whether the pass should be skipped.
Definition: RegionPass.cpp:279
llvm::RegionPass::assignPassManager
void assignPassManager(PMStack &PMS, PassManagerType PMT=PMT_RegionPassManager) override
Assign pass manager to manage this pass.
Definition: RegionPass.cpp:233
llvm::Function
Definition: Function.h:61
Pass.h
llvm::RGPassManager::getPassManagerType
PassManagerType getPassManagerType() const override
Definition: RegionPass.h:119
llvm::PassManagerType
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:52
llvm::PT_Region
@ PT_Region
Definition: Pass.h:64
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::RegionPass::runOnRegion
virtual bool runOnRegion(Region *R, RGPassManager &RGM)=0
Run the pass on a specific Region.
llvm::RGPassManager::dumpPassStructure
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
Definition: RegionPass.cpp:163
llvm::PMDataManager
PMDataManager provides the common place to manage the analysis data used by pass managers.
Definition: LegacyPassManagers.h:296
llvm::RegionPass::getPotentialPassManagerType
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: RegionPass.h:74
llvm::RegionPass::doInitialization
virtual bool doInitialization(Region *R, RGPassManager &RGM)
Definition: RegionPass.h:61
LegacyPassManagers.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::RegionPass::RegionPass
RegionPass(char &pid)
Definition: RegionPass.h:33
llvm::RegionPass::preparePassManager
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: RegionPass.cpp:216
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:197
llvm::RGPassManager::ID
static char ID
Definition: RegionPass.h:92
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::RGPassManager
The pass manager to schedule RegionPasses.
Definition: RegionPass.h:86
llvm::RegionPass
A pass that runs on each Region in a function.
Definition: RegionPass.h:31
llvm::Pass::doFinalization
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:120
llvm::Pass::doInitialization
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:116
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::RGPassManager::getAsPass
Pass * getAsPass() override
Definition: RegionPass.h:107
llvm::RegionInfo
Definition: RegionInfo.h:900
llvm::PMStack
PMStack - This class implements a stack data structure of PMDataManager pointers.
Definition: LegacyPassManagers.h:137
llvm::RegionPass::createPrinterPass
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:270
llvm::RGPassManager::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: RegionPass.h:104
llvm::PMDataManager::PassVector
SmallVector< Pass *, 16 > PassVector
Definition: LegacyPassManagers.h:425
llvm::PMT_RegionPassManager
@ PMT_RegionPassManager
RGPassManager.
Definition: Pass.h:58
llvm::RegionPass::doFinalization
virtual bool doFinalization()
Definition: RegionPass.h:62
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
N
#define N
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::RGPassManager::RGPassManager
RGPassManager()
Definition: RegionPass.cpp:32
llvm::RGPassManager::runOnFunction
bool runOnFunction(Function &F) override
Execute all of the passes scheduled for execution.
Definition: RegionPass.cpp:53
llvm::Region
Definition: RegionInfo.h:889
llvm::RGPassManager::getContainedPass
Pass * getContainedPass(unsigned N)
Get passes contained by this manager.
Definition: RegionPass.h:113
llvm::RGPassManager::getAsPMDataManager
PMDataManager * getAsPMDataManager() override
Definition: RegionPass.h:106
llvm::codeview::PublicSymFlags::Function
@ Function