diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-05-11 10:50:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 10:50:11 -0700 |
commit | 91ec2ee5bedefc4736fcda78ae39298846aeeb41 (patch) | |
tree | fd7c34a65f7c2273bad64d93f554a7aedca5be60 | |
parent | 2c30ee408a72f5403fddeba8b4b856437c711727 (diff) | |
download | binaryen-91ec2ee5bedefc4736fcda78ae39298846aeeb41.tar.gz binaryen-91ec2ee5bedefc4736fcda78ae39298846aeeb41.tar.bz2 binaryen-91ec2ee5bedefc4736fcda78ae39298846aeeb41.zip |
Handle throw and rethrow in DCE (#2844)
This adds missing handlings for `throw` and `rethrow` in DCE. They
should set `reachable` variable to `false`, like other branches.
-rw-r--r-- | src/passes/DeadCodeElimination.cpp | 20 | ||||
-rw-r--r-- | test/passes/dce_all-features.txt | 10 | ||||
-rw-r--r-- | test/passes/dce_all-features.wast | 35 |
3 files changed, 57 insertions, 8 deletions
diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp index ebeeca364..400252e8f 100644 --- a/src/passes/DeadCodeElimination.cpp +++ b/src/passes/DeadCodeElimination.cpp @@ -148,14 +148,6 @@ struct DeadCodeElimination reachable = false; } - void visitBrOnExn(BrOnExn* curr) { - if (isDead(curr->exnref)) { - replaceCurrent(curr->exnref); - return; - } - addBreak(curr->name); - } - void visitReturn(Return* curr) { if (isDead(curr->value)) { replaceCurrent(curr->value); @@ -259,6 +251,18 @@ struct DeadCodeElimination typeUpdater.maybeUpdateTypeToUnreachable(curr); } + void visitThrow(Throw* curr) { reachable = false; } + + void visitRethrow(Rethrow* curr) { reachable = false; } + + void visitBrOnExn(BrOnExn* curr) { + if (isDead(curr->exnref)) { + replaceCurrent(curr->exnref); + return; + } + addBreak(curr->name); + } + static void scan(DeadCodeElimination* self, Expression** currp) { auto* curr = *currp; if (!self->reachable) { diff --git a/test/passes/dce_all-features.txt b/test/passes/dce_all-features.txt index 47b2e6cc2..e5af0bff9 100644 --- a/test/passes/dce_all-features.txt +++ b/test/passes/dce_all-features.txt @@ -503,6 +503,7 @@ ) (module (type $none_=>_none (func)) + (event $e (attr 0) (param)) (func $foo (nop) ) @@ -531,6 +532,15 @@ ) ) ) + (func $throw + (throw $e + ) + ) + (func $rethrow + (rethrow + (ref.null) + ) + ) ) (module (type $none_=>_none (func)) diff --git a/test/passes/dce_all-features.wast b/test/passes/dce_all-features.wast index cfdc58bbb..98b2b0ecd 100644 --- a/test/passes/dce_all-features.wast +++ b/test/passes/dce_all-features.wast @@ -739,6 +739,7 @@ ;; reachable (module (func $foo) + (event $e (attr 0)) (func $try_unreachable (try @@ -767,6 +768,40 @@ ) (call $foo) ;; should be dce'd ) + + (func $throw + (drop + (block $label$0 (result nullref) + (if + (i32.clz + (block $label$1 (result i32) + (throw $e) + ) + ) + (nop) + ) + (ref.null) + ) + ) + ) + + (func $rethrow + (drop + (block $label$0 (result nullref) + (if + (i32.clz + (block $label$1 (result i32) + (rethrow + (ref.null) + ) + ) + ) + (nop) + ) + (ref.null) + ) + ) + ) ) ;; Push-pop |