MLIR  16.0.0git
Go to the documentation of this file.
1 //===- PassDetail.h - MLIR Pass details -------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
11 #include "mlir/Pass/Pass.h"
12 #include "mlir/Pass/PassManager.h"
14 namespace mlir {
15 namespace detail {
17 //===----------------------------------------------------------------------===//
18 // OpToOpPassAdaptor
19 //===----------------------------------------------------------------------===//
21 /// An adaptor pass used to run operation passes over nested operations.
23  : public PassWrapper<OpToOpPassAdaptor, OperationPass<>> {
24 public:
26  OpToOpPassAdaptor(const OpToOpPassAdaptor &rhs) = default;
28  /// Run the held pipeline over all operations.
29  void runOnOperation(bool verifyPasses);
30  void runOnOperation() override;
32  /// Try to merge the current pass adaptor into 'rhs'. This will try to append
33  /// the pass managers of this adaptor into those within `rhs`, or return
34  /// failure if merging isn't possible. The main situation in which merging is
35  /// not possible is if one of the adaptors has an `any` pipeline that is not
36  /// compatible with a pass manager in the other adaptor. For example, if this
37  /// adaptor has a `func.func` pipeline and `rhs` has an `any` pipeline that
38  /// operates on FunctionOpInterface. In this situation the pipelines have a
39  /// conflict (they both want to run on the same operations), so we can't
40  /// merge.
43  /// Returns the pass managers held by this adaptor.
46  /// Populate the set of dependent dialects for the passes in the current
47  /// adaptor.
48  void getDependentDialects(DialectRegistry &dialects) const override;
50  /// Return the async pass managers held by this parallel adaptor.
52  return asyncExecutors;
53  }
55  /// Returns the adaptor pass name.
56  std::string getAdaptorName();
58 private:
59  /// Run this pass adaptor synchronously.
60  void runOnOperationImpl(bool verifyPasses);
62  /// Run this pass adaptor asynchronously.
63  void runOnOperationAsyncImpl(bool verifyPasses);
65  /// Run the given operation and analysis manager on a single pass.
66  /// `parentInitGeneration` is the initialization generation of the parent pass
67  /// manager, and is used to initialize any dynamic pass pipelines run by the
68  /// given pass.
69  static LogicalResult run(Pass *pass, Operation *op, AnalysisManager am,
70  bool verifyPasses, unsigned parentInitGeneration);
72  /// Run the given operation and analysis manager on a provided op pass
73  /// manager. `parentInitGeneration` is the initialization generation of the
74  /// parent pass manager, and is used to initialize any dynamic pass pipelines
75  /// run by the given passes.
76  static LogicalResult runPipeline(
77  OpPassManager &pm, Operation *op, AnalysisManager am, bool verifyPasses,
78  unsigned parentInitGeneration, PassInstrumentor *instrumentor = nullptr,
79  const PassInstrumentation::PipelineParentInfo *parentInfo = nullptr);
81  /// A set of adaptors to run.
84  /// A set of executors, cloned from the main executor, that run asynchronously
85  /// on different threads. This is used when threading is enabled.
88  // For accessing "runPipeline".
89  friend class mlir::PassManager;
90 };
92 //===----------------------------------------------------------------------===//
93 // PassCrashReproducerGenerator
94 //===----------------------------------------------------------------------===//
97 public:
100  bool localReproducer);
103  /// Initialize the generator in preparation for reproducer generation. The
104  /// generator should be reinitialized before each run of the pass manager.
106  Operation *op, bool pmFlagVerifyPasses);
107  /// Finalize the current run of the generator, generating any necessary
108  /// reproducers if the provided execution result is a failure.
109  void finalize(Operation *rootOp, LogicalResult executionResult);
111  /// Prepare a new reproducer for the given pass, operating on `op`.
112  void prepareReproducerFor(Pass *pass, Operation *op);
114  /// Prepare a new reproducer for the given passes, operating on `op`.
115  void prepareReproducerFor(iterator_range<PassManager::pass_iterator> passes,
116  Operation *op);
118  /// Remove the last recorded reproducer anchored at the given pass and
119  /// operation.
120  void removeLastReproducerFor(Pass *pass, Operation *op);
122 private:
123  struct Impl;
125  /// The internal implementation of the crash reproducer.
126  std::unique_ptr<Impl> impl;
127 };
129 } // namespace detail
130 } // namespace mlir
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
This struct represents information related to the parent pass of pipeline.
The main pass manager and pipeline builder.
Definition: PassManager.h:210
LogicalResult tryMergeInto(MLIRContext *ctx, OpToOpPassAdaptor &rhs)
Try to merge the current pass adaptor into &#39;rhs&#39;.
Definition: Pass.cpp:573
This class represents an analysis manager for a particular operation instance.
An adaptor pass used to run operation passes over nested operations.
Definition: PassDetail.h:22
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
OpToOpPassAdaptor(OpPassManager &&mgr)
Definition: Pass.cpp:564
MutableArrayRef< SmallVector< OpPassManager, 1 > > getParallelPassManagers()
Return the async pass managers held by this parallel adaptor.
Definition: PassDetail.h:51
void getDependentDialects(DialectRegistry &dialects) const override
Populate the set of dependent dialects for the passes in the current adaptor.
Definition: Pass.cpp:568
void runOnOperation() override
The polymorphic API that runs the pass over the currently held operation.
Definition: Pass.cpp:647
This class holds a collection of PassInstrumentation objects, and invokes their respective call backs...
std::function< std::unique_ptr< ReproducerStream >(std::string &error)> ReproducerStreamFactory
Method type for constructing ReproducerStream.
Definition: PassManager.h:252
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
The abstract base pass class.
Definition: Pass.h:50
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:55
MutableArrayRef< OpPassManager > getPassManagers()
Returns the pass managers held by this adaptor.
Definition: PassDetail.h:44
virtual LogicalResult initialize(MLIRContext *context)
Initialize any complex state necessary for running this pass.
Definition: Pass.h:184
This class represents a pass manager that runs passes on either a specific operation type...
Definition: PassManager.h:52
std::string getAdaptorName()
Returns the adaptor pass name.
Definition: Pass.cpp:637
This class provides a CRTP wrapper around a base pass class to define several necessary utility metho...
Definition: Pass.h:440