@@ -358,8 +358,8 @@ class OpenACCClauseCIREmitter final
358358
359359 template <typename RecipeTy>
360360 RecipeTy getOrCreateRecipe (ASTContext &astCtx, const Expr *varRef,
361- DeclContext *dc, QualType baseType ,
362- mlir::Value mainOp) {
361+ const VarDecl *varRecipe, DeclContext *dc ,
362+ QualType baseType, mlir::Value mainOp) {
363363 mlir::ModuleOp mod =
364364 builder.getBlock ()->getParent ()->getParentOfType <mlir::ModuleOp>();
365365
@@ -398,12 +398,6 @@ class OpenACCClauseCIREmitter final
398398 auto recipe =
399399 RecipeTy::create (modBuilder, loc, recipeName, mainOp.getType ());
400400
401- // Magic-up a var-decl so we can use normal init/destruction operations for
402- // a variable declaration.
403- VarDecl &tempDecl = *VarDecl::Create (
404- astCtx, dc, varRef->getBeginLoc (), varRef->getBeginLoc (),
405- &astCtx.Idents .get (" openacc.private.init" ), baseType,
406- astCtx.getTrivialTypeSourceInfo (baseType), SC_Auto);
407401 CIRGenFunction::AutoVarEmission tempDeclEmission{
408402 CIRGenFunction::AutoVarEmission::invalid ()};
409403
@@ -422,9 +416,11 @@ class OpenACCClauseCIREmitter final
422416 " OpenACC non-private recipe init" );
423417 }
424418
425- tempDeclEmission =
426- cgf.emitAutoVarAlloca (tempDecl, builder.saveInsertionPoint ());
427- cgf.emitAutoVarInit (tempDeclEmission);
419+ if (varRecipe) {
420+ tempDeclEmission =
421+ cgf.emitAutoVarAlloca (*varRecipe, builder.saveInsertionPoint ());
422+ cgf.emitAutoVarInit (tempDeclEmission);
423+ }
428424
429425 mlir::acc::YieldOp::create (builder, locEnd);
430426 }
@@ -439,7 +435,7 @@ class OpenACCClauseCIREmitter final
439435 }
440436
441437 // Destroy section (doesn't currently exist).
442- if (tempDecl. needsDestruction (cgf.getContext ())) {
438+ if (varRecipe && varRecipe-> needsDestruction (cgf.getContext ())) {
443439 llvm::SmallVector<mlir::Type> argsTys{mainOp.getType ()};
444440 llvm::SmallVector<mlir::Location> argsLocs{loc};
445441 mlir::Block *block = builder.createBlock (&recipe.getDestroyRegion (),
@@ -450,7 +446,7 @@ class OpenACCClauseCIREmitter final
450446 mlir::Type elementTy =
451447 mlir::cast<cir::PointerType>(mainOp.getType ()).getPointee ();
452448 Address addr{block->getArgument (0 ), elementTy,
453- cgf.getContext ().getDeclAlign (&tempDecl )};
449+ cgf.getContext ().getDeclAlign (varRecipe )};
454450 cgf.emitDestroy (addr, baseType,
455451 cgf.getDestroyer (QualType::DK_cxx_destructor));
456452
@@ -1080,9 +1076,10 @@ class OpenACCClauseCIREmitter final
10801076 void VisitPrivateClause (const OpenACCPrivateClause &clause) {
10811077 if constexpr (isOneOfTypes<OpTy, mlir::acc::ParallelOp, mlir::acc::SerialOp,
10821078 mlir::acc::LoopOp>) {
1083- for (const Expr *var : clause.getVarList ()) {
1079+ for (const auto [varExpr, varRecipe] :
1080+ llvm::zip_equal (clause.getVarList (), clause.getInitRecipes ())) {
10841081 CIRGenFunction::OpenACCDataOperandInfo opInfo =
1085- cgf.getOpenACCDataOperandInfo (var );
1082+ cgf.getOpenACCDataOperandInfo (varExpr );
10861083 auto privateOp = mlir::acc::PrivateOp::create (
10871084 builder, opInfo.beginLoc , opInfo.varValue , /* structured=*/ true ,
10881085 /* implicit=*/ false , opInfo.name , opInfo.bounds );
@@ -1091,8 +1088,9 @@ class OpenACCClauseCIREmitter final
10911088 {
10921089 mlir::OpBuilder::InsertionGuard guardCase (builder);
10931090 auto recipe = getOrCreateRecipe<mlir::acc::PrivateRecipeOp>(
1094- cgf.getContext (), var, Decl::castToDeclContext (cgf.curFuncDecl ),
1095- opInfo.baseType , privateOp.getResult ());
1091+ cgf.getContext (), varExpr, varRecipe,
1092+ Decl::castToDeclContext (cgf.curFuncDecl ), opInfo.baseType ,
1093+ privateOp.getResult ());
10961094 // TODO: OpenACC: The dialect is going to change in the near future to
10971095 // have these be on a different operation, so when that changes, we
10981096 // probably need to change these here.
0 commit comments