summaryrefslogtreecommitdiff
path: root/src/passes/pass.cpp
diff options
context:
space:
mode:
authorGoktug Gokdogan <goktug@google.com>2023-12-12 09:45:18 -0800
committerGitHub <noreply@github.com>2023-12-12 09:45:18 -0800
commit71dad8795112b5c9ed1442450fa7e7bbe33622d1 (patch)
tree7b99430d76b39bf78061e9ab85c6e7843eebdc4a /src/passes/pass.cpp
parent36e21c60a5bc6b392069af2777dd310680588350 (diff)
downloadbinaryen-71dad8795112b5c9ed1442450fa7e7bbe33622d1.tar.gz
binaryen-71dad8795112b5c9ed1442450fa7e7bbe33622d1.tar.bz2
binaryen-71dad8795112b5c9ed1442450fa7e7bbe33622d1.zip
Add J2CL optimization pass to binaryen. (#6151)
This PR creates a new pass to optimize J2CL specific patterns that would otherwise difficult to recognize/prove generically by other binaryen passes. The pass currently handles fields what we call as "constant-like". These fields are fields initialized once and unconditionally through "clinit" function and technically they do have 2 observable states; - initial null/0 state - initialized state. However you can only observe initial null/0 state in contrived examples, not in real world/correct applications. This pass moves such "clinit" initialized fields to global initialization. Above pattern also matches other lazy init construct like String and Class literals (which binaryen already reduces to constant expressions). So the pass is generalized to include them as well. (by matching any functions with the name pattern "_@once_") In order for this pass to be effective: 1. It needs to run between O3 passes 2. We need to stop inlining of "once" functions. Stopping inlining of the once functions are important to preserve their structure. This both helps existing OnceReducer pass and new J2CL pass to be a lot more effective. Also it is not useful to inline these functions as by defintion they only executed once. This could be achieved by passing no-inline filter. Although the inlining is generally disabled for these functions, it is still needed for some cases since inliner is effectively responsible for removal of the once functions that are simplified into empty or simple delegating functions. For this reason, the pass will rename such trivial function so no-inline filter will no longer match them. Also note that after all optimizations completed, it does make sense to have a final stage where the "partial inline" of all once functions are allowed. This will speed them up by moving the initialization check to call-site.
Diffstat (limited to 'src/passes/pass.cpp')
-rw-r--r--src/passes/pass.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index 525248924..d7391a390 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -193,6 +193,8 @@ void PassRegistry::registerPasses() {
registerPass("gufa-optimizing",
"GUFA plus local optimizations in functions we modified",
createGUFAOptimizingPass);
+ registerPass(
+ "optimize-j2cl", "optimizes J2CL specific constructs.", createJ2CLOptsPass);
registerPass("type-refining",
"apply more specific subtypes to type fields where possible",
createTypeRefiningPass);