Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/test/extensions/INTEL/SPV_INTEL_function_pointers/function-pointer.ll

raw
1 ; RUN: llvm-as -opaque-pointers=0 %s -o %t.bc
2 ; RUN: llvm-spirv %t.bc -opaque-pointers=0 -spirv-text --spirv-ext=+SPV_INTEL_function_pointers -o %t.spt
3 ; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
4 ; RUN: llvm-spirv %t.bc -opaque-pointers=0 --spirv-ext=+SPV_INTEL_function_pointers -o %t.spv
5 ; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.r.bc
6 ; RUN: llvm-dis %t.r.bc -o %t.r.ll
7 ; RUN: FileCheck < %t.r.ll %s --check-prefix=CHECK-LLVM
8 ;
9 ; Generated from:
10 ; int foo(int arg) {
11 ; return arg + 10;
12 ; }
13 ;
14 ; void __kernel test(__global int *data, int input) {
15 ; int (__constant *fp)(int) = &foo;
16 ;
17 ; *data = fp(input);
18 ; }
19 ;
20 ; CHECK-SPIRV: Capability FunctionPointersINTEL
21 ; CHECK-SPIRV: Extension "SPV_INTEL_function_pointers"
22 ; CHECK-SPIRV: Name [[KERNEL_ID:[0-9]+]] "test"
23 ; CHECK-SPIRV: TypeInt [[TYPE_INT_ID:[0-9]+]]
24 ; CHECK-SPIRV: TypeFunction [[FOO_TYPE_ID:[0-9]+]] [[TYPE_INT_ID]] [[TYPE_INT_ID]]
25 ; CHECK-SPIRV: TypePointer [[FOO_PTR_ID:[0-9]+]] {{[0-9]+}} [[FOO_TYPE_ID]]
26 ; CHECK-SPIRV: TypePointer [[FOO_PTR_ALLOCA_ID:[0-9]+]] 7 [[FOO_PTR_ID]]
27 ; CHECK-SPIRV: ConstantFunctionPointerINTEL [[FOO_PTR_ID]] [[FOO_PTR:[0-9]+]] [[FOO_ID:[0-9]+]]
28 ;
29 ; CHECK-SPIRV: Function {{[0-9]+}} [[FOO_ID]] {{[0-9]+}} [[FOO_TYPE_ID]]
30 ; CHECK-SPIRV: Function {{[0-9]+}} [[KERNEL_ID]]
31 ; CHECK-SPIRV: Variable [[FOO_PTR_ALLOCA_ID]] [[FOO_PTR_ALLOCA:[0-9]+]]
32 ; CHECK-SPIRV: Store [[FOO_PTR_ALLOCA]] [[FOO_PTR]]
33 ; CHECK-SPIRV: Load [[FOO_PTR_ID]] [[LOADED_FOO_PTR:[0-9]+]] [[FOO_PTR_ALLOCA]]
34 ; CHECK-SPIRV: FunctionPointerCallINTEL 2 {{[0-9]+}} [[LOADED_FOO_PTR]]
35 ;
36 ; CHECK-LLVM: define spir_kernel void @test
37 ; CHECK-LLVM: %fp = alloca ptr
38 ; CHECK-LLVM: store ptr @foo, ptr %fp
39 ; CHECK-LLVM: %0 = load ptr, ptr %fp
40 ; CHECK-LLVM: %call = call spir_func i32 %0(i32 %1)
41
42 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
43 target triple = "spir64-unknown-unknown"
44
45 ; Function Attrs: convergent noinline nounwind optnone
46 define spir_func i32 @foo(i32 %arg) #0 {
47 entry:
48 %arg.addr = alloca i32, align 4
49 store i32 %arg, i32* %arg.addr, align 4
50 %0 = load i32, i32* %arg.addr, align 4
51 %add = add nsw i32 %0, 10
52 ret i32 %add
53 }
54
55 ; Function Attrs: convergent noinline nounwind optnone
56 define spir_kernel void @test(i32 addrspace(1)* %data, i32 %input) #1 !kernel_arg_addr_space !1 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
57 entry:
58 %data.addr = alloca i32 addrspace(1)*, align 8
59 %input.addr = alloca i32, align 4
60 %fp = alloca i32 (i32)*, align 8
61 store i32 addrspace(1)* %data, i32 addrspace(1)** %data.addr, align 8
62 store i32 %input, i32* %input.addr, align 4
63 store i32 (i32)* @foo, i32 (i32)** %fp, align 8
64 %0 = load i32 (i32)*, i32 (i32)** %fp, align 8
65 %1 = load i32, i32* %input.addr, align 4
66 %call = call spir_func i32 %0(i32 %1) #2
67 %2 = load i32 addrspace(1)*, i32 addrspace(1)** %data.addr, align 8
68 store i32 %call, i32 addrspace(1)* %2, align 4
69 ret void
70 }
71
72 attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
73 attributes #1 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
74 attributes #2 = { convergent }
75
76 !llvm.module.flags = !{!0}
77 !opencl.ocl.version = !{!1}
78 !opencl.spir.version = !{!2}
79 !opencl.used.extensions = !{!3}
80 !opencl.used.optional.core.features = !{!3}
81 !opencl.compiler.options = !{!3}
82 !llvm.ident = !{!4}
83
84 !0 = !{i32 1, !"wchar_size", i32 4}
85 !1 = !{i32 1, i32 0}
86 !2 = !{i32 1, i32 2}
87 !3 = !{}
88 !4 = !{!"clang version 7.0.0 "}
89 !5 = !{!"none", !"none"}
90 !6 = !{!"int*", !"int"}
91 !7 = !{!"", !""}
92