Skip to content

Commit 2f8b164

Browse files
committed
[mlir][drr] NFC: avoid SmallVector when collecting substitution values
Now both Operation::operand_range and Operation::result_range have .begin() and .end() for ranged-based for loop and we have ValueRange for wrapping a single Value. We can remove the SmallVector materialization! Differential Revision: https://reviews.llvm.org/D78766
1 parent bfbdab6 commit 2f8b164

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

mlir/lib/TableGen/Pattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ std::string tblgen::SymbolInfoMap::SymbolInfo::getAllRangeUse(
345345
case Kind::Value: {
346346
assert(index < 0 && "only allowed for symbol bound to result");
347347
assert(op == nullptr);
348-
auto repl = formatv(fmt, formatv("{{{0}}", name));
348+
auto repl = formatv(fmt, formatv("ValueRange{{{0}}", name));
349349
LLVM_DEBUG(llvm::dbgs() << repl << " (Value)\n");
350350
return std::string(repl);
351351
}

mlir/tools/mlir-tblgen/RewriterGen.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -612,15 +612,8 @@ void PatternEmitter::emitRewriteLogic() {
612612
auto val = handleResultPattern(resultTree, offsets[i], 0);
613613
os.indent(4) << "\n";
614614
// Resolve each symbol for all range use so that we can loop over them.
615-
// We need an explicit cast to `SmallVector` to capture the cases where
616-
// `{0}` resolves to an `Operation::result_range` as well as cases that
617-
// are not iterable (e.g. vector that gets wrapped in additional braces by
618-
// RewriterGen).
619-
// TODO(b/147096809): Revisit the need for materializing a vector.
620615
os << symbolInfoMap.getAllRangeUse(
621-
val,
622-
" for (auto v : SmallVector<Value, 4>{ {0} }) {{ "
623-
"tblgen_repl_values.push_back(v); }",
616+
val, " for (Value v : {0}) {{ tblgen_repl_values.push_back(v); }",
624617
"\n");
625618
}
626619
os.indent(4) << "\n";

0 commit comments

Comments
 (0)