summaryrefslogtreecommitdiff
path: root/src/ast
Commit message (Collapse)AuthorAgeFilesLines
* notation change: AST => IR (#1245)Alon Zakai2017-10-2425-3206/+0
| | | The IR is indeed a tree, but not an "abstract syntax tree" since there is no language for which it is the syntax (except in the most trivial and meaningless sense).
* only look at the |signed| field of loads if it is relevant (#1235)Alon Zakai2017-10-232-4/+49
|
* Emit binary function index in comment in text format, for convenience (#1232)Alon Zakai2017-10-201-0/+59
|
* Atomics support in interpreter + optimizer + fuzz fixes for that (#1227)Alon Zakai2017-10-203-8/+47
|
* clean up ImportUtils: make getImport return the import (more consistent with ↵Alon Zakai2017-10-171-3/+3
| | | | other similar APIs) and fix some ctor-evalling handling of imports, which was incorrect - we need to create fake globals when importing globals, not later, which is too late for initialized globals from imports (#1226)
* fix ssaify bug where we failed to update the location of values as we moved ↵Alon Zakai2017-10-111-0/+13
| | | | them around, causing us to zero out the wrong thing in another place and ensuing hilarity (#1212)
* fix a dce fuzz bug where if changed to unreachable but didn't propagate that ↵Alon Zakai2017-10-101-0/+13
| | | | effect up. also add set_global support in dce (#1218)
* optimize helper funcs (like i32-div) if created in asm2wasm, so they are ↵Alon Zakai2017-10-041-0/+4
| | | | consistently handled regardless of whether we optimize in parallel or not (#1208)
* Add --trap-mode=allow/clamp/js argument to asm2wasm and s2wasm (#1210)jgravelle-google2017-10-031-0/+16
| | | | | | | | | | * Add --trap-mode=allow/clamp/js argument to asm2wasm and s2wasm * Update asm2wasm and auto_update_tests scripts to use --trap-mode * Throw std::invalid_argument instead of adding a new Invalid TrapMode type * Remove legacy asm2wasm trap mode arguments
* Share trap mode between asm2wasm and s2wasm (#1168)jgravelle-google2017-10-021-0/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Extract Asm2WasmBuilder::TrapMode to shared FloatTrapMode * Extract makeTrappingI32Binary * Extract makeTrappingI64Binary * Extract asm2wasm test script into scripts/test/asm2wasm.py This matches s2wasm.py, and makes iterating on asm2wasm slightly faster. * Simplify callsites with an arg struct * Combine func adding across i32 and i64 * Support f32-to-int in asm2wasm * Add BinaryenTrapMode pass, run pass from s2wasm * BinaryenTrapMode pass takes trap context as a parameter * Pass fully supports non-trapping binary ops * Defer adding functions until after iteration (hackily) * Update asm2wasm to work with deferred function adding, rebuild tests * Extract makeTrappingFloatToInt32 * Extract makeTrappingFloatToInt64 * Add unary conversions to trap pass * Add functions in the pass itself * Set s2wasm trap mode with command-line arguments * Print BINARYEN_PASS_DEBUG state when testing * Get asm2wasm using the BinaryenTrapMode pass instead of handling it inline * Also handle f32 to int in asm2wasm * Make BinaryenTrapMode only need a FloatTrapMode from the caller * Just pass the current binary Expression directly * Combine makeTrappingI32Binary with makeTrappingI64Binary * Pass Unary expr to makeTrappingFloatToInt32 * Unify makeTrappingFloatToInt32 & 64 * Move makeTrapping* functions inside BinaryenTrapMode, make addedFunctions non-static * Remove FloatTrapContext * Minor cleanups * Extract some smaller subfunctions * Emit name switch/casing, rename is32Bit to isI64 for consistency * Rename BinaryenTrapMode to FloatTrap, make trap mode a nested enum * Add some comments explaining why FloatTrap is non-parallel * Rename addedFunctions to generatedFunctions for precision * Rename move and split float-clamp.h to passes/FloatTrap.(h|cpp) * Use builder instead of allocator * Instantiate trap handling passes via the pass manager * Move passes/FloatTrap.h to ast/trapping.h * Add helper function to add trap-handling passes * Add trap mode pass tests * Rename FloatTrap.cpp to TrapMode.cpp * Add s2wasm trap mode tests. Force float->int conversion to be signed * Add trapping_sint_div_s test to unit.asm.js * Fix flake8 issues with test scripts * Update pass description comment * Extract building functions methods * Make generate functions into top-level functions * Add GeneratedTrappingFunctions class to manage function/import additions * Move ensure/makeTrapping functions outside class scope * Use GeneratedTrappingFunctions to add immediately in asm2wasm mode * Remove trapping_sint_div_s test We only added it to test that trapping divisions would get constant-folded at the correct time. Now that we're not changing the timing of trapping modes, the test is unneeded (and problematic). * Review feedback, add validator/*.wasm to .gitignore * Add support for unsigned float-to-int conversion * Use opcode directly instead of bools * Update s2wasm clamp test for unsigned ftoi
* fix ExpressionAnalyzer::equals on consts, they need to be bitwise equal, ↵Alon Zakai2017-09-271-1/+3
| | | | i.e., 0 != -0
* fix dce bug with not updating the parent when turning a node unreachable (#1198)Alon Zakai2017-09-251-3/+13
|
* precompute-propagate pass (#1179)Alon Zakai2017-09-124-0/+420
| | | | | | | Implements #1172: this adds a variant of precompute, "precompute-propagate", which also does constant propagation. Precompute by itself just runs the interpreter on each expression and sees if it is in fact a constant; precompute-propagate also looks at the graph of connections between get and set locals, and propagates those constant values. This helps with cases as noticed in #1168 - while in most cases LLVM will do this already, it's important when inlining, e.g. inlining of the clamping math functions. This new pass is run when inlining, and otherwise only in -O3/-Oz, as it does increase compilation time noticeably if run on everything (and for almost no benefit if LLVM has run). Most of the code here is just refactoring out from the ssa pass the get/set graph computation, so it can now be used by both the ssa pass and precompute-propagate.
* Const hoisting (#1176)Alon Zakai2017-09-121-1/+1
| | | A pass that hoists repeating constants to a local, and replaces their uses with a get of that local. This can reduce binary size, but can also *increase* gzip size, so it's mostly for experimentation and not used by default.
* asm2wasm atomics (#1171)Alon Zakai2017-09-112-0/+62
| | | | | | | | | | * translate asm.js atomics into wasm atomics * fix wasm-builder atomic load emitting, the alignment is the loaded size, not the output size * don't require code for each node type in vaccuum, for non-mentioned nodes, assume we can't optimize them out * support atomics in hashing, comparing, and copying
* clean up untaken => unreachable, as well as unnecessary named stuff in ↵Alon Zakai2017-09-061-11/+11
| | | | validation that was from when we differentiated reachable from unreachable breaks (#1166)
* Return to more structured type rules for block and if (#1148)Alon Zakai2017-09-052-37/+20
| | | | | | | | * if a block has a concrete final element (or a break with a value), then even if it has an unreachable child, keep it with that concrete type. this means we no longe allow the silly case of a block with an unreachable in the middle and a concrete as the final element while the block is unreachable - after this change, the block would have the type of the final element * if an if has a concrete element in one arm, make it have that type as a result, even if the if condition is unreachable, to parallel block * make type rules for brs and switches simpler, ignore whether they are reachable or not. whether they are dead code should not affect how they influence other types in our IR.
* Safe heap pass (#1145)Alon Zakai2017-08-281-0/+41
| | | Adds --safe-heap which instruments the code to check heap loads and stores for validity (null pointer derefs, within range of valid sbrk memory, and alignment). Used in SAFE_HEAP in emscripten.
* Add support for atomic wait and wake operators (#1140)Derek Schuff2017-08-241-0/+18
| | | According to spec at https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-wake-operators
* Don't reorder an implicit trap with a global side effect (#1133)Alon Zakai2017-08-181-6/+10
|
* use effective shifts in more places in optimize-instructionsAlon Zakai (kripken)2017-08-012-5/+6
|
* fix optimizing two shifts into one; if the number of effective shifts ↵Alon Zakai (kripken)2017-07-302-11/+30
| | | | overflows, it is not vali to just add them
* refactor effective shift size computationAlon Zakai2017-07-291-0/+11
|
* Optimizer support for atomic instructions (#1094)Derek Schuff2017-07-213-6/+55
| | | | | | * Teach EffectAnalyzer not to reorder atomics wrt other memory operations. * Teach EffectAnalyzer not to reorder host operations with memory operations * Teach various passes about the operands of AtomicRMW and AtomicCmpxchg * Factor out some functions in DeadCodeElimination and MergeBlocks
* zero shifts are not sign-extendsAlon Zakai2017-07-131-10/+14
|
* infinite loops have side effectsAlon Zakai (kripken)2017-07-131-1/+15
|
* add the option to seek named breaks, not just taken breaks; refactor headers ↵Alon Zakai (kripken)2017-07-113-2/+293
| | | | to make this practical
* refactor and improve break validation. breaks names are unique, so we don't ↵Alon Zakai (kripken)2017-07-111-0/+9
| | | | need a stack, and break targets must exist even if they are not actually taken
* Code folding (#1076)Alon Zakai2017-06-282-0/+117
| | | | | | | | | | | | | | | | Adds a pass that folds code, i.e. merges it when possible. See details in comment in the pass implementation cpp. This is enabled by default in -Os and -Oz. Seems risky to enable anywhere else, as it does add branches - likely predictable ones so maybe no slowdown, but still some risk. Code size numbers: wasm-backend: 196331 + binaryen -Os (before): 182598 + binaryen -Os (with folding): 181943 asm2wasm -Os (before): 172463 asm2wasm -Os (with folding): 168774 So this reduces wasm-backend output by an additional 0.5% than it could before. Mainly this is because the wasm backend already has code folding, whereas on asm2wasm output, where we didn't have folding before, this saves over 2%. The 0.5% improvement on the wasm backend's output might be because this can fold more types of code than LLVM can (it can fold nested control flow, in particular).
* SSA pass (#1049)Alon Zakai2017-06-131-0/+46
| | | | | | | * Add SSA pass which ensures a single assign for each local, except for merged locals where we ensure exactly a single assign from one of the paths leading to that use * Also add InstrumentLocals pass, useful for debugging locals (similar to InstrumentMemory but for locals) * Fix a PickLoadSigns bug with tees not being ignored, which was not noticed until now because we ran it on flatter output by default, but the ssa pass uncovered the bug
* Address review feedback for #1014 (#1016)Alon Zakai2017-05-184-14/+60
| | | | | | * address review feedback for #1014
* Validate finalization (#1014)Alon Zakai2017-05-184-0/+418
| | | | | | | * 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.
* ctor-eval fixes (#996)Alon Zakai2017-05-051-0/+55
| | | | | | | | * fix wasm-ctor-eval, we need to look for the STACKTOP etc. imports, they may not be named, if this build is not with -g * pack memory after ctor evalling, since we merge it up which is less efficient * do some useful opts after ctor-evalling, to clean things up
* ctor evaller (#982)Alon Zakai2017-04-281-0/+56
| | | | | Add wasm-ctor-eval, which evaluates functions at compile time - typically static constructor functions - and applies their effects into memory, saving work at startup. If we encounter something we can't evaluate at compile time in our interpreter, stop there. This is similar to ctor_evaller.py in emscripten (which was for asm.js).
* optimize pow (#934)Alon Zakai2017-03-101-0/+47
| | | | | | * optimize pow(x,2) => x*x * optimize pow(x, 0.5) => sqrt(x)
* Local CSE (#930)Alon Zakai2017-03-081-0/+59
| | | Simple local common subexpression elimination. Useful mostly to reduce code size (as VMs do GVN etc.). Enabled by default in -Oz.
* Default Walker subclasses to using Visitor<SubType> (#921)jgravelle-google2017-02-231-1/+1
| | | | Most module walkers use PostWalker<T, Visitor<T>>, let that pattern be expressed as simply PostWalker<T>
* fix a sign/unsigned compare compiler warningAlon Zakai2017-02-161-2/+2
|
* refactor sign/zero extension code into nice headers, and prepare ↵Alon Zakai2017-02-162-0/+124
| | | | PickLoadSigns pass
* Make ast_utils into a library (#892)Derek Schuff2017-01-313-0/+652
| | | | Split ExpressionAnalyzer and ExpressionManipulator into cpp files, and turn their giant template functions into simple functions which take a callback. More organization, fewer mammoth headers, makes the build a few seconds faster, and the binaries a couple MB smaller.
* refactor get_local counting out of simplify-locals (#812)Alon Zakai2016-10-281-0/+50
|
* Conditionalize boolean operations based on cost (#805)Alon Zakai2016-10-261-0/+249
| | | When we have expensive | expensive, and both are boolean, then we can execute one of them conditionally if it doesn't have side effects.
* Optimize out bool & 1 (#804)Alon Zakai2016-10-251-0/+60
* asm.js corrections to unit.asm.js test * optimize out bool&1