Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions clang/include/clang/AST/OpenACCClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,14 +840,13 @@ class OpenACCClauseWithVarList : public OpenACCClauseWithExprs {
// alloca at the level of the base, and the init at the element level.
struct OpenACCPrivateRecipe {
VarDecl *AllocaDecl;
Expr *InitExpr;

OpenACCPrivateRecipe(VarDecl *A, Expr *I) : AllocaDecl(A), InitExpr(I) {}
OpenACCPrivateRecipe(VarDecl *A) : AllocaDecl(A) {}

bool isSet() const { return AllocaDecl; }

static OpenACCPrivateRecipe Empty() {
return OpenACCPrivateRecipe(nullptr, nullptr);
return OpenACCPrivateRecipe(/*AllocaDecl=*/nullptr);
}
};

Expand Down Expand Up @@ -899,18 +898,17 @@ class OpenACCPrivateClause final
// InitFromTemporary is the 'temp' declaration we put in to be 'copied from'.
struct OpenACCFirstPrivateRecipe {
VarDecl *AllocaDecl;
Expr *InitExpr;
VarDecl *InitFromTemporary;
OpenACCFirstPrivateRecipe(VarDecl *A, Expr *I, VarDecl *T)
: AllocaDecl(A), InitExpr(I), InitFromTemporary(T) {
assert(!AllocaDecl || AllocaDecl->getInit() == nullptr);
OpenACCFirstPrivateRecipe(VarDecl *A, VarDecl *T)
: AllocaDecl(A), InitFromTemporary(T) {
assert(!InitFromTemporary || InitFromTemporary->getInit() == nullptr);
}

bool isSet() const { return AllocaDecl; }

static OpenACCFirstPrivateRecipe Empty() {
return OpenACCFirstPrivateRecipe(nullptr, nullptr, nullptr);
return OpenACCFirstPrivateRecipe(/*AllocaDecl=*/nullptr,
/*InitFromTemporary=*/nullptr);
}
};

Expand Down Expand Up @@ -1282,16 +1280,13 @@ class OpenACCCreateClause final
// 'main' declaration used for initializaiton, which is fixed.
struct OpenACCReductionRecipe {
VarDecl *AllocaDecl;
Expr *InitExpr;
// TODO: OpenACC: this should eventually have the operations here too.

OpenACCReductionRecipe(VarDecl *A, Expr *I) : AllocaDecl(A), InitExpr(I) {
assert(!AllocaDecl || AllocaDecl->getInit() == nullptr);
}
OpenACCReductionRecipe(VarDecl *A) : AllocaDecl(A) {}

bool isSet() const { return AllocaDecl; }
static OpenACCReductionRecipe Empty() {
return OpenACCReductionRecipe(nullptr, nullptr);
return OpenACCReductionRecipe(/*AllocaDecl=*/nullptr);
}
};

Expand Down
8 changes: 1 addition & 7 deletions clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2655,8 +2655,6 @@ void OpenACCClauseProfiler::VisitPrivateClause(

for (auto &Recipe : Clause.getInitRecipes()) {
Profiler.VisitDecl(Recipe.AllocaDecl);
if (Recipe.InitExpr)
Profiler.VisitExpr(Recipe.InitExpr);
}
}

Expand All @@ -2666,8 +2664,6 @@ void OpenACCClauseProfiler::VisitFirstPrivateClause(

for (auto &Recipe : Clause.getInitRecipes()) {
Profiler.VisitDecl(Recipe.AllocaDecl);
if (Recipe.InitExpr)
Profiler.VisitExpr(Recipe.InitExpr);
Profiler.VisitDecl(Recipe.InitFromTemporary);
}
}
Expand Down Expand Up @@ -2773,12 +2769,10 @@ void OpenACCClauseProfiler::VisitReductionClause(

for (auto &Recipe : Clause.getRecipes()) {
Profiler.VisitDecl(Recipe.AllocaDecl);
if (Recipe.InitExpr)
Profiler.VisitExpr(Recipe.InitExpr);
// TODO: OpenACC: Make sure we remember to update this when we figure out
// what we're adding for the operation recipe, in the meantime, a static
// assert will make sure we don't add something.
static_assert(sizeof(OpenACCReductionRecipe) == 2 * sizeof(int *));
static_assert(sizeof(OpenACCReductionRecipe) == sizeof(int *));
}
}

Expand Down
19 changes: 3 additions & 16 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ class OpenACCClauseCIREmitter final
OpenACCRecipeBuilder<mlir::acc::PrivateRecipeOp>(cgf, builder)
.getOrCreateRecipe(
cgf.getContext(), recipeInsertLocation, varExpr,
varRecipe.AllocaDecl, varRecipe.InitExpr,
varRecipe.AllocaDecl,
/*temporary=*/nullptr, OpenACCReductionOperator::Invalid,
Decl::castToDeclContext(cgf.curFuncDecl), opInfo.origType,
opInfo.bounds.size(), opInfo.boundTypes, opInfo.baseType,
Expand Down Expand Up @@ -1036,20 +1036,13 @@ class OpenACCClauseCIREmitter final

{
mlir::OpBuilder::InsertionGuard guardCase(builder);
// TODO: OpenACC: At the moment this is a bit of a hacky way of doing
// this, and won't work when we get to bounds/etc. Do this for now to
// limit the scope of this refactor.
VarDecl *allocaDecl = varRecipe.AllocaDecl;
allocaDecl->setInit(varRecipe.InitExpr);
allocaDecl->setInitStyle(VarDecl::CallInit);

auto recipe =
OpenACCRecipeBuilder<mlir::acc::FirstprivateRecipeOp>(cgf,
builder)
.getOrCreateRecipe(
cgf.getContext(), recipeInsertLocation, varExpr,
varRecipe.AllocaDecl, varRecipe.InitExpr,
varRecipe.InitFromTemporary,
varRecipe.AllocaDecl, varRecipe.InitFromTemporary,
OpenACCReductionOperator::Invalid,
Decl::castToDeclContext(cgf.curFuncDecl), opInfo.origType,
opInfo.bounds.size(), opInfo.boundTypes, opInfo.baseType,
Expand Down Expand Up @@ -1086,18 +1079,12 @@ class OpenACCClauseCIREmitter final

{
mlir::OpBuilder::InsertionGuard guardCase(builder);
// TODO: OpenACC: At the moment this is a bit of a hacky way of doing
// this, and won't work when we get to bounds/etc. Do this for now to
// limit the scope of this refactor.
VarDecl *allocaDecl = varRecipe.AllocaDecl;
allocaDecl->setInit(varRecipe.InitExpr);
allocaDecl->setInitStyle(VarDecl::CallInit);

auto recipe =
OpenACCRecipeBuilder<mlir::acc::ReductionRecipeOp>(cgf, builder)
.getOrCreateRecipe(
cgf.getContext(), recipeInsertLocation, varExpr,
varRecipe.AllocaDecl, varRecipe.InitExpr,
varRecipe.AllocaDecl,
/*temporary=*/nullptr, clause.getReductionOp(),
Decl::castToDeclContext(cgf.curFuncDecl), opInfo.origType,
opInfo.bounds.size(), opInfo.boundTypes, opInfo.baseType,
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void OpenACCRecipeBuilderBase::createPrivateInitRecipe(
mlir::Location loc, mlir::Location locEnd, SourceRange exprRange,
mlir::Value mainOp, mlir::acc::PrivateRecipeOp recipe, size_t numBounds,
llvm::ArrayRef<QualType> boundTypes, const VarDecl *allocaDecl,
QualType origType, const Expr *initExpr) {
QualType origType) {
assert(allocaDecl && "Required recipe variable not set?");
CIRGenFunction::DeclMapRevertingRAII declMapRAII{cgf, allocaDecl};

Expand Down Expand Up @@ -473,9 +473,10 @@ void OpenACCRecipeBuilderBase::createPrivateInitRecipe(

// If the initializer is trivial, there is nothing to do here, so save
// ourselves some effort.
if (initExpr && (!cgf.isTrivialInitializer(initExpr) ||
cgf.getContext().getLangOpts().getTrivialAutoVarInit() !=
LangOptions::TrivialAutoVarInitKind::Uninitialized))
if (allocaDecl->getInit() &&
(!cgf.isTrivialInitializer(allocaDecl->getInit()) ||
cgf.getContext().getLangOpts().getTrivialAutoVarInit() !=
LangOptions::TrivialAutoVarInitKind::Uninitialized))
makeBoundsInit(alloca, loc, block, allocaDecl, origType,
/*isInitSection=*/true);
}
Expand Down
20 changes: 8 additions & 12 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ class OpenACCRecipeBuilderBase {
mlir::acc::PrivateRecipeOp recipe,
size_t numBounds,
llvm::ArrayRef<QualType> boundTypes,
const VarDecl *allocaDecl, QualType origType,
const Expr *initExpr);
const VarDecl *allocaDecl, QualType origType);

void createRecipeDestroySection(mlir::Location loc, mlir::Location locEnd,
mlir::Value mainOp, CharUnits alignment,
Expand Down Expand Up @@ -212,15 +211,12 @@ class OpenACCRecipeBuilder : OpenACCRecipeBuilderBase {
OpenACCRecipeBuilder(CIRGen::CIRGenFunction &cgf,
CIRGen::CIRGenBuilderTy &builder)
: OpenACCRecipeBuilderBase(cgf, builder) {}
RecipeTy getOrCreateRecipe(ASTContext &astCtx,
mlir::OpBuilder::InsertPoint &insertLocation,
const Expr *varRef, const VarDecl *varRecipe,
const Expr *initExpr, const VarDecl *temporary,
OpenACCReductionOperator reductionOp,
DeclContext *dc, QualType origType,
size_t numBounds,
llvm::ArrayRef<QualType> boundTypes,
QualType baseType, mlir::Value mainOp) {
RecipeTy getOrCreateRecipe(
ASTContext &astCtx, mlir::OpBuilder::InsertPoint &insertLocation,
const Expr *varRef, const VarDecl *varRecipe, const VarDecl *temporary,
OpenACCReductionOperator reductionOp, DeclContext *dc, QualType origType,
size_t numBounds, llvm::ArrayRef<QualType> boundTypes, QualType baseType,
mlir::Value mainOp) {
assert(!varRecipe->getType()->isSpecificBuiltinType(
BuiltinType::ArraySection) &&
"array section shouldn't make it to recipe creation");
Expand Down Expand Up @@ -266,7 +262,7 @@ class OpenACCRecipeBuilder : OpenACCRecipeBuilderBase {
if constexpr (std::is_same_v<RecipeTy, mlir::acc::PrivateRecipeOp>) {
createPrivateInitRecipe(loc, locEnd, varRef->getSourceRange(), mainOp,
recipe, numBounds, boundTypes, varRecipe,
origType, initExpr);
origType);
} else {
createRecipeInitCopy(loc, locEnd, varRef->getSourceRange(), mainOp,
recipe, varRecipe, temporary);
Expand Down
30 changes: 26 additions & 4 deletions clang/lib/Sema/SemaOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@ OpenACCPrivateRecipe SemaOpenACC::CreatePrivateInitRecipe(const Expr *VarExpr) {
AllocaDecl->setInitStyle(VarDecl::CallInit);
}

return OpenACCPrivateRecipe(AllocaDecl, Init.get());
return OpenACCPrivateRecipe(AllocaDecl);
}

OpenACCFirstPrivateRecipe
Expand Down Expand Up @@ -2828,7 +2828,14 @@ SemaOpenACC::CreateFirstPrivateInitRecipe(const Expr *VarExpr) {
if (!ArrTy) {
ExprResult Init = FinishValueInit(
SemaRef.SemaRef, Entity, VarExpr->getBeginLoc(), VarTy, TemporaryDRE);
return OpenACCFirstPrivateRecipe(AllocaDecl, Init.get(), Temporary);

// For 'no bounds' version, we can use this as a shortcut, so set the init
// anyway.
if (Init.isUsable()) {
AllocaDecl->setInit(Init.get());
AllocaDecl->setInitStyle(VarDecl::CallInit);
}
return OpenACCFirstPrivateRecipe(AllocaDecl, Temporary);
}

// Arrays need to have each individual element initialized as there
Expand Down Expand Up @@ -2875,8 +2882,16 @@ SemaOpenACC::CreateFirstPrivateInitRecipe(const Expr *VarExpr) {
ExprResult Init = FinishValueInit(SemaRef.SemaRef, Entity,
VarExpr->getBeginLoc(), VarTy, InitExpr);

return OpenACCFirstPrivateRecipe(AllocaDecl, Init.get(), Temporary);
// For 'no bounds' version, we can use this as a shortcut, so set the init
// anyway.
if (Init.isUsable()) {
AllocaDecl->setInit(Init.get());
AllocaDecl->setInitStyle(VarDecl::CallInit);
}

return OpenACCFirstPrivateRecipe(AllocaDecl, Temporary);
}

OpenACCReductionRecipe SemaOpenACC::CreateReductionInitRecipe(
OpenACCReductionOperator ReductionOperator, const Expr *VarExpr) {
// TODO: OpenACC: This shouldn't be necessary, see PrivateInitRecipe
Expand Down Expand Up @@ -2932,5 +2947,12 @@ OpenACCReductionRecipe SemaOpenACC::CreateReductionInitRecipe(

ExprResult Init = FinishValueInit(SemaRef.SemaRef, Entity,
VarExpr->getBeginLoc(), VarTy, InitExpr);
return OpenACCReductionRecipe(AllocaDecl, Init.get());

// For 'no bounds' version, we can use this as a shortcut, so set the init
// anyway.
if (Init.isUsable()) {
AllocaDecl->setInit(Init.get());
AllocaDecl->setInitStyle(VarDecl::CallInit);
}
return OpenACCReductionRecipe(AllocaDecl);
}
15 changes: 6 additions & 9 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12860,10 +12860,9 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {

llvm::SmallVector<OpenACCPrivateRecipe> RecipeList;
for (unsigned I = 0; I < VarList.size(); ++I) {
static_assert(sizeof(OpenACCPrivateRecipe) == 2 * sizeof(int *));
static_assert(sizeof(OpenACCPrivateRecipe) == 1 * sizeof(int *));
VarDecl *Alloca = readDeclAs<VarDecl>();
Expr *InitExpr = readSubExpr();
RecipeList.push_back({Alloca, InitExpr});
RecipeList.push_back({Alloca});
}

return OpenACCPrivateClause::Create(getContext(), BeginLoc, LParenLoc,
Expand All @@ -12886,11 +12885,10 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
llvm::SmallVector<Expr *> VarList = readOpenACCVarList();
llvm::SmallVector<OpenACCFirstPrivateRecipe> RecipeList;
for (unsigned I = 0; I < VarList.size(); ++I) {
static_assert(sizeof(OpenACCFirstPrivateRecipe) == 3 * sizeof(int *));
static_assert(sizeof(OpenACCFirstPrivateRecipe) == 2 * sizeof(int *));
VarDecl *Recipe = readDeclAs<VarDecl>();
Expr *InitExpr = readSubExpr();
VarDecl *RecipeTemp = readDeclAs<VarDecl>();
RecipeList.push_back({Recipe, InitExpr, RecipeTemp});
RecipeList.push_back({Recipe, RecipeTemp});
}

return OpenACCFirstPrivateClause::Create(getContext(), BeginLoc, LParenLoc,
Expand Down Expand Up @@ -13011,10 +13009,9 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
llvm::SmallVector<OpenACCReductionRecipe> RecipeList;

for (unsigned I = 0; I < VarList.size(); ++I) {
static_assert(sizeof(OpenACCReductionRecipe) == 2 * sizeof(int *));
static_assert(sizeof(OpenACCReductionRecipe) == sizeof(int *));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having that assert here is a bit weird

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It IS a touch. But the idea is that this type (OpenACCReductionRecipe) is going to grow in the future, and this is an attempt to make sure I don't miss it when I add fields.

VarDecl *Recipe = readDeclAs<VarDecl>();
Expr *InitExpr = readSubExpr();
RecipeList.push_back({Recipe, InitExpr});
RecipeList.push_back({Recipe});
}

return OpenACCReductionClause::Create(getContext(), BeginLoc, LParenLoc, Op,
Expand Down
9 changes: 3 additions & 6 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8779,9 +8779,8 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
writeOpenACCVarList(PC);

for (const OpenACCPrivateRecipe &R : PC->getInitRecipes()) {
static_assert(sizeof(R) == 2 * sizeof(int *));
static_assert(sizeof(R) == 1 * sizeof(int *));
AddDeclRef(R.AllocaDecl);
AddStmt(const_cast<Expr *>(R.InitExpr));
}
return;
}
Expand All @@ -8803,9 +8802,8 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
writeOpenACCVarList(FPC);

for (const OpenACCFirstPrivateRecipe &R : FPC->getInitRecipes()) {
static_assert(sizeof(R) == 3 * sizeof(int *));
static_assert(sizeof(R) == 2 * sizeof(int *));
AddDeclRef(R.AllocaDecl);
AddStmt(const_cast<Expr *>(R.InitExpr));
AddDeclRef(R.InitFromTemporary);
}
return;
Expand Down Expand Up @@ -8927,9 +8925,8 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
writeOpenACCVarList(RC);

for (const OpenACCReductionRecipe &R : RC->getRecipes()) {
static_assert(sizeof(OpenACCReductionRecipe) == 2 * sizeof(int *));
static_assert(sizeof(OpenACCReductionRecipe) == 1 * sizeof(int *));
AddDeclRef(R.AllocaDecl);
AddStmt(const_cast<Expr *>(R.InitExpr));
}
return;
}
Expand Down
9 changes: 2 additions & 7 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2832,10 +2832,8 @@ void OpenACCClauseEnqueue::VisitTileClause(const OpenACCTileClause &C) {

void OpenACCClauseEnqueue::VisitPrivateClause(const OpenACCPrivateClause &C) {
VisitVarList(C);
for (const OpenACCPrivateRecipe &R : C.getInitRecipes()) {
for (const OpenACCPrivateRecipe &R : C.getInitRecipes())
Visitor.AddDecl(R.AllocaDecl);
Visitor.AddStmt(R.InitExpr);
}
}

void OpenACCClauseEnqueue::VisitHostClause(const OpenACCHostClause &C) {
Expand All @@ -2851,7 +2849,6 @@ void OpenACCClauseEnqueue::VisitFirstPrivateClause(
VisitVarList(C);
for (const OpenACCFirstPrivateRecipe &R : C.getInitRecipes()) {
Visitor.AddDecl(R.AllocaDecl);
Visitor.AddStmt(R.InitExpr);
Visitor.AddDecl(R.InitFromTemporary);
}
}
Expand Down Expand Up @@ -2927,10 +2924,8 @@ void OpenACCClauseEnqueue::VisitDeviceTypeClause(
void OpenACCClauseEnqueue::VisitReductionClause(
const OpenACCReductionClause &C) {
VisitVarList(C);
for (const OpenACCReductionRecipe &R : C.getRecipes()) {
for (const OpenACCReductionRecipe &R : C.getRecipes())
Visitor.AddDecl(R.AllocaDecl);
Visitor.AddStmt(R.InitExpr);
}
}
void OpenACCClauseEnqueue::VisitAutoClause(const OpenACCAutoClause &C) {}
void OpenACCClauseEnqueue::VisitIndependentClause(
Expand Down