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
24 changes: 21 additions & 3 deletions clang/include/clang/AST/OpenACCClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -1280,13 +1280,31 @@ class OpenACCCreateClause final
// 'main' declaration used for initializaiton, which is fixed.
struct OpenACCReductionRecipe {
VarDecl *AllocaDecl;
// TODO: OpenACC: this should eventually have the operations here too.

OpenACCReductionRecipe(VarDecl *A) : AllocaDecl(A) {}
// A combiner recipe is represented by an operation expression. However, in
// order to generate these properly, we have to make up a LHS and a RHS
// expression for the purposes of generation.
struct CombinerRecipe {
VarDecl *LHS;
VarDecl *RHS;
Expr *Op;
};

// Contains a collection of the recipe elements we need for the combiner:
// -For Scalars, there will be 1 element, just the combiner for that scalar.
// -For a struct with a valid operator, this will be 1 element, just that
// call.
// -For a struct without the operator, this will be 1 element per field, which
// should be the combiner for that element.
// -For an array of any of the above, it will be the above for the element.
llvm::SmallVector<CombinerRecipe, 1> CombinerRecipes;

OpenACCReductionRecipe(VarDecl *A, llvm::ArrayRef<CombinerRecipe> Combiners)
: AllocaDecl(A), CombinerRecipes(Combiners) {}

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

Expand Down
11 changes: 10 additions & 1 deletion clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2769,10 +2769,19 @@ void OpenACCClauseProfiler::VisitReductionClause(

for (auto &Recipe : Clause.getRecipes()) {
Profiler.VisitDecl(Recipe.AllocaDecl);

// 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::CombinerRecipe) ==
3 * sizeof(int *));
for (auto &CombinerRecipe : Recipe.CombinerRecipes) {
if (CombinerRecipe.Op) {
Profiler.VisitDecl(CombinerRecipe.LHS);
Profiler.VisitDecl(CombinerRecipe.RHS);
Profiler.VisitStmt(CombinerRecipe.Op);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2946,5 +2946,5 @@ OpenACCReductionRecipe SemaOpenACC::CreateReductionInitRecipe(
AllocaDecl->setInit(Init.get());
AllocaDecl->setInitStyle(VarDecl::CallInit);
}
return OpenACCReductionRecipe(AllocaDecl);
return OpenACCReductionRecipe(AllocaDecl, {});
}
17 changes: 15 additions & 2 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13009,9 +13009,22 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
llvm::SmallVector<OpenACCReductionRecipe> RecipeList;

for (unsigned I = 0; I < VarList.size(); ++I) {
static_assert(sizeof(OpenACCReductionRecipe) == sizeof(int *));
VarDecl *Recipe = readDeclAs<VarDecl>();
RecipeList.push_back({Recipe});

static_assert(sizeof(OpenACCReductionRecipe::CombinerRecipe) ==
3 * sizeof(int *));

llvm::SmallVector<OpenACCReductionRecipe::CombinerRecipe> Combiners;
unsigned NumCombiners = readInt();
for (unsigned I = 0; I < NumCombiners; ++I) {
VarDecl *LHS = readDeclAs<VarDecl>();
VarDecl *RHS = readDeclAs<VarDecl>();
Expr *Op = readExpr();

Combiners.push_back({LHS, RHS, Op});
}

RecipeList.push_back({Recipe, Combiners});
}

return OpenACCReductionClause::Create(getContext(), BeginLoc, LParenLoc, Op,
Expand Down
11 changes: 10 additions & 1 deletion clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8925,8 +8925,17 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
writeOpenACCVarList(RC);

for (const OpenACCReductionRecipe &R : RC->getRecipes()) {
static_assert(sizeof(OpenACCReductionRecipe) == 1 * sizeof(int *));
AddDeclRef(R.AllocaDecl);

static_assert(sizeof(OpenACCReductionRecipe::CombinerRecipe) ==
3 * sizeof(int *));
writeUInt32(R.CombinerRecipes.size());

for (auto &CombinerRecipe : R.CombinerRecipes) {
AddDeclRef(CombinerRecipe.LHS);
AddDeclRef(CombinerRecipe.RHS);
AddStmt(CombinerRecipe.Op);
}
}
return;
}
Expand Down