Skip to content

Commit 14d9e99

Browse files
committed
change recipe
1 parent 8ec4d87 commit 14d9e99

File tree

3 files changed

+40
-44
lines changed

3 files changed

+40
-44
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,16 @@ static void createDeclareAllocFuncWithArg(mlir::OpBuilder &modBuilder,
244244
if (unwrapFirBox)
245245
asFortranDesc << accFirDescriptorPostfix.str();
246246

247-
// Updating descriptor must occur before the mapping of the data so that
248-
// attached data pointer is not overwritten.
249-
mlir::acc::UpdateDeviceOp updateDeviceOp =
250-
createDataEntryOp<mlir::acc::UpdateDeviceOp>(
251-
builder, loc, registerFuncOp.getArgument(0), asFortranDesc, bounds,
252-
/*structured=*/false, /*implicit=*/true,
253-
mlir::acc::DataClause::acc_update_device, descTy,
254-
/*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{});
255-
llvm::SmallVector<int32_t> operandSegments{0, 0, 0, 1};
256-
llvm::SmallVector<mlir::Value> operands{updateDeviceOp.getResult()};
257-
createSimpleOp<mlir::acc::UpdateOp>(builder, loc, operands, operandSegments);
247+
// Use declare_enter for the descriptor so the runtime mirrors allocation
248+
// semantics instead of issuing an update. This ensures the descriptor's
249+
// device-side metadata is established via a structured begin.
250+
EntryOp descEntryOp = createDataEntryOp<EntryOp>(
251+
builder, loc, registerFuncOp.getArgument(0), asFortranDesc, bounds,
252+
/*structured=*/false, /*implicit=*/true, clause, descTy,
253+
/*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{});
254+
mlir::acc::DeclareEnterOp::create(
255+
builder, loc, mlir::acc::DeclareTokenType::get(descEntryOp.getContext()),
256+
mlir::ValueRange(descEntryOp.getAccVar()));
258257

259258
if (unwrapFirBox) {
260259
mlir::Value desc =
@@ -3989,17 +3988,16 @@ static void createDeclareAllocFunc(mlir::OpBuilder &modBuilder,
39893988
asFortranDesc << accFirDescriptorPostfix.str();
39903989
llvm::SmallVector<mlir::Value> bounds;
39913990

3992-
// Updating descriptor must occur before the mapping of the data so that
3993-
// attached data pointer is not overwritten.
3994-
mlir::acc::UpdateDeviceOp updateDeviceOp =
3995-
createDataEntryOp<mlir::acc::UpdateDeviceOp>(
3996-
builder, loc, addrOp, asFortranDesc, bounds,
3997-
/*structured=*/false, /*implicit=*/true,
3998-
mlir::acc::DataClause::acc_update_device, addrOp.getType(),
3999-
/*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{});
4000-
llvm::SmallVector<int32_t> operandSegments{0, 0, 0, 1};
4001-
llvm::SmallVector<mlir::Value> operands{updateDeviceOp.getResult()};
4002-
createSimpleOp<mlir::acc::UpdateOp>(builder, loc, operands, operandSegments);
3991+
// Use declare_enter for the descriptor so the runtime mirrors allocation
3992+
// semantics instead of issuing an update. This ensures the descriptor's
3993+
// device-side metadata is established via a structured begin.
3994+
EntryOp descEntryOp = createDataEntryOp<EntryOp>(
3995+
builder, loc, addrOp, asFortranDesc, bounds,
3996+
/*structured=*/false, /*implicit=*/true, clause, addrOp.getType(),
3997+
/*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{});
3998+
mlir::acc::DeclareEnterOp::create(
3999+
builder, loc, mlir::acc::DeclareTokenType::get(descEntryOp.getContext()),
4000+
mlir::ValueRange(descEntryOp.getAccVar()));
40034001

40044002
if (unwrapFirBox) {
40054003
auto loadOp = fir::LoadOp::create(builder, loc, addrOp.getResult());
@@ -4092,15 +4090,15 @@ static void createDeclareDeallocFunc(mlir::OpBuilder &modBuilder,
40924090
if (unwrapFirBox)
40934091
asFortran << accFirDescriptorPostfix.str();
40944092
llvm::SmallVector<mlir::Value> bounds;
4095-
mlir::acc::UpdateDeviceOp updateDeviceOp =
4096-
createDataEntryOp<mlir::acc::UpdateDeviceOp>(
4093+
// Use declare_exit for the descriptor to end the structured declare region
4094+
// instead of issuing an update.
4095+
mlir::acc::GetDevicePtrOp descEntryOp =
4096+
createDataEntryOp<mlir::acc::GetDevicePtrOp>(
40974097
builder, loc, addrOp, asFortran, bounds,
4098-
/*structured=*/false, /*implicit=*/true,
4099-
mlir::acc::DataClause::acc_update_device, addrOp.getType(),
4098+
/*structured=*/false, /*implicit=*/true, clause, addrOp.getType(),
41004099
/*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{});
4101-
llvm::SmallVector<int32_t> operandSegments{0, 0, 0, 1};
4102-
llvm::SmallVector<mlir::Value> operands{updateDeviceOp.getResult()};
4103-
createSimpleOp<mlir::acc::UpdateOp>(builder, loc, operands, operandSegments);
4100+
mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{},
4101+
mlir::ValueRange(descEntryOp.getAccVar()));
41044102
modBuilder.setInsertionPointAfter(postDeallocOp);
41054103
}
41064104

flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
! This test checks lowering of OpenACC declare directive in function and
22
! subroutine specification parts.
3-
43
! RUN: bbc -fopenacc -emit-hlfir --openacc-unwrap-fir-box=true --openacc-generate-default-bounds=true %s -o - | FileCheck %s
54

5+
66
module acc_declare
77
contains
88

@@ -258,8 +258,6 @@ subroutine acc_declare_allocate()
258258

259259
! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_alloc(
260260
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) {
261-
! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[ARG0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "a_desc", structured = false}
262-
! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
263261
! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
264262
! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] {acc.declare = #acc.declare<dataClause = acc_create>} : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
265263
! CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[BOX_ADDR]] : !fir.heap<!fir.array<?xi32>>) -> !fir.heap<!fir.array<?xi32>> {name = "a", structured = false}
@@ -281,7 +279,7 @@ subroutine acc_declare_allocate()
281279
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) {
282280
! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
283281
! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
284-
! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[BOX_ADDR]] : !fir.heap<!fir.array<?xi32>>) -> !fir.heap<!fir.array<?xi32>> {implicit = true, name = "a_desc", structured = false}
282+
! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[BOX_ADDR]] : !fir.heap<!fir.array<?xi32>>) -> !fir.heap<!fir.array<?xi32>>
285283
! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.heap<!fir.array<?xi32>>)
286284
! CHECK: return
287285
! CHECK: }
@@ -355,8 +353,8 @@ module acc_declare_allocatable_test
355353

356354
! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_alloc() {
357355
! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
358-
! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "data1_desc", structured = false}
359-
! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
356+
! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "data1_desc", structured = false}
357+
! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
360358
! CHECK: %[[LOAD:.*]] = fir.load %[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
361359
! CHECK: %[[BOXADDR:.*]] = fir.box_addr %[[LOAD]] {acc.declare = #acc.declare<dataClause = acc_create>} : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
362360
! CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[BOXADDR]] : !fir.heap<!fir.array<?xi32>>) -> !fir.heap<!fir.array<?xi32>> {name = "data1", structured = false}
@@ -376,8 +374,8 @@ module acc_declare_allocatable_test
376374

377375
! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_dealloc() {
378376
! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
379-
! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "data1_desc", structured = false}
380-
! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
377+
! CHECK: %[[DEVPTR:.*]] = acc.getdeviceptr varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {dataClause = #acc<data_clause acc_create>, implicit = true, name = "data1_desc", structured = false}
378+
! CHECK: acc.declare_exit dataOperands(%[[DEVPTR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
381379
! CHECK: return
382380
! CHECK: }
383381

flang/test/Lower/OpenACC/acc-declare.f90

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
! This test checks lowering of OpenACC declare directive in function and
22
! subroutine specification parts.
3-
43
! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
54

5+
66
module acc_declare
77
contains
88

@@ -250,8 +250,8 @@ subroutine acc_declare_allocate()
250250

251251
! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_alloc(
252252
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) {
253-
! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[ARG0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "a", structured = false}
254-
! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
253+
! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[ARG0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "a", structured = false}
254+
! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
255255
! CHECK: return
256256
! CHECK: }
257257

@@ -330,15 +330,15 @@ module acc_declare_allocatable_test
330330

331331
! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_alloc() {
332332
! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
333-
! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "data1", structured = false}
334-
! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
333+
! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "data1", structured = false}
334+
! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
335335
! CHECK: return
336336
! CHECK: }
337337

338338
! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_dealloc() {
339339
! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
340-
! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {implicit = true, name = "data1", structured = false}
341-
! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
340+
! CHECK: %[[DEVPTR:.*]] = acc.getdeviceptr varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {dataClause = #acc<data_clause acc_create>, implicit = true, name = "data1", structured = false}
341+
! CHECK: acc.declare_exit dataOperands(%[[DEVPTR]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
342342
! CHECK: return
343343
! CHECK: }
344344

0 commit comments

Comments
 (0)