1009b1c42SEd Schouten //===- LoopPass.cpp - Loop Pass and Loop Pass Manager ---------------------===//
2009b1c42SEd Schouten //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6009b1c42SEd Schouten //
7009b1c42SEd Schouten //===----------------------------------------------------------------------===//
8009b1c42SEd Schouten //
9009b1c42SEd Schouten // This file implements LoopPass and LPPassManager. All loop optimization
10009b1c42SEd Schouten // and transformation passes are derived from LoopPass. LPPassManager is
11009b1c42SEd Schouten // responsible for managing LoopPasses.
12009b1c42SEd Schouten //
13009b1c42SEd Schouten //===----------------------------------------------------------------------===//
14009b1c42SEd Schouten
15009b1c42SEd Schouten #include "llvm/Analysis/LoopPass.h"
16145449b1SDimitry Andric #include "llvm/Analysis/LoopInfo.h"
17b915e9e0SDimitry Andric #include "llvm/IR/Dominators.h"
185ca98fd9SDimitry Andric #include "llvm/IR/LLVMContext.h"
19ac9a064cSDimitry Andric #include "llvm/IR/Module.h"
2001095a5dSDimitry Andric #include "llvm/IR/OptBisect.h"
21d8e91e46SDimitry Andric #include "llvm/IR/PassTimingInfo.h"
22b60736ecSDimitry Andric #include "llvm/IR/PrintPasses.h"
23706b4fc4SDimitry Andric #include "llvm/InitializePasses.h"
24b5efedafSRoman Divacky #include "llvm/Support/Debug.h"
25e6d15924SDimitry Andric #include "llvm/Support/TimeProfiler.h"
26706b4fc4SDimitry Andric #include "llvm/Support/Timer.h"
275a5ac124SDimitry Andric #include "llvm/Support/raw_ostream.h"
28009b1c42SEd Schouten using namespace llvm;
29009b1c42SEd Schouten
305ca98fd9SDimitry Andric #define DEBUG_TYPE "loop-pass-manager"
315ca98fd9SDimitry Andric
32b5efedafSRoman Divacky namespace {
33b5efedafSRoman Divacky
34b5efedafSRoman Divacky /// PrintLoopPass - Print a Function corresponding to a Loop.
35b5efedafSRoman Divacky ///
36dd58ef01SDimitry Andric class PrintLoopPassWrapper : public LoopPass {
37581a6d85SDimitry Andric raw_ostream &OS;
38581a6d85SDimitry Andric std::string Banner;
39b5efedafSRoman Divacky
40b5efedafSRoman Divacky public:
41b5efedafSRoman Divacky static char ID;
PrintLoopPassWrapper()42581a6d85SDimitry Andric PrintLoopPassWrapper() : LoopPass(ID), OS(dbgs()) {}
PrintLoopPassWrapper(raw_ostream & OS,const std::string & Banner)43dd58ef01SDimitry Andric PrintLoopPassWrapper(raw_ostream &OS, const std::string &Banner)
44581a6d85SDimitry Andric : LoopPass(ID), OS(OS), Banner(Banner) {}
45b5efedafSRoman Divacky
getAnalysisUsage(AnalysisUsage & AU) const465ca98fd9SDimitry Andric void getAnalysisUsage(AnalysisUsage &AU) const override {
47b5efedafSRoman Divacky AU.setPreservesAll();
48b5efedafSRoman Divacky }
49b5efedafSRoman Divacky
runOnLoop(Loop * L,LPPassManager &)505ca98fd9SDimitry Andric bool runOnLoop(Loop *L, LPPassManager &) override {
51044eb2f6SDimitry Andric auto BBI = llvm::find_if(L->blocks(), [](BasicBlock *BB) { return BB; });
52050e163aSDimitry Andric if (BBI != L->blocks().end() &&
5301095a5dSDimitry Andric isFunctionInPrintList((*BBI)->getParent()->getName())) {
54581a6d85SDimitry Andric printLoop(*L, OS, Banner);
5501095a5dSDimitry Andric }
56b5efedafSRoman Divacky return false;
57b5efedafSRoman Divacky }
5871d5a254SDimitry Andric
getPassName() const5971d5a254SDimitry Andric StringRef getPassName() const override { return "Print Loop IR"; }
60b5efedafSRoman Divacky };
61b5efedafSRoman Divacky
62dd58ef01SDimitry Andric char PrintLoopPassWrapper::ID = 0;
63ac9a064cSDimitry Andric } // namespace
64b5efedafSRoman Divacky
65009b1c42SEd Schouten //===----------------------------------------------------------------------===//
66009b1c42SEd Schouten // LPPassManager
67009b1c42SEd Schouten //
68009b1c42SEd Schouten
69009b1c42SEd Schouten char LPPassManager::ID = 0;
70009b1c42SEd Schouten
LPPassManager()716f8fc217SDimitry Andric LPPassManager::LPPassManager() : FunctionPass(ID) {
725ca98fd9SDimitry Andric LI = nullptr;
735ca98fd9SDimitry Andric CurrentLoop = nullptr;
74009b1c42SEd Schouten }
75009b1c42SEd Schouten
76ab44ce3dSDimitry Andric // Insert loop into loop nest (LoopInfo) and loop queue (LQ).
addLoop(Loop & L)77ab44ce3dSDimitry Andric void LPPassManager::addLoop(Loop &L) {
78b60736ecSDimitry Andric if (L.isOutermost()) {
79dd58ef01SDimitry Andric // This is the top level loop.
80ab44ce3dSDimitry Andric LQ.push_front(&L);
81ab44ce3dSDimitry Andric return;
8259850d08SRoman Divacky }
8359850d08SRoman Divacky
84dd58ef01SDimitry Andric // Insert L into the loop queue after the parent loop.
85dd58ef01SDimitry Andric for (auto I = LQ.begin(), E = LQ.end(); I != E; ++I) {
86ab44ce3dSDimitry Andric if (*I == L.getParentLoop()) {
87009b1c42SEd Schouten // deque does not support insert after.
88009b1c42SEd Schouten ++I;
89ab44ce3dSDimitry Andric LQ.insert(I, 1, &L);
90ab44ce3dSDimitry Andric return;
91009b1c42SEd Schouten }
92009b1c42SEd Schouten }
93009b1c42SEd Schouten }
94009b1c42SEd Schouten
95009b1c42SEd Schouten // Recurse through all subloops and all loops into LQ.
addLoopIntoQueue(Loop * L,std::deque<Loop * > & LQ)96009b1c42SEd Schouten static void addLoopIntoQueue(Loop *L, std::deque<Loop *> &LQ) {
97009b1c42SEd Schouten LQ.push_back(L);
98b915e9e0SDimitry Andric for (Loop *I : reverse(*L))
99b915e9e0SDimitry Andric addLoopIntoQueue(I, LQ);
100009b1c42SEd Schouten }
101009b1c42SEd Schouten
102009b1c42SEd Schouten /// Pass Manager itself does not invalidate any analysis info.
getAnalysisUsage(AnalysisUsage & Info) const103009b1c42SEd Schouten void LPPassManager::getAnalysisUsage(AnalysisUsage &Info) const {
104009b1c42SEd Schouten // LPPassManager needs LoopInfo. In the long term LoopInfo class will
105009b1c42SEd Schouten // become part of LPPassManager.
1065a5ac124SDimitry Andric Info.addRequired<LoopInfoWrapperPass>();
107b915e9e0SDimitry Andric Info.addRequired<DominatorTreeWrapperPass>();
108009b1c42SEd Schouten Info.setPreservesAll();
109009b1c42SEd Schouten }
110009b1c42SEd Schouten
markLoopAsDeleted(Loop & L)111044eb2f6SDimitry Andric void LPPassManager::markLoopAsDeleted(Loop &L) {
112044eb2f6SDimitry Andric assert((&L == CurrentLoop || CurrentLoop->contains(&L)) &&
113044eb2f6SDimitry Andric "Must not delete loop outside the current loop tree!");
114eb11fae6SDimitry Andric // If this loop appears elsewhere within the queue, we also need to remove it
115eb11fae6SDimitry Andric // there. However, we have to be careful to not remove the back of the queue
116eb11fae6SDimitry Andric // as that is assumed to match the current loop.
117eb11fae6SDimitry Andric assert(LQ.back() == CurrentLoop && "Loop queue back isn't the current loop!");
118b1c73532SDimitry Andric llvm::erase(LQ, &L);
119eb11fae6SDimitry Andric
120eb11fae6SDimitry Andric if (&L == CurrentLoop) {
121044eb2f6SDimitry Andric CurrentLoopDeleted = true;
122eb11fae6SDimitry Andric // Add this loop back onto the back of the queue to preserve our invariants.
123eb11fae6SDimitry Andric LQ.push_back(&L);
124eb11fae6SDimitry Andric }
125044eb2f6SDimitry Andric }
126044eb2f6SDimitry Andric
127009b1c42SEd Schouten /// run - Execute all of the passes scheduled for execution. Keep track of
128009b1c42SEd Schouten /// whether any of the passes modifies the function, and if so, return true.
runOnFunction(Function & F)129009b1c42SEd Schouten bool LPPassManager::runOnFunction(Function &F) {
1305a5ac124SDimitry Andric auto &LIWP = getAnalysis<LoopInfoWrapperPass>();
1315a5ac124SDimitry Andric LI = &LIWP.getLoopInfo();
132eb11fae6SDimitry Andric Module &M = *F.getParent();
133eb11fae6SDimitry Andric #if 0
134b915e9e0SDimitry Andric DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
135eb11fae6SDimitry Andric #endif
136009b1c42SEd Schouten bool Changed = false;
137009b1c42SEd Schouten
138009b1c42SEd Schouten // Collect inherited analysis from Module level pass manager.
139009b1c42SEd Schouten populateInheritedAnalysis(TPM->activeStack);
140009b1c42SEd Schouten
14158b69754SDimitry Andric // Populate the loop queue in reverse program order. There is no clear need to
14258b69754SDimitry Andric // process sibling loops in either forward or reverse order. There may be some
14358b69754SDimitry Andric // advantage in deleting uses in a later loop before optimizing the
14458b69754SDimitry Andric // definitions in an earlier loop. If we find a clear reason to process in
14558b69754SDimitry Andric // forward order, then a forward variant of LoopPassManager should be created.
146f8af5cf6SDimitry Andric //
147f8af5cf6SDimitry Andric // Note that LoopInfo::iterator visits loops in reverse program
148f8af5cf6SDimitry Andric // order. Here, reverse_iterator gives us a forward order, and the LoopQueue
149f8af5cf6SDimitry Andric // reverses the order a third time by popping from the back.
150b915e9e0SDimitry Andric for (Loop *L : reverse(*LI))
151b915e9e0SDimitry Andric addLoopIntoQueue(L, LQ);
152009b1c42SEd Schouten
15318f153bdSEd Schouten if (LQ.empty()) // No loops, skip calling finalizers
15418f153bdSEd Schouten return false;
15518f153bdSEd Schouten
156009b1c42SEd Schouten // Initialization
157b915e9e0SDimitry Andric for (Loop *L : LQ) {
158009b1c42SEd Schouten for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
159d39c594dSDimitry Andric LoopPass *P = getContainedPass(Index);
160989df958SRoman Divacky Changed |= P->doInitialization(L, *this);
161009b1c42SEd Schouten }
162009b1c42SEd Schouten }
163009b1c42SEd Schouten
164009b1c42SEd Schouten // Walk Loops
165d8e91e46SDimitry Andric unsigned InstrCount, FunctionSize = 0;
166d8e91e46SDimitry Andric StringMap<std::pair<unsigned, unsigned>> FunctionToInstrCount;
167eb11fae6SDimitry Andric bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
168d8e91e46SDimitry Andric // Collect the initial size of the module and the function we're looking at.
169d8e91e46SDimitry Andric if (EmitICRemark) {
170d8e91e46SDimitry Andric InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
171d8e91e46SDimitry Andric FunctionSize = F.getInstructionCount();
172d8e91e46SDimitry Andric }
173009b1c42SEd Schouten while (!LQ.empty()) {
174044eb2f6SDimitry Andric CurrentLoopDeleted = false;
175009b1c42SEd Schouten CurrentLoop = LQ.back();
176050e163aSDimitry Andric
17759850d08SRoman Divacky // Run all passes on the current Loop.
178009b1c42SEd Schouten for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
179d39c594dSDimitry Andric LoopPass *P = getContainedPass(Index);
18063faed5bSDimitry Andric
181e6d15924SDimitry Andric llvm::TimeTraceScope LoopPassScope("RunLoopPass", P->getPassName());
182e6d15924SDimitry Andric
18359850d08SRoman Divacky dumpPassInfo(P, EXECUTION_MSG, ON_LOOP_MSG,
184104bd817SRoman Divacky CurrentLoop->getHeader()->getName());
185009b1c42SEd Schouten dumpRequiredSet(P);
186009b1c42SEd Schouten
187009b1c42SEd Schouten initializeAnalysisImpl(P);
18863faed5bSDimitry Andric
189d8e91e46SDimitry Andric bool LocalChanged = false;
190009b1c42SEd Schouten {
191989df958SRoman Divacky PassManagerPrettyStackEntry X(P, *CurrentLoop->getHeader());
192104bd817SRoman Divacky TimeRegion PassTimer(getPassTimer(P));
193b60736ecSDimitry Andric #ifdef EXPENSIVE_CHECKS
194145449b1SDimitry Andric uint64_t RefHash = P->structuralHash(F);
195b60736ecSDimitry Andric #endif
196d8e91e46SDimitry Andric LocalChanged = P->runOnLoop(CurrentLoop, *this);
197b60736ecSDimitry Andric
198b60736ecSDimitry Andric #ifdef EXPENSIVE_CHECKS
199145449b1SDimitry Andric if (!LocalChanged && (RefHash != P->structuralHash(F))) {
200b60736ecSDimitry Andric llvm::errs() << "Pass modifies its input and doesn't report it: "
201b60736ecSDimitry Andric << P->getPassName() << "\n";
202b60736ecSDimitry Andric llvm_unreachable("Pass modifies its input and doesn't report it");
203b60736ecSDimitry Andric }
204b60736ecSDimitry Andric #endif
205b60736ecSDimitry Andric
206d8e91e46SDimitry Andric Changed |= LocalChanged;
207d8e91e46SDimitry Andric if (EmitICRemark) {
208d8e91e46SDimitry Andric unsigned NewSize = F.getInstructionCount();
209d8e91e46SDimitry Andric // Update the size of the function, emit a remark, and update the
210d8e91e46SDimitry Andric // size of the module.
211d8e91e46SDimitry Andric if (NewSize != FunctionSize) {
212d8e91e46SDimitry Andric int64_t Delta = static_cast<int64_t>(NewSize) -
213d8e91e46SDimitry Andric static_cast<int64_t>(FunctionSize);
214d8e91e46SDimitry Andric emitInstrCountChangedRemark(P, M, Delta, InstrCount,
215d8e91e46SDimitry Andric FunctionToInstrCount, &F);
216d8e91e46SDimitry Andric InstrCount = static_cast<int64_t>(InstrCount) + Delta;
217d8e91e46SDimitry Andric FunctionSize = NewSize;
218d8e91e46SDimitry Andric }
219d8e91e46SDimitry Andric }
220009b1c42SEd Schouten }
221009b1c42SEd Schouten
222d8e91e46SDimitry Andric if (LocalChanged)
22359850d08SRoman Divacky dumpPassInfo(P, MODIFICATION_MSG, ON_LOOP_MSG,
224044eb2f6SDimitry Andric CurrentLoopDeleted ? "<deleted loop>"
225044eb2f6SDimitry Andric : CurrentLoop->getName());
226009b1c42SEd Schouten dumpPreservedSet(P);
227009b1c42SEd Schouten
228cfca06d7SDimitry Andric if (!CurrentLoopDeleted) {
22959850d08SRoman Divacky // Manually check that this loop is still healthy. This is done
23059850d08SRoman Divacky // instead of relying on LoopInfo::verifyLoop since LoopInfo
23159850d08SRoman Divacky // is a function pass and it's really expensive to verify every
23259850d08SRoman Divacky // loop in the function every time. That level of checking can be
23359850d08SRoman Divacky // enabled with the -verify-loop-info option.
234104bd817SRoman Divacky {
2355a5ac124SDimitry Andric TimeRegion PassTimer(getPassTimer(&LIWP));
23659850d08SRoman Divacky CurrentLoop->verifyLoop();
237104bd817SRoman Divacky }
238b915e9e0SDimitry Andric // Here we apply same reasoning as in the above case. Only difference
239b915e9e0SDimitry Andric // is that LPPassManager might run passes which do not require LCSSA
240b915e9e0SDimitry Andric // form (LoopPassPrinter for example). We should skip verification for
241b915e9e0SDimitry Andric // such passes.
242eb11fae6SDimitry Andric // FIXME: Loop-sink currently break LCSSA. Fix it and reenable the
243eb11fae6SDimitry Andric // verification!
244eb11fae6SDimitry Andric #if 0
245b915e9e0SDimitry Andric if (mustPreserveAnalysisID(LCSSAVerificationPass::ID))
246eb11fae6SDimitry Andric assert(CurrentLoop->isRecursivelyLCSSAForm(*DT, *LI));
247eb11fae6SDimitry Andric #endif
24859850d08SRoman Divacky
24959850d08SRoman Divacky // Then call the regular verifyAnalysis functions.
250989df958SRoman Divacky verifyPreservedAnalysis(P);
2515ca98fd9SDimitry Andric
2525ca98fd9SDimitry Andric F.getContext().yield();
25359850d08SRoman Divacky }
25459850d08SRoman Divacky
255b60736ecSDimitry Andric if (LocalChanged)
256009b1c42SEd Schouten removeNotPreservedAnalysis(P);
257009b1c42SEd Schouten recordAvailableAnalysis(P);
258044eb2f6SDimitry Andric removeDeadPasses(P,
259044eb2f6SDimitry Andric CurrentLoopDeleted ? "<deleted>"
260dd58ef01SDimitry Andric : CurrentLoop->getHeader()->getName(),
26159850d08SRoman Divacky ON_LOOP_MSG);
262009b1c42SEd Schouten
263044eb2f6SDimitry Andric if (CurrentLoopDeleted)
264009b1c42SEd Schouten // Do not run other passes on this loop.
265009b1c42SEd Schouten break;
266009b1c42SEd Schouten }
267009b1c42SEd Schouten
26859850d08SRoman Divacky // If the loop was deleted, release all the loop passes. This frees up
26959850d08SRoman Divacky // some memory, and avoids trouble with the pass manager trying to call
27059850d08SRoman Divacky // verifyAnalysis on them.
271044eb2f6SDimitry Andric if (CurrentLoopDeleted) {
27259850d08SRoman Divacky for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
27359850d08SRoman Divacky Pass *P = getContainedPass(Index);
27459850d08SRoman Divacky freePass(P, "<deleted>", ON_LOOP_MSG);
27559850d08SRoman Divacky }
276dd58ef01SDimitry Andric }
27759850d08SRoman Divacky
278009b1c42SEd Schouten // Pop the loop from queue after running all passes.
279009b1c42SEd Schouten LQ.pop_back();
280009b1c42SEd Schouten }
281009b1c42SEd Schouten
282009b1c42SEd Schouten // Finalization
283009b1c42SEd Schouten for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
284d39c594dSDimitry Andric LoopPass *P = getContainedPass(Index);
285989df958SRoman Divacky Changed |= P->doFinalization();
286009b1c42SEd Schouten }
287009b1c42SEd Schouten
288009b1c42SEd Schouten return Changed;
289009b1c42SEd Schouten }
290009b1c42SEd Schouten
291009b1c42SEd Schouten /// Print passes managed by this manager
dumpPassStructure(unsigned Offset)292009b1c42SEd Schouten void LPPassManager::dumpPassStructure(unsigned Offset) {
29359850d08SRoman Divacky errs().indent(Offset*2) << "Loop Pass Manager\n";
294009b1c42SEd Schouten for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
295009b1c42SEd Schouten Pass *P = getContainedPass(Index);
296009b1c42SEd Schouten P->dumpPassStructure(Offset + 1);
297009b1c42SEd Schouten dumpLastUses(P, Offset+1);
298009b1c42SEd Schouten }
299009b1c42SEd Schouten }
300009b1c42SEd Schouten
301009b1c42SEd Schouten
302009b1c42SEd Schouten //===----------------------------------------------------------------------===//
303009b1c42SEd Schouten // LoopPass
304009b1c42SEd Schouten
createPrinterPass(raw_ostream & O,const std::string & Banner) const305b5efedafSRoman Divacky Pass *LoopPass::createPrinterPass(raw_ostream &O,
306b5efedafSRoman Divacky const std::string &Banner) const {
307dd58ef01SDimitry Andric return new PrintLoopPassWrapper(O, Banner);
308b5efedafSRoman Divacky }
309b5efedafSRoman Divacky
310009b1c42SEd Schouten // Check if this pass is suitable for the current LPPassManager, if
311009b1c42SEd Schouten // available. This pass P is not suitable for a LPPassManager if P
312009b1c42SEd Schouten // is not preserving higher level analysis info used by other
313009b1c42SEd Schouten // LPPassManager passes. In such case, pop LPPassManager from the
314009b1c42SEd Schouten // stack. This will force assignPassManager() to create new
315009b1c42SEd Schouten // LPPassManger as expected.
preparePassManager(PMStack & PMS)316009b1c42SEd Schouten void LoopPass::preparePassManager(PMStack &PMS) {
317009b1c42SEd Schouten
318009b1c42SEd Schouten // Find LPPassManager
319009b1c42SEd Schouten while (!PMS.empty() &&
320009b1c42SEd Schouten PMS.top()->getPassManagerType() > PMT_LoopPassManager)
321009b1c42SEd Schouten PMS.pop();
322009b1c42SEd Schouten
323009b1c42SEd Schouten // If this pass is destroying high level information that is used
324009b1c42SEd Schouten // by other passes that are managed by LPM then do not insert
325009b1c42SEd Schouten // this pass in current LPM. Use new LPPassManager.
326989df958SRoman Divacky if (PMS.top()->getPassManagerType() == PMT_LoopPassManager &&
327989df958SRoman Divacky !PMS.top()->preserveHigherLevelAnalysis(this))
328009b1c42SEd Schouten PMS.pop();
329009b1c42SEd Schouten }
330009b1c42SEd Schouten
331009b1c42SEd Schouten /// Assign pass manager to manage this pass.
assignPassManager(PMStack & PMS,PassManagerType PreferredType)332009b1c42SEd Schouten void LoopPass::assignPassManager(PMStack &PMS,
333009b1c42SEd Schouten PassManagerType PreferredType) {
334009b1c42SEd Schouten // Find LPPassManager
335009b1c42SEd Schouten while (!PMS.empty() &&
336009b1c42SEd Schouten PMS.top()->getPassManagerType() > PMT_LoopPassManager)
337009b1c42SEd Schouten PMS.pop();
338009b1c42SEd Schouten
339989df958SRoman Divacky LPPassManager *LPPM;
340989df958SRoman Divacky if (PMS.top()->getPassManagerType() == PMT_LoopPassManager)
341989df958SRoman Divacky LPPM = (LPPassManager*)PMS.top();
342989df958SRoman Divacky else {
343009b1c42SEd Schouten // Create new Loop Pass Manager if it does not exist.
344009b1c42SEd Schouten assert (!PMS.empty() && "Unable to create Loop Pass Manager");
345009b1c42SEd Schouten PMDataManager *PMD = PMS.top();
346009b1c42SEd Schouten
34730815c53SDimitry Andric // [1] Create new Loop Pass Manager
34830815c53SDimitry Andric LPPM = new LPPassManager();
349009b1c42SEd Schouten LPPM->populateInheritedAnalysis(PMS);
350009b1c42SEd Schouten
351009b1c42SEd Schouten // [2] Set up new manager's top level manager
352009b1c42SEd Schouten PMTopLevelManager *TPM = PMD->getTopLevelManager();
353009b1c42SEd Schouten TPM->addIndirectPassManager(LPPM);
354009b1c42SEd Schouten
355009b1c42SEd Schouten // [3] Assign manager to manage this new manager. This may create
356009b1c42SEd Schouten // and push new managers into PMS
357989df958SRoman Divacky Pass *P = LPPM->getAsPass();
358009b1c42SEd Schouten TPM->schedulePass(P);
359009b1c42SEd Schouten
360009b1c42SEd Schouten // [4] Push new manager into PMS
361009b1c42SEd Schouten PMS.push(LPPM);
362009b1c42SEd Schouten }
363009b1c42SEd Schouten
364009b1c42SEd Schouten LPPM->add(this);
365009b1c42SEd Schouten }
3665ca98fd9SDimitry Andric
getDescription(const Loop & L)367e6d15924SDimitry Andric static std::string getDescription(const Loop &L) {
368e6d15924SDimitry Andric return "loop";
369e6d15924SDimitry Andric }
370e6d15924SDimitry Andric
skipLoop(const Loop * L) const37101095a5dSDimitry Andric bool LoopPass::skipLoop(const Loop *L) const {
3725ca98fd9SDimitry Andric const Function *F = L->getHeader()->getParent();
37301095a5dSDimitry Andric if (!F)
37401095a5dSDimitry Andric return false;
37501095a5dSDimitry Andric // Check the opt bisect limit.
376e6d15924SDimitry Andric OptPassGate &Gate = F->getContext().getOptPassGate();
377e3b55780SDimitry Andric if (Gate.isEnabled() &&
378e3b55780SDimitry Andric !Gate.shouldRunPass(this->getPassName(), getDescription(*L)))
37901095a5dSDimitry Andric return true;
38001095a5dSDimitry Andric // Check for the OptimizeNone attribute.
381e6d15924SDimitry Andric if (F->hasOptNone()) {
3825ca98fd9SDimitry Andric // FIXME: Report this to dbgs() only once per function.
383eb11fae6SDimitry Andric LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName() << "' in function "
384eb11fae6SDimitry Andric << F->getName() << "\n");
3855ca98fd9SDimitry Andric // FIXME: Delete loop from pass manager's queue?
3865ca98fd9SDimitry Andric return true;
3875ca98fd9SDimitry Andric }
3885ca98fd9SDimitry Andric return false;
3895ca98fd9SDimitry Andric }
390b915e9e0SDimitry Andric
LCSSAVerificationPass()391706b4fc4SDimitry Andric LCSSAVerificationPass::LCSSAVerificationPass() : FunctionPass(ID) {
392706b4fc4SDimitry Andric initializeLCSSAVerificationPassPass(*PassRegistry::getPassRegistry());
393706b4fc4SDimitry Andric }
394706b4fc4SDimitry Andric
395b915e9e0SDimitry Andric char LCSSAVerificationPass::ID = 0;
396b915e9e0SDimitry Andric INITIALIZE_PASS(LCSSAVerificationPass, "lcssa-verification", "LCSSA Verifier",
397b915e9e0SDimitry Andric false, false)
398