WasmTraits.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //===- WasmTraits.h - DenseMap traits for the Wasm structures ---*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file provides llvm::DenseMapInfo traits for the Wasm structures.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_BINARYFORMAT_WASMTRAITS_H
  13. #define LLVM_BINARYFORMAT_WASMTRAITS_H
  14. #include "llvm/ADT/Hashing.h"
  15. #include "llvm/BinaryFormat/Wasm.h"
  16. namespace llvm {
  17. template <typename T> struct DenseMapInfo;
  18. // Traits for using WasmSignature in a DenseMap.
  19. template <> struct DenseMapInfo<wasm::WasmSignature> {
  20. static wasm::WasmSignature getEmptyKey() {
  21. wasm::WasmSignature Sig;
  22. Sig.State = wasm::WasmSignature::Empty;
  23. return Sig;
  24. }
  25. static wasm::WasmSignature getTombstoneKey() {
  26. wasm::WasmSignature Sig;
  27. Sig.State = wasm::WasmSignature::Tombstone;
  28. return Sig;
  29. }
  30. static unsigned getHashValue(const wasm::WasmSignature &Sig) {
  31. uintptr_t H = hash_value(Sig.State);
  32. for (auto Ret : Sig.Returns)
  33. H = hash_combine(H, Ret);
  34. for (auto Param : Sig.Params)
  35. H = hash_combine(H, Param);
  36. return H;
  37. }
  38. static bool isEqual(const wasm::WasmSignature &LHS,
  39. const wasm::WasmSignature &RHS) {
  40. return LHS == RHS;
  41. }
  42. };
  43. // Traits for using WasmGlobalType in a DenseMap
  44. template <> struct DenseMapInfo<wasm::WasmGlobalType> {
  45. static wasm::WasmGlobalType getEmptyKey() {
  46. return wasm::WasmGlobalType{1, true};
  47. }
  48. static wasm::WasmGlobalType getTombstoneKey() {
  49. return wasm::WasmGlobalType{2, true};
  50. }
  51. static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType) {
  52. return hash_combine(GlobalType.Type, GlobalType.Mutable);
  53. }
  54. static bool isEqual(const wasm::WasmGlobalType &LHS,
  55. const wasm::WasmGlobalType &RHS) {
  56. return LHS == RHS;
  57. }
  58. };
  59. } // end namespace llvm
  60. #endif // LLVM_BINARYFORMAT_WASMTRAITS_H