Skip to content

Commit 2b91357

Browse files
bashbaugsvenvh
authored andcommitted
[Backport to 15] 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 db50326 commit 2b91357

4 files changed

+76
-0
lines changed

lib/SPIRV/libSPIRV/SPIRVDecorate.h

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ class SPIRVDecorate : public SPIRVDecorateGeneric {
203203
}
204204
};
205205

206+
class SPIRVDecorateString : public SPIRVDecorate {};
207+
206208
class SPIRVDecorateId : public SPIRVDecorateGeneric {
207209
public:
208210
static const Op OC = OpDecorateId;
@@ -352,6 +354,8 @@ class SPIRVMemberDecorate : public SPIRVDecorateGeneric {
352354
SPIRVWord MemberNumber;
353355
};
354356

357+
class SPIRVMemberDecorateString : public SPIRVMemberDecorate {};
358+
355359
class SPIRVDecorationGroup : public SPIRVEntry {
356360
public:
357361
static const Op OC = OpDecorationGroup;

lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h

+2
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ _SPIRV_OP(AtomicFMinEXT, 5614)
364364
_SPIRV_OP(AtomicFMaxEXT, 5615)
365365
_SPIRV_OP(AssumeTrueKHR, 5630)
366366
_SPIRV_OP(ExpectKHR, 5631)
367+
_SPIRV_OP(DecorateString, 5632)
368+
_SPIRV_OP(MemberDecorateString, 5633)
367369
_SPIRV_OP(VmeImageINTEL, 5699)
368370
_SPIRV_OP(TypeVmeImageINTEL, 5700)
369371
_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 -emit-opaque-pointers -r -o - %t.spv | llvm-dis -opaque-pointers | 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(ptr %{{.*}}, ptr getelementptr inbounds ([4 x i8], ptr [[STR]], i32 0, i32 0), 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 -emit-opaque-pointers -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)