From 2e74cc6c04fc61b5524d3b17a4eff53bffa1b207 Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Thu, 21 Aug 2025 09:38:21 +0100 Subject: [PATCH] [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. --- offload/liboffload/API/Common.td | 2 +- offload/tools/offload-tblgen/APIGen.cpp | 36 ++++++++++--------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/offload/liboffload/API/Common.td b/offload/liboffload/API/Common.td index 6eaf604c8ebb..9a397812e417 100644 --- a/offload/liboffload/API/Common.td +++ b/offload/liboffload/API/Common.td @@ -127,7 +127,7 @@ def : Struct { def : Typedef { let name = "ol_result_t"; let desc = "Result type returned by all entry points."; - let value = "const ol_error_struct_t*"; + let value = "const struct ol_error_struct_t*"; } def : Macro { diff --git a/offload/tools/offload-tblgen/APIGen.cpp b/offload/tools/offload-tblgen/APIGen.cpp index 5a59d2a37377..1e79c00ae06c 100644 --- a/offload/tools/offload-tblgen/APIGen.cpp +++ b/offload/tools/offload-tblgen/APIGen.cpp @@ -226,31 +226,23 @@ OL_APIEXPORT ol_result_t OL_APICALL {0}WithCodeLoc( void EmitOffloadAPI(const RecordKeeper &Records, raw_ostream &OS) { OS << GenericHeader; OS << FileHeader; - // Generate main API definitions - for (auto *R : Records.getAllDerivedDefinitions("APIObject")) { - if (R->isSubClassOf("Macro")) { - ProcessMacro(MacroRec{R}, OS); - } else if (R->isSubClassOf("Typedef")) { - ProcessTypedef(TypedefRec{R}, OS); - } else if (R->isSubClassOf("Handle")) { - ProcessHandle(HandleRec{R}, OS); - } else if (R->isSubClassOf("Function")) { - ProcessFunction(FunctionRec{R}, OS); - } else if (R->isSubClassOf("Enum")) { - ProcessEnum(EnumRec{R}, OS); - } else if (R->isSubClassOf("Struct")) { - ProcessStruct(StructRec{R}, OS); - } else if (R->isSubClassOf("FptrTypedef")) { - ProcessFptrTypedef(FptrTypedefRec{R}, OS); - } - } - // Generate auxiliary definitions (func param structs etc) + // Generate main API definitions + for (auto *R : Records.getAllDerivedDefinitions("Macro")) + ProcessMacro(MacroRec{R}, OS); + for (auto *R : Records.getAllDerivedDefinitions("Handle")) + ProcessHandle(HandleRec{R}, OS); + for (auto *R : Records.getAllDerivedDefinitions("Enum")) + ProcessEnum(EnumRec{R}, OS); + for (auto *R : Records.getAllDerivedDefinitions("Typedef")) + ProcessTypedef(TypedefRec{R}, OS); + for (auto *R : Records.getAllDerivedDefinitions("FptrTypedef")) + ProcessFptrTypedef(FptrTypedefRec{R}, OS); + for (auto *R : Records.getAllDerivedDefinitions("Struct")) + ProcessStruct(StructRec{R}, OS); for (auto *R : Records.getAllDerivedDefinitions("Function")) { ProcessFuncParamStruct(FunctionRec{R}, OS); - } - - for (auto *R : Records.getAllDerivedDefinitions("Function")) { + ProcessFunction(FunctionRec{R}, OS); ProcessFuncWithCodeLocVariant(FunctionRec{R}, OS); }