Skip to content

Commit db81e8c

Browse files
committed
[OpenACC] Initial sema implementation of 'update' construct
This executable construct has a larger list of clauses than some of the others, plus has some additional restrictions. This patch implements the AST node, plus the 'cannot be the body of a if, while, do, switch, or label' statement restriction. Future patches will handle the rest of the restrictions, which are based on clauses.
1 parent 56c5a6b commit db81e8c

27 files changed

+382
-25
lines changed

clang/include/clang-c/Index.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,11 @@ enum CXCursorKind {
22022202
*/
22032203
CXCursor_OpenACCSetConstruct = 330,
22042204

2205-
CXCursor_LastStmt = CXCursor_OpenACCSetConstruct,
2205+
/** OpenACC update Construct.
2206+
*/
2207+
CXCursor_OpenACCUpdateConstruct = 331,
2208+
2209+
CXCursor_LastStmt = CXCursor_OpenACCUpdateConstruct,
22062210

22072211
/**
22082212
* Cursor that represents the translation unit itself.

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,8 @@ DEF_TRAVERSE_STMT(OpenACCShutdownConstruct,
40824082
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
40834083
DEF_TRAVERSE_STMT(OpenACCSetConstruct,
40844084
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4085+
DEF_TRAVERSE_STMT(OpenACCUpdateConstruct,
4086+
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
40854087

40864088
// Traverse HLSL: Out argument expression
40874089
DEF_TRAVERSE_STMT(HLSLOutArgExpr, {})

clang/include/clang/AST/StmtOpenACC.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,5 +712,44 @@ class OpenACCSetConstruct final
712712
SourceLocation End,
713713
ArrayRef<const OpenACCClause *> Clauses);
714714
};
715+
// This class represents an 'update' construct, which has just a clause list.
716+
class OpenACCUpdateConstruct final
717+
: public OpenACCConstructStmt,
718+
private llvm::TrailingObjects<OpenACCUpdateConstruct,
719+
const OpenACCClause *> {
720+
friend TrailingObjects;
721+
OpenACCUpdateConstruct(unsigned NumClauses)
722+
: OpenACCConstructStmt(OpenACCUpdateConstructClass,
723+
OpenACCDirectiveKind::Update, SourceLocation{},
724+
SourceLocation{}, SourceLocation{}) {
725+
std::uninitialized_value_construct(
726+
getTrailingObjects<const OpenACCClause *>(),
727+
getTrailingObjects<const OpenACCClause *>() + NumClauses);
728+
setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
729+
NumClauses));
730+
}
731+
732+
OpenACCUpdateConstruct(SourceLocation Start, SourceLocation DirectiveLoc,
733+
SourceLocation End,
734+
ArrayRef<const OpenACCClause *> Clauses)
735+
: OpenACCConstructStmt(OpenACCUpdateConstructClass,
736+
OpenACCDirectiveKind::Update, Start, DirectiveLoc,
737+
End) {
738+
std::uninitialized_copy(Clauses.begin(), Clauses.end(),
739+
getTrailingObjects<const OpenACCClause *>());
740+
setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
741+
Clauses.size()));
742+
}
743+
744+
public:
745+
static bool classof(const Stmt *T) {
746+
return T->getStmtClass() == OpenACCUpdateConstructClass;
747+
}
748+
static OpenACCUpdateConstruct *CreateEmpty(const ASTContext &C,
749+
unsigned NumClauses);
750+
static OpenACCUpdateConstruct *
751+
Create(const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc,
752+
SourceLocation End, ArrayRef<const OpenACCClause *> Clauses);
753+
};
715754
} // namespace clang
716755
#endif // LLVM_CLANG_AST_STMTOPENACC_H

clang/include/clang/AST/TextNodeDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ class TextNodeDumper
419419
void VisitOpenACCInitConstruct(const OpenACCInitConstruct *S);
420420
void VisitOpenACCSetConstruct(const OpenACCSetConstruct *S);
421421
void VisitOpenACCShutdownConstruct(const OpenACCShutdownConstruct *S);
422+
void VisitOpenACCUpdateConstruct(const OpenACCUpdateConstruct *S);
422423
void VisitOpenACCAsteriskSizeExpr(const OpenACCAsteriskSizeExpr *S);
423424
void VisitEmbedExpr(const EmbedExpr *S);
424425
void VisitAtomicExpr(const AtomicExpr *AE);

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12827,6 +12827,10 @@ def err_acc_loop_not_monotonic
1282712827
"('++', '--', or compound assignment)">;
1282812828
def err_acc_construct_one_clause_of
1282912829
: Error<"OpenACC '%0' construct must have at least one %1 clause">;
12830+
def err_acc_update_as_body
12831+
: Error<"OpenACC 'update' construct may not appear in place of the "
12832+
"statement following a%select{n if statement| while statement| do "
12833+
"statement| switch statement| label statement}0">;
1283012834

1283112835
// AMDGCN builtins diagnostics
1283212836
def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size value">;

clang/include/clang/Basic/StmtNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def OpenACCWaitConstruct : StmtNode<OpenACCConstructStmt>;
316316
def OpenACCInitConstruct : StmtNode<OpenACCConstructStmt>;
317317
def OpenACCShutdownConstruct : StmtNode<OpenACCConstructStmt>;
318318
def OpenACCSetConstruct : StmtNode<OpenACCConstructStmt>;
319+
def OpenACCUpdateConstruct : StmtNode<OpenACCConstructStmt>;
319320

320321
// OpenACC Additional Expressions.
321322
def OpenACCAsteriskSizeExpr : StmtNode<Expr>;

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,7 @@ enum StmtCode {
20252025
STMT_OPENACC_INIT_CONSTRUCT,
20262026
STMT_OPENACC_SHUTDOWN_CONSTRUCT,
20272027
STMT_OPENACC_SET_CONSTRUCT,
2028+
STMT_OPENACC_UPDATE_CONSTRUCT,
20282029

20292030
// HLSL Constructs
20302031
EXPR_HLSL_OUT_ARG,

clang/lib/AST/StmtOpenACC.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,24 @@ OpenACCSetConstruct::Create(const ASTContext &C, SourceLocation Start,
284284
auto *Inst = new (Mem) OpenACCSetConstruct(Start, DirectiveLoc, End, Clauses);
285285
return Inst;
286286
}
287+
288+
OpenACCUpdateConstruct *
289+
OpenACCUpdateConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) {
290+
void *Mem = C.Allocate(
291+
OpenACCUpdateConstruct::totalSizeToAlloc<const OpenACCClause *>(
292+
NumClauses));
293+
auto *Inst = new (Mem) OpenACCUpdateConstruct(NumClauses);
294+
return Inst;
295+
}
296+
297+
OpenACCUpdateConstruct *
298+
OpenACCUpdateConstruct::Create(const ASTContext &C, SourceLocation Start,
299+
SourceLocation DirectiveLoc, SourceLocation End,
300+
ArrayRef<const OpenACCClause *> Clauses) {
301+
void *Mem = C.Allocate(
302+
OpenACCUpdateConstruct::totalSizeToAlloc<const OpenACCClause *>(
303+
Clauses.size()));
304+
auto *Inst =
305+
new (Mem) OpenACCUpdateConstruct(Start, DirectiveLoc, End, Clauses);
306+
return Inst;
307+
}

clang/lib/AST/StmtPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,10 +1204,12 @@ void StmtPrinter::VisitOpenACCInitConstruct(OpenACCInitConstruct *S) {
12041204
void StmtPrinter::VisitOpenACCShutdownConstruct(OpenACCShutdownConstruct *S) {
12051205
PrintOpenACCConstruct(S);
12061206
}
1207-
12081207
void StmtPrinter::VisitOpenACCSetConstruct(OpenACCSetConstruct *S) {
12091208
PrintOpenACCConstruct(S);
12101209
}
1210+
void StmtPrinter::VisitOpenACCUpdateConstruct(OpenACCUpdateConstruct *S) {
1211+
PrintOpenACCConstruct(S);
1212+
}
12111213

12121214
void StmtPrinter::VisitOpenACCWaitConstruct(OpenACCWaitConstruct *S) {
12131215
Indent() << "#pragma acc wait";

clang/lib/AST/StmtProfile.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,13 @@ void StmtProfiler::VisitOpenACCSetConstruct(const OpenACCSetConstruct *S) {
27802780
P.VisitOpenACCClauseList(S->clauses());
27812781
}
27822782

2783+
void StmtProfiler::VisitOpenACCUpdateConstruct(
2784+
const OpenACCUpdateConstruct *S) {
2785+
VisitStmt(S);
2786+
OpenACCClauseProfiler P{*this};
2787+
P.VisitOpenACCClauseList(S->clauses());
2788+
}
2789+
27832790
void StmtProfiler::VisitHLSLOutArgExpr(const HLSLOutArgExpr *S) {
27842791
VisitStmt(S);
27852792
}

0 commit comments

Comments
 (0)