-
Notifications
You must be signed in to change notification settings - Fork 857
[wasm-split] Split module elements early #8688
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
| ;; We need to disable reference-types to reuse the existing table as the active | ||
| ;; table | ||
| ;; RUN: wasm-split %s --disable-reference-types --split-funcs=split -g -o1 %t.1.wasm -o2 %t.2.wasm | ||
| ;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY | ||
| ;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix SECONDARY | ||
|
|
||
| ;; This tests the case when an existing table is used as the active table, and | ||
| ;; the active table and its base global already has existing uses in the | ||
| ;; secondary module. | ||
|
|
||
| (module | ||
| ;; PRIMARY: (type $0 (func)) | ||
| ;; SECONDARY: (type $0 (func)) | ||
| (type $0 (func)) | ||
| (global $base (import "env" "base") i32) | ||
| ;; PRIMARY: (import "env" "base" (global $base i32)) | ||
|
|
||
| ;; PRIMARY: (import "placeholder.deferred" "1" (func $placeholder_1)) | ||
|
|
||
| ;; PRIMARY: (table $table 2 funcref) | ||
| (table $table 1 funcref) | ||
| (elem (global.get $base) $keep) | ||
| ;; PRIMARY: (elem $0 (global.get $base) $keep $placeholder_1) | ||
|
|
||
| ;; PRIMARY: (export "table" (table $table)) | ||
|
|
||
| ;; PRIMARY: (export "global" (global $base)) | ||
|
|
||
| ;; PRIMARY: (export "keep" (func $keep)) | ||
|
|
||
| ;; PRIMARY: (func $keep | ||
| ;; PRIMARY-NEXT: (call_indirect (type $0) | ||
| ;; PRIMARY-NEXT: (i32.add | ||
| ;; PRIMARY-NEXT: (global.get $base) | ||
| ;; PRIMARY-NEXT: (i32.const 1) | ||
| ;; PRIMARY-NEXT: ) | ||
| ;; PRIMARY-NEXT: ) | ||
| ;; PRIMARY-NEXT: ) | ||
| (func $keep | ||
| (call $split) | ||
| ) | ||
| ;; SECONDARY: (import "primary" "table" (table $table 1 funcref)) | ||
|
|
||
| ;; SECONDARY: (import "primary" "global" (global $base i32)) | ||
|
|
||
| ;; SECONDARY: (import "primary" "keep" (func $keep)) | ||
|
|
||
| ;; SECONDARY: (elem $0 (global.get $base) $keep $split) | ||
|
|
||
| ;; SECONDARY: (func $split | ||
| ;; SECONDARY-NEXT: (drop | ||
| ;; SECONDARY-NEXT: (global.get $base) | ||
| ;; SECONDARY-NEXT: ) | ||
| ;; SECONDARY-NEXT: (call_indirect (type $0) | ||
| ;; SECONDARY-NEXT: (i32.const 0) | ||
| ;; SECONDARY-NEXT: ) | ||
| ;; SECONDARY-NEXT: ) | ||
| (func $split | ||
| (drop (global.get $base)) | ||
| (call_indirect (type $0) (i32.const 0)) | ||
| ) | ||
| ) | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| ;; RUN: wasm-split %s -all -g -o1 %t.1.wasm -o2 %t.2.wasm --keep-funcs=keep | ||
|
Member
Author
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. This was renamed from |
||
| ;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY | ||
| ;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix SECONDARY | ||
|
|
||
| ;; When a split global ($a here)'s initializer contains a ref.func of a split | ||
| ;; function, we should NOT create any trampolines, and the split global should | ||
| ;; direclty refer to the function. | ||
|
|
||
| (module | ||
| (global $a funcref (ref.func $split)) | ||
| (global $b funcref (ref.func $keep)) | ||
|
|
||
| (func $keep) | ||
|
|
||
| (func $split | ||
| (drop | ||
| (global.get $a) | ||
| ) | ||
| (drop | ||
| (global.get $b) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| ;; PRIMARY: (module | ||
| ;; PRIMARY-NEXT: (type $0 (func)) | ||
| ;; PRIMARY-NEXT: (export "keep" (func $keep)) | ||
| ;; PRIMARY-NEXT: (func $keep | ||
| ;; PRIMARY-NEXT: ) | ||
| ;; PRIMARY-NEXT: ) | ||
|
|
||
| ;; SECONDARY: (module | ||
| ;; SECONDARY-NEXT: (type $0 (func)) | ||
| ;; SECONDARY-NEXT: (import "primary" "keep" (func $keep (exact))) | ||
| ;; SECONDARY-NEXT: (global $a funcref (ref.func $split)) | ||
| ;; SECONDARY-NEXT: (global $b funcref (ref.func $keep)) | ||
| ;; SECONDARY-NEXT: (func $split | ||
| ;; SECONDARY-NEXT: (drop | ||
| ;; SECONDARY-NEXT: (global.get $a) | ||
| ;; SECONDARY-NEXT: ) | ||
| ;; SECONDARY-NEXT: (drop | ||
| ;; SECONDARY-NEXT: (global.get $b) | ||
| ;; SECONDARY-NEXT: ) | ||
| ;; SECONDARY-NEXT: ) | ||
| ;; SECONDARY-NEXT: ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| ;; RUN: wasm-split %s -all -g -o1 %t.1.wasm -o2 %t.2.wasm --split-funcs=split1,split2 | ||
|
Member
Author
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. This is the test reduced from #8510 |
||
| ;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY | ||
| ;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix SECONDARY | ||
|
|
||
| ;; Global $g1 is used (exported) in the primary module so it can't move, and | ||
| ;; global $g2 is only used in the secondary module so it will move there. | ||
|
|
||
| (module | ||
| (global $g1 funcref (ref.func $split1)) | ||
| (global $g2 funcref (ref.func $split2)) | ||
| (export "g1" (global $g1)) | ||
|
|
||
| (func $split1 | ||
| (unreachable) | ||
| ) | ||
|
|
||
| (func $split2 | ||
| (drop | ||
| (global.get $g2) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| ;; PRIMARY: (module | ||
| ;; PRIMARY-NEXT: (type $0 (func)) | ||
| ;; PRIMARY-NEXT: (import "placeholder.deferred" "0" (func $placeholder_0)) | ||
| ;; PRIMARY-NEXT: (global $g1 funcref (ref.func $trampoline_split1)) | ||
| ;; PRIMARY-NEXT: (table $0 1 funcref) | ||
| ;; PRIMARY-NEXT: (elem $0 (i32.const 0) $placeholder_0) | ||
| ;; PRIMARY-NEXT: (export "g1" (global $g1)) | ||
| ;; PRIMARY-NEXT: (export "table" (table $0)) | ||
| ;; PRIMARY-NEXT: (func $trampoline_split1 | ||
| ;; PRIMARY-NEXT: (call_indirect (type $0) | ||
| ;; PRIMARY-NEXT: (i32.const 0) | ||
| ;; PRIMARY-NEXT: ) | ||
| ;; PRIMARY-NEXT: ) | ||
| ;; PRIMARY-NEXT: ) | ||
|
|
||
| ;; SECONDARY: (module | ||
| ;; SECONDARY-NEXT: (type $0 (func)) | ||
| ;; SECONDARY-NEXT: (import "primary" "table" (table $timport$0 1 funcref)) | ||
| ;; SECONDARY-NEXT: (global $g2 funcref (ref.func $split2)) | ||
| ;; SECONDARY-NEXT: (elem $0 (i32.const 0) $split1) | ||
| ;; SECONDARY-NEXT: (func $split1 | ||
| ;; SECONDARY-NEXT: (unreachable) | ||
| ;; SECONDARY-NEXT: ) | ||
| ;; SECONDARY-NEXT: (func $split2 | ||
| ;; SECONDARY-NEXT: (drop | ||
| ;; SECONDARY-NEXT: (global.get $g2) | ||
| ;; SECONDARY-NEXT: ) | ||
| ;; SECONDARY-NEXT: ) | ||
| ;; SECONDARY-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.
These are some edge cases that I feel easy to miss, because now we specially handle the active table and the base global in
setupTablePatching