Skip to content

Commit 8c06d0e

Browse files
authored
[Offload] Generate OffloadInfo.inc (#147316)
This is a generated file which contains a macro for all Device Info keys. This is visible to the plugin interface so that it can use the definitions in a future patch.
1 parent f676014 commit 8c06d0e

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

offload/liboffload/API/Device.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def : Enum {
2222
];
2323
}
2424

25-
def : Enum {
25+
def DeviceInfo : Enum {
2626
let name = "ol_device_info_t";
2727
let desc = "Supported device info.";
2828
let is_typed = 1;

offload/plugins-nextgen/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include(TableGen)
44
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
55
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/../../liboffload/API/OffloadAPI.td)
66
tablegen(OFFLOAD include/OffloadErrcodes.inc -gen-errcodes -I ${CMAKE_CURRENT_SOURCE_DIR}/../../liboffload/API)
7+
tablegen(OFFLOAD include/OffloadInfo.inc -gen-info -I ${CMAKE_CURRENT_SOURCE_DIR}/../../liboffload/API)
78
add_public_tablegen_target(PluginErrcodes)
89

910
# NOTE: Don't try to build `PluginInterface` using `add_llvm_library` because we

offload/tools/offload-tblgen/Generators.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ void EmitOffloadExports(const llvm::RecordKeeper &Records,
2323
llvm::raw_ostream &OS);
2424
void EmitOffloadErrcodes(const llvm::RecordKeeper &Records,
2525
llvm::raw_ostream &OS);
26+
void EmitOffloadInfo(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);

offload/tools/offload-tblgen/MiscGen.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,24 @@ void EmitOffloadErrcodes(const RecordKeeper &Records, raw_ostream &OS) {
9393
EnumVal.getDesc(), EtorVal++);
9494
}
9595
}
96+
97+
// Emit macro calls for each info
98+
void EmitOffloadInfo(const RecordKeeper &Records, raw_ostream &OS) {
99+
OS << GenericHeader;
100+
OS << R"(
101+
#ifndef OFFLOAD_DEVINFO
102+
#error Please define the macro OFFLOAD_DEVINFO(Name, Desc, Value)
103+
#endif
104+
105+
// Device info codes are shared between PluginInterface and liboffload.
106+
// To add new error codes, add them to offload/liboffload/API/Device.td.
107+
108+
)";
109+
110+
auto ErrorCodeEnum = EnumRec{Records.getDef("DeviceInfo")};
111+
uint32_t EtorVal = 0;
112+
for (const auto &EnumVal : ErrorCodeEnum.getValues()) {
113+
OS << formatv(TAB_1 "OFFLOAD_DEVINFO({0}, \"{1}\", {2})\n",
114+
EnumVal.getName(), EnumVal.getDesc(), EtorVal++);
115+
}
116+
}

offload/tools/offload-tblgen/offload-tblgen.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum ActionType {
3232
GenPrintHeader,
3333
GenExports,
3434
GenErrcodes,
35+
GenInfo,
3536
};
3637

3738
namespace {
@@ -55,7 +56,8 @@ cl::opt<ActionType> Action(
5556
clEnumValN(GenExports, "gen-exports",
5657
"Generate export file for the Offload library"),
5758
clEnumValN(GenErrcodes, "gen-errcodes",
58-
"Generate Offload Error Code enum")));
59+
"Generate Offload Error Code enum"),
60+
clEnumValN(GenInfo, "gen-info", "Generate Offload Info enum")));
5961
}
6062

6163
static bool OffloadTableGenMain(raw_ostream &OS, const RecordKeeper &Records) {
@@ -87,6 +89,9 @@ static bool OffloadTableGenMain(raw_ostream &OS, const RecordKeeper &Records) {
8789
case GenErrcodes:
8890
EmitOffloadErrcodes(Records, OS);
8991
break;
92+
case GenInfo:
93+
EmitOffloadInfo(Records, OS);
94+
break;
9095
}
9196

9297
return false;

0 commit comments

Comments
 (0)