llvm.org GIT mirror llvm / 7d4e993
Encapsulate PassManager debug flags to avoid static init and cxa_exit. This puts all the global PassManager debugging flags, like -print-after-all and -time-passes, behind a managed static. This eliminates their static initializers and, more importantly, exit-time destructors. The only behavioral change I anticipate is that tools need to initialize the PassManager before parsing the command line in order to export these options, which makes sense. Tools that already initialize the standard passes (opt/llc) don't need to do anything new. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190974 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 6 years ago
11 changed file(s) with 140 addition(s) and 78 deletion(s). Raw diff Collapse all Expand all
2626
2727 class PassManagerImpl;
2828 class FunctionPassManagerImpl;
29
30 /// Called by tools to initialize globals and register options at a particular
31 /// point (before command line parsing). If this is not called, then PassManager
32 /// globals are lazily initialized at first use.
33 void initializePassManager();
2934
3035 /// PassManagerBase - An abstract interface to allow code to add passes to
3136 /// a pass manager without having to hard-code what kind of pass manager
3939 using namespace llvm;
4040
4141 void llvm::initializeCore(PassRegistry &Registry) {
42 initializePassManager();
4243 initializeDominatorTreePass(Registry);
4344 initializePrintModulePassPass(Registry);
4445 initializePrintFunctionPassPass(Registry);
4444 Disabled, Arguments, Structure, Executions, Details
4545 };
4646
47 static cl::opt
48 PassDebugging("debug-pass", cl::Hidden,
47 bool TimePassesIsEnabled = false;
48
49 /// Encapsulate PassManager debug options. These are convenient options that
50 /// should be available to any LLVM-based tool. They exist purely as
51 /// command-line debug options, therefore don't need to be local to an LLVM
52 /// context or captured by a formal API. In all respects they are handled like
53 /// global variables, but being defined in the LLVMCore library cannot have
54 /// static initializers and must be destroyed only at llvm_shutdown.
55 struct PassDebugOpts {
56 cl::opt PassDebugging;
57
58 typedef llvm::cl::list
59 PassOptionList;
60
61 // Print IR out before/after specified passes.
62 PassOptionList PrintBefore;
63
64 PassOptionList PrintAfter;
65
66 cl::opt PrintBeforeAll;
67 cl::opt PrintAfterAll;
68
69 cl::opt EnableTiming;
70
71 PassDebugOpts():
72 PassDebugging("debug-pass", cl::Hidden,
4973 cl::desc("Print PassManager debugging information"),
5074 cl::values(
51 clEnumVal(Disabled , "disable debug output"),
52 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
53 clEnumVal(Structure , "print pass structure before run()"),
54 clEnumVal(Executions, "print pass name before it is executed"),
55 clEnumVal(Details , "print pass details when it is executed"),
56 clEnumValEnd));
57
58 typedef llvm::cl::list
59 PassOptionList;
60
61 // Print IR out before/after specified passes.
62 static PassOptionList
63 PrintBefore("print-before",
64 llvm::cl::desc("Print IR before specified passes"),
65 cl::Hidden);
66
67 static PassOptionList
68 PrintAfter("print-after",
69 llvm::cl::desc("Print IR after specified passes"),
70 cl::Hidden);
71
72 static cl::opt
73 PrintBeforeAll("print-before-all",
74 llvm::cl::desc("Print IR before each pass"),
75 cl::init(false));
76 static cl::opt
77 PrintAfterAll("print-after-all",
78 llvm::cl::desc("Print IR after each pass"),
79 cl::init(false));
80
81 /// This is a helper to determine whether to print IR before or
82 /// after a pass.
83
84 static bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI,
85 PassOptionList &PassesToPrint) {
86 for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) {
87 const llvm::PassInfo *PassInf = PassesToPrint[i];
88 if (PassInf)
89 if (PassInf->getPassArgument() == PI->getPassArgument()) {
90 return true;
91 }
92 }
93 return false;
94 }
95
96 /// This is a utility to check whether a pass should have IR dumped
97 /// before it.
98 static bool ShouldPrintBeforePass(const PassInfo *PI) {
99 return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PI, PrintBefore);
100 }
101
102 /// This is a utility to check whether a pass should have IR dumped
103 /// after it.
104 static bool ShouldPrintAfterPass(const PassInfo *PI) {
105 return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter);
75 clEnumVal(Disabled , "disable debug output"),
76 clEnumVal(Arguments,
77 "print pass arguments to pass to 'opt'"),
78 clEnumVal(Structure, "print pass structure before run()"),
79 clEnumVal(Executions,
80 "print pass name before it is executed"),
81 clEnumVal(Details,
82 "print pass details when it is executed"),
83 clEnumValEnd)),
84 PrintBefore("print-before",
85 llvm::cl::desc("Print IR before specified passes"),
86 cl::Hidden),
87 PrintAfter("print-after",
88 llvm::cl::desc("Print IR after specified passes"),
89 cl::Hidden),
90 PrintBeforeAll("print-before-all",
91 llvm::cl::desc("Print IR before each pass"),
92 cl::init(false)),
93 PrintAfterAll("print-after-all",
94 llvm::cl::desc("Print IR after each pass"),
95 cl::init(false)),
96 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
97 cl::desc(
98 "Time each pass, printing elapsed time for each on exit"))
99 {}
100
101 /// This is a helper to determine whether to print IR before or
102 /// after a pass.
103 bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI,
104 PassOptionList &PassesToPrint) {
105 for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) {
106 const llvm::PassInfo *PassInf = PassesToPrint[i];
107 if (PassInf)
108 if (PassInf->getPassArgument() == PI->getPassArgument()) {
109 return true;
110 }
111 }
112 return false;
113 }
114
115 /// This is a utility to check whether a pass should have IR dumped
116 /// before it.
117 bool ShouldPrintBeforePass(const PassInfo *PI) {
118 return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PI, PrintBefore);
119 }
120
121 /// This is a utility to check whether a pass should have IR dumped
122 /// after it.
123 bool ShouldPrintAfterPass(const PassInfo *PI) {
124 return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter);
125 }
126 };
127
128 static ManagedStatic GlobalPassDebugOpts;
129
130 /// This is called by tools to force registration of debugging options and
131 /// ensure they appear in the tool's -help usage.
132 void initializePassManager() {
133 // Force instantiation of PassDebugOpts.
134 *GlobalPassDebugOpts;
106135 }
107136
108137 } // End of llvm namespace
110139 /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
111140 /// or higher is specified.
112141 bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
113 return PassDebugging >= Executions;
114 }
115
116
117
142 return GlobalPassDebugOpts->PassDebugging >= Executions;
143 }
118144
119145 void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
120146 if (V == 0 && M == 0)
667693 return;
668694 }
669695
670 if (PI && !PI->isAnalysis() && ShouldPrintBeforePass(PI)) {
696 if (PI && !PI->isAnalysis() &&
697 GlobalPassDebugOpts->ShouldPrintBeforePass(PI)) {
671698 Pass *PP = P->createPrinterPass(
672699 dbgs(), std::string("*** IR Dump Before ") + P->getPassName() + " ***");
673700 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
676703 // Add the requested pass to the best available pass manager.
677704 P->assignPassManager(activeStack, getTopLevelPassManagerType());
678705
679 if (PI && !PI->isAnalysis() && ShouldPrintAfterPass(PI)) {
706 if (PI && !PI->isAnalysis() &&
707 GlobalPassDebugOpts->ShouldPrintAfterPass(PI)) {
680708 Pass *PP = P->createPrinterPass(
681709 dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***");
682710 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
728756 // Print passes managed by this top level manager.
729757 void PMTopLevelManager::dumpPasses() const {
730758
731 if (PassDebugging < Structure)
759 if (GlobalPassDebugOpts->PassDebugging < Structure)
732760 return;
733761
734762 // Print out the immutable passes
747775
748776 void PMTopLevelManager::dumpArguments() const {
749777
750 if (PassDebugging < Arguments)
778 if (GlobalPassDebugOpts->PassDebugging < Arguments)
751779 return;
752780
753781 dbgs() << "Pass Arguments: ";
880908 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
881909 PreservedSet.end()) {
882910 // Remove this analysis
883 if (PassDebugging >= Details) {
911 if (GlobalPassDebugOpts->PassDebugging >= Details) {
884912 Pass *S = Info->second;
885913 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
886914 dbgs() << S->getPassName() << "'\n";
904932 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
905933 PreservedSet.end()) {
906934 // Remove this analysis
907 if (PassDebugging >= Details) {
935 if (GlobalPassDebugOpts->PassDebugging >= Details) {
908936 Pass *S = Info->second;
909937 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
910938 dbgs() << S->getPassName() << "'\n";
927955
928956 TPM->collectLastUses(DeadPasses, P);
929957
930 if (PassDebugging >= Details && !DeadPasses.empty()) {
958 if (GlobalPassDebugOpts->PassDebugging >= Details && !DeadPasses.empty()) {
931959 dbgs() << " -*- '" << P->getPassName();
932960 dbgs() << "' is the last user of following pass instances.";
933961 dbgs() << " Free these instances\n";
11451173 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
11461174 enum PassDebuggingString S2,
11471175 StringRef Msg) {
1148 if (PassDebugging < Executions)
1176 if (GlobalPassDebugOpts->PassDebugging < Executions)
11491177 return;
11501178 dbgs() << (void*)this << std::string(getDepth()*2+1, ' ');
11511179 switch (S1) {
11861214 }
11871215
11881216 void PMDataManager::dumpRequiredSet(const Pass *P) const {
1189 if (PassDebugging < Details)
1217 if (GlobalPassDebugOpts->PassDebugging < Details)
11901218 return;
11911219
11921220 AnalysisUsage analysisUsage;
11951223 }
11961224
11971225 void PMDataManager::dumpPreservedSet(const Pass *P) const {
1198 if (PassDebugging < Details)
1226 if (GlobalPassDebugOpts->PassDebugging < Details)
11991227 return;
12001228
12011229 AnalysisUsage analysisUsage;
12051233
12061234 void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
12071235 const AnalysisUsage::VectorType &Set) const {
1208 assert(PassDebugging >= Details);
1236 assert(GlobalPassDebugOpts->PassDebugging >= Details);
12091237 if (Set.empty())
12101238 return;
12111239 dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
17401768 //===----------------------------------------------------------------------===//
17411769 // TimingInfo implementation
17421770
1743 bool llvm::TimePassesIsEnabled = false;
1744 static cl::opt
1745 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1746 cl::desc("Time each pass, printing elapsed time for each on exit"));
1747
17481771 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
17491772 // a non null value (if the -time-passes option is enabled) or it leaves it
17501773 // null. It may be called multiple times.
1919 #include "llvm/Assembly/Parser.h"
2020 #include "llvm/Bitcode/ReaderWriter.h"
2121 #include "llvm/IR/Module.h"
22 #include "llvm/PassManager.h"
2223 #include "llvm/Support/CommandLine.h"
2324 #include "llvm/Support/ManagedStatic.h"
2425 #include "llvm/Support/PrettyStackTrace.h"
8889 PrettyStackTraceProgram X(argc, argv);
8990 LLVMContext &Context = getGlobalContext();
9091 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
92
93 // Initialize PassManager for -time-passes support.
94 initializePassManager();
95
9196 cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
9297
9398 // Parse the file now...
1919 #include "llvm/IR/Module.h"
2020 #include "llvm/IR/Type.h"
2121 #include "llvm/IRReader/IRReader.h"
22 #include "llvm/PassManager.h"
2223 #include "llvm/Support/CommandLine.h"
2324 #include "llvm/Support/MemoryBuffer.h"
2425 #include "llvm/Support/SourceMgr.h"
6667 cl::desc(""));
6768
6869 int main(int argc, char **argv) {
70 // Initialize PassManager for -time-passes support.
71 initializePassManager();
72
6973 cl::ParseCommandLineOptions(argc, argv);
7074
7175 LLVMContext Context;
2222 #include "llvm/IR/IntrinsicInst.h"
2323 #include "llvm/IR/Module.h"
2424 #include "llvm/IR/Type.h"
25 #include "llvm/PassManager.h"
2526 #include "llvm/Support/CommandLine.h"
2627 #include "llvm/Support/DataStream.h"
2728 #include "llvm/Support/FormattedStream.h"
118119 LLVMContext &Context = getGlobalContext();
119120 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
120121
122 // Initialize PassManager for -time-passes support.
123 initializePassManager();
121124
122125 cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
123126
9595
9696 LLVMContext &Context = getGlobalContext();
9797 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
98
99 // Initialize PassManager for -time-passes support.
100 initializePassManager();
101
98102 cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
99103
100104 // Use lazy loading, since we only care about selected global values.
1717 #include "llvm/IR/LLVMContext.h"
1818 #include "llvm/IR/Module.h"
1919 #include "llvm/IRReader/IRReader.h"
20 #include "llvm/PassManager.h"
2021 #include "llvm/Support/CommandLine.h"
2122 #include "llvm/Support/ManagedStatic.h"
2223 #include "llvm/Support/Path.h"
7273
7374 LLVMContext &Context = getGlobalContext();
7475 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
76
77 // Initialize PassManager for -time-passes support.
78 initializePassManager();
79
7580 cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
7681
7782 unsigned BaseArg = 0;
2121 #include "llvm/Object/Archive.h"
2222 #include "llvm/Object/MachOUniversal.h"
2323 #include "llvm/Object/ObjectFile.h"
24 #include "llvm/PassManager.h"
2425 #include "llvm/Support/CommandLine.h"
2526 #include "llvm/Support/FileSystem.h"
2627 #include "llvm/Support/Format.h"
445446 PrettyStackTraceProgram X(argc, argv);
446447
447448 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
449
450 // Initialize PassManager for -time-passes support.
451 initializePassManager();
452
448453 cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
449454
450455 // llvm-nm only reads binary files.
259259 LLVMContext &Context = getGlobalContext();
260260 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
261261
262 // Initialize PassManager for -time-passes support.
263 initializePassManager();
264
262265 cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n");
263266
264267 // Read in the bitcode file...
680680 int main(int argc, char **argv) {
681681 // Init LLVM, call llvm_shutdown() on exit, parse args, etc.
682682 llvm::PrettyStackTraceProgram X(argc, argv);
683
684 // Initialize PassManager for -time-passes support.
685 initializePassManager();
686
683687 cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
684688 llvm_shutdown_obj Y;
685689