-
Notifications
You must be signed in to change notification settings - Fork 14.5k
default clause replaced by otherwise clause for metadirective in OpenMP 5.2 #125648
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
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Urvi Rav (ravurvi20) ChangesThis PR replaces the Full diff: https://github.com/llvm/llvm-project/pull/125648.diff 12 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f5..4b8449e9ee9b62 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1657,6 +1657,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
def err_omp_missing_comma : Error< "missing ',' after %0">;
def err_omp_expected_context_selector
: Error<"expected valid context selector in %0">;
+def err_omp_unknown_clause
+ : Error<"unknown clause '%0' in %1">;
+def warn_omp_default_deprecated : Warning<"'default' clause for"
+ " 'metadirective' is deprecated; use 'otherwise' instead">, InGroup<Deprecated>;
def err_omp_requires_out_inout_depend_type : Error<
"reserved locator 'omp_all_memory' requires 'out' or 'inout' "
"dependency types">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 89b83938f352df..673806ef28b9fc 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2743,6 +2743,15 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
+ // Check if the clause is unrecognized.
+ if (CKind == OMPC_unknown) {
+ Diag(Tok, diag::err_omp_unknown_clause)
+ << PP.getSpelling(Tok) << "metadirective";
+ return Directive;
+ }
+ if(CKind == OMPC_default) {
+ Diag(Tok, diag::warn_omp_default_deprecated);
+ }
SourceLocation Loc = ConsumeToken();
// Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
return Directive;
}
}
+ if (CKind == OMPC_otherwise) {
+ // Check for 'otherwise' keyword.
+ if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == "otherwise") {
+ ConsumeToken(); // Consume 'otherwise'
+ }
+ }
// Skip Directive for now. We will parse directive in the second iteration
int paren = 0;
while (Tok.isNot(tok::r_paren) || paren != 0) {
diff --git a/clang/test/OpenMP/metadirective_ast_print.c b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e76452160..28efaac5949427 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -15,18 +15,18 @@ void bar(void);
#define N 10
void foo(void) {
#pragma omp metadirective when(device = {kind(cpu)} \
- : parallel) default()
+ : parallel) otherwise()
bar();
#pragma omp metadirective when(implementation = {vendor(score(0) \
: llvm)}, \
device = {kind(cpu)} \
- : parallel) default(target teams)
+ : parallel) otherwise(target teams)
bar();
#pragma omp metadirective when(device = {kind(gpu)} \
: target teams) when(implementation = {vendor(llvm)} \
- : parallel) default()
+ : parallel) otherwise()
bar();
-#pragma omp metadirective default(target) when(implementation = {vendor(score(5) \
+#pragma omp metadirective otherwise(target) when(implementation = {vendor(score(5) \
: llvm)}, \
device = {kind(cpu, host)} \
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
for (int i = 0; i < 100; i++)
;
#pragma omp metadirective when(implementation = {extension(match_all)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
#pragma omp metadirective when(implementation = {extension(match_any)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
#pragma omp metadirective when(implementation = {extension(match_none)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
@@ -64,17 +64,17 @@ void foo(void) {
#pragma omp metadirective when(device={arch("amdgcn")}: \
teams distribute parallel for)\
- default(parallel for)
+ otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
#pragma omp metadirective when(implementation = {extension(match_all)} \
- : nothing) default(parallel for)
+ : nothing) otherwise(parallel for)
for (int i = 0; i < 16; i++)
;
#pragma omp metadirective when(implementation = {extension(match_any)} \
- : parallel) default(nothing)
+ : parallel) otherwise(nothing)
for (int i = 0; i < 16; i++)
;
}
diff --git a/clang/test/OpenMP/metadirective_device_arch_codegen.cpp b/clang/test/OpenMP/metadirective_device_arch_codegen.cpp
index eecae310d0a778..c44337b33d5b39 100644
--- a/clang/test/OpenMP/metadirective_device_arch_codegen.cpp
+++ b/clang/test/OpenMP/metadirective_device_arch_codegen.cpp
@@ -27,7 +27,7 @@ int metadirective1() {
{
#pragma omp metadirective \
when(device={arch("amdgcn")}: teams distribute parallel for) \
- default(parallel for)
+ otherwise(parallel for)
for (int i = 0; i < N; i++) {
#pragma omp atomic write
diff --git a/clang/test/OpenMP/metadirective_device_isa_codegen.cpp b/clang/test/OpenMP/metadirective_device_isa_codegen.cpp
index 1d098063101d7e..1b9829f7a56cef 100644
--- a/clang/test/OpenMP/metadirective_device_isa_codegen.cpp
+++ b/clang/test/OpenMP/metadirective_device_isa_codegen.cpp
@@ -8,7 +8,7 @@ void bar();
void x86_64_device_isa_selected() {
#pragma omp metadirective when(device = {isa("sse2")} \
- : parallel) default(single)
+ : parallel) otherwise(single)
bar();
}
// CHECK-LABEL: void @_Z26x86_64_device_isa_selectedv()
@@ -21,7 +21,7 @@ void x86_64_device_isa_selected() {
void x86_64_device_isa_not_selected() {
#pragma omp metadirective when(device = {isa("some-unsupported-feature")} \
- : parallel) default(single)
+ : parallel) otherwise(single)
bar();
}
// CHECK-LABEL: void @_Z30x86_64_device_isa_not_selectedv()
diff --git a/clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp b/clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
index cbb75c4a68376a..c2c7b72a8469fd 100644
--- a/clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
+++ b/clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
@@ -15,7 +15,7 @@ int amdgcn_device_isa_selected() {
{
#pragma omp metadirective \
when(device = {isa("dpp")} \
- : parallel) default(single)
+ : parallel) otherwise(single)
threadCount++;
}
@@ -38,7 +38,7 @@ int amdgcn_device_isa_not_selected() {
when(device = {isa("sse")} \
: parallel) \
when(device = {isa("another-unsupported-gpu-feature")} \
- : parallel) default(single)
+ : parallel) otherwise(single)
threadCount++;
}
diff --git a/clang/test/OpenMP/metadirective_device_kind_codegen.c b/clang/test/OpenMP/metadirective_device_kind_codegen.c
index f77f50426a16d4..0a8c54af2effd1 100644
--- a/clang/test/OpenMP/metadirective_device_kind_codegen.c
+++ b/clang/test/OpenMP/metadirective_device_kind_codegen.c
@@ -30,7 +30,7 @@ void foo(void) {
: parallel)
bar();
#pragma omp metadirective when(device = {kind(gpu)} \
- : target parallel for) default(parallel for)
+ : target parallel for) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
}
diff --git a/clang/test/OpenMP/metadirective_device_kind_codegen.cpp b/clang/test/OpenMP/metadirective_device_kind_codegen.cpp
index bfbfec8b27e1e8..446fd646ef17fc 100644
--- a/clang/test/OpenMP/metadirective_device_kind_codegen.cpp
+++ b/clang/test/OpenMP/metadirective_device_kind_codegen.cpp
@@ -31,7 +31,7 @@ void foo() {
: parallel)
bar();
#pragma omp metadirective when(device = {kind(gpu)} \
- : target parallel for) default(parallel for)
+ : target parallel for) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
}
diff --git a/clang/test/OpenMP/metadirective_empty.cpp b/clang/test/OpenMP/metadirective_empty.cpp
index b93ed722cb6e90..9fcd35e82292d9 100644
--- a/clang/test/OpenMP/metadirective_empty.cpp
+++ b/clang/test/OpenMP/metadirective_empty.cpp
@@ -11,12 +11,12 @@ void func() {
// Test where a valid when clause contains empty directive.
// The directive will be ignored and code for a serial for loop will be generated.
#pragma omp metadirective when(implementation = {vendor(llvm)} \
- :) default(parallel for)
+ :) otherwise(parallel for)
for (int i = 0; i < N; i++)
;
#pragma omp metadirective when(implementation = {vendor(llvm)} \
- :nothing) default(parallel for)
+ :nothing) otherwise(parallel for)
for (int i = 0; i < N; i++)
;
}
diff --git a/clang/test/OpenMP/metadirective_implementation_codegen.c b/clang/test/OpenMP/metadirective_implementation_codegen.c
index da09b639d6d409..dc0bcbaebd0992 100644
--- a/clang/test/OpenMP/metadirective_implementation_codegen.c
+++ b/clang/test/OpenMP/metadirective_implementation_codegen.c
@@ -12,27 +12,27 @@ void foo(void) {
#pragma omp metadirective when(implementation = {vendor(score(0) \
: llvm)}, \
device = {kind(cpu)} \
- : parallel) default(target teams)
+ : parallel) otherwise(target teams)
bar();
#pragma omp metadirective when(device = {kind(gpu)} \
: target teams) when(implementation = {vendor(llvm)} \
- : parallel) default()
+ : parallel) otherwise()
bar();
-#pragma omp metadirective default(target) when(implementation = {vendor(score(5) \
+#pragma omp metadirective otherwise(target) when(implementation = {vendor(score(5) \
: llvm)}, \
device = {kind(cpu, host)} \
: parallel)
bar();
#pragma omp metadirective when(implementation = {extension(match_all)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
#pragma omp metadirective when(implementation = {extension(match_any)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
#pragma omp metadirective when(implementation = {extension(match_none)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
}
diff --git a/clang/test/OpenMP/metadirective_implementation_codegen.cpp b/clang/test/OpenMP/metadirective_implementation_codegen.cpp
index b9f43d1a1e87cd..a20b2e2f14bcd4 100644
--- a/clang/test/OpenMP/metadirective_implementation_codegen.cpp
+++ b/clang/test/OpenMP/metadirective_implementation_codegen.cpp
@@ -12,27 +12,27 @@ void foo() {
#pragma omp metadirective when(implementation = {vendor(score(0) \
: llvm)}, \
device = {kind(cpu)} \
- : parallel) default(target teams)
+ : parallel) otherwise(target teams)
bar();
#pragma omp metadirective when(device = {kind(gpu)} \
: target teams) when(implementation = {vendor(llvm)} \
- : parallel) default()
+ : parallel) otherwise()
bar();
-#pragma omp metadirective default(target) when(implementation = {vendor(score(5) \
+#pragma omp metadirective otherwise(target) when(implementation = {vendor(score(5) \
: llvm)}, \
device = {kind(cpu, host)} \
: parallel)
bar();
#pragma omp metadirective when(implementation = {extension(match_all)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
#pragma omp metadirective when(implementation = {extension(match_any)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
#pragma omp metadirective when(implementation = {extension(match_none)} \
- : parallel) default(parallel for)
+ : parallel) otherwise(parallel for)
for (int i = 0; i < 100; i++)
;
}
diff --git a/clang/test/OpenMP/metadirective_messages.cpp b/clang/test/OpenMP/metadirective_messages.cpp
index b342a094a7870a..8a32b36c016d6e 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -11,12 +11,16 @@ void foo() {
;
#pragma omp metadirective when(device{arch(nvptx)}) // expected-error {{missing ':' in when clause}} expected-error {{expected expression}} expected-warning {{expected '=' after the context set name "device"; '=' assumed}}
;
-#pragma omp metadirective when(device{arch(nvptx)}: ) default() // expected-warning {{expected '=' after the context set name "device"; '=' assumed}}
+#pragma omp metadirective when(device{arch(nvptx)}: ) otherwise() // expected-warning {{expected '=' after the context set name "device"; '=' assumed}}
;
-#pragma omp metadirective when(device = {arch(nvptx)} : ) default(xyz) // expected-error {{expected an OpenMP directive}} expected-error {{use of undeclared identifier 'xyz'}}
+#pragma omp metadirective when(device = {arch(nvptx)} : ) otherwise(xyz) // expected-error {{expected an OpenMP directive}} expected-error {{use of undeclared identifier 'xyz'}}
;
-#pragma omp metadirective when(device = {arch(nvptx)} : parallel default() // expected-error {{expected ',' or ')' in 'when' clause}} expected-error {{expected expression}}
+#pragma omp metadirective when(device = {arch(nvptx)} : parallel otherwise() // expected-error {{expected ',' or ')' in 'when' clause}} expected-error {{expected expression}}
;
-#pragma omp metadirective when(device = {isa("some-unsupported-feature")} : parallel) default(single) // expected-warning {{isa trait 'some-unsupported-feature' is not known to the current target; verify the spelling or consider restricting the context selector with the 'arch' selector further}}
+#pragma omp metadirective when(device = {isa("some-unsupported-feature")} : parallel) otherwise(single) // expected-warning {{isa trait 'some-unsupported-feature' is not known to the current target; verify the spelling or consider restricting the context selector with the 'arch' selector further}}
+ ;
+#pragma omp metadirective when(device = {arch(nvptx)} : parallel) default() // expected-warning {{'default' clause for 'metadirective' is deprecated; use 'otherwise' instead}}
+ ;
+#pragma omp metadirective when(device = {arch(nvptx)} : parallel) xyz() //expected-error {{unknown clause 'xyz' in metadirective}} expected-error {{use of undeclared identifier 'xyz'}} expected-error {{expected expression}} expected-error {{expected ';' after expression}}
;
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. May I suggest to also test for the old spelling with default
and test that the compiler issues the warning?
Thank you for this patch. I wonder: was this spelling change introduced in 5.2? If so, does the compiler after this patch still support the 5.1 spelling when providing this as the OpenMP version ( |
I have addressed this in the metadirective_messages.cpp test case. If the default clause is used in OpenMP 5.2 or later, the compiler will generate the expected warning. |
Yes, otherwise clause was introduced in OpenMP 5.2 version (Metadirective). I have added a condition where, for OpenMP 5.2 or later, the compiler generates a warning for the default clause, while for OpenMP 5.1 and earlier, the default clause is accepted without warnings. |
@mjklemm I addressed the changes that you requested. Kindly review it and let me know if any further modifications are required. |
ping @mjklemm |
ping @jplehr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Did anybody run the OpenMP VV suite before and after this change? Curious to know if that improves results. |
The changes I implemented are related to parsing, specifically addressing the deprecation of the default clause. These modifications do not impact the results, as they primarily refine how parsing is handled. Previously, keywords such as default, otherwise, or other variations were all parsed without distinction. With my changes, the parsing behavior now aligns with the expected standard—supporting default for OpenMP versions lower than 5.2 and otherwise for higher versions. Additionally, a warning is now generated when default is used in higher versions. I also validated these changes by running the OpenMP VV suite to ensure correctness. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the comments and addressing concerns.
✅ With the latest revision this PR passed the C/C++ code formatter. |
7e8c74c
to
112dffa
Compare
112dffa
to
e1c333e
Compare
Merging as already approved !! |
@ravurvi20 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/12198 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/15050 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/65/builds/12602 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/168/builds/8949 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/95/builds/9883 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/125/builds/5817 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/85/builds/5712 Here is the relevant piece of the build log for the reference
|
This broke all AArch64 buildbots. Could you please take a look? |
Looks like this also broke tests on macOS, see http://45.33.8.238/macm1/101361/step_6.txt Given that a bunch of failures have been reported several hours ago, I'll revert this for now. |
…tadirective in OpenMP 5.2 (#125648)" This reverts commit 73ad78c. Breaks check-clang, see comments on llvm/llvm-project#125648
This PR replaces the
default
clause with theotherwise
clause for themetadirective
in OpenMP. Theotherwise
clause serves as a fallback condition when no directive from thewhen
clauses is selected. In thewhen
clause, context selectors define traits evaluated to determine the directive to be applied.