[flang-commits] [flang] f865620 - [flang][cuda] Do not lower device target in porgram as global (#120126)

via flang-commits flang-commits at lists.llvm.org
Mon Dec 16 12:34:05 PST 2024


Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-12-16T12:34:01-08:00
New Revision: f8656204d7ce2fd97c15ffa134212e0e3dc5f662

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

LOG: [flang][cuda] Do not lower device target in porgram as global (#120126)

As it was done in #102512, do not create global for arrays declared in
program unit with cuda data attribute.

Added: 
    

Modified: 
    flang/lib/Evaluate/tools.cpp
    flang/test/Lower/CUDA/cuda-program-global.cuf

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index a040f7ce79dc10..cb6c821433b52d 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1719,7 +1719,8 @@ bool IsSaved(const Symbol &original) {
     return false;
   } else if (scopeKind == Scope::Kind::Module ||
       (scopeKind == Scope::Kind::MainProgram &&
-          (symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)))) {
+          (symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)) &&
+          Fortran::evaluate::CanCUDASymbolHaveSaveAttr(symbol))) {
     // 8.5.16p4
     // In main programs, implied SAVE matters only for pointer
     // initialization targets and coarrays.

diff  --git a/flang/test/Lower/CUDA/cuda-program-global.cuf b/flang/test/Lower/CUDA/cuda-program-global.cuf
index 90b401c9ba6a5c..a21fc06537f75d 100644
--- a/flang/test/Lower/CUDA/cuda-program-global.cuf
+++ b/flang/test/Lower/CUDA/cuda-program-global.cuf
@@ -7,6 +7,7 @@ program test
   integer, device :: a(10)
   integer, unified :: u(10)
   integer, allocatable, pinned :: p(:)
+  real, device, target :: t(10)
   integer :: b(10)
   integer :: i
   print*,i
@@ -18,6 +19,7 @@ end
 ! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
 ! CHECK: hlfir.declare %[[ALLOCA]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
 ! CHECK: cuf.alloc !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = "p", data_attr = #cuf.cuda<pinned>, uniq_name = "_QFEp"} -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
+! CHECK: cuf.alloc !fir.array<10xf32> {bindc_name = "t", data_attr = #cuf.cuda<device>, uniq_name = "_QFEt"} -> !fir.ref<!fir.array<10xf32>>
 
 ! CHECK-NOT: fir.global internal @_QFEa {data_attr = #cuf.cuda<device>} : !fir.array<10xi32> {{{$}}
 ! CHECK: fir.global internal @_QFEb : !fir.array<10xi32> {{{$}}


        


More information about the flang-commits mailing list