From 14d9e99a1be08d811ea6c720950c73e4c7bc0f39 Mon Sep 17 00:00:00 2001 From: Susan Tan Date: Tue, 9 Sep 2025 15:29:09 -0700 Subject: [PATCH 1/6] change recipe --- flang/lib/Lower/OpenACC.cpp | 56 +++++++++---------- .../acc-declare-unwrap-defaultbounds.f90 | 14 ++--- flang/test/Lower/OpenACC/acc-declare.f90 | 14 ++--- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index bbe749f8c8805..8aa40f84c474f 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -244,17 +244,16 @@ static void createDeclareAllocFuncWithArg(mlir::OpBuilder &modBuilder, if (unwrapFirBox) asFortranDesc << accFirDescriptorPostfix.str(); - // Updating descriptor must occur before the mapping of the data so that - // attached data pointer is not overwritten. - mlir::acc::UpdateDeviceOp updateDeviceOp = - createDataEntryOp( - builder, loc, registerFuncOp.getArgument(0), asFortranDesc, bounds, - /*structured=*/false, /*implicit=*/true, - mlir::acc::DataClause::acc_update_device, descTy, - /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - llvm::SmallVector operandSegments{0, 0, 0, 1}; - llvm::SmallVector operands{updateDeviceOp.getResult()}; - createSimpleOp(builder, loc, operands, operandSegments); + // Use declare_enter for the descriptor so the runtime mirrors allocation + // semantics instead of issuing an update. This ensures the descriptor's + // device-side metadata is established via a structured begin. + EntryOp descEntryOp = createDataEntryOp( + builder, loc, registerFuncOp.getArgument(0), asFortranDesc, bounds, + /*structured=*/false, /*implicit=*/true, clause, descTy, + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + mlir::acc::DeclareEnterOp::create( + builder, loc, mlir::acc::DeclareTokenType::get(descEntryOp.getContext()), + mlir::ValueRange(descEntryOp.getAccVar())); if (unwrapFirBox) { mlir::Value desc = @@ -3989,17 +3988,16 @@ static void createDeclareAllocFunc(mlir::OpBuilder &modBuilder, asFortranDesc << accFirDescriptorPostfix.str(); llvm::SmallVector bounds; - // Updating descriptor must occur before the mapping of the data so that - // attached data pointer is not overwritten. - mlir::acc::UpdateDeviceOp updateDeviceOp = - createDataEntryOp( - builder, loc, addrOp, asFortranDesc, bounds, - /*structured=*/false, /*implicit=*/true, - mlir::acc::DataClause::acc_update_device, addrOp.getType(), - /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - llvm::SmallVector operandSegments{0, 0, 0, 1}; - llvm::SmallVector operands{updateDeviceOp.getResult()}; - createSimpleOp(builder, loc, operands, operandSegments); + // Use declare_enter for the descriptor so the runtime mirrors allocation + // semantics instead of issuing an update. This ensures the descriptor's + // device-side metadata is established via a structured begin. + EntryOp descEntryOp = createDataEntryOp( + builder, loc, addrOp, asFortranDesc, bounds, + /*structured=*/false, /*implicit=*/true, clause, addrOp.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + mlir::acc::DeclareEnterOp::create( + builder, loc, mlir::acc::DeclareTokenType::get(descEntryOp.getContext()), + mlir::ValueRange(descEntryOp.getAccVar())); if (unwrapFirBox) { auto loadOp = fir::LoadOp::create(builder, loc, addrOp.getResult()); @@ -4092,15 +4090,15 @@ static void createDeclareDeallocFunc(mlir::OpBuilder &modBuilder, if (unwrapFirBox) asFortran << accFirDescriptorPostfix.str(); llvm::SmallVector bounds; - mlir::acc::UpdateDeviceOp updateDeviceOp = - createDataEntryOp( + // Use declare_exit for the descriptor to end the structured declare region + // instead of issuing an update. + mlir::acc::GetDevicePtrOp descEntryOp = + createDataEntryOp( builder, loc, addrOp, asFortran, bounds, - /*structured=*/false, /*implicit=*/true, - mlir::acc::DataClause::acc_update_device, addrOp.getType(), + /*structured=*/false, /*implicit=*/true, clause, addrOp.getType(), /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - llvm::SmallVector operandSegments{0, 0, 0, 1}; - llvm::SmallVector operands{updateDeviceOp.getResult()}; - createSimpleOp(builder, loc, operands, operandSegments); + mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(descEntryOp.getAccVar())); modBuilder.setInsertionPointAfter(postDeallocOp); } diff --git a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 index 6869af863644d..f9a8f7bf0469b 100644 --- a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 +++ b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 @@ -1,8 +1,8 @@ ! This test checks lowering of OpenACC declare directive in function and ! subroutine specification parts. - ! RUN: bbc -fopenacc -emit-hlfir --openacc-unwrap-fir-box=true --openacc-generate-default-bounds=true %s -o - | FileCheck %s + module acc_declare contains @@ -258,8 +258,6 @@ subroutine acc_declare_allocate() ! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_alloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "a_desc", structured = false} -! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) ! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref>>> ! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] {acc.declare = #acc.declare} : (!fir.box>>) -> !fir.heap> ! CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[BOX_ADDR]] : !fir.heap>) -> !fir.heap> {name = "a", structured = false} @@ -281,7 +279,7 @@ subroutine acc_declare_allocate() ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { ! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref>>> ! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box>>) -> !fir.heap> -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[BOX_ADDR]] : !fir.heap>) -> !fir.heap> {implicit = true, name = "a_desc", structured = false} +! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[BOX_ADDR]] : !fir.heap>) -> !fir.heap> ! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.heap>) ! CHECK: return ! CHECK: } @@ -355,8 +353,8 @@ module acc_declare_allocatable_test ! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_alloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1_desc", structured = false} -! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) +! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1_desc", structured = false} +! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref>>>) ! CHECK: %[[LOAD:.*]] = fir.load %[[GLOBAL_ADDR]] : !fir.ref>>> ! CHECK: %[[BOXADDR:.*]] = fir.box_addr %[[LOAD]] {acc.declare = #acc.declare} : (!fir.box>>) -> !fir.heap> ! CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[BOXADDR]] : !fir.heap>) -> !fir.heap> {name = "data1", structured = false} @@ -376,8 +374,8 @@ module acc_declare_allocatable_test ! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_dealloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1_desc", structured = false} -! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) +! CHECK: %[[DEVPTR:.*]] = acc.getdeviceptr varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {dataClause = #acc, implicit = true, name = "data1_desc", structured = false} +! CHECK: acc.declare_exit dataOperands(%[[DEVPTR]] : !fir.ref>>>) ! CHECK: return ! CHECK: } diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90 index 4d95ffa10edaf..3b17dee796619 100644 --- a/flang/test/Lower/OpenACC/acc-declare.f90 +++ b/flang/test/Lower/OpenACC/acc-declare.f90 @@ -1,8 +1,8 @@ ! This test checks lowering of OpenACC declare directive in function and ! subroutine specification parts. - ! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s + module acc_declare contains @@ -250,8 +250,8 @@ subroutine acc_declare_allocate() ! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_alloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "a", structured = false} -! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) +! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "a", structured = false} +! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref>>>) ! CHECK: return ! CHECK: } @@ -330,15 +330,15 @@ module acc_declare_allocatable_test ! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_alloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1", structured = false} -! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) +! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1", structured = false} +! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref>>>) ! CHECK: return ! CHECK: } ! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_dealloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1", structured = false} -! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) +! CHECK: %[[DEVPTR:.*]] = acc.getdeviceptr varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {dataClause = #acc, implicit = true, name = "data1", structured = false} +! CHECK: acc.declare_exit dataOperands(%[[DEVPTR]] : !fir.ref>>>) ! CHECK: return ! CHECK: } From 153e1f152f4f7a1fffd37cd518cda1cc983ce5f9 Mon Sep 17 00:00:00 2001 From: Susan Tan Date: Tue, 9 Sep 2025 15:50:55 -0700 Subject: [PATCH 2/6] add dealloc change --- flang/lib/Lower/OpenACC.cpp | 14 +++++++------- .../OpenACC/acc-declare-unwrap-defaultbounds.f90 | 4 ++-- flang/test/Lower/OpenACC/acc-declare.f90 | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 8aa40f84c474f..1e687d6eb788a 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -337,15 +337,15 @@ static void createDeclareDeallocFuncWithArg( asFortran << accFirDescriptorPostfix.str(); } - mlir::acc::UpdateDeviceOp updateDeviceOp = - createDataEntryOp( + // End the structured declare region for the descriptor or its payload + // using declare_exit instead of issuing an update. + mlir::acc::GetDevicePtrOp postEntryOp = + createDataEntryOp( builder, loc, var, asFortran, bounds, - /*structured=*/false, /*implicit=*/true, - mlir::acc::DataClause::acc_update_device, var.getType(), + /*structured=*/false, /*implicit=*/true, clause, var.getType(), /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - llvm::SmallVector operandSegments{0, 0, 0, 1}; - llvm::SmallVector operands{updateDeviceOp.getResult()}; - createSimpleOp(builder, loc, operands, operandSegments); + mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(postEntryOp.getAccVar())); modBuilder.setInsertionPointAfter(postDeallocOp); builder.restoreInsertionPoint(crtInsPt); } diff --git a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 index f9a8f7bf0469b..8ccaae829dfdf 100644 --- a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 +++ b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 @@ -279,8 +279,8 @@ subroutine acc_declare_allocate() ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { ! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref>>> ! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box>>) -> !fir.heap> -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[BOX_ADDR]] : !fir.heap>) -> !fir.heap> -! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.heap>) +! CHECK: %[[GETDEVICEPTR:.*]] = acc.getdeviceptr varPtr(%[[BOX_ADDR]] : !fir.heap>) -> !fir.heap> {dataClause = #acc, implicit = true, name = "a_desc", structured = false} +! CHECK: acc.declare_exit dataOperands(%[[GETDEVICEPTR]] : !fir.heap>) ! CHECK: return ! CHECK: } diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90 index 3b17dee796619..5a8ab7ed00fe8 100644 --- a/flang/test/Lower/OpenACC/acc-declare.f90 +++ b/flang/test/Lower/OpenACC/acc-declare.f90 @@ -257,8 +257,8 @@ subroutine acc_declare_allocate() ! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_dealloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { -! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "a", structured = false} -! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) +! CHECK: %[[DEVPTR:.*]] = acc.getdeviceptr varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {dataClause = #acc, implicit = true, name = "a", structured = false} +! CHECK: acc.declare_exit dataOperands(%[[DEVPTR]] : !fir.ref>>>) ! CHECK: return ! CHECK: } From 46c9a8ce0f3157e9cb3bccb60d2196bc354c8a07 Mon Sep 17 00:00:00 2001 From: Susan Tan Date: Tue, 9 Sep 2025 16:50:16 -0700 Subject: [PATCH 3/6] preserve unwrap --- flang/lib/Lower/OpenACC.cpp | 202 ++++++++++++------ .../acc-declare-unwrap-defaultbounds.f90 | 18 +- 2 files changed, 150 insertions(+), 70 deletions(-) diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 1e687d6eb788a..1fbd1b31a8db7 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -244,16 +244,29 @@ static void createDeclareAllocFuncWithArg(mlir::OpBuilder &modBuilder, if (unwrapFirBox) asFortranDesc << accFirDescriptorPostfix.str(); - // Use declare_enter for the descriptor so the runtime mirrors allocation - // semantics instead of issuing an update. This ensures the descriptor's - // device-side metadata is established via a structured begin. - EntryOp descEntryOp = createDataEntryOp( - builder, loc, registerFuncOp.getArgument(0), asFortranDesc, bounds, - /*structured=*/false, /*implicit=*/true, clause, descTy, - /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - mlir::acc::DeclareEnterOp::create( - builder, loc, mlir::acc::DeclareTokenType::get(descEntryOp.getContext()), - mlir::ValueRange(descEntryOp.getAccVar())); + // For descriptor, preserve old behavior when unwrapping FIR box: update. + if (unwrapFirBox) { + mlir::acc::UpdateDeviceOp updateDeviceOp = + createDataEntryOp( + builder, loc, registerFuncOp.getArgument(0), asFortranDesc, bounds, + /*structured=*/false, /*implicit=*/true, + mlir::acc::DataClause::acc_update_device, descTy, + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + llvm::SmallVector operandSegments{0, 0, 0, 1}; + llvm::SmallVector operands{updateDeviceOp.getResult()}; + createSimpleOp(builder, loc, operands, + operandSegments); + } else { + // New behavior: start a structured region with declare_enter. + EntryOp descEntryOp = createDataEntryOp( + builder, loc, registerFuncOp.getArgument(0), asFortranDesc, bounds, + /*structured=*/false, /*implicit=*/true, clause, descTy, + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + mlir::acc::DeclareEnterOp::create( + builder, loc, + mlir::acc::DeclareTokenType::get(descEntryOp.getContext()), + mlir::ValueRange(descEntryOp.getAccVar())); + } if (unwrapFirBox) { mlir::Value desc = @@ -298,30 +311,58 @@ static void createDeclareDeallocFuncWithArg( } llvm::SmallVector bounds; - mlir::acc::GetDevicePtrOp entryOp = - createDataEntryOp( - builder, loc, var, asFortran, bounds, - /*structured=*/false, /*implicit=*/false, clause, var.getType(), - /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, - mlir::ValueRange(entryOp.getAccVar())); - - if constexpr (std::is_same_v || - std::is_same_v) - ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), - entryOp.getVar(), entryOp.getVarType(), entryOp.getBounds(), - entryOp.getAsyncOperands(), - entryOp.getAsyncOperandsDeviceTypeAttr(), - entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), - /*structured=*/false, /*implicit=*/false, - builder.getStringAttr(*entryOp.getName())); - else - ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), - entryOp.getBounds(), entryOp.getAsyncOperands(), - entryOp.getAsyncOperandsDeviceTypeAttr(), - entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), - /*structured=*/false, /*implicit=*/false, - builder.getStringAttr(*entryOp.getName())); + if (unwrapFirBox) { + // Unwrap: delete device payload using getdeviceptr + declare_exit + ExitOp + mlir::acc::GetDevicePtrOp entryOp = + createDataEntryOp( + builder, loc, var, asFortran, bounds, + /*structured=*/false, /*implicit=*/false, clause, var.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(entryOp.getAccVar())); + + if constexpr (std::is_same_v || + std::is_same_v) + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getVar(), entryOp.getVarType(), + entryOp.getBounds(), entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); + else + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getBounds(), entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); + } else { + mlir::acc::GetDevicePtrOp entryOp = + createDataEntryOp( + builder, loc, var, asFortran, bounds, + /*structured=*/false, /*implicit=*/false, clause, var.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(entryOp.getAccVar())); + + if constexpr (std::is_same_v || + std::is_same_v) + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getVar(), entryOp.getVarType(), + entryOp.getBounds(), entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); + else + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getBounds(), entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); + } // Generate the post dealloc function. modBuilder.setInsertionPointAfter(preDeallocOp); @@ -337,15 +378,28 @@ static void createDeclareDeallocFuncWithArg( asFortran << accFirDescriptorPostfix.str(); } - // End the structured declare region for the descriptor or its payload - // using declare_exit instead of issuing an update. - mlir::acc::GetDevicePtrOp postEntryOp = - createDataEntryOp( - builder, loc, var, asFortran, bounds, - /*structured=*/false, /*implicit=*/true, clause, var.getType(), - /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, - mlir::ValueRange(postEntryOp.getAccVar())); + if (unwrapFirBox) { + // Old behavior: update descriptor after deallocation. + mlir::acc::UpdateDeviceOp updateDeviceOp = + createDataEntryOp( + builder, loc, var, asFortran, bounds, + /*structured=*/false, /*implicit=*/true, + mlir::acc::DataClause::acc_update_device, var.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + llvm::SmallVector operandSegments{0, 0, 0, 1}; + llvm::SmallVector operands{updateDeviceOp.getResult()}; + createSimpleOp(builder, loc, operands, + operandSegments); + } else { + // New behavior: end structured region with declare_exit. + mlir::acc::GetDevicePtrOp postEntryOp = + createDataEntryOp( + builder, loc, var, asFortran, bounds, + /*structured=*/false, /*implicit=*/true, clause, var.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(postEntryOp.getAccVar())); + } modBuilder.setInsertionPointAfter(postDeallocOp); builder.restoreInsertionPoint(crtInsPt); } @@ -3988,16 +4042,28 @@ static void createDeclareAllocFunc(mlir::OpBuilder &modBuilder, asFortranDesc << accFirDescriptorPostfix.str(); llvm::SmallVector bounds; - // Use declare_enter for the descriptor so the runtime mirrors allocation - // semantics instead of issuing an update. This ensures the descriptor's - // device-side metadata is established via a structured begin. - EntryOp descEntryOp = createDataEntryOp( - builder, loc, addrOp, asFortranDesc, bounds, - /*structured=*/false, /*implicit=*/true, clause, addrOp.getType(), - /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - mlir::acc::DeclareEnterOp::create( - builder, loc, mlir::acc::DeclareTokenType::get(descEntryOp.getContext()), - mlir::ValueRange(descEntryOp.getAccVar())); + // For unwrapFirBox=false this remains declare_enter; for unwrapFirBox=true, + // the descriptor post-alloc remains update behavior. + if (unwrapFirBox) { + mlir::acc::UpdateDeviceOp updDesc = + createDataEntryOp( + builder, loc, addrOp, asFortranDesc, bounds, + /*structured=*/false, /*implicit=*/true, + mlir::acc::DataClause::acc_update_device, addrOp.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + llvm::SmallVector seg{0, 0, 0, 1}; + llvm::SmallVector ops{updDesc.getResult()}; + createSimpleOp(builder, loc, ops, seg); + } else { + EntryOp descEntryOp = createDataEntryOp( + builder, loc, addrOp, asFortranDesc, bounds, + /*structured=*/false, /*implicit=*/true, clause, addrOp.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + mlir::acc::DeclareEnterOp::create( + builder, loc, + mlir::acc::DeclareTokenType::get(descEntryOp.getContext()), + mlir::ValueRange(descEntryOp.getAccVar())); + } if (unwrapFirBox) { auto loadOp = fir::LoadOp::create(builder, loc, addrOp.getResult()); @@ -4090,15 +4156,27 @@ static void createDeclareDeallocFunc(mlir::OpBuilder &modBuilder, if (unwrapFirBox) asFortran << accFirDescriptorPostfix.str(); llvm::SmallVector bounds; - // Use declare_exit for the descriptor to end the structured declare region - // instead of issuing an update. - mlir::acc::GetDevicePtrOp descEntryOp = - createDataEntryOp( - builder, loc, addrOp, asFortran, bounds, - /*structured=*/false, /*implicit=*/true, clause, addrOp.getType(), - /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, - mlir::ValueRange(descEntryOp.getAccVar())); + if (unwrapFirBox) { + // Unwrap mode: update the descriptor after deallocation (no declare_exit). + mlir::acc::UpdateDeviceOp updDesc = + createDataEntryOp( + builder, loc, addrOp, asFortran, bounds, + /*structured=*/false, /*implicit=*/true, + mlir::acc::DataClause::acc_update_device, addrOp.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + llvm::SmallVector seg{0, 0, 0, 1}; + llvm::SmallVector ops{updDesc.getResult()}; + createSimpleOp(builder, loc, ops, seg); + } else { + // Default: end the structured declare region using declare_exit. + mlir::acc::GetDevicePtrOp descEntryOp = + createDataEntryOp( + builder, loc, addrOp, asFortran, bounds, + /*structured=*/false, /*implicit=*/true, clause, addrOp.getType(), + /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); + mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(descEntryOp.getAccVar())); + } modBuilder.setInsertionPointAfter(postDeallocOp); } diff --git a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 index 8ccaae829dfdf..19566b31af108 100644 --- a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 +++ b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 @@ -1,7 +1,7 @@ ! This test checks lowering of OpenACC declare directive in function and ! subroutine specification parts. -! RUN: bbc -fopenacc -emit-hlfir --openacc-unwrap-fir-box=true --openacc-generate-default-bounds=true %s -o - | FileCheck %s +! RUN: bbc -fopenacc -emit-hlfir --openacc-unwrap-fir-box=true --openacc-generate-default-bounds=true %s -o - | FileCheck %s module acc_declare contains @@ -258,6 +258,8 @@ subroutine acc_declare_allocate() ! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_alloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { +! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "a_desc", structured = false} +! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) ! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref>>> ! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] {acc.declare = #acc.declare} : (!fir.box>>) -> !fir.heap> ! CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[BOX_ADDR]] : !fir.heap>) -> !fir.heap> {name = "a", structured = false} @@ -279,8 +281,8 @@ subroutine acc_declare_allocate() ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { ! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref>>> ! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box>>) -> !fir.heap> -! CHECK: %[[GETDEVICEPTR:.*]] = acc.getdeviceptr varPtr(%[[BOX_ADDR]] : !fir.heap>) -> !fir.heap> {dataClause = #acc, implicit = true, name = "a_desc", structured = false} -! CHECK: acc.declare_exit dataOperands(%[[GETDEVICEPTR]] : !fir.heap>) +! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[BOX_ADDR]] : !fir.heap>) -> !fir.heap> {implicit = true, name = "a_desc", structured = false} +! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.heap>) ! CHECK: return ! CHECK: } @@ -353,8 +355,8 @@ module acc_declare_allocatable_test ! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_alloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> -! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1_desc", structured = false} -! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref>>>) +! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1_desc", structured = false} +! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) ! CHECK: %[[LOAD:.*]] = fir.load %[[GLOBAL_ADDR]] : !fir.ref>>> ! CHECK: %[[BOXADDR:.*]] = fir.box_addr %[[LOAD]] {acc.declare = #acc.declare} : (!fir.box>>) -> !fir.heap> ! CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[BOXADDR]] : !fir.heap>) -> !fir.heap> {name = "data1", structured = false} @@ -374,8 +376,8 @@ module acc_declare_allocatable_test ! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_dealloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> -! CHECK: %[[DEVPTR:.*]] = acc.getdeviceptr varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {dataClause = #acc, implicit = true, name = "data1_desc", structured = false} -! CHECK: acc.declare_exit dataOperands(%[[DEVPTR]] : !fir.ref>>>) +! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1_desc", structured = false} +! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) ! CHECK: return ! CHECK: } @@ -473,4 +475,4 @@ subroutine init() ! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit() ! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 ! CHECK: fir.if -! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 +! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 \ No newline at end of file From ce9550b8acf88c24ed1234211bf21b06d396ef2c Mon Sep 17 00:00:00 2001 From: Susan Tan Date: Tue, 9 Sep 2025 16:54:44 -0700 Subject: [PATCH 4/6] restore one test --- flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 index 19566b31af108..6869af863644d 100644 --- a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 +++ b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 @@ -475,4 +475,4 @@ subroutine init() ! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit() ! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 ! CHECK: fir.if -! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 \ No newline at end of file +! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 From a86ac0f289546af696ea601b65f62e4c799fcdcf Mon Sep 17 00:00:00 2001 From: Susan Tan Date: Tue, 9 Sep 2025 16:55:19 -0700 Subject: [PATCH 5/6] clean up --- flang/test/Lower/OpenACC/acc-declare.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90 index 5a8ab7ed00fe8..8d808e811f769 100644 --- a/flang/test/Lower/OpenACC/acc-declare.f90 +++ b/flang/test/Lower/OpenACC/acc-declare.f90 @@ -1,7 +1,7 @@ ! This test checks lowering of OpenACC declare directive in function and ! subroutine specification parts. -! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s +! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s module acc_declare contains From 8ac5725b2173d2b1abf9e6ee73fbf2c3d0192553 Mon Sep 17 00:00:00 2001 From: Susan Tan Date: Mon, 15 Sep 2025 11:36:07 -0700 Subject: [PATCH 6/6] change name --- flang/include/flang/Lower/OpenACC.h | 6 ++-- .../acc-declare-unwrap-defaultbounds.f90 | 34 +++++++++---------- flang/test/Lower/OpenACC/acc-declare.f90 | 30 ++++++++-------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/flang/include/flang/Lower/OpenACC.h b/flang/include/flang/Lower/OpenACC.h index e974f3d6eef11..19d759479abaf 100644 --- a/flang/include/flang/Lower/OpenACC.h +++ b/flang/include/flang/Lower/OpenACC.h @@ -66,11 +66,11 @@ struct Evaluation; } // namespace pft static constexpr llvm::StringRef declarePostAllocSuffix = - "_acc_declare_update_desc_post_alloc"; + "_acc_declare_post_alloc"; static constexpr llvm::StringRef declarePreDeallocSuffix = - "_acc_declare_update_desc_pre_dealloc"; + "_acc_declare_pre_dealloc"; static constexpr llvm::StringRef declarePostDeallocSuffix = - "_acc_declare_update_desc_post_dealloc"; + "_acc_declare_post_dealloc"; static constexpr llvm::StringRef privatizationRecipePrefix = "privatization"; diff --git a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 index 6869af863644d..4b181f8a26987 100644 --- a/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 +++ b/flang/test/Lower/OpenACC/acc-declare-unwrap-defaultbounds.f90 @@ -240,23 +240,23 @@ subroutine acc_declare_allocate() allocate(a(100)) ! CHECK: %{{.*}} = fir.allocmem !fir.array, %{{.*}} {fir.must_be_heap = true, uniq_name = "_QMacc_declareFacc_declare_allocateEa.alloc"} -! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> deallocate(a) -! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action} : (!fir.box>>) -> !fir.heap> +! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action} : (!fir.box>>) -> !fir.heap> ! CHECK: fir.freemem %{{.*}} : !fir.heap> -! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> ! CHECK: fir.if ! CHECK: fir.freemem %{{.*}} : !fir.heap> -! CHECK: fir.store %{{.*}} to %{{.*}}#0 {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: fir.store %{{.*}} to %{{.*}}#0 {acc.declare_action = #acc.declare_action} : !fir.ref>>> ! CHECK: } end subroutine -! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_alloc( +! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_post_alloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { ! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "a_desc", structured = false} ! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) @@ -267,7 +267,7 @@ subroutine acc_declare_allocate() ! CHECK: return ! CHECK: } -! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_pre_dealloc( +! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_pre_dealloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { ! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref>>> ! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] {acc.declare = #acc.declare} : (!fir.box>>) -> !fir.heap> @@ -277,7 +277,7 @@ subroutine acc_declare_allocate() ! CHECK: return ! CHECK: } -! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_dealloc( +! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_post_dealloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { ! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref>>> ! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box>>) -> !fir.heap> @@ -337,8 +337,8 @@ subroutine acc_declare_allocate_with_stat() end subroutine ! CHECK-LABEL: func.func @_QMacc_declarePacc_declare_allocate_with_stat() -! CHECK: fir.call @_FortranAPointerAllocate(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} {acc.declare_action = #acc.declare_action} -! CHECK: fir.call @_FortranAPointerDeallocate(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} {acc.declare_action = #acc.declare_action} +! CHECK: fir.call @_FortranAPointerAllocate(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} {acc.declare_action = #acc.declare_action} +! CHECK: fir.call @_FortranAPointerDeallocate(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} {acc.declare_action = #acc.declare_action} end module module acc_declare_allocatable_test @@ -353,7 +353,7 @@ module acc_declare_allocatable_test ! CHECK: acc.terminator ! CHECK: } -! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_alloc() { +! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_post_alloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> ! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1_desc", structured = false} ! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) @@ -364,7 +364,7 @@ module acc_declare_allocatable_test ! CHECK: return ! CHECK: } -! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_pre_dealloc() { +! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_pre_dealloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> ! CHECK: %[[LOAD:.*]] = fir.load %[[GLOBAL_ADDR]] : !fir.ref>>> ! CHECK: %[[BOXADDR:.*]] = fir.box_addr %[[LOAD]] {acc.declare = #acc.declare} : (!fir.box>>) -> !fir.heap> @@ -374,7 +374,7 @@ module acc_declare_allocatable_test ! CHECK: return ! CHECK: } -! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_dealloc() { +! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_post_dealloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> ! CHECK: %[[UPDATE:.*]] = acc.update_device varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1_desc", structured = false} ! CHECK: acc.update dataOperands(%[[UPDATE]] : !fir.ref>>>) @@ -440,14 +440,14 @@ module acc_declare_allocatable_test2 subroutine init() use acc_declare_allocatable_test allocate(data1(100)) -! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> end subroutine subroutine finalize() use acc_declare_allocatable_test deallocate(data1) -! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action} : (!fir.box>>) -> !fir.heap> -! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action} : (!fir.box>>) -> !fir.heap> +! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> end subroutine end module @@ -473,6 +473,6 @@ subroutine init() end module ! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit() -! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 +! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 ! CHECK: fir.if -! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 +! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90 index 8d808e811f769..edae0e6a4d37e 100644 --- a/flang/test/Lower/OpenACC/acc-declare.f90 +++ b/flang/test/Lower/OpenACC/acc-declare.f90 @@ -232,30 +232,30 @@ subroutine acc_declare_allocate() allocate(a(100)) ! CHECK: %{{.*}} = fir.allocmem !fir.array, %{{.*}} {fir.must_be_heap = true, uniq_name = "_QMacc_declareFacc_declare_allocateEa.alloc"} -! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> deallocate(a) -! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action} : (!fir.box>>) -> !fir.heap> +! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action} : (!fir.box>>) -> !fir.heap> ! CHECK: fir.freemem %{{.*}} : !fir.heap> -! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> ! CHECK: fir.if ! CHECK: fir.freemem %{{.*}} : !fir.heap> -! CHECK: fir.store %{{.*}} to %{{.*}}#0 {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: fir.store %{{.*}} to %{{.*}}#0 {acc.declare_action = #acc.declare_action} : !fir.ref>>> ! CHECK: } end subroutine -! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_alloc( +! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_post_alloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { ! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "a", structured = false} ! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref>>>) ! CHECK: return ! CHECK: } -! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_update_desc_post_dealloc( +! CHECK-LABEL: func.func private @_QMacc_declareFacc_declare_allocateEa_acc_declare_post_dealloc( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>>) { ! CHECK: %[[DEVPTR:.*]] = acc.getdeviceptr varPtr(%[[ARG0]] : !fir.ref>>>) -> !fir.ref>>> {dataClause = #acc, implicit = true, name = "a", structured = false} ! CHECK: acc.declare_exit dataOperands(%[[DEVPTR]] : !fir.ref>>>) @@ -312,8 +312,8 @@ subroutine acc_declare_allocate_with_stat() end subroutine ! CHECK-LABEL: func.func @_QMacc_declarePacc_declare_allocate_with_stat() -! CHECK: fir.call @_FortranAPointerAllocate(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} {acc.declare_action = #acc.declare_action} -! CHECK: fir.call @_FortranAPointerDeallocate(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} {acc.declare_action = #acc.declare_action} +! CHECK: fir.call @_FortranAPointerAllocate(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} {acc.declare_action = #acc.declare_action} +! CHECK: fir.call @_FortranAPointerDeallocate(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} {acc.declare_action = #acc.declare_action} end module module acc_declare_allocatable_test @@ -328,14 +328,14 @@ module acc_declare_allocatable_test ! CHECK: acc.terminator ! CHECK: } -! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_alloc() { +! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_post_alloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> ! CHECK: %[[CREATE_DESC:.*]] = acc.create varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {implicit = true, name = "data1", structured = false} ! CHECK: acc.declare_enter dataOperands(%[[CREATE_DESC]] : !fir.ref>>>) ! CHECK: return ! CHECK: } -! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_update_desc_post_dealloc() { +! CHECK-LABEL: func.func private @_QMacc_declare_allocatable_testEdata1_acc_declare_post_dealloc() { ! CHECK: %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) : !fir.ref>>> ! CHECK: %[[DEVPTR:.*]] = acc.getdeviceptr varPtr(%[[GLOBAL_ADDR]] : !fir.ref>>>) -> !fir.ref>>> {dataClause = #acc, implicit = true, name = "data1", structured = false} ! CHECK: acc.declare_exit dataOperands(%[[DEVPTR]] : !fir.ref>>>) @@ -401,14 +401,14 @@ module acc_declare_allocatable_test2 subroutine init() use acc_declare_allocatable_test allocate(data1(100)) -! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> end subroutine subroutine finalize() use acc_declare_allocatable_test deallocate(data1) -! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action} : (!fir.box>>) -> !fir.heap> -! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> +! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action} : (!fir.box>>) -> !fir.heap> +! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action} : !fir.ref>>> end subroutine end module @@ -434,6 +434,6 @@ subroutine init() end module ! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit() -! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 +! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 ! CHECK: fir.if -! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 +! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath {acc.declare_action = #acc.declare_action} : (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32