summaryrefslogtreecommitdiff
path: root/test/passes/spill-pointers.wast
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-06-06 13:24:11 -0700
committerGitHub <noreply@github.com>2022-06-06 13:24:11 -0700
commitec88ea6df0925ae0e648b26d327239e946de48a6 (patch)
tree78b92a32e971025e370c8cdbcfcd0538b540c33e /test/passes/spill-pointers.wast
parentb6040f5834c9ab7d52fc257cd65f3384304a73cf (diff)
downloadbinaryen-ec88ea6df0925ae0e648b26d327239e946de48a6.tar.gz
binaryen-ec88ea6df0925ae0e648b26d327239e946de48a6.tar.bz2
binaryen-ec88ea6df0925ae0e648b26d327239e946de48a6.zip
Restore and fix SpillPointers pass (#4570)
We have some possible use cases for this pass, and so are restoring it. This reverts the removal in #3261, fixes compile errors in internal API changes since then, and flips the direction of the stack for the wasm backend.
Diffstat (limited to 'test/passes/spill-pointers.wast')
-rw-r--r--test/passes/spill-pointers.wast338
1 files changed, 338 insertions, 0 deletions
diff --git a/test/passes/spill-pointers.wast b/test/passes/spill-pointers.wast
new file mode 100644
index 000000000..4eb05a721
--- /dev/null
+++ b/test/passes/spill-pointers.wast
@@ -0,0 +1,338 @@
+(module
+ (memory 10)
+ (type $ii (func (param i32 i32)))
+ (table 1 1 funcref)
+ (elem (i32.const 0))
+ (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32))
+ (import "env" "segfault" (func $segfault (param i32)))
+ (global $stack_ptr (mut i32) (global.get $STACKTOP$asm2wasm$import))
+
+ (func $nothing
+ )
+ (func $not-alive
+ (local $x i32)
+ (local.set $x (i32.const 1))
+ (call $nothing)
+ )
+ (func $spill
+ (local $x i32)
+ (call $nothing)
+ (drop (local.get $x))
+ )
+ (func $ignore-non-pointers
+ (local $x i32)
+ (local $y i64)
+ (local $z f32)
+ (local $w f64)
+ (local.set $x (i32.const 1))
+ (local.set $y (i64.const 1))
+ (local.set $z (f32.const 1))
+ (local.set $w (f64.const 1))
+ (call $nothing)
+ (drop (local.get $x))
+ (drop (local.get $y))
+ (drop (local.get $z))
+ (drop (local.get $w))
+ )
+ (func $spill4
+ (local $x i32)
+ (local $y i32)
+ (local $z i32)
+ (local $w i32)
+ (local.set $x (i32.const 1))
+ (local.set $y (i32.const 1))
+ (local.set $z (i32.const 1))
+ (local.set $w (i32.const 1))
+ (call $nothing)
+ (drop (local.get $x))
+ (drop (local.get $y))
+ (drop (local.get $z))
+ (drop (local.get $w))
+ )
+ (func $spill5
+ (local $x i32)
+ (local $y i32)
+ (local $z i32)
+ (local $w i32)
+ (local $a i32)
+ (local.set $x (i32.const 1))
+ (local.set $y (i32.const 1))
+ (local.set $z (i32.const 1))
+ (local.set $w (i32.const 1))
+ (local.set $a (i32.const 1))
+ (call $nothing)
+ (drop (local.get $x))
+ (drop (local.get $y))
+ (drop (local.get $z))
+ (drop (local.get $w))
+ (drop (local.get $a))
+ )
+ (func $some-alive
+ (local $x i32)
+ (local $y i32)
+ (call $nothing)
+ (drop (local.get $x))
+ )
+ (func $spill-args (param $p i32) (param $q i32)
+ (local $x i32)
+ (call $spill-args (i32.const 1) (i32.const 2))
+ (drop (local.get $x))
+ )
+ (func $spill-ret (result i32)
+ (local $x i32)
+ (call $nothing)
+ (drop (local.get $x))
+ (if (i32.const 1)
+ (return (i32.const 2))
+ (return (i32.const 3))
+ )
+ (i32.const 4)
+ )
+ (func $spill-unreachable (result i32)
+ (local $x i32)
+ (call $nothing)
+ (drop (local.get $x))
+ (unreachable)
+ )
+ (func $spill-call-call0 (param $p i32) (result i32)
+ (unreachable)
+ )
+ (func $spill-call-call1 (param $p i32) (result i32)
+ (local $x i32)
+ (drop
+ (call $spill-call-call0
+ (call $spill-call-call1
+ (i32.const 1)
+ )
+ )
+ )
+ (local.get $x)
+ )
+ (func $spill-call-ret (param $p i32) (result i32)
+ (local $x i32)
+ (drop
+ (call $spill-call-call0
+ (return
+ (i32.const 1)
+ )
+ )
+ )
+ (local.get $x)
+ )
+ (func $spill-ret-call (param $p i32) (result i32)
+ (local $x i32)
+ (drop
+ (return
+ (call $spill-call-call0
+ (i32.const 1)
+ )
+ )
+ )
+ (local.get $x)
+ )
+ (func $spill-ret-ret (result i32)
+ (local $x i32)
+ (call $nothing)
+ (drop (local.get $x))
+ (drop
+ (return
+ (return
+ (i32.const 1)
+ )
+ )
+ )
+ (local.get $x)
+ )
+ (func $spill-call-othertype (param $y f64)
+ (local $x i32)
+ (call $spill-call-othertype (f64.const 1))
+ (drop (local.get $x))
+ )
+ (func $spill-call_indirect
+ (local $x i32)
+ (call_indirect (type $ii)
+ (i32.const 123)
+ (i32.const 456)
+ (i32.const 789)
+ )
+ (drop (local.get $x))
+ )
+ (func $spill-call_import
+ (local $x i32)
+ (call $segfault
+ (i32.const 200)
+ )
+ (drop (local.get $x))
+ )
+)
+
+(module
+ (memory 10)
+ (type $ii (func (param i32 i32)))
+ (table 1 1 funcref)
+ (elem (i32.const 0))
+ (global $stack_ptr (mut i32) (i32.const 1716592))
+ (export "stackSave" (func $stack_save))
+ (import "env" "segfault" (func $segfault (param i32)))
+ (func $stack_save (result i32)
+ (global.get $stack_ptr)
+ )
+
+ (func $nothing
+ )
+ (func $not-alive
+ (local $x i32)
+ (local.set $x (i32.const 1))
+ (call $nothing)
+ )
+ (func $spill
+ (local $x i32)
+ (call $nothing)
+ (drop (local.get $x))
+ )
+ (func $ignore-non-pointers
+ (local $x i32)
+ (local $y i64)
+ (local $z f32)
+ (local $w f64)
+ (local.set $x (i32.const 1))
+ (local.set $y (i64.const 1))
+ (local.set $z (f32.const 1))
+ (local.set $w (f64.const 1))
+ (call $nothing)
+ (drop (local.get $x))
+ (drop (local.get $y))
+ (drop (local.get $z))
+ (drop (local.get $w))
+ )
+ (func $spill4
+ (local $x i32)
+ (local $y i32)
+ (local $z i32)
+ (local $w i32)
+ (local.set $x (i32.const 1))
+ (local.set $y (i32.const 1))
+ (local.set $z (i32.const 1))
+ (local.set $w (i32.const 1))
+ (call $nothing)
+ (drop (local.get $x))
+ (drop (local.get $y))
+ (drop (local.get $z))
+ (drop (local.get $w))
+ )
+ (func $spill5
+ (local $x i32)
+ (local $y i32)
+ (local $z i32)
+ (local $w i32)
+ (local $a i32)
+ (local.set $x (i32.const 1))
+ (local.set $y (i32.const 1))
+ (local.set $z (i32.const 1))
+ (local.set $w (i32.const 1))
+ (local.set $a (i32.const 1))
+ (call $nothing)
+ (drop (local.get $x))
+ (drop (local.get $y))
+ (drop (local.get $z))
+ (drop (local.get $w))
+ (drop (local.get $a))
+ )
+ (func $some-alive
+ (local $x i32)
+ (local $y i32)
+ (call $nothing)
+ (drop (local.get $x))
+ )
+ (func $spill-args (param $p i32) (param $q i32)
+ (local $x i32)
+ (call $spill-args (i32.const 1) (i32.const 2))
+ (drop (local.get $x))
+ )
+ (func $spill-ret (result i32)
+ (local $x i32)
+ (call $nothing)
+ (drop (local.get $x))
+ (if (i32.const 1)
+ (return (i32.const 2))
+ (return (i32.const 3))
+ )
+ (i32.const 4)
+ )
+ (func $spill-unreachable (result i32)
+ (local $x i32)
+ (call $nothing)
+ (drop (local.get $x))
+ (unreachable)
+ )
+ (func $spill-call-call0 (param $p i32) (result i32)
+ (unreachable)
+ )
+ (func $spill-call-call1 (param $p i32) (result i32)
+ (local $x i32)
+ (drop
+ (call $spill-call-call0
+ (call $spill-call-call1
+ (i32.const 1)
+ )
+ )
+ )
+ (local.get $x)
+ )
+ (func $spill-call-ret (param $p i32) (result i32)
+ (local $x i32)
+ (drop
+ (call $spill-call-call0
+ (return
+ (i32.const 1)
+ )
+ )
+ )
+ (local.get $x)
+ )
+ (func $spill-ret-call (param $p i32) (result i32)
+ (local $x i32)
+ (drop
+ (return
+ (call $spill-call-call0
+ (i32.const 1)
+ )
+ )
+ )
+ (local.get $x)
+ )
+ (func $spill-ret-ret (result i32)
+ (local $x i32)
+ (call $nothing)
+ (drop (local.get $x))
+ (drop
+ (return
+ (return
+ (i32.const 1)
+ )
+ )
+ )
+ (local.get $x)
+ )
+ (func $spill-call-othertype (param $y f64)
+ (local $x i32)
+ (call $spill-call-othertype (f64.const 1))
+ (drop (local.get $x))
+ )
+ (func $spill-call_indirect
+ (local $x i32)
+ (call_indirect (type $ii)
+ (i32.const 123)
+ (i32.const 456)
+ (i32.const 789)
+ )
+ (drop (local.get $x))
+ )
+ (func $spill-call_import
+ (local $x i32)
+ (call $segfault
+ (i32.const 200)
+ )
+ (drop (local.get $x))
+ )
+)