summaryrefslogtreecommitdiff
path: root/src/ir/possible-contents.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-09-28 16:01:58 -0700
committerGitHub <noreply@github.com>2022-09-28 23:01:58 +0000
commite74a63076b7c21bd45f5156fc028d41db8aa5eb0 (patch)
treeb54ce00a756c2483226ce4429866a9c13d218976 /src/ir/possible-contents.h
parente8915d2a0f8ab592d5da2d572c971a65b753c87c (diff)
downloadbinaryen-e74a63076b7c21bd45f5156fc028d41db8aa5eb0.tar.gz
binaryen-e74a63076b7c21bd45f5156fc028d41db8aa5eb0.tar.bz2
binaryen-e74a63076b7c21bd45f5156fc028d41db8aa5eb0.zip
[GUFA] Improve hashing (#5091)
Avoid manually doing bitshifts etc. - leave combining to the core hash logic, which can do a better job.
Diffstat (limited to 'src/ir/possible-contents.h')
-rw-r--r--src/ir/possible-contents.h21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/ir/possible-contents.h b/src/ir/possible-contents.h
index f7c39e1f9..863a0dbab 100644
--- a/src/ir/possible-contents.h
+++ b/src/ir/possible-contents.h
@@ -21,6 +21,7 @@
#include "ir/possible-constant.h"
#include "ir/subtypes.h"
+#include "support/hash.h"
#include "support/small_vector.h"
#include "wasm-builder.h"
#include "wasm.h"
@@ -213,23 +214,21 @@ public:
}
size_t hash() const {
- // Encode this using three bits for the variant type, then the rest of the
- // contents.
- if (isNone()) {
- return 0;
+ // First hash the index of the variant, then add the internals for each.
+ size_t ret = std::hash<size_t>()(value.index());
+ if (isNone() || isMany()) {
+ // Nothing to add.
} else if (isLiteral()) {
- return size_t(1) | (std::hash<Literal>()(getLiteral()) << 3);
+ rehash(ret, getLiteral());
} else if (isGlobal()) {
- return size_t(2) | (std::hash<Name>()(getGlobal()) << 3);
+ rehash(ret, getGlobal());
} else if (auto* coneType = std::get_if<ConeType>(&value)) {
- return size_t(3) | ((std::hash<std::pair<Type, Index>>{}(
- {coneType->type, coneType->depth}))
- << 3);
- } else if (isMany()) {
- return 4;
+ rehash(ret, coneType->type);
+ rehash(ret, coneType->depth);
} else {
WASM_UNREACHABLE("bad variant");
}
+ return ret;
}
void dump(std::ostream& o, Module* wasm = nullptr) const {