]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/Analysis/RegionPass.h
MFV r367082:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / Analysis / RegionPass.h
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
18 #include "llvm/Analysis/RegionInfo.h"
19 #include "llvm/IR/LegacyPassManagers.h"
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.
55   Pass *createPrinterPass(raw_ostream &O,
56                           const std::string &Banner) const override;
57
58   using llvm::Pass::doInitialization;
59   using llvm::Pass::doFinalization;
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
74   PassManagerType getPotentialPassManagerType() const override {
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   bool skipThisRegion;
89   bool redoThisRegion;
90   RegionInfo *RI;
91   Region *CurrentRegion;
92
93 public:
94   static char ID;
95   explicit RGPassManager();
96
97   /// Execute all of the passes scheduled for execution.
98   ///
99   /// @return True if any of the passes modifies the function.
100   bool runOnFunction(Function &F) override;
101
102   /// Pass Manager itself does not invalidate any analysis info.
103   /// RGPassManager needs RegionInfo.
104   void getAnalysisUsage(AnalysisUsage &Info) const override;
105
106   StringRef getPassName() const override { return "Region Pass Manager"; }
107
108   PMDataManager *getAsPMDataManager() override { return this; }
109   Pass *getAsPass() override { return this; }
110
111   /// Print passes managed by this manager.
112   void dumpPassStructure(unsigned Offset) override;
113
114   /// 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]);
118     return FP;
119   }
120
121   PassManagerType getPassManagerType() const override {
122     return PMT_RegionPassManager;
123   }
124 };
125
126 } // End llvm namespace
127
128 #endif