MLIR  21.0.0git
PassManager.h
Go to the documentation of this file.
1 //===- PassManager.h - Pass Management Interface ----------------*- 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 
9 #ifndef MLIR_PASS_PASSMANAGER_H
10 #define MLIR_PASS_PASSMANAGER_H
11 
12 #include "mlir/IR/Dialect.h"
14 #include "mlir/Support/Timing.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/iterator.h"
17 #include "llvm/Support/raw_ostream.h"
18 
19 #include <functional>
20 #include <optional>
21 
22 namespace mlir {
23 class AnalysisManager;
24 class MLIRContext;
25 class Operation;
26 class Pass;
27 class PassInstrumentation;
28 class PassInstrumentor;
29 
30 namespace detail {
31 struct OpPassManagerImpl;
32 class OpToOpPassAdaptor;
33 class PassCrashReproducerGenerator;
34 struct PassExecutionState;
35 } // namespace detail
36 
37 //===----------------------------------------------------------------------===//
38 // OpPassManager
39 //===----------------------------------------------------------------------===//
40 
41 /// This class represents a pass manager that runs passes on either a specific
42 /// operation type, or any isolated operation. This pass manager can not be run
43 /// on an operation directly, but must be run either as part of a top-level
44 /// `PassManager`(e.g. when constructed via `nest` calls), or dynamically within
45 /// a pass by using the `Pass::runPipeline` API.
47 public:
48  /// This enum represents the nesting behavior of the pass manager.
49  enum class Nesting {
50  /// Implicit nesting behavior. This allows for adding passes operating on
51  /// operations different from this pass manager, in which case a new pass
52  /// manager is implicitly nested for the operation type of the new pass.
53  Implicit,
54  /// Explicit nesting behavior. This requires that any passes added to this
55  /// pass manager support its operation type.
56  Explicit
57  };
58 
59  /// Construct a new op-agnostic ("any") pass manager with the given operation
60  /// type and nesting behavior. This is the same as invoking:
61  /// `OpPassManager(getAnyOpAnchorName(), nesting)`.
63 
64  /// Construct a new pass manager with the given anchor operation type and
65  /// nesting behavior.
66  OpPassManager(StringRef name, Nesting nesting = Nesting::Explicit);
69  OpPassManager(const OpPassManager &rhs);
73 
74  /// Iterator over the passes in this pass manager.
75  using pass_iterator =
76  llvm::pointee_iterator<MutableArrayRef<std::unique_ptr<Pass>>::iterator>;
80 
82  llvm::pointee_iterator<ArrayRef<std::unique_ptr<Pass>>::const_iterator>;
83  const_pass_iterator begin() const;
84  const_pass_iterator end() const;
86  return {begin(), end()};
87  }
88 
89  /// Returns true if the pass manager has no passes.
90  bool empty() const { return begin() == end(); }
91 
92  /// Nest a new operation pass manager for the given operation kind under this
93  /// pass manager.
94  OpPassManager &nest(OperationName nestedName);
95  OpPassManager &nest(StringRef nestedName);
96  template <typename OpT>
98  return nest(OpT::getOperationName());
99  }
100 
101  /// Nest a new op-agnostic ("any") pass manager under this pass manager.
102  /// Note: This is the same as invoking `nest(getAnyOpAnchorName())`.
104 
105  /// Add the given pass to this pass manager. If this pass has a concrete
106  /// operation type, it must be the same type as this pass manager.
107  void addPass(std::unique_ptr<Pass> pass);
108 
109  /// Clear the pipeline, but not the other options set on this OpPassManager.
110  void clear();
111 
112  /// Add the given pass to a nested pass manager for the given operation kind
113  /// `OpT`.
114  template <typename OpT>
115  void addNestedPass(std::unique_ptr<Pass> pass) {
116  nest<OpT>().addPass(std::move(pass));
117  }
118 
119  /// Returns the number of passes held by this manager.
120  size_t size() const;
121 
122  /// Return the operation name that this pass manager operates on, or
123  /// std::nullopt if this is an op-agnostic pass manager.
124  std::optional<OperationName> getOpName(MLIRContext &context) const;
125 
126  /// Return the operation name that this pass manager operates on, or
127  /// std::nullopt if this is an op-agnostic pass manager.
128  std::optional<StringRef> getOpName() const;
129 
130  /// Return the name used to anchor this pass manager. This is either the name
131  /// of an operation, or the result of `getAnyOpAnchorName()` in the case of an
132  /// op-agnostic pass manager.
133  StringRef getOpAnchorName() const;
134 
135  /// Return the string name used to anchor op-agnostic pass managers that
136  /// operate generically on any viable operation.
137  static StringRef getAnyOpAnchorName() { return "any"; }
138 
139  /// Returns the internal implementation instance.
141 
142  /// Prints out the passes of the pass manager as the textual representation
143  /// of pipelines.
144  /// Note: The quality of the string representation depends entirely on the
145  /// the correctness of per-pass overrides of Pass::printAsTextualPipeline.
146  void printAsTextualPipeline(raw_ostream &os) const;
147 
148  /// Raw dump of the pass manager to llvm::errs().
149  void dump();
150 
151  /// Merge the pass statistics of this class into 'other'.
152  void mergeStatisticsInto(OpPassManager &other);
153 
154  /// Register dependent dialects for the current pass manager.
155  /// This is forwarding to every pass in this PassManager, see the
156  /// documentation for the same method on the Pass class.
157  void getDependentDialects(DialectRegistry &dialects) const;
158 
159  /// Enable or disable the implicit nesting on this particular PassManager.
160  /// This will also apply to any newly nested PassManager built from this
161  /// instance.
162  void setNesting(Nesting nesting);
163 
164  /// Return the current nesting mode.
166 
167 private:
168  /// Initialize all of the passes within this pass manager with the given
169  /// initialization generation. The initialization generation is used to detect
170  /// if a pass manager has already been initialized.
171  LogicalResult initialize(MLIRContext *context, unsigned newInitGeneration);
172 
173  /// Compute a hash of the pipeline, so that we can detect changes (a pass is
174  /// added...).
175  llvm::hash_code hash();
176 
177  /// A pointer to an internal implementation instance.
178  std::unique_ptr<detail::OpPassManagerImpl> impl;
179 
180  /// Allow access to initialize.
182 
183  /// Allow access to the constructor.
184  friend class PassManager;
185  friend class Pass;
186 
187  /// Allow access.
189 };
190 
191 //===----------------------------------------------------------------------===//
192 // PassManager
193 //===----------------------------------------------------------------------===//
194 
195 /// An enum describing the different display modes for the information within
196 /// the pass manager.
197 enum class PassDisplayMode {
198  // In this mode the results are displayed in a list sorted by total,
199  // with each pass/analysis instance aggregated into one unique result.
200  List,
201 
202  // In this mode the results are displayed in a nested pipeline view that
203  // mirrors the internal pass pipeline that is being executed in the pass
204  // manager.
205  Pipeline,
206 };
207 
208 /// Streams on which to output crash reproducer.
210  virtual ~ReproducerStream() = default;
211 
212  /// Description of the reproducer stream.
213  virtual StringRef description() = 0;
214 
215  /// Stream on which to output reproducer.
216  virtual raw_ostream &os() = 0;
217 };
218 
219 /// Method type for constructing ReproducerStream.
221  std::function<std::unique_ptr<ReproducerStream>(std::string &error)>;
222 
223 std::string
224 makeReproducer(StringRef anchorName,
226  Operation *op, StringRef outputFile, bool disableThreads = false,
227  bool verifyPasses = false);
228 
229 /// The main pass manager and pipeline builder.
230 class PassManager : public OpPassManager {
231 public:
232  /// Create a new pass manager under the given context with a specific nesting
233  /// style. The created pass manager can schedule operations that match
234  /// `operationName`.
236  StringRef operationName = PassManager::getAnyOpAnchorName(),
237  Nesting nesting = Nesting::Explicit);
238  PassManager(OperationName operationName, Nesting nesting = Nesting::Explicit);
240 
241  /// Create a new pass manager under the given context with a specific nesting
242  /// style. The created pass manager can schedule operations that match
243  /// `OperationTy`.
244  template <typename OperationTy>
246  return PassManager(ctx, OperationTy::getOperationName(), nesting);
247  }
248 
249  /// Run the passes within this manager on the provided operation. The
250  /// specified operation must have the same name as the one provided the pass
251  /// manager on construction.
252  LogicalResult run(Operation *op);
253 
254  /// Return an instance of the context.
255  MLIRContext *getContext() const { return context; }
256 
257  /// Enable support for the pass manager to generate a reproducer on the event
258  /// of a crash or a pass failure. `outputFile` is a .mlir filename used to
259  /// write the generated reproducer. If `genLocalReproducer` is true, the pass
260  /// manager will attempt to generate a local reproducer that contains the
261  /// smallest pipeline.
262  void enableCrashReproducerGeneration(StringRef outputFile,
263  bool genLocalReproducer = false);
264 
265  /// Enable support for the pass manager to generate a reproducer on the event
266  /// of a crash or a pass failure. `factory` is used to construct the streams
267  /// to write the generated reproducer to. If `genLocalReproducer` is true, the
268  /// pass manager will attempt to generate a local reproducer that contains the
269  /// smallest pipeline.
271  bool genLocalReproducer = false);
272 
273  /// Runs the verifier after each individual pass.
274  void enableVerifier(bool enabled = true);
275 
276  //===--------------------------------------------------------------------===//
277  // Instrumentations
278  //===--------------------------------------------------------------------===//
279 
280  /// Add the provided instrumentation to the pass manager.
281  void addInstrumentation(std::unique_ptr<PassInstrumentation> pi);
282 
283  //===--------------------------------------------------------------------===//
284  // IR Printing
285 
286  /// A configuration struct provided to the IR printer instrumentation.
288  public:
289  using PrintCallbackFn = function_ref<void(raw_ostream &)>;
290 
291  /// Initialize the configuration.
292  /// * 'printModuleScope' signals if the top-level module IR should always be
293  /// printed. This should only be set to true when multi-threading is
294  /// disabled, otherwise we may try to print IR that is being modified
295  /// asynchronously.
296  /// * 'printAfterOnlyOnChange' signals that when printing the IR after a
297  /// pass, in the case of a non-failure, we should first check if any
298  /// potential mutations were made. This allows for reducing the number of
299  /// logs that don't contain meaningful changes.
300  /// * 'printAfterOnlyOnFailure' signals that when printing the IR after a
301  /// pass, we only print in the case of a failure.
302  /// - This option should *not* be used with the other `printAfter` flags
303  /// above.
304  /// * 'opPrintingFlags' sets up the printing flags to use when printing the
305  /// IR.
306  explicit IRPrinterConfig(
307  bool printModuleScope = false, bool printAfterOnlyOnChange = false,
308  bool printAfterOnlyOnFailure = false,
309  OpPrintingFlags opPrintingFlags = OpPrintingFlags());
310  virtual ~IRPrinterConfig();
311 
312  /// A hook that may be overridden by a derived config that checks if the IR
313  /// of 'operation' should be dumped *before* the pass 'pass' has been
314  /// executed. If the IR should be dumped, 'printCallback' should be invoked
315  /// with the stream to dump into.
316  virtual void printBeforeIfEnabled(Pass *pass, Operation *operation,
317  PrintCallbackFn printCallback);
318 
319  /// A hook that may be overridden by a derived config that checks if the IR
320  /// of 'operation' should be dumped *after* the pass 'pass' has been
321  /// executed. If the IR should be dumped, 'printCallback' should be invoked
322  /// with the stream to dump into.
323  virtual void printAfterIfEnabled(Pass *pass, Operation *operation,
324  PrintCallbackFn printCallback);
325 
326  /// Returns true if the IR should always be printed at the top-level scope.
327  bool shouldPrintAtModuleScope() const { return printModuleScope; }
328 
329  /// Returns true if the IR should only printed after a pass if the IR
330  /// "changed".
331  bool shouldPrintAfterOnlyOnChange() const { return printAfterOnlyOnChange; }
332 
333  /// Returns true if the IR should only printed after a pass if the pass
334  /// "failed".
336  return printAfterOnlyOnFailure;
337  }
338 
339  /// Returns the printing flags to be used to print the IR.
340  OpPrintingFlags getOpPrintingFlags() const { return opPrintingFlags; }
341 
342  private:
343  /// A flag that indicates if the IR should be printed at module scope.
344  bool printModuleScope;
345 
346  /// A flag that indicates that the IR after a pass should only be printed if
347  /// a change is detected.
348  bool printAfterOnlyOnChange;
349 
350  /// A flag that indicates that the IR after a pass should only be printed if
351  /// the pass failed.
352  bool printAfterOnlyOnFailure;
353 
354  /// Flags to control printing behavior.
355  OpPrintingFlags opPrintingFlags;
356  };
357 
358  /// Add an instrumentation to print the IR before and after pass execution,
359  /// using the provided configuration.
360  void enableIRPrinting(std::unique_ptr<IRPrinterConfig> config);
361 
362  /// Add an instrumentation to print the IR before and after pass execution,
363  /// using the provided fields to generate a default configuration:
364  /// * 'shouldPrintBeforePass' and 'shouldPrintAfterPass' correspond to filter
365  /// functions that take a 'Pass *' and `Operation *`. These function should
366  /// return true if the IR should be printed or not.
367  /// * 'printModuleScope' signals if the module IR should be printed, even
368  /// for non module passes.
369  /// * 'printAfterOnlyOnChange' signals that when printing the IR after a
370  /// pass, in the case of a non-failure, we should first check if any
371  /// potential mutations were made.
372  /// * 'printAfterOnlyOnFailure' signals that when printing the IR after a
373  /// pass, we only print in the case of a failure.
374  /// - This option should *not* be used with the other `printAfter` flags
375  /// above.
376  /// * 'out' corresponds to the stream to output the printed IR to.
377  /// * 'opPrintingFlags' sets up the printing flags to use when printing the
378  /// IR.
379  void enableIRPrinting(
380  std::function<bool(Pass *, Operation *)> shouldPrintBeforePass =
381  [](Pass *, Operation *) { return true; },
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());
387 
388  /// Similar to `enableIRPrinting` above, except that instead of printing
389  /// the IR to a single output stream, the instrumentation will print the
390  /// output of each pass to a separate file. The files will be organized into a
391  /// directory tree rooted at `printTreeDir`. The directories mirror the
392  /// nesting structure of the IR. For example, if the IR is congruent to the
393  /// pass-pipeline "builtin.module(passA,passB,func.func(passC,passD),passE)",
394  /// and `printTreeDir=/tmp/pipeline_output`, then then the tree file tree
395  /// created will look like:
396  ///
397  /// ```
398  /// /tmp/pass_output
399  /// ├── builtin_module_the_symbol_name
400  /// │ ├── 0_passA.mlir
401  /// │ ├── 1_passB.mlir
402  /// │ ├── 2_passE.mlir
403  /// │ ├── func_func_my_func_name
404  /// │ │ ├── 1_0_passC.mlir
405  /// │ │ ├── 1_1__passD.mlir
406  /// │ ├── func_func_my_other_func_name
407  /// │ │ ├── 1_0_passC.mlir
408  /// │ │ ├── 1_1_passD.mlir
409  /// ```
410  ///
411  /// The subdirectories are given names that reflect the parent operation name
412  /// and symbol name (if present). The output MLIR files are prefixed using an
413  /// atomic counter to indicate the order the passes were printed in and to
414  /// prevent any potential name collisions.
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());
424 
425  //===--------------------------------------------------------------------===//
426  // Pass Timing
427 
428  /// Add an instrumentation to time the execution of passes and the computation
429  /// of analyses. Timing will be reported by nesting timers into the provided
430  /// `timingScope`.
431  ///
432  /// Note: Timing should be enabled after all other instrumentations to avoid
433  /// any potential "ghost" timing from other instrumentations being
434  /// unintentionally included in the timing results.
435  void enableTiming(TimingScope &timingScope);
436 
437  /// Add an instrumentation to time the execution of passes and the computation
438  /// of analyses. The pass manager will take ownership of the timing manager
439  /// passed to the function and timing will be reported by nesting timers into
440  /// the timing manager's root scope.
441  ///
442  /// Note: Timing should be enabled after all other instrumentations to avoid
443  /// any potential "ghost" timing from other instrumentations being
444  /// unintentionally included in the timing results.
445  void enableTiming(std::unique_ptr<TimingManager> tm);
446 
447  /// Add an instrumentation to time the execution of passes and the computation
448  /// of analyses. Creates a temporary TimingManager owned by this PassManager
449  /// which will be used to report timing.
450  ///
451  /// Note: Timing should be enabled after all other instrumentations to avoid
452  /// any potential "ghost" timing from other instrumentations being
453  /// unintentionally included in the timing results.
454  void enableTiming();
455 
456  //===--------------------------------------------------------------------===//
457  // Pass Statistics
458 
459  /// Prompts the pass manager to print the statistics collected for each of the
460  /// held passes after each call to 'run'.
461  void
463 
464 private:
465  /// Dump the statistics of the passes within this pass manager.
466  void dumpStatistics();
467 
468  /// Run the pass manager with crash recovery enabled.
469  LogicalResult runWithCrashRecovery(Operation *op, AnalysisManager am);
470 
471  /// Run the passes of the pass manager, and return the result.
472  LogicalResult runPasses(Operation *op, AnalysisManager am);
473 
474  /// Context this PassManager was initialized with.
475  MLIRContext *context;
476 
477  /// Flag that specifies if pass statistics should be dumped.
478  std::optional<PassDisplayMode> passStatisticsMode;
479 
480  /// A manager for pass instrumentations.
481  std::unique_ptr<PassInstrumentor> instrumentor;
482 
483  /// An optional crash reproducer generator, if this pass manager is setup to
484  /// generate reproducers.
485  std::unique_ptr<detail::PassCrashReproducerGenerator> crashReproGenerator;
486 
487  /// Hash keys used to detect when reinitialization is necessary.
488  llvm::hash_code initializationKey =
489  DenseMapInfo<llvm::hash_code>::getTombstoneKey();
490  llvm::hash_code pipelineInitializationKey =
491  DenseMapInfo<llvm::hash_code>::getTombstoneKey();
492 
493  /// Flag that specifies if pass timing is enabled.
494  bool passTiming : 1;
495 
496  /// A flag that indicates if the IR should be verified in between passes.
497  bool verifyPasses : 1;
498 };
499 
500 /// Register a set of useful command-line options that can be used to configure
501 /// a pass manager. The values of these options can be applied via the
502 /// 'applyPassManagerCLOptions' method below.
504 
505 /// Apply any values provided to the pass manager options that were registered
506 /// with 'registerPassManagerOptions'.
507 LogicalResult applyPassManagerCLOptions(PassManager &pm);
508 
509 /// Apply any values provided to the timing manager options that were registered
510 /// with `registerDefaultTimingManagerOptions`. This is a handy helper function
511 /// if you do not want to bother creating your own timing manager and passing it
512 /// to the pass manager.
513 void applyDefaultTimingPassManagerCLOptions(PassManager &pm);
514 
515 } // namespace mlir
516 
517 #endif // MLIR_PASS_PASSMANAGER_H
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:46
void mergeStatisticsInto(OpPassManager &other)
Merge the pass statistics of this class into 'other'.
OpPassManager & operator=(const OpPassManager &rhs)
Definition: Pass.cpp:326
friend class PassManager
Allow access to the constructor.
Definition: PassManager.h:184
OpPassManager(Nesting nesting=Nesting::Explicit)
Construct a new op-agnostic ("any") pass manager with the given operation type and nesting behavior.
Definition: Pass.cpp:318
OpPassManager & nest()
Definition: PassManager.h:97
iterator_range< const_pass_iterator > getPasses() const
Definition: PassManager.h:85
void printAsTextualPipeline(raw_ostream &os) const
Prints out the passes of the pass manager as the textual representation of pipelines.
Definition: Pass.cpp:401
friend class Pass
Definition: PassManager.h:185
void setNesting(Nesting nesting)
Enable or disable the implicit nesting on this particular PassManager.
Definition: Pass.cpp:425
bool empty() const
Returns true if the pass manager has no passes.
Definition: PassManager.h:90
size_t size() const
Returns the number of passes held by this manager.
Definition: Pass.cpp:370
detail::OpPassManagerImpl & getImpl()
Returns the internal implementation instance.
Definition: Pass.cpp:373
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Definition: Pass.cpp:363
Nesting getNesting()
Return the current nesting mode.
Definition: Pass.cpp:427
Nesting
This enum represents the nesting behavior of the pass manager.
Definition: PassManager.h:49
@ Implicit
Implicit nesting behavior.
@ Explicit
Explicit nesting behavior.
void dump()
Raw dump of the pass manager to llvm::errs().
Definition: Pass.cpp:409
llvm::pointee_iterator< MutableArrayRef< std::unique_ptr< Pass > >::iterator > pass_iterator
Iterator over the passes in this pass manager.
Definition: PassManager.h:76
llvm::pointee_iterator< ArrayRef< std::unique_ptr< Pass > >::const_iterator > const_pass_iterator
Definition: PassManager.h:82
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
Definition: PassManager.h:115
void getDependentDialects(DialectRegistry &dialects) const
Register dependent dialects for the current pass manager.
Definition: Pass.cpp:421
StringRef getOpAnchorName() const
Return the name used to anchor this pass manager.
Definition: Pass.cpp:386
std::optional< StringRef > getOpName() const
Return the operation name that this pass manager operates on, or std::nullopt if this is an op-agnost...
Definition: Pass.cpp:376
OpPassManager & nestAny()
Nest a new op-agnostic ("any") pass manager under this pass manager.
Definition: Pass.cpp:359
iterator_range< pass_iterator > getPasses()
Definition: PassManager.h:79
static StringRef getAnyOpAnchorName()
Return the string name used to anchor op-agnostic pass managers that operate generically on any viabl...
Definition: PassManager.h:137
void clear()
Clear the pipeline, but not the other options set on this OpPassManager.
Definition: Pass.cpp:367
pass_iterator begin()
Definition: Pass.cpp:337
pass_iterator end()
Definition: Pass.cpp:340
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.
Definition: Operation.h:88
A configuration struct provided to the IR printer instrumentation.
Definition: PassManager.h:287
IRPrinterConfig(bool printModuleScope=false, bool printAfterOnlyOnChange=false, bool printAfterOnlyOnFailure=false, OpPrintingFlags opPrintingFlags=OpPrintingFlags())
Initialize the configuration.
Definition: IRPrinting.cpp:138
bool shouldPrintAfterOnlyOnFailure() const
Returns true if the IR should only printed after a pass if the pass "failed".
Definition: PassManager.h:335
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...
Definition: IRPrinting.cpp:152
bool shouldPrintAtModuleScope() const
Returns true if the IR should always be printed at the top-level scope.
Definition: PassManager.h:327
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...
Definition: IRPrinting.cpp:161
OpPrintingFlags getOpPrintingFlags() const
Returns the printing flags to be used to print the IR.
Definition: PassManager.h:340
bool shouldPrintAfterOnlyOnChange() const
Returns true if the IR should only printed after a pass if the IR "changed".
Definition: PassManager.h:331
The main pass manager and pipeline builder.
Definition: PassManager.h:230
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.
Definition: PassManager.h:255
void enableTiming()
Add an instrumentation to time the execution of passes and the computation of analyses.
Definition: PassTiming.cpp:164
void enableIRPrinting(std::unique_ptr< IRPrinterConfig > config)
Add an instrumentation to print the IR before and after pass execution, using the provided configurat...
Definition: IRPrinting.cpp:354
LogicalResult run(Operation *op)
Run the passes within this manager on the provided operation.
Definition: Pass.cpp:847
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,...
Definition: IRPrinting.cpp:377
static PassManager on(MLIRContext *ctx, Nesting nesting=Nesting::Explicit)
Create a new pass manager under the given context with a specific nesting style.
Definition: PassManager.h:245
void addInstrumentation(std::unique_ptr< PassInstrumentation > pi)
Add the provided instrumentation to the pass manager.
Definition: Pass.cpp:897
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.
Definition: Pass.cpp:844
The abstract base pass class.
Definition: Pass.h:51
An adaptor pass used to run operation passes over nested operations.
Definition: PassDetail.h:26
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.
Definition: PassManager.h:221
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.
Definition: PassManager.h:197
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.
Definition: PassManager.h:209
virtual StringRef description()=0
Description of the reproducer stream.
virtual raw_ostream & os()=0
Stream on which to output reproducer.
virtual ~ReproducerStream()=default