Skip to content

Commit 95e96b9

Browse files
authored
[SPIRV] Addition of entry-point-interfaces.ll, get_global_size.ll, layout.ll test files (#151648)
--Test that verifies correct emission of OpEntryPoint and interface variables for SPIR-V when using multiple global constants in the kernel entry point. --Test that verifies code generation for get_global_size() calls. --Test that verifies SPIR-V layout and initialization of various global variables.
1 parent f3e7b35 commit 95e96b9

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK: OpEntryPoint Kernel %[[#Func:]] "test" %[[#Interface1:]] %[[#Interface2:]] %[[#Interface3:]] %[[#Interface4:]]
5+
; CHECK-DAG: OpName %[[#Func]] "test"
6+
; CHECK-DAG: OpName %[[#Interface1]] "var"
7+
; CHECK-DAG: OpName %[[#Interface3]] "var2"
8+
; CHECK-DAG: OpName %[[#Interface2]] "var.const"
9+
; CHECK-DAG: OpName %[[#Interface4]] "var2.const"
10+
; CHECK-DAG: %[[#TypeInt:]] = OpTypeInt 32 0
11+
; CHECK-DAG: %[[#Const1:]] = OpConstant %[[#TypeInt]] 1
12+
; CHECK-DAG: %[[#Const2:]] = OpConstant %[[#TypeInt]] 3
13+
14+
; CHECK: %[[#Interface1]] = OpVariable %[[#]] UniformConstant %[[#Const1]]
15+
; CHECK: %[[#Interface3]] = OpVariable %[[#]] UniformConstant %[[#Const2]]
16+
; CHECK: %[[#Interface2]] = OpVariable %[[#]] UniformConstant %[[#Const1]]
17+
; CHECK: %[[#Interface4]] = OpVariable %[[#]] UniformConstant %[[#Const2]]
18+
19+
@var = dso_local addrspace(2) constant i32 1, align 4
20+
@var2 = dso_local addrspace(2) constant i32 3, align 4
21+
@var.const = private unnamed_addr addrspace(2) constant i32 1, align 4
22+
@var2.const = private unnamed_addr addrspace(2) constant i32 3, align 4
23+
24+
define dso_local spir_kernel void @test() {
25+
entry:
26+
%0 = load i32, ptr addrspace(2) @var.const, align 4
27+
%1 = load i32, ptr addrspace(2) @var2.const, align 4
28+
%mul = mul nsw i32 %0, %1
29+
%mul1 = mul nsw i32 %mul, 2
30+
ret void
31+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK: %[[#int32:]] = OpTypeInt 32 0
5+
; CHECK: %[[#int64:]] = OpTypeInt 64 0
6+
; CHECK: %[[#vec3:]] = OpTypeVector %[[#int64]] 3
7+
; CHECK: %[[#ptr_input_vec3:]] = OpTypePointer Input %[[#vec3]]
8+
; CHECK: %[[#global_size_var:]] = OpVariable %[[#ptr_input_vec3]] Input
9+
10+
; CHECK: %[[#load_gs1:]] = OpLoad %[[#vec3]] %[[#global_size_var]] Aligned 1
11+
; CHECK: %[[#extract3:]] = OpCompositeExtract %[[#int64]] %[[#load_gs1]] 0
12+
13+
; CHECK: %[[#bitcast1:]] = OpBitcast %[[#]] %[[#]]
14+
; CHECK: %[[#load_out1:]] = OpLoad %[[#]] %[[#bitcast1]] Aligned 8
15+
; CHECK: %[[#gep1:]] = OpInBoundsPtrAccessChain %[[#]] %[[#load_out1]] %[[#]]
16+
; CHECK: OpStore %[[#gep1]] %[[#extract3]] Aligned 8
17+
18+
; CHECK: %[[#load_param_x:]] = OpLoad %[[#int32]] %[[#]]
19+
; CHECK: %[[#load_gs2:]] = OpLoad %[[#vec3]] %[[#global_size_var]] Aligned 1
20+
; CHECK: %[[#dyn_extract:]] = OpVectorExtractDynamic %[[#int64]] %[[#load_gs2]] %[[#load_param_x]]
21+
; CHECK: %[[#cmp:]] = OpULessThan %[[#]] %[[#load_param_x]] %[[#]]
22+
; CHECK: %[[#select2:]] = OpSelect %[[#int64]] %[[#cmp]] %[[#dyn_extract]] %[[#]]
23+
; CHECK: %[[#bitcast2:]] = OpBitcast %[[#]] %[[#]]
24+
; CHECK: %[[#load_out2:]] = OpLoad %[[#]] %[[#bitcast2]] Aligned 8
25+
; CHECK: %[[#gep2:]] = OpInBoundsPtrAccessChain %[[#]] %[[#load_out2]] %[[#]]
26+
; CHECK: OpStore %[[#gep2]] %[[#select2]] Aligned 8
27+
28+
define dso_local spir_kernel void @ggs(ptr noundef align 8 %out, i32 noundef %x) {
29+
entry:
30+
%out.addr = alloca ptr, align 8
31+
%x.addr = alloca i32, align 4
32+
store ptr %out, ptr %out.addr, align 8
33+
store i32 %x, ptr %x.addr, align 4
34+
%call = call i64 @_Z15get_global_sizej(i32 noundef 0)
35+
%0 = load ptr, ptr %out.addr, align 8
36+
%arrayidx = getelementptr inbounds i64, ptr %0, i64 0
37+
store i64 %call, ptr %arrayidx, align 8
38+
%call1 = call i64 @_Z15get_global_sizej(i32 noundef 3)
39+
%1 = load ptr, ptr %out.addr, align 8
40+
%arrayidx2 = getelementptr inbounds i64, ptr %1, i64 1
41+
store i64 %call1, ptr %arrayidx2, align 8
42+
%2 = load i32, ptr %x.addr, align 4
43+
%call3 = call i64 @_Z15get_global_sizej(i32 noundef %2)
44+
%3 = load ptr, ptr %out.addr, align 8
45+
%arrayidx4 = getelementptr inbounds i64, ptr %3, i64 2
46+
store i64 %call3, ptr %arrayidx4, align 8
47+
ret void
48+
}
49+
50+
declare i64 @_Z15get_global_sizej(i32 noundef)

llvm/test/CodeGen/SPIRV/layout.ll

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK: OpCapability Kernel
5+
; CHECK: OpCapability Addresses
6+
; CHECK: OpCapability GenericPointer
7+
; CHECK: OpCapability Int64
8+
; CHECK: OpCapability Int8
9+
; CHECK: OpCapability Linkage
10+
11+
; CHECK: OpExtInstImport "OpenCL.std"
12+
; CHECK: OpMemoryModel Physical64 OpenCL
13+
; CHECK: OpEntryPoint Kernel %[[#]] "foo" %[[#]]
14+
; CHECK: OpSource OpenCL_C 200000
15+
16+
; CHECK-DAG: OpName %[[#]]
17+
; CHECK-DAG: OpDecorate %[[#]]
18+
19+
20+
; CHECK: %[[#I8:]] = OpTypeInt 8 0
21+
; CHECK: %[[#PTR_CW_I8:]] = OpTypePointer CrossWorkgroup %[[#I8]]
22+
; CHECK: %[[#I32:]] = OpTypeInt 32 0
23+
; CHECK: %[[#VEC4:]] = OpTypeVector %[[#I32]] 4
24+
; CHECK: %[[#VOID:]] = OpTypeVoid
25+
; CHECK: %[[#FUNC_TYPE0:]] = OpTypeFunction %[[#VOID]] %[[#PTR_CW_I8]] %[[#VEC4]]
26+
; CHECK: %[[#FUNC_TYPE1:]] = OpTypeFunction %[[#VOID]] %[[#PTR_CW_I8]]
27+
; CHECK: %[[#VEC3:]] = OpTypeVector %[[#I32]] 3
28+
; CHECK: %[[#FUNC_TYPE2:]] = OpTypeFunction %[[#VOID]] %[[#PTR_CW_I8]] %[[#VEC3]]
29+
; CHECK: %[[#PTR_GEN_I8:]] = OpTypePointer Generic %[[#I8]]
30+
; CHECK: %[[#STRUCT_B:]] = OpTypeStruct %[[#I32]] %[[#PTR_GEN_I8]]
31+
; CHECK: %[[#STRUCT_C:]] = OpTypeStruct %[[#I32]] %[[#STRUCT_B]]
32+
; CHECK: %[[#STRUCT_A:]] = OpTypeStruct %[[#I32]] %[[#STRUCT_C]]
33+
; CHECK: %[[#F32:]] = OpTypeFloat 32
34+
; CHECK: %[[#CONST_2:]] = OpConstant %[[#I32]] 2
35+
; CHECK: %[[#ARRAY_F:]] = OpTypeArray %[[#F32]] %[[#CONST_2]]
36+
; CHECK: %[[#ARRAY_I:]] = OpTypeArray %[[#I32]] %[[#CONST_2]]
37+
; CHECK: %[[#PTR_CW_STRUCT_A:]] = OpTypePointer CrossWorkgroup %[[#STRUCT_A]]
38+
; CHECK: %[[#PTR_UC_VEC4:]] = OpTypePointer UniformConstant %[[#VEC4]]
39+
; CHECK: %[[#PTR_UC_ARRAY_F:]] = OpTypePointer UniformConstant %[[#ARRAY_F]]
40+
; CHECK: %[[#PTR_CW_PTR_CW_I8:]] = OpTypePointer CrossWorkgroup %[[#PTR_CW_I8]]
41+
; CHECK: %[[#I64:]] = OpTypeInt 64 0
42+
; CHECK: %[[#PTR_CW_ARRAY_I:]] = OpTypePointer CrossWorkgroup %[[#ARRAY_I]]
43+
44+
; CHECK: %[[#NULL_I32:]] = OpConstantNull %[[#I32]]
45+
; CHECK: %[[#CONST_I64_4:]] = OpConstant %[[#I64]] 4
46+
; CHECK: %[[#CONST_I32_1:]] = OpConstant %[[#I32]] 1
47+
; CHECK: %[[#COMP_I32:]] = OpConstantComposite %[[#ARRAY_I]] %[[#CONST_I32_1]] %[[#CONST_2]]
48+
49+
; CHECK: %[[#VAR_V:]] = OpVariable %[[#PTR_CW_ARRAY_I]] CrossWorkgroup %[[#COMP_I32]]
50+
; CHECK: %[[#SPECCONSTOP:]] = OpSpecConstantOp %[[#PTR_CW_I8]] InBoundsPtrAccessChain %[[#VAR_V]] %[[#NULL_I32]] %[[#CONST_I64_4]]
51+
; CHECK: %[[#VAR_S:]] = OpVariable %[[#PTR_CW_PTR_CW_I8]] CrossWorkgroup %[[#SPECCONSTOP]]
52+
; CHECK: %[[#NULL_ARRAY_F:]] = OpConstantNull %[[#ARRAY_F]]
53+
; CHECK: %[[#VAR_F:]] = OpVariable %[[#PTR_UC_ARRAY_F]] UniformConstant %[[#NULL_ARRAY_F]]
54+
; CHECK: %[[#NULL_STRUCT_A:]] = OpConstantNull %[[#STRUCT_A]]
55+
; CHECK: %[[#VAR_A:]] = OpVariable %[[#PTR_CW_STRUCT_A]] CrossWorkgroup %[[#NULL_STRUCT_A]]
56+
57+
; CHECK: %[[#FN_BAR1:]] = OpFunction %[[#VOID]] None %[[#FUNC_TYPE1]]
58+
; CHECK: %[[#P_BAR1:]] = OpFunctionParameter %[[#PTR_CW_I8]]
59+
; CHECK: OpFunctionEnd
60+
61+
@v = addrspace(1) global [2 x i32] [i32 1, i32 2], align 4
62+
@s = addrspace(1) global ptr addrspace(1) getelementptr inbounds ([2 x i32], ptr addrspace(1) @v, i32 0, i32 1), align 4
63+
64+
%struct.A = type { i32, %struct.C }
65+
%struct.C = type { i32, %struct.B }
66+
%struct.B = type { i32, ptr addrspace(4) }
67+
68+
@f = addrspace(2) constant [2 x float] zeroinitializer, align 4
69+
@b = external addrspace(2) constant <4 x i32>
70+
@a = common addrspace(1) global %struct.A zeroinitializer, align 4
71+
72+
define spir_kernel void @foo(ptr addrspace(1) %a, <4 x i32> %vec_in) {
73+
entry:
74+
call spir_func void @bar1(ptr addrspace(1) %a)
75+
%extractVec = shufflevector <4 x i32> %vec_in, <4 x i32> %vec_in, <3 x i32> <i32 0, i32 1, i32 2>
76+
call spir_func void @bar2(ptr addrspace(1) %a, <3 x i32> %extractVec)
77+
ret void
78+
}
79+
80+
declare spir_func void @bar1(ptr addrspace(1))
81+
declare spir_func void @bar2(ptr addrspace(1), <3 x i32>)
82+
83+
!opencl.ocl.version = !{!7}
84+
!7 = !{i32 2, i32 0}

0 commit comments

Comments
 (0)