66 :
impl(std::make_shared<Impl>()) {
70 std::vector<RegisteredOperationName> opInfos;
72 [&](std::unique_ptr<RewritePattern> &pattern,
75 opInfos = pattern->getContext()->getRegisteredOperations();
78 impl->nativeOpSpecificPatternMap[info].push_back(pattern.get());
79 impl->nativeOpSpecificPatternList.push_back(std::move(pattern));
90 auto matchesAnyUserLabel = [](StringRef label,
92 size_t pos = label.rfind(
"::");
93 StringRef unqualified =
94 (pos == StringRef::npos) ? label : label.substr(pos + 2);
95 for (StringRef ul : userLabels) {
98 if (!ul.contains(
"::") && unqualified == ul)
104 for (std::unique_ptr<RewritePattern> &pat : patterns.getNativePatterns()) {
106 if (!enabledPatternLabels.empty()) {
107 auto isEnabledFn = [&](StringRef label) {
108 return matchesAnyUserLabel(label, enabledPatternLabels);
110 if (!isEnabledFn(pat->getDebugName()) &&
111 llvm::none_of(pat->getDebugLabels(), isEnabledFn))
115 if (!disabledPatternLabels.empty()) {
116 auto isDisabledFn = [&](StringRef label) {
117 return matchesAnyUserLabel(label, disabledPatternLabels);
119 if (isDisabledFn(pat->getDebugName()) ||
120 llvm::any_of(pat->getDebugLabels(), isDisabledFn))
124 if (std::optional<OperationName> rootName = pat->getRootKind()) {
125 impl->nativeOpSpecificPatternMap[*rootName].push_back(pat.get());
126 impl->nativeOpSpecificPatternList.push_back(std::move(pat));
129 if (std::optional<TypeID> interfaceID = pat->getRootInterfaceID()) {
130 addToOpsWhen(pat, [&](RegisteredOperationName info) {
131 return info.hasInterface(*interfaceID);
135 if (std::optional<TypeID> traitID = pat->getRootTraitID()) {
141 impl->nativeAnyOpPatterns.push_back(std::move(pat));
144#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
146 PDLPatternModule &pdlPatterns = patterns.getPDLPatterns();
147 ModuleOp pdlModule = pdlPatterns.getModule();
151 pdlPatterns.takeConfigMap();
152 if (
failed(convertPDLToPDLInterp(pdlModule, configMap)))
153 llvm::report_fatal_error(
154 "failed to lower PDL pattern module to the PDL Interpreter");
161 if (!pdlModule.lookupSymbol(
162 pdl_interp::PDLInterpDialect::getMatcherFunctionName()))
166 impl->pdlByteCode = std::make_unique<detail::PDLByteCode>(
167 pdlModule, pdlPatterns.takeConfigs(), configMap,
168 pdlPatterns.takeConstraintFunctions(),
169 pdlPatterns.takeRewriteFunctions());