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
9 changes: 8 additions & 1 deletion clang/include/clang/Sema/SemaOpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,14 @@ class SemaOpenACC : public SemaBase {
// '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);
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);

public:
ComputeConstructInfo &getActiveComputeConstructInfo() {
Expand Down
22 changes: 15 additions & 7 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class OpenACCClauseCIREmitter final
&recipe.getCopyRegion(), recipe.getCopyRegion().end(),
{mainOp.getType(), mainOp.getType()}, {loc, loc});
builder.setInsertionPointToEnd(&recipe.getCopyRegion().back());
CIRGenFunction::LexicalScope ls(cgf, loc, block);

mlir::BlockArgument fromArg = block->getArgument(0);
mlir::BlockArgument toArg = block->getArgument(1);
Expand Down Expand Up @@ -457,21 +458,19 @@ class OpenACCClauseCIREmitter final
RecipeTy recipe, const VarDecl *varRecipe,
const VarDecl *temporary) {
assert(varRecipe && "Required recipe variable not set?");
if constexpr (std::is_same_v<RecipeTy, mlir::acc::ReductionRecipeOp>) {
// We haven't implemented the 'init' recipe for Reduction yet, so NYI
// it.
cgf.cgm.errorNYI(exprRange, "OpenACC Reduction recipe init");
}

CIRGenFunction::AutoVarEmission tempDeclEmission{
CIRGenFunction::AutoVarEmission::invalid()};
CIRGenFunction::DeclMapRevertingRAII declMapRAII{cgf, varRecipe};

// Do the 'init' section of the recipe IR, which does an alloca, then the
// initialization (except for firstprivate).
builder.createBlock(&recipe.getInitRegion(), recipe.getInitRegion().end(),
{mainOp.getType()}, {loc});
mlir::Block *block = builder.createBlock(&recipe.getInitRegion(),
recipe.getInitRegion().end(),
{mainOp.getType()}, {loc});
builder.setInsertionPointToEnd(&recipe.getInitRegion().back());
CIRGenFunction::LexicalScope ls(cgf, loc, block);

tempDeclEmission =
cgf.emitAutoVarAlloca(*varRecipe, builder.saveInsertionPoint());

Expand All @@ -496,6 +495,13 @@ class OpenACCClauseCIREmitter final
cgf.cgm.errorNYI(exprRange, "private default-init recipe");
}
cgf.emitAutoVarInit(tempDeclEmission);
} else if constexpr (std::is_same_v<RecipeTy,
mlir::acc::ReductionRecipeOp>) {
// Unlike Private, the recipe here is always required as it has to do
// init, not just 'default' init.
if (!varRecipe->getInit())
cgf.cgm.errorNYI(exprRange, "reduction init recipe");
cgf.emitAutoVarInit(tempDeclEmission);
}

mlir::acc::YieldOp::create(builder, locEnd);
Expand Down Expand Up @@ -527,6 +533,7 @@ class OpenACCClauseCIREmitter final
&recipe.getCombinerRegion(), recipe.getCombinerRegion().end(),
{mainOp.getType(), mainOp.getType()}, {loc, loc});
builder.setInsertionPointToEnd(&recipe.getCombinerRegion().back());
CIRGenFunction::LexicalScope ls(cgf, loc, block);

mlir::BlockArgument lhsArg = block->getArgument(0);

Expand All @@ -544,6 +551,7 @@ class OpenACCClauseCIREmitter final
mlir::Block *block = builder.createBlock(
&destroyRegion, destroyRegion.end(), {mainOp.getType()}, {loc});
builder.setInsertionPointToEnd(&destroyRegion.back());
CIRGenFunction::LexicalScope ls(cgf, loc, block);

mlir::Type elementTy =
mlir::cast<cir::PointerType>(mainOp.getType()).getPointee();
Expand Down
44 changes: 42 additions & 2 deletions clang/lib/Sema/SemaOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2590,7 +2590,9 @@ SemaOpenACC::ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc) {
}

std::pair<VarDecl *, VarDecl *>
SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK, const Expr *VarExpr) {
SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK,
OpenACCReductionOperator ReductionOperator,
const Expr *VarExpr) {
// Strip off any array subscripts/array section exprs to get to the type of
// the variable.
while (isa_and_present<ArraySectionExpr, ArraySubscriptExpr>(VarExpr)) {
Expand Down Expand Up @@ -2722,7 +2724,45 @@ SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK, const Expr *VarExpr) {
/*TreatUnavailableAsInvalid=*/false);
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, InitExpr, &VarTy);
} else if (CK == OpenACCClauseKind::Reduction) {
// TODO: OpenACC: Implement this for whatever reduction needs.
// How we initialize the reduction variable depends on the operator used,
// according to the chart in OpenACC 3.3 section 2.6.15.

switch (ReductionOperator) {
case OpenACCReductionOperator::Invalid:
// This can only happen when there is an error, and since these inits
// are used for code generation, we can just ignore/not bother doing any
// initialization here.
break;
case OpenACCReductionOperator::Multiplication:
case OpenACCReductionOperator::Max:
case OpenACCReductionOperator::Min:
case OpenACCReductionOperator::BitwiseAnd:
case OpenACCReductionOperator::And:
// TODO: OpenACC: figure out init for these.
break;

case OpenACCReductionOperator::Addition:
case OpenACCReductionOperator::BitwiseOr:
case OpenACCReductionOperator::BitwiseXOr:
case OpenACCReductionOperator::Or: {
// +, |, ^, and || all use 0 for their initializers, so we can just
// use 'zero init' here and not bother with the rest of the
// array/compound type/etc contents.
Expr *InitExpr = new (getASTContext()) InitListExpr(
getASTContext(), VarExpr->getBeginLoc(), {}, VarExpr->getEndLoc());
// we set this to void so that the initialization sequence generation
// will get this type correct/etc.
InitExpr->setType(getASTContext().VoidTy);

InitializationKind Kind = InitializationKind::CreateForInit(
Recipe->getLocation(), /*DirectInit=*/true, InitExpr);
InitializationSequence InitSeq(SemaRef.SemaRef, Entity, Kind, InitExpr,
/*TopLevelOfInitList=*/false,
/*TreatUnavailableAsInvalid=*/false);
Init = InitSeq.Perform(SemaRef.SemaRef, Entity, Kind, InitExpr, &VarTy);
break;
}
}
} else {
llvm_unreachable("Unknown clause kind in CreateInitRecipe");
}
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Sema/SemaOpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1784,9 +1784,10 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause(
ValidVars.push_back(Res.get());

VarDecl *InitRecipe =
SemaRef.CreateInitRecipe(OpenACCClauseKind::Reduction, Res.get())
SemaRef
.CreateInitRecipe(OpenACCClauseKind::Reduction,
Clause.getReductionOp(), Res.get())
.first;
// TODO: OpenACC: Create the reduction operation recipe here too.
Recipes.push_back({InitRecipe});
}
}
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -12430,11 +12430,11 @@ void OpenACCClauseTransform<Derived>::VisitReductionClause(
if (OrigRecipes.RecipeDecl)
InitRecipe = OrigRecipes.RecipeDecl;
else
InitRecipe =
Self.getSema()
.OpenACC()
.CreateInitRecipe(OpenACCClauseKind::Reduction, Res.get())
.first;
InitRecipe = Self.getSema()
.OpenACC()
.CreateInitRecipe(OpenACCClauseKind::Reduction,
C.getReductionOp(), Res.get())
.first;

Recipes.push_back({InitRecipe});
}
Expand Down
Loading