[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz closed 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits

kparzysz wrote:

Hey @erichkeane, do you have anything to add?  I have replaced `leafs` in the 
.td file with `leafConstructs`, and with `leaves` elsewhere.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits


@@ -435,6 +450,217 @@ static void GenerateIsAllowedClause(const 
DirectiveLanguage ,
   OS << "}\n"; // End of function isAllowedClauseForDirective
 }
 
+// Generate the getLeafConstructs function implementation.
+static void GenerateGetLeafConstructs(const DirectiveLanguage ,
+  raw_ostream ) {
+  auto getQualifiedName = [&](StringRef Formatted) -> std::string {
+return (llvm::Twine("llvm::") + DirLang.getCppNamespace() +
+"::Directive::" + DirLang.getDirectivePrefix() + Formatted)
+.str();
+  };
+
+  // For each list of leaves, generate a static local object, then
+  // return a reference to that object for a given directive, e.g.
+  //
+  //   static ListTy leafConstructs_A_B = { A, B };
+  //   static ListTy leafConstructs_C_D_E = { C, D, E };
+  //   switch (Dir) {
+  // case A_B:
+  //   return leafConstructs_A_B;
+  // case C_D_E:
+  //   return leafConstructs_C_D_E;
+  //   }
+
+  // Map from a record that defines a directive to the name of the
+  // local object with the list of its leaves.
+  DenseMap ListNames;
+
+  std::string DirectiveTypeName =
+  std::string("llvm::") + DirLang.getCppNamespace().str() + "::Directive";
+
+  OS << '\n';
+
+  // ArrayRef<...> llvmGetLeafConstructs(llvmDirective Dir)
+  OS << "llvm::ArrayRef<" << DirectiveTypeName
+ << "> llvm::" << DirLang.getCppNamespace() << "::getLeafConstructs("
+ << DirectiveTypeName << " Dir) ";
+  OS << "{\n";
+
+  // Generate the locals.
+  for (Record *R : DirLang.getDirectives()) {
+Directive Dir{R};
+
+std::vector LeafConstructs = Dir.getLeafConstructs();
+if (LeafConstructs.empty())
+  continue;
+
+std::string ListName = "leafConstructs_" + Dir.getFormattedName();
+OS << "  static const " << DirectiveTypeName << ' ' << ListName
+   << "[] = {\n";
+for (Record *L : LeafConstructs) {
+  Directive LeafDir{L};
+  OS << "" << getQualifiedName(LeafDir.getFormattedName()) << ",\n";
+}
+OS << "  };\n";

kparzysz wrote:

Yes,
```
static const llvm::omp::Directive[] = {...};
```

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits


@@ -342,4 +359,22 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:llvm_unreachable("Invalid Tdl Directive kind");
 // IMPL-NEXT:  }
 // IMPL-EMPTY:
+// IMPL-NEXT:  llvm::ArrayRef 
llvm::tdl::getLeafConstructs(llvm::tdl::Directive Dir) {
+// IMPL-NEXT:static llvm::ArrayRef nothing {};

kparzysz wrote:

Returning an empty ArrayRef by value now.  I can't use regular array (as in the 
case of non-empty sets), because I can't create a zero-length array.  The empty 
ArrayRef does not refer to any storage, so returning it by value should be ok.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/9] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-06 Thread Krzysztof Parzyszek via cfe-commits


@@ -342,4 +359,22 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:llvm_unreachable("Invalid Tdl Directive kind");
 // IMPL-NEXT:  }
 // IMPL-EMPTY:
+// IMPL-NEXT:  llvm::ArrayRef 
llvm::tdl::getLeafConstructs(llvm::tdl::Directive Dir) {
+// IMPL-NEXT:static llvm::ArrayRef nothing {};

kparzysz wrote:

Eh, sorry, it's a mistake.  Thanks for the catch.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/8] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

kparzysz wrote:

I've changed it.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/7] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

kparzysz wrote:

Uh, the "leafs" is only used as a local variable name, the function name has 
singular "Leaf".

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Erich Keane via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

erichkeane wrote:

'strongly prefer'?  No.  Mildly? Yeah, mildly.  Perhaps slightly more than 
mildly because it is in an API and I'd prefer we be consistent with the 'more 
common' spelling.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

kparzysz wrote:

If you strongly prefer the more conformist spelling, I can change it...  :)

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Erich Keane via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

erichkeane wrote:

Huh, interestingly, that Merriam Webster link is the only one I can find that 
acknowledges `leafs` as a plural for the general case.  The only other case I 
could find was wiktionary: https://en.wiktionary.org/wiki/leaf

Which shows that `leafs` is valid in 2 cases: when talking about multi-section 
doors, or when used as a pejorative for a Canadian.  So I don't really know 
anything anymore.

That said, while LLVM's policy is only 'english' and doesn't specify American, 
Canadian, or British English, by practice we use American English spellings for 
things.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits


@@ -435,6 +450,213 @@ static void GenerateIsAllowedClause(const 
DirectiveLanguage ,
   OS << "}\n"; // End of function isAllowedClauseForDirective
 }
 
+// Generate the getLeafConstructs function implementation.
+static void GenerateGetLeafConstructs(const DirectiveLanguage ,
+  raw_ostream ) {
+  auto getQualifiedName = [&](StringRef Formatted) -> std::string {
+return (llvm::Twine("llvm::") + DirLang.getCppNamespace() +
+"::Directive::" + DirLang.getDirectivePrefix() + Formatted)
+.str();
+  };
+
+  // For each list of leafs, generate a static local object, then
+  // return a reference to that object for a given directive, e.g.
+  //
+  //   static ListTy leafConstructs_A_B = { A, B };

kparzysz wrote:

Done.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/6] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

kparzysz wrote:

Merriam-Webster is more oriented towards American English.  The [entry for 
leaf](https://www.merriam-webster.com/dictionary/leaf) shows "leafs" as an 
alternative plural form.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Sergio Afonso via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

skatrak wrote:

> Leafs is an accepted form.

Could you point to some source where that's described? After a quick search, I 
find that "leaves" is the widely accepted plural of "leaf", and that "leafs" is 
only recognized by certain dictionaries. One instance where it's not: 
https://dictionary.cambridge.org/dictionary/english/leaf.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper , 
raw_ostream ) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector (Directive 
D);\n";

kparzysz wrote:

That's about input parameters (because then we don't restrict what objects can 
be passed, i.e. converted to an ArrayRef).  For return values it doesn't 
matter, at least from the point of view of interface flexibility.  The static 
constructor issue you pointed out will need this though.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -435,6 +450,213 @@ static void GenerateIsAllowedClause(const 
DirectiveLanguage ,
   OS << "}\n"; // End of function isAllowedClauseForDirective
 }
 
+// Generate the getLeafConstructs function implementation.
+static void GenerateGetLeafConstructs(const DirectiveLanguage ,
+  raw_ostream ) {
+  auto getQualifiedName = [&](StringRef Formatted) -> std::string {
+return (llvm::Twine("llvm::") + DirLang.getCppNamespace() +
+"::Directive::" + DirLang.getDirectivePrefix() + Formatted)
+.str();
+  };
+
+  // For each list of leafs, generate a static local object, then
+  // return a reference to that object for a given directive, e.g.
+  //
+  //   static ListTy leafConstructs_A_B = { A, B };

kparzysz wrote:

Sure, will do.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -435,6 +450,213 @@ static void GenerateIsAllowedClause(const 
DirectiveLanguage ,
   OS << "}\n"; // End of function isAllowedClauseForDirective
 }
 
+// Generate the getLeafConstructs function implementation.
+static void GenerateGetLeafConstructs(const DirectiveLanguage ,
+  raw_ostream ) {
+  auto getQualifiedName = [&](StringRef Formatted) -> std::string {
+return (llvm::Twine("llvm::") + DirLang.getCppNamespace() +
+"::Directive::" + DirLang.getDirectivePrefix() + Formatted)
+.str();
+  };
+
+  // For each list of leafs, generate a static local object, then
+  // return a reference to that object for a given directive, e.g.
+  //
+  //   static ListTy leafConstructs_A_B = { A, B };

alexey-bataev wrote:

Looks like this approach breaks 
https://llvm.org/docs/CodingStandards.html#do-not-use-static-constructors. 
Better to avoid static SmallVectors (IIUC you're creating static SmallVector 
vars here) and use POD instead to avoid use of static constructors/destructors.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper , 
raw_ostream ) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector (Directive 
D);\n";

alexey-bataev wrote:

Read the documentation 
https://llvm.org/docs/ProgrammersManual.html#llvm-adt-arrayref-h

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper , 
raw_ostream ) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector (Directive 
D);\n";

kparzysz wrote:

I'm expecting you to be more professional in your replies.  I'm simply trying 
to understand your motivation here.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper , 
raw_ostream ) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector (Directive 
D);\n";

alexey-bataev wrote:

No, it is not.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper , 
raw_ostream ) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector (Directive 
D);\n";

kparzysz wrote:

The ArrayRef will be the temporary object.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper , 
raw_ostream ) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector (Directive 
D);\n";

alexey-bataev wrote:

No, it won't. ArrayRef is not an owning container, so it does not create a copy.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +617,45 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto Leafs = getLeafConstructs(DKind);

kparzysz wrote:

Done

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/5] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper , 
raw_ostream ) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector (Directive 
D);\n";

kparzysz wrote:

I don't think this is a good idea.  Returning a reference is pretty much free, 
Returning an ArrayRef will always create a temporary object.  You can always 
use ArrayRef in the caller, if that's what's desired there.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper , 
raw_ostream ) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector (Directive 
D);\n";

alexey-bataev wrote:

```suggestion
  OS << "ArrayRef getLeafConstructs(Directive D);\n";
```


https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -665,60 +617,45 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto Leafs = getLeafConstructs(DKind);

alexey-bataev wrote:

Expand auto here and in other places (ArrayRef)

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -341,5 +356,19 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:}
 // IMPL-NEXT:llvm_unreachable("Invalid Tdl Directive kind");
 // IMPL-NEXT:  }
+// IMPL-NEXT:  const llvm::SmallVector 
::tdl::getLeafConstructs(llvm::tdl::Directive Dir) {

alexey-bataev wrote:

```suggestion
// IMPL-NEXT:  ArrayRef 
llvm::tdl::getLeafConstructs(llvm::tdl::Directive Dir) {
```


https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/4] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_parallel_workshare)
+return false;

kparzysz wrote:

I removed the check.  Formally, it does fall under the "parallel" family of 
directives, so I think we shouldn't exclude it on the basis that it will never 
show up.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Kiran Chandramohan via cfe-commits


@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_parallel_workshare)
+return false;

kiranchandramohan wrote:

Nit: A comment that workshare is not applicable to C/C++ might be helpful.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan approved this pull request.

> Add members "leafs" and "association" to .td describing OpenMP/ACC 
> directives: "leafs" are the leaf constructs for composite/combined 
> constructs, and "association" is the source language construct to which the 
> directive applies (e.g. loop, block, etc.)

Could you clarify that these are terminology used in the OpenMP standard?

Great work @kparzysz.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/3] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-02 Thread Krzysztof Parzyszek via cfe-commits

kparzysz wrote:

The failing test on Windows is unrelated.  I've seen it fail in other builds 
before.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-02 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/3] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);
+  return !leafs.empty() && leafs.front() == OMPD_teams;
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
-  return isOpenMPNestingTeamsDirective(DKind) || DKind == OMPD_target_teams ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_teams_loop;
+  return DKind == OMPD_teams ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
 }
 
 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd;
+  // Avoid OMPD_declare_simd
+  if (DKind == OMPD_end_do_simd ||

kparzysz wrote:

Removed.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

kparzysz wrote:

Leafs is an accepted form.  I used to live in Toronto, btw.  :)

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/3] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Erich Keane via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

erichkeane wrote:

Plural of 'leaf' is 'leaves'.  'leafs' is a canadian hockey team :D 

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval approved this pull request.

Looks good to me from the OpenACC point of view. Someone from OpenMP should 
approve as well.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits

kparzysz wrote:

I removed the check for `end do simd` with a comment that it can't appear in 
clang.  I think you deleted that remark, let me know if I should bring the 
check back.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);
+  return !leafs.empty() && leafs.front() == OMPD_teams;
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
-  return isOpenMPNestingTeamsDirective(DKind) || DKind == OMPD_target_teams ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_teams_loop;
+  return DKind == OMPD_teams ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
 }
 
 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd;
+  // Avoid OMPD_declare_simd
+  if (DKind == OMPD_end_do_simd ||
+  getDirectiveAssociation(DKind) != Association::Loop)
+return false;
+
+  return DKind == OMPD_simd ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_simd);
 }
 
 bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
-  return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for ||
- Kind == OMPD_distribute_parallel_for_simd ||
- Kind == OMPD_distribute_simd;
-  // TODO add next directives.
+  if (Kind == OMPD_distribute)
+return true;
+  auto leafs = getLeafConstructs(Kind);
+  return !leafs.empty() && leafs.front() == OMPD_distribute;
 }
 
 bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
-  return isOpenMPNestingDistributeDirective(Kind) ||
- Kind == OMPD_teams_distribute || Kind == OMPD_teams_distribute_simd ||
- Kind == OMPD_teams_distribute_parallel_for_simd ||
- Kind == OMPD_teams_distribute_parallel_for ||
- Kind == OMPD_target_teams_distribute ||
- Kind == OMPD_target_teams_distribute_parallel_for ||
- Kind == OMPD_target_teams_distribute_parallel_for_simd ||
- Kind == OMPD_target_teams_distribute_simd;
+  return Kind == OMPD_distribute ||
+ llvm::is_contained(getLeafConstructs(Kind), OMPD_distribute);
 }
 
 bool clang::isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind) {
-  return Kind == OMPD_loop || Kind == OMPD_teams_loop ||
- Kind == OMPD_target_teams_loop || Kind == OMPD_parallel_loop ||
- Kind == OMPD_target_parallel_loop;
+  if (Kind == OMPD_loop)
+return true;
+  auto leafs = getLeafConstructs(Kind);

kparzysz wrote:

Done

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);
+  return !leafs.empty() && leafs.front() == OMPD_teams;
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
-  return isOpenMPNestingTeamsDirective(DKind) || DKind == OMPD_target_teams ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_teams_loop;
+  return DKind == OMPD_teams ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
 }
 
 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd;
+  // Avoid OMPD_declare_simd
+  if (DKind == OMPD_end_do_simd ||
+  getDirectiveAssociation(DKind) != Association::Loop)
+return false;
+
+  return DKind == OMPD_simd ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_simd);
 }
 
 bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
-  return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for ||
- Kind == OMPD_distribute_parallel_for_simd ||
- Kind == OMPD_distribute_simd;
-  // TODO add next directives.
+  if (Kind == OMPD_distribute)
+return true;
+  auto leafs = getLeafConstructs(Kind);

kparzysz wrote:

Done

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

kparzysz wrote:

Done

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/2] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH] [Frontend] Add leaf constructs and association to OpenMP/ACC
 directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Alexey Bataev via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);
+  return !leafs.empty() && leafs.front() == OMPD_teams;
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
-  return isOpenMPNestingTeamsDirective(DKind) || DKind == OMPD_target_teams ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_teams_loop;
+  return DKind == OMPD_teams ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
 }
 
 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd;
+  // Avoid OMPD_declare_simd
+  if (DKind == OMPD_end_do_simd ||
+  getDirectiveAssociation(DKind) != Association::Loop)
+return false;
+
+  return DKind == OMPD_simd ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_simd);
 }
 
 bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
-  return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for ||
- Kind == OMPD_distribute_parallel_for_simd ||
- Kind == OMPD_distribute_simd;
-  // TODO add next directives.
+  if (Kind == OMPD_distribute)
+return true;
+  auto leafs = getLeafConstructs(Kind);
+  return !leafs.empty() && leafs.front() == OMPD_distribute;
 }
 
 bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
-  return isOpenMPNestingDistributeDirective(Kind) ||
- Kind == OMPD_teams_distribute || Kind == OMPD_teams_distribute_simd ||
- Kind == OMPD_teams_distribute_parallel_for_simd ||
- Kind == OMPD_teams_distribute_parallel_for ||
- Kind == OMPD_target_teams_distribute ||
- Kind == OMPD_target_teams_distribute_parallel_for ||
- Kind == OMPD_target_teams_distribute_parallel_for_simd ||
- Kind == OMPD_target_teams_distribute_simd;
+  return Kind == OMPD_distribute ||
+ llvm::is_contained(getLeafConstructs(Kind), OMPD_distribute);
 }
 
 bool clang::isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind) {
-  return Kind == OMPD_loop || Kind == OMPD_teams_loop ||
- Kind == OMPD_target_teams_loop || Kind == OMPD_parallel_loop ||
- Kind == OMPD_target_parallel_loop;
+  if (Kind == OMPD_loop)
+return true;
+  auto leafs = getLeafConstructs(Kind);

alexey-bataev wrote:

Leafs

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Alexey Bataev via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);
+  return !leafs.empty() && leafs.front() == OMPD_teams;
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
-  return isOpenMPNestingTeamsDirective(DKind) || DKind == OMPD_target_teams ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_teams_loop;
+  return DKind == OMPD_teams ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
 }
 
 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd;
+  // Avoid OMPD_declare_simd
+  if (DKind == OMPD_end_do_simd ||
+  getDirectiveAssociation(DKind) != Association::Loop)
+return false;
+
+  return DKind == OMPD_simd ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_simd);
 }
 
 bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
-  return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for ||
- Kind == OMPD_distribute_parallel_for_simd ||
- Kind == OMPD_distribute_simd;
-  // TODO add next directives.
+  if (Kind == OMPD_distribute)
+return true;
+  auto leafs = getLeafConstructs(Kind);

alexey-bataev wrote:

Leafs

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Alexey Bataev via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);
+  return !leafs.empty() && leafs.front() == OMPD_teams;
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
-  return isOpenMPNestingTeamsDirective(DKind) || DKind == OMPD_target_teams ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_teams_loop;
+  return DKind == OMPD_teams ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
 }
 
 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd;
+  // Avoid OMPD_declare_simd
+  if (DKind == OMPD_end_do_simd ||

alexey-bataev wrote:

There is no OMPD_end_do_simd in clang

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Alexey Bataev via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

alexey-bataev wrote:

Leafs

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff d01576bb6033865c20a4c0da581939dcae5b30be 
544b309d77a7094d35794e574a1a1d12438021cd -- clang/lib/Basic/OpenMPKinds.cpp 
llvm/include/llvm/TableGen/DirectiveEmitter.h 
llvm/utils/TableGen/DirectiveEmitter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/TableGen/DirectiveEmitter.h 
b/llvm/include/llvm/TableGen/DirectiveEmitter.h
index 208d3bac5b..4805183507 100644
--- a/llvm/include/llvm/TableGen/DirectiveEmitter.h
+++ b/llvm/include/llvm/TableGen/DirectiveEmitter.h
@@ -130,9 +130,7 @@ public:
 return Def->getValueAsListOfDefs("leafs");
   }
 
-  Record *getAssociation() const {
-return Def->getValueAsDef("association");
-  }
+  Record *getAssociation() const { return Def->getValueAsDef("association"); }
 };
 
 // Wrapper class that contains Clause's information defined in DirectiveBase.td

``




https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krzysztof Parzyszek (kparzysz)


Changes

Add members "leafs" and "association" to .td describing OpenMP/ACC directives: 
"leafs" are the leaf constructs for composite/combined constructs, and 
"association" is the source language construct to which the directive applies 
(e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D) plus "enum class Association", all in namespaces 
"llvm::omp" and "llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct that is 
itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions in clang.

---

Patch is 53.90 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/83625.diff


6 Files Affected:

- (modified) clang/lib/Basic/OpenMPKinds.cpp (+34-96) 
- (modified) llvm/include/llvm/Frontend/Directive/DirectiveBase.td (+36) 
- (modified) llvm/include/llvm/Frontend/OpenACC/ACC.td (+25-2) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+152-20) 
- (modified) llvm/include/llvm/TableGen/DirectiveEmitter.h (+12) 
- (modified) llvm/utils/TableGen/DirectiveEmitter.cpp (+232-4) 


``diff
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Krzysztof Parzyszek via cfe-commits

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

Add members "leafs" and "association" to .td describing OpenMP/ACC directives: 
"leafs" are the leaf constructs for composite/combined constructs, and 
"association" is the source language construct to which the directive applies 
(e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D) plus "enum class Association", all in namespaces 
"llvm::omp" and "llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct that is 
itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions in clang.

>From 544b309d77a7094d35794e574a1a1d12438021cd Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH] [Frontend] Add leaf constructs and association to OpenMP/ACC
 directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  12 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 491 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind ==