@@ -812,23 +812,25 @@ static void genDeclareDataOperandOperationsWithModifier(
812
812
}
813
813
814
814
template <typename EntryOp, typename ExitOp>
815
- static void genDataExitOperations (fir::FirOpBuilder &builder,
816
- llvm::SmallVector<mlir::Value> operands,
817
- bool structured) {
815
+ static void
816
+ genDataExitOperations (fir::FirOpBuilder &builder,
817
+ llvm::SmallVector<mlir::Value> operands, bool structured,
818
+ std::optional<mlir::Location> exitLoc = std::nullopt) {
818
819
for (mlir::Value operand : operands) {
819
820
auto entryOp = mlir::dyn_cast_or_null<EntryOp>(operand.getDefiningOp ());
820
821
assert (entryOp && " data entry op expected" );
822
+ mlir::Location opLoc = exitLoc ? *exitLoc : entryOp.getLoc ();
821
823
if constexpr (std::is_same_v<ExitOp, mlir::acc::CopyoutOp> ||
822
824
std::is_same_v<ExitOp, mlir::acc::UpdateHostOp>)
823
825
builder.create <ExitOp>(
824
- entryOp.getLoc (), entryOp.getAccVar (), entryOp.getVar (),
825
- entryOp.getVarType (), entryOp. getBounds (), entryOp.getAsyncOperands (),
826
+ opLoc, entryOp.getAccVar (), entryOp.getVar (), entryOp.getVarType (),
827
+ entryOp.getBounds (), entryOp.getAsyncOperands (),
826
828
entryOp.getAsyncOperandsDeviceTypeAttr (), entryOp.getAsyncOnlyAttr (),
827
829
entryOp.getDataClause (), structured, entryOp.getImplicit (),
828
830
builder.getStringAttr (*entryOp.getName ()));
829
831
else
830
832
builder.create <ExitOp>(
831
- entryOp. getLoc () , entryOp.getAccVar (), entryOp.getBounds (),
833
+ opLoc , entryOp.getAccVar (), entryOp.getBounds (),
832
834
entryOp.getAsyncOperands (), entryOp.getAsyncOperandsDeviceTypeAttr (),
833
835
entryOp.getAsyncOnlyAttr (), entryOp.getDataClause (), structured,
834
836
entryOp.getImplicit (), builder.getStringAttr (*entryOp.getName ()));
@@ -2976,6 +2978,7 @@ static Op createComputeOp(
2976
2978
2977
2979
static void genACCDataOp (Fortran::lower::AbstractConverter &converter,
2978
2980
mlir::Location currentLocation,
2981
+ mlir::Location endLocation,
2979
2982
Fortran::lower::pft::Evaluation &eval,
2980
2983
Fortran::semantics::SemanticsContext &semanticsContext,
2981
2984
Fortran::lower::StatementContext &stmtCtx,
@@ -3170,19 +3173,19 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
3170
3173
3171
3174
// Create the exit operations after the region.
3172
3175
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
3173
- builder, copyEntryOperands, /* structured=*/ true );
3176
+ builder, copyEntryOperands, /* structured=*/ true , endLocation );
3174
3177
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::DeleteOp>(
3175
- builder, copyinEntryOperands, /* structured=*/ true );
3178
+ builder, copyinEntryOperands, /* structured=*/ true , endLocation );
3176
3179
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
3177
- builder, copyoutEntryOperands, /* structured=*/ true );
3180
+ builder, copyoutEntryOperands, /* structured=*/ true , endLocation );
3178
3181
genDataExitOperations<mlir::acc::AttachOp, mlir::acc::DetachOp>(
3179
- builder, attachEntryOperands, /* structured=*/ true );
3182
+ builder, attachEntryOperands, /* structured=*/ true , endLocation );
3180
3183
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
3181
- builder, createEntryOperands, /* structured=*/ true );
3184
+ builder, createEntryOperands, /* structured=*/ true , endLocation );
3182
3185
genDataExitOperations<mlir::acc::NoCreateOp, mlir::acc::DeleteOp>(
3183
- builder, nocreateEntryOperands, /* structured=*/ true );
3186
+ builder, nocreateEntryOperands, /* structured=*/ true , endLocation );
3184
3187
genDataExitOperations<mlir::acc::PresentOp, mlir::acc::DeleteOp>(
3185
- builder, presentEntryOperands, /* structured=*/ true );
3188
+ builder, presentEntryOperands, /* structured=*/ true , endLocation );
3186
3189
3187
3190
builder.restoreInsertionPoint (insPt);
3188
3191
}
@@ -3259,7 +3262,9 @@ genACC(Fortran::lower::AbstractConverter &converter,
3259
3262
std::get<Fortran::parser::AccBlockDirective>(beginBlockDirective.t );
3260
3263
const auto &accClauseList =
3261
3264
std::get<Fortran::parser::AccClauseList>(beginBlockDirective.t );
3262
-
3265
+ const auto &endBlockDirective =
3266
+ std::get<Fortran::parser::AccEndBlockDirective>(blockConstruct.t );
3267
+ mlir::Location endLocation = converter.genLocation (endBlockDirective.source );
3263
3268
mlir::Location currentLocation = converter.genLocation (blockDirective.source );
3264
3269
Fortran::lower::StatementContext stmtCtx;
3265
3270
@@ -3268,8 +3273,8 @@ genACC(Fortran::lower::AbstractConverter &converter,
3268
3273
semanticsContext, stmtCtx,
3269
3274
accClauseList);
3270
3275
} else if (blockDirective.v == llvm::acc::ACCD_data) {
3271
- genACCDataOp (converter, currentLocation, eval, semanticsContext, stmtCtx ,
3272
- accClauseList);
3276
+ genACCDataOp (converter, currentLocation, endLocation, eval ,
3277
+ semanticsContext, stmtCtx, accClauseList);
3273
3278
} else if (blockDirective.v == llvm::acc::ACCD_serial) {
3274
3279
createComputeOp<mlir::acc::SerialOp>(converter, currentLocation, eval,
3275
3280
semanticsContext, stmtCtx,
0 commit comments