mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[opt][NewPM] Add a --print-passes flag to print all available passes
It seems nicer to list passes given a flag rather than displaying all passes in opt --help. This is awkwardly structured because a PassBuilder is required, but reusing the PassBuilder in runPassPipeline() doesn't work because we read the input IR before getting to runPassPipeline(). So printing the list of passes needs to happen before reading the input IR. If we remove the legacy PM code in main() and move everything from NewPMDriver.cpp into opt.cpp, we can create the PassBuilder before reading IR and check if we should print the list of passes and exit. But until then this hack seems fine. Compared to the legacy PM, the new PM passes are lacking descriptions. We'll need to figure out a way to add descriptions if we think this is important. Also, this only works for passes specified in PassRegistry.def. If we want to print other custom registered passes, we'll need a different mechanism. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D96101
This commit is contained in:
parent
ca72db68cf
commit
31acdea7b2
@ -19,6 +19,7 @@
|
||||
#include "llvm/Analysis/CGSCCPassManager.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/IPO/Inliner.h"
|
||||
#include "llvm/Transforms/Instrumentation.h"
|
||||
#include "llvm/Transforms/Scalar/LoopPassManager.h"
|
||||
@ -532,6 +533,9 @@ public:
|
||||
/// Returns true if the pass name is the name of a (non-alias) analysis pass.
|
||||
bool isAnalysisPassName(StringRef PassName);
|
||||
|
||||
/// Print pass names.
|
||||
void printPassNames(raw_ostream &OS);
|
||||
|
||||
/// Register a callback for a default optimizer pipeline extension
|
||||
/// point
|
||||
///
|
||||
|
@ -3060,6 +3060,54 @@ bool PassBuilder::isAnalysisPassName(StringRef PassName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void printPassName(StringRef PassName, raw_ostream &OS) {
|
||||
OS << " " << PassName << "\n";
|
||||
}
|
||||
|
||||
void PassBuilder::printPassNames(raw_ostream &OS) {
|
||||
// TODO: print pass descriptions when they are available
|
||||
|
||||
OS << "Module passes:\n";
|
||||
#define MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "Module analyses:\n";
|
||||
#define MODULE_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "Module alias analyses:\n";
|
||||
#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "CGSCC passes:\n";
|
||||
#define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "CGSCC analyses:\n";
|
||||
#define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "Function passes:\n";
|
||||
#define FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "Function analyses:\n";
|
||||
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "Function alias analyses:\n";
|
||||
#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "Loop passes:\n";
|
||||
#define LOOP_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
|
||||
OS << "Loop analyses:\n";
|
||||
#define LOOP_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
|
||||
#include "PassRegistry.def"
|
||||
}
|
||||
|
||||
void PassBuilder::registerParseTopLevelPipelineCallback(
|
||||
const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>,
|
||||
bool DebugLogging)> &C) {
|
||||
|
22
test/Other/print-passes.ll
Normal file
22
test/Other/print-passes.ll
Normal file
@ -0,0 +1,22 @@
|
||||
; RUN: opt --print-passes | FileCheck %s
|
||||
|
||||
; CHECK: Module passes:
|
||||
; CHECK: no-op-module
|
||||
; CHECK: Module analyses:
|
||||
; CHECK: no-op-module
|
||||
; CHECK: Module alias analyses:
|
||||
; CHECK: globals-aa
|
||||
; CHECK: CGSCC passes:
|
||||
; CHECK: no-op-cgscc
|
||||
; CHECK: CGSCC analyses:
|
||||
; CHECK: no-op-cgscc
|
||||
; CHECK: Function passes:
|
||||
; CHECK: no-op-function
|
||||
; CHECK: Function analyses:
|
||||
; CHECK: no-op-function
|
||||
; CHECK: Function alias analyses:
|
||||
; CHECK: basic-aa
|
||||
; CHECK: Loop passes:
|
||||
; CHECK: no-op-loop
|
||||
; CHECK: Loop analyses:
|
||||
; CHECK: no-op-loop
|
@ -463,3 +463,8 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void llvm::printPasses(raw_ostream &OS) {
|
||||
PassBuilder PB;
|
||||
PB.printPassNames(OS);
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ enum PGOKind {
|
||||
enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse };
|
||||
}
|
||||
|
||||
void printPasses(raw_ostream &OS);
|
||||
|
||||
/// Driver function to run the new pass manager over a module.
|
||||
///
|
||||
/// This function only exists factored away from opt.cpp in order to prevent
|
||||
|
@ -82,8 +82,13 @@ static cl::opt<bool> EnableNewPassManager(
|
||||
// pass management.
|
||||
static cl::opt<std::string> PassPipeline(
|
||||
"passes",
|
||||
cl::desc("A textual description of the pass pipeline for optimizing"),
|
||||
cl::Hidden);
|
||||
cl::desc(
|
||||
"A textual description of the pass pipeline. To have analysis passes "
|
||||
"available before a certain pass, add 'require<foo-analysis>'."));
|
||||
|
||||
static cl::opt<bool> PrintPasses("print-passes",
|
||||
cl::desc("Print available passes that can be "
|
||||
"specified in -passes=foo and exit"));
|
||||
|
||||
static cl::opt<std::string>
|
||||
InputFilename(cl::Positional, cl::desc("<input bitcode file>"),
|
||||
@ -589,6 +594,14 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// FIXME: once the legacy PM code is deleted, move runPassPipeline() here and
|
||||
// construct the PassBuilder before parsing IR so we can reuse the same
|
||||
// PassBuilder for print passes.
|
||||
if (PrintPasses) {
|
||||
printPasses(outs());
|
||||
return 0;
|
||||
}
|
||||
|
||||
TimeTracerRAII TimeTracer(argv[0]);
|
||||
|
||||
SMDiagnostic Err;
|
||||
|
Loading…
x
Reference in New Issue
Block a user