Skip to content

Commit 6c33126

Browse files
committed
default clause replaced by otherwise clause in metadirective
1 parent 14ffff3 commit 6c33126

14 files changed

+64
-35
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,10 @@ def err_omp_expected_colon : Error<"missing ':' in %0">;
16471647
def err_omp_missing_comma : Error< "missing ',' after %0">;
16481648
def err_omp_expected_context_selector
16491649
: Error<"expected valid context selector in %0">;
1650+
def err_omp_unknown_clause
1651+
: Error<"unknown clause '%0' in %1">;
1652+
def warn_omp_default_deprecated : Warning<"'default' clause for"
1653+
" 'metadirective' is deprecated; use 'otherwise' instead">, InGroup<Deprecated>;
16501654
def err_omp_requires_out_inout_depend_type : Error<
16511655
"reserved locator 'omp_all_memory' requires 'out' or 'inout' "
16521656
"dependency types">;

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
246246
case OMPC_uses_allocators:
247247
case OMPC_affinity:
248248
case OMPC_when:
249+
case OMPC_otherwise:
249250
case OMPC_append_args:
250251
break;
251252
default:
@@ -580,6 +581,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
580581
case OMPC_uses_allocators:
581582
case OMPC_affinity:
582583
case OMPC_when:
584+
case OMPC_otherwise:
583585
case OMPC_append_args:
584586
break;
585587
default:

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,15 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
27432743
OpenMPClauseKind CKind = Tok.isAnnotation()
27442744
? OMPC_unknown
27452745
: getOpenMPClauseKind(PP.getSpelling(Tok));
2746+
// Check if the clause is unrecognized.
2747+
if (CKind == OMPC_unknown) {
2748+
Diag(Tok, diag::err_omp_unknown_clause)
2749+
<< PP.getSpelling(Tok) << "metadirective";
2750+
return Directive;
2751+
}
2752+
if(CKind == OMPC_default) {
2753+
Diag(Tok, diag::warn_omp_default_deprecated);
2754+
}
27462755
SourceLocation Loc = ConsumeToken();
27472756

27482757
// Parse '('.
@@ -2769,6 +2778,12 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
27692778
return Directive;
27702779
}
27712780
}
2781+
if (CKind == OMPC_otherwise) {
2782+
// Check for 'otherwise' keyword.
2783+
if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->getName() == "otherwise") {
2784+
ConsumeToken(); // Consume 'otherwise'
2785+
}
2786+
}
27722787
// Skip Directive for now. We will parse directive in the second iteration
27732788
int paren = 0;
27742789
while (Tok.isNot(tok::r_paren) || paren != 0) {

clang/test/OpenMP/metadirective_ast_print.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ void bar(void);
1515
#define N 10
1616
void foo(void) {
1717
#pragma omp metadirective when(device = {kind(cpu)} \
18-
: parallel) default()
18+
: parallel) otherwise()
1919
bar();
2020
#pragma omp metadirective when(implementation = {vendor(score(0) \
2121
: llvm)}, \
2222
device = {kind(cpu)} \
23-
: parallel) default(target teams)
23+
: parallel) otherwise(target teams)
2424
bar();
2525
#pragma omp metadirective when(device = {kind(gpu)} \
2626
: target teams) when(implementation = {vendor(llvm)} \
27-
: parallel) default()
27+
: parallel) otherwise()
2828
bar();
29-
#pragma omp metadirective default(target) when(implementation = {vendor(score(5) \
29+
#pragma omp metadirective otherwise(target) when(implementation = {vendor(score(5) \
3030
: llvm)}, \
3131
device = {kind(cpu, host)} \
3232
: parallel)
@@ -40,15 +40,15 @@ void foo(void) {
4040
for (int i = 0; i < 100; i++)
4141
;
4242
#pragma omp metadirective when(implementation = {extension(match_all)} \
43-
: parallel) default(parallel for)
43+
: parallel) otherwise(parallel for)
4444
for (int i = 0; i < 100; i++)
4545
;
4646
#pragma omp metadirective when(implementation = {extension(match_any)} \
47-
: parallel) default(parallel for)
47+
: parallel) otherwise(parallel for)
4848
for (int i = 0; i < 100; i++)
4949
;
5050
#pragma omp metadirective when(implementation = {extension(match_none)} \
51-
: parallel) default(parallel for)
51+
: parallel) otherwise(parallel for)
5252
for (int i = 0; i < 100; i++)
5353
;
5454

@@ -64,17 +64,17 @@ void foo(void) {
6464

6565
#pragma omp metadirective when(device={arch("amdgcn")}: \
6666
teams distribute parallel for)\
67-
default(parallel for)
67+
otherwise(parallel for)
6868
for (int i = 0; i < 100; i++)
6969
;
7070

7171
#pragma omp metadirective when(implementation = {extension(match_all)} \
72-
: nothing) default(parallel for)
72+
: nothing) otherwise(parallel for)
7373
for (int i = 0; i < 16; i++)
7474
;
7575

7676
#pragma omp metadirective when(implementation = {extension(match_any)} \
77-
: parallel) default(nothing)
77+
: parallel) otherwise(nothing)
7878
for (int i = 0; i < 16; i++)
7979
;
8080
}

clang/test/OpenMP/metadirective_device_arch_codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int metadirective1() {
2727
{
2828
#pragma omp metadirective \
2929
when(device={arch("amdgcn")}: teams distribute parallel for) \
30-
default(parallel for)
30+
otherwise(parallel for)
3131

3232
for (int i = 0; i < N; i++) {
3333
#pragma omp atomic write

clang/test/OpenMP/metadirective_device_isa_codegen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void bar();
88

99
void x86_64_device_isa_selected() {
1010
#pragma omp metadirective when(device = {isa("sse2")} \
11-
: parallel) default(single)
11+
: parallel) otherwise(single)
1212
bar();
1313
}
1414
// CHECK-LABEL: void @_Z26x86_64_device_isa_selectedv()
@@ -21,7 +21,7 @@ void x86_64_device_isa_selected() {
2121

2222
void x86_64_device_isa_not_selected() {
2323
#pragma omp metadirective when(device = {isa("some-unsupported-feature")} \
24-
: parallel) default(single)
24+
: parallel) otherwise(single)
2525
bar();
2626
}
2727
// CHECK-LABEL: void @_Z30x86_64_device_isa_not_selectedv()

clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int amdgcn_device_isa_selected() {
1515
{
1616
#pragma omp metadirective \
1717
when(device = {isa("dpp")} \
18-
: parallel) default(single)
18+
: parallel) otherwise(single)
1919
threadCount++;
2020
}
2121

@@ -38,7 +38,7 @@ int amdgcn_device_isa_not_selected() {
3838
when(device = {isa("sse")} \
3939
: parallel) \
4040
when(device = {isa("another-unsupported-gpu-feature")} \
41-
: parallel) default(single)
41+
: parallel) otherwise(single)
4242
threadCount++;
4343
}
4444

clang/test/OpenMP/metadirective_device_kind_codegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void foo(void) {
3030
: parallel)
3131
bar();
3232
#pragma omp metadirective when(device = {kind(gpu)} \
33-
: target parallel for) default(parallel for)
33+
: target parallel for) otherwise(parallel for)
3434
for (int i = 0; i < 100; i++)
3535
;
3636
}

clang/test/OpenMP/metadirective_device_kind_codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void foo() {
3131
: parallel)
3232
bar();
3333
#pragma omp metadirective when(device = {kind(gpu)} \
34-
: target parallel for) default(parallel for)
34+
: target parallel for) otherwise(parallel for)
3535
for (int i = 0; i < 100; i++)
3636
;
3737
}

clang/test/OpenMP/metadirective_empty.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ void func() {
1111
// Test where a valid when clause contains empty directive.
1212
// The directive will be ignored and code for a serial for loop will be generated.
1313
#pragma omp metadirective when(implementation = {vendor(llvm)} \
14-
:) default(parallel for)
14+
:) otherwise(parallel for)
1515
for (int i = 0; i < N; i++)
1616
;
1717

1818
#pragma omp metadirective when(implementation = {vendor(llvm)} \
19-
:nothing) default(parallel for)
19+
:nothing) otherwise(parallel for)
2020
for (int i = 0; i < N; i++)
2121
;
2222
}

0 commit comments

Comments
 (0)