-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Offload][NFC] Use tablegen names rather than name parameter for API
#154736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-offload Author: Ross Brunton (RossBrunton) ChangesPatch is 24.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/154736.diff 12 Files Affected:
diff --git a/offload/liboffload/API/APIDefs.td b/offload/liboffload/API/APIDefs.td
index a30307fc90849..ea3896fc31035 100644
--- a/offload/liboffload/API/APIDefs.td
+++ b/offload/liboffload/API/APIDefs.td
@@ -145,7 +145,6 @@ defvar DefaultReturns = [Return<PREFIX#"_RESULT_SUCCESS">,
Return<PREFIX#"_ERRC_DEVICE_LOST">];
class APIObject {
- string name;
string desc;
}
diff --git a/offload/liboffload/API/Common.td b/offload/liboffload/API/Common.td
index 9a397812e417f..ac27d85b6c964 100644
--- a/offload/liboffload/API/Common.td
+++ b/offload/liboffload/API/Common.td
@@ -10,77 +10,64 @@
//
//===----------------------------------------------------------------------===//
-def : Macro {
- let name = "OL_VERSION_MAJOR";
+def OL_VERSION_MAJOR : Macro {
let desc = "Major version of the Offload API";
let value = "0";
}
-def : Macro {
- let name = "OL_VERSION_MINOR";
+def OL_VERSION_MINOR : Macro {
let desc = "Minor version of the Offload API";
let value = "0";
}
-def : Macro {
- let name = "OL_VERSION_PATCH";
+def OL_VERSION_PATCH : Macro {
let desc = "Patch version of the Offload API";
let value = "1";
}
-def : Macro {
- let name = "OL_APICALL";
+def OL_APICALL : Macro {
let desc = "Calling convention for all API functions";
let condition = "defined(_WIN32)";
let value = "__cdecl";
let alt_value = "";
}
-def : Macro {
- let name = "OL_APIEXPORT";
+def OL_APIEXPORT : Macro {
let desc = "Microsoft-specific dllexport storage-class attribute";
let condition = "defined(_WIN32)";
let value = "__declspec(dllexport)";
let alt_value = "";
}
-def : Handle {
- let name = "ol_platform_handle_t";
+def ol_platform_handle_t : Handle {
let desc = "Handle of a platform instance";
}
-def : Handle {
- let name = "ol_device_handle_t";
+def ol_device_handle_t : Handle {
let desc = "Handle of platform's device object";
}
-def : Handle {
- let name = "ol_context_handle_t";
+def ol_context_handle_t : Handle {
let desc = "Handle of context object";
}
-def : Handle {
- let name = "ol_queue_handle_t";
+def ol_queue_handle_t : Handle {
let desc = "Handle of queue object";
}
-def : Handle {
- let name = "ol_event_handle_t";
+def ol_event_handle_t : Handle {
let desc = "Handle of event object";
}
-def : Handle {
- let name = "ol_program_handle_t";
+def ol_program_handle_t : Handle {
let desc = "Handle of program object";
}
-def : Handle {
- let name = "ol_symbol_handle_t";
+def ol_symbol_handle_t : Handle {
let desc = "Handle of an object in a device's memory for a specific program";
}
-def ErrorCode : Enum {
- let name = "ol_errc_t";
+def ol_errc_t : Enum {
let desc = "Defines Return/Error codes";
let etors =[
Etor<"SUCCESS", "success">,
@@ -115,8 +102,7 @@ def ErrorCode : Enum {
];
}
-def : Struct {
- let name = "ol_error_struct_t";
+def ol_error_struct_t : Struct {
let desc = "Details of the error condition returned by an API call";
let members = [
StructMember<"ol_errc_t", "Code", "The error code">,
@@ -124,20 +110,17 @@ def : Struct {
];
}
-def : Typedef {
- let name = "ol_result_t";
+def ol_result_t : Typedef {
let desc = "Result type returned by all entry points.";
let value = "const struct ol_error_struct_t*";
}
-def : Macro {
- let name = "OL_SUCCESS";
+def OL_SUCCESS : Macro {
let desc = "Success condition";
let value = "NULL";
}
-def : Struct {
- let name = "ol_code_location_t";
+def ol_code_location_t : Struct {
let desc = "Code location information that can optionally be associated with an API call";
let members = [
StructMember<"const char*", "FunctionName", "Function name">,
@@ -147,8 +130,7 @@ def : Struct {
];
}
-def : Struct {
- let name = "ol_dimensions_t";
+def ol_dimensions_t : Struct {
let desc = "A three element vector";
let members = [
StructMember<"uint32_t", "x", "X">,
@@ -157,8 +139,7 @@ def : Struct {
];
}
-def : Function {
- let name = "olInit";
+def olInit : Function {
let desc = "Perform initialization of the Offload library and plugins";
let details = [
"This must be the first API call made by a user of the Offload library",
@@ -168,8 +149,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olShutDown";
+def olShutDown : Function {
let desc = "Release the resources in use by Offload";
let details = [
"This decrements an internal reference count. When this reaches 0, all resources will be released",
diff --git a/offload/liboffload/API/Device.td b/offload/liboffload/API/Device.td
index f9ba184759c25..d1baa28687fb2 100644
--- a/offload/liboffload/API/Device.td
+++ b/offload/liboffload/API/Device.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Enum {
- let name = "ol_device_type_t";
+def ol_device_type_t : Enum {
let desc = "Supported device types.";
let etors =[
Etor<"DEFAULT", "The default device type as preferred by the runtime">,
@@ -22,8 +21,7 @@ def : Enum {
];
}
-def DeviceInfo : Enum {
- let name = "ol_device_info_t";
+def ol_device_info_t : Enum {
let desc = "Supported device info.";
let is_typed = 1;
list<TaggedEtor> basic_etors =[
@@ -47,8 +45,7 @@ def DeviceInfo : Enum {
let etors = !listconcat(basic_etors, fp_configs, native_vec_widths);
}
-def : Enum {
- let name = "ol_device_fp_capability_flag_t";
+def ol_device_fp_capability_flag_t : Enum {
let desc = "Device floating-point capability flags";
let is_bit_field = 1;
let etors =[
@@ -63,14 +60,12 @@ def : Enum {
];
}
-def : Typedef {
- let name = "ol_device_fp_capability_flags_t";
+def ol_device_fp_capability_flags_t : Typedef {
let desc = "Device floating-point capability flags";
let value = "uint32_t";
}
-def : FptrTypedef {
- let name = "ol_device_iterate_cb_t";
+def ol_device_iterate_cb_t : FptrTypedef {
let desc = "User-provided function to be used with `olIterateDevices`";
let params = [
Param<"ol_device_handle_t", "Device", "the device handle of the current iteration", PARAM_IN>,
@@ -79,8 +74,7 @@ def : FptrTypedef {
let return = "bool";
}
-def : Function {
- let name = "olIterateDevices";
+def olIterateDevices : Function {
let desc = "Iterates over all available devices, calling the callback for each device.";
let details = [
"If the user-provided callback returns `false`, the iteration is stopped."
@@ -94,8 +88,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetDeviceInfo";
+def olGetDeviceInfo : Function {
let desc = "Queries the given property of the device.";
let details = [];
let params = [
@@ -118,8 +111,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetDeviceInfoSize";
+def olGetDeviceInfoSize : Function {
let desc = "Returns the storage size of the given device query.";
let details = [];
let params = [
diff --git a/offload/liboffload/API/Event.td b/offload/liboffload/API/Event.td
index 9d217ae230384..01d00692db3b4 100644
--- a/offload/liboffload/API/Event.td
+++ b/offload/liboffload/API/Event.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Function {
- let name = "olCreateEvent";
+def olCreateEvent : Function {
let desc = "Enqueue an event to `Queue` and return it.";
let details = [
"This event can be used with `olSyncEvent` and `olWaitEvents` and will be complete once all enqueued work prior to the `olCreateEvent` call is complete.",
@@ -23,8 +22,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olDestroyEvent";
+def olDestroyEvent : Function {
let desc = "Destroy the event and free all underlying resources.";
let details = [];
let params = [
@@ -33,8 +31,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olSyncEvent";
+def olSyncEvent : Function {
let desc = "Block the calling thread until the event is complete.";
let details = [];
let params = [
@@ -43,8 +40,7 @@ def : Function {
let returns = [];
}
-def : Enum {
- let name = "ol_event_info_t";
+def ol_event_info_t : Enum {
let desc = "Supported event info.";
let is_typed = 1;
let etors = [
@@ -52,8 +48,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetEventInfo";
+def olGetEventInfo : Function {
let desc = "Queries the given property of the event.";
let details = [
"`olGetEventInfoSize` can be used to query the storage size "
@@ -77,8 +72,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetEventInfoSize";
+def olGetEventInfoSize : Function {
let desc = "Returns the storage size of the given event query.";
let details = [];
let params = [
diff --git a/offload/liboffload/API/Kernel.td b/offload/liboffload/API/Kernel.td
index f9f5ef74b560d..2f5692a19d712 100644
--- a/offload/liboffload/API/Kernel.td
+++ b/offload/liboffload/API/Kernel.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Struct {
- let name = "ol_kernel_launch_size_args_t";
+def ol_kernel_launch_size_args_t : Struct {
let desc = "Size-related arguments for a kernel launch.";
let members = [
StructMember<"size_t", "Dimensions", "Number of work dimensions">,
@@ -21,8 +20,7 @@ def : Struct {
];
}
-def : Function {
- let name = "olLaunchKernel";
+def olLaunchKernel : Function {
let desc = "Enqueue a kernel launch with the specified size and parameters.";
let details = [
"If a queue is not specified, kernel execution happens synchronously",
@@ -43,8 +41,7 @@ def : Function {
];
}
-def : Function {
- let name = "olCalculateOptimalOccupancy";
+def olCalculateOptimalOccupancy : Function {
let desc = "Given dynamic memory size, query the device for a workgroup size that will result in optimal occupancy.";
let details = [
"For most devices, this will be the largest workgroup size that will result in all work items fitting on the device at once.",
diff --git a/offload/liboffload/API/Memory.td b/offload/liboffload/API/Memory.td
index 5f7158588bc77..248d9621b651e 100644
--- a/offload/liboffload/API/Memory.td
+++ b/offload/liboffload/API/Memory.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Enum {
- let name = "ol_alloc_type_t";
+def ol_alloc_type_t : Enum {
let desc = "Represents the type of allocation made with olMemAlloc.";
let etors = [
Etor<"HOST", "Host allocation">,
@@ -20,8 +19,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olMemAlloc";
+def olMemAlloc : Function {
let desc = "Creates a memory allocation on the specified device.";
let params = [
Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>,
@@ -36,8 +34,7 @@ def : Function {
];
}
-def : Function {
- let name = "olMemFree";
+def olMemFree : Function {
let desc = "Frees a memory allocation previously made by olMemAlloc.";
let params = [
Param<"void*", "Address", "address of the allocation to free", PARAM_IN>,
@@ -45,8 +42,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olMemcpy";
+def olMemcpy : Function {
let desc = "Enqueue a memcpy operation.";
let details = [
"For host pointers, use the host device belonging to the OL_PLATFORM_BACKEND_HOST platform.",
diff --git a/offload/liboffload/API/Platform.td b/offload/liboffload/API/Platform.td
index 97c2cc2d05704..906f899076a80 100644
--- a/offload/liboffload/API/Platform.td
+++ b/offload/liboffload/API/Platform.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Enum {
- let name = "ol_platform_info_t";
+def ol_platform_info_t : Enum {
let desc = "Supported platform info.";
let is_typed = 1;
let etors = [
@@ -22,8 +21,7 @@ def : Enum {
];
}
-def : Enum {
- let name = "ol_platform_backend_t";
+def ol_platform_backend_t : Enum {
let desc = "Identifies the native backend of the platform.";
let etors =[
Etor<"UNKNOWN", "The backend is not recognized">,
@@ -33,8 +31,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetPlatformInfo";
+def olGetPlatformInfo : Function {
let desc = "Queries the given property of the platform.";
let details = [
"`olGetPlatformInfoSize` can be used to query the storage size "
@@ -61,8 +58,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetPlatformInfoSize";
+def olGetPlatformInfoSize : Function {
let desc = "Returns the storage size of the given platform query.";
let details = [];
let params = [
diff --git a/offload/liboffload/API/Program.td b/offload/liboffload/API/Program.td
index 0476fa1f7c27a..1f48f650cab70 100644
--- a/offload/liboffload/API/Program.td
+++ b/offload/liboffload/API/Program.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Function {
- let name = "olCreateProgram";
+def olCreateProgram : Function {
let desc = "Create a program for the device from the binary image pointed to by `ProgData`.";
let details = [
"The provided `ProgData` will be copied and need not outlive the returned handle",
@@ -25,8 +24,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olDestroyProgram";
+def olDestroyProgram : Function {
let desc = "Destroy the program and free all underlying resources.";
let details = [];
let params = [
diff --git a/offload/liboffload/API/Queue.td b/offload/liboffload/API/Queue.td
index 0e20e23999d5e..ededa9cc92fef 100644
--- a/offload/liboffload/API/Queue.td
+++ b/offload/liboffload/API/Queue.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Function {
- let name = "olCreateQueue";
+def olCreateQueue : Function {
let desc = "Create a queue for the given device.";
let details = [];
let params = [
@@ -21,8 +20,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olDestroyQueue";
+def olDestroyQueue : Function {
let desc = "Destroy the queue and free all underlying resources.";
let details = [
"Any work previously enqueued to the queue is still performed and any events generated for this queue remain valid."
@@ -33,8 +31,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olSyncQueue";
+def olSyncQueue : Function {
let desc = "Block the calling thread until the enqueued work on a queue is complete.";
let details = [];
let params = [
@@ -43,8 +40,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olWaitEvents";
+def olWaitEvents : Function {
let desc = "Make any future work submitted to this queue wait until the provided events are complete.";
let details = [
"All events in `Events` must complete before the queue is unblocked.",
@@ -60,8 +56,7 @@ def : Function {
];
}
-def : Enum {
- let name = "ol_queue_info_t";
+def ol_queue_info_t : Enum {
let desc = "Supported queue info.";
let is_typed = 1;
let etors = [
@@ -70,8 +65,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetQueueInfo";
+def olGetQueueInfo : Function {
let desc = "Queries the given property of the queue.";
let details = [
"`olGetQueueInfoSize` can be used to query the storage size "
@@ -95,8 +89,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetQueueInfoSize";
+def olGetQueueInfoSize : Function {
let desc = "Returns the storage size of the given queue query.";
let details = [];
let params = [
@@ -109,8 +102,7 @@ def : Function {
];
}
-def : FptrTypedef {
- let name = "ol_host_function_cb_t";
+def ol_host_function_cb_t : FptrTypedef {
let desc = "Host function for use by `olLaunchHostFunction`.";
let params = [
Param<"void *", "UserData", "user specified data passed into `olLaunchHostFunction`.", PARAM_IN>,
@@ -118,8 +110,7 @@ def : FptrTypedef {
let return = "void";
}
-def : Function {
- let name = "olLaunchHostFunction";
+def olLaunchHostFunction : Function {
let desc = "Enqueue a callback function on the host.";
let details = [
"The provided function will be called from the same process as the one that called `olLaunchHostFunction`.",
diff --git a/offload/liboffload/API/Symbol.td b/offload/liboffload/API/Symbol.td
index 2e94d703809e7..c57a2e1b83632 100644
--- a/offload/liboffload/API/Symbol.td
+++ b/offload/liboffload/API/Symbol.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Enum {
- let name = "ol_symbol_kind_t";
+def ol_symbol_kind_t : Enum {
let desc = "The kind of a symbol";
let etors =[
Etor<"KERNEL", "a kernel object">,
@@ -19,8 +18,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetSymbol";
+def olGetSymbol : Function {
let desc = "Get a symbol (kernel or global variable) identified by `Name` in the given program.";
let details = [
"Symbol handles are owned by the program and do not need to be manually destroyed."
@@ -34,8 +32,7 @@ def : Function {
let returns = [];
}
-def : Enum {
- let name = "ol_symbol_info_t";
+def ol_symbol_info_t : Enum {
let desc = "Supported symbol info.";
let is_typed = 1;
let etors = [
@@ -45,8 +42,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetSymbolInfo";
+def olGetSymbolInfo : Function {
let desc = "Queries the given property of the symbol.";
let details = [
"`olGetSymbolInfoSize` can be used to query the storage size "
@@ -73,8 +69,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetSymbolInfoSize";
+def olGetSymbolInfoSize : Function {
let desc = "Returns the storage size of the given symbol query.";
let details = [];
let params = [
diff --git a/offload/tools/offload-tblgen/MiscGen.cpp b/offload/tools/offload-tblgen/MiscGen.cpp
index 17378331242a4..8a8b9caf2348d 100644
--- a/offload/tools/offload-tblgen/MiscGen.cpp
+++ b/offload/tools/offload-tblgen/MiscGen.cpp
@@ -86,7 +86,7 @@ void EmitOffloadErrcodes(const RecordKeeper &Records, raw_ostream &OS) {
)";
- auto ErrorCodeEnum = EnumRec{Records.getDef("ErrorCode")};
+ auto ErrorCodeEnum = EnumRec{Records.getDef("ol_errc_t")};
uint32_t EtorVal = 0;
for (const auto &EnumVal : ErrorCodeEnum.getValues()) {
OS << formatv(TAB_1 "OFFLOAD_ERRC({0}, \"{1}\", {2})\n", EnumVal.getName(),
@@ -107,7 +107,7 @@ void EmitOffloadInfo(const RecordKeeper &Records, raw_ostream &OS) {
)";
- auto Enum = EnumRec{Records.getDef("DeviceInfo")};
+ auto Enum = EnumRec{Records.getDef("ol_device_info_t")};
// Bitfields start from 1, other enums from 0
uint32_t EtorVal = Enum.isBitField();
for (const auto &EnumVal : Enum.getValues()) {
diff --git a/offload/tools/offload-tblgen/RecordTypes.hpp b/offload/tools/offload-tblgen/RecordTypes.hpp
index 1cde8b84c3069..2abd9e10f0f96 100644
--- a/offload/tools/offload-tblgen/RecordTypes.hpp
+++ b/offload/tools/offload-tblgen/RecordTypes.hpp
@@ -16,25 +16,30 @@ namespace llvm {
namespace offload {
namespace tblgen {
-class HandleRec {
+class APIObject {
public:
- explicit HandleRec(const Record *rec) : rec(rec) {}
- StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getName() const { return rec->getName(); }
StringRef getDesc() const { return rec->getValueAsString("desc"); }
-private:
+protected:
+ APIObject(const Record *rec) : rec(rec) {}
const Record *rec;
};
-class MacroRec {
+class HandleRec : public APIObject {
public:
- explicit MacroRec(const Record *rec) : rec(rec) {
- auto Name = rec->getValueAsString("name");
+ explicit HandleRec(const Record *rec) : APIObject(rec) {};
+};
+
+class MacroRec : public APIObject {
+public:
+ explicit MacroRec(const Record *rec) : APIObject(rec) {
+ auto Name = rec->getName();
auto OpenBrace = Name.find_first_of("(");
nameWithoutArgs = Name.substr(0, OpenBrace);
}
StringRef getName() const { return nameWithoutArgs; }
- StringRef getNameWithA...
[truncated]
|
jhuber6
approved these changes
Aug 21, 2025
callumfare
approved these changes
Aug 21, 2025
Member
|
This seems to be causing a bunch of test failures for me: and so on: Don't tests need to be updated after this change? |
RossBrunton
added a commit
to RossBrunton/llvm-project
that referenced
this pull request
Aug 29, 2025
These were not updated after llvm#154736 .
Contributor
Author
RossBrunton
added a commit
that referenced
this pull request
Aug 29, 2025
These were not updated after #154736 .
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.