[flang-commits] [flang] [flang][cuda] Add data attribute to program globals (PR #92610)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Fri May 17 14:57:15 PDT 2024
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/92610
Make sure the local variable in `PROGRAM` unit that are promoted as global keep their CUDA data attribute.
>From e36556f744acc258f1dd9019011dd471854b8d20 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 17 May 2024 14:55:52 -0700
Subject: [PATCH] [flang][cuda] Add data attribute to program globals
---
flang/lib/Lower/ConvertVariable.cpp | 5 ++++-
flang/test/Lower/CUDA/cuda-program-global.cuf | 19 +++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Lower/CUDA/cuda-program-global.cuf
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index b8868161fa050..075d0634fd1ee 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -656,7 +656,10 @@ static void instantiateGlobal(Fortran::lower::AbstractConverter &converter,
// Emit only a declaration if the global does not exist.
global = declareGlobal(converter, var, globalName, linkage);
} else {
- global = defineGlobal(converter, var, globalName, linkage);
+ cuf::DataAttributeAttr dataAttr =
+ Fortran::lower::translateSymbolCUFDataAttribute(builder.getContext(),
+ sym);
+ global = defineGlobal(converter, var, globalName, linkage, dataAttr);
}
auto addrOf = builder.create<fir::AddrOfOp>(loc, global.resultType(),
global.getSymbol());
diff --git a/flang/test/Lower/CUDA/cuda-program-global.cuf b/flang/test/Lower/CUDA/cuda-program-global.cuf
new file mode 100644
index 0000000000000..97b9927b3082f
--- /dev/null
+++ b/flang/test/Lower/CUDA/cuda-program-global.cuf
@@ -0,0 +1,19 @@
+! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
+
+! Test lowering of program local variable that are global
+
+program test
+ integer, device :: a(10)
+ integer :: b(10)
+ integer :: i
+ print*,i
+end
+
+! CHECK-LABEL: func.func @_QQmain()
+! CHECK: fir.address_of(@_QFEa) : !fir.ref<!fir.array<10xi32>>
+! CHECK: fir.address_of(@_QFEb) : !fir.ref<!fir.array<10xi32>>
+! 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: 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