LLVM  14.0.0git
WasmTraits.h
Go to the documentation of this file.
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 
13 #ifndef LLVM_BINARYFORMAT_WASMTRAITS_H
14 #define LLVM_BINARYFORMAT_WASMTRAITS_H
15 
16 #include "llvm/ADT/Hashing.h"
17 #include "llvm/BinaryFormat/Wasm.h"
18 
19 namespace llvm {
20 
21 template <typename T> struct DenseMapInfo;
22 
23 // Traits for using WasmSignature in a DenseMap.
24 template <> struct DenseMapInfo<wasm::WasmSignature> {
28  return Sig;
29  }
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 
49 // Traits for using WasmGlobalType in a DenseMap
50 template <> struct DenseMapInfo<wasm::WasmGlobalType> {
52  return wasm::WasmGlobalType{1, true};
53  }
55  return wasm::WasmGlobalType{2, true};
56  }
57  static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType) {
58  return hash_combine(GlobalType.Type, GlobalType.Mutable);
59  }
60  static bool isEqual(const wasm::WasmGlobalType &LHS,
61  const wasm::WasmGlobalType &RHS) {
62  return LHS == RHS;
63  }
64 };
65 
66 // Traits for using WasmLimits in a DenseMap
67 template <> struct DenseMapInfo<wasm::WasmLimits> {
69  return wasm::WasmLimits{0xff, 0xff, 0xff};
70  }
72  return wasm::WasmLimits{0xee, 0xee, 0xee};
73  }
74  static unsigned getHashValue(const wasm::WasmLimits &Limits) {
75  unsigned Hash = hash_value(Limits.Flags);
76  Hash = hash_combine(Hash, Limits.Minimum);
78  Hash = hash_combine(Hash, Limits.Maximum);
79  }
80  return Hash;
81  }
82  static bool isEqual(const wasm::WasmLimits &LHS,
83  const wasm::WasmLimits &RHS) {
84  return LHS == RHS;
85  }
86 };
87 
88 // Traits for using WasmTableType in a DenseMap
89 template <> struct DenseMapInfo<wasm::WasmTableType> {
91  return wasm::WasmTableType{0,
93  }
95  return wasm::WasmTableType{
97  }
98  static unsigned getHashValue(const wasm::WasmTableType &TableType) {
99  return hash_combine(
100  TableType.ElemType,
102  }
103  static bool isEqual(const wasm::WasmTableType &LHS,
104  const wasm::WasmTableType &RHS) {
105  return LHS == RHS;
106  }
107 };
108 
109 } // end namespace llvm
110 
111 #endif // LLVM_BINARYFORMAT_WASMTRAITS_H
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::DenseMapInfo< wasm::WasmSignature >::getTombstoneKey
static wasm::WasmSignature getTombstoneKey()
Definition: WasmTraits.h:30
llvm::wasm::WasmSignature::Empty
@ Empty
Definition: Wasm.h:424
llvm::wasm::WasmLimits::Minimum
uint64_t Minimum
Definition: Wasm.h:79
llvm::DenseMapInfo< wasm::WasmLimits >::getEmptyKey
static wasm::WasmLimits getEmptyKey()
Definition: WasmTraits.h:68
Hashing.h
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::hash_value
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4821
llvm::DenseMapInfo< wasm::WasmGlobalType >::getEmptyKey
static wasm::WasmGlobalType getEmptyKey()
Definition: WasmTraits.h:51
llvm::DenseMapInfo< wasm::WasmSignature >::getEmptyKey
static wasm::WasmSignature getEmptyKey()
Definition: WasmTraits.h:25
llvm::DenseMapInfo< wasm::WasmLimits >::getTombstoneKey
static wasm::WasmLimits getTombstoneKey()
Definition: WasmTraits.h:71
llvm::DenseMapInfo
Definition: APInt.h:34
llvm::wasm::WasmGlobalType::Mutable
bool Mutable
Definition: Wasm.h:107
llvm::wasm::WasmLimits
Definition: Wasm.h:77
llvm::wasm::WasmTableType::ElemType
uint8_t ElemType
Definition: Wasm.h:84
llvm::DenseMapInfo< wasm::WasmGlobalType >::getTombstoneKey
static wasm::WasmGlobalType getTombstoneKey()
Definition: WasmTraits.h:54
Param
Value * Param
Definition: NVPTXLowerArgs.cpp:163
llvm::wasm::WasmGlobalType
Definition: Wasm.h:105
llvm::DenseMapInfo< wasm::WasmLimits >::isEqual
static bool isEqual(const wasm::WasmLimits &LHS, const wasm::WasmLimits &RHS)
Definition: WasmTraits.h:82
llvm::DenseMapInfo< wasm::WasmSignature >::getHashValue
static unsigned getHashValue(const wasm::WasmSignature &Sig)
Definition: WasmTraits.h:35
llvm::wasm::WasmLimits::Flags
uint8_t Flags
Definition: Wasm.h:78
llvm::DenseMapInfo< wasm::WasmTableType >::isEqual
static bool isEqual(const wasm::WasmTableType &LHS, const wasm::WasmTableType &RHS)
Definition: WasmTraits.h:103
llvm::DenseMapInfo< wasm::WasmLimits >::getHashValue
static unsigned getHashValue(const wasm::WasmLimits &Limits)
Definition: WasmTraits.h:74
llvm::wasm::WasmSignature::Returns
SmallVector< ValType, 1 > Returns
Definition: Wasm.h:421
llvm::DenseMapInfo< wasm::WasmGlobalType >::getHashValue
static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType)
Definition: WasmTraits.h:57
llvm::DenseMapInfo< wasm::WasmGlobalType >::isEqual
static bool isEqual(const wasm::WasmGlobalType &LHS, const wasm::WasmGlobalType &RHS)
Definition: WasmTraits.h:60
llvm::DenseMapInfo< wasm::WasmSignature >::isEqual
static bool isEqual(const wasm::WasmSignature &LHS, const wasm::WasmSignature &RHS)
Definition: WasmTraits.h:43
llvm::DenseMapInfo< wasm::WasmTableType >::getHashValue
static unsigned getHashValue(const wasm::WasmTableType &TableType)
Definition: WasmTraits.h:98
llvm::wasm::WasmLimits::Maximum
uint64_t Maximum
Definition: Wasm.h:80
llvm::wasm::WasmSignature::State
enum llvm::wasm::WasmSignature::@169 State
llvm::wasm::WasmTableType::Limits
WasmLimits Limits
Definition: Wasm.h:85
llvm::wasm::WasmSignature::Tombstone
@ Tombstone
Definition: Wasm.h:424
llvm::wasm::WasmGlobalType::Type
uint8_t Type
Definition: Wasm.h:106
H
#define H(x, y, z)
Definition: MD5.cpp:58
llvm::wasm::WASM_LIMITS_FLAG_HAS_MAX
@ WASM_LIMITS_FLAG_HAS_MAX
Definition: Wasm.h:311
Wasm.h
llvm::hash_combine
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:605
llvm::DenseMapInfo< wasm::WasmTableType >::getTombstoneKey
static wasm::WasmTableType getTombstoneKey()
Definition: WasmTraits.h:94
llvm::DenseMapInfo< wasm::WasmTableType >::getEmptyKey
static wasm::WasmTableType getEmptyKey()
Definition: WasmTraits.h:90
llvm::wasm::WasmTableType
Definition: Wasm.h:83
llvm::wasm::WasmSignature::Params
SmallVector< ValType, 4 > Params
Definition: Wasm.h:422
llvm::wasm::WasmSignature
Definition: Wasm.h:420