Skip to content

Commit d69320e

Browse files
authored
[OpenMP] Introduce "loop sequence" as directive association (#168934)
OpenMP 6.0 introduced a `fuse` directive, and with it a "loop sequence" as the associated code. What used to be "loop association" has become "loop-nest association". Rename Association::Loop to LoopNest, add Association::LoopSeq to represent the "loop sequence" association. Change the association of fuse from "block" to "loop sequence".
1 parent fe74323 commit d69320e

File tree

9 files changed

+38
-34
lines changed

9 files changed

+38
-34
lines changed

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
680680
}
681681

682682
bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
683-
return getDirectiveAssociation(DKind) == Association::Loop;
683+
return getDirectiveAssociation(DKind) == Association::LoopNest;
684684
}
685685

686686
bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -741,7 +741,7 @@ bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
741741

742742
bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
743743
// Avoid OMPD_declare_simd
744-
if (getDirectiveAssociation(DKind) != Association::Loop)
744+
if (getDirectiveAssociation(DKind) != Association::LoopNest)
745745
return false;
746746
// Formally, OMPD_end_do_simd also has a loop association, but
747747
// it's a Fortran-specific directive.

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ static void createBodyOfOp(mlir::Operation &op, const OpWithBodyGenInfo &info,
12021202
// Start with privatization, so that the lowering of the nested
12031203
// code will use the right symbols.
12041204
bool isLoop = llvm::omp::getDirectiveAssociation(info.dir) ==
1205-
llvm::omp::Association::Loop;
1205+
llvm::omp::Association::LoopNest;
12061206
bool privatize = info.clauses && info.privatize;
12071207

12081208
firOpBuilder.setInsertionPoint(marker);
@@ -3398,7 +3398,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
33983398
};
33993399

34003400
bool loopLeaf = llvm::omp::getDirectiveAssociation(item->id) ==
3401-
llvm::omp::Association::Loop;
3401+
llvm::omp::Association::LoopNest;
34023402
if (loopLeaf) {
34033403
symTable.pushScope();
34043404
if (genOMPCompositeDispatch(converter, symTable, stmtCtx, semaCtx, eval,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ def AS_Block : Association<"Block"> {} // Block (incl. single
162162
def AS_Declaration : Association<"Declaration"> {} // Declaration
163163
def AS_Delimited : Association<"Delimited"> {} // Region delimited with
164164
// begin/end
165-
def AS_Loop : Association<"Loop"> {} // Loop
165+
def AS_LoopNest : Association<"LoopNest"> {} // Loop nest
166+
def AS_LoopSeq : Association<"LoopSeq"> {} // Loop sequence
166167
def AS_Separating : Association<"Separating"> {} // Separates parts of a
167168
// construct
168169

@@ -173,7 +174,7 @@ def AS_FromLeaves : Association<"FromLeaves"> {} // See below
173174
// x + y = y + x
174175
// x + x = x
175176
// AS_None + x = x
176-
// AS_Block + AS_Loop = AS_Loop
177+
// AS_Block + AS_Loop{Nest|Seq} = AS_Loop{Nest|Seq}
177178
// Other combinations are not allowed.
178179
// This association is not valid for leaf constructs.
179180
// The name "AS_FromLeaves" is recognized by TableGen, and there is no enum

llvm/include/llvm/Frontend/OpenACC/ACC.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def ACC_Loop : Directive<[Spelling<"loop">]> {
419419
VersionedClause<ACCC_Independent>,
420420
VersionedClause<ACCC_Seq>
421421
];
422-
let association = AS_Loop;
422+
let association = AS_LoopNest;
423423
let category = CA_Executable;
424424
}
425425

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def OMP_Distribute : Directive<[Spelling<"distribute">]> {
859859
VersionedClause<OMPC_DistSchedule>,
860860
VersionedClause<OMPC_Order, 50>,
861861
];
862-
let association = AS_Loop;
862+
let association = AS_LoopNest;
863863
let category = CA_Executable;
864864
}
865865
def OMP_Do : Directive<[Spelling<"do">]> {
@@ -877,7 +877,7 @@ def OMP_Do : Directive<[Spelling<"do">]> {
877877
VersionedClause<OMPC_Ordered>,
878878
VersionedClause<OMPC_Schedule>,
879879
];
880-
let association = AS_Loop;
880+
let association = AS_LoopNest;
881881
let category = CA_Executable;
882882
let languages = [L_Fortran];
883883
}
@@ -926,7 +926,7 @@ def OMP_For : Directive<[Spelling<"for">]> {
926926
VersionedClause<OMPC_Reduction>,
927927
VersionedClause<OMPC_Schedule>,
928928
];
929-
let association = AS_Loop;
929+
let association = AS_LoopNest;
930930
let category = CA_Executable;
931931
let languages = [L_C];
932932
}
@@ -940,14 +940,14 @@ def OMP_Groupprivate : Directive<[Spelling<"groupprivate">]> {
940940
}
941941
def OMP_Fuse : Directive<[Spelling<"fuse">]> {
942942
let allowedOnceClauses = [VersionedClause<OMPC_LoopRange, 60>];
943-
let association = AS_Block;
943+
let association = AS_LoopSeq;
944944
let category = CA_Executable;
945945
}
946946
def OMP_Interchange : Directive<[Spelling<"interchange">]> {
947947
let allowedOnceClauses = [
948948
VersionedClause<OMPC_Permutation>,
949949
];
950-
let association = AS_Loop;
950+
let association = AS_LoopNest;
951951
let category = CA_Executable;
952952
}
953953
def OMP_interop : Directive<[Spelling<"interop">]> {
@@ -973,7 +973,7 @@ def OMP_loop : Directive<[Spelling<"loop">]> {
973973
VersionedClause<OMPC_Collapse>,
974974
VersionedClause<OMPC_Order, 50>,
975975
];
976-
let association = AS_Loop;
976+
let association = AS_LoopNest;
977977
let category = CA_Executable;
978978
}
979979
def OMP_masked : Directive<[Spelling<"masked">]> {
@@ -1056,7 +1056,7 @@ def OMP_Requires : Directive<[Spelling<"requires">]> {
10561056
let category = CA_Informational;
10571057
}
10581058
def OMP_Reverse : Directive<[Spelling<"reverse">]> {
1059-
let association = AS_Loop;
1059+
let association = AS_LoopNest;
10601060
let category = CA_Executable;
10611061
}
10621062
def OMP_Scan : Directive<[Spelling<"scan">]> {
@@ -1131,7 +1131,7 @@ def OMP_Simd : Directive<[Spelling<"simd">]> {
11311131
VersionedClause<OMPC_SafeLen>,
11321132
VersionedClause<OMPC_SimdLen>,
11331133
];
1134-
let association = AS_Loop;
1134+
let association = AS_LoopNest;
11351135
let category = CA_Executable;
11361136
}
11371137
def OMP_Single : Directive<[Spelling<"single">]> {
@@ -1323,7 +1323,7 @@ def OMP_TaskLoop : Directive<[Spelling<"taskloop">]> {
13231323
VersionedClause<OMPC_GrainSize>,
13241324
VersionedClause<OMPC_NumTasks>,
13251325
];
1326-
let association = AS_Loop;
1326+
let association = AS_LoopNest;
13271327
let category = CA_Executable;
13281328
}
13291329
def OMP_TaskWait : Directive<[Spelling<"taskwait">]> {
@@ -1371,14 +1371,14 @@ def OMP_Tile : Directive<[Spelling<"tile">]> {
13711371
let requiredClauses = [
13721372
VersionedClause<OMPC_Sizes, 51>,
13731373
];
1374-
let association = AS_Loop;
1374+
let association = AS_LoopNest;
13751375
let category = CA_Executable;
13761376
}
13771377
def OMP_Stripe : Directive<[Spelling<"stripe">]> {
13781378
let allowedOnceClauses = [
13791379
VersionedClause<OMPC_Sizes, 60>,
13801380
];
1381-
let association = AS_Loop;
1381+
let association = AS_LoopNest;
13821382
let category = CA_Executable;
13831383
}
13841384
def OMP_Unknown : Directive<[Spelling<"unknown">]> {
@@ -1391,7 +1391,7 @@ def OMP_Unroll : Directive<[Spelling<"unroll">]> {
13911391
VersionedClause<OMPC_Full, 51>,
13921392
VersionedClause<OMPC_Partial, 51>,
13931393
];
1394-
let association = AS_Loop;
1394+
let association = AS_LoopNest;
13951395
let category = CA_Executable;
13961396
}
13971397
def OMP_Workshare : Directive<[Spelling<"workshare">]> {

llvm/lib/Frontend/OpenMP/OMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ getFirstCompositeRange(iterator_range<ArrayRef<Directive>::iterator> Leafs) {
5353
auto firstLoopAssociated =
5454
[](iterator_range<ArrayRef<Directive>::iterator> List) {
5555
for (auto It = List.begin(), End = List.end(); It != End; ++It) {
56-
if (getDirectiveAssociation(*It) == Association::Loop)
56+
if (getDirectiveAssociation(*It) == Association::LoopNest)
5757
return It;
5858
}
5959
return List.end();
@@ -71,7 +71,7 @@ getFirstCompositeRange(iterator_range<ArrayRef<Directive>::iterator> Leafs) {
7171
return Empty;
7272

7373
for (; End != Leafs.end(); ++End) {
74-
if (getDirectiveAssociation(*End) != Association::Loop)
74+
if (getDirectiveAssociation(*End) != Association::LoopNest)
7575
break;
7676
}
7777
return llvm::make_range(Begin, End);

llvm/test/TableGen/directive1.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
7171
// CHECK-NEXT: First_ = Block,
7272
// CHECK-NEXT: Declaration,
7373
// CHECK-NEXT: Delimited,
74-
// CHECK-NEXT: Loop,
74+
// CHECK-NEXT: LoopNest,
75+
// CHECK-NEXT: LoopSeq,
7576
// CHECK-NEXT: None,
7677
// CHECK-NEXT: Separating,
7778
// CHECK-NEXT: Last_ = Separating,
7879
// CHECK-NEXT: };
7980
// CHECK-EMPTY:
80-
// CHECK-NEXT: static constexpr std::size_t Association_enumSize = 6;
81+
// CHECK-NEXT: static constexpr std::size_t Association_enumSize = 7;
8182
// CHECK-EMPTY:
8283
// CHECK-NEXT: enum class Category {
8384
// CHECK-NEXT: Declarative,

llvm/test/TableGen/directive2.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
6262
// CHECK-NEXT: First_ = Block,
6363
// CHECK-NEXT: Declaration,
6464
// CHECK-NEXT: Delimited,
65-
// CHECK-NEXT: Loop,
65+
// CHECK-NEXT: LoopNest,
66+
// CHECK-NEXT: LoopSeq,
6667
// CHECK-NEXT: None,
6768
// CHECK-NEXT: Separating,
6869
// CHECK-NEXT: Last_ = Separating,
6970
// CHECK-NEXT: };
7071
// CHECK-EMPTY:
71-
// CHECK-NEXT: static constexpr std::size_t Association_enumSize = 6;
72+
// CHECK-NEXT: static constexpr std::size_t Association_enumSize = 7;
7273
// CHECK-EMPTY:
7374
// CHECK-NEXT: enum class Category {
7475
// CHECK-NEXT: Declarative,

llvm/utils/TableGen/Basic/DirectiveEmitter.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,12 @@ static void emitLeafTable(const DirectiveLanguage &DirLang, raw_ostream &OS,
729729
static void generateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
730730
raw_ostream &OS) {
731731
enum struct Association {
732-
None = 0, // None should be the smallest value.
733-
Block, // The values of the rest don't matter.
734-
Declaration,
732+
None = 0, // None should be the smallest value.
733+
Block, // If the order of the rest of these changes, update the
734+
Declaration, // 'Reduce' function below.
735735
Delimited,
736-
Loop,
736+
LoopNest,
737+
LoopSeq,
737738
Separating,
738739
FromLeaves,
739740
Invalid,
@@ -746,7 +747,8 @@ static void generateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
746747
.Case("AS_Block", Association::Block)
747748
.Case("AS_Declaration", Association::Declaration)
748749
.Case("AS_Delimited", Association::Delimited)
749-
.Case("AS_Loop", Association::Loop)
750+
.Case("AS_LoopNest", Association::LoopNest)
751+
.Case("AS_LoopSeq", Association::LoopSeq)
750752
.Case("AS_None", Association::None)
751753
.Case("AS_Separating", Association::Separating)
752754
.Case("AS_FromLeaves", Association::FromLeaves)
@@ -777,13 +779,12 @@ static void generateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
777779
// Calculate the result using the following rules:
778780
// x + x = x
779781
// AS_None + x = x
780-
// AS_Block + AS_Loop = AS_Loop
782+
// AS_Block + AS_Loop{Nest|Seq} = AS_Loop{Nest|Seq}
781783
if (A == Association::None || A == B)
782784
return B;
783-
if (A == Association::Block && B == Association::Loop)
785+
if (A == Association::Block &&
786+
(B == Association::LoopNest || B == Association::LoopSeq))
784787
return B;
785-
if (A == Association::Loop && B == Association::Block)
786-
return A;
787788
return Association::Invalid;
788789
};
789790

0 commit comments

Comments
 (0)