10b57cec5SDimitry Andric //===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric /// \file 100b57cec5SDimitry Andric /// This is a verifier for AMDGPU HSA metadata, which can verify both 110b57cec5SDimitry Andric /// well-typed metadata and untyped metadata. When verifying in the non-strict 120b57cec5SDimitry Andric /// mode, untyped metadata is coerced into the correct type if possible. 130b57cec5SDimitry Andric // 140b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric #ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H 170b57cec5SDimitry Andric #define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H 180b57cec5SDimitry Andric 1904eeddc0SDimitry Andric #include "llvm/ADT/STLFunctionalExtras.h" 2004eeddc0SDimitry Andric #include "llvm/ADT/StringRef.h" 2104eeddc0SDimitry Andric #include "llvm/BinaryFormat/MsgPackReader.h" 2204eeddc0SDimitry Andric 2304eeddc0SDimitry Andric #include <cstddef> 24*bdd1243dSDimitry Andric #include <optional> 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric namespace llvm { 2704eeddc0SDimitry Andric 2804eeddc0SDimitry Andric namespace msgpack { 2904eeddc0SDimitry Andric class DocNode; 3004eeddc0SDimitry Andric class MapDocNode; 3104eeddc0SDimitry Andric } 3204eeddc0SDimitry Andric 330b57cec5SDimitry Andric namespace AMDGPU { 340b57cec5SDimitry Andric namespace HSAMD { 350b57cec5SDimitry Andric namespace V3 { 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric /// Verifier for AMDGPU HSA metadata. 380b57cec5SDimitry Andric /// 390b57cec5SDimitry Andric /// Operates in two modes: 400b57cec5SDimitry Andric /// 410b57cec5SDimitry Andric /// In strict mode, metadata must already be well-typed. 420b57cec5SDimitry Andric /// 430b57cec5SDimitry Andric /// In non-strict mode, metadata is coerced into expected types when possible. 440b57cec5SDimitry Andric class MetadataVerifier { 450b57cec5SDimitry Andric bool Strict; 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric bool verifyScalar(msgpack::DocNode &Node, msgpack::Type SKind, 480b57cec5SDimitry Andric function_ref<bool(msgpack::DocNode &)> verifyValue = {}); 490b57cec5SDimitry Andric bool verifyInteger(msgpack::DocNode &Node); 500b57cec5SDimitry Andric bool verifyArray(msgpack::DocNode &Node, 510b57cec5SDimitry Andric function_ref<bool(msgpack::DocNode &)> verifyNode, 52*bdd1243dSDimitry Andric std::optional<size_t> Size = std::nullopt); 530b57cec5SDimitry Andric bool verifyEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required, 540b57cec5SDimitry Andric function_ref<bool(msgpack::DocNode &)> verifyNode); 550b57cec5SDimitry Andric bool 560b57cec5SDimitry Andric verifyScalarEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required, 570b57cec5SDimitry Andric msgpack::Type SKind, 580b57cec5SDimitry Andric function_ref<bool(msgpack::DocNode &)> verifyValue = {}); 590b57cec5SDimitry Andric bool verifyIntegerEntry(msgpack::MapDocNode &MapNode, StringRef Key, 600b57cec5SDimitry Andric bool Required); 610b57cec5SDimitry Andric bool verifyKernelArgs(msgpack::DocNode &Node); 620b57cec5SDimitry Andric bool verifyKernel(msgpack::DocNode &Node); 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric public: 650b57cec5SDimitry Andric /// Construct a MetadataVerifier, specifying whether it will operate in \p 660b57cec5SDimitry Andric /// Strict mode. MetadataVerifier(bool Strict)670b57cec5SDimitry Andric MetadataVerifier(bool Strict) : Strict(Strict) {} 680b57cec5SDimitry Andric 690b57cec5SDimitry Andric /// Verify given HSA metadata. 700b57cec5SDimitry Andric /// 710b57cec5SDimitry Andric /// \returns True when successful, false when metadata is invalid. 720b57cec5SDimitry Andric bool verify(msgpack::DocNode &HSAMetadataRoot); 730b57cec5SDimitry Andric }; 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric } // end namespace V3 760b57cec5SDimitry Andric } // end namespace HSAMD 770b57cec5SDimitry Andric } // end namespace AMDGPU 780b57cec5SDimitry Andric } // end namespace llvm 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric #endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H 81