AMDGPUMetadataVerifier.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// \file
  15. /// This is a verifier for AMDGPU HSA metadata, which can verify both
  16. /// well-typed metadata and untyped metadata. When verifying in the non-strict
  17. /// mode, untyped metadata is coerced into the correct type if possible.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
  21. #define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
  22. #include "llvm/ADT/STLFunctionalExtras.h"
  23. #include "llvm/ADT/StringRef.h"
  24. #include "llvm/BinaryFormat/MsgPackReader.h"
  25. #include <cstddef>
  26. #include <optional>
  27. namespace llvm {
  28. namespace msgpack {
  29. class DocNode;
  30. class MapDocNode;
  31. }
  32. namespace AMDGPU {
  33. namespace HSAMD {
  34. namespace V3 {
  35. /// Verifier for AMDGPU HSA metadata.
  36. ///
  37. /// Operates in two modes:
  38. ///
  39. /// In strict mode, metadata must already be well-typed.
  40. ///
  41. /// In non-strict mode, metadata is coerced into expected types when possible.
  42. class MetadataVerifier {
  43. bool Strict;
  44. bool verifyScalar(msgpack::DocNode &Node, msgpack::Type SKind,
  45. function_ref<bool(msgpack::DocNode &)> verifyValue = {});
  46. bool verifyInteger(msgpack::DocNode &Node);
  47. bool verifyArray(msgpack::DocNode &Node,
  48. function_ref<bool(msgpack::DocNode &)> verifyNode,
  49. std::optional<size_t> Size = std::nullopt);
  50. bool verifyEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
  51. function_ref<bool(msgpack::DocNode &)> verifyNode);
  52. bool
  53. verifyScalarEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
  54. msgpack::Type SKind,
  55. function_ref<bool(msgpack::DocNode &)> verifyValue = {});
  56. bool verifyIntegerEntry(msgpack::MapDocNode &MapNode, StringRef Key,
  57. bool Required);
  58. bool verifyKernelArgs(msgpack::DocNode &Node);
  59. bool verifyKernel(msgpack::DocNode &Node);
  60. public:
  61. /// Construct a MetadataVerifier, specifying whether it will operate in \p
  62. /// Strict mode.
  63. MetadataVerifier(bool Strict) : Strict(Strict) {}
  64. /// Verify given HSA metadata.
  65. ///
  66. /// \returns True when successful, false when metadata is invalid.
  67. bool verify(msgpack::DocNode &HSAMetadataRoot);
  68. };
  69. } // end namespace V3
  70. } // end namespace HSAMD
  71. } // end namespace AMDGPU
  72. } // end namespace llvm
  73. #endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
  74. #ifdef __GNUC__
  75. #pragma GCC diagnostic pop
  76. #endif