summaryrefslogtreecommitdiff
path: root/src/tools
Commit message (Collapse)AuthorAgeFilesLines
* First pass at LLD support for Emscripten (#1346)Jacob Gravelle2018-01-223-1/+222
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Skeleton of a beginning of o2wasm, WIP and probably not going to be used * Get building post-cherry-pick * ast->ir, remove commented out code, include a debug module print because linking * Read linking section, print emscripten metadata json * WasmBinaryWriter emits user sections on Module * Remove debugging prints, everything that isn't needed to build metadata * Rename o2wasm to lld-metadata * lld-metadata support for outputting to file * Use tables index instead of function index for initializer functions * Add lld-emscripten tool to add emscripten-runtime functions to wasm modules (built with lld) * Handle EM_ASM in lld-emscripten * Add a list of functions to forcibly export (for initializer functions) * Disable incorrect initializer function reading * Add error printing when parsing .o files in lld-metadata * Remove ';; METADATA: ' prefix from lld-metadata, output is now standalone json * Support em_asm consts that aren't at the start of a segment * Initial test framework for lld-metadata tool * Add em_asm test * Add support for WASM_INIT_FUNCS in the linking section * Remove reloc section parsing because it's unused * lld-emscripten can read and write text * Add test harness for lld-emscripten * Export all functions for now * Add missing lld test output * Add support for reading object files differently Only difference so far is in importing mutable globals being an object file representation for symbols, but invalid wasm. * Update help strings * Update linking tests for stackAlloc fix * Rename lld-emscripten,lld-metadata to wasm-emscripten-finalize,wasm-link-metadata * Add help text to header comments * auto& instead of auto & * Extract LinkType to abi/wasm-object.h * Remove special handling for wasm object file reading, allow mutable globals * Add braces around default switch case * Fix flake8 errors * Handle generating dyncall thunks for imports as well * Use explicit bool for stackPointerGlobal * Use glob patterns for lld file iteration * Use __wasm_call_ctors for all initializer functions
* Optimize wasm-reduce (#1359)Alon Zakai2018-01-201-30/+99
|
* Add readData to fuzz support, making it easier to use (#1378)Sergey Pepyakin2018-01-191-7/+16
|
* Refactor optimization defaults (#1366)Alon Zakai2018-01-171-3/+1
| | | | | Followup to #1357. This moves the optimization settings into pass.h, and uses it from there in the various places. This also splits up huge lines from the tracing code, which put all block children (whose number can be arbitrarily large) on one line. This seems to have caused random errors on the bots, I suspect from overflowing a buffer. Anyhow, it's much more clear to split the lines at a reasonable length.
* Add optimize, shrink level and debug info options to C/JS (#1357)Daniel Wirtz2018-01-171-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add optimize, shrink level and debug info options to C/JS * Add instantiate functionality for creating additional unique instances of the API * Use a workaround when running tests in node Tests misuse a module as a script by concatenating, so instead of catching this case in the library, catch it there * Update sieve test Seems optimized output changed due to running with optimize levels 2/1 now * Use the options with all pass runners * Update relooper-fuzz C-API test * Share defaults between tools and the C-API * Add a test for optimize levels * Unify node test support in check.by and auto_update_tests.py * Also add getters for optimize levels and test them * Also test debugInfo * Add debug info to C tests that used it as well * Fix missing NODEJS import in auto_update_tests * Detect node.js version (WASM support) * Update hello-world JS test (now also runs with node) * feature-test WebAssembly in node instead * Document that these options apply globally, and where * Make sure hello-world.js output doesn't differ between mozjs/node
* when not allowing atomics, don't emit the new extend instructions that ↵Alon Zakai2018-01-101-2/+16
| | | | arrive with them (#1354)
* Optimize out memory and table when possible (#1352)Alon Zakai2018-01-101-3/+12
| | | We can remove the memory/table (itself, or an import if imported) if they are not used. This is pretty minor on a large wasm file, but when reading small wasts it's very noticeable to have an unused memory and table all the time.
* fix an infinite loop in fuzz testcase generation code (#1345)Alon Zakai2018-01-031-1/+1
|
* merge-locals pass (#1334)Alon Zakai2017-12-172-23/+39
| | | | | | | | | This optimizes the situation described in #1331. Namely, when x is copied into y, then on subsequent gets of x we could use y instead, and vice versa, as their value is equal. Specifically, this seems to get rid of the definite overlap in the live ranges of x and y, as removing it allows coalesce-locals to merge them. The pass therefore does nothing if the live range of y ends there anyhow. The danger here is that we may extend the live range so that it causes more conflicts with other things, so this is a heuristic, but I've tested it on every codebase I can find and it always produces a net win, even on one I saw a 0.4% reduction of code size, which surprised me. This is a fairly slow pass, because it uses LocalGraph which isn't much optimized. This PR includes a minor optimization for it, but we should rewrite it. Meanwhile this is just enabled in -O3 and -Oz. This PR also includes some fuzzing improvements, to better test stuff like this.
* metadce fixes (#1329)Alon Zakai2017-12-071-37/+114
| | | | | | | | | | | | * ignore missing imports (the wasm may have already had them optimized out) * handle segments that hold on to globals (root them, for now, as we can't remove segments) * run reorder-functions, as the optimal order may have changed after we dce * fix global, global init, and segment offset reachability * fix import rooting and processing - imports may be imported more than once
* wasm-metadce tool (#1320)Alon Zakai2017-12-061-0/+471
| | | | | | | This adds a new tool for better dead code elimination. The problem this helps overcome is when the wasm module is part of something larger, like a wasm+JS combination, and therefore doing DCE in either one is not sufficient as it can't remove a cycle spanning the wasm and JS worlds. Concretely, when binaryen performs DCE by itself, it can never remove an export, because it considers those roots - but in the larger ("meta") space outside, they may actually be removable. To solve that, this tool receives a description of the outside graph (in very abstract form), including which nodes are roots. It then adds to that graph nodes from the wasm, so that we have a single graph representing the entire space (the outside + wasm + connections between them). It then performs DCE, finding what is not reachable from the roots, and cleaning it up from the wasm. It of course can't clean up things from the outside, since all it has is the abstract representation of those things in the graph, but it prints out the ids of the removable nodes, which an outside tool can use. This tool is written in as general a way as possible, hopefully it can have multiple uses. The use I have in mind is to write something in emscripten that uses this to DCE the JS+wasm combination that we emit.
* support i*.extend* instructions in interpreter (#1322)Alon Zakai2017-12-061-2/+2
| | | * also fixes optimizing them in Precompute
* support fixed (non-relocatable) segments in wasm-merge. also a few printing ↵Alon Zakai2017-12-051-7/+27
| | | | fixes for multiple segments, which we never really printed that prettily (#1316)
* Fixed compilation in GCC 7 (#1301)Iban Eguia2017-11-301-1/+15
|
* add invocation functions for fuzz functions, so they are tested with many ↵Alon Zakai2017-11-301-4/+36
| | | | input values (#1303)
* Fix wasm-reduce testing out of tree (#1284)Alon Zakai2017-11-211-2/+3
| | | | * fix wasm-reduce when out-of-tree: do not use a hardcoded bin/wasm-opt, instead add a Path namespace with utilities to get the proper path, and use BINARYEN_ROOT which our test setup code ensures
* Decouple wasm-linker from Emscripten glue (#1293)Jacob Gravelle2017-11-151-12/+12
|
* Fast pass fuzzing (#1258)Alon Zakai2017-11-132-24/+85
| | | | * add fuzz-pass option, which picks random passes to fuzz in each wasm-opt invocation
* fix wasm-reduce bug, the second validator param is the features, not the ↵Alon Zakai2017-11-091-1/+1
| | | | flags (#1277)
* Restrict validation output to just validation errors in the API (#1253)Daniel Wirtz2017-11-016-4/+23
| | | Do not print the entire and possibly very large module when validation fails. Leave printing to tools using the validator, instead of always doing it in the validator where it can't be overridden.
* Print wasm2asm parsing errors (#1251)Alon Zakai2017-10-271-0/+100
|
* Add Features enum to IR (#1250)Derek Schuff2017-10-274-7/+15
| | | | | | | | | | | | This enum describes which wasm features the IR is expected to include. The validator should reject operations which require excluded features, and passes should avoid producing IR which requires excluded features. This makes it easier to catch possible errors in Binaryen producers (e.g. emscripten). Asm2wasm has a flag to enable or disable atomics. Other tools currently just accept all features (as, dis and opt are just for inspecting or modifying existing modules, so it would be annoying to have to use flags with those tools and I expect the risk of accidentally introducing atomics to be low).
* notation change: AST => IR (#1245)Alon Zakai2017-10-245-8/+8
| | | 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).
* Improve constant fuzzing (#1244)Alon Zakai2017-10-241-5/+8
| | | | | Generalize constant emitting in fuzzer, using +-1 and *+-1 effects to create more constants in a convenient way. Also workaround for a gcc-7.2/windows issue that we don't fully understand, but removing the 1, -1 from those pick() calls avoids the bug.
* Remove unused PassOptions from wasm-ctor-eval.cpp (#1238)Taiju Tsuiki2017-10-241-1/+0
| | | |passOptions| in wasm-ctor-eval.cpp causes a compile failure, -Wunused-variable on the clang build.
* add a timeout param to wasm-reduce (#1230)Alon Zakai2017-10-231-2/+11
|
* Atomics support in interpreter + optimizer + fuzz fixes for that (#1227)Alon Zakai2017-10-201-83/+103
|
* Avoid returning a PassRunner just for OptimizationOptions (#1234)Alon Zakai2017-10-202-5/+3
| | | | | | | | * avoid returning a PassRunner just for OptimizationOptions, it would need a more careful design with a copy constructor. instead, just simplify the API to do the thing we need, which is run the passes * disallow copy constructor * delete copy operator too
* clean up ImportUtils: make getImport return the import (more consistent with ↵Alon Zakai2017-10-171-22/+38
| | | | 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)
* Add Builder::makeGlobal for nicer global creation (#1221)Alon Zakai2017-10-101-10/+12
|
* some readme and doc fixes and improvements (#1219)Alon Zakai2017-10-101-1/+1
|
* Fuzzer: create and use globals in fuzz programs (#1217)Alon Zakai2017-10-101-5/+44
|
* Refactor validator API to use enums (#1209)Alon Zakai2017-10-033-3/+4
| | | | * refactor validator API to use enums
* Add --trap-mode=allow/clamp/js argument to asm2wasm and s2wasm (#1210)jgravelle-google2017-10-032-33/+27
| | | | | | | | | | * 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
* Fast validation (#1204)Alon Zakai2017-10-021-3/+1
| | | | | | | This makes wasm validation parallel (the function part). This makes loading+validating tanks (a 12MB wasm file) 2.3x faster on a 4-core machine (from 3.5 to 1.5 seconds). It's a big speedup because most of loading+validating was actually validating. It's also noticeable during compilation, since we validate by default at the end. 8% faster on -O2 and 23% on -O0. So actually fairly significant on -O0 builds. As a bonus, this PR also moves the code from being 99% in the header to be 1% in the header.
* Share trap mode between asm2wasm and s2wasm (#1168)jgravelle-google2017-10-022-5/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* fuzzing improvements:Alon Zakai2017-09-271-2/+29
| | | | | | | | * randomize initial memory * low chance to have tiny blocks * decent chance to have a branch back to the loop top
* remove implicit fallthroughs (#1194) (#1196)Jeremy Day2017-09-201-3/+11
|
* precompute-propagate pass (#1179)Alon Zakai2017-09-122-15/+3
| | | | | | | 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.
* more special constants classes in fuzzingAlon Zakai2017-09-061-3/+24
|
* initial call_indirect support in ttf modeAlon Zakai2017-09-061-2/+59
|
* wasm-reduce tool (#1139)Alon Zakai2017-09-011-0/+661
| | | Reduce an interesting wasm to a smaller still interesting wasm. This takes an arbitrary command to run, and reduces the wasm as much as it can while keeping the behavior of that command fixed. This can be used to reduce compiler bugs in an arbitrary VM, etc.
* improve fuzzing of functions with unreachable bodyAlon Zakai (kripken)2017-08-281-7/+7
|
* add an option to run an extra command when fuzzing in wasm-optAlon Zakai2017-08-251-13/+56
| | | | for now this is linux-only as it uses popen etc.
* add a chance to make a get_local in makeTrivial, so that hang-check returns ↵Alon Zakai (kripken)2017-08-251-5/+11
| | | | etc. don't always return a constant, but may return the result of computation
* increase fuzz hang limit (to basically the point where the spec interpreter ↵Alon Zakai (kripken)2017-08-251-1/+1
| | | | almost fails)
* Fuzzing improvement: Run execution results on the same instance (#1132)Alon Zakai2017-08-221-12/+27
| | | | | | | | * run execution results on the same instance, so side effects of memory writes persist, which is the same as when we run the code in a js vm, so we can directly compare * fuzz only exported functions, not things that opts might remove * note results in fuzz-exec by export name
* New fuzzer (#1126)Alon Zakai2017-08-116-83/+1441
| | | | | | This adds a new method of fuzzing, "translate to fuzz" which means we consider the input to be a stream of data that we translate into a valid wasm module. It's sort of like a random seed for a process that creates a random wasm module. By using the input that way, we can explore the space of valid wasm modules quickly, and it makes afl-fuzz integration easy. Also adds a "fuzz binary" option which is similar to "fuzz execution". It makes wasm-opt not only execute the code before and after opts, but also write to binary and read from it, helping to fuzz the binary format.
* Improve and enable inlining pass (#966)Alon Zakai2017-08-071-1/+1
| | | | | | | | * 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
* Fix wrong name in --help output (#1099)Alan Mimms2017-07-171-1/+1
|