-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[OpenMP][Clang] Add support for OMP6.1 fb_nullify and fb_preserve in need_device_ptr modifier #168905
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
base: main
Are you sure you want to change the base?
[OpenMP][Clang] Add support for OMP6.1 fb_nullify and fb_preserve in need_device_ptr modifier #168905
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4932,6 +4932,37 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, | |
| ConsumeToken(); | ||
| if (Tok.is(tok::colon)) | ||
| Data.ColonLoc = Tok.getLocation(); | ||
| if (getLangOpts().OpenMP >= 61) { | ||
| // Handle optional need_device_ptr modifier. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should say "Handle the optional fallback argument for the need_device_ptr modifier." |
||
| if (Tok.is(tok::l_paren)) { | ||
| BalancedDelimiterTracker T(*this, tok::l_paren); | ||
| T.consumeOpen(); | ||
| if (Tok.is(tok::identifier)) { | ||
| std::string Modifier = PP.getSpelling(Tok); | ||
| if (Modifier == "fb_nullify" || Modifier == "fb_preserve") { | ||
| Data.NeedDevicePtrModifier = Modifier == "fb_nullify" | ||
| ? OMPC_NEEDDEVICE_fp_nullify | ||
| : OMPC_NEEDDEVICE_fp_preserve; | ||
| } else { | ||
| Diag(Tok, diag::err_omp_unknown_need_device_ptr_modifier) | ||
| << (getLangOpts().OpenMP >= 60 ? 1 : 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, | ||
| StopBeforeMatch); | ||
| return false; | ||
| } | ||
| ConsumeToken(); | ||
| if (Tok.is(tok::r_paren)) { | ||
| Data.NeedDevicePtrModifierLoc = Tok.getLocation(); | ||
| ConsumeAnyToken(); | ||
| } else { | ||
| Diag(Tok, diag::err_expected) << tok::r_paren; | ||
| SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, | ||
| StopBeforeMatch); | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ExpectAndConsume(tok::colon, diag::warn_pragma_expected_colon, | ||
| "adjust-op"); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=61 -ast-print %s | FileCheck %s | ||
|
|
||
| // expected-no-diagnostics | ||
|
|
||
| void __attribute__((noinline)) device_impl(int *xp, int *&xpref, int n) {} | ||
|
|
||
| #pragma omp declare variant(device_impl) \ | ||
| adjust_args(need_device_ptr(fb_nullify) : xp, xpref) | ||
| void __attribute__((noinline)) host_entry_a(int *xp, int *&xpref, int n) {} | ||
|
|
||
| #pragma omp declare variant(device_impl) \ | ||
| adjust_args(need_device_ptr(fb_preserve) : xp, xpref) | ||
| void __attribute__((noinline)) host_entry_b(int *xp, int *&xpref, int n) {} | ||
|
|
||
| // CHECK-LABEL: int main() | ||
| int main() { | ||
| int x; | ||
| int *xp = &x; | ||
|
|
||
| host_entry_a(xp, xp, 1); | ||
| host_entry_b(xp, xp, 1); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=61 %s | ||
|
|
||
| void __attribute__((noinline)) device_impl(int *xp, int *&xpref, int n) {} | ||
|
|
||
| #pragma omp declare variant(device_impl) \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add 2/3 more cases:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I think the LIT tests name should start with |
||
| adjust_args(need_device_ptr(foo) : xp, xpref) // expected-error{{unknown modifier in 'need_device_ptr' clause (OpenMP 6.1 or later only)}} // expected-error{{expected 'match', 'adjust_args', or 'append_args' clause on 'omp declare variant' directive}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message is not really accurate. The clause is Ideally, we should say something like: Otherwise, at the very least we should say |
||
| void __attribute__((noinline)) host_entry_a(int *xp, int *&xpref, int n) {} | ||
|
|
||
| int main() { | ||
| int x; | ||
| int *xp = &x; | ||
|
|
||
| host_entry_a(xp, xp, 1); | ||
| return 0; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.