Debian Codegraph @

llvm/test/CodeGen/SPIRV/pointers/fun-with-aggregate-arg-in-const-init.ll

raw
1 ; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s
2 ; TODO: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - -filetype=obj | spirv-val %}
3
4 ; CHECK: OpCapability Kernel
5 ; CHECK-DAG: OpCapability FunctionPointersINTEL
6 ; CHECK-DAG: OpExtension "SPV_INTEL_function_pointers"
7 ; CHECK-DAG: OpName %[[#fArray:]] "array"
8 ; CHECK-DAG: OpName %[[#fStruct:]] "struct"
9
10 ; CHECK-DAG: %[[#Int8Ty:]] = OpTypeInt 8 0
11 ; CHECK: %[[#GlobalInt8PtrTy:]] = OpTypePointer CrossWorkgroup %[[#Int8Ty]]
12 ; CHECK: %[[#VoidTy:]] = OpTypeVoid
13 ; CHECK: %[[#TestFnTy:]] = OpTypeFunction %[[#VoidTy]] %[[#GlobalInt8PtrTy]]
14 ; CHECK: %[[#F16Ty:]] = OpTypeFloat 16
15 ; CHECK: %[[#t_halfTy:]] = OpTypeStruct %[[#F16Ty]]
16 ; CHECK: %[[#FnTy:]] = OpTypeFunction %[[#t_halfTy]] %[[#GlobalInt8PtrTy]] %[[#t_halfTy]]
17 ; CHECK: %[[#IntelFnPtrTy:]] = OpTypePointer CodeSectionINTEL %[[#FnTy]]
18 ; CHECK: %[[#Int8PtrTy:]] = OpTypePointer Function %[[#Int8Ty]]
19 ; CHECK: %[[#Int32Ty:]] = OpTypeInt 32 0
20 ; CHECK: %[[#I32Const3:]] = OpConstant %[[#Int32Ty]] 3
21 ; CHECK: %[[#FnArrTy:]] = OpTypeArray %[[#Int8PtrTy]] %[[#I32Const3]]
22 ; CHECK: %[[#GlobalFnArrPtrTy:]] = OpTypePointer CrossWorkgroup %[[#FnArrTy]]
23 ; CHECK: %[[#GlobalFnPtrTy:]] = OpTypePointer CrossWorkgroup %[[#FnTy]]
24 ; CHECK: %[[#FnPtrTy:]] = OpTypePointer Function %[[#FnTy]]
25 ; CHECK: %[[#StructWithPfnTy:]] = OpTypeStruct %[[#FnPtrTy]] %[[#FnPtrTy]] %[[#FnPtrTy]]
26 ; CHECK: %[[#ArrayOfPfnTy:]] = OpTypeArray %[[#FnPtrTy]] %[[#I32Const3]]
27 ; CHECK: %[[#Int64Ty:]] = OpTypeInt 64 0
28 ; CHECK: %[[#GlobalStructWithPfnPtrTy:]] = OpTypePointer CrossWorkgroup %[[#StructWithPfnTy]]
29 ; CHECK: %[[#GlobalArrOfPfnPtrTy:]] = OpTypePointer CrossWorkgroup %[[#ArrayOfPfnTy]]
30 ; CHECK: %[[#I64Const2:]] = OpConstant %[[#Int64Ty]] 2
31 ; CHECK: %[[#I64Const1:]] = OpConstant %[[#Int64Ty]] 1
32 ; CHECK: %[[#I64Const0:]] = OpConstantNull %[[#Int64Ty]]
33 ; CHECK: %[[#f0Pfn:]] = OpConstantFunctionPointerINTEL %[[#IntelFnPtrTy]] %28
34 ; CHECK: %[[#f1Pfn:]] = OpConstantFunctionPointerINTEL %[[#IntelFnPtrTy]] %32
35 ; CHECK: %[[#f2Pfn:]] = OpConstantFunctionPointerINTEL %[[#IntelFnPtrTy]] %36
36 ; CHECK: %[[#f0Cast:]] = OpSpecConstantOp %[[#FnPtrTy]] Bitcast %[[#f0Pfn]]
37 ; CHECK: %[[#f1Cast:]] = OpSpecConstantOp %[[#FnPtrTy]] Bitcast %[[#f1Pfn]]
38 ; CHECK: %[[#f2Cast:]] = OpSpecConstantOp %[[#FnPtrTy]] Bitcast %[[#f2Pfn]]
39 ; CHECK: %[[#fnptrTy:]] = OpConstantComposite %[[#ArrayOfPfnTy]] %[[#f0Cast]] %[[#f1Cast]] %[[#f2Cast]]
40 ; CHECK: %[[#fnptr:]] = OpVariable %[[#GlobalArrOfPfnPtrTy]] CrossWorkgroup %[[#fnptrTy]]
41 ; CHECK: %[[#fnstructTy:]] = OpConstantComposite %[[#StructWithPfnTy]] %[[#f0Cast]] %[[#f1Cast]] %[[#f2Cast]]
42 ; CHECK: %[[#fnstruct:]] = OpVariable %[[#GlobalStructWithPfnPtrTy:]] CrossWorkgroup %[[#fnstructTy]]
43 ; CHECK-DAG: %[[#GlobalInt8PtrPtrTy:]] = OpTypePointer CrossWorkgroup %[[#Int8PtrTy]]
44 ; CHECK: %[[#StructWithPtrTy:]] = OpTypeStruct %[[#Int8PtrTy]] %[[#Int8PtrTy]] %[[#Int8PtrTy]]
45 ; CHECK: %[[#GlobalStructWithPtrPtrTy:]] = OpTypePointer CrossWorkgroup %[[#StructWithPtrTy]]
46 ; CHECK: %[[#I32Const2:]] = OpConstant %[[#Int32Ty]] 2
47 ; CHECK: %[[#I32Const1:]] = OpConstant %[[#Int32Ty]] 1
48 ; CHECK: %[[#I32Const0:]] = OpConstantNull %[[#Int32Ty]]
49 ; CHECK: %[[#GlobalFnPtrPtrTy:]] = OpTypePointer CrossWorkgroup %[[#FnPtrTy]]
50 %t_half = type { half }
51 %struct.anon = type { ptr, ptr, ptr }
52
53 declare spir_func %t_half @f0(ptr addrspace(1) %a, %t_half %b)
54 declare spir_func %t_half @f1(ptr addrspace(1) %a, %t_half %b)
55 declare spir_func %t_half @f2(ptr addrspace(1) %a, %t_half %b)
56
57 @fnptr = addrspace(1) constant [3 x ptr] [ptr @f0, ptr @f1, ptr @f2]
58 @fnstruct = addrspace(1) constant %struct.anon { ptr @f0, ptr @f1, ptr @f2 }, align 8
59
60 ; CHECK-DAG: %[[#fArray]] = OpFunction %[[#VoidTy]] None %[[#TestFnTy]]
61 ; CHECK-DAG: %[[#fnptrCast:]] = OpBitcast %[[#GlobalFnArrPtrTy]] %[[#fnptr]]
62 ; CHECK: %[[#f0GEP:]] = OpInBoundsPtrAccessChain %[[#GlobalFnArrPtrTy]] %[[#fnptrCast]] %[[#I64Const0]]
63 ; CHECK: %[[#f0GEPCast:]] = OpBitcast %[[#GlobalFnPtrTy]] %[[#f0GEP]]
64 ; CHECK: %[[#f1GEP:]] = OpInBoundsPtrAccessChain %[[#GlobalFnArrPtrTy]] %[[#fnptrCast]] %[[#I64Const1]]
65 ; CHECK: %[[#f1GEPCast:]] = OpBitcast %[[#GlobalFnPtrTy]] %[[#f1GEP]]
66 ; CHECK: %[[#f2GEP:]] = OpInBoundsPtrAccessChain %[[#GlobalFnArrPtrTy]] %[[#fnptrCast]] %[[#I64Const2]]
67 ; CHECK: %[[#f2GEPCast:]] = OpBitcast %[[#GlobalFnPtrTy]] %[[#f2GEP]]
68 ; CHECK: %{{.*}} = OpFunctionPointerCallINTEL %[[#t_halfTy]] %[[#f0GEPCast]]
69 ; CHECK: %{{.*}} = OpFunctionPointerCallINTEL %[[#t_halfTy]] %[[#f1GEPCast]]
70 ; CHECK: %{{.*}} = OpFunctionPointerCallINTEL %[[#t_halfTy]] %[[#f2GEPCast]]
71 define spir_func void @array(ptr addrspace(1) %p) {
72 entry:
73 %f = getelementptr inbounds [3 x ptr], ptr addrspace(1) @fnptr, i64 0
74 %g = getelementptr inbounds [3 x ptr], ptr addrspace(1) @fnptr, i64 1
75 %h = getelementptr inbounds [3 x ptr], ptr addrspace(1) @fnptr, i64 2
76 %0 = call spir_func addrspace(1) %t_half %f(ptr addrspace(1) %p, %t_half poison)
77 %1 = call spir_func addrspace(1) %t_half %g(ptr addrspace(1) %p, %t_half %0)
78 %2 = call spir_func addrspace(1) %t_half %h(ptr addrspace(1) %p, %t_half %1)
79
80 ret void
81 }
82
83 ; CHECK-DAG: %[[#fStruct]] = OpFunction %[[#VoidTy]] None %[[#TestFnTy]]
84 ; CHECK-DAG: %[[#fnStructCast0:]] = OpBitcast %[[#GlobalInt8PtrPtrTy]] %[[#fnstruct]]
85 ; CHECK: %[[#fnStructCast1:]] = OpBitcast %[[#GlobalFnPtrPtrTy]] %[[#fnStructCast0]]
86 ; CHECK: %[[#f0Load:]] = OpLoad %[[#FnPtrTy]] %[[#fnStructCast1]]
87 ; CHECK: %[[#fnStructCast2:]] = OpBitcast %[[#GlobalStructWithPtrPtrTy]] %[[#fnstruct]]
88 ; CHECK: %[[#f1GEP:]] = OpInBoundsPtrAccessChain %[[#GlobalInt8PtrPtrTy]] %[[#fnStructCast2]] %[[#I32Const0]] %[[#I32Const1]]
89 ; CHECK: %[[#f1GEPCast:]] = OpBitcast %[[#GlobalFnPtrPtrTy]] %[[#f1GEP]]
90 ; CHECK: %[[#f1Load:]] = OpLoad %[[#FnPtrTy]] %[[#f1GEPCast]]
91 ; CHECK: %[[#f2GEP:]] = OpInBoundsPtrAccessChain %[[#GlobalInt8PtrPtrTy]] %[[#fnStructCast2]] %[[#I32Const0]] %[[#I32Const2]]
92 ; CHECK: %[[#f2GEPCast:]] = OpBitcast %[[#GlobalFnPtrPtrTy]] %[[#f2GEP]]
93 ; CHECK: %[[#f2Load:]] = OpLoad %[[#FnPtrTy]] %[[#f2GEPCast]]
94 ; CHECK: %{{.*}} = OpFunctionPointerCallINTEL %[[#t_halfTy]] %[[#f0Load]]
95 ; CHECK: %{{.*}} = OpFunctionPointerCallINTEL %[[#t_halfTy]] %[[#f1Load]]
96 ; CHECK: %{{.*}} = OpFunctionPointerCallINTEL %[[#t_halfTy]] %[[#f2Load]]
97 define spir_func void @struct(ptr addrspace(1) %p) {
98 entry:
99 %f = load ptr, ptr addrspace(1) @fnstruct
100 %g = load ptr, ptr addrspace(1) getelementptr inbounds (%struct.anon, ptr addrspace(1) @fnstruct, i32 0, i32 1)
101 %h = load ptr, ptr addrspace(1) getelementptr inbounds (%struct.anon, ptr addrspace(1) @fnstruct, i32 0, i32 2)
102 %0 = call spir_func noundef %t_half %f(ptr addrspace(1) %p, %t_half poison)
103 %1 = call spir_func noundef %t_half %g(ptr addrspace(1) %p, %t_half %0)
104 %2 = call spir_func noundef %t_half %h(ptr addrspace(1) %p, %t_half %1)
105
106 ret void
107 }