Skip to content

Commit bb83f8e

Browse files
committed
[OpenMP] Initial parsing and sema for 'parallel masked' construct
Differential Revision: https://reviews.llvm.org/D127454
1 parent 6181c19 commit bb83f8e

35 files changed

+2474
-4
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ def __repr__(self):
13121312
#
13131313
# The translation unit cursor exists primarily to act as the root cursor for
13141314
# traversing the contents of a translation unit.
1315-
CursorKind.TRANSLATION_UNIT = CursorKind(300)
1315+
CursorKind.TRANSLATION_UNIT = CursorKind(350)
13161316

13171317
###
13181318
# Attributes

clang/include/clang-c/Index.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,15 +2626,19 @@ enum CXCursorKind {
26262626
*/
26272627
CXCursor_OMPTargetParallelGenericLoopDirective = 299,
26282628

2629-
CXCursor_LastStmt = CXCursor_OMPTargetParallelGenericLoopDirective,
2629+
/** OpenMP parallel masked directive.
2630+
*/
2631+
CXCursor_OMPParallelMaskedDirective = 300,
2632+
2633+
CXCursor_LastStmt = CXCursor_OMPParallelMaskedDirective,
26302634

26312635
/**
26322636
* Cursor that represents the translation unit itself.
26332637
*
26342638
* The translation unit cursor exists primarily to act as the root
26352639
* cursor for traversing the contents of a translation unit.
26362640
*/
2637-
CXCursor_TranslationUnit = 300,
2641+
CXCursor_TranslationUnit = 350,
26382642

26392643
/* Attributes */
26402644
CXCursor_FirstAttr = 400,

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,9 @@ DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
29942994
DEF_TRAVERSE_STMT(OMPParallelMasterDirective,
29952995
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
29962996

2997+
DEF_TRAVERSE_STMT(OMPParallelMaskedDirective,
2998+
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
2999+
29973000
DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
29983001
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
29993002

clang/include/clang/AST/StmtOpenMP.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,69 @@ class OMPParallelMasterDirective : public OMPExecutableDirective {
23042304
}
23052305
};
23062306

2307+
/// This represents '#pragma omp parallel masked' directive.
2308+
///
2309+
/// \code
2310+
/// #pragma omp parallel masked filter(tid)
2311+
/// \endcode
2312+
/// In this example directive '#pragma omp parallel masked' has a clause
2313+
/// 'filter' with the variable tid
2314+
///
2315+
class OMPParallelMaskedDirective final : public OMPExecutableDirective {
2316+
friend class ASTStmtReader;
2317+
friend class OMPExecutableDirective;
2318+
2319+
OMPParallelMaskedDirective(SourceLocation StartLoc, SourceLocation EndLoc)
2320+
: OMPExecutableDirective(OMPParallelMaskedDirectiveClass,
2321+
llvm::omp::OMPD_parallel_masked, StartLoc,
2322+
EndLoc) {}
2323+
2324+
explicit OMPParallelMaskedDirective()
2325+
: OMPExecutableDirective(OMPParallelMaskedDirectiveClass,
2326+
llvm::omp::OMPD_parallel_masked,
2327+
SourceLocation(), SourceLocation()) {}
2328+
2329+
/// Sets special task reduction descriptor.
2330+
void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; }
2331+
2332+
public:
2333+
/// Creates directive with a list of \a Clauses.
2334+
///
2335+
/// \param C AST context.
2336+
/// \param StartLoc Starting location of the directive kind.
2337+
/// \param EndLoc Ending Location of the directive.
2338+
/// \param Clauses List of clauses.
2339+
/// \param AssociatedStmt Statement, associated with the directive.
2340+
/// \param TaskRedRef Task reduction special reference expression to handle
2341+
/// taskgroup descriptor.
2342+
///
2343+
static OMPParallelMaskedDirective *
2344+
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
2345+
ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef);
2346+
2347+
/// Creates an empty directive with the place for \a NumClauses
2348+
/// clauses.
2349+
///
2350+
/// \param C AST context.
2351+
/// \param NumClauses Number of clauses.
2352+
///
2353+
static OMPParallelMaskedDirective *
2354+
CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
2355+
2356+
/// Returns special task reduction reference expression.
2357+
Expr *getTaskReductionRefExpr() {
2358+
return cast_or_null<Expr>(Data->getChildren()[0]);
2359+
}
2360+
const Expr *getTaskReductionRefExpr() const {
2361+
return const_cast<OMPParallelMaskedDirective *>(this)
2362+
->getTaskReductionRefExpr();
2363+
}
2364+
2365+
static bool classof(const Stmt *T) {
2366+
return T->getStmtClass() == OMPParallelMaskedDirectiveClass;
2367+
}
2368+
};
2369+
23072370
/// This represents '#pragma omp parallel sections' directive.
23082371
///
23092372
/// \code

clang/include/clang/Basic/StmtNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ def OMPTargetTeamsDistributeSimdDirective : StmtNode<OMPLoopDirective>;
282282
def OMPInteropDirective : StmtNode<OMPExecutableDirective>;
283283
def OMPDispatchDirective : StmtNode<OMPExecutableDirective>;
284284
def OMPMaskedDirective : StmtNode<OMPExecutableDirective>;
285+
def OMPParallelMaskedDirective : StmtNode<OMPExecutableDirective>;
285286
def OMPGenericLoopDirective : StmtNode<OMPLoopDirective>;
286287
def OMPTeamsGenericLoopDirective : StmtNode<OMPLoopDirective>;
287288
def OMPTargetTeamsGenericLoopDirective : StmtNode<OMPLoopDirective>;

clang/include/clang/Sema/Sema.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10942,6 +10942,12 @@ class Sema final {
1094210942
Stmt *AStmt,
1094310943
SourceLocation StartLoc,
1094410944
SourceLocation EndLoc);
10945+
/// Called on well-formed '\#pragma omp parallel masked' after
10946+
/// parsing of the associated statement.
10947+
StmtResult ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses,
10948+
Stmt *AStmt,
10949+
SourceLocation StartLoc,
10950+
SourceLocation EndLoc);
1094510951
/// Called on well-formed '\#pragma omp parallel sections' after
1094610952
/// parsing of the associated statement.
1094710953
StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,7 @@ enum StmtCode {
19221922
STMT_OMP_PARALLEL_FOR_DIRECTIVE,
19231923
STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE,
19241924
STMT_OMP_PARALLEL_MASTER_DIRECTIVE,
1925+
STMT_OMP_PARALLEL_MASKED_DIRECTIVE,
19251926
STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE,
19261927
STMT_OMP_TASK_DIRECTIVE,
19271928
STMT_OMP_TASKYIELD_DIRECTIVE,

clang/lib/AST/StmtOpenMP.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,22 @@ OMPParallelMasterDirective::CreateEmpty(const ASTContext &C,
682682
C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/1);
683683
}
684684

685+
OMPParallelMaskedDirective *OMPParallelMaskedDirective::Create(
686+
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
687+
ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef) {
688+
auto *Dir = createDirective<OMPParallelMaskedDirective>(
689+
C, Clauses, AssociatedStmt, /*NumChildren=*/1, StartLoc, EndLoc);
690+
Dir->setTaskReductionRefExpr(TaskRedRef);
691+
return Dir;
692+
}
693+
694+
OMPParallelMaskedDirective *
695+
OMPParallelMaskedDirective::CreateEmpty(const ASTContext &C,
696+
unsigned NumClauses, EmptyShell) {
697+
return createEmptyDirective<OMPParallelMaskedDirective>(
698+
C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/1);
699+
}
700+
685701
OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create(
686702
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
687703
ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef,

clang/lib/AST/StmtPrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,12 @@ void StmtPrinter::VisitOMPParallelMasterDirective(
749749
PrintOMPExecutableDirective(Node);
750750
}
751751

752+
void StmtPrinter::VisitOMPParallelMaskedDirective(
753+
OMPParallelMaskedDirective *Node) {
754+
Indent() << "#pragma omp parallel masked";
755+
PrintOMPExecutableDirective(Node);
756+
}
757+
752758
void StmtPrinter::VisitOMPParallelSectionsDirective(
753759
OMPParallelSectionsDirective *Node) {
754760
Indent() << "#pragma omp parallel sections";

clang/lib/AST/StmtProfile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,11 @@ void StmtProfiler::VisitOMPParallelMasterDirective(
988988
VisitOMPExecutableDirective(S);
989989
}
990990

991+
void StmtProfiler::VisitOMPParallelMaskedDirective(
992+
const OMPParallelMaskedDirective *S) {
993+
VisitOMPExecutableDirective(S);
994+
}
995+
991996
void StmtProfiler::VisitOMPParallelSectionsDirective(
992997
const OMPParallelSectionsDirective *S) {
993998
VisitOMPExecutableDirective(S);

0 commit comments

Comments
 (0)