[flang-commits] [flang] [flang][openacc] Avoid creation of duplicate global ctor (PR #71846)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Thu Nov 9 12:55:08 PST 2023


https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/71846

>From 6fce3bf491d3419db68c56e05f15820e32551ea9 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 9 Nov 2023 11:03:27 -0800
Subject: [PATCH 1/2] [flang][openacc] Avoid creation of duplicate global ctor

---
 flang/lib/Lower/OpenACC.cpp                    | 6 ++++++
 flang/test/Lower/OpenACC/HLFIR/acc-declare.f90 | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 1c045b4273e2607..9c04707f5197f38 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2906,6 +2906,11 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter,
                 std::stringstream asFortran;
                 asFortran << name->symbol->name().ToString();
 
+                if (builder.getModule()
+                        .lookupSymbol<mlir::acc::GlobalConstructorOp>(
+                            declareGlobalCtorName.str()))
+                  return;
+
                 if (!globalOp) {
                   if (Fortran::semantics::FindEquivalenceSet(*name->symbol)) {
                     for (Fortran::semantics::EquivalenceObject eqObj :
@@ -2959,6 +2964,7 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter,
                 }
                 builder.restoreInsertionPoint(crtPos);
               }
+
             },
             [&](const Fortran::parser::Name &name) {
               TODO(operandLocation, "OpenACC Global Ctor from parser::Name");
diff --git a/flang/test/Lower/OpenACC/HLFIR/acc-declare.f90 b/flang/test/Lower/OpenACC/HLFIR/acc-declare.f90
index 6ebdd39802fef0f..7670cd654bf6fd7 100644
--- a/flang/test/Lower/OpenACC/HLFIR/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/HLFIR/acc-declare.f90
@@ -304,3 +304,12 @@ module acc_declare_equivalent2
 ! ALL:         acc.delete accPtr(%[[DEVICEPTR]] : !fir.ref<!fir.array<40xi8>>) {dataClause = #acc<data_clause acc_create>, name = "v2", structured = false}
 ! ALL:         acc.terminator
 ! ALL:       }
+
+module acc_declare_allocatable_test2
+  integer, allocatable :: data1(:)
+  integer, allocatable :: data2(:)
+  !$acc declare create(data1, data2, data1)
+end module
+
+! ALL-LABEL: acc.global_ctor @_QMacc_declare_allocatable_test2Edata1_acc_ctor
+! ALL-LABEL: acc.global_ctor @_QMacc_declare_allocatable_test2Edata2_acc_ctor

>From 2e14d24032615973edba1ec35fa3650aef65c056 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 9 Nov 2023 12:54:55 -0800
Subject: [PATCH 2/2] Remove blank line

---
 flang/lib/Lower/OpenACC.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 9c04707f5197f38..f13fb41d2baffe7 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2964,7 +2964,6 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter,
                 }
                 builder.restoreInsertionPoint(crtPos);
               }
-
             },
             [&](const Fortran::parser::Name &name) {
               TODO(operandLocation, "OpenACC Global Ctor from parser::Name");



More information about the flang-commits mailing list