Skip to content

Commit 2fc7512

Browse files
committed
[flang][cuda] Set address space for constant variables
1 parent 2424118 commit 2fc7512

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3231,7 +3231,8 @@ struct GlobalOpConversion : public fir::FIROpConversion<fir::GlobalOp> {
32313231

32323232
if (global.getDataAttr() &&
32333233
*global.getDataAttr() == cuf::DataAttribute::Constant)
3234-
TODO(global.getLoc(), "CUDA Fortran CONSTANT variable code generation");
3234+
g.setAddrSpace(
3235+
static_cast<unsigned>(mlir::NVVM::NVVMMemorySpace::Constant));
32353236

32363237
rewriter.eraseOp(global);
32373238
return mlir::success();

flang/test/Fir/CUDA/cuda-code-gen.mlir

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,22 @@ module attributes {gpu.container_module, dlti.dl_spec = #dlti.dl_spec<#dlti.dl_e
284284
// CHECK-LABEL: llvm.func @_QQxxx()
285285
// CHECK: llvm.alloca %{{.*}} x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<2 x array<3 x i64>>)> {alignment = 8 : i64} : (i32) -> !llvm.ptr
286286
// CHECK-NOT: llvm.call @_FortranACUFAllocDescriptor
287+
288+
// -----
289+
290+
fir.global @_QMkernelsEinitial_val {data_attr = #cuf.cuda<constant>} : i32 {
291+
%0 = fir.zero_bits i32
292+
fir.has_value %0 : i32
293+
}
294+
func.func @_QMkernelsPassign(%arg0: !fir.ref<i32> {cuf.data_attr = #cuf.cuda<device>, fir.bindc_name = "a"}) attributes {cuf.proc_attr = #cuf.cuda_proc<global>} {
295+
%1 = fir.address_of(@_QMkernelsEinitial_val) : !fir.ref<i32>
296+
%14 = fir.load %1 : !fir.ref<i32>
297+
fir.store %14 to %arg0 : !fir.ref<i32>
298+
return
299+
}
300+
301+
// CHECK: llvm.mlir.global external @_QMkernelsEinitial_val() {addr_space = 4 : i32} : i32
302+
// CHECK-LABEL: llvm.func @_QMkernelsPassign
303+
// CHECK: %[[ADDROF:.*]] = llvm.mlir.addressof @_QMkernelsEinitial_val : !llvm.ptr<4>
304+
// CHECK: %{{.*}} = llvm.addrspacecast %[[ADDROF]] : !llvm.ptr<4> to !llvm.ptr
305+

0 commit comments

Comments
 (0)