9#ifndef MLIR_PASS_PASS_H
10#define MLIR_PASS_PASS_H
15#include "llvm/ADT/PointerIntPair.h"
16#include "llvm/ADT/Statistic.h"
83 std::optional<StringRef>
getOpName()
const {
return opName; }
90 template <
typename DataType,
93 template <
typename... Args>
96 parent.passOptions, arg, std::forward<Args>(args)...) {}
101 template <
typename DataType,
105 template <
typename... Args>
108 parent.passOptions, arg, std::forward<Args>(args)...) {}
116 virtual LogicalResult
118 function_ref<LogicalResult(
const Twine &)> errorHandler);
137 Statistic(
Pass *owner,
const char *name,
const char *description);
159 return threadingSibling ? threadingSibling :
this;
163 explicit Pass(
TypeID passID, std::optional<StringRef> opName = std::nullopt)
164 : passID(passID), opName(opName) {}
172 assert(passState &&
"pass state was never initialized");
197 std::optional<RegisteredOperationName> registeredInfo =
208 return passState->pipelineExecutor(pipeline, op);
212 std::unique_ptr<Pass>
clone()
const {
214 newInst->copyOptionValuesFrom(
this);
228 template <
typename AnalysisT>
235 template <
typename AnalysisT,
typename OpT>
242 template <
typename AnalysisT>
253 template <
typename... AnalysesT>
262 template <
typename AnalysisT>
263 std::optional<std::reference_wrapper<AnalysisT>>
269 template <
typename AnalysisT>
276 template <
typename AnalysisT>
277 std::optional<std::reference_wrapper<AnalysisT>>
284 template <
typename AnalysisT>
291 template <
typename AnalysisT,
typename OpTy>
311 virtual void anchor();
318 std::optional<StringRef> opName;
321 std::optional<detail::PassExecutionState> passState;
324 std::vector<Statistic *> statistics;
331 const Pass *threadingSibling =
nullptr;
362template <
typename OpT =
void>
376 return pass->
getOpName() == OpT::getOperationName();
381 return opName.getStringRef() ==
getOpName();
389 template <
typename AnalysisT>
438template <
typename InterfaceT>
448 return opName.hasInterface<InterfaceT>();
455 template <
typename AnalysisT>
465template <
typename PassT,
typename BaseT>
482 StringRef
getName()
const override {
return llvm::getTypeName<PassT>(); }
486 return std::make_unique<PassT>(*
static_cast<const PassT *
>(
this));
510 static constexpr StringLiteral
tag =
"pass-execution";
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)
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.
AnalysisT & getAnalysis()
Query an analysis for the current operation.
OperationPass(TypeID passID)
bool canScheduleOn(Operation *op) const final
Indicate if the current pass can be scheduled on the given operation type.
bool canScheduleOn(RegisteredOperationName opName) const final
Indicate if the current pass can be scheduled on the given operation type.
InterfaceT getOperation()
Return the current operation being transformed.
MLIRContext is the top-level object for a collection of MLIR operations.
This class represents a pass manager that runs passes on either a specific operation type,...
std::optional< RegisteredOperationName > getRegisteredInfo() const
If this operation is registered, returns the registered information, std::nullopt otherwise.
OperationPass(TypeID passID)
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.
OperationPass & operator=(OperationPass &&)=delete
OperationPass(TypeID passID)
static bool classof(const Pass *pass)
Support isa/dyn_cast functionality.
OperationPass & operator=(const OperationPass &)=delete
OperationPass(const OperationPass &)=default
AnalysisT & getAnalysis()
Query an analysis for the current operation of the specific derived operation type.
OpT getOperation()
Return the current operation being transformed.
bool canScheduleOn(RegisteredOperationName opName) const final
Indicate if the current pass can be scheduled on the given operation type.
OperationPass(OperationPass &&)=delete
~OperationPass() override=default
Operation is the basic unit of execution within MLIR.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
OperationName getName()
The name of an operation is the key identifier for it.
MLIRContext * getContext()
Return the context this operation is associated with.
This class encapsulates the "action" of executing a single pass.
void print(raw_ostream &os) const override
Print a textual version of this action to os.
PassExecutionAction(ArrayRef< IRUnit > irUnits, const Pass &pass)
Construct a PassExecutionAction.
Operation * op
The base op for this pass.
Operation * getOp() const
Get the operation that is the base of this pass.
static constexpr StringLiteral tag
The tag required by ActionImpl to identify this action.
const Pass & getPass() const
Get the pass that will be executed by this action.
const Pass & pass
Reference to the pass being run.
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.
~PassWrapper() override=default
PassWrapper(PassWrapper &&)=delete
static bool classof(const Pass *pass)
Support isa/dyn_cast functionality for the derived pass class.
std::unique_ptr< Pass > clonePass() const override
A clone method to create a copy of this pass.
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.
void copyOptionValuesFrom(const Pass *other)
Copy the option values from 'other', which is another instance of this pass.
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.
MutableArrayRef< Statistic * > getStatistics()
virtual LogicalResult initializeOptions(StringRef options, function_ref< LogicalResult(const Twine &)> errorHandler)
Attempt to initialize the options of this pass from the given string.
AnalysisManager getAnalysisManager()
Returns the current analysis manager.
Pass & operator=(Pass &&)=delete
std::optional< std::reference_wrapper< AnalysisT > > getCachedParentAnalysis(Operation *parent)
Returns the analysis for the given parent operation if it exists.
void markAllAnalysesPreserved()
Mark all analyses as preserved.
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.
TypeID getTypeID() const
Returns the unique identifier that corresponds to this pass.
detail::PassExecutionState & getPassState()
Returns the current pass state.
Pass(TypeID passID, std::optional< StringRef > opName=std::nullopt)
void printAsTextualPipeline(raw_ostream &os, bool pretty=false)
Prints out the pass in the textual representation of pipelines.
MLIRContext & getContext()
Return the MLIR context for the current operation being transformed.
virtual StringRef getDescription() const
Return the command line description used when registering this pass.
std::optional< std::reference_wrapper< AnalysisT > > getCachedParentAnalysis()
Returns the analysis for the parent operation if it exists.
LogicalResult runPipeline(OpPassManager &pipeline, Operation *op)
Schedule an arbitrary pass pipeline on the provided operation.
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.
AnalysisT & getAnalysis()
Query an analysis for the current ir unit.
std::unique_ptr< Pass > clone() const
A clone method to create a copy of this pass.
Operation * getOperation()
Return the current operation being transformed.
AnalysisT & getAnalysis()
Query an analysis for the current ir unit of a specific derived operation type.
virtual bool canScheduleOn(Operation *op) const
friend class PassInfo
Allow access to 'passOptions'.
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...
virtual LogicalResult initialize(MLIRContext *context)
Initialize any complex state necessary for running this pass.
virtual void getDependentDialects(DialectRegistry ®istry) const
Register dependent dialects for the current pass.
void markAnalysesPreserved(TypeID id)
std::optional< std::reference_wrapper< AnalysisT > > getCachedChildAnalysis(Operation *child)
Returns the analysis for the given child operation if it exists.
AnalysisT & getChildAnalysis(Operation *child)
Returns the analysis for the given child operation, or creates it if it doesn't exist.
friend class OpPassManager
Allow access to 'clone'.
virtual StringRef getName() const =0
Returns the derived pass name.
void markAnalysesPreserved()
Mark the provided analyses as preserved.
void signalPassFailure()
Signal that some invariant was broken when running.
virtual StringRef getArgument() const
Return the command line argument used when registering this pass.
const PassInfo * lookupPassInfo() const
Returns the pass info for this pass, or null if unknown.
AnalysisT & getChildAnalysis(OpTy child)
Returns the analysis for the given child operation of specific derived operation type,...
const Pass * getThreadingSiblingOrThis() const
Returns the thread sibling of this pass, or the pass itself it has no sibling.
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.
static TypeID get()
Construct a type info object for the given type T.
An adaptor pass used to run operation passes over nested operations.
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.
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.
ArrayRef< IRUnit > irUnits
Set of IR units (operations, regions, blocks, values) that are associated with this action.
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
ListOption(Pass &parent, StringRef arg, Args &&...args)
Option(Pass &parent, StringRef arg, Args &&...args)
The state for a single execution of a pass.
detail::PreservedAnalyses preservedAnalyses
The set of preserved analyses for the current execution.
function_ref< LogicalResult(OpPassManager &, Operation *)> pipelineExecutor
This is a callback in the PassManager that allows to schedule dynamic pipelines that will be rooted a...
AnalysisManager analysisManager
The analysis manager for the operation.
llvm::PointerIntPair< Operation *, 1, bool > irAndPassFailed
The current operation being transformed and a bool for if the pass signaled a failure.
PassExecutionState(Operation *ir, AnalysisManager analysisManager, function_ref< LogicalResult(OpPassManager &, Operation *)> pipelineExecutor)