23#include "mlir/Dialect/OpenACC/OpenACC.h"
28 void makeAllocaCopy(mlir::Location loc, mlir::Type copyType,
29 mlir::Value numEltsToCopy, mlir::Value offsetPerSubarray,
30 mlir::Value destAlloca, mlir::Value srcAlloca);
33 mlir::Value makeBoundsAlloca(mlir::Block *block,
SourceRange exprRange,
34 mlir::Location loc, std::string_view allocaName,
43 mlir::Location loc,
size_t numBounds,
48 mlir::Value
createBoundsLoop(mlir::Value subscriptedValue, mlir::Value bound,
49 mlir::Location loc,
bool inverse);
52 mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp,
54 mlir::acc::FirstprivateRecipeOp recipe,
const VarDecl *varRecipe,
63 mlir::acc::ReductionRecipeOp recipe);
66 mlir::acc::PrivateRecipeOp recipe,
70 const Expr *initExpr);
76 mlir::Region &destroyRegion);
83template <
typename RecipeTy>
88 std::string recipeName;
90 llvm::raw_string_ostream stream(recipeName);
92 if constexpr (std::is_same_v<RecipeTy, mlir::acc::PrivateRecipeOp>) {
93 stream <<
"privatization_";
94 }
else if constexpr (std::is_same_v<RecipeTy,
95 mlir::acc::FirstprivateRecipeOp>) {
96 stream <<
"firstprivatization_";
98 }
else if constexpr (std::is_same_v<RecipeTy,
99 mlir::acc::ReductionRecipeOp>) {
100 stream <<
"reduction_";
104 switch (reductionOp) {
133 llvm_unreachable(
"invalid reduction operator");
136 static_assert(!
sizeof(RecipeTy),
"Unknown Recipe op kind");
142 stream <<
"_Bcnt" << numBounds <<
'_';
154 void createRecipeInitCopy(mlir::Location loc, mlir::Location locEnd,
156 RecipeTy recipe,
const VarDecl *varRecipe,
161 assert(varRecipe &&
"Required recipe variable not set?");
172 builder.setInsertionPointToEnd(&recipe.getInitRegion().back());
176 cgf.emitAutoVarAlloca(*varRecipe,
builder.saveInsertionPoint());
181 if constexpr (std::is_same_v<RecipeTy, mlir::acc::ReductionRecipeOp>) {
185 cgf.cgm.errorNYI(exprRange,
"reduction init recipe");
186 cgf.emitAutoVarInit(tempDeclEmission);
189 mlir::acc::YieldOp::create(
builder, locEnd);
191 if constexpr (std::is_same_v<RecipeTy, mlir::acc::FirstprivateRecipeOp>) {
199 exprRange,
"firstprivate copy-init recipe not properly generated");
203 recipe, varRecipe, temporary);
212 mlir::OpBuilder::InsertPoint &insertLocation,
219 QualType baseType, mlir::Value mainOp) {
221 BuiltinType::ArraySection) &&
222 "array section shouldn't make it to recipe creation");
227 if constexpr (!std::is_same_v<RecipeTy, mlir::acc::PrivateRecipeOp>) {
230 "firstprivate/reduction-init with bounds");
237 mlir::ModuleOp mod =
builder.getBlock()
239 ->template getParentOfType<mlir::ModuleOp>();
241 std::string recipeName = getRecipeName(varRef->
getSourceRange(), baseType,
242 numBounds, reductionOp);
243 if (
auto recipe = mod.lookupSymbol<RecipeTy>(recipeName))
247 mlir::Location locEnd =
cgf.cgm.getLoc(varRef->
getEndLoc());
249 mlir::OpBuilder modBuilder(mod.getBodyRegion());
250 if (insertLocation.isSet())
251 modBuilder.restoreInsertionPoint(insertLocation);
254 if constexpr (std::is_same_v<RecipeTy, mlir::acc::ReductionRecipeOp>) {
255 recipe = RecipeTy::create(modBuilder, loc, recipeName, mainOp.getType(),
258 recipe = RecipeTy::create(modBuilder, loc, recipeName, mainOp.getType());
260 insertLocation = modBuilder.saveInsertionPoint();
262 if constexpr (std::is_same_v<RecipeTy, mlir::acc::PrivateRecipeOp>) {
264 recipe, numBounds, boundTypes, varRecipe,
267 createRecipeInitCopy(loc, locEnd, varRef->
getSourceRange(), mainOp,
268 recipe, varRecipe, temporary);
271 if constexpr (std::is_same_v<RecipeTy, mlir::acc::ReductionRecipeOp>) {
277 loc, locEnd, mainOp,
cgf.getContext().getDeclAlign(varRecipe),
278 origType, numBounds, baseType, recipe.getDestroyRegion());
Defines the clang::ASTContext interface.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines some OpenACC-specific enums and functions.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void createFirstprivateRecipeCopy(mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp, CIRGenFunction::AutoVarEmission tempDeclEmission, mlir::acc::FirstprivateRecipeOp recipe, const VarDecl *varRecipe, const VarDecl *temporary)
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, const Expr *initExpr)
OpenACCRecipeBuilderBase(CIRGen::CIRGenFunction &cgf, CIRGen::CIRGenBuilderTy &builder)
mlir::Value createBoundsLoop(mlir::Value subscriptedValue, mlir::Value bound, mlir::Location loc, bool inverse)
CIRGen::CIRGenBuilderTy & builder
mlir::acc::ReductionOperator convertReductionOp(OpenACCReductionOperator op)
CIRGen::CIRGenFunction & cgf
void createReductionRecipeCombiner(mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp, mlir::acc::ReductionRecipeOp recipe)
void createRecipeDestroySection(mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp, CharUnits alignment, QualType origType, size_t numBounds, QualType baseType, mlir::Region &destroyRegion)
mlir::Block * createRecipeBlock(mlir::Region ®ion, mlir::Type opTy, mlir::Location loc, size_t numBounds, bool isInit)
OpenACCRecipeBuilder(CIRGen::CIRGenFunction &cgf, CIRGen::CIRGenBuilderTy &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)
CharUnits - This is an opaque type for sizes expressed in character units.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
This represents one expression.
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
virtual void mangleCanonicalTypeName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
Generates a unique string for an externally visible type for use with TBAA or type uniquing.
A (possibly-)qualified type.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
A trivial tuple used to represent a source range.
SourceLocation getEndLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Represents a variable declaration or definition.
const Expr * getInit() const
@ Invalid
Invalid Reduction Clause Kind.
static AutoVarEmission invalid()
Represents a scope, including function bodies, compound statements, and the substatements of if/while...