summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Lublinerman <rluble@google.com>2024-04-29 17:42:06 -0700
committerGitHub <noreply@github.com>2024-04-30 00:42:06 +0000
commit049ff7a828f3e11b2877034dd452481cd7c04f96 (patch)
tree5152c18add92221f39d5f08fab49071102e863ab
parent497ffe211d68debcca05bf67e8439206db100cd3 (diff)
downloadbinaryen-049ff7a828f3e11b2877034dd452481cd7c04f96.tar.gz
binaryen-049ff7a828f3e11b2877034dd452481cd7c04f96.tar.bz2
binaryen-049ff7a828f3e11b2877034dd452481cd7c04f96.zip
J2CLOpts: Add "precompute" and "remove-unused-brs" as additional cleanup
This makes the cleanup of bodies of functions that have had constants hoisted from them more effective.
-rw-r--r--src/passes/J2CLOpts.cpp2
-rw-r--r--test/lit/passes/j2cl.wast52
2 files changed, 54 insertions, 0 deletions
diff --git a/src/passes/J2CLOpts.cpp b/src/passes/J2CLOpts.cpp
index 78edecc45..97129d2cc 100644
--- a/src/passes/J2CLOpts.cpp
+++ b/src/passes/J2CLOpts.cpp
@@ -105,6 +105,8 @@ public:
// TODO: maybe we should not introduce "nop" in the first place and try
// removing instead.
PassRunner runner(getModule());
+ runner.add("precompute");
+ runner.add("remove-unused-brs");
runner.add("vacuum");
runner.setIsNested(true);
runner.runOnFunction(curr);
diff --git a/test/lit/passes/j2cl.wast b/test/lit/passes/j2cl.wast
index d5753907d..50fe807c0 100644
--- a/test/lit/passes/j2cl.wast
+++ b/test/lit/passes/j2cl.wast
@@ -151,3 +151,55 @@
(global.set $field@Foo (i32.const 1))
)
)
+
+
+(module
+ ;; CHECK: (type $0 (func (result i32)))
+
+ ;; CHECK: (global $$var2@Zoo (mut i32) (i32.const 0))
+
+ ;; CHECK: (global $$var1@Zoo i32 (i32.const 2))
+ (global $$var1@Zoo (mut i32) (i32.const 0))
+ (global $$var2@Zoo (mut i32) (i32.const 0))
+
+ ;; CHECK: (export "getVar1_<once>_@Zoo" (func $getVar1_<once>_@Zoo))
+
+ ;; CHECK: (func $getVar1_<once>_@Zoo (type $0) (result i32)
+ ;; CHECK-NEXT: (i32.const 2)
+ ;; CHECK-NEXT: )
+ (func $getVar1_<once>_@Zoo (export "getVar1_<once>_@Zoo") (result i32)
+ (if (global.get $$var1@Zoo)
+ (then
+ (return (global.get $$var1@Zoo))
+ )
+ )
+ (global.set $$var1@Zoo (i32.const 2))
+ (return (global.get $$var1@Zoo))
+ )
+
+ ;; CHECK: (func $getVar2_<once>_@Zoo (type $0) (result i32)
+ ;; CHECK-NEXT: (if
+ ;; CHECK-NEXT: (global.get $$var2@Zoo)
+ ;; CHECK-NEXT: (then
+ ;; CHECK-NEXT: (return
+ ;; CHECK-NEXT: (global.get $$var2@Zoo)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (global.set $$var2@Zoo
+ ;; CHECK-NEXT: (call $getVar1_<once>_@Zoo)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (return
+ ;; CHECK-NEXT: (global.get $$var2@Zoo)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $getVar2_<once>_@Zoo (result i32)
+ (if (global.get $$var2@Zoo)
+ (then
+ (return (global.get $$var2@Zoo))
+ )
+ )
+ (global.set $$var2@Zoo (call $getVar1_<once>_@Zoo))
+ (return (global.get $$var2@Zoo))
+ )
+)