Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / include / llvm / Analysis / LoopPass.h
blobc5f08d0ae8af68af4c429d0a062ce3d036f8c6f7
1 //===- LoopPass.h - LoopPass class ----------------------------------------===//
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 LoopPass class. All loop optimization
10 // and transformation passes are derived from LoopPass.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_LOOPPASS_H
15 #define LLVM_ANALYSIS_LOOPPASS_H
17 #include "llvm/IR/LegacyPassManagers.h"
18 #include "llvm/Pass.h"
19 #include <deque>
21 namespace llvm {
23 class Loop;
24 class LoopInfo;
25 class LPPassManager;
26 class Function;
28 class LoopPass : public Pass {
29 public:
30 explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
32 /// getPrinterPass - Get a pass to print the function corresponding
33 /// to a Loop.
34 Pass *createPrinterPass(raw_ostream &O,
35 const std::string &Banner) const override;
37 // runOnLoop - This method should be implemented by the subclass to perform
38 // whatever action is necessary for the specified Loop.
39 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
41 using llvm::Pass::doInitialization;
42 using llvm::Pass::doFinalization;
44 // Initialization and finalization hooks.
45 virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
46 return false;
49 // Finalization hook does not supply Loop because at this time
50 // loop nest is completely different.
51 virtual bool doFinalization() { return false; }
53 // Check if this pass is suitable for the current LPPassManager, if
54 // available. This pass P is not suitable for a LPPassManager if P
55 // is not preserving higher level analysis info used by other
56 // LPPassManager passes. In such case, pop LPPassManager from the
57 // stack. This will force assignPassManager() to create new
58 // LPPassManger as expected.
59 void preparePassManager(PMStack &PMS) override;
61 /// Assign pass manager to manage this pass
62 void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
64 /// Return what kind of Pass Manager can manage this pass.
65 PassManagerType getPotentialPassManagerType() const override {
66 return PMT_LoopPassManager;
69 protected:
70 /// Optional passes call this function to check whether the pass should be
71 /// skipped. This is the case when Attribute::OptimizeNone is set or when
72 /// optimization bisect is over the limit.
73 bool skipLoop(const Loop *L) const;
76 class LPPassManager : public FunctionPass, public PMDataManager {
77 public:
78 static char ID;
79 explicit LPPassManager();
81 /// run - Execute all of the passes scheduled for execution. Keep track of
82 /// whether any of the passes modifies the module, and if so, return true.
83 bool runOnFunction(Function &F) override;
85 /// Pass Manager itself does not invalidate any analysis info.
86 // LPPassManager needs LoopInfo.
87 void getAnalysisUsage(AnalysisUsage &Info) const override;
89 StringRef getPassName() const override { return "Loop Pass Manager"; }
91 PMDataManager *getAsPMDataManager() override { return this; }
92 Pass *getAsPass() override { return this; }
94 /// Print passes managed by this manager
95 void dumpPassStructure(unsigned Offset) override;
97 LoopPass *getContainedPass(unsigned N) {
98 assert(N < PassVector.size() && "Pass number out of range!");
99 LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
100 return LP;
103 PassManagerType getPassManagerType() const override {
104 return PMT_LoopPassManager;
107 public:
108 // Add a new loop into the loop queue.
109 void addLoop(Loop &L);
111 // Mark \p L as deleted.
112 void markLoopAsDeleted(Loop &L);
114 private:
115 std::deque<Loop *> LQ;
116 LoopInfo *LI;
117 Loop *CurrentLoop;
118 bool CurrentLoopDeleted;
121 // This pass is required by the LCSSA transformation. It is used inside
122 // LPPassManager to check if current pass preserves LCSSA form, and if it does
123 // pass manager calls lcssa verification for the current loop.
124 struct LCSSAVerificationPass : public FunctionPass {
125 static char ID;
126 LCSSAVerificationPass();
128 bool runOnFunction(Function &F) override { return false; }
130 void getAnalysisUsage(AnalysisUsage &AU) const override {
131 AU.setPreservesAll();
135 } // End llvm namespace
137 #endif