]>
git.proxmox.com Git - rustc.git/blob - src/llvm/include/llvm/Analysis/RegionPass.h
1 //===- RegionPass.h - RegionPass class --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_ANALYSIS_REGIONPASS_H
17 #define LLVM_ANALYSIS_REGIONPASS_H
19 #include "llvm/Analysis/RegionInfo.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/LegacyPassManagers.h"
22 #include "llvm/Pass.h"
30 //===----------------------------------------------------------------------===//
31 /// @brief A pass that runs on each Region in a function.
33 /// RegionPass is managed by RGPassManager.
34 class RegionPass
: public Pass
{
36 explicit RegionPass(char &pid
) : Pass(PT_Region
, pid
) {}
38 //===--------------------------------------------------------------------===//
39 /// @name To be implemented by every RegionPass
42 /// @brief Run the pass on a specific Region
44 /// Accessing regions not contained in the current region is not allowed.
46 /// @param R The region this pass is run on.
47 /// @param RGM The RegionPassManager that manages this Pass.
49 /// @return True if the pass modifies this Region.
50 virtual bool runOnRegion(Region
*R
, RGPassManager
&RGM
) = 0;
52 /// @brief Get a pass to print the LLVM IR in the region.
54 /// @param O The output stream to print the Region.
55 /// @param Banner The banner to separate different printed passes.
57 /// @return The pass to print the LLVM IR in the region.
58 Pass
*createPrinterPass(raw_ostream
&O
,
59 const std::string
&Banner
) const override
;
61 using llvm::Pass::doInitialization
;
62 using llvm::Pass::doFinalization
;
64 virtual bool doInitialization(Region
*R
, RGPassManager
&RGM
) { return false; }
65 virtual bool doFinalization() { return false; }
68 //===--------------------------------------------------------------------===//
69 /// @name PassManager API
72 void preparePassManager(PMStack
&PMS
) override
;
74 void assignPassManager(PMStack
&PMS
,
75 PassManagerType PMT
= PMT_RegionPassManager
) override
;
77 PassManagerType
getPotentialPassManagerType() const override
{
78 return PMT_RegionPassManager
;
83 /// @brief The pass manager to schedule RegionPasses.
84 class RGPassManager
: public FunctionPass
, public PMDataManager
{
85 std::deque
<Region
*> RQ
;
89 Region
*CurrentRegion
;
93 explicit RGPassManager();
95 /// @brief Execute all of the passes scheduled for execution.
97 /// @return True if any of the passes modifies the function.
98 bool runOnFunction(Function
&F
) override
;
100 /// Pass Manager itself does not invalidate any analysis info.
101 /// RGPassManager needs RegionInfo.
102 void getAnalysisUsage(AnalysisUsage
&Info
) const override
;
104 const char *getPassName() const override
{
105 return "Region Pass Manager";
108 PMDataManager
*getAsPMDataManager() override
{ return this; }
109 Pass
*getAsPass() override
{ return this; }
111 /// @brief Print passes managed by this manager.
112 void dumpPassStructure(unsigned Offset
) override
;
114 /// @brief Get passes contained by this manager.
115 Pass
*getContainedPass(unsigned N
) {
116 assert(N
< PassVector
.size() && "Pass number out of range!");
117 Pass
*FP
= static_cast<Pass
*>(PassVector
[N
]);
121 PassManagerType
getPassManagerType() const override
{
122 return PMT_RegionPassManager
;
126 } // End llvm namespace