[clang] a1dfe15 - [clang][OpenMP] Simplify check for taskloop in `ActOnOpenMPLoopInitia… (#98633)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 06:53:18 PDT 2024


Author: Krzysztof Parzyszek
Date: 2024-07-15T08:53:14-05:00
New Revision: a1dfe15632170342ae073d7238294dfe224682ed

URL: https://github.com/llvm/llvm-project/commit/a1dfe15632170342ae073d7238294dfe224682ed
DIFF: https://github.com/llvm/llvm-project/commit/a1dfe15632170342ae073d7238294dfe224682ed.diff

LOG: [clang][OpenMP] Simplify check for taskloop in `ActOnOpenMPLoopInitia… (#98633)

…lization`

Replace the explicit list of compound directives ending with taskloop
with checking for the last leaf construct.

Added: 
    

Modified: 
    clang/lib/Sema/SemaOpenMP.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index cde27530e9bac..c1a58fc7f2076 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9090,14 +9090,15 @@ void SemaOpenMP::ActOnOpenMPLoopInitialization(SourceLocation ForLoc,
           isOpenMPSimdDirective(DKind)
               ? (DSAStack->hasMutipleLoops() ? OMPC_lastprivate : OMPC_linear)
               : OMPC_private;
+      auto IsOpenMPTaskloopDirective = [](OpenMPDirectiveKind DK) {
+        return getLeafConstructsOrSelf(DK).back() == OMPD_taskloop;
+      };
       if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
             DVar.CKind != PredeterminedCKind && DVar.RefExpr &&
             (getLangOpts().OpenMP <= 45 ||
              (DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_private))) ||
-           ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop ||
-             DKind == OMPD_master_taskloop || DKind == OMPD_masked_taskloop ||
-             DKind == OMPD_parallel_master_taskloop ||
-             DKind == OMPD_parallel_masked_taskloop ||
+           ((isOpenMPWorksharingDirective(DKind) ||
+             IsOpenMPTaskloopDirective(DKind) ||
              isOpenMPDistributeDirective(DKind)) &&
             !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
             DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) &&
@@ -18600,14 +18601,22 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
   // worksharing-loop construct, a worksharing-loop SIMD construct, a simd
   // construct, a parallel worksharing-loop construct or a parallel
   // worksharing-loop SIMD construct.
-  if (Modifier == OMPC_REDUCTION_inscan &&
-      (DSAStack->getCurrentDirective() != OMPD_for &&
-       DSAStack->getCurrentDirective() != OMPD_for_simd &&
-       DSAStack->getCurrentDirective() != OMPD_simd &&
-       DSAStack->getCurrentDirective() != OMPD_parallel_for &&
-       DSAStack->getCurrentDirective() != OMPD_parallel_for_simd)) {
-    Diag(ModifierLoc, diag::err_omp_wrong_inscan_reduction);
-    return nullptr;
+  // [5.2:136:1-4] A reduction clause with the inscan reduction-modifier may
+  // only appear on a worksharing-loop construct, a simd construct or a
+  // combined or composite construct for which any of the aforementioned
+  // constructs is a constituent construct and distribute is not a constituent
+  // construct.
+  if (Modifier == OMPC_REDUCTION_inscan) {
+    SmallVector<OpenMPDirectiveKind, 4> LeafOrComposite;
+    ArrayRef<OpenMPDirectiveKind> CurrentLOC = getLeafOrCompositeConstructs(
+        DSAStack->getCurrentDirective(), LeafOrComposite);
+    bool Valid = llvm::any_of(CurrentLOC, [](OpenMPDirectiveKind DK) {
+      return llvm::is_contained({OMPD_for, OMPD_simd, OMPD_for_simd}, DK);
+    });
+    if (!Valid) {
+      Diag(ModifierLoc, diag::err_omp_wrong_inscan_reduction);
+      return nullptr;
+    }
   }
 
   ReductionData RD(VarList.size(), Modifier);


        


More information about the cfe-commits mailing list