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