Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:20

0001 //===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 /// \file
0010 /// This is a verifier for AMDGPU HSA metadata, which can verify both
0011 /// well-typed metadata and untyped metadata. When verifying in the non-strict
0012 /// mode, untyped metadata is coerced into the correct type if possible.
0013 //
0014 //===----------------------------------------------------------------------===//
0015 
0016 #ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
0017 #define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
0018 
0019 #include "llvm/ADT/STLFunctionalExtras.h"
0020 #include "llvm/ADT/StringRef.h"
0021 #include "llvm/BinaryFormat/MsgPackReader.h"
0022 
0023 #include <cstddef>
0024 #include <optional>
0025 
0026 namespace llvm {
0027 
0028 namespace msgpack {
0029   class DocNode;
0030   class MapDocNode;
0031 }
0032 
0033 namespace AMDGPU {
0034 namespace HSAMD {
0035 namespace V3 {
0036 
0037 /// Verifier for AMDGPU HSA metadata.
0038 ///
0039 /// Operates in two modes:
0040 ///
0041 /// In strict mode, metadata must already be well-typed.
0042 ///
0043 /// In non-strict mode, metadata is coerced into expected types when possible.
0044 class MetadataVerifier {
0045   bool Strict;
0046 
0047   bool verifyScalar(msgpack::DocNode &Node, msgpack::Type SKind,
0048                     function_ref<bool(msgpack::DocNode &)> verifyValue = {});
0049   bool verifyInteger(msgpack::DocNode &Node);
0050   bool verifyArray(msgpack::DocNode &Node,
0051                    function_ref<bool(msgpack::DocNode &)> verifyNode,
0052                    std::optional<size_t> Size = std::nullopt);
0053   bool verifyEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
0054                    function_ref<bool(msgpack::DocNode &)> verifyNode);
0055   bool
0056   verifyScalarEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
0057                     msgpack::Type SKind,
0058                     function_ref<bool(msgpack::DocNode &)> verifyValue = {});
0059   bool verifyIntegerEntry(msgpack::MapDocNode &MapNode, StringRef Key,
0060                           bool Required);
0061   bool verifyKernelArgs(msgpack::DocNode &Node);
0062   bool verifyKernel(msgpack::DocNode &Node);
0063 
0064 public:
0065   /// Construct a MetadataVerifier, specifying whether it will operate in \p
0066   /// Strict mode.
0067   MetadataVerifier(bool Strict) : Strict(Strict) {}
0068 
0069   /// Verify given HSA metadata.
0070   ///
0071   /// \returns True when successful, false when metadata is invalid.
0072   bool verify(msgpack::DocNode &HSAMetadataRoot);
0073 };
0074 
0075 } // end namespace V3
0076 } // end namespace HSAMD
0077 } // end namespace AMDGPU
0078 } // end namespace llvm
0079 
0080 #endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H