19 #if MLIR_ENABLE_PDL_IN_PATTERNMATCH
24 convertPDLToPDLInterp(ModuleOp pdlModule,
27 if (pdlModule.getOps<pdl::PatternOp>().empty())
37 pdlModule.getBody()->walk(simplifyFn);
44 pdlPipeline.enableVerifier(
false);
47 if (failed(pdlPipeline.run(pdlModule)))
51 pdlModule.getBody()->walk(simplifyFn);
61 :
impl(std::make_shared<Impl>()) {}
66 :
impl(std::make_shared<Impl>()) {
68 disabledPatterns.insert(disabledPatternLabels.begin(),
69 disabledPatternLabels.end());
70 enabledPatterns.insert(enabledPatternLabels.begin(),
71 enabledPatternLabels.end());
76 std::vector<RegisteredOperationName> opInfos;
78 [&](std::unique_ptr<RewritePattern> &pattern,
81 opInfos = pattern->getContext()->getRegisteredOperations();
84 impl->nativeOpSpecificPatternMap[info].push_back(pattern.get());
85 impl->nativeOpSpecificPatternList.push_back(std::move(pattern));
88 for (std::unique_ptr<RewritePattern> &pat : patterns.getNativePatterns()) {
90 if (!enabledPatterns.empty()) {
91 auto isEnabledFn = [&](StringRef label) {
92 return enabledPatterns.count(label);
94 if (!isEnabledFn(pat->getDebugName()) &&
95 llvm::none_of(pat->getDebugLabels(), isEnabledFn))
99 if (!disabledPatterns.empty()) {
100 auto isDisabledFn = [&](StringRef label) {
101 return disabledPatterns.count(label);
103 if (isDisabledFn(pat->getDebugName()) ||
104 llvm::any_of(pat->getDebugLabels(), isDisabledFn))
108 if (std::optional<OperationName> rootName = pat->getRootKind()) {
109 impl->nativeOpSpecificPatternMap[*rootName].push_back(pat.get());
110 impl->nativeOpSpecificPatternList.push_back(std::move(pat));
113 if (std::optional<TypeID> interfaceID = pat->getRootInterfaceID()) {
119 if (std::optional<TypeID> traitID = pat->getRootTraitID()) {
125 impl->nativeAnyOpPatterns.push_back(std::move(pat));
128 #if MLIR_ENABLE_PDL_IN_PATTERNMATCH
130 PDLPatternModule &pdlPatterns = patterns.getPDLPatterns();
131 ModuleOp pdlModule = pdlPatterns.getModule();
135 pdlPatterns.takeConfigMap();
136 if (failed(convertPDLToPDLInterp(pdlModule, configMap)))
137 llvm::report_fatal_error(
138 "failed to lower PDL pattern module to the PDL Interpreter");
141 impl->pdlByteCode = std::make_unique<detail::PDLByteCode>(
142 pdlModule, pdlPatterns.takeConfigs(), configMap,
143 pdlPatterns.takeConstraintFunctions(),
144 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.
bool isOpTriviallyDead(Operation *op)
Return true if the given operation is unused, and has no side effects on memory that prevent erasing.
std::unique_ptr< OperationPass< ModuleOp > > createPDLToPDLInterpPass()
Creates and returns a pass to convert PDL ops to PDL interpreter ops.