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_range(disabledPatternLabels);
69 enabledPatterns.insert_range(enabledPatternLabels);
74 std::vector<RegisteredOperationName> opInfos;
76 [&](std::unique_ptr<RewritePattern> &pattern,
79 opInfos = pattern->getContext()->getRegisteredOperations();
82 impl->nativeOpSpecificPatternMap[info].push_back(pattern.get());
83 impl->nativeOpSpecificPatternList.push_back(std::move(pattern));
86 for (std::unique_ptr<RewritePattern> &pat :
patterns.getNativePatterns()) {
88 if (!enabledPatterns.empty()) {
89 auto isEnabledFn = [&](StringRef label) {
90 return enabledPatterns.count(label);
92 if (!isEnabledFn(pat->getDebugName()) &&
93 llvm::none_of(pat->getDebugLabels(), isEnabledFn))
97 if (!disabledPatterns.empty()) {
98 auto isDisabledFn = [&](StringRef label) {
99 return disabledPatterns.count(label);
101 if (isDisabledFn(pat->getDebugName()) ||
102 llvm::any_of(pat->getDebugLabels(), isDisabledFn))
106 if (std::optional<OperationName> rootName = pat->getRootKind()) {
107 impl->nativeOpSpecificPatternMap[*rootName].push_back(pat.get());
108 impl->nativeOpSpecificPatternList.push_back(std::move(pat));
111 if (std::optional<TypeID> interfaceID = pat->getRootInterfaceID()) {
117 if (std::optional<TypeID> traitID = pat->getRootTraitID()) {
123 impl->nativeAnyOpPatterns.push_back(std::move(pat));
126 #if MLIR_ENABLE_PDL_IN_PATTERNMATCH
128 PDLPatternModule &pdlPatterns =
patterns.getPDLPatterns();
129 ModuleOp pdlModule = pdlPatterns.getModule();
133 pdlPatterns.takeConfigMap();
134 if (failed(convertPDLToPDLInterp(pdlModule, configMap)))
135 llvm::report_fatal_error(
136 "failed to lower PDL pattern module to the PDL Interpreter");
139 impl->pdlByteCode = std::make_unique<detail::PDLByteCode>(
140 pdlModule, pdlPatterns.takeConfigs(), configMap,
141 pdlPatterns.takeConstraintFunctions(),
142 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