[llvm] [Frontend][OpenMP] Allow implicit clauses to fail to apply (PR #100460)

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 24 13:12:58 PDT 2024


https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/100460

The `linear(x)` clause implies `firstprivate(x)` on the compound construct if `x` is not an induction variable. With more construct combinations coming in OpenMP 6.0, the `firstprivate` clause may not be possible to apply, e.g. in "masked simd".
An additional benefit from this change is that it allows treating leaf constructs as combined constructs with a single constituent. Otherwise, a `linear` clause on a `simd` construct could imply a `firstprivate` clause that can't be applied.

>From 37afd4890e14d08824e4a7fde5f1521e405fefc6 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Wed, 24 Jul 2024 13:59:51 -0500
Subject: [PATCH] [Frontend][OpenMP] Allow implicit clauses to fail to apply

The `linear(x)` clause implies `firstprivate(x)` on the compound construct
if `x` is not an induction variable. With more construct combinations
coming in OpenMP 6.0, the `firstprivate` clause may not be possible to
apply, e.g. in "masked simd".
An additional benefit from this change is that it allows treating leaf
constructs as combined constructs with a single constituent. Otherwise,
a `linear` clause on a `simd` construct could imply a `firstprivate`
clause that can't be applied.
---
 .../llvm/Frontend/OpenMP/ConstructDecompositionT.h     | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
index 349d862135d8c..b93bc594a82bf 100644
--- a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
+++ b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
@@ -1114,6 +1114,11 @@ bool ConstructDecompositionT<C, H>::applyClause(
 template <typename C, typename H> bool ConstructDecompositionT<C, H>::split() {
   bool success = true;
 
+  auto isImplicit = [this](const ClauseTy *node) {
+    return llvm::any_of(
+        implicit, [node](const ClauseTy &clause) { return &clause == node; });
+  };
+
   for (llvm::omp::Directive leaf :
        llvm::omp::getLeafConstructsOrSelf(construct))
     leafs.push_back(LeafReprInternal{leaf, /*clauses=*/{}});
@@ -1153,9 +1158,10 @@ template <typename C, typename H> bool ConstructDecompositionT<C, H>::split() {
   for (const ClauseTy *node : nodes) {
     if (skip(node))
       continue;
-    success =
-        success &&
+    bool result =
         std::visit([&](auto &&s) { return applyClause(s, node); }, node->u);
+    if (!isImplicit(node))
+      success = success && result;
   }
 
   // Apply "allocate".



More information about the llvm-commits mailing list