Skip to content

Commit 5282541

Browse files
committed
Remove OMPLoopCategory enum and Category field
With the rearranged AST hierarchy we don't need it. Storing the original Stmt should be enough now. This change also introduces a few helper functions so we can keep the generation of the analysis and the use of the analysis in sync (this was previously done through the Category field)
1 parent 6ae86ec commit 5282541

File tree

2 files changed

+36
-46
lines changed

2 files changed

+36
-46
lines changed

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,40 +1494,36 @@ class SemaOpenMP : public SemaBase {
14941494
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
14951495
Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *>> &OriginalInits);
14961496

1497-
/// Categories of loops encountered during semantic OpenMP loop
1498-
/// analysis.
1499-
///
1500-
/// This enumeration identifies the structural category of a loop or sequence
1501-
/// of loops analyzed in the context of OpenMP transformations and directives.
1502-
/// This categorization helps differentiate between original source loops
1503-
/// and the structures resulting from applying OpenMP loop transformations.
1504-
enum class OMPLoopCategory {
1505-
/// @var OMPLoopCategory::RegularLoop
1506-
/// Represents a standard canonical loop nest found in the
1507-
/// original source code or an intact loop after transformations
1508-
/// (i.e Post/Pre loops of a loopranged fusion).
1509-
RegularLoop,
1510-
1511-
/// @var OMPLoopCategory::TransformSingleLoop
1512-
/// Represents the resulting loop structure when an OpenMP loop
1513-
/// transformation, generates a single, top-level loop.
1514-
TransformSingleLoop,
1515-
};
1516-
15171497
/// Holds the result of the analysis of a (possibly canonical) loop.
15181498
struct LoopAnalysis {
1519-
/// Category of the analyzed loop.
1520-
OMPLoopCategory Category;
1499+
/// The analyzed loop or loop transformation.
1500+
Stmt *AStmt;
15211501
/// Loop analyses results.
15221502
OMPLoopBasedDirective::HelperExprs HelperExprs;
1523-
/// The for-statement of the loop.
1503+
/// The for-statement of the loop. ForStmt equals AStmt only when the latter
1504+
/// is a canonical loop (i.e. not a loop transformation).
15241505
Stmt *ForStmt;
15251506
/// Initialization statements before transformations.
15261507
SmallVector<Stmt *> OriginalInits;
15271508
/// Initialization statements required after transformation of this loop.
15281509
SmallVector<Stmt *> TransformsPreInits;
15291510

1530-
explicit LoopAnalysis(OMPLoopCategory Category) : Category(Category) {}
1511+
explicit LoopAnalysis(Stmt *S) : AStmt(S) {}
1512+
1513+
bool isRegularLoop() const {
1514+
return isRegularLoop(AStmt);
1515+
}
1516+
bool isLoopTransformation() const {
1517+
return isLoopTransformation(AStmt);
1518+
}
1519+
1520+
// Convenience functions used when building LoopSequenceAnalysis.
1521+
static bool isRegularLoop(Stmt *S) {
1522+
return isa<clang::ForStmt, CXXForRangeStmt>(S);
1523+
}
1524+
static bool isLoopTransformation(Stmt *S) {
1525+
return isa<OMPLoopTransformationDirective>(S);
1526+
}
15311527
};
15321528

15331529
/// Holds the result of the analysis of a (possibly canonical) loop sequence.
@@ -1538,6 +1534,12 @@ class SemaOpenMP : public SemaBase {
15381534
SmallVector<LoopAnalysis, 2> Loops;
15391535
/// Additional code required before entering the transformed loop sequence.
15401536
SmallVector<Stmt *> LoopSequencePreInits;
1537+
1538+
// Convenience function used when building the LoopSequenceAnalysis.
1539+
static bool isLoopSequenceDerivation(Stmt *S) {
1540+
return LoopAnalysis::isRegularLoop(S) ||
1541+
LoopAnalysis::isLoopTransformation(S);
1542+
}
15411543
};
15421544

15431545
/// The main recursive process of `checkTransformableLoopSequence` that

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14513,7 +14513,7 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1451314513
// Vast majority: (Tile, Unroll, Stripe, Reverse, Interchange, Fuse all)
1451414514
// Process the transformed loop statement
1451514515
LoopAnalysis &NewTransformedSingleLoop =
14516-
SeqAnalysis.Loops.emplace_back(OMPLoopCategory::TransformSingleLoop);
14516+
SeqAnalysis.Loops.emplace_back(Child);
1451714517
unsigned IsCanonical = checkOpenMPLoop(
1451814518
Kind, nullptr, nullptr, TransformedStmt, SemaRef, *DSAStack, TmpDSA,
1451914519
NewTransformedSingleLoop.HelperExprs);
@@ -14531,7 +14531,7 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1453114531
// Modularized code for handling regular canonical loops.
1453214532
auto AnalyzeRegularLoop = [&](Stmt *Child) {
1453314533
LoopAnalysis &NewRegularLoop =
14534-
SeqAnalysis.Loops.emplace_back(OMPLoopCategory::RegularLoop);
14534+
SeqAnalysis.Loops.emplace_back(Child);
1453514535
unsigned IsCanonical =
1453614536
checkOpenMPLoop(Kind, nullptr, nullptr, Child, SemaRef, *DSAStack,
1453714537
TmpDSA, NewRegularLoop.HelperExprs);
@@ -14545,21 +14545,12 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1454514545
return true;
1454614546
};
1454714547

14548-
// Helper functions to validate loop sequence grammar derivations.
14549-
auto IsLoopSequenceDerivation = [](auto *Child) {
14550-
return isa<ForStmt, CXXForRangeStmt, OMPLoopTransformationDirective>(Child);
14551-
};
14552-
// Helper functions to validate loop generating grammar derivations.
14553-
auto IsLoopGeneratingStmt = [](auto *Child) {
14554-
return isa<OMPLoopTransformationDirective>(Child);
14555-
};
14556-
1455714548
// High level grammar validation.
1455814549
for (Stmt *Child : LoopSeqStmt->children()) {
1455914550
if (!Child)
1456014551
continue;
1456114552
// Skip over non-loop-sequence statements.
14562-
if (!IsLoopSequenceDerivation(Child)) {
14553+
if (!LoopSequenceAnalysis::isLoopSequenceDerivation(Child)) {
1456314554
Child = Child->IgnoreContainers();
1456414555
// Ignore empty compound statement.
1456514556
if (!Child)
@@ -14574,8 +14565,8 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1457414565
}
1457514566
}
1457614567
// Regular loop sequence handling.
14577-
if (IsLoopSequenceDerivation(Child)) {
14578-
if (IsLoopGeneratingStmt(Child)) {
14568+
if (LoopSequenceAnalysis::isLoopSequenceDerivation(Child)) {
14569+
if (LoopAnalysis::isLoopTransformation(Child)) {
1457914570
if (!AnalyzeLoopGeneration(Child))
1458014571
return false;
1458114572
// AnalyzeLoopGeneration updates SeqAnalysis.LoopSeqSize accordingly.
@@ -16073,17 +16064,16 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1607316064
// looprange section
1607416065
unsigned int TransformIndex = 0;
1607516066
for (unsigned I : llvm::seq<unsigned>(FirstVal - 1)) {
16076-
if (SeqAnalysis.Loops[I].Category == OMPLoopCategory::TransformSingleLoop)
16067+
if (SeqAnalysis.Loops[I].isLoopTransformation())
1607716068
++TransformIndex;
1607816069
}
1607916070

1608016071
for (unsigned int I = FirstVal - 1, J = 0; I < LastVal; ++I, ++J) {
16081-
if (SeqAnalysis.Loops[I].Category == OMPLoopCategory::RegularLoop) {
16072+
if (SeqAnalysis.Loops[I].isRegularLoop()) {
1608216073
addLoopPreInits(Context, SeqAnalysis.Loops[I].HelperExprs,
1608316074
SeqAnalysis.Loops[I].ForStmt,
1608416075
SeqAnalysis.Loops[I].OriginalInits, PreInits);
16085-
} else if (SeqAnalysis.Loops[I].Category ==
16086-
OMPLoopCategory::TransformSingleLoop) {
16076+
} else if (SeqAnalysis.Loops[I].isLoopTransformation()) {
1608716077
// For transformed loops, insert both pre-inits and original inits.
1608816078
// Order matters: pre-inits may define variables used in the original
1608916079
// inits such as upper bounds...
@@ -16352,8 +16342,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1635216342
if (I >= FirstVal - 1 && I < FirstVal + CountVal - 1) {
1635316343
// Update the Transformation counter to skip already treated
1635416344
// loop transformations
16355-
if (SeqAnalysis.Loops[I].Category !=
16356-
OMPLoopCategory::TransformSingleLoop)
16345+
if (!SeqAnalysis.Loops[I].isLoopTransformation())
1635716346
++TransformIndex;
1635816347
continue;
1635916348
}
@@ -16362,8 +16351,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1636216351
// Regular loops: they are kept intact as-is.
1636316352
// Loop-sequence-generating transformations: already handled earlier.
1636416353
// Only TransformSingleLoop requires inserting pre-inits here
16365-
if (SeqAnalysis.Loops[I].Category ==
16366-
OMPLoopCategory::TransformSingleLoop) {
16354+
if (SeqAnalysis.Loops[I].isRegularLoop()) {
1636716355
const auto &TransformPreInit =
1636816356
SeqAnalysis.Loops[TransformIndex++].TransformsPreInits;
1636916357
if (!TransformPreInit.empty())

0 commit comments

Comments
 (0)