Lines Matching +full:pass +full:- +full:1
1 //===- LegacyPassManager.cpp - LLVM Pass Infrastructure Implementation ----===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the legacy LLVM Pass Manager infrastructure.
11 //===----------------------------------------------------------------------===//
35 // See PassManagers.h for Pass Manager infrastructure overview.
37 //===----------------------------------------------------------------------===//
38 // Pass debugging information. Often it is useful to find out what pass is
40 // debugging on, a command line option (--debug-pass) is enabled that causes the
41 // pass name to be printed before it executes.
52 "debug-pass", cl::Hidden,
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")));
60 /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
68 // Only calculate getInstructionCount if the size-info remark is requested. in initSizeRemarkInfo()
72 // per-function size remarks later. in initSizeRemarkInfo()
78 // member to 0; if the function is deleted by the pass, then when we get in initSizeRemarkInfo()
89 Pass *P, Module &M, int64_t Delta, unsigned CountBefore, in emitInstrCountChangedRemark()
92 // If it's a pass manager, don't emit a remark. (This hinges on the assumption in emitInstrCountChangedRemark()
93 // that the only passes that return non-null with getAsPMDataManager are pass in emitInstrCountChangedRemark()
96 if (P->getAsPMDataManager()) in emitInstrCountChangedRemark()
99 // Set to true if this isn't a module pass or CGSCC pass. in emitInstrCountChangedRemark()
118 It->second.second = FnSize; in emitInstrCountChangedRemark()
122 // If no function was passed in, then we're either a module pass or an in emitInstrCountChangedRemark()
123 // CGSCC pass. in emitInstrCountChangedRemark()
145 BasicBlock &BB = *F->begin(); in emitInstrCountChangedRemark()
146 OptimizationRemarkAnalysis R("size-info", "IRSizeChange", in emitInstrCountChangedRemark()
150 R << DiagnosticInfoOptimizationBase::Argument("Pass", P->getPassName()) in emitInstrCountChangedRemark()
157 F->getContext().diagnose(R); // Not using ORE for layering reasons. in emitInstrCountChangedRemark()
159 // Emit per-function size change remarks separately. in emitInstrCountChangedRemark()
160 std::string PassName = P->getPassName().str(); in emitInstrCountChangedRemark()
168 int64_t FnDelta = static_cast<int64_t>(FnCountAfter) - in emitInstrCountChangedRemark()
178 // whole-module size change remarks really ought not to have source in emitInstrCountChangedRemark()
180 OptimizationRemarkAnalysis FR("size-info", "FunctionIRSizeChange", in emitInstrCountChangedRemark()
182 FR << DiagnosticInfoOptimizationBase::Argument("Pass", PassName) in emitInstrCountChangedRemark()
193 F->getContext().diagnose(FR); in emitInstrCountChangedRemark()
206 EmitFunctionSizeChangedRemark(F->getName().str()); in emitInstrCountChangedRemark()
211 OS << "Releasing pass '"; in print()
213 OS << "Running pass '"; in print()
215 OS << P->getPassName() << "'"; in print()
218 OS << " on module '" << M->getModuleIdentifier() << "'.\n"; in print()
235 V->printAsOperand(OS, /*PrintType=*/false, M); in print()
243 //===----------------------------------------------------------------------===//
247 class FunctionPassManagerImpl : public Pass,
256 : Pass(PT_PassManager, ID), PMTopLevelManager(new FPPassManager()), in FunctionPassManagerImpl()
260 void add(Pass *P) { in add()
264 /// createPrinterPass - Get a function printer pass.
265 Pass *createPrinterPass(raw_ostream &O, in createPrinterPass()
270 // Prepare for running an on the fly pass, freeing memory if needed
274 /// run - Execute all of the passes scheduled for execution. Keep track of
278 /// doInitialization - Run all of the initializers for the function passes.
282 /// doFinalization - Run all of the finalizers for the function passes.
288 Pass *getAsPass() override { return this; } in getAsPass()
293 /// Pass Manager itself does not invalidate any analysis info.
299 assert(N < PassManagers.size() && "Pass number out of range!"); in getContainedManager()
306 getContainedManager(I)->dumpPassStructure(Offset); in dumpPassStructure()
314 //===----------------------------------------------------------------------===//
324 Changed |= ImPass->doInitialization(M); in doInitialization()
327 Changed |= getContainedManager(Index)->doInitialization(M); in doInitialization()
335 for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index) in doFinalization()
336 Changed |= getContainedManager(Index)->doFinalization(M); in doFinalization()
339 Changed |= ImPass->doFinalization(M); in doFinalization()
349 for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) { in releaseMemoryOnTheFly()
350 FPPM->getContainedPass(Index)->releaseMemory(); in releaseMemoryOnTheFly()
357 // Return true if any function is modified by a pass.
363 Changed |= getContainedManager(Index)->runOnFunction(F); in run()
368 getContainedManager(Index)->cleanup(); in run()
377 //===----------------------------------------------------------------------===//
380 /// MPPassManager manages ModulePasses and function pass managers.
381 /// It batches all Module passes and function pass managers together and
383 class MPPassManager : public Pass, public PMDataManager {
386 explicit MPPassManager() : Pass(PT_PassManager, ID) {} in MPPassManager()
396 /// createPrinterPass - Get a module printer pass.
397 Pass *createPrinterPass(raw_ostream &O, in createPrinterPass()
402 /// run - Execute all of the passes scheduled for execution. Keep track of
406 using llvm::Pass::doInitialization;
407 using llvm::Pass::doFinalization;
409 /// Pass Manager itself does not invalidate any analysis info.
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
417 void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) override;
419 /// Return function pass corresponding to PassInfo PI, that is
420 /// required by module pass MP. Instantiate analysis pass, by using
422 std::tuple<Pass *, bool> getOnTheFlyPass(Pass *MP, AnalysisID PI,
425 StringRef getPassName() const override { return "Module Pass Manager"; } in getPassName()
428 Pass *getAsPass() override { return this; } in getAsPass()
435 MP->dumpPassStructure(Offset + 1); in dumpPassStructure()
436 MapVector<Pass *, legacy::FunctionPassManagerImpl *>::const_iterator I = in dumpPassStructure()
439 I->second->dumpPassStructure(Offset + 2); in dumpPassStructure()
440 dumpLastUses(MP, Offset+1); in dumpPassStructure()
445 assert(N < PassVector.size() && "Pass number out of range!"); in getContainedPass()
456 MapVector<Pass *, legacy::FunctionPassManagerImpl *> OnTheFlyManagers;
464 //===----------------------------------------------------------------------===//
469 class PassManagerImpl : public Pass,
477 : Pass(PT_PassManager, ID), PMTopLevelManager(new MPPassManager()) {} in PassManagerImpl()
480 void add(Pass *P) { in add()
484 /// createPrinterPass - Get a module printer pass.
485 Pass *createPrinterPass(raw_ostream &O, in createPrinterPass()
490 /// run - Execute all of the passes scheduled for execution. Keep track of
494 using llvm::Pass::doInitialization;
495 using llvm::Pass::doFinalization;
497 /// Pass Manager itself does not invalidate any analysis info.
503 Pass *getAsPass() override { return this; } in getAsPass()
509 assert(N < PassManagers.size() && "Pass number out of range!"); in getContainedManager()
519 //===----------------------------------------------------------------------===//
523 /// run - Execute all of the passes scheduled for execution. Keep track of
532 // DbgVariableRecord representation of debug-info for the duration of these in run()
537 Changed |= ImPass->doInitialization(M); in run()
541 Changed |= getContainedManager(Index)->runOnModule(M); in run()
546 Changed |= ImPass->doFinalization(M); in run()
553 //===----------------------------------------------------------------------===//
556 /// Initialize top level manager. Create first pass manager.
558 PMDM->setTopLevelManager(this); in PMTopLevelManager()
563 /// Set pass P as the last user of the given analysis passes.
565 PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) { in setLastUser()
567 if (P->getResolver()) in setLastUser()
568 PDepth = P->getResolver()->getPMDataManager().getDepth(); in setLastUser()
570 for (Pass *AP : AnalysisPasses) { in setLastUser()
583 const AnalysisUsage::VectorType &IDs = AnUsage->getRequiredTransitiveSet(); in setLastUser()
584 SmallVector<Pass *, 12> LastUses; in setLastUser()
585 SmallVector<Pass *, 12> LastPMUses; in setLastUser()
587 Pass *AnalysisPass = findAnalysisPass(ID); in setLastUser()
588 assert(AnalysisPass && "Expected analysis pass to exist."); in setLastUser()
589 AnalysisResolver *AR = AnalysisPass->getResolver(); in setLastUser()
591 unsigned APDepth = AR->getPMDataManager().getDepth(); in setLastUser()
601 // If this pass has a corresponding pass manager, push higher level in setLastUser()
602 // analysis to this pass manager. in setLastUser()
603 if (P->getResolver()) in setLastUser()
604 setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass()); in setLastUser()
609 for (Pass *L : LastUsedByAP) in setLastUser()
617 void PMTopLevelManager::collectLastUses(SmallVectorImpl<Pass *> &LastUses, in collectLastUses()
618 Pass *P) { in collectLastUses()
623 auto &LU = DMI->second; in collectLastUses()
627 AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) { in findAnalysisUsage()
631 AnUsage = DMI->second; in findAnalysisUsage()
633 // Look up the analysis usage from the pass instance (different instances in findAnalysisUsage()
634 // of the same pass can produce different results), but unique the in findAnalysisUsage()
636 // memory usage when we have many instances of only a few pass types in findAnalysisUsage()
640 P->getAnalysisUsage(AU); in findAnalysisUsage()
654 AnUsageMap[P] = &Node->AU; in findAnalysisUsage()
655 AnUsage = &Node->AU; in findAnalysisUsage()
660 /// Schedule pass P for execution. Make sure that passes required by
663 void PMTopLevelManager::schedulePass(Pass *P) { in schedulePass()
665 // TODO : Allocate function manager for this pass, other wise required set in schedulePass()
668 // Give pass a chance to prepare the stage. in schedulePass()
669 P->preparePassManager(activeStack); in schedulePass()
671 // If P is an analysis pass and it is available then do not in schedulePass()
674 const PassInfo *PI = findAnalysisPassInfo(P->getPassID()); in schedulePass()
675 if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) { in schedulePass()
688 const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet(); in schedulePass()
691 Pass *AnalysisPass = findAnalysisPass(ID); in schedulePass()
696 // Pass P is not in the global PassRegistry in schedulePass()
697 dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n"; in schedulePass()
698 dbgs() << "Verify if there is a pass dependency cycle." << "\n"; in schedulePass()
703 Pass *AnalysisPass2 = findAnalysisPass(ID2); in schedulePass()
705 dbgs() << "\t" << AnalysisPass2->getPassName() << "\n"; in schedulePass()
707 dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n"; in schedulePass()
708 dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n"; in schedulePass()
709 dbgs() << "\t\t" << "- Corruption of the global PassRegistry" << "\n"; in schedulePass()
715 AnalysisPass = PI->createPass(); in schedulePass()
716 if (P->getPotentialPassManagerType () == in schedulePass()
717 AnalysisPass->getPotentialPassManagerType()) in schedulePass()
718 // Schedule analysis pass that is managed by the same pass manager. in schedulePass()
720 else if (P->getPotentialPassManagerType () > in schedulePass()
721 AnalysisPass->getPotentialPassManagerType()) { in schedulePass()
722 // Schedule analysis pass that is managed by a new manager. in schedulePass()
736 if (ImmutablePass *IP = P->getAsImmutablePass()) { in schedulePass()
737 // P is a immutable pass and it will be managed by this in schedulePass()
741 P->setResolver(AR); in schedulePass()
742 DM->initializeAnalysisImpl(P); in schedulePass()
744 DM->recordAvailableAnalysis(IP); in schedulePass()
748 if (PI && !PI->isAnalysis() && shouldPrintBeforePass(PI->getPassArgument())) { in schedulePass()
749 Pass *PP = in schedulePass()
750 P->createPrinterPass(dbgs(), ("*** IR Dump Before " + P->getPassName() + in schedulePass()
751 " (" + PI->getPassArgument() + ") ***") in schedulePass()
753 PP->assignPassManager(activeStack, getTopLevelPassManagerType()); in schedulePass()
756 // Add the requested pass to the best available pass manager. in schedulePass()
757 P->assignPassManager(activeStack, getTopLevelPassManagerType()); in schedulePass()
759 if (PI && !PI->isAnalysis() && shouldPrintAfterPass(PI->getPassArgument())) { in schedulePass()
760 Pass *PP = in schedulePass()
761 P->createPrinterPass(dbgs(), ("*** IR Dump After " + P->getPassName() + in schedulePass()
762 " (" + PI->getPassArgument() + ") ***") in schedulePass()
764 PP->assignPassManager(activeStack, getTopLevelPassManagerType()); in schedulePass()
768 /// Find the pass that implements Analysis AID. Search immutable
769 /// passes and all pass managers. If desired pass is not found
771 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) { in findAnalysisPass()
772 // For immutable passes we have a direct mapping from ID to pass, so check in findAnalysisPass()
774 if (Pass *P = ImmutablePassMap.lookup(AID)) in findAnalysisPass()
777 // Check pass managers in findAnalysisPass()
779 if (Pass *P = PassManager->findAnalysisPass(AID, false)) in findAnalysisPass()
782 // Check other pass managers in findAnalysisPass()
784 if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false)) in findAnalysisPass()
793 PI = PassRegistry::getPassRegistry()->getPassInfo(AID); in findAnalysisPassInfo()
795 assert(PI == PassRegistry::getPassRegistry()->getPassInfo(AID) && in findAnalysisPassInfo()
796 "The pass info pointer changed for an analysis ID!"); in findAnalysisPassInfo()
802 P->initializePass(); in addImmutablePass()
805 // Add this pass to the map from its analysis ID. We clobber any prior runs in addImmutablePass()
806 // of the pass in the map so that the last one added is the one found when in addImmutablePass()
808 AnalysisID AID = P->getPassID(); in addImmutablePass()
811 // Also add any interfaces implemented by the immutable pass to the map for in addImmutablePass()
815 for (const PassInfo *ImmPI : PassInf->getInterfacesImplemented()) in addImmutablePass()
816 ImmutablePassMap[ImmPI->getTypeInfo()] = P; in addImmutablePass()
826 for (ImmutablePass *Pass : ImmutablePasses) in dumpPasses()
827 Pass->dumpPassStructure(0); in dumpPasses()
829 // Every class that derives from PMDataManager also derives from Pass in dumpPasses()
831 // between PMDataManager and Pass, so we have to getAsPass to get in dumpPasses()
832 // from a PMDataManager* to a Pass*. in dumpPasses()
834 Manager->getAsPass()->dumpPassStructure(1); in dumpPasses()
842 dbgs() << "Pass Arguments: "; in dumpArguments()
844 if (const PassInfo *PI = findAnalysisPassInfo(P->getPassID())) { in dumpArguments()
846 if (!PI->isAnalysisGroup()) in dumpArguments()
847 dbgs() << " -" << PI->getPassArgument(); in dumpArguments()
850 PM->dumpPassArguments(); in dumpArguments()
856 PM->initializeAnalysisInfo(); in initializeAllAnalysisInfo()
858 // Initailize other pass managers in initializeAllAnalysisInfo()
860 IPM->initializeAnalysisInfo(); in initializeAllAnalysisInfo()
872 //===----------------------------------------------------------------------===//
875 /// Augement AvailableAnalysis by adding analysis made available by pass P.
876 void PMDataManager::recordAvailableAnalysis(Pass *P) { in recordAvailableAnalysis()
877 AnalysisID PI = P->getPassID(); in recordAvailableAnalysis()
883 // This pass is the current implementation of all of the interfaces it in recordAvailableAnalysis()
885 const PassInfo *PInf = TPM->findAnalysisPassInfo(PI); in recordAvailableAnalysis()
887 for (const PassInfo *PI : PInf->getInterfacesImplemented()) in recordAvailableAnalysis()
888 AvailableAnalysis[PI->getTypeInfo()] = P; in recordAvailableAnalysis()
893 bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) { in preserveHigherLevelAnalysis()
894 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P); in preserveHigherLevelAnalysis()
895 if (AnUsage->getPreservesAll()) in preserveHigherLevelAnalysis()
898 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet(); in preserveHigherLevelAnalysis()
899 for (Pass *P1 : HigherLevelAnalysis) { in preserveHigherLevelAnalysis()
900 if (P1->getAsImmutablePass() == nullptr && in preserveHigherLevelAnalysis()
901 !is_contained(PreservedSet, P1->getPassID())) in preserveHigherLevelAnalysis()
908 /// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
909 void PMDataManager::verifyPreservedAnalysis(Pass *P) { in verifyPreservedAnalysis()
914 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P); in verifyPreservedAnalysis()
915 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet(); in verifyPreservedAnalysis()
919 if (Pass *AP = findAnalysisPass(AID, true)) { in verifyPreservedAnalysis()
921 AP->verifyAnalysis(); in verifyPreservedAnalysis()
926 /// Remove Analysis not preserved by Pass P
927 void PMDataManager::removeNotPreservedAnalysis(Pass *P) { in removeNotPreservedAnalysis()
928 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P); in removeNotPreservedAnalysis()
929 if (AnUsage->getPreservesAll()) in removeNotPreservedAnalysis()
932 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet(); in removeNotPreservedAnalysis()
933 for (DenseMap<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(), in removeNotPreservedAnalysis()
935 DenseMap<AnalysisID, Pass*>::iterator Info = I++; in removeNotPreservedAnalysis()
936 if (Info->second->getAsImmutablePass() == nullptr && in removeNotPreservedAnalysis()
937 !is_contained(PreservedSet, Info->first)) { in removeNotPreservedAnalysis()
940 Pass *S = Info->second; in removeNotPreservedAnalysis()
941 dbgs() << " -- '" << P->getPassName() << "' is not preserving '"; in removeNotPreservedAnalysis()
942 dbgs() << S->getPassName() << "'\n"; in removeNotPreservedAnalysis()
950 for (DenseMap<AnalysisID, Pass *> *IA : InheritedAnalysis) { in removeNotPreservedAnalysis()
954 for (DenseMap<AnalysisID, Pass *>::iterator I = IA->begin(), in removeNotPreservedAnalysis()
955 E = IA->end(); in removeNotPreservedAnalysis()
957 DenseMap<AnalysisID, Pass *>::iterator Info = I++; in removeNotPreservedAnalysis()
958 if (Info->second->getAsImmutablePass() == nullptr && in removeNotPreservedAnalysis()
959 !is_contained(PreservedSet, Info->first)) { in removeNotPreservedAnalysis()
962 Pass *S = Info->second; in removeNotPreservedAnalysis()
963 dbgs() << " -- '" << P->getPassName() << "' is not preserving '"; in removeNotPreservedAnalysis()
964 dbgs() << S->getPassName() << "'\n"; in removeNotPreservedAnalysis()
966 IA->erase(Info); in removeNotPreservedAnalysis()
973 void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg, in removeDeadPasses()
976 SmallVector<Pass *, 12> DeadPasses; in removeDeadPasses()
982 TPM->collectLastUses(DeadPasses, P); in removeDeadPasses()
985 dbgs() << " -*- '" << P->getPassName(); in removeDeadPasses()
986 dbgs() << "' is the last user of following pass instances."; in removeDeadPasses()
990 for (Pass *P : DeadPasses) in removeDeadPasses()
994 void PMDataManager::freePass(Pass *P, StringRef Msg, in freePass()
999 // If the pass crashes releasing memory, remember this. in freePass()
1003 P->releaseMemory(); in freePass()
1006 AnalysisID PI = P->getPassID(); in freePass()
1007 if (const PassInfo *PInf = TPM->findAnalysisPassInfo(PI)) { in freePass()
1008 // Remove the pass itself (if it is not already removed). in freePass()
1011 // Remove all interfaces this pass implements, for which it is also in freePass()
1013 for (const PassInfo *PI : PInf->getInterfacesImplemented()) { in freePass()
1014 DenseMap<AnalysisID, Pass *>::iterator Pos = in freePass()
1015 AvailableAnalysis.find(PI->getTypeInfo()); in freePass()
1016 if (Pos != AvailableAnalysis.end() && Pos->second == P) in freePass()
1022 /// Add pass P into the PassVector. Update
1024 void PMDataManager::add(Pass *P, bool ProcessAnalysis) { in add()
1025 // This manager is going to manage pass P. Set up analysis resolver in add()
1028 P->setResolver(AR); in add()
1032 SmallVector<Pass *, 12> TransferLastUses; in add()
1035 // Add pass in add()
1040 // At the moment, this pass is the last user of all required passes. in add()
1041 SmallVector<Pass *, 12> LastUses; in add()
1042 SmallVector<Pass *, 8> UsedPasses; in add()
1045 unsigned PDepth = this->getDepth(); in add()
1048 for (Pass *PUsed : UsedPasses) { in add()
1051 assert(PUsed->getResolver() && "Analysis Resolver is not set"); in add()
1052 PMDataManager &DM = PUsed->getResolver()->getPMDataManager(); in add()
1063 llvm_unreachable("Unable to accommodate Used Pass"); in add()
1067 // However, if P is a Pass Manager then it does not need in add()
1069 if (!P->getAsPMDataManager()) in add()
1071 TPM->setLastUser(LastUses, P); in add()
1074 Pass *My_PM = getAsPass(); in add()
1075 TPM->setLastUser(TransferLastUses, My_PM); in add()
1081 const PassInfo *PI = TPM->findAnalysisPassInfo(ID); in add()
1082 Pass *AnalysisPass = PI->createPass(); in add()
1083 this->addLowerLevelRequiredPass(P, AnalysisPass); in add()
1086 // Take a note of analysis required and made available by this pass. in add()
1087 // Remove the analysis not preserved by this pass in add()
1091 // Add pass in add()
1096 /// Populate UP with analysis pass that are used or required by
1097 /// pass P and are available. Populate RP_NotAvail with analysis
1098 /// pass that are required by pass P but are not available.
1100 SmallVectorImpl<Pass *> &UP, SmallVectorImpl<AnalysisID> &RP_NotAvail, in collectRequiredAndUsedAnalyses()
1101 Pass *P) { in collectRequiredAndUsedAnalyses()
1102 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P); in collectRequiredAndUsedAnalyses()
1104 for (const auto &UsedID : AnUsage->getUsedSet()) in collectRequiredAndUsedAnalyses()
1105 if (Pass *AnalysisPass = findAnalysisPass(UsedID, true)) in collectRequiredAndUsedAnalyses()
1108 for (const auto &RequiredID : AnUsage->getRequiredSet()) in collectRequiredAndUsedAnalyses()
1109 if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true)) in collectRequiredAndUsedAnalyses()
1115 // All Required analyses should be available to the pass as it runs! Here
1116 // we fill in the AnalysisImpls member of the pass so that it can
1120 void PMDataManager::initializeAnalysisImpl(Pass *P) { in initializeAnalysisImpl()
1121 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P); in initializeAnalysisImpl()
1123 for (const AnalysisID ID : AnUsage->getRequiredSet()) { in initializeAnalysisImpl()
1124 Pass *Impl = findAnalysisPass(ID, true); in initializeAnalysisImpl()
1126 // This may be analysis pass that is initialized on the fly. in initializeAnalysisImpl()
1129 AnalysisResolver *AR = P->getResolver(); in initializeAnalysisImpl()
1131 AR->addAnalysisImplsPair(ID, Impl); in initializeAnalysisImpl()
1135 /// Find the pass that implements Analysis AID. If desired pass is not found
1137 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) { in findAnalysisPass()
1140 DenseMap<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID); in findAnalysisPass()
1143 return I->second; in findAnalysisPass()
1147 return TPM->findAnalysisPass(AID); in findAnalysisPass()
1153 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{ in dumpLastUses()
1157 SmallVector<Pass *, 12> LUses; in dumpLastUses()
1163 TPM->collectLastUses(LUses, P); in dumpLastUses()
1165 for (Pass *P : LUses) { in dumpLastUses()
1166 dbgs() << "--" << std::string(Offset*2, ' '); in dumpLastUses()
1167 P->dumpPassStructure(0); in dumpLastUses()
1172 for (Pass *P : PassVector) { in dumpPassArguments()
1173 if (PMDataManager *PMD = P->getAsPMDataManager()) in dumpPassArguments()
1174 PMD->dumpPassArguments(); in dumpPassArguments()
1177 TPM->findAnalysisPassInfo(P->getPassID())) in dumpPassArguments()
1178 if (!PI->isAnalysisGroup()) in dumpPassArguments()
1179 dbgs() << " -" << PI->getPassArgument(); in dumpPassArguments()
1183 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1, in dumpPassInfo()
1189 << std::string(getDepth() * 2 + 1, ' '); in dumpPassInfo()
1192 dbgs() << "Executing Pass '" << P->getPassName(); in dumpPassInfo()
1195 dbgs() << "Made Modification '" << P->getPassName(); in dumpPassInfo()
1198 dbgs() << " Freeing Pass '" << P->getPassName(); in dumpPassInfo()
1224 void PMDataManager::dumpRequiredSet(const Pass *P) const { in dumpRequiredSet()
1229 P->getAnalysisUsage(analysisUsage); in dumpRequiredSet()
1233 void PMDataManager::dumpPreservedSet(const Pass *P) const { in dumpPreservedSet()
1238 P->getAnalysisUsage(analysisUsage); in dumpPreservedSet()
1242 void PMDataManager::dumpUsedSet(const Pass *P) const { in dumpUsedSet()
1247 P->getAnalysisUsage(analysisUsage); in dumpUsedSet()
1251 void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P, in dumpAnalysisUsage()
1259 const PassInfo *PInf = TPM->findAnalysisPassInfo(Set[i]); in dumpAnalysisUsage()
1263 dbgs() << " Uninitialized Pass"; in dumpAnalysisUsage()
1266 dbgs() << ' ' << PInf->getPassName(); in dumpAnalysisUsage()
1271 /// Add RequiredPass into list of lower level passes required by pass P.
1272 /// RequiredPass is run on the fly by Pass Manager when P requests it
1274 /// This should be handled by specific pass manager.
1275 void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) { in addLowerLevelRequiredPass()
1277 TPM->dumpArguments(); in addLowerLevelRequiredPass()
1278 TPM->dumpPasses(); in addLowerLevelRequiredPass()
1281 // Module Level pass may required Function Level analysis info in addLowerLevelRequiredPass()
1282 // (e.g. dominator info). Pass manager uses on the fly function pass manager in addLowerLevelRequiredPass()
1283 // to provide this on demand. In that case, in Pass manager terminology, in addLowerLevelRequiredPass()
1284 // module level pass is requiring lower level analysis info managed by in addLowerLevelRequiredPass()
1285 // lower level pass manager. in addLowerLevelRequiredPass()
1287 // When Pass manager is not able to order required analysis info, Pass manager in addLowerLevelRequiredPass()
1291 dbgs() << "Unable to schedule '" << RequiredPass->getPassName(); in addLowerLevelRequiredPass()
1292 dbgs() << "' required by '" << P->getPassName() << "'\n"; in addLowerLevelRequiredPass()
1294 llvm_unreachable("Unable to schedule pass"); in addLowerLevelRequiredPass()
1297 std::tuple<Pass *, bool> PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI, in getOnTheFlyPass()
1299 llvm_unreachable("Unable to find on the fly pass"); in getOnTheFlyPass()
1304 for (Pass *P : PassVector) in ~PMDataManager()
1308 //===----------------------------------------------------------------------===//
1310 // getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
1311 Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID) const { in getAnalysisIfAvailable()
1315 std::tuple<Pass *, bool>
1316 AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI, Function &F) { in findImplPass()
1323 //===----------------------------------------------------------------------===//
1326 /// Create new Function pass manager
1330 FPM->setTopLevelManager(FPM); in FunctionPassManager()
1333 FPM->setResolver(AR); in FunctionPassManager()
1340 void FunctionPassManager::add(Pass *P) { in add()
1341 FPM->add(P); in add()
1344 /// run - Execute all of the passes scheduled for execution. Keep
1352 return FPM->run(F); in run()
1356 /// doInitialization - Run all of the initializers for the function passes.
1359 return FPM->doInitialization(*M); in doInitialization()
1362 /// doFinalization - Run all of the finalizers for the function passes.
1365 return FPM->doFinalization(*M); in doFinalization()
1370 /// cleanup - After running all passes, clean up pass manager cache.
1374 AnalysisResolver *AR = FP->getResolver(); in cleanup()
1376 AR->clearAnalysisImpls(); in cleanup()
1381 //===----------------------------------------------------------------------===//
1390 FP->dumpPassStructure(Offset + 1); in dumpPassStructure()
1391 dumpLastUses(FP, Offset+1); in dumpPassStructure()
1404 // Collect inherited analysis from Module level pass manager. in runOnFunction()
1405 populateInheritedAnalysis(TPM->activeStack); in runOnFunction()
1427 "RunPass", [FP]() { return std::string(FP->getPassName()); }); in runOnFunction()
1438 uint64_t RefHash = FP->structuralHash(F); in runOnFunction()
1440 LocalChanged |= FP->runOnFunction(F); in runOnFunction()
1443 if (!LocalChanged && (RefHash != FP->structuralHash(F))) { in runOnFunction()
1444 llvm::errs() << "Pass modifies its input and doesn't report it: " in runOnFunction()
1445 << FP->getPassName() << "\n"; in runOnFunction()
1446 llvm_unreachable("Pass modifies its input and doesn't report it"); in runOnFunction()
1456 int64_t Delta = static_cast<int64_t>(NewSize) - in runOnFunction()
1495 Changed |= getContainedPass(Index)->doInitialization(M); in doInitialization()
1503 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index) in doFinalization()
1504 Changed |= getContainedPass(Index)->doFinalization(M); in doFinalization()
1509 //===----------------------------------------------------------------------===//
1521 // Initialize on-the-fly passes in runOnModule()
1524 Changed |= FPP->doInitialization(M); in runOnModule()
1529 Changed |= getContainedPass(Index)->doInitialization(M); in runOnModule()
1552 uint64_t RefHash = MP->structuralHash(M); in runOnModule()
1555 LocalChanged |= MP->runOnModule(M); in runOnModule()
1558 assert((LocalChanged || (RefHash == MP->structuralHash(M))) && in runOnModule()
1559 "Pass modifies its input and doesn't report it."); in runOnModule()
1566 int64_t Delta = static_cast<int64_t>(ModuleCount) - in runOnModule()
1590 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index) in runOnModule()
1591 Changed |= getContainedPass(Index)->doFinalization(M); in runOnModule()
1593 // Finalize on-the-fly passes in runOnModule()
1596 // We don't know when is the last time an on-the-fly pass is run, in runOnModule()
1598 FPP->releaseMemoryOnTheFly(); in runOnModule()
1599 Changed |= FPP->doFinalization(M); in runOnModule()
1605 /// Add RequiredPass into list of lower level passes required by pass P.
1606 /// RequiredPass is run on the fly by Pass Manager when P requests it
1608 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) { in addLowerLevelRequiredPass()
1609 assert(RequiredPass && "No required pass?"); in addLowerLevelRequiredPass()
1610 assert(P->getPotentialPassManagerType() == PMT_ModulePassManager && in addLowerLevelRequiredPass()
1611 "Unable to handle Pass that requires lower level Analysis pass"); in addLowerLevelRequiredPass()
1612 assert((P->getPotentialPassManagerType() < in addLowerLevelRequiredPass()
1613 RequiredPass->getPotentialPassManagerType()) && in addLowerLevelRequiredPass()
1614 "Unable to handle Pass that requires lower level Analysis pass"); in addLowerLevelRequiredPass()
1620 FPP->setTopLevelManager(FPP); in addLowerLevelRequiredPass()
1625 TPM->findAnalysisPassInfo(RequiredPass->getPassID()); in addLowerLevelRequiredPass()
1627 Pass *FoundPass = nullptr; in addLowerLevelRequiredPass()
1628 if (RequiredPassPI && RequiredPassPI->isAnalysis()) { in addLowerLevelRequiredPass()
1630 ((PMTopLevelManager*)FPP)->findAnalysisPass(RequiredPass->getPassID()); in addLowerLevelRequiredPass()
1636 FPP->add(RequiredPass); in addLowerLevelRequiredPass()
1639 SmallVector<Pass *, 1> LU; in addLowerLevelRequiredPass()
1641 FPP->setLastUser(LU, P); in addLowerLevelRequiredPass()
1644 /// Return function pass corresponding to PassInfo PI, that is
1645 /// required by module pass MP. Instantiate analysis pass, by using
1647 std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI, in getOnTheFlyPass()
1650 assert(FPP && "Unable to find on the fly pass"); in getOnTheFlyPass()
1652 FPP->releaseMemoryOnTheFly(); in getOnTheFlyPass()
1653 bool Changed = FPP->run(F); in getOnTheFlyPass()
1654 return std::make_tuple(((PMTopLevelManager *)FPP)->findAnalysisPass(PI), in getOnTheFlyPass()
1661 //===----------------------------------------------------------------------===//
1664 /// Create new pass manager
1668 PM->setTopLevelManager(PM); in PassManager()
1675 void PassManager::add(Pass *P) { in add()
1676 PM->add(P); in add()
1679 /// run - Execute all of the passes scheduled for execution. Keep track of
1682 return PM->run(M); in run()
1687 //===----------------------------------------------------------------------===//
1691 // Pop Pass Manager from the stack and clear its analysis info.
1694 PMDataManager *Top = this->top(); in pop()
1695 Top->initializeAnalysisInfo(); in pop()
1702 assert(PM && "Unable to push. Pass Manager expected"); in push()
1703 assert(PM->getDepth()==0 && "Pass Manager depth set too early"); in push()
1705 if (!this->empty()) { in push()
1706 assert(PM->getPassManagerType() > this->top()->getPassManagerType() in push()
1707 && "pushing bad pass manager to PMStack"); in push()
1708 PMTopLevelManager *TPM = this->top()->getTopLevelManager(); in push()
1711 TPM->addIndirectPassManager(PM); in push()
1712 PM->setTopLevelManager(TPM); in push()
1713 PM->setDepth(this->top()->getDepth()+1); in push()
1715 assert((PM->getPassManagerType() == PMT_ModulePassManager in push()
1716 || PM->getPassManagerType() == PMT_FunctionPassManager) in push()
1717 && "pushing bad pass manager to PMStack"); in push()
1718 PM->setDepth(1); in push()
1724 // Dump content of the pass manager stack.
1727 dbgs() << Manager->getAsPass()->getPassName() << ' '; in dump()
1733 /// Find appropriate Module Pass Manager in the PM Stack and
1737 // Find Module Pass Manager in assignPassManager()
1739 while ((T = PMS.top()->getPassManagerType()) > PMT_ModulePassManager && in assignPassManager()
1742 PMS.top()->add(this); in assignPassManager()
1745 /// Find appropriate Function Pass Manager or Call Graph Pass Manager
1749 // Find Function Pass Manager in assignPassManager()
1751 while (PM = PMS.top(), PM->getPassManagerType() > PMT_FunctionPassManager) in assignPassManager()
1754 // Create new Function Pass Manager if needed. in assignPassManager()
1755 if (PM->getPassManagerType() != PMT_FunctionPassManager) { in assignPassManager()
1756 // [1] Create new Function Pass Manager in assignPassManager()
1758 FPP->populateInheritedAnalysis(PMS); in assignPassManager()
1761 PM->getTopLevelManager()->addIndirectPassManager(FPP); in assignPassManager()
1765 FPP->assignPassManager(PMS, PM->getPassManagerType()); in assignPassManager()
1772 // Assign FPP as the manager of this pass. in assignPassManager()
1773 PM->add(this); in assignPassManager()