brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · fdfb2ce Raw
63 lines · plain
1// RUN: fir-opt --opt-bufferization %s | FileCheck %s2 3// Fortran F2023 15.5.2.14 point 4. ensures that _QPfoo cannot access _QFtestEx4// and the temporary storage for the result can be avoided.5func.func @_QPtest(%arg0: !fir.ref<!fir.array<10xf32>> {fir.bindc_name = "x"}) {6  %c10 = arith.constant 10 : index7  %0 = fir.dummy_scope : !fir.dscope8  %1 = fir.shape %c10 : (index) -> !fir.shape<1>9  %2:2 = hlfir.declare %arg0(%1) dummy_scope %0 {uniq_name = "_QFtestEx"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>)10  %3 = hlfir.eval_in_mem shape %1 : (!fir.shape<1>) -> !hlfir.expr<10xf32> {11  ^bb0(%arg1: !fir.ref<!fir.array<10xf32>>):12    %4 = fir.call @_QPfoo() fastmath<contract> : () -> !fir.array<10xf32>13    fir.save_result %4 to %arg1(%1) : !fir.array<10xf32>, !fir.ref<!fir.array<10xf32>>, !fir.shape<1>14  }15  hlfir.assign %3 to %2#0 : !hlfir.expr<10xf32>, !fir.ref<!fir.array<10xf32>>16  hlfir.destroy %3 : !hlfir.expr<10xf32>17  return18}19func.func private @_QPfoo() -> !fir.array<10xf32>20 21// CHECK-LABEL: func.func @_QPtest(22// CHECK-SAME:                     %[[VAL_0:.*]]: !fir.ref<!fir.array<10xf32>> {fir.bindc_name = "x"}) {23// CHECK:         %[[VAL_1:.*]] = arith.constant 10 : index24// CHECK:         %[[VAL_2:.*]] = fir.dummy_scope : !fir.dscope25// CHECK:         %[[VAL_3:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>26// CHECK:         %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_3]]) dummy_scope %[[VAL_2]] {uniq_name = "_QFtestEx"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>)27// CHECK:         %[[VAL_5:.*]] = fir.call @_QPfoo() fastmath<contract> : () -> !fir.array<10xf32>28// CHECK:         fir.save_result %[[VAL_5]] to %[[VAL_4]]#0(%[[VAL_3]]) : !fir.array<10xf32>, !fir.ref<!fir.array<10xf32>>, !fir.shape<1>29// CHECK:         return30// CHECK:       }31 32 33// Temporary storage cannot be avoided in this case since34// _QFnegative_test_is_targetEx has the TARGET attribute.35func.func @_QPnegative_test_is_target(%arg0: !fir.ref<!fir.array<10xf32>> {fir.bindc_name = "x", fir.target}) {36  %c10 = arith.constant 10 : index37  %0 = fir.dummy_scope : !fir.dscope38  %1 = fir.shape %c10 : (index) -> !fir.shape<1>39  %2:2 = hlfir.declare %arg0(%1) dummy_scope %0 {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFnegative_test_is_targetEx"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>)40  %3 = hlfir.eval_in_mem shape %1 : (!fir.shape<1>) -> !hlfir.expr<10xf32> {41  ^bb0(%arg1: !fir.ref<!fir.array<10xf32>>):42    %4 = fir.call @_QPfoo() fastmath<contract> : () -> !fir.array<10xf32>43    fir.save_result %4 to %arg1(%1) : !fir.array<10xf32>, !fir.ref<!fir.array<10xf32>>, !fir.shape<1>44  }45  hlfir.assign %3 to %2#0 : !hlfir.expr<10xf32>, !fir.ref<!fir.array<10xf32>>46  hlfir.destroy %3 : !hlfir.expr<10xf32>47  return48}49// CHECK-LABEL: func.func @_QPnegative_test_is_target(50// CHECK-SAME:                                        %[[VAL_0:.*]]: !fir.ref<!fir.array<10xf32>> {fir.bindc_name = "x", fir.target}) {51// CHECK:         %[[VAL_2:.*]] = arith.constant false52// CHECK:         %[[VAL_3:.*]] = arith.constant 10 : index53// CHECK:         %[[VAL_4:.*]] = fir.alloca !fir.array<10xf32>54// CHECK:         %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_0]]{{.*}}55// CHECK:         %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_4]]{{.*}}56// CHECK:         %[[VAL_9:.*]] = fir.call @_QPfoo() fastmath<contract> : () -> !fir.array<10xf32>57// CHECK:         fir.save_result %[[VAL_9]] to %[[VAL_8]]#1{{.*}}58// CHECK:         %[[VAL_10:.*]] = hlfir.as_expr %[[VAL_8]]#0 move %[[VAL_2]] : (!fir.ref<!fir.array<10xf32>>, i1) -> !hlfir.expr<10xf32>59// CHECK:         hlfir.assign %[[VAL_10]] to %[[VAL_7]]#0 : !hlfir.expr<10xf32>, !fir.ref<!fir.array<10xf32>>60// CHECK:         hlfir.destroy %[[VAL_10]] : !hlfir.expr<10xf32>61// CHECK:         return62// CHECK:       }63