Skip to content

Commit 86bdd0a

Browse files
bashbaugsvenvh
authored andcommitted
[Backport to 19] add reverse translation for OpDecorateString and OpMemberDecorateString (KhronosGroup#2677)
This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions. I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR. (cherry picked from commit f7057b4)
1 parent d7ad072 commit 86bdd0a

4 files changed

+76
-0
lines changed

lib/SPIRV/libSPIRV/SPIRVDecorate.h

+4
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ class SPIRVDecorate : public SPIRVDecorateGeneric {
231231
}
232232
};
233233

234+
class SPIRVDecorateString : public SPIRVDecorate {};
235+
234236
class SPIRVDecorateId : public SPIRVDecorateGeneric {
235237
public:
236238
static const Op OC = OpDecorateId;
@@ -383,6 +385,8 @@ class SPIRVMemberDecorate : public SPIRVDecorateGeneric {
383385
SPIRVWord MemberNumber;
384386
};
385387

388+
class SPIRVMemberDecorateString : public SPIRVMemberDecorate {};
389+
386390
class SPIRVDecorationGroup : public SPIRVEntry {
387391
public:
388392
static const Op OC = OpDecorationGroup;

lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h

+2
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ _SPIRV_OP(AtomicFMinEXT, 5614)
365365
_SPIRV_OP(AtomicFMaxEXT, 5615)
366366
_SPIRV_OP(AssumeTrueKHR, 5630)
367367
_SPIRV_OP(ExpectKHR, 5631)
368+
_SPIRV_OP(DecorateString, 5632)
369+
_SPIRV_OP(MemberDecorateString, 5633)
368370
_SPIRV_OP(VmeImageINTEL, 5699)
369371
_SPIRV_OP(TypeVmeImageINTEL, 5700)
370372
_SPIRV_OP(TypeAvcImePayloadINTEL, 5701)
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; REQUIRES: spirv-as
2+
; RUN: spirv-as --target-env spv1.4 -o %t.spv %s
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -r -o - %t.spv | llvm-dis | FileCheck %s
5+
6+
; SPIR-V
7+
; Version: 1.4
8+
; Generator: Khronos LLVM/SPIR-V Translator; 14
9+
; Bound: 40
10+
; Schema: 0
11+
OpCapability Addresses
12+
OpCapability Linkage
13+
OpCapability Kernel
14+
OpMemoryModel Physical64 OpenCL
15+
OpEntryPoint Kernel %kernel "test"
16+
; Note: this is decorating a variable in the function storage class, which
17+
; is not actually valid according to the SPIR-V spec, but is processed by
18+
; the SPIR-V LLVM Translator and not rejected by spirv-val.
19+
OpDecorateString %temp UserSemantic "foo"
20+
; CHECK: [[STR:@[0-9_.]+]] = {{.*}}foo
21+
; CHECK: call void @llvm.var.annotation.p0.p0(ptr %{{.*}}, ptr [[STR]], ptr undef, i32 undef, ptr undef)
22+
%uint = OpTypeInt 32 0
23+
%void = OpTypeVoid
24+
%kernel_sig = OpTypeFunction %void %uint
25+
%ptr_uint = OpTypePointer Function %uint
26+
%kernel = OpFunction %void None %kernel_sig
27+
%a = OpFunctionParameter %uint
28+
%entry = OpLabel
29+
%temp = OpVariable %ptr_uint Function
30+
%add = OpIAdd %uint %a %a
31+
OpStore %temp %add Aligned 4
32+
OpReturn
33+
OpFunctionEnd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; REQUIRES: spirv-as
2+
; RUN: spirv-as --target-env spv1.4 -o %t.spv %s
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -r -o - %t.spv | llvm-dis | FileCheck %s
5+
6+
; SPIR-V
7+
; Version: 1.4
8+
; Generator: Khronos LLVM/SPIR-V Translator; 14
9+
; Bound: 44
10+
; Schema: 0
11+
OpCapability Addresses
12+
OpCapability Linkage
13+
OpCapability Kernel
14+
OpCapability Int64
15+
OpMemoryModel Physical64 OpenCL
16+
OpEntryPoint Kernel %kernel "test"
17+
OpMemberDecorateString %struct 0 UserSemantic "foo"
18+
; CHECK: [[STR:@[0-9_.]+]] = {{.*}}foo
19+
; Note: this is checking for an annotation on an instantiation of the structure,
20+
; which is different than an annotation on the structure type.
21+
; CHECK: call ptr @llvm.ptr.annotation.p0.p0(ptr %{{.*}}, ptr [[STR]], ptr undef, i32 undef, ptr undef)
22+
%uint = OpTypeInt 32 0
23+
%uint_0 = OpConstant %uint 0
24+
%void = OpTypeVoid
25+
%kernel_sig = OpTypeFunction %void %uint
26+
%struct = OpTypeStruct %uint
27+
%ptr_struct = OpTypePointer Function %struct
28+
%ptr_uint = OpTypePointer Function %uint
29+
%kernel = OpFunction %void None %kernel_sig
30+
%a = OpFunctionParameter %uint
31+
%entry = OpLabel
32+
%s = OpVariable %ptr_struct Function
33+
%add = OpIAdd %uint %a %a
34+
%x = OpInBoundsPtrAccessChain %ptr_uint %s %uint_0 %uint_0
35+
OpStore %x %add Aligned 4
36+
OpReturn
37+
OpFunctionEnd

0 commit comments

Comments
 (0)