LLVM  15.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 
19 #include "llvm/Pass.h"
20 #include <deque>
21 
22 namespace llvm {
23 class Function;
24 class RGPassManager;
25 class Region;
26 class RegionInfo;
27 
28 //===----------------------------------------------------------------------===//
29 /// A pass that runs on each Region in a function.
30 ///
31 /// RegionPass is managed by RGPassManager.
32 class RegionPass : public Pass {
33 public:
34  explicit RegionPass(char &pid) : Pass(PT_Region, pid) {}
35 
36  //===--------------------------------------------------------------------===//
37  /// @name To be implemented by every RegionPass
38  ///
39  //@{
40  /// Run the pass on a specific Region
41  ///
42  /// Accessing regions not contained in the current region is not allowed.
43  ///
44  /// @param R The region this pass is run on.
45  /// @param RGM The RegionPassManager that manages this Pass.
46  ///
47  /// @return True if the pass modifies this Region.
48  virtual bool runOnRegion(Region *R, RGPassManager &RGM) = 0;
49 
50  /// Get a pass to print the LLVM IR in the region.
51  ///
52  /// @param O The output stream to print the Region.
53  /// @param Banner The banner to separate different printed passes.
54  ///
55  /// @return The pass to print the LLVM IR in the region.
57  const std::string &Banner) const override;
58 
61 
62  virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; }
63  virtual bool doFinalization() { return false; }
64  //@}
65 
66  //===--------------------------------------------------------------------===//
67  /// @name PassManager API
68  ///
69  //@{
70  void preparePassManager(PMStack &PMS) override;
71 
72  void assignPassManager(PMStack &PMS,
73  PassManagerType PMT = PMT_RegionPassManager) override;
74 
76  return PMT_RegionPassManager;
77  }
78  //@}
79 
80 protected:
81  /// Optional passes call this function to check whether the pass should be
82  /// skipped. This is the case when optimization bisect is over the limit.
83  bool skipRegion(Region &R) const;
84 };
85 
86 /// The pass manager to schedule RegionPasses.
87 class RGPassManager : public FunctionPass, public PMDataManager {
88  std::deque<Region*> RQ;
89  RegionInfo *RI;
90  Region *CurrentRegion;
91 
92 public:
93  static char ID;
94  explicit RGPassManager();
95 
96  /// Execute all of the passes scheduled for execution.
97  ///
98  /// @return True if any of the passes modifies the function.
99  bool runOnFunction(Function &F) override;
100 
101  /// Pass Manager itself does not invalidate any analysis info.
102  /// RGPassManager needs RegionInfo.
103  void getAnalysisUsage(AnalysisUsage &Info) const override;
104 
105  StringRef getPassName() const override { return "Region Pass Manager"; }
106 
107  PMDataManager *getAsPMDataManager() override { return this; }
108  Pass *getAsPass() override { return this; }
109 
110  /// Print passes managed by this manager.
111  void dumpPassStructure(unsigned Offset) override;
112 
113  /// 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
llvm::RGPassManager::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition: RegionPass.cpp:48
CmpMode::FP
@ FP
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::RegionPass::skipRegion
bool skipRegion(Region &R) const
Optional passes call this function to check whether the pass should be skipped.
Definition: RegionPass.cpp:283
llvm::RegionPass::assignPassManager
void assignPassManager(PMStack &PMS, PassManagerType PMT=PMT_RegionPassManager) override
Assign pass manager to manage this pass.
Definition: RegionPass.cpp:237
llvm::Function
Definition: Function.h:60
Pass.h
llvm::RGPassManager::getPassManagerType
PassManagerType getPassManagerType() const override
Definition: RegionPass.h:120
llvm::AMDGPU::HSAMD::AddressSpaceQualifier::Region
@ Region
llvm::PassManagerType
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:52
llvm::PT_Region
@ PT_Region
Definition: Pass.h:64
F
#define F(x, y, z)
Definition: MD5.cpp:55
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:165
llvm::PMDataManager
PMDataManager provides the common place to manage the analysis data used by pass managers.
Definition: LegacyPassManagers.h:295
llvm::RegionPass::getPotentialPassManagerType
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: RegionPass.h:75
llvm::RegionPass::doInitialization
virtual bool doInitialization(Region *R, RGPassManager &RGM)
Definition: RegionPass.h:62
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:54
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::RegionPass::RegionPass
RegionPass(char &pid)
Definition: RegionPass.h:34
llvm::RegionPass::preparePassManager
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: RegionPass.cpp:220
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:239
llvm::RGPassManager::ID
static char ID
Definition: RegionPass.h:93
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::RGPassManager
The pass manager to schedule RegionPasses.
Definition: RegionPass.h:87
llvm::RegionPass
A pass that runs on each Region in a function.
Definition: RegionPass.h:32
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:108
llvm::RegionInfo
Definition: RegionInfo.h:900
llvm::PMStack
PMStack - This class implements a stack data structure of PMDataManager pointers.
Definition: LegacyPassManagers.h:136
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:274
llvm::RGPassManager::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: RegionPass.h:105
llvm::PMDataManager::PassVector
SmallVector< Pass *, 16 > PassVector
Definition: LegacyPassManagers.h:422
llvm::PMT_RegionPassManager
@ PMT_RegionPassManager
RGPassManager.
Definition: Pass.h:58
llvm::RegionPass::doFinalization
virtual bool doFinalization()
Definition: RegionPass.h:63
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:308
llvm::RGPassManager::RGPassManager
RGPassManager()
Definition: RegionPass.cpp:35
llvm::RGPassManager::runOnFunction
bool runOnFunction(Function &F) override
Execute all of the passes scheduled for execution.
Definition: RegionPass.cpp:55
llvm::Region
Definition: RegionInfo.h:889
llvm::RGPassManager::getContainedPass
Pass * getContainedPass(unsigned N)
Get passes contained by this manager.
Definition: RegionPass.h:114
llvm::RGPassManager::getAsPMDataManager
PMDataManager * getAsPMDataManager() override
Definition: RegionPass.h:107
llvm::codeview::PublicSymFlags::Function
@ Function