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