Index: mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp =================================================================== --- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -3208,9 +3208,11 @@ OpBuilder moduleBuilder(module.getBodyRegion(), builder.getListener()); MLIRContext *ctx = builder.getContext(); auto type = LLVM::LLVMArrayType::get(IntegerType::get(ctx, 8), value.size()); - auto global = moduleBuilder.create( - loc, type, /*isConstant=*/true, linkage, name, - builder.getStringAttr(value), /*alignment=*/0); + auto symbol = module.lookupSymbol(name.str()); + auto global = symbol ? symbol + : moduleBuilder.create( + loc, type, /*isConstant=*/true, linkage, name, + builder.getStringAttr(value), /*alignment=*/0); LLVMPointerType resultType; LLVMPointerType charPtr; Index: mlir/test/Integration/GPU/CUDA/kernel-call-multi-times.mlir =================================================================== --- /dev/null +++ mlir/test/Integration/GPU/CUDA/kernel-call-multi-times.mlir @@ -0,0 +1,31 @@ +// RUN: mlir-opt %s \ +// RUN: -pass-pipeline='builtin.module(gpu.module(strip-debuginfo,convert-gpu-to-nvvm,test-gpu-to-cubin))' \ +// RUN: | mlir-opt -gpu-to-llvm \ +// RUN: | FileCheck %s + +// CHECK: llvm.mlir.global internal constant @main_kernel_empty_kernel_kernel_name +// CHECK: llvm.mlir.global internal constant @main_kernel_gpubin_cst("CUBIN") +module attributes {gpu.container_module} { + // CHECK-LABEL: llvm.func @main + func.func @main() { + %one = arith.constant 1 : index + %sx = arith.constant 12 : index + // CHECK: llvm.mlir.addressof @main_kernel_gpubin_cst + // CHECK: llvm.mlir.addressof @main_kernel_empty_kernel_kernel_name + gpu.launch_func @main_kernel::@empty_kernel blocks in (%one, %one, %one) threads in (%sx, %one, %one) args() + %token_1 = gpu.wait async + + // CHECK: llvm.mlir.addressof @main_kernel_gpubin_cst + // CHECK: llvm.mlir.addressof @main_kernel_empty_kernel_kernel_name + gpu.launch_func @main_kernel::@empty_kernel blocks in (%one, %one, %one) threads in (%sx, %one, %one) args() + %token_2 = gpu.wait async + + return + } + + gpu.module @main_kernel attributes {gpu.binary = "CUBIN"}{ + gpu.func @empty_kernel() kernel { + gpu.return + } + } +}