blob: 3eee8e71b1876ad9a0aab7b96363d1e8e52eda8e [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- WasmTraits.h - DenseMap traits for the Wasm structures ---*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
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
19namespace llvm {
20
21template <typename T> struct DenseMapInfo;
22
23// Traits for using WasmSignature in a DenseMap.
24template <> struct DenseMapInfo<wasm::WasmSignature> {
25 static wasm::WasmSignature getEmptyKey() {
Andrew Scull0372a572018-11-16 15:47:06 +000026 wasm::WasmSignature Sig;
27 Sig.State = wasm::WasmSignature::Empty;
28 return Sig;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010029 }
30 static wasm::WasmSignature getTombstoneKey() {
Andrew Scull0372a572018-11-16 15:47:06 +000031 wasm::WasmSignature Sig;
32 Sig.State = wasm::WasmSignature::Tombstone;
33 return Sig;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010034 }
35 static unsigned getHashValue(const wasm::WasmSignature &Sig) {
Andrew Scull0372a572018-11-16 15:47:06 +000036 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)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010040 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
50template <> struct DenseMapInfo<wasm::WasmGlobalType> {
51 static wasm::WasmGlobalType getEmptyKey() {
52 return wasm::WasmGlobalType{1, true};
53 }
54 static wasm::WasmGlobalType getTombstoneKey() {
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