summaryrefslogtreecommitdiff
path: root/src/wasm-module-building.h
Commit message (Collapse)AuthorAgeFilesLines
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-2/+4
| | | Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-23/+44
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* Rename atomic wait/notify instructions (#1972)Heejin Ahn2019-03-301-10/+10
| | | | | | | | This renames the following: - `i32.wait` -> `i32.atomic.wait` - `i64.wait` -> `i64.atomic.wait` - `wake` -> `atomic.notify` to match the spec.
* DeadArgumentElimination Pass (#1641)Alon Zakai2018-09-051-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a pass to remove unnecessary call arguments in an LTO-like manner, that is: * If a parameter is not actually used in a function, we don't need to send anything, and can remove it from the function's declaration. Concretely, (func $a (param $x i32) ..no uses of $x.. ) (func $b (call $a (..)) ) => (func $a ..no uses of $x.. ) (func $b (call $a) ) And * If a parameter is only ever sent the same constant value, we can just set that constant value in the function (which then means that the values sent from the outside are no longer used, as in the previous point). Concretely, (func $a (param $x i32) ..may use $x.. ) (func $b (call $a (i32.const 1)) (call $a (i32.const 1)) ) => (func $a (local $x i32) (set_local $x (i32.const 1) ..may use $x.. ) (func $b (call $a) (call $a) ) How much this helps depends on the codebase obviously, but sometimes it is pretty useful. For example, it shrinks 0.72% on Unity and 0.37% on Mono. Note that those numbers include not just the optimization itself, but the other optimizations it then enables - in particular the second point from earlier leads to inlining a constant value, which often allows constant propagation, and also removing parameters may enable more duplicate function elimination, etc. - which explains how this can shrink Unity by almost 1%. Implementation is pretty straightforward, but there is some work to make the heavy part of the pass parallel, and a bunch of corner cases to avoid (can't change a function that is exported or in the table, etc.). Like the Inlining pass, there is both a standard and an "optimizing" version of this pass - the latter also optimizes the functions it changes, as like Inlining, it's useful to not need to re-run all function optimizations on the whole module.
* Clarify what function-parallel passes can do, and fix an asm2wasm bug (#1627)Alon Zakai2018-07-231-0/+4
| | | | | The problem this fixes is that we made precompute look at globals in #1622, while asm2wasm was creating globals while adding functions and optimizing them - which could race. This was caught by threadSanitizer (with low frequency, so we missed it on the initial landing). The underlying issue is that function-parallel passes should be able to read global state, just not modify it, and not read other functions' contents (which is why the Call node has a name, not a pointer to a function). This PR clarifies that in the docs, and fixes asm2wasm by not handling function bodies in parallel to creating globals.
* Global optimization fixes (#1360)Alon Zakai2018-01-171-9/+4
| | | | | | | | | | | | | | | | * 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
* runFunction => runOnFunction (we run on the function, not run the function) ↵Alon Zakai2018-01-101-1/+1
| | | | (#1356)
* optimize helper funcs (like i32-div) if created in asm2wasm, so they are ↵Alon Zakai2017-10-041-8/+15
| | | | consistently handled regardless of whether we optimize in parallel or not (#1208)
* Improve and enable inlining pass (#966)Alon Zakai2017-08-071-2/+2
| | | | | | | | * improve inlining pass to inline single-use functions that are fairly small, which makes it useful for removing unnecessary global constructors from clang. add an inlining-optimizing pass that also optimizes where it inlined, as new opportunities arise. enable that it by default in O2+ * fix a bug where we didn't run all passes properly - refactor addDefaultGlobalOptimizationPasses() into a pre and post version. we can only run the post version in incremental optimizing builds (functions appear one by one, we optimize them first, and do global stuff when all are done), but can run both when doing a full optimize * copy in inlining, allowing multiple inlinings of the same function in the future
* Validate finalization (#1014)Alon Zakai2017-05-181-1/+2
| | | | | | | * validate that types are properly finalized, when in pass-debug mode (BINARYEN_PASS_DEBUG env var): check after each pass is run that the type of each node is equal to the proper type (when finalizing it, i.e., fully recomputing the type). * fix many fuzz bugs found by that. * in particular, fix dce bugs with type changes not being fully updated during code removal. add a new TypeUpdater helper class that lets a pass update types efficiently, by the helper tracking deps between blocks and branches etc., and updating/propagating type changes only as necessary.
* Make header guards consistent (#997)Sam Clegg2017-05-041-4/+3
|
* Preserve debug info through the optimizer (#981)Alon Zakai2017-04-281-7/+14
| | | | | | | | | | | | | | * add debugInfo option to passes, and use it to keep debug info alive through optimizations when we need it * add fib testcase for debug info * when preserving debug info, do not move code around call-imports, so debug info intrinsics remain stationary * improve wasm-module-building handling of the single-threaded case: don't create workers, which is more efficient and also nicer for debugging * process debug info in a more precise way, reordering it from being after the node (as it was a comment in JS) to before the node * remove unreachable hack for debug info, which is no longer needed since we reorder them, and make sure to finalize blocks in which we reorder
* pass PassOptions to OptimizingIncrementalModuleBuilder, so that it can pass ↵Alon Zakai2016-10-211-6/+7
| | | | them to all the PassRunners it creates, letting them have the proper options at all times
* passRunner debug and validation improvements (#726)Alon Zakai2016-10-021-4/+19
|
* refactor pass hooks, creating a proper way to run code before a pass is runAlon Zakai2016-09-121-1/+1
|
* ensure we create the OptimizeInstructions database on demand, avoiding ↵Alon Zakai2016-09-071-0/+8
| | | | global ctors
* autodrop must be run before we optimize in asm2wasm, as otherwise its input ↵Alon Zakai2016-09-071-2/+4
| | | | | | is not yet valid then after finalizeCalls, we must autodrop again to drop things that finalizeCalls changed
* Fix asm2wasm dead lock caused by empty modules.Logan Chien2016-08-261-1/+9
| | | | | | | | | This commit fixes an asm2wasm dead lock when asm2wasm is compiling an empty module, i.e. a module without any functions. Without this commit, worker threads are likely to leave `workerMain()` and decrease `liveWorkers` early. Consequently, `waitUntilAllReady()` will never observe `liveWorkers == numWorkers`.
* Remove unnecessary type cast.Logan Chien2016-08-261-2/+1
| | | | | std::thread can forward the arguments to main function properly. We don't have to cast them from/to void*.
* Replace std::unique<T>(new T()) with make_unique<T>().Logan Chien2016-08-261-1/+1
| | | | | | | | | | | | | | | | This commit modernize the code base by replacing: std::unique_ptr<T>(new T(...)) with: make_unique<T>(...) or: wasm::make_unique<T>(...) This is a step closer to adopt C++14 std::make_unique<T>(...).
* add OptimizingIncrementalModuleBuilder for faster incremental module ↵Alon Zakai2016-06-021-0/+252
building + optimizing