Skip to content
Closed
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
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,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">;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Basic/OpenMPKinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
case OMPC_uses_allocators:
case OMPC_affinity:
case OMPC_when:
case OMPC_otherwise:
case OMPC_append_args:
break;
default:
Expand Down Expand Up @@ -580,6 +581,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
case OMPC_uses_allocators:
case OMPC_affinity:
case OMPC_when:
case OMPC_otherwise:
case OMPC_append_args:
break;
default:
Expand Down
15 changes: 15 additions & 0 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 '('.
Expand All @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions clang/test/OpenMP/metadirective_ast_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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++)
;

Expand All @@ -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++)
;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/metadirective_device_arch_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions clang/test/OpenMP/metadirective_device_isa_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int amdgcn_device_isa_selected() {
{
#pragma omp metadirective \
when(device = {isa("dpp")} \
: parallel) default(single)
: parallel) otherwise(single)
threadCount++;
}

Expand All @@ -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++;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/metadirective_device_kind_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/metadirective_device_kind_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/OpenMP/metadirective_empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
;
}
Expand Down
12 changes: 6 additions & 6 deletions clang/test/OpenMP/metadirective_implementation_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
;
}
Expand Down
12 changes: 6 additions & 6 deletions clang/test/OpenMP/metadirective_implementation_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
;
}
Expand Down
11 changes: 7 additions & 4 deletions clang/test/OpenMP/metadirective_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ 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}}
}
5 changes: 5 additions & 0 deletions llvm/include/llvm/Frontend/OpenMP/OMP.td
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ def OMPC_Weak : Clause<"weak"> {
}
def OMPC_When: Clause<"when"> {
}
def OMPC_Otherwise: Clause<"otherwise"> {
}
def OMPC_Write : Clause<"write"> {
let clangClass = "OMPWriteClause";
}
Expand Down Expand Up @@ -844,6 +846,9 @@ def OMP_Metadirective : Directive<"metadirective"> {
let allowedClauses = [
VersionedClause<OMPC_When>,
];
let allowedClauses = [
VersionedClause<OMPC_Otherwise>,
];
let allowedOnceClauses = [
VersionedClause<OMPC_Default>,
];
Expand Down
Loading