Home | History | Annotate | Download | only in CodeGen
      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 #ifdef __arm64__
     21 #include <arm_neon.h>
     22 #else
     23 #include <arm_neon.h>
     24 #endif
     25 
     26 struct homogeneous_struct {
     27   float f[2];
     28   float f3;
     29   float f4;
     30 };
     31 // CHECK: define arm_aapcs_vfpcc %struct.homogeneous_struct @test_struct(%struct.homogeneous_struct %{{.*}})
     32 // CHECK64: define %struct.homogeneous_struct @test_struct([4 x float] %{{.*}})
     33 extern struct homogeneous_struct struct_callee(struct homogeneous_struct);
     34 struct homogeneous_struct test_struct(struct homogeneous_struct arg) {
     35   return struct_callee(arg);
     36 }
     37 
     38 // CHECK: define arm_aapcs_vfpcc void @test_struct_variadic(%struct.homogeneous_struct* {{.*}}, ...)
     39 struct homogeneous_struct test_struct_variadic(struct homogeneous_struct arg, ...) {
     40   return struct_callee(arg);
     41 }
     42 
     43 struct nested_array {
     44   double d[4];
     45 };
     46 // CHECK: define arm_aapcs_vfpcc void @test_array(%struct.nested_array %{{.*}})
     47 // CHECK64: define void @test_array([4 x double] %{{.*}})
     48 extern void array_callee(struct nested_array);
     49 void test_array(struct nested_array arg) {
     50   array_callee(arg);
     51 }
     52 
     53 extern void complex_callee(__complex__ double);
     54 // CHECK: define arm_aapcs_vfpcc void @test_complex({ double, double } %{{.*}})
     55 // CHECK64: define void @test_complex([2 x double] %cd.coerce)
     56 void test_complex(__complex__ double cd) {
     57   complex_callee(cd);
     58 }
     59 
     60 // Long double is the same as double on AAPCS, it should be homogeneous.
     61 extern void complex_long_callee(__complex__ long double);
     62 // CHECK: define arm_aapcs_vfpcc void @test_complex_long({ double, double } %{{.*}})
     63 void test_complex_long(__complex__ long double cd) {
     64   complex_callee(cd);
     65 }
     66 
     67 // Structs with more than 4 elements of the base type are not treated
     68 // as homogeneous aggregates.  Test that.
     69 
     70 struct big_struct {
     71   float f1;
     72   float f[2];
     73   float f3;
     74   float f4;
     75 };
     76 // CHECK: define arm_aapcs_vfpcc void @test_big([5 x i32] %{{.*}})
     77 // CHECK64: define void @test_big(%struct.big_struct* %{{.*}})
     78 // CHECK64: call void @llvm.memcpy
     79 // CHECK64: call void @big_callee(%struct.big_struct*
     80 extern void big_callee(struct big_struct);
     81 void test_big(struct big_struct arg) {
     82   big_callee(arg);
     83 }
     84 
     85 // Make sure that aggregates with multiple base types are not treated as
     86 // homogeneous aggregates.
     87 
     88 struct heterogeneous_struct {
     89   float f1;
     90   int i2;
     91 };
     92 // CHECK: define arm_aapcs_vfpcc void @test_hetero([2 x i32] %{{.*}})
     93 // CHECK64: define void @test_hetero(i64 %{{.*}})
     94 extern void hetero_callee(struct heterogeneous_struct);
     95 void test_hetero(struct heterogeneous_struct arg) {
     96   hetero_callee(arg);
     97 }
     98 
     99 // Neon multi-vector types are homogeneous aggregates.
    100 // CHECK: define arm_aapcs_vfpcc <16 x i8> @f0(%struct.int8x16x4_t %{{.*}})
    101 // CHECK64: define <16 x i8> @f0([4 x <16 x i8>] %{{.*}})
    102 int8x16_t f0(int8x16x4_t v4) {
    103   return vaddq_s8(v4.val[0], v4.val[3]);
    104 }
    105 
    106 // ...and it doesn't matter whether the vectors are exactly the same, as long
    107 // as they have the same size.
    108 
    109 struct neon_struct {
    110   int8x8x2_t v12;
    111   int32x2_t v3;
    112   int16x4_t v4;
    113 };
    114 // CHECK: define arm_aapcs_vfpcc void @test_neon(%struct.neon_struct %{{.*}})
    115 // CHECK64: define void @test_neon([4 x <8 x i8>] %{{.*}})
    116 extern void neon_callee(struct neon_struct);
    117 void test_neon(struct neon_struct arg) {
    118   neon_callee(arg);
    119 }
    120 
    121 // CHECK-LABEL: define arm_aapcs_vfpcc void @f33(%struct.s33* byval align 4 %s)
    122 struct s33 { char buf[32*32]; };
    123 void f33(struct s33 s) { }
    124 
    125 typedef struct { long long x; int y; } struct_long_long_int;
    126 // 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)
    127 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, int j, long long k, int l) {}
    128 
    129 // 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)
    130 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, int j, struct_long_long_int k) {}
    131 
    132 // 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)
    133 struct_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) {}
    134 
    135 typedef struct { int a; int b:4; int c; } struct_int_bitfield_int;
    136 // 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)
    137 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, int j, int k, struct_int_bitfield_int l) {}
    138 
    139 // Note: this struct requires internal padding
    140 typedef struct { int x; long long y; } struct_int_long_long;
    141 // 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)
    142 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, int j, struct_int_long_long k) {}
    143 
    144 // This very large struct (passed byval) uses up the GPRs, so no padding is needed
    145 typedef struct { int x[17]; } struct_seventeen_ints;
    146 typedef struct { int x[4]; } struct_four_ints;
    147 // 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)
    148 void 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) {}
    149 
    150 // Here, parameter k would need padding to prevent it from being split, but it
    151 // is passed ByVal (due to being > 64 bytes), so the backend handles this instead.
    152 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, int j, struct_seventeen_ints k) {}
    153 // 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)
    154