| 1 |
// Test hlfir.destroy code generation and hlfir.yield_element "implicit |
| 2 |
// hlfir.destroy" aspect. |
| 3 |
|
| 4 |
// RUN: fir-opt %s -bufferize-hlfir | FileCheck %s |
| 5 |
|
| 6 |
func.func @test_move_with_cleanup(%arg0 : !fir.ref<!fir.array<100xi32>>) { |
| 7 |
%must_free = arith.constant true |
| 8 |
%expr = hlfir.as_expr %arg0 move %must_free: (!fir.ref<!fir.array<100xi32>>, i1) -> !hlfir.expr<100xi32> |
| 9 |
hlfir.destroy %expr : !hlfir.expr<100xi32> |
| 10 |
return |
| 11 |
} |
| 12 |
// CHECK-LABEL: func.func @test_move_with_cleanup( |
| 13 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<100xi32>>) { |
| 14 |
// CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<100xi32>>) -> !fir.heap<!fir.array<100xi32>> |
| 15 |
// CHECK: fir.freemem %[[VAL_5]] : !fir.heap<!fir.array<100xi32>> |
| 16 |
|
| 17 |
func.func @test_move_no_cleanup(%arg0 : !fir.ref<!fir.array<100xi32>>) { |
| 18 |
%must_free = arith.constant false |
| 19 |
%expr = hlfir.as_expr %arg0 move %must_free: (!fir.ref<!fir.array<100xi32>>, i1) -> !hlfir.expr<100xi32> |
| 20 |
hlfir.destroy %expr : !hlfir.expr<100xi32> |
| 21 |
return |
| 22 |
} |
| 23 |
// CHECK-LABEL: func.func @test_move_no_cleanup( |
| 24 |
// CHECK-NOT: fir.freemem |
| 25 |
// CHECK: return |
| 26 |
|
| 27 |
func.func @test_elemental() { |
| 28 |
%c100 = arith.constant 100 : index |
| 29 |
%c20 = arith.constant 20 : index |
| 30 |
%0 = fir.shape %c100 : (index) -> !fir.shape<1> |
| 31 |
%3 = hlfir.elemental %0 typeparams %c20 : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1,20>> { |
| 32 |
^bb0(%i: index): |
| 33 |
%buffer = fir.allocmem !fir.char<1,20> |
| 34 |
%must_free = arith.constant true |
| 35 |
%expr = hlfir.as_expr %buffer move %must_free: (!fir.heap<!fir.char<1,20>>, i1) -> !hlfir.expr<!fir.char<1,20>> |
| 36 |
hlfir.yield_element %expr : !hlfir.expr<!fir.char<1,20>> |
| 37 |
} |
| 38 |
return |
| 39 |
} |
| 40 |
// CHECK-LABEL: func.func @test_elemental( |
| 41 |
// CHECK: fir.do_loop |
| 42 |
// CHECK: %[[VAL_9:.*]] = fir.allocmem !fir.char<1,20> |
| 43 |
// CHECK: hlfir.assign %[[VAL_9]] to %{{.*}} : !fir.heap<!fir.char<1,20>>, !fir.ref<!fir.char<1,20>> |
| 44 |
// CHECK: fir.freemem %[[VAL_9]] : !fir.heap<!fir.char<1,20>> |
| 45 |
// CHECK: } |
| 46 |
// CHECK: return |
| 47 |
|
| 48 |
func.func @test_elemental_expr_created_outside_of_loops() { |
| 49 |
%buffer = fir.allocmem !fir.char<1,20> |
| 50 |
%must_free = arith.constant true |
| 51 |
%expr = hlfir.as_expr %buffer move %must_free: (!fir.heap<!fir.char<1,20>>, i1) -> !hlfir.expr<!fir.char<1,20>> |
| 52 |
%c100 = arith.constant 100 : index |
| 53 |
%c20 = arith.constant 20 : index |
| 54 |
%0 = fir.shape %c100 : (index) -> !fir.shape<1> |
| 55 |
%3 = hlfir.elemental %0 typeparams %c20 : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1,20>> { |
| 56 |
^bb0(%i: index): |
| 57 |
// No freemem should be inserted inside the loops. |
| 58 |
hlfir.yield_element %expr : !hlfir.expr<!fir.char<1,20>> |
| 59 |
} |
| 60 |
hlfir.destroy %expr : !hlfir.expr<!fir.char<1,20>> |
| 61 |
return |
| 62 |
} |
| 63 |
// CHECK-LABEL: func.func @test_elemental_expr_created_outside_of_loops() { |
| 64 |
// CHECK: %[[VAL_9:.*]] = fir.allocmem !fir.char<1,20> |
| 65 |
// CHECK: fir.do_loop |
| 66 |
// CHECK: hlfir.assign %[[VAL_9]] to %{{.*}} : !fir.heap<!fir.char<1,20>>, !fir.ref<!fir.char<1,20>> |
| 67 |
// CHECK-NOT: fir.freemem |
| 68 |
// CHECK: } |
| 69 |
// CHECK: fir.freemem %[[VAL_9]] : !fir.heap<!fir.char<1,20>> |
| 70 |
// CHECK: return |