diff options
author | Alon Zakai <azakai@google.com> | 2024-01-31 14:29:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 14:29:53 -0800 |
commit | dfcae55bd02747cb1eaf8410c02ac4d53ee1fd01 (patch) | |
tree | 2e771bfe2827e48a5542b6d65f6f003b0db5f007 /test/lit/passes/simplify-globals-strings.wast | |
parent | 396a826d791e63322cd4f47f116412d3e30ea5fc (diff) | |
download | binaryen-dfcae55bd02747cb1eaf8410c02ac4d53ee1fd01.tar.gz binaryen-dfcae55bd02747cb1eaf8410c02ac4d53ee1fd01.tar.bz2 binaryen-dfcae55bd02747cb1eaf8410c02ac4d53ee1fd01.zip |
StringGathering pass (#6257)
This pass finds all string.const and creates globals for them. After this transform, no
string.const appears anywhere but in a global, and each string appears in one global
which is then global.get-ed everywhere.
This avoids overhead in VMs where executing a string.const is an allocation, and is
also a good step towards imported strings. For that, this pass will be extended from
gathering to a full lowering pass, which will first gather into globals as this pass does,
and then turn each of those globals with a string.const into an imported externref.
(For that reason this pass is in a file called StringLowering, as the two passes will
share much of their code, and the larger pass should decide the name I think.)
This pass runs in -O2 and above. Repeated executions have no downside (see
details in code).
Diffstat (limited to 'test/lit/passes/simplify-globals-strings.wast')
-rw-r--r-- | test/lit/passes/simplify-globals-strings.wast | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/test/lit/passes/simplify-globals-strings.wast b/test/lit/passes/simplify-globals-strings.wast deleted file mode 100644 index 813e2964c..000000000 --- a/test/lit/passes/simplify-globals-strings.wast +++ /dev/null @@ -1,65 +0,0 @@ -;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. -;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up. - -;; We do not "inline" strings from globals, as that might cause more -;; allocations to happen. TODO if VMs optimize that, remove this - -;; RUN: foreach %s %t wasm-opt --simplify-globals -all -S -o - | filecheck %s - -;; Also test with -O3 --gufa to see that no other pass does this kind of thing, -;; as extra coverage. - -;; RUN: foreach %s %t wasm-opt -O3 --gufa -all -S -o - | filecheck %s --check-prefix=O3GUF - -(module - ;; CHECK: (type $0 (func (result anyref))) - - ;; CHECK: (global $string stringref (string.const "one")) - ;; O3GUF: (type $0 (func (result anyref))) - - ;; O3GUF: (global $string (ref string) (string.const "one")) - (global $string stringref (string.const "one")) - - ;; CHECK: (global $string-mut (mut stringref) (string.const "two")) - ;; O3GUF: (global $string-mut (mut (ref string)) (string.const "two")) - (global $string-mut (mut stringref) (string.const "two")) - - ;; CHECK: (export "global" (func $global)) - ;; O3GUF: (export "global" (func $global)) - (export "global" (func $global)) - - ;; CHECK: (export "written" (func $written)) - ;; O3GUF: (export "written" (func $written)) - (export "written" (func $written)) - - ;; CHECK: (func $global (type $0) (result anyref) - ;; CHECK-NEXT: (global.get $string) - ;; CHECK-NEXT: ) - ;; O3GUF: (func $global (type $0) (result anyref) - ;; O3GUF-NEXT: (global.get $string) - ;; O3GUF-NEXT: ) - (func $global (result anyref) - ;; This should not turn into "one". - (global.get $string) - ) - - ;; CHECK: (func $written (type $0) (result anyref) - ;; CHECK-NEXT: (global.set $string-mut - ;; CHECK-NEXT: (string.const "three") - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (global.get $string-mut) - ;; CHECK-NEXT: ) - ;; O3GUF: (func $written (type $0) (result anyref) - ;; O3GUF-NEXT: (global.set $string-mut - ;; O3GUF-NEXT: (string.const "three") - ;; O3GUF-NEXT: ) - ;; O3GUF-NEXT: (global.get $string-mut) - ;; O3GUF-NEXT: ) - (func $written (result anyref) - (global.set $string-mut - (string.const "three") - ) - ;; This should not turn into "three". - (global.get $string-mut) - ) -) |