Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ class CUFDeviceGlobal : public fir::impl::CUFDeviceGlobalBase<CUFDeviceGlobal> {
return signalPassFailure();
mlir::SymbolTable gpuSymTable(gpuMod);
for (auto globalOp : mod.getOps<fir::GlobalOp>()) {
if (cuf::isRegisteredDeviceGlobal(globalOp))
if (cuf::isRegisteredDeviceGlobal(globalOp)) {
candidates.insert(globalOp);
} else if (globalOp.getConstant() &&
mlir::isa<fir::SequenceType>(
fir::unwrapRefType(globalOp.resultType()))) {
mlir::Attribute initAttr =
globalOp.getInitVal().value_or(mlir::Attribute());
if (initAttr && mlir::dyn_cast<mlir::DenseElementsAttr>(initAttr))
candidates.insert(globalOp);
}
}
for (auto globalOp : candidates) {
auto globalName{globalOp.getSymbol().getValue()};
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Fir/CUDA/cuda-device-global.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,16 @@ module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", gpu.conta

// CHECK: gpu.module @cuda_device_mo
// CHECK-NEXT: fir.global @_QMmtestsEn(dense<[3, 4, 5, 6, 7]> : tensor<5xi32>) {data_attr = #cuf.cuda<device>} : !fir.array<5xi32>

// -----

module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", gpu.container_module} {
fir.global @_QMm1ECb(dense<[90, 100, 110]> : tensor<3xi32>) constant : !fir.array<3xi32>
fir.global @_QMm2ECc(dense<[100, 200, 300]> : tensor<3xi32>) constant : !fir.array<3xi32>
}

// CHECK: fir.global @_QMm1ECb
// CHECK: fir.global @_QMm2ECc
// CHECK: gpu.module @cuda_device_mod
// CHECK-DAG: fir.global @_QMm2ECc
// CHECK-DAG: fir.global @_QMm1ECb
Loading