[llvm] [Offload] Properly report errors when jit compiling (PR #145498)
Ross Brunton via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 04:32:18 PDT 2025
https://github.com/RossBrunton created https://github.com/llvm/llvm-project/pull/145498
Previously, if a binary failed to load due to failures when jit
compiling, the function would return success with nullptr. Now it
returns a new plugin error, `COMPILE_FAILURE`.
>From 9291eba5437855f783b5690c0bf8bdaeb2185551 Mon Sep 17 00:00:00 2001
From: Ross Brunton <ross at codeplay.com>
Date: Tue, 24 Jun 2025 12:30:29 +0100
Subject: [PATCH] [Offload] Properly report errors when jit compiling
Previously, if a binary failed to load due to failures when jit
compiling, the function would return success with nullptr. Now it
returns a new plugin error, `COMPILE_FAILURE`.
---
offload/liboffload/API/Common.td | 1 +
offload/liboffload/src/OffloadImpl.cpp | 1 +
offload/plugins-nextgen/common/src/PluginInterface.cpp | 5 +++--
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/offload/liboffload/API/Common.td b/offload/liboffload/API/Common.td
index cd8c3c63fde81..79c3bd46f1984 100644
--- a/offload/liboffload/API/Common.td
+++ b/offload/liboffload/API/Common.td
@@ -104,6 +104,7 @@ def ErrorCode : Enum {
Etor<"UNIMPLEMENTED", "generic error code for features currently unimplemented by the device/backend">,
Etor<"UNSUPPORTED", "generic error code for features unsupported by the device/backend">,
Etor<"ASSEMBLE_FAILURE", "assembler failure while processing binary image">,
+ Etor<"COMPILE_FAILURE", "jit compile failure while processing binary image">,
Etor<"LINK_FAILURE", "linker failure while processing binary image">,
Etor<"BACKEND_FAILURE", "the plugin backend is in an invalid or unsupported state">,
Etor<"UNINITIALIZED", "not initialized">,
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index eba8e91ed6880..da2101529ffec 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -471,6 +471,7 @@ Error olCreateProgram_impl(ol_device_handle_t Device, const void *ProgData,
delete Prog;
return Res.takeError();
}
+ assert(*Res != nullptr && "loadBinary returned nullptr");
Prog->Image = *Res;
*Program = Prog;
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp
index 6fd3405d03afa..3e9a62f57095f 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -909,8 +909,9 @@ GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
if (!PostJITImageOrErr) {
auto Err = PostJITImageOrErr.takeError();
REPORT("Failure to jit IR image %p on device %d: %s\n", InputTgtImage,
- DeviceId, toString(std::move(Err)).data());
- return nullptr;
+ DeviceId, toStringWithoutConsuming(Err).data());
+ return Plugin::error(ErrorCode::COMPILE_FAILURE, std::move(Err),
+ "failure to jit IR image");
}
// Load the binary and allocate the image object. Use the next available id
More information about the llvm-commits
mailing list