LLVM 19.0.0git
LoopPass.h
Go to the documentation of this file.
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.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_LOOPPASS_H
15#define LLVM_ANALYSIS_LOOPPASS_H
16
18#include "llvm/Pass.h"
19#include <deque>
20
21namespace llvm {
22
23class Loop;
24class LoopInfo;
25class LPPassManager;
26class Function;
27
28class LoopPass : public Pass {
29public:
30 explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
31
32 /// getPrinterPass - Get a pass to print the function corresponding
33 /// to a Loop.
35 const std::string &Banner) const override;
36
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;
40
43
44 // Initialization and finalization hooks.
45 virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
46 return false;
47 }
48
49 // Finalization hook does not supply Loop because at this time
50 // loop nest is completely different.
51 virtual bool doFinalization() { return false; }
52
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;
60
61 /// Assign pass manager to manage this pass
62 void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
63
64 /// Return what kind of Pass Manager can manage this pass.
67 }
68
69protected:
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;
74};
75
77public:
78 static char ID;
79 explicit LPPassManager();
80
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;
84
85 /// Pass Manager itself does not invalidate any analysis info.
86 // LPPassManager needs LoopInfo.
87 void getAnalysisUsage(AnalysisUsage &Info) const override;
88
89 StringRef getPassName() const override { return "Loop Pass Manager"; }
90
91 PMDataManager *getAsPMDataManager() override { return this; }
92 Pass *getAsPass() override { return this; }
93
94 /// Print passes managed by this manager
95 void dumpPassStructure(unsigned Offset) override;
96
98 assert(N < PassVector.size() && "Pass number out of range!");
99 LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
100 return LP;
101 }
102
104 return PMT_LoopPassManager;
105 }
106
107public:
108 // Add a new loop into the loop queue.
109 void addLoop(Loop &L);
110
111 // Mark \p L as deleted.
112 void markLoopAsDeleted(Loop &L);
113
114private:
115 std::deque<Loop *> LQ;
116 LoopInfo *LI;
117 Loop *CurrentLoop;
118 bool CurrentLoopDeleted;
119};
120
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.
125 static char ID;
127
128 bool runOnFunction(Function &F) override { return false; }
129
130 void getAnalysisUsage(AnalysisUsage &AU) const override {
131 AU.setPreservesAll();
132 }
133};
134
135} // End llvm namespace
136
137#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.
void setPreservesAll()
Set by analyses that do not transform their input at all.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
static char ID
Definition: LoopPass.h:78
bool runOnFunction(Function &F) override
run - Execute all of the passes scheduled for execution.
Definition: LoopPass.cpp:128
Pass * getAsPass() override
Definition: LoopPass.h:92
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
Definition: LoopPass.cpp:291
PassManagerType getPassManagerType() const override
Definition: LoopPass.h:103
void markLoopAsDeleted(Loop &L)
Definition: LoopPass.cpp:110
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: LoopPass.h:89
PMDataManager * getAsPMDataManager() override
Definition: LoopPass.h:91
void addLoop(Loop &L)
Definition: LoopPass.cpp:76
LoopPass * getContainedPass(unsigned N)
Definition: LoopPass.h:97
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition: LoopPass.cpp:102
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: LoopPass.h:65
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: LoopPass.cpp:315
virtual bool doInitialization(Loop *L, LPPassManager &LPM)
Definition: LoopPass.h:45
LoopPass(char &pid)
Definition: LoopPass.h:30
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
getPrinterPass - Get a pass to print the function corresponding to a Loop.
Definition: LoopPass.cpp:304
virtual bool runOnLoop(Loop *L, LPPassManager &LPM)=0
virtual bool doFinalization()
Definition: LoopPass.h:51
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manage this pass.
Definition: LoopPass.cpp:331
bool skipLoop(const Loop *L) const
Optional passes call this function to check whether the pass should be skipped.
Definition: LoopPass.cpp:370
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:44
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
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:456
@ PT_Loop
Definition: Pass.h:68
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:55
@ PMT_LoopPassManager
LPPassManager.
Definition: Pass.h:60
#define N
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Definition: LoopPass.h:128
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LoopPass.h:130