LLVM  9.0.0svn
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_OBJECT_WASMTRAITS_H
14 #define LLVM_OBJECT_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 } // end namespace llvm
67 
68 #endif // LLVM_OBJECT_WASMTRAITS_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
SmallVector< ValType, 1 > Returns
Definition: Wasm.h:336
static wasm::WasmGlobalType getEmptyKey()
Definition: WasmTraits.h:51
SmallVector< ValType, 4 > Params
Definition: Wasm.h:337
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4433
static wasm::WasmGlobalType getTombstoneKey()
Definition: WasmTraits.h:54
#define H(x, y, z)
Definition: MD5.cpp:57
static bool isEqual(const wasm::WasmGlobalType &LHS, const wasm::WasmGlobalType &RHS)
Definition: WasmTraits.h:60
static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType)
Definition: WasmTraits.h:57
static wasm::WasmSignature getEmptyKey()
Definition: WasmTraits.h:25
static unsigned getHashValue(const wasm::WasmSignature &Sig)
Definition: WasmTraits.h:35
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:600
static wasm::WasmSignature getTombstoneKey()
Definition: WasmTraits.h:30
enum llvm::wasm::WasmSignature::@151 State
static bool isEqual(const wasm::WasmSignature &LHS, const wasm::WasmSignature &RHS)
Definition: WasmTraits.h:43