Skip to content

Commit 7ba0800

Browse files
committed
initial commit
1 parent 6520b21 commit 7ba0800

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
@@ -812,23 +812,25 @@ static void genDeclareDataOperandOperationsWithModifier(
812812
}
813813

814814
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) {
818819
for (mlir::Value operand : operands) {
819820
auto entryOp = mlir::dyn_cast_or_null<EntryOp>(operand.getDefiningOp());
820821
assert(entryOp && "data entry op expected");
822+
auto opLoc = exitLoc ? *exitLoc : entryOp.getLoc();
821823
if constexpr (std::is_same_v<ExitOp, mlir::acc::CopyoutOp> ||
822824
std::is_same_v<ExitOp, mlir::acc::UpdateHostOp>)
823825
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(),
826828
entryOp.getAsyncOperandsDeviceTypeAttr(), entryOp.getAsyncOnlyAttr(),
827829
entryOp.getDataClause(), structured, entryOp.getImplicit(),
828830
builder.getStringAttr(*entryOp.getName()));
829831
else
830832
builder.create<ExitOp>(
831-
entryOp.getLoc(), entryOp.getAccVar(), entryOp.getBounds(),
833+
opLoc, entryOp.getAccVar(), entryOp.getBounds(),
832834
entryOp.getAsyncOperands(), entryOp.getAsyncOperandsDeviceTypeAttr(),
833835
entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), structured,
834836
entryOp.getImplicit(), builder.getStringAttr(*entryOp.getName()));
@@ -2976,6 +2978,7 @@ static Op createComputeOp(
29762978

29772979
static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
29782980
mlir::Location currentLocation,
2981+
mlir::Location endLocation,
29792982
Fortran::lower::pft::Evaluation &eval,
29802983
Fortran::semantics::SemanticsContext &semanticsContext,
29812984
Fortran::lower::StatementContext &stmtCtx,
@@ -3170,19 +3173,19 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
31703173

31713174
// Create the exit operations after the region.
31723175
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
3173-
builder, copyEntryOperands, /*structured=*/true);
3176+
builder, copyEntryOperands, /*structured=*/true, endLocation);
31743177
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::DeleteOp>(
3175-
builder, copyinEntryOperands, /*structured=*/true);
3178+
builder, copyinEntryOperands, /*structured=*/true, endLocation);
31763179
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
3177-
builder, copyoutEntryOperands, /*structured=*/true);
3180+
builder, copyoutEntryOperands, /*structured=*/true, endLocation);
31783181
genDataExitOperations<mlir::acc::AttachOp, mlir::acc::DetachOp>(
3179-
builder, attachEntryOperands, /*structured=*/true);
3182+
builder, attachEntryOperands, /*structured=*/true, endLocation);
31803183
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
3181-
builder, createEntryOperands, /*structured=*/true);
3184+
builder, createEntryOperands, /*structured=*/true, endLocation);
31823185
genDataExitOperations<mlir::acc::NoCreateOp, mlir::acc::DeleteOp>(
3183-
builder, nocreateEntryOperands, /*structured=*/true);
3186+
builder, nocreateEntryOperands, /*structured=*/true, endLocation);
31843187
genDataExitOperations<mlir::acc::PresentOp, mlir::acc::DeleteOp>(
3185-
builder, presentEntryOperands, /*structured=*/true);
3188+
builder, presentEntryOperands, /*structured=*/true, endLocation);
31863189

31873190
builder.restoreInsertionPoint(insPt);
31883191
}
@@ -3259,7 +3262,9 @@ genACC(Fortran::lower::AbstractConverter &converter,
32593262
std::get<Fortran::parser::AccBlockDirective>(beginBlockDirective.t);
32603263
const auto &accClauseList =
32613264
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);
32633268
mlir::Location currentLocation = converter.genLocation(blockDirective.source);
32643269
Fortran::lower::StatementContext stmtCtx;
32653270

@@ -3268,8 +3273,8 @@ genACC(Fortran::lower::AbstractConverter &converter,
32683273
semanticsContext, stmtCtx,
32693274
accClauseList);
32703275
} 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);
32733278
} else if (blockDirective.v == llvm::acc::ACCD_serial) {
32743279
createComputeOp<mlir::acc::SerialOp>(converter, currentLocation, eval,
32753280
semanticsContext, stmtCtx,

0 commit comments

Comments
 (0)