34 #include <unordered_set> 50 Disabled,
Arguments, Structure, Executions, Details
56 cl::desc(
"Print PassManager debugging information"),
58 clEnumVal(Disabled ,
"disable debug output"),
60 clEnumVal(Structure ,
"print pass structure before run()"),
61 clEnumVal(Executions,
"print pass name before it is executed"),
62 clEnumVal(Details ,
"print pass details when it is executed")));
89 cl::desc(
"When printing IR for print-[before|after]{-all} " 90 "always print a module IR"),
95 cl::desc(
"Only print IR for functions whose name " 96 "match this for all print-[before|after][-all] " 112 PassOptionList &PassesToPrint) {
113 for (
auto *PassInf : PassesToPrint) {
115 if (PassInf->getPassArgument() == PassID) {
133 static std::unordered_set<std::string> PrintFuncNames(PrintFuncsList.begin(),
134 PrintFuncsList.end());
135 return PrintFuncNames.empty() || PrintFuncNames.count(FunctionName);
140 return PassDebugging >= Executions;
144 Module &M,
StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount) {
151 unsigned FCount =
F.getInstructionCount();
158 FunctionToInstrCount[
F.getName().str()] =
159 std::pair<unsigned, unsigned>(FCount, 0);
160 InstrCount += FCount;
166 Pass *
P,
Module &M, int64_t Delta,
unsigned CountBefore,
167 StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount,
177 bool CouldOnlyImpactOneFunction = (F !=
nullptr);
180 auto UpdateFunctionChanges =
181 [&FunctionToInstrCount](
Function &MaybeChangedFn) {
183 unsigned FnSize = MaybeChangedFn.getInstructionCount();
184 auto It = FunctionToInstrCount.find(MaybeChangedFn.getName());
188 if (It == FunctionToInstrCount.end()) {
189 FunctionToInstrCount[MaybeChangedFn.getName()] =
190 std::pair<unsigned, unsigned>(0, FnSize);
195 It->second.second = FnSize;
201 if (!CouldOnlyImpactOneFunction)
204 UpdateFunctionChanges(*F);
207 if (!CouldOnlyImpactOneFunction) {
213 [](
const Function &Fn) {
return !Fn.empty(); });
222 int64_t CountAfter =
static_cast<int64_t
>(CountBefore) + Delta;
229 <<
": IR instruction count changed from " 241 auto EmitFunctionSizeChangedRemark = [&FunctionToInstrCount, &
F, &BB,
242 &PassName](
const std::string &Fname) {
243 unsigned FnCountBefore, FnCountAfter;
244 std::pair<unsigned, unsigned> &Change = FunctionToInstrCount[Fname];
245 std::tie(FnCountBefore, FnCountAfter) = Change;
246 int64_t FnDelta =
static_cast<int64_t
>(FnCountAfter) -
247 static_cast<int64_t>(FnCountBefore);
260 FR << DiagnosticInfoOptimizationBase::Argument(
"Pass", PassName)
262 << DiagnosticInfoOptimizationBase::Argument(
"Function", Fname)
263 <<
": IR instruction count changed from " 264 << DiagnosticInfoOptimizationBase::Argument(
"IRInstrsBefore",
267 << DiagnosticInfoOptimizationBase::Argument(
"IRInstrsAfter",
270 << DiagnosticInfoOptimizationBase::Argument(
"DeltaInstrCount", FnDelta);
271 F->getContext().diagnose(FR);
274 Change.first = FnCountAfter;
279 if (!CouldOnlyImpactOneFunction)
281 FunctionToInstrCount.keys().end(),
282 EmitFunctionSizeChangedRemark);
284 EmitFunctionSizeChangedRemark(F->getName().str());
289 OS <<
"Releasing pass '";
291 OS <<
"Running pass '";
293 OS <<
P->getPassName() <<
"'";
296 OS <<
" on module '" << M->getModuleIdentifier() <<
"'.\n";
305 if (isa<Function>(V))
307 else if (isa<BasicBlock>(V))
313 V->printAsOperand(OS,
false, M);
329 explicit BBPassManager()
341 bool doInitialization(
Module &M)
override;
343 bool doFinalization(
Module &M)
override;
346 PMDataManager *getAsPMDataManager()
override {
return this; }
347 Pass *getAsPass()
override {
return this; }
349 StringRef getPassName()
const override {
return "BasicBlock Pass Manager"; }
352 void dumpPassStructure(
unsigned Offset)
override {
353 dbgs().
indent(Offset*2) <<
"BasicBlockPass Manager\n";
357 dumpLastUses(BP, Offset+1);
362 assert(N < PassVector.size() &&
"Pass number out of range!");
384 virtual void anchor();
400 const std::string &Banner)
const override {
406 void releaseMemoryOnTheFly();
414 bool doInitialization(
Module &M)
override;
418 bool doFinalization(
Module &M)
override;
433 assert(N < PassManagers.size() &&
"Pass number out of range!");
439 void FunctionPassManagerImpl::anchor() {}
455 explicit MPPassManager() :
459 ~MPPassManager()
override {
460 for (
auto &OnTheFlyManager : OnTheFlyManagers) {
468 const std::string &Banner)
const override {
474 bool runOnModule(
Module &M);
487 void addLowerLevelRequiredPass(
Pass *
P,
Pass *RequiredPass)
override;
494 StringRef getPassName()
const override {
return "Module Pass Manager"; }
496 PMDataManager *getAsPMDataManager()
override {
return this; }
497 Pass *getAsPass()
override {
return this; }
500 void dumpPassStructure(
unsigned Offset)
override {
501 dbgs().
indent(Offset*2) <<
"ModulePass Manager\n";
506 OnTheFlyManagers.find(MP);
507 if (I != OnTheFlyManagers.
end())
508 I->second->dumpPassStructure(Offset + 2);
509 dumpLastUses(MP, Offset+1);
514 assert(N < PassVector.size() &&
"Pass number out of range!");
541 virtual void anchor();
556 const std::string &Banner)
const override {
579 assert(N < PassManagers.size() &&
"Pass number out of range!");
580 MPPassManager *MP =
static_cast<MPPassManager *
>(PassManagers[
N]);
585 void PassManagerImpl::anchor() {}
597 addPassManager(PMDM);
598 activeStack.push(PMDM);
608 for (
Pass *AP : AnalysisPasses) {
620 Pass *AnalysisPass = findAnalysisPass(
ID);
621 assert(AnalysisPass &&
"Expected analysis pass to exist.");
623 assert(AR &&
"Expected analysis resolver to exist.");
626 if (PDepth == APDepth)
628 else if (PDepth > APDepth)
632 setLastUser(LastUses, P);
642 for (
auto LU : LastUser) {
646 LastUser[LU.first] =
P;
655 InversedLastUser.
find(P);
656 if (DMI == InversedLastUser.
end())
660 for (
Pass *LUP : LU) {
668 auto DMI = AnUsageMap.find(P);
669 if (DMI != AnUsageMap.end())
670 AnUsage = DMI->second;
681 AUFoldingSetNode* Node =
nullptr;
683 AUFoldingSetNode::Profile(ID, AU);
685 if (
auto *
N = UniqueAnalysisUsages.FindNodeOrInsertPos(ID, IP))
688 Node =
new (AUFoldingSetNodeAllocator.Allocate()) AUFoldingSetNode(AU);
689 UniqueAnalysisUsages.InsertNode(Node, IP);
691 assert(Node &&
"cached analysis usage must be non null");
693 AnUsageMap[
P] = &Node->AU;
723 bool checkAnalysis =
true;
724 while (checkAnalysis) {
725 checkAnalysis =
false;
730 Pass *AnalysisPass = findAnalysisPass(
ID);
732 const PassInfo *PI = findAnalysisPassInfo(
ID);
736 dbgs() <<
"Pass '" << P->
getPassName() <<
"' is not initialized." <<
"\n";
737 dbgs() <<
"Verify if there is a pass dependency cycle." <<
"\n";
738 dbgs() <<
"Required Passes:" <<
"\n";
742 Pass *AnalysisPass2 = findAnalysisPass(ID2);
746 dbgs() <<
"\t" <<
"Error: Required pass not found! Possible causes:" <<
"\n";
747 dbgs() <<
"\t\t" <<
"- Pass misconfiguration (e.g.: missing macros)" <<
"\n";
748 dbgs() <<
"\t\t" <<
"- Corruption of the global PassRegistry" <<
"\n";
753 assert(PI &&
"Expected required passes to be initialized");
758 schedulePass(AnalysisPass);
762 schedulePass(AnalysisPass);
765 checkAnalysis =
true;
782 addImmutablePass(IP);
809 if (
Pass *
P = ImmutablePassMap.lookup(AID))
818 for (
PMDataManager *IndirectPassManager : IndirectPassManagers)
819 if (
Pass *
P = IndirectPassManager->findAnalysisPass(AID,
false))
826 const PassInfo *&PI = AnalysisPassInfos[AID];
831 "The pass info pointer changed for an analysis ID!");
838 ImmutablePasses.push_back(P);
844 ImmutablePassMap[AID] =
P;
848 const PassInfo *PassInf = findAnalysisPassInfo(AID);
849 assert(PassInf &&
"Expected all immutable passes to be initialized");
851 ImmutablePassMap[ImmPI->getTypeInfo()] =
P;
857 if (PassDebugging < Structure)
861 for (
unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
862 ImmutablePasses[i]->dumpPassStructure(0);
870 Manager->getAsPass()->dumpPassStructure(1);
878 dbgs() <<
"Pass Arguments: ";
880 if (
const PassInfo *PI = findAnalysisPassInfo(
P->getPassID())) {
881 assert(PI &&
"Expected all immutable passes to be initialized");
882 if (!PI->isAnalysisGroup())
883 dbgs() <<
" -" << PI->getPassArgument();
886 PM->dumpPassArguments();
892 PM->initializeAnalysisInfo();
896 IPM->initializeAnalysisInfo();
898 for (
auto LU : LastUser) {
920 AvailableAnalysis[PI] =
P;
922 assert(!AvailableAnalysis.empty());
926 const PassInfo *PInf = TPM->findAnalysisPassInfo(PI);
929 for (
unsigned i = 0, e = II.size(); i != e; ++i)
930 AvailableAnalysis[II[i]->getTypeInfo()] =
P;
941 for (
Pass *P1 : HigherLevelAnalysis) {
942 if (P1->getAsImmutablePass() ==
nullptr &&
961 if (
Pass *AP = findAnalysisPass(AID,
true)) {
963 AP->verifyAnalysis();
976 E = AvailableAnalysis.end();
I !=
E; ) {
978 if (Info->second->getAsImmutablePass() ==
nullptr &&
981 if (PassDebugging >= Details) {
982 Pass *S = Info->second;
986 AvailableAnalysis.erase(Info);
994 if (!InheritedAnalysis[
Index])
998 I = InheritedAnalysis[Index]->
begin(),
999 E = InheritedAnalysis[Index]->
end();
I !=
E; ) {
1001 if (Info->second->getAsImmutablePass() ==
nullptr &&
1004 if (PassDebugging >= Details) {
1005 Pass *S = Info->second;
1009 InheritedAnalysis[
Index]->erase(Info);
1025 TPM->collectLastUses(DeadPasses, P);
1027 if (PassDebugging >= Details && !DeadPasses.
empty()) {
1029 dbgs() <<
"' is the last user of following pass instances.";
1030 dbgs() <<
" Free these instances\n";
1033 for (
Pass *P : DeadPasses)
1034 freePass(P, Msg, DBG_STR);
1050 if (
const PassInfo *PInf = TPM->findAnalysisPassInfo(PI)) {
1052 AvailableAnalysis.erase(PI);
1056 const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
1057 for (
unsigned i = 0, e = II.size(); i != e; ++i) {
1059 AvailableAnalysis.find(II[i]->getTypeInfo());
1060 if (Pos != AvailableAnalysis.end() && Pos->second ==
P)
1061 AvailableAnalysis.erase(Pos);
1078 if (!ProcessAnalysis) {
1089 unsigned PDepth = this->getDepth();
1091 collectRequiredAndUsedAnalyses(UsedPasses, ReqAnalysisNotAvailable, P);
1092 for (
Pass *PUsed : UsedPasses) {
1093 unsigned RDepth = 0;
1095 assert(PUsed->getResolver() &&
"Analysis Resolver is not set");
1096 PMDataManager &DM = PUsed->getResolver()->getPMDataManager();
1097 RDepth = DM.getDepth();
1099 if (PDepth == RDepth)
1101 else if (PDepth > RDepth) {
1105 HigherLevelAnalysis.push_back(PUsed);
1115 TPM->setLastUser(LastUses, P);
1117 if (!TransferLastUses.
empty()) {
1118 Pass *My_PM = getAsPass();
1119 TPM->setLastUser(TransferLastUses, My_PM);
1120 TransferLastUses.
clear();
1125 const PassInfo *PI = TPM->findAnalysisPassInfo(
ID);
1127 this->addLowerLevelRequiredPass(P, AnalysisPass);
1132 removeNotPreservedAnalysis(P);
1133 recordAvailableAnalysis(P);
1136 PassVector.push_back(P);
1148 for (
const auto &UsedID : AnUsage->
getUsedSet())
1149 if (
Pass *AnalysisPass = findAnalysisPass(UsedID,
true))
1153 if (
Pass *AnalysisPass = findAnalysisPass(RequiredID,
true))
1159 if (
Pass *AnalysisPass = findAnalysisPass(RequiredID,
true))
1174 Pass *Impl = findAnalysisPass(
ID,
true);
1180 assert(AR &&
"Analysis Resolver is not set");
1192 if (I != AvailableAnalysis.end())
1197 return TPM->findAnalysisPass(AID);
1211 TPM->collectLastUses(LUses, P);
1213 for (
Pass *P : LUses) {
1214 dbgs() <<
"--" << std::string(Offset*2,
' ');
1220 for (
Pass *
P : PassVector) {
1222 PMD->dumpPassArguments();
1225 TPM->findAnalysisPassInfo(
P->getPassID()))
1226 if (!PI->isAnalysisGroup())
1227 dbgs() <<
" -" << PI->getPassArgument();
1234 if (PassDebugging < Executions)
1237 << std::string(getDepth() * 2 + 1,
' ');
1253 dbgs() <<
"' on BasicBlock '" << Msg <<
"'...\n";
1256 dbgs() <<
"' on Function '" << Msg <<
"'...\n";
1259 dbgs() <<
"' on Module '" << Msg <<
"'...\n";
1262 dbgs() <<
"' on Region '" << Msg <<
"'...\n";
1265 dbgs() <<
"' on Loop '" << Msg <<
"'...\n";
1268 dbgs() <<
"' on Call Graph Nodes '" << Msg <<
"'...\n";
1276 if (PassDebugging < Details)
1281 dumpAnalysisUsage(
"Required", P, analysisUsage.
getRequiredSet());
1285 if (PassDebugging < Details)
1294 if (PassDebugging < Details)
1299 dumpAnalysisUsage(
"Used", P, analysisUsage.
getUsedSet());
1302 void PMDataManager::dumpAnalysisUsage(
StringRef Msg,
const Pass *
P,
1304 assert(PassDebugging >= Details);
1307 dbgs() << (
const void*)P << std::string(getDepth()*2+3,
' ') << Msg <<
" Analyses:";
1308 for (
unsigned i = 0; i != Set.
size(); ++i) {
1309 if (i)
dbgs() <<
',';
1310 const PassInfo *PInf = TPM->findAnalysisPassInfo(Set[i]);
1314 dbgs() <<
" Uninitialized Pass";
1328 TPM->dumpArguments();
1354 for (
Pass *P : PassVector)
1362 return PM.findAnalysisPass(ID, dir);
1367 return PM.getOnTheFlyPass(P, AnalysisPI, F);
1380 bool Changed = doInitialization(F);
1387 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1395 bool LocalChanged =
false;
1398 dumpRequiredSet(BP);
1400 initializeAnalysisImpl(BP);
1408 unsigned NewSize = BB.size();
1411 if (NewSize != BBSize) {
1413 static_cast<int64_t
>(NewSize) - static_cast<int64_t>(BBSize);
1414 emitInstrCountChangedRemark(BP, M, Delta, InstrCount,
1415 FunctionToInstrCount, &F);
1416 InstrCount =
static_cast<int64_t
>(
InstrCount) + Delta;
1422 Changed |= LocalChanged;
1426 dumpPreservedSet(BP);
1429 verifyPreservedAnalysis(BP);
1430 removeNotPreservedAnalysis(BP);
1431 recordAvailableAnalysis(BP);
1436 return doFinalization(F) || Changed;
1440 bool BBPassManager::doInitialization(
Module &M) {
1441 bool Changed =
false;
1444 Changed |= getContainedPass(
Index)->doInitialization(M);
1449 bool BBPassManager::doFinalization(
Module &M) {
1450 bool Changed =
false;
1453 Changed |= getContainedPass(
Index)->doFinalization(M);
1458 bool BBPassManager::doInitialization(
Function &F) {
1459 bool Changed =
false;
1469 bool BBPassManager::doFinalization(
Function &F) {
1470 bool Changed =
false;
1530 bool Changed =
false;
1536 Changed |= ImPass->doInitialization(M);
1539 Changed |= getContainedManager(
Index)->doInitialization(M);
1545 bool Changed =
false;
1548 Changed |= getContainedManager(
Index)->doFinalization(M);
1551 Changed |= ImPass->doFinalization(M);
1561 assert(AR &&
"Analysis Resolver is not set");
1569 for (
unsigned Index = 0;
Index < getNumContainedManagers(); ++
Index) {
1581 bool Changed =
false;
1583 initializeAllAnalysisInfo();
1584 for (
unsigned Index = 0;
Index < getNumContainedManagers(); ++
Index) {
1585 Changed |= getContainedManager(
Index)->runOnFunction(F);
1590 getContainedManager(
Index)->cleanup();
1602 dbgs().
indent(Offset*2) <<
"FunctionPass Manager\n";
1606 dumpLastUses(FP, Offset+1);
1618 bool Changed =
false;
1621 populateInheritedAnalysis(TPM->activeStack);
1628 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1634 bool LocalChanged =
false;
1637 dumpRequiredSet(FP);
1639 initializeAnalysisImpl(FP);
1650 if (NewSize != FunctionSize) {
1651 int64_t Delta =
static_cast<int64_t
>(NewSize) -
1652 static_cast<int64_t>(FunctionSize);
1653 emitInstrCountChangedRemark(FP, M, Delta, InstrCount,
1654 FunctionToInstrCount, &F);
1655 InstrCount =
static_cast<int64_t
>(
InstrCount) + Delta;
1656 FunctionSize = NewSize;
1661 Changed |= LocalChanged;
1664 dumpPreservedSet(FP);
1667 verifyPreservedAnalysis(FP);
1668 removeNotPreservedAnalysis(FP);
1669 recordAvailableAnalysis(FP);
1676 bool Changed =
false;
1685 bool Changed =
false;
1688 Changed |= getContainedPass(
Index)->doInitialization(M);
1694 bool Changed =
false;
1697 Changed |= getContainedPass(
Index)->doFinalization(M);
1709 MPPassManager::runOnModule(
Module &M) {
1710 bool Changed =
false;
1713 for (
auto &OnTheFlyManager : OnTheFlyManagers) {
1720 Changed |= getContainedPass(
Index)->doInitialization(M);
1727 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1733 bool LocalChanged =
false;
1736 dumpRequiredSet(MP);
1738 initializeAnalysisImpl(MP);
1748 if (ModuleCount != InstrCount) {
1749 int64_t Delta =
static_cast<int64_t
>(ModuleCount) -
1750 static_cast<int64_t>(InstrCount);
1751 emitInstrCountChangedRemark(MP, M, Delta, InstrCount,
1752 FunctionToInstrCount);
1753 InstrCount = ModuleCount;
1758 Changed |= LocalChanged;
1762 dumpPreservedSet(MP);
1765 verifyPreservedAnalysis(MP);
1766 removeNotPreservedAnalysis(MP);
1767 recordAvailableAnalysis(MP);
1773 Changed |= getContainedPass(
Index)->doFinalization(M);
1776 for (
auto &OnTheFlyManager : OnTheFlyManagers) {
1790 void MPPassManager::addLowerLevelRequiredPass(
Pass *P,
Pass *RequiredPass) {
1792 "Unable to handle Pass that requires lower level Analysis pass");
1795 "Unable to handle Pass that requires lower level Analysis pass");
1805 OnTheFlyManagers[
P] = FPP;
1808 TPM->findAnalysisPassInfo(RequiredPass->
getPassID());
1810 Pass *FoundPass =
nullptr;
1811 if (RequiredPassPI && RequiredPassPI->
isAnalysis()) {
1816 FoundPass = RequiredPass;
1819 FPP->
add(RequiredPass);
1832 assert(FPP &&
"Unable to find on the fly pass");
1847 bool Changed =
false;
1853 Changed |= ImPass->doInitialization(M);
1855 initializeAllAnalysisInfo();
1856 for (
unsigned Index = 0;
Index < getNumContainedManagers(); ++
Index) {
1857 Changed |= getContainedManager(
Index)->runOnModule(M);
1862 Changed |= ImPass->doFinalization(M);
1874 PM->setTopLevelManager(PM);
1906 assert(PM &&
"Unable to push. Pass Manager expected");
1909 if (!this->
empty()) {
1911 &&
"pushing bad pass manager to PMStack");
1914 assert(TPM &&
"Unable to find top level manager");
1915 TPM->addIndirectPassManager(PM);
1917 PM->
setDepth(this->top()->getDepth()+1);
1921 &&
"pushing bad pass manager to PMStack");
1931 dbgs() << Manager->getAsPass()->getPassName() <<
' ';
1942 while (!PMS.
empty()) {
1944 if (TopPMType == PreferredType)
1951 assert(!PMS.
empty() &&
"Unable to find appropriate Pass Manager");
1961 while (!PMS.
empty()) {
1973 assert(!PMS.
empty() &&
"Unable to create Function Pass Manager");
2006 BBP = (BBPassManager *)PMS.
top();
2010 assert(!PMS.
empty() &&
"Unable to create BasicBlock Pass Manager");
2014 BBP =
new BBPassManager();
2023 BBP->assignPassManager(PMS, PreferredType);
Pass interface - Implemented by all 'passes'.
const PassInfo * getPassInfo(const void *TI) const
getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass' type identifier (&MyPass::...
bool preserveHigherLevelAnalysis(Pass *P)
const_iterator end(StringRef path)
Get end iterator over path.
PassManagerType
Different types of internal pass managers.
bool shouldPrintAfterPass()
void initializeAllAnalysisInfo()
bool forcePrintModuleIR()
forcePrintModuleIR - returns true if IR printing passes should
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Pass * findAnalysisPass(AnalysisID AID, bool Direction)
Find the pass that implements Analysis AID.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
virtual PMDataManager * getAsPMDataManager()
virtual void dumpPassStructure(unsigned Offset=0)
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on...
void dumpLastUses(Pass *P, unsigned Offset) const
A Module instance is used to store all the information related to an LLVM module. ...
FunctionPassManagerImpl manages FPPassManagers.
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
virtual void releaseMemory()
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
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...
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in this function.
void push_back(const T &Elt)
bool shouldPrintBeforePass()
This is a helper to determine whether to print IR before or after a pass.
static cl::opt< enum PassDebugLevel > PassDebugging("debug-pass", cl::Hidden, cl::desc("Print 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")))
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...
virtual bool doInitialization(Function &)
doInitialization - Virtual method overridden by BasicBlockPass subclasses to do any necessary per-fun...
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
PMDataManager * getAsPMDataManager() override
static PassOptionList PrintBefore("print-before", llvm::cl::desc("Print IR before specified passes"), cl::Hidden)
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...
This class implements a map that also provides access to all stored values in a deterministic order...
const VectorType & getUsedSet() const
void yield()
Calls the yield callback (if applicable).
Pass * getAsPass() override
static unsigned InstrCount
const VectorType & getRequiredSet() const
PMTopLevelManager(PMDataManager *PMDM)
Initialize top level manager. Create first pass manager.
AnalysisResolver * getResolver() const
virtual void preparePassManager(PMStack &)
Check if available pass managers are suitable for this pass or not.
Base class for error info classes.
void dumpPassInfo(Pass *P, enum PassDebuggingString S1, enum PassDebuggingString S2, StringRef Msg)
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
virtual void initializePass()
initializePass - This method may be overriden by immutable passes to allow them to perform various in...
void setResolver(AnalysisResolver *AR)
PMTopLevelManager manages LastUser info and collects common APIs used by top level pass managers...
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
void setDepth(unsigned newDepth)
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
AnalysisResolver - Simple interface used by Pass objects to pull all analysis information out of pass...
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
void schedulePass(Pass *P)
Schedule pass P for execution.
void dumpPassArguments() const
void add(Pass *P) override
Add a pass to the queue of passes to run.
virtual PassManagerType getPotentialPassManagerType() const
Return what kind of Pass Manager can manage this pass.
void freePass(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove P.
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
LLVMContext & getContext() const
Get the global data context.
virtual ~PMTopLevelManager()
Destructor.
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
unsigned getInstructionCount()
Returns the number of non-debug IR instructions in the module.
void verifyPreservedAnalysis(Pass *P)
verifyPreservedAnalysis – Verify analysis presreved by pass P.
static const PassInfo * getPassInfo(StringRef PassName)
void initializeAnalysisInfo()
Initialize available analysis information.
static cl::opt< bool > PrintModuleScope("print-module-scope", cl::desc("When printing IR for print-[before|after]{-all} " "always print a module IR"), cl::init(false), cl::Hidden)
virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass)
Add RequiredPass into list of lower level passes required by pass P.
const VectorType & getPreservedSet() const
void populateInheritedAnalysis(PMStack &PMS)
This header defines classes/functions to handle pass execution timing information with interfaces for...
FPPassManager manages BBPassManagers and FunctionPasses.
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
void initializeAnalysisImpl(Pass *P)
All Required analyses should be available to the pass as it runs! Here we fill in the AnalysisImpls m...
#define clEnumVal(ENUMVAL, DESC)
PassManagerPrettyStackEntry - This is used to print informative information about what pass is runnin...
void assignPassManager(PMStack &PMS, PassManagerType T) override
Find appropriate Module Pass Manager in the PM Stack and add self into that manager.
bool isPassDebuggingExecutionsOrMore() const
isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions or higher is specified...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
PassManagerType getTopLevelPassManagerType() override
void add(Pass *P, bool ProcessAnalysis=true)
Add pass P into the PassVector.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
PassManagerType getTopLevelPassManagerType() override
void add(Pass *P) override
Add a pass to the queue of passes to run.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
virtual Pass * getAsPass()=0
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
virtual bool doFinalization(Function &)
doFinalization - Virtual method overriden by BasicBlockPass subclasses to do any post processing need...
bool run(Function &F)
run - Execute all of the passes scheduled for execution.
virtual ImmutablePass * getAsImmutablePass()
Analysis containing CSE Info
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
iterator find(const_arg_type_t< KeyT > Val)
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
void dumpUsedSet(const Pass *P) const
static PassOptionList PrintAfter("print-after", llvm::cl::desc("Print IR after specified passes"), cl::Hidden)
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
void assignPassManager(PMStack &PMS, PassManagerType T) override
Find appropriate Basic Pass Manager or Call Graph Pass Manager in the PM Stack and add self into that...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
FPPassManager * getContainedManager(unsigned N)
LLVM Basic Block Representation.
void print(raw_ostream &OS) const override
print - Emit information about this stack frame to OS.
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
void releaseMemoryOnTheFly()
bool shouldEmitInstrCountChangedRemark()
Return true if size-info optimization remark is enabled, false otherwise.
void addIndirectPassManager(PMDataManager *Manager)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Pass * getAsPass() override
virtual PassManagerType getPassManagerType() const
void collectLastUses(SmallVectorImpl< Pass *> &LastUses, Pass *P)
Collect passes whose last user is P.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
AMDGPU Lower Kernel Arguments
static sys::TimePoint< std::chrono::seconds > now(bool Deterministic)
const PassInfo * findAnalysisPassInfo(AnalysisID AID) const
Retrieve the PassInfo for an analysis.
Represent the analysis usage information of a pass.
PassManagerImpl manages MPPassManagers.
FunctionPass class - This class is used to implement most global optimizations.
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Pass * getAnalysisIfAvailable(AnalysisID ID, bool Direction) const
Return analysis result or null if it doesn't exist.
Error materialize()
Make sure this GlobalValue is fully read.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
PassInfo class - An instance of this class exists for every pass known by the system, and can be obtained from a live Pass by calling its getPassInfo() method.
Used in the streaming interface as the general argument type.
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
BasicBlockPass class - This class is used to implement most local optimizations.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on...
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
void addImmutablePass(ImmutablePass *P)
Add immutable pass and initialize it.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
void dumpArguments() const
print lazy value Lazy Value Info Printer Pass
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
virtual ~PassManagerBase()
ImmutablePass class - This class is used to provide information that does not need to be run...
void recordAvailableAnalysis(Pass *P)
Augment AvailableAnalysis by adding analysis made available by pass P.
FunctionPassManagerImpl()
FunctionPassManager(Module *M)
FunctionPassManager ctor - This initializes the pass manager.
void dumpRequiredSet(const Pass *P) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void removeNotPreservedAnalysis(Pass *P)
Remove Analysis that is not preserved by the pass.
Module.h This file contains the declarations for the Module class.
typename VectorType::const_iterator const_iterator
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...
PMDataManager * getAsPMDataManager() override
void addAnalysisImplsPair(AnalysisID PI, Pass *P)
bool runOnFunction(Function &F)
run - Execute all of the passes scheduled for execution.
bool doFinalization()
doFinalization - Run all of the finalizers for the function passes.
void removeDeadPasses(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove dead passes used by P.
virtual Pass * getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F)
bool isFunctionInPrintList(StringRef FunctionName)
isFunctionInPrintList - returns true if a function should be printed via
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
static bool ShouldPrintBeforeOrAfterPass(StringRef PassID, PassOptionList &PassesToPrint)
void clearAnalysisImpls()
Clear cache that is used to connect a pass to the analysis (PassInfo).
Pass * createPass() const
createPass() - Use this method to create an instance of this pass.
Pass * findImplPass(AnalysisID PI)
Find pass that is implementing PI.
void setPreservesAll()
Set by analyses that do not transform their input at all.
const VectorType & getRequiredTransitiveSet() const
AnalysisUsage * findAnalysisUsage(Pass *P)
Find analysis usage information for the pass P.
void add(Pass *P)
Add a pass to the queue of passes to run.
void setTopLevelManager(PMTopLevelManager *T)
void setLastUser(ArrayRef< Pass *> AnalysisPasses, Pass *P)
Set pass P as the last user of the given analysis passes.
Manages a sequence of passes over a particular unit of IR.
LLVM_NODISCARD bool empty() const
PMDataManager & getPMDataManager()
FunctionPass * getContainedPass(unsigned N)
static cl::opt< bool > PrintBeforeAll("print-before-all", llvm::cl::desc("Print IR before each pass"), cl::init(false), cl::Hidden)
StringRef getName() const
Return a constant reference to the value's name.
StringRef getPassName() const
getPassName - Return the friendly name for the pass, never returns null
void cleanup()
cleanup - After running all passes, clean up pass manager cache.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
void push(PMDataManager *PM)
PMDataManager provides the common place to manage the analysis data used by pass managers.
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.
This file defines passes to print out IR in various granularities.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Pass * findAnalysisPass(AnalysisID AID)
Find the pass that implements Analysis AID.
void add(Pass *P)
Add a pass to the queue of passes to run.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
~FunctionPassManager() override
PMDataManager * top() const
Module * getParent()
Get the module that this global value is contained inside of...
virtual Pass * createPrinterPass(raw_ostream &OS, const std::string &Banner) const =0
createPrinterPass - Get a Pass appropriate to print the IR this pass operates on (Module, Function or MachineFunction).
bool run(Function &F)
run - Execute all of the passes scheduled for execution.
MPPassManager * getContainedManager(unsigned N)
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
const std::vector< const PassInfo * > & getInterfacesImplemented() const
getInterfacesImplemented - Return a list of all of the analysis group interfaces implemented by this ...
virtual bool runOnBasicBlock(BasicBlock &BB)=0
runOnBasicBlock - Virtual method overriden by subclasses to do the per-basicblock processing of the p...
unsigned getNumContainedPasses() const
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to 'opt' that will cause this pas...
This class implements an extremely fast bulk output stream that can only output to a stream...
bool doInitialization()
doInitialization - Run all of the initializers for the function passes.
StringRef - Represent a constant reference to a string, i.e.
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a module printer pass.
PassManager()
Create new pass manager.
static cl::list< std::string > PrintFuncsList("filter-print-funcs", cl::value_desc("function names"), cl::desc("Only print IR for functions whose name " "match this for all print-[before|after][-all] " "options"), cl::CommaSeparated, cl::Hidden)
UnaryPredicate for_each(R &&Range, UnaryPredicate P)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly...
static cl::opt< bool > PrintAfterAll("print-after-all", llvm::cl::desc("Print IR after each pass"), cl::init(false), cl::Hidden)
unsigned getDepth() const
bool getPreservesAll() const
Determine whether a pass said it does not transform its input at all.
void dumpPreservedSet(const Pass *P) const
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a function printer pass.
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.
virtual void assignPassManager(PMStack &, PassManagerType)
Each pass is responsible for assigning a pass manager to itself.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.