Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 %s -triple=renderscript32-none-linux-gnueabi -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-RS32
      2 // RUN: %clang_cc1 %s -triple=renderscript64-none-linux-android -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-RS64
      3 // RUN: %clang_cc1 %s -triple=armv7-none-linux-gnueabi -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-ARM
      4 
      5 // Ensure that the bitcode has the correct triple
      6 // CHECK-RS32: target triple = "armv7-none-linux-gnueabi"
      7 // CHECK-RS64: target triple = "aarch64-none-linux-android"
      8 // CHECK-ARM: target triple = "armv7-none-linux-gnueabi"
      9 
     10 // Ensure that long data type has 8-byte size and alignment in RenderScript
     11 #ifdef __RENDERSCRIPT__
     12 #define LONG_WIDTH_AND_ALIGN 8
     13 #else
     14 #define LONG_WIDTH_AND_ALIGN 4
     15 #endif
     16 
     17 _Static_assert(sizeof(long) == LONG_WIDTH_AND_ALIGN, "sizeof long is wrong");
     18 _Static_assert(_Alignof(long) == LONG_WIDTH_AND_ALIGN, "sizeof long is wrong");
     19 
     20 // CHECK-RS32: i64 @test_long(i64 %v)
     21 // CHECK-RS64: i64 @test_long(i64 %v)
     22 // CHECK-ARM: i32 @test_long(i32 %v)
     23 long test_long(long v) {
     24   return v + 1;
     25 }
     26 
     27 // =============================================================================
     28 // Test coercion of aggregate argument or return value into integer arrays
     29 // =============================================================================
     30 
     31 // =============================================================================
     32 // aggregate parameter <= 4 bytes: coerced to [a x iNN] for both 32-bit and
     33 // 64-bit RenderScript
     34 // ==============================================================================
     35 
     36 typedef struct {char c1, c2, c3; } sChar3;
     37 typedef struct {short s; char c;} sShortChar;
     38 
     39 // CHECK-RS32: void @argChar3([3 x i8] %s.coerce)
     40 // CHECK-RS64: void @argChar3([3 x i8] %s.coerce)
     41 void argChar3(sChar3 s) {}
     42 
     43 // CHECK-RS32: void @argShortChar([2 x i16] %s.coerce)
     44 // CHECK-RS64: void @argShortChar([2 x i16] %s.coerce)
     45 void argShortChar(sShortChar s) {}
     46 
     47 // =============================================================================
     48 // aggregate return value <= 4 bytes: coerced to [a x iNN] for both 32-bit and
     49 // 64-bit RenderScript
     50 // =============================================================================
     51 
     52 // CHECK-RS32: [3 x i8] @retChar3()
     53 // CHECK-RS64: [3 x i8] @retChar3()
     54 sChar3 retChar3() { sChar3 r; return r; }
     55 
     56 // CHECK-RS32: [2 x i16] @retShortChar()
     57 // CHECK-RS64: [2 x i16] @retShortChar()
     58 sShortChar retShortChar() { sShortChar r; return r; }
     59 
     60 // =============================================================================
     61 // aggregate parameter <= 16 bytes: coerced to [a x iNN] for both 32-bit and
     62 // 64-bit RenderScript
     63 // =============================================================================
     64 
     65 typedef struct {short s1; char c; short s2; } sShortCharShort;
     66 typedef struct {int i; short s; char c; } sIntShortChar;
     67 typedef struct {long l; int i; } sLongInt;
     68 
     69 // CHECK-RS32: void @argShortCharShort([3 x i16] %s.coerce)
     70 // CHECK-RS64: void @argShortCharShort([3 x i16] %s.coerce)
     71 void argShortCharShort(sShortCharShort s) {}
     72 
     73 // CHECK-RS32: void @argIntShortChar([2 x i32] %s.coerce)
     74 // CHECK-RS64: void @argIntShortChar([2 x i32] %s.coerce)
     75 void argIntShortChar(sIntShortChar s) {}
     76 
     77 // CHECK-RS32: void @argLongInt([2 x i64] %s.coerce)
     78 // CHECK-RS64: void @argLongInt([2 x i64] %s.coerce)
     79 void argLongInt(sLongInt s) {}
     80 
     81 // =============================================================================
     82 // aggregate return value <= 16 bytes: returned on stack for 32-bit RenderScript
     83 // and coerced to [a x iNN] for 64-bit RenderScript
     84 // =============================================================================
     85 
     86 // CHECK-RS32: void @retShortCharShort(%struct.sShortCharShort* noalias sret %agg.result)
     87 // CHECK-RS64: [3 x i16] @retShortCharShort()
     88 sShortCharShort retShortCharShort() { sShortCharShort r; return r; }
     89 
     90 // CHECK-RS32: void @retIntShortChar(%struct.sIntShortChar* noalias sret %agg.result)
     91 // CHECK-RS64: [2 x i32] @retIntShortChar()
     92 sIntShortChar retIntShortChar() { sIntShortChar r; return r; }
     93 
     94 // CHECK-RS32: void @retLongInt(%struct.sLongInt* noalias sret %agg.result)
     95 // CHECK-RS64: [2 x i64] @retLongInt()
     96 sLongInt retLongInt() { sLongInt r; return r; }
     97 
     98 // =============================================================================
     99 // aggregate parameter <= 64 bytes: coerced to [a x iNN] for 32-bit RenderScript
    100 // and passed on the stack for 64-bit RenderScript
    101 // =============================================================================
    102 
    103 typedef struct {int i1, i2, i3, i4, i5; } sInt5;
    104 typedef struct {long l1, l2; char c; } sLong2Char;
    105 
    106 // CHECK-RS32: void @argInt5([5 x i32] %s.coerce)
    107 // CHECK-RS64: void @argInt5(%struct.sInt5* %s)
    108 void argInt5(sInt5 s) {}
    109 
    110 // CHECK-RS32: void @argLong2Char([3 x i64] %s.coerce)
    111 // CHECK-RS64: void @argLong2Char(%struct.sLong2Char* %s)
    112 void argLong2Char(sLong2Char s) {}
    113 
    114 // =============================================================================
    115 // aggregate return value <= 64 bytes: returned on stack for both 32-bit and
    116 // 64-bit RenderScript
    117 // =============================================================================
    118 
    119 // CHECK-RS32: void @retInt5(%struct.sInt5* noalias sret %agg.result)
    120 // CHECK-RS64: void @retInt5(%struct.sInt5* noalias sret %agg.result)
    121 sInt5 retInt5() { sInt5 r; return r;}
    122 
    123 // CHECK-RS32: void @retLong2Char(%struct.sLong2Char* noalias sret %agg.result)
    124 // CHECK-RS64: void @retLong2Char(%struct.sLong2Char* noalias sret %agg.result)
    125 sLong2Char retLong2Char() { sLong2Char r; return r;}
    126 
    127 // =============================================================================
    128 // aggregate parameters and return values > 64 bytes: passed and returned on the
    129 // stack for both 32-bit and 64-bit RenderScript
    130 // =============================================================================
    131 
    132 typedef struct {long l1, l2, l3, l4, l5, l6, l7, l8, l9; } sLong9;
    133 
    134 // CHECK-RS32: void @argLong9(%struct.sLong9* byval align 8 %s)
    135 // CHECK-RS64: void @argLong9(%struct.sLong9* %s)
    136 void argLong9(sLong9 s) {}
    137 
    138 // CHECK-RS32: void @retLong9(%struct.sLong9* noalias sret %agg.result)
    139 // CHECK-RS64: void @retLong9(%struct.sLong9* noalias sret %agg.result)
    140 sLong9 retLong9() { sLong9 r; return r; }
    141