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"
76 llvm::pointee_iterator<MutableArrayRef<std::unique_ptr<Pass>>::iterator>;
82 llvm::pointee_iterator<ArrayRef<std::unique_ptr<Pass>>::const_iterator>;
96 template <
typename OpT>
98 return nest(OpT::getOperationName());
107 void addPass(std::unique_ptr<Pass> pass);
114 template <
typename OpT>
128 std::optional<StringRef>
getOpName()
const;
151#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
152 LLVM_DUMP_METHOD
void dump();
179 llvm::hash_code
hash();
182 std::unique_ptr<detail::OpPassManagerImpl>
impl;
225 std::function<std::unique_ptr<ReproducerStream>(std::string &error)>;
230 Operation *op, StringRef outputFile,
bool disableThreads =
false,
231 bool verifyPasses =
false);
248 template <
typename OperationTy>
250 return PassManager(ctx, OperationTy::getOperationName(), nesting);
267 bool genLocalReproducer =
false);
275 bool genLocalReproducer =
false);
311 bool printModuleScope =
false,
bool printAfterOnlyOnChange =
false,
312 bool printAfterOnlyOnFailure =
false,
340 return printAfterOnlyOnFailure;
348 bool printModuleScope;
352 bool printAfterOnlyOnChange;
356 bool printAfterOnlyOnFailure;
384 std::function<
bool(
Pass *,
Operation *)> shouldPrintBeforePass =
386 std::function<
bool(
Pass *, Operation *)> shouldPrintAfterPass =
387 [](
Pass *, Operation *) {
return true; },
388 bool printModuleScope =
true,
bool printAfterOnlyOnChange =
true,
389 bool printAfterOnlyOnFailure =
false, raw_ostream &out = llvm::errs(),
390 OpPrintingFlags opPrintingFlags = OpPrintingFlags());
420 std::function<
bool(
Pass *, Operation *)> shouldPrintBeforePass =
421 [](
Pass *, Operation *) {
return true; },
422 std::function<bool(
Pass *, Operation *)> shouldPrintAfterPass =
423 [](
Pass *, Operation *) {
return true; },
424 bool printModuleScope =
true,
bool printAfterOnlyOnChange =
true,
425 bool printAfterOnlyOnFailure =
false,
426 llvm::StringRef printTreeDir =
".pass_manager_output",
427 OpPrintingFlags opPrintingFlags = OpPrintingFlags());
470 void dumpStatistics();
473 LogicalResult runWithCrashRecovery(Operation *op, AnalysisManager am);
476 LogicalResult runPasses(Operation *op, AnalysisManager am);
479 MLIRContext *context;
482 std::optional<PassDisplayMode> passStatisticsMode;
485 std::unique_ptr<PassInstrumentor> instrumentor;
489 std::unique_ptr<detail::PassCrashReproducerGenerator> crashReproGenerator;
492 llvm::hash_code initializationKey = llvm::hash_code(
static_cast<size_t>(-1));
493 llvm::hash_code pipelineInitializationKey =
494 llvm::hash_code(
static_cast<size_t>(-1));
500 bool verifyPasses : 1;
LogicalResult initialize(unsigned origNumLoops, ArrayRef< ReassociationIndices > foldedIterationDims)
static size_t hash(const T &value)
Local helper to compute std::hash for a value.
This class represents an analysis manager for a particular operation instance.
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,...
iterator_range< const_pass_iterator > getPasses() const
void mergeStatisticsInto(OpPassManager &other)
Merge the pass statistics of this class into 'other'.
void printAsTextualPipeline(raw_ostream &os, bool pretty=false) const
Prints out the passes of the pass manager as the textual representation of pipelines.
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.
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.
LLVM_DUMP_METHOD 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.
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...
iterator_range< pass_iterator > getPasses()
OpPassManager & nestAny()
Nest a new op-agnostic ("any") pass manager under this pass manager.
llvm::pointee_iterator< ArrayRef< std::unique_ptr< Pass > >::const_iterator > const_pass_iterator
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.
PassInstrumentation provides several entry points into the pass manager infrastructure.
This class holds a collection of PassInstrumentation objects, and invokes their respective call backs...
virtual ~IRPrinterConfig()
IRPrinterConfig(bool printModuleScope=false, bool printAfterOnlyOnChange=false, bool printAfterOnlyOnFailure=false, OpPrintingFlags opPrintingFlags=OpPrintingFlags())
Initialize the configuration.
function_ref< void(raw_ostream &)> PrintCallbackFn
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...
PassManager(MLIRContext *ctx, StringRef operationName=PassManager::getAnyOpAnchorName(), Nesting nesting=Nesting::Explicit)
Create a new pass manager under the given context with a specific nesting style.
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...
MLIRContext * getContext() const
Return an instance of the context.
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)
void registerPassManagerCLOptions()
Register a set of useful command-line options that can be used to configure a pass manager.
std::function< std::unique_ptr< ReproducerStream >(std::string &error)> ReproducerStreamFactory
Method type for constructing ReproducerStream.
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...
llvm::function_ref< Fn > function_ref
Streams on which to output crash reproducer.
virtual raw_ostream & os()=0
Stream on which to output reproducer.
virtual StringRef description()=0
Description of the reproducer stream.
virtual ~ReproducerStream()=default
The state for a single execution of a pass.