-
Notifications
You must be signed in to change notification settings - Fork 745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasm-split: Handle RefFuncs #6513
Changes from 14 commits
d2eef23
c3338f3
9153f0b
9a3e84f
a4dc3d4
422ad86
15ca0a5
1f81117
bc24e02
b2b93b4
8e972b1
591f4d5
bd36f82
a0ffac6
910f01b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
|
||
;; RUN: wasm-split %s --split-funcs=second-in-table -g -o1 %t.1.wasm -o2 %t.2.wasm -all | ||
;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY | ||
;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix SECONDARY | ||
|
||
(module | ||
(type $func-array (array (mut funcref))) | ||
|
||
;; PRIMARY: (type $0 (func)) | ||
|
||
;; PRIMARY: (import "placeholder" "0" (func $placeholder_0)) | ||
|
||
;; PRIMARY: (table $table 3 funcref) | ||
(table $table 3 funcref) | ||
|
||
;; Workaround for https://github.com/WebAssembly/binaryen/issues/6572 - we | ||
;; error without an active segment. | ||
(elem (i32.const 0)) | ||
|
||
;; PRIMARY: (elem $0 (i32.const 0) $placeholder_0) | ||
|
||
;; PRIMARY: (elem $passive func $in-table $1) | ||
(elem $passive func $in-table $second-in-table) | ||
|
||
;; PRIMARY: (export "table" (table $table)) | ||
|
||
;; PRIMARY: (func $in-table | ||
;; PRIMARY-NEXT: (nop) | ||
;; PRIMARY-NEXT: ) | ||
(func $in-table | ||
;; This is in a passive segment, but it is in the main module so we need no | ||
;; special handling. | ||
) | ||
|
||
;; SECONDARY: (type $0 (func)) | ||
|
||
;; SECONDARY: (import "primary" "table" (table $table 3 funcref)) | ||
|
||
;; SECONDARY: (elem $0 (i32.const 0) $second-in-table) | ||
|
||
;; SECONDARY: (func $second-in-table | ||
;; SECONDARY-NEXT: (nop) | ||
;; SECONDARY-NEXT: ) | ||
(func $second-in-table | ||
;; This is in a passive segment, and it is in the secondary module, so we will | ||
;; handle it by adding a trampoline from the segment as a new function "$1". | ||
) | ||
) | ||
;; PRIMARY: (func $1 | ||
;; PRIMARY-NEXT: (call_indirect (type $0) | ||
;; PRIMARY-NEXT: (i32.const 0) | ||
;; PRIMARY-NEXT: ) | ||
;; PRIMARY-NEXT: ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
|
||
;; RUN: wasm-split %s --split-funcs=second,second-in-table -g -o1 %t.1.wasm -o2 %t.2.wasm -all | ||
;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY | ||
;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix SECONDARY | ||
|
||
;; Test that we handle ref.func operations properly as we split out $second. | ||
;; ref.funcs that refer to the other module must be fixed up to refer to | ||
;; something in the same module, that then trampolines to the other. | ||
(module | ||
;; PRIMARY: (type $0 (func)) | ||
|
||
;; PRIMARY: (import "placeholder" "1" (func $placeholder_1)) | ||
|
||
;; PRIMARY: (import "placeholder" "2" (func $placeholder_2)) | ||
|
||
;; PRIMARY: (global $glob1 (ref func) (ref.func $prime)) | ||
|
||
;; PRIMARY: (global $glob2 (ref func) (ref.func $2)) | ||
|
||
;; PRIMARY: (table $table 3 3 funcref) | ||
(table $table 1 1 funcref) | ||
|
||
(global $glob1 (ref func) (ref.func $prime)) | ||
|
||
(global $glob2 (ref func) (ref.func $second)) | ||
|
||
(elem (i32.const 0) $in-table $second-in-table) | ||
|
||
;; PRIMARY: (elem $0 (i32.const 0) $in-table $placeholder_1 $placeholder_2) | ||
|
||
;; PRIMARY: (export "prime" (func $prime)) | ||
|
||
;; PRIMARY: (export "table" (table $table)) | ||
|
||
;; PRIMARY: (export "global" (global $glob1)) | ||
|
||
;; PRIMARY: (export "global_3" (global $glob2)) | ||
|
||
;; PRIMARY: (func $prime | ||
;; PRIMARY-NEXT: (drop | ||
;; PRIMARY-NEXT: (ref.func $prime) | ||
;; PRIMARY-NEXT: ) | ||
;; PRIMARY-NEXT: (drop | ||
;; PRIMARY-NEXT: (ref.func $2) | ||
;; PRIMARY-NEXT: ) | ||
;; PRIMARY-NEXT: ) | ||
(func $prime | ||
(drop | ||
(ref.func $prime) | ||
) | ||
(drop | ||
(ref.func $second) | ||
) | ||
) | ||
|
||
;; SECONDARY: (type $0 (func)) | ||
|
||
;; SECONDARY: (import "primary" "table" (table $table 3 3 funcref)) | ||
|
||
;; SECONDARY: (import "primary" "global" (global $glob1 (ref func))) | ||
|
||
;; SECONDARY: (import "primary" "global_3" (global $glob2 (ref func))) | ||
|
||
;; SECONDARY: (import "primary" "prime" (func $prime)) | ||
|
||
;; SECONDARY: (elem $0 (i32.const 1) $second-in-table $second) | ||
|
||
;; SECONDARY: (func $second | ||
;; SECONDARY-NEXT: (drop | ||
;; SECONDARY-NEXT: (ref.func $prime) | ||
;; SECONDARY-NEXT: ) | ||
;; SECONDARY-NEXT: (drop | ||
;; SECONDARY-NEXT: (ref.func $second) | ||
;; SECONDARY-NEXT: ) | ||
;; SECONDARY-NEXT: ) | ||
(func $second | ||
(drop | ||
(ref.func $prime) | ||
) | ||
(drop | ||
(ref.func $second) | ||
) | ||
) | ||
|
||
;; PRIMARY: (func $in-table | ||
;; PRIMARY-NEXT: (nop) | ||
;; PRIMARY-NEXT: ) | ||
(func $in-table | ||
;; This empty function is in the table. Just being present in the table is not | ||
;; enough of a reason for us to make a trampoline, even though in our IR the | ||
;; table is a list of ref.funcs. | ||
Comment on lines
+89
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the code differentiate RefFuncs in a table from other RefFuncs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this was a part I meant to write Friday evening and somehow forgot 😄 Added now + testing. |
||
) | ||
|
||
;; SECONDARY: (func $second-in-table | ||
;; SECONDARY-NEXT: (nop) | ||
;; SECONDARY-NEXT: ) | ||
(func $second-in-table | ||
;; As above, but in the secondary module. We still don't need a trampoline | ||
;; (but we will get a placeholder, as all split-out functions do). | ||
) | ||
) | ||
;; PRIMARY: (func $2 | ||
;; PRIMARY-NEXT: (call_indirect (type $0) | ||
;; PRIMARY-NEXT: (i32.const 2) | ||
;; PRIMARY-NEXT: ) | ||
;; PRIMARY-NEXT: ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you give this a name, its output line will be attached above it.