Skip to content

Commit 0833493

Browse files
authored
[Clang][NFC] Rename OMPLoopTransformationDirective to OMPCanonicalLoopNestTransformationDirective (#155848)
This is preparatory work for the implementation of `#pragma omp fuse` in #139293 Not all OpenMP loop transformations makes sense to make them inherit from `OMPLoopBasedDirective`, in particular in OpenMP 6.0 'fuse' (to be implemented later) is a transformation of a canonical loop sequence. This change renames class `OMPLoopTransformationDirective` to `OMPCanonicalLoopNestTransformationDirective` so we can reclaim that name in a later change.
1 parent 2f2a98b commit 0833493

File tree

11 files changed

+106
-82
lines changed

11 files changed

+106
-82
lines changed

clang/include/clang/AST/StmtOpenMP.h

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -889,23 +889,24 @@ class OMPLoopBasedDirective : public OMPExecutableDirective {
889889

890890
/// Calls the specified callback function for all the loops in \p CurStmt,
891891
/// from the outermost to the innermost.
892-
static bool
893-
doForAllLoops(Stmt *CurStmt, bool TryImperfectlyNestedLoops,
894-
unsigned NumLoops,
895-
llvm::function_ref<bool(unsigned, Stmt *)> Callback,
896-
llvm::function_ref<void(OMPLoopTransformationDirective *)>
897-
OnTransformationCallback);
892+
static bool doForAllLoops(
893+
Stmt *CurStmt, bool TryImperfectlyNestedLoops, unsigned NumLoops,
894+
llvm::function_ref<bool(unsigned, Stmt *)> Callback,
895+
llvm::function_ref<void(OMPCanonicalLoopNestTransformationDirective *)>
896+
OnTransformationCallback);
898897
static bool
899898
doForAllLoops(const Stmt *CurStmt, bool TryImperfectlyNestedLoops,
900899
unsigned NumLoops,
901900
llvm::function_ref<bool(unsigned, const Stmt *)> Callback,
902-
llvm::function_ref<void(const OMPLoopTransformationDirective *)>
901+
llvm::function_ref<
902+
void(const OMPCanonicalLoopNestTransformationDirective *)>
903903
OnTransformationCallback) {
904904
auto &&NewCallback = [Callback](unsigned Cnt, Stmt *CurStmt) {
905905
return Callback(Cnt, CurStmt);
906906
};
907907
auto &&NewTransformCb =
908-
[OnTransformationCallback](OMPLoopTransformationDirective *A) {
908+
[OnTransformationCallback](
909+
OMPCanonicalLoopNestTransformationDirective *A) {
909910
OnTransformationCallback(A);
910911
};
911912
return doForAllLoops(const_cast<Stmt *>(CurStmt), TryImperfectlyNestedLoops,
@@ -918,7 +919,7 @@ class OMPLoopBasedDirective : public OMPExecutableDirective {
918919
doForAllLoops(Stmt *CurStmt, bool TryImperfectlyNestedLoops,
919920
unsigned NumLoops,
920921
llvm::function_ref<bool(unsigned, Stmt *)> Callback) {
921-
auto &&TransformCb = [](OMPLoopTransformationDirective *) {};
922+
auto &&TransformCb = [](OMPCanonicalLoopNestTransformationDirective *) {};
922923
return doForAllLoops(CurStmt, TryImperfectlyNestedLoops, NumLoops, Callback,
923924
TransformCb);
924925
}
@@ -955,19 +956,18 @@ class OMPLoopBasedDirective : public OMPExecutableDirective {
955956
}
956957
};
957958

958-
/// The base class for all loop transformation directives.
959-
class OMPLoopTransformationDirective : public OMPLoopBasedDirective {
959+
/// The base class for all transformation directives of canonical loop nests.
960+
class OMPCanonicalLoopNestTransformationDirective
961+
: public OMPLoopBasedDirective {
960962
friend class ASTStmtReader;
961963

962964
/// Number of loops generated by this loop transformation.
963965
unsigned NumGeneratedLoops = 0;
964966

965967
protected:
966-
explicit OMPLoopTransformationDirective(StmtClass SC,
967-
OpenMPDirectiveKind Kind,
968-
SourceLocation StartLoc,
969-
SourceLocation EndLoc,
970-
unsigned NumAssociatedLoops)
968+
explicit OMPCanonicalLoopNestTransformationDirective(
969+
StmtClass SC, OpenMPDirectiveKind Kind, SourceLocation StartLoc,
970+
SourceLocation EndLoc, unsigned NumAssociatedLoops)
971971
: OMPLoopBasedDirective(SC, Kind, StartLoc, EndLoc, NumAssociatedLoops) {}
972972

973973
/// Set the number of loops generated by this loop transformation.
@@ -5545,7 +5545,8 @@ class OMPTargetTeamsDistributeSimdDirective final : public OMPLoopDirective {
55455545
};
55465546

55475547
/// This represents the '#pragma omp tile' loop transformation directive.
5548-
class OMPTileDirective final : public OMPLoopTransformationDirective {
5548+
class OMPTileDirective final
5549+
: public OMPCanonicalLoopNestTransformationDirective {
55495550
friend class ASTStmtReader;
55505551
friend class OMPExecutableDirective;
55515552

@@ -5557,9 +5558,9 @@ class OMPTileDirective final : public OMPLoopTransformationDirective {
55575558

55585559
explicit OMPTileDirective(SourceLocation StartLoc, SourceLocation EndLoc,
55595560
unsigned NumLoops)
5560-
: OMPLoopTransformationDirective(OMPTileDirectiveClass,
5561-
llvm::omp::OMPD_tile, StartLoc, EndLoc,
5562-
NumLoops) {
5561+
: OMPCanonicalLoopNestTransformationDirective(
5562+
OMPTileDirectiveClass, llvm::omp::OMPD_tile, StartLoc, EndLoc,
5563+
NumLoops) {
55635564
setNumGeneratedLoops(2 * NumLoops);
55645565
}
55655566

@@ -5622,7 +5623,8 @@ class OMPTileDirective final : public OMPLoopTransformationDirective {
56225623
};
56235624

56245625
/// This represents the '#pragma omp stripe' loop transformation directive.
5625-
class OMPStripeDirective final : public OMPLoopTransformationDirective {
5626+
class OMPStripeDirective final
5627+
: public OMPCanonicalLoopNestTransformationDirective {
56265628
friend class ASTStmtReader;
56275629
friend class OMPExecutableDirective;
56285630

@@ -5634,9 +5636,9 @@ class OMPStripeDirective final : public OMPLoopTransformationDirective {
56345636

56355637
explicit OMPStripeDirective(SourceLocation StartLoc, SourceLocation EndLoc,
56365638
unsigned NumLoops)
5637-
: OMPLoopTransformationDirective(OMPStripeDirectiveClass,
5638-
llvm::omp::OMPD_stripe, StartLoc, EndLoc,
5639-
NumLoops) {
5639+
: OMPCanonicalLoopNestTransformationDirective(
5640+
OMPStripeDirectiveClass, llvm::omp::OMPD_stripe, StartLoc, EndLoc,
5641+
NumLoops) {
56405642
setNumGeneratedLoops(2 * NumLoops);
56415643
}
56425644

@@ -5702,7 +5704,8 @@ class OMPStripeDirective final : public OMPLoopTransformationDirective {
57025704
/// #pragma omp unroll
57035705
/// for (int i = 0; i < 64; ++i)
57045706
/// \endcode
5705-
class OMPUnrollDirective final : public OMPLoopTransformationDirective {
5707+
class OMPUnrollDirective final
5708+
: public OMPCanonicalLoopNestTransformationDirective {
57065709
friend class ASTStmtReader;
57075710
friend class OMPExecutableDirective;
57085711

@@ -5713,9 +5716,9 @@ class OMPUnrollDirective final : public OMPLoopTransformationDirective {
57135716
};
57145717

57155718
explicit OMPUnrollDirective(SourceLocation StartLoc, SourceLocation EndLoc)
5716-
: OMPLoopTransformationDirective(OMPUnrollDirectiveClass,
5717-
llvm::omp::OMPD_unroll, StartLoc, EndLoc,
5718-
1) {}
5719+
: OMPCanonicalLoopNestTransformationDirective(OMPUnrollDirectiveClass,
5720+
llvm::omp::OMPD_unroll,
5721+
StartLoc, EndLoc, 1) {}
57195722

57205723
/// Set the pre-init statements.
57215724
void setPreInits(Stmt *PreInits) {
@@ -5776,7 +5779,8 @@ class OMPUnrollDirective final : public OMPLoopTransformationDirective {
57765779
/// for (int i = 0; i < n; ++i)
57775780
/// ...
57785781
/// \endcode
5779-
class OMPReverseDirective final : public OMPLoopTransformationDirective {
5782+
class OMPReverseDirective final
5783+
: public OMPCanonicalLoopNestTransformationDirective {
57805784
friend class ASTStmtReader;
57815785
friend class OMPExecutableDirective;
57825786

@@ -5788,9 +5792,9 @@ class OMPReverseDirective final : public OMPLoopTransformationDirective {
57885792

57895793
explicit OMPReverseDirective(SourceLocation StartLoc, SourceLocation EndLoc,
57905794
unsigned NumLoops)
5791-
: OMPLoopTransformationDirective(OMPReverseDirectiveClass,
5792-
llvm::omp::OMPD_reverse, StartLoc,
5793-
EndLoc, NumLoops) {
5795+
: OMPCanonicalLoopNestTransformationDirective(
5796+
OMPReverseDirectiveClass, llvm::omp::OMPD_reverse, StartLoc, EndLoc,
5797+
NumLoops) {
57945798
setNumGeneratedLoops(NumLoops);
57955799
}
57965800

@@ -5848,7 +5852,8 @@ class OMPReverseDirective final : public OMPLoopTransformationDirective {
58485852
/// for (int j = 0; j < n; ++j)
58495853
/// ..
58505854
/// \endcode
5851-
class OMPInterchangeDirective final : public OMPLoopTransformationDirective {
5855+
class OMPInterchangeDirective final
5856+
: public OMPCanonicalLoopNestTransformationDirective {
58525857
friend class ASTStmtReader;
58535858
friend class OMPExecutableDirective;
58545859

@@ -5860,9 +5865,9 @@ class OMPInterchangeDirective final : public OMPLoopTransformationDirective {
58605865

58615866
explicit OMPInterchangeDirective(SourceLocation StartLoc,
58625867
SourceLocation EndLoc, unsigned NumLoops)
5863-
: OMPLoopTransformationDirective(OMPInterchangeDirectiveClass,
5864-
llvm::omp::OMPD_interchange, StartLoc,
5865-
EndLoc, NumLoops) {
5868+
: OMPCanonicalLoopNestTransformationDirective(
5869+
OMPInterchangeDirectiveClass, llvm::omp::OMPD_interchange, StartLoc,
5870+
EndLoc, NumLoops) {
58665871
setNumGeneratedLoops(NumLoops);
58675872
}
58685873

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ bool isOpenMPTaskingDirective(OpenMPDirectiveKind Kind);
365365
/// functions
366366
bool isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind);
367367

368+
/// Checks if the specified directive is a loop transformation directive that
369+
/// applies to a canonical loop nest.
370+
/// \param DKind Specified directive.
371+
/// \return True iff the directive is a loop transformation.
372+
bool isOpenMPCanonicalLoopNestTransformationDirective(
373+
OpenMPDirectiveKind DKind);
374+
368375
/// Checks if the specified directive is a loop transformation directive.
369376
/// \param DKind Specified directive.
370377
/// \return True iff the directive is a loop transformation.

clang/include/clang/Basic/StmtNodes.td

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,14 @@ def OMPLoopBasedDirective : StmtNode<OMPExecutableDirective, 1>;
230230
def OMPLoopDirective : StmtNode<OMPLoopBasedDirective, 1>;
231231
def OMPParallelDirective : StmtNode<OMPExecutableDirective>;
232232
def OMPSimdDirective : StmtNode<OMPLoopDirective>;
233-
def OMPLoopTransformationDirective : StmtNode<OMPLoopBasedDirective, 1>;
234-
def OMPTileDirective : StmtNode<OMPLoopTransformationDirective>;
235-
def OMPStripeDirective : StmtNode<OMPLoopTransformationDirective>;
236-
def OMPUnrollDirective : StmtNode<OMPLoopTransformationDirective>;
237-
def OMPReverseDirective : StmtNode<OMPLoopTransformationDirective>;
238-
def OMPInterchangeDirective : StmtNode<OMPLoopTransformationDirective>;
233+
def OMPCanonicalLoopNestTransformationDirective
234+
: StmtNode<OMPLoopBasedDirective, 1>;
235+
def OMPTileDirective : StmtNode<OMPCanonicalLoopNestTransformationDirective>;
236+
def OMPStripeDirective : StmtNode<OMPCanonicalLoopNestTransformationDirective>;
237+
def OMPUnrollDirective : StmtNode<OMPCanonicalLoopNestTransformationDirective>;
238+
def OMPReverseDirective : StmtNode<OMPCanonicalLoopNestTransformationDirective>;
239+
def OMPInterchangeDirective
240+
: StmtNode<OMPCanonicalLoopNestTransformationDirective>;
239241
def OMPForDirective : StmtNode<OMPLoopDirective>;
240242
def OMPForSimdDirective : StmtNode<OMPLoopDirective>;
241243
def OMPSectionsDirective : StmtNode<OMPExecutableDirective>;

clang/lib/AST/StmtOpenMP.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ OMPLoopBasedDirective::tryToFindNextInnerLoop(Stmt *CurStmt,
125125
bool OMPLoopBasedDirective::doForAllLoops(
126126
Stmt *CurStmt, bool TryImperfectlyNestedLoops, unsigned NumLoops,
127127
llvm::function_ref<bool(unsigned, Stmt *)> Callback,
128-
llvm::function_ref<void(OMPLoopTransformationDirective *)>
128+
llvm::function_ref<void(OMPCanonicalLoopNestTransformationDirective *)>
129129
OnTransformationCallback) {
130130
CurStmt = CurStmt->IgnoreContainers();
131131
for (unsigned Cnt = 0; Cnt < NumLoops; ++Cnt) {
132132
while (true) {
133-
auto *Dir = dyn_cast<OMPLoopTransformationDirective>(CurStmt);
133+
auto *Dir =
134+
dyn_cast<OMPCanonicalLoopNestTransformationDirective>(CurStmt);
134135
if (!Dir)
135136
break;
136137

@@ -369,11 +370,11 @@ OMPForDirective *OMPForDirective::Create(
369370
return Dir;
370371
}
371372

372-
Stmt *OMPLoopTransformationDirective::getTransformedStmt() const {
373+
Stmt *OMPCanonicalLoopNestTransformationDirective::getTransformedStmt() const {
373374
switch (getStmtClass()) {
374375
#define STMT(CLASS, PARENT)
375376
#define ABSTRACT_STMT(CLASS)
376-
#define OMPLOOPTRANSFORMATIONDIRECTIVE(CLASS, PARENT) \
377+
#define OMPCANONICALLOOPNESTTRANSFORMATIONDIRECTIVE(CLASS, PARENT) \
377378
case Stmt::CLASS##Class: \
378379
return static_cast<const CLASS *>(this)->getTransformedStmt();
379380
#include "clang/AST/StmtNodes.inc"
@@ -382,11 +383,11 @@ Stmt *OMPLoopTransformationDirective::getTransformedStmt() const {
382383
}
383384
}
384385

385-
Stmt *OMPLoopTransformationDirective::getPreInits() const {
386+
Stmt *OMPCanonicalLoopNestTransformationDirective::getPreInits() const {
386387
switch (getStmtClass()) {
387388
#define STMT(CLASS, PARENT)
388389
#define ABSTRACT_STMT(CLASS)
389-
#define OMPLOOPTRANSFORMATIONDIRECTIVE(CLASS, PARENT) \
390+
#define OMPCANONICALLOOPNESTTRANSFORMATIONDIRECTIVE(CLASS, PARENT) \
390391
case Stmt::CLASS##Class: \
391392
return static_cast<const CLASS *>(this)->getPreInits();
392393
#include "clang/AST/StmtNodes.inc"

clang/lib/AST/StmtProfile.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -999,30 +999,30 @@ void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
999999
VisitOMPLoopDirective(S);
10001000
}
10011001

1002-
void StmtProfiler::VisitOMPLoopTransformationDirective(
1003-
const OMPLoopTransformationDirective *S) {
1002+
void StmtProfiler::VisitOMPCanonicalLoopNestTransformationDirective(
1003+
const OMPCanonicalLoopNestTransformationDirective *S) {
10041004
VisitOMPLoopBasedDirective(S);
10051005
}
10061006

10071007
void StmtProfiler::VisitOMPTileDirective(const OMPTileDirective *S) {
1008-
VisitOMPLoopTransformationDirective(S);
1008+
VisitOMPCanonicalLoopNestTransformationDirective(S);
10091009
}
10101010

10111011
void StmtProfiler::VisitOMPStripeDirective(const OMPStripeDirective *S) {
1012-
VisitOMPLoopTransformationDirective(S);
1012+
VisitOMPCanonicalLoopNestTransformationDirective(S);
10131013
}
10141014

10151015
void StmtProfiler::VisitOMPUnrollDirective(const OMPUnrollDirective *S) {
1016-
VisitOMPLoopTransformationDirective(S);
1016+
VisitOMPCanonicalLoopNestTransformationDirective(S);
10171017
}
10181018

10191019
void StmtProfiler::VisitOMPReverseDirective(const OMPReverseDirective *S) {
1020-
VisitOMPLoopTransformationDirective(S);
1020+
VisitOMPCanonicalLoopNestTransformationDirective(S);
10211021
}
10221022

10231023
void StmtProfiler::VisitOMPInterchangeDirective(
10241024
const OMPInterchangeDirective *S) {
1025-
VisitOMPLoopTransformationDirective(S);
1025+
VisitOMPCanonicalLoopNestTransformationDirective(S);
10261026
}
10271027

10281028
void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,17 @@ bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) {
717717
Kind == OMPD_teams_loop || Kind == OMPD_target_teams_loop;
718718
}
719719

720-
bool clang::isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind) {
720+
bool clang::isOpenMPCanonicalLoopNestTransformationDirective(
721+
OpenMPDirectiveKind DKind) {
721722
return DKind == OMPD_tile || DKind == OMPD_unroll || DKind == OMPD_reverse ||
722723
DKind == OMPD_interchange || DKind == OMPD_stripe;
723724
}
724725

726+
bool clang::isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind) {
727+
// FIXME: There will be more cases when we implement 'fuse'.
728+
return isOpenMPCanonicalLoopNestTransformationDirective(DKind);
729+
}
730+
725731
bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) {
726732
return DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
727733
DKind == OMPD_parallel_master ||

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,8 @@ static void emitBody(CodeGenFunction &CGF, const Stmt *S, const Stmt *NextLoop,
19391939
return;
19401940
}
19411941
if (SimplifiedS == NextLoop) {
1942-
if (auto *Dir = dyn_cast<OMPLoopTransformationDirective>(SimplifiedS))
1942+
if (auto *Dir =
1943+
dyn_cast<OMPCanonicalLoopNestTransformationDirective>(SimplifiedS))
19431944
SimplifiedS = Dir->getTransformedStmt();
19441945
if (const auto *CanonLoop = dyn_cast<OMPCanonicalLoop>(SimplifiedS))
19451946
SimplifiedS = CanonLoop->getLoopStmt();

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,7 +4146,8 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
41464146
VisitSubCaptures(S);
41474147
}
41484148

4149-
void VisitOMPLoopTransformationDirective(OMPLoopTransformationDirective *S) {
4149+
void VisitOMPCanonicalLoopNestTransformationDirective(
4150+
OMPCanonicalLoopNestTransformationDirective *S) {
41504151
// Loop transformation directives do not introduce data sharing
41514152
VisitStmt(S);
41524153
}
@@ -9773,7 +9774,8 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
97739774
}
97749775
return false;
97759776
},
9776-
[&SemaRef, &Captures](OMPLoopTransformationDirective *Transform) {
9777+
[&SemaRef,
9778+
&Captures](OMPCanonicalLoopNestTransformationDirective *Transform) {
97779779
Stmt *DependentPreInits = Transform->getPreInits();
97789780
if (!DependentPreInits)
97799781
return;

clang/lib/Serialization/ASTReaderStmt.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,30 +2447,30 @@ void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) {
24472447
VisitOMPLoopDirective(D);
24482448
}
24492449

2450-
void ASTStmtReader::VisitOMPLoopTransformationDirective(
2451-
OMPLoopTransformationDirective *D) {
2450+
void ASTStmtReader::VisitOMPCanonicalLoopNestTransformationDirective(
2451+
OMPCanonicalLoopNestTransformationDirective *D) {
24522452
VisitOMPLoopBasedDirective(D);
24532453
D->setNumGeneratedLoops(Record.readUInt32());
24542454
}
24552455

24562456
void ASTStmtReader::VisitOMPTileDirective(OMPTileDirective *D) {
2457-
VisitOMPLoopTransformationDirective(D);
2457+
VisitOMPCanonicalLoopNestTransformationDirective(D);
24582458
}
24592459

24602460
void ASTStmtReader::VisitOMPStripeDirective(OMPStripeDirective *D) {
2461-
VisitOMPLoopTransformationDirective(D);
2461+
VisitOMPCanonicalLoopNestTransformationDirective(D);
24622462
}
24632463

24642464
void ASTStmtReader::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
2465-
VisitOMPLoopTransformationDirective(D);
2465+
VisitOMPCanonicalLoopNestTransformationDirective(D);
24662466
}
24672467

24682468
void ASTStmtReader::VisitOMPReverseDirective(OMPReverseDirective *D) {
2469-
VisitOMPLoopTransformationDirective(D);
2469+
VisitOMPCanonicalLoopNestTransformationDirective(D);
24702470
}
24712471

24722472
void ASTStmtReader::VisitOMPInterchangeDirective(OMPInterchangeDirective *D) {
2473-
VisitOMPLoopTransformationDirective(D);
2473+
VisitOMPCanonicalLoopNestTransformationDirective(D);
24742474
}
24752475

24762476
void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {

0 commit comments

Comments
 (0)