[mlir][drr] NFC: avoid SmallVector when collecting substitution values
authorLei Zhang <antiagainst@google.com>
Thu, 23 Apr 2020 22:28:22 +0000 (18:28 -0400)
committerLei Zhang <antiagainst@google.com>
Fri, 24 Apr 2020 13:36:47 +0000 (09:36 -0400)
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

mlir/lib/TableGen/Pattern.cpp
mlir/tools/mlir-tblgen/RewriterGen.cpp

index b04c8e2..7fb3a96 100644 (file)
@@ -345,7 +345,7 @@ std::string tblgen::SymbolInfoMap::SymbolInfo::getAllRangeUse(
   case Kind::Value: {
     assert(index < 0 && "only allowed for symbol bound to result");
     assert(op == nullptr);
-    auto repl = formatv(fmt, formatv("{{{0}}", name));
+    auto repl = formatv(fmt, formatv("ValueRange{{{0}}", name));
     LLVM_DEBUG(llvm::dbgs() << repl << " (Value)\n");
     return std::string(repl);
   }
index 62638e6..8e8decc 100644 (file)
@@ -612,15 +612,8 @@ void PatternEmitter::emitRewriteLogic() {
       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.
-      // We need an explicit cast to `SmallVector` to capture the cases where
-      // `{0}` resolves to an `Operation::result_range` as well as cases that
-      // are not iterable (e.g. vector that gets wrapped in additional braces by
-      // RewriterGen).
-      // TODO(b/147096809): Revisit the need for materializing a vector.
       os << symbolInfoMap.getAllRangeUse(
-          val,
-          "    for (auto v : SmallVector<Value, 4>{ {0} }) {{ "
-          "tblgen_repl_values.push_back(v); }",
+          val, "    for (Value v : {0}) {{ tblgen_repl_values.push_back(v); }",
           "\n");
     }
     os.indent(4) << "\n";