LLVM 20.0.0git
LegacyPassManager.cpp
Go to the documentation of this file.
1//===- LegacyPassManager.cpp - LLVM Pass Infrastructure Implementation ----===//
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 implements the legacy LLVM Pass Manager infrastructure.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/MapVector.h"
17#include "llvm/IR/LLVMContext.h"
19#include "llvm/IR/Module.h"
21#include "llvm/IR/PrintPasses.h"
22#include "llvm/Support/Chrono.h"
24#include "llvm/Support/Debug.h"
25#include "llvm/Support/Error.h"
28#include "llvm/Support/Timer.h"
30#include <algorithm>
31
32using namespace llvm;
33
35// See PassManagers.h for Pass Manager infrastructure overview.
36
37//===----------------------------------------------------------------------===//
38// Pass debugging information. Often it is useful to find out what pass is
39// running when a crash occurs in a utility. When this library is compiled with
40// debugging on, a command line option (--debug-pass) is enabled that causes the
41// pass name to be printed before it executes.
42//
43
44namespace {
45// Different debug levels that can be enabled...
46enum PassDebugLevel {
47 Disabled, Arguments, Structure, Executions, Details
48};
49} // namespace
50
52 "debug-pass", cl::Hidden,
53 cl::desc("Print legacy PassManager debugging information"),
54 cl::values(clEnumVal(Disabled, "disable debug output"),
55 clEnumVal(Arguments, "print pass arguments to pass to 'opt'"),
56 clEnumVal(Structure, "print pass structure before run()"),
57 clEnumVal(Executions, "print pass name before it is executed"),
58 clEnumVal(Details, "print pass details when it is executed")));
59
60/// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
61/// or higher is specified.
63 return PassDebugging >= Executions;
64}
65
67 Module &M, StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount) {
68 // Only calculate getInstructionCount if the size-info remark is requested.
69 unsigned InstrCount = 0;
70
71 // Collect instruction counts for every function. We'll use this to emit
72 // per-function size remarks later.
73 for (Function &F : M) {
74 unsigned FCount = F.getInstructionCount();
75
76 // Insert a record into FunctionToInstrCount keeping track of the current
77 // size of the function as the first member of a pair. Set the second
78 // member to 0; if the function is deleted by the pass, then when we get
79 // here, we'll be able to let the user know that F no longer contributes to
80 // the module.
81 FunctionToInstrCount[F.getName().str()] =
82 std::pair<unsigned, unsigned>(FCount, 0);
83 InstrCount += FCount;
84 }
85 return InstrCount;
86}
87
89 Pass *P, Module &M, int64_t Delta, unsigned CountBefore,
90 StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount,
91 Function *F) {
92 // If it's a pass manager, don't emit a remark. (This hinges on the assumption
93 // that the only passes that return non-null with getAsPMDataManager are pass
94 // managers.) The reason we have to do this is to avoid emitting remarks for
95 // CGSCC passes.
96 if (P->getAsPMDataManager())
97 return;
98
99 // Set to true if this isn't a module pass or CGSCC pass.
100 bool CouldOnlyImpactOneFunction = (F != nullptr);
101
102 // Helper lambda that updates the changes to the size of some function.
103 auto UpdateFunctionChanges =
104 [&FunctionToInstrCount](Function &MaybeChangedFn) {
105 // Update the total module count.
106 unsigned FnSize = MaybeChangedFn.getInstructionCount();
107
108 // If we created a new function, then we need to add it to the map and
109 // say that it changed from 0 instructions to FnSize.
110 auto [It, Inserted] = FunctionToInstrCount.try_emplace(
111 MaybeChangedFn.getName(), 0, FnSize);
112 if (Inserted)
113 return;
114 // Insert the new function size into the second member of the pair. This
115 // tells us whether or not this function changed in size.
116 It->second.second = FnSize;
117 };
118
119 // We need to initially update all of the function sizes.
120 // If no function was passed in, then we're either a module pass or an
121 // CGSCC pass.
122 if (!CouldOnlyImpactOneFunction)
123 std::for_each(M.begin(), M.end(), UpdateFunctionChanges);
124 else
125 UpdateFunctionChanges(*F);
126
127 // Do we have a function we can use to emit a remark?
128 if (!CouldOnlyImpactOneFunction) {
129 // We need a function containing at least one basic block in order to output
130 // remarks. Since it's possible that the first function in the module
131 // doesn't actually contain a basic block, we have to go and find one that's
132 // suitable for emitting remarks.
133 auto It = llvm::find_if(M, [](const Function &Fn) { return !Fn.empty(); });
134
135 // Didn't find a function. Quit.
136 if (It == M.end())
137 return;
138
139 // We found a function containing at least one basic block.
140 F = &*It;
141 }
142 int64_t CountAfter = static_cast<int64_t>(CountBefore) + Delta;
143 BasicBlock &BB = *F->begin();
144 OptimizationRemarkAnalysis R("size-info", "IRSizeChange",
145 DiagnosticLocation(), &BB);
146 // FIXME: Move ore namespace to DiagnosticInfo so that we can use it. This
147 // would let us use NV instead of DiagnosticInfoOptimizationBase::Argument.
148 R << DiagnosticInfoOptimizationBase::Argument("Pass", P->getPassName())
149 << ": IR instruction count changed from "
150 << DiagnosticInfoOptimizationBase::Argument("IRInstrsBefore", CountBefore)
151 << " to "
152 << DiagnosticInfoOptimizationBase::Argument("IRInstrsAfter", CountAfter)
153 << "; Delta: "
154 << DiagnosticInfoOptimizationBase::Argument("DeltaInstrCount", Delta);
155 F->getContext().diagnose(R); // Not using ORE for layering reasons.
156
157 // Emit per-function size change remarks separately.
158 std::string PassName = P->getPassName().str();
159
160 // Helper lambda that emits a remark when the size of a function has changed.
161 auto EmitFunctionSizeChangedRemark = [&FunctionToInstrCount, &F, &BB,
162 &PassName](StringRef Fname) {
163 unsigned FnCountBefore, FnCountAfter;
164 std::pair<unsigned, unsigned> &Change = FunctionToInstrCount[Fname];
165 std::tie(FnCountBefore, FnCountAfter) = Change;
166 int64_t FnDelta = static_cast<int64_t>(FnCountAfter) -
167 static_cast<int64_t>(FnCountBefore);
168
169 if (FnDelta == 0)
170 return;
171
172 // FIXME: We shouldn't use BB for the location here. Unfortunately, because
173 // the function that we're looking at could have been deleted, we can't use
174 // it for the source location. We *want* remarks when a function is deleted
175 // though, so we're kind of stuck here as is. (This remark, along with the
176 // whole-module size change remarks really ought not to have source
177 // locations at all.)
178 OptimizationRemarkAnalysis FR("size-info", "FunctionIRSizeChange",
179 DiagnosticLocation(), &BB);
181 << ": Function: "
182 << DiagnosticInfoOptimizationBase::Argument("Function", Fname)
183 << ": IR instruction count changed from "
185 FnCountBefore)
186 << " to "
188 FnCountAfter)
189 << "; Delta: "
190 << DiagnosticInfoOptimizationBase::Argument("DeltaInstrCount", FnDelta);
191 F->getContext().diagnose(FR);
192
193 // Update the function size.
194 Change.first = FnCountAfter;
195 };
196
197 // Are we looking at more than one function? If so, emit remarks for all of
198 // the functions in the module. Otherwise, only emit one remark.
199 if (!CouldOnlyImpactOneFunction)
200 std::for_each(FunctionToInstrCount.keys().begin(),
201 FunctionToInstrCount.keys().end(),
202 EmitFunctionSizeChangedRemark);
203 else
204 EmitFunctionSizeChangedRemark(F->getName().str());
205}
206
208 if (!V && !M)
209 OS << "Releasing pass '";
210 else
211 OS << "Running pass '";
212
213 OS << P->getPassName() << "'";
214
215 if (M) {
216 OS << " on module '" << M->getModuleIdentifier() << "'.\n";
217 return;
218 }
219 if (!V) {
220 OS << '\n';
221 return;
222 }
223
224 OS << " on ";
225 if (isa<Function>(V))
226 OS << "function";
227 else if (isa<BasicBlock>(V))
228 OS << "basic block";
229 else
230 OS << "value";
231
232 OS << " '";
233 V->printAsOperand(OS, /*PrintType=*/false, M);
234 OS << "'\n";
235}
236
237namespace llvm {
238namespace legacy {
240
241//===----------------------------------------------------------------------===//
242// FunctionPassManagerImpl
243//
244/// FunctionPassManagerImpl manages FPPassManagers
246 public PMDataManager,
247 public PMTopLevelManager {
248 virtual void anchor();
249private:
250 bool wasRun;
251public:
252 static char ID;
255 wasRun(false) {}
256
257 /// \copydoc FunctionPassManager::add()
258 void add(Pass *P) {
260 }
261
262 /// createPrinterPass - Get a function printer pass.
264 const std::string &Banner) const override {
265 return createPrintFunctionPass(O, Banner);
266 }
267
268 // Prepare for running an on the fly pass, freeing memory if needed
269 // from a previous run.
271
272 /// run - Execute all of the passes scheduled for execution. Keep track of
273 /// whether any of the passes modifies the module, and if so, return true.
274 bool run(Function &F);
275
276 /// doInitialization - Run all of the initializers for the function passes.
277 ///
278 bool doInitialization(Module &M) override;
279
280 /// doFinalization - Run all of the finalizers for the function passes.
281 ///
282 bool doFinalization(Module &M) override;
283
284
285 PMDataManager *getAsPMDataManager() override { return this; }
286 Pass *getAsPass() override { return this; }
289 }
290
291 /// Pass Manager itself does not invalidate any analysis info.
292 void getAnalysisUsage(AnalysisUsage &Info) const override {
293 Info.setPreservesAll();
294 }
295
297 assert(N < PassManagers.size() && "Pass number out of range!");
298 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
299 return FP;
300 }
301
302 void dumpPassStructure(unsigned Offset) override {
303 for (unsigned I = 0; I < getNumContainedManagers(); ++I)
305 }
306};
307
308void FunctionPassManagerImpl::anchor() {}
309
311
312//===----------------------------------------------------------------------===//
313// FunctionPassManagerImpl implementation
314//
316 bool Changed = false;
317
319 dumpPasses();
320
321 for (ImmutablePass *ImPass : getImmutablePasses())
322 Changed |= ImPass->doInitialization(M);
323
324 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
325 Changed |= getContainedManager(Index)->doInitialization(M);
326
327 return Changed;
328}
329
331 bool Changed = false;
332
333 for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index)
334 Changed |= getContainedManager(Index)->doFinalization(M);
335
336 for (ImmutablePass *ImPass : getImmutablePasses())
337 Changed |= ImPass->doFinalization(M);
338
339 return Changed;
340}
341
343 if (!wasRun)
344 return;
345 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
346 FPPassManager *FPPM = getContainedManager(Index);
347 for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) {
348 FPPM->getContainedPass(Index)->releaseMemory();
349 }
350 }
351 wasRun = false;
352}
353
354// Execute all the passes managed by this top level manager.
355// Return true if any function is modified by a pass.
357 bool Changed = false;
358
360 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
361 Changed |= getContainedManager(Index)->runOnFunction(F);
362 F.getContext().yield();
363 }
364
365 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
367
368 wasRun = true;
369 return Changed;
370}
371} // namespace legacy
372} // namespace llvm
373
374namespace {
375//===----------------------------------------------------------------------===//
376// MPPassManager
377//
378/// MPPassManager manages ModulePasses and function pass managers.
379/// It batches all Module passes and function pass managers together and
380/// sequences them to process one module.
381class MPPassManager : public Pass, public PMDataManager {
382public:
383 static char ID;
384 explicit MPPassManager() : Pass(PT_PassManager, ID) {}
385
386 // Delete on the fly managers.
387 ~MPPassManager() override {
388 for (auto &OnTheFlyManager : OnTheFlyManagers) {
389 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
390 delete FPP;
391 }
392 }
393
394 /// createPrinterPass - Get a module printer pass.
396 const std::string &Banner) const override {
397 return createPrintModulePass(O, Banner);
398 }
399
400 /// run - Execute all of the passes scheduled for execution. Keep track of
401 /// whether any of the passes modifies the module, and if so, return true.
402 bool runOnModule(Module &M);
403
406
407 /// Pass Manager itself does not invalidate any analysis info.
408 void getAnalysisUsage(AnalysisUsage &Info) const override {
409 Info.setPreservesAll();
410 }
411
412 /// Add RequiredPass into list of lower level passes required by pass P.
413 /// RequiredPass is run on the fly by Pass Manager when P requests it
414 /// through getAnalysis interface.
415 void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) override;
416
417 /// Return function pass corresponding to PassInfo PI, that is
418 /// required by module pass MP. Instantiate analysis pass, by using
419 /// its runOnFunction() for function F.
420 std::tuple<Pass *, bool> getOnTheFlyPass(Pass *MP, AnalysisID PI,
421 Function &F) override;
422
423 StringRef getPassName() const override { return "Module Pass Manager"; }
424
425 PMDataManager *getAsPMDataManager() override { return this; }
426 Pass *getAsPass() override { return this; }
427
428 // Print passes managed by this manager
429 void dumpPassStructure(unsigned Offset) override {
430 dbgs().indent(Offset*2) << "ModulePass Manager\n";
431 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
432 ModulePass *MP = getContainedPass(Index);
433 MP->dumpPassStructure(Offset + 1);
435 OnTheFlyManagers.find(MP);
436 if (I != OnTheFlyManagers.end())
437 I->second->dumpPassStructure(Offset + 2);
438 dumpLastUses(MP, Offset+1);
439 }
440 }
441
442 ModulePass *getContainedPass(unsigned N) {
443 assert(N < PassVector.size() && "Pass number out of range!");
444 return static_cast<ModulePass *>(PassVector[N]);
445 }
446
447 PassManagerType getPassManagerType() const override {
449 }
450
451 private:
452 /// Collection of on the fly FPPassManagers. These managers manage
453 /// function passes that are required by module passes.
455};
456
457char MPPassManager::ID = 0;
458} // End anonymous namespace
459
460namespace llvm {
461namespace legacy {
462//===----------------------------------------------------------------------===//
463// PassManagerImpl
464//
465
466/// PassManagerImpl manages MPPassManagers
467class PassManagerImpl : public Pass,
468 public PMDataManager,
469 public PMTopLevelManager {
470 virtual void anchor();
471
472public:
473 static char ID;
475 : Pass(PT_PassManager, ID), PMTopLevelManager(new MPPassManager()) {}
476
477 /// \copydoc PassManager::add()
478 void add(Pass *P) {
480 }
481
482 /// createPrinterPass - Get a module printer pass.
484 const std::string &Banner) const override {
485 return createPrintModulePass(O, Banner);
486 }
487
488 /// run - Execute all of the passes scheduled for execution. Keep track of
489 /// whether any of the passes modifies the module, and if so, return true.
490 bool run(Module &M);
491
494
495 /// Pass Manager itself does not invalidate any analysis info.
496 void getAnalysisUsage(AnalysisUsage &Info) const override {
497 Info.setPreservesAll();
498 }
499
500 PMDataManager *getAsPMDataManager() override { return this; }
501 Pass *getAsPass() override { return this; }
504 }
505
506 MPPassManager *getContainedManager(unsigned N) {
507 assert(N < PassManagers.size() && "Pass number out of range!");
508 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
509 return MP;
510 }
511};
512
513void PassManagerImpl::anchor() {}
514
515char PassManagerImpl::ID = 0;
516
517//===----------------------------------------------------------------------===//
518// PassManagerImpl implementation
519
520//
521/// run - Execute all of the passes scheduled for execution. Keep track of
522/// whether any of the passes modifies the module, and if so, return true.
524 bool Changed = false;
525
527 dumpPasses();
528
529 // RemoveDIs: if a command line flag is given, convert to the
530 // DbgVariableRecord representation of debug-info for the duration of these
531 // passes.
533
534 for (ImmutablePass *ImPass : getImmutablePasses())
535 Changed |= ImPass->doInitialization(M);
536
538 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
539 Changed |= getContainedManager(Index)->runOnModule(M);
540 M.getContext().yield();
541 }
542
543 for (ImmutablePass *ImPass : getImmutablePasses())
544 Changed |= ImPass->doFinalization(M);
545
546 return Changed;
547}
548} // namespace legacy
549} // namespace llvm
550
551//===----------------------------------------------------------------------===//
552// PMTopLevelManager implementation
553
554/// Initialize top level manager. Create first pass manager.
556 PMDM->setTopLevelManager(this);
557 addPassManager(PMDM);
558 activeStack.push(PMDM);
559}
560
561/// Set pass P as the last user of the given analysis passes.
562void
564 unsigned PDepth = 0;
565 if (P->getResolver())
566 PDepth = P->getResolver()->getPMDataManager().getDepth();
567
568 for (Pass *AP : AnalysisPasses) {
569 // Record P as the new last user of AP.
570 auto &LastUserOfAP = LastUser[AP];
571 if (LastUserOfAP)
572 InversedLastUser[LastUserOfAP].erase(AP);
573 LastUserOfAP = P;
574 InversedLastUser[P].insert(AP);
575
576 if (P == AP)
577 continue;
578
579 // Update the last users of passes that are required transitive by AP.
580 AnalysisUsage *AnUsage = findAnalysisUsage(AP);
583 SmallVector<Pass *, 12> LastPMUses;
584 for (AnalysisID ID : IDs) {
585 Pass *AnalysisPass = findAnalysisPass(ID);
586 assert(AnalysisPass && "Expected analysis pass to exist.");
587 AnalysisResolver *AR = AnalysisPass->getResolver();
588 assert(AR && "Expected analysis resolver to exist.");
589 unsigned APDepth = AR->getPMDataManager().getDepth();
590
591 if (PDepth == APDepth)
592 LastUses.push_back(AnalysisPass);
593 else if (PDepth > APDepth)
594 LastPMUses.push_back(AnalysisPass);
595 }
596
597 setLastUser(LastUses, P);
598
599 // If this pass has a corresponding pass manager, push higher level
600 // analysis to this pass manager.
601 if (P->getResolver())
602 setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass());
603
604 // If AP is the last user of other passes then make P last user of
605 // such passes.
606 auto &LastUsedByAP = InversedLastUser[AP];
607 for (Pass *L : LastUsedByAP)
608 LastUser[L] = P;
609 InversedLastUser[P].insert(LastUsedByAP.begin(), LastUsedByAP.end());
610 LastUsedByAP.clear();
611 }
612}
613
614/// Collect passes whose last user is P
616 Pass *P) {
617 auto DMI = InversedLastUser.find(P);
618 if (DMI == InversedLastUser.end())
619 return;
620
621 auto &LU = DMI->second;
622 LastUses.append(LU.begin(), LU.end());
623}
624
626 AnalysisUsage *AnUsage = nullptr;
627 auto DMI = AnUsageMap.find(P);
628 if (DMI != AnUsageMap.end())
629 AnUsage = DMI->second;
630 else {
631 // Look up the analysis usage from the pass instance (different instances
632 // of the same pass can produce different results), but unique the
633 // resulting object to reduce memory usage. This helps to greatly reduce
634 // memory usage when we have many instances of only a few pass types
635 // (e.g. instcombine, simplifycfg, etc...) which tend to share a fixed set
636 // of dependencies.
637 AnalysisUsage AU;
638 P->getAnalysisUsage(AU);
639
640 AUFoldingSetNode* Node = nullptr;
642 AUFoldingSetNode::Profile(ID, AU);
643 void *IP = nullptr;
644 if (auto *N = UniqueAnalysisUsages.FindNodeOrInsertPos(ID, IP))
645 Node = N;
646 else {
647 Node = new (AUFoldingSetNodeAllocator.Allocate()) AUFoldingSetNode(AU);
648 UniqueAnalysisUsages.InsertNode(Node, IP);
649 }
650 assert(Node && "cached analysis usage must be non null");
651
652 AnUsageMap[P] = &Node->AU;
653 AnUsage = &Node->AU;
654 }
655 return AnUsage;
656}
657
658/// Schedule pass P for execution. Make sure that passes required by
659/// P are run before P is run. Update analysis info maintained by
660/// the manager. Remove dead passes. This is a recursive function.
662
663 // TODO : Allocate function manager for this pass, other wise required set
664 // may be inserted into previous function manager
665
666 // Give pass a chance to prepare the stage.
667 P->preparePassManager(activeStack);
668
669 // If P is an analysis pass and it is available then do not
670 // generate the analysis again. Stale analysis info should not be
671 // available at this point.
672 const PassInfo *PI = findAnalysisPassInfo(P->getPassID());
673 if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) {
674 // Remove any cached AnalysisUsage information.
675 AnUsageMap.erase(P);
676 delete P;
677 return;
678 }
679
681
682 bool checkAnalysis = true;
683 while (checkAnalysis) {
684 checkAnalysis = false;
685
686 const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
687 for (const AnalysisID ID : RequiredSet) {
688
689 Pass *AnalysisPass = findAnalysisPass(ID);
690 if (!AnalysisPass) {
691 const PassInfo *PI = findAnalysisPassInfo(ID);
692
693 if (!PI) {
694 // Pass P is not in the global PassRegistry
695 dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
696 dbgs() << "Verify if there is a pass dependency cycle." << "\n";
697 dbgs() << "Required Passes:" << "\n";
698 for (const AnalysisID ID2 : RequiredSet) {
699 if (ID == ID2)
700 break;
701 Pass *AnalysisPass2 = findAnalysisPass(ID2);
702 if (AnalysisPass2) {
703 dbgs() << "\t" << AnalysisPass2->getPassName() << "\n";
704 } else {
705 dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n";
706 dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n";
707 dbgs() << "\t\t" << "- Corruption of the global PassRegistry" << "\n";
708 }
709 }
710 }
711
712 assert(PI && "Expected required passes to be initialized");
713 AnalysisPass = PI->createPass();
714 if (P->getPotentialPassManagerType () ==
715 AnalysisPass->getPotentialPassManagerType())
716 // Schedule analysis pass that is managed by the same pass manager.
717 schedulePass(AnalysisPass);
718 else if (P->getPotentialPassManagerType () >
719 AnalysisPass->getPotentialPassManagerType()) {
720 // Schedule analysis pass that is managed by a new manager.
721 schedulePass(AnalysisPass);
722 // Recheck analysis passes to ensure that required analyses that
723 // are already checked are still available.
724 checkAnalysis = true;
725 } else
726 // Do not schedule this analysis. Lower level analysis
727 // passes are run on the fly.
728 delete AnalysisPass;
729 }
730 }
731 }
732
733 // Now all required passes are available.
734 if (ImmutablePass *IP = P->getAsImmutablePass()) {
735 // P is a immutable pass and it will be managed by this
736 // top level manager. Set up analysis resolver to connect them.
737 PMDataManager *DM = getAsPMDataManager();
739 P->setResolver(AR);
740 DM->initializeAnalysisImpl(P);
742 DM->recordAvailableAnalysis(IP);
743 return;
744 }
745
746 if (PI && !PI->isAnalysis() && shouldPrintBeforePass(PI->getPassArgument())) {
747 Pass *PP =
748 P->createPrinterPass(dbgs(), ("*** IR Dump Before " + P->getPassName() +
749 " (" + PI->getPassArgument() + ") ***")
750 .str());
751 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
752 }
753
754 // Add the requested pass to the best available pass manager.
755 P->assignPassManager(activeStack, getTopLevelPassManagerType());
756
757 if (PI && !PI->isAnalysis() && shouldPrintAfterPass(PI->getPassArgument())) {
758 Pass *PP =
759 P->createPrinterPass(dbgs(), ("*** IR Dump After " + P->getPassName() +
760 " (" + PI->getPassArgument() + ") ***")
761 .str());
762 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
763 }
764}
765
766/// Find the pass that implements Analysis AID. Search immutable
767/// passes and all pass managers. If desired pass is not found
768/// then return NULL.
770 // For immutable passes we have a direct mapping from ID to pass, so check
771 // that first.
772 if (Pass *P = ImmutablePassMap.lookup(AID))
773 return P;
774
775 // Check pass managers
777 if (Pass *P = PassManager->findAnalysisPass(AID, false))
778 return P;
779
780 // Check other pass managers
781 for (PMDataManager *IndirectPassManager : IndirectPassManagers)
782 if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false))
783 return P;
784
785 return nullptr;
786}
787
789 const PassInfo *&PI = AnalysisPassInfos[AID];
790 if (!PI)
792 else
794 "The pass info pointer changed for an analysis ID!");
795
796 return PI;
797}
798
800 P->initializePass();
801 ImmutablePasses.push_back(P);
802
803 // Add this pass to the map from its analysis ID. We clobber any prior runs
804 // of the pass in the map so that the last one added is the one found when
805 // doing lookups.
806 AnalysisID AID = P->getPassID();
807 ImmutablePassMap[AID] = P;
808}
809
810// Print passes managed by this top level manager.
812
813 if (PassDebugging < Structure)
814 return;
815
816 // Print out the immutable passes
817 for (ImmutablePass *Pass : ImmutablePasses)
819
820 // Every class that derives from PMDataManager also derives from Pass
821 // (sometimes indirectly), but there's no inheritance relationship
822 // between PMDataManager and Pass, so we have to getAsPass to get
823 // from a PMDataManager* to a Pass*.
824 for (PMDataManager *Manager : PassManagers)
825 Manager->getAsPass()->dumpPassStructure(1);
826}
827
829
831 return;
832
833 dbgs() << "Pass Arguments: ";
834 for (ImmutablePass *P : ImmutablePasses)
835 if (const PassInfo *PI = findAnalysisPassInfo(P->getPassID())) {
836 assert(PI && "Expected all immutable passes to be initialized");
837 dbgs() << " -" << PI->getPassArgument();
838 }
839 for (PMDataManager *PM : PassManagers)
840 PM->dumpPassArguments();
841 dbgs() << "\n";
842}
843
845 for (PMDataManager *PM : PassManagers)
846 PM->initializeAnalysisInfo();
847
848 // Initailize other pass managers
849 for (PMDataManager *IPM : IndirectPassManagers)
850 IPM->initializeAnalysisInfo();
851}
852
853/// Destructor
855 for (PMDataManager *PM : PassManagers)
856 delete PM;
857
858 for (ImmutablePass *P : ImmutablePasses)
859 delete P;
860}
861
862//===----------------------------------------------------------------------===//
863// PMDataManager implementation
864
865/// Augement AvailableAnalysis by adding analysis made available by pass P.
867 AnalysisID PI = P->getPassID();
868
869 AvailableAnalysis[PI] = P;
870}
871
872// Return true if P preserves high level analysis used by other
873// passes managed by this manager
876 if (AnUsage->getPreservesAll())
877 return true;
878
879 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
880 for (Pass *P1 : HigherLevelAnalysis) {
881 if (P1->getAsImmutablePass() == nullptr &&
882 !is_contained(PreservedSet, P1->getPassID()))
883 return false;
884 }
885
886 return true;
887}
888
889/// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
891 // Don't do this unless assertions are enabled.
892#ifdef NDEBUG
893 return;
894#endif
896 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
897
898 // Verify preserved analysis
899 for (AnalysisID AID : PreservedSet) {
900 if (Pass *AP = findAnalysisPass(AID, true)) {
901 TimeRegion PassTimer(getPassTimer(AP));
902 AP->verifyAnalysis();
903 }
904 }
905}
906
907/// Remove Analysis not preserved by Pass P
910 if (AnUsage->getPreservesAll())
911 return;
912
913 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
914 for (DenseMap<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
915 E = AvailableAnalysis.end(); I != E; ) {
917 if (Info->second->getAsImmutablePass() == nullptr &&
918 !is_contained(PreservedSet, Info->first)) {
919 // Remove this analysis
920 if (PassDebugging >= Details) {
921 Pass *S = Info->second;
922 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
923 dbgs() << S->getPassName() << "'\n";
924 }
925 AvailableAnalysis.erase(Info);
926 }
927 }
928
929 // Check inherited analysis also. If P is not preserving analysis
930 // provided by parent manager then remove it here.
932 if (!IA)
933 continue;
934
935 for (DenseMap<AnalysisID, Pass *>::iterator I = IA->begin(),
936 E = IA->end();
937 I != E;) {
939 if (Info->second->getAsImmutablePass() == nullptr &&
940 !is_contained(PreservedSet, Info->first)) {
941 // Remove this analysis
942 if (PassDebugging >= Details) {
943 Pass *S = Info->second;
944 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
945 dbgs() << S->getPassName() << "'\n";
946 }
947 IA->erase(Info);
948 }
949 }
950 }
951}
952
953/// Remove analysis passes that are not used any longer
955 enum PassDebuggingString DBG_STR) {
956
957 SmallVector<Pass *, 12> DeadPasses;
958
959 // If this is a on the fly manager then it does not have TPM.
960 if (!TPM)
961 return;
962
963 TPM->collectLastUses(DeadPasses, P);
964
965 if (PassDebugging >= Details && !DeadPasses.empty()) {
966 dbgs() << " -*- '" << P->getPassName();
967 dbgs() << "' is the last user of following pass instances.";
968 dbgs() << " Free these instances\n";
969 }
970
971 for (Pass *P : DeadPasses)
972 freePass(P, Msg, DBG_STR);
973}
974
976 enum PassDebuggingString DBG_STR) {
977 dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
978
979 {
980 // If the pass crashes releasing memory, remember this.
982 TimeRegion PassTimer(getPassTimer(P));
983
984 P->releaseMemory();
985 }
986
987 // Remove the pass itself (if it is not already removed).
988 AvailableAnalysis.erase(P->getPassID());
989}
990
991/// Add pass P into the PassVector. Update
992/// AvailableAnalysis appropriately if ProcessAnalysis is true.
993void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
994 // This manager is going to manage pass P. Set up analysis resolver
995 // to connect them.
996 AnalysisResolver *AR = new AnalysisResolver(*this);
997 P->setResolver(AR);
998
999 // If a FunctionPass F is the last user of ModulePass info M
1000 // then the F's manager, not F, records itself as a last user of M.
1001 SmallVector<Pass *, 12> TransferLastUses;
1002
1003 if (!ProcessAnalysis) {
1004 // Add pass
1005 PassVector.push_back(P);
1006 return;
1007 }
1008
1009 // At the moment, this pass is the last user of all required passes.
1010 SmallVector<Pass *, 12> LastUses;
1011 SmallVector<Pass *, 8> UsedPasses;
1012 SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
1013
1014 unsigned PDepth = this->getDepth();
1015
1016 collectRequiredAndUsedAnalyses(UsedPasses, ReqAnalysisNotAvailable, P);
1017 for (Pass *PUsed : UsedPasses) {
1018 unsigned RDepth = 0;
1019
1020 assert(PUsed->getResolver() && "Analysis Resolver is not set");
1021 PMDataManager &DM = PUsed->getResolver()->getPMDataManager();
1022 RDepth = DM.getDepth();
1023
1024 if (PDepth == RDepth)
1025 LastUses.push_back(PUsed);
1026 else if (PDepth > RDepth) {
1027 // Let the parent claim responsibility of last use
1028 TransferLastUses.push_back(PUsed);
1029 // Keep track of higher level analysis used by this manager.
1030 HigherLevelAnalysis.push_back(PUsed);
1031 } else
1032 llvm_unreachable("Unable to accommodate Used Pass");
1033 }
1034
1035 // Set P as P's last user until someone starts using P.
1036 // However, if P is a Pass Manager then it does not need
1037 // to record its last user.
1038 if (!P->getAsPMDataManager())
1039 LastUses.push_back(P);
1040 TPM->setLastUser(LastUses, P);
1041
1042 if (!TransferLastUses.empty()) {
1043 Pass *My_PM = getAsPass();
1044 TPM->setLastUser(TransferLastUses, My_PM);
1045 TransferLastUses.clear();
1046 }
1047
1048 // Now, take care of required analyses that are not available.
1049 for (AnalysisID ID : ReqAnalysisNotAvailable) {
1050 const PassInfo *PI = TPM->findAnalysisPassInfo(ID);
1051 Pass *AnalysisPass = PI->createPass();
1052 this->addLowerLevelRequiredPass(P, AnalysisPass);
1053 }
1054
1055 // Take a note of analysis required and made available by this pass.
1056 // Remove the analysis not preserved by this pass
1059
1060 // Add pass
1061 PassVector.push_back(P);
1062}
1063
1064
1065/// Populate UP with analysis pass that are used or required by
1066/// pass P and are available. Populate RP_NotAvail with analysis
1067/// pass that are required by pass P but are not available.
1070 Pass *P) {
1071 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
1072
1073 for (const auto &UsedID : AnUsage->getUsedSet())
1074 if (Pass *AnalysisPass = findAnalysisPass(UsedID, true))
1075 UP.push_back(AnalysisPass);
1076
1077 for (const auto &RequiredID : AnUsage->getRequiredSet())
1078 if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true))
1079 UP.push_back(AnalysisPass);
1080 else
1081 RP_NotAvail.push_back(RequiredID);
1082}
1083
1084// All Required analyses should be available to the pass as it runs! Here
1085// we fill in the AnalysisImpls member of the pass so that it can
1086// successfully use the getAnalysis() method to retrieve the
1087// implementations it needs.
1088//
1090 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
1091
1092 for (const AnalysisID ID : AnUsage->getRequiredSet()) {
1093 Pass *Impl = findAnalysisPass(ID, true);
1094 if (!Impl)
1095 // This may be analysis pass that is initialized on the fly.
1096 // If that is not the case then it will raise an assert when it is used.
1097 continue;
1098 AnalysisResolver *AR = P->getResolver();
1099 assert(AR && "Analysis Resolver is not set");
1100 AR->addAnalysisImplsPair(ID, Impl);
1101 }
1102}
1103
1104/// Find the pass that implements Analysis AID. If desired pass is not found
1105/// then return NULL.
1107
1108 // Check if AvailableAnalysis map has one entry.
1109 DenseMap<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
1110
1111 if (I != AvailableAnalysis.end())
1112 return I->second;
1113
1114 // Search Parents through TopLevelManager
1115 if (SearchParent)
1116 return TPM->findAnalysisPass(AID);
1117
1118 return nullptr;
1119}
1120
1121// Print list of passes that are last used by P.
1123 if (PassDebugging < Details)
1124 return;
1125
1127
1128 // If this is a on the fly manager then it does not have TPM.
1129 if (!TPM)
1130 return;
1131
1132 TPM->collectLastUses(LUses, P);
1133
1134 for (Pass *P : LUses) {
1135 dbgs() << "--" << std::string(Offset*2, ' ');
1136 P->dumpPassStructure(0);
1137 }
1138}
1139
1141 for (Pass *P : PassVector) {
1142 if (PMDataManager *PMD = P->getAsPMDataManager())
1143 PMD->dumpPassArguments();
1144 else if (const PassInfo *PI = TPM->findAnalysisPassInfo(P->getPassID()))
1145 dbgs() << " -" << PI->getPassArgument();
1146 }
1147}
1148
1150 enum PassDebuggingString S2,
1151 StringRef Msg) {
1152 if (PassDebugging < Executions)
1153 return;
1154 dbgs() << "[" << std::chrono::system_clock::now() << "] " << (void *)this
1155 << std::string(getDepth() * 2 + 1, ' ');
1156 switch (S1) {
1157 case EXECUTION_MSG:
1158 dbgs() << "Executing Pass '" << P->getPassName();
1159 break;
1160 case MODIFICATION_MSG:
1161 dbgs() << "Made Modification '" << P->getPassName();
1162 break;
1163 case FREEING_MSG:
1164 dbgs() << " Freeing Pass '" << P->getPassName();
1165 break;
1166 default:
1167 break;
1168 }
1169 switch (S2) {
1170 case ON_FUNCTION_MSG:
1171 dbgs() << "' on Function '" << Msg << "'...\n";
1172 break;
1173 case ON_MODULE_MSG:
1174 dbgs() << "' on Module '" << Msg << "'...\n";
1175 break;
1176 case ON_REGION_MSG:
1177 dbgs() << "' on Region '" << Msg << "'...\n";
1178 break;
1179 case ON_LOOP_MSG:
1180 dbgs() << "' on Loop '" << Msg << "'...\n";
1181 break;
1182 case ON_CG_MSG:
1183 dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
1184 break;
1185 default:
1186 break;
1187 }
1188}
1189
1191 if (PassDebugging < Details)
1192 return;
1193
1194 AnalysisUsage analysisUsage;
1195 P->getAnalysisUsage(analysisUsage);
1196 dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
1197}
1198
1200 if (PassDebugging < Details)
1201 return;
1202
1203 AnalysisUsage analysisUsage;
1204 P->getAnalysisUsage(analysisUsage);
1205 dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
1206}
1207
1209 if (PassDebugging < Details)
1210 return;
1211
1212 AnalysisUsage analysisUsage;
1213 P->getAnalysisUsage(analysisUsage);
1214 dumpAnalysisUsage("Used", P, analysisUsage.getUsedSet());
1215}
1216
1217void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
1218 const AnalysisUsage::VectorType &Set) const {
1219 assert(PassDebugging >= Details);
1220 if (Set.empty())
1221 return;
1222 dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
1223 for (unsigned i = 0; i != Set.size(); ++i) {
1224 if (i) dbgs() << ',';
1225 const PassInfo *PInf = TPM->findAnalysisPassInfo(Set[i]);
1226 if (!PInf) {
1227 // Some preserved passes, such as AliasAnalysis, may not be initialized by
1228 // all drivers.
1229 dbgs() << " Uninitialized Pass";
1230 continue;
1231 }
1232 dbgs() << ' ' << PInf->getPassName();
1233 }
1234 dbgs() << '\n';
1235}
1236
1237/// Add RequiredPass into list of lower level passes required by pass P.
1238/// RequiredPass is run on the fly by Pass Manager when P requests it
1239/// through getAnalysis interface.
1240/// This should be handled by specific pass manager.
1242 if (TPM) {
1243 TPM->dumpArguments();
1244 TPM->dumpPasses();
1245 }
1246
1247 // Module Level pass may required Function Level analysis info
1248 // (e.g. dominator info). Pass manager uses on the fly function pass manager
1249 // to provide this on demand. In that case, in Pass manager terminology,
1250 // module level pass is requiring lower level analysis info managed by
1251 // lower level pass manager.
1252
1253 // When Pass manager is not able to order required analysis info, Pass manager
1254 // checks whether any lower level manager will be able to provide this
1255 // analysis info on demand or not.
1256#ifndef NDEBUG
1257 dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
1258 dbgs() << "' required by '" << P->getPassName() << "'\n";
1259#endif
1260 llvm_unreachable("Unable to schedule pass");
1261}
1262
1263std::tuple<Pass *, bool> PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI,
1264 Function &F) {
1265 llvm_unreachable("Unable to find on the fly pass");
1266}
1267
1268// Destructor
1270 for (Pass *P : PassVector)
1271 delete P;
1272}
1273
1274//===----------------------------------------------------------------------===//
1275// NOTE: Is this the right place to define this method ?
1276// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
1278 return PM.findAnalysisPass(ID, true);
1279}
1280
1281std::tuple<Pass *, bool>
1283 return PM.getOnTheFlyPass(P, AnalysisPI, F);
1284}
1285
1286namespace llvm {
1287namespace legacy {
1288
1289//===----------------------------------------------------------------------===//
1290// FunctionPassManager implementation
1291
1292/// Create new Function pass manager
1293FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
1295 // FPM is the top level manager.
1296 FPM->setTopLevelManager(FPM);
1297
1298 AnalysisResolver *AR = new AnalysisResolver(*FPM);
1299 FPM->setResolver(AR);
1300}
1301
1302FunctionPassManager::~FunctionPassManager() {
1303 delete FPM;
1304}
1305
1306void FunctionPassManager::add(Pass *P) {
1307 FPM->add(P);
1308}
1309
1310/// run - Execute all of the passes scheduled for execution. Keep
1311/// track of whether any of the passes modifies the function, and if
1312/// so, return true.
1313///
1315 handleAllErrors(F.materialize(), [&](ErrorInfoBase &EIB) {
1316 report_fatal_error(Twine("Error reading bitcode file: ") + EIB.message());
1317 });
1318 return FPM->run(F);
1319}
1320
1321
1322/// doInitialization - Run all of the initializers for the function passes.
1323///
1324bool FunctionPassManager::doInitialization() {
1325 return FPM->doInitialization(*M);
1326}
1327
1328/// doFinalization - Run all of the finalizers for the function passes.
1329///
1330bool FunctionPassManager::doFinalization() {
1331 return FPM->doFinalization(*M);
1332}
1333} // namespace legacy
1334} // namespace llvm
1335
1336/// cleanup - After running all passes, clean up pass manager cache.
1338 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1340 AnalysisResolver *AR = FP->getResolver();
1341 assert(AR && "Analysis Resolver is not set");
1342 AR->clearAnalysisImpls();
1343 }
1344}
1345
1346
1347//===----------------------------------------------------------------------===//
1348// FPPassManager implementation
1349
1350char FPPassManager::ID = 0;
1351/// Print passes managed by this manager
1353 dbgs().indent(Offset*2) << "FunctionPass Manager\n";
1354 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1356 FP->dumpPassStructure(Offset + 1);
1358 }
1359}
1360
1361/// Execute all of the passes scheduled for execution by invoking
1362/// runOnFunction method. Keep track of whether any of the passes modifies
1363/// the function, and if so, return true.
1365 if (F.isDeclaration())
1366 return false;
1367
1368 bool Changed = false;
1369 Module &M = *F.getParent();
1370 // Collect inherited analysis from Module level pass manager.
1372
1373 unsigned InstrCount, FunctionSize = 0;
1374 StringMap<std::pair<unsigned, unsigned>> FunctionToInstrCount;
1375 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
1376 // Collect the initial size of the module.
1377 if (EmitICRemark) {
1378 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1379 FunctionSize = F.getInstructionCount();
1380 }
1381
1382 // Store name outside of loop to avoid redundant calls.
1383 const StringRef Name = F.getName();
1384 llvm::TimeTraceScope FunctionScope("OptFunction", Name);
1385
1386 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1388 bool LocalChanged = false;
1389
1390 // Call getPassName only when required. The call itself is fairly cheap, but
1391 // still virtual and repeated calling adds unnecessary overhead.
1392 llvm::TimeTraceScope PassScope(
1393 "RunPass", [FP]() { return std::string(FP->getPassName()); });
1394
1397
1399
1400 {
1402 TimeRegion PassTimer(getPassTimer(FP));
1403#ifdef EXPENSIVE_CHECKS
1404 uint64_t RefHash = FP->structuralHash(F);
1405#endif
1406 LocalChanged |= FP->runOnFunction(F);
1407
1408#if defined(EXPENSIVE_CHECKS) && !defined(NDEBUG)
1409 if (!LocalChanged && (RefHash != FP->structuralHash(F))) {
1410 llvm::errs() << "Pass modifies its input and doesn't report it: "
1411 << FP->getPassName() << "\n";
1412 llvm_unreachable("Pass modifies its input and doesn't report it");
1413 }
1414#endif
1415
1416 if (EmitICRemark) {
1417 unsigned NewSize = F.getInstructionCount();
1418
1419 // Update the size of the function, emit a remark, and update the size
1420 // of the module.
1421 if (NewSize != FunctionSize) {
1422 int64_t Delta = static_cast<int64_t>(NewSize) -
1423 static_cast<int64_t>(FunctionSize);
1425 FunctionToInstrCount, &F);
1426 InstrCount = static_cast<int64_t>(InstrCount) + Delta;
1427 FunctionSize = NewSize;
1428 }
1429 }
1430 }
1431
1432 Changed |= LocalChanged;
1433 if (LocalChanged)
1436 dumpUsedSet(FP);
1437
1439 if (LocalChanged)
1443 }
1444
1445 return Changed;
1446}
1447
1449 bool Changed = false;
1450
1451 for (Function &F : M)
1452 Changed |= runOnFunction(F);
1453
1454 return Changed;
1455}
1456
1458 bool Changed = false;
1459
1460 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1461 Changed |= getContainedPass(Index)->doInitialization(M);
1462
1463 return Changed;
1464}
1465
1467 bool Changed = false;
1468
1469 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
1470 Changed |= getContainedPass(Index)->doFinalization(M);
1471
1472 return Changed;
1473}
1474
1475//===----------------------------------------------------------------------===//
1476// MPPassManager implementation
1477
1478/// Execute all of the passes scheduled for execution by invoking
1479/// runOnModule method. Keep track of whether any of the passes modifies
1480/// the module, and if so, return true.
1481bool
1482MPPassManager::runOnModule(Module &M) {
1483 llvm::TimeTraceScope TimeScope("OptModule", M.getName());
1484
1485 bool Changed = false;
1486
1487 // Initialize on-the-fly passes
1488 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1489 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
1490 Changed |= FPP->doInitialization(M);
1491 }
1492
1493 // Initialize module passes
1494 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1495 Changed |= getContainedPass(Index)->doInitialization(M);
1496
1497 unsigned InstrCount;
1498 StringMap<std::pair<unsigned, unsigned>> FunctionToInstrCount;
1499 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
1500 // Collect the initial size of the module.
1501 if (EmitICRemark)
1502 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1503
1504 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1505 ModulePass *MP = getContainedPass(Index);
1506 bool LocalChanged = false;
1507
1508 dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier());
1509 dumpRequiredSet(MP);
1510
1511 initializeAnalysisImpl(MP);
1512
1513 {
1515 TimeRegion PassTimer(getPassTimer(MP));
1516
1517#ifdef EXPENSIVE_CHECKS
1518 uint64_t RefHash = MP->structuralHash(M);
1519#endif
1520
1521 LocalChanged |= MP->runOnModule(M);
1522
1523#ifdef EXPENSIVE_CHECKS
1524 assert((LocalChanged || (RefHash == MP->structuralHash(M))) &&
1525 "Pass modifies its input and doesn't report it.");
1526#endif
1527
1528 if (EmitICRemark) {
1529 // Update the size of the module.
1530 unsigned ModuleCount = M.getInstructionCount();
1531 if (ModuleCount != InstrCount) {
1532 int64_t Delta = static_cast<int64_t>(ModuleCount) -
1533 static_cast<int64_t>(InstrCount);
1534 emitInstrCountChangedRemark(MP, M, Delta, InstrCount,
1535 FunctionToInstrCount);
1536 InstrCount = ModuleCount;
1537 }
1538 }
1539 }
1540
1541 Changed |= LocalChanged;
1542 if (LocalChanged)
1543 dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
1544 M.getModuleIdentifier());
1545 dumpPreservedSet(MP);
1546 dumpUsedSet(MP);
1547
1548 verifyPreservedAnalysis(MP);
1549 if (LocalChanged)
1550 removeNotPreservedAnalysis(MP);
1551 recordAvailableAnalysis(MP);
1552 removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
1553 }
1554
1555 // Finalize module passes
1556 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
1557 Changed |= getContainedPass(Index)->doFinalization(M);
1558
1559 // Finalize on-the-fly passes
1560 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1561 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
1562 // We don't know when is the last time an on-the-fly pass is run,
1563 // so we need to releaseMemory / finalize here
1564 FPP->releaseMemoryOnTheFly();
1565 Changed |= FPP->doFinalization(M);
1566 }
1567
1568 return Changed;
1569}
1570
1571/// Add RequiredPass into list of lower level passes required by pass P.
1572/// RequiredPass is run on the fly by Pass Manager when P requests it
1573/// through getAnalysis interface.
1574void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1575 assert(RequiredPass && "No required pass?");
1576 assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
1577 "Unable to handle Pass that requires lower level Analysis pass");
1578 assert((P->getPotentialPassManagerType() <
1579 RequiredPass->getPotentialPassManagerType()) &&
1580 "Unable to handle Pass that requires lower level Analysis pass");
1581
1582 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
1583 if (!FPP) {
1585 // FPP is the top level manager.
1586 FPP->setTopLevelManager(FPP);
1587
1588 OnTheFlyManagers[P] = FPP;
1589 }
1590 const PassInfo *RequiredPassPI =
1591 TPM->findAnalysisPassInfo(RequiredPass->getPassID());
1592
1593 Pass *FoundPass = nullptr;
1594 if (RequiredPassPI && RequiredPassPI->isAnalysis()) {
1595 FoundPass =
1596 ((PMTopLevelManager*)FPP)->findAnalysisPass(RequiredPass->getPassID());
1597 }
1598 if (!FoundPass) {
1599 FoundPass = RequiredPass;
1600 // This should be guaranteed to add RequiredPass to the passmanager given
1601 // that we checked for an available analysis above.
1602 FPP->add(RequiredPass);
1603 }
1604 // Register P as the last user of FoundPass or RequiredPass.
1606 LU.push_back(FoundPass);
1607 FPP->setLastUser(LU, P);
1608}
1609
1610/// Return function pass corresponding to PassInfo PI, that is
1611/// required by module pass MP. Instantiate analysis pass, by using
1612/// its runOnFunction() for function F.
1613std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI,
1614 Function &F) {
1615 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
1616 assert(FPP && "Unable to find on the fly pass");
1617
1618 FPP->releaseMemoryOnTheFly();
1619 bool Changed = FPP->run(F);
1620 return std::make_tuple(((PMTopLevelManager *)FPP)->findAnalysisPass(PI),
1621 Changed);
1622}
1623
1624namespace llvm {
1625namespace legacy {
1626
1627//===----------------------------------------------------------------------===//
1628// PassManager implementation
1629
1630/// Create new pass manager
1632 PM = new PassManagerImpl();
1633 // PM is the top level manager
1634 PM->setTopLevelManager(PM);
1635}
1636
1638 delete PM;
1639}
1640
1642 PM->add(P);
1643}
1644
1645/// run - Execute all of the passes scheduled for execution. Keep track of
1646/// whether any of the passes modifies the module, and if so, return true.
1648 return PM->run(M);
1649}
1650} // namespace legacy
1651} // namespace llvm
1652
1653//===----------------------------------------------------------------------===//
1654// PMStack implementation
1655//
1656
1657// Pop Pass Manager from the stack and clear its analysis info.
1659
1660 PMDataManager *Top = this->top();
1662
1663 S.pop_back();
1664}
1665
1666// Push PM on the stack and set its top level manager.
1668 assert(PM && "Unable to push. Pass Manager expected");
1669 assert(PM->getDepth()==0 && "Pass Manager depth set too early");
1670
1671 if (!this->empty()) {
1672 assert(PM->getPassManagerType() > this->top()->getPassManagerType()
1673 && "pushing bad pass manager to PMStack");
1674 PMTopLevelManager *TPM = this->top()->getTopLevelManager();
1675
1676 assert(TPM && "Unable to find top level manager");
1677 TPM->addIndirectPassManager(PM);
1678 PM->setTopLevelManager(TPM);
1679 PM->setDepth(this->top()->getDepth()+1);
1680 } else {
1683 && "pushing bad pass manager to PMStack");
1684 PM->setDepth(1);
1685 }
1686
1687 S.push_back(PM);
1688}
1689
1690// Dump content of the pass manager stack.
1692 for (PMDataManager *Manager : S)
1693 dbgs() << Manager->getAsPass()->getPassName() << ' ';
1694
1695 if (!S.empty())
1696 dbgs() << '\n';
1697}
1698
1699/// Find appropriate Module Pass Manager in the PM Stack and
1700/// add self into that manager.
1702 PassManagerType PreferredType) {
1703 // Find Module Pass Manager
1705 while ((T = PMS.top()->getPassManagerType()) > PMT_ModulePassManager &&
1706 T != PreferredType)
1707 PMS.pop();
1708 PMS.top()->add(this);
1709}
1710
1711/// Find appropriate Function Pass Manager or Call Graph Pass Manager
1712/// in the PM Stack and add self into that manager.
1714 PassManagerType /*PreferredType*/) {
1715 // Find Function Pass Manager
1716 PMDataManager *PM;
1717 while (PM = PMS.top(), PM->getPassManagerType() > PMT_FunctionPassManager)
1718 PMS.pop();
1719
1720 // Create new Function Pass Manager if needed.
1722 // [1] Create new Function Pass Manager
1723 auto *FPP = new FPPassManager;
1724 FPP->populateInheritedAnalysis(PMS);
1725
1726 // [2] Set up new manager's top level manager
1728
1729 // [3] Assign manager to manage this new manager. This may create
1730 // and push new managers into PMS
1731 FPP->assignPassManager(PMS, PM->getPassManagerType());
1732
1733 // [4] Push new manager into PMS
1734 PMS.push(FPP);
1735 PM = FPP;
1736 }
1737
1738 // Assign FPP as the manager of this pass.
1739 PM->add(this);
1740}
1741
static const LLT S1
AMDGPU Lower Kernel Arguments
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define clEnumVal(ENUMVAL, DESC)
Definition: CommandLine.h:684
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
static unsigned InstrCount
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
std::string Name
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file contains an interface for creating legacy passes to print out IR in various granularities.
Module.h This file contains the declarations for the Module class.
cl::opt< bool > UseNewDbgInfoFormat
static cl::opt< enum PassDebugLevel > PassDebugging("debug-pass", cl::Hidden, cl::desc("Print legacy PassManager debugging information"), cl::values(clEnumVal(Disabled, "disable debug output"), clEnumVal(Arguments, "print pass arguments to pass to 'opt'"), clEnumVal(Structure, "print pass structure before run()"), clEnumVal(Executions, "print pass name before it is executed"), clEnumVal(Details, "print pass details when it is executed")))
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file implements a map that provides insertion order iteration.
#define P(N)
llvm::cl::opt< bool > UseNewDbgInfoFormat
This header defines classes/functions to handle pass execution timing information with interfaces for...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
static const PassInfo * getPassInfo(StringRef PassName)
static const char PassName[]
AnalysisResolver - Simple interface used by Pass objects to pull all analysis information out of pass...
void addAnalysisImplsPair(AnalysisID PI, Pass *P)
Pass * findImplPass(AnalysisID PI)
Find pass that is implementing PI.
PMDataManager & getPMDataManager()
void clearAnalysisImpls()
Clear cache that is used to connect a pass to the analysis (PassInfo).
Pass * getAnalysisIfAvailable(AnalysisID ID) const
Return analysis result or null if it doesn't exist.
Represent the analysis usage information of a pass.
const VectorType & getRequiredSet() const
const VectorType & getRequiredTransitiveSet() const
const VectorType & getUsedSet() const
bool getPreservesAll() const
Determine whether a pass said it does not transform its input at all.
const VectorType & getPreservedSet() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
Base class for error info classes.
Definition: Error.h:45
FPPassManager manages BBPassManagers and FunctionPasses.
bool runOnFunction(Function &F)
run - Execute all of the passes scheduled for execution.
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
FunctionPass * getContainedPass(unsigned N)
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void cleanup()
cleanup - After running all passes, clean up pass manager cache.
void InsertNode(T *N, void *InsertPos)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
Definition: FoldingSet.h:513
T * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
Definition: FoldingSet.h:505
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:327
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:310
void assignPassManager(PMStack &PMS, PassManagerType T) override
Find appropriate Function Pass Manager or Call Graph Pass Manager in the PM Stack and add self into t...
bool empty() const
Definition: Function.h:859
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:281
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
typename VectorType::const_iterator const_iterator
Definition: MapVector.h:50
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
void assignPassManager(PMStack &PMS, PassManagerType T) override
Find appropriate Module Pass Manager in the PM Stack and add self into that manager.
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:268
Diagnostic information for optimization analysis remarks.
PMDataManager provides the common place to manage the analysis data used by pass managers.
void removeDeadPasses(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove dead passes used by P.
void dumpLastUses(Pass *P, unsigned Offset) const
virtual Pass * getAsPass()=0
virtual std::tuple< Pass *, bool > getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F)
void setDepth(unsigned newDepth)
void recordAvailableAnalysis(Pass *P)
Augment AvailableAnalysis by adding analysis made available by pass P.
Pass * findAnalysisPass(AnalysisID AID, bool Direction)
Find the pass that implements Analysis AID.
bool isPassDebuggingExecutionsOrMore() const
isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions or higher is specified.
unsigned getDepth() const
SmallVector< Pass *, 16 > PassVector
DenseMap< AnalysisID, Pass * > * InheritedAnalysis[PMT_Last]
virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass)
Add RequiredPass into list of lower level passes required by pass P.
PMTopLevelManager * getTopLevelManager()
unsigned initSizeRemarkInfo(Module &M, StringMap< std::pair< unsigned, unsigned > > &FunctionToInstrCount)
Set the initial size of the module if the user has specified that they want remarks for size.
void setTopLevelManager(PMTopLevelManager *T)
void dumpRequiredSet(const Pass *P) const
void initializeAnalysisImpl(Pass *P)
All Required analyses should be available to the pass as it runs! Here we fill in the AnalysisImpls m...
void verifyPreservedAnalysis(Pass *P)
verifyPreservedAnalysis – Verify analysis presreved by pass P.
void initializeAnalysisInfo()
Initialize available analysis information.
void freePass(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove P.
bool preserveHigherLevelAnalysis(Pass *P)
unsigned getNumContainedPasses() const
virtual PassManagerType getPassManagerType() const
PMTopLevelManager * TPM
void emitInstrCountChangedRemark(Pass *P, Module &M, int64_t Delta, unsigned CountBefore, StringMap< std::pair< unsigned, unsigned > > &FunctionToInstrCount, Function *F=nullptr)
Emit a remark signifying that the number of IR instructions in the module changed.
void add(Pass *P, bool ProcessAnalysis=true)
Add pass P into the PassVector.
void collectRequiredAndUsedAnalyses(SmallVectorImpl< Pass * > &UsedPasses, SmallVectorImpl< AnalysisID > &ReqPassNotAvailable, Pass *P)
Populate UsedPasses with analysis pass that are used or required by pass P and are available.
void populateInheritedAnalysis(PMStack &PMS)
void dumpPreservedSet(const Pass *P) const
void dumpUsedSet(const Pass *P) const
void removeNotPreservedAnalysis(Pass *P)
Remove Analysis that is not preserved by the pass.
void dumpPassInfo(Pass *P, enum PassDebuggingString S1, enum PassDebuggingString S2, StringRef Msg)
PMStack - This class implements a stack data structure of PMDataManager pointers.
PMDataManager * top() const
bool empty() const
void push(PMDataManager *PM)
PMTopLevelManager manages LastUser info and collects common APIs used by top level pass managers.
void addIndirectPassManager(PMDataManager *Manager)
void addImmutablePass(ImmutablePass *P)
Add immutable pass and initialize it.
const PassInfo * findAnalysisPassInfo(AnalysisID AID) const
Retrieve the PassInfo for an analysis.
void setLastUser(ArrayRef< Pass * > AnalysisPasses, Pass *P)
Set pass P as the last user of the given analysis passes.
virtual ~PMTopLevelManager()
Destructor.
void schedulePass(Pass *P)
Schedule pass P for execution.
SmallVector< PMDataManager *, 8 > PassManagers
Collection of pass managers.
Pass * findAnalysisPass(AnalysisID AID)
Find the pass that implements Analysis AID.
AnalysisUsage * findAnalysisUsage(Pass *P)
Find analysis usage information for the pass P.
void addPassManager(PMDataManager *Manager)
unsigned getNumContainedManagers() const
SmallVectorImpl< ImmutablePass * > & getImmutablePasses()
PMTopLevelManager(PMDataManager *PMDM)
Initialize top level manager. Create first pass manager.
void collectLastUses(SmallVectorImpl< Pass * > &LastUses, Pass *P)
Collect passes whose last user is P.
PassInfo class - An instance of this class exists for every pass known by the system,...
Definition: PassInfo.h:30
bool isAnalysis() const
Definition: PassInfo.h:68
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to 'opt' that will cause this pas...
Definition: PassInfo.h:59
StringRef getPassName() const
getPassName - Return the friendly name for the pass, never returns null
Definition: PassInfo.h:54
Pass * createPass() const
createPass() - Use this method to create an instance of this pass.
Definition: PassInfo.h:85
PassManagerPrettyStackEntry - This is used to print informative information about what pass is runnin...
void print(raw_ostream &OS) const override
print - Emit information about this stack frame to OS.
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:162
PreservedAnalyses run(Function &IR, AnalysisManager< Function > &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const PassInfo * getPassInfo(const void *TI) const
getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass' type identifier (&MyPass::...
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
virtual PassManagerType getPotentialPassManagerType() const
Return what kind of Pass Manager can manage this pass.
Definition: Pass.cpp:93
void setResolver(AnalysisResolver *AR)
Definition: Pass.cpp:122
virtual PMDataManager * getAsPMDataManager()
Definition: Pass.cpp:118
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
Definition: Pass.h:113
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:98
virtual void assignPassManager(PMStack &, PassManagerType)
Each pass is responsible for assigning a pass manager to itself.
Definition: Pass.h:142
AnalysisResolver * getResolver() const
Definition: Pass.h:153
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:119
virtual Pass * createPrinterPass(raw_ostream &OS, const std::string &Banner) const =0
createPrinterPass - Get a Pass appropriate to print the IR this pass operates on (Module,...
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:123
virtual void dumpPassStructure(unsigned Offset=0)
Definition: Pass.cpp:74
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
virtual void releaseMemory()
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: Pass.cpp:102
Used to temporarily set the debug info format of a function, module, or basic block for the duration ...
bool empty() const
Definition: SmallVector.h:81
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:683
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
T * Allocate(size_t num=1)
Allocate space for an array of objects without constructing them.
Definition: Allocator.h:439
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
Definition: Timer.h:143
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
Definition: TimeProfiler.h:180
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Definition: AsmWriter.cpp:5144
FunctionPassManagerImpl manages FPPassManagers.
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a function printer pass.
FPPassManager * getContainedManager(unsigned N)
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
PMDataManager * getAsPMDataManager() override
void dumpPassStructure(unsigned Offset) override
bool run(Function &F)
run - Execute all of the passes scheduled for execution.
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
PassManagerType getTopLevelPassManagerType() override
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
PassManagerImpl manages MPPassManagers.
PassManagerType getTopLevelPassManagerType() override
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
void add(Pass *P)
Add a pass to the queue of passes to run.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
PMDataManager * getAsPMDataManager() override
MPPassManager * getContainedManager(unsigned N)
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a module printer pass.
void add(Pass *P) override
Add a pass to the queue of passes to run.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
PassManager()
Create new pass manager.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:711
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
@ PT_PassManager
Definition: Pass.h:72
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:977
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:55
@ PMT_ModulePassManager
MPPassManager.
Definition: Pass.h:57
@ PMT_FunctionPassManager
FPPassManager.
Definition: Pass.h:59
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
@ MODIFICATION_MSG
const void * AnalysisID
Definition: Pass.h:50
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1766
ModulePass * createPrintModulePass(raw_ostream &OS, const std::string &Banner="", bool ShouldPreserveUseListOrder=false)
Create and return a pass that writes the module to the specified raw_ostream.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1903
bool shouldPrintBeforePass(StringRef PassID)
bool shouldPrintAfterPass(StringRef PassID)
FunctionPass * createPrintFunctionPass(raw_ostream &OS, const std::string &Banner="")
Create and return a pass that prints functions to the specified raw_ostream as they are processed.
#define N
Used in the streaming interface as the general argument type.