From 6cc2bb302d5729c76da42dc0815d6dbba645d952 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 21 Nov 2018 08:59:13 -0800 Subject: Relooper CFG optimizations (#1759) Previously the relooper would do some optimizations when deciding when to use an if vs a switch, how to group blocks, etc. This PR adds an additional pre-optimization phase with some basic but useful simplify-cfg style passes, * Skip empty blocks when they have just one exit. * Merge exiting branches when they are equivalent. * Canonicalize block contents to make such comparisons more useful. * Turn a trivial one-target switch into a simple branch. This can help in noticeable ways when running the rereloop pass, e.g. on LLVM wasm backend output. Also: * Binaryen C API changes to the relooper, which now gets a Module for its constructor. It needs it for the optimizations, as it may construct new nodes. * Many relooper-fuzzer improvements. * Clean up HashType usage. --- src/ir/ExpressionAnalyzer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/ir/ExpressionAnalyzer.cpp') diff --git a/src/ir/ExpressionAnalyzer.cpp b/src/ir/ExpressionAnalyzer.cpp index 44abc2f64..f9b981129 100644 --- a/src/ir/ExpressionAnalyzer.cpp +++ b/src/ir/ExpressionAnalyzer.cpp @@ -305,14 +305,14 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, Expression* right, Expr // hash an expression, ignoring superficial details like specific internal names -uint32_t ExpressionAnalyzer::hash(Expression* curr) { - uint32_t digest = 0; +HashType ExpressionAnalyzer::hash(Expression* curr) { + HashType digest = 0; - auto hash = [&digest](uint32_t hash) { + auto hash = [&digest](HashType hash) { digest = rehash(digest, hash); }; auto hash64 = [&digest](uint64_t hash) { - digest = rehash(rehash(digest, uint32_t(hash >> 32)), uint32_t(hash)); + digest = rehash(rehash(digest, HashType(hash >> 32)), HashType(hash)); }; std::vector nameStack; @@ -498,7 +498,7 @@ uint32_t ExpressionAnalyzer::hash(Expression* curr) { hash(c->type); auto bits = c->value.getBits(); if (getTypeSize(c->type) == 4) { - hash(uint32_t(bits)); + hash(HashType(bits)); } else { hash64(bits); } -- cgit v1.2.3