File: destroy-codegen.fir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (70 lines) | stat: -rw-r--r-- 3,035 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Test hlfir.destroy code generation and hlfir.yield_element "implicit
// hlfir.destroy" aspect.

// RUN: fir-opt %s -bufferize-hlfir | FileCheck %s

func.func @test_move_with_cleanup(%arg0 : !fir.ref<!fir.array<100xi32>>) {
  %must_free = arith.constant true
  %expr = hlfir.as_expr %arg0 move %must_free: (!fir.ref<!fir.array<100xi32>>, i1) -> !hlfir.expr<100xi32>
  hlfir.destroy %expr : !hlfir.expr<100xi32>
  return
}
// CHECK-LABEL:   func.func @test_move_with_cleanup(
// CHECK-SAME:    %[[VAL_0:.*]]: !fir.ref<!fir.array<100xi32>>) {
// CHECK:  %[[VAL_5:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<100xi32>>) -> !fir.heap<!fir.array<100xi32>>
// CHECK:  fir.freemem %[[VAL_5]] : !fir.heap<!fir.array<100xi32>>

func.func @test_move_no_cleanup(%arg0 : !fir.ref<!fir.array<100xi32>>) {
  %must_free = arith.constant false
  %expr = hlfir.as_expr %arg0 move %must_free: (!fir.ref<!fir.array<100xi32>>, i1) -> !hlfir.expr<100xi32>
  hlfir.destroy %expr : !hlfir.expr<100xi32>
  return
}
// CHECK-LABEL:   func.func @test_move_no_cleanup(
// CHECK-NOT:  fir.freemem
// CHECK:  return

func.func @test_elemental() {
  %c100 = arith.constant 100 : index
  %c20 = arith.constant 20 : index
  %0 = fir.shape %c100 : (index) -> !fir.shape<1>
  %3 = hlfir.elemental %0 typeparams %c20 : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1,20>> {
  ^bb0(%i: index):
    %buffer = fir.allocmem !fir.char<1,20>
    %must_free = arith.constant true
    %expr = hlfir.as_expr %buffer move %must_free: (!fir.heap<!fir.char<1,20>>, i1) -> !hlfir.expr<!fir.char<1,20>>
    hlfir.yield_element %expr : !hlfir.expr<!fir.char<1,20>>
  }
  return
}
// CHECK-LABEL:   func.func @test_elemental(
// CHECK:  fir.do_loop
// CHECK:    %[[VAL_9:.*]] = fir.allocmem !fir.char<1,20>
// CHECK:    hlfir.assign %[[VAL_9]] to %{{.*}} : !fir.heap<!fir.char<1,20>>, !fir.ref<!fir.char<1,20>>
// CHECK:    fir.freemem %[[VAL_9]] : !fir.heap<!fir.char<1,20>>
// CHECK:  }
// CHECK:  return

func.func @test_elemental_expr_created_outside_of_loops() {
  %buffer = fir.allocmem !fir.char<1,20>
  %must_free = arith.constant true
  %expr = hlfir.as_expr %buffer move %must_free: (!fir.heap<!fir.char<1,20>>, i1) -> !hlfir.expr<!fir.char<1,20>>
  %c100 = arith.constant 100 : index
  %c20 = arith.constant 20 : index
  %0 = fir.shape %c100 : (index) -> !fir.shape<1>
  %3 = hlfir.elemental %0 typeparams %c20 : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1,20>> {
  ^bb0(%i: index):
    // No freemem should be inserted inside the loops.
    hlfir.yield_element %expr : !hlfir.expr<!fir.char<1,20>>
  }
  hlfir.destroy %expr : !hlfir.expr<!fir.char<1,20>>
  return
}
// CHECK-LABEL:   func.func @test_elemental_expr_created_outside_of_loops() {
// CHECK:  %[[VAL_9:.*]] = fir.allocmem !fir.char<1,20>
// CHECK:  fir.do_loop
// CHECK:    hlfir.assign %[[VAL_9]] to %{{.*}} : !fir.heap<!fir.char<1,20>>, !fir.ref<!fir.char<1,20>>
// CHECK-NOT:  fir.freemem
// CHECK:  }
// CHECK:  fir.freemem %[[VAL_9]] : !fir.heap<!fir.char<1,20>>
// CHECK:  return