Skip to content

Commit fcba7c3

Browse files
committed
[OPENMP50]Initial support for scan directive.
Addedi basic parsing/sema/serialization support for scan directive.
1 parent ce6c95a commit fcba7c3

File tree

27 files changed

+796
-7
lines changed

27 files changed

+796
-7
lines changed

clang/include/clang-c/Index.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,11 @@ enum CXCursorKind {
25782578
*/
25792579
CXCursor_OMPDepobjDirective = 286,
25802580

2581-
CXCursor_LastStmt = CXCursor_OMPDepobjDirective,
2581+
/** OpenMP scan directive.
2582+
*/
2583+
CXCursor_OMPScanDirective = 287,
2584+
2585+
CXCursor_LastStmt = CXCursor_OMPScanDirective,
25822586

25832587
/**
25842588
* Cursor that represents the translation unit itself.

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,6 +2852,9 @@ DEF_TRAVERSE_STMT(OMPFlushDirective,
28522852
DEF_TRAVERSE_STMT(OMPDepobjDirective,
28532853
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
28542854

2855+
DEF_TRAVERSE_STMT(OMPScanDirective,
2856+
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
2857+
28552858
DEF_TRAVERSE_STMT(OMPOrderedDirective,
28562859
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
28572860

clang/include/clang/AST/StmtOpenMP.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,6 +4688,63 @@ class OMPTargetTeamsDistributeSimdDirective final : public OMPLoopDirective {
46884688
}
46894689
};
46904690

4691+
/// This represents '#pragma omp scan' directive.
4692+
///
4693+
/// \code
4694+
/// #pragma omp scan inclusive(a)
4695+
/// \endcode
4696+
/// In this example directive '#pragma omp scan' has clause 'inclusive' with
4697+
/// list item 'a'.
4698+
class OMPScanDirective final : public OMPExecutableDirective {
4699+
friend class ASTStmtReader;
4700+
/// Build directive with the given start and end location.
4701+
///
4702+
/// \param StartLoc Starting location of the directive kind.
4703+
/// \param EndLoc Ending location of the directive.
4704+
/// \param NumClauses Number of clauses.
4705+
///
4706+
OMPScanDirective(SourceLocation StartLoc, SourceLocation EndLoc,
4707+
unsigned NumClauses)
4708+
: OMPExecutableDirective(this, OMPScanDirectiveClass,
4709+
llvm::omp::OMPD_scan, StartLoc, EndLoc,
4710+
NumClauses, 0) {}
4711+
4712+
/// Build an empty directive.
4713+
///
4714+
/// \param NumClauses Number of clauses.
4715+
///
4716+
explicit OMPScanDirective(unsigned NumClauses)
4717+
: OMPExecutableDirective(this, OMPScanDirectiveClass,
4718+
llvm::omp::OMPD_scan, SourceLocation(),
4719+
SourceLocation(), NumClauses, 0) {}
4720+
4721+
public:
4722+
/// Creates directive with a list of \a Clauses.
4723+
///
4724+
/// \param C AST context.
4725+
/// \param StartLoc Starting location of the directive kind.
4726+
/// \param EndLoc Ending Location of the directive.
4727+
/// \param Clauses List of clauses (only single OMPFlushClause clause is
4728+
/// allowed).
4729+
///
4730+
static OMPScanDirective *Create(const ASTContext &C, SourceLocation StartLoc,
4731+
SourceLocation EndLoc,
4732+
ArrayRef<OMPClause *> Clauses);
4733+
4734+
/// Creates an empty directive with the place for \a NumClauses
4735+
/// clauses.
4736+
///
4737+
/// \param C AST context.
4738+
/// \param NumClauses Number of clauses.
4739+
///
4740+
static OMPScanDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
4741+
EmptyShell);
4742+
4743+
static bool classof(const Stmt *T) {
4744+
return T->getStmtClass() == OMPScanDirectiveClass;
4745+
}
4746+
};
4747+
46914748
} // end namespace clang
46924749

46934750
#endif

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9823,9 +9823,10 @@ def err_omp_prohibited_region : Error<
98239823
"%select{|; perhaps you forget to enclose 'omp %3' directive into a parallel region?|"
98249824
"; perhaps you forget to enclose 'omp %3' directive into a for or a parallel for region with 'ordered' clause?|"
98259825
"; perhaps you forget to enclose 'omp %3' directive into a target region?|"
9826-
"; perhaps you forget to enclose 'omp %3' directive into a teams region?}2">;
9826+
"; perhaps you forget to enclose 'omp %3' directive into a teams region?|"
9827+
"; perhaps you forget to enclose 'omp %3' directive into a for, simd, or for simd region?}2">;
98279828
def err_omp_prohibited_region_simd : Error<
9828-
"OpenMP constructs may not be nested inside a simd region%select{| except for ordered simd, simd or atomic directive}0">;
9829+
"OpenMP constructs may not be nested inside a simd region%select{| except for ordered simd, simd, scan, or atomic directive}0">;
98299830
def err_omp_prohibited_region_atomic : Error<
98309831
"OpenMP constructs may not be nested inside an atomic region">;
98319832
def err_omp_prohibited_region_critical_same_name : Error<
@@ -10016,7 +10017,7 @@ def warn_omp_nesting_simd : Warning<
1001610017
InGroup<SourceUsesOpenMP>;
1001710018
def err_omp_orphaned_device_directive : Error<
1001810019
"orphaned 'omp %0' directives are prohibited"
10019-
"; perhaps you forget to enclose the directive into a %select{|||target |teams }1region?">;
10020+
"; perhaps you forget to enclose the directive into a %select{|||target |teams|for, simd, or for simd }1region?">;
1002010021
def err_omp_reduction_non_addressable_expression : Error<
1002110022
"expected addressable reduction item for the task-based directives">;
1002210023
def err_omp_reduction_with_nogroup : Error<

clang/include/clang/Basic/StmtNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def OMPTaskwaitDirective : StmtNode<OMPExecutableDirective>;
233233
def OMPTaskgroupDirective : StmtNode<OMPExecutableDirective>;
234234
def OMPFlushDirective : StmtNode<OMPExecutableDirective>;
235235
def OMPDepobjDirective : StmtNode<OMPExecutableDirective>;
236+
def OMPScanDirective : StmtNode<OMPExecutableDirective>;
236237
def OMPOrderedDirective : StmtNode<OMPExecutableDirective>;
237238
def OMPAtomicDirective : StmtNode<OMPExecutableDirective>;
238239
def OMPTargetDirective : StmtNode<OMPExecutableDirective>;

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10094,6 +10094,10 @@ class Sema final {
1009410094
StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses,
1009510095
SourceLocation StartLoc,
1009610096
SourceLocation EndLoc);
10097+
/// Called on well-formed '\#pragma omp scan'.
10098+
StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses,
10099+
SourceLocation StartLoc,
10100+
SourceLocation EndLoc);
1009710101
/// Called on well-formed '\#pragma omp ordered' after parsing of the
1009810102
/// associated statement.
1009910103
StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses,

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,7 @@ namespace serialization {
18261826
STMT_OMP_TASKWAIT_DIRECTIVE,
18271827
STMT_OMP_FLUSH_DIRECTIVE,
18281828
STMT_OMP_DEPOBJ_DIRECTIVE,
1829+
STMT_OMP_SCAN_DIRECTIVE,
18291830
STMT_OMP_ORDERED_DIRECTIVE,
18301831
STMT_OMP_ATOMIC_DIRECTIVE,
18311832
STMT_OMP_TARGET_DIRECTIVE,

clang/lib/AST/StmtOpenMP.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,27 @@ OMPDepobjDirective *OMPDepobjDirective::CreateEmpty(const ASTContext &C,
781781
return new (Mem) OMPDepobjDirective(NumClauses);
782782
}
783783

784+
OMPScanDirective *OMPScanDirective::Create(const ASTContext &C,
785+
SourceLocation StartLoc,
786+
SourceLocation EndLoc,
787+
ArrayRef<OMPClause *> Clauses) {
788+
unsigned Size = llvm::alignTo(sizeof(OMPScanDirective), alignof(OMPClause *));
789+
void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size(),
790+
alignof(OMPScanDirective));
791+
auto *Dir = new (Mem) OMPScanDirective(StartLoc, EndLoc, Clauses.size());
792+
Dir->setClauses(Clauses);
793+
return Dir;
794+
}
795+
796+
OMPScanDirective *OMPScanDirective::CreateEmpty(const ASTContext &C,
797+
unsigned NumClauses,
798+
EmptyShell) {
799+
unsigned Size = llvm::alignTo(sizeof(OMPScanDirective), alignof(OMPClause *));
800+
void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses,
801+
alignof(OMPScanDirective));
802+
return new (Mem) OMPScanDirective(NumClauses);
803+
}
804+
784805
OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C,
785806
SourceLocation StartLoc,
786807
SourceLocation EndLoc,

clang/lib/AST/StmtPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,11 @@ void StmtPrinter::VisitOMPDepobjDirective(OMPDepobjDirective *Node) {
758758
PrintOMPExecutableDirective(Node);
759759
}
760760

761+
void StmtPrinter::VisitOMPScanDirective(OMPScanDirective *Node) {
762+
Indent() << "#pragma omp scan";
763+
PrintOMPExecutableDirective(Node);
764+
}
765+
761766
void StmtPrinter::VisitOMPOrderedDirective(OMPOrderedDirective *Node) {
762767
Indent() << "#pragma omp ordered";
763768
PrintOMPExecutableDirective(Node, Node->hasClausesOfKind<OMPDependClause>());

clang/lib/AST/StmtProfile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@ void StmtProfiler::VisitOMPDepobjDirective(const OMPDepobjDirective *S) {
900900
VisitOMPExecutableDirective(S);
901901
}
902902

903+
void StmtProfiler::VisitOMPScanDirective(const OMPScanDirective *S) {
904+
VisitOMPExecutableDirective(S);
905+
}
906+
903907
void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
904908
VisitOMPExecutableDirective(S);
905909
}

0 commit comments

Comments
 (0)