Skip to content

Commit 2e74cc6

Browse files
authored
[Offload][NFC] Use a sensible order for APIGen (#154518)
The order entries in the tablegen API files are iterated is not the order they appear in the file. To avoid any issues with the order changing in future, we now generate all definitions of a certain class before class that can use them. This is a NFC; the definitions don't actually change, just the order they exist in in the OffloadAPI.h header.
1 parent 273ca1f commit 2e74cc6

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

offload/liboffload/API/Common.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def : Struct {
127127
def : Typedef {
128128
let name = "ol_result_t";
129129
let desc = "Result type returned by all entry points.";
130-
let value = "const ol_error_struct_t*";
130+
let value = "const struct ol_error_struct_t*";
131131
}
132132

133133
def : Macro {

offload/tools/offload-tblgen/APIGen.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,31 +226,23 @@ OL_APIEXPORT ol_result_t OL_APICALL {0}WithCodeLoc(
226226
void EmitOffloadAPI(const RecordKeeper &Records, raw_ostream &OS) {
227227
OS << GenericHeader;
228228
OS << FileHeader;
229-
// Generate main API definitions
230-
for (auto *R : Records.getAllDerivedDefinitions("APIObject")) {
231-
if (R->isSubClassOf("Macro")) {
232-
ProcessMacro(MacroRec{R}, OS);
233-
} else if (R->isSubClassOf("Typedef")) {
234-
ProcessTypedef(TypedefRec{R}, OS);
235-
} else if (R->isSubClassOf("Handle")) {
236-
ProcessHandle(HandleRec{R}, OS);
237-
} else if (R->isSubClassOf("Function")) {
238-
ProcessFunction(FunctionRec{R}, OS);
239-
} else if (R->isSubClassOf("Enum")) {
240-
ProcessEnum(EnumRec{R}, OS);
241-
} else if (R->isSubClassOf("Struct")) {
242-
ProcessStruct(StructRec{R}, OS);
243-
} else if (R->isSubClassOf("FptrTypedef")) {
244-
ProcessFptrTypedef(FptrTypedefRec{R}, OS);
245-
}
246-
}
247229

248-
// Generate auxiliary definitions (func param structs etc)
230+
// Generate main API definitions
231+
for (auto *R : Records.getAllDerivedDefinitions("Macro"))
232+
ProcessMacro(MacroRec{R}, OS);
233+
for (auto *R : Records.getAllDerivedDefinitions("Handle"))
234+
ProcessHandle(HandleRec{R}, OS);
235+
for (auto *R : Records.getAllDerivedDefinitions("Enum"))
236+
ProcessEnum(EnumRec{R}, OS);
237+
for (auto *R : Records.getAllDerivedDefinitions("Typedef"))
238+
ProcessTypedef(TypedefRec{R}, OS);
239+
for (auto *R : Records.getAllDerivedDefinitions("FptrTypedef"))
240+
ProcessFptrTypedef(FptrTypedefRec{R}, OS);
241+
for (auto *R : Records.getAllDerivedDefinitions("Struct"))
242+
ProcessStruct(StructRec{R}, OS);
249243
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
250244
ProcessFuncParamStruct(FunctionRec{R}, OS);
251-
}
252-
253-
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
245+
ProcessFunction(FunctionRec{R}, OS);
254246
ProcessFuncWithCodeLocVariant(FunctionRec{R}, OS);
255247
}
256248

0 commit comments

Comments
 (0)