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"
23 class AnalysisManager;
27 class PassInstrumentation;
28 class PassInstrumentor;
31 struct OpPassManagerImpl;
32 class OpToOpPassAdaptor;
33 class PassCrashReproducerGenerator;
34 struct PassExecutionState;
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>
116 nest<OpT>().addPass(std::move(pass));
128 std::optional<StringRef>
getOpName()
const;
171 LogicalResult initialize(
MLIRContext *context,
unsigned newInitGeneration);
175 llvm::hash_code hash();
178 std::unique_ptr<detail::OpPassManagerImpl>
impl;
216 virtual raw_ostream &
os() = 0;
221 std::function<std::unique_ptr<ReproducerStream>(std::string &error)>;
226 Operation *op, StringRef outputFile,
bool disableThreads =
false,
227 bool verifyPasses =
false);
244 template <
typename OperationTy>
246 return PassManager(ctx, OperationTy::getOperationName(), nesting);
263 bool genLocalReproducer =
false);
271 bool genLocalReproducer =
false);
307 bool printModuleScope =
false,
bool printAfterOnlyOnChange =
false,
308 bool printAfterOnlyOnFailure =
false,
336 return printAfterOnlyOnFailure;
344 bool printModuleScope;
348 bool printAfterOnlyOnChange;
352 bool printAfterOnlyOnFailure;
380 std::function<
bool(
Pass *,
Operation *)> shouldPrintBeforePass =
382 std::function<bool(
Pass *, Operation *)> shouldPrintAfterPass =
383 [](
Pass *, Operation *) {
return true; },
384 bool printModuleScope =
true,
bool printAfterOnlyOnChange =
true,
385 bool printAfterOnlyOnFailure =
false, raw_ostream &out = llvm::errs(),
386 OpPrintingFlags opPrintingFlags = OpPrintingFlags());
416 std::function<
bool(
Pass *, Operation *)> shouldPrintBeforePass =
417 [](
Pass *, Operation *) {
return true; },
418 std::function<bool(
Pass *, Operation *)> shouldPrintAfterPass =
419 [](
Pass *, Operation *) {
return true; },
420 bool printModuleScope =
true,
bool printAfterOnlyOnChange =
true,
421 bool printAfterOnlyOnFailure =
false,
422 llvm::StringRef printTreeDir =
".pass_manager_output",
423 OpPrintingFlags opPrintingFlags = OpPrintingFlags());
466 void dumpStatistics();
469 LogicalResult runWithCrashRecovery(Operation *op, AnalysisManager am);
472 LogicalResult runPasses(Operation *op, AnalysisManager am);
475 MLIRContext *context;
478 std::optional<PassDisplayMode> passStatisticsMode;
481 std::unique_ptr<PassInstrumentor> instrumentor;
485 std::unique_ptr<detail::PassCrashReproducerGenerator> crashReproGenerator;
488 llvm::hash_code initializationKey =
489 DenseMapInfo<llvm::hash_code>::getTombstoneKey();
490 llvm::hash_code pipelineInitializationKey =
491 DenseMapInfo<llvm::hash_code>::getTombstoneKey();
497 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...
const FrozenRewritePatternSet GreedyRewriteConfig config
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