Skip to content

Commit 8abf3ea

Browse files
committed
[Clang] [OpenMP] Add support for '#pragma omp stripe'.
1 parent f3a1d55 commit 8abf3ea

File tree

30 files changed

+3588
-32
lines changed

30 files changed

+3588
-32
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,9 @@ def is_unexposed(self):
14101410
# OpenMP scope directive.
14111411
OMP_SCOPE_DIRECTIVE = 306
14121412

1413+
# OpenMP stripe directive.
1414+
OMP_STRIPE_DIRECTIVE = 310
1415+
14131416
# OpenACC Compute Construct.
14141417
OPEN_ACC_COMPUTE_DIRECTIVE = 320
14151418

clang/docs/OpenMPSupport.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ implementation.
374374
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
375375
| Loop transformation constructs | :none:`unclaimed` | :none:`unclaimed` | |
376376
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
377+
| loop stripe transformation | :good:`done` | https://github.com/llvm/llvm-project/pull/119891 |
378+
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
377379
| work distribute construct | :none:`unclaimed` | :none:`unclaimed` | |
378380
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
379381
| task_iteration | :none:`unclaimed` | :none:`unclaimed` | |

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ Python Binding Changes
291291
OpenMP Support
292292
--------------
293293
- Added support 'no_openmp_constructs' assumption clause.
294+
- Added support for 'omp stripe' directive.
294295

295296
Improvements
296297
^^^^^^^^^^^^

clang/include/clang-c/Index.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,10 @@ enum CXCursorKind {
21582158
*/
21592159
CXCursor_OMPAssumeDirective = 309,
21602160

2161+
/** OpenMP assume directive.
2162+
*/
2163+
CXCursor_OMPStripeDirective = 310,
2164+
21612165
/** OpenACC Compute Construct.
21622166
*/
21632167
CXCursor_OpenACCComputeConstruct = 320,

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,6 +3056,9 @@ DEF_TRAVERSE_STMT(OMPSimdDirective,
30563056
DEF_TRAVERSE_STMT(OMPTileDirective,
30573057
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
30583058

3059+
DEF_TRAVERSE_STMT(OMPStripeDirective,
3060+
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
3061+
30593062
DEF_TRAVERSE_STMT(OMPUnrollDirective,
30603063
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
30613064

clang/include/clang/AST/StmtOpenMP.h

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,8 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective {
994994
static bool classof(const Stmt *T) {
995995
Stmt::StmtClass C = T->getStmtClass();
996996
return C == OMPTileDirectiveClass || C == OMPUnrollDirectiveClass ||
997-
C == OMPReverseDirectiveClass || C == OMPInterchangeDirectiveClass;
997+
C == OMPReverseDirectiveClass || C == OMPInterchangeDirectiveClass ||
998+
C == OMPStripeDirectiveClass;
998999
}
9991000
};
10001001

@@ -5560,7 +5561,7 @@ class OMPTileDirective final : public OMPLoopTransformationDirective {
55605561
: OMPLoopTransformationDirective(OMPTileDirectiveClass,
55615562
llvm::omp::OMPD_tile, StartLoc, EndLoc,
55625563
NumLoops) {
5563-
setNumGeneratedLoops(3 * NumLoops);
5564+
setNumGeneratedLoops(2 * NumLoops);
55645565
}
55655566

55665567
void setPreInits(Stmt *PreInits) {
@@ -5621,6 +5622,80 @@ class OMPTileDirective final : public OMPLoopTransformationDirective {
56215622
}
56225623
};
56235624

5625+
/// This represents the '#pragma omp stripe' loop transformation directive.
5626+
class OMPStripeDirective final : public OMPLoopTransformationDirective {
5627+
friend class ASTStmtReader;
5628+
friend class OMPExecutableDirective;
5629+
5630+
/// Default list of offsets.
5631+
enum {
5632+
PreInitsOffset = 0,
5633+
TransformedStmtOffset,
5634+
};
5635+
5636+
explicit OMPStripeDirective(SourceLocation StartLoc, SourceLocation EndLoc,
5637+
unsigned NumLoops)
5638+
: OMPLoopTransformationDirective(OMPStripeDirectiveClass,
5639+
llvm::omp::OMPD_stripe, StartLoc, EndLoc,
5640+
NumLoops) {
5641+
setNumGeneratedLoops(2 * NumLoops);
5642+
}
5643+
5644+
void setPreInits(Stmt *PreInits) {
5645+
Data->getChildren()[PreInitsOffset] = PreInits;
5646+
}
5647+
5648+
void setTransformedStmt(Stmt *S) {
5649+
Data->getChildren()[TransformedStmtOffset] = S;
5650+
}
5651+
public:
5652+
/// Create a new AST node representation for '#pragma omp stripe'.
5653+
///
5654+
/// \param C Context of the AST.
5655+
/// \param StartLoc Location of the introducer (e.g. the 'omp' token).
5656+
/// \param EndLoc Location of the directive's end (e.g. the tok::eod).
5657+
/// \param Clauses The directive's clauses.
5658+
/// \param NumLoops Number of associated loops (number of items in the
5659+
/// 'sizes' clause).
5660+
/// \param AssociatedStmt The outermost associated loop.
5661+
/// \param TransformedStmt The loop nest after striping, or nullptr in
5662+
/// dependent contexts.
5663+
/// \param PreInits Helper preinits statements for the loop nest.
5664+
static OMPStripeDirective *
5665+
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
5666+
ArrayRef<OMPClause *> Clauses, unsigned NumLoops, Stmt *AssociatedStmt,
5667+
Stmt *TransformedStmt, Stmt *PreInits);
5668+
5669+
/// Build an empty '#pragma omp stripe' AST node for deserialization.
5670+
///
5671+
/// \param C Context of the AST.
5672+
/// \param NumClauses Number of clauses to allocate.
5673+
/// \param NumLoops Number of associated loops to allocate.
5674+
static OMPStripeDirective *
5675+
CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned NumLoops);
5676+
/// Gets/sets the associated loops after striping.
5677+
///
5678+
/// This is in de-sugared format stored as a CompoundStmt.
5679+
///
5680+
/// \code
5681+
/// for (...)
5682+
/// ...
5683+
/// \endcode
5684+
///
5685+
/// Note that if the generated loops a become associated loops of another
5686+
/// directive, they may need to be hoisted before them.
5687+
Stmt *getTransformedStmt() const {
5688+
return Data->getChildren()[TransformedStmtOffset];
5689+
}
5690+
5691+
/// Return preinits statement.
5692+
Stmt *getPreInits() const { return Data->getChildren()[PreInitsOffset]; }
5693+
5694+
static bool classof(const Stmt *T) {
5695+
return T->getStmtClass() == OMPStripeDirectiveClass;
5696+
}
5697+
};
5698+
56245699
/// This represents the '#pragma omp unroll' loop transformation directive.
56255700
///
56265701
/// \code

clang/include/clang/Basic/StmtNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def OMPParallelDirective : StmtNode<OMPExecutableDirective>;
231231
def OMPSimdDirective : StmtNode<OMPLoopDirective>;
232232
def OMPLoopTransformationDirective : StmtNode<OMPLoopBasedDirective, 1>;
233233
def OMPTileDirective : StmtNode<OMPLoopTransformationDirective>;
234+
def OMPStripeDirective : StmtNode<OMPLoopTransformationDirective>;
234235
def OMPUnrollDirective : StmtNode<OMPLoopTransformationDirective>;
235236
def OMPReverseDirective : StmtNode<OMPLoopTransformationDirective>;
236237
def OMPInterchangeDirective : StmtNode<OMPLoopTransformationDirective>;

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ class SemaOpenMP : public SemaBase {
440440
StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
441441
Stmt *AStmt, SourceLocation StartLoc,
442442
SourceLocation EndLoc);
443+
StmtResult ActOnOpenMPStripeDirective(ArrayRef<OMPClause *> Clauses,
444+
Stmt *AStmt, SourceLocation StartLoc,
445+
SourceLocation EndLoc);
443446
/// Called on well-formed '#pragma omp unroll' after parsing of its clauses
444447
/// and the associated statement.
445448
StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,7 @@ enum StmtCode {
19391939
STMT_OMP_PARALLEL_DIRECTIVE,
19401940
STMT_OMP_SIMD_DIRECTIVE,
19411941
STMT_OMP_TILE_DIRECTIVE,
1942+
STMP_OMP_STRIPE_DIRECTIVE,
19421943
STMT_OMP_UNROLL_DIRECTIVE,
19431944
STMT_OMP_REVERSE_DIRECTIVE,
19441945
STMT_OMP_INTERCHANGE_DIRECTIVE,

clang/lib/AST/StmtOpenMP.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,27 @@ OMPTileDirective *OMPTileDirective::CreateEmpty(const ASTContext &C,
425425
SourceLocation(), SourceLocation(), NumLoops);
426426
}
427427

428+
OMPStripeDirective *
429+
OMPStripeDirective::Create(const ASTContext &C, SourceLocation StartLoc,
430+
SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses,
431+
unsigned NumLoops, Stmt *AssociatedStmt,
432+
Stmt *TransformedStmt, Stmt *PreInits) {
433+
OMPStripeDirective *Dir = createDirective<OMPStripeDirective>(
434+
C, Clauses, AssociatedStmt, TransformedStmtOffset + 1, StartLoc, EndLoc,
435+
NumLoops);
436+
Dir->setTransformedStmt(TransformedStmt);
437+
Dir->setPreInits(PreInits);
438+
return Dir;
439+
}
440+
441+
OMPStripeDirective *OMPStripeDirective::CreateEmpty(const ASTContext &C,
442+
unsigned NumClauses,
443+
unsigned NumLoops) {
444+
return createEmptyDirective<OMPStripeDirective>(
445+
C, NumClauses, /*HasAssociatedStmt=*/true, TransformedStmtOffset + 1,
446+
SourceLocation(), SourceLocation(), NumLoops);
447+
}
448+
428449
OMPUnrollDirective *
429450
OMPUnrollDirective::Create(const ASTContext &C, SourceLocation StartLoc,
430451
SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses,

0 commit comments

Comments
 (0)