Home | History | Annotate | Download | only in IR

Lines Matching full:pass

1 //===- LegacyPassManager.cpp - LLVM Pass Infrastructure Implementation ----===//
10 // This file implements the legacy LLVM Pass Manager infrastructure.
34 // See PassManagers.h for Pass Manager infrastructure overview.
37 // Pass debugging information. Often it is useful to find out what pass is
39 // debugging on, a command line option (--debug-pass) is enabled that causes the
40 // pass name to be printed before it executes.
51 PassDebugging("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"),
79 llvm::cl::desc("Print IR before each pass"),
83 llvm::cl::desc("Print IR after each pass"),
87 /// after a pass.
100 /// This is a utility to check whether a pass should have IR dumped
106 /// This is a utility to check whether a pass should have IR dumped
112 /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
123 OS << "Releasing pass '";
125 OS << "Running pass '";
157 /// pass together and sequence them to process one basic block before
170 /// Pass Manager itself does not invalidate any analysis info.
181 Pass *getAsPass() override { return this; }
184 return "BasicBlock Pass Manager";
198 assert(N < PassVector.size() && "Pass number out of range!");
217 class FunctionPassManagerImpl : public Pass,
226 Pass(PT_PassManager, ID), PMDataManager(),
230 void add(Pass *P) {
234 /// createPrinterPass - Get a function printer pass.
235 Pass *createPrinterPass(raw_ostream &O,
240 // Prepare for running an on the fly pass, freeing memory if needed
258 Pass *getAsPass() override { return this; }
263 /// Pass Manager itself does not invalidate any analysis info.
269 assert(N < PassManagers.size() && "Pass number out of range!");
285 /// MPPassManager manages ModulePasses and function pass managers.
286 /// It batches all Module passes and function pass managers together and
288 class MPPassManager : public Pass, public PMDataManager {
292 Pass(PT_PassManager, ID), PMDataManager() { }
302 /// createPrinterPass - Get a module printer pass.
303 Pass *createPrinterPass(raw_ostream &O,
312 using llvm::Pass::doInitialization;
313 using llvm::Pass::doFinalization;
323 /// Pass Manager itself does not invalidate any analysis info.
328 /// Add RequiredPass into list of lower level passes required by pass P.
329 /// RequiredPass is run on the fly by Pass Manager when P requests it
331 void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) override;
333 /// Return function pass corresponding to PassInfo PI, that is
334 /// required by module pass MP. Instantiate analysis pass, by using
336 Pass* getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F) override;
339 return "Module Pass Manager";
343 Pass *getAsPass() override { return this; }
351 std::map<Pass *, FunctionPassManagerImpl *>::const_iterator I =
360 assert(N < PassVector.size() && "Pass number out of range!");
371 std::map<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
384 class PassManagerImpl : public Pass,
392 Pass(PT_PassManager, ID), PMDataManager(),
396 void add(Pass *P) {
400 /// createPrinterPass - Get a module printer pass.
401 Pass *createPrinterPass(raw_ostream &O,
410 using llvm::Pass::doInitialization;
411 using llvm::Pass::doFinalization;
421 /// Pass Manager itself does not invalidate any analysis info.
427 Pass *getAsPass() override { return this; }
433 assert(N < PassManagers.size() && "Pass number out of range!");
449 /// amount of time each pass takes to execute. This only happens when
456 DenseMap<Pass*, Timer*> TimingData;
460 TimingInfo() : TG("... Pass execution timing report ...") {}
476 /// getPassTimer - Return the timer for the specified pass if it exists.
477 Timer *getPassTimer(Pass *P) {
496 /// Initialize top level manager. Create first pass manager.
503 /// Set pass P as the last user of the given analysis passes.
505 PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) {
510 for (Pass *AP : AnalysisPasses) {
519 SmallVector<Pass *, 12> LastUses;
520 SmallVector<Pass *, 12> LastPMUses;
523 Pass
524 assert(AnalysisPass && "Expected analysis pass to exist.");
537 // If this pass has a corresponding pass manager, push higher level
538 // analysis to this pass manager.
545 for (DenseMap<Pass *, Pass *>::iterator LUI = LastUser.begin(),
556 void PMTopLevelManager::collectLastUses(SmallVectorImpl<Pass *> &LastUses,
557 Pass *P) {
558 DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator DMI =
563 SmallPtrSet<Pass *, 8> &LU = DMI->second;
564 for (Pass *LUP : LU) {
570 AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) {
576 // Look up the analysis usage from the pass instance (different instances
577 // of the same pass can produce different results), but unique the
579 // memory usage when we have many instances of only a few pass types
603 /// Schedule pass P for execution. Make sure that passes required by
606 void PMTopLevelManager::schedulePass(Pass *P) {
608 // TODO : Allocate function manager for this pass, other wise required set
611 // Give pass a chance to prepare the stage.
614 // If P is an analysis pass and it is available then do not
633 Pass *AnalysisPass = findAnalysisPass(*I);
638 // Pass P is not in the global PassRegistry
639 dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
640 dbgs() << "Verify if there is a pass dependency cycle." << "\n";
644 Pass *AnalysisPass2 = findAnalysisPass(*I2);
648 dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n";
649 dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n";
659 // Schedule analysis pass that is managed by the same pass manager.
663 // Schedule analysis pass that is managed by a new manager.
678 // P is a immutable pass and it will be managed by this
690 Pass *PP = P->createPrinterPass(
695 // Add the requested pass to the best available pass manager.
699 Pass *PP = P->createPrinterPass(
705 /// Find the pass that implements Analysis AID. Search immutable
706 /// passes and all pass managers. If desired pass is not found
708 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
709 // For immutable passes we have a direct mapping from ID to pass, so check
711 if (Pass *P = ImmutablePassMap.lookup(AID))
714 // Check pass managers
716 if (Pass *P = PassManager->findAnalysisPass(AID, false))
719 // Check other pass managers
721 if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false))
733 "The pass info pointer changed for an analysis ID!");
742 // Add this pass to the map from its analysis ID. We clobber any prior runs
743 // of the pass in the map so that the last one added is the one found when
748 // Also add any interfaces implemented by the immutable pass to the map for
767 // Every class that derives from PMDataManager also derives from Pass
769 // between PMDataManager and Pass, so we have to getAsPass to get
770 // from a PMDataManager* to a Pass*.
780 dbgs() << "Pass Arguments: ";
799 // Initailize other pass managers
805 for (DenseMap<Pass *, Pass *>::iterator DMI = LastUser.begin(),
807 SmallPtrSet<Pass *, 8> &L = InversedLastUser[DMI->second];
826 /// Augement AvailableAnalysis by adding analysis made available by pass P.
827 void PMDataManager::recordAvailableAnalysis(Pass *P) {
834 // This pass is the current implementation of all of the interfaces it
845 bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
851 for (SmallVectorImpl<Pass *>::iterator I = HigherLevelAnalysis.begin(),
853 Pass *P1 = *I;
864 /// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
865 void PMDataManager::verifyPreservedAnalysis(Pass *P) {
877 if (Pass *AP = findAnalysisPass(AID, true)) {
884 /// Remove Analysis not preserved by Pass P
885 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
891 for (DenseMap<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
893 DenseMap<AnalysisID, Pass*>::iterator Info = I++;
899 Pass *S = Info->second;
914 for (DenseMap<AnalysisID, Pass*>::iterator
917 DenseMap<AnalysisID, Pass *>::iterator Info = I++;
923 Pass *S = Info->second;
934 void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
937 SmallVector<Pass *, 12> DeadPasses;
947 dbgs() << "' is the last user of following pass instances.";
951 for (SmallVectorImpl<Pass *>::iterator I = DeadPasses.begin(),
956 void PMDataManager::freePass(Pass *P, StringRef Msg,
961 // If the pass crashes releasing memory, remember this.
970 // Remove the pass itself (if it is not already removed).
973 // Remove all interfaces this pass implements, for which it is also
977 DenseMap<AnalysisID, Pass*>::iterator Pos =
985 /// Add pass P into the PassVector. Update
987 void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
988 // This manager is going to manage pass P. Set up analysis resolver
995 SmallVector<Pass *, 12> TransferLastUses;
998 // Add pass
1003 // At the moment, this pass is the last user of all required passes.
1004 SmallVector<Pass *, 12> LastUses;
1005 SmallVector<Pass *, 8> UsedPasses;
1011 for (Pass *PUsed : UsedPasses) {
1026 llvm_unreachable("Unable to accommodate Used Pass");
1030 // However, if P is a Pass Manager then it does not need
1037 Pass *My_PM = getAsPass();
1045 Pass *AnalysisPass = PI->createPass();
1049 // Take a note of analysis required and made available by this pass.
1050 // Remove the analysis not preserved by this pass
1054 // Add pass
1059 /// Populate UP with analysis pass that are used or required by
1060 /// pass P and are available. Populate RP_NotAvail with analysis
1061 /// pass that are required by pass P but are not available.
1063 SmallVectorImpl<Pass *> &UP, SmallVectorImpl<AnalysisID> &RP_NotAvail,
1064 Pass *P) {
1068 if (Pass *AnalysisPass = findAnalysisPass(UsedID, true))
1072 if (Pass *AnalysisPass = findAnalysisPass(RequiredID, 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) {
1095 Pass *Impl = findAnalysisPass(*I, true);
1097 // This may be analysis pass that is initialized on the fly.
1106 /// Find the pass that implements Analysis AID. If desired pass is not found
1108 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
1111 DenseMap<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
1124 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
1126 SmallVector<Pass *, 12> LUses;
1134 for (SmallVectorImpl<Pass *>::iterator I = LUses.begin(),
1142 for (SmallVectorImpl<Pass *>::const_iterator I = PassVector.begin(),
1154 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
1163 dbgs() << "Executing Pass '" << P->getPassName();
1169 dbgs() << " Freeing Pass '" << P->getPassName();
1198 void PMDataManager::dumpRequiredSet(const Pass *P) const {
1207 void PMDataManager::dumpPreservedSet(const Pass *P) const {
1216 void PMDataManager::dumpUsedSet(const Pass *P) const {
1225 void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
1237 dbgs() << " Uninitialized Pass";
1245 /// Add RequiredPass into list of lower level passes required by pass P.
1246 /// RequiredPass is run on the fly by Pass Manager when P requests it
1248 /// This should be handled by specific pass manager.
1249 void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1255 // Module Level pass may required Function Level analysis info
1256 // (e.g. dominator info). Pass manager uses on the fly function pass manager
1257 // to provide this on demand. In that case, in Pass manager terminology,
1258 // module level pass is requiring lower level analysis info managed by
1259 // lower level pass manager.
1261 // When Pass manager is not able to order required analysis info, Pass manager
1268 llvm_unreachable("Unable to schedule pass");
1271 Pass *PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F) {
1272 llvm_unreachable("Unable to find on the fly pass");
1277 for (SmallVectorImpl<Pass *>::iterator I = PassVector.begin(),
1285 Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const {
1289 Pass *AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI,
1317 // If the pass crashes, remember this.
1385 /// Create new Function pass manager
1399 void FunctionPassManager::add(Pass *P) {
1456 /// cleanup - After running all passes, clean up pass manager cache.
1479 // Return true if any function is modified by a pass.
1521 // Collect inherited analysis from Module level pass manager.
1637 // We don't know when is the last time an on-the-fly pass is run,
1646 /// Add RequiredPass into list of lower level passes required by pass P.
1647 /// RequiredPass is run on the fly by Pass Manager when P requests it
1649 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1651 "Unable to handle Pass that requires lower level Analysis pass");
1654 "Unable to handle Pass that requires lower level Analysis pass");
1669 Pass *FoundPass = nullptr;
1681 SmallVector<Pass *, 1> LU;
1686 /// Return function pass corresponding to PassInfo PI, that is
1687 /// required by module pass MP. Instantiate analysis pass, by using
1689 Pass* MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F){
1691 assert(FPP && "Unable to find on the fly pass");
1730 /// Create new pass manager
1741 void PassManager::add(Pass *P) {
1757 cl::desc("Time each pass, printing elapsed time for each on exit"));
1772 /// If TimingInfo is enabled then start pass timer.
1773 Timer *llvm::getPassTimer(Pass *P) {
1783 // Pop Pass Manager from the stack and clear its analysis info.
1794 assert(PM && "Unable to push. Pass Manager expected");
1795 assert(PM->getDepth()==0 && "Pass Manager depth set too early");
1799 && "pushing bad pass manager to PMStack");
1809 && "pushing bad pass manager to PMStack");
1816 // Dump content of the pass manager stack.
1825 /// Find appropriate Module Pass Manager in the PM Stack and
1829 // Find Module Pass Manager
1833 break; // We found desired pass manager
1835 PMS.pop(); // Pop children pass managers
1839 assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
1843 /// Find appropriate Function Pass Manager or Call Graph Pass Manager
1848 // Find Function Pass Manager
1856 // Create new Function Pass Manager if needed.
1861 assert(!PMS.empty() && "Unable to create Function Pass Manager");
1864 // [1] Create new Function Pass Manager
1880 // Assign FPP as the manager of this pass.
1884 /// Find appropriate Basic Pass Manager or Call Graph Pass Manager
1890 // Basic Pass Manager is a leaf pass manager. It does not handle
1891 // any other pass manager.
1896 // If leaf manager is not Basic Block Pass manager then create new
1897 // basic Block Pass manager.
1898 assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
1905 // Basic Block Pass Manager does not live by itself
1917 // Assign BBP as the manager of this pass.