1 //===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This is a verifier for AMDGPU HSA metadata, which can verify both
11 /// well-typed metadata and untyped metadata. When verifying in the non-strict
12 /// mode, untyped metadata is coerced into the correct type if possible.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
17 #define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
19 #include "llvm/BinaryFormat/MsgPackDocument.h"
26 /// Verifier for AMDGPU HSA metadata.
28 /// Operates in two modes:
30 /// In strict mode, metadata must already be well-typed.
32 /// In non-strict mode, metadata is coerced into expected types when possible.
33 class MetadataVerifier
{
36 bool verifyScalar(msgpack::DocNode
&Node
, msgpack::Type SKind
,
37 function_ref
<bool(msgpack::DocNode
&)> verifyValue
= {});
38 bool verifyInteger(msgpack::DocNode
&Node
);
39 bool verifyArray(msgpack::DocNode
&Node
,
40 function_ref
<bool(msgpack::DocNode
&)> verifyNode
,
41 Optional
<size_t> Size
= None
);
42 bool verifyEntry(msgpack::MapDocNode
&MapNode
, StringRef Key
, bool Required
,
43 function_ref
<bool(msgpack::DocNode
&)> verifyNode
);
45 verifyScalarEntry(msgpack::MapDocNode
&MapNode
, StringRef Key
, bool Required
,
47 function_ref
<bool(msgpack::DocNode
&)> verifyValue
= {});
48 bool verifyIntegerEntry(msgpack::MapDocNode
&MapNode
, StringRef Key
,
50 bool verifyKernelArgs(msgpack::DocNode
&Node
);
51 bool verifyKernel(msgpack::DocNode
&Node
);
54 /// Construct a MetadataVerifier, specifying whether it will operate in \p
56 MetadataVerifier(bool Strict
) : Strict(Strict
) {}
58 /// Verify given HSA metadata.
60 /// \returns True when successful, false when metadata is invalid.
61 bool verify(msgpack::DocNode
&HSAMetadataRoot
);
65 } // end namespace HSAMD
66 } // end namespace AMDGPU
67 } // end namespace llvm
69 #endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H