]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/BinaryFormat/AMDGPUMetadataVerifier.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / BinaryFormat / AMDGPUMetadataVerifier.h
1 //===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
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.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
18 #define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
19
20 #include "llvm/BinaryFormat/MsgPackTypes.h"
21
22 namespace llvm {
23 namespace AMDGPU {
24 namespace HSAMD {
25 namespace V3 {
26
27 /// Verifier for AMDGPU HSA metadata.
28 ///
29 /// Operates in two modes:
30 ///
31 /// In strict mode, metadata must already be well-typed.
32 ///
33 /// In non-strict mode, metadata is coerced into expected types when possible.
34 class MetadataVerifier {
35   bool Strict;
36
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);
45   bool
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,
50                           bool Required);
51   bool verifyKernelArgs(msgpack::Node &Node);
52   bool verifyKernel(msgpack::Node &Node);
53
54 public:
55   /// Construct a MetadataVerifier, specifying whether it will operate in \p
56   /// Strict mode.
57   MetadataVerifier(bool Strict) : Strict(Strict) {}
58
59   /// Verify given HSA metadata.
60   ///
61   /// \returns True when successful, false when metadata is invalid.
62   bool verify(msgpack::Node &HSAMetadataRoot);
63 };
64
65 } // end namespace V3
66 } // end namespace HSAMD
67 } // end namespace AMDGPU
68 } // end namespace llvm
69
70 #endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H