LLVM  16.0.0git
AMDGPUMetadataVerifier.h
Go to the documentation of this file.
1 //===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
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.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
17 #define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
18 
19 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/StringRef.h"
24 
25 #include <cstddef>
26 
27 namespace llvm {
28 
29 namespace msgpack {
30  class DocNode;
31  class MapDocNode;
32 }
33 
34 namespace AMDGPU {
35 namespace HSAMD {
36 namespace V3 {
37 
38 /// Verifier for AMDGPU HSA metadata.
39 ///
40 /// Operates in two modes:
41 ///
42 /// In strict mode, metadata must already be well-typed.
43 ///
44 /// In non-strict mode, metadata is coerced into expected types when possible.
46  bool Strict;
47 
48  bool verifyScalar(msgpack::DocNode &Node, msgpack::Type SKind,
49  function_ref<bool(msgpack::DocNode &)> verifyValue = {});
50  bool verifyInteger(msgpack::DocNode &Node);
51  bool verifyArray(msgpack::DocNode &Node,
52  function_ref<bool(msgpack::DocNode &)> verifyNode,
53  Optional<size_t> Size = std::nullopt);
54  bool verifyEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
55  function_ref<bool(msgpack::DocNode &)> verifyNode);
56  bool
57  verifyScalarEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
58  msgpack::Type SKind,
59  function_ref<bool(msgpack::DocNode &)> verifyValue = {});
60  bool verifyIntegerEntry(msgpack::MapDocNode &MapNode, StringRef Key,
61  bool Required);
62  bool verifyKernelArgs(msgpack::DocNode &Node);
63  bool verifyKernel(msgpack::DocNode &Node);
64 
65 public:
66  /// Construct a MetadataVerifier, specifying whether it will operate in \p
67  /// Strict mode.
68  MetadataVerifier(bool Strict) : Strict(Strict) {}
69 
70  /// Verify given HSA metadata.
71  ///
72  /// \returns True when successful, false when metadata is invalid.
73  bool verify(msgpack::DocNode &HSAMetadataRoot);
74 };
75 
76 } // end namespace V3
77 } // end namespace HSAMD
78 } // end namespace AMDGPU
79 } // end namespace llvm
80 
81 #endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Optional.h
StringRef.h
llvm::Optional< size_t >
llvm::msgpack::DocNode
A node in a MsgPack Document.
Definition: MsgPackDocument.h:38
llvm::cl::Required
@ Required
Definition: CommandLine.h:118
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
AMDGPU
Definition: AMDGPUReplaceLDSUseWithPointer.cpp:114
STLFunctionalExtras.h
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::msgpack::MapDocNode
A DocNode that is a map.
Definition: MsgPackDocument.h:219
llvm::AMDGPU::HSAMD::V3::MetadataVerifier
Verifier for AMDGPU HSA metadata.
Definition: AMDGPUMetadataVerifier.h:45
llvm::AMDGPU::HSAMD::V3::MetadataVerifier::MetadataVerifier
MetadataVerifier(bool Strict)
Construct a MetadataVerifier, specifying whether it will operate in Strict mode.
Definition: AMDGPUMetadataVerifier.h:68
None.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Node
Definition: ItaniumDemangle.h:156
llvm::AMDGPU::HSAMD::V3::MetadataVerifier::verify
bool verify(msgpack::DocNode &HSAMetadataRoot)
Verify given HSA metadata.
Definition: AMDGPUMetadataVerifier.cpp:284
MsgPackReader.h
llvm::msgpack::Type
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48