Skip to content

Commit 21c785d

Browse files
committed
[OpenACC] Implement 'set' construct sema
The 'set' construct is another fairly simple one, it doesn't have an associated statement and only a handful of allowed clauses. This patch implements it and all the rules for it, allowing 3 of its for clauses. The only exception is default_async, which will be implemented in a future patch, because it isn't just being enabled, it needs a complete new implementation.
1 parent 3f93625 commit 21c785d

26 files changed

+384
-16
lines changed

clang/include/clang-c/Index.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,11 @@ enum CXCursorKind {
21982198
*/
21992199
CXCursor_OpenACCShutdownConstruct = 329,
22002200

2201-
CXCursor_LastStmt = CXCursor_OpenACCShutdownConstruct,
2201+
/** OpenACC set Construct.
2202+
*/
2203+
CXCursor_OpenACCSetConstruct = 330,
2204+
2205+
CXCursor_LastStmt = CXCursor_OpenACCSetConstruct,
22022206

22032207
/**
22042208
* 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
@@ -4080,6 +4080,8 @@ DEF_TRAVERSE_STMT(OpenACCInitConstruct,
40804080
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
40814081
DEF_TRAVERSE_STMT(OpenACCShutdownConstruct,
40824082
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4083+
DEF_TRAVERSE_STMT(OpenACCSetConstruct,
4084+
{ TRY_TO(VisitOpenACCClauseList(S->clauses())); })
40834085

40844086
// Traverse HLSL: Out argument expression
40854087
DEF_TRAVERSE_STMT(HLSLOutArgExpr, {})

clang/include/clang/AST/StmtOpenACC.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,5 +672,45 @@ class OpenACCShutdownConstruct final
672672
SourceLocation End, ArrayRef<const OpenACCClause *> Clauses);
673673
};
674674

675+
// This class represents a 'set' construct, which has just a clause list.
676+
class OpenACCSetConstruct final
677+
: public OpenACCConstructStmt,
678+
private llvm::TrailingObjects<OpenACCSetConstruct,
679+
const OpenACCClause *> {
680+
friend TrailingObjects;
681+
OpenACCSetConstruct(unsigned NumClauses)
682+
: OpenACCConstructStmt(OpenACCSetConstructClass,
683+
OpenACCDirectiveKind::Set, SourceLocation{},
684+
SourceLocation{}, SourceLocation{}) {
685+
std::uninitialized_value_construct(
686+
getTrailingObjects<const OpenACCClause *>(),
687+
getTrailingObjects<const OpenACCClause *>() + NumClauses);
688+
setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
689+
NumClauses));
690+
}
691+
692+
OpenACCSetConstruct(SourceLocation Start, SourceLocation DirectiveLoc,
693+
SourceLocation End,
694+
ArrayRef<const OpenACCClause *> Clauses)
695+
: OpenACCConstructStmt(OpenACCSetConstructClass,
696+
OpenACCDirectiveKind::Set, Start, DirectiveLoc,
697+
End) {
698+
std::uninitialized_copy(Clauses.begin(), Clauses.end(),
699+
getTrailingObjects<const OpenACCClause *>());
700+
setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
701+
Clauses.size()));
702+
}
703+
704+
public:
705+
static bool classof(const Stmt *T) {
706+
return T->getStmtClass() == OpenACCSetConstructClass;
707+
}
708+
static OpenACCSetConstruct *CreateEmpty(const ASTContext &C,
709+
unsigned NumClauses);
710+
static OpenACCSetConstruct *Create(const ASTContext &C, SourceLocation Start,
711+
SourceLocation DirectiveLoc,
712+
SourceLocation End,
713+
ArrayRef<const OpenACCClause *> Clauses);
714+
};
675715
} // namespace clang
676716
#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
@@ -417,6 +417,7 @@ class TextNodeDumper
417417
void VisitOpenACCHostDataConstruct(const OpenACCHostDataConstruct *S);
418418
void VisitOpenACCWaitConstruct(const OpenACCWaitConstruct *S);
419419
void VisitOpenACCInitConstruct(const OpenACCInitConstruct *S);
420+
void VisitOpenACCSetConstruct(const OpenACCSetConstruct *S);
420421
void VisitOpenACCShutdownConstruct(const OpenACCShutdownConstruct *S);
421422
void VisitOpenACCAsteriskSizeExpr(const OpenACCAsteriskSizeExpr *S);
422423
void VisitEmbedExpr(const EmbedExpr *S);

clang/include/clang/Basic/StmtNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def OpenACCHostDataConstruct : StmtNode<OpenACCAssociatedStmtConstruct>;
315315
def OpenACCWaitConstruct : StmtNode<OpenACCConstructStmt>;
316316
def OpenACCInitConstruct : StmtNode<OpenACCConstructStmt>;
317317
def OpenACCShutdownConstruct : StmtNode<OpenACCConstructStmt>;
318+
def OpenACCSetConstruct : StmtNode<OpenACCConstructStmt>;
318319

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

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,7 @@ enum StmtCode {
20242024
STMT_OPENACC_WAIT_CONSTRUCT,
20252025
STMT_OPENACC_INIT_CONSTRUCT,
20262026
STMT_OPENACC_SHUTDOWN_CONSTRUCT,
2027+
STMT_OPENACC_SET_CONSTRUCT,
20272028

20282029
// HLSL Constructs
20292030
EXPR_HLSL_OUT_ARG,

clang/lib/AST/StmtOpenACC.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,22 @@ OpenACCShutdownConstruct *OpenACCShutdownConstruct::Create(
265265
new (Mem) OpenACCShutdownConstruct(Start, DirectiveLoc, End, Clauses);
266266
return Inst;
267267
}
268+
269+
OpenACCSetConstruct *OpenACCSetConstruct::CreateEmpty(const ASTContext &C,
270+
unsigned NumClauses) {
271+
void *Mem = C.Allocate(
272+
OpenACCSetConstruct::totalSizeToAlloc<const OpenACCClause *>(NumClauses));
273+
auto *Inst = new (Mem) OpenACCSetConstruct(NumClauses);
274+
return Inst;
275+
}
276+
277+
OpenACCSetConstruct *
278+
OpenACCSetConstruct::Create(const ASTContext &C, SourceLocation Start,
279+
SourceLocation DirectiveLoc, SourceLocation End,
280+
ArrayRef<const OpenACCClause *> Clauses) {
281+
void *Mem =
282+
C.Allocate(OpenACCSetConstruct::totalSizeToAlloc<const OpenACCClause *>(
283+
Clauses.size()));
284+
auto *Inst = new (Mem) OpenACCSetConstruct(Start, DirectiveLoc, End, Clauses);
285+
return Inst;
286+
}

clang/lib/AST/StmtPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,10 @@ void StmtPrinter::VisitOpenACCShutdownConstruct(OpenACCShutdownConstruct *S) {
12051205
PrintOpenACCConstruct(S);
12061206
}
12071207

1208+
void StmtPrinter::VisitOpenACCSetConstruct(OpenACCSetConstruct *S) {
1209+
PrintOpenACCConstruct(S);
1210+
}
1211+
12081212
void StmtPrinter::VisitOpenACCWaitConstruct(OpenACCWaitConstruct *S) {
12091213
Indent() << "#pragma acc wait";
12101214
if (!S->getLParenLoc().isInvalid()) {

clang/lib/AST/StmtProfile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,6 +2769,12 @@ void StmtProfiler::VisitOpenACCShutdownConstruct(
27692769
P.VisitOpenACCClauseList(S->clauses());
27702770
}
27712771

2772+
void StmtProfiler::VisitOpenACCSetConstruct(const OpenACCSetConstruct *S) {
2773+
VisitStmt(S);
2774+
OpenACCClauseProfiler P{*this};
2775+
P.VisitOpenACCClauseList(S->clauses());
2776+
}
2777+
27722778
void StmtProfiler::VisitHLSLOutArgExpr(const HLSLOutArgExpr *S) {
27732779
VisitStmt(S);
27742780
}

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,6 +2971,9 @@ void TextNodeDumper::VisitOpenACCShutdownConstruct(
29712971
const OpenACCShutdownConstruct *S) {
29722972
OS << " " << S->getDirectiveKind();
29732973
}
2974+
void TextNodeDumper::VisitOpenACCSetConstruct(const OpenACCSetConstruct *S) {
2975+
OS << " " << S->getDirectiveKind();
2976+
}
29742977

29752978
void TextNodeDumper::VisitEmbedExpr(const EmbedExpr *S) {
29762979
AddChild("begin", [=] { OS << S->getStartingElementPos(); });

0 commit comments

Comments
 (0)