Skip to content

[mlir] Move supplemental patterns before op replacement #66959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions mlir/tools/mlir-tblgen/RewriterGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,9 +1172,22 @@ void PatternEmitter::emitRewriteLogic() {
os << val << ";\n";
}

auto processSupplementalPatterns = [&]() {
int numSupplementalPatterns = pattern.getNumSupplementalPatterns();
for (int i = 0, offset = -numSupplementalPatterns;
i < numSupplementalPatterns; ++i) {
DagNode resultTree = pattern.getSupplementalPattern(i);
auto val = handleResultPattern(resultTree, offset++, 0);
if (resultTree.isNativeCodeCall() &&
resultTree.getNumReturnsOfNativeCode() == 0)
os << val << ";\n";
}
};

if (numExpectedResults == 0) {
assert(replStartIndex >= numResultPatterns &&
"invalid auxiliary vs. replacement pattern division!");
processSupplementalPatterns();
// No result to replace. Just erase the op.
os << "rewriter.eraseOp(op0);\n";
} else {
Expand All @@ -1196,20 +1209,10 @@ void PatternEmitter::emitRewriteLogic() {
" tblgen_repl_values.push_back(v);\n}\n",
"\n");
}
processSupplementalPatterns();
os << "\nrewriter.replaceOp(op0, tblgen_repl_values);\n";
}

// Process supplemtal patterns.
int numSupplementalPatterns = pattern.getNumSupplementalPatterns();
for (int i = 0, offset = -numSupplementalPatterns;
i < numSupplementalPatterns; ++i) {
DagNode resultTree = pattern.getSupplementalPattern(i);
auto val = handleResultPattern(resultTree, offset++, 0);
if (resultTree.isNativeCodeCall() &&
resultTree.getNumReturnsOfNativeCode() == 0)
os << val << ";\n";
}

LLVM_DEBUG(llvm::dbgs() << "--- done emitting rewrite logic ---\n");
}

Expand Down