Debian Codegraph @

flang/test/Fir/struct-return-x86-64.fir

raw
1 // Test X86-64 ABI rewrite of struct returned by value (BIND(C), VALUE derived types).
2 // RUN: fir-opt --target-rewrite %s | FileCheck %s
3
4 !fits_in_reg = !fir.type<t1{i:f32,j:i32,k:f32}>
5 !too_big = !fir.type<t2{i:!fir.array<5xf32>}>
6
7 module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.target_triple = "x86_64-unknown-linux-gnu"} {
8
9 func.func private @test_inreg() -> !fits_in_reg
10 func.func @test_call_inreg(%arg0: !fir.ref<!fits_in_reg>) {
11 %0 = fir.call @test_inreg() : () -> !fits_in_reg
12 fir.store %0 to %arg0 : !fir.ref<!fits_in_reg>
13 return
14 }
15 func.func @test_addr_of_inreg() -> (() -> ()) {
16 %0 = fir.address_of(@test_inreg) : () -> !fits_in_reg
17 %1 = fir.convert %0 : (() -> !fits_in_reg) -> (() -> ())
18 return %1 : () -> ()
19 }
20 func.func @test_dispatch_inreg(%arg0: !fir.ref<!fits_in_reg>, %arg1: !fir.class<!fir.type<somet>>) {
21 %0 = fir.dispatch "bar"(%arg1 : !fir.class<!fir.type<somet>>) (%arg1 : !fir.class<!fir.type<somet>>) -> !fits_in_reg {pass_arg_pos = 0 : i32}
22 fir.store %0 to %arg0 : !fir.ref<!fits_in_reg>
23 return
24 }
25
26 func.func private @test_sret() -> !too_big
27 func.func @test_call_sret(%arg0: !fir.ref<!too_big>) {
28 %0 = fir.call @test_sret() : () -> !too_big
29 fir.store %0 to %arg0 : !fir.ref<!too_big>
30 return
31 }
32 func.func @test_addr_of_sret() -> (() -> ()) {
33 %0 = fir.address_of(@test_sret) : () -> !too_big
34 %1 = fir.convert %0 : (() -> !too_big) -> (() -> ())
35 return %1 : () -> ()
36 }
37 func.func @test_dispatch_sret(%arg0: !fir.ref<!too_big>, %arg1: !fir.class<!fir.type<somet>>) {
38 %0 = fir.dispatch "bar"(%arg1 : !fir.class<!fir.type<somet>>) (%arg1 : !fir.class<!fir.type<somet>>) -> !too_big {pass_arg_pos = 0 : i32}
39 fir.store %0 to %arg0 : !fir.ref<!too_big>
40 return
41 }
42 func.func private @test_fp_80() -> !fir.type<t3{i:f80}>
43 func.func private @test_complex_80() -> !fir.type<t4{i:complex<f80>}>
44 func.func private @test_two_fp_80() -> !fir.type<t5{i:f80,j:f80}>
45 func.func private @test_fp128() -> !fir.type<t6{i:f128}>
46 }
47
48 // CHECK-LABEL: func.func private @test_inreg() -> tuple<i64, f32>
49
50 // CHECK-LABEL: func.func @test_call_inreg(
51 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>) {
52 // CHECK: %[[VAL_1:.*]] = fir.call @test_inreg() : () -> tuple<i64, f32>
53 // CHECK: %[[VAL_2:.*]] = llvm.intr.stacksave : !llvm.ptr
54 // CHECK: %[[VAL_3:.*]] = fir.alloca tuple<i64, f32>
55 // CHECK: fir.store %[[VAL_1]] to %[[VAL_3]] : !fir.ref<tuple<i64, f32>>
56 // CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<tuple<i64, f32>>) -> !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>
57 // CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>
58 // CHECK: llvm.intr.stackrestore %[[VAL_2]] : !llvm.ptr
59 // CHECK: fir.store %[[VAL_5]] to %[[VAL_0]] : !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>
60 // CHECK: return
61 // CHECK: }
62
63 // CHECK-LABEL: func.func @test_addr_of_inreg() -> (() -> ()) {
64 // CHECK: %[[VAL_0:.*]] = fir.address_of(@test_inreg) : () -> tuple<i64, f32>
65 // CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (() -> tuple<i64, f32>) -> (() -> ())
66 // CHECK: return %[[VAL_1]] : () -> ()
67 // CHECK: }
68
69 // CHECK-LABEL: func.func @test_dispatch_inreg(
70 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>,
71 // CHECK-SAME: %[[VAL_1:.*]]: !fir.class<!fir.type<somet>>) {
72 // CHECK: %[[VAL_2:.*]] = fir.dispatch "bar"(%[[VAL_1]] : !fir.class<!fir.type<somet>>) (%[[VAL_1]] : !fir.class<!fir.type<somet>>) -> tuple<i64, f32> {pass_arg_pos = 0 : i32}
73 // CHECK: %[[VAL_3:.*]] = llvm.intr.stacksave : !llvm.ptr
74 // CHECK: %[[VAL_4:.*]] = fir.alloca tuple<i64, f32>
75 // CHECK: fir.store %[[VAL_2]] to %[[VAL_4]] : !fir.ref<tuple<i64, f32>>
76 // CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (!fir.ref<tuple<i64, f32>>) -> !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>
77 // CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>
78 // CHECK: llvm.intr.stackrestore %[[VAL_3]] : !llvm.ptr
79 // CHECK: fir.store %[[VAL_6]] to %[[VAL_0]] : !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>
80 // CHECK: return
81 // CHECK: }
82 // CHECK: func.func private @test_sret(!fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>> {llvm.align = 8 : i32, llvm.sret = !fir.type<t2{i:!fir.array<5xf32>}>})
83
84 // CHECK-LABEL: func.func @test_call_sret(
85 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>) {
86 // CHECK: %[[VAL_1:.*]] = llvm.intr.stacksave : !llvm.ptr
87 // CHECK: %[[VAL_2:.*]] = fir.alloca !fir.type<t2{i:!fir.array<5xf32>}>
88 // CHECK: fir.call @test_sret(%[[VAL_2]]) : (!fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>> {llvm.align = 8 : i32, llvm.sret = !fir.type<t2{i:!fir.array<5xf32>}>}) -> ()
89 // CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>) -> !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>
90 // CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>
91 // CHECK: llvm.intr.stackrestore %[[VAL_1]] : !llvm.ptr
92 // CHECK: fir.store %[[VAL_4]] to %[[VAL_0]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>
93 // CHECK: return
94 // CHECK: }
95
96 // CHECK-LABEL: func.func @test_addr_of_sret() -> (() -> ()) {
97 // CHECK: %[[VAL_0:.*]] = fir.address_of(@test_sret) : (!fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>) -> ()
98 // CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : ((!fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>) -> ()) -> (() -> ())
99 // CHECK: return %[[VAL_1]] : () -> ()
100 // CHECK: }
101
102 // CHECK-LABEL: func.func @test_dispatch_sret(
103 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>,
104 // CHECK-SAME: %[[VAL_1:.*]]: !fir.class<!fir.type<somet>>) {
105 // CHECK: %[[VAL_2:.*]] = llvm.intr.stacksave : !llvm.ptr
106 // CHECK: %[[VAL_3:.*]] = fir.alloca !fir.type<t2{i:!fir.array<5xf32>}>
107 // CHECK: fir.dispatch "bar"(%[[VAL_1]] : !fir.class<!fir.type<somet>>) (%[[VAL_3]], %[[VAL_1]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>, !fir.class<!fir.type<somet>>) {pass_arg_pos = 1 : i32}
108 // CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>) -> !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>
109 // CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>
110 // CHECK: llvm.intr.stackrestore %[[VAL_2]] : !llvm.ptr
111 // CHECK: fir.store %[[VAL_5]] to %[[VAL_0]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>
112 // CHECK: return
113 // CHECK: }
114
115
116 // CHECK: func.func private @test_fp_80() -> f80
117 // CHECK: func.func private @test_complex_80(!fir.ref<!fir.type<t4{i:complex<f80>}>> {llvm.align = 16 : i32, llvm.sret = !fir.type<t4{i:complex<f80>}>})
118 // CHECK: func.func private @test_two_fp_80(!fir.ref<!fir.type<t5{i:f80,j:f80}>> {llvm.align = 16 : i32, llvm.sret = !fir.type<t5{i:f80,j:f80}>})
119 // CHECK: func.func private @test_fp128() -> f128