LLVM 24.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/PassInfo.h"
24#include "llvm/Support/Chrono.h"
27#include "llvm/Support/Debug.h"
28#include "llvm/Support/Error.h"
31#include "llvm/Support/Timer.h"
33
34using namespace llvm;
35
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
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 auto [It, Inserted] = FunctionToInstrCount.try_emplace(
112 MaybeChangedFn.getName(), 0, FnSize);
113 if (Inserted)
114 return;
115 // Insert the new function size into the second member of the pair. This
116 // tells us whether or not this function changed in size.
117 It->second.second = FnSize;
118 };
119
120 // We need to initially update all of the function sizes.
121 // If no function was passed in, then we're either a module pass or an
122 // CGSCC pass.
123 if (!CouldOnlyImpactOneFunction)
124 llvm::for_each(M, UpdateFunctionChanges);
125 else
126 UpdateFunctionChanges(*F);
127
128 // Do we have a function we can use to emit a remark?
129 if (!CouldOnlyImpactOneFunction) {
130 // We need a function containing at least one basic block in order to output
131 // remarks. Since it's possible that the first function in the module
132 // doesn't actually contain a basic block, we have to go and find one that's
133 // suitable for emitting remarks.
134 auto It = llvm::find_if(M, [](const Function &Fn) { return !Fn.empty(); });
135
136 // Didn't find a function. Quit.
137 if (It == M.end())
138 return;
139
140 // We found a function containing at least one basic block.
141 F = &*It;
142 }
143 int64_t CountAfter = static_cast<int64_t>(CountBefore) + Delta;
144 BasicBlock &BB = *F->begin();
145 OptimizationRemarkAnalysis R("size-info", "IRSizeChange",
146 DiagnosticLocation(), &BB);
147 // FIXME: Move ore namespace to DiagnosticInfo so that we can use it. This
148 // would let us use NV instead of DiagnosticInfoOptimizationBase::Argument.
149 R << DiagnosticInfoOptimizationBase::Argument("Pass", P->getPassName())
150 << ": IR instruction count changed from "
151 << DiagnosticInfoOptimizationBase::Argument("IRInstrsBefore", CountBefore)
152 << " to "
153 << DiagnosticInfoOptimizationBase::Argument("IRInstrsAfter", CountAfter)
154 << "; Delta: "
155 << DiagnosticInfoOptimizationBase::Argument("DeltaInstrCount", Delta);
156 F->getContext().diagnose(R); // Not using ORE for layering reasons.
157
158 // Emit per-function size change remarks separately.
159 std::string PassName = P->getPassName().str();
160
161 // Helper lambda that emits a remark when the size of a function has changed.
162 auto EmitFunctionSizeChangedRemark = [&FunctionToInstrCount, &F, &BB,
163 &PassName](StringRef Fname) {
164 unsigned FnCountBefore, FnCountAfter;
165 std::pair<unsigned, unsigned> &Change = FunctionToInstrCount[Fname];
166 std::tie(FnCountBefore, FnCountAfter) = Change;
167 int64_t FnDelta = static_cast<int64_t>(FnCountAfter) -
168 static_cast<int64_t>(FnCountBefore);
169
170 if (FnDelta == 0)
171 return;
172
173 // FIXME: We shouldn't use BB for the location here. Unfortunately, because
174 // the function that we're looking at could have been deleted, we can't use
175 // it for the source location. We *want* remarks when a function is deleted
176 // though, so we're kind of stuck here as is. (This remark, along with the
177 // whole-module size change remarks really ought not to have source
178 // locations at all.)
179 OptimizationRemarkAnalysis FR("size-info", "FunctionIRSizeChange",
180 DiagnosticLocation(), &BB);
182 << ": Function: "
183 << DiagnosticInfoOptimizationBase::Argument("Function", Fname)
184 << ": IR instruction count changed from "
186 FnCountBefore)
187 << " to "
189 FnCountAfter)
190 << "; Delta: "
191 << DiagnosticInfoOptimizationBase::Argument("DeltaInstrCount", FnDelta);
192 F->getContext().diagnose(FR);
193
194 // Update the function size.
195 Change.first = FnCountAfter;
196 };
197
198 // Are we looking at more than one function? If so, emit remarks for all of
199 // the functions in the module. Otherwise, only emit one remark.
200 if (!CouldOnlyImpactOneFunction)
201 llvm::for_each(FunctionToInstrCount.keys(), EmitFunctionSizeChangedRemark);
202 else
203 EmitFunctionSizeChangedRemark(F->getName().str());
204}
205
207 if (!V && !M)
208 OS << "Releasing pass '";
209 else
210 OS << "Running pass '";
211
212 OS << P->getPassName() << "'";
213
214 if (M) {
215 OS << " on module '" << M->getModuleIdentifier() << "'.\n";
216 return;
217 }
218 if (!V) {
219 OS << '\n';
220 return;
221 }
222
223 OS << " on ";
224 if (isa<Function>(V))
225 OS << "function";
226 else if (isa<BasicBlock>(V))
227 OS << "basic block";
228 else
229 OS << "value";
230
231 OS << " '";
232 V->printAsOperand(OS, /*PrintType=*/false, M);
233 OS << "'\n";
234}
235
236namespace llvm {
237namespace legacy {
239
240//===----------------------------------------------------------------------===//
241// FunctionPassManagerImpl
242//
243/// FunctionPassManagerImpl manages FPPassManagers
245 public PMDataManager,
246 public PMTopLevelManager {
247 virtual void anchor();
248private:
249 bool wasRun;
250public:
251 static char ID;
255
256 /// \copydoc FunctionPassManager::add()
257 void add(Pass *P) {
259 }
260
261 /// createPrinterPass - Get a function printer pass.
263 const std::string &Banner) const override {
264 return createPrintFunctionPass(O, Banner);
265 }
266
267 // Prepare for running an on the fly pass, freeing memory if needed
268 // from a previous run.
270
271 /// run - Execute all of the passes scheduled for execution. Keep track of
272 /// whether any of the passes modifies the module, and if so, return true.
273 bool run(Function &F);
274
275 /// doInitialization - Run all of the initializers for the function passes.
276 ///
277 bool doInitialization(Module &M) override;
278
279 /// doFinalization - Run all of the finalizers for the function passes.
280 ///
281 bool doFinalization(Module &M) override;
282
283
284 PMDataManager *getAsPMDataManager() override { return this; }
285 Pass *getAsPass() override { return this; }
289
290 /// Pass Manager itself does not invalidate any analysis info.
291 void getAnalysisUsage(AnalysisUsage &Info) const override {
292 Info.setPreservesAll();
293 }
294
296 assert(N < PassManagers.size() && "Pass number out of range!");
297 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
298 return FP;
299 }
300
301 void dumpPassStructure(unsigned Offset) override {
302 for (unsigned I = 0; I < getNumContainedManagers(); ++I)
304 }
305};
306
307void FunctionPassManagerImpl::anchor() {}
308
310
311//===----------------------------------------------------------------------===//
312// FunctionPassManagerImpl implementation
313//
315 bool Changed = false;
316
318 dumpPasses();
319
320 for (ImmutablePass *ImPass : getImmutablePasses())
321 Changed |= ImPass->doInitialization(M);
322
323 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
325
326 return Changed;
327}
328
330 bool Changed = false;
331
332 for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index)
334
335 for (ImmutablePass *ImPass : getImmutablePasses())
336 Changed |= ImPass->doFinalization(M);
337
338 return Changed;
339}
340
342 if (!wasRun)
343 return;
344 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
345 FPPassManager *FPPM = getContainedManager(Index);
346 for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) {
347 FPPM->getContainedPass(Index)->releaseMemory();
348 }
349 }
350 wasRun = false;
351}
352
353// Execute all the passes managed by this top level manager.
354// Return true if any function is modified by a pass.
356 bool Changed = false;
357
359 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
361 F.getContext().yield();
362 }
363
364 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
366
367 wasRun = true;
368 return Changed;
369}
370} // namespace legacy
371} // namespace llvm
372
373namespace {
374//===----------------------------------------------------------------------===//
375// MPPassManager
376//
377/// MPPassManager manages ModulePasses and function pass managers.
378/// It batches all Module passes and function pass managers together and
379/// sequences them to process one module.
380class MPPassManager : public Pass, public PMDataManager {
381public:
382 static char ID;
383 explicit MPPassManager() : Pass(PT_PassManager, ID) {}
384
385 // Delete on the fly managers.
386 ~MPPassManager() override {
387 for (auto &OnTheFlyManager : OnTheFlyManagers) {
388 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
389 delete FPP;
390 }
391 }
392
393 /// createPrinterPass - Get a module printer pass.
394 Pass *createPrinterPass(raw_ostream &O,
395 const std::string &Banner) const override {
396 return createPrintModulePass(O, Banner);
397 }
398
399 /// run - Execute all of the passes scheduled for execution. Keep track of
400 /// whether any of the passes modifies the module, and if so, return true.
401 bool runOnModule(Module &M);
402
405
406 /// Pass Manager itself does not invalidate any analysis info.
407 void getAnalysisUsage(AnalysisUsage &Info) const override {
408 Info.setPreservesAll();
409 }
410
411 /// Add RequiredPass into list of lower level passes required by pass P.
412 /// RequiredPass is run on the fly by Pass Manager when P requests it
413 /// through getAnalysis interface.
414 void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) override;
415
416 /// Return function pass corresponding to PassInfo PI, that is
417 /// required by module pass MP. Instantiate analysis pass, by using
418 /// its runOnFunction() for function F.
419 std::tuple<Pass *, bool> getOnTheFlyPass(Pass *MP, AnalysisID PI,
420 Function &F) override;
421
422 StringRef getPassName() const override { return "Module Pass Manager"; }
423
424 PMDataManager *getAsPMDataManager() override { return this; }
425 Pass *getAsPass() override { return this; }
426
427 // Print passes managed by this manager
428 void dumpPassStructure(unsigned Offset) override {
429 dbgs().indent(Offset*2) << "ModulePass Manager\n";
430 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
431 ModulePass *MP = getContainedPass(Index);
432 MP->dumpPassStructure(Offset + 1);
434 OnTheFlyManagers.find(MP);
435 if (I != OnTheFlyManagers.end())
436 I->second->dumpPassStructure(Offset + 2);
437 dumpLastUses(MP, Offset+1);
438 }
439 }
440
441 ModulePass *getContainedPass(unsigned N) {
442 assert(N < PassVector.size() && "Pass number out of range!");
443 return static_cast<ModulePass *>(PassVector[N]);
444 }
445
446 PassManagerType getPassManagerType() const override {
448 }
449
450 private:
451 /// Collection of on the fly FPPassManagers. These managers manage
452 /// function passes that are required by module passes.
453 MapVector<Pass *, legacy::FunctionPassManagerImpl *> OnTheFlyManagers;
454};
455
456char MPPassManager::ID = 0;
457} // End anonymous namespace
458
459namespace llvm {
460namespace legacy {
461//===----------------------------------------------------------------------===//
462// PassManagerImpl
463//
464
465/// PassManagerImpl manages MPPassManagers
466class PassManagerImpl : public Pass,
467 public PMDataManager,
468 public PMTopLevelManager {
469 virtual void anchor();
470
471public:
472 static char ID;
474 : Pass(PT_PassManager, ID), PMTopLevelManager(new MPPassManager()) {}
475
476 /// \copydoc PassManager::add()
477 void add(Pass *P) {
479 }
480
481 /// createPrinterPass - Get a module printer pass.
483 const std::string &Banner) const override {
484 return createPrintModulePass(O, Banner);
485 }
486
487 /// run - Execute all of the passes scheduled for execution. Keep track of
488 /// whether any of the passes modifies the module, and if so, return true.
489 bool run(Module &M);
490
493
494 /// Pass Manager itself does not invalidate any analysis info.
495 void getAnalysisUsage(AnalysisUsage &Info) const override {
496 Info.setPreservesAll();
497 }
498
499 PMDataManager *getAsPMDataManager() override { return this; }
500 Pass *getAsPass() override { return this; }
504
505 MPPassManager *getContainedManager(unsigned N) {
506 assert(N < PassManagers.size() && "Pass number out of range!");
507 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
508 return MP;
509 }
510};
511
512void PassManagerImpl::anchor() {}
513
514char PassManagerImpl::ID = 0;
515
516//===----------------------------------------------------------------------===//
517// PassManagerImpl implementation
518
519//
520/// run - Execute all of the passes scheduled for execution. Keep track of
521/// whether any of the passes modifies the module, and if so, return true.
523 bool Changed = false;
524
526 dumpPasses();
527
528 for (ImmutablePass *ImPass : getImmutablePasses())
529 Changed |= ImPass->doInitialization(M);
530
532 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
533 Changed |= getContainedManager(Index)->runOnModule(M);
534 M.getContext().yield();
535 }
536
537 for (ImmutablePass *ImPass : getImmutablePasses())
538 Changed |= ImPass->doFinalization(M);
539
540 return Changed;
541}
542} // namespace legacy
543} // namespace llvm
544
545//===----------------------------------------------------------------------===//
546// PMTopLevelManager implementation
547
548/// Initialize top level manager. Create first pass manager.
554
555/// Set pass P as the last user of the given analysis passes.
556void
558 unsigned PDepth = 0;
559 if (P->getResolver())
560 PDepth = P->getResolver()->getPMDataManager().getDepth();
561
562 for (Pass *AP : AnalysisPasses) {
563 // Record P as the new last user of AP.
564 auto &LastUserOfAP = LastUser[AP];
565 if (LastUserOfAP)
566 InversedLastUser[LastUserOfAP].erase(AP);
567 LastUserOfAP = P;
568 InversedLastUser[P].insert(AP);
569
570 if (P == AP)
571 continue;
572
573 // Update the last users of passes that are required transitive by AP.
574 AnalysisUsage *AnUsage = findAnalysisUsage(AP);
577 SmallVector<Pass *, 12> LastPMUses;
578 for (AnalysisID ID : IDs) {
579 Pass *AnalysisPass = findAnalysisPass(ID);
580 assert(AnalysisPass && "Expected analysis pass to exist.");
581 AnalysisResolver *AR = AnalysisPass->getResolver();
582 assert(AR && "Expected analysis resolver to exist.");
583 unsigned APDepth = AR->getPMDataManager().getDepth();
584
585 if (PDepth == APDepth)
586 LastUses.push_back(AnalysisPass);
587 else if (PDepth > APDepth)
588 LastPMUses.push_back(AnalysisPass);
589 }
590
591 setLastUser(LastUses, P);
592
593 // If this pass has a corresponding pass manager, push higher level
594 // analysis to this pass manager.
595 if (P->getResolver())
596 setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass());
597
598 // If AP is the last user of other passes then make P last user of
599 // such passes.
600 auto &LastUsedByAP = InversedLastUser[AP];
601 for (Pass *L : LastUsedByAP)
602 LastUser[L] = P;
603 InversedLastUser[P].insert_range(LastUsedByAP);
604 LastUsedByAP.clear();
605 }
606}
607
608/// Collect passes whose last user is P
610 Pass *P) {
611 auto DMI = InversedLastUser.find(P);
612 if (DMI == InversedLastUser.end())
613 return;
614
615 auto &LU = DMI->second;
616 LastUses.append(LU.begin(), LU.end());
617}
618
620 AnalysisUsage *AnUsage = nullptr;
621 auto DMI = AnUsageMap.find(P);
622 if (DMI != AnUsageMap.end())
623 AnUsage = DMI->second;
624 else {
625 // Look up the analysis usage from the pass instance (different instances
626 // of the same pass can produce different results), but unique the
627 // resulting object to reduce memory usage. This helps to greatly reduce
628 // memory usage when we have many instances of only a few pass types
629 // (e.g. instcombine, simplifycfg, etc...) which tend to share a fixed set
630 // of dependencies.
631 AnalysisUsage AU;
632 P->getAnalysisUsage(AU);
633
634 AUFoldingSetNode* Node = nullptr;
636 AUFoldingSetNode::Profile(ID, AU);
638 if (auto *N = UniqueAnalysisUsages.lookup(ID, Token))
639 Node = N;
640 else {
641 Node = new (AUFoldingSetNodeAllocator.Allocate()) AUFoldingSetNode(AU);
642 UniqueAnalysisUsages.insert(Node, Token);
643 }
644 assert(Node && "cached analysis usage must be non null");
645
646 AnUsageMap[P] = &Node->AU;
647 AnUsage = &Node->AU;
648 }
649 return AnUsage;
650}
651
652/// Schedule pass P for execution. Make sure that passes required by
653/// P are run before P is run. Update analysis info maintained by
654/// the manager. Remove dead passes. This is a recursive function.
656
657 // TODO : Allocate function manager for this pass, other wise required set
658 // may be inserted into previous function manager
659
660 // Give pass a chance to prepare the stage.
661 P->preparePassManager(activeStack);
662
663 // If P is an analysis pass and it is available then do not
664 // generate the analysis again. Stale analysis info should not be
665 // available at this point.
666 const PassInfo *PI = findAnalysisPassInfo(P->getPassID());
667 if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) {
668 // Remove any cached AnalysisUsage information.
669 AnUsageMap.erase(P);
670 delete P;
671 return;
672 }
673
675
676 bool checkAnalysis = true;
677 while (checkAnalysis) {
678 checkAnalysis = false;
679
680 const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
681 for (const AnalysisID ID : RequiredSet) {
682
683 Pass *AnalysisPass = findAnalysisPass(ID);
684 if (!AnalysisPass) {
685 const PassInfo *PI = findAnalysisPassInfo(ID);
686
687 if (!PI) {
688 // Pass P is not in the global PassRegistry
689 dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
690 dbgs() << "Verify if there is a pass dependency cycle." << "\n";
691 dbgs() << "Required Passes:" << "\n";
692 for (const AnalysisID ID2 : RequiredSet) {
693 if (ID == ID2)
694 break;
695 Pass *AnalysisPass2 = findAnalysisPass(ID2);
696 if (AnalysisPass2) {
697 dbgs() << "\t" << AnalysisPass2->getPassName() << "\n";
698 } else {
699 dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n";
700 dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n";
701 dbgs() << "\t\t" << "- Corruption of the global PassRegistry" << "\n";
702 }
703 }
704 }
705
706 assert(PI && "Expected required passes to be initialized");
707 AnalysisPass = PI->createPass();
708 if (P->getPotentialPassManagerType () ==
709 AnalysisPass->getPotentialPassManagerType())
710 // Schedule analysis pass that is managed by the same pass manager.
711 schedulePass(AnalysisPass);
712 else if (P->getPotentialPassManagerType () >
713 AnalysisPass->getPotentialPassManagerType()) {
714 // Schedule analysis pass that is managed by a new manager.
715 schedulePass(AnalysisPass);
716 // Recheck analysis passes to ensure that required analyses that
717 // are already checked are still available.
718 checkAnalysis = true;
719 } else
720 // Do not schedule this analysis. Lower level analysis
721 // passes are run on the fly.
722 delete AnalysisPass;
723 }
724 }
725 }
726
727 // Now all required passes are available.
728 if (ImmutablePass *IP = P->getAsImmutablePass()) {
729 // P is a immutable pass and it will be managed by this
730 // top level manager. Set up analysis resolver to connect them.
731 PMDataManager *DM = getAsPMDataManager();
733 P->setResolver(AR);
734 DM->initializeAnalysisImpl(P);
736 DM->recordAvailableAnalysis(IP);
737 return;
738 }
739
740 if (PI && !PI->isAnalysis() && shouldPrintBeforePass(PI->getPassArgument())) {
741 Pass *PP =
742 P->createPrinterPass(dbgs(), ("*** IR Dump Before " + P->getPassName() +
743 " (" + PI->getPassArgument() + ") ***")
744 .str());
745 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
746 }
747
748 // Add the requested pass to the best available pass manager.
749 P->assignPassManager(activeStack, getTopLevelPassManagerType());
750
751 if (PI && !PI->isAnalysis() && shouldPrintAfterPass(PI->getPassArgument())) {
752 Pass *PP =
753 P->createPrinterPass(dbgs(), ("*** IR Dump After " + P->getPassName() +
754 " (" + PI->getPassArgument() + ") ***")
755 .str());
756 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
757 }
758}
759
760/// Find the pass that implements Analysis AID. Search immutable
761/// passes and all pass managers. If desired pass is not found
762/// then return NULL.
764 // For immutable passes we have a direct mapping from ID to pass, so check
765 // that first.
766 if (Pass *P = ImmutablePassMap.lookup(AID))
767 return P;
768
769 // Check pass managers
771 if (Pass *P = PassManager->findAnalysisPass(AID, false))
772 return P;
773
774 // Check other pass managers
775 for (PMDataManager *IndirectPassManager : IndirectPassManagers)
776 if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false))
777 return P;
778
779 return nullptr;
780}
781
783 const PassInfo *&PI = AnalysisPassInfos[AID];
784 if (!PI)
786 else
788 "The pass info pointer changed for an analysis ID!");
789
790 return PI;
791}
792
794 P->initializePass();
795 ImmutablePasses.push_back(P);
796
797 // Add this pass to the map from its analysis ID. We clobber any prior runs
798 // of the pass in the map so that the last one added is the one found when
799 // doing lookups.
800 AnalysisID AID = P->getPassID();
801 ImmutablePassMap[AID] = P;
802}
803
804// Print passes managed by this top level manager.
806
807 if (PassDebugging < Structure)
808 return;
809
810 // Print out the immutable passes
811 for (ImmutablePass *Pass : ImmutablePasses)
813
814 // Every class that derives from PMDataManager also derives from Pass
815 // (sometimes indirectly), but there's no inheritance relationship
816 // between PMDataManager and Pass, so we have to getAsPass to get
817 // from a PMDataManager* to a Pass*.
818 for (PMDataManager *Manager : PassManagers)
819 Manager->getAsPass()->dumpPassStructure(1);
820}
821
823
825 return;
826
827 dbgs() << "Pass Arguments: ";
828 for (ImmutablePass *P : ImmutablePasses)
829 if (const PassInfo *PI = findAnalysisPassInfo(P->getPassID())) {
830 assert(PI && "Expected all immutable passes to be initialized");
831 dbgs() << " -" << PI->getPassArgument();
832 }
833 for (PMDataManager *PM : PassManagers)
834 PM->dumpPassArguments();
835 dbgs() << "\n";
836}
837
839 for (PMDataManager *PM : PassManagers)
840 PM->initializeAnalysisInfo();
841
842 // Initailize other pass managers
843 for (PMDataManager *IPM : IndirectPassManagers)
844 IPM->initializeAnalysisInfo();
845}
846
847/// Destructor
849 for (PMDataManager *PM : PassManagers)
850 delete PM;
851
852 for (ImmutablePass *P : ImmutablePasses)
853 delete P;
854}
855
856//===----------------------------------------------------------------------===//
857// PMDataManager implementation
858
859/// Augement AvailableAnalysis by adding analysis made available by pass P.
861 AnalysisID PI = P->getPassID();
862
863 AvailableAnalysis[PI] = P;
864}
865
866// Return true if P preserves high level analysis used by other
867// passes managed by this manager
869 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
870 if (AnUsage->getPreservesAll())
871 return true;
872
873 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
874 for (Pass *P1 : HigherLevelAnalysis) {
875 if (P1->getAsImmutablePass() == nullptr &&
876 !is_contained(PreservedSet, P1->getPassID()))
877 return false;
878 }
879
880 return true;
881}
882
883/// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
885 // Don't do this unless assertions are enabled.
886#ifdef NDEBUG
887 return;
888#endif
889 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
890 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
891
892 // Verify preserved analysis
893 for (AnalysisID AID : PreservedSet) {
894 if (Pass *AP = findAnalysisPass(AID, true)) {
895 TimeRegion PassTimer(getPassTimer(AP));
896 AP->verifyAnalysis();
897 }
898 }
899}
900
901/// Remove Analysis not preserved by Pass P
903 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
904 if (AnUsage->getPreservesAll())
905 return;
906
907 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
908 SmallVector<DenseMap<AnalysisID, Pass *> *, 8> Maps = {&AvailableAnalysis};
909 // Check inherited analysis also. If P is not preserving analysis
910 // provided by parent manager then remove it here.
912 if (IA)
913 Maps.push_back(IA);
914 // Prune every map from a single remove_if call site. The instantiated
915 // DenseMap::remove_if is a local function; sharing it across more than one
916 // call site makes the inliner emit it out of line, which adds a call in this
917 // hot per-pass path. A single call site keeps it inlined here.
918 for (DenseMap<AnalysisID, Pass *> *M : Maps) {
919 // These maps are usually empty here, but a DenseMap keeps its grown bucket
920 // array after the entries are erased, so remove_if would still scan all
921 // those empty buckets. Skip it.
922 if (M->empty())
923 continue;
924 M->remove_if([&](const auto &Entry) {
925 if (Entry.second->getAsImmutablePass() != nullptr ||
926 is_contained(PreservedSet, Entry.first))
927 return false;
928 // Remove this analysis
929 if (PassDebugging >= Details) {
930 Pass *S = Entry.second;
931 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
932 dbgs() << S->getPassName() << "'\n";
933 }
934 return true;
935 });
936 }
937}
938
939/// Remove analysis passes that are not used any longer
941 enum PassDebuggingString DBG_STR) {
942
943 SmallVector<Pass *, 12> DeadPasses;
944
945 // If this is a on the fly manager then it does not have TPM.
946 if (!TPM)
947 return;
948
949 TPM->collectLastUses(DeadPasses, P);
950
951 if (PassDebugging >= Details && !DeadPasses.empty()) {
952 dbgs() << " -*- '" << P->getPassName();
953 dbgs() << "' is the last user of following pass instances.";
954 dbgs() << " Free these instances\n";
955 }
956
957 for (Pass *P : DeadPasses)
958 freePass(P, Msg, DBG_STR);
959}
960
962 enum PassDebuggingString DBG_STR) {
963 dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
964
965 {
966 // If the pass crashes releasing memory, remember this.
968 TimeRegion PassTimer(getPassTimer(P));
969
970 P->releaseMemory();
971 }
972
973 // Remove the pass itself (if it is not already removed).
974 AvailableAnalysis.erase(P->getPassID());
975}
976
977/// Add pass P into the PassVector. Update
978/// AvailableAnalysis appropriately if ProcessAnalysis is true.
979void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
980 // This manager is going to manage pass P. Set up analysis resolver
981 // to connect them.
982 AnalysisResolver *AR = new AnalysisResolver(*this);
983 P->setResolver(AR);
984
985 // If a FunctionPass F is the last user of ModulePass info M
986 // then the F's manager, not F, records itself as a last user of M.
987 SmallVector<Pass *, 12> TransferLastUses;
988
989 if (!ProcessAnalysis) {
990 // Add pass
991 PassVector.push_back(P);
992 return;
993 }
994
995 // At the moment, this pass is the last user of all required passes.
997 SmallVector<Pass *, 8> UsedPasses;
998 SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
999
1000 unsigned PDepth = this->getDepth();
1001
1002 collectRequiredAndUsedAnalyses(UsedPasses, ReqAnalysisNotAvailable, P);
1003 for (Pass *PUsed : UsedPasses) {
1004 unsigned RDepth = 0;
1005
1006 assert(PUsed->getResolver() && "Analysis Resolver is not set");
1007 PMDataManager &DM = PUsed->getResolver()->getPMDataManager();
1008 RDepth = DM.getDepth();
1009
1010 if (PDepth == RDepth)
1011 LastUses.push_back(PUsed);
1012 else if (PDepth > RDepth) {
1013 // Let the parent claim responsibility of last use
1014 TransferLastUses.push_back(PUsed);
1015 // Keep track of higher level analysis used by this manager.
1016 HigherLevelAnalysis.push_back(PUsed);
1017 } else
1018 llvm_unreachable("Unable to accommodate Used Pass");
1019 }
1020
1021 // Set P as P's last user until someone starts using P.
1022 // However, if P is a Pass Manager then it does not need
1023 // to record its last user.
1024 if (!P->getAsPMDataManager())
1025 LastUses.push_back(P);
1026 TPM->setLastUser(LastUses, P);
1027
1028 if (!TransferLastUses.empty()) {
1029 Pass *My_PM = getAsPass();
1030 TPM->setLastUser(TransferLastUses, My_PM);
1031 TransferLastUses.clear();
1032 }
1033
1034 // Now, take care of required analyses that are not available.
1035 for (AnalysisID ID : ReqAnalysisNotAvailable) {
1036 const PassInfo *PI = TPM->findAnalysisPassInfo(ID);
1037 Pass *AnalysisPass = PI->createPass();
1038 this->addLowerLevelRequiredPass(P, AnalysisPass);
1039 }
1040
1041 // Take a note of analysis required and made available by this pass.
1042 // Remove the analysis not preserved by this pass
1045
1046 // Add pass
1047 PassVector.push_back(P);
1048}
1049
1050
1051/// Populate UP with analysis pass that are used or required by
1052/// pass P and are available. Populate RP_NotAvail with analysis
1053/// pass that are required by pass P but are not available.
1056 Pass *P) {
1057 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
1058
1059 for (const auto &UsedID : AnUsage->getUsedSet())
1060 if (Pass *AnalysisPass = findAnalysisPass(UsedID, true))
1061 UP.push_back(AnalysisPass);
1062
1063 for (const auto &RequiredID : AnUsage->getRequiredSet())
1064 if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true))
1065 UP.push_back(AnalysisPass);
1066 else
1067 RP_NotAvail.push_back(RequiredID);
1068}
1069
1070// All Required analyses should be available to the pass as it runs! Here
1071// we fill in the AnalysisImpls member of the pass so that it can
1072// successfully use the getAnalysis() method to retrieve the
1073// implementations it needs.
1074//
1076 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
1077
1078 for (const AnalysisID ID : AnUsage->getRequiredSet()) {
1079 Pass *Impl = findAnalysisPass(ID, true);
1080 if (!Impl)
1081 // This may be analysis pass that is initialized on the fly.
1082 // If that is not the case then it will raise an assert when it is used.
1083 continue;
1084 AnalysisResolver *AR = P->getResolver();
1085 assert(AR && "Analysis Resolver is not set");
1086 AR->addAnalysisImplsPair(ID, Impl);
1087 }
1088}
1089
1090/// Find the pass that implements Analysis AID. If desired pass is not found
1091/// then return NULL.
1093
1094 // Check if AvailableAnalysis map has one entry.
1095 auto I = AvailableAnalysis.find(AID);
1096
1097 if (I != AvailableAnalysis.end())
1098 return I->second;
1099
1100 // Search Parents through TopLevelManager
1101 if (SearchParent)
1102 return TPM->findAnalysisPass(AID);
1103
1104 return nullptr;
1105}
1106
1107// Print list of passes that are last used by P.
1109 if (PassDebugging < Details)
1110 return;
1111
1113
1114 // If this is a on the fly manager then it does not have TPM.
1115 if (!TPM)
1116 return;
1117
1118 TPM->collectLastUses(LUses, P);
1119
1120 for (Pass *P : LUses) {
1121 dbgs() << "--" << std::string(Offset*2, ' ');
1122 P->dumpPassStructure(0);
1123 }
1124}
1125
1127 for (Pass *P : PassVector) {
1128 if (PMDataManager *PMD = P->getAsPMDataManager())
1129 PMD->dumpPassArguments();
1130 else if (const PassInfo *PI = TPM->findAnalysisPassInfo(P->getPassID()))
1131 dbgs() << " -" << PI->getPassArgument();
1132 }
1133}
1134
1136 enum PassDebuggingString S2,
1137 StringRef Msg) {
1138 if (PassDebugging < Executions)
1139 return;
1140 dbgs() << "[" << std::chrono::system_clock::now() << "] " << (void *)this
1141 << std::string(getDepth() * 2 + 1, ' ');
1142 switch (S1) {
1143 case EXECUTION_MSG:
1144 dbgs() << "Executing Pass '" << P->getPassName();
1145 break;
1146 case MODIFICATION_MSG:
1147 dbgs() << "Made Modification '" << P->getPassName();
1148 break;
1149 case FREEING_MSG:
1150 dbgs() << " Freeing Pass '" << P->getPassName();
1151 break;
1152 default:
1153 break;
1154 }
1155 switch (S2) {
1156 case ON_FUNCTION_MSG:
1157 dbgs() << "' on Function '" << Msg << "'...\n";
1158 break;
1159 case ON_MODULE_MSG:
1160 dbgs() << "' on Module '" << Msg << "'...\n";
1161 break;
1162 case ON_LOOP_MSG:
1163 dbgs() << "' on Loop '" << Msg << "'...\n";
1164 break;
1165 case ON_CG_MSG:
1166 dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
1167 break;
1168 default:
1169 break;
1170 }
1171}
1172
1174 if (PassDebugging < Details)
1175 return;
1176
1177 AnalysisUsage analysisUsage;
1178 P->getAnalysisUsage(analysisUsage);
1179 dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
1180}
1181
1183 if (PassDebugging < Details)
1184 return;
1185
1186 AnalysisUsage analysisUsage;
1187 P->getAnalysisUsage(analysisUsage);
1188 dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
1189}
1190
1192 if (PassDebugging < Details)
1193 return;
1194
1195 AnalysisUsage analysisUsage;
1196 P->getAnalysisUsage(analysisUsage);
1197 dumpAnalysisUsage("Used", P, analysisUsage.getUsedSet());
1198}
1199
1200void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
1201 const AnalysisUsage::VectorType &Set) const {
1202 assert(PassDebugging >= Details);
1203 if (Set.empty())
1204 return;
1205 dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
1206 for (unsigned i = 0; i != Set.size(); ++i) {
1207 if (i) dbgs() << ',';
1208 const PassInfo *PInf = TPM->findAnalysisPassInfo(Set[i]);
1209 if (!PInf) {
1210 // Some preserved passes, such as AliasAnalysis, may not be initialized by
1211 // all drivers.
1212 dbgs() << " Uninitialized Pass";
1213 continue;
1214 }
1215 dbgs() << ' ' << PInf->getPassName();
1216 }
1217 dbgs() << '\n';
1218}
1219
1220/// Add RequiredPass into list of lower level passes required by pass P.
1221/// RequiredPass is run on the fly by Pass Manager when P requests it
1222/// through getAnalysis interface.
1223/// This should be handled by specific pass manager.
1225 if (TPM) {
1226 TPM->dumpArguments();
1227 TPM->dumpPasses();
1228 }
1229
1230 // Module Level pass may required Function Level analysis info
1231 // (e.g. dominator info). Pass manager uses on the fly function pass manager
1232 // to provide this on demand. In that case, in Pass manager terminology,
1233 // module level pass is requiring lower level analysis info managed by
1234 // lower level pass manager.
1235
1236 // When Pass manager is not able to order required analysis info, Pass manager
1237 // checks whether any lower level manager will be able to provide this
1238 // analysis info on demand or not.
1239#ifndef NDEBUG
1240 dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
1241 dbgs() << "' required by '" << P->getPassName() << "'\n";
1242#endif
1243 llvm_unreachable("Unable to schedule pass");
1244}
1245
1246std::tuple<Pass *, bool> PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI,
1247 Function &F) {
1248 llvm_unreachable("Unable to find on the fly pass");
1249}
1250
1251// Destructor
1253 for (Pass *P : PassVector)
1254 delete P;
1255}
1256
1257//===----------------------------------------------------------------------===//
1258// NOTE: Is this the right place to define this method ?
1259// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
1261 return PM.findAnalysisPass(ID, true);
1262}
1263
1264std::tuple<Pass *, bool>
1266 return PM.getOnTheFlyPass(P, AnalysisPI, F);
1267}
1268
1269namespace llvm {
1270namespace legacy {
1271
1272//===----------------------------------------------------------------------===//
1273// FunctionPassManager implementation
1274
1275/// Create new Function pass manager
1276FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
1278 // FPM is the top level manager.
1279 FPM->setTopLevelManager(FPM);
1280
1281 AnalysisResolver *AR = new AnalysisResolver(*FPM);
1282 FPM->setResolver(AR);
1283}
1284
1285FunctionPassManager::~FunctionPassManager() {
1286 delete FPM;
1287}
1288
1289void FunctionPassManager::add(Pass *P) {
1290 FPM->add(P);
1291}
1292
1293/// run - Execute all of the passes scheduled for execution. Keep
1294/// track of whether any of the passes modifies the function, and if
1295/// so, return true.
1296///
1298 handleAllErrors(F.materialize(), [&](ErrorInfoBase &EIB) {
1299 report_fatal_error(Twine("Error reading bitcode file: ") + EIB.message());
1300 });
1301 return FPM->run(F);
1302}
1303
1304
1305/// doInitialization - Run all of the initializers for the function passes.
1306///
1307bool FunctionPassManager::doInitialization() {
1308 return FPM->doInitialization(*M);
1309}
1310
1311/// doFinalization - Run all of the finalizers for the function passes.
1312///
1313bool FunctionPassManager::doFinalization() {
1314 return FPM->doFinalization(*M);
1315}
1316} // namespace legacy
1317} // namespace llvm
1318
1319/// cleanup - After running all passes, clean up pass manager cache.
1321 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1323 AnalysisResolver *AR = FP->getResolver();
1324 assert(AR && "Analysis Resolver is not set");
1325 AR->clearAnalysisImpls();
1326 }
1327}
1328
1329
1330//===----------------------------------------------------------------------===//
1331// FPPassManager implementation
1332
1333char FPPassManager::ID = 0;
1334/// Print passes managed by this manager
1336 dbgs().indent(Offset*2) << "FunctionPass Manager\n";
1337 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1339 FP->dumpPassStructure(Offset + 1);
1341 }
1342}
1343
1344/// Execute all of the passes scheduled for execution by invoking
1345/// runOnFunction method. Keep track of whether any of the passes modifies
1346/// the function, and if so, return true.
1348 if (F.isDeclaration())
1349 return false;
1350
1351 bool Changed = false;
1352 Module &M = *F.getParent();
1353 // Collect inherited analysis from Module level pass manager.
1354 populateInheritedAnalysis(TPM->activeStack);
1355
1356 unsigned InstrCount, FunctionSize = 0;
1357 StringMap<std::pair<unsigned, unsigned>> FunctionToInstrCount;
1358 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
1359 // Collect the initial size of the module.
1360 if (EmitICRemark) {
1361 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1362 FunctionSize = F.getInstructionCount();
1363 }
1364
1365 // Store name outside of loop to avoid redundant calls.
1366 const StringRef Name = F.getName();
1367 llvm::TimeTraceScope FunctionScope("OptFunction", Name);
1368 SmallString<0> BeforeStr, AfterStr;
1369 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1371 bool LocalChanged = false;
1372
1373 // Call getPassName only when required. The call itself is fairly cheap, but
1374 // still virtual and repeated calling adds unnecessary overhead.
1375 llvm::TimeTraceScope PassScope(
1376 "RunPass", [FP]() { return std::string(FP->getPassName()); });
1377
1380
1382
1383 // For --print-changed, capture the IR before the pass. Skip analyses (like
1384 // the new pass manager) and passes with no registry info (pass managers and
1385 // unregistered infrastructure passes).
1386 StringRef PassID;
1387 bool ReportChanged = PrintChanged != ChangePrinter::None;
1388 bool IsInteresting = false, ShouldCaptureChanged = false;
1389 bool ShouldPrintChanged = false;
1390 if (ReportChanged) {
1391 const PassInfo *PI = Pass::lookupPassInfo(FP->getPassID());
1392 if (PI && !PI->isAnalysis()) {
1393 PassID = PI->getPassArgument();
1394 IsInteresting = isPassInPrintList(PassID);
1395 ShouldCaptureChanged = IsInteresting;
1396 } else {
1397 ReportChanged = false;
1398 }
1399 }
1400 if (ShouldCaptureChanged) {
1401 BeforeStr.clear();
1402 AfterStr.clear();
1403 raw_svector_ostream OS(BeforeStr);
1404 // printIRUnit returns false if there is nothing to report.
1405 ShouldPrintChanged = FP->printIRUnit(OS, F);
1406 }
1407
1408 {
1410 TimeRegion PassTimer(getPassTimer(FP));
1411#ifdef EXPENSIVE_CHECKS
1412 uint64_t RefHash = FP->structuralHash(F);
1413#endif
1414 LocalChanged |= FP->runOnFunction(F);
1415
1416#if defined(EXPENSIVE_CHECKS) && !defined(NDEBUG)
1417 if (!LocalChanged && (RefHash != FP->structuralHash(F))) {
1418 llvm::errs() << "Pass modifies its input and doesn't report it: "
1419 << FP->getPassName() << "\n";
1420 llvm_unreachable("Pass modifies its input and doesn't report it");
1421 }
1422#endif
1423
1424 if (EmitICRemark) {
1425 unsigned NewSize = F.getInstructionCount();
1426
1427 // Update the size of the function, emit a remark, and update the size
1428 // of the module.
1429 if (NewSize != FunctionSize) {
1430 int64_t Delta = static_cast<int64_t>(NewSize) -
1431 static_cast<int64_t>(FunctionSize);
1433 FunctionToInstrCount, &F);
1434 InstrCount = static_cast<int64_t>(InstrCount) + Delta;
1435 FunctionSize = NewSize;
1436 }
1437 }
1438 }
1439
1440 if (ShouldCaptureChanged) {
1441 raw_svector_ostream OS(AfterStr);
1442 ShouldPrintChanged |= FP->printIRUnit(OS, F);
1443 }
1444 if (ReportChanged)
1445 reportChangedIR(BeforeStr, AfterStr, FP->getPassName(), PassID, Name,
1446 IsInteresting, ShouldPrintChanged);
1447
1448 Changed |= LocalChanged;
1449 if (LocalChanged)
1452 dumpUsedSet(FP);
1453
1455 if (LocalChanged)
1459 }
1460
1461 return Changed;
1462}
1463
1465 bool Changed = false;
1466
1467 for (Function &F : M)
1469
1470 return Changed;
1471}
1472
1474 bool Changed = false;
1475
1476 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1478
1479 return Changed;
1480}
1481
1483 bool Changed = false;
1484
1485 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
1487
1488 return Changed;
1489}
1490
1491//===----------------------------------------------------------------------===//
1492// MPPassManager implementation
1493
1494/// Execute all of the passes scheduled for execution by invoking
1495/// runOnModule method. Keep track of whether any of the passes modifies
1496/// the module, and if so, return true.
1497bool
1498MPPassManager::runOnModule(Module &M) {
1499 llvm::TimeTraceScope TimeScope("OptModule", M.getName());
1500
1501 bool Changed = false;
1502
1503 // Initialize on-the-fly passes
1504 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1505 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
1506 Changed |= FPP->doInitialization(M);
1507 }
1508
1509 // Initialize module passes
1510 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1511 Changed |= getContainedPass(Index)->doInitialization(M);
1512
1513 unsigned InstrCount;
1514 StringMap<std::pair<unsigned, unsigned>> FunctionToInstrCount;
1515 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
1516 // Collect the initial size of the module.
1517 if (EmitICRemark)
1518 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1519
1520 SmallString<0> BeforeStr, AfterStr;
1521 auto PrintIR = [&M](raw_ostream &OS) {
1522 if (isSourceLocFilterEmpty()) {
1523 M.print(OS, /*AAW=*/nullptr);
1524 return true;
1525 }
1526
1527 bool Printed = false;
1528 for (const Function &F : M) {
1529 if (!shouldPrintFunction(F))
1530 continue;
1531 F.print(OS);
1532 Printed = true;
1533 }
1534 return Printed;
1535 };
1536
1537 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1538 ModulePass *MP = getContainedPass(Index);
1539 bool LocalChanged = false;
1540
1541 dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier());
1542 dumpRequiredSet(MP);
1543
1544 initializeAnalysisImpl(MP);
1545
1546 // As in FPPassManager, but for module passes. A function-name filter by
1547 // itself does not filter module passes.
1548 StringRef PassID;
1549 bool ReportChanged = PrintChanged != ChangePrinter::None;
1550 bool IsInteresting = false, ShouldPrintChanged = false;
1551 if (ReportChanged) {
1552 const PassInfo *PI = Pass::lookupPassInfo(MP->getPassID());
1553 if (PI && !PI->isAnalysis()) {
1554 PassID = PI->getPassArgument();
1555 IsInteresting = isPassInPrintList(PassID);
1556 } else {
1557 ReportChanged = false;
1558 }
1559 }
1560 if (IsInteresting) {
1561 BeforeStr.clear();
1562 AfterStr.clear();
1563 raw_svector_ostream OS(BeforeStr);
1564 ShouldPrintChanged = PrintIR(OS);
1565 }
1566
1567 {
1569 TimeRegion PassTimer(getPassTimer(MP));
1570
1571#ifdef EXPENSIVE_CHECKS
1572 uint64_t RefHash = MP->structuralHash(M);
1573#endif
1574
1575 LocalChanged |= MP->runOnModule(M);
1576
1577#ifdef EXPENSIVE_CHECKS
1578 assert((LocalChanged || (RefHash == MP->structuralHash(M))) &&
1579 "Pass modifies its input and doesn't report it.");
1580#endif
1581
1582 if (EmitICRemark) {
1583 // Update the size of the module.
1584 unsigned ModuleCount = M.getInstructionCount();
1585 if (ModuleCount != InstrCount) {
1586 int64_t Delta = static_cast<int64_t>(ModuleCount) -
1587 static_cast<int64_t>(InstrCount);
1588 emitInstrCountChangedRemark(MP, M, Delta, InstrCount,
1589 FunctionToInstrCount);
1590 InstrCount = ModuleCount;
1591 }
1592 }
1593 }
1594
1595 if (IsInteresting) {
1596 raw_svector_ostream OS(AfterStr);
1597 ShouldPrintChanged |= PrintIR(OS);
1598 }
1599 if (ReportChanged)
1600 reportChangedIR(BeforeStr, AfterStr, MP->getPassName(), PassID,
1601 M.getModuleIdentifier(), IsInteresting,
1602 ShouldPrintChanged);
1603
1604 Changed |= LocalChanged;
1605 if (LocalChanged)
1606 dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
1607 M.getModuleIdentifier());
1608 dumpPreservedSet(MP);
1609 dumpUsedSet(MP);
1610
1611 verifyPreservedAnalysis(MP);
1612 if (LocalChanged)
1613 removeNotPreservedAnalysis(MP);
1614 recordAvailableAnalysis(MP);
1615 removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
1616 }
1617
1618 // Finalize module passes
1619 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
1620 Changed |= getContainedPass(Index)->doFinalization(M);
1621
1622 // Finalize on-the-fly passes
1623 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1624 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
1625 // We don't know when is the last time an on-the-fly pass is run,
1626 // so we need to releaseMemory / finalize here
1627 FPP->releaseMemoryOnTheFly();
1628 Changed |= FPP->doFinalization(M);
1629 }
1630
1631 return Changed;
1632}
1633
1634/// Add RequiredPass into list of lower level passes required by pass P.
1635/// RequiredPass is run on the fly by Pass Manager when P requests it
1636/// through getAnalysis interface.
1637void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1638 assert(RequiredPass && "No required pass?");
1639 assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
1640 "Unable to handle Pass that requires lower level Analysis pass");
1641 assert((P->getPotentialPassManagerType() <
1642 RequiredPass->getPotentialPassManagerType()) &&
1643 "Unable to handle Pass that requires lower level Analysis pass");
1644
1645 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
1646 if (!FPP) {
1648 // FPP is the top level manager.
1649 FPP->setTopLevelManager(FPP);
1650
1651 OnTheFlyManagers[P] = FPP;
1652 }
1653 const PassInfo *RequiredPassPI =
1654 TPM->findAnalysisPassInfo(RequiredPass->getPassID());
1655
1656 Pass *FoundPass = nullptr;
1657 if (RequiredPassPI && RequiredPassPI->isAnalysis()) {
1658 FoundPass =
1659 ((PMTopLevelManager*)FPP)->findAnalysisPass(RequiredPass->getPassID());
1660 }
1661 if (!FoundPass) {
1662 FoundPass = RequiredPass;
1663 // This should be guaranteed to add RequiredPass to the passmanager given
1664 // that we checked for an available analysis above.
1665 FPP->add(RequiredPass);
1666 }
1667 // Register P as the last user of FoundPass or RequiredPass.
1669 LU.push_back(FoundPass);
1670 FPP->setLastUser(LU, P);
1671}
1672
1673/// Return function pass corresponding to PassInfo PI, that is
1674/// required by module pass MP. Instantiate analysis pass, by using
1675/// its runOnFunction() for function F.
1676std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI,
1677 Function &F) {
1678 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
1679 assert(FPP && "Unable to find on the fly pass");
1680
1681 FPP->releaseMemoryOnTheFly();
1682 bool Changed = FPP->run(F);
1683 return std::make_tuple(((PMTopLevelManager *)FPP)->findAnalysisPass(PI),
1684 Changed);
1685}
1686
1687namespace llvm {
1688namespace legacy {
1689
1690//===----------------------------------------------------------------------===//
1691// PassManager implementation
1692
1693/// Create new pass manager
1695 PM = new PassManagerImpl();
1696 // PM is the top level manager
1697 PM->setTopLevelManager(PM);
1698}
1699
1701 delete PM;
1702}
1703
1705 PM->add(P);
1706}
1707
1708/// run - Execute all of the passes scheduled for execution. Keep track of
1709/// whether any of the passes modifies the module, and if so, return true.
1711 return PM->run(M);
1712}
1713} // namespace legacy
1714} // namespace llvm
1715
1716//===----------------------------------------------------------------------===//
1717// PMStack implementation
1718//
1719
1720// Pop Pass Manager from the stack and clear its analysis info.
1722
1723 PMDataManager *Top = this->top();
1725
1726 S.pop_back();
1727}
1728
1729// Push PM on the stack and set its top level manager.
1731 assert(PM && "Unable to push. Pass Manager expected");
1732 assert(PM->getDepth()==0 && "Pass Manager depth set too early");
1733
1734 if (!this->empty()) {
1735 assert(PM->getPassManagerType() > this->top()->getPassManagerType()
1736 && "pushing bad pass manager to PMStack");
1737 PMTopLevelManager *TPM = this->top()->getTopLevelManager();
1738
1739 assert(TPM && "Unable to find top level manager");
1740 TPM->addIndirectPassManager(PM);
1741 PM->setTopLevelManager(TPM);
1742 PM->setDepth(this->top()->getDepth()+1);
1743 } else {
1746 && "pushing bad pass manager to PMStack");
1747 PM->setDepth(1);
1748 }
1749
1750 S.push_back(PM);
1751}
1752
1753// Dump content of the pass manager stack.
1755 for (PMDataManager *Manager : S)
1756 dbgs() << Manager->getAsPass()->getPassName() << ' ';
1757
1758 if (!S.empty())
1759 dbgs() << '\n';
1760}
1761
1762/// Find appropriate Module Pass Manager in the PM Stack and
1763/// add self into that manager.
1765 PassManagerType PreferredType) {
1766 // Find Module Pass Manager
1768 while ((T = PMS.top()->getPassManagerType()) > PMT_ModulePassManager &&
1769 T != PreferredType)
1770 PMS.pop();
1771 PMS.top()->add(this);
1772}
1773
1774/// Find appropriate Function Pass Manager or Call Graph Pass Manager
1775/// in the PM Stack and add self into that manager.
1777 PassManagerType /*PreferredType*/) {
1778 // Find Function Pass Manager
1779 PMDataManager *PM;
1780 while (PM = PMS.top(), PM->getPassManagerType() > PMT_FunctionPassManager)
1781 PMS.pop();
1782
1783 // Create new Function Pass Manager if needed.
1785 // [1] Create new Function Pass Manager
1786 auto *FPP = new FPPassManager;
1787 FPP->populateInheritedAnalysis(PMS);
1788
1789 // [2] Set up new manager's top level manager
1791
1792 // [3] Assign manager to manage this new manager. This may create
1793 // and push new managers into PMS
1794 FPP->assignPassManager(PMS, PM->getPassManagerType());
1795
1796 // [4] Push new manager into PMS
1797 PMS.push(FPP);
1798 PM = FPP;
1799 }
1800
1801 // Assign FPP as the manager of this pass.
1802 PM->add(this);
1803}
1804
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
constexpr LLT S1
AMDGPU Lower Kernel Arguments
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
#define clEnumVal(ENUMVAL, DESC)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:682
static unsigned InstrCount
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
This file contains an interface for creating legacy passes to print out IR in various granularities.
Module.h This file contains the declarations for the Module class.
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:54
#define I(x, y, z)
Definition MD5.cpp:57
print mir2vec MIR2Vec Vocabulary Printer Pass
Definition MIR2Vec.cpp:629
This file implements a map that provides insertion order iteration.
#define T
#define P(N)
This header defines classes/functions to handle pass execution timing information with interfaces for...
const char * Msg
This file defines the SmallString class.
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).
LLVM_ABI 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
SmallVectorImpl< AnalysisID > VectorType
const VectorType & getUsedSet() const
bool getPreservesAll() const
Determine whether a pass said it does not transform its input at all.
const VectorType & getPreservedSet() const
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Base class for error info classes.
Definition Error.h:44
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.
Insertion token: a failed lookup fills it in, the matching insert consumes it.
Definition FoldingSet.h:284
This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:162
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
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:844
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition Pass.h:283
typename VectorType::const_iterator const_iterator
Definition MapVector.h:45
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:253
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:68
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!
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.
LLVM_ABI void pop()
PMDataManager * top() const
LLVM_ABI void dump() const
LLVM_ABI 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:29
bool isAnalysis() const
Definition PassInfo.h:67
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to 'opt' that will cause this pas...
Definition PassInfo.h:58
StringRef getPassName() const
getPassName - Return the friendly name for the pass, never returns null
Definition PassInfo.h:53
Pass * createPass() const
createPass() - Use this method to create an instance of this pass.
Definition PassInfo.h:84
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.
PreservedAnalyses run(Function &IR, AnalysisManager< Function > &AM, ExtraArgTs... ExtraArgs)
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM_ABI 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:97
virtual PassManagerType getPotentialPassManagerType() const
Return what kind of Pass Manager can manage this pass.
Definition Pass.cpp:109
Pass(PassKind K, char &pid)
Definition Pass.h:103
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
Definition Pass.h:120
virtual void assignPassManager(PMStack &, PassManagerType)
Each pass is responsible for assigning a pass manager to itself.
Definition Pass.h:149
AnalysisResolver * getResolver() const
Definition Pass.h:160
static const PassInfo * lookupPassInfo(const void *TI)
Definition Pass.cpp:216
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition Pass.h:126
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition Pass.h:130
virtual void dumpPassStructure(unsigned Offset=0)
Definition Pass.cpp:80
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition Pass.cpp:87
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:118
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
Definition Timer.h:155
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
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:53
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an SmallVector or SmallString.
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
LLVM_ABI bool debugPassSpecified()
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1748
@ PT_PassManager
Definition Pass.h:71
LLVM_ABI void reportChangedIR(StringRef Before, StringRef After, StringRef PassName, StringRef PassID, StringRef IRName, bool IsInteresting, bool ShouldReport)
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:1013
PassManagerType
Different types of internal pass managers.
Definition Pass.h:56
@ PMT_ModulePassManager
MPPassManager.
Definition Pass.h:58
@ PMT_FunctionPassManager
FPPassManager.
Definition Pass.h:60
LLVM_ABI cl::opt< ChangePrinter > PrintChanged
LLVM_ABI Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI bool isPassInPrintList(StringRef PassName)
LLVM_ABI bool isSourceLocFilterEmpty()
LLVM_ABI bool shouldPrintFunction(const Function &F)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI 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.
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:1788
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
LLVM_ABI bool shouldPrintBeforePass(StringRef PassID)
LLVM_ABI bool shouldPrintAfterPass(StringRef PassID)
@ Disabled
Don't do any conversion of .debug_str_offsets tables.
Definition DWP.h:30
LLVM_ABI 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.
const void * AnalysisID
Definition Pass.h:51
#define N
Used in the streaming interface as the general argument type.