Skip to content

Commit 2ddba30

Browse files
committed
[flang][openmp] Use common Directive and Clause enum from llvm/Frontend
Summary: This patch is removing the custom enumeration for OpenMP Directives and Clauses and replace them with the newly tablegen generated one from llvm/Frontend. This is a first patch and some will follow to share the same infrastructure where possible. The next patch should use the clauses allowance defined in the tablegen file. Reviewers: jdoerfert, DavidTruby, sscalpone, kiranchandramohan, ichoyjx Reviewed By: DavidTruby, ichoyjx Subscribers: jholewinski, cfe-commits, dblaikie, MaskRay, ymandel, ichoyjx, mgorny, yaxunl, guansong, jfb, sstefan1, aaron.ballman, llvm-commits Tags: #llvm, #flang, #clang Differential Revision: https://reviews.llvm.org/D82906
1 parent aded4f0 commit 2ddba30

File tree

24 files changed

+720
-653
lines changed

24 files changed

+720
-653
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7556,6 +7556,8 @@ class OMPClauseVisitorBase {
75567556
case llvm::omp::Clause::Enum: \
75577557
break;
75587558
#include "llvm/Frontend/OpenMP/OMPKinds.def"
7559+
default:
7560+
break;
75597561
}
75607562
}
75617563
// Base case, ignore it. :)

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,8 @@ bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
30003000
case llvm::omp::Clause::Enum: \
30013001
break;
30023002
#include "llvm/Frontend/OpenMP/OMPKinds.def"
3003+
default:
3004+
break;
30033005
}
30043006
return true;
30053007
}

clang/lib/AST/ASTTypeTraits.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ ASTNodeKind ASTNodeKind::getFromNode(const OMPClause &C) {
118118
#define OMP_CLAUSE_NO_CLASS(Enum, Str) \
119119
case llvm::omp::Clause::Enum: \
120120
llvm_unreachable("unexpected OpenMP clause kind");
121+
default:
122+
break;
121123
#include "llvm/Frontend/OpenMP/OMPKinds.def"
122124
}
123125
llvm_unreachable("invalid stmt kind");

clang/lib/AST/OpenMPClause.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ OMPClause::child_range OMPClause::used_children() {
5151
case OMPC_match:
5252
case OMPC_unknown:
5353
break;
54+
default:
55+
break;
5456
}
5557
llvm_unreachable("unknown OMPClause");
5658
}
@@ -154,6 +156,8 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
154156
case OMPC_uses_allocators:
155157
case OMPC_affinity:
156158
break;
159+
default:
160+
break;
157161
}
158162

159163
return nullptr;
@@ -246,6 +250,8 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
246250
case OMPC_uses_allocators:
247251
case OMPC_affinity:
248252
break;
253+
default:
254+
break;
249255
}
250256

251257
return nullptr;

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
178178
case OMPC_uses_allocators:
179179
case OMPC_affinity:
180180
break;
181+
default:
182+
break;
181183
}
182184
llvm_unreachable("Invalid OpenMP simple clause kind");
183185
}
@@ -427,6 +429,8 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
427429
case OMPC_uses_allocators:
428430
case OMPC_affinity:
429431
break;
432+
default:
433+
break;
430434
}
431435
llvm_unreachable("Invalid OpenMP simple clause kind");
432436
}
@@ -681,6 +685,7 @@ void clang::getOpenMPCaptureRegions(
681685
case OMPD_end_declare_variant:
682686
llvm_unreachable("OpenMP Directive is not allowed");
683687
case OMPD_unknown:
688+
default:
684689
llvm_unreachable("Unknown OpenMP directive");
685690
}
686691
}

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6680,6 +6680,8 @@ emitNumTeamsForTargetDirective(CodeGenFunction &CGF,
66806680
case OMPD_requires:
66816681
case OMPD_unknown:
66826682
break;
6683+
default:
6684+
break;
66836685
}
66846686
llvm_unreachable("Unexpected directive kind.");
66856687
}
@@ -6995,6 +6997,8 @@ emitNumThreadsForTargetDirective(CodeGenFunction &CGF,
69956997
case OMPD_requires:
69966998
case OMPD_unknown:
69976999
break;
7000+
default:
7001+
break;
69987002
}
69997003
llvm_unreachable("Unsupported directive kind.");
70007004
}
@@ -8914,6 +8918,7 @@ getNestedDistributeDirective(ASTContext &Ctx, const OMPExecutableDirective &D) {
89148918
case OMPD_parallel_master_taskloop_simd:
89158919
case OMPD_requires:
89168920
case OMPD_unknown:
8921+
default:
89178922
llvm_unreachable("Unexpected directive.");
89188923
}
89198924
}
@@ -9704,6 +9709,7 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S,
97049709
case OMPD_parallel_master_taskloop_simd:
97059710
case OMPD_requires:
97069711
case OMPD_unknown:
9712+
default:
97079713
llvm_unreachable("Unknown target directive for OpenMP device codegen.");
97089714
}
97099715
return;
@@ -10362,6 +10368,7 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(
1036210368
case OMPD_target_parallel_for_simd:
1036310369
case OMPD_requires:
1036410370
case OMPD_unknown:
10371+
default:
1036510372
llvm_unreachable("Unexpected standalone target data directive.");
1036610373
break;
1036710374
}

clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ static bool hasNestedSPMDDirective(ASTContext &Ctx,
819819
case OMPD_parallel_master_taskloop_simd:
820820
case OMPD_requires:
821821
case OMPD_unknown:
822+
default:
822823
llvm_unreachable("Unexpected directive.");
823824
}
824825
}
@@ -899,6 +900,7 @@ static bool supportsSPMDExecutionMode(ASTContext &Ctx,
899900
case OMPD_parallel_master_taskloop_simd:
900901
case OMPD_requires:
901902
case OMPD_unknown:
903+
default:
902904
break;
903905
}
904906
llvm_unreachable(
@@ -1072,6 +1074,7 @@ static bool hasNestedLightweightDirective(ASTContext &Ctx,
10721074
case OMPD_parallel_master_taskloop_simd:
10731075
case OMPD_requires:
10741076
case OMPD_unknown:
1077+
default:
10751078
llvm_unreachable("Unexpected directive.");
10761079
}
10771080
}
@@ -1158,6 +1161,7 @@ static bool supportsLightweightRuntime(ASTContext &Ctx,
11581161
case OMPD_parallel_master_taskloop_simd:
11591162
case OMPD_requires:
11601163
case OMPD_unknown:
1164+
default:
11611165
break;
11621166
}
11631167
llvm_unreachable(

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ void CodeGenFunction::EmitOMPReductionClauseInit(
13771377
case OMPD_begin_declare_variant:
13781378
case OMPD_end_declare_variant:
13791379
case OMPD_unknown:
1380+
default:
13801381
llvm_unreachable("Enexpected directive with task reductions.");
13811382
}
13821383

@@ -5302,6 +5303,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
53025303
case OMPC_exclusive:
53035304
case OMPC_uses_allocators:
53045305
case OMPC_affinity:
5306+
default:
53055307
llvm_unreachable("Clause is not allowed in 'omp atomic'.");
53065308
}
53075309
}

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
20092009
Diag(Tok, diag::err_omp_unexpected_directive)
20102010
<< 1 << getOpenMPDirectiveName(DKind);
20112011
break;
2012+
default:
2013+
break;
20122014
}
20132015
while (Tok.isNot(tok::annot_pragma_openmp_end))
20142016
ConsumeAnyToken();
@@ -2358,6 +2360,7 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) {
23582360
SkipUntil(tok::annot_pragma_openmp_end);
23592361
break;
23602362
case OMPD_unknown:
2363+
default:
23612364
Diag(Tok, diag::err_omp_unknown_directive);
23622365
SkipUntil(tok::annot_pragma_openmp_end);
23632366
break;
@@ -2681,6 +2684,8 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
26812684
<< getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind);
26822685
SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
26832686
break;
2687+
default:
2688+
break;
26842689
}
26852690
return ErrorFound ? nullptr : Clause;
26862691
}

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,6 +4050,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
40504050
case OMPD_end_declare_variant:
40514051
llvm_unreachable("OpenMP Directive is not allowed");
40524052
case OMPD_unknown:
4053+
default:
40534054
llvm_unreachable("Unknown OpenMP directive");
40544055
}
40554056
}
@@ -5335,6 +5336,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
53355336
case OMPD_end_declare_variant:
53365337
llvm_unreachable("OpenMP Directive is not allowed");
53375338
case OMPD_unknown:
5339+
default:
53385340
llvm_unreachable("Unknown OpenMP directive");
53395341
}
53405342

@@ -5437,6 +5439,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
54375439
case OMPC_atomic_default_mem_order:
54385440
case OMPC_device_type:
54395441
case OMPC_match:
5442+
default:
54405443
llvm_unreachable("Unexpected clause");
54415444
}
54425445
for (Stmt *CC : C->children()) {
@@ -11683,6 +11686,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
1168311686
case OMPC_exclusive:
1168411687
case OMPC_uses_allocators:
1168511688
case OMPC_affinity:
11689+
default:
1168611690
llvm_unreachable("Clause is not allowed.");
1168711691
}
1168811692
return Res;
@@ -11837,6 +11841,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1183711841
case OMPD_requires:
1183811842
llvm_unreachable("Unexpected OpenMP directive with if-clause");
1183911843
case OMPD_unknown:
11844+
default:
1184011845
llvm_unreachable("Unknown OpenMP directive");
1184111846
}
1184211847
break;
@@ -11915,6 +11920,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1191511920
case OMPD_requires:
1191611921
llvm_unreachable("Unexpected OpenMP directive with num_threads-clause");
1191711922
case OMPD_unknown:
11923+
default:
1191811924
llvm_unreachable("Unknown OpenMP directive");
1191911925
}
1192011926
break;
@@ -11991,6 +11997,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1199111997
case OMPD_requires:
1199211998
llvm_unreachable("Unexpected OpenMP directive with num_teams-clause");
1199311999
case OMPD_unknown:
12000+
default:
1199412001
llvm_unreachable("Unknown OpenMP directive");
1199512002
}
1199612003
break;
@@ -12067,6 +12074,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1206712074
case OMPD_requires:
1206812075
llvm_unreachable("Unexpected OpenMP directive with thread_limit-clause");
1206912076
case OMPD_unknown:
12077+
default:
1207012078
llvm_unreachable("Unknown OpenMP directive");
1207112079
}
1207212080
break;
@@ -12143,6 +12151,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1214312151
case OMPD_requires:
1214412152
llvm_unreachable("Unexpected OpenMP directive with schedule clause");
1214512153
case OMPD_unknown:
12154+
default:
1214612155
llvm_unreachable("Unknown OpenMP directive");
1214712156
}
1214812157
break;
@@ -12219,6 +12228,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1221912228
case OMPD_requires:
1222012229
llvm_unreachable("Unexpected OpenMP directive with schedule clause");
1222112230
case OMPD_unknown:
12231+
default:
1222212232
llvm_unreachable("Unknown OpenMP directive");
1222312233
}
1222412234
break;
@@ -12295,6 +12305,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1229512305
case OMPD_requires:
1229612306
llvm_unreachable("Unexpected OpenMP directive with num_teams-clause");
1229712307
case OMPD_unknown:
12308+
default:
1229812309
llvm_unreachable("Unknown OpenMP directive");
1229912310
}
1230012311
break;
@@ -12373,6 +12384,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1237312384
case OMPD_requires:
1237412385
llvm_unreachable("Unexpected OpenMP directive with grainsize-clause");
1237512386
case OMPD_unknown:
12387+
default:
1237612388
llvm_unreachable("Unknown OpenMP directive");
1237712389
}
1237812390
break;
@@ -12439,6 +12451,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1243912451
case OMPC_exclusive:
1244012452
case OMPC_uses_allocators:
1244112453
case OMPC_affinity:
12454+
default:
1244212455
llvm_unreachable("Unexpected OpenMP clause.");
1244312456
}
1244412457
return CaptureRegion;
@@ -12880,6 +12893,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(
1288012893
case OMPC_exclusive:
1288112894
case OMPC_uses_allocators:
1288212895
case OMPC_affinity:
12896+
default:
1288312897
llvm_unreachable("Clause is not allowed.");
1288412898
}
1288512899
return Res;
@@ -13108,6 +13122,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
1310813122
case OMPC_exclusive:
1310913123
case OMPC_uses_allocators:
1311013124
case OMPC_affinity:
13125+
default:
1311113126
llvm_unreachable("Clause is not allowed.");
1311213127
}
1311313128
return Res;
@@ -13345,6 +13360,7 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
1334513360
case OMPC_exclusive:
1334613361
case OMPC_uses_allocators:
1334713362
case OMPC_affinity:
13363+
default:
1334813364
llvm_unreachable("Clause is not allowed.");
1334913365
}
1335013366
return Res;
@@ -13618,6 +13634,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
1361813634
case OMPC_destroy:
1361913635
case OMPC_detach:
1362013636
case OMPC_uses_allocators:
13637+
default:
1362113638
llvm_unreachable("Clause is not allowed.");
1362213639
}
1362313640
return Res;

clang/lib/Serialization/ASTReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11994,6 +11994,8 @@ OMPClause *OMPClauseReader::readClause() {
1199411994
case llvm::omp::Enum: \
1199511995
break;
1199611996
#include "llvm/Frontend/OpenMP/OMPKinds.def"
11997+
default:
11998+
break;
1199711999
}
1199812000
assert(C && "Unknown OMPClause type");
1199912001

flang/include/flang/Common/enum-set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ template <typename ENUM, std::size_t BITS> class EnumSet {
190190
// std::bitset: just iterate
191191
for (std::size_t j{0}; j < BITS; ++j) {
192192
auto enumerator{static_cast<enumerationType>(j)};
193-
if (bitset_.test(enumerator)) {
193+
if (bitset_.test(j)) {
194194
return {enumerator};
195195
}
196196
}

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ class ParseTreeDumper {
409409
NODE(parser, OmpBeginLoopDirective)
410410
NODE(parser, OmpBeginSectionsDirective)
411411
NODE(parser, OmpBlockDirective)
412-
NODE_ENUM(OmpBlockDirective, Directive)
412+
static std::string GetNodeName(const llvm::omp::Directive &x) {
413+
return llvm::Twine(
414+
"llvm::omp::Directive = ", llvm::omp::getOpenMPDirectiveName(x))
415+
.str();
416+
}
413417
NODE(parser, OmpCancelType)
414418
NODE_ENUM(OmpCancelType, Type)
415419
NODE(parser, OmpClause)
@@ -477,7 +481,6 @@ class ParseTreeDumper {
477481
NODE(parser, OmpLinearModifier)
478482
NODE_ENUM(OmpLinearModifier, Type)
479483
NODE(parser, OmpLoopDirective)
480-
NODE_ENUM(OmpLoopDirective, Directive)
481484
NODE(parser, OmpMapClause)
482485
NODE(parser, OmpMapType)
483486
NODE(OmpMapType, Always)
@@ -505,9 +508,7 @@ class ParseTreeDumper {
505508
NODE_ENUM(OmpScheduleModifierType, ModType)
506509
NODE(parser, OmpSectionBlocks)
507510
NODE(parser, OmpSectionsDirective)
508-
NODE_ENUM(OmpSectionsDirective, Directive)
509511
NODE(parser, OmpSimpleStandaloneDirective)
510-
NODE_ENUM(OmpSimpleStandaloneDirective, Directive)
511512
NODE(parser, Only)
512513
NODE(parser, OpenMPAtomicConstruct)
513514
NODE(parser, OpenMPBlockConstruct)

0 commit comments

Comments
 (0)