1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

Revert "Encapsulate PassManager debug flags to avoid static init and cxa_exit."

Working on a better solution to this.

This reverts commit 7d4e9934e7ca83094c5cf41346966c8350179ff2.

llvm-svn: 190990
This commit is contained in:
Andrew Trick 2013-09-19 06:02:43 +00:00
parent 2a04344d58
commit e482b777ac
11 changed files with 73 additions and 135 deletions

View File

@ -28,11 +28,6 @@ class Module;
class PassManagerImpl; class PassManagerImpl;
class FunctionPassManagerImpl; class FunctionPassManagerImpl;
/// Called by tools to initialize globals and register options at a particular
/// point (before command line parsing). If this is not called, then PassManager
/// globals are lazily initialized at first use.
void initializePassManager();
/// PassManagerBase - An abstract interface to allow code to add passes to /// PassManagerBase - An abstract interface to allow code to add passes to
/// a pass manager without having to hard-code what kind of pass manager /// a pass manager without having to hard-code what kind of pass manager
/// it is. /// it is.

View File

@ -40,7 +40,6 @@
using namespace llvm; using namespace llvm;
void llvm::initializeCore(PassRegistry &Registry) { void llvm::initializeCore(PassRegistry &Registry) {
initializePassManager();
initializeDominatorTreePass(Registry); initializeDominatorTreePass(Registry);
initializePrintModulePassPass(Registry); initializePrintModulePassPass(Registry);
initializePrintFunctionPassPass(Registry); initializePrintFunctionPassPass(Registry);

View File

@ -45,94 +45,65 @@ enum PassDebugLevel {
Disabled, Arguments, Structure, Executions, Details Disabled, Arguments, Structure, Executions, Details
}; };
bool TimePassesIsEnabled = false; static cl::opt<enum PassDebugLevel>
PassDebugging("debug-pass", cl::Hidden,
/// Encapsulate PassManager debug options. These are convenient options that
/// should be available to any LLVM-based tool. They exist purely as
/// command-line debug options, therefore don't need to be local to an LLVM
/// context or captured by a formal API. In all respects they are handled like
/// global variables, but being defined in the LLVMCore library cannot have
/// static initializers and must be destroyed only at llvm_shutdown.
struct PassDebugOpts {
cl::opt<enum PassDebugLevel> PassDebugging;
typedef llvm::cl::list<const llvm::PassInfo *, bool, PassNameParser>
PassOptionList;
// Print IR out before/after specified passes.
PassOptionList PrintBefore;
PassOptionList PrintAfter;
cl::opt<bool> PrintBeforeAll;
cl::opt<bool> PrintAfterAll;
cl::opt<bool,true> EnableTiming;
PassDebugOpts():
PassDebugging("debug-pass", cl::Hidden,
cl::desc("Print PassManager debugging information"), cl::desc("Print PassManager debugging information"),
cl::values( cl::values(
clEnumVal(Disabled , "disable debug output"), clEnumVal(Disabled , "disable debug output"),
clEnumVal(Arguments, clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
"print pass arguments to pass to 'opt'"), clEnumVal(Structure , "print pass structure before run()"),
clEnumVal(Structure, "print pass structure before run()"), clEnumVal(Executions, "print pass name before it is executed"),
clEnumVal(Executions, clEnumVal(Details , "print pass details when it is executed"),
"print pass name before it is executed"), clEnumValEnd));
clEnumVal(Details,
"print pass details when it is executed"),
clEnumValEnd)),
PrintBefore("print-before",
llvm::cl::desc("Print IR before specified passes"),
cl::Hidden),
PrintAfter("print-after",
llvm::cl::desc("Print IR after specified passes"),
cl::Hidden),
PrintBeforeAll("print-before-all",
llvm::cl::desc("Print IR before each pass"),
cl::init(false)),
PrintAfterAll("print-after-all",
llvm::cl::desc("Print IR after each pass"),
cl::init(false)),
EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
cl::desc(
"Time each pass, printing elapsed time for each on exit"))
{}
/// This is a helper to determine whether to print IR before or typedef llvm::cl::list<const llvm::PassInfo *, bool, PassNameParser>
/// after a pass. PassOptionList;
bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI,
PassOptionList &PassesToPrint) { // Print IR out before/after specified passes.
for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) { static PassOptionList
const llvm::PassInfo *PassInf = PassesToPrint[i]; PrintBefore("print-before",
if (PassInf) llvm::cl::desc("Print IR before specified passes"),
if (PassInf->getPassArgument() == PI->getPassArgument()) { cl::Hidden);
return true;
} static PassOptionList
} PrintAfter("print-after",
return false; llvm::cl::desc("Print IR after specified passes"),
cl::Hidden);
static cl::opt<bool>
PrintBeforeAll("print-before-all",
llvm::cl::desc("Print IR before each pass"),
cl::init(false));
static cl::opt<bool>
PrintAfterAll("print-after-all",
llvm::cl::desc("Print IR after each pass"),
cl::init(false));
/// This is a helper to determine whether to print IR before or
/// after a pass.
static bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI,
PassOptionList &PassesToPrint) {
for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) {
const llvm::PassInfo *PassInf = PassesToPrint[i];
if (PassInf)
if (PassInf->getPassArgument() == PI->getPassArgument()) {
return true;
}
} }
return false;
}
/// This is a utility to check whether a pass should have IR dumped /// This is a utility to check whether a pass should have IR dumped
/// before it. /// before it.
bool ShouldPrintBeforePass(const PassInfo *PI) { static bool ShouldPrintBeforePass(const PassInfo *PI) {
return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PI, PrintBefore); return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PI, PrintBefore);
} }
/// This is a utility to check whether a pass should have IR dumped /// This is a utility to check whether a pass should have IR dumped
/// after it. /// after it.
bool ShouldPrintAfterPass(const PassInfo *PI) { static bool ShouldPrintAfterPass(const PassInfo *PI) {
return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter); return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter);
}
};
static ManagedStatic<PassDebugOpts> GlobalPassDebugOpts;
/// This is called by tools to force registration of debugging options and
/// ensure they appear in the tool's -help usage.
void initializePassManager() {
// Force instantiation of PassDebugOpts.
*GlobalPassDebugOpts;
} }
} // End of llvm namespace } // End of llvm namespace
@ -140,9 +111,12 @@ void initializePassManager() {
/// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
/// or higher is specified. /// or higher is specified.
bool PMDataManager::isPassDebuggingExecutionsOrMore() const { bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
return GlobalPassDebugOpts->PassDebugging >= Executions; return PassDebugging >= Executions;
} }
void PassManagerPrettyStackEntry::print(raw_ostream &OS) const { void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
if (V == 0 && M == 0) if (V == 0 && M == 0)
OS << "Releasing pass '"; OS << "Releasing pass '";
@ -694,8 +668,7 @@ void PMTopLevelManager::schedulePass(Pass *P) {
return; return;
} }
if (PI && !PI->isAnalysis() && if (PI && !PI->isAnalysis() && ShouldPrintBeforePass(PI)) {
GlobalPassDebugOpts->ShouldPrintBeforePass(PI)) {
Pass *PP = P->createPrinterPass( Pass *PP = P->createPrinterPass(
dbgs(), std::string("*** IR Dump Before ") + P->getPassName() + " ***"); dbgs(), std::string("*** IR Dump Before ") + P->getPassName() + " ***");
PP->assignPassManager(activeStack, getTopLevelPassManagerType()); PP->assignPassManager(activeStack, getTopLevelPassManagerType());
@ -704,8 +677,7 @@ void PMTopLevelManager::schedulePass(Pass *P) {
// Add the requested pass to the best available pass manager. // Add the requested pass to the best available pass manager.
P->assignPassManager(activeStack, getTopLevelPassManagerType()); P->assignPassManager(activeStack, getTopLevelPassManagerType());
if (PI && !PI->isAnalysis() && if (PI && !PI->isAnalysis() && ShouldPrintAfterPass(PI)) {
GlobalPassDebugOpts->ShouldPrintAfterPass(PI)) {
Pass *PP = P->createPrinterPass( Pass *PP = P->createPrinterPass(
dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***"); dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***");
PP->assignPassManager(activeStack, getTopLevelPassManagerType()); PP->assignPassManager(activeStack, getTopLevelPassManagerType());
@ -757,7 +729,7 @@ Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
// Print passes managed by this top level manager. // Print passes managed by this top level manager.
void PMTopLevelManager::dumpPasses() const { void PMTopLevelManager::dumpPasses() const {
if (GlobalPassDebugOpts->PassDebugging < Structure) if (PassDebugging < Structure)
return; return;
// Print out the immutable passes // Print out the immutable passes
@ -776,7 +748,7 @@ void PMTopLevelManager::dumpPasses() const {
void PMTopLevelManager::dumpArguments() const { void PMTopLevelManager::dumpArguments() const {
if (GlobalPassDebugOpts->PassDebugging < Arguments) if (PassDebugging < Arguments)
return; return;
dbgs() << "Pass Arguments: "; dbgs() << "Pass Arguments: ";
@ -909,7 +881,7 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) == std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
PreservedSet.end()) { PreservedSet.end()) {
// Remove this analysis // Remove this analysis
if (GlobalPassDebugOpts->PassDebugging >= Details) { if (PassDebugging >= Details) {
Pass *S = Info->second; Pass *S = Info->second;
dbgs() << " -- '" << P->getPassName() << "' is not preserving '"; dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
dbgs() << S->getPassName() << "'\n"; dbgs() << S->getPassName() << "'\n";
@ -933,7 +905,7 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) == std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
PreservedSet.end()) { PreservedSet.end()) {
// Remove this analysis // Remove this analysis
if (GlobalPassDebugOpts->PassDebugging >= Details) { if (PassDebugging >= Details) {
Pass *S = Info->second; Pass *S = Info->second;
dbgs() << " -- '" << P->getPassName() << "' is not preserving '"; dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
dbgs() << S->getPassName() << "'\n"; dbgs() << S->getPassName() << "'\n";
@ -956,7 +928,7 @@ void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
TPM->collectLastUses(DeadPasses, P); TPM->collectLastUses(DeadPasses, P);
if (GlobalPassDebugOpts->PassDebugging >= Details && !DeadPasses.empty()) { if (PassDebugging >= Details && !DeadPasses.empty()) {
dbgs() << " -*- '" << P->getPassName(); dbgs() << " -*- '" << P->getPassName();
dbgs() << "' is the last user of following pass instances."; dbgs() << "' is the last user of following pass instances.";
dbgs() << " Free these instances\n"; dbgs() << " Free these instances\n";
@ -1174,7 +1146,7 @@ void PMDataManager::dumpPassArguments() const {
void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1, void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
enum PassDebuggingString S2, enum PassDebuggingString S2,
StringRef Msg) { StringRef Msg) {
if (GlobalPassDebugOpts->PassDebugging < Executions) if (PassDebugging < Executions)
return; return;
dbgs() << (void*)this << std::string(getDepth()*2+1, ' '); dbgs() << (void*)this << std::string(getDepth()*2+1, ' ');
switch (S1) { switch (S1) {
@ -1215,7 +1187,7 @@ void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
} }
void PMDataManager::dumpRequiredSet(const Pass *P) const { void PMDataManager::dumpRequiredSet(const Pass *P) const {
if (GlobalPassDebugOpts->PassDebugging < Details) if (PassDebugging < Details)
return; return;
AnalysisUsage analysisUsage; AnalysisUsage analysisUsage;
@ -1224,7 +1196,7 @@ void PMDataManager::dumpRequiredSet(const Pass *P) const {
} }
void PMDataManager::dumpPreservedSet(const Pass *P) const { void PMDataManager::dumpPreservedSet(const Pass *P) const {
if (GlobalPassDebugOpts->PassDebugging < Details) if (PassDebugging < Details)
return; return;
AnalysisUsage analysisUsage; AnalysisUsage analysisUsage;
@ -1234,7 +1206,7 @@ void PMDataManager::dumpPreservedSet(const Pass *P) const {
void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P, void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
const AnalysisUsage::VectorType &Set) const { const AnalysisUsage::VectorType &Set) const {
assert(GlobalPassDebugOpts->PassDebugging >= Details); assert(PassDebugging >= Details);
if (Set.empty()) if (Set.empty())
return; return;
dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:"; dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
@ -1769,6 +1741,11 @@ bool PassManager::run(Module &M) {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// TimingInfo implementation // TimingInfo implementation
bool llvm::TimePassesIsEnabled = false;
static cl::opt<bool,true>
EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
cl::desc("Time each pass, printing elapsed time for each on exit"));
// createTheTimeInfo - This method either initializes the TheTimeInfo pointer to // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
// a non null value (if the -time-passes option is enabled) or it leaves it // a non null value (if the -time-passes option is enabled) or it leaves it
// null. It may be called multiple times. // null. It may be called multiple times.

View File

@ -20,7 +20,6 @@
#include "llvm/Assembly/Parser.h" #include "llvm/Assembly/Parser.h"
#include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/PrettyStackTrace.h"
@ -90,10 +89,6 @@ int main(int argc, char **argv) {
PrettyStackTraceProgram X(argc, argv); PrettyStackTraceProgram X(argc, argv);
LLVMContext &Context = getGlobalContext(); LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Initialize PassManager for -time-passes support.
initializePassManager();
cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n"); cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
// Parse the file now... // Parse the file now...

View File

@ -20,7 +20,6 @@
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/Type.h" #include "llvm/IR/Type.h"
#include "llvm/IRReader/IRReader.h" #include "llvm/IRReader/IRReader.h"
#include "llvm/PassManager.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h" #include "llvm/Support/SourceMgr.h"
@ -68,9 +67,6 @@ static cl::list<std::string> GlobalsToCompare(cl::Positional,
cl::desc("<globals to compare>")); cl::desc("<globals to compare>"));
int main(int argc, char **argv) { int main(int argc, char **argv) {
// Initialize PassManager for -time-passes support.
initializePassManager();
cl::ParseCommandLineOptions(argc, argv); cl::ParseCommandLineOptions(argc, argv);
LLVMContext Context; LLVMContext Context;

View File

@ -23,7 +23,6 @@
#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/Type.h" #include "llvm/IR/Type.h"
#include "llvm/PassManager.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/DataStream.h" #include "llvm/Support/DataStream.h"
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
@ -120,8 +119,6 @@ int main(int argc, char **argv) {
LLVMContext &Context = getGlobalContext(); LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Initialize PassManager for -time-passes support.
initializePassManager();
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n"); cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");

View File

@ -96,10 +96,6 @@ int main(int argc, char **argv) {
LLVMContext &Context = getGlobalContext(); LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Initialize PassManager for -time-passes support.
initializePassManager();
cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n"); cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
// Use lazy loading, since we only care about selected global values. // Use lazy loading, since we only care about selected global values.

View File

@ -18,7 +18,6 @@
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h" #include "llvm/IRReader/IRReader.h"
#include "llvm/PassManager.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h" #include "llvm/Support/Path.h"
@ -74,10 +73,6 @@ int main(int argc, char **argv) {
LLVMContext &Context = getGlobalContext(); LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Initialize PassManager for -time-passes support.
initializePassManager();
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
unsigned BaseArg = 0; unsigned BaseArg = 0;

View File

@ -22,7 +22,6 @@
#include "llvm/Object/Archive.h" #include "llvm/Object/Archive.h"
#include "llvm/Object/MachOUniversal.h" #include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h" #include "llvm/Object/ObjectFile.h"
#include "llvm/PassManager.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h" #include "llvm/Support/Format.h"
@ -447,10 +446,6 @@ int main(int argc, char **argv) {
PrettyStackTraceProgram X(argc, argv); PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Initialize PassManager for -time-passes support.
initializePassManager();
cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n"); cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
// llvm-nm only reads binary files. // llvm-nm only reads binary files.

View File

@ -260,9 +260,6 @@ int main(int argc, char **argv) {
LLVMContext &Context = getGlobalContext(); LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Initialize PassManager for -time-passes support.
initializePassManager();
cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n"); cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n");
// Read in the bitcode file... // Read in the bitcode file...

View File

@ -681,10 +681,6 @@ void IntroduceControlFlow(Function *F, Random &R) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
// Init LLVM, call llvm_shutdown() on exit, parse args, etc. // Init LLVM, call llvm_shutdown() on exit, parse args, etc.
llvm::PrettyStackTraceProgram X(argc, argv); llvm::PrettyStackTraceProgram X(argc, argv);
// Initialize PassManager for -time-passes support.
initializePassManager();
cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n"); cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
llvm_shutdown_obj Y; llvm_shutdown_obj Y;