LLVM 18.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"
18
19namespace llvm {
20
21// Traits for using WasmSignature in a DenseMap.
22template <> 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
48template <> 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,
60 return LHS == RHS;
61 }
62};
63
64// Traits for using WasmLimits in a DenseMap
65template <> 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
87template <> struct DenseMapInfo<wasm::WasmTableType, void> {
91 }
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
#define H(x, y, z)
Definition: MD5.cpp:57
Value * RHS
Value * LHS
@ WASM_LIMITS_FLAG_HAS_MAX
Definition: Wasm.h:325
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:128
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:613
static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType)
Definition: WasmTraits.h:55
static bool isEqual(const wasm::WasmGlobalType &LHS, const wasm::WasmGlobalType &RHS)
Definition: WasmTraits.h:58
static wasm::WasmGlobalType getTombstoneKey()
Definition: WasmTraits.h:52
static wasm::WasmGlobalType getEmptyKey()
Definition: WasmTraits.h:49
static wasm::WasmLimits getTombstoneKey()
Definition: WasmTraits.h:69
static wasm::WasmLimits getEmptyKey()
Definition: WasmTraits.h:66
static bool isEqual(const wasm::WasmLimits &LHS, const wasm::WasmLimits &RHS)
Definition: WasmTraits.h:80
static unsigned getHashValue(const wasm::WasmLimits &Limits)
Definition: WasmTraits.h:72
static bool isEqual(const wasm::WasmSignature &LHS, const wasm::WasmSignature &RHS)
Definition: WasmTraits.h:41
static wasm::WasmSignature getTombstoneKey()
Definition: WasmTraits.h:28
static wasm::WasmSignature getEmptyKey()
Definition: WasmTraits.h:23
static unsigned getHashValue(const wasm::WasmSignature &Sig)
Definition: WasmTraits.h:33
static unsigned getHashValue(const wasm::WasmTableType &TableType)
Definition: WasmTraits.h:96
static wasm::WasmTableType getEmptyKey()
Definition: WasmTraits.h:88
static wasm::WasmTableType getTombstoneKey()
Definition: WasmTraits.h:92
static bool isEqual(const wasm::WasmTableType &LHS, const wasm::WasmTableType &RHS)
Definition: WasmTraits.h:101
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:50
uint64_t Minimum
Definition: Wasm.h:79
uint64_t Maximum
Definition: Wasm.h:80
enum llvm::wasm::WasmSignature::@183 State
SmallVector< ValType, 1 > Returns
Definition: Wasm.h:436
SmallVector< ValType, 4 > Params
Definition: Wasm.h:437
WasmLimits Limits
Definition: Wasm.h:85