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