@@ -1493,16 +1493,96 @@ class SemaOpenMP : public SemaBase {
1493
1493
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
1494
1494
Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *, 0 >> &OriginalInits);
1495
1495
1496
- // / Analyzes and checks a loop sequence for use by a loop transformation
1496
+ // / @brief Categories of loops encountered during semantic OpenMP loop
1497
+ // / analysis
1498
+ // /
1499
+ // / This enumeration identifies the structural category of a loop or sequence
1500
+ // / of loops analyzed in the context of OpenMP transformations and directives.
1501
+ // / This categorization helps differentiate between original source loops
1502
+ // / and the structures resulting from applying OpenMP loop transformations.
1503
+ enum class OMPLoopCategory {
1504
+
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
+ // / @var OMPLoopCategory::TransformLoopSequence
1517
+ // / Represents the resulting loop structure when an OpenMP loop
1518
+ // / transformation
1519
+ // / generates a sequence of two or more canonical loop nests
1520
+ TransformLoopSequence
1521
+ };
1522
+
1523
+ // / The main recursive process of `checkTransformableLoopSequence` that
1524
+ // / performs grammatical parsing of a canonical loop sequence. It extracts
1525
+ // / key information, such as the number of top-level loops, loop statements,
1526
+ // / helper expressions, and other relevant loop-related data, all in a single
1527
+ // / execution to avoid redundant traversals. This analysis flattens inner
1528
+ // / Loop Sequences
1529
+ // /
1530
+ // / \param LoopSeqStmt The AST of the original statement.
1531
+ // / \param LoopSeqSize [out] Number of top level canonical loops.
1532
+ // / \param NumLoops [out] Number of total canonical loops (nested too).
1533
+ // / \param LoopHelpers [out] The multiple loop analyses results.
1534
+ // / \param ForStmts [out] The multiple Stmt of each For loop.
1535
+ // / \param OriginalInits [out] The raw original initialization statements
1536
+ // / of each belonging to a loop of the loop sequence
1537
+ // / \param TransformPreInits [out] The multiple collection of statements and
1538
+ // / declarations that must have been executed/declared
1539
+ // / before entering the loop (each belonging to a
1540
+ // / particular loop transformation, nullptr otherwise)
1541
+ // / \param LoopSequencePreInits [out] Additional general collection of loop
1542
+ // / transformation related statements and declarations
1543
+ // / not bounded to a particular loop that must be
1544
+ // / executed before entering the loop transformation
1545
+ // / \param LoopCategories [out] A sequence of OMPLoopCategory values,
1546
+ // / one for each loop or loop transformation node
1547
+ // / successfully analyzed.
1548
+ // / \param Context
1549
+ // / \param Kind The loop transformation directive kind.
1550
+ // / \return Whether the original statement is both syntactically and
1551
+ // / semantically correct according to OpenMP 6.0 canonical loop
1552
+ // / sequence definition.
1553
+ bool analyzeLoopSequence (
1554
+ Stmt *LoopSeqStmt, unsigned &LoopSeqSize, unsigned &NumLoops,
1555
+ SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
1556
+ SmallVectorImpl<Stmt *> &ForStmts,
1557
+ SmallVectorImpl<SmallVector<Stmt *, 0 >> &OriginalInits,
1558
+ SmallVectorImpl<SmallVector<Stmt *, 0 >> &TransformsPreInits,
1559
+ SmallVectorImpl<SmallVector<Stmt *, 0 >> &LoopSequencePreInits,
1560
+ SmallVectorImpl<OMPLoopCategory> &LoopCategories, ASTContext &Context,
1561
+ OpenMPDirectiveKind Kind);
1562
+
1563
+ // / Validates and checks whether a loop sequence can be transformed according
1564
+ // / to the given directive, providing necessary setup and initialization
1565
+ // / (Driver function) before recursion using `analyzeLoopSequence`.
1497
1566
// /
1498
1567
// / \param Kind The loop transformation directive kind.
1499
- // / \param NumLoops [out] Number of total canonical loops
1500
- // / \param LoopSeqSize [out] Number of top level canonical loops
1568
+ // / \param AStmt The AST of the original statement
1569
+ // / \param LoopSeqSize [out] Number of top level canonical loops.
1570
+ // / \param NumLoops [out] Number of total canonical loops (nested too)
1501
1571
// / \param LoopHelpers [out] The multiple loop analyses results.
1502
- // / \param LoopStmts [out] The multiple Stmt of each For loop.
1503
- // / \param OriginalInits [out] The multiple collection of statements and
1572
+ // / \param ForStmts [out] The multiple Stmt of each For loop.
1573
+ // / \param OriginalInits [out] The raw original initialization statements
1574
+ // / of each belonging to a loop of the loop sequence
1575
+ // / \param TransformsPreInits [out] The multiple collection of statements and
1504
1576
// / declarations that must have been executed/declared
1505
- // / before entering the loop.
1577
+ // / before entering the loop (each belonging to a
1578
+ // / particular loop transformation, nullptr otherwise)
1579
+ // / \param LoopSequencePreInits [out] Additional general collection of loop
1580
+ // / transformation related statements and declarations
1581
+ // / not bounded to a particular loop that must be
1582
+ // / executed before entering the loop transformation
1583
+ // / \param LoopCategories [out] A sequence of OMPLoopCategory values,
1584
+ // / one for each loop or loop transformation node
1585
+ // / successfully analyzed.
1506
1586
// / \param Context
1507
1587
// / \return Whether there was an absence of errors or not
1508
1588
bool checkTransformableLoopSequence (
@@ -1511,7 +1591,9 @@ class SemaOpenMP : public SemaBase {
1511
1591
SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
1512
1592
SmallVectorImpl<Stmt *> &ForStmts,
1513
1593
SmallVectorImpl<SmallVector<Stmt *, 0 >> &OriginalInits,
1514
- ASTContext &Context);
1594
+ SmallVectorImpl<SmallVector<Stmt *, 0 >> &TransformsPreInits,
1595
+ SmallVectorImpl<SmallVector<Stmt *, 0 >> &LoopSequencePreInits,
1596
+ SmallVectorImpl<OMPLoopCategory> &LoopCategories, ASTContext &Context);
1515
1597
1516
1598
// / Helper to keep information about the current `omp begin/end declare
1517
1599
// / variant` nesting.
0 commit comments