[PATCH] D120460: [flang] Fix lowering OpenMP/OpenACC declarative constructs in non-module unit

Peixin Qiao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 24 00:28:26 PST 2022


peixin created this revision.
peixin added reviewers: jeanPerier, PeteSteinfeld, schweitz, klausler, clementval, kiranchandramohan, Chuanfeng, bryanpkc, arnamoy10.
peixin added a project: Flang.
Herald added subscribers: mehdi_amini, jdoerfert, guansong, yaxunl.
peixin requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.

Only pop the evaluation and need to do the exit process when the 
OpenMP/OpenACC declarative construct is used in module unit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120460

Files:
  flang/lib/Lower/PFTBuilder.cpp
  flang/test/Lower/pre-fir-tree06.f90


Index: flang/test/Lower/pre-fir-tree06.f90
===================================================================
--- flang/test/Lower/pre-fir-tree06.f90
+++ flang/test/Lower/pre-fir-tree06.f90
@@ -10,3 +10,30 @@
 end
 ! CHECK: End ModuleLike
 
+! CHECK: Program main
+program main
+  real :: y
+  ! CHECK-NEXT: OpenMPDeclarativeConstruct
+  !$omp threadprivate(y)
+end
+! CHECK: End Program main
+
+! CHECK: Subroutine sub1
+subroutine sub1()
+  real, save :: p
+  ! CHECK-NEXT: OpenMPDeclarativeConstruct
+  !$omp threadprivate(p)
+end
+! CHECK: End Subroutine sub1
+
+! CHECK: Subroutine sub2
+subroutine sub2()
+  real, save :: q
+  ! CHECK-NEXT: OpenMPDeclarativeConstruct
+  !$omp threadprivate(q)
+contains
+  subroutine sub()
+  end
+end
+! CHECK: End Subroutine sub2
+
Index: flang/lib/Lower/PFTBuilder.cpp
===================================================================
--- flang/lib/Lower/PFTBuilder.cpp
+++ flang/lib/Lower/PFTBuilder.cpp
@@ -161,7 +161,8 @@
     } else if constexpr (lower::pft::isConstruct<A> ||
                          lower::pft::isDirective<A>) {
       if constexpr (lower::pft::isDeclConstruct<A>)
-        return;
+        if (pftParentStack.back().getIf<lower::pft::ModuleLikeUnit>())
+          return;
       exitConstructOrDirective();
     }
   }
@@ -317,10 +318,12 @@
     pftParentStack.emplace_back(eval);
     constructAndDirectiveStack.emplace_back(&eval);
     if constexpr (lower::pft::isDeclConstruct<A>) {
-      popEvaluationList();
-      pftParentStack.pop_back();
-      constructAndDirectiveStack.pop_back();
-      popEvaluationList();
+      if (pftParentStack.back().getIf<lower::pft::ModuleLikeUnit>()) {
+        popEvaluationList();
+        pftParentStack.pop_back();
+        constructAndDirectiveStack.pop_back();
+        popEvaluationList();
+      }
     }
     return true;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120460.411025.patch
Type: text/x-patch
Size: 1850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220224/29f3f491/attachment.bin>


More information about the llvm-commits mailing list