diff --git a/mlir/lib/Target/Target.cpp b/mlir/lib/Target/Target.cpp index 9f4bd666e0e4..290cd13d7009 100644 --- a/mlir/lib/Target/Target.cpp +++ b/mlir/lib/Target/Target.cpp @@ -128,6 +128,11 @@ AMDGPUSerializer::loadBitcodeFiles(llvm::Module &module) { ", error message:" + error.getMessage()); return std::nullopt; } + // Packaged libraries can come from a newer LLVM than ours. Give them the + // same handling as libraries loaded from disk so they adopt our triple + // and data layout instead of warning on every kernel that links them. + if (failed(handleBitcodeFile(*library))) + return std::nullopt; // Unset the lib so we don't add it with `appendStandardLibs`. libs = libs & ~lib; bcFiles.push_back(std::move(library)); diff --git a/mlir/test/Target/packaged-device-libs.mlir b/mlir/test/Target/packaged-device-libs.mlir new file mode 100644 index 000000000000..9b41f8276fb0 --- /dev/null +++ b/mlir/test/Target/packaged-device-libs.mlir @@ -0,0 +1,17 @@ +// RUN: rocmlir-opt %s --rocdl-attach-target=chip=gfx942 --gpu-module-to-binary 2>&1 \ +// RUN: | FileCheck %s --implicit-check-not="Linking two modules" + +// The packaged device libraries can be built by a newer LLVM than ours, with a +// different triple spelling and data layout. Linking them must not warn. + +// CHECK: gpu.binary @kernels +module attributes {gpu.container_module} { + gpu.module @kernels { + llvm.func @__ocml_exp_f32(f32) -> f32 + llvm.func @kernel(%arg0: f32, %arg1: !llvm.ptr<1>) attributes {rocdl.kernel} { + %0 = llvm.call @__ocml_exp_f32(%arg0) : (f32) -> f32 + llvm.store %0, %arg1 : f32, !llvm.ptr<1> + llvm.return + } + } +}