File indexing completed on 2026-05-10 08:43:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_BINARYFORMAT_WASMTRAITS_H
0014 #define LLVM_BINARYFORMAT_WASMTRAITS_H
0015
0016 #include "llvm/ADT/Hashing.h"
0017 #include "llvm/BinaryFormat/Wasm.h"
0018
0019 namespace llvm {
0020
0021
0022 template <> struct DenseMapInfo<wasm::WasmSignature, void> {
0023 static wasm::WasmSignature getEmptyKey() {
0024 wasm::WasmSignature Sig;
0025 Sig.State = wasm::WasmSignature::Empty;
0026 return Sig;
0027 }
0028 static wasm::WasmSignature getTombstoneKey() {
0029 wasm::WasmSignature Sig;
0030 Sig.State = wasm::WasmSignature::Tombstone;
0031 return Sig;
0032 }
0033 static unsigned getHashValue(const wasm::WasmSignature &Sig) {
0034 uintptr_t H = hash_value(Sig.State);
0035 for (auto Ret : Sig.Returns)
0036 H = hash_combine(H, Ret);
0037 for (auto Param : Sig.Params)
0038 H = hash_combine(H, Param);
0039 return H;
0040 }
0041 static bool isEqual(const wasm::WasmSignature &LHS,
0042 const wasm::WasmSignature &RHS) {
0043 return LHS == RHS;
0044 }
0045 };
0046
0047
0048 template <> struct DenseMapInfo<wasm::WasmGlobalType, void> {
0049 static wasm::WasmGlobalType getEmptyKey() {
0050 return wasm::WasmGlobalType{1, true};
0051 }
0052 static wasm::WasmGlobalType getTombstoneKey() {
0053 return wasm::WasmGlobalType{2, true};
0054 }
0055 static unsigned getHashValue(const wasm::WasmGlobalType &GlobalType) {
0056 return hash_combine(GlobalType.Type, GlobalType.Mutable);
0057 }
0058 static bool isEqual(const wasm::WasmGlobalType &LHS,
0059 const wasm::WasmGlobalType &RHS) {
0060 return LHS == RHS;
0061 }
0062 };
0063
0064
0065 template <> struct DenseMapInfo<wasm::WasmLimits, void> {
0066 static wasm::WasmLimits getEmptyKey() {
0067 return wasm::WasmLimits{0xff, 0xff, 0xff};
0068 }
0069 static wasm::WasmLimits getTombstoneKey() {
0070 return wasm::WasmLimits{0xee, 0xee, 0xee};
0071 }
0072 static unsigned getHashValue(const wasm::WasmLimits &Limits) {
0073 unsigned Hash = hash_value(Limits.Flags);
0074 Hash = hash_combine(Hash, Limits.Minimum);
0075 if (Limits.Flags & llvm::wasm::WASM_LIMITS_FLAG_HAS_MAX) {
0076 Hash = hash_combine(Hash, Limits.Maximum);
0077 }
0078 return Hash;
0079 }
0080 static bool isEqual(const wasm::WasmLimits &LHS,
0081 const wasm::WasmLimits &RHS) {
0082 return LHS == RHS;
0083 }
0084 };
0085
0086
0087 template <> struct DenseMapInfo<wasm::WasmTableType, void> {
0088 static wasm::WasmTableType getEmptyKey() {
0089 return wasm::WasmTableType{
0090 wasm::ValType(0), DenseMapInfo<wasm::WasmLimits, void>::getEmptyKey()};
0091 }
0092 static wasm::WasmTableType getTombstoneKey() {
0093 return wasm::WasmTableType{
0094 wasm::ValType(1),
0095 DenseMapInfo<wasm::WasmLimits, void>::getTombstoneKey()};
0096 }
0097 static unsigned getHashValue(const wasm::WasmTableType &TableType) {
0098 return hash_combine(
0099 TableType.ElemType,
0100 DenseMapInfo<wasm::WasmLimits, void>::getHashValue(TableType.Limits));
0101 }
0102 static bool isEqual(const wasm::WasmTableType &LHS,
0103 const wasm::WasmTableType &RHS) {
0104 return LHS == RHS;
0105 }
0106 };
0107
0108 }
0109
0110 #endif