Skip to content

Commit 8e2ac7d

Browse files
authored
[llvm][OpenMP] Add "SourceLanguages" property to Directive (#139960)
The official languages that OpenMP recognizes are C/C++ and Fortran. Some OpenMP directives are language-specific, some are C/C++-only, some are Fortran-only. Add a property to the TableGen definition of Directive that will be the list of languages that allow the directive. The TableGen backend will then generate a bitmask-like enumeration SourceLanguages, and a function SourceLanguages getDirectiveLanguages(Directive D);
1 parent b26adac commit 8e2ac7d

File tree

6 files changed

+198
-21
lines changed

6 files changed

+198
-21
lines changed

llvm/include/llvm/Frontend/Directive/DirectiveBase.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ def CA_Meta: Category<"Meta"> {}
172172
def CA_Subsidiary: Category<"Subsidiary"> {}
173173
def CA_Utility: Category<"Utility"> {}
174174

175+
class SourceLanguage<string n> {
176+
string name = n; // Name of the enum value in enum class Association.
177+
}
178+
179+
// The C languages also implies C++ until there is a reason to add C++
180+
// separately.
181+
def L_C : SourceLanguage<"C"> {}
182+
def L_Fortran : SourceLanguage<"Fortran"> {}
183+
175184
// Information about a specific directive.
176185
class Directive<string d> {
177186
// Name of the directive. Can be composite directive sepearted by whitespace.
@@ -205,4 +214,7 @@ class Directive<string d> {
205214

206215
// The category of the directive.
207216
Category category = ?;
217+
218+
// The languages that allow this directive. Default: all languages.
219+
list<SourceLanguage> languages = [L_C, L_Fortran];
208220
}

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ def OMP_Allocators : Directive<"allocators"> {
573573
];
574574
let association = AS_Block;
575575
let category = CA_Executable;
576+
let languages = [L_Fortran];
576577
}
577578
def OMP_Assumes : Directive<"assumes"> {
578579
let association = AS_None;
@@ -586,10 +587,6 @@ def OMP_Assumes : Directive<"assumes"> {
586587
VersionedClause<OMPC_NoParallelism, 51>,
587588
];
588589
}
589-
def OMP_EndAssumes : Directive<"end assumes"> {
590-
let association = AS_Delimited;
591-
let category = OMP_Assumes.category;
592-
}
593590
def OMP_Assume : Directive<"assume"> {
594591
let association = AS_Block;
595592
let category = CA_Informational;
@@ -637,6 +634,12 @@ def OMP_BeginAssumes : Directive<"begin assumes"> {
637634
VersionedClause<OMPC_NoOpenMPRoutines, 51>,
638635
VersionedClause<OMPC_NoParallelism, 51>,
639636
];
637+
let languages = [L_C];
638+
}
639+
def OMP_EndAssumes : Directive<"end assumes"> {
640+
let association = AS_Delimited;
641+
let category = OMP_BeginAssumes.category;
642+
let languages = OMP_BeginAssumes.languages;
640643
}
641644
def OMP_BeginDeclareTarget : Directive<"begin declare target"> {
642645
let allowedClauses = [
@@ -647,10 +650,22 @@ def OMP_BeginDeclareTarget : Directive<"begin declare target"> {
647650
];
648651
let association = AS_Delimited;
649652
let category = CA_Declarative;
653+
let languages = [L_C];
654+
}
655+
def OMP_EndDeclareTarget : Directive<"end declare target"> {
656+
let association = AS_Delimited;
657+
let category = OMP_BeginDeclareTarget.category;
658+
let languages = OMP_BeginDeclareTarget.languages;
650659
}
651660
def OMP_BeginDeclareVariant : Directive<"begin declare variant"> {
652661
let association = AS_Delimited;
653662
let category = CA_Declarative;
663+
let languages = [L_C];
664+
}
665+
def OMP_EndDeclareVariant : Directive<"end declare variant"> {
666+
let association = AS_Delimited;
667+
let category = OMP_BeginDeclareVariant.category;
668+
let languages = OMP_BeginDeclareVariant.languages;
654669
}
655670
def OMP_Cancel : Directive<"cancel"> {
656671
let allowedOnceClauses = [
@@ -717,10 +732,6 @@ def OMP_DeclareTarget : Directive<"declare target"> {
717732
let association = AS_None;
718733
let category = CA_Declarative;
719734
}
720-
def OMP_EndDeclareTarget : Directive<"end declare target"> {
721-
let association = AS_Delimited;
722-
let category = OMP_DeclareTarget.category;
723-
}
724735
def OMP_DeclareVariant : Directive<"declare variant"> {
725736
let allowedClauses = [
726737
VersionedClause<OMPC_AdjustArgs, 51>,
@@ -731,10 +742,7 @@ def OMP_DeclareVariant : Directive<"declare variant"> {
731742
];
732743
let association = AS_Declaration;
733744
let category = CA_Declarative;
734-
}
735-
def OMP_EndDeclareVariant : Directive<"end declare variant"> {
736-
let association = AS_Delimited;
737-
let category = OMP_DeclareVariant.category;
745+
let languages = [L_C];
738746
}
739747
def OMP_Depobj : Directive<"depobj"> {
740748
let allowedClauses = [
@@ -793,15 +801,16 @@ def OMP_Do : Directive<"do"> {
793801
];
794802
let association = AS_Loop;
795803
let category = CA_Executable;
804+
let languages = [L_Fortran];
796805
}
797806
def OMP_EndDo : Directive<"end do"> {
798807
let allowedOnceClauses = [
799808
VersionedClause<OMPC_NoWait>,
800809
];
801-
// Needed for association computation, since OMP_Do has it "from leafConstructs".
802810
let leafConstructs = OMP_Do.leafConstructs;
803811
let association = OMP_Do.association;
804812
let category = OMP_Do.category;
813+
let languages = OMP_Do.languages;
805814
}
806815
def OMP_Error : Directive<"error"> {
807816
let allowedClauses = [
@@ -841,6 +850,7 @@ def OMP_For : Directive<"for"> {
841850
];
842851
let association = AS_Loop;
843852
let category = CA_Executable;
853+
let languages = [L_C];
844854
}
845855
def OMP_Interchange : Directive<"interchange"> {
846856
let allowedOnceClauses = [
@@ -984,6 +994,7 @@ def OMP_EndScope : Directive<"end scope"> {
984994
let leafConstructs = OMP_Scope.leafConstructs;
985995
let association = OMP_Scope.association;
986996
let category = OMP_Scope.category;
997+
let languages = [L_Fortran];
987998
}
988999
def OMP_Section : Directive<"section"> {
9891000
let association = AS_Separating;
@@ -1008,6 +1019,7 @@ def OMP_EndSections : Directive<"end sections"> {
10081019
let leafConstructs = OMP_Sections.leafConstructs;
10091020
let association = OMP_Sections.association;
10101021
let category = OMP_Sections.category;
1022+
let languages = [L_Fortran];
10111023
}
10121024
def OMP_Simd : Directive<"simd"> {
10131025
let allowedClauses = [
@@ -1052,6 +1064,7 @@ def OMP_EndSingle : Directive<"end single"> {
10521064
let leafConstructs = OMP_Single.leafConstructs;
10531065
let association = OMP_Single.association;
10541066
let category = OMP_Single.category;
1067+
let languages = [L_Fortran];
10551068
}
10561069
def OMP_Target : Directive<"target"> {
10571070
let allowedClauses = [
@@ -1259,6 +1272,7 @@ def OMP_Workshare : Directive<"workshare"> {
12591272
];
12601273
let association = AS_Block;
12611274
let category = CA_Executable;
1275+
let languages = [L_Fortran];
12621276
}
12631277
def OMP_EndWorkshare : Directive<"end workshare"> {
12641278
let allowedOnceClauses = [
@@ -1267,6 +1281,7 @@ def OMP_EndWorkshare : Directive<"end workshare"> {
12671281
let leafConstructs = OMP_Workshare.leafConstructs;
12681282
let association = OMP_Workshare.association;
12691283
let category = OMP_Workshare.category;
1284+
let languages = [L_Fortran];
12701285
}
12711286

12721287
//===----------------------------------------------------------------------===//
@@ -1298,6 +1313,7 @@ def OMP_DistributeParallelDo : Directive<"distribute parallel do"> {
12981313
];
12991314
let leafConstructs = [OMP_Distribute, OMP_Parallel, OMP_Do];
13001315
let category = CA_Executable;
1316+
let languages = [L_Fortran];
13011317
}
13021318
def OMP_DistributeParallelDoSimd : Directive<"distribute parallel do simd"> {
13031319
let allowedClauses = [
@@ -1324,6 +1340,7 @@ def OMP_DistributeParallelDoSimd : Directive<"distribute parallel do simd"> {
13241340
];
13251341
let leafConstructs = [OMP_Distribute, OMP_Parallel, OMP_Do, OMP_Simd];
13261342
let category = CA_Executable;
1343+
let languages = [L_Fortran];
13271344
}
13281345
def OMP_DistributeParallelFor : Directive<"distribute parallel for"> {
13291346
let allowedClauses = [
@@ -1346,6 +1363,7 @@ def OMP_DistributeParallelFor : Directive<"distribute parallel for"> {
13461363
];
13471364
let leafConstructs = [OMP_Distribute, OMP_Parallel, OMP_For];
13481365
let category = CA_Executable;
1366+
let languages = [L_C];
13491367
}
13501368
def OMP_DistributeParallelForSimd : Directive<"distribute parallel for simd"> {
13511369
let allowedClauses = [
@@ -1373,6 +1391,7 @@ def OMP_DistributeParallelForSimd : Directive<"distribute parallel for simd"> {
13731391
];
13741392
let leafConstructs = [OMP_Distribute, OMP_Parallel, OMP_For, OMP_Simd];
13751393
let category = CA_Executable;
1394+
let languages = [L_C];
13761395
}
13771396
def OMP_DistributeSimd : Directive<"distribute simd"> {
13781397
let allowedClauses = [
@@ -1422,6 +1441,7 @@ def OMP_DoSimd : Directive<"do simd"> {
14221441
];
14231442
let leafConstructs = [OMP_Do, OMP_Simd];
14241443
let category = CA_Executable;
1444+
let languages = [L_Fortran];
14251445
}
14261446
def OMP_EndDoSimd : Directive<"end do simd"> {
14271447
let allowedOnceClauses = [
@@ -1430,6 +1450,7 @@ def OMP_EndDoSimd : Directive<"end do simd"> {
14301450
let leafConstructs = OMP_DoSimd.leafConstructs;
14311451
let association = OMP_DoSimd.association;
14321452
let category = OMP_DoSimd.category;
1453+
let languages = [L_Fortran];
14331454
}
14341455
def OMP_ForSimd : Directive<"for simd"> {
14351456
let allowedClauses = [
@@ -1611,6 +1632,7 @@ def OMP_ParallelDo : Directive<"parallel do"> {
16111632
];
16121633
let leafConstructs = [OMP_Parallel, OMP_Do];
16131634
let category = CA_Executable;
1635+
let languages = [L_Fortran];
16141636
}
16151637
def OMP_ParallelDoSimd : Directive<"parallel do simd"> {
16161638
let allowedClauses = [
@@ -1639,6 +1661,7 @@ def OMP_ParallelDoSimd : Directive<"parallel do simd"> {
16391661
];
16401662
let leafConstructs = [OMP_Parallel, OMP_Do, OMP_Simd];
16411663
let category = CA_Executable;
1664+
let languages = [L_Fortran];
16421665
}
16431666
def OMP_ParallelFor : Directive<"parallel for"> {
16441667
let allowedClauses = [
@@ -1662,6 +1685,7 @@ def OMP_ParallelFor : Directive<"parallel for"> {
16621685
];
16631686
let leafConstructs = [OMP_Parallel, OMP_For];
16641687
let category = CA_Executable;
1688+
let languages = [L_C];
16651689
}
16661690
def OMP_ParallelForSimd : Directive<"parallel for simd"> {
16671691
let allowedClauses = [
@@ -1689,6 +1713,7 @@ def OMP_ParallelForSimd : Directive<"parallel for simd"> {
16891713
];
16901714
let leafConstructs = [OMP_Parallel, OMP_For, OMP_Simd];
16911715
let category = CA_Executable;
1716+
let languages = [L_C];
16921717
}
16931718
def OMP_parallel_loop : Directive<"parallel loop"> {
16941719
let allowedClauses = [
@@ -1907,6 +1932,7 @@ def OMP_ParallelWorkshare : Directive<"parallel workshare"> {
19071932
];
19081933
let leafConstructs = [OMP_Parallel, OMP_Workshare];
19091934
let category = CA_Executable;
1935+
let languages = [L_Fortran];
19101936
}
19111937
def OMP_TargetParallel : Directive<"target parallel"> {
19121938
let allowedClauses = [
@@ -1966,6 +1992,7 @@ def OMP_TargetParallelDo : Directive<"target parallel do"> {
19661992
];
19671993
let leafConstructs = [OMP_Target, OMP_Parallel, OMP_Do];
19681994
let category = CA_Executable;
1995+
let languages = [L_Fortran];
19691996
}
19701997
def OMP_TargetParallelDoSimd : Directive<"target parallel do simd"> {
19711998
let allowedClauses = [
@@ -1999,6 +2026,7 @@ def OMP_TargetParallelDoSimd : Directive<"target parallel do simd"> {
19992026
];
20002027
let leafConstructs = [OMP_Target, OMP_Parallel, OMP_Do, OMP_Simd];
20012028
let category = CA_Executable;
2029+
let languages = [L_Fortran];
20022030
}
20032031
def OMP_TargetParallelFor : Directive<"target parallel for"> {
20042032
let allowedClauses = [
@@ -2033,6 +2061,7 @@ def OMP_TargetParallelFor : Directive<"target parallel for"> {
20332061
];
20342062
let leafConstructs = [OMP_Target, OMP_Parallel, OMP_For];
20352063
let category = CA_Executable;
2064+
let languages = [L_C];
20362065
}
20372066
def OMP_TargetParallelForSimd : Directive<"target parallel for simd"> {
20382067
let allowedClauses = [
@@ -2071,6 +2100,7 @@ def OMP_TargetParallelForSimd : Directive<"target parallel for simd"> {
20712100
];
20722101
let leafConstructs = [OMP_Target, OMP_Parallel, OMP_For, OMP_Simd];
20732102
let category = CA_Executable;
2103+
let languages = [L_C];
20742104
}
20752105
def OMP_target_parallel_loop : Directive<"target parallel loop"> {
20762106
let allowedClauses = [
@@ -2230,8 +2260,10 @@ def OMP_TargetTeamsDistributeParallelDo :
22302260
VersionedClause<OMPC_Schedule>,
22312261
VersionedClause<OMPC_ThreadLimit>,
22322262
];
2233-
let leafConstructs = [OMP_Target, OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_Do];
2263+
let leafConstructs =
2264+
[OMP_Target, OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_Do];
22342265
let category = CA_Executable;
2266+
let languages = [L_Fortran];
22352267
}
22362268
def OMP_TargetTeamsDistributeParallelDoSimd :
22372269
Directive<"target teams distribute parallel do simd"> {
@@ -2268,8 +2300,10 @@ def OMP_TargetTeamsDistributeParallelDoSimd :
22682300
VersionedClause<OMPC_SimdLen>,
22692301
VersionedClause<OMPC_ThreadLimit>,
22702302
];
2271-
let leafConstructs = [OMP_Target, OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_Do, OMP_Simd];
2303+
let leafConstructs =
2304+
[OMP_Target, OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_Do, OMP_Simd];
22722305
let category = CA_Executable;
2306+
let languages = [L_Fortran];
22732307
}
22742308
def OMP_TargetTeamsDistributeParallelFor :
22752309
Directive<"target teams distribute parallel for"> {
@@ -2303,8 +2337,10 @@ def OMP_TargetTeamsDistributeParallelFor :
23032337
let allowedOnceClauses = [
23042338
VersionedClause<OMPC_OMPX_DynCGroupMem>,
23052339
];
2306-
let leafConstructs = [OMP_Target, OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_For];
2340+
let leafConstructs =
2341+
[OMP_Target, OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_For];
23072342
let category = CA_Executable;
2343+
let languages = [L_C];
23082344
}
23092345
def OMP_TargetTeamsDistributeParallelForSimd :
23102346
Directive<"target teams distribute parallel for simd"> {
@@ -2343,8 +2379,10 @@ def OMP_TargetTeamsDistributeParallelForSimd :
23432379
let allowedOnceClauses = [
23442380
VersionedClause<OMPC_OMPX_DynCGroupMem>,
23452381
];
2346-
let leafConstructs = [OMP_Target, OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_For, OMP_Simd];
2382+
let leafConstructs =
2383+
[OMP_Target, OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_For, OMP_Simd];
23472384
let category = CA_Executable;
2385+
let languages = [L_C];
23482386
}
23492387
def OMP_TargetTeamsDistributeSimd :
23502388
Directive<"target teams distribute simd"> {
@@ -2494,6 +2532,7 @@ def OMP_TeamsDistributeParallelDo :
24942532
];
24952533
let leafConstructs = [OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_Do];
24962534
let category = CA_Executable;
2535+
let languages = [L_Fortran];
24972536
}
24982537
def OMP_TeamsDistributeParallelDoSimd :
24992538
Directive<"teams distribute parallel do simd"> {
@@ -2522,8 +2561,10 @@ def OMP_TeamsDistributeParallelDoSimd :
25222561
VersionedClause<OMPC_SimdLen>,
25232562
VersionedClause<OMPC_ThreadLimit>,
25242563
];
2525-
let leafConstructs = [OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_Do, OMP_Simd];
2564+
let leafConstructs =
2565+
[OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_Do, OMP_Simd];
25262566
let category = CA_Executable;
2567+
let languages = [L_Fortran];
25272568
}
25282569
def OMP_TeamsDistributeParallelFor :
25292570
Directive<"teams distribute parallel for"> {
@@ -2549,6 +2590,7 @@ def OMP_TeamsDistributeParallelFor :
25492590
];
25502591
let leafConstructs = [OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_For];
25512592
let category = CA_Executable;
2593+
let languages = [L_C];
25522594
}
25532595
def OMP_TeamsDistributeParallelForSimd :
25542596
Directive<"teams distribute parallel for simd"> {
@@ -2576,8 +2618,10 @@ def OMP_TeamsDistributeParallelForSimd :
25762618
VersionedClause<OMPC_SimdLen>,
25772619
VersionedClause<OMPC_ThreadLimit>,
25782620
];
2579-
let leafConstructs = [OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_For, OMP_Simd];
2621+
let leafConstructs =
2622+
[OMP_Teams, OMP_Distribute, OMP_Parallel, OMP_For, OMP_Simd];
25802623
let category = CA_Executable;
2624+
let languages = [L_C];
25812625
}
25822626
def OMP_TeamsDistributeSimd : Directive<"teams distribute simd"> {
25832627
let allowedClauses = [

0 commit comments

Comments
 (0)