[DRR] Use eraseOp() to replace no-result ops

PiperOrigin-RevId: 275475229
This commit is contained in:
Lei Zhang 2019-10-18 08:19:54 -07:00 committed by A. Unique TensorFlower
parent 151e7e61e8
commit 3aae473658
1 changed files with 18 additions and 10 deletions

View File

@ -542,18 +542,26 @@ void PatternEmitter::emitRewriteLogic() {
os.indent(4) << val << ";\n";
}
// Process replacement result patterns.
os.indent(4) << "SmallVector<Value *, 4> tblgen_values;";
for (int i = replStartIndex; i < numResultPatterns; ++i) {
DagNode resultTree = pattern.getResultPattern(i);
auto val = handleResultPattern(resultTree, offsets[i], 0);
if (numExpectedResults == 0) {
assert(replStartIndex >= numResultPatterns &&
"invalid auxiliary vs. replacement pattern division!");
// No result to replace. Just erase the op.
os.indent(4) << "rewriter.eraseOp(op0);\n";
} else {
// Process replacement result patterns.
os.indent(4) << "SmallVector<Value *, 4> tblgen_values;";
for (int i = replStartIndex; i < numResultPatterns; ++i) {
DagNode resultTree = pattern.getResultPattern(i);
auto val = handleResultPattern(resultTree, offsets[i], 0);
os.indent(4) << "\n";
// Resolve each symbol for all range use so that we can loop over them.
os << symbolInfoMap.getAllRangeUse(
val, " for (auto *v : {0}) tblgen_values.push_back(v);", "\n");
}
os.indent(4) << "\n";
// Resolve each symbol for all range use so that we can loop over them.
os << symbolInfoMap.getAllRangeUse(
val, " for (auto *v : {0}) tblgen_values.push_back(v);", "\n");
os.indent(4) << "rewriter.replaceOp(op0, tblgen_values);\n";
}
os.indent(4) << "\n";
os.indent(4) << "rewriter.replaceOp(op0, tblgen_values);\n";
LLVM_DEBUG(llvm::dbgs() << "--- done emitting rewrite logic ---\n");
}