blob: 049d72f79e4173d55aea93f7a729bd5cebe2a801 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- WasmTraits.h - DenseMap traits for the Wasm structures ---*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides llvm::DenseMapInfo traits for the Wasm structures.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_OBJECT_WASMTRAITS_H
15#define LLVM_OBJECT_WASMTRAITS_H
16
17#include "llvm/ADT/Hashing.h"
18#include "llvm/BinaryFormat/Wasm.h"
19
20namespace llvm {
21
22template <typename T> struct DenseMapInfo;
23
24// Traits for using WasmSignature in a DenseMap.
25template <> struct DenseMapInfo<wasm::WasmSignature> {
26 static wasm::WasmSignature getEmptyKey() {
Andrew Scull0372a572018-11-16 15:47:06 +000027 wasm::WasmSignature Sig;
28 Sig.State = wasm::WasmSignature::Empty;
29 return Sig;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010030 }
31 static wasm::WasmSignature getTombstoneKey() {
Andrew Scull0372a572018-11-16 15:47:06 +000032 wasm::WasmSignature Sig;
33 Sig.State = wasm::WasmSignature::Tombstone;
34 return Sig;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010035 }
36 static unsigned getHashValue(const wasm::WasmSignature &Sig) {
Andrew Scull0372a572018-11-16 15:47:06 +000037 uintptr_t H = hash_value(Sig.State);
38 for (auto Ret : Sig.Returns)
39 H = hash_combine(H, Ret);
40 for (auto Param : Sig.Params)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010041 H = hash_combine(H, Param);
42 return H;
43 }
44 static bool isEqual(const wasm::WasmSignature &LHS,
45 const wasm::WasmSignature &RHS) {
46 return LHS == RHS;
47 }
48};
49
50// Traits for using WasmGlobalType in a DenseMap
51template <> struct DenseMapInfo<wasm::WasmGlobalType> {
52 static wasm::WasmGlobalType getEmptyKey() {
53 return wasm::WasmGlobalType{1, true};
54 }
55 static wasm::WasmGlobalType getTombstoneKey() {
56 return wasm::WasmGlobalType{2, true};
57 }
58 static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType) {
59 return hash_combine(GlobalType.Type, GlobalType.Mutable);
60 }
61 static bool isEqual(const wasm::WasmGlobalType &LHS,
62 const wasm::WasmGlobalType &RHS) {
63 return LHS == RHS;
64 }
65};
66
67} // end namespace llvm
68
69#endif // LLVM_OBJECT_WASMTRAITS_H