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);
326 virtual void anchor();
342 const std::string &Banner)
const override {
348 void releaseMemoryOnTheFly();
356 bool doInitialization(
Module &M)
override;
360 bool doFinalization(
Module &M)
override;
375 assert(N < PassManagers.size() &&
"Pass number out of range!");
381 for (
unsigned I = 0;
I < getNumContainedManagers(); ++
I)
382 getContainedManager(
I)->dumpPassStructure(Offset);
386 void FunctionPassManagerImpl::anchor() {}
402 explicit MPPassManager() :
406 ~MPPassManager()
override {
407 for (
auto &OnTheFlyManager : OnTheFlyManagers) {
415 const std::string &Banner)
const override {
421 bool runOnModule(
Module &M);
434 void addLowerLevelRequiredPass(
Pass *
P,
Pass *RequiredPass)
override;
441 StringRef getPassName()
const override {
return "Module Pass Manager"; }
443 PMDataManager *getAsPMDataManager()
override {
return this; }
444 Pass *getAsPass()
override {
return this; }
447 void dumpPassStructure(
unsigned Offset)
override {
448 dbgs().
indent(Offset*2) <<
"ModulePass Manager\n";
453 OnTheFlyManagers.find(MP);
454 if (I != OnTheFlyManagers.
end())
455 I->second->dumpPassStructure(Offset + 2);
456 dumpLastUses(MP, Offset+1);
461 assert(N < PassVector.size() &&
"Pass number out of range!");
488 virtual void anchor();
503 const std::string &Banner)
const override {
526 assert(N < PassManagers.size() &&
"Pass number out of range!");
527 MPPassManager *MP =
static_cast<MPPassManager *
>(PassManagers[
N]);
532 void PassManagerImpl::anchor() {}
544 addPassManager(PMDM);
545 activeStack.push(PMDM);
555 for (
Pass *AP : AnalysisPasses) {
567 Pass *AnalysisPass = findAnalysisPass(
ID);
568 assert(AnalysisPass &&
"Expected analysis pass to exist.");
570 assert(AR &&
"Expected analysis resolver to exist.");
573 if (PDepth == APDepth)
575 else if (PDepth > APDepth)
579 setLastUser(LastUses, P);
589 for (
auto LU : LastUser) {
593 LastUser[LU.first] =
P;
602 InversedLastUser.
find(P);
603 if (DMI == InversedLastUser.
end())
607 for (
Pass *LUP : LU) {
615 auto DMI = AnUsageMap.find(P);
616 if (DMI != AnUsageMap.end())
617 AnUsage = DMI->second;
628 AUFoldingSetNode* Node =
nullptr;
630 AUFoldingSetNode::Profile(ID, AU);
632 if (
auto *
N = UniqueAnalysisUsages.FindNodeOrInsertPos(ID, IP))
635 Node =
new (AUFoldingSetNodeAllocator.Allocate()) AUFoldingSetNode(AU);
636 UniqueAnalysisUsages.InsertNode(Node, IP);
638 assert(Node &&
"cached analysis usage must be non null");
640 AnUsageMap[
P] = &Node->AU;
670 bool checkAnalysis =
true;
671 while (checkAnalysis) {
672 checkAnalysis =
false;
677 Pass *AnalysisPass = findAnalysisPass(
ID);
679 const PassInfo *PI = findAnalysisPassInfo(
ID);
683 dbgs() <<
"Pass '" << P->
getPassName() <<
"' is not initialized." <<
"\n";
684 dbgs() <<
"Verify if there is a pass dependency cycle." <<
"\n";
685 dbgs() <<
"Required Passes:" <<
"\n";
689 Pass *AnalysisPass2 = findAnalysisPass(ID2);
693 dbgs() <<
"\t" <<
"Error: Required pass not found! Possible causes:" <<
"\n";
694 dbgs() <<
"\t\t" <<
"- Pass misconfiguration (e.g.: missing macros)" <<
"\n";
695 dbgs() <<
"\t\t" <<
"- Corruption of the global PassRegistry" <<
"\n";
700 assert(PI &&
"Expected required passes to be initialized");
705 schedulePass(AnalysisPass);
709 schedulePass(AnalysisPass);
712 checkAnalysis =
true;
729 addImmutablePass(IP);
756 if (
Pass *
P = ImmutablePassMap.lookup(AID))
765 for (
PMDataManager *IndirectPassManager : IndirectPassManagers)
766 if (
Pass *
P = IndirectPassManager->findAnalysisPass(AID,
false))
773 const PassInfo *&PI = AnalysisPassInfos[AID];
778 "The pass info pointer changed for an analysis ID!");
785 ImmutablePasses.push_back(P);
791 ImmutablePassMap[AID] =
P;
795 const PassInfo *PassInf = findAnalysisPassInfo(AID);
796 assert(PassInf &&
"Expected all immutable passes to be initialized");
798 ImmutablePassMap[ImmPI->getTypeInfo()] =
P;
804 if (PassDebugging < Structure)
808 for (
unsigned i = 0,
e = ImmutablePasses.size(); i !=
e; ++i) {
809 ImmutablePasses[i]->dumpPassStructure(0);
817 Manager->getAsPass()->dumpPassStructure(1);
825 dbgs() <<
"Pass Arguments: ";
827 if (
const PassInfo *PI = findAnalysisPassInfo(
P->getPassID())) {
828 assert(PI &&
"Expected all immutable passes to be initialized");
829 if (!PI->isAnalysisGroup())
830 dbgs() <<
" -" << PI->getPassArgument();
833 PM->dumpPassArguments();
839 PM->initializeAnalysisInfo();
843 IPM->initializeAnalysisInfo();
845 for (
auto LU : LastUser) {
867 AvailableAnalysis[PI] =
P;
869 assert(!AvailableAnalysis.empty());
873 const PassInfo *PInf = TPM->findAnalysisPassInfo(PI);
876 for (
unsigned i = 0,
e = II.size(); i !=
e; ++i)
877 AvailableAnalysis[II[i]->getTypeInfo()] =
P;
888 for (
Pass *P1 : HigherLevelAnalysis) {
889 if (P1->getAsImmutablePass() ==
nullptr &&
908 if (
Pass *AP = findAnalysisPass(AID,
true)) {
910 AP->verifyAnalysis();
923 E = AvailableAnalysis.end();
I !=
E; ) {
925 if (Info->second->getAsImmutablePass() ==
nullptr &&
928 if (PassDebugging >= Details) {
929 Pass *S = Info->second;
933 AvailableAnalysis.erase(Info);
941 if (!InheritedAnalysis[
Index])
945 I = InheritedAnalysis[Index]->
begin(),
946 E = InheritedAnalysis[Index]->
end();
I !=
E; ) {
948 if (Info->second->getAsImmutablePass() ==
nullptr &&
951 if (PassDebugging >= Details) {
952 Pass *S = Info->second;
956 InheritedAnalysis[
Index]->erase(Info);
972 TPM->collectLastUses(DeadPasses, P);
974 if (PassDebugging >= Details && !DeadPasses.
empty()) {
976 dbgs() <<
"' is the last user of following pass instances.";
977 dbgs() <<
" Free these instances\n";
980 for (
Pass *P : DeadPasses)
981 freePass(P, Msg, DBG_STR);
997 if (
const PassInfo *PInf = TPM->findAnalysisPassInfo(PI)) {
999 AvailableAnalysis.erase(PI);
1003 const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
1004 for (
unsigned i = 0,
e = II.size(); i !=
e; ++i) {
1006 AvailableAnalysis.find(II[i]->getTypeInfo());
1007 if (Pos != AvailableAnalysis.end() && Pos->second ==
P)
1008 AvailableAnalysis.erase(Pos);
1025 if (!ProcessAnalysis) {
1036 unsigned PDepth = this->
getDepth();
1038 collectRequiredAndUsedAnalyses(UsedPasses, ReqAnalysisNotAvailable, P);
1039 for (
Pass *PUsed : UsedPasses) {
1040 unsigned RDepth = 0;
1042 assert(PUsed->getResolver() &&
"Analysis Resolver is not set");
1044 RDepth = DM.getDepth();
1046 if (PDepth == RDepth)
1048 else if (PDepth > RDepth) {
1052 HigherLevelAnalysis.push_back(PUsed);
1062 TPM->setLastUser(LastUses, P);
1064 if (!TransferLastUses.
empty()) {
1065 Pass *My_PM = getAsPass();
1066 TPM->setLastUser(TransferLastUses, My_PM);
1067 TransferLastUses.
clear();
1072 const PassInfo *PI = TPM->findAnalysisPassInfo(
ID);
1074 this->addLowerLevelRequiredPass(P, AnalysisPass);
1079 removeNotPreservedAnalysis(P);
1080 recordAvailableAnalysis(P);
1083 PassVector.push_back(P);
1095 for (
const auto &UsedID : AnUsage->
getUsedSet())
1096 if (
Pass *AnalysisPass = findAnalysisPass(UsedID,
true))
1100 if (
Pass *AnalysisPass = findAnalysisPass(RequiredID,
true))
1106 if (
Pass *AnalysisPass = findAnalysisPass(RequiredID,
true))
1121 Pass *Impl = findAnalysisPass(
ID,
true);
1127 assert(AR &&
"Analysis Resolver is not set");
1139 if (I != AvailableAnalysis.end())
1144 return TPM->findAnalysisPass(AID);
1158 TPM->collectLastUses(LUses, P);
1160 for (
Pass *P : LUses) {
1161 dbgs() <<
"--" << std::string(Offset*2,
' ');
1167 for (
Pass *
P : PassVector) {
1169 PMD->dumpPassArguments();
1172 TPM->findAnalysisPassInfo(
P->getPassID()))
1173 if (!PI->isAnalysisGroup())
1174 dbgs() <<
" -" << PI->getPassArgument();
1181 if (PassDebugging < Executions)
1184 << std::string(
getDepth() * 2 + 1,
' ');
1200 dbgs() <<
"' on Function '" << Msg <<
"'...\n";
1203 dbgs() <<
"' on Module '" << Msg <<
"'...\n";
1206 dbgs() <<
"' on Region '" << Msg <<
"'...\n";
1209 dbgs() <<
"' on Loop '" << Msg <<
"'...\n";
1212 dbgs() <<
"' on Call Graph Nodes '" << Msg <<
"'...\n";
1220 if (PassDebugging < Details)
1225 dumpAnalysisUsage(
"Required", P, analysisUsage.
getRequiredSet());
1229 if (PassDebugging < Details)
1238 if (PassDebugging < Details)
1243 dumpAnalysisUsage(
"Used", P, analysisUsage.
getUsedSet());
1246 void PMDataManager::dumpAnalysisUsage(
StringRef Msg,
const Pass *
P,
1248 assert(PassDebugging >= Details);
1251 dbgs() << (
const void*)P << std::string(
getDepth()*2+3,
' ') << Msg <<
" Analyses:";
1252 for (
unsigned i = 0; i != Set.
size(); ++i) {
1253 if (i)
dbgs() <<
',';
1254 const PassInfo *PInf = TPM->findAnalysisPassInfo(Set[i]);
1258 dbgs() <<
" Uninitialized Pass";
1272 TPM->dumpArguments();
1298 for (
Pass *P : PassVector)
1306 return PM.findAnalysisPass(ID, dir);
1311 return PM.getOnTheFlyPass(P, AnalysisPI, F);
1363 bool Changed =
false;
1369 Changed |= ImPass->doInitialization(M);
1372 Changed |= getContainedManager(
Index)->doInitialization(M);
1378 bool Changed =
false;
1381 Changed |= getContainedManager(
Index)->doFinalization(M);
1384 Changed |= ImPass->doFinalization(M);
1394 assert(AR &&
"Analysis Resolver is not set");
1402 for (
unsigned Index = 0;
Index < getNumContainedManagers(); ++
Index) {
1414 bool Changed =
false;
1416 initializeAllAnalysisInfo();
1417 for (
unsigned Index = 0;
Index < getNumContainedManagers(); ++
Index) {
1418 Changed |= getContainedManager(
Index)->runOnFunction(F);
1423 getContainedManager(
Index)->cleanup();
1435 dbgs().
indent(Offset*2) <<
"FunctionPass Manager\n";
1439 dumpLastUses(FP, Offset+1);
1451 bool Changed =
false;
1454 populateInheritedAnalysis(TPM->activeStack);
1461 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1469 bool LocalChanged =
false;
1474 dumpRequiredSet(FP);
1476 initializeAnalysisImpl(FP);
1487 if (NewSize != FunctionSize) {
1488 int64_t Delta =
static_cast<int64_t
>(NewSize) -
1489 static_cast<int64_t>(FunctionSize);
1490 emitInstrCountChangedRemark(FP, M, Delta, InstrCount,
1491 FunctionToInstrCount, &F);
1492 InstrCount =
static_cast<int64_t
>(
InstrCount) + Delta;
1493 FunctionSize = NewSize;
1498 Changed |= LocalChanged;
1501 dumpPreservedSet(FP);
1504 verifyPreservedAnalysis(FP);
1505 removeNotPreservedAnalysis(FP);
1506 recordAvailableAnalysis(FP);
1514 bool Changed =
false;
1523 bool Changed =
false;
1526 Changed |= getContainedPass(
Index)->doInitialization(M);
1532 bool Changed =
false;
1535 Changed |= getContainedPass(
Index)->doFinalization(M);
1547 MPPassManager::runOnModule(
Module &M) {
1550 bool Changed =
false;
1553 for (
auto &OnTheFlyManager : OnTheFlyManagers) {
1560 Changed |= getContainedPass(
Index)->doInitialization(M);
1567 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1571 bool LocalChanged =
false;
1574 dumpRequiredSet(MP);
1576 initializeAnalysisImpl(MP);
1586 if (ModuleCount != InstrCount) {
1587 int64_t Delta =
static_cast<int64_t
>(ModuleCount) -
1588 static_cast<int64_t>(InstrCount);
1589 emitInstrCountChangedRemark(MP, M, Delta, InstrCount,
1590 FunctionToInstrCount);
1591 InstrCount = ModuleCount;
1596 Changed |= LocalChanged;
1600 dumpPreservedSet(MP);
1603 verifyPreservedAnalysis(MP);
1604 removeNotPreservedAnalysis(MP);
1605 recordAvailableAnalysis(MP);
1611 Changed |= getContainedPass(
Index)->doFinalization(M);
1614 for (
auto &OnTheFlyManager : OnTheFlyManagers) {
1628 void MPPassManager::addLowerLevelRequiredPass(
Pass *P,
Pass *RequiredPass) {
1629 assert(RequiredPass &&
"No required pass?");
1631 "Unable to handle Pass that requires lower level Analysis pass");
1634 "Unable to handle Pass that requires lower level Analysis pass");
1642 OnTheFlyManagers[
P] = FPP;
1645 TPM->findAnalysisPassInfo(RequiredPass->
getPassID());
1647 Pass *FoundPass =
nullptr;
1648 if (RequiredPassPI && RequiredPassPI->
isAnalysis()) {
1653 FoundPass = RequiredPass;
1656 FPP->
add(RequiredPass);
1669 assert(FPP &&
"Unable to find on the fly pass");
1684 bool Changed =
false;
1690 Changed |= ImPass->doInitialization(M);
1692 initializeAllAnalysisInfo();
1693 for (
unsigned Index = 0;
Index < getNumContainedManagers(); ++
Index) {
1694 Changed |= getContainedManager(
Index)->runOnModule(M);
1699 Changed |= ImPass->doFinalization(M);
1711 PM->setTopLevelManager(PM);
1743 assert(PM &&
"Unable to push. Pass Manager expected");
1746 if (!this->
empty()) {
1748 &&
"pushing bad pass manager to PMStack");
1751 assert(TPM &&
"Unable to find top level manager");
1752 TPM->addIndirectPassManager(PM);
1758 &&
"pushing bad pass manager to PMStack");
1768 dbgs() << Manager->getAsPass()->getPassName() <<
' ';
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.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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.
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler...
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...
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...
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
StringRef getName() const
Get a short "name" for the module.
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.
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)
* 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.
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.
static unsigned getDepth(const SmallVectorImpl< const MachineBasicBlock *> &Stack, const MachineBasicBlock *MBB)
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())
void dumpPassStructure(unsigned Offset) override
~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 ...
unsigned getNumContainedPasses() const
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to 'opt' that will cause this pas...
PMTopLevelManager * getTopLevelManager()
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.