Clang Project

clang_source_code/test/CodeGen/arm-aapcs-vfp.c
1// REQUIRES: arm-registered-target
2// REQUIRES: aarch64-registered-target
3// RUN: %clang_cc1 -triple thumbv7-apple-darwin9 \
4// RUN:   -target-abi aapcs \
5// RUN:   -target-cpu cortex-a8 \
6// RUN:   -mfloat-abi hard \
7// RUN:   -ffreestanding \
8// RUN:   -emit-llvm -w -o - %s | FileCheck %s
9
10// RUN: %clang_cc1 -triple armv7-unknown-nacl-gnueabi \
11// RUN:  -target-cpu cortex-a8 \
12// RUN:  -mfloat-abi hard \
13// RUN:  -ffreestanding \
14// RUN:  -emit-llvm -w -o - %s | FileCheck %s
15
16// RUN: %clang_cc1 -triple arm64-apple-darwin9 -target-feature +neon \
17// RUN:   -ffreestanding \
18// RUN:   -emit-llvm -w -o - %s | FileCheck -check-prefix=CHECK64 %s
19
20#include <arm_neon.h>
21
22struct homogeneous_struct {
23  float f[2];
24  float f3;
25  float f4;
26};
27// CHECK: define arm_aapcs_vfpcc %struct.homogeneous_struct @test_struct(%struct.homogeneous_struct %{{.*}})
28// CHECK64: define %struct.homogeneous_struct @test_struct([4 x float] %{{.*}})
29extern struct homogeneous_struct struct_callee(struct homogeneous_struct);
30struct homogeneous_struct test_struct(struct homogeneous_struct arg) {
31  return struct_callee(arg);
32}
33
34// CHECK: define arm_aapcs_vfpcc void @test_struct_variadic(%struct.homogeneous_struct* {{.*}}, ...)
35struct homogeneous_struct test_struct_variadic(struct homogeneous_struct arg, ...) {
36  return struct_callee(arg);
37}
38
39struct nested_array {
40  double d[4];
41};
42// CHECK: define arm_aapcs_vfpcc void @test_array(%struct.nested_array %{{.*}})
43// CHECK64: define void @test_array([4 x double] %{{.*}})
44extern void array_callee(struct nested_array);
45void test_array(struct nested_array arg) {
46  array_callee(arg);
47}
48
49extern void complex_callee(__complex__ double);
50// CHECK: define arm_aapcs_vfpcc void @test_complex({ double, double } %{{.*}})
51// CHECK64: define void @test_complex([2 x double] %cd.coerce)
52void test_complex(__complex__ double cd) {
53  complex_callee(cd);
54}
55
56// Long double is the same as double on AAPCS, it should be homogeneous.
57extern void complex_long_callee(__complex__ long double);
58// CHECK: define arm_aapcs_vfpcc void @test_complex_long({ double, double } %{{.*}})
59void test_complex_long(__complex__ long double cd) {
60  complex_callee(cd);
61}
62
63// Structs with more than 4 elements of the base type are not treated
64// as homogeneous aggregates.  Test that.
65
66struct big_struct {
67  float f1;
68  float f[2];
69  float f3;
70  float f4;
71};
72// CHECK: define arm_aapcs_vfpcc void @test_big([5 x i32] %{{.*}})
73// CHECK64: define void @test_big(%struct.big_struct* %{{.*}})
74// CHECK64: call void @llvm.memcpy
75// CHECK64: call void @big_callee(%struct.big_struct*
76extern void big_callee(struct big_struct);
77void test_big(struct big_struct arg) {
78  big_callee(arg);
79}
80
81// Make sure that aggregates with multiple base types are not treated as
82// homogeneous aggregates.
83
84struct heterogeneous_struct {
85  float f1;
86  int i2;
87};
88// CHECK: define arm_aapcs_vfpcc void @test_hetero([2 x i32] %{{.*}})
89// CHECK64: define void @test_hetero(i64 %{{.*}})
90extern void hetero_callee(struct heterogeneous_struct);
91void test_hetero(struct heterogeneous_struct arg) {
92  hetero_callee(arg);
93}
94
95// Neon multi-vector types are homogeneous aggregates.
96// CHECK: define arm_aapcs_vfpcc <16 x i8> @f0(%struct.int8x16x4_t %{{.*}})
97// CHECK64: define <16 x i8> @f0([4 x <16 x i8>] %{{.*}})
98int8x16_t f0(int8x16x4_t v4) {
99  return vaddq_s8(v4.val[0], v4.val[3]);
100}
101
102// ...and it doesn't matter whether the vectors are exactly the same, as long
103// as they have the same size.
104
105struct neon_struct {
106  int8x8x2_t v12;
107  int32x2_t v3;
108  int16x4_t v4;
109};
110// CHECK: define arm_aapcs_vfpcc void @test_neon(%struct.neon_struct %{{.*}})
111// CHECK64: define void @test_neon([4 x <8 x i8>] %{{.*}})
112extern void neon_callee(struct neon_struct);
113void test_neon(struct neon_struct arg) {
114  neon_callee(arg);
115}
116
117// CHECK-LABEL: define arm_aapcs_vfpcc void @f33(%struct.s33* byval align 4 %s)
118struct s33 { char buf[32*32]; };
119void f33(struct s33 s) { }
120
121typedef struct { long long x; int y; } struct_long_long_int;
122// CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_1(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, i64 %k, i32 %l)
123void test_vfp_stack_gpr_split_1(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, long long k, int l) {}
124
125// CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_2(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, [2 x i64] %k.coerce)
126void test_vfp_stack_gpr_split_2(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, struct_long_long_int k) {}
127
128// CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_3(%struct.struct_long_long_int* noalias sret %agg.result, double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, [2 x i64] %k.coerce)
129struct_long_long_int test_vfp_stack_gpr_split_3(double a, double b, double c, double d, double e, double f, double g, double h, double i, struct_long_long_int k) {}
130
131typedef struct { int a; int b:4; int c; } struct_int_bitfield_int;
132// CHECK: define arm_aapcs_vfpcc void @test_test_vfp_stack_gpr_split_bitfield(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, i32 %k, [3 x i32] %l.coerce)
133void test_test_vfp_stack_gpr_split_bitfield(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, int k, struct_int_bitfield_int l) {}
134
135// Note: this struct requires internal padding
136typedef struct { int x; long long y; } struct_int_long_long;
137// CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_4(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, [2 x i64] %k.coerce)
138void test_vfp_stack_gpr_split_4(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, struct_int_long_long k) {}
139
140// This very large struct (passed byval) uses up the GPRs, so no padding is needed
141typedef struct { int x[17]; } struct_seventeen_ints;
142typedef struct { int x[4]; } struct_four_ints;
143// CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_5(%struct.struct_seventeen_ints* byval align 4 %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, double %j, [4 x i32] %k.coerce)
144void test_vfp_stack_gpr_split_5(struct_seventeen_ints a, double b, double c, double d, double e, double f, double g, double h, double i, double j, struct_four_ints k) {}
145
146// Here, parameter k would need padding to prevent it from being split, but it
147// is passed ByVal (due to being > 64 bytes), so the backend handles this instead.
148void test_vfp_stack_gpr_split_6(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, struct_seventeen_ints k) {}
149// CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_6(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, %struct.struct_seventeen_ints* byval align 4 %k)
150