[flang-commits] [flang] [llvm] [Flang] Adding lowering for the allocation and deallocation of coarrays (PR #182110)
Jean-Didier PAILLEUX via flang-commits
flang-commits at lists.llvm.org
Mon Mar 16 05:23:03 PDT 2026
================
@@ -0,0 +1,74 @@
+! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s
+
+! CHECK: fir.global @_QMtestEcount_i_test : i32
+module test
+ integer :: count_i_test[*]
+end module
+
+! CHECK-LABEL: func.func @_QPtest_save_coarray
+subroutine test_save_coarray()
+ use test
+ implicit none
+ integer, save :: count_i[*] = 0
+
+ count_i = count_i + 1
+ count_i_test = count_i_test + 1
+
+ ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.array<0xi64>
+ ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.array<1xi64>
+ ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.array<0xi64>
+ ! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.array<1xi64>
+ ! CHECK: %[[VAL_4:.*]] = fir.dummy_scope : !fir.dscope
+ ! CHECK: %[[VAL_5:.*]] = fir.address_of(@_QFtest_save_coarrayEcount_i) : !fir.ref<i32>
+ ! CHECK: %[[C1_I64:.*]] = arith.constant 1 : i64
+ ! CHECK: %[[C0:.*]] = arith.constant 0 : index
+ ! CHECK: %[[VAL_6:.*]] = fir.coordinate_of %[[VAL_3]], %[[C0]] : (!fir.ref<!fir.array<1xi64>>, index) -> !fir.ref<i64>
+ ! CHECK: fir.store %[[C1_I64]] to %[[VAL_6]] : !fir.ref<i64>
+ ! CHECK: %[[VAL_7:.*]] = fir.embox %[[VAL_3]] : (!fir.ref<!fir.array<1xi64>>) -> !fir.box<!fir.array<1xi64>>
+ ! CHECK: %[[VAL_8:.*]] = fir.embox %[[VAL_2]] : (!fir.ref<!fir.array<0xi64>>) -> !fir.box<!fir.array<0xi64>>
+ ! CHECK: mif.alloc_coarray %[[VAL_5]] lcobounds %[[VAL_7]] ucobounds %[[VAL_8]] {uniq_name = "_QFtest_save_coarrayEcount_i"} : (!fir.ref<i32>, !fir.box<!fir.array<1xi64>>, !fir.box<!fir.array<0xi64>>) -> ()
+ ! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_5]] {uniq_name = "_QFtest_save_coarrayEcount_i"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+ ! CHECK: %[[VAL_10:.*]] = fir.address_of(@_QMtestEcount_i_test) : !fir.ref<i32>
+ ! CHECK: %[[C1_I64_0:.*]] = arith.constant 1 : i64
+ ! CHECK: %[[C0_1:.*]] = arith.constant 0 : index
+ ! CHECK: %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_1]], %[[C0_1]] : (!fir.ref<!fir.array<1xi64>>, index) -> !fir.ref<i64>
+ ! CHECK: fir.store %[[C1_I64_0]] to %[[VAL_11]] : !fir.ref<i64>
+ ! CHECK: %[[VAL_12:.*]] = fir.embox %[[VAL_1]] : (!fir.ref<!fir.array<1xi64>>) -> !fir.box<!fir.array<1xi64>>
+ ! CHECK: %[[VAL_13:.*]] = fir.embox %0 : (!fir.ref<!fir.array<0xi64>>) -> !fir.box<!fir.array<0xi64>>
+ ! CHECK: mif.alloc_coarray %[[VAL_10]] lcobounds %[[VAL_12]] ucobounds %[[VAL_13]] {uniq_name = "_QMtestEcount_i_test"} : (!fir.ref<i32>, !fir.box<!fir.array<1xi64>>, !fir.box<!fir.array<0xi64>>) -> ()
+ ! CHECK: %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_10]] {uniq_name = "_QMtestEcount_i_test"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
----------------
JDPailleux wrote:
Actually, that seems much more complicated to handle to me, especially collecting all the SAVE coarrays in the external modules. I think it makes sense to put those on the TODO (as you recommend) list for now, especially if we want to get a first version of the allocation (even if its for simple cases).
https://github.com/llvm/llvm-project/pull/182110
More information about the flang-commits
mailing list