Debian Codegraph @

flang/test/Transforms/stack-arrays-lifetime.fir

raw
1 // Test insertion of llvm.lifetime for allocmem turn into alloca with constant size.
2 // RUN: fir-opt --stack-arrays -stack-arrays-lifetime %s | FileCheck %s
3
4 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"} {
5
6 func.func @_QPcst_alloca(%arg0: !fir.ref<!fir.array<100000xf32>> {fir.bindc_name = "x"}) {
7 %c1 = arith.constant 1 : index
8 %c100000 = arith.constant 100000 : index
9 %0 = fir.dummy_scope : !fir.dscope
10 %1 = fir.shape %c100000 : (index) -> !fir.shape<1>
11 %2 = fir.declare %arg0(%1) dummy_scope %0 {uniq_name = "_QFcst_allocaEx"} : (!fir.ref<!fir.array<100000xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<100000xf32>>
12 %3 = fir.allocmem !fir.array<100000xf32> {bindc_name = ".tmp.array", uniq_name = ""}
13 %4 = fir.declare %3(%1) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<100000xf32>>, !fir.shape<1>) -> !fir.heap<!fir.array<100000xf32>>
14 fir.do_loop %arg1 = %c1 to %c100000 step %c1 unordered {
15 %9 = fir.array_coor %2(%1) %arg1 : (!fir.ref<!fir.array<100000xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
16 %10 = fir.load %9 : !fir.ref<f32>
17 %11 = arith.addf %10, %10 fastmath<contract> : f32
18 %12 = fir.array_coor %4(%1) %arg1 : (!fir.heap<!fir.array<100000xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
19 fir.store %11 to %12 : !fir.ref<f32>
20 }
21 %5 = fir.convert %4 : (!fir.heap<!fir.array<100000xf32>>) -> !fir.ref<!fir.array<100000xf32>>
22 fir.call @_QPbar(%5) fastmath<contract> : (!fir.ref<!fir.array<100000xf32>>) -> ()
23 fir.freemem %4 : !fir.heap<!fir.array<100000xf32>>
24 %6 = fir.allocmem !fir.array<100000xi32> {bindc_name = ".tmp.array", uniq_name = ""}
25 %7 = fir.declare %6(%1) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<100000xi32>>, !fir.shape<1>) -> !fir.heap<!fir.array<100000xi32>>
26 fir.do_loop %arg1 = %c1 to %c100000 step %c1 unordered {
27 %9 = fir.array_coor %2(%1) %arg1 : (!fir.ref<!fir.array<100000xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
28 %10 = fir.load %9 : !fir.ref<f32>
29 %11 = fir.convert %10 : (f32) -> i32
30 %12 = fir.array_coor %7(%1) %arg1 : (!fir.heap<!fir.array<100000xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
31 fir.store %11 to %12 : !fir.ref<i32>
32 }
33 %8 = fir.convert %7 : (!fir.heap<!fir.array<100000xi32>>) -> !fir.ref<!fir.array<100000xi32>>
34 fir.call @_QPibar(%8) fastmath<contract> : (!fir.ref<!fir.array<100000xi32>>) -> ()
35 fir.freemem %7 : !fir.heap<!fir.array<100000xi32>>
36 return
37 }
38 // CHECK-LABEL: func.func @_QPcst_alloca(
39 // CHECK-DAG: %[[VAL_0:.*]] = fir.alloca !fir.array<100000xf32> {bindc_name = ".tmp.array", fir.has_lifetime}
40 // CHECK-DAG: %[[VAL_2:.*]] = fir.alloca !fir.array<100000xi32> {bindc_name = ".tmp.array", fir.has_lifetime}
41 // CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<100000xf32>>) -> !llvm.ptr
42 // CHECK: llvm.intr.lifetime.start 400000, %[[VAL_9]] : !llvm.ptr
43 // CHECK: fir.do_loop
44 // CHECK: fir.call @_QPbar(
45 // CHECK: llvm.intr.lifetime.end 400000, %[[VAL_9]] : !llvm.ptr
46 // CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.array<100000xi32>>) -> !llvm.ptr
47 // CHECK: llvm.intr.lifetime.start 400000, %[[VAL_17]] : !llvm.ptr
48 // CHECK: fir.do_loop
49 // CHECK: fir.call @_QPibar(
50 // CHECK: llvm.intr.lifetime.end 400000, %[[VAL_17]] : !llvm.ptr
51
52
53 func.func @_QPdyn_alloca(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i64> {fir.bindc_name = "n"}) {
54 %c1 = arith.constant 1 : index
55 %c0 = arith.constant 0 : index
56 %0 = fir.dummy_scope : !fir.dscope
57 %1 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFdyn_allocaEn"} : (!fir.ref<i64>, !fir.dscope) -> !fir.ref<i64>
58 %2 = fir.load %1 : !fir.ref<i64>
59 %3 = fir.convert %2 : (i64) -> index
60 %4 = arith.cmpi sgt, %3, %c0 : index
61 %5 = arith.select %4, %3, %c0 : index
62 %6 = fir.shape %5 : (index) -> !fir.shape<1>
63 %7 = fir.declare %arg0(%6) dummy_scope %0 {uniq_name = "_QFdyn_allocaEx"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<?xf32>>
64 %8 = fir.allocmem !fir.array<?xf32>, %5 {bindc_name = ".tmp.array", uniq_name = ""}
65 %9 = fir.declare %8(%6) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.heap<!fir.array<?xf32>>
66 fir.do_loop %arg2 = %c1 to %5 step %c1 unordered {
67 %14 = fir.array_coor %7(%6) %arg2 : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
68 %15 = fir.load %14 : !fir.ref<f32>
69 %16 = arith.addf %15, %15 fastmath<contract> : f32
70 %17 = fir.array_coor %9(%6) %arg2 : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
71 fir.store %16 to %17 : !fir.ref<f32>
72 }
73 %10 = fir.convert %9 : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
74 fir.call @_QPbar(%10) fastmath<contract> : (!fir.ref<!fir.array<?xf32>>) -> ()
75 fir.freemem %9 : !fir.heap<!fir.array<?xf32>>
76 %11 = fir.allocmem !fir.array<?xf32>, %5 {bindc_name = ".tmp.array", uniq_name = ""}
77 %12 = fir.declare %11(%6) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.heap<!fir.array<?xf32>>
78 fir.do_loop %arg2 = %c1 to %5 step %c1 unordered {
79 %14 = fir.array_coor %7(%6) %arg2 : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
80 %15 = fir.load %14 : !fir.ref<f32>
81 %16 = arith.mulf %15, %15 fastmath<contract> : f32
82 %17 = fir.array_coor %12(%6) %arg2 : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
83 fir.store %16 to %17 : !fir.ref<f32>
84 }
85 %13 = fir.convert %12 : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
86 fir.call @_QPbar(%13) fastmath<contract> : (!fir.ref<!fir.array<?xf32>>) -> ()
87 fir.freemem %12 : !fir.heap<!fir.array<?xf32>>
88 return
89 }
90 // CHECK-LABEL: func.func @_QPdyn_alloca(
91 // CHECK-NOT: llvm.intr.lifetime.start
92 // CHECK: return
93
94 func.func private @_QPbar(!fir.ref<!fir.array<100000xf32>>)
95 func.func private @_QPibar(!fir.ref<!fir.array<100000xi32>>)
96 }