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