| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. |
| ;; RUN: wasm-split %s -all --no-placeholders -g -o1 %t.1.wasm -o2 %t.2.wasm --keep-funcs=keep |
| ;; RUN: wasm-dis %t.1.wasm -all | filecheck %s --check-prefix PRIMARY |
| ;; RUN: wasm-dis %t.2.wasm -all | filecheck %s --check-prefix SECONDARY |
| |
| ;; When placeholders are NOT used and all functions in an element segment belong |
| ;; to a single secondary module, we can move the segment to that secondary |
| ;; module. |
| |
| (module |
| ;; PRIMARY: (type $array (array (mut funcref))) |
| (type $array (array (mut funcref))) |
| |
| ;; PRIMARY: (global $keep-global funcref (ref.func $trampoline_split)) |
| (global $keep-global funcref (ref.func $split)) |
| ;; PRIMARY: (table $keep-table 2 2 funcref) |
| (table $keep-table 2 2 funcref) |
| ;; PRIMARY: (table $keep-table2 1 1 externref) |
| (table $keep-table2 1 1 externref) |
| |
| ;; This contains both a primary function and a secondary function, so keep this |
| ;; in the primary. |
| ;; PRIMARY: (elem $keep-elem1 (table $keep-table) (i32.const 0) func $keep $trampoline_split) |
| (elem $keep-elem1 (table $keep-table) (i32.const 0) func $keep $split) |
| ;; This contains a global.get, so keep it in the primary. |
| ;; PRIMARY: (elem $keep-elem2 (table $keep-table) (i32.const 0) funcref (item (ref.func $trampoline_split)) (item (global.get $keep-global))) |
| (elem $keep-elem2 (table $keep-table) (i32.const 0) funcref (ref.func $split) (global.get $keep-global)) |
| ;; This is not a funcref table, and the referenced table is kept in the |
| ;; primary. So keep this in the primary too. |
| ;; PRIMARY: (elem $keep-elem3 (table $keep-table2) (i32.const 0) externref (item (ref.null noextern))) |
| (elem $keep-elem3 (table $keep-table2) (i32.const 0) externref (ref.null extern)) |
| ;; The offset exceeds the table size, so keep this in the primary. |
| ;; PRIMARY: (elem $keep-elem4 (table $keep-table) (i32.const 10) func $trampoline_split) |
| (elem $keep-elem4 (table $keep-table) (i32.const 10) func $split) |
| ;; This segment contains only secondary functions, but it is referenced by an |
| ;; array.init_elem instruction in the primary module, so keep this in the |
| ;; primary. |
| ;; PRIMARY: (elem $keep-elem5 (table $keep-table) (i32.const 0) func $trampoline_split) |
| (elem $keep-elem5 (table $keep-table) (i32.const 0) func $split) |
| |
| ;; SECONDARY: (global $split-global funcref (ref.func $split)) |
| (global $split-global funcref (ref.func $split)) |
| ;; SECONDARY: (table $split-table 2 2 funcref) |
| (table $split-table 2 2 funcref) |
| |
| ;; All functions are in the secondary module, so split this to the secondary, |
| ;; even if the referenced table is in the primary module. |
| ;; SECONDARY: (elem $split-elem1 (table $keep-table) (i32.const 0) func $split $split) |
| (elem $split-elem1 (table $keep-table) (i32.const 0) func $split $split) |
| ;; The same test with $split-table. |
| ;; SECONDARY: (elem $split-elem2 (table $split-table) (i32.const 0) func $split $split) |
| (elem $split-elem2 (table $split-table) (i32.const 0) func $split $split) |
| ;; ref.null within data doesn't affect the segment's splitability. |
| ;; SECONDARY: (elem $split-elem3 (table $split-table) (i32.const 0) funcref (item (ref.func $split)) (item (ref.null nofunc))) |
| (elem $split-elem3 (table $split-table) (i32.const 0) funcref (ref.func $split) (ref.null nofunc)) |
| |
| ;; PRIMARY: (func $keep (type $0) |
| ;; PRIMARY-NEXT: (call_indirect $keep-table (type $0) |
| ;; PRIMARY-NEXT: (i32.const 0) |
| ;; PRIMARY-NEXT: ) |
| ;; PRIMARY-NEXT: (drop |
| ;; PRIMARY-NEXT: (table.get $keep-table2 |
| ;; PRIMARY-NEXT: (i32.const 0) |
| ;; PRIMARY-NEXT: ) |
| ;; PRIMARY-NEXT: ) |
| ;; PRIMARY-NEXT: (drop |
| ;; PRIMARY-NEXT: (global.get $keep-global) |
| ;; PRIMARY-NEXT: ) |
| ;; PRIMARY-NEXT: ) |
| (func $keep |
| ;; Uses $keep-table |
| (call_indirect $keep-table |
| (i32.const 0) |
| ) |
| ;; Uses $keep-table2 |
| (drop |
| (table.get $keep-table2 |
| (i32.const 0) |
| ) |
| ) |
| ;; Uses $keep-global |
| (drop |
| (global.get $keep-global) |
| ) |
| ) |
| |
| ;; This is not in --keep-funcs but will be kept in the primary because it |
| ;; references a segment. |
| ;; PRIMARY: (func $array-init-elem-user (type $0) |
| ;; PRIMARY-NEXT: (array.init_elem $array $keep-elem5 |
| ;; PRIMARY-NEXT: (array.new_default $array |
| ;; PRIMARY-NEXT: (i32.const 1) |
| ;; PRIMARY-NEXT: ) |
| ;; PRIMARY-NEXT: (i32.const 0) |
| ;; PRIMARY-NEXT: (i32.const 0) |
| ;; PRIMARY-NEXT: (i32.const 1) |
| ;; PRIMARY-NEXT: ) |
| ;; PRIMARY-NEXT: ) |
| (func $array-init-elem-user |
| ;; References $keep-elem5 |
| (array.init_elem $array $keep-elem5 |
| (array.new_default $array (i32.const 1)) |
| (i32.const 0) |
| (i32.const 0) |
| (i32.const 1) |
| ) |
| ) |
| |
| ;; SECONDARY: (func $split (type $0) |
| ;; SECONDARY-NEXT: (call_indirect $split-table (type $0) |
| ;; SECONDARY-NEXT: (i32.const 0) |
| ;; SECONDARY-NEXT: ) |
| ;; SECONDARY-NEXT: (drop |
| ;; SECONDARY-NEXT: (global.get $split-global) |
| ;; SECONDARY-NEXT: ) |
| ;; SECONDARY-NEXT: ) |
| (func $split |
| ;; Uses $split-table |
| (call_indirect $split-table |
| (i32.const 0) |
| ) |
| ;; Uses $split-global |
| (drop |
| (global.get $split-global) |
| ) |
| ) |
| ) |
| |