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