AMDGPUMetadataVerifier.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/None.h"
  23. #include "llvm/ADT/Optional.h"
  24. #include "llvm/ADT/STLFunctionalExtras.h"
  25. #include "llvm/ADT/StringRef.h"
  26. #include "llvm/BinaryFormat/MsgPackReader.h"
  27. #include <cstddef>
  28. namespace llvm {
  29. namespace msgpack {
  30. class DocNode;
  31. class MapDocNode;
  32. }
  33. namespace AMDGPU {
  34. namespace HSAMD {
  35. namespace V3 {
  36. /// Verifier for AMDGPU HSA metadata.
  37. ///
  38. /// Operates in two modes:
  39. ///
  40. /// In strict mode, metadata must already be well-typed.
  41. ///
  42. /// In non-strict mode, metadata is coerced into expected types when possible.
  43. class MetadataVerifier {
  44. bool Strict;
  45. bool verifyScalar(msgpack::DocNode &Node, msgpack::Type SKind,
  46. function_ref<bool(msgpack::DocNode &)> verifyValue = {});
  47. bool verifyInteger(msgpack::DocNode &Node);
  48. bool verifyArray(msgpack::DocNode &Node,
  49. function_ref<bool(msgpack::DocNode &)> verifyNode,
  50. Optional<size_t> Size = None);
  51. bool verifyEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
  52. function_ref<bool(msgpack::DocNode &)> verifyNode);
  53. bool
  54. verifyScalarEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
  55. msgpack::Type SKind,
  56. function_ref<bool(msgpack::DocNode &)> verifyValue = {});
  57. bool verifyIntegerEntry(msgpack::MapDocNode &MapNode, StringRef Key,
  58. bool Required);
  59. bool verifyKernelArgs(msgpack::DocNode &Node);
  60. bool verifyKernel(msgpack::DocNode &Node);
  61. public:
  62. /// Construct a MetadataVerifier, specifying whether it will operate in \p
  63. /// Strict mode.
  64. MetadataVerifier(bool Strict) : Strict(Strict) {}
  65. /// Verify given HSA metadata.
  66. ///
  67. /// \returns True when successful, false when metadata is invalid.
  68. bool verify(msgpack::DocNode &HSAMetadataRoot);
  69. };
  70. } // end namespace V3
  71. } // end namespace HSAMD
  72. } // end namespace AMDGPU
  73. } // end namespace llvm
  74. #endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
  75. #ifdef __GNUC__
  76. #pragma GCC diagnostic pop
  77. #endif