Verified Commit 8a1b2965 authored by Camil Staps's avatar Camil Staps 🚀

WIP: try to use call_indirect to optimize the wasm interpreter (does not work;...

WIP: try to use call_indirect to optimize the wasm interpreter (does not work; previous commit is faster)
parent d7906461
Pipeline #48656 failed with stages
in 21 minutes and 12 seconds
......@@ -105,15 +105,10 @@ collect_instructions {debug_instructions,instructions_order= ?Just instrs_order}
]
where
all_instructions =
sortBy lt_by_may_need_gc
[ end_instruction (instr_unimplemented (begin_instruction "illegal" start))
: [{i & stmts=map (optimize fast_opt_options) i.stmts} \\ i <- is]
]
lt_by_may_need_gc i1 i2 = not (may_need_gc i1) && may_need_gc i2
where
may_need_gc i = any (any (\e->e=:(Ecall "abc-gc" _)) o subexpressions) i.stmts
fast_opt_options = {rename_labels=[]}
header =
......@@ -177,52 +172,38 @@ where
head = reverse [";; "+++i \\ i <- t.instrs]
interpret =
[ "(func (export \"interpret\") (result i32)"
[ "(table funcref (elem"
] ++
["\t"+++i \\ i <- sorted_instructions] ++
[ ")) ;; table"
, "(type $instr (func (param i32 i32 i32 i32 i32 i32) (result i32 i32 i32 i32 i32 i32)))"
, "(func (export \"interpret\") (result i32)"
, "(local $i i32)"
] ++
["(local $"+++v+++" i32)" \\ v <- rt_vars] ++
["(local.set $"+++v+++" (global.get $g-"+++v+++"))" \\ v <- rt_vars] ++
[ "(loop $abc-loop"
] ++
["(block $instr_"+++hd i.instrs \\ i <- reverse all_instructions] ++
switch True ++
flatten
[
[ ")"
, "(call $instr_"+++hd i.instrs+++" (local.get $pc) (local.get $asp) (local.get $bsp) (local.get $csp) (local.get $hp) (local.get $hp-free))"
, "(local.set $hp-free)"
, "(local.set $hp)"
, "(local.set $csp)"
, "(local.set $bsp)"
, "(local.set $asp)"
, "(local.set $pc)"
, "(br $abc-loop)"
]
\\ i <- all_instructions
] ++
[ /*"(unreachable)"
,*/ ") ;; loop"
, if debug_instructions "(call $clean_debug_instr (local.get $pc) (i32.load (local.get $pc)))" ""
, "(call_indirect (type $instr) (local.get $pc) (local.get $asp) (local.get $bsp) (local.get $csp) (local.get $hp) (local.get $hp-free) (i32.load (local.get $pc)))"
, "(local.set $hp-free)"
, "(local.set $hp)"
, "(local.set $csp)"
, "(local.set $bsp)"
, "(local.set $asp)"
, "(local.set $pc)"
, "(br $abc-loop)"
, ")"
, "(i32.const 0)"
, ") ;; interpret"
]
switch inner =
[ if (inner && debug_instructions)
(toString (Ecall "clean_debug_instr" [Pc, Eload I32 I32 DontCare 0 Pc]))
""
, "\t(br_table " +++
foldr (+++) "" [find_label i all_instructions \\ i <- instrs_order] +++
illegal_label +++
(toString (Eload I32 I32 DontCare 0 Pc)) +++ ")"
]
where
sorted_instructions = [find_label i all_instructions \\ i <- instrs_order]
find_label i [t:ts]
| isMember i t.instrs
= "$instr_"+++hd t.instrs+++" "
= find_label i ts
find_label _ [] = illegal_label
illegal_label = "$instr_illegal "
find_label i [] = "$instr_illegal"
type x :== Type TypeInferenceSettings x
type2 x y :== Type2 TypeInferenceSettings x y
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment