From 6ebda46f19a78166b2c4940982eba1fe3104ad29 Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Fri, 2 May 2025 12:50:45 +0100 Subject: [PATCH 1/4] [Offload] Add Error Codes to PluginInterface A new ErrorCode enumeration is present in PluginInterface which can be used when returning an llvm::Error from offload and PluginInterface functions. This enum must be kept up to sync with liboffload's ol_errc_t enum, so both are automatically generated from liboffload's enum definition. Some error codes have also been shuffled around to allow for future work. Note that this patch only adds the machinery; actual error codes will be added in a future patch. --- offload/liboffload/API/APIDefs.td | 3 +- offload/liboffload/API/CMakeLists.txt | 10 ++- offload/liboffload/API/Common.td | 22 +++-- offload/liboffload/CMakeLists.txt | 2 + offload/liboffload/include/OffloadImpl.hpp | 14 +++- .../liboffload/include/generated/OffloadAPI.h | 83 +++++++++---------- .../include/generated/OffloadPrint.hpp | 27 +++--- .../common/include/OffloadErrcodes.inc | 37 +++++++++ .../common/include/PluginInterface.h | 38 ++++++++- offload/tools/offload-tblgen/APIGen.cpp | 3 + offload/tools/offload-tblgen/CMakeLists.txt | 3 +- offload/tools/offload-tblgen/Generators.hpp | 2 + .../{FuncsGen.cpp => MiscGen.cpp} | 24 ++++++ offload/tools/offload-tblgen/RecordTypes.hpp | 7 ++ .../tools/offload-tblgen/offload-tblgen.cpp | 10 ++- 15 files changed, 207 insertions(+), 78 deletions(-) create mode 100644 offload/plugins-nextgen/common/include/OffloadErrcodes.inc rename offload/tools/offload-tblgen/{FuncsGen.cpp => MiscGen.cpp} (75%) diff --git a/offload/liboffload/API/APIDefs.td b/offload/liboffload/API/APIDefs.td index 640932dcf8464..38508525f1d26 100644 --- a/offload/liboffload/API/APIDefs.td +++ b/offload/liboffload/API/APIDefs.td @@ -152,9 +152,10 @@ class Function : APIObject { AddHandleChecksToReturns.returns_out>.returns_out; } -class Etor { +class Etor { string name = Name; string desc = Desc; + int value = Value; string tagged_type; } diff --git a/offload/liboffload/API/CMakeLists.txt b/offload/liboffload/API/CMakeLists.txt index 8fd6cb539374a..62b8803ca2a13 100644 --- a/offload/liboffload/API/CMakeLists.txt +++ b/offload/liboffload/API/CMakeLists.txt @@ -11,13 +11,17 @@ if (CLANG_FORMAT) tablegen(OFFLOAD OffloadFuncs.inc -gen-func-names) tablegen(OFFLOAD OffloadImplFuncDecls.inc -gen-impl-func-decls) tablegen(OFFLOAD OffloadPrint.hpp -gen-print-header) + tablegen(OFFLOAD OffloadErrcodes.inc -gen-errcodes) - set(OFFLOAD_GENERATED_FILES ${TABLEGEN_OUTPUT}) + set(FILES_TO_COPY "OffloadAPI.h;OffloadEntryPoints.inc;OffloadFuncs.inc;OffloadImplFuncDecls.inc;OffloadPrint.hpp") + set(GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include/generated) add_public_tablegen_target(OffloadGenerate) add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CLANG_FORMAT} - -i ${OFFLOAD_GENERATED_FILES}) + -i ${TABLEGEN_OUTPUT}) add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND} - -E copy_if_different ${OFFLOAD_GENERATED_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/../include/generated") + -E copy_if_different ${FILES_TO_COPY} ${GEN_DIR}) + add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND} + -E copy_if_different OffloadErrcodes.inc "${LIBOFFLOAD_ROOT}/../plugins-nextgen/common/include/OffloadErrcodes.inc") else() message(WARNING "clang-format was not found, so the OffloadGenerate target\ will not be available. Offload will still build, but you will not be\ diff --git a/offload/liboffload/API/Common.td b/offload/liboffload/API/Common.td index de7502b540618..12551d1eb5fd5 100644 --- a/offload/liboffload/API/Common.td +++ b/offload/liboffload/API/Common.td @@ -83,26 +83,30 @@ def : Typedef { let value = "void *"; } -def : Enum { +def ErrorCode : Enum { let name = "ol_errc_t"; let desc = "Defines Return/Error codes"; let etors =[ - Etor<"SUCCESS", "Success">, - Etor<"INVALID_VALUE", "Invalid Value">, + Etor<"SUCCESS", "Success", 0>, + + // Universal errors + Etor<"INVALID_NULL_POINTER", "A pointer argument is null when it should not be">, + Etor<"INVALID_ARGUMENT", "An argument is invalid">, + Etor<"OUT_OF_RESOURCES", "Out of resources">, + Etor<"UNSUPPORTED", "generic error code for unsupported features and enums">, + + // Liboffload specific errors + Etor<"INVALID_VALUE", "Invalid Value", 0x1000>, Etor<"INVALID_PLATFORM", "Invalid platform">, Etor<"INVALID_DEVICE", "Invalid device">, Etor<"INVALID_QUEUE", "Invalid queue">, Etor<"INVALID_EVENT", "Invalid event">, Etor<"INVALID_KERNEL_NAME", "Named kernel not found in the program binary">, - Etor<"OUT_OF_RESOURCES", "Out of resources">, - Etor<"UNSUPPORTED_FEATURE", "generic error code for unsupported features">, - Etor<"INVALID_ARGUMENT", "generic error code for invalid arguments">, Etor<"INVALID_NULL_HANDLE", "handle argument is not valid">, - Etor<"INVALID_NULL_POINTER", "pointer argument may not be nullptr">, Etor<"INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">, Etor<"INVALID_ENUMERATION", "enumerator argument is not valid">, - Etor<"UNSUPPORTED_ENUMERATION", "enumerator argument is not supported by the device">, - Etor<"UNKNOWN", "Unknown or internal error"> + + Etor<"UNKNOWN", "Unknown or internal error", 0x10000> ]; } diff --git a/offload/liboffload/CMakeLists.txt b/offload/liboffload/CMakeLists.txt index db12236ddfc7f..9927fa3c3400a 100644 --- a/offload/liboffload/CMakeLists.txt +++ b/offload/liboffload/CMakeLists.txt @@ -1,3 +1,5 @@ +set(LIBOFFLOAD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") + add_subdirectory(API) add_llvm_library( diff --git a/offload/liboffload/include/OffloadImpl.hpp b/offload/liboffload/include/OffloadImpl.hpp index 48fdc2b884199..7d2c0c53fc85b 100644 --- a/offload/liboffload/include/OffloadImpl.hpp +++ b/offload/liboffload/include/OffloadImpl.hpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #pragma once +#include "PluginInterface.h" #include #include #include @@ -93,9 +94,7 @@ struct ol_impl_result_t { ol_errc_t ErrCode; llvm::StringRef Details; llvm::handleAllErrors(std::move(Error), [&](llvm::StringError &Err) { - // TODO: PluginInterface doesn't yet have a way to communicate offload - // error codes - ErrCode = OL_ERRC_UNKNOWN; + ErrCode = GetErrorCode(Err.convertToErrorCode()); Details = errorStrs().insert(Err.getMessage()).first->getKeyData(); }); @@ -105,5 +104,14 @@ struct ol_impl_result_t { operator ol_result_t() { return Result; } private: + static ol_errc_t GetErrorCode(std::error_code Code) { + if (Code.category() == llvm::omp::target::plugin::make_error_code( + llvm::omp::target::plugin::ErrorCode::SUCCESS) + .category()) { + return static_cast(Code.value()); + } + return OL_ERRC_UNKNOWN; + } + ol_result_t Result; }; diff --git a/offload/liboffload/include/generated/OffloadAPI.h b/offload/liboffload/include/generated/OffloadAPI.h index ace31c57cf2f8..13a840ce772fb 100644 --- a/offload/liboffload/include/generated/OffloadAPI.h +++ b/offload/liboffload/include/generated/OffloadAPI.h @@ -17,6 +17,45 @@ extern "C" { #endif +/////////////////////////////////////////////////////////////////////////////// +/// @brief Defines Return/Error codes +typedef enum ol_errc_t { + /// Success + OL_ERRC_SUCCESS = 0, + /// A pointer argument is null when it should not be + OL_ERRC_INVALID_NULL_POINTER = 1, + /// An argument is invalid + OL_ERRC_INVALID_ARGUMENT = 2, + /// Out of resources + OL_ERRC_OUT_OF_RESOURCES = 3, + /// generic error code for unsupported features and enums + OL_ERRC_UNSUPPORTED = 4, + /// Invalid Value + OL_ERRC_INVALID_VALUE = 4096, + /// Invalid platform + OL_ERRC_INVALID_PLATFORM = 4097, + /// Invalid device + OL_ERRC_INVALID_DEVICE = 4098, + /// Invalid queue + OL_ERRC_INVALID_QUEUE = 4099, + /// Invalid event + OL_ERRC_INVALID_EVENT = 4100, + /// Named kernel not found in the program binary + OL_ERRC_INVALID_KERNEL_NAME = 4101, + /// handle argument is not valid + OL_ERRC_INVALID_NULL_HANDLE = 4102, + /// invalid size or dimensions (e.g., must not be zero, or is out of bounds) + OL_ERRC_INVALID_SIZE = 4103, + /// enumerator argument is not valid + OL_ERRC_INVALID_ENUMERATION = 4104, + /// Unknown or internal error + OL_ERRC_UNKNOWN = 65536, + /// @cond + OL_ERRC_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ol_errc_t; + /////////////////////////////////////////////////////////////////////////////// #ifndef OL_VERSION_MAJOR /// @brief Major version of the Offload API @@ -101,47 +140,6 @@ typedef struct ol_program_impl_t *ol_program_handle_t; /// @brief Handle of kernel object typedef void *ol_kernel_handle_t; -/////////////////////////////////////////////////////////////////////////////// -/// @brief Defines Return/Error codes -typedef enum ol_errc_t { - /// Success - OL_ERRC_SUCCESS = 0, - /// Invalid Value - OL_ERRC_INVALID_VALUE = 1, - /// Invalid platform - OL_ERRC_INVALID_PLATFORM = 2, - /// Invalid device - OL_ERRC_INVALID_DEVICE = 3, - /// Invalid queue - OL_ERRC_INVALID_QUEUE = 4, - /// Invalid event - OL_ERRC_INVALID_EVENT = 5, - /// Named kernel not found in the program binary - OL_ERRC_INVALID_KERNEL_NAME = 6, - /// Out of resources - OL_ERRC_OUT_OF_RESOURCES = 7, - /// generic error code for unsupported features - OL_ERRC_UNSUPPORTED_FEATURE = 8, - /// generic error code for invalid arguments - OL_ERRC_INVALID_ARGUMENT = 9, - /// handle argument is not valid - OL_ERRC_INVALID_NULL_HANDLE = 10, - /// pointer argument may not be nullptr - OL_ERRC_INVALID_NULL_POINTER = 11, - /// invalid size or dimensions (e.g., must not be zero, or is out of bounds) - OL_ERRC_INVALID_SIZE = 12, - /// enumerator argument is not valid - OL_ERRC_INVALID_ENUMERATION = 13, - /// enumerator argument is not supported by the device - OL_ERRC_UNSUPPORTED_ENUMERATION = 14, - /// Unknown or internal error - OL_ERRC_UNKNOWN = 15, - /// @cond - OL_ERRC_FORCE_UINT32 = 0x7fffffff - /// @endcond - -} ol_errc_t; - /////////////////////////////////////////////////////////////////////////////// /// @brief Details of the error condition returned by an API call typedef struct ol_error_struct_t { @@ -477,7 +475,8 @@ OL_APIEXPORT ol_result_t OL_APICALL olMemFree( /// @brief Enqueue a memcpy operation. /// /// @details -/// - For host pointers, use the device returned by olGetHostDevice +/// - For host pointers, use the host device belonging to the +/// OL_PLATFORM_BACKEND_HOST platform. /// - If a queue is specified, at least one device must be a non-host device /// - If a queue is not specified, the memcpy happens synchronously /// diff --git a/offload/liboffload/include/generated/OffloadPrint.hpp b/offload/liboffload/include/generated/OffloadPrint.hpp index 7f5e33aea6f73..e99bb2db669fb 100644 --- a/offload/liboffload/include/generated/OffloadPrint.hpp +++ b/offload/liboffload/include/generated/OffloadPrint.hpp @@ -49,6 +49,18 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, case OL_ERRC_SUCCESS: os << "OL_ERRC_SUCCESS"; break; + case OL_ERRC_INVALID_NULL_POINTER: + os << "OL_ERRC_INVALID_NULL_POINTER"; + break; + case OL_ERRC_INVALID_ARGUMENT: + os << "OL_ERRC_INVALID_ARGUMENT"; + break; + case OL_ERRC_OUT_OF_RESOURCES: + os << "OL_ERRC_OUT_OF_RESOURCES"; + break; + case OL_ERRC_UNSUPPORTED: + os << "OL_ERRC_UNSUPPORTED"; + break; case OL_ERRC_INVALID_VALUE: os << "OL_ERRC_INVALID_VALUE"; break; @@ -67,30 +79,15 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, case OL_ERRC_INVALID_KERNEL_NAME: os << "OL_ERRC_INVALID_KERNEL_NAME"; break; - case OL_ERRC_OUT_OF_RESOURCES: - os << "OL_ERRC_OUT_OF_RESOURCES"; - break; - case OL_ERRC_UNSUPPORTED_FEATURE: - os << "OL_ERRC_UNSUPPORTED_FEATURE"; - break; - case OL_ERRC_INVALID_ARGUMENT: - os << "OL_ERRC_INVALID_ARGUMENT"; - break; case OL_ERRC_INVALID_NULL_HANDLE: os << "OL_ERRC_INVALID_NULL_HANDLE"; break; - case OL_ERRC_INVALID_NULL_POINTER: - os << "OL_ERRC_INVALID_NULL_POINTER"; - break; case OL_ERRC_INVALID_SIZE: os << "OL_ERRC_INVALID_SIZE"; break; case OL_ERRC_INVALID_ENUMERATION: os << "OL_ERRC_INVALID_ENUMERATION"; break; - case OL_ERRC_UNSUPPORTED_ENUMERATION: - os << "OL_ERRC_UNSUPPORTED_ENUMERATION"; - break; case OL_ERRC_UNKNOWN: os << "OL_ERRC_UNKNOWN"; break; diff --git a/offload/plugins-nextgen/common/include/OffloadErrcodes.inc b/offload/plugins-nextgen/common/include/OffloadErrcodes.inc new file mode 100644 index 0000000000000..146a2cd0ce0bf --- /dev/null +++ b/offload/plugins-nextgen/common/include/OffloadErrcodes.inc @@ -0,0 +1,37 @@ +//===- Auto-generated file, part of the LLVM/Offload project --------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef OFFLOAD_ERRC +#error Please define the macro OFFLOAD_ERRCODE(Name, Desc, Value) +#endif + +// Error codes are shared between PluginInterface and liboffload. +// To add new error codes, add them to offload/liboffload/API/Common.td and run +// the GenerateOffload target. + +OFFLOAD_ERRC(SUCCESS, "Success", 0) +OFFLOAD_ERRC(INVALID_NULL_POINTER, + "A pointer argument is null when it should not be", 1) +OFFLOAD_ERRC(INVALID_ARGUMENT, "An argument is invalid", 2) +OFFLOAD_ERRC(OUT_OF_RESOURCES, "Out of resources", 3) +OFFLOAD_ERRC(UNSUPPORTED, + "generic error code for unsupported features and enums", 4) +OFFLOAD_ERRC(INVALID_VALUE, "Invalid Value", 4096) +OFFLOAD_ERRC(INVALID_PLATFORM, "Invalid platform", 4097) +OFFLOAD_ERRC(INVALID_DEVICE, "Invalid device", 4098) +OFFLOAD_ERRC(INVALID_QUEUE, "Invalid queue", 4099) +OFFLOAD_ERRC(INVALID_EVENT, "Invalid event", 4100) +OFFLOAD_ERRC(INVALID_KERNEL_NAME, + "Named kernel not found in the program binary", 4101) +OFFLOAD_ERRC(INVALID_NULL_HANDLE, "handle argument is not valid", 4102) +OFFLOAD_ERRC( + INVALID_SIZE, + "invalid size or dimensions (e.g., must not be zero, or is out of bounds)", + 4103) +OFFLOAD_ERRC(INVALID_ENUMERATION, "enumerator argument is not valid", 4104) +OFFLOAD_ERRC(UNKNOWN, "Unknown or internal error", 65536) diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h index e54a8afdd3f4f..19fe26b10760b 100644 --- a/offload/plugins-nextgen/common/include/PluginInterface.h +++ b/offload/plugins-nextgen/common/include/PluginInterface.h @@ -58,6 +58,30 @@ struct GenericKernelTy; struct GenericDeviceTy; struct RecordReplayTy; +enum class ErrorCode { +#define OFFLOAD_ERRC(Name, _, Value) Name = Value, +#include "OffloadErrcodes.inc" +#undef OFFLOAD_ERRC +}; + +class OffloadErrorCategory : public std::error_category { + const char *name() const noexcept override { return "Offload Error"; } + std::string message(int ev) const override { + switch (static_cast(ev)) { +#define OFFLOAD_ERRC(Name, Desc, Value) \ + case ErrorCode::Name: \ + return #Desc; +#include "OffloadErrcodes.inc" +#undef OFFLOAD_ERRC + } + } +}; + +inline std::error_code make_error_code(ErrorCode EC) { + static OffloadErrorCategory Cat{}; + return {static_cast(EC), Cat}; +} + /// Class that wraps the __tgt_async_info to simply its usage. In case the /// object is constructed without a valid __tgt_async_info, the object will use /// an internal one and will synchronize the current thread with the pending @@ -1385,7 +1409,13 @@ static inline Error success() { return Error::success(); } /// Create a string error. template static Error error(const char *ErrFmt, ArgsTy... Args) { - return createStringError(inconvertibleErrorCode(), ErrFmt, Args...); + return createStringError(ErrorCode::UNKNOWN, ErrFmt, Args...); +} + +/// Create a string error. +template +static Error error(ErrorCode Code, const char *ErrFmt, ArgsTy... Args) { + return createStringError(Code, ErrFmt, Args...); } /// Check the plugin-specific error code and return an error or success @@ -1596,4 +1626,10 @@ template class GenericDeviceResourceManagerTy { } // namespace omp } // namespace llvm +namespace std { +template <> +struct is_error_code_enum + : std::true_type {}; +} // namespace std + #endif // OPENMP_LIBOMPTARGET_PLUGINS_COMMON_PLUGININTERFACE_H diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp index 800c9cadfe38b..14f8435c578d7 100644 --- a/offload/tools/offload-tblgen/APIGen.cpp +++ b/offload/tools/offload-tblgen/APIGen.cpp @@ -132,6 +132,9 @@ static void ProcessEnum(const EnumRec &Enum, raw_ostream &OS) { uint32_t EtorVal = 0; for (const auto &EnumVal : Enum.getValues()) { + if (auto NewVal = EnumVal.getEnumValue()) { + EtorVal = *NewVal; + } if (Enum.isTyped()) { OS << MakeComment( formatv("[{0}] {1}", EnumVal.getTaggedType(), EnumVal.getDesc()) diff --git a/offload/tools/offload-tblgen/CMakeLists.txt b/offload/tools/offload-tblgen/CMakeLists.txt index e7e7c85490543..613b166d62b4d 100644 --- a/offload/tools/offload-tblgen/CMakeLists.txt +++ b/offload/tools/offload-tblgen/CMakeLists.txt @@ -13,7 +13,7 @@ add_tablegen(offload-tblgen OFFLOAD EXPORT OFFLOAD APIGen.cpp EntryPointGen.cpp - FuncsGen.cpp + MiscGen.cpp GenCommon.hpp Generators.hpp offload-tblgen.cpp @@ -23,4 +23,3 @@ add_tablegen(offload-tblgen OFFLOAD set(OFFLOAD_TABLEGEN_EXE "${OFFLOAD_TABLEGEN_EXE}" CACHE INTERNAL "") set(OFFLOAD_TABLEGEN_TARGET "${OFFLOAD_TABLEGEN_TARGET}" CACHE INTERNAL "") - diff --git a/offload/tools/offload-tblgen/Generators.hpp b/offload/tools/offload-tblgen/Generators.hpp index 8b6104c5cd9c6..f3474dfc52e86 100644 --- a/offload/tools/offload-tblgen/Generators.hpp +++ b/offload/tools/offload-tblgen/Generators.hpp @@ -21,3 +21,5 @@ void EmitOffloadPrintHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS); void EmitOffloadExports(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS); +void EmitOffloadErrcodes(const llvm::RecordKeeper &Records, + llvm::raw_ostream &OS); diff --git a/offload/tools/offload-tblgen/FuncsGen.cpp b/offload/tools/offload-tblgen/MiscGen.cpp similarity index 75% rename from offload/tools/offload-tblgen/FuncsGen.cpp rename to offload/tools/offload-tblgen/MiscGen.cpp index 3238652176198..e0e12ab3af714 100644 --- a/offload/tools/offload-tblgen/FuncsGen.cpp +++ b/offload/tools/offload-tblgen/MiscGen.cpp @@ -72,3 +72,27 @@ void EmitOffloadImplFuncDecls(const RecordKeeper &Records, raw_ostream &OS) { OS << ");\n\n"; } } + +// Emit macro calls for each error enum +void EmitOffloadErrcodes(const RecordKeeper &Records, raw_ostream &OS) { + OS << GenericHeader; + OS << R"( +#ifndef OFFLOAD_ERRC +#error Please define the macro OFFLOAD_ERRCODE(Name, Desc, Value) +#endif + +// Error codes are shared between PluginInterface and liboffload. +// To add new error codes, add them to offload/liboffload/API/Common.td and run the GenerateOffload target. + +)"; + + auto ErrorCodeEnum = EnumRec{Records.getDef("ErrorCode")}; + uint32_t EtorVal = 0; + for (const auto &EnumVal : ErrorCodeEnum.getValues()) { + if (auto NewVal = EnumVal.getEnumValue()) { + EtorVal = *NewVal; + } + OS << formatv(TAB_1 "OFFLOAD_ERRC({0}, \"{1}\", {2})\n", EnumVal.getName(), + EnumVal.getDesc(), EtorVal++); + } +} diff --git a/offload/tools/offload-tblgen/RecordTypes.hpp b/offload/tools/offload-tblgen/RecordTypes.hpp index 686634ed778aa..5969ec311b28e 100644 --- a/offload/tools/offload-tblgen/RecordTypes.hpp +++ b/offload/tools/offload-tblgen/RecordTypes.hpp @@ -69,6 +69,13 @@ class EnumValueRec { StringRef getTaggedType() const { return rec->getValueAsString("tagged_type"); } + std::optional getEnumValue() const { + if (rec->getValueAsInt("value") == -1) { + return std::nullopt; + } else { + return rec->getValueAsInt("value"); + } + } private: const Record *rec; diff --git a/offload/tools/offload-tblgen/offload-tblgen.cpp b/offload/tools/offload-tblgen/offload-tblgen.cpp index 1912abf5265c7..83a4af04b8b22 100644 --- a/offload/tools/offload-tblgen/offload-tblgen.cpp +++ b/offload/tools/offload-tblgen/offload-tblgen.cpp @@ -30,7 +30,8 @@ enum ActionType { GenImplFuncDecls, GenEntryPoints, GenPrintHeader, - GenExports + GenExports, + GenErrcodes, }; namespace { @@ -52,7 +53,9 @@ cl::opt Action( clEnumValN(GenPrintHeader, "gen-print-header", "Generate Offload API print header"), clEnumValN(GenExports, "gen-exports", - "Generate export file for the Offload library"))); + "Generate export file for the Offload library"), + clEnumValN(GenErrcodes, "gen-errcodes", + "Generate Offload Error Code enum"))); } static bool OffloadTableGenMain(raw_ostream &OS, const RecordKeeper &Records) { @@ -81,6 +84,9 @@ static bool OffloadTableGenMain(raw_ostream &OS, const RecordKeeper &Records) { case GenExports: EmitOffloadExports(Records, OS); break; + case GenErrcodes: + EmitOffloadErrcodes(Records, OS); + break; } return false; From 5850cb9ec404f11499cbc7fa2cdf0c0fbdfb7057 Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Mon, 5 May 2025 11:18:49 +0100 Subject: [PATCH 2/4] [Offload] Don't partition error code enum into categories --- offload/liboffload/API/APIDefs.td | 3 +- offload/liboffload/API/Common.td | 17 +++++---- .../liboffload/include/generated/OffloadAPI.h | 36 +++++++++---------- .../include/generated/OffloadPrint.hpp | 24 ++++++------- .../common/include/OffloadErrcodes.inc | 30 ++++++++-------- offload/tools/offload-tblgen/APIGen.cpp | 3 -- offload/tools/offload-tblgen/MiscGen.cpp | 3 -- offload/tools/offload-tblgen/RecordTypes.hpp | 7 ---- 8 files changed, 54 insertions(+), 69 deletions(-) diff --git a/offload/liboffload/API/APIDefs.td b/offload/liboffload/API/APIDefs.td index 38508525f1d26..640932dcf8464 100644 --- a/offload/liboffload/API/APIDefs.td +++ b/offload/liboffload/API/APIDefs.td @@ -152,10 +152,9 @@ class Function : APIObject { AddHandleChecksToReturns.returns_out>.returns_out; } -class Etor { +class Etor { string name = Name; string desc = Desc; - int value = Value; string tagged_type; } diff --git a/offload/liboffload/API/Common.td b/offload/liboffload/API/Common.td index 12551d1eb5fd5..d19c9c662faec 100644 --- a/offload/liboffload/API/Common.td +++ b/offload/liboffload/API/Common.td @@ -87,26 +87,25 @@ def ErrorCode : Enum { let name = "ol_errc_t"; let desc = "Defines Return/Error codes"; let etors =[ - Etor<"SUCCESS", "Success", 0>, + Etor<"SUCCESS", "Success">, // Universal errors + Etor<"UNKNOWN", "Unknown or internal error">, Etor<"INVALID_NULL_POINTER", "A pointer argument is null when it should not be">, Etor<"INVALID_ARGUMENT", "An argument is invalid">, Etor<"OUT_OF_RESOURCES", "Out of resources">, Etor<"UNSUPPORTED", "generic error code for unsupported features and enums">, + Etor<"INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">, + Etor<"INVALID_ENUMERATION", "enumerator argument is not valid">, + Etor<"INVALID_KERNEL_NAME", "Named kernel not found in the program binary">, - // Liboffload specific errors - Etor<"INVALID_VALUE", "Invalid Value", 0x1000>, + // Handle related errors - only makes sense for liboffload + Etor<"INVALID_VALUE", "Invalid Value">, Etor<"INVALID_PLATFORM", "Invalid platform">, Etor<"INVALID_DEVICE", "Invalid device">, Etor<"INVALID_QUEUE", "Invalid queue">, Etor<"INVALID_EVENT", "Invalid event">, - Etor<"INVALID_KERNEL_NAME", "Named kernel not found in the program binary">, - Etor<"INVALID_NULL_HANDLE", "handle argument is not valid">, - Etor<"INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">, - Etor<"INVALID_ENUMERATION", "enumerator argument is not valid">, - - Etor<"UNKNOWN", "Unknown or internal error", 0x10000> + Etor<"INVALID_NULL_HANDLE", "handle argument is not valid"> ]; } diff --git a/offload/liboffload/include/generated/OffloadAPI.h b/offload/liboffload/include/generated/OffloadAPI.h index 13a840ce772fb..66ea48c8ca14f 100644 --- a/offload/liboffload/include/generated/OffloadAPI.h +++ b/offload/liboffload/include/generated/OffloadAPI.h @@ -22,34 +22,34 @@ extern "C" { typedef enum ol_errc_t { /// Success OL_ERRC_SUCCESS = 0, + /// Unknown or internal error + OL_ERRC_UNKNOWN = 1, /// A pointer argument is null when it should not be - OL_ERRC_INVALID_NULL_POINTER = 1, + OL_ERRC_INVALID_NULL_POINTER = 2, /// An argument is invalid - OL_ERRC_INVALID_ARGUMENT = 2, + OL_ERRC_INVALID_ARGUMENT = 3, /// Out of resources - OL_ERRC_OUT_OF_RESOURCES = 3, + OL_ERRC_OUT_OF_RESOURCES = 4, /// generic error code for unsupported features and enums - OL_ERRC_UNSUPPORTED = 4, + OL_ERRC_UNSUPPORTED = 5, + /// invalid size or dimensions (e.g., must not be zero, or is out of bounds) + OL_ERRC_INVALID_SIZE = 6, + /// enumerator argument is not valid + OL_ERRC_INVALID_ENUMERATION = 7, + /// Named kernel not found in the program binary + OL_ERRC_INVALID_KERNEL_NAME = 8, /// Invalid Value - OL_ERRC_INVALID_VALUE = 4096, + OL_ERRC_INVALID_VALUE = 9, /// Invalid platform - OL_ERRC_INVALID_PLATFORM = 4097, + OL_ERRC_INVALID_PLATFORM = 10, /// Invalid device - OL_ERRC_INVALID_DEVICE = 4098, + OL_ERRC_INVALID_DEVICE = 11, /// Invalid queue - OL_ERRC_INVALID_QUEUE = 4099, + OL_ERRC_INVALID_QUEUE = 12, /// Invalid event - OL_ERRC_INVALID_EVENT = 4100, - /// Named kernel not found in the program binary - OL_ERRC_INVALID_KERNEL_NAME = 4101, + OL_ERRC_INVALID_EVENT = 13, /// handle argument is not valid - OL_ERRC_INVALID_NULL_HANDLE = 4102, - /// invalid size or dimensions (e.g., must not be zero, or is out of bounds) - OL_ERRC_INVALID_SIZE = 4103, - /// enumerator argument is not valid - OL_ERRC_INVALID_ENUMERATION = 4104, - /// Unknown or internal error - OL_ERRC_UNKNOWN = 65536, + OL_ERRC_INVALID_NULL_HANDLE = 14, /// @cond OL_ERRC_FORCE_UINT32 = 0x7fffffff /// @endcond diff --git a/offload/liboffload/include/generated/OffloadPrint.hpp b/offload/liboffload/include/generated/OffloadPrint.hpp index e99bb2db669fb..af5ca0a96b509 100644 --- a/offload/liboffload/include/generated/OffloadPrint.hpp +++ b/offload/liboffload/include/generated/OffloadPrint.hpp @@ -49,6 +49,9 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, case OL_ERRC_SUCCESS: os << "OL_ERRC_SUCCESS"; break; + case OL_ERRC_UNKNOWN: + os << "OL_ERRC_UNKNOWN"; + break; case OL_ERRC_INVALID_NULL_POINTER: os << "OL_ERRC_INVALID_NULL_POINTER"; break; @@ -61,6 +64,15 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, case OL_ERRC_UNSUPPORTED: os << "OL_ERRC_UNSUPPORTED"; break; + case OL_ERRC_INVALID_SIZE: + os << "OL_ERRC_INVALID_SIZE"; + break; + case OL_ERRC_INVALID_ENUMERATION: + os << "OL_ERRC_INVALID_ENUMERATION"; + break; + case OL_ERRC_INVALID_KERNEL_NAME: + os << "OL_ERRC_INVALID_KERNEL_NAME"; + break; case OL_ERRC_INVALID_VALUE: os << "OL_ERRC_INVALID_VALUE"; break; @@ -76,21 +88,9 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, case OL_ERRC_INVALID_EVENT: os << "OL_ERRC_INVALID_EVENT"; break; - case OL_ERRC_INVALID_KERNEL_NAME: - os << "OL_ERRC_INVALID_KERNEL_NAME"; - break; case OL_ERRC_INVALID_NULL_HANDLE: os << "OL_ERRC_INVALID_NULL_HANDLE"; break; - case OL_ERRC_INVALID_SIZE: - os << "OL_ERRC_INVALID_SIZE"; - break; - case OL_ERRC_INVALID_ENUMERATION: - os << "OL_ERRC_INVALID_ENUMERATION"; - break; - case OL_ERRC_UNKNOWN: - os << "OL_ERRC_UNKNOWN"; - break; default: os << "unknown enumerator"; break; diff --git a/offload/plugins-nextgen/common/include/OffloadErrcodes.inc b/offload/plugins-nextgen/common/include/OffloadErrcodes.inc index 146a2cd0ce0bf..217565647c4e1 100644 --- a/offload/plugins-nextgen/common/include/OffloadErrcodes.inc +++ b/offload/plugins-nextgen/common/include/OffloadErrcodes.inc @@ -15,23 +15,23 @@ // the GenerateOffload target. OFFLOAD_ERRC(SUCCESS, "Success", 0) +OFFLOAD_ERRC(UNKNOWN, "Unknown or internal error", 1) OFFLOAD_ERRC(INVALID_NULL_POINTER, - "A pointer argument is null when it should not be", 1) -OFFLOAD_ERRC(INVALID_ARGUMENT, "An argument is invalid", 2) -OFFLOAD_ERRC(OUT_OF_RESOURCES, "Out of resources", 3) + "A pointer argument is null when it should not be", 2) +OFFLOAD_ERRC(INVALID_ARGUMENT, "An argument is invalid", 3) +OFFLOAD_ERRC(OUT_OF_RESOURCES, "Out of resources", 4) OFFLOAD_ERRC(UNSUPPORTED, - "generic error code for unsupported features and enums", 4) -OFFLOAD_ERRC(INVALID_VALUE, "Invalid Value", 4096) -OFFLOAD_ERRC(INVALID_PLATFORM, "Invalid platform", 4097) -OFFLOAD_ERRC(INVALID_DEVICE, "Invalid device", 4098) -OFFLOAD_ERRC(INVALID_QUEUE, "Invalid queue", 4099) -OFFLOAD_ERRC(INVALID_EVENT, "Invalid event", 4100) -OFFLOAD_ERRC(INVALID_KERNEL_NAME, - "Named kernel not found in the program binary", 4101) -OFFLOAD_ERRC(INVALID_NULL_HANDLE, "handle argument is not valid", 4102) + "generic error code for unsupported features and enums", 5) OFFLOAD_ERRC( INVALID_SIZE, "invalid size or dimensions (e.g., must not be zero, or is out of bounds)", - 4103) -OFFLOAD_ERRC(INVALID_ENUMERATION, "enumerator argument is not valid", 4104) -OFFLOAD_ERRC(UNKNOWN, "Unknown or internal error", 65536) + 6) +OFFLOAD_ERRC(INVALID_ENUMERATION, "enumerator argument is not valid", 7) +OFFLOAD_ERRC(INVALID_KERNEL_NAME, + "Named kernel not found in the program binary", 8) +OFFLOAD_ERRC(INVALID_VALUE, "Invalid Value", 9) +OFFLOAD_ERRC(INVALID_PLATFORM, "Invalid platform", 10) +OFFLOAD_ERRC(INVALID_DEVICE, "Invalid device", 11) +OFFLOAD_ERRC(INVALID_QUEUE, "Invalid queue", 12) +OFFLOAD_ERRC(INVALID_EVENT, "Invalid event", 13) +OFFLOAD_ERRC(INVALID_NULL_HANDLE, "handle argument is not valid", 14) diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp index 14f8435c578d7..800c9cadfe38b 100644 --- a/offload/tools/offload-tblgen/APIGen.cpp +++ b/offload/tools/offload-tblgen/APIGen.cpp @@ -132,9 +132,6 @@ static void ProcessEnum(const EnumRec &Enum, raw_ostream &OS) { uint32_t EtorVal = 0; for (const auto &EnumVal : Enum.getValues()) { - if (auto NewVal = EnumVal.getEnumValue()) { - EtorVal = *NewVal; - } if (Enum.isTyped()) { OS << MakeComment( formatv("[{0}] {1}", EnumVal.getTaggedType(), EnumVal.getDesc()) diff --git a/offload/tools/offload-tblgen/MiscGen.cpp b/offload/tools/offload-tblgen/MiscGen.cpp index e0e12ab3af714..b73d70d58c239 100644 --- a/offload/tools/offload-tblgen/MiscGen.cpp +++ b/offload/tools/offload-tblgen/MiscGen.cpp @@ -89,9 +89,6 @@ void EmitOffloadErrcodes(const RecordKeeper &Records, raw_ostream &OS) { auto ErrorCodeEnum = EnumRec{Records.getDef("ErrorCode")}; uint32_t EtorVal = 0; for (const auto &EnumVal : ErrorCodeEnum.getValues()) { - if (auto NewVal = EnumVal.getEnumValue()) { - EtorVal = *NewVal; - } OS << formatv(TAB_1 "OFFLOAD_ERRC({0}, \"{1}\", {2})\n", EnumVal.getName(), EnumVal.getDesc(), EtorVal++); } diff --git a/offload/tools/offload-tblgen/RecordTypes.hpp b/offload/tools/offload-tblgen/RecordTypes.hpp index 5969ec311b28e..686634ed778aa 100644 --- a/offload/tools/offload-tblgen/RecordTypes.hpp +++ b/offload/tools/offload-tblgen/RecordTypes.hpp @@ -69,13 +69,6 @@ class EnumValueRec { StringRef getTaggedType() const { return rec->getValueAsString("tagged_type"); } - std::optional getEnumValue() const { - if (rec->getValueAsInt("value") == -1) { - return std::nullopt; - } else { - return rec->getValueAsInt("value"); - } - } private: const Record *rec; From e8e6651859415f054d1c00876f0b23caeccfb53c Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Wed, 7 May 2025 14:50:39 +0100 Subject: [PATCH 3/4] [Offload] Follow other LLVM error code handling --- offload/plugins-nextgen/common/CMakeLists.txt | 1 + .../common/include/OffloadError.h | 76 +++++++++++++++++++ .../common/include/PluginInterface.h | 52 ++++--------- .../common/src/OffloadError.cpp | 40 ++++++++++ 4 files changed, 133 insertions(+), 36 deletions(-) create mode 100644 offload/plugins-nextgen/common/include/OffloadError.h create mode 100644 offload/plugins-nextgen/common/src/OffloadError.cpp diff --git a/offload/plugins-nextgen/common/CMakeLists.txt b/offload/plugins-nextgen/common/CMakeLists.txt index ffc431f68dbc5..2fcfaf8225a63 100644 --- a/offload/plugins-nextgen/common/CMakeLists.txt +++ b/offload/plugins-nextgen/common/CMakeLists.txt @@ -5,6 +5,7 @@ add_library(PluginCommon OBJECT src/GlobalHandler.cpp src/JIT.cpp src/RPC.cpp + src/OffloadError.cpp src/Utils/ELF.cpp ) add_dependencies(PluginCommon intrinsics_gen) diff --git a/offload/plugins-nextgen/common/include/OffloadError.h b/offload/plugins-nextgen/common/include/OffloadError.h new file mode 100644 index 0000000000000..2b0f49cdf7262 --- /dev/null +++ b/offload/plugins-nextgen/common/include/OffloadError.h @@ -0,0 +1,76 @@ +//===- OffloadError.h - Definition of error class -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +//===----------------------------------------------------------------------===// + +#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OFFLOAD_ERROR_H +#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OFFLOAD_ERROR_H + +#include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" + +namespace llvm { +namespace omp { +namespace target { +namespace plugin { + +enum class ErrorCode { +#define OFFLOAD_ERRC(Name, _, Value) Name = Value, +#include "OffloadErrcodes.inc" +#undef OFFLOAD_ERRC +}; + +class OffloadErrorCategory : public std::error_category { + const char *name() const noexcept override { return "Offload Error"; } + std::string message(int ev) const override { + switch (static_cast(ev)) { +#define OFFLOAD_ERRC(Name, Desc, Value) \ + case ErrorCode::Name: \ + return #Desc; +#include "OffloadErrcodes.inc" +#undef OFFLOAD_ERRC + } + } +}; +} // namespace plugin +} // namespace target +} // namespace omp +} // namespace llvm + +namespace std { +template <> +struct is_error_code_enum + : std::true_type {}; +} // namespace std + +namespace llvm { +namespace omp { +namespace target { +namespace plugin { + +const std::error_category &OffloadErrCategory(); + +inline std::error_code make_error_code(ErrorCode E) { + return std::error_code(static_cast(E), OffloadErrCategory()); +} + +/// Base class for errors originating in DIA SDK, e.g. COM calls +class OffloadError : public ErrorInfo { +public: + using ErrorInfo::ErrorInfo; + + OffloadError(const Twine &S) : ErrorInfo(S, ErrorCode::UNKNOWN) {} + + static char ID; +}; +} // namespace plugin +} // namespace target +} // namespace omp +} // namespace llvm + +#endif diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h index 19fe26b10760b..899ae0f9be3f5 100644 --- a/offload/plugins-nextgen/common/include/PluginInterface.h +++ b/offload/plugins-nextgen/common/include/PluginInterface.h @@ -30,6 +30,7 @@ #include "GlobalHandler.h" #include "JIT.h" #include "MemoryManager.h" +#include "OffloadError.h" #include "RPC.h" #include "omptarget.h" @@ -58,30 +59,6 @@ struct GenericKernelTy; struct GenericDeviceTy; struct RecordReplayTy; -enum class ErrorCode { -#define OFFLOAD_ERRC(Name, _, Value) Name = Value, -#include "OffloadErrcodes.inc" -#undef OFFLOAD_ERRC -}; - -class OffloadErrorCategory : public std::error_category { - const char *name() const noexcept override { return "Offload Error"; } - std::string message(int ev) const override { - switch (static_cast(ev)) { -#define OFFLOAD_ERRC(Name, Desc, Value) \ - case ErrorCode::Name: \ - return #Desc; -#include "OffloadErrcodes.inc" -#undef OFFLOAD_ERRC - } - } -}; - -inline std::error_code make_error_code(ErrorCode EC) { - static OffloadErrorCategory Cat{}; - return {static_cast(EC), Cat}; -} - /// Class that wraps the __tgt_async_info to simply its usage. In case the /// object is constructed without a valid __tgt_async_info, the object will use /// an internal one and will synchronize the current thread with the pending @@ -1406,16 +1383,25 @@ namespace Plugin { /// Plugin::check(). static inline Error success() { return Error::success(); } -/// Create a string error. +/// Create an Offload error. template -static Error error(const char *ErrFmt, ArgsTy... Args) { - return createStringError(ErrorCode::UNKNOWN, ErrFmt, Args...); +static Error error(ErrorCode Code, const char *ErrFmt, ArgsTy... Args) { + std::string Buffer; + raw_string_ostream(Buffer) << format(ErrFmt, Args...); + return make_error(Code, Buffer); } -/// Create a string error. template -static Error error(ErrorCode Code, const char *ErrFmt, ArgsTy... Args) { - return createStringError(Code, ErrFmt, Args...); +static Error error(const char *ErrFmt, ArgsTy... Args) { + return error(ErrorCode::UNKNOWN, ErrFmt, Args...); +} + +inline Error error(ErrorCode Code, const char *S) { + return make_error(Code, S); +} + +inline Error error(const char *S) { + return make_error(ErrorCode::UNKNOWN, S); } /// Check the plugin-specific error code and return an error or success @@ -1626,10 +1612,4 @@ template class GenericDeviceResourceManagerTy { } // namespace omp } // namespace llvm -namespace std { -template <> -struct is_error_code_enum - : std::true_type {}; -} // namespace std - #endif // OPENMP_LIBOMPTARGET_PLUGINS_COMMON_PLUGININTERFACE_H diff --git a/offload/plugins-nextgen/common/src/OffloadError.cpp b/offload/plugins-nextgen/common/src/OffloadError.cpp new file mode 100644 index 0000000000000..51d35bdcb0289 --- /dev/null +++ b/offload/plugins-nextgen/common/src/OffloadError.cpp @@ -0,0 +1,40 @@ +//===- OffloadError.cpp - Error extensions for offload --------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "OffloadError.h" +#include "llvm/Support/ErrorHandling.h" + +using namespace llvm; +using namespace llvm::omp::target::plugin; + +namespace { +// FIXME: This class is only here to support the transition to llvm::Error. It +// will be removed once this transition is complete. Clients should prefer to +// deal with the Error value directly, rather than converting to error_code. +class OffloadErrorCategory : public std::error_category { +public: + const char *name() const noexcept override { return "llvm.offload"; } + std::string message(int Condition) const override { + switch (static_cast(Condition)) { +#define OFFLOAD_ERRC(Name, Desc, Value) \ + case ErrorCode::Name: \ + return #Desc; +#include "OffloadErrcodes.inc" +#undef OFFLOAD_ERRC + } + llvm_unreachable("Unrecognized offload ErrorCode"); + } +}; +} // namespace + +const std::error_category &llvm::omp::target::plugin::OffloadErrCategory() { + static OffloadErrorCategory MSFCategory; + return MSFCategory; +} + +char OffloadError::ID; From 06d962ad8a3c74f2f923a31ebb99e0b39cd475d5 Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Wed, 7 May 2025 16:18:49 +0100 Subject: [PATCH 4/4] [Offload] Respond to feedback and fix extra definition --- .../include => include/Shared}/OffloadErrcodes.inc | 0 offload/liboffload/API/CMakeLists.txt | 2 +- .../plugins-nextgen/common/include/OffloadError.h | 14 +------------- .../plugins-nextgen/common/src/OffloadError.cpp | 8 ++++---- 4 files changed, 6 insertions(+), 18 deletions(-) rename offload/{plugins-nextgen/common/include => include/Shared}/OffloadErrcodes.inc (100%) diff --git a/offload/plugins-nextgen/common/include/OffloadErrcodes.inc b/offload/include/Shared/OffloadErrcodes.inc similarity index 100% rename from offload/plugins-nextgen/common/include/OffloadErrcodes.inc rename to offload/include/Shared/OffloadErrcodes.inc diff --git a/offload/liboffload/API/CMakeLists.txt b/offload/liboffload/API/CMakeLists.txt index 62b8803ca2a13..5f8d1435d141f 100644 --- a/offload/liboffload/API/CMakeLists.txt +++ b/offload/liboffload/API/CMakeLists.txt @@ -21,7 +21,7 @@ if (CLANG_FORMAT) add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FILES_TO_COPY} ${GEN_DIR}) add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND} - -E copy_if_different OffloadErrcodes.inc "${LIBOFFLOAD_ROOT}/../plugins-nextgen/common/include/OffloadErrcodes.inc") + -E copy_if_different OffloadErrcodes.inc "${LIBOMPTARGET_INCLUDE_DIR}/Shared/OffloadErrcodes.inc") else() message(WARNING "clang-format was not found, so the OffloadGenerate target\ will not be available. Offload will still build, but you will not be\ diff --git a/offload/plugins-nextgen/common/include/OffloadError.h b/offload/plugins-nextgen/common/include/OffloadError.h index 2b0f49cdf7262..04f5c31b4c9e1 100644 --- a/offload/plugins-nextgen/common/include/OffloadError.h +++ b/offload/plugins-nextgen/common/include/OffloadError.h @@ -21,22 +21,10 @@ namespace plugin { enum class ErrorCode { #define OFFLOAD_ERRC(Name, _, Value) Name = Value, -#include "OffloadErrcodes.inc" +#include "Shared/OffloadErrcodes.inc" #undef OFFLOAD_ERRC }; -class OffloadErrorCategory : public std::error_category { - const char *name() const noexcept override { return "Offload Error"; } - std::string message(int ev) const override { - switch (static_cast(ev)) { -#define OFFLOAD_ERRC(Name, Desc, Value) \ - case ErrorCode::Name: \ - return #Desc; -#include "OffloadErrcodes.inc" -#undef OFFLOAD_ERRC - } - } -}; } // namespace plugin } // namespace target } // namespace omp diff --git a/offload/plugins-nextgen/common/src/OffloadError.cpp b/offload/plugins-nextgen/common/src/OffloadError.cpp index 51d35bdcb0289..d0b05af791bc1 100644 --- a/offload/plugins-nextgen/common/src/OffloadError.cpp +++ b/offload/plugins-nextgen/common/src/OffloadError.cpp @@ -13,9 +13,9 @@ using namespace llvm; using namespace llvm::omp::target::plugin; namespace { -// FIXME: This class is only here to support the transition to llvm::Error. It -// will be removed once this transition is complete. Clients should prefer to -// deal with the Error value directly, rather than converting to error_code. +// OffloadError inherits from llvm::StringError which requires a +// std::error_code. Once/if that requirement is removed, then this +// std::error_code machinery can be removed. class OffloadErrorCategory : public std::error_category { public: const char *name() const noexcept override { return "llvm.offload"; } @@ -24,7 +24,7 @@ class OffloadErrorCategory : public std::error_category { #define OFFLOAD_ERRC(Name, Desc, Value) \ case ErrorCode::Name: \ return #Desc; -#include "OffloadErrcodes.inc" +#include "Shared/OffloadErrcodes.inc" #undef OFFLOAD_ERRC } llvm_unreachable("Unrecognized offload ErrorCode");