Skip to content

Commit 89d658c

Browse files
authored
Skip spirv decoration metadata with --spirv-preserve-auxdata (#2013)
It's already explicitly handled for forward and reverse translation, and it's a bit complicated to handle MDNode metadata. Just skip it so we don't assert. If I see this come up in more cases I will add support for MDNode metadata. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 8cbf726 commit 89d658c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,13 +1181,22 @@ void LLVMToSPIRVBase::transAuxDataInst(SPIRVFunction *BF, Function *F) {
11811181
F->getContext().getMDKindNames(MDNames);
11821182
F->getAllMetadata(AllMD);
11831183
for (auto MD : AllMD) {
1184+
std::string MDName = MDNames[MD.first].str();
1185+
1186+
// spirv.Decorations and spirv.ParameterDecorations are handled
1187+
// elsewhere for both forward and reverse translation and are complicated
1188+
// to support here, so just skip them.
1189+
if (MDName == SPIRV_MD_DECORATIONS ||
1190+
MDName == SPIRV_MD_PARAMETER_DECORATIONS)
1191+
continue;
1192+
11841193
// Format for metadata is:
11851194
// NonSemanticAuxDataFunctionMetadata Fcn MDName MDVals...
11861195
// MDName is always a String, MDVals have different types as explained
11871196
// below. Also note this instruction has a variable number of operands
11881197
std::vector<SPIRVWord> Ops;
11891198
Ops.push_back(BF->getId());
1190-
Ops.push_back(BM->getString(MDNames[MD.first].str())->getId());
1199+
Ops.push_back(BM->getString(MDName)->getId());
11911200
for (unsigned int OpIdx = 0; OpIdx < MD.second->getNumOperands(); OpIdx++) {
11921201
const auto &CurOp = MD.second->getOperand(OpIdx);
11931202
if (auto *MDStr = dyn_cast<MDString>(CurOp)) {

test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-metadata.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ ret void
3232
}
3333

3434
; CHECK-LLVM: define spir_func void @test_string() {{.*}} !bar ![[#LLVMStr:]]
35-
define spir_func void @test_string() #1 !bar !2 {
35+
define spir_func void @test_string() #1 !bar !2 !spirv.Decorations !4 !spirv.ParameterDecorations !3 {
3636
ret void
3737
}
3838

3939
; CHECK-LLVM: ![[#LLVMVal]] = !{i32 5}
4040
!1 = !{i32 5}
4141
; CHECK-LLVM ![[#LLVMSTR]] = !{!"baz"}
4242
!2 = !{!"baz"}
43+
!3 = !{!4, !7, !4}
44+
!4 = !{!5, !6}
45+
!5 = !{i32 0, i32 2}
46+
!6 = !{i32 0, i32 8}
47+
!7 = !{!6}

0 commit comments

Comments
 (0)