Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LLVM][OpenMP] Add "nowait" clause as valid for "workshare" #88426

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

kparzysz
Copy link
Contributor

@kparzysz kparzysz commented Apr 11, 2024

Add the "nowait" clause to the list of allowed clauses for the "workshare"
directive. This will make it consistent with other directives (which are
shared between C/C++ and Fortran).

The parser will still reject "nowait" on "!$omp workshare", so this has no
effect on accepting/rejecting Fortran source code.

Add the "if" clause to the list of allowed clauses for the "workshare"
directive.
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 11, 2024

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)

Changes

Add the "if" clause to the list of allowed clauses for the "workshare" directive.


Full diff: https://github.com/llvm/llvm-project/pull/88426.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+3)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index d9a931438b4292..e91169e8da1aa5 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -2115,6 +2115,9 @@ def OMP_scope : Directive<"scope"> {
   let association = AS_Block;
 }
 def OMP_Workshare : Directive<"workshare"> {
+  let allowedOnceClauses = [
+    VersionedClause<OMPC_NoWait>
+  ];
   let association = AS_Block;
 }
 def OMP_ParallelWorkshare : Directive<"parallel workshare"> {

Copy link
Member

@carlobertolli carlobertolli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: nowait has been part of OpenMP since 4.5 (or earlier, I didn't check 4.0).
It'd be nice if you added a clang/test/OpenMP minimal test. I checked and I couldn't find a single parse test for the workshare directive.

@kparzysz
Copy link
Contributor Author

kparzysz commented Apr 11, 2024

I can add a flang test for it (clang won't likely handle it, since "workshare" is Fortran-only).

Edit: turns out there is a semantics test for it already (line 339, flang/test/Semantics/OpenMP/clause-validity01.f90):

334 ! 2.7.4 workshare
335
336   !$omp parallel
337   !$omp workshare
338   a = 1.0
339   !$omp end workshare nowait
340   !ERROR: NUM_THREADS clause is not allowed on the WORKSHARE directive
341   !$omp workshare num_threads(4)
342   a = 1.0

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG.

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. It is already there in "End Workshare".

@kparzysz
Copy link
Contributor Author

kparzysz commented Apr 11, 2024

Sorry. It is already there in "End Workshare".

All directives that have "DIR/END DIR" format in Fortran, allow the clauses from the "END DIR" to be present in "DIR" (since there is no "END DIR" in C/C++). Workshare (being Fortran-only) is the only one that doesn't allow it.

Not having the consistency makes it harder to handle OpenMP constructs with language-agnostic code.

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Please wait for @mjklemm or @kkwli before proceeding. If you are going ahead might be good to call this out in https://github.com/llvm/llvm-project/blob/main/flang/docs/Extensions.md

Looking at other compilers. gfortran seems to accept it, ifx and classic flang rejects.

Not having the consistency makes it harder to handle OpenMP constructs with language-agnostic code.

It wasn't clear from the title that this is deviating from the standard specification for ease of implementation.

Add the "if" clause to the list of allowed clauses for the "workshare" directive.

"if" -> "nowait"

@kkwli
Copy link
Collaborator

kkwli commented Apr 11, 2024

As far as I understand, nowait is only allowed on the end workshare directive in the spec. However, I have no objection to extend it to have the clause on the workshare directive as long as it also allowed on the end workshare directive. However, we probably want to add semantic check for having nowait on both workshare and end workshare. How about the copyprivate clause on the single directive?

@kparzysz
Copy link
Contributor Author

It wasn't clear from the title that this is deviating from the standard specification for ease of implementation.

It was a good catch on your side. I was testing my code that relied on this (which I had forgotten about). When I created the PR I honestly thought that this is where the "nowait" clause was supposed to be. Only after you pointed out the "end workshare" when I realized what really happened.

@kparzysz kparzysz changed the title [LLVM][OpenMP] "nowait" clause is valid for "workshare" [LLVM][OpenMP] Add "nowait" clause as valid for "workshare" Apr 11, 2024
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 12, 2024
@kparzysz
Copy link
Contributor Author

However, we probably want to add semantic check for having nowait on both workshare and end workshare. How about the copyprivate clause on the single directive?

The flang parser actually checks for such cases explicitly, and rejects cases of "nowait" on directives that allow it based on the .td contents, but where Fortran syntax requires them to be on the "end" directive. I added "workshare" to the list, and updated the testcase. I have checked that "copyprivate" on "!$omp single" is rejected as well.

In the current form this PR will not have any effect on the accepted syntax, it will simply allow "nowait" to be associated with "workshare" internally to the compiler.

@kparzysz kparzysz merged commit 4078afc into llvm:main Apr 12, 2024
6 checks passed
@kparzysz kparzysz deleted the users/kparzysz/workshare-nowait branch April 12, 2024 19:52
bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
Add the "nowait" clause to the list of allowed clauses for the "workshare"
directive. This will make it consistent with other directives (which are
shared between C/C++ and Fortran).

The parser will still reject "nowait" on "!$omp workshare", so this has no
effect on accepting/rejecting Fortran source code.
@mjklemm
Copy link
Contributor

mjklemm commented Apr 16, 2024

As far as I understand, nowait is only allowed on the end workshare directive in the spec.

Post-merge comment: this was changed with OpenMP 5.2:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:openmp OpenMP related changes to Clang flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants