23 bool MetadataVerifier::verifyScalar(
25 function_ref<
bool(msgpack::ScalarNode &)> verifyValue) {
26 auto ScalarPtr =
dyn_cast<msgpack::ScalarNode>(&Node);
32 if (
Scalar.getScalarKind() != SKind) {
39 std::string StringValue =
Scalar.getString();
40 Scalar.setScalarKind(SKind);
41 if (
Scalar.inputYAML(StringValue) != StringRef())
45 return verifyValue(
Scalar);
49 bool MetadataVerifier::verifyInteger(msgpack::Node &Node) {
56 bool MetadataVerifier::verifyArray(
57 msgpack::Node &Node, function_ref<
bool(msgpack::Node &)> verifyNode,
58 Optional<size_t>
Size) {
59 auto ArrayPtr =
dyn_cast<msgpack::ArrayNode>(&Node);
62 auto &
Array = *ArrayPtr;
65 for (
auto &Item : Array)
66 if (!verifyNode(*Item.get()))
72 bool MetadataVerifier::verifyEntry(
73 msgpack::MapNode &MapNode, StringRef
Key,
bool Required,
74 function_ref<
bool(msgpack::Node &)> verifyNode) {
75 auto Entry = MapNode.find(Key);
76 if (Entry == MapNode.end())
78 return verifyNode(*Entry->second.get());
81 bool MetadataVerifier::verifyScalarEntry(
82 msgpack::MapNode &MapNode, StringRef Key,
bool Required,
84 function_ref<
bool(msgpack::ScalarNode &)> verifyValue) {
85 return verifyEntry(MapNode, Key, Required, [=](msgpack::Node &Node) {
86 return verifyScalar(Node, SKind, verifyValue);
90 bool MetadataVerifier::verifyIntegerEntry(msgpack::MapNode &MapNode,
91 StringRef Key,
bool Required) {
92 return verifyEntry(MapNode, Key, Required, [
this](msgpack::Node &Node) {
93 return verifyInteger(Node);
97 bool MetadataVerifier::verifyKernelArgs(msgpack::Node &Node) {
98 auto ArgsMapPtr =
dyn_cast<msgpack::MapNode>(&Node);
101 auto &ArgsMap = *ArgsMapPtr;
103 if (!verifyScalarEntry(ArgsMap,
".name",
false,
106 if (!verifyScalarEntry(ArgsMap,
".type_name",
false,
109 if (!verifyIntegerEntry(ArgsMap,
".size",
true))
111 if (!verifyIntegerEntry(ArgsMap,
".offset",
true))
113 if (!verifyScalarEntry(ArgsMap,
".value_kind",
true,
115 [](msgpack::ScalarNode &SNode) {
116 return StringSwitch<bool>(SNode.getString())
117 .Case(
"by_value",
true)
118 .Case(
"global_buffer",
true)
119 .Case(
"dynamic_shared_pointer",
true)
120 .Case(
"sampler",
true)
124 .Case(
"hidden_global_offset_x",
true)
125 .Case(
"hidden_global_offset_y",
true)
126 .Case(
"hidden_global_offset_z",
true)
127 .Case(
"hidden_none",
true)
128 .Case(
"hidden_printf_buffer",
true)
129 .Case(
"hidden_default_queue",
true)
130 .Case(
"hidden_completion_action",
true)
134 if (!verifyScalarEntry(ArgsMap,
".value_type",
true,
136 [](msgpack::ScalarNode &SNode) {
137 return StringSwitch<bool>(SNode.getString())
138 .Case(
"struct",
true)
153 if (!verifyIntegerEntry(ArgsMap,
".pointee_align",
false))
155 if (!verifyScalarEntry(ArgsMap,
".address_space",
false,
157 [](msgpack::ScalarNode &SNode) {
158 return StringSwitch<bool>(SNode.getString())
159 .Case(
"private",
true)
160 .Case(
"global",
true)
161 .Case(
"constant",
true)
163 .Case(
"generic",
true)
164 .Case(
"region",
true)
168 if (!verifyScalarEntry(ArgsMap,
".access",
false,
170 [](msgpack::ScalarNode &SNode) {
171 return StringSwitch<bool>(SNode.getString())
172 .Case(
"read_only",
true)
173 .Case(
"write_only",
true)
174 .Case(
"read_write",
true)
178 if (!verifyScalarEntry(ArgsMap,
".actual_access",
false,
180 [](msgpack::ScalarNode &SNode) {
181 return StringSwitch<bool>(SNode.getString())
182 .Case(
"read_only",
true)
183 .Case(
"write_only",
true)
184 .Case(
"read_write",
true)
188 if (!verifyScalarEntry(ArgsMap,
".is_const",
false,
191 if (!verifyScalarEntry(ArgsMap,
".is_restrict",
false,
194 if (!verifyScalarEntry(ArgsMap,
".is_volatile",
false,
197 if (!verifyScalarEntry(ArgsMap,
".is_pipe",
false,
204 bool MetadataVerifier::verifyKernel(msgpack::Node &Node) {
205 auto KernelMapPtr =
dyn_cast<msgpack::MapNode>(&Node);
208 auto &KernelMap = *KernelMapPtr;
210 if (!verifyScalarEntry(KernelMap,
".name",
true,
213 if (!verifyScalarEntry(KernelMap,
".symbol",
true,
216 if (!verifyScalarEntry(KernelMap,
".language",
false,
218 [](msgpack::ScalarNode &SNode) {
219 return StringSwitch<bool>(SNode.getString())
220 .Case(
"OpenCL C",
true)
221 .Case(
"OpenCL C++",
true)
224 .Case(
"OpenMP",
true)
225 .Case(
"Assembler",
true)
230 KernelMap,
".language_version",
false, [
this](msgpack::Node &Node) {
233 [
this](msgpack::Node &Node) {
return verifyInteger(Node); }, 2);
236 if (!verifyEntry(KernelMap,
".args",
false, [
this](msgpack::Node &Node) {
237 return verifyArray(Node, [
this](msgpack::Node &Node) {
238 return verifyKernelArgs(Node);
242 if (!verifyEntry(KernelMap,
".reqd_workgroup_size",
false,
243 [
this](msgpack::Node &Node) {
244 return verifyArray(Node,
245 [
this](msgpack::Node &Node) {
246 return verifyInteger(Node);
251 if (!verifyEntry(KernelMap,
".workgroup_size_hint",
false,
252 [
this](msgpack::Node &Node) {
253 return verifyArray(Node,
254 [
this](msgpack::Node &Node) {
255 return verifyInteger(Node);
260 if (!verifyScalarEntry(KernelMap,
".vec_type_hint",
false,
263 if (!verifyScalarEntry(KernelMap,
".device_enqueue_symbol",
false,
266 if (!verifyIntegerEntry(KernelMap,
".kernarg_segment_size",
true))
268 if (!verifyIntegerEntry(KernelMap,
".group_segment_fixed_size",
true))
270 if (!verifyIntegerEntry(KernelMap,
".private_segment_fixed_size",
true))
272 if (!verifyIntegerEntry(KernelMap,
".kernarg_segment_align",
true))
274 if (!verifyIntegerEntry(KernelMap,
".wavefront_size",
true))
276 if (!verifyIntegerEntry(KernelMap,
".sgpr_count",
true))
278 if (!verifyIntegerEntry(KernelMap,
".vgpr_count",
true))
280 if (!verifyIntegerEntry(KernelMap,
".max_flat_workgroup_size",
true))
282 if (!verifyIntegerEntry(KernelMap,
".sgpr_spill_count",
false))
284 if (!verifyIntegerEntry(KernelMap,
".vgpr_spill_count",
false))
294 auto &RootMap = *RootMapPtr;
297 RootMap,
"amdhsa.version",
true, [
this](
msgpack::Node &Node) {
300 [
this](
msgpack::Node &Node) {
return verifyInteger(Node); }, 2);
304 RootMap,
"amdhsa.printf",
false, [
this](
msgpack::Node &Node) {
310 if (!verifyEntry(RootMap,
"amdhsa.kernels",
true,
313 return verifyKernel(Node);
This class represents lattice values for constants.
Abstract base-class which can be any MessagePack type.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)