Skip to content

Commit 7711464

Browse files
committed
Add new keyword spellings with cilk_ instead of _Cilk_.
Add cilk_reducer as alternative spelling of _Hyperobject.
1 parent b316798 commit 7711464

File tree

13 files changed

+93
-53
lines changed

13 files changed

+93
-53
lines changed

clang/include/clang/Basic/TokenKinds.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ KEYWORD(_Bool , KEYNOCXX)
339339
KEYWORD(_Complex , KEYALL)
340340
KEYWORD(_Generic , KEYALL)
341341
KEYWORD(_Hyperobject , KEYALL)
342+
KEYWORD(cilk_reducer , KEYOPENCILK)
342343
// Note, C2y removed support for _Imaginary; we retain it as a keyword because
343344
// 1) it's a reserved identifier, so we're allowed to steal it, 2) there's no
344345
// good way to specify a keyword in earlier but not later language modes within
@@ -494,6 +495,10 @@ KEYWORD(_Cilk_spawn , KEYALL)
494495
KEYWORD(_Cilk_sync , KEYALL)
495496
KEYWORD(_Cilk_for , KEYALL)
496497
KEYWORD(_Cilk_scope , KEYALL)
498+
KEYWORD(cilk_spawn , KEYOPENCILK)
499+
KEYWORD(cilk_sync , KEYOPENCILK)
500+
KEYWORD(cilk_for , KEYOPENCILK)
501+
KEYWORD(cilk_scope , KEYOPENCILK)
497502

498503
// MSVC12.0 / VS2013 Type Traits
499504
TYPE_TRAIT_1(__is_destructible, IsDestructible, KEYALL)

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ namespace {
109109
KEYCUDA = 0x1000000,
110110
KEYHLSL = 0x2000000,
111111
KEYFIXEDPOINT = 0x4000000,
112-
KEYMAX = KEYFIXEDPOINT, // The maximum key
112+
KEYOPENCILK = 0x8000000,
113+
KEYMAX = KEYOPENCILK, // The maximum key
113114
KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
114115
KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 &
115116
~KEYNOOPENCL // KEYNOMS18 and KEYNOOPENCL are used to exclude.
@@ -213,6 +214,9 @@ static KeywordStatus getKeywordStatusHelper(const LangOptions &LangOpts,
213214
return KS_Unknown;
214215
case KEYFIXEDPOINT:
215216
return LangOpts.FixedPoint ? KS_Enabled : KS_Disabled;
217+
case KEYOPENCILK:
218+
return LangOpts.getCilk() == LangOptions::Cilk_opencilk ?
219+
KS_Enabled : KS_Disabled;
216220
default:
217221
llvm_unreachable("Unknown KeywordStatus flag");
218222
}

clang/lib/Parse/ParseCilk.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ using namespace clang;
1919
/// cilk_sync-statement:
2020
/// '_Cilk_sync' ';'
2121
StmtResult Parser::ParseCilkSyncStatement() {
22-
assert(Tok.is(tok::kw__Cilk_sync) && "Not a _Cilk_sync stmt!");
22+
assert(Tok.isOneOf(tok::kw__Cilk_sync, tok::kw_cilk_sync) &&
23+
"Not a cilk_sync stmt!");
2324
return Actions.ActOnCilkSyncStmt(ConsumeToken());
2425
}
2526

2627
/// ParseCilkSpawnStatement
2728
/// cilk_spawn-statement:
2829
/// '_Cilk_spawn' statement
2930
StmtResult Parser::ParseCilkSpawnStatement() {
30-
assert(Tok.is(tok::kw__Cilk_spawn) && "Not a _Cilk_spawn stmt!");
31+
assert(Tok.isOneOf(tok::kw__Cilk_spawn, tok::kw_cilk_spawn) &&
32+
"Not a cilk_spawn stmt!");
3133
SourceLocation SpawnLoc = ConsumeToken(); // eat the '_Cilk_spawn'.
3234

3335
unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope;
@@ -149,9 +151,9 @@ struct MisleadingIndentationChecker {
149151

150152
/// ParseCilkForStatement
151153
/// cilk_for-statement:
152-
/// '_Cilk_for' '(' expr ';' expr ';' expr ')' statement
153-
/// '_Cilk_for' '(' declaration expr ';' expr ';' expr ')' statement
154-
/// [C++0x] '_Cilk_for'
154+
/// 'cilk_for' '(' expr ';' expr ';' expr ')' statement
155+
/// 'cilk_for' '(' declaration expr ';' expr ';' expr ')' statement
156+
/// [C++0x] 'cilk_for'
155157
/// '(' for-range-declaration ':' for-range-initializer ')'
156158
/// statement
157159
///
@@ -161,15 +163,17 @@ struct MisleadingIndentationChecker {
161163
/// [C++0x] expression
162164
/// [C++0x] braced-init-list
163165
StmtResult Parser::ParseCilkForStatement(SourceLocation *TrailingElseLoc) {
164-
assert(Tok.is(tok::kw__Cilk_for) && "Not a _Cilk_for stmt!");
165-
SourceLocation ForLoc = ConsumeToken(); // eat the '_Cilk_for'.
166+
StringRef Spelling = Tok.getName();
167+
assert(Tok.isOneOf(tok::kw__Cilk_for, tok::kw_cilk_for) &&
168+
"Not a cilk_for stmt!");
169+
SourceLocation ForLoc = ConsumeToken(); // eat the 'cilk_for'.
166170

167171
// SourceLocation CoawaitLoc;
168172
// if (Tok.is(tok::kw_co_await))
169173
// CoawaitLoc = ConsumeToken();
170174

171175
if (Tok.isNot(tok::l_paren)) {
172-
Diag(Tok, diag::err_expected_lparen_after) << "_Cilk_for";
176+
Diag(Tok, diag::err_expected_lparen_after) << Spelling;
173177
SkipUntil(tok::semi);
174178
return StmtError();
175179
}
@@ -523,7 +527,8 @@ StmtResult Parser::ParseCilkForStatement(SourceLocation *TrailingElseLoc) {
523527
/// cilk_scope-statement:
524528
/// '_Cilk_scope' statement
525529
StmtResult Parser::ParseCilkScopeStatement() {
526-
assert(Tok.is(tok::kw__Cilk_scope) && "Not a _Cilk_scope stmt!");
530+
assert(Tok.isOneOf(tok::kw__Cilk_scope, tok::kw_cilk_scope) &&
531+
"Not a cilk_scope stmt!");
527532
SourceLocation ScopeLoc = ConsumeToken(); // eat the '_Cilk_scope'.
528533

529534
// TODO: Decide whether to allow break statements in _Cilk_scopes.

clang/lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5776,6 +5776,7 @@ bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const {
57765776
case tok::kw_signed:
57775777
case tok::kw_unsigned:
57785778
case tok::kw__Hyperobject:
5779+
case tok::kw_cilk_reducer:
57795780
case tok::kw__Complex:
57805781
case tok::kw__Imaginary:
57815782
case tok::kw_void:
@@ -5861,6 +5862,7 @@ bool Parser::isTypeSpecifierQualifier() {
58615862
case tok::kw_signed:
58625863
case tok::kw_unsigned:
58635864
case tok::kw__Hyperobject:
5865+
case tok::kw_cilk_reducer:
58645866
case tok::kw__Complex:
58655867
case tok::kw__Imaginary:
58665868
case tok::kw_void:
@@ -6083,6 +6085,7 @@ bool Parser::isDeclarationSpecifier(
60836085
case tok::kw_signed:
60846086
case tok::kw_unsigned:
60856087
case tok::kw__Hyperobject:
6088+
case tok::kw_cilk_reducer:
60866089
case tok::kw__Complex:
60876090
case tok::kw__Imaginary:
60886091
case tok::kw_void:
@@ -6586,7 +6589,7 @@ static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang,
65866589
Lang.getOpenCLCompatibleVersion() >= 200)
65876590
return true;
65886591

6589-
if (Kind == tok::kw__Hyperobject)
6592+
if (Kind == tok::kw__Hyperobject || Kind == tok::kw_cilk_reducer)
65906593
return true;
65916594

65926595
if (!Lang.CPlusPlus)
@@ -6725,7 +6728,7 @@ void Parser::ParseDeclaratorInternal(Declarator &D,
67256728
SourceLocation Loc = ConsumeToken(); // Eat the *, ^, & or &&.
67266729
D.SetRangeEnd(Loc);
67276730

6728-
if (Kind == tok::kw__Hyperobject) {
6731+
if (Kind == tok::kw__Hyperobject || Kind == tok::kw_cilk_reducer) {
67296732
// Is a hyperobject.
67306733
DeclSpec DS(AttrFactory);
67316734

clang/lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
18401840

18411841
// postfix-expression: [CP]
18421842
// _Cilk_spawn[opt] postfix-expression '(' argument-expression-list[opt] ')'
1843-
case tok::kw__Cilk_spawn: {
1843+
case tok::kw__Cilk_spawn:
1844+
case tok::kw_cilk_spawn: {
18441845
SourceLocation SpawnLoc = ConsumeToken();
18451846
// if (!getLangOpts().Cilk) {
18461847
// Diag(SpawnLoc, diag::err_cilkplus_disable);

clang/lib/Parse/ParseObjc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@ IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
11621162
case tok::kw___alignof:
11631163
case tok::kw___auto_type:
11641164
case tok::kw__Hyperobject:
1165+
case tok::kw_cilk_reducer:
11651166
IdentifierInfo *II = Tok.getIdentifierInfo();
11661167
SelectorLoc = ConsumeToken();
11671168
return II;

clang/lib/Parse/ParseStmt.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
488488
ProhibitAttributes(GNUAttrs);
489489
return HandlePragmaCaptured();
490490

491-
case tok::kw__Cilk_spawn: // [CP] _Cilk_spawn statement
491+
case tok::kw__Cilk_spawn: // [CP] cilk_spawn statement
492+
case tok::kw_cilk_spawn:
492493
// if (!getLangOpts().Cilk) {
493494
// Diag(Tok, diag::err_cilkplus_disable);
494495
// SkipUntil(tok::semi);
@@ -497,16 +498,18 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
497498
return ParseCilkSpawnStatement();
498499

499500
case tok::kw__Cilk_sync: // [CP] _Cilk_sync statement
501+
case tok::kw_cilk_sync:
500502
// if (!getLangOpts().Cilk) {
501503
// Diag(Tok, diag::err_cilkplus_disable);
502504
// SkipUntil(tok::semi);
503505
// return StmtError();
504506
// }
505507
Res = ParseCilkSyncStatement();
506-
SemiError = "_Cilk_sync";
508+
SemiError = "cilk_sync";
507509
break;
508510

509511
case tok::kw__Cilk_for:
512+
case tok::kw_cilk_for:
510513
// if (!getLangOpts().Cilk) {
511514
// Diag(Tok, diag::err_cilkplus_disable);
512515
// SkipUntil(tok::semi);
@@ -515,6 +518,7 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
515518
return ParseCilkForStatement(TrailingElseLoc);
516519

517520
case tok::kw__Cilk_scope: // [CP] _Cilk_scope statement
521+
case tok::kw_cilk_scope:
518522
// if (!getLangOpts().Cilk) {
519523
// Diag(Tok, diag::err_cilkplus_disable);
520524
// SkipUntil(tok::semi);

clang/lib/Parse/ParseTentative.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
15571557

15581558
// Cilk
15591559
case tok::kw__Hyperobject:
1560+
case tok::kw_cilk_reducer:
15601561

15611562
// GNU
15621563
case tok::kw_restrict:

clang/test/Cilk/cilk-exceptions.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ void serial_tryblock(int n) {
6565
}
6666

6767
////////////////////////////////////////////////////////////////////////////////
68-
/// _Cilk_for code snippets
68+
/// cilk_for code snippets
6969
////////////////////////////////////////////////////////////////////////////////
7070

7171
// CHECK-LABEL: @_Z20parallelfor_noexcepti(
7272
// CHECK-NOT: detach within %{{.+}}, label %{{.+}}, label %{{.+}} unwind
7373
// CHECK-NOT: landingpad
7474
// CHECK-NOT: resume
7575
void parallelfor_noexcept(int n) {
76-
_Cilk_for (int i = 0; i < n; ++i)
76+
cilk_for (int i = 0; i < n; ++i)
7777
quuz(i);
7878
}
7979

@@ -99,7 +99,7 @@ void parallelfor_noexcept(int n) {
9999
// CHECK: [[DRUNREACH]]:
100100
// CHECK-NEXT: unreachable
101101
void parallelfor_except(int n) {
102-
_Cilk_for (int i = 0; i < n; ++i)
102+
cilk_for (int i = 0; i < n; ++i)
103103
bar(new Foo());
104104
}
105105

@@ -110,7 +110,7 @@ void parallelfor_tryblock(int n) {
110110
try
111111
{
112112
// CHECK-NOT: detach within %[[SYNCREG1]], label %{{.+}}, label %{{.+}} unwind
113-
_Cilk_for (int i = 0; i < n; ++i)
113+
cilk_for (int i = 0; i < n; ++i)
114114
quuz(i);
115115
// CHECK: invoke void @llvm.sync.unwind(token %[[SYNCREG1]])
116116
// CHECK-NEXT: to label %{{.+}} unwind label %[[CATCH:.+]]
@@ -145,7 +145,7 @@ void parallelfor_tryblock(int n) {
145145
// CHECK: invoke void @llvm.detached.rethrow
146146
// CHECK: (token %[[SYNCREG2]], [[LPADTYPE]] {{.+}})
147147
// CHECK-NEXT: to label {{.+}} unwind label %[[CATCH]]
148-
_Cilk_for (int i = 0; i < n; ++i)
148+
cilk_for (int i = 0; i < n; ++i)
149149
bar(new Foo());
150150
}
151151
catch (int e)
@@ -182,7 +182,7 @@ void parallelfor_tryblock_inline(int n) {
182182
// CHECK: landingpad [[LPADTYPE]]
183183
// CHECK-NEXT: catch ptr @_ZTIi
184184
// CHECK-NEXT: catch ptr null
185-
_Cilk_for (int i = 0; i < n; ++i)
185+
cilk_for (int i = 0; i < n; ++i)
186186
foo(new Foo());
187187
}
188188
catch (int e)
@@ -196,14 +196,14 @@ void parallelfor_tryblock_inline(int n) {
196196
}
197197

198198
////////////////////////////////////////////////////////////////////////////////
199-
/// _Cilk_spawn code snippets
199+
/// cilk_spawn code snippets
200200
////////////////////////////////////////////////////////////////////////////////
201201

202202
// CHECK-LABEL: @_Z14spawn_noexcepti(
203203
// CHECK-NOT: landingpad
204204
// CHECK-NOT: detached.rethrow
205205
void spawn_noexcept(int n) {
206-
_Cilk_spawn quuz(n);
206+
cilk_spawn quuz(n);
207207
quuz(n);
208208
}
209209

@@ -237,7 +237,7 @@ void spawn_tf_except(int n) {
237237
// CHECK-NOT: load ptr, ptr %[[EXN]],
238238
// CHECK-NOT: load i32, ptr %[[EHSELECTOR]],
239239
// CHECK: resume [[LPADTYPE]]
240-
_Cilk_spawn bar(new Foo());
240+
cilk_spawn bar(new Foo());
241241
quuz(n);
242242
}
243243

@@ -292,7 +292,7 @@ void spawn_stmt_destructor(int n) {
292292
// CHECK-NOT: load ptr, ptr %[[EXNTF]],
293293
// CHECK-NOT: load i32, ptr %[[EHSELECTORTF]],
294294
// CHECK: resume [[LPADTYPE]]
295-
_Cilk_spawn baz(Foo());
295+
cilk_spawn baz(Foo());
296296
quuz(n);
297297
}
298298

@@ -348,7 +348,7 @@ void spawn_decl_destructor(int n) {
348348
// CHECK-NOT: load ptr, ptr %[[EXNTF]],
349349
// CHECK-NOT: load i32, ptr %[[EHSELECTORTF]],
350350
// CHECK: resume [[LPADTYPE]]
351-
int result = _Cilk_spawn baz(Foo());
351+
int result = cilk_spawn baz(Foo());
352352
quuz(n);
353353
}
354354

@@ -414,7 +414,7 @@ void spawn_block_destructor(int n) {
414414
// CHECK: resume [[LPADTYPE]]
415415
{
416416
auto f = Foo();
417-
int result = _Cilk_spawn baz(f);
417+
int result = cilk_spawn baz(f);
418418
quuz(n);
419419
}
420420
}
@@ -444,7 +444,7 @@ void spawn_throw_inline(int n) {
444444
// CHECK: invoke void @llvm.taskframe.resume
445445
// CHECK: (token %[[TASKFRAME]], [[LPADTYPE]] {{.+}})
446446
// CHECK-NEXT: to label {{.+}} unwind label {{.+}}
447-
_Cilk_spawn foo(new Foo());
447+
cilk_spawn foo(new Foo());
448448
quuz(n);
449449
}
450450

@@ -460,7 +460,7 @@ void spawn_tryblock(int n) {
460460
// CHECK-NEXT: call void @llvm.taskframe.use(token %[[TASKFRAME]])
461461
// CHECK-NEXT: call {{.*}}i32 @_Z4quuzi(
462462
// CHECK-NEXT: reattach within %[[SYNCREG]], label %[[CONTINUE1]]
463-
_Cilk_spawn quuz(n);
463+
cilk_spawn quuz(n);
464464
// CHECK: %[[TASKFRAME2:.+]] = call token @llvm.taskframe.create()
465465
// CHECK: detach within %[[SYNCREG]], label %[[DETACHED2:.+]], label %[[CONTINUE2:.+]] unwind label %[[DUNWIND:.+]]
466466
// CHECK: [[DETACHED2]]:
@@ -469,21 +469,21 @@ void spawn_tryblock(int n) {
469469
// CHECK-NEXT: to label %[[INVOKECONT1:.+]] unwind label %[[TASKLPAD:.+]]
470470
// CHECK: [[INVOKECONT1]]:
471471
// CHECK-NEXT: reattach within %[[SYNCREG]], label %[[CONTINUE2]]
472-
_Cilk_spawn bar(new Foo());
472+
cilk_spawn bar(new Foo());
473473
// CHECK: %[[TASKFRAME3:.+]] = call token @llvm.taskframe.create()
474474
// CHECK: detach within %[[SYNCREG]], label %[[DETACHED3:.+]], label %[[CONTINUE3:.+]]
475475
// CHECK: [[DETACHED3]]:
476476
// CHECK-NEXT: call void @llvm.taskframe.use(token %[[TASKFRAME3]])
477477
// CHECK-NEXT: call {{.*}}i32 @_Z4quuzi(
478478
// CHECK-NEXT: reattach within %[[SYNCREG]], label %[[CONTINUE3]]
479-
_Cilk_spawn quuz(n);
479+
cilk_spawn quuz(n);
480480
// CHECK: [[CONTINUE3]]:
481481
// CHECK: invoke {{.*}}i32 @_Z3barP3Foo(
482482
// CHECK-NEXT: to label %[[INVOKECONT2:.+]] unwind label %[[CONT3UNWIND:.+]]
483483
bar(new Foo());
484484
// CHECK: [[INVOKECONT2]]:
485485
// CHECK-NEXT: sync within %[[SYNCREG]]
486-
_Cilk_sync;
486+
cilk_sync;
487487
}
488488
// CHECK: [[DUNWIND]]:
489489
// CHECK: landingpad [[LPADTYPE]]

clang/test/Cilk/hyper-address.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
void identity(void * value);
1111
void reduce(void* left, void* right);
1212
extern void consume_view(long *);
13-
extern void consume_hyper(long _Hyperobject *);
13+
extern void consume_hyper(long cilk_reducer *);
1414
// CHECK-LABEL: assorted_addresses
1515
void assorted_addresses()
1616
{
1717
// CHECK: call void @llvm.reducer.register
18-
long _Hyperobject(identity, reduce) sum = 0;
18+
long cilk_reducer(identity, reduce) sum = 0;
1919
// CHECK-NOT: llvm.hyper.lookup
2020
// CHECK: call void @[[FN1:.*consume_hyper]]
2121
consume_hyper(__builtin_addressof(sum));

clang/test/Cilk/hyper-assign.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %clang_cc1 %s -x c++ -fopencilk -verify -emit-llvm -disable-llvm-passes -o - | FileCheck %s
33
// expected-no-diagnostics
44

5-
extern long _Hyperobject x, _Hyperobject y;
5+
extern long _Hyperobject x, cilk_reducer y; // use both spellings of keyword
66

77
long chain_assign()
88
{

clang/test/Cilk/keywords.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 %s -fopencilk -fsyntax-only -verify
2+
// RUN: %clang_cc1 %s -fsyntax-only -verify=nokeyword
3+
// nokeyword-no-diagnostics
4+
int cilk_spawn;
5+
// expected-error@-1{{expected identifier}}
6+
int cilk_sync = 1;
7+
// expected-error@-1{{expected identifier}}
8+
int cilk_scope = 2;
9+
// expected-error@-1{{expected identifier}}
10+
int cilk_for(int x)
11+
// expected-error@-1{{expected identifier}}
12+
{
13+
return cilk_spawn + cilk_sync + cilk_scope;
14+
}
15+
int cilk_reducer = 3;
16+
// expected-error@-1{{expected identifier}}

0 commit comments

Comments
 (0)