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

via flang-commits flang-commits at lists.llvm.org
Tue Jan 27 01:19:57 PST 2026


https://github.com/jeanPerier updated https://github.com/llvm/llvm-project/pull/177018

>From ab4072e024ca1b78e515e7314c5aa3ade37d98a7 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Tue, 20 Jan 2026 01:50:03 -0800
Subject: [PATCH] [flang][acc] remap variable in device_ptr clauses

---
 flang/lib/Lower/OpenACC.cpp                |  8 +-------
 flang/test/Lower/OpenACC/acc-deviceptr.f90 | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 7 deletions(-)
 create mode 100644 flang/test/Lower/OpenACC/acc-deviceptr.f90

diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index f0f671e8e524d..01e80a9b844fa 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;
 
@@ -2817,12 +2812,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