clang: lib/CIR/CodeGen/CIRGenOpenACCRecipe.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
15
22
23#include "mlir/Dialect/OpenACC/OpenACC.h"
24
27
28 void makeAllocaCopy(mlir::Location loc, mlir::Type copyType,
29 mlir::Value numEltsToCopy, mlir::Value offsetPerSubarray,
30 mlir::Value destAlloca, mlir::Value srcAlloca);
31
32
33 mlir::Value makeBoundsAlloca(mlir::Block *block, SourceRange exprRange,
34 mlir::Location loc, std::string_view allocaName,
35 size_t numBounds,
37
38 void makeBoundsInit(mlir::Value alloca, mlir::Location loc,
39 mlir::Block *block, const VarDecl *allocaDecl,
40 QualType origType, bool isInitSection);
41
42protected:
45
46 mlir::Block *createRecipeBlock(mlir::Region ®ion, mlir::Type opTy,
47 mlir::Location loc, size_t numBounds,
48 bool isInit);
49
50
51
52 std::pair<mlir::Value, mlir::Value>
53 createBoundsLoop(mlir::Value subscriptedValue, mlir::Value subscriptedValue2,
54 mlir::Value bound, mlir::Location loc, bool inverse);
55
56 mlir::Value createBoundsLoop(mlir::Value subscriptedValue, mlir::Value bound,
57 mlir::Location loc, bool inverse) {
58 return createBoundsLoop(subscriptedValue, {}, bound, loc, inverse).first;
59 }
60
62
63
64
65
66
68 mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp,
69 mlir::acc::ReductionRecipeOp recipe, size_t numBounds, QualType origType,
71
72 void createInitRecipe(mlir::Location loc, mlir::Location locEnd,
73 SourceRange exprRange, mlir::Value mainOp,
74 mlir::Region &recipeInitRegion, size_t numBounds,
77 bool emitInitExpr);
78
80 mlir::Value mainOp,
81 const VarDecl *allocaDecl,
83 mlir::Region ©Region, size_t numBounds);
84
86 mlir::Value mainOp, CharUnits alignment,
87 QualType origType, size_t numBounds,
89 mlir::Region &destroyRegion);
90
94};
95
96template
99 unsigned numBounds,
101 std::string recipeName;
102 {
103 llvm::raw_string_ostream stream(recipeName);
104
105 if constexpr (std::is_same_v<RecipeTy, mlir::acc::PrivateRecipeOp>) {
106 stream << "privatization_";
107 } else if constexpr (std::is_same_v<RecipeTy,
108 mlir::acc::FirstprivateRecipeOp>) {
109 stream << "firstprivatization_";
110
111 } else if constexpr (std::is_same_v<RecipeTy,
112 mlir::acc::ReductionRecipeOp>) {
113 stream << "reduction_";
114
115
116
117 switch (reductionOp) {
119 stream << "add_";
120 break;
122 stream << "mul_";
123 break;
125 stream << "max_";
126 break;
128 stream << "min_";
129 break;
131 stream << "iand_";
132 break;
134 stream << "ior_";
135 break;
137 stream << "xor_";
138 break;
140 stream << "land_";
141 break;
143 stream << "lor_";
144 break;
146 llvm_unreachable("invalid reduction operator");
147 }
148 } else {
149 static_assert(!sizeof(RecipeTy), "Unknown Recipe op kind");
150 }
151
152
153
154 if (numBounds)
155 stream << "_Bcnt" << numBounds << '_';
156
159 }
160 return recipeName;
161 }
162
163public:
168 ASTContext &astCtx, mlir::OpBuilder::InsertPoint &insertLocation,
169 const Expr *varRef, const VarDecl *varRecipe, const VarDecl *temporary,
172 mlir::Value mainOp,
174 reductionCombinerRecipes) {
176 BuiltinType::ArraySection) &&
177 "array section shouldn't make it to recipe creation");
178
179 mlir::ModuleOp mod = builder.getBlock()
180 ->getParent()
181 ->template getParentOfTypemlir::ModuleOp();
182
183 std::string recipeName = getRecipeName(varRef->getSourceRange(), baseType,
184 numBounds, reductionOp);
185 if (auto recipe = mod.lookupSymbol(recipeName))
186 return recipe;
187
188 mlir::Location loc = cgf.cgm.getLoc(varRef->getBeginLoc());
189 mlir::Location locEnd = cgf.cgm.getLoc(varRef->getEndLoc());
190
191 mlir::OpBuilder modBuilder(mod.getBodyRegion());
192 if (insertLocation.isSet())
193 modBuilder.restoreInsertionPoint(insertLocation);
194 RecipeTy recipe;
195
196 if constexpr (std::is_same_v<RecipeTy, mlir::acc::ReductionRecipeOp>) {
197 recipe = RecipeTy::create(modBuilder, loc, recipeName, mainOp.getType(),
199 } else {
200 recipe = RecipeTy::create(modBuilder, loc, recipeName, mainOp.getType());
201 }
202 insertLocation = modBuilder.saveInsertionPoint();
203
204 if constexpr (std::is_same_v<RecipeTy, mlir::acc::PrivateRecipeOp>) {
206 recipe.getInitRegion(), numBounds, boundTypes, varRecipe,
207 origType, true);
208 } else if constexpr (std::is_same_v<RecipeTy,
209 mlir::acc::ReductionRecipeOp>) {
211 recipe.getInitRegion(), numBounds, boundTypes, varRecipe,
212 origType, true);
214 origType, reductionCombinerRecipes);
215 } else {
216 static_assert(std::is_same_v<RecipeTy, mlir::acc::FirstprivateRecipeOp>);
218 recipe.getInitRegion(), numBounds, boundTypes, varRecipe,
219 origType, false);
221 recipe.getCopyRegion(), numBounds);
222 }
223
226 loc, locEnd, mainOp, cgf.getContext().getDeclAlign(varRecipe),
227 origType, numBounds, baseType, recipe.getDestroyRegion());
228 return recipe;
229 }
230};
231}
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 createReductionRecipeCombiner(mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp, mlir::acc::ReductionRecipeOp recipe, size_t numBounds, QualType origType, llvm::ArrayRef< OpenACCReductionRecipe::CombinerRecipe > combinerRecipes)
OpenACCRecipeBuilderBase(CIRGen::CIRGenFunction &cgf, CIRGen::CIRGenBuilderTy &builder)
Definition CIRGenOpenACCRecipe.h:91
mlir::Value createBoundsLoop(mlir::Value subscriptedValue, mlir::Value bound, mlir::Location loc, bool inverse)
Definition CIRGenOpenACCRecipe.h:56
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, bool emitInitExpr)
CIRGen::CIRGenBuilderTy & builder
Definition CIRGenOpenACCRecipe.h:44
void createFirstprivateRecipeCopy(mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp, const VarDecl *allocaDecl, const VarDecl *temporary, mlir::Region ©Region, size_t numBounds)
mlir::acc::ReductionOperator convertReductionOp(OpenACCReductionOperator op)
CIRGen::CIRGenFunction & cgf
Definition CIRGenOpenACCRecipe.h:43
std::pair< mlir::Value, mlir::Value > createBoundsLoop(mlir::Value subscriptedValue, mlir::Value subscriptedValue2, mlir::Value bound, mlir::Location loc, bool inverse)
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)
Definition CIRGenOpenACCRecipe.h:164
RecipeTy getOrCreateRecipe(ASTContext &astCtx, mlir::OpBuilder::InsertPoint &insertLocation, const Expr *varRef, const VarDecl *varRecipe, const VarDecl *temporary, OpenACCReductionOperator reductionOp, DeclContext *dc, QualType origType, size_t numBounds, llvm::ArrayRef< QualType > boundTypes, QualType baseType, mlir::Value mainOp, llvm::ArrayRef< OpenACCReductionRecipe::CombinerRecipe > reductionCombinerRecipes)
Definition CIRGenOpenACCRecipe.h:167
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.
@ Invalid
Invalid Reduction Clause Kind.