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
89 Pass *P, Module &M, int64_t Delta, unsigned CountBefore,
92 // If it's a pass manager, don't emit a remark. (This hinges on the assumption
93 // that the only passes that return non-null with getAsPMDataManager are pass
99 // Set to true if this isn't a module pass or CGSCC pass.
120 // If no function was passed in, then we're either a module pass or an
121 // CGSCC pass.
148 R << DiagnosticInfoOptimizationBase::Argument("Pass", P->getPassName())
180 FR << DiagnosticInfoOptimizationBase::Argument("Pass", PassName)
209 OS << "Releasing pass '";
211 OS << "Running pass '";
245 class FunctionPassManagerImpl : public Pass,
254 : Pass(PT_PassManager, ID), PMTopLevelManager(new FPPassManager()),
258 void add(Pass *P) {
262 /// createPrinterPass - Get a function printer pass.
263 Pass *createPrinterPass(raw_ostream &O,
268 // Prepare for running an on the fly pass, freeing memory if needed
286 Pass *getAsPass() override { return this; }
291 /// Pass Manager itself does not invalidate any analysis info.
297 assert(N < PassManagers.size() && "Pass number out of range!");
355 // Return true if any function is modified by a pass.
378 /// MPPassManager manages ModulePasses and function pass managers.
379 /// It batches all Module passes and function pass managers together and
381 class MPPassManager : public Pass, public PMDataManager {
384 explicit MPPassManager() : Pass(PT_PassManager, ID) {}
394 /// createPrinterPass - Get a module printer pass.
395 Pass *createPrinterPass(raw_ostream &O,
404 using llvm::Pass::doInitialization;
405 using llvm::Pass::doFinalization;
407 /// Pass Manager itself does not invalidate any analysis info.
412 /// Add RequiredPass into list of lower level passes required by pass P.
413 /// RequiredPass is run on the fly by Pass Manager when P requests it
415 void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) override;
417 /// Return function pass corresponding to PassInfo PI, that is
418 /// required by module pass MP. Instantiate analysis pass, by using
420 std::tuple<Pass *, bool> getOnTheFlyPass(Pass *MP, AnalysisID PI,
423 StringRef getPassName() const override { return "Module Pass Manager"; }
426 Pass *getAsPass() override { return this; }
434 MapVector<Pass *, legacy::FunctionPassManagerImpl *>::const_iterator I =
443 assert(N < PassVector.size() && "Pass number out of range!");
454 MapVector<Pass *, legacy::FunctionPassManagerImpl *> OnTheFlyManagers;
467 class PassManagerImpl : public Pass,
475 : Pass(PT_PassManager, ID), PMTopLevelManager(new MPPassManager()) {}
478 void add(Pass *P) {
482 /// createPrinterPass - Get a module printer pass.
483 Pass *createPrinterPass(raw_ostream &O,
492 using llvm::Pass::doInitialization;
493 using llvm::Pass::doFinalization;
495 /// Pass Manager itself does not invalidate any analysis info.
501 Pass *getAsPass() override { return this; }
507 assert(N < PassManagers.size() && "Pass number out of range!");
554 /// Initialize top level manager. Create first pass manager.
561 /// Set pass P as the last user of the given analysis passes.
563 PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) {
568 for (Pass *AP : AnalysisPasses) {
582 SmallVector<Pass *, 12> LastUses;
583 SmallVector<Pass *, 12> LastPMUses;
585 Pass *AnalysisPass = findAnalysisPass(ID);
586 assert(AnalysisPass && "Expected analysis pass to exist.");
599 // If this pass has a corresponding pass manager, push higher level
600 // analysis to this pass manager.
607 for (Pass *L : LastUsedByAP)
615 void PMTopLevelManager::collectLastUses(SmallVectorImpl<Pass *> &LastUses,
616 Pass *P) {
625 AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) {
631 // Look up the analysis usage from the pass instance (different instances
632 // of the same pass can produce different results), but unique the
634 // memory usage when we have many instances of only a few pass types
658 /// Schedule pass P for execution. Make sure that passes required by
661 void PMTopLevelManager::schedulePass(Pass *P) {
663 // TODO : Allocate function manager for this pass, other wise required set
666 // Give pass a chance to prepare the stage.
669 // If P is an analysis pass and it is available then do not
689 Pass *AnalysisPass = findAnalysisPass(ID);
694 // Pass P is not in the global PassRegistry
695 dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
696 dbgs() << "Verify if there is a pass dependency cycle." << "\n";
701 Pass *AnalysisPass2 = findAnalysisPass(ID2);
705 dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n";
706 dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n";
716 // Schedule analysis pass that is managed by the same pass manager.
720 // Schedule analysis pass that is managed by a new manager.
735 // P is a immutable pass and it will be managed by this
747 Pass *PP =
754 // Add the requested pass to the best available pass manager.
758 Pass *PP =
766 /// Find the pass that implements Analysis AID. Search immutable
767 /// passes and all pass managers. If desired pass is not found
769 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
770 // For immutable passes we have a direct mapping from ID to pass, so check
772 if (Pass *P = ImmutablePassMap.lookup(AID))
775 // Check pass managers
777 if (Pass *P = PassManager->findAnalysisPass(AID, false))
780 // Check other pass managers
782 if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false))
794 "The pass info pointer changed for an analysis ID!");
803 // Add this pass to the map from its analysis ID. We clobber any prior runs
804 // of the pass in the map so that the last one added is the one found when
817 for (ImmutablePass *Pass : ImmutablePasses)
818 Pass->dumpPassStructure(0);
820 // Every class that derives from PMDataManager also derives from Pass
822 // between PMDataManager and Pass, so we have to getAsPass to get
823 // from a PMDataManager* to a Pass*.
833 dbgs() << "Pass Arguments: ";
848 // Initailize other pass managers
865 /// Augement AvailableAnalysis by adding analysis made available by pass P.
866 void PMDataManager::recordAvailableAnalysis(Pass *P) {
874 bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
880 for (Pass *P1 : HigherLevelAnalysis) {
889 /// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
890 void PMDataManager::verifyPreservedAnalysis(Pass *P) {
900 if (Pass *AP = findAnalysisPass(AID, true)) {
907 /// Remove Analysis not preserved by Pass P
908 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
914 for (DenseMap<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
916 DenseMap<AnalysisID, Pass*>::iterator Info = I++;
921 Pass *S = Info->second;
931 for (DenseMap<AnalysisID, Pass *> *IA : InheritedAnalysis) {
935 for (DenseMap<AnalysisID, Pass *>::iterator I = IA->begin(),
938 DenseMap<AnalysisID, Pass *>::iterator Info = I++;
943 Pass *S = Info->second;
954 void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
957 SmallVector<Pass *, 12> DeadPasses;
967 dbgs() << "' is the last user of following pass instances.";
971 for (Pass *P : DeadPasses)
975 void PMDataManager::freePass(Pass *P, StringRef Msg,
980 // If the pass crashes releasing memory, remember this.
987 // Remove the pass itself (if it is not already removed).
991 /// Add pass P into the PassVector. Update
993 void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
994 // This manager is going to manage pass P. Set up analysis resolver
1001 SmallVector<Pass *, 12> TransferLastUses;
1004 // Add pass
1009 // At the moment, this pass is the last user of all required passes.
1010 SmallVector<Pass *, 12> LastUses;
1011 SmallVector<Pass *, 8> UsedPasses;
1017 for (Pass *PUsed : UsedPasses) {
1032 llvm_unreachable("Unable to accommodate Used Pass");
1036 // However, if P is a Pass Manager then it does not need
1043 Pass *My_PM = getAsPass();
1051 Pass *AnalysisPass = PI->createPass();
1055 // Take a note of analysis required and made available by this pass.
1056 // Remove the analysis not preserved by this pass
1060 // Add pass
1065 /// Populate UP with analysis pass that are used or required by
1066 /// pass P and are available. Populate RP_NotAvail with analysis
1067 /// pass that are required by pass P but are not available.
1069 SmallVectorImpl<Pass *> &UP, SmallVectorImpl<AnalysisID> &RP_NotAvail,
1070 Pass *P) {
1074 if (Pass *AnalysisPass = findAnalysisPass(UsedID, true))
1078 if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true))
1084 // All Required analyses should be available to the pass as it runs! Here
1085 // we fill in the AnalysisImpls member of the pass so that it can
1089 void PMDataManager::initializeAnalysisImpl(Pass *P) {
1093 Pass *Impl = findAnalysisPass(ID, true);
1095 // This may be analysis pass that is initialized on the fly.
1104 /// Find the pass that implements Analysis AID. If desired pass is not found
1106 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
1109 DenseMap<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
1122 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
1126 SmallVector<Pass *, 12> LUses;
1134 for (Pass *P : LUses) {
1141 for (Pass *P : PassVector) {
1149 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
1158 dbgs() << "Executing Pass '" << P->getPassName();
1164 dbgs() << " Freeing Pass '" << P->getPassName();
1190 void PMDataManager::dumpRequiredSet(const Pass *P) const {
1199 void PMDataManager::dumpPreservedSet(const Pass *P) const {
1208 void PMDataManager::dumpUsedSet(const Pass *P) const {
1217 void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
1229 dbgs() << " Uninitialized Pass";
1237 /// Add RequiredPass into list of lower level passes required by pass P.
1238 /// RequiredPass is run on the fly by Pass Manager when P requests it
1240 /// This should be handled by specific pass manager.
1241 void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1247 // Module Level pass may required Function Level analysis info
1248 // (e.g. dominator info). Pass manager uses on the fly function pass manager
1249 // to provide this on demand. In that case, in Pass manager terminology,
1250 // module level pass is requiring lower level analysis info managed by
1251 // lower level pass manager.
1253 // When Pass manager is not able to order required analysis info, Pass manager
1260 llvm_unreachable("Unable to schedule pass");
1263 std::tuple<Pass *, bool> PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI,
1265 llvm_unreachable("Unable to find on the fly pass");
1270 for (Pass *P : PassVector)
1277 Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID) const {
1281 std::tuple<Pass *, bool>
1282 AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI, Function &F) {
1292 /// Create new Function pass manager
1306 void FunctionPassManager::add(Pass *P) {
1336 /// cleanup - After running all passes, clean up pass manager cache.
1370 // Collect inherited analysis from Module level pass manager.
1410 llvm::errs() << "Pass modifies its input and doesn't report it: "
1412 llvm_unreachable("Pass modifies its input and doesn't report it");
1525 "Pass modifies its input and doesn't report it.");
1562 // We don't know when is the last time an on-the-fly pass is run,
1571 /// Add RequiredPass into list of lower level passes required by pass P.
1572 /// RequiredPass is run on the fly by Pass Manager when P requests it
1574 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1575 assert(RequiredPass && "No required pass?");
1577 "Unable to handle Pass that requires lower level Analysis pass");
1580 "Unable to handle Pass that requires lower level Analysis pass");
1593 Pass *FoundPass = nullptr;
1605 SmallVector<Pass *, 1> LU;
1610 /// Return function pass corresponding to PassInfo PI, that is
1611 /// required by module pass MP. Instantiate analysis pass, by using
1613 std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI,
1616 assert(FPP && "Unable to find on the fly pass");
1630 /// Create new pass manager
1641 void PassManager::add(Pass *P) {
1657 // Pop Pass Manager from the stack and clear its analysis info.
1668 assert(PM && "Unable to push. Pass Manager expected");
1669 assert(PM->getDepth()==0 && "Pass Manager depth set too early");
1673 && "pushing bad pass manager to PMStack");
1683 && "pushing bad pass manager to PMStack");
1690 // Dump content of the pass manager stack.
1699 /// Find appropriate Module Pass Manager in the PM Stack and
1703 // Find Module Pass Manager
1711 /// Find appropriate Function Pass Manager or Call Graph Pass Manager
1715 // Find Function Pass Manager
1720 // Create new Function Pass Manager if needed.
1722 // [1] Create new Function Pass Manager
1738 // Assign FPP as the manager of this pass.