Skip to content

Commit 849b0d7

Browse files
author
git apple-llvm automerger
committed
Merge commit '258997c16e4d' from llvm.org/main into next
2 parents e54757a + 258997c commit 849b0d7

File tree

10 files changed

+92
-20
lines changed

10 files changed

+92
-20
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,23 +878,46 @@ class OpenACCPrivateClause final
878878

879879
class OpenACCFirstPrivateClause final
880880
: public OpenACCClauseWithVarList,
881-
private llvm::TrailingObjects<OpenACCFirstPrivateClause, Expr *> {
881+
private llvm::TrailingObjects<OpenACCFirstPrivateClause, Expr *,
882+
VarDecl *> {
882883
friend TrailingObjects;
883884

884885
OpenACCFirstPrivateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
885-
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
886+
ArrayRef<Expr *> VarList,
887+
ArrayRef<VarDecl *> InitRecipes,
888+
SourceLocation EndLoc)
886889
: OpenACCClauseWithVarList(OpenACCClauseKind::FirstPrivate, BeginLoc,
887890
LParenLoc, EndLoc) {
888-
setExprs(getTrailingObjects(VarList.size()), VarList);
891+
assert(VarList.size() == InitRecipes.size());
892+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
893+
llvm::uninitialized_copy(InitRecipes, getTrailingObjects<VarDecl *>());
889894
}
890895

891896
public:
892897
static bool classof(const OpenACCClause *C) {
893898
return C->getClauseKind() == OpenACCClauseKind::FirstPrivate;
894899
}
900+
901+
// Gets a list of 'made up' `VarDecl` objects that can be used by codegen to
902+
// ensure that we properly initialize each of these variables.
903+
ArrayRef<VarDecl *> getInitRecipes() {
904+
return ArrayRef<VarDecl *>{getTrailingObjects<VarDecl *>(),
905+
getExprs().size()};
906+
}
907+
908+
ArrayRef<VarDecl *> getInitRecipes() const {
909+
return ArrayRef<VarDecl *>{getTrailingObjects<VarDecl *>(),
910+
getExprs().size()};
911+
}
912+
895913
static OpenACCFirstPrivateClause *
896914
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
897-
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
915+
ArrayRef<Expr *> VarList, ArrayRef<VarDecl *> InitRecipes,
916+
SourceLocation EndLoc);
917+
918+
size_t numTrailingObjects(OverloadToken<Expr *>) const {
919+
return getExprs().size();
920+
}
898921
};
899922

900923
class OpenACCDevicePtrClause final

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ class SemaOpenACC : public SemaBase {
238238
ArrayRef<const OpenACCClause *> Clauses);
239239

240240
// Creates a VarDecl with a proper default init for the purposes of a
241-
// `private` clause, so it can be used to generate a recipe later.
242-
VarDecl *CreateInitRecipe(const Expr *VarExpr);
241+
// `private`/'firstprivate'/'reduction' clause, so it can be used to generate
242+
// a recipe later.
243+
VarDecl *CreateInitRecipe(OpenACCClauseKind CK, const Expr *VarExpr);
243244

244245
public:
245246
ComputeConstructInfo &getActiveComputeConstructInfo() {

clang/lib/AST/OpenACCClause.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,13 @@ OpenACCPrivateClause::Create(const ASTContext &C, SourceLocation BeginLoc,
329329

330330
OpenACCFirstPrivateClause *OpenACCFirstPrivateClause::Create(
331331
const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
332-
ArrayRef<Expr *> VarList, SourceLocation EndLoc) {
333-
void *Mem = C.Allocate(
334-
OpenACCFirstPrivateClause::totalSizeToAlloc<Expr *>(VarList.size()));
335-
return new (Mem)
336-
OpenACCFirstPrivateClause(BeginLoc, LParenLoc, VarList, EndLoc);
332+
ArrayRef<Expr *> VarList, ArrayRef<VarDecl *> InitRecipes,
333+
SourceLocation EndLoc) {
334+
void *Mem =
335+
C.Allocate(OpenACCFirstPrivateClause::totalSizeToAlloc<Expr *, VarDecl *>(
336+
VarList.size(), InitRecipes.size()));
337+
return new (Mem) OpenACCFirstPrivateClause(BeginLoc, LParenLoc, VarList,
338+
InitRecipes, EndLoc);
337339
}
338340

339341
OpenACCAttachClause *OpenACCAttachClause::Create(const ASTContext &C,

clang/lib/AST/StmtProfile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,9 @@ void OpenACCClauseProfiler::VisitPrivateClause(
26892689
void OpenACCClauseProfiler::VisitFirstPrivateClause(
26902690
const OpenACCFirstPrivateClause &Clause) {
26912691
VisitClauseWithVarList(Clause);
2692+
2693+
for (auto *VD : Clause.getInitRecipes())
2694+
Profiler.VisitDecl(VD);
26922695
}
26932696

26942697
void OpenACCClauseProfiler::VisitAttachClause(

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,8 @@ SemaOpenACC::ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc) {
25752575
return BuildOpenACCAsteriskSizeExpr(AsteriskLoc);
25762576
}
25772577

2578-
VarDecl *SemaOpenACC::CreateInitRecipe(const Expr *VarExpr) {
2578+
VarDecl *SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK,
2579+
const Expr *VarExpr) {
25792580
// Strip off any array subscripts/array section exprs to get to the type of
25802581
// the variable.
25812582
while (isa_and_present<ArraySectionExpr, ArraySubscriptExpr>(VarExpr)) {
@@ -2602,7 +2603,7 @@ VarDecl *SemaOpenACC::CreateInitRecipe(const Expr *VarExpr) {
26022603

26032604
ExprResult Init;
26042605

2605-
{
2606+
if (CK == OpenACCClauseKind::Private) {
26062607
// Trap errors so we don't get weird ones here. If we can't init, we'll just
26072608
// swallow the errors.
26082609
Sema::TentativeAnalysisScope Trap{SemaRef};
@@ -2612,6 +2613,12 @@ VarDecl *SemaOpenACC::CreateInitRecipe(const Expr *VarExpr) {
26122613

26132614
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, {});
26142615
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, {});
2616+
} else if (CK == OpenACCClauseKind::FirstPrivate) {
2617+
// TODO: OpenACC: Implement this to do a 'copy' operation.
2618+
} else if (CK == OpenACCClauseKind::Reduction) {
2619+
// TODO: OpenACC: Implement this for whatever reduction needs.
2620+
} else {
2621+
llvm_unreachable("Unknown clause kind in CreateInitRecipe");
26152622
}
26162623

26172624
if (Init.get()) {

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,8 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitPrivateClause(
799799

800800
// Assemble the recipes list.
801801
for (const Expr *VarExpr : Clause.getVarList())
802-
InitRecipes.push_back(SemaRef.CreateInitRecipe(VarExpr));
802+
InitRecipes.push_back(
803+
SemaRef.CreateInitRecipe(OpenACCClauseKind::Private, VarExpr));
803804

804805
return OpenACCPrivateClause::Create(
805806
Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
@@ -812,9 +813,16 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitFirstPrivateClause(
812813
// really isn't anything to do here. GCC does some duplicate-finding, though
813814
// it isn't apparent in the standard where this is justified.
814815

816+
llvm::SmallVector<VarDecl *> InitRecipes;
817+
818+
// Assemble the recipes list.
819+
for (const Expr *VarExpr : Clause.getVarList())
820+
InitRecipes.push_back(
821+
SemaRef.CreateInitRecipe(OpenACCClauseKind::FirstPrivate, VarExpr));
822+
815823
return OpenACCFirstPrivateClause::Create(
816824
Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
817-
Clause.getEndLoc());
825+
InitRecipes, Clause.getEndLoc());
818826
}
819827

820828
OpenACCClause *SemaOpenACCClauseVisitor::VisitNoCreateClause(

clang/lib/Sema/TreeTransform.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12100,8 +12100,8 @@ void OpenACCClauseTransform<Derived>::VisitPrivateClause(
1210012100
if (InitRecipe)
1210112101
InitRecipes.push_back(InitRecipe);
1210212102
else
12103-
InitRecipes.push_back(
12104-
Self.getSema().OpenACC().CreateInitRecipe(VarRef.get()));
12103+
InitRecipes.push_back(Self.getSema().OpenACC().CreateInitRecipe(
12104+
OpenACCClauseKind::Private, VarRef.get()));
1210512105
}
1210612106
}
1210712107
ParsedClause.setVarListDetails(InstantiatedVarList,
@@ -12140,12 +12140,31 @@ void OpenACCClauseTransform<Derived>::VisitDeviceClause(
1214012140
template <typename Derived>
1214112141
void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
1214212142
const OpenACCFirstPrivateClause &C) {
12143-
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12143+
llvm::SmallVector<Expr *> InstantiatedVarList;
12144+
llvm::SmallVector<VarDecl *> InitRecipes;
12145+
12146+
for (const auto [RefExpr, InitRecipe] :
12147+
llvm::zip(C.getVarList(), C.getInitRecipes())) {
12148+
ExprResult VarRef = VisitVar(RefExpr);
12149+
12150+
if (VarRef.isUsable()) {
12151+
InstantiatedVarList.push_back(VarRef.get());
12152+
12153+
// We only have to create a new one if it is dependent, and Sema won't
12154+
// make one of these unless the type is non-dependent.
12155+
if (InitRecipe)
12156+
InitRecipes.push_back(InitRecipe);
12157+
else
12158+
InitRecipes.push_back(Self.getSema().OpenACC().CreateInitRecipe(
12159+
OpenACCClauseKind::FirstPrivate, VarRef.get()));
12160+
}
12161+
}
12162+
ParsedClause.setVarListDetails(InstantiatedVarList,
1214412163
OpenACCModifierKind::Invalid);
1214512164

1214612165
NewClause = OpenACCFirstPrivateClause::Create(
1214712166
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12148-
ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12167+
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
1214912168
ParsedClause.getEndLoc());
1215012169
}
1215112170

clang/lib/Serialization/ASTReader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13014,8 +13014,12 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
1301413014
case OpenACCClauseKind::FirstPrivate: {
1301513015
SourceLocation LParenLoc = readSourceLocation();
1301613016
llvm::SmallVector<Expr *> VarList = readOpenACCVarList();
13017+
llvm::SmallVector<VarDecl *> RecipeList;
13018+
for (unsigned I = 0; I < VarList.size(); ++I)
13019+
RecipeList.push_back(readDeclAs<VarDecl>());
13020+
1301713021
return OpenACCFirstPrivateClause::Create(getContext(), BeginLoc, LParenLoc,
13018-
VarList, EndLoc);
13022+
VarList, RecipeList, EndLoc);
1301913023
}
1302013024
case OpenACCClauseKind::Attach: {
1302113025
SourceLocation LParenLoc = readSourceLocation();

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8886,6 +8886,9 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
88868886
const auto *FPC = cast<OpenACCFirstPrivateClause>(C);
88878887
writeSourceLocation(FPC->getLParenLoc());
88888888
writeOpenACCVarList(FPC);
8889+
8890+
for (VarDecl *VD : FPC->getInitRecipes())
8891+
AddDeclRef(VD);
88898892
return;
88908893
}
88918894
case OpenACCClauseKind::Attach: {

clang/tools/libclang/CIndex.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,8 @@ void OpenACCClauseEnqueue::VisitDeviceClause(const OpenACCDeviceClause &C) {
29062906
void OpenACCClauseEnqueue::VisitFirstPrivateClause(
29072907
const OpenACCFirstPrivateClause &C) {
29082908
VisitVarList(C);
2909+
for (VarDecl *V : C.getInitRecipes())
2910+
Visitor.AddDecl(V);
29092911
}
29102912

29112913
void OpenACCClauseEnqueue::VisitPresentClause(const OpenACCPresentClause &C) {

0 commit comments

Comments
 (0)