13 #include "llvm/Support/CommandLine.h"
14 #include "llvm/Support/ManagedStatic.h"
19 struct PassManagerOptions {
23 llvm::cl::opt<std::string> reproducerFile{
24 "mlir-pass-pipeline-crash-reproducer",
25 llvm::cl::desc(
"Generate a .mlir reproducer file at the given output path"
26 " if the pass manager crashes or fails")};
27 llvm::cl::opt<bool> localReproducer{
28 "mlir-pass-pipeline-local-reproducer",
29 llvm::cl::desc(
"When generating a crash reproducer, attempt to generated "
30 "a reproducer with the smallest pipeline."),
31 llvm::cl::init(
false)};
37 "Print IR before specified passes"};
39 "Print IR after specified passes"};
40 llvm::cl::opt<bool> printBeforeAll{
41 "mlir-print-ir-before-all", llvm::cl::desc(
"Print IR before each pass"),
42 llvm::cl::init(
false)};
43 llvm::cl::opt<bool> printAfterAll{
"mlir-print-ir-after-all",
44 llvm::cl::desc(
"Print IR after each pass"),
45 llvm::cl::init(
false)};
46 llvm::cl::opt<bool> printAfterChange{
47 "mlir-print-ir-after-change",
49 "When printing the IR after a pass, only print if the IR changed"),
50 llvm::cl::init(
false)};
51 llvm::cl::opt<bool> printAfterFailure{
52 "mlir-print-ir-after-failure",
54 "When printing the IR after a pass, only print if the pass failed"),
55 llvm::cl::init(
false)};
56 llvm::cl::opt<bool> printModuleScope{
57 "mlir-print-ir-module-scope",
58 llvm::cl::desc(
"When printing IR for print-ir-[before|after]{-all} "
59 "always print the top-level operation"),
60 llvm::cl::init(
false)};
61 llvm::cl::opt<std::string> printTreeDir{
62 "mlir-print-ir-tree-dir",
63 llvm::cl::desc(
"When printing the IR before/after a pass, print file "
64 "tree rooted at this directory. Use in conjunction with "
65 "mlir-print-ir-* flags")};
73 llvm::cl::opt<bool> passStatistics{
74 "mlir-pass-statistics",
75 llvm::cl::desc(
"Display the statistics of each pass")};
76 llvm::cl::opt<PassDisplayMode> passStatisticsDisplayMode{
77 "mlir-pass-statistics-display",
78 llvm::cl::desc(
"Display method for pass statistics"),
83 "display the results in a merged list sorted by pass name"),
85 "display the results with a nested pipeline view"))};
89 static llvm::ManagedStatic<PassManagerOptions>
options;
92 void PassManagerOptions::addPrinterInstrumentation(
PassManager &pm) {
93 std::function<bool(
Pass *,
Operation *)> shouldPrintBeforePass;
94 std::function<bool(
Pass *,
Operation *)> shouldPrintAfterPass;
99 shouldPrintBeforePass = [](
Pass *,
Operation *) {
return true; };
100 }
else if (printBefore.hasAnyOccurrences()) {
105 return passInfo && printBefore.contains(passInfo);
110 if (printAfterAll || printAfterFailure) {
113 shouldPrintAfterPass = [](
Pass *,
Operation *) {
return true; };
114 }
else if (printAfter.hasAnyOccurrences()) {
119 return passInfo && printAfter.contains(passInfo);
124 if (!shouldPrintBeforePass && !shouldPrintAfterPass)
128 if (!printTreeDir.empty()) {
130 printModuleScope, printAfterChange,
131 printAfterFailure, printTreeDir);
136 printModuleScope, printAfterChange, printAfterFailure,
150 if (
options->reproducerFile.getNumOccurrences())
160 <<
"IR print for module scope can't be setup on a pass-manager "
161 "without disabling multi-threading first.\n";
166 options->addPrinterInstrumentation(pm);
173 auto tm = std::make_unique<DefaultTimingManager>();
static llvm::ManagedStatic< PassManagerOptions > options
bool isMultithreadingEnabled()
Return true if multi-threading is enabled by the context.
Operation is the basic unit of execution within MLIR.
The main pass manager and pipeline builder.
void enableStatistics(PassDisplayMode displayMode=PassDisplayMode::Pipeline)
Prompts the pass manager to print the statistics collected for each of the held passes after each cal...
MLIRContext * getContext() const
Return an instance of the context.
void enableIRPrinting(std::unique_ptr< IRPrinterConfig > config)
Add an instrumentation to print the IR before and after pass execution, using the provided configurat...
void enableIRPrintingToFileTree(std::function< bool(Pass *, Operation *)> shouldPrintBeforePass=[](Pass *, Operation *) { return true;}, std::function< bool(Pass *, Operation *)> shouldPrintAfterPass=[](Pass *, Operation *) { return true;}, bool printModuleScope=true, bool printAfterOnlyOnChange=true, bool printAfterOnlyOnFailure=false, llvm::StringRef printTreeDir=".pass_manager_output", OpPrintingFlags opPrintingFlags=OpPrintingFlags())
Similar to enableIRPrinting above, except that instead of printing the IR to a single output stream,...
void enableCrashReproducerGeneration(StringRef outputFile, bool genLocalReproducer=false)
Enable support for the pass manager to generate a reproducer on the event of a crash or a pass failur...
void enableTiming(TimingScope &timingScope)
Add an instrumentation to time the execution of passes and the computation of analyses.
This class implements a command-line parser specifically for MLIR pass names.
The abstract base pass class.
const PassInfo * lookupPassInfo() const
Returns the pass info for this pass, or null if unknown.
Include the generated interface declarations.
LogicalResult applyPassManagerCLOptions(PassManager &pm)
Apply any values provided to the pass manager options that were registered with 'registerPassManagerO...
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
void registerPassManagerCLOptions()
Register a set of useful command-line options that can be used to configure a pass manager.
void applyDefaultTimingManagerCLOptions(DefaultTimingManager &tm)
Apply any values that were registered with 'registerDefaultTimingManagerOptions' to a DefaultTimingMa...
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
void applyDefaultTimingPassManagerCLOptions(PassManager &pm)
Apply any values provided to the timing manager options that were registered with registerDefaultTimi...