Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,9 @@ def warn_omp_invalid_attribute_for_ompx_attributes : Warning<"'ompx_attribute' c
"%0 is ignored">, InGroup<OpenMPExtensions>;
def err_omp_duplicate_modifier : Error<"duplicate modifier '%0' in '%1' clause">;
def err_omp_expected_modifier : Error<"expected modifier in '%0' clause">;
def err_omp_unknown_need_device_ptr_modifier
: Error<"unknown modifier in 'need_device_ptr' clause%select{| (OpenMP 6.1 or later only)}0">;


// Pragma loop support.
def err_pragma_loop_missing_argument : Error<
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
#ifndef OPENMP_THREADSET_KIND
#define OPENMP_THREADSET_KIND(Name)
#endif
#ifndef OPENMP_NEEDDEVICE_MODIFIER
#define OPENMP_NEEDDEVICE_MODIFIER(Name)
#endif

// Static attributes for 'schedule' clause.
OPENMP_SCHEDULE_KIND(static)
Expand Down Expand Up @@ -261,6 +264,10 @@ OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)
OPENMP_THREADSET_KIND(omp_pool)
OPENMP_THREADSET_KIND(omp_team)

// OpenMP 6.1 modifiers for 'adjust_args' clause.
OPENMP_NEEDDEVICE_MODIFIER(fp_nullify)
OPENMP_NEEDDEVICE_MODIFIER(fp_preserve)

#undef OPENMP_NUMTASKS_MODIFIER
#undef OPENMP_NUMTHREADS_MODIFIER
#undef OPENMP_GRAINSIZE_MODIFIER
Expand Down Expand Up @@ -291,3 +298,4 @@ OPENMP_THREADSET_KIND(omp_team)
#undef OPENMP_DOACROSS_MODIFIER
#undef OPENMP_ALLOCATE_MODIFIER
#undef OPENMP_THREADSET_KIND
#undef OPENMP_NEEDDEVICE_MODIFIER
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ enum OpenMPAdjustArgsOpKind {
OMPC_ADJUST_ARGS_unknown,
};

/// OpenMP 6.1 need_device modifier
enum OpenMPNeedDeviceModifier {
#define OPENMP_NEEDDEVICE_MODIFIER(Name) OMPC_NEEDDEVICE_##Name,
#include "clang/Basic/OpenMPKinds.def"
OMPC_NEEDDEVICE_unknown,
};

/// OpenMP bindings for the 'bind' clause.
enum OpenMPBindClauseKind {
#define OPENMP_BIND_KIND(Name) OMPC_BIND_##Name,
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Sema/SemaOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,8 @@ class SemaOpenMP : public SemaBase {
int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
///< lastprivate clause.
int OriginalSharingModifier = 0; // Default is shared
int NeedDevicePtrModifier = 0;
SourceLocation NeedDevicePtrModifierLoc;
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
MapTypeModifiers;
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
Expand Down
31 changes: 31 additions & 0 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

getLangOpts().OpenMP >= 60 should it be >=61. Line 4935 checks for >=61.

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");
}
Expand Down
23 changes: 23 additions & 0 deletions clang/test/OpenMP/need_device_modifier_ast_print.cpp
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;
}
15 changes: 15 additions & 0 deletions clang/test/OpenMP/need_device_modifier_messages.cpp
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) \
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add 2/3 more cases:

#pragma omp declare variant(device_impl)                                       \
    adjust_args(need_device_ptr(fb_nullify) : xp, xpref)   // no error 
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)   // no error 
void __attribute__((noinline)) host_entry_a(int *xp, int *&xpref, int n) {} // expected `)`

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think the LIT tests name should start with need_device_ptr_modifier_<messages/ast_print>.cpp

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}}
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message is not really accurate. The clause is adjust_args, modifier is need_device_ptr, and foo here is an argument to the need_device_ptr modifier.

Ideally, we should say something like:

unknown argument for 'need_device_ptr' complex-modifier.
Expected 'fb_nullify' or 'fb_preserve'.

Otherwise, at the very least we should say unknown modifier in 'adjust_args' clause.

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;
}