1 //===- WasmTraits.h - DenseMap traits for the Wasm structures ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file provides llvm::DenseMapInfo traits for the Wasm structures.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_OBJECT_WASMTRAITS_H
14 #define LLVM_OBJECT_WASMTRAITS_H
16 #include "llvm/ADT/Hashing.h"
17 #include "llvm/BinaryFormat/Wasm.h"
21 template <typename T
> struct DenseMapInfo
;
23 // Traits for using WasmSignature in a DenseMap.
24 template <> struct DenseMapInfo
<wasm::WasmSignature
> {
25 static wasm::WasmSignature
getEmptyKey() {
26 wasm::WasmSignature Sig
;
27 Sig
.State
= wasm::WasmSignature::Empty
;
30 static wasm::WasmSignature
getTombstoneKey() {
31 wasm::WasmSignature Sig
;
32 Sig
.State
= wasm::WasmSignature::Tombstone
;
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
);
43 static bool isEqual(const wasm::WasmSignature
&LHS
,
44 const wasm::WasmSignature
&RHS
) {
49 // Traits for using WasmGlobalType in a DenseMap
50 template <> struct DenseMapInfo
<wasm::WasmGlobalType
> {
51 static wasm::WasmGlobalType
getEmptyKey() {
52 return wasm::WasmGlobalType
{1, true};
54 static wasm::WasmGlobalType
getTombstoneKey() {
55 return wasm::WasmGlobalType
{2, true};
57 static unsigned getHashValue(const wasm::WasmGlobalType
&GlobalType
) {
58 return hash_combine(GlobalType
.Type
, GlobalType
.Mutable
);
60 static bool isEqual(const wasm::WasmGlobalType
&LHS
,
61 const wasm::WasmGlobalType
&RHS
) {
66 } // end namespace llvm
68 #endif // LLVM_OBJECT_WASMTRAITS_H