LLVM 22.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"
20#include <deque>
21
22namespace llvm {
23
24class Loop;
25class LoopInfo;
26class LPPassManager;
27class Function;
28
29class LLVM_ABI LoopPass : public Pass {
30public:
31 explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
32
33 /// getPrinterPass - Get a pass to print the function corresponding
34 /// to a Loop.
35 Pass *createPrinterPass(raw_ostream &O,
36 const std::string &Banner) const override;
37
38 // runOnLoop - This method should be implemented by the subclass to perform
39 // whatever action is necessary for the specified Loop.
40 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
41
44
45 // Initialization and finalization hooks.
46 virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
47 return false;
48 }
49
50 // Finalization hook does not supply Loop because at this time
51 // loop nest is completely different.
52 virtual bool doFinalization() { return false; }
53
54 // Check if this pass is suitable for the current LPPassManager, if
55 // available. This pass P is not suitable for a LPPassManager if P
56 // is not preserving higher level analysis info used by other
57 // LPPassManager passes. In such case, pop LPPassManager from the
58 // stack. This will force assignPassManager() to create new
59 // LPPassManger as expected.
60 void preparePassManager(PMStack &PMS) override;
61
62 /// Assign pass manager to manage this pass
63 void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
64
65 /// Return what kind of Pass Manager can manage this pass.
68 }
69
70protected:
71 /// Optional passes call this function to check whether the pass should be
72 /// skipped. This is the case when Attribute::OptimizeNone is set or when
73 /// optimization bisect is over the limit.
74 bool skipLoop(const Loop *L) const;
75};
76
78public:
79 static char ID;
80 explicit LPPassManager();
81
82 /// run - Execute all of the passes scheduled for execution. Keep track of
83 /// whether any of the passes modifies the module, and if so, return true.
84 bool runOnFunction(Function &F) override;
85
86 /// Pass Manager itself does not invalidate any analysis info.
87 // LPPassManager needs LoopInfo.
88 void getAnalysisUsage(AnalysisUsage &Info) const override;
89
90 StringRef getPassName() const override { return "Loop Pass Manager"; }
91
92 PMDataManager *getAsPMDataManager() override { return this; }
93 Pass *getAsPass() override { return this; }
94
95 /// Print passes managed by this manager
96 void dumpPassStructure(unsigned Offset) override;
97
99 assert(N < PassVector.size() && "Pass number out of range!");
100 LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
101 return LP;
102 }
103
105 return PMT_LoopPassManager;
106 }
107
108public:
109 // Add a new loop into the loop queue.
110 void addLoop(Loop &L);
111
112 // Mark \p L as deleted.
113 void markLoopAsDeleted(Loop &L);
114
115private:
116 std::deque<Loop *> LQ;
117 LoopInfo *LI;
118 Loop *CurrentLoop;
119 bool CurrentLoopDeleted;
120};
121
122// This pass is required by the LCSSA transformation. It is used inside
123// LPPassManager to check if current pass preserves LCSSA form, and if it does
124// pass manager calls lcssa verification for the current loop.
126 LLVM_ABI static char ID;
128
129 bool runOnFunction(Function &F) override { return false; }
130
131 void getAnalysisUsage(AnalysisUsage &AU) const override {
132 AU.setPreservesAll();
133 }
134};
135
136} // End llvm namespace
137
138#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define LLVM_ABI
Definition: Compiler.h:213
uint64_t Offset
Definition: ELF_riscv.cpp:478
static bool runOnFunction(Function &F, bool PostInlining)
#define F(x, y, z)
Definition: MD5.cpp:55
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:314
static char ID
Definition: LoopPass.h:79
Pass * getAsPass() override
Definition: LoopPass.h:93
PassManagerType getPassManagerType() const override
Definition: LoopPass.h:104
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: LoopPass.h:90
PMDataManager * getAsPMDataManager() override
Definition: LoopPass.h:92
LoopPass * getContainedPass(unsigned N)
Definition: LoopPass.h:98
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: LoopPass.h:66
virtual bool doInitialization(Loop *L, LPPassManager &LPM)
Definition: LoopPass.h:46
LoopPass(char &pid)
Definition: LoopPass.h:31
virtual bool runOnLoop(Loop *L, LPPassManager &LPM)=0
virtual bool doFinalization()
Definition: LoopPass.h:52
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:40
PMDataManager provides the common place to manage the analysis data used by pass managers.
PMStack - This class implements a stack data structure of PMDataManager pointers.
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:128
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:132
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ PT_Loop
Definition: Pass.h:69
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:56
@ PMT_LoopPassManager
LPPassManager.
Definition: Pass.h:61
#define N
static LLVM_ABI char ID
Definition: LoopPass.h:126
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Definition: LoopPass.h:129
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LoopPass.h:131
LLVM_ABI LCSSAVerificationPass()
Definition: LoopPass.cpp:391