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