- Notifications
You must be signed in to change notification settings - Fork 818
wasm-split: Handle RefFuncs #6513
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits Select commit Hold shift + click to select a range
d2eef23
work
kripken c3338f3
format
kripken 9153f0b
Update src/ir/module-splitting.cpp
kripken 9a3e84f
Merge remote-tracking branch 'origin/main' into split.ref.func
kripken a4dc3d4
feedback
kripken 422ad86
feedback
kripken 15ca0a5
fix
kripken 1f81117
fix
kripken bc24e02
fix
kripken b2b93b4
work
kripken 8e972b1
Merge remote-tracking branch 'origin/main' into split.ref.func
kripken 591f4d5
Handle passive segments
kripken bd36f82
format
kripken a0ffac6
fix two tests
kripken 910f01b
feedback: add name to elem segment
kripken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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: ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
;; 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)) | ||
| ||
;; PRIMARY: (elem $elem (i32.const 0) $in-table $placeholder_1 $placeholder_2) | ||
(elem $elem (i32.const 0) $in-table $second-in-table) | ||
| ||
;; 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. | ||
) | ||
| ||
;; 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: ) |
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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.