MLIR  18.0.0git
PassDetail.h
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 https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef MLIR_PASS_PASSDETAIL_H_
9 #define MLIR_PASS_PASSDETAIL_H_
10 
11 #include "mlir/IR/Action.h"
12 #include "mlir/Pass/Pass.h"
13 #include "mlir/Pass/PassManager.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/Support/FormatVariadic.h"
16 
17 namespace mlir {
18 /// Encapsulate the "action" of executing a single pass, used for the MLIR
19 /// tracing infrastructure.
20 struct PassExecutionAction : public tracing::ActionImpl<PassExecutionAction> {
23  : Base(irUnits), pass(pass) {}
24  static constexpr StringLiteral tag = "pass-execution";
25  void print(raw_ostream &os) const override;
26  const Pass &getPass() const { return pass; }
27  Operation *getOp() const {
29  return irUnits.empty() ? nullptr
30  : llvm::dyn_cast_if_present<Operation *>(irUnits[0]);
31  }
32 
33 public:
34  const Pass &pass;
36 };
37 
38 namespace detail {
39 
40 //===----------------------------------------------------------------------===//
41 // OpToOpPassAdaptor
42 //===----------------------------------------------------------------------===//
43 
44 /// An adaptor pass used to run operation passes over nested operations.
46  : public PassWrapper<OpToOpPassAdaptor, OperationPass<>> {
47 public:
49  OpToOpPassAdaptor(const OpToOpPassAdaptor &rhs) = default;
50 
51  /// Run the held pipeline over all operations.
52  void runOnOperation(bool verifyPasses);
53  void runOnOperation() override;
54 
55  /// Try to merge the current pass adaptor into 'rhs'. This will try to append
56  /// the pass managers of this adaptor into those within `rhs`, or return
57  /// failure if merging isn't possible. The main situation in which merging is
58  /// not possible is if one of the adaptors has an `any` pipeline that is not
59  /// compatible with a pass manager in the other adaptor. For example, if this
60  /// adaptor has a `func.func` pipeline and `rhs` has an `any` pipeline that
61  /// operates on FunctionOpInterface. In this situation the pipelines have a
62  /// conflict (they both want to run on the same operations), so we can't
63  /// merge.
65 
66  /// Returns the pass managers held by this adaptor.
68 
69  /// Populate the set of dependent dialects for the passes in the current
70  /// adaptor.
71  void getDependentDialects(DialectRegistry &dialects) const override;
72 
73  /// Return the async pass managers held by this parallel adaptor.
75  return asyncExecutors;
76  }
77 
78  /// Returns the adaptor pass name.
79  std::string getAdaptorName();
80 
81 private:
82  /// Run this pass adaptor synchronously.
83  void runOnOperationImpl(bool verifyPasses);
84 
85  /// Run this pass adaptor asynchronously.
86  void runOnOperationAsyncImpl(bool verifyPasses);
87 
88  /// Run the given operation and analysis manager on a single pass.
89  /// `parentInitGeneration` is the initialization generation of the parent pass
90  /// manager, and is used to initialize any dynamic pass pipelines run by the
91  /// given pass.
92  static LogicalResult run(Pass *pass, Operation *op, AnalysisManager am,
93  bool verifyPasses, unsigned parentInitGeneration);
94 
95  /// Run the given operation and analysis manager on a provided op pass
96  /// manager. `parentInitGeneration` is the initialization generation of the
97  /// parent pass manager, and is used to initialize any dynamic pass pipelines
98  /// run by the given passes.
99  static LogicalResult runPipeline(
100  OpPassManager &pm, Operation *op, AnalysisManager am, bool verifyPasses,
101  unsigned parentInitGeneration, PassInstrumentor *instrumentor = nullptr,
102  const PassInstrumentation::PipelineParentInfo *parentInfo = nullptr);
103 
104  /// A set of adaptors to run.
106 
107  /// A set of executors, cloned from the main executor, that run asynchronously
108  /// on different threads. This is used when threading is enabled.
110 
111  // For accessing "runPipeline".
112  friend class mlir::PassManager;
113 };
114 
115 //===----------------------------------------------------------------------===//
116 // PassCrashReproducerGenerator
117 //===----------------------------------------------------------------------===//
118 
120 public:
123  bool localReproducer);
125 
126  /// Initialize the generator in preparation for reproducer generation. The
127  /// generator should be reinitialized before each run of the pass manager.
129  Operation *op, bool pmFlagVerifyPasses);
130  /// Finalize the current run of the generator, generating any necessary
131  /// reproducers if the provided execution result is a failure.
132  void finalize(Operation *rootOp, LogicalResult executionResult);
133 
134  /// Prepare a new reproducer for the given pass, operating on `op`.
135  void prepareReproducerFor(Pass *pass, Operation *op);
136 
137  /// Prepare a new reproducer for the given passes, operating on `op`.
139  Operation *op);
140 
141  /// Remove the last recorded reproducer anchored at the given pass and
142  /// operation.
143  void removeLastReproducerFor(Pass *pass, Operation *op);
144 
145 private:
146  struct Impl;
147 
148  /// The internal implementation of the crash reproducer.
149  std::unique_ptr<Impl> impl;
150 };
151 
152 } // namespace detail
153 } // namespace mlir
154 #endif // MLIR_PASS_PASSDETAIL_H_
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.
Definition: MLIRContext.h:60
This class represents a pass manager that runs passes on either a specific operation type,...
Definition: PassManager.h:48
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class holds a collection of PassInstrumentation objects, and invokes their respective call backs...
The main pass manager and pipeline builder.
Definition: PassManager.h:211
std::function< std::unique_ptr< ReproducerStream >(std::string &error)> ReproducerStreamFactory
Method type for constructing ReproducerStream.
Definition: PassManager.h:259
This class provides a CRTP wrapper around a base pass class to define several necessary utility metho...
Definition: Pass.h:440
The abstract base pass class.
Definition: Pass.h:51
An adaptor pass used to run operation passes over nested operations.
Definition: PassDetail.h:46
void getDependentDialects(DialectRegistry &dialects) const override
Populate the set of dependent dialects for the passes in the current adaptor.
Definition: Pass.cpp:603
MutableArrayRef< OpPassManager > getPassManagers()
Returns the pass managers held by this adaptor.
Definition: PassDetail.h:67
OpToOpPassAdaptor(const OpToOpPassAdaptor &rhs)=default
void runOnOperation() override
The polymorphic API that runs the pass over the currently held operation.
Definition: Pass.cpp:682
std::string getAdaptorName()
Returns the adaptor pass name.
Definition: Pass.cpp:672
MutableArrayRef< SmallVector< OpPassManager, 1 > > getParallelPassManagers()
Return the async pass managers held by this parallel adaptor.
Definition: PassDetail.h:74
LogicalResult tryMergeInto(MLIRContext *ctx, OpToOpPassAdaptor &rhs)
Try to merge the current pass adaptor into 'rhs'.
Definition: Pass.cpp:608
OpToOpPassAdaptor(OpPassManager &&mgr)
Definition: Pass.cpp:599
void initialize(iterator_range< PassManager::pass_iterator > passes, Operation *op, bool pmFlagVerifyPasses)
Initialize the generator in preparation for reproducer generation.
void removeLastReproducerFor(Pass *pass, Operation *op)
Remove the last recorded reproducer anchored at the given pass and operation.
void finalize(Operation *rootOp, LogicalResult executionResult)
Finalize the current run of the generator, generating any necessary reproducers if the provided execu...
PassCrashReproducerGenerator(PassManager::ReproducerStreamFactory &streamFactory, bool localReproducer)
void prepareReproducerFor(Pass *pass, Operation *op)
Prepare a new reproducer for the given pass, operating on op.
CRTP Implementation of an action.
Definition: Action.h:77
virtual ArrayRef< IRUnit > getContextIRUnits() const
Return the set of IR units that are associated with this action.
Definition: Action.h:56
ArrayRef< IRUnit > irUnits
Set of IR units (operations, regions, blocks, values) that are associated with this action.
Definition: Action.h:67
Include the generated interface declarations.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
Encapsulate the "action" of executing a single pass, used for the MLIR tracing infrastructure.
Definition: PassDetail.h:20
PassExecutionAction(ArrayRef< IRUnit > irUnits, const Pass &pass)
Definition: PassDetail.h:22
void print(raw_ostream &os) const override
Definition: Pass.cpp:39
const Pass & getPass() const
Definition: PassDetail.h:26
Operation * getOp() const
Definition: PassDetail.h:27
static constexpr StringLiteral tag
Definition: PassDetail.h:24
This struct represents information related to the parent pass of pipeline.