9 #ifndef MLIR_PASS_PASS_H
10 #define MLIR_PASS_PASS_H
15 #include "llvm/ADT/PointerIntPair.h"
16 #include "llvm/ADT/Statistic.h"
21 class OpToOpPassAdaptor;
22 struct OpPassManagerImpl;
83 std::optional<StringRef>
getOpName()
const {
return opName; }
90 template <
typename DataType,
93 template <
typename... Args>
95 : detail::PassOptions::
Option<DataType, OptionParser>(
96 parent.passOptions, arg, std::forward<Args>(args)...) {}
101 template <
typename DataType,
105 template <
typename... Args>
107 : detail::PassOptions::
ListOption<DataType, OptionParser>(
108 parent.passOptions, arg, std::forward<Args>(args)...) {}
134 Statistic(
Pass *owner,
const char *name,
const char *description);
156 return threadingSibling ? threadingSibling :
this;
160 explicit Pass(
TypeID passID, std::optional<StringRef> opName = std::nullopt)
161 : passID(passID), opName(opName) {}
166 assert(passState &&
"pass state was never initialized");
195 return passState->pipelineExecutor(pipeline, op);
199 std::unique_ptr<Pass>
clone()
const {
201 newInst->copyOptionValuesFrom(
this);
215 template <
typename AnalysisT>
222 template <
typename AnalysisT,
typename OpT>
229 template <
typename AnalysisT>
240 template <
typename... AnalysesT>
249 template <
typename AnalysisT>
250 std::optional<std::reference_wrapper<AnalysisT>>
256 template <
typename AnalysisT>
263 template <
typename AnalysisT>
264 std::optional<std::reference_wrapper<AnalysisT>>
271 template <
typename AnalysisT>
278 template <
typename AnalysisT,
typename OpTy>
298 virtual void anchor();
305 std::optional<StringRef> opName;
308 std::optional<detail::PassExecutionState> passState;
311 std::vector<Statistic *> statistics;
318 const Pass *threadingSibling =
nullptr;
349 template <
typename OpT =
void>
357 return pass->
getOpName() == OpT::getOperationName();
362 return opName.getStringRef() ==
getOpName();
370 template <
typename AnalysisT>
372 return Pass::getAnalysis<AnalysisT, OpT>();
413 template <
typename InterfaceT>
422 return opName.hasInterface<InterfaceT>();
429 template <
typename AnalysisT>
431 return Pass::getAnalysis<AnalysisT, InterfaceT>();
439 template <
typename PassT,
typename BaseT>
444 return pass->
getTypeID() == TypeID::get<PassT>();
452 StringRef
getName()
const override {
return llvm::getTypeName<PassT>(); }
456 return std::make_unique<PassT>(*
static_cast<const PassT *
>(
this));
static llvm::ManagedStatic< PassManagerOptions > options
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.
AnalysisT & getAnalysis()
Query an analysis for the current operation.
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,...
OperationPass(TypeID passID)
OperationPass(const OperationPass &)=default
bool canScheduleOn(RegisteredOperationName opName) const override
Indicate if the current pass can be scheduled on the given operation type.
Pass to transform an operation of a specific type.
OperationPass(TypeID passID)
static bool classof(const Pass *pass)
Support isa/dyn_cast functionality.
AnalysisT & getAnalysis()
Query an analysis for the current operation of the specific derived operation type.
OperationPass(const OperationPass &)=default
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.
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
A structure to represent the information for a derived pass class.
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...
PassWrapper(const PassWrapper &)=default
std::unique_ptr< Pass > clonePass() const override
A clone method to create a copy of this pass.
StringRef getName() const override
Returns the derived pass name.
static bool classof(const Pass *pass)
Support isa/dyn_cast functionality for the derived pass class.
This class represents a single pass statistic.
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.
void printAsTextualPipeline(raw_ostream &os)
Prints out the pass in the textual representation of pipelines.
AnalysisManager getAnalysisManager()
Returns the current analysis manager.
MutableArrayRef< Statistic * > getStatistics()
AnalysisT & getChildAnalysis(OpTy child)
Returns the analysis for the given child operation of specific derived operation type,...
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.
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.
std::optional< std::reference_wrapper< AnalysisT > > getCachedChildAnalysis(Operation *child)
Returns the analysis for the given child operation if it exists.
Pass(TypeID passID, std::optional< StringRef > opName=std::nullopt)
virtual StringRef getDescription() const
Return the command line description used when registering this pass.
std::optional< std::reference_wrapper< AnalysisT > > getCachedAnalysis()
Query a cached instance of an analysis for the current ir unit if one exists.
AnalysisT & getAnalysis()
Query an analysis for the current ir unit of a specific derived operation type.
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 LogicalResult initializeOptions(StringRef options)
Attempt to initialize the options of this pass from the given string.
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 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.
std::unique_ptr< Pass > clone() const
A clone method to create a copy of this pass.
detail::PassExecutionState & getPassState()
Returns the current pass state.
const Pass * getThreadingSiblingOrThis() const
Returns the thread sibling of this pass, or the pass itself it has no sibling.
const Pass * getThreadingSibling() const
Returns the thread sibling of this pass.
AnalysisT & getChildAnalysis(Operation *child)
Returns the analysis for the given child operation, or creates it if it doesn't exist.
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)
virtual StringRef getName() const =0
Returns the derived pass name.
void markAnalysesPreserved()
Mark the provided analyses as preserved.
Operation * getOperation()
Return the current operation being transformed.
void signalPassFailure()
Signal that some invariant was broken when running.
std::optional< std::reference_wrapper< AnalysisT > > getCachedParentAnalysis(Operation *parent)
Returns the analysis for the given parent operation if it exists.
const PassInfo * lookupPassInfo() const
Returns the pass info for this pass, or null if unknown.
virtual StringRef getArgument() const
Return the command line argument used when registering this pass.
MLIRContext & getContext()
Return the MLIR context for the current operation being transformed.
AnalysisT & getAnalysis()
Query an analysis for the current ir unit.
This is a "type erased" representation of a registered operation.
This class provides an efficient unique identifier for a specific C++ type.
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< 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.
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.
This header declares functions that assist transformations in the MemRef dialect.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
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.
This class represents a specific pass option that contains a list of values of the provided data type...
ListOption(Pass &parent, StringRef arg, Args &&...args)
This class represents a specific pass option, with a provided data type.
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)