9 #ifndef MLIR_PASS_PASS_H 10 #define MLIR_PASS_PASS_H 16 #include "llvm/ADT/PointerIntPair.h" 17 #include "llvm/ADT/Statistic.h" 43 virtual ~
Pass() =
default;
51 return lookupPassInfo(PassID::getID<PassT>());
58 virtual StringRef getName() = 0;
69 template <
typename DataType>
71 template <
typename... Args>
73 : detail::PassOptions::
Option<DataType>(parent.passOptions, arg,
74 std::forward<Args>(args)...) {}
79 template <
typename DataType>
81 template <
typename... Args>
84 parent.passOptions, arg, std::forward<Args>(args)...) {}
93 void printAsTextualPipeline(raw_ostream &os);
107 Statistic(
Pass *owner,
const char *name,
const char *description);
114 using llvm::Statistic::getDebugType;
123 : passID(passID), opName(opName) {}
127 assert(passState &&
"pass state was never initialized");
135 virtual void runOnOperation() = 0;
138 virtual std::unique_ptr<Pass> clone()
const = 0;
142 return getPassState().irAndPassFailed.getPointer();
147 return getPassState().analysisManager;
152 void copyOptionValuesFrom(
const Pass *other);
161 virtual void anchor();
174 std::vector<Statistic *> statistics;
189 template <
typename PassT,
typename BasePassT>
194 return pass->
getPassID() == PassID::getID<PassT>();
199 : BasePassT(
PassID::getID<PassT>(), opName) {}
204 this->getPassState().irAndPassFailed.setInt(
true);
209 return this->getAnalysisManager().template getAnalysis<AnalysisT>();
214 template <
typename AnalysisT>
216 return this->getAnalysisManager().template getCachedAnalysis<AnalysisT>();
221 this->getPassState().preservedAnalyses.preserveAll();
226 this->getPassState().preservedAnalyses.template preserve<AnalysesT...>();
229 this->getPassState().preservedAnalyses.preserve(
id);
234 StringRef name = llvm::getTypeName<PassT>();
235 if (!name.consume_front(
"mlir::"))
236 name.consume_front(
"(anonymous namespace)::");
241 std::unique_ptr<Pass>
clone()
const override {
242 auto newInst = std::make_unique<PassT>(*
static_cast<const PassT *
>(
this));
243 newInst->copyOptionValuesFrom(
this);
248 template <
typename AnalysisT>
251 return this->getAnalysisManager()
252 .template getCachedParentAnalysis<AnalysisT>(parent);
254 template <
typename AnalysisT>
256 return this->getAnalysisManager()
257 .template getCachedParentAnalysis<AnalysisT>(
258 this->getOperation()->getParentOp());
262 template <
typename AnalysisT>
265 return this->getAnalysisManager()
266 .template getCachedChildAnalysis<AnalysisT>(child);
272 return this->getAnalysisManager().template getChildAnalysis<AnalysisT>(
286 return pass->
getOpName() == OpT::getOperationName();
300 template <
typename PassT,
typename OpT =
void>
304 : detail::PassModel<PassT,
OpPassBase<OpT>>(OpT::getOperationName()) {}
320 template <
typename PassT>
329 virtual void runOnFunction() = 0;
333 if (!getFunction().isExternal())
347 virtual void runOnModule() = 0;
357 #endif // MLIR_PASS_PASS_H
Definition: InferTypeOpInterface.cpp:20
void markAnalysesPreserved(const AnalysisID *id)
Definition: Pass.h:228
Definition: STLExtras.h:95
Definition: Operation.h:27
Optional< std::reference_wrapper< AnalysisT > > getCachedParentAnalysis()
Definition: Pass.h:255
FuncOp getFunction()
Return the current module being transformed.
Definition: Pass.h:338
Definition: PassOptions.h:141
PassExecutionState(Operation *ir, AnalysisManager analysisManager)
Definition: Pass.h:24
Pass(const PassID *passID, Optional< StringRef > opName=llvm::None)
Definition: Pass.h:122
StringRef getName() override
Returns the derived pass name.
Definition: Pass.h:233
Definition: AnalysisManager.h:217
This class represents a specific pass option, with a provided data type.
Definition: Pass.h:70
Optional< std::reference_wrapper< AnalysisT > > getCachedParentAnalysis(Operation *parent)
Returns the analysis for the parent operation if it exists.
Definition: Pass.h:250
llvm::PointerIntPair< Operation *, 1, bool > irAndPassFailed
Definition: Pass.h:29
void runOnOperation() final
The polymorphic API that runs the pass over the currently held operation.
Definition: Pass.h:350
MLIRContext & getContext()
Return the MLIR context for the current function being transformed.
Definition: Pass.h:132
PassModel(Optional< StringRef > opName=llvm::None)
Definition: Pass.h:198
void signalPassFailure()
Definition: Pass.h:203
Definition: LogicalResult.h:18
void markAllAnalysesPreserved()
Mark all analyses as preserved.
Definition: Pass.h:220
Definition: Function.h:32
AnalysisT & getChildAnalysis(Operation *child)
Definition: Pass.h:271
AnalysisManager analysisManager
The analysis manager for the operation.
Definition: Pass.h:32
OperationPass()
Definition: Pass.h:303
Optional< StringRef > getOpName() const
Definition: Pass.h:62
A utility class to represent the analyses that are known to be preserved.
Definition: AnalysisManager.h:30
This class represents a specific pass option, with a provided data type.
Definition: PassOptions.h:105
OpT getOperation()
Return the current operation being transformed.
Definition: Pass.h:307
detail::PreservedAnalyses preservedAnalyses
The set of preserved analyses for the current execution.
Definition: Pass.h:35
const PassID * getPassID() const
Returns the unique identifier that corresponds to this pass.
Definition: Pass.h:46
static bool classof(const Pass *pass)
Support isa/dyn_cast functionality for the derived pass class.
Definition: Pass.h:193
static bool classof(const Pass *pass)
Support isa/dyn_cast functionality.
Definition: Pass.h:285
Base container class and manager for all pass options.
Definition: PassOptions.h:28
void markAnalysesPreserved()
Mark the provided analyses as preserved.
Definition: Pass.h:225
AnalysisManager getAnalysisManager()
Returns the current analysis manager.
Definition: Pass.h:146
ListOption(Pass &parent, StringRef arg, Args &&... args)
Definition: Pass.h:82
Operation * getOperation()
Return the current operation being transformed.
Definition: Pass.h:141
A structure to represent the information for a derived pass class.
Definition: PassRegistry.h:83
MutableArrayRef< Statistic * > getStatistics()
Definition: Pass.h:119
Definition: MLIRContext.h:34
Option(Pass &parent, StringRef arg, Args &&... args)
Definition: Pass.h:72
detail::PassExecutionState & getPassState()
Returns the current pass state.
Definition: Pass.h:126
Definition: StandardTypes.h:63
Optional< std::reference_wrapper< AnalysisT > > getCachedAnalysis()
Definition: Pass.h:215
std::unique_ptr< Pass > clone() const override
A clone method to create a copy of this pass.
Definition: Pass.h:241
const PassInfo * lookupPassInfo() const
Returns the pass info for this pass.
Definition: Pass.h:55
Optional< std::reference_wrapper< AnalysisT > > getCachedChildAnalysis(Operation *child)
Returns the analysis for the given child operation if it exists.
Definition: Pass.h:264
ArrayRef< Statistic * > getStatistics() const
Returns the main statistics for this pass instance.
Definition: Pass.h:118
AnalysisT & getAnalysis()
Query an analysis for the current ir unit.
Definition: Pass.h:208
void runOnOperation() final
The polymorphic API that runs the pass over the currently held operation.
Definition: Pass.h:332
static const PassInfo * lookupPassInfo()
Definition: Pass.h:50
Definition: PassManager.h:44
ModuleOp getModule()
Return the current module being transformed.
Definition: Pass.h:353