Skip to content

Commit d2c280e

Browse files
sarnexjsji
authored andcommitted
Fix AttrKind attributes with --spirv-preserve-auxdata (#2107)
For AttrKind attributes, we need to convert them to the AttrKind enum before checking if it exists or adding it, otherwise it gets added as a string. Signed-off-by: Sarnie, Nick <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@d24b9c6
1 parent 3516299 commit d2c280e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4525,15 +4525,21 @@ void SPIRVToLLVM::transAuxDataInst(SPIRVExtInst *BC) {
45254525
case NonSemanticAuxData::FunctionAttribute: {
45264526
assert(Args.size() < 4 && "Unexpected FunctionAttribute Args");
45274527
// If this attr was specially handled and added elsewhere, skip it.
4528-
if (F->hasFnAttribute(AttrOrMDName))
4528+
Attribute::AttrKind AsKind = Attribute::getAttrKindFromName(AttrOrMDName);
4529+
if (AsKind != Attribute::None && F->hasFnAttribute(AsKind))
4530+
return;
4531+
if (AsKind == Attribute::None && F->hasFnAttribute(AttrOrMDName))
45294532
return;
45304533
// For attributes, arg 2 is the attribute value as a string, which may not
45314534
// exist.
45324535
if (Args.size() == 3) {
45334536
auto AttrValue = BC->getModule()->get<SPIRVString>(Args[2])->getStr();
45344537
F->addFnAttr(AttrOrMDName, AttrValue);
45354538
} else {
4536-
F->addFnAttr(AttrOrMDName);
4539+
if (AsKind != Attribute::None)
4540+
F->addFnAttr(AsKind);
4541+
else
4542+
F->addFnAttr(AttrOrMDName);
45374543
}
45384544
break;
45394545
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata -o - | FileCheck %s --check-prefix=CHECK-SPIRV
3+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-preserve-auxdata
4+
; RUN: llvm-spirv -r -emit-opaque-pointers --spirv-preserve-auxdata %t.spv -o %t.rev.bc
5+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM
6+
7+
; CHECK-SPIRV: Extension "SPV_KHR_non_semantic_info"
8+
; CHECK-SPIRV: ExtInstImport [[#Import:]] "NonSemantic.AuxData"
9+
10+
; CHECK-SPIRV: String [[#Attr0:]] "nounwind"
11+
12+
; CHECK-SPIRV: Name [[#Fcn0:]] "foo"
13+
14+
; CHECK-SPIRV: TypeVoid [[#VoidT:]]
15+
16+
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#Attr0Inst:]] [[#Import]] NonSemanticAuxDataFunctionAttribute [[#Fcn0]] [[#Attr0]] {{$}}
17+
18+
target triple = "spir64-unknown-unknown"
19+
20+
; CHECK-LLVM: define spir_func void @foo() #[[#Fcn0IRAttr:]]
21+
define spir_func void @foo() #0 {
22+
entry:
23+
ret void
24+
}
25+
; CHECK-LLVM: attributes #[[#Fcn0IRAttr]] = { nounwind }
26+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)