9 #ifndef MLIR_PASS_PASSMANAGER_H
10 #define MLIR_PASS_PASSMANAGER_H
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/iterator.h"
17 #include "llvm/Support/raw_ostream.h"
24 class AnalysisManager;
28 class PassInstrumentation;
29 class PassInstrumentor;
32 struct OpPassManagerImpl;
33 class OpToOpPassAdaptor;
34 class PassCrashReproducerGenerator;
35 struct PassExecutionState;
77 llvm::pointee_iterator<MutableArrayRef<std::unique_ptr<Pass>>::iterator>;
83 llvm::pointee_iterator<ArrayRef<std::unique_ptr<Pass>>::const_iterator>;
97 template <
typename OpT>
99 return nest(OpT::getOperationName());
108 void addPass(std::unique_ptr<Pass> pass);
115 template <
typename OpT>
117 nest<OpT>().addPass(std::move(pass));
129 std::optional<StringRef>
getOpName()
const;
172 LogicalResult initialize(
MLIRContext *context,
unsigned newInitGeneration);
176 llvm::hash_code hash();
179 std::unique_ptr<detail::OpPassManagerImpl>
impl;
217 virtual raw_ostream &
os() = 0;
222 std::function<std::unique_ptr<ReproducerStream>(std::string &error)>;
227 Operation *op, StringRef outputFile,
bool disableThreads =
false,
228 bool verifyPasses =
false);
245 template <
typename OperationTy>
247 return PassManager(ctx, OperationTy::getOperationName(), nesting);
264 bool genLocalReproducer =
false);
272 bool genLocalReproducer =
false);
308 bool printModuleScope =
false,
bool printAfterOnlyOnChange =
false,
309 bool printAfterOnlyOnFailure =
false,
337 return printAfterOnlyOnFailure;
345 bool printModuleScope;
349 bool printAfterOnlyOnChange;
353 bool printAfterOnlyOnFailure;
381 std::function<
bool(
Pass *,
Operation *)> shouldPrintBeforePass =
383 std::function<bool(
Pass *, Operation *)> shouldPrintAfterPass =
384 [](
Pass *, Operation *) {
return true; },
385 bool printModuleScope =
true,
bool printAfterOnlyOnChange =
true,
386 bool printAfterOnlyOnFailure =
false, raw_ostream &out = llvm::errs(),
387 OpPrintingFlags opPrintingFlags = OpPrintingFlags());
417 std::function<
bool(
Pass *, Operation *)> shouldPrintBeforePass =
418 [](
Pass *, Operation *) {
return true; },
419 std::function<bool(
Pass *, Operation *)> shouldPrintAfterPass =
420 [](
Pass *, Operation *) {
return true; },
421 bool printModuleScope =
true,
bool printAfterOnlyOnChange =
true,
422 bool printAfterOnlyOnFailure =
false,
423 llvm::StringRef printTreeDir =
".pass_manager_output",
424 OpPrintingFlags opPrintingFlags = OpPrintingFlags());
467 void dumpStatistics();
470 LogicalResult runWithCrashRecovery(Operation *op, AnalysisManager am);
473 LogicalResult runPasses(Operation *op, AnalysisManager am);
476 MLIRContext *context;
479 std::optional<PassDisplayMode> passStatisticsMode;
482 std::unique_ptr<PassInstrumentor> instrumentor;
486 std::unique_ptr<detail::PassCrashReproducerGenerator> crashReproGenerator;
489 llvm::hash_code initializationKey =
490 DenseMapInfo<llvm::hash_code>::getTombstoneKey();
491 llvm::hash_code pipelineInitializationKey =
492 DenseMapInfo<llvm::hash_code>::getTombstoneKey();
498 bool verifyPasses : 1;
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
This class represents a pass manager that runs passes on either a specific operation type,...
void mergeStatisticsInto(OpPassManager &other)
Merge the pass statistics of this class into 'other'.
OpPassManager & operator=(const OpPassManager &rhs)
friend class PassManager
Allow access to the constructor.
OpPassManager(Nesting nesting=Nesting::Explicit)
Construct a new op-agnostic ("any") pass manager with the given operation type and nesting behavior.
iterator_range< const_pass_iterator > getPasses() const
void printAsTextualPipeline(raw_ostream &os) const
Prints out the passes of the pass manager as the textual representation of pipelines.
void setNesting(Nesting nesting)
Enable or disable the implicit nesting on this particular PassManager.
bool empty() const
Returns true if the pass manager has no passes.
size_t size() const
Returns the number of passes held by this manager.
detail::OpPassManagerImpl & getImpl()
Returns the internal implementation instance.
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Nesting getNesting()
Return the current nesting mode.
Nesting
This enum represents the nesting behavior of the pass manager.
@ Implicit
Implicit nesting behavior.
@ Explicit
Explicit nesting behavior.
void dump()
Raw dump of the pass manager to llvm::errs().
llvm::pointee_iterator< MutableArrayRef< std::unique_ptr< Pass > >::iterator > pass_iterator
Iterator over the passes in this pass manager.
llvm::pointee_iterator< ArrayRef< std::unique_ptr< Pass > >::const_iterator > const_pass_iterator
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
void getDependentDialects(DialectRegistry &dialects) const
Register dependent dialects for the current pass manager.
StringRef getOpAnchorName() const
Return the name used to anchor this pass manager.
std::optional< StringRef > getOpName() const
Return the operation name that this pass manager operates on, or std::nullopt if this is an op-agnost...
OpPassManager & nestAny()
Nest a new op-agnostic ("any") pass manager under this pass manager.
iterator_range< pass_iterator > getPasses()
static StringRef getAnyOpAnchorName()
Return the string name used to anchor op-agnostic pass managers that operate generically on any viabl...
void clear()
Clear the pipeline, but not the other options set on this OpPassManager.
Set of flags used to control the behavior of the various IR print methods (e.g.
Operation is the basic unit of execution within MLIR.
A configuration struct provided to the IR printer instrumentation.
virtual ~IRPrinterConfig()
IRPrinterConfig(bool printModuleScope=false, bool printAfterOnlyOnChange=false, bool printAfterOnlyOnFailure=false, OpPrintingFlags opPrintingFlags=OpPrintingFlags())
Initialize the configuration.
bool shouldPrintAfterOnlyOnFailure() const
Returns true if the IR should only printed after a pass if the pass "failed".
virtual void printBeforeIfEnabled(Pass *pass, Operation *operation, PrintCallbackFn printCallback)
A hook that may be overridden by a derived config that checks if the IR of 'operation' should be dump...
bool shouldPrintAtModuleScope() const
Returns true if the IR should always be printed at the top-level scope.
virtual void printAfterIfEnabled(Pass *pass, Operation *operation, PrintCallbackFn printCallback)
A hook that may be overridden by a derived config that checks if the IR of 'operation' should be dump...
OpPrintingFlags getOpPrintingFlags() const
Returns the printing flags to be used to print the IR.
bool shouldPrintAfterOnlyOnChange() const
Returns true if the IR should only printed after a pass if the IR "changed".
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 enableTiming()
Add an instrumentation to time the execution of passes and the computation of analyses.
void enableIRPrinting(std::unique_ptr< IRPrinterConfig > config)
Add an instrumentation to print the IR before and after pass execution, using the provided configurat...
LogicalResult run(Operation *op)
Run the passes within this manager on the provided operation.
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,...
static PassManager on(MLIRContext *ctx, Nesting nesting=Nesting::Explicit)
Create a new pass manager under the given context with a specific nesting style.
void addInstrumentation(std::unique_ptr< PassInstrumentation > pi)
Add the provided instrumentation to the pass manager.
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 enableVerifier(bool enabled=true)
Runs the verifier after each individual pass.
The abstract base pass class.
An adaptor pass used to run operation passes over nested operations.
Include the generated interface declarations.
LogicalResult applyPassManagerCLOptions(PassManager &pm)
Apply any values provided to the pass manager options that were registered with 'registerPassManagerO...
std::string makeReproducer(StringRef anchorName, const llvm::iterator_range< OpPassManager::pass_iterator > &passes, Operation *op, StringRef outputFile, bool disableThreads=false, bool verifyPasses=false)
std::function< std::unique_ptr< ReproducerStream >(std::string &error)> ReproducerStreamFactory
Method type for constructing ReproducerStream.
void registerPassManagerCLOptions()
Register a set of useful command-line options that can be used to configure a pass manager.
PassDisplayMode
An enum describing the different display modes for the information within the pass manager.
void applyDefaultTimingPassManagerCLOptions(PassManager &pm)
Apply any values provided to the timing manager options that were registered with registerDefaultTimi...
Streams on which to output crash reproducer.
virtual StringRef description()=0
Description of the reproducer stream.
virtual raw_ostream & os()=0
Stream on which to output reproducer.
virtual ~ReproducerStream()=default