Skip to content

Commit 2251d84

Browse files
committed
Add additional offload-tblgen tests and associated fixes
1 parent c270fcc commit 2251d84

File tree

6 files changed

+133
-15
lines changed

6 files changed

+133
-15
lines changed

offload/new-api/API/Platform.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def : Enum {
5050
let is_typed = 1;
5151
let etors = [
5252
TaggedEtor<"NAME", "char[]", "The string denoting name of the platform. The size of the info needs to be dynamically queried.">,
53-
TaggedEtor<"VENDOR_NAME", "char[]","The string denoting name of the vendor of the platform. The size of the info needs to be dynamically queried.">,
53+
TaggedEtor<"VENDOR_NAME", "char[]", "The string denoting name of the vendor of the platform. The size of the info needs to be dynamically queried.">,
5454
TaggedEtor<"VERSION", "char[]", "The string denoting the version of the platform. The size of the info needs to be dynamically queried.">,
5555
TaggedEtor<"BACKEND", "offload_platform_backend_t", "The native backend of the platform.">
5656
];

offload/new-api/include/offload_api.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,16 @@ OFFLOAD_APIEXPORT offload_result_t OFFLOAD_APICALL offloadPlatformGetCount(
213213
///////////////////////////////////////////////////////////////////////////////
214214
/// @brief Supported platform info
215215
typedef enum offload_platform_info_t {
216-
/// The string denoting name of the platform. The size of the info needs to be
217-
/// dynamically queried.
216+
/// [char[]] The string denoting name of the platform. The size of the info
217+
/// needs to be dynamically queried.
218218
OFFLOAD_PLATFORM_INFO_NAME = 0,
219-
/// The string denoting name of the vendor of the platform. The size of the
220-
/// info needs to be dynamically queried.
219+
/// [char[]] The string denoting name of the vendor of the platform. The size
220+
/// of the info needs to be dynamically queried.
221221
OFFLOAD_PLATFORM_INFO_VENDOR_NAME = 1,
222-
/// The string denoting the version of the platform. The size of the info
223-
/// needs to be dynamically queried.
222+
/// [char[]] The string denoting the version of the platform. The size of the
223+
/// info needs to be dynamically queried.
224224
OFFLOAD_PLATFORM_INFO_VERSION = 2,
225-
/// The native backend of the platform.
225+
/// [offload_platform_backend_t] The native backend of the platform.
226226
OFFLOAD_PLATFORM_INFO_BACKEND = 3,
227227
/// @cond
228228
OFFLOAD_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
@@ -328,15 +328,15 @@ typedef enum offload_device_type_t {
328328
///////////////////////////////////////////////////////////////////////////////
329329
/// @brief Supported device info
330330
typedef enum offload_device_info_t {
331-
/// type of the device
331+
/// [offload_device_type_t] type of the device
332332
OFFLOAD_DEVICE_INFO_TYPE = 0,
333-
/// the platform associated with the device
333+
/// [offload_platform_handle_t] the platform associated with the device
334334
OFFLOAD_DEVICE_INFO_PLATFORM = 1,
335-
/// Device name
335+
/// [char[]] Device name
336336
OFFLOAD_DEVICE_INFO_NAME = 2,
337-
/// Device vendor
337+
/// [char[]] Device vendor
338338
OFFLOAD_DEVICE_INFO_VENDOR = 3,
339-
/// Driver version
339+
/// [char[]] Driver version
340340
OFFLOAD_DEVICE_INFO_DRIVER_VERSION = 4,
341341
/// @cond
342342
OFFLOAD_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %offload-tblgen -gen-print-header -I %S/../../../new-api/API %s | %fcheck-generic
2+
3+
// Check that ranged function parameters are implemented correctly. These
4+
// are pointers to an array of an arbitrary size. Their size is described as a
5+
// range between two values. This is typically between 0 and a parameter such
6+
// as NumItems. The range information helps the printing code print the entire
7+
// range of the output rather than just the pointer or the first element.
8+
9+
include "APIDefs.td"
10+
11+
def : Handle {
12+
let name = "some_handle_t";
13+
let desc = "An example handle type";
14+
}
15+
16+
def : Function {
17+
let name = "FunctionA";
18+
let desc = "Function A description";
19+
let details = [ "Function A detailed information" ];
20+
let params = [
21+
Param<"size_t", "OutCount", "the number of things to write out", PARAM_IN>,
22+
RangedParam<"some_handle_t*", "OutPtr", "pointer to the output things.", PARAM_OUT,
23+
Range<"0", "OutCount">>
24+
];
25+
let returns = [];
26+
}
27+
28+
// CHECK: inline std::ostream &operator<<(std::ostream &os, const struct function_a_params_t *params) {
29+
// CHECK: os << ".OutPtr = ";
30+
// CHECK: for (size_t i = 0; i < *params->pOutCount; i++) {
31+
// CHECK: if (i > 0) {
32+
// CHECK: os << ", ";
33+
// CHECK: }
34+
// CHECK: printPtr(os, (*params->pOutPtr)[i]);
35+
// CHECK: }
36+
// CHECK: os << "}";
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
2+
// RUN: %offload-tblgen -gen-print-header -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-PRINT
3+
4+
// Check that type-tagged enumerators are implemented correctly. They enable
5+
// functions to return data of an arbitrary type and size via a void*, using
6+
// the value of an enum parameter to indicate which type is being returned.
7+
// This allows, for example, for a single offloadDeviceGetInfo function, rather
8+
// than requiring a separate entry point for every possible query.
9+
10+
include "APIDefs.td"
11+
12+
def : Handle {
13+
let name = "some_handle_t";
14+
let desc = "An example handle type";
15+
}
16+
17+
def : Enum {
18+
let name = "my_type_tagged_enum_t";
19+
let desc = "Example type tagged enum";
20+
let is_typed = 1;
21+
let etors = [
22+
TaggedEtor<"VALUE_ONE", "uint32_t", "Value one.">,
23+
TaggedEtor<"VALUE_TWO", "char[]", "Value two.">,
24+
TaggedEtor<"VALUE_THREE", "some_handle_t", "Value three.">
25+
];
26+
}
27+
28+
// Check the tagged types appear in the comments
29+
// CHECK-API: typedef enum my_type_tagged_enum_t {
30+
// CHECK-API-NEXT: [uint32_t] Value one.
31+
// CHECK-API-NEXT: MY_TYPE_TAGGED_ENUM_VALUE_ONE = 0,
32+
// CHECK-API-NEXT: [char[]] Value two.
33+
// CHECK-API-NEXT: MY_TYPE_TAGGED_ENUM_VALUE_TWO = 1,
34+
// CHECK-API-NEXT: [some_handle_t] Value three.
35+
// CHECK-API-NEXT: MY_TYPE_TAGGED_ENUM_VALUE_THREE = 2,
36+
37+
def : Function {
38+
let name = "FunctionA";
39+
let desc = "Function A description";
40+
let details = [ "Function A detailed information" ];
41+
let params = [
42+
Param<"my_type_tagged_enum_t", "PropName", "type of the info to retrieve", PARAM_IN>,
43+
Param<"size_t", "PropSize", "the number of bytes pointed to by PropValue.", PARAM_IN>,
44+
TypeTaggedParam<"void*", "PropValue", "array of bytes holding the info. "
45+
"If PropSize is not equal to or greater to the real number of bytes needed to return the info "
46+
"then the OFFLOAD_ERRC_INVALID_SIZE error is returned and PropValue is not used.", PARAM_OUT,
47+
TypeInfo<"PropName" , "PropSize">>
48+
];
49+
let returns = [];
50+
}
51+
52+
// Check that a tagged enum print function definition is generated
53+
// CHECK-PRINT: void printTagged(std::ostream &os, const void *ptr, my_type_tagged_enum_t value, size_t size) {
54+
// CHECK-PRINT: case MY_TYPE_TAGGED_ENUM_VALUE_ONE: {
55+
// CHECK-PRINT: const uint32_t * const tptr = (const uint32_t * const)ptr;
56+
// CHECK-PRINT: os << (const void *)tptr << " (";
57+
// CHECK-PRINT: os << *tptr;
58+
// CHECK-PRINT: os << ")";
59+
// CHECK-PRINT: break;
60+
// CHECK-PRINT: }
61+
// CHECK-PRINT: case MY_TYPE_TAGGED_ENUM_VALUE_TWO: {
62+
// CHECK-PRINT: printPtr(os, (const char*) ptr);
63+
// CHECK-PRINT: break;
64+
// CHECK-PRINT: }
65+
// CHECK-PRINT: case MY_TYPE_TAGGED_ENUM_VALUE_THREE: {
66+
// CHECK-PRINT: const some_handle_t * const tptr = (const some_handle_t * const)ptr;
67+
// CHECK-PRINT: os << (const void *)tptr << " (";
68+
// CHECK-PRINT: os << *tptr;
69+
// CHECK-PRINT: os << ")";
70+
// CHECK-PRINT: break;
71+
// CHECK-PRINT: }
72+
73+
// Check that the tagged type information is used when printing function parameters
74+
// CHECK-PRINT: std::ostream &operator<<(std::ostream &os, const struct function_a_params_t *params) {
75+
// CHECK-PRINT: os << ".PropValue = "
76+
// CHECK-PRINT-NEXT: printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize);

offload/tools/offload-tblgen/APIGen.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ static void ProcessEnum(const EnumRec &Enum, raw_ostream &OS) {
125125

126126
uint32_t EtorVal = 0;
127127
for (const auto &EnumVal : Enum.getValues()) {
128-
OS << TAB_1 << MakeComment(EnumVal.getDesc());
128+
if (Enum.isTyped()) {
129+
OS << MakeComment(
130+
formatv("[{0}] {1}", EnumVal.getTaggedType(), EnumVal.getDesc())
131+
.str());
132+
} else {
133+
OS << MakeComment(EnumVal.getDesc());
134+
}
129135
OS << formatv(TAB_1 "{0}_{1} = {2},\n", Enum.getEnumValNamePrefix(),
130136
EnumVal.getName(), EtorVal++);
131137
}

offload/tools/offload-tblgen/PrintGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ inline std::ostream &operator<<(std::ostream &os, const struct {0} *params) {{
123123
OS << formatv(TAB_1 "os << \".{0} = \";\n", Param.getName());
124124
if (auto Range = Param.getRange()) {
125125
OS << formatv(TAB_1 "os << \"{{\";\n");
126-
OS << formatv(TAB_1 "for (size_t i = {0}; i < *params->p{1}; i++){{\n",
126+
OS << formatv(TAB_1 "for (size_t i = {0}; i < *params->p{1}; i++) {{\n",
127127
Range->first, Range->second);
128128
OS << TAB_2 "if (i > 0) {\n";
129129
OS << TAB_3 " os << \", \";\n";

0 commit comments

Comments
 (0)