brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.2 KiB · b45983d Raw
132 lines · plain
1// Test X86-64 ABI rewrite of struct returned by value (BIND(C), VALUE derived types).2// RUN: fir-opt --target-rewrite %s | FileCheck %s3 4!fits_in_reg = !fir.type<t1{i:f32,j:i32,k:f32}>5!too_big = !fir.type<t2{i:!fir.array<5xf32>}>6 7module 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_reg10  func.func @test_call_inreg(%arg0: !fir.ref<!fits_in_reg>) {11    %0 = fir.call @test_inreg() : () -> !fits_in_reg12    fir.store %0 to %arg0 : !fir.ref<!fits_in_reg>13    return14  }15  func.func @test_addr_of_inreg() -> (() -> ()) {16    %0 = fir.address_of(@test_inreg) : () -> !fits_in_reg17    %1 = fir.convert %0 : (() -> !fits_in_reg) -> (() -> ())18    return %1 : () -> ()19  }20  func.func @test_addr_of_inreg_2() -> (() -> !fits_in_reg) {21    %0 = fir.address_of(@test_inreg) : () -> !fits_in_reg22    return %0 : () -> !fits_in_reg23  }24  func.func @test_dispatch_inreg(%arg0: !fir.ref<!fits_in_reg>, %arg1: !fir.class<!fir.type<somet>>) {25    %0 = fir.dispatch "bar"(%arg1 : !fir.class<!fir.type<somet>>) (%arg1 : !fir.class<!fir.type<somet>>) -> !fits_in_reg {pass_arg_pos = 0 : i32}26    fir.store %0 to %arg0 : !fir.ref<!fits_in_reg>27    return28  }29 30  func.func private @test_sret() -> !too_big31  func.func @test_call_sret(%arg0: !fir.ref<!too_big>) {32    %0 = fir.call @test_sret() : () -> !too_big33    fir.store %0 to %arg0 : !fir.ref<!too_big>34    return35  }36  func.func @test_addr_of_sret() -> (() -> ()) {37    %0 = fir.address_of(@test_sret) : () -> !too_big38    %1 = fir.convert %0 : (() -> !too_big) -> (() -> ())39    return %1 : () -> ()40  }41  func.func @test_dispatch_sret(%arg0: !fir.ref<!too_big>, %arg1: !fir.class<!fir.type<somet>>) {42    %0 = fir.dispatch "bar"(%arg1 : !fir.class<!fir.type<somet>>) (%arg1 : !fir.class<!fir.type<somet>>) -> !too_big {pass_arg_pos = 0 : i32}43    fir.store %0 to %arg0 : !fir.ref<!too_big>44    return45  }46  func.func private @test_fp_80() -> !fir.type<t3{i:f80}>47  func.func private @test_complex_80() -> !fir.type<t4{i:complex<f80>}>48  func.func private @test_two_fp_80() -> !fir.type<t5{i:f80,j:f80}>49  func.func private @test_fp128() -> !fir.type<t6{i:f128}>50}51 52// CHECK-LABEL:   func.func private @test_inreg() -> tuple<i64, f32>53 54// CHECK-LABEL:   func.func @test_call_inreg(55// CHECK-SAME:                               %[[VAL_0:.*]]: !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>) {56// CHECK:           %[[VAL_1:.*]] = fir.call @test_inreg() : () -> tuple<i64, f32>57// CHECK:           %[[VAL_2:.*]] = llvm.intr.stacksave : !llvm.ptr58// CHECK:           %[[VAL_3:.*]] = fir.alloca tuple<i64, f32>59// CHECK:           fir.store %[[VAL_1]] to %[[VAL_3]] : !fir.ref<tuple<i64, f32>>60// CHECK:           %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<tuple<i64, f32>>) -> !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>61// CHECK:           %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>62// CHECK:           llvm.intr.stackrestore %[[VAL_2]] : !llvm.ptr63// CHECK:           fir.store %[[VAL_5]] to %[[VAL_0]] : !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>64// CHECK:           return65// CHECK:         }66 67// CHECK-LABEL:   func.func @test_addr_of_inreg() -> (() -> ()) {68// CHECK:           %[[VAL_0:.*]] = fir.address_of(@test_inreg) : () -> tuple<i64, f32>69// CHECK:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (() -> tuple<i64, f32>) -> (() -> !fir.type<t1{i:f32,j:i32,k:f32}>)70// CHECK:           %[[VAL_2:.*]] = fir.convert %[[VAL_1]] : (() -> !fir.type<t1{i:f32,j:i32,k:f32}>) -> (() -> ())71// CHECK:           return %[[VAL_2]] : () -> ()72// CHECK:         }73 74// CHECK-LABEL:   func.func @test_addr_of_inreg_2() -> (() -> !fir.type<t1{i:f32,j:i32,k:f32}>) {75// CHECK:           %[[VAL_0:.*]] = fir.address_of(@test_inreg) : () -> tuple<i64, f32>76// CHECK:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (() -> tuple<i64, f32>) -> (() -> !fir.type<t1{i:f32,j:i32,k:f32}>)77// CHECK:           return %[[VAL_1]] : () -> !fir.type<t1{i:f32,j:i32,k:f32}>78// CHECK:         }79 80// CHECK-LABEL:   func.func @test_dispatch_inreg(81// CHECK-SAME:                                   %[[VAL_0:.*]]: !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>,82// CHECK-SAME:                                   %[[VAL_1:.*]]: !fir.class<!fir.type<somet>>) {83// 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}84// CHECK:           %[[VAL_3:.*]] = llvm.intr.stacksave : !llvm.ptr85// CHECK:           %[[VAL_4:.*]] = fir.alloca tuple<i64, f32>86// CHECK:           fir.store %[[VAL_2]] to %[[VAL_4]] : !fir.ref<tuple<i64, f32>>87// CHECK:           %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (!fir.ref<tuple<i64, f32>>) -> !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>88// CHECK:           %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>89// CHECK:           llvm.intr.stackrestore %[[VAL_3]] : !llvm.ptr90// CHECK:           fir.store %[[VAL_6]] to %[[VAL_0]] : !fir.ref<!fir.type<t1{i:f32,j:i32,k:f32}>>91// CHECK:           return92// CHECK:         }93// 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>}>})94 95// CHECK-LABEL:   func.func @test_call_sret(96// CHECK-SAME:                              %[[VAL_0:.*]]: !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>) {97// CHECK:           %[[VAL_1:.*]] = llvm.intr.stacksave : !llvm.ptr98// CHECK:           %[[VAL_2:.*]] = fir.alloca !fir.type<t2{i:!fir.array<5xf32>}>99// 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>}>}) -> ()100// 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>}>>101// CHECK:           %[[VAL_4:.*]] = fir.load %[[VAL_3]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>102// CHECK:           llvm.intr.stackrestore %[[VAL_1]] : !llvm.ptr103// CHECK:           fir.store %[[VAL_4]] to %[[VAL_0]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>104// CHECK:           return105// CHECK:         }106 107// CHECK-LABEL:   func.func @test_addr_of_sret() -> (() -> ()) {108// CHECK:           %[[VAL_0:.*]] = fir.address_of(@test_sret) : (!fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>) -> ()109// CHECK:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : ((!fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>) -> ()) -> (() -> !fir.type<t2{i:!fir.array<5xf32>}>)110// CHECK:           %[[VAL_2:.*]] = fir.convert %[[VAL_1]] : (() -> !fir.type<t2{i:!fir.array<5xf32>}>) -> (() -> ())111// CHECK:           return %[[VAL_2]] : () -> ()112// CHECK:         }113 114// CHECK-LABEL:   func.func @test_dispatch_sret(115// CHECK-SAME:                                  %[[VAL_0:.*]]: !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>,116// CHECK-SAME:                                  %[[VAL_1:.*]]: !fir.class<!fir.type<somet>>) {117// CHECK:           %[[VAL_2:.*]] = llvm.intr.stacksave : !llvm.ptr118// CHECK:           %[[VAL_3:.*]] = fir.alloca !fir.type<t2{i:!fir.array<5xf32>}>119// 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}120// 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>}>>121// CHECK:           %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>122// CHECK:           llvm.intr.stackrestore %[[VAL_2]] : !llvm.ptr123// CHECK:           fir.store %[[VAL_5]] to %[[VAL_0]] : !fir.ref<!fir.type<t2{i:!fir.array<5xf32>}>>124// CHECK:           return125// CHECK:         }126 127 128// CHECK: func.func private @test_fp_80() -> f80129// 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>}>})130// 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}>})131// CHECK: func.func private @test_fp128() -> f128132