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