diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-01-17 13:11:14 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-17 13:11:14 -0800 |
commit | 0a9ddae715b2cff23a86cf14bbf6a4b870511395 (patch) | |
tree | ac15dd6da937509b22b6cc5b97f21fa508f48570 /src/asm2wasm.h | |
parent | 01b23987405d8d7b2f13e40ef906169163ac2a5f (diff) | |
download | binaryen-0a9ddae715b2cff23a86cf14bbf6a4b870511395.tar.gz binaryen-0a9ddae715b2cff23a86cf14bbf6a4b870511395.tar.bz2 binaryen-0a9ddae715b2cff23a86cf14bbf6a4b870511395.zip |
Global optimization fixes (#1360)
* run dfe at the very end, as it may be more effective after inlining
* optimize reorder-functions
* do a final dfe in asm2wasm after all other opts
* make inlining deterministic: std::atomic<T> values are not zero-initialized
* do global post opts at the end of asm2wasm, and don't also do them in the module builder
* fix function type removing
* don't inline+optimize when preserving debug info
Diffstat (limited to 'src/asm2wasm.h')
-rw-r--r-- | src/asm2wasm.h | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index b5f701dac..aa8394d3a 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -966,21 +966,6 @@ void Asm2WasmBuilder::processAsm(Ref ast) { } // optimize relooper label variable usage at the wasm level, where it is easy passRunner.add("relooper-jump-threading"); - }, [&]() { - // beforeGlobalOptimizations - // if we added any helper functions (like non-trapping i32-div, etc.), then those - // have not been optimized (the optimizing builder has just been fed the asm.js - // functions). Optimize those now. Typically there are very few, just do it - // sequentially. - PassRunner passRunner(&wasm, passOptions); - passRunner.addDefaultFunctionOptimizationPasses(); - for (auto& pair : trappingFunctions.getFunctions()) { - auto* func = pair.second; - passRunner.runOnFunction(func); - } - for (auto* func : extraSupportFunctions) { - passRunner.runOnFunction(func); - } }, debug, false /* do not validate globally yet */); } @@ -1190,6 +1175,19 @@ void Asm2WasmBuilder::processAsm(Ref ast) { if (runOptimizationPasses) { optimizingBuilder->finish(); + // if we added any helper functions (like non-trapping i32-div, etc.), then those + // have not been optimized (the optimizing builder has just been fed the asm.js + // functions). Optimize those now. Typically there are very few, just do it + // sequentially. + PassRunner passRunner(&wasm, passOptions); + passRunner.addDefaultFunctionOptimizationPasses(); + for (auto& pair : trappingFunctions.getFunctions()) { + auto* func = pair.second; + passRunner.runOnFunction(func); + } + for (auto* func : extraSupportFunctions) { + passRunner.runOnFunction(func); + } } wasm.debugInfoFileNames = std::move(preprocessor.debugInfoFileNames); @@ -1382,7 +1380,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { } }; - PassRunner passRunner(&wasm); + PassRunner passRunner(&wasm, passOptions); passRunner.setFeatures(passOptions.features); if (debug) { passRunner.setDebug(true); @@ -1411,6 +1409,11 @@ void Asm2WasmBuilder::processAsm(Ref ast) { passRunner.add<ApplyDebugInfo>(); passRunner.add("vacuum"); // FIXME maybe just remove the nops that were debuginfo nodes, if not optimizing? } + if (runOptimizationPasses) { + // do final global optimizations after all function work is done + // (e.g. duplicate funcs may appear thanks to that work) + passRunner.addDefaultGlobalOptimizationPostPasses(); + } passRunner.run(); // remove the debug info intrinsic |