41 mlir::Location loc,
bool inverse) {
42 mlir::Operation *bodyInsertLoc;
44 mlir::Type itrTy =
cgf.cgm.convertType(
cgf.getContext().UnsignedLongLongTy);
45 auto itrPtrTy = cir::PointerType::get(itrTy);
46 mlir::IntegerAttr itrAlign =
47 cgf.cgm.getSize(
cgf.getContext().getTypeAlignInChars(
48 cgf.getContext().UnsignedLongLongTy));
49 auto idxType = mlir::IndexType::get(&
cgf.getMLIRContext());
51 auto doSubscriptOp = [&](mlir::Value subVal,
52 cir::LoadOp idxLoad) -> mlir::Value {
55 if (
auto arrayTy = dyn_cast<cir::ArrayType>(eltTy))
56 return builder.getArrayElement(loc, loc, subVal, arrayTy.getElementType(),
62 auto eltLoad = cir::LoadOp::create(
builder, loc, {subVal});
64 return cir::PtrStrideOp::create(
builder, loc, eltLoad.getType(), eltLoad,
69 auto forStmtBuilder = [&]() {
72 mlir::acc::GetLowerboundOp::create(
builder, loc, idxType, bound);
73 auto lbConversion = mlir::UnrealizedConversionCastOp::create(
74 builder, loc, itrTy, lowerBoundVal.getResult());
76 mlir::acc::GetUpperboundOp::create(
builder, loc, idxType, bound);
77 auto ubConversion = mlir::UnrealizedConversionCastOp::create(
78 builder, loc, itrTy, upperBoundVal.getResult());
82 cir::AllocaOp::create(
builder, loc, itrPtrTy, itrTy,
"iter", itrAlign);
86 cir::ConstantOp constOne =
builder.getConstInt(loc, itrTy, 1);
89 cir::BinOp::create(
builder, loc, itrTy, cir::BinOpKind::Sub,
90 ubConversion.getResult(0), constOne.getResult());
93 builder.CIRBaseBuilderTy::createStore(loc, sub.getResult(), itr);
96 builder.CIRBaseBuilderTy::createStore(loc, lbConversion.getResult(0),
102 auto endItr = inverse ? lbConversion : ubConversion;
107 [&](mlir::OpBuilder &
b, mlir::Location loc) {
108 auto loadCur = cir::LoadOp::create(
builder, loc, {itr});
110 auto cmp =
builder.createCompare(
111 loc, inverse ? cir::CmpOpKind::ge : cir::CmpOpKind::lt,
112 loadCur.getResult(), endItr.getResult(0));
116 [&](mlir::OpBuilder &
b, mlir::Location loc) {
117 auto load = cir::LoadOp::create(
builder, loc, {itr});
119 if (subscriptedValue)
120 subscriptedValue = doSubscriptOp(subscriptedValue, load);
121 bodyInsertLoc =
builder.createYield(loc);
124 [&](mlir::OpBuilder &
b, mlir::Location loc) {
125 auto load = cir::LoadOp::create(
builder, loc, {itr});
126 auto unary = cir::UnaryOp::create(
builder, loc, load.getType(),
127 inverse ? cir::UnaryOpKind::Dec
128 : cir::UnaryOpKind::Inc,
130 builder.CIRBaseBuilderTy::createStore(loc, unary.getResult(), itr);
135 cir::ScopeOp::create(
builder, loc,
136 [&](mlir::OpBuilder &
b, mlir::Location loc) {
143 builder.setInsertionPoint(bodyInsertLoc);
144 return subscriptedValue;
180 mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp,
182 mlir::Region &destroyRegion) {
185 builder.setInsertionPointToEnd(&destroyRegion.back());
188 mlir::Type elementTy =
189 mlir::cast<cir::PointerType>(mainOp.getType()).getPointee();
190 auto emitDestroy = [&](mlir::Value var, mlir::Type ty) {
191 Address addr{var, ty, alignment};
192 cgf.emitDestroy(addr, origType,
197 mlir::OpBuilder::InsertionGuard guardCase(
builder);
201 block->getArguments().drop_front(2);
203 mlir::Value subscriptedValue = block->getArgument(1);
204 for (mlir::BlockArgument boundArg : llvm::reverse(boundsRange))
208 emitDestroy(subscriptedValue,
cgf.cgm.convertType(origType));
214 emitDestroy(block->getArgument(1), elementTy);
217 mlir::acc::YieldOp::create(
builder, locEnd);
225 mlir::Location loc, mlir::Location locEnd,
SourceRange exprRange,
226 mlir::Value mainOp, mlir::acc::PrivateRecipeOp recipe,
size_t numBounds,
229 assert(allocaDecl &&
"Required recipe variable not set?");
235 builder.setInsertionPointToEnd(&recipe.getInitRegion().back());
238 const Type *allocaPointeeType =
242 if (
cgf.getContext().getLangOpts().CPlusPlus && !allocaDecl->
getInit() &&
251 cgf.cgm.errorNYI(exprRange,
"private default-init recipe");
258 cgf.emitAutoVarAlloca(*allocaDecl,
builder.saveInsertionPoint());
259 cgf.emitAutoVarInit(tempDeclEmission);
261 cgf.cgm.errorNYI(exprRange,
"private-init with bounds");
264 mlir::acc::YieldOp::create(
builder, locEnd);
268 mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp,
270 mlir::acc::FirstprivateRecipeOp recipe,
const VarDecl *varRecipe,
275 builder.setInsertionPointToEnd(&recipe.getCopyRegion().back());
278 mlir::BlockArgument fromArg = block->getArgument(0);
279 mlir::BlockArgument toArg = block->getArgument(1);
281 mlir::Type elementTy =
282 mlir::cast<cir::PointerType>(mainOp.getType()).getPointee();
287 Address{toArg, elementTy,
cgf.getContext().getDeclAlign(varRecipe)});
291 cgf.setAddrOfLocalVar(
293 Address{fromArg, elementTy,
cgf.getContext().getDeclAlign(varRecipe)});
295 cgf.emitAutoVarInit(tempDeclEmission);
296 mlir::acc::YieldOp::create(
builder, locEnd);
303 mlir::Location loc, mlir::Location locEnd, mlir::Value mainOp,
304 mlir::acc::ReductionRecipeOp recipe) {
305 mlir::Block *block =
builder.createBlock(
306 &recipe.getCombinerRegion(), recipe.getCombinerRegion().end(),
307 {mainOp.getType(), mainOp.getType()}, {loc, loc});
308 builder.setInsertionPointToEnd(&recipe.getCombinerRegion().back());
311 mlir::BlockArgument lhsArg = block->getArgument(0);
313 mlir::acc::YieldOp::create(
builder, locEnd, lhsArg);
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)