MLIR  20.0.0git
Pass.h
Go to the documentation of this file.
1 //===- Pass.h - Base classes for compiler passes ----------------*- 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_PASS_H
10 #define MLIR_PASS_PASS_H
11 
12 #include "mlir/IR/Action.h"
14 #include "mlir/Pass/PassRegistry.h"
15 #include "llvm/ADT/PointerIntPair.h"
16 #include "llvm/ADT/Statistic.h"
17 #include <optional>
18 
19 namespace mlir {
20 namespace detail {
21 class OpToOpPassAdaptor;
22 struct OpPassManagerImpl;
23 
24 /// The state for a single execution of a pass. This provides a unified
25 /// interface for accessing and initializing necessary state for pass execution.
28  function_ref<LogicalResult(OpPassManager &, Operation *)>
32 
33  /// The current operation being transformed and a bool for if the pass
34  /// signaled a failure.
35  llvm::PointerIntPair<Operation *, 1, bool> irAndPassFailed;
36 
37  /// The analysis manager for the operation.
39 
40  /// The set of preserved analyses for the current execution.
42 
43  /// This is a callback in the PassManager that allows to schedule dynamic
44  /// pipelines that will be rooted at the provided operation.
46 };
47 } // namespace detail
48 
49 /// The abstract base pass class. This class contains information describing the
50 /// derived pass object, e.g its kind and abstract TypeID.
51 class Pass {
52 public:
53  virtual ~Pass() = default;
54 
55  /// Returns the unique identifier that corresponds to this pass.
56  TypeID getTypeID() const { return passID; }
57 
58  /// Returns the pass info for this pass, or null if unknown.
59  const PassInfo *lookupPassInfo() const {
60  return PassInfo::lookup(getArgument());
61  }
62 
63  /// Returns the derived pass name.
64  virtual StringRef getName() const = 0;
65 
66  /// Register dependent dialects for the current pass.
67  /// A pass is expected to register the dialects it will create entities for
68  /// (Operations, Types, Attributes), other than dialect that exists in the
69  /// input. For example, a pass that converts from Linalg to Affine would
70  /// register the Affine dialect but does not need to register Linalg.
71  virtual void getDependentDialects(DialectRegistry &registry) const {}
72 
73  /// Return the command line argument used when registering this pass. Return
74  /// an empty string if one does not exist.
75  virtual StringRef getArgument() const { return ""; }
76 
77  /// Return the command line description used when registering this pass.
78  /// Return an empty string if one does not exist.
79  virtual StringRef getDescription() const { return ""; }
80 
81  /// Returns the name of the operation that this pass operates on, or
82  /// std::nullopt if this is a generic OperationPass.
83  std::optional<StringRef> getOpName() const { return opName; }
84 
85  //===--------------------------------------------------------------------===//
86  // Options
87  //===--------------------------------------------------------------------===//
88 
89  /// This class represents a specific pass option, with a provided data type.
90  template <typename DataType,
91  typename OptionParser = detail::PassOptions::OptionParser<DataType>>
92  struct Option : public detail::PassOptions::Option<DataType, OptionParser> {
93  template <typename... Args>
94  Option(Pass &parent, StringRef arg, Args &&...args)
95  : detail::PassOptions::Option<DataType, OptionParser>(
96  parent.passOptions, arg, std::forward<Args>(args)...) {}
98  };
99  /// This class represents a specific pass option that contains a list of
100  /// values of the provided data type.
101  template <typename DataType,
102  typename OptionParser = detail::PassOptions::OptionParser<DataType>>
103  struct ListOption
104  : public detail::PassOptions::ListOption<DataType, OptionParser> {
105  template <typename... Args>
106  ListOption(Pass &parent, StringRef arg, Args &&...args)
107  : detail::PassOptions::ListOption<DataType, OptionParser>(
108  parent.passOptions, arg, std::forward<Args>(args)...) {}
110  };
111 
112  /// Attempt to initialize the options of this pass from the given string.
113  /// Derived classes may override this method to hook into the point at which
114  /// options are initialized, but should generally always invoke this base
115  /// class variant.
116  virtual LogicalResult
117  initializeOptions(StringRef options,
118  function_ref<LogicalResult(const Twine &)> errorHandler);
119 
120  /// Prints out the pass in the textual representation of pipelines. If this is
121  /// an adaptor pass, print its pass managers.
122  void printAsTextualPipeline(raw_ostream &os);
123 
124  //===--------------------------------------------------------------------===//
125  // Statistics
126  //===--------------------------------------------------------------------===//
127 
128  /// This class represents a single pass statistic. This statistic functions
129  /// similarly to an unsigned integer value, and may be updated and incremented
130  /// accordingly. This class can be used to provide additional information
131  /// about the transformations and analyses performed by a pass.
132  class Statistic : public llvm::Statistic {
133  public:
134  /// The statistic is initialized by the pass owner, a name, and a
135  /// description.
136  Statistic(Pass *owner, const char *name, const char *description);
137 
138  /// Assign the statistic to the given value.
139  Statistic &operator=(unsigned value);
140  };
141 
142  /// Returns the main statistics for this pass instance.
143  ArrayRef<Statistic *> getStatistics() const { return statistics; }
145 
146  /// Returns the thread sibling of this pass.
147  ///
148  /// If this pass was cloned by the pass manager for the sake of
149  /// multi-threading, this function returns the original pass it was cloned
150  /// from. This is useful for diagnostic purposes to distinguish passes that
151  /// were replicated for threading purposes from passes instantiated by the
152  /// user. Used to collapse passes in timing statistics.
153  const Pass *getThreadingSibling() const { return threadingSibling; }
154 
155  /// Returns the thread sibling of this pass, or the pass itself it has no
156  /// sibling. See `getThreadingSibling()` for details.
158  return threadingSibling ? threadingSibling : this;
159  }
160 
161 protected:
162  explicit Pass(TypeID passID, std::optional<StringRef> opName = std::nullopt)
163  : passID(passID), opName(opName) {}
164  Pass(const Pass &other) : Pass(other.passID, other.opName) {}
165  Pass &operator=(const Pass &) = delete;
166  Pass(Pass &&) = delete;
167  Pass &operator=(Pass &&) = delete;
168 
169  /// Returns the current pass state.
171  assert(passState && "pass state was never initialized");
172  return *passState;
173  }
174 
175  /// Return the MLIR context for the current operation being transformed.
177 
178  /// The polymorphic API that runs the pass over the currently held operation.
179  virtual void runOnOperation() = 0;
180 
181  /// Initialize any complex state necessary for running this pass. This hook
182  /// should not rely on any state accessible during the execution of a pass.
183  /// For example, `getContext`/`getOperation`/`getAnalysis`/etc. should not be
184  /// invoked within this hook.
185  /// This method is invoked after all dependent dialects for the pipeline are
186  /// loaded, and is not allowed to load any further dialects (override the
187  /// `getDependentDialects()` for this purpose instead). Returns a LogicalResult
188  /// to indicate failure, in which case the pass pipeline won't execute.
189  virtual LogicalResult initialize(MLIRContext *context) { return success(); }
190 
191  /// Indicate if the current pass can be scheduled on the given operation type.
192  /// This is useful for generic operation passes to add restrictions on the
193  /// operations they operate on.
194  virtual bool canScheduleOn(RegisteredOperationName opName) const = 0;
195 
196  /// Schedule an arbitrary pass pipeline on the provided operation.
197  /// This can be invoke any time in a pass to dynamic schedule more passes.
198  /// The provided operation must be the current one or one nested below.
199  LogicalResult runPipeline(OpPassManager &pipeline, Operation *op) {
200  return passState->pipelineExecutor(pipeline, op);
201  }
202 
203  /// A clone method to create a copy of this pass.
204  std::unique_ptr<Pass> clone() const {
205  auto newInst = clonePass();
206  newInst->copyOptionValuesFrom(this);
207  return newInst;
208  }
209 
210  /// Return the current operation being transformed.
212  return getPassState().irAndPassFailed.getPointer();
213  }
214 
215  /// Signal that some invariant was broken when running. The IR is allowed to
216  /// be in an invalid state.
217  void signalPassFailure() { getPassState().irAndPassFailed.setInt(true); }
218 
219  /// Query an analysis for the current ir unit.
220  template <typename AnalysisT>
221  AnalysisT &getAnalysis() {
222  return getAnalysisManager().getAnalysis<AnalysisT>();
223  }
224 
225  /// Query an analysis for the current ir unit of a specific derived operation
226  /// type.
227  template <typename AnalysisT, typename OpT>
228  AnalysisT &getAnalysis() {
229  return getAnalysisManager().getAnalysis<AnalysisT, OpT>();
230  }
231 
232  /// Query a cached instance of an analysis for the current ir unit if one
233  /// exists.
234  template <typename AnalysisT>
235  std::optional<std::reference_wrapper<AnalysisT>> getCachedAnalysis() {
236  return getAnalysisManager().getCachedAnalysis<AnalysisT>();
237  }
238 
239  /// Mark all analyses as preserved.
242  }
243 
244  /// Mark the provided analyses as preserved.
245  template <typename... AnalysesT>
247  getPassState().preservedAnalyses.preserve<AnalysesT...>();
248  }
251  }
252 
253  /// Returns the analysis for the given parent operation if it exists.
254  template <typename AnalysisT>
255  std::optional<std::reference_wrapper<AnalysisT>>
257  return getAnalysisManager().getCachedParentAnalysis<AnalysisT>(parent);
258  }
259 
260  /// Returns the analysis for the parent operation if it exists.
261  template <typename AnalysisT>
262  std::optional<std::reference_wrapper<AnalysisT>> getCachedParentAnalysis() {
263  return getAnalysisManager().getCachedParentAnalysis<AnalysisT>(
265  }
266 
267  /// Returns the analysis for the given child operation if it exists.
268  template <typename AnalysisT>
269  std::optional<std::reference_wrapper<AnalysisT>>
271  return getAnalysisManager().getCachedChildAnalysis<AnalysisT>(child);
272  }
273 
274  /// Returns the analysis for the given child operation, or creates it if it
275  /// doesn't exist.
276  template <typename AnalysisT>
277  AnalysisT &getChildAnalysis(Operation *child) {
278  return getAnalysisManager().getChildAnalysis<AnalysisT>(child);
279  }
280 
281  /// Returns the analysis for the given child operation of specific derived
282  /// operation type, or creates it if it doesn't exist.
283  template <typename AnalysisT, typename OpTy>
284  AnalysisT &getChildAnalysis(OpTy child) {
285  return getAnalysisManager().getChildAnalysis<AnalysisT>(child);
286  }
287 
288  /// Returns the current analysis manager.
290  return getPassState().analysisManager;
291  }
292 
293  /// Create a copy of this pass, ignoring statistics and options.
294  virtual std::unique_ptr<Pass> clonePass() const = 0;
295 
296  /// Copy the option values from 'other', which is another instance of this
297  /// pass.
298  void copyOptionValuesFrom(const Pass *other);
299 
300 private:
301  /// Out of line virtual method to ensure vtables and metadata are emitted to a
302  /// single .o file.
303  virtual void anchor();
304 
305  /// Represents a unique identifier for the pass.
306  TypeID passID;
307 
308  /// The name of the operation that this pass operates on, or std::nullopt if
309  /// this is a generic OperationPass.
310  std::optional<StringRef> opName;
311 
312  /// The current execution state for the pass.
313  std::optional<detail::PassExecutionState> passState;
314 
315  /// The set of statistics held by this pass.
316  std::vector<Statistic *> statistics;
317 
318  /// The pass options registered to this pass instance.
319  detail::PassOptions passOptions;
320 
321  /// A pointer to the pass this pass was cloned from, if the clone was made by
322  /// the pass manager for the sake of multi-threading.
323  const Pass *threadingSibling = nullptr;
324 
325  /// Allow access to 'clone'.
326  friend class OpPassManager;
327 
328  /// Allow access to 'canScheduleOn'.
330 
331  /// Allow access to 'passState'.
333 
334  /// Allow access to 'passOptions'.
335  friend class PassInfo;
336 };
337 
338 //===----------------------------------------------------------------------===//
339 // Pass Model Definitions
340 //===----------------------------------------------------------------------===//
341 
342 /// Pass to transform an operation of a specific type.
343 ///
344 /// Operation passes must not:
345 /// - modify any other operations within the parent region, as other threads
346 /// may be manipulating them concurrently.
347 /// - modify any state within the parent operation, this includes adding
348 /// additional operations.
349 ///
350 /// Derived operation passes are expected to provide the following:
351 /// - A 'void runOnOperation()' method.
352 /// - A 'StringRef getName() const' method.
353 /// - A 'std::unique_ptr<Pass> clonePass() const' method.
354 template <typename OpT = void>
355 class OperationPass : public Pass {
356 public:
357  ~OperationPass() override = default;
358 
359 protected:
360  OperationPass(TypeID passID) : Pass(passID, OpT::getOperationName()) {}
361  OperationPass(const OperationPass &) = default;
365 
366  /// Support isa/dyn_cast functionality.
367  static bool classof(const Pass *pass) {
368  return pass->getOpName() == OpT::getOperationName();
369  }
370 
371  /// Indicate if the current pass can be scheduled on the given operation type.
372  bool canScheduleOn(RegisteredOperationName opName) const final {
373  return opName.getStringRef() == getOpName();
374  }
375 
376  /// Return the current operation being transformed.
377  OpT getOperation() { return cast<OpT>(Pass::getOperation()); }
378 
379  /// Query an analysis for the current operation of the specific derived
380  /// operation type.
381  template <typename AnalysisT>
382  AnalysisT &getAnalysis() {
383  return Pass::getAnalysis<AnalysisT, OpT>();
384  }
385 };
386 
387 /// Pass to transform an operation.
388 ///
389 /// Operation passes must not:
390 /// - modify any other operations within the parent region, as other threads
391 /// may be manipulating them concurrently.
392 /// - modify any state within the parent operation, this includes adding
393 /// additional operations.
394 ///
395 /// Derived operation passes are expected to provide the following:
396 /// - A 'void runOnOperation()' method.
397 /// - A 'StringRef getName() const' method.
398 /// - A 'std::unique_ptr<Pass> clonePass() const' method.
399 template <>
400 class OperationPass<void> : public Pass {
401 public:
402  ~OperationPass() override = default;
403 
404 protected:
405  OperationPass(TypeID passID) : Pass(passID) {}
406  OperationPass(const OperationPass &) = default;
410 
411  /// Indicate if the current pass can be scheduled on the given operation type.
412  /// By default, generic operation passes can be scheduled on any operation.
413  bool canScheduleOn(RegisteredOperationName opName) const override {
414  return true;
415  }
416 };
417 
418 /// Pass to transform an operation that implements the given interface.
419 ///
420 /// Interface passes must not:
421 /// - modify any other operations within the parent region, as other threads
422 /// may be manipulating them concurrently.
423 /// - modify any state within the parent operation, this includes adding
424 /// additional operations.
425 ///
426 /// Derived interface passes are expected to provide the following:
427 /// - A 'void runOnOperation()' method.
428 /// - A 'StringRef getName() const' method.
429 /// - A 'std::unique_ptr<Pass> clonePass() const' method.
430 template <typename InterfaceT>
431 class InterfacePass : public OperationPass<> {
432 protected:
434 
435  /// Indicate if the current pass can be scheduled on the given operation type.
436  /// For an InterfacePass, this checks if the operation implements the given
437  /// interface.
438  bool canScheduleOn(RegisteredOperationName opName) const final {
439  return opName.hasInterface<InterfaceT>();
440  }
441 
442  /// Return the current operation being transformed.
443  InterfaceT getOperation() { return cast<InterfaceT>(Pass::getOperation()); }
444 
445  /// Query an analysis for the current operation.
446  template <typename AnalysisT>
447  AnalysisT &getAnalysis() {
448  return Pass::getAnalysis<AnalysisT, InterfaceT>();
449  }
450 };
451 
452 /// This class provides a CRTP wrapper around a base pass class to define
453 /// several necessary utility methods. This should only be used for passes that
454 /// are not suitably represented using the declarative pass specification(i.e.
455 /// tablegen backend).
456 template <typename PassT, typename BaseT>
457 class PassWrapper : public BaseT {
458 public:
459  /// Support isa/dyn_cast functionality for the derived pass class.
460  static bool classof(const Pass *pass) {
461  return pass->getTypeID() == TypeID::get<PassT>();
462  }
463  ~PassWrapper() override = default;
464 
465 protected:
466  PassWrapper() : BaseT(TypeID::get<PassT>()) {}
467  PassWrapper(const PassWrapper &) = default;
468  PassWrapper &operator=(const PassWrapper &) = delete;
469  PassWrapper(PassWrapper &&) = delete;
471 
472  /// Returns the derived pass name.
473  StringRef getName() const override { return llvm::getTypeName<PassT>(); }
474 
475  /// A clone method to create a copy of this pass.
476  std::unique_ptr<Pass> clonePass() const override {
477  return std::make_unique<PassT>(*static_cast<const PassT *>(this));
478  }
479 };
480 
481 /// This class encapsulates the "action" of executing a single pass. This allows
482 /// a user of the Action infrastructure to query information about an action in
483 /// (for example) a breakpoint context. You could use it like this:
484 ///
485 /// auto onBreakpoint = [&](const ActionActiveStack *backtrace) {
486 /// if (auto passExec = dyn_cast<PassExecutionAction>(anAction))
487 /// record(passExec.getPass());
488 /// return ExecutionContext::Apply;
489 /// };
490 /// ExecutionContext exeCtx(onBreakpoint);
491 ///
492 class PassExecutionAction : public tracing::ActionImpl<PassExecutionAction> {
494 
495 public:
496  /// Define a TypeID for this PassExecutionAction.
498  /// Construct a PassExecutionAction. This is called by the OpToOpPassAdaptor
499  /// when it calls `executeAction`.
501 
502  /// The tag required by ActionImpl to identify this action.
503  static constexpr StringLiteral tag = "pass-execution";
504 
505  /// Print a textual version of this action to `os`.
506  void print(raw_ostream &os) const override;
507 
508  /// Get the pass that will be executed by this action. This is not a class of
509  /// passes, or all instances of a pass kind, this is a single pass.
510  const Pass &getPass() const { return pass; }
511 
512  /// Get the operation that is the base of this pass. For example, an
513  /// OperationPass<ModuleOp> would return a ModuleOp.
514  Operation *getOp() const;
515 
516 public:
517  /// Reference to the pass being run. Notice that this will *not* extend the
518  /// lifetime of the pass, and so this class is therefore unsafe to keep past
519  /// the lifetime of the `executeAction` call.
520  const Pass &pass;
521 
522  /// The base op for this pass. For an OperationPass<ModuleOp>, we would have a
523  /// ModuleOp here.
525 };
526 
527 } // namespace mlir
528 
529 #endif // MLIR_PASS_PASS_H
static llvm::ManagedStatic< PassManagerOptions > options
#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME)
Definition: TypeID.h:274
This class represents an analysis manager for a particular operation instance.
std::optional< std::reference_wrapper< AnalysisT > > getCachedChildAnalysis(Operation *op) const
Query for a cached analysis of a child operation, or return null.
std::optional< std::reference_wrapper< AnalysisT > > getCachedAnalysis() const
Query for a cached entry of the given analysis on the current operation.
AnalysisT & getAnalysis()
Query for the given analysis for the current operation.
std::optional< std::reference_wrapper< AnalysisT > > getCachedParentAnalysis(Operation *parentOp) const
Query for a cached analysis on the given parent operation.
AnalysisT & getChildAnalysis(Operation *op)
Query for an analysis of a child operation, constructing it if necessary.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Pass to transform an operation that implements the given interface.
Definition: Pass.h:431
AnalysisT & getAnalysis()
Query an analysis for the current operation.
Definition: Pass.h:447
bool canScheduleOn(RegisteredOperationName opName) const final
Indicate if the current pass can be scheduled on the given operation type.
Definition: Pass.h:438
InterfaceT getOperation()
Return the current operation being transformed.
Definition: Pass.h:443
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:47
OperationPass & operator=(const OperationPass &)=delete
OperationPass(TypeID passID)
Definition: Pass.h:405
OperationPass(const OperationPass &)=default
OperationPass(OperationPass &&)=delete
~OperationPass() override=default
bool canScheduleOn(RegisteredOperationName opName) const override
Indicate if the current pass can be scheduled on the given operation type.
Definition: Pass.h:413
OperationPass & operator=(OperationPass &&)=delete
Pass to transform an operation of a specific type.
Definition: Pass.h:355
OperationPass & operator=(OperationPass &&)=delete
OperationPass(TypeID passID)
Definition: Pass.h:360
static bool classof(const Pass *pass)
Support isa/dyn_cast functionality.
Definition: Pass.h:367
AnalysisT & getAnalysis()
Query an analysis for the current operation of the specific derived operation type.
Definition: Pass.h:382
OperationPass(const OperationPass &)=default
OperationPass & operator=(const OperationPass &)=delete
OpT getOperation()
Return the current operation being transformed.
Definition: Pass.h:377
bool canScheduleOn(RegisteredOperationName opName) const final
Indicate if the current pass can be scheduled on the given operation type.
Definition: Pass.h:372
OperationPass(OperationPass &&)=delete
~OperationPass() override=default
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
MLIRContext * getContext()
Return the context this operation is associated with.
Definition: Operation.h:216
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Definition: Operation.h:234
This class encapsulates the "action" of executing a single pass.
Definition: Pass.h:492
void print(raw_ostream &os) const override
Print a textual version of this action to os.
Definition: Pass.cpp:43
const Pass & getPass() const
Get the pass that will be executed by this action.
Definition: Pass.h:510
PassExecutionAction(ArrayRef< IRUnit > irUnits, const Pass &pass)
Define a TypeID for this PassExecutionAction.
Definition: Pass.cpp:39
Operation * op
The base op for this pass.
Definition: Pass.h:524
Operation * getOp() const
Get the operation that is the base of this pass.
Definition: Pass.cpp:48
static constexpr StringLiteral tag
The tag required by ActionImpl to identify this action.
Definition: Pass.h:503
const Pass & pass
Reference to the pass being run.
Definition: Pass.h:520
A structure to represent the information for a derived pass class.
Definition: PassRegistry.h:115
static const PassInfo * lookup(StringRef passArg)
Returns the pass info for the specified pass class or null if unknown.
This class provides a CRTP wrapper around a base pass class to define several necessary utility metho...
Definition: Pass.h:457
PassWrapper(const PassWrapper &)=default
PassWrapper & operator=(PassWrapper &&)=delete
std::unique_ptr< Pass > clonePass() const override
A clone method to create a copy of this pass.
Definition: Pass.h:476
StringRef getName() const override
Returns the derived pass name.
Definition: Pass.h:473
PassWrapper & operator=(const PassWrapper &)=delete
~PassWrapper() override=default
PassWrapper(PassWrapper &&)=delete
static bool classof(const Pass *pass)
Support isa/dyn_cast functionality for the derived pass class.
Definition: Pass.h:460
This class represents a single pass statistic.
Definition: Pass.h:132
Statistic(Pass *owner, const char *name, const char *description)
The statistic is initialized by the pass owner, a name, and a description.
Statistic & operator=(unsigned value)
Assign the statistic to the given value.
The abstract base pass class.
Definition: Pass.h:51
void copyOptionValuesFrom(const Pass *other)
Copy the option values from 'other', which is another instance of this pass.
Definition: Pass.cpp:77
void printAsTextualPipeline(raw_ostream &os)
Prints out the pass in the textual representation of pipelines.
Definition: Pass.cpp:83
virtual LogicalResult initializeOptions(StringRef options, function_ref< LogicalResult(const Twine &)> errorHandler)
Attempt to initialize the options of this pass from the given string.
Definition: Pass.cpp:63
AnalysisManager getAnalysisManager()
Returns the current analysis manager.
Definition: Pass.h:289
MutableArrayRef< Statistic * > getStatistics()
Definition: Pass.h:144
AnalysisT & getChildAnalysis(OpTy child)
Returns the analysis for the given child operation of specific derived operation type,...
Definition: Pass.h:284
virtual std::unique_ptr< Pass > clonePass() const =0
Create a copy of this pass, ignoring statistics and options.
void markAllAnalysesPreserved()
Mark all analyses as preserved.
Definition: Pass.h:240
virtual bool canScheduleOn(RegisteredOperationName opName) const =0
Indicate if the current pass can be scheduled on the given operation type.
TypeID getTypeID() const
Returns the unique identifier that corresponds to this pass.
Definition: Pass.h:56
std::optional< std::reference_wrapper< AnalysisT > > getCachedChildAnalysis(Operation *child)
Returns the analysis for the given child operation if it exists.
Definition: Pass.h:270
Pass(TypeID passID, std::optional< StringRef > opName=std::nullopt)
Definition: Pass.h:162
virtual StringRef getDescription() const
Return the command line description used when registering this pass.
Definition: Pass.h:79
std::optional< std::reference_wrapper< AnalysisT > > getCachedAnalysis()
Query a cached instance of an analysis for the current ir unit if one exists.
Definition: Pass.h:235
AnalysisT & getAnalysis()
Query an analysis for the current ir unit of a specific derived operation type.
Definition: Pass.h:228
std::optional< std::reference_wrapper< AnalysisT > > getCachedParentAnalysis()
Returns the analysis for the parent operation if it exists.
Definition: Pass.h:262
LogicalResult runPipeline(OpPassManager &pipeline, Operation *op)
Schedule an arbitrary pass pipeline on the provided operation.
Definition: Pass.h:199
std::optional< StringRef > getOpName() const
Returns the name of the operation that this pass operates on, or std::nullopt if this is a generic Op...
Definition: Pass.h:83
virtual void runOnOperation()=0
The polymorphic API that runs the pass over the currently held operation.
ArrayRef< Statistic * > getStatistics() const
Returns the main statistics for this pass instance.
Definition: Pass.h:143
std::unique_ptr< Pass > clone() const
A clone method to create a copy of this pass.
Definition: Pass.h:204
virtual ~Pass()=default
detail::PassExecutionState & getPassState()
Returns the current pass state.
Definition: Pass.h:170
const Pass * getThreadingSiblingOrThis() const
Returns the thread sibling of this pass, or the pass itself it has no sibling.
Definition: Pass.h:157
const Pass * getThreadingSibling() const
Returns the thread sibling of this pass.
Definition: Pass.h:153
Pass(Pass &&)=delete
AnalysisT & getChildAnalysis(Operation *child)
Returns the analysis for the given child operation, or creates it if it doesn't exist.
Definition: Pass.h:277
virtual LogicalResult initialize(MLIRContext *context)
Initialize any complex state necessary for running this pass.
Definition: Pass.h:189
virtual void getDependentDialects(DialectRegistry &registry) const
Register dependent dialects for the current pass.
Definition: Pass.h:71
void markAnalysesPreserved(TypeID id)
Definition: Pass.h:249
Pass & operator=(Pass &&)=delete
virtual StringRef getName() const =0
Returns the derived pass name.
void markAnalysesPreserved()
Mark the provided analyses as preserved.
Definition: Pass.h:246
Pass(const Pass &other)
Definition: Pass.h:164
Operation * getOperation()
Return the current operation being transformed.
Definition: Pass.h:211
void signalPassFailure()
Signal that some invariant was broken when running.
Definition: Pass.h:217
std::optional< std::reference_wrapper< AnalysisT > > getCachedParentAnalysis(Operation *parent)
Returns the analysis for the given parent operation if it exists.
Definition: Pass.h:256
Pass & operator=(const Pass &)=delete
const PassInfo * lookupPassInfo() const
Returns the pass info for this pass, or null if unknown.
Definition: Pass.h:59
virtual StringRef getArgument() const
Return the command line argument used when registering this pass.
Definition: Pass.h:75
MLIRContext & getContext()
Return the MLIR context for the current operation being transformed.
Definition: Pass.h:176
AnalysisT & getAnalysis()
Query an analysis for the current ir unit.
Definition: Pass.h:221
This is a "type erased" representation of a registered operation.
This class provides an efficient unique identifier for a specific C++ type.
Definition: TypeID.h:104
An adaptor pass used to run operation passes over nested operations.
Definition: PassDetail.h:26
This class represents a specific pass option that contains a list of values of the provided data type...
Definition: PassOptions.h:220
This class represents a specific pass option, with a provided data type.
Definition: PassOptions.h:173
Base container class and manager for all pass options.
Definition: PassOptions.h:92
std::conditional_t< std::is_base_of< llvm::cl::generic_parser_base, llvm::cl::parser< DataType > >::value, GenericOptionParser< DataType >, llvm::cl::parser< DataType > > OptionParser
The specific parser to use depending on llvm::cl parser used.
Definition: PassOptions.h:167
A utility class to represent the analyses that are known to be preserved.
void preserveAll()
Mark all analyses as preserved.
void preserve()
Preserve the given analyses.
CRTP Implementation of an action.
Definition: Action.h:76
ArrayRef< IRUnit > irUnits
Set of IR units (operations, regions, blocks, values) that are associated with this action.
Definition: Action.h:66
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This class represents a specific pass option that contains a list of values of the provided data type...
Definition: Pass.h:104
ListOption(Pass &parent, StringRef arg, Args &&...args)
Definition: Pass.h:106
This class represents a specific pass option, with a provided data type.
Definition: Pass.h:92
Option(Pass &parent, StringRef arg, Args &&...args)
Definition: Pass.h:94
The state for a single execution of a pass.
Definition: Pass.h:26
detail::PreservedAnalyses preservedAnalyses
The set of preserved analyses for the current execution.
Definition: Pass.h:41
function_ref< LogicalResult(OpPassManager &, Operation *)> pipelineExecutor
This is a callback in the PassManager that allows to schedule dynamic pipelines that will be rooted a...
Definition: Pass.h:45
AnalysisManager analysisManager
The analysis manager for the operation.
Definition: Pass.h:38
llvm::PointerIntPair< Operation *, 1, bool > irAndPassFailed
The current operation being transformed and a bool for if the pass signaled a failure.
Definition: Pass.h:35
PassExecutionState(Operation *ir, AnalysisManager analysisManager, function_ref< LogicalResult(OpPassManager &, Operation *)> pipelineExecutor)
Definition: Pass.h:27