1 //===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This is a verifier for AMDGPU HSA metadata, which can verify both
12 /// well-typed metadata and untyped metadata. When verifying in the non-strict
13 /// mode, untyped metadata is coerced into the correct type if possible.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
18 #define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
20 #include "llvm/BinaryFormat/MsgPackTypes.h"
27 /// Verifier for AMDGPU HSA metadata.
29 /// Operates in two modes:
31 /// In strict mode, metadata must already be well-typed.
33 /// In non-strict mode, metadata is coerced into expected types when possible.
34 class MetadataVerifier {
37 bool verifyScalar(msgpack::Node &Node, msgpack::ScalarNode::ScalarKind SKind,
38 function_ref<bool(msgpack::ScalarNode &)> verifyValue = {});
39 bool verifyInteger(msgpack::Node &Node);
40 bool verifyArray(msgpack::Node &Node,
41 function_ref<bool(msgpack::Node &)> verifyNode,
42 Optional<size_t> Size = None);
43 bool verifyEntry(msgpack::MapNode &MapNode, StringRef Key, bool Required,
44 function_ref<bool(msgpack::Node &)> verifyNode);
46 verifyScalarEntry(msgpack::MapNode &MapNode, StringRef Key, bool Required,
47 msgpack::ScalarNode::ScalarKind SKind,
48 function_ref<bool(msgpack::ScalarNode &)> verifyValue = {});
49 bool verifyIntegerEntry(msgpack::MapNode &MapNode, StringRef Key,
51 bool verifyKernelArgs(msgpack::Node &Node);
52 bool verifyKernel(msgpack::Node &Node);
55 /// Construct a MetadataVerifier, specifying whether it will operate in \p
57 MetadataVerifier(bool Strict) : Strict(Strict) {}
59 /// Verify given HSA metadata.
61 /// \returns True when successful, false when metadata is invalid.
62 bool verify(msgpack::Node &HSAMetadataRoot);
66 } // end namespace HSAMD
67 } // end namespace AMDGPU
68 } // end namespace llvm
70 #endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H