diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-08-13 02:48:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 17:48:52 -0700 |
commit | 902469769dee0a3f61e7e5aaca597d3cbac139ad (patch) | |
tree | 024c9e010e9a1d406632994df747a1657eff937a /src/cfg | |
parent | f067a45c1e88124173af992e66a7125fe6ab366a (diff) | |
download | binaryen-902469769dee0a3f61e7e5aaca597d3cbac139ad.tar.gz binaryen-902469769dee0a3f61e7e5aaca597d3cbac139ad.tar.bz2 binaryen-902469769dee0a3f61e7e5aaca597d3cbac139ad.zip |
Refactor hashing (#3023)
* Unifies internal hashing helpers to naturally integrate with std::hash
* Removes the previous custom implementation
* Computed hashes are now always size_t
* Introduces a hash_combine helper
* Fixes an overwritten partial hash in Relooper.cpp
Diffstat (limited to 'src/cfg')
-rw-r--r-- | src/cfg/Relooper.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/cfg/Relooper.cpp b/src/cfg/Relooper.cpp index 0c9b581bd..b3bbe0153 100644 --- a/src/cfg/Relooper.cpp +++ b/src/cfg/Relooper.cpp @@ -669,8 +669,7 @@ struct Optimizer : public RelooperRecursor { std::cout << "at parent " << ParentBlock->Id << '\n'; #endif if (ParentBlock->BranchesOut.size() >= 2) { - std::unordered_map<wasm::HashType, std::vector<BranchBlock>> - HashedBranchesOut; + std::unordered_map<size_t, std::vector<BranchBlock>> HashedBranchesOut; std::vector<Block*> BlocksToErase; for (auto& iter : ParentBlock->BranchesOut) { Block* CurrBlock = iter.first; @@ -999,41 +998,42 @@ private: // (like Shapes). Only partially hashes the branches out, no // recursion: hashes the branch infos, looks at raw pointers // for the blocks. - wasm::HashType Hash(Block* Curr) { - wasm::HashType Ret = wasm::ExpressionAnalyzer::hash(Curr->Code); - Ret = wasm::rehash(Ret, 1); + size_t Hash(Block* Curr) { + auto digest = wasm::ExpressionAnalyzer::hash(Curr->Code); + wasm::rehash(digest, uint8_t(1)); if (Curr->SwitchCondition) { - Ret = wasm::ExpressionAnalyzer::hash(Curr->SwitchCondition); + wasm::hash_combine(digest, + wasm::ExpressionAnalyzer::hash(Curr->SwitchCondition)); } - Ret = wasm::rehash(Ret, 2); + wasm::rehash(digest, uint8_t(2)); for (auto& Pair : Curr->BranchesOut) { // Hash the Block* as a pointer TODO: full hash? - Ret = - wasm::rehash(Ret, wasm::HashType(reinterpret_cast<size_t>(Pair.first))); + wasm::rehash(digest, reinterpret_cast<size_t>(Pair.first)); // Hash the Branch info properly - Ret = wasm::rehash(Ret, Hash(Pair.second)); + wasm::hash_combine(digest, Hash(Pair.second)); } - return Ret; + return digest; } // Hashes the direct block contents, but not Relooper internals // (like Shapes). - wasm::HashType Hash(Branch* Curr) { - wasm::HashType Ret = 0; + size_t Hash(Branch* Curr) { + auto digest = wasm::hash(0); if (Curr->SwitchValues) { for (auto i : *Curr->SwitchValues) { - Ret = wasm::rehash(Ret, i); // TODO hash i + wasm::rehash(digest, i); // TODO hash i } } else { if (Curr->Condition) { - Ret = wasm::ExpressionAnalyzer::hash(Curr->Condition); + wasm::hash_combine(digest, + wasm::ExpressionAnalyzer::hash(Curr->Condition)); } } - Ret = wasm::rehash(Ret, 1); + wasm::rehash(digest, uint8_t(1)); if (Curr->Code) { - Ret = wasm::ExpressionAnalyzer::hash(Curr->Code); + wasm::hash_combine(digest, wasm::ExpressionAnalyzer::hash(Curr->Code)); } - return Ret; + return digest; } }; |