Skip to content

Commit 353f349

Browse files
sarnexsys-ce-bb
authored andcommitted
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]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@89d658c
1 parent 23a3ea0 commit 353f349

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,13 +1199,22 @@ void LLVMToSPIRVBase::transAuxDataInst(SPIRVFunction *BF, Function *F) {
11991199
F->getContext().getMDKindNames(MDNames);
12001200
F->getAllMetadata(AllMD);
12011201
for (auto MD : AllMD) {
1202+
std::string MDName = MDNames[MD.first].str();
1203+
1204+
// spirv.Decorations and spirv.ParameterDecorations are handled
1205+
// elsewhere for both forward and reverse translation and are complicated
1206+
// to support here, so just skip them.
1207+
if (MDName == SPIRV_MD_DECORATIONS ||
1208+
MDName == SPIRV_MD_PARAMETER_DECORATIONS)
1209+
continue;
1210+
12021211
// Format for metadata is:
12031212
// NonSemanticAuxDataFunctionMetadata Fcn MDName MDVals...
12041213
// MDName is always a String, MDVals have different types as explained
12051214
// below. Also note this instruction has a variable number of operands
12061215
std::vector<SPIRVWord> Ops;
12071216
Ops.push_back(BF->getId());
1208-
Ops.push_back(BM->getString(MDNames[MD.first].str())->getId());
1217+
Ops.push_back(BM->getString(MDName)->getId());
12091218
for (unsigned int OpIdx = 0; OpIdx < MD.second->getNumOperands(); OpIdx++) {
12101219
const auto &CurOp = MD.second->getOperand(OpIdx);
12111220
if (auto *MDStr = dyn_cast<MDString>(CurOp)) {

llvm-spirv/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)