llvm.org GIT mirror llvm / abe68f5
Revert "Encapsulate PassManager debug flags to avoid static init and cxa_exit." Working on a better solution to this. This reverts commit 7d4e9934e7ca83094c5cf41346966c8350179ff2. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190990 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 6 years ago
11 changed file(s) with 78 addition(s) and 140 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();
3429
3530 /// PassManagerBase - An abstract interface to allow code to add passes to
3631 /// 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();
4342 initializeDominatorTreePass(Registry);
4443 initializePrintModulePassPass(Registry);
4544 initializePrintFunctionPassPass(Registry);
4444 Disabled, Arguments, Structure, Executions, Details
4545 };
4646
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,
47 static cl::opt
48 PassDebugging("debug-pass", cl::Hidden,
7349 cl::desc("Print PassManager debugging information"),
7450 cl::values(
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;
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);
135106 }
136107
137108 } // End of llvm namespace
139110 /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
140111 /// or higher is specified.
141112 bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
142 return GlobalPassDebugOpts->PassDebugging >= Executions;
143 }
113 return PassDebugging >= Executions;
114 }
115
116
117
144118
145119 void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
146120 if (V == 0 && M == 0)
693667 return;
694668 }
695669
696 if (PI && !PI->isAnalysis() &&
697 GlobalPassDebugOpts->ShouldPrintBeforePass(PI)) {
670 if (PI && !PI->isAnalysis() && ShouldPrintBeforePass(PI)) {
698671 Pass *PP = P->createPrinterPass(
699672 dbgs(), std::string("*** IR Dump Before ") + P->getPassName() + " ***");
700673 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
703676 // Add the requested pass to the best available pass manager.
704677 P->assignPassManager(activeStack, getTopLevelPassManagerType());
705678
706 if (PI && !PI->isAnalysis() &&
707 GlobalPassDebugOpts->ShouldPrintAfterPass(PI)) {
679 if (PI && !PI->isAnalysis() && ShouldPrintAfterPass(PI)) {
708680 Pass *PP = P->createPrinterPass(
709681 dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***");
710682 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
756728 // Print passes managed by this top level manager.
757729 void PMTopLevelManager::dumpPasses() const {
758730
759 if (GlobalPassDebugOpts->PassDebugging < Structure)
731 if (PassDebugging < Structure)
760732 return;
761733
762734 // Print out the immutable passes
775747
776748 void PMTopLevelManager::dumpArguments() const {
777749
778 if (GlobalPassDebugOpts->PassDebugging < Arguments)
750 if (PassDebugging < Arguments)
779751 return;
780752
781753 dbgs() << "Pass Arguments: ";
908880 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
909881 PreservedSet.end()) {
910882 // Remove this analysis
911 if (GlobalPassDebugOpts->PassDebugging >= Details) {
883 if (PassDebugging >= Details) {
912884 Pass *S = Info->second;
913885 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
914886 dbgs() << S->getPassName() << "'\n";
932904 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
933905 PreservedSet.end()) {
934906 // Remove this analysis
935 if (GlobalPassDebugOpts->PassDebugging >= Details) {
907 if (PassDebugging >= Details) {
936908 Pass *S = Info->second;
937909 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
938910 dbgs() << S->getPassName() << "'\n";
955927
956928 TPM->collectLastUses(DeadPasses, P);
957929
958 if (GlobalPassDebugOpts->PassDebugging >= Details && !DeadPasses.empty()) {
930 if (PassDebugging >= Details && !DeadPasses.empty()) {
959931 dbgs() << " -*- '" << P->getPassName();
960932 dbgs() << "' is the last user of following pass instances.";
961933 dbgs() << " Free these instances\n";
11731145 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
11741146 enum PassDebuggingString S2,
11751147 StringRef Msg) {
1176 if (GlobalPassDebugOpts->PassDebugging < Executions)
1148 if (PassDebugging < Executions)
11771149 return;
11781150 dbgs() << (void*)this << std::string(getDepth()*2+1, ' ');
11791151 switch (S1) {
12141186 }
12151187
12161188 void PMDataManager::dumpRequiredSet(const Pass *P) const {
1217 if (GlobalPassDebugOpts->PassDebugging < Details)
1189 if (PassDebugging < Details)
12181190 return;
12191191
12201192 AnalysisUsage analysisUsage;
12231195 }
12241196
12251197 void PMDataManager::dumpPreservedSet(const Pass *P) const {
1226 if (GlobalPassDebugOpts->PassDebugging < Details)
1198 if (PassDebugging < Details)
12271199 return;
12281200
12291201 AnalysisUsage analysisUsage;
12331205
12341206 void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
12351207 const AnalysisUsage::VectorType &Set) const {
1236 assert(GlobalPassDebugOpts->PassDebugging >= Details);
1208 assert(PassDebugging >= Details);
12371209 if (Set.empty())
12381210 return;
12391211 dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
17681740 //===----------------------------------------------------------------------===//
17691741 // TimingInfo implementation
17701742
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
17711748 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
17721749 // a non null value (if the -time-passes option is enabled) or it leaves it
17731750 // 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"
2322 #include "llvm/Support/CommandLine.h"
2423 #include "llvm/Support/ManagedStatic.h"
2524 #include "llvm/Support/PrettyStackTrace.h"
8988 PrettyStackTraceProgram X(argc, argv);
9089 LLVMContext &Context = getGlobalContext();
9190 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
92
93 // Initialize PassManager for -time-passes support.
94 initializePassManager();
95
9691 cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
9792
9893 // 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"
2322 #include "llvm/Support/CommandLine.h"
2423 #include "llvm/Support/MemoryBuffer.h"
2524 #include "llvm/Support/SourceMgr.h"
6766 cl::desc(""));
6867
6968 int main(int argc, char **argv) {
70 // Initialize PassManager for -time-passes support.
71 initializePassManager();
72
7369 cl::ParseCommandLineOptions(argc, argv);
7470
7571 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"
2625 #include "llvm/Support/CommandLine.h"
2726 #include "llvm/Support/DataStream.h"
2827 #include "llvm/Support/FormattedStream.h"
119118 LLVMContext &Context = getGlobalContext();
120119 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
121120
122 // Initialize PassManager for -time-passes support.
123 initializePassManager();
124121
125122 cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
126123
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
10298 cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
10399
104100 // 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"
2120 #include "llvm/Support/CommandLine.h"
2221 #include "llvm/Support/ManagedStatic.h"
2322 #include "llvm/Support/Path.h"
7372
7473 LLVMContext &Context = getGlobalContext();
7574 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
76
77 // Initialize PassManager for -time-passes support.
78 initializePassManager();
79
8075 cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
8176
8277 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"
2524 #include "llvm/Support/CommandLine.h"
2625 #include "llvm/Support/FileSystem.h"
2726 #include "llvm/Support/Format.h"
446445 PrettyStackTraceProgram X(argc, argv);
447446
448447 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
449
450 // Initialize PassManager for -time-passes support.
451 initializePassManager();
452
453448 cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
454449
455450 // 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
265262 cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n");
266263
267264 // 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
687683 cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
688684 llvm_shutdown_obj Y;
689685