Lines Matching full:pass

1 //===- LegacyPassManager.cpp - LLVM Pass Infrastructure Implementation ----===//
9 // This file implements the legacy LLVM Pass Manager infrastructure.
35 // See PassManagers.h for Pass Manager infrastructure overview.
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
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()
99 // Set to true if this isn't a module pass or CGSCC pass. 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()
150 R << DiagnosticInfoOptimizationBase::Argument("Pass", P->getPassName()) in emitInstrCountChangedRemark()
182 FR << DiagnosticInfoOptimizationBase::Argument("Pass", PassName) in emitInstrCountChangedRemark()
211 OS << "Releasing pass '"; in print()
213 OS << "Running pass '"; in print()
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
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()
357 // Return true if any function is modified by a pass.
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()
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()
436 MapVector<Pass *, legacy::FunctionPassManagerImpl *>::const_iterator I = in dumpPassStructure()
445 assert(N < PassVector.size() && "Pass number out of range!"); in getContainedPass()
456 MapVector<Pass *, legacy::FunctionPassManagerImpl *> OnTheFlyManagers;
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()
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()
556 /// Initialize top level manager. Create first pass manager.
563 /// Set pass P as the last user of the given analysis passes.
565 PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) { in setLastUser()
570 for (Pass *AP : AnalysisPasses) { 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()
601 // If this pass has a corresponding pass manager, push higher level in setLastUser()
602 // analysis to this pass manager. in setLastUser()
609 for (Pass *L : LastUsedByAP) in setLastUser()
617 void PMTopLevelManager::collectLastUses(SmallVectorImpl<Pass *> &LastUses, in collectLastUses()
618 Pass *P) { in collectLastUses()
627 AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) { 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()
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()
671 // If P is an analysis pass and it is available then do not 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()
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()
718 // Schedule analysis pass that is managed by the same pass manager. in schedulePass()
722 // Schedule analysis pass that is managed by a new manager. in schedulePass()
737 // P is a immutable pass and it will be managed by this in schedulePass()
749 Pass *PP = in schedulePass()
756 // Add the requested pass to the best available pass manager. in schedulePass()
760 Pass *PP = 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()
796 "The pass info pointer changed for an analysis ID!"); in findAnalysisPassInfo()
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()
811 // Also add any interfaces implemented by the immutable pass to the map for 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()
842 dbgs() << "Pass Arguments: "; in dumpArguments()
858 // Initailize other pass managers in initializeAllAnalysisInfo()
875 /// Augement AvailableAnalysis by adding analysis made available by pass P.
876 void PMDataManager::recordAvailableAnalysis(Pass *P) { in recordAvailableAnalysis()
883 // This pass is the current implementation of all of the interfaces it in recordAvailableAnalysis()
893 bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) { in preserveHigherLevelAnalysis()
899 for (Pass *P1 : HigherLevelAnalysis) { in preserveHigherLevelAnalysis()
908 /// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
909 void PMDataManager::verifyPreservedAnalysis(Pass *P) { in verifyPreservedAnalysis()
919 if (Pass *AP = findAnalysisPass(AID, true)) { in verifyPreservedAnalysis()
926 /// Remove Analysis not preserved by Pass P
927 void PMDataManager::removeNotPreservedAnalysis(Pass *P) { in removeNotPreservedAnalysis()
933 for (DenseMap<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(), in removeNotPreservedAnalysis()
935 DenseMap<AnalysisID, Pass*>::iterator Info = I++; in removeNotPreservedAnalysis()
940 Pass *S = Info->second; in removeNotPreservedAnalysis()
950 for (DenseMap<AnalysisID, Pass *> *IA : InheritedAnalysis) { in removeNotPreservedAnalysis()
954 for (DenseMap<AnalysisID, Pass *>::iterator I = IA->begin(), in removeNotPreservedAnalysis()
957 DenseMap<AnalysisID, Pass *>::iterator Info = I++; in removeNotPreservedAnalysis()
962 Pass *S = Info->second; in removeNotPreservedAnalysis()
973 void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg, in removeDeadPasses()
976 SmallVector<Pass *, 12> DeadPasses; 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()
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()
1014 DenseMap<AnalysisID, Pass *>::iterator Pos = 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()
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()
1048 for (Pass *PUsed : UsedPasses) { 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()
1074 Pass *My_PM = getAsPass(); in add()
1082 Pass *AnalysisPass = PI->createPass(); 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()
1105 if (Pass *AnalysisPass = findAnalysisPass(UsedID, true)) 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()
1124 Pass *Impl = findAnalysisPass(ID, true); in initializeAnalysisImpl()
1126 // This may be analysis pass that is initialized on the fly. 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()
1153 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{ in dumpLastUses()
1157 SmallVector<Pass *, 12> LUses; in dumpLastUses()
1165 for (Pass *P : LUses) { in dumpLastUses()
1172 for (Pass *P : PassVector) { in dumpPassArguments()
1183 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1, in dumpPassInfo()
1192 dbgs() << "Executing Pass '" << P->getPassName(); in dumpPassInfo()
1198 dbgs() << " Freeing Pass '" << P->getPassName(); in dumpPassInfo()
1224 void PMDataManager::dumpRequiredSet(const Pass *P) const { in dumpRequiredSet()
1233 void PMDataManager::dumpPreservedSet(const Pass *P) const { in dumpPreservedSet()
1242 void PMDataManager::dumpUsedSet(const Pass *P) const { in dumpUsedSet()
1251 void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P, in dumpAnalysisUsage()
1263 dbgs() << " Uninitialized Pass"; 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()
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()
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()
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()
1326 /// Create new Function pass manager
1340 void FunctionPassManager::add(Pass *P) { in add()
1370 /// cleanup - After running all passes, clean up pass manager cache.
1404 // Collect inherited analysis from Module level pass manager. in runOnFunction()
1444 llvm::errs() << "Pass modifies its input and doesn't report it: " in runOnFunction()
1446 llvm_unreachable("Pass modifies its input and doesn't report it"); in runOnFunction()
1559 "Pass modifies its input and doesn't report it."); in runOnModule()
1596 // We don't know when is the last time an on-the-fly pass is run, 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()
1611 "Unable to handle Pass that requires lower level Analysis pass"); in addLowerLevelRequiredPass()
1614 "Unable to handle Pass that requires lower level Analysis pass"); in addLowerLevelRequiredPass()
1627 Pass *FoundPass = nullptr; in addLowerLevelRequiredPass()
1639 SmallVector<Pass *, 1> LU; 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()
1664 /// Create new pass manager
1675 void PassManager::add(Pass *P) { in add()
1691 // Pop Pass Manager from the stack and clear its analysis info.
1702 assert(PM && "Unable to push. Pass Manager expected"); in push()
1703 assert(PM->getDepth()==0 && "Pass Manager depth set too early"); in push()
1707 && "pushing bad pass manager to PMStack"); in push()
1717 && "pushing bad pass manager to PMStack"); in push()
1724 // Dump content of the pass manager stack.
1733 /// Find appropriate Module Pass Manager in the PM Stack and
1737 // Find Module Pass Manager in assignPassManager()
1745 /// Find appropriate Function Pass Manager or Call Graph Pass Manager
1749 // Find Function Pass Manager in assignPassManager()
1754 // Create new Function Pass Manager if needed. in assignPassManager()
1756 // [1] Create new Function Pass Manager in assignPassManager()
1772 // Assign FPP as the manager of this pass. in assignPassManager()