[flang-commits] [flang] d456e56 - [flang][acc] remap variable in device_ptr clauses (#177018)

via flang-commits flang-commits at lists.llvm.org
Tue Jan 27 06:17:52 PST 2026


Author: jeanPerier
Date: 2026-01-27T15:17:48+01:00
New Revision: d456e56f27814a82ba125499186a30e44517f415

URL: https://github.com/llvm/llvm-project/commit/d456e56f27814a82ba125499186a30e44517f415
DIFF: https://github.com/llvm/llvm-project/commit/d456e56f27814a82ba125499186a30e44517f415.diff

LOG: [flang][acc] remap variable in device_ptr clauses (#177018)

I previously disabled the variable remapping to data operand results in
the IR for the deviceptr clause because it was not clear how fir.box
would be dealt with and the remapping increased the usage of fir.box.
Since then, it was clarified that lowering could use fir.box and that it
would be up to the runtime to deal with the fact that the fir.box is
implemented by a descriptor allocated on the host and containing the
base address of an entity on the device.
Remove the workaround.

Added: 
    flang/test/Lower/OpenACC/acc-deviceptr.f90

Modified: 
    flang/lib/Lower/OpenACC.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 0cbdc52f2500d..183f9e717532a 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -73,11 +73,6 @@ static llvm::cl::opt<bool> enableSymbolRemapping(
     llvm::cl::desc("Whether to remap symbols that appears in data clauses."),
     llvm::cl::init(true));
 
-static llvm::cl::opt<bool> enableDevicePtrRemap(
-    "openacc-remap-device-ptr-symbols",
-    llvm::cl::desc("sub-option of openacc-remap-symbols for deviceptr clause"),
-    llvm::cl::init(false));
-
 // Special value for * passed in device_type or gang clauses.
 static constexpr std::int64_t starCst = -1;
 
@@ -2434,12 +2429,11 @@ static Op createComputeOp(
     } else if (const auto *devicePtrClause =
                    std::get_if<Fortran::parser::AccClause::Deviceptr>(
                        &clause.u)) {
-      AccDataMap *symPairs = enableDevicePtrRemap ? &dataMap : nullptr;
       genDataOperandOperations<mlir::acc::DevicePtrOp>(
           devicePtrClause->v, converter, semanticsContext, stmtCtx,
           dataClauseOperands, mlir::acc::DataClause::acc_deviceptr,
           /*structured=*/true, /*implicit=*/false, async, asyncDeviceTypes,
-          asyncOnlyDeviceTypes, /*setDeclareAttr=*/false, symPairs);
+          asyncOnlyDeviceTypes, /*setDeclareAttr=*/false, &dataMap);
     } else if (const auto *attachClause =
                    std::get_if<Fortran::parser::AccClause::Attach>(&clause.u)) {
       auto crtDataStart = dataClauseOperands.size();

diff  --git a/flang/test/Lower/OpenACC/acc-deviceptr.f90 b/flang/test/Lower/OpenACC/acc-deviceptr.f90
new file mode 100644
index 0000000000000..9d7987208811a
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-deviceptr.f90
@@ -0,0 +1,21 @@
+! Test lowering of deviceptr clause.
+! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
+
+subroutine test (a, b, n)
+   real(8) :: a(:), b(:)
+   !$acc parallel loop deviceptr(a,b)
+   do i = 1,n
+      a(i) = b(i)
+   enddo
+end subroutine
+! CHECK-LABEL:   func.func @_QPtest(
+! CHECK:           %[[DECLARE_0:.*]]:2 = hlfir.declare {{.*}}"_QFtestEa"
+! CHECK:           %[[DECLARE_1:.*]]:2 = hlfir.declare {{.*}}"_QFtestEb"
+! CHECK:           %[[DEVICEPTR_0:.*]] = acc.deviceptr var(%[[DECLARE_0]]#0 : !fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>> {name = "a"}
+! CHECK:           %[[DEVICEPTR_1:.*]] = acc.deviceptr var(%[[DECLARE_1]]#0 : !fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>> {name = "b"}
+! CHECK:           acc.parallel combined(loop) dataOperands(%[[DEVICEPTR_0]], %[[DEVICEPTR_1]] : !fir.box<!fir.array<?xf64>>, !fir.box<!fir.array<?xf64>>) {
+! CHECK:             %[[DECLARE_4:.*]]:2 = hlfir.declare %[[DEVICEPTR_0]]
+! CHECK:             %[[DECLARE_5:.*]]:2 = hlfir.declare %[[DEVICEPTR_1]]
+! CHECK:             acc.loop combined(parallel)
+! CHECK:               hlfir.designate %[[DECLARE_5]]#0
+! CHECK:               hlfir.designate %[[DECLARE_4]]#0


        


More information about the flang-commits mailing list