@@ -810,23 +810,25 @@ static void genDeclareDataOperandOperationsWithModifier(
810
810
}
811
811
812
812
template <typename EntryOp, typename ExitOp>
813
- static void genDataExitOperations (fir::FirOpBuilder &builder,
814
- llvm::SmallVector<mlir::Value> operands,
815
- bool structured) {
813
+ static void
814
+ genDataExitOperations (fir::FirOpBuilder &builder,
815
+ llvm::SmallVector<mlir::Value> operands, bool structured,
816
+ std::optional<mlir::Location> exitLoc = std::nullopt) {
816
817
for (mlir::Value operand : operands) {
817
818
auto entryOp = mlir::dyn_cast_or_null<EntryOp>(operand.getDefiningOp ());
818
819
assert (entryOp && " data entry op expected" );
820
+ auto opLoc = exitLoc ? *exitLoc : entryOp.getLoc ();
819
821
if constexpr (std::is_same_v<ExitOp, mlir::acc::CopyoutOp> ||
820
822
std::is_same_v<ExitOp, mlir::acc::UpdateHostOp>)
821
823
builder.create <ExitOp>(
822
- entryOp.getLoc (), entryOp.getAccVar (), entryOp.getVar (),
823
- entryOp.getVarType (), entryOp. getBounds (), entryOp.getAsyncOperands (),
824
+ opLoc, entryOp.getAccVar (), entryOp.getVar (), entryOp.getVarType (),
825
+ entryOp.getBounds (), entryOp.getAsyncOperands (),
824
826
entryOp.getAsyncOperandsDeviceTypeAttr (), entryOp.getAsyncOnlyAttr (),
825
827
entryOp.getDataClause (), structured, entryOp.getImplicit (),
826
828
builder.getStringAttr (*entryOp.getName ()));
827
829
else
828
830
builder.create <ExitOp>(
829
- entryOp. getLoc () , entryOp.getAccVar (), entryOp.getBounds (),
831
+ opLoc , entryOp.getAccVar (), entryOp.getBounds (),
830
832
entryOp.getAsyncOperands (), entryOp.getAsyncOperandsDeviceTypeAttr (),
831
833
entryOp.getAsyncOnlyAttr (), entryOp.getDataClause (), structured,
832
834
entryOp.getImplicit (), builder.getStringAttr (*entryOp.getName ()));
@@ -3017,6 +3019,7 @@ static Op createComputeOp(
3017
3019
3018
3020
static void genACCDataOp (Fortran::lower::AbstractConverter &converter,
3019
3021
mlir::Location currentLocation,
3022
+ mlir::Location endLocation,
3020
3023
Fortran::lower::pft::Evaluation &eval,
3021
3024
Fortran::semantics::SemanticsContext &semanticsContext,
3022
3025
Fortran::lower::StatementContext &stmtCtx,
@@ -3211,19 +3214,19 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
3211
3214
3212
3215
// Create the exit operations after the region.
3213
3216
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
3214
- builder, copyEntryOperands, /* structured=*/ true );
3217
+ builder, copyEntryOperands, /* structured=*/ true , endLocation );
3215
3218
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::DeleteOp>(
3216
- builder, copyinEntryOperands, /* structured=*/ true );
3219
+ builder, copyinEntryOperands, /* structured=*/ true , endLocation );
3217
3220
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
3218
- builder, copyoutEntryOperands, /* structured=*/ true );
3221
+ builder, copyoutEntryOperands, /* structured=*/ true , endLocation );
3219
3222
genDataExitOperations<mlir::acc::AttachOp, mlir::acc::DetachOp>(
3220
- builder, attachEntryOperands, /* structured=*/ true );
3223
+ builder, attachEntryOperands, /* structured=*/ true , endLocation );
3221
3224
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
3222
- builder, createEntryOperands, /* structured=*/ true );
3225
+ builder, createEntryOperands, /* structured=*/ true , endLocation );
3223
3226
genDataExitOperations<mlir::acc::NoCreateOp, mlir::acc::DeleteOp>(
3224
- builder, nocreateEntryOperands, /* structured=*/ true );
3227
+ builder, nocreateEntryOperands, /* structured=*/ true , endLocation );
3225
3228
genDataExitOperations<mlir::acc::PresentOp, mlir::acc::DeleteOp>(
3226
- builder, presentEntryOperands, /* structured=*/ true );
3229
+ builder, presentEntryOperands, /* structured=*/ true , endLocation );
3227
3230
3228
3231
builder.restoreInsertionPoint (insPt);
3229
3232
}
@@ -3300,7 +3303,9 @@ genACC(Fortran::lower::AbstractConverter &converter,
3300
3303
std::get<Fortran::parser::AccBlockDirective>(beginBlockDirective.t );
3301
3304
const auto &accClauseList =
3302
3305
std::get<Fortran::parser::AccClauseList>(beginBlockDirective.t );
3303
-
3306
+ const auto &endBlockDirective =
3307
+ std::get<Fortran::parser::AccEndBlockDirective>(blockConstruct.t );
3308
+ mlir::Location endLocation = converter.genLocation (endBlockDirective.source );
3304
3309
mlir::Location currentLocation = converter.genLocation (blockDirective.source );
3305
3310
Fortran::lower::StatementContext stmtCtx;
3306
3311
@@ -3309,8 +3314,8 @@ genACC(Fortran::lower::AbstractConverter &converter,
3309
3314
semanticsContext, stmtCtx,
3310
3315
accClauseList);
3311
3316
} else if (blockDirective.v == llvm::acc::ACCD_data) {
3312
- genACCDataOp (converter, currentLocation, eval, semanticsContext, stmtCtx ,
3313
- accClauseList);
3317
+ genACCDataOp (converter, currentLocation, endLocation, eval ,
3318
+ semanticsContext, stmtCtx, accClauseList);
3314
3319
} else if (blockDirective.v == llvm::acc::ACCD_serial) {
3315
3320
createComputeOp<mlir::acc::SerialOp>(converter, currentLocation, eval,
3316
3321
semanticsContext, stmtCtx,
0 commit comments