WasmTraits.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- WasmTraits.h - DenseMap traits for the Wasm structures ---*- 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. // This file provides llvm::DenseMapInfo traits for the Wasm structures.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_BINARYFORMAT_WASMTRAITS_H
  18. #define LLVM_BINARYFORMAT_WASMTRAITS_H
  19. #include "llvm/ADT/Hashing.h"
  20. #include "llvm/BinaryFormat/Wasm.h"
  21. namespace llvm {
  22. template <typename T> struct DenseMapInfo;
  23. // Traits for using WasmSignature in a DenseMap.
  24. template <> struct DenseMapInfo<wasm::WasmSignature> {
  25. static wasm::WasmSignature getEmptyKey() {
  26. wasm::WasmSignature Sig;
  27. Sig.State = wasm::WasmSignature::Empty;
  28. return Sig;
  29. }
  30. static wasm::WasmSignature getTombstoneKey() {
  31. wasm::WasmSignature Sig;
  32. Sig.State = wasm::WasmSignature::Tombstone;
  33. return Sig;
  34. }
  35. static unsigned getHashValue(const wasm::WasmSignature &Sig) {
  36. uintptr_t H = hash_value(Sig.State);
  37. for (auto Ret : Sig.Returns)
  38. H = hash_combine(H, Ret);
  39. for (auto Param : Sig.Params)
  40. H = hash_combine(H, Param);
  41. return H;
  42. }
  43. static bool isEqual(const wasm::WasmSignature &LHS,
  44. const wasm::WasmSignature &RHS) {
  45. return LHS == RHS;
  46. }
  47. };
  48. // Traits for using WasmGlobalType in a DenseMap
  49. template <> struct DenseMapInfo<wasm::WasmGlobalType> {
  50. static wasm::WasmGlobalType getEmptyKey() {
  51. return wasm::WasmGlobalType{1, true};
  52. }
  53. static wasm::WasmGlobalType getTombstoneKey() {
  54. return wasm::WasmGlobalType{2, true};
  55. }
  56. static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType) {
  57. return hash_combine(GlobalType.Type, GlobalType.Mutable);
  58. }
  59. static bool isEqual(const wasm::WasmGlobalType &LHS,
  60. const wasm::WasmGlobalType &RHS) {
  61. return LHS == RHS;
  62. }
  63. };
  64. } // end namespace llvm
  65. #endif // LLVM_BINARYFORMAT_WASMTRAITS_H
  66. #ifdef __GNUC__
  67. #pragma GCC diagnostic pop
  68. #endif