summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2020-02-26 18:20:24 -0800
committerGitHub <noreply@github.com>2020-02-26 18:20:24 -0800
commitf79faeb14e4da75f131c00c26796ae25ee96a7b7 (patch)
tree5b954daf160f83ae8227520055fb5b32fc1272f3 /test
parentb17e84b491a309c9f15e7a502f115ece19404b11 (diff)
downloadbinaryen-f79faeb14e4da75f131c00c26796ae25ee96a7b7.tar.gz
binaryen-f79faeb14e4da75f131c00c26796ae25ee96a7b7.tar.bz2
binaryen-f79faeb14e4da75f131c00c26796ae25ee96a7b7.zip
Add EH support for CodeFolding (#2665)
This does two things: - Treats the target branch of `br_on_exn` as unoptimizables, because it is a conditional branch. - Makes sure we don't move expressions that contain `exnref.pop`, which should follow right after `catch`. - Adds `containsChild` utility function, which can search all children, optionally with limited depth. This was actually added to be used in CodeFolding but ended up not being used, but wasn't removed in case there will be uses later.
Diffstat (limited to 'test')
-rw-r--r--test/passes/remove-unused-names_code-folding_all-features.txt (renamed from test/passes/remove-unused-names_code-folding.txt)75
-rw-r--r--test/passes/remove-unused-names_code-folding_all-features.wast (renamed from test/passes/remove-unused-names_code-folding.wast)50
2 files changed, 125 insertions, 0 deletions
diff --git a/test/passes/remove-unused-names_code-folding.txt b/test/passes/remove-unused-names_code-folding_all-features.txt
index 93f503579..2aa40da24 100644
--- a/test/passes/remove-unused-names_code-folding.txt
+++ b/test/passes/remove-unused-names_code-folding_all-features.txt
@@ -3,6 +3,7 @@
(type $none_=>_i32 (func (result i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
+ (event $e (attr 0) (param))
(func $ifs (; 0 ;)
(if
(i32.const 0)
@@ -1708,4 +1709,78 @@
(i32.const 2)
)
)
+ (func $exnref_pop_test (; 36 ;)
+ (local $exn exnref)
+ (block $folding-inner0
+ (try
+ (try
+ (nop)
+ (catch
+ (local.set $exn
+ (exnref.pop)
+ )
+ (br $folding-inner0)
+ )
+ )
+ (catch
+ (local.set $exn
+ (exnref.pop)
+ )
+ (br $folding-inner0)
+ )
+ )
+ (return)
+ )
+ (drop
+ (i32.const 111)
+ )
+ (drop
+ (i32.const 222)
+ )
+ (drop
+ (i32.const 333)
+ )
+ (unreachable)
+ )
+ (func $br_on_exn_target_block (; 37 ;)
+ (local $exn exnref)
+ (block $x
+ (if
+ (i32.const 0)
+ (block
+ (drop
+ (i32.const 1)
+ )
+ (drop
+ (i32.const 2)
+ )
+ (br $x)
+ )
+ )
+ (if
+ (i32.const 0)
+ (block
+ (drop
+ (i32.const 1)
+ )
+ (drop
+ (i32.const 2)
+ )
+ (br $x)
+ )
+ )
+ (drop
+ (br_on_exn $x $e
+ (local.get $exn)
+ )
+ )
+ (drop
+ (i32.const 1)
+ )
+ (drop
+ (i32.const 2)
+ )
+ (br $x)
+ )
+ )
)
diff --git a/test/passes/remove-unused-names_code-folding.wast b/test/passes/remove-unused-names_code-folding_all-features.wast
index 9979a0a3c..ad803864e 100644
--- a/test/passes/remove-unused-names_code-folding.wast
+++ b/test/passes/remove-unused-names_code-folding_all-features.wast
@@ -1191,4 +1191,54 @@
)
)
)
+
+ (func $exnref_pop_test (local $exn exnref)
+ (try
+ (try
+ (catch
+ ;; Expressions containing exnref.pop should NOT be taken out and
+ ;; folded.
+ (local.set $exn (exnref.pop))
+ (drop (i32.const 111))
+ (drop (i32.const 222))
+ (drop (i32.const 333))
+ (unreachable)
+ )
+ )
+ (catch
+ (local.set $exn (exnref.pop))
+ (drop (i32.const 111))
+ (drop (i32.const 222))
+ (drop (i32.const 333))
+ (unreachable)
+ )
+ )
+ )
+
+ (event $e (attr 0)) ;; exception with no param
+ (func $br_on_exn_target_block (local $exn exnref)
+ ;; Here this block $x is targeted by br_on_exn, so code folding out of this
+ ;; block should NOT happen.
+ (block $x
+ (if (i32.const 0)
+ (block
+ (drop (i32.const 1))
+ (drop (i32.const 2))
+ (br $x)
+ )
+ )
+ (if (i32.const 0)
+ (block
+ (drop (i32.const 1))
+ (drop (i32.const 2))
+ (br $x)
+ )
+ )
+ (drop (br_on_exn $x $e (local.get $exn)))
+ ;; no fallthrough, another thing to merge
+ (drop (i32.const 1))
+ (drop (i32.const 2))
+ (br $x)
+ )
+ )
)