• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -O0 -triple amdgcn -emit-llvm %s -o - | FileCheck %s
2 
3 class A {
4 public:
5   int x;
A()6   A():x(0) {}
~A()7   ~A() {}
8 };
9 
10 class B {
11 int x[100];
12 };
13 
14 A g_a;
15 B g_b;
16 
17 void func_with_ref_arg(A &a);
18 void func_with_ref_arg(B &b);
19 
20 // CHECK-LABEL: define void @_Z22func_with_indirect_arg1A(%class.A addrspace(5)* %a)
21 // CHECK:  %p = alloca %class.A*, align 8, addrspace(5)
22 // CHECK:  %[[r1:.+]] = addrspacecast %class.A* addrspace(5)* %p to %class.A**
23 // CHECK:  %[[r0:.+]] = addrspacecast %class.A addrspace(5)* %a to %class.A*
24 // CHECK:  store %class.A* %[[r0]], %class.A** %[[r1]], align 8
func_with_indirect_arg(A a)25 void func_with_indirect_arg(A a) {
26   A *p = &a;
27 }
28 
29 // CHECK-LABEL: define void @_Z22test_indirect_arg_autov()
30 // CHECK:  %a = alloca %class.A, align 4, addrspace(5)
31 // CHECK:  %[[r0:.+]] = addrspacecast %class.A addrspace(5)* %a to %class.A*
32 // CHECK:  %agg.tmp = alloca %class.A, align 4, addrspace(5)
33 // CHECK:  %[[r1:.+]] = addrspacecast %class.A addrspace(5)* %agg.tmp to %class.A*
34 // CHECK:  call void @_ZN1AC1Ev(%class.A* {{[^,]*}} %[[r0]])
35 // CHECK:  call void @llvm.memcpy.p0i8.p0i8.i64
36 // CHECK:  %[[r4:.+]] = addrspacecast %class.A* %[[r1]] to %class.A addrspace(5)*
37 // CHECK:  call void @_Z22func_with_indirect_arg1A(%class.A addrspace(5)* %[[r4]])
38 // CHECK:  call void @_ZN1AD1Ev(%class.A* {{[^,]*}} %[[r1]])
39 // CHECK:  call void @_Z17func_with_ref_argR1A(%class.A* nonnull align 4 dereferenceable(4) %[[r0]])
40 // CHECK:  call void @_ZN1AD1Ev(%class.A* {{[^,]*}} %[[r0]])
test_indirect_arg_auto()41 void test_indirect_arg_auto() {
42   A a;
43   func_with_indirect_arg(a);
44   func_with_ref_arg(a);
45 }
46 
47 // CHECK: define void @_Z24test_indirect_arg_globalv()
48 // CHECK:  %agg.tmp = alloca %class.A, align 4, addrspace(5)
49 // CHECK:  %[[r0:.+]] = addrspacecast %class.A addrspace(5)* %agg.tmp to %class.A*
50 // CHECK:  call void @llvm.memcpy.p0i8.p0i8.i64
51 // CHECK:  %[[r2:.+]] = addrspacecast %class.A* %[[r0]] to %class.A addrspace(5)*
52 // CHECK:  call void @_Z22func_with_indirect_arg1A(%class.A addrspace(5)* %[[r2]])
53 // CHECK:  call void @_ZN1AD1Ev(%class.A* {{[^,]*}} %[[r0]])
54 // CHECK:  call void @_Z17func_with_ref_argR1A(%class.A* nonnull align 4 dereferenceable(4) addrspacecast (%class.A addrspace(1)* @g_a to %class.A*))
test_indirect_arg_global()55 void test_indirect_arg_global() {
56   func_with_indirect_arg(g_a);
57   func_with_ref_arg(g_a);
58 }
59 
60 // CHECK-LABEL: define void @_Z19func_with_byval_arg1B(%class.B addrspace(5)* byval(%class.B) align 4 %b)
61 // CHECK:  %p = alloca %class.B*, align 8, addrspace(5)
62 // CHECK:  %[[r1:.+]] = addrspacecast %class.B* addrspace(5)* %p to %class.B**
63 // CHECK:  %[[r0:.+]] = addrspacecast %class.B addrspace(5)* %b to %class.B*
64 // CHECK:  store %class.B* %[[r0]], %class.B** %[[r1]], align 8
func_with_byval_arg(B b)65 void func_with_byval_arg(B b) {
66   B *p = &b;
67 }
68 
69 // CHECK-LABEL: define void @_Z19test_byval_arg_autov()
70 // CHECK:  %b = alloca %class.B, align 4, addrspace(5)
71 // CHECK:  %[[r0:.+]] = addrspacecast %class.B addrspace(5)* %b to %class.B*
72 // CHECK:  %agg.tmp = alloca %class.B, align 4, addrspace(5)
73 // CHECK:  %[[r1:.+]] = addrspacecast %class.B addrspace(5)* %agg.tmp to %class.B*
74 // CHECK:  call void @llvm.memcpy.p0i8.p0i8.i64
75 // CHECK:  %[[r4:.+]] = addrspacecast %class.B* %[[r1]] to %class.B addrspace(5)*
76 // CHECK:  call void @_Z19func_with_byval_arg1B(%class.B addrspace(5)* byval(%class.B) align 4 %[[r4]])
77 // CHECK:  call void @_Z17func_with_ref_argR1B(%class.B* nonnull align 4 dereferenceable(400) %[[r0]])
test_byval_arg_auto()78 void test_byval_arg_auto() {
79   B b;
80   func_with_byval_arg(b);
81   func_with_ref_arg(b);
82 }
83 
84 // CHECK-LABEL: define void @_Z21test_byval_arg_globalv()
85 // CHECK:  %agg.tmp = alloca %class.B, align 4, addrspace(5)
86 // CHECK:  %[[r0:.+]] = addrspacecast %class.B addrspace(5)* %agg.tmp to %class.B*
87 // CHECK:  call void @llvm.memcpy.p0i8.p0i8.i64
88 // CHECK:  %[[r2:.+]] = addrspacecast %class.B* %[[r0]] to %class.B addrspace(5)*
89 // CHECK:  call void @_Z19func_with_byval_arg1B(%class.B addrspace(5)* byval(%class.B) align 4 %[[r2]])
90 // CHECK:  call void @_Z17func_with_ref_argR1B(%class.B* nonnull align 4 dereferenceable(400) addrspacecast (%class.B addrspace(1)* @g_b to %class.B*))
test_byval_arg_global()91 void test_byval_arg_global() {
92   func_with_byval_arg(g_b);
93   func_with_ref_arg(g_b);
94 }
95