Use operand number during serialization to get the <id>s of the operands
authorMahesh Ravishankar <ravishankarm@google.com>
Wed, 31 Jul 2019 19:34:17 +0000 (12:34 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Wed, 31 Jul 2019 19:34:51 +0000 (12:34 -0700)
During serialization, the operand number must be used to get the
values assocaited with an operand. Using the argument number in Op
specification was wrong since some of the elements in the arguments
list might be attributes on the operation. This resulted in a segfault
during serialization.
Add a test that exercise that path.

PiperOrigin-RevId: 260977758

mlir/test/Dialect/SPIRV/Serialization/variables_init.mlir [new file with mode: 0644]
mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp

diff --git a/mlir/test/Dialect/SPIRV/Serialization/variables_init.mlir b/mlir/test/Dialect/SPIRV/Serialization/variables_init.mlir
new file mode 100644 (file)
index 0000000..65e0703
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s
+
+func @spirv_variables() -> () {
+  spv.module "Logical" "VulkanKHR" {
+    // CHECK: [[INIT:%.*]] = spv.constant 4.000000e+00 : f32
+    // CHECK: {{%.*}} = spv.Variable init([[INIT]]) bind(1, 0) : !spv.ptr<f32, Input>
+    %0 = spv.constant 4.0 : f32
+    %2 = spv.Variable init(%0) bind(1, 0) : !spv.ptr<f32, Input>
+  }
+  return
+}
\ No newline at end of file
index 75da5e7..94b7aaa 100644 (file)
@@ -130,7 +130,7 @@ static void emitSerializationFunction(const Record *attrClass,
     auto argument = op.getArg(i);
     os << "  {\n";
     if (argument.is<NamedTypeConstraint *>()) {
-      os << "    for (auto arg : op.getODSOperands(" << i << ")) {\n";
+      os << "    for (auto arg : op.getODSOperands(" << operandNum << ")) {\n";
       os << "      auto argID = findValueID(arg);\n";
       os << "      if (!argID) {\n";
       os << "        emitError(op.getLoc(), \"operand " << operandNum