LLVM 20.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
22namespace llvm {
23class Function;
24class RGPassManager;
25class Region;
26class RegionInfo;
27
28//===----------------------------------------------------------------------===//
29/// A pass that runs on each Region in a function.
30///
31/// RegionPass is managed by RGPassManager.
32class RegionPass : public Pass {
33public:
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,
74
77 }
78 //@}
79
80protected:
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.
88 std::deque<Region*> RQ;
89 RegionInfo *RI;
90 Region *CurrentRegion;
91
92public:
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.
115 assert(N < PassVector.size() && "Pass number out of range!");
116 Pass *FP = static_cast<Pass *>(PassVector[N]);
117 return FP;
118 }
119
122 }
123};
124
125} // End llvm namespace
126
127#endif
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:310
PMDataManager provides the common place to manage the analysis data used by pass managers.
SmallVector< Pass *, 16 > PassVector
PMStack - This class implements a stack data structure of PMDataManager pointers.
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:119
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:123
The pass manager to schedule RegionPasses.
Definition: RegionPass.h:87
PMDataManager * getAsPMDataManager() override
Definition: RegionPass.h:107
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: RegionPass.h:105
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
Definition: RegionPass.cpp:165
Pass * getContainedPass(unsigned N)
Get passes contained by this manager.
Definition: RegionPass.h:114
static char ID
Definition: RegionPass.h:93
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition: RegionPass.cpp:48
PassManagerType getPassManagerType() const override
Definition: RegionPass.h:120
bool runOnFunction(Function &F) override
Execute all of the passes scheduled for execution.
Definition: RegionPass.cpp:55
Pass * getAsPass() override
Definition: RegionPass.h:108
A pass that runs on each Region in a function.
Definition: RegionPass.h:32
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: RegionPass.cpp:220
bool skipRegion(Region &R) const
Optional passes call this function to check whether the pass should be skipped.
Definition: RegionPass.cpp:283
void assignPassManager(PMStack &PMS, PassManagerType PMT=PMT_RegionPassManager) override
Assign pass manager to manage this pass.
Definition: RegionPass.cpp:237
RegionPass(char &pid)
Definition: RegionPass.h:34
virtual bool doFinalization()
Definition: RegionPass.h:63
virtual bool doInitialization(Region *R, RGPassManager &RGM)
Definition: RegionPass.h:62
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: RegionPass.h:75
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 override
Get a pass to print the LLVM IR in the region.
Definition: RegionPass.cpp:274
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
@ PT_Region
Definition: Pass.h:67
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:55
@ PMT_RegionPassManager
RGPassManager.
Definition: Pass.h:61
#define N