9 #ifndef MLIR_PASS_PASSMANAGER_H
10 #define MLIR_PASS_PASSMANAGER_H
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/iterator.h"
18 #include "llvm/Support/raw_ostream.h"
25 class AnalysisManager;
29 class PassInstrumentation;
30 class PassInstrumentor;
33 struct OpPassManagerImpl;
34 class OpToOpPassAdaptor;
35 class PassCrashReproducerGenerator;
36 struct PassExecutionState;
78 llvm::pointee_iterator<MutableArrayRef<std::unique_ptr<Pass>>::iterator>;
84 llvm::pointee_iterator<ArrayRef<std::unique_ptr<Pass>>::const_iterator>;
98 template <
typename OpT>
100 return nest(OpT::getOperationName());
109 void addPass(std::unique_ptr<Pass> pass);
116 template <
typename OpT>
118 nest<OpT>().addPass(std::move(pass));
130 std::optional<StringRef>
getOpName()
const;
177 llvm::hash_code hash();
180 std::unique_ptr<detail::OpPassManagerImpl>
impl;
225 template <
typename OperationTy>
227 return PassManager(ctx, OperationTy::getOperationName(), nesting);
244 bool genLocalReproducer =
false);
254 virtual raw_ostream &
os() = 0;
259 std::function<std::unique_ptr<ReproducerStream>(std::string &error)>;
267 bool genLocalReproducer =
false);
303 bool printModuleScope =
false,
bool printAfterOnlyOnChange =
false,
304 bool printAfterOnlyOnFailure =
false,
332 return printAfterOnlyOnFailure;
340 bool printModuleScope;
344 bool printAfterOnlyOnChange;
348 bool printAfterOnlyOnFailure;
376 std::function<
bool(
Pass *,
Operation *)> shouldPrintBeforePass =
378 std::function<bool(
Pass *, Operation *)> shouldPrintAfterPass =
379 [](
Pass *, Operation *) {
return true; },
380 bool printModuleScope =
true,
bool printAfterOnlyOnChange =
true,
381 bool printAfterOnlyOnFailure =
false, raw_ostream &out = llvm::errs(),
382 OpPrintingFlags opPrintingFlags = OpPrintingFlags());
425 void dumpStatistics();
428 LogicalResult runWithCrashRecovery(Operation *op, AnalysisManager am);
431 LogicalResult runPasses(Operation *op, AnalysisManager am);
434 MLIRContext *context;
437 std::optional<PassDisplayMode> passStatisticsMode;
440 std::unique_ptr<PassInstrumentor> instrumentor;
444 std::unique_ptr<detail::PassCrashReproducerGenerator> crashReproGenerator;
447 llvm::hash_code initializationKey =
448 DenseMapInfo<llvm::hash_code>::getTombstoneKey();
449 llvm::hash_code pipelineInitializationKey =
450 DenseMapInfo<llvm::hash_code>::getTombstoneKey();
456 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.
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.
std::function< std::unique_ptr< ReproducerStream >(std::string &error)> ReproducerStreamFactory
Method type for constructing ReproducerStream.
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...
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...
This class represents an efficient way to signal success or failure.
Streams on which to output crash reproducer.
virtual ~ReproducerStream()=default
virtual raw_ostream & os()=0
Stream on which to output reproducer.
virtual StringRef description()=0
Description of the reproducer stream.