| 1 |
/// Test LoongArch64 ABI rewrite of struct returned by value (BIND(C), VALUE derived types). |
| 2 |
/// This test test cases where the struct can be returned in registers. |
| 3 |
/// Test cases can be roughly divided into two categories: |
| 4 |
/// - struct with a single intrinsic component; |
| 5 |
/// - sturct with more than one field; |
| 6 |
/// Since the argument marshalling logic is largely the same within each category, |
| 7 |
/// only the first example in each category checks the entire invocation process, |
| 8 |
/// while the other examples only check the signatures. |
| 9 |
|
| 10 |
// RUN: fir-opt --split-input-file --target-rewrite="target=loongarch64-unknown-linux-gnu" %s | FileCheck %s |
| 11 |
|
| 12 |
|
| 13 |
/// *********************** Struct with a single intrinsic component *********************** /// |
| 14 |
|
| 15 |
!ty_i16 = !fir.type<ti16{i:i16}> |
| 16 |
!ty_i32 = !fir.type<ti32{i:i32}> |
| 17 |
!ty_i64 = !fir.type<ti64{i:i64}> |
| 18 |
!ty_i128 = !fir.type<ti128{i:i128}> |
| 19 |
!ty_f16 = !fir.type<tf16{i:f16}> |
| 20 |
!ty_f32 = !fir.type<tf32{i:f32}> |
| 21 |
!ty_f64 = !fir.type<tf64{i:f64}> |
| 22 |
!ty_f128 = !fir.type<tf128{i:f128}> |
| 23 |
!ty_bf16 = !fir.type<tbf16{i:bf16}> |
| 24 |
!ty_char1 = !fir.type<tchar1{i:!fir.char<1>}> |
| 25 |
!ty_char2 = !fir.type<tchar2{i:!fir.char<1,2>}> |
| 26 |
!ty_log1 = !fir.type<tlog1{i:!fir.logical<1>}> |
| 27 |
!ty_log2 = !fir.type<tlog2{i:!fir.logical<2>}> |
| 28 |
!ty_log4 = !fir.type<tlog4{i:!fir.logical<4>}> |
| 29 |
!ty_log8 = !fir.type<tlog8{i:!fir.logical<8>}> |
| 30 |
!ty_log16 = !fir.type<tlog16{i:!fir.logical<16>}> |
| 31 |
!ty_cmplx_f32 = !fir.type<tcmplx_f32{i:complex<f32>}> |
| 32 |
!ty_cmplx_f64 = !fir.type<tcmplx_f64{i:complex<f64>}> |
| 33 |
|
| 34 |
module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", llvm.target_triple = "loongarch64-unknown-linux-gnu"} { |
| 35 |
|
| 36 |
// CHECK-LABEL: func.func private @test_func_i16() -> i64 |
| 37 |
func.func private @test_func_i16() -> !ty_i16 |
| 38 |
// CHECK-LABEL: func.func @test_call_i16( |
| 39 |
// CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.type<ti16{i:i16}>>) { |
| 40 |
func.func @test_call_i16(%arg0: !fir.ref<!ty_i16>) { |
| 41 |
// CHECK: %[[OUT:.*]] = fir.call @test_func_i16() : () -> i64 |
| 42 |
// CHECK: %[[STACK:.*]] = llvm.intr.stacksave : !llvm.ptr |
| 43 |
// CHECK: %[[ARR:.*]] = fir.alloca i64 |
| 44 |
// CHECK: fir.store %[[OUT]] to %[[ARR]] : !fir.ref<i64> |
| 45 |
// CHECK: %[[CVT:.*]] = fir.convert %[[ARR]] : (!fir.ref<i64>) -> !fir.ref<!fir.type<ti16{i:i16}>> |
| 46 |
// CHECK: %[[LD:.*]] = fir.load %[[CVT]] : !fir.ref<!fir.type<ti16{i:i16}>> |
| 47 |
// CHECK: llvm.intr.stackrestore %[[STACK]] : !llvm.ptr |
| 48 |
%out = fir.call @test_func_i16() : () -> !ty_i16 |
| 49 |
// CHECK: fir.store %[[LD]] to %[[ARG0]] : !fir.ref<!fir.type<ti16{i:i16}>> |
| 50 |
fir.store %out to %arg0 : !fir.ref<!ty_i16> |
| 51 |
// CHECK: return |
| 52 |
return |
| 53 |
} |
| 54 |
|
| 55 |
// CHECK-LABEL: func.func private @test_func_i32() -> i64 |
| 56 |
func.func private @test_func_i32() -> !ty_i32 |
| 57 |
|
| 58 |
// CHECK-LABEL: func.func private @test_func_i64() -> i64 |
| 59 |
func.func private @test_func_i64() -> !ty_i64 |
| 60 |
|
| 61 |
// CHECK-LABEL: func.func private @test_func_i128() -> i128 |
| 62 |
func.func private @test_func_i128() -> !ty_i128 |
| 63 |
|
| 64 |
// CHECK-LABEL: func.func private @test_func_f16() -> i64 |
| 65 |
func.func private @test_func_f16() -> !ty_f16 |
| 66 |
|
| 67 |
// CHECK-LABEL: func.func private @test_func_f32() -> f32 |
| 68 |
func.func private @test_func_f32() -> !ty_f32 |
| 69 |
|
| 70 |
// CHECK-LABEL: func.func private @test_func_f64() -> f64 |
| 71 |
func.func private @test_func_f64() -> !ty_f64 |
| 72 |
|
| 73 |
// CHECK-LABEL: func.func private @test_func_f128() -> i128 |
| 74 |
func.func private @test_func_f128() -> !ty_f128 |
| 75 |
|
| 76 |
// CHECK-LABEL: func.func private @test_func_bf16() -> i64 |
| 77 |
func.func private @test_func_bf16() -> !ty_bf16 |
| 78 |
|
| 79 |
// CHECK-LABEL: func.func private @test_func_char1() -> i64 |
| 80 |
func.func private @test_func_char1() -> !ty_char1 |
| 81 |
|
| 82 |
// CHECK-LABEL: func.func private @test_func_char2() -> i64 |
| 83 |
func.func private @test_func_char2() -> !ty_char2 |
| 84 |
|
| 85 |
// CHECK-LABEL: func.func private @test_func_log1() -> i64 |
| 86 |
func.func private @test_func_log1() -> !ty_log1 |
| 87 |
|
| 88 |
// CHECK-LABEL: func.func private @test_func_log2() -> i64 |
| 89 |
func.func private @test_func_log2() -> !ty_log2 |
| 90 |
|
| 91 |
// CHECK-LABEL: func.func private @test_func_log4() -> i64 |
| 92 |
func.func private @test_func_log4() -> !ty_log4 |
| 93 |
|
| 94 |
// CHECK-LABEL: func.func private @test_func_log8() -> i64 |
| 95 |
func.func private @test_func_log8() -> !ty_log8 |
| 96 |
|
| 97 |
// CHECK-LABEL: func.func private @test_func_log16() -> i128 |
| 98 |
func.func private @test_func_log16() -> !ty_log16 |
| 99 |
|
| 100 |
// CHECK-LABEL: func.func private @test_func_cmplx_f32() -> tuple<f32, f32> |
| 101 |
func.func private @test_func_cmplx_f32() -> !ty_cmplx_f32 |
| 102 |
|
| 103 |
// CHECK-LABEL: func.func private @test_func_cmplx_f64() -> tuple<f64, f64> |
| 104 |
func.func private @test_func_cmplx_f64() -> !ty_cmplx_f64 |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
/// *************************** Struct with more than one field **************************** /// |
| 109 |
|
| 110 |
// ----- |
| 111 |
|
| 112 |
!ty_i32_f32 = !fir.type<ti32_f32{i:i32,j:f32}> |
| 113 |
!ty_i32_f64 = !fir.type<ti32_f64{i:i32,j:f64}> |
| 114 |
!ty_i64_f32 = !fir.type<ti64_f32{i:i64,j:f32}> |
| 115 |
!ty_i64_f64 = !fir.type<ti64_f64{i:i64,j:f64}> |
| 116 |
!ty_f64_i64 = !fir.type<tf64_i64{i:f64,j:i64}> |
| 117 |
!ty_f16_f16 = !fir.type<tf16_f16{i:f16,j:f16}> |
| 118 |
!ty_f32_f32 = !fir.type<tf32_f32{i:f32,j:f32}> |
| 119 |
!ty_f64_f64 = !fir.type<tf64_f64{i:f64,j:f64}> |
| 120 |
!ty_f32_i32_i32 = !fir.type<tf32_i32_i32{i:f32,j:i32,k:i32}> |
| 121 |
!ty_f32_f32_i32 = !fir.type<tf32_f32_i32{i:f32,j:f32,k:i32}> |
| 122 |
!ty_f32_f32_f32 = !fir.type<tf32_f32_f32{i:f32,j:f32,k:f32}> |
| 123 |
|
| 124 |
!ty_i8_a8 = !fir.type<ti8_a8{i:!fir.array<8xi8>}> |
| 125 |
!ty_i8_a16 = !fir.type<ti8_a16{i:!fir.array<16xi8>}> |
| 126 |
!ty_f32_a2 = !fir.type<tf32_a2{i:!fir.array<2xf32>}> |
| 127 |
!ty_f64_a2 = !fir.type<tf64_a2{i:!fir.array<2xf64>}> |
| 128 |
!ty_nested_i32_f32 = !fir.type<t11{i:!ty_i32_f32}> |
| 129 |
!ty_nested_i8_a8_i32 = !fir.type<t12{i:!ty_i8_a8, j:i32}> |
| 130 |
|
| 131 |
module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", llvm.target_triple = "loongarch64-unknown-linux-gnu"} { |
| 132 |
|
| 133 |
// CHECK-LABEL: func.func private @test_func_i32_f32() -> tuple<i32, f32> |
| 134 |
func.func private @test_func_i32_f32() -> !ty_i32_f32 |
| 135 |
// CHECK-LABEL: func.func @test_call_i32_f32( |
| 136 |
// CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.type<ti32_f32{i:i32,j:f32}>>) { |
| 137 |
func.func @test_call_i32_f32(%arg0: !fir.ref<!ty_i32_f32>) { |
| 138 |
// CHECK: %[[OUT:.*]] = fir.call @test_func_i32_f32() : () -> tuple<i32, f32> |
| 139 |
// CHECK: %[[STACK:.*]] = llvm.intr.stacksave : !llvm.ptr |
| 140 |
// CHECK: %[[ARR:.*]] = fir.alloca tuple<i32, f32> |
| 141 |
// CHECK: fir.store %[[OUT]] to %[[ARR]] : !fir.ref<tuple<i32, f32>> |
| 142 |
// CHECK: %[[CVT:.*]] = fir.convert %[[ARR]] : (!fir.ref<tuple<i32, f32>>) -> !fir.ref<!fir.type<ti32_f32{i:i32,j:f32}>> |
| 143 |
// CHECK: %[[LD:.*]] = fir.load %[[CVT]] : !fir.ref<!fir.type<ti32_f32{i:i32,j:f32}>> |
| 144 |
// CHECK: llvm.intr.stackrestore %[[STACK]] : !llvm.ptr |
| 145 |
%out = fir.call @test_func_i32_f32() : () -> !ty_i32_f32 |
| 146 |
// CHECK: fir.store %[[LD]] to %[[ARG0]] : !fir.ref<!fir.type<ti32_f32{i:i32,j:f32}>> |
| 147 |
fir.store %out to %arg0 : !fir.ref<!ty_i32_f32> |
| 148 |
// CHECK: return |
| 149 |
return |
| 150 |
} |
| 151 |
|
| 152 |
// CHECK-LABEL: func.func private @test_func_i32_f64() -> tuple<i32, f64> |
| 153 |
func.func private @test_func_i32_f64() -> !ty_i32_f64 |
| 154 |
|
| 155 |
// CHECK-LABEL: func.func private @test_func_i64_f32() -> tuple<i64, f32> |
| 156 |
func.func private @test_func_i64_f32() -> !ty_i64_f32 |
| 157 |
|
| 158 |
// CHECK-LABEL: func.func private @test_func_i64_f64() -> tuple<i64, f64> |
| 159 |
func.func private @test_func_i64_f64() -> !ty_i64_f64 |
| 160 |
|
| 161 |
// CHECK-LABEL: func.func private @test_func_f64_i64() -> tuple<f64, i64> |
| 162 |
func.func private @test_func_f64_i64() -> !ty_f64_i64 |
| 163 |
|
| 164 |
// CHECK-LABEL: func.func private @test_func_f16_f16() -> i64 |
| 165 |
func.func private @test_func_f16_f16() -> !ty_f16_f16 |
| 166 |
|
| 167 |
// CHECK-LABEL: func.func private @test_func_f32_f32() -> tuple<f32, f32> |
| 168 |
func.func private @test_func_f32_f32() -> !ty_f32_f32 |
| 169 |
|
| 170 |
// CHECK-LABEL: func.func private @test_func_f64_f64() -> tuple<f64, f64> |
| 171 |
func.func private @test_func_f64_f64() -> !ty_f64_f64 |
| 172 |
|
| 173 |
// CHECK-LABEL: func.func private @test_func_f32_i32_i32() -> !fir.array<2xi64> |
| 174 |
func.func private @test_func_f32_i32_i32() -> !ty_f32_i32_i32 |
| 175 |
|
| 176 |
// CHECK-LABEL: func.func private @test_func_f32_f32_i32() -> !fir.array<2xi64> |
| 177 |
func.func private @test_func_f32_f32_i32() -> !ty_f32_f32_i32 |
| 178 |
|
| 179 |
// CHECK-LABEL: func.func private @test_func_f32_f32_f32() -> !fir.array<2xi64> |
| 180 |
func.func private @test_func_f32_f32_f32() -> !ty_f32_f32_f32 |
| 181 |
|
| 182 |
// CHECK-LABEL: func.func private @test_func_i8_a8() -> i64 |
| 183 |
func.func private @test_func_i8_a8() -> !ty_i8_a8 |
| 184 |
|
| 185 |
// CHECK-LABEL: func.func private @test_func_i8_a16() -> !fir.array<2xi64> |
| 186 |
func.func private @test_func_i8_a16() -> !ty_i8_a16 |
| 187 |
|
| 188 |
// CHECK-LABEL: func.func private @test_func_f32_a2() -> tuple<f32, f32> |
| 189 |
func.func private @test_func_f32_a2() -> !ty_f32_a2 |
| 190 |
|
| 191 |
// CHECK-LABEL: func.func private @test_func_f64_a2() -> tuple<f64, f64> |
| 192 |
func.func private @test_func_f64_a2() -> !ty_f64_a2 |
| 193 |
|
| 194 |
// CHECK-LABEL: func.func private @test_func_nested_i32_f32() -> tuple<i32, f32> |
| 195 |
func.func private @test_func_nested_i32_f32() -> !ty_nested_i32_f32 |
| 196 |
|
| 197 |
// CHECK-LABEL: func.func private @test_func_nested_i8_a8_i32() -> !fir.array<2xi64> |
| 198 |
func.func private @test_func_nested_i8_a8_i32() -> !ty_nested_i8_a8_i32 |
| 199 |
} |