LLVM  15.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 // Traits for using WasmSignature in a DenseMap.
22 template <> struct DenseMapInfo<wasm::WasmSignature, void> {
26  return Sig;
27  }
31  return Sig;
32  }
33  static unsigned getHashValue(const wasm::WasmSignature &Sig) {
34  uintptr_t H = hash_value(Sig.State);
35  for (auto Ret : Sig.Returns)
36  H = hash_combine(H, Ret);
37  for (auto Param : Sig.Params)
38  H = hash_combine(H, Param);
39  return H;
40  }
41  static bool isEqual(const wasm::WasmSignature &LHS,
42  const wasm::WasmSignature &RHS) {
43  return LHS == RHS;
44  }
45 };
46 
47 // Traits for using WasmGlobalType in a DenseMap
48 template <> struct DenseMapInfo<wasm::WasmGlobalType, void> {
50  return wasm::WasmGlobalType{1, true};
51  }
53  return wasm::WasmGlobalType{2, true};
54  }
55  static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType) {
56  return hash_combine(GlobalType.Type, GlobalType.Mutable);
57  }
58  static bool isEqual(const wasm::WasmGlobalType &LHS,
59  const wasm::WasmGlobalType &RHS) {
60  return LHS == RHS;
61  }
62 };
63 
64 // Traits for using WasmLimits in a DenseMap
65 template <> struct DenseMapInfo<wasm::WasmLimits, void> {
67  return wasm::WasmLimits{0xff, 0xff, 0xff};
68  }
70  return wasm::WasmLimits{0xee, 0xee, 0xee};
71  }
72  static unsigned getHashValue(const wasm::WasmLimits &Limits) {
73  unsigned Hash = hash_value(Limits.Flags);
74  Hash = hash_combine(Hash, Limits.Minimum);
76  Hash = hash_combine(Hash, Limits.Maximum);
77  }
78  return Hash;
79  }
80  static bool isEqual(const wasm::WasmLimits &LHS,
81  const wasm::WasmLimits &RHS) {
82  return LHS == RHS;
83  }
84 };
85 
86 // Traits for using WasmTableType in a DenseMap
87 template <> struct DenseMapInfo<wasm::WasmTableType, void> {
89  return wasm::WasmTableType{
91  }
93  return wasm::WasmTableType{
95  }
96  static unsigned getHashValue(const wasm::WasmTableType &TableType) {
97  return hash_combine(
98  TableType.ElemType,
100  }
101  static bool isEqual(const wasm::WasmTableType &LHS,
102  const wasm::WasmTableType &RHS) {
103  return LHS == RHS;
104  }
105 };
106 
107 } // end namespace llvm
108 
109 #endif // LLVM_BINARYFORMAT_WASMTRAITS_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::wasm::WasmLimits::Minimum
uint64_t Minimum
Definition: Wasm.h:79
llvm::DenseMapInfo< wasm::WasmLimits, void >::isEqual
static bool isEqual(const wasm::WasmLimits &LHS, const wasm::WasmLimits &RHS)
Definition: WasmTraits.h:80
llvm::wasm::WasmSignature::State
enum llvm::wasm::WasmSignature::@176 State
Hashing.h
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::hash_value
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4821
llvm::DenseMapInfo< wasm::WasmGlobalType, void >::isEqual
static bool isEqual(const wasm::WasmGlobalType &LHS, const wasm::WasmGlobalType &RHS)
Definition: WasmTraits.h:58
llvm::DenseMapInfo< wasm::WasmLimits, void >::getTombstoneKey
static wasm::WasmLimits getTombstoneKey()
Definition: WasmTraits.h:69
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::DenseMapInfo
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: APInt.h:34
llvm::wasm::WASM_LIMITS_FLAG_HAS_MAX
@ WASM_LIMITS_FLAG_HAS_MAX
Definition: Wasm.h:324
llvm::DenseMapInfo< wasm::WasmTableType, void >::getHashValue
static unsigned getHashValue(const wasm::WasmTableType &TableType)
Definition: WasmTraits.h:96
llvm::wasm::WasmGlobalType::Mutable
bool Mutable
Definition: Wasm.h:114
llvm::wasm::WasmLimits
Definition: Wasm.h:77
llvm::wasm::WasmTableType::ElemType
uint8_t ElemType
Definition: Wasm.h:84
Param
Value * Param
Definition: NVPTXLowerArgs.cpp:164
llvm::wasm::WasmGlobalType
Definition: Wasm.h:112
llvm::DenseMapInfo< wasm::WasmSignature, void >::getHashValue
static unsigned getHashValue(const wasm::WasmSignature &Sig)
Definition: WasmTraits.h:33
llvm::wasm::WasmSignature::Empty
@ Empty
Definition: Wasm.h:437
llvm::DenseMapInfo< wasm::WasmLimits, void >::getEmptyKey
static wasm::WasmLimits getEmptyKey()
Definition: WasmTraits.h:66
llvm::DenseMapInfo< wasm::WasmTableType, void >::getEmptyKey
static wasm::WasmTableType getEmptyKey()
Definition: WasmTraits.h:88
llvm::wasm::WasmLimits::Flags
uint8_t Flags
Definition: Wasm.h:78
llvm::DenseMapInfo< wasm::WasmGlobalType, void >::getHashValue
static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType)
Definition: WasmTraits.h:55
llvm::wasm::WasmSignature::Tombstone
@ Tombstone
Definition: Wasm.h:437
llvm::wasm::WasmSignature::Returns
SmallVector< ValType, 1 > Returns
Definition: Wasm.h:434
llvm::DenseMapInfo< wasm::WasmGlobalType, void >::getTombstoneKey
static wasm::WasmGlobalType getTombstoneKey()
Definition: WasmTraits.h:52
llvm::DenseMapInfo< wasm::WasmGlobalType, void >::getEmptyKey
static wasm::WasmGlobalType getEmptyKey()
Definition: WasmTraits.h:49
llvm::DenseMapInfo< wasm::WasmSignature, void >::getTombstoneKey
static wasm::WasmSignature getTombstoneKey()
Definition: WasmTraits.h:28
llvm::DenseMapInfo< wasm::WasmLimits, void >::getHashValue
static unsigned getHashValue(const wasm::WasmLimits &Limits)
Definition: WasmTraits.h:72
llvm::wasm::WasmLimits::Maximum
uint64_t Maximum
Definition: Wasm.h:80
llvm::wasm::WasmTableType::Limits
WasmLimits Limits
Definition: Wasm.h:85
llvm::wasm::WasmGlobalType::Type
uint8_t Type
Definition: Wasm.h:113
llvm::DenseMapInfo< wasm::WasmTableType, void >::getTombstoneKey
static wasm::WasmTableType getTombstoneKey()
Definition: WasmTraits.h:92
H
#define H(x, y, z)
Definition: MD5.cpp:57
llvm::DenseMapInfo< wasm::WasmSignature, void >::getEmptyKey
static wasm::WasmSignature getEmptyKey()
Definition: WasmTraits.h:23
llvm::DenseMapInfo< wasm::WasmSignature, void >::isEqual
static bool isEqual(const wasm::WasmSignature &LHS, const wasm::WasmSignature &RHS)
Definition: WasmTraits.h:41
Wasm.h
llvm::DenseMapInfo< wasm::WasmTableType, void >::isEqual
static bool isEqual(const wasm::WasmTableType &LHS, const wasm::WasmTableType &RHS)
Definition: WasmTraits.h:101
llvm::hash_combine
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:605
llvm::wasm::WasmTableType
Definition: Wasm.h:83
llvm::wasm::WasmSignature::Params
SmallVector< ValType, 4 > Params
Definition: Wasm.h:435
llvm::wasm::WasmSignature
Definition: Wasm.h:433