Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/test/extensions/INTEL/SPV_INTEL_function_pointers/const-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-ext=+SPV_INTEL_function_pointers -o %t.spv
3 ; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
4 ; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.r.bc
5 ; RUN: llvm-dis %t.r.bc -o %t.r.ll
6 ; RUN: FileCheck < %t.r.ll %s --check-prefix=CHECK-LLVM
7
8 ; CHECK-SPIRV: Capability FunctionPointersINTEL
9 ; CHECK-SPIRV: Extension "SPV_INTEL_function_pointers"
10 ; CHECK-SPIRV: Name [[F1Name:[0-9]+]] "f1"
11 ; CHECK-SPIRV: Name [[F2Name:[0-9]+]] "f2"
12 ; CHECK-SPIRV-DAG: TypeInt [[Int32:[0-9]+]] 32
13 ; CHECK-SPIRV-DAG: TypeInt [[Int64:[0-9]+]] 64
14 ; CHECK-SPIRV-DAG: Constant [[Int32]] [[XArg:[0-9]+]] 32
15 ; CHECK-SPIRV-DAG: Constant [[Int32]] [[YArg:[0-9]+]] 2
16
17 ; CHECK-SPIRV: ConstantFunctionPointerINTEL {{[0-9]+}} [[F1:[0-9]+]] [[F1Name]]
18 ; CHECK-SPIRV: ConstantFunctionPointerINTEL {{[0-9]+}} [[F2:[0-9]+]] [[F2Name]]
19 ; CHECK-SPIRV: ConstantComposite {{[0-9]+}} [[ConstComp:[0-9]+]] [[F1]] [[F2]]
20 ; CHECK-SPIRV: Variable {{[0-9]+}} [[Var:[0-9]+]] {{[0-9]+}} [[ConstComp]]
21
22 ; CHECK-SPIRV: InBoundsPtrAccessChain {{[0-9]+}} [[GEP:[0-9]+]] [[Var]] {{[0-9]+}} {{[0-9]+}}
23 ; CHECK-SPIRV: Load {{[0-9]+}} [[FuncPtr:[0-9]+]] [[GEP]]
24 ; CHECK-SPIRV: FunctionPointerCallINTEL [[Int32]] {{[0-9]+}} [[FuncPtr]] [[XArg]] [[YArg]]
25
26 ; CHECK-LLVM: @__const.main.funcs = internal constant [2 x ptr] [ptr @f1, ptr @f2], align 16
27 ; CHECK-LLVM: %[[Idx:[a-z0-9]+]] = getelementptr inbounds [2 x ptr], ptr @__const.main.funcs, i64 0, i64 %{{[a-z0-9]+}}
28 ; CHECK-LLVM: %[[FuncPtr:[a-z0-9]+]] = load ptr, ptr %[[Idx]], align 8
29 ; CHECK-LLVM: %{{[a-z0-9]+}} = call spir_func i32 %[[FuncPtr]](i32 32, i32 2)
30
31 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
32 target triple = "spir-unknown-unknown"
33
34 @__const.main.funcs = private unnamed_addr constant [2 x i32 (i32, i32)*] [i32 (i32, i32)* @f1, i32 (i32, i32)* @f2], align 16
35
36 ; Function Attrs: norecurse nounwind readnone uwtable
37 define dso_local i32 @f1(i32 %a, i32 %b) #0 {
38 entry:
39 %add = add nsw i32 %b, %a
40 ret i32 %add
41 }
42
43 ; Function Attrs: norecurse nounwind readnone uwtable
44 define dso_local i32 @f2(i32 %a, i32 %b) #0 {
45 entry:
46 %sub = sub nsw i32 %a, %b
47 ret i32 %sub
48 }
49
50 ; Function Attrs: nounwind uwtable
51 define dso_local i32 @main() local_unnamed_addr #1 {
52 entry:
53 %call = tail call i32 @rand() #3
54 %rem = srem i32 %call, 2
55 %idxprom = sext i32 %rem to i64
56 %arrayidx = getelementptr inbounds [2 x i32 (i32, i32)*], [2 x i32 (i32, i32)*]* @__const.main.funcs, i64 0, i64 %idxprom
57 %0 = load i32 (i32, i32)*, i32 (i32, i32)** %arrayidx, align 8
58 %call1 = tail call i32 %0(i32 32, i32 2) #3
59 ret i32 %call1
60 }
61
62 ; Function Attrs: nounwind
63 declare dso_local i32 @rand() local_unnamed_addr #2
64
65 attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
66 attributes #1 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
67 attributes #2 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }