@@ -400,6 +400,32 @@ void OpenACCRecipeBuilderBase::createRecipeDestroySection(
400400
401401 mlir::acc::YieldOp::create (builder, locEnd);
402402}
403+ void OpenACCRecipeBuilderBase::makeBoundsInit (
404+ mlir::Value alloca, mlir::Location loc, mlir::Block *block,
405+ const VarDecl *allocaDecl, QualType origType, bool isInitSection) {
406+ mlir::OpBuilder::InsertionGuard guardCase (builder);
407+ builder.setInsertionPointToEnd (block);
408+ CIRGenFunction::LexicalScope ls (cgf, loc, block);
409+
410+ CIRGenFunction::AutoVarEmission tempDeclEmission{*allocaDecl};
411+ tempDeclEmission.EmittedAsOffload = true ;
412+
413+ // The init section is the only one of the handful that only has a single
414+ // argument for the 'type', so we have to drop 1 for init, and future calls
415+ // to this will need to drop 2.
416+ llvm::MutableArrayRef<mlir::BlockArgument> boundsRange =
417+ block->getArguments ().drop_front (isInitSection ? 1 : 2 );
418+
419+ mlir::Value subscriptedValue = alloca;
420+ for (mlir::BlockArgument boundArg : llvm::reverse (boundsRange))
421+ subscriptedValue = createBoundsLoop (subscriptedValue, boundArg, loc,
422+ /* inverse=*/ false );
423+
424+ tempDeclEmission.setAllocatedAddress (
425+ Address{subscriptedValue, cgf.convertType (origType),
426+ cgf.getContext ().getDeclAlign (allocaDecl)});
427+ cgf.emitAutoVarInit (tempDeclEmission);
428+ }
403429
404430// TODO: OpenACC: When we get this implemented for the reduction/firstprivate,
405431// this might end up re-merging with createRecipeInitCopy. For now, keep it
@@ -442,11 +468,16 @@ void OpenACCRecipeBuilderBase::createPrivateInitRecipe(
442468 cgf.emitAutoVarAlloca (*allocaDecl, builder.saveInsertionPoint ());
443469 cgf.emitAutoVarInit (tempDeclEmission);
444470 } else {
445- makeBoundsAlloca (block, exprRange, loc, " openacc.private.init" , numBounds,
446- boundTypes);
447-
448- if (initExpr)
449- cgf.cgm .errorNYI (exprRange, " private-init with bounds initialization" );
471+ mlir::Value alloca = makeBoundsAlloca (
472+ block, exprRange, loc, " openacc.private.init" , numBounds, boundTypes);
473+
474+ // If the initializer is trivial, there is nothing to do here, so save
475+ // ourselves some effort.
476+ if (initExpr && (!cgf.isTrivialInitializer (initExpr) ||
477+ cgf.getContext ().getLangOpts ().getTrivialAutoVarInit () !=
478+ LangOptions::TrivialAutoVarInitKind::Uninitialized))
479+ makeBoundsInit (alloca, loc, block, allocaDecl, origType,
480+ /* isInitSection=*/ true );
450481 }
451482
452483 mlir::acc::YieldOp::create (builder, locEnd);
0 commit comments