[Mlir-commits] [mlir] [mlir][TblGen] `get...Mutable` returns `OpOperand &` for single operands (PR #66519)

Jacques Pienaar llvmlistbot at llvm.org
Fri Sep 15 09:25:24 PDT 2023


================
@@ -2071,29 +2071,36 @@ void OpEmitter::genNamedOperandSetters() {
       continue;
     std::string name = op.getGetterName(operand.name);
 
-    auto *m = opClass.addMethod(operand.isVariadicOfVariadic()
-                                    ? "::mlir::MutableOperandRangeRange"
-                                    : "::mlir::MutableOperandRange",
-                                name + "Mutable");
+    StringRef returnType;
+    if (operand.isVariadicOfVariadic()) {
+      returnType = "::mlir::MutableOperandRangeRange";
+    } else if (operand.isVariableLength()) {
+      returnType = "::mlir::MutableOperandRange";
+    } else {
+      returnType = "::mlir::OpOperand &";
+    }
+    auto *m = opClass.addMethod(returnType, name + "Mutable");
     ERROR_IF_PRUNED(m, name, op);
     auto &body = m->body();
-    body << "  auto range = getODSOperandIndexAndLength(" << i << ");\n"
-         << "  auto mutableRange = "
-            "::mlir::MutableOperandRange(getOperation(), "
-            "range.first, range.second";
-    if (attrSizedOperands) {
-      if (emitHelper.hasProperties())
-        body << formatv(", ::mlir::MutableOperandRange::OperandSegment({0}u, "
-                        "{{getOperandSegmentSizesAttrName(), "
-                        "::mlir::DenseI32ArrayAttr::get(getContext(), "
-                        "getProperties().operandSegmentSizes)})",
-                        i);
-      else
-        body << formatv(
-            ", ::mlir::MutableOperandRange::OperandSegment({0}u, *{1})", i,
-            emitHelper.getAttr(operandSegmentAttrName, /*isNamed=*/true));
+    body << "  auto range = getODSOperandIndexAndLength(" << i << ");\n";
+    if (operand.isVariadicOfVariadic() || operand.isVariableLength()) {
----------------
jpienaar wrote:

For variadic of variadic case, could this result in changing number of operands without updating the segment attribute? (Folks ran into a foot gun around this the other day).

https://github.com/llvm/llvm-project/pull/66519


More information about the Mlir-commits mailing list