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