18 #if MLIR_ENABLE_PDL_IN_PATTERNMATCH
23 convertPDLToPDLInterp(ModuleOp pdlModule,
26 if (pdlModule.getOps<pdl::PatternOp>().empty())
36 pdlModule.getBody()->walk(simplifyFn);
43 pdlPipeline.enableVerifier(
false);
46 if (
failed(pdlPipeline.run(pdlModule)))
50 pdlModule.getBody()->walk(simplifyFn);
60 :
impl(std::make_shared<Impl>()) {}
65 :
impl(std::make_shared<Impl>()) {
67 disabledPatterns.insert_range(disabledPatternLabels);
68 enabledPatterns.insert_range(enabledPatternLabels);
73 std::vector<RegisteredOperationName> opInfos;
75 [&](std::unique_ptr<RewritePattern> &pattern,
78 opInfos = pattern->getContext()->getRegisteredOperations();
81 impl->nativeOpSpecificPatternMap[info].push_back(pattern.get());
82 impl->nativeOpSpecificPatternList.push_back(std::move(pattern));
85 for (std::unique_ptr<RewritePattern> &pat :
patterns.getNativePatterns()) {
87 if (!enabledPatterns.empty()) {
88 auto isEnabledFn = [&](StringRef label) {
89 return enabledPatterns.count(label);
91 if (!isEnabledFn(pat->getDebugName()) &&
92 llvm::none_of(pat->getDebugLabels(), isEnabledFn))
96 if (!disabledPatterns.empty()) {
97 auto isDisabledFn = [&](StringRef label) {
98 return disabledPatterns.count(label);
100 if (isDisabledFn(pat->getDebugName()) ||
101 llvm::any_of(pat->getDebugLabels(), isDisabledFn))
105 if (std::optional<OperationName> rootName = pat->getRootKind()) {
106 impl->nativeOpSpecificPatternMap[*rootName].push_back(pat.get());
107 impl->nativeOpSpecificPatternList.push_back(std::move(pat));
110 if (std::optional<TypeID> interfaceID = pat->getRootInterfaceID()) {
116 if (std::optional<TypeID> traitID = pat->getRootTraitID()) {
122 impl->nativeAnyOpPatterns.push_back(std::move(pat));
125 #if MLIR_ENABLE_PDL_IN_PATTERNMATCH
127 PDLPatternModule &pdlPatterns =
patterns.getPDLPatterns();
128 ModuleOp pdlModule = pdlPatterns.getModule();
132 pdlPatterns.takeConfigMap();
133 if (
failed(convertPDLToPDLInterp(pdlModule, configMap)))
134 llvm::report_fatal_error(
135 "failed to lower PDL pattern module to the PDL Interpreter");
138 impl->pdlByteCode = std::make_unique<detail::PDLByteCode>(
139 pdlModule, pdlPatterns.takeConfigs(), configMap,
140 pdlPatterns.takeConstraintFunctions(),
141 pdlPatterns.takeRewriteFunctions());
FrozenRewritePatternSet()
~FrozenRewritePatternSet()
bool hasTrait() const
Returns true if the operation was registered with a particular trait, e.g.
bool hasInterface() const
Returns true if this operation has the given interface registered to it.
Operation is the basic unit of execution within MLIR.
The main pass manager and pipeline builder.
This is a "type erased" representation of a registered operation.
Include the generated interface declarations.
std::unique_ptr< OperationPass< ModuleOp > > createConvertPDLToPDLInterpPass(DenseMap< Operation *, PDLPatternConfigSet * > &configMap)
Creates and returns a pass to convert PDL ops to PDL interpreter ops.
bool isOpTriviallyDead(Operation *op)
Return true if the given operation is unused, and has no side effects on memory that prevent erasing.
const FrozenRewritePatternSet & patterns