linker: merge debug annotations from category c)
authorPierre Moreau <dev@pmoreau.org>
Wed, 14 Feb 2018 18:12:05 +0000 (19:12 +0100)
committerDavid Neto <dneto@google.com>
Tue, 27 Feb 2018 17:31:50 +0000 (12:31 -0500)
Fixes: https://github.com/KhronosGroup/SPIRV-Tools/issues/1218

source/link/linker.cpp
test/link/matching_imports_to_exports_test.cpp
test/link/partial_linkage_test.cpp

index 4f51c57..60788f3 100644 (file)
@@ -448,6 +448,24 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
           std::unique_ptr<Instruction>(inst.Clone(linked_context)));
 
   for (const auto& module : input_modules)
+    for (const auto& inst : module->debugs3())
+      linked_module->AddDebug3Inst(
+          std::unique_ptr<Instruction>(inst.Clone(linked_context)));
+
+  // If the generated module uses SPIR-V 1.1 or higher, add an
+  // OpModuleProcessed instruction about the linking step.
+  if (linked_module->version() >= 0x10100) {
+    const std::string processed_string("Linked by SPIR-V Tools Linker");
+    const size_t words_nb =
+        processed_string.size() / 4u + (processed_string.size() % 4u != 0u);
+    std::vector<uint32_t> processed_words(words_nb, 0u);
+    std::memcpy(processed_words.data(), processed_string.data(), words_nb * 4u);
+    linked_module->AddDebug3Inst(std::unique_ptr<Instruction>(
+        new Instruction(linked_context, SpvOpModuleProcessed, 0u, 0u,
+                        {{SPV_OPERAND_TYPE_LITERAL_STRING, processed_words}})));
+  }
+
+  for (const auto& module : input_modules)
     for (const auto& inst : module->annotations())
       linked_module->AddAnnotationInst(
           std::unique_ptr<Instruction>(inst.Clone(linked_context)));
index b37917b..8496b9c 100644 (file)
@@ -40,7 +40,9 @@ OpDecorate %1 LinkageAttributes "foo" Export
   EXPECT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary))
       << GetErrorMessage();
 
-  const std::string expected_res = R"(%1 = OpTypeFloat 32
+  const std::string expected_res =
+      R"(OpModuleProcessed "Linked by SPIR-V Tools Linker"
+%1 = OpTypeFloat 32
 %2 = OpVariable %1 Input
 %3 = OpConstant %1 42
 %4 = OpVariable %1 Uniform %3
@@ -64,7 +66,9 @@ OpDecorate %1 LinkageAttributes "foo" Export
   EXPECT_EQ(SPV_SUCCESS, AssembleAndLink({body}, &linked_binary))
       << GetErrorMessage();
 
-  const std::string expected_res = R"(%1 = OpTypeFloat 32
+  const std::string expected_res =
+      R"(OpModuleProcessed "Linked by SPIR-V Tools Linker"
+%1 = OpTypeFloat 32
 %2 = OpVariable %1 Uniform
 )";
   std::string res_body;
@@ -89,6 +93,7 @@ OpDecorate %1 LinkageAttributes "foo" Export
       << GetErrorMessage();
 
   const std::string expected_res = R"(OpCapability Linkage
+OpModuleProcessed "Linked by SPIR-V Tools Linker"
 OpDecorate %1 LinkageAttributes "foo" Export
 %2 = OpTypeFloat 32
 %1 = OpVariable %2 Uniform
@@ -267,6 +272,7 @@ OpFunctionEnd
       << GetErrorMessage();
 
   const std::string expected_res = R"(OpCapability Kernel
+OpModuleProcessed "Linked by SPIR-V Tools Linker"
 OpDecorate %1 FuncParamAttr Sext
 %2 = OpTypeVoid
 %3 = OpTypeInt 32 0
@@ -310,7 +316,9 @@ OpFunctionEnd
   EXPECT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary))
       << GetErrorMessage();
 
-  const std::string expected_res = R"(%1 = OpTypeVoid
+  const std::string expected_res =
+      R"(OpModuleProcessed "Linked by SPIR-V Tools Linker"
+%1 = OpTypeVoid
 %2 = OpTypeFunction %1
 %3 = OpTypeFloat 32
 %4 = OpVariable %3 Uniform
index bf5a289..386d7a8 100644 (file)
@@ -44,6 +44,7 @@ OpDecorate %1 LinkageAttributes "bar" Export
             AssembleAndLink({body1, body2}, &linked_binary, linker_options));
 
   const std::string expected_res = R"(OpCapability Linkage
+OpModuleProcessed "Linked by SPIR-V Tools Linker"
 OpDecorate %1 LinkageAttributes "foo" Import
 %2 = OpTypeFloat 32
 %1 = OpVariable %2 Uniform