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
72 changes: 56 additions & 16 deletions clang/include/clang/AST/OpenACCClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,19 +835,40 @@ class OpenACCClauseWithVarList : public OpenACCClauseWithExprs {
ArrayRef<Expr *> getVarList() const { return getExprs(); }
};

// Represents all the data needed for recipe generation. The declaration and
// init are stored separately, because in the case of subscripts, we do the
// 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) {
assert(!AllocaDecl || AllocaDecl->getInit() == nullptr);
}

bool isSet() const { return AllocaDecl; }

static OpenACCPrivateRecipe Empty() {
return OpenACCPrivateRecipe(nullptr, nullptr);
}
};

class OpenACCPrivateClause final
: public OpenACCClauseWithVarList,
private llvm::TrailingObjects<OpenACCPrivateClause, Expr *, VarDecl *> {
private llvm::TrailingObjects<OpenACCPrivateClause, Expr *,
OpenACCPrivateRecipe> {
friend TrailingObjects;

OpenACCPrivateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
ArrayRef<Expr *> VarList,
ArrayRef<VarDecl *> InitRecipes, SourceLocation EndLoc)
ArrayRef<OpenACCPrivateRecipe> InitRecipes,
SourceLocation EndLoc)
: OpenACCClauseWithVarList(OpenACCClauseKind::Private, BeginLoc,
LParenLoc, EndLoc) {
assert(VarList.size() == InitRecipes.size());
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
llvm::uninitialized_copy(InitRecipes, getTrailingObjects<VarDecl *>());
llvm::uninitialized_copy(InitRecipes,
getTrailingObjects<OpenACCPrivateRecipe>());
}

public:
Expand All @@ -856,19 +877,19 @@ class OpenACCPrivateClause final
}
// Gets a list of 'made up' `VarDecl` objects that can be used by codegen to
// ensure that we properly initialize each of these variables.
ArrayRef<VarDecl *> getInitRecipes() {
return ArrayRef<VarDecl *>{getTrailingObjects<VarDecl *>(),
getExprs().size()};
ArrayRef<OpenACCPrivateRecipe> getInitRecipes() {
return ArrayRef<OpenACCPrivateRecipe>{
getTrailingObjects<OpenACCPrivateRecipe>(), getExprs().size()};
}

ArrayRef<VarDecl *> getInitRecipes() const {
return ArrayRef<VarDecl *>{getTrailingObjects<VarDecl *>(),
getExprs().size()};
ArrayRef<OpenACCPrivateRecipe> getInitRecipes() const {
return ArrayRef<OpenACCPrivateRecipe>{
getTrailingObjects<OpenACCPrivateRecipe>(), getExprs().size()};
}

static OpenACCPrivateClause *
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
ArrayRef<Expr *> VarList, ArrayRef<VarDecl *> InitRecipes,
ArrayRef<Expr *> VarList, ArrayRef<OpenACCPrivateRecipe> InitRecipes,
SourceLocation EndLoc);

size_t numTrailingObjects(OverloadToken<Expr *>) const {
Expand All @@ -879,11 +900,20 @@ class OpenACCPrivateClause final
// A 'pair' to stand in for the recipe. RecipeDecl is the main declaration, and
// InitFromTemporary is the 'temp' declaration we put in to be 'copied from'.
struct OpenACCFirstPrivateRecipe {
VarDecl *RecipeDecl, *InitFromTemporary;
OpenACCFirstPrivateRecipe(VarDecl *R, VarDecl *T)
: RecipeDecl(R), InitFromTemporary(T) {}
OpenACCFirstPrivateRecipe(std::pair<VarDecl *, VarDecl *> p)
: RecipeDecl(p.first), InitFromTemporary(p.second) {}
VarDecl *AllocaDecl;
Expr *InitExpr;
VarDecl *InitFromTemporary;
OpenACCFirstPrivateRecipe(VarDecl *A, Expr *I, VarDecl *T)
: AllocaDecl(A), InitExpr(I), InitFromTemporary(T) {
assert(!AllocaDecl || AllocaDecl->getInit() == nullptr);
assert(!InitFromTemporary || InitFromTemporary->getInit() == nullptr);
}

bool isSet() const { return AllocaDecl; }

static OpenACCFirstPrivateRecipe Empty() {
return OpenACCFirstPrivateRecipe(nullptr, nullptr, nullptr);
}
};

class OpenACCFirstPrivateClause final
Expand Down Expand Up @@ -1253,8 +1283,18 @@ class OpenACCCreateClause final
// A structure to stand in for the recipe on a reduction. RecipeDecl is the
// 'main' declaration used for initializaiton, which is fixed.
struct OpenACCReductionRecipe {
VarDecl *RecipeDecl;
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);
}

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

class OpenACCReductionClause final
Expand Down
21 changes: 6 additions & 15 deletions clang/include/clang/Sema/SemaOpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define LLVM_CLANG_SEMA_SEMAOPENACC_H

#include "clang/AST/DeclGroup.h"
#include "clang/AST/OpenACCClause.h"
#include "clang/AST/StmtOpenACC.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/OpenACCKinds.h"
Expand Down Expand Up @@ -237,21 +238,11 @@ class SemaOpenACC : public SemaBase {
SourceLocation ClauseLoc,
ArrayRef<const OpenACCClause *> Clauses);

// Creates a VarDecl with a proper default init for the purposes of a
// `private`/'firstprivate'/'reduction' clause, so it can be used to generate
// a recipe later.
// The first entry is the recipe itself, the second is any required
// 'temporary' created for the init (in the case of a copy), such as with
// firstprivate.
std::pair<VarDecl *, VarDecl *> CreateInitRecipe(OpenACCClauseKind CK,
const Expr *VarExpr) {
assert(CK != OpenACCClauseKind::Reduction);
return CreateInitRecipe(CK, OpenACCReductionOperator::Invalid, VarExpr);
}
std::pair<VarDecl *, VarDecl *>
CreateInitRecipe(OpenACCClauseKind CK,
OpenACCReductionOperator ReductionOperator,
const Expr *VarExpr);
OpenACCPrivateRecipe CreatePrivateInitRecipe(const Expr *VarExpr);
OpenACCFirstPrivateRecipe CreateFirstPrivateInitRecipe(const Expr *VarExpr);
OpenACCReductionRecipe
CreateReductionInitRecipe(OpenACCReductionOperator ReductionOperator,
const Expr *VarExpr);

public:
ComputeConstructInfo &getActiveComputeConstructInfo() {
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/AST/OpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ OpenACCTileClause *OpenACCTileClause::Create(const ASTContext &C,
OpenACCPrivateClause *
OpenACCPrivateClause::Create(const ASTContext &C, SourceLocation BeginLoc,
SourceLocation LParenLoc, ArrayRef<Expr *> VarList,
ArrayRef<VarDecl *> InitRecipes,
ArrayRef<OpenACCPrivateRecipe> InitRecipes,
SourceLocation EndLoc) {
assert(VarList.size() == InitRecipes.size());
void *Mem =
C.Allocate(OpenACCPrivateClause::totalSizeToAlloc<Expr *, VarDecl *>(
void *Mem = C.Allocate(
OpenACCPrivateClause::totalSizeToAlloc<Expr *, OpenACCPrivateRecipe>(
VarList.size(), InitRecipes.size()));
return new (Mem)
OpenACCPrivateClause(BeginLoc, LParenLoc, VarList, InitRecipes, EndLoc);
Expand Down
17 changes: 12 additions & 5 deletions clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,16 +2636,21 @@ void OpenACCClauseProfiler::VisitPrivateClause(
const OpenACCPrivateClause &Clause) {
VisitClauseWithVarList(Clause);

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

void OpenACCClauseProfiler::VisitFirstPrivateClause(
const OpenACCFirstPrivateClause &Clause) {
VisitClauseWithVarList(Clause);

for (auto &Recipe : Clause.getInitRecipes()) {
Profiler.VisitDecl(Recipe.RecipeDecl);
Profiler.VisitDecl(Recipe.AllocaDecl);
if (Recipe.InitExpr)
Profiler.VisitExpr(Recipe.InitExpr);
Profiler.VisitDecl(Recipe.InitFromTemporary);
}
}
Expand Down Expand Up @@ -2750,11 +2755,13 @@ void OpenACCClauseProfiler::VisitReductionClause(
VisitClauseWithVarList(Clause);

for (auto &Recipe : Clause.getRecipes()) {
Profiler.VisitDecl(Recipe.RecipeDecl);
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) == sizeof(int *));
static_assert(sizeof(OpenACCReductionRecipe) == 2 * sizeof(int *));
}
}

Expand Down
27 changes: 23 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,10 +1280,16 @@ 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 = getOrCreateRecipe<mlir::acc::PrivateRecipeOp>(
cgf.getContext(), varExpr, varRecipe, /*temporary=*/nullptr,
cgf.getContext(), varExpr, allocaDecl, /*temporary=*/nullptr,
OpenACCReductionOperator::Invalid,

Decl::castToDeclContext(cgf.curFuncDecl), opInfo.baseType,
privateOp.getResult());
// TODO: OpenACC: The dialect is going to change in the near future to
Expand Down Expand Up @@ -1316,8 +1322,15 @@ 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 = getOrCreateRecipe<mlir::acc::FirstprivateRecipeOp>(
cgf.getContext(), varExpr, varRecipe.RecipeDecl,
cgf.getContext(), varExpr, allocaDecl,
varRecipe.InitFromTemporary, OpenACCReductionOperator::Invalid,
Decl::castToDeclContext(cgf.curFuncDecl), opInfo.baseType,
firstPrivateOp.getResult());
Expand Down Expand Up @@ -1353,9 +1366,15 @@ 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 = getOrCreateRecipe<mlir::acc::ReductionRecipeOp>(
cgf.getContext(), varExpr, varRecipe.RecipeDecl,
cgf.getContext(), varExpr, allocaDecl,
/*temporary=*/nullptr, clause.getReductionOp(),
Decl::castToDeclContext(cgf.curFuncDecl), opInfo.baseType,
reductionOp.getResult());
Expand Down
Loading