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
30 changes: 14 additions & 16 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,20 @@ void OpenACCRecipeBuilderBase::makeBoundsInit(
cgf.emitAutoVarInit(tempDeclEmission);
}

// TODO: OpenACC: When we get this implemented for the reduction/firstprivate,
// this might end up re-merging with createRecipeInitCopy. For now, keep it
// separate until we're sure what everything looks like to keep this as clean
// as possible.
void OpenACCRecipeBuilderBase::createPrivateInitRecipe(
// TODO: OpenACC: when we start doing firstprivate for array/vlas/etc, we
// probably need to do a little work about the 'init' calls to put it in 'copy'
// region instead.
void OpenACCRecipeBuilderBase::createInitRecipe(
mlir::Location loc, mlir::Location locEnd, SourceRange exprRange,
mlir::Value mainOp, mlir::acc::PrivateRecipeOp recipe, size_t numBounds,
mlir::Value mainOp, mlir::Region &recipeInitRegion, size_t numBounds,
llvm::ArrayRef<QualType> boundTypes, const VarDecl *allocaDecl,
QualType origType) {
assert(allocaDecl && "Required recipe variable not set?");
CIRGenFunction::DeclMapRevertingRAII declMapRAII{cgf, allocaDecl};

mlir::Block *block =
createRecipeBlock(recipe.getInitRegion(), mainOp.getType(), loc,
numBounds, /*isInit=*/true);
builder.setInsertionPointToEnd(&recipe.getInitRegion().back());
mlir::Block *block = createRecipeBlock(recipeInitRegion, mainOp.getType(),
loc, numBounds, /*isInit=*/true);
builder.setInsertionPointToEnd(&recipeInitRegion.back());
CIRGenFunction::LexicalScope ls(cgf, loc, block);

const Type *allocaPointeeType =
Expand All @@ -458,7 +456,7 @@ void OpenACCRecipeBuilderBase::createPrivateInitRecipe(
// Sema::TentativeAnalysisScopes in SemaOpenACC::CreateInitRecipe, it'll
// emit an error to tell us. However, emitting those errors during
// production is a violation of the standard, so we cannot do them.
cgf.cgm.errorNYI(exprRange, "private default-init recipe");
cgf.cgm.errorNYI(exprRange, "private/reduction default-init recipe");
}

if (!numBounds) {
Expand All @@ -469,7 +467,7 @@ void OpenACCRecipeBuilderBase::createPrivateInitRecipe(
cgf.emitAutoVarInit(tempDeclEmission);
} else {
mlir::Value alloca = makeBoundsAlloca(
block, exprRange, loc, "openacc.private.init", numBounds, boundTypes);
block, exprRange, loc, allocaDecl->getName(), numBounds, boundTypes);

// If the initializer is trivial, there is nothing to do here, so save
// ourselves some effort.
Expand Down Expand Up @@ -521,10 +519,10 @@ void OpenACCRecipeBuilderBase::createFirstprivateRecipeCopy(
// doesn't restore it aftewards.
void OpenACCRecipeBuilderBase::createReductionRecipeCombiner(
mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp,
mlir::acc::ReductionRecipeOp recipe) {
mlir::Block *block = builder.createBlock(
&recipe.getCombinerRegion(), recipe.getCombinerRegion().end(),
{mainOp.getType(), mainOp.getType()}, {loc, loc});
mlir::acc::ReductionRecipeOp recipe, size_t numBounds) {
mlir::Block *block =
createRecipeBlock(recipe.getCombinerRegion(), mainOp.getType(), loc,
numBounds, /*isInit=*/false);
builder.setInsertionPointToEnd(&recipe.getCombinerRegion().back());
CIRGenFunction::LexicalScope ls(cgf, loc, block);

Expand Down
39 changes: 23 additions & 16 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ class OpenACCRecipeBuilderBase {
// doesn't restore it aftewards.
void createReductionRecipeCombiner(mlir::Location loc, mlir::Location locEnd,
mlir::Value mainOp,
mlir::acc::ReductionRecipeOp recipe);
void 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);
mlir::acc::ReductionRecipeOp recipe,
size_t numBounds);
void createInitRecipe(mlir::Location loc, mlir::Location locEnd,
SourceRange exprRange, mlir::Value mainOp,
mlir::Region &recipeInitRegion, size_t numBounds,
llvm::ArrayRef<QualType> boundTypes,
const VarDecl *allocaDecl, QualType origType);

void createRecipeDestroySection(mlir::Location loc, mlir::Location locEnd,
mlir::Value mainOp, CharUnits alignment,
Expand Down Expand Up @@ -224,10 +224,10 @@ class OpenACCRecipeBuilder : OpenACCRecipeBuilderBase {
// TODO: OpenACC: This is a bit of a hackery to get this to not change for
// the non-private recipes. This will be removed soon, when we get this
// 'right' for firstprivate and reduction.
if constexpr (!std::is_same_v<RecipeTy, mlir::acc::PrivateRecipeOp>) {
if constexpr (std::is_same_v<RecipeTy, mlir::acc::FirstprivateRecipeOp>) {
if (numBounds) {
cgf.cgm.errorNYI(varRef->getSourceRange(),
"firstprivate/reduction-init with bounds");
"firstprivate-init with bounds");
}
boundTypes = {};
numBounds = 0;
Expand Down Expand Up @@ -260,18 +260,25 @@ class OpenACCRecipeBuilder : OpenACCRecipeBuilderBase {
insertLocation = modBuilder.saveInsertionPoint();

if constexpr (std::is_same_v<RecipeTy, mlir::acc::PrivateRecipeOp>) {
createPrivateInitRecipe(loc, locEnd, varRef->getSourceRange(), mainOp,
recipe, numBounds, boundTypes, varRecipe,
origType);
createInitRecipe(loc, locEnd, varRef->getSourceRange(), mainOp,
recipe.getInitRegion(), numBounds, boundTypes, varRecipe,
origType);
} else if constexpr (std::is_same_v<RecipeTy,
mlir::acc::ReductionRecipeOp>) {
createInitRecipe(loc, locEnd, varRef->getSourceRange(), mainOp,
recipe.getInitRegion(), numBounds, boundTypes, varRecipe,
origType);
createReductionRecipeCombiner(loc, locEnd, mainOp, recipe, numBounds);
} else {
static_assert(std::is_same_v<RecipeTy, mlir::acc::FirstprivateRecipeOp>);
// TODO: OpenACC: we probably want this to call createInitRecipe as well,
// but do so in a way that omits the 'initialization', so that we can do
// it separately, since it belongs in the 'copy' region. It also might
// need a way of getting the tempDeclEmission out of it for that purpose.
createRecipeInitCopy(loc, locEnd, varRef->getSourceRange(), mainOp,
recipe, varRecipe, temporary);
}

if constexpr (std::is_same_v<RecipeTy, mlir::acc::ReductionRecipeOp>) {
createReductionRecipeCombiner(loc, locEnd, mainOp, recipe);
}

if (origType.isDestructedType())
createRecipeDestroySection(
loc, locEnd, mainOp, cgf.getContext().getDeclAlign(varRecipe),
Expand Down
11 changes: 6 additions & 5 deletions clang/lib/Sema/SemaOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2894,17 +2894,18 @@ SemaOpenACC::CreateFirstPrivateInitRecipe(const Expr *VarExpr) {

OpenACCReductionRecipe SemaOpenACC::CreateReductionInitRecipe(
OpenACCReductionOperator ReductionOperator, const Expr *VarExpr) {
// TODO: OpenACC: This shouldn't be necessary, see PrivateInitRecipe
VarExpr = StripOffBounds(VarExpr);

// We don't strip bounds here, so that we are doing our recipe init at the
// 'lowest' possible level. Codegen is going to have to do its own 'looping'.
if (!VarExpr || VarExpr->getType()->isDependentType())
return OpenACCReductionRecipe::Empty();

QualType VarTy =
VarExpr->getType().getNonReferenceType().getUnqualifiedType();

// TODO: OpenACC: for arrays/bounds versions, we're going to have to do a
// different initializer, but for now we can go ahead with this.
// Array sections are special, and we have to treat them that way.
if (const auto *ASE =
dyn_cast<ArraySectionExpr>(VarExpr->IgnoreParenImpCasts()))
VarTy = ArraySectionExpr::getBaseOriginalType(ASE);

VarDecl *AllocaDecl = CreateAllocaDecl(
getASTContext(), SemaRef.getCurContext(), VarExpr->getBeginLoc(),
Expand Down
Loading