diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-05-18 10:47:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-18 10:47:23 -0700 |
commit | 9c6b8e0f626ade30cee113294019edbdbf29dd36 (patch) | |
tree | da088ba8eef1d3d20f1f0e9fa3b5af2c8dbeba1d /src/passes/MergeBlocks.cpp | |
parent | bb1c44a3f975bf8fb72216b9c04bcd34e31bd815 (diff) | |
download | binaryen-9c6b8e0f626ade30cee113294019edbdbf29dd36.tar.gz binaryen-9c6b8e0f626ade30cee113294019edbdbf29dd36.tar.bz2 binaryen-9c6b8e0f626ade30cee113294019edbdbf29dd36.zip |
Validate finalization (#1014)
* validate that types are properly finalized, when in pass-debug mode (BINARYEN_PASS_DEBUG env var): check after each pass is run that the type of each node is equal to the proper type (when finalizing it, i.e., fully recomputing the type).
* fix many fuzz bugs found by that.
* in particular, fix dce bugs with type changes not being fully updated during code removal. add a new TypeUpdater helper class that lets a pass update types efficiently, by the helper tracking deps between blocks and branches etc., and updating/propagating type changes only as necessary.
Diffstat (limited to 'src/passes/MergeBlocks.cpp')
-rw-r--r-- | src/passes/MergeBlocks.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp index 494bf5a9e..37ada0174 100644 --- a/src/passes/MergeBlocks.cpp +++ b/src/passes/MergeBlocks.cpp @@ -169,6 +169,7 @@ static void optimizeBlock(Block* curr, Module* module) { // we can do it! // reuse the drop drop->value = child->list.back(); + drop->finalize(); child->list.back() = drop; child->finalize(); curr->list[i] = child; @@ -223,10 +224,17 @@ struct MergeBlocks : public WalkerPass<PostWalker<MergeBlocks>> { if (auto* block = child->dynCast<Block>()) { if (!block->name.is() && block->list.size() >= 2) { child = block->list.back(); + // we modified child )which is *&), which modifies curr, which might change its type + // (e.g. (drop (block i32 .. (unreachable))) + // the child was a block of i32, and is being replaced with an unreachable, so the + // parent will likely need to be unreachable too + auto oldType = curr->type; + ReFinalize().walk(curr); if (outer == nullptr) { // reuse the block, move it out block->list.back() = curr; - block->finalize(); // last block element was our input, and is now our output, which may differ TODO optimize + // we want the block outside to have the same type as curr had + block->finalize(oldType); replaceCurrent(block); return block; } else { @@ -264,7 +272,16 @@ struct MergeBlocks : public WalkerPass<PostWalker<MergeBlocks>> { } void visitSelect(Select* curr) { - optimize(curr, curr->condition, optimize(curr, curr->ifFalse, optimize(curr, curr->ifTrue), &curr->ifTrue), &curr->ifTrue, &curr->ifFalse); + Block* outer = nullptr; + outer = optimize(curr, curr->ifTrue, outer); + if (EffectAnalyzer(getPassOptions(), curr->ifTrue).hasSideEffects()) return; + outer = optimize(curr, curr->ifFalse, outer); + if (EffectAnalyzer(getPassOptions(), curr->ifFalse).hasSideEffects()) return; + /* . */ optimize(curr, curr->condition, outer); + } + + void visitDrop(Drop* curr) { + optimize(curr, curr->value); } void visitBreak(Break* curr) { |