From 3928189214e03430bbc9f2b51c6af3887b465160 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 11 Nov 2022 10:16:32 -0800 Subject: [Wasm GC] Add Monomorphize pass (#5238) Monomorphization finds cases where we send more refined types to a function than it declares. In such cases we can copy the function and refine the parameters: // B is a subtype of A foo(new B()); function foo(x : A) { ..} => foo_B(new B()); // call redirected to refined copy function foo(x : A) { ..} // unchanged function foo_B(x : B) { ..} // refined copy This increases code size so it may not be worth it in all cases. This initial PR is hopefully enough to start experimenting with this on performance, and so it does not enable the pass by default. This adds two variations of monomorphization, one that always does it, and the default which is "careful": it sees whether monomorphizing lets the refined function actually be better than the original (say, by removing a cast). If there is no improvement then we do not make any changes. This saves a significant amount of code size - on j2wasm the careful version increases by 13% instead of 20% - but it does run more slowly obviously. --- test/lit/help/wasm2js.test | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/lit/help/wasm2js.test') diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test index f190c8fed..7a782c872 100644 --- a/test/lit/help/wasm2js.test +++ b/test/lit/help/wasm2js.test @@ -232,6 +232,12 @@ ;; CHECK-NEXT: --mod-asyncify-never-unwind apply the assumption that ;; CHECK-NEXT: asyncify never unwinds ;; CHECK-NEXT: +;; CHECK-NEXT: --monomorphize creates specialized versions of +;; CHECK-NEXT: functions +;; CHECK-NEXT: +;; CHECK-NEXT: --monomorphize-always creates specialized versions of +;; CHECK-NEXT: functions (even if unhelpful) +;; CHECK-NEXT: ;; CHECK-NEXT: --multi-memory-lowering combines multiple memories into ;; CHECK-NEXT: a single memory ;; CHECK-NEXT: -- cgit v1.2.3