Skip to content

Commit a061048

Browse files
committed
initial commit
1 parent ad6bb70 commit a061048

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -810,23 +810,25 @@ static void genDeclareDataOperandOperationsWithModifier(
810810
}
811811

812812
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) {
816817
for (mlir::Value operand : operands) {
817818
auto entryOp = mlir::dyn_cast_or_null<EntryOp>(operand.getDefiningOp());
818819
assert(entryOp && "data entry op expected");
820+
auto opLoc = exitLoc ? *exitLoc : entryOp.getLoc();
819821
if constexpr (std::is_same_v<ExitOp, mlir::acc::CopyoutOp> ||
820822
std::is_same_v<ExitOp, mlir::acc::UpdateHostOp>)
821823
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(),
824826
entryOp.getAsyncOperandsDeviceTypeAttr(), entryOp.getAsyncOnlyAttr(),
825827
entryOp.getDataClause(), structured, entryOp.getImplicit(),
826828
builder.getStringAttr(*entryOp.getName()));
827829
else
828830
builder.create<ExitOp>(
829-
entryOp.getLoc(), entryOp.getAccVar(), entryOp.getBounds(),
831+
opLoc, entryOp.getAccVar(), entryOp.getBounds(),
830832
entryOp.getAsyncOperands(), entryOp.getAsyncOperandsDeviceTypeAttr(),
831833
entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), structured,
832834
entryOp.getImplicit(), builder.getStringAttr(*entryOp.getName()));
@@ -3017,6 +3019,7 @@ static Op createComputeOp(
30173019

30183020
static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
30193021
mlir::Location currentLocation,
3022+
mlir::Location endLocation,
30203023
Fortran::lower::pft::Evaluation &eval,
30213024
Fortran::semantics::SemanticsContext &semanticsContext,
30223025
Fortran::lower::StatementContext &stmtCtx,
@@ -3211,19 +3214,19 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
32113214

32123215
// Create the exit operations after the region.
32133216
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
3214-
builder, copyEntryOperands, /*structured=*/true);
3217+
builder, copyEntryOperands, /*structured=*/true, endLocation);
32153218
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::DeleteOp>(
3216-
builder, copyinEntryOperands, /*structured=*/true);
3219+
builder, copyinEntryOperands, /*structured=*/true, endLocation);
32173220
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
3218-
builder, copyoutEntryOperands, /*structured=*/true);
3221+
builder, copyoutEntryOperands, /*structured=*/true, endLocation);
32193222
genDataExitOperations<mlir::acc::AttachOp, mlir::acc::DetachOp>(
3220-
builder, attachEntryOperands, /*structured=*/true);
3223+
builder, attachEntryOperands, /*structured=*/true, endLocation);
32213224
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
3222-
builder, createEntryOperands, /*structured=*/true);
3225+
builder, createEntryOperands, /*structured=*/true, endLocation);
32233226
genDataExitOperations<mlir::acc::NoCreateOp, mlir::acc::DeleteOp>(
3224-
builder, nocreateEntryOperands, /*structured=*/true);
3227+
builder, nocreateEntryOperands, /*structured=*/true, endLocation);
32253228
genDataExitOperations<mlir::acc::PresentOp, mlir::acc::DeleteOp>(
3226-
builder, presentEntryOperands, /*structured=*/true);
3229+
builder, presentEntryOperands, /*structured=*/true, endLocation);
32273230

32283231
builder.restoreInsertionPoint(insPt);
32293232
}
@@ -3300,7 +3303,9 @@ genACC(Fortran::lower::AbstractConverter &converter,
33003303
std::get<Fortran::parser::AccBlockDirective>(beginBlockDirective.t);
33013304
const auto &accClauseList =
33023305
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);
33043309
mlir::Location currentLocation = converter.genLocation(blockDirective.source);
33053310
Fortran::lower::StatementContext stmtCtx;
33063311

@@ -3309,8 +3314,8 @@ genACC(Fortran::lower::AbstractConverter &converter,
33093314
semanticsContext, stmtCtx,
33103315
accClauseList);
33113316
} 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);
33143319
} else if (blockDirective.v == llvm::acc::ACCD_serial) {
33153320
createComputeOp<mlir::acc::SerialOp>(converter, currentLocation, eval,
33163321
semanticsContext, stmtCtx,

0 commit comments

Comments
 (0)