summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* fix liveness-traversal: an action can be either a get, a set, or an other, ↵Alon Zakai2018-03-141-2/+4
| | | | and we assumed a non-get is a set (caught by valgrind) (#1472)
* Function pointer cast emulation (#1468)Alon Zakai2018-03-1311-8/+272
| | | | | | | | | | | This adds a pass that implements "function pointer cast emulation" - allows indirect calls to go through even if the number of arguments or their types is incorrect. That is undefined behavior in C/C++ but in practice somehow works in native archs. It is even relied upon in e.g. Python. Emscripten already has such emulation for asm.js, which also worked for asm2wasm. This implements something like it in binaryen which also allows the wasm backend to use it. As a result, Python should now be portable using the wasm backend. The mechanism used for the emulation is to make all indirect calls use a fixed number of arguments, all of type i64, and a return type of also i64. Thunks are then placed in the table which translate the arguments properly for the target, basically by reinterpreting to i64 and back. As a result, receiving an i64 when an i32 is sent will have the upper bits all zero, and the reverse would truncate the upper bits, etc. (Note that this is different than emscripten's existing emulation, which converts (as signed) to a double. That makes sense for JS where double's can contain all numeric values, but in wasm we have i64s. Also, bitwise conversion may be more like what native archs do anyhow. It is enough for Python.) Also adds validation for a function's type matching the function's actual params and result (surprised we didn't have that before, but we didn't, and there was even a place in the test suite where that was wrong). Also simplifies the build script by moving two cpp files into the wasm/ subdir, so they can be built once and shared between the various tools.
* Fuzz fix: fix copying of host node operands (#1464)Alon Zakai2018-03-081-2/+6
|
* asm2wasm warning improvement (#1463)Alon Zakai2018-03-081-0/+14
| | | | | | * limit the amount of asm2wasm warnings on arguments added/removed in flexible argument handling (e.g. in Python there can be many thousands of such warnings, flooding the output...) * also lock, because those warnings can come from multiple threads
* Let s2wasm emit binary output (#1465)Jacob Gravelle2018-03-083-12/+81
| | | | | | | | | | | | | | | | | | | | * Emit invokeFuncs list as metadata * Refactor s2wasm to use ModuleWriter * Fix wasm-emscripten-finalize metadata output for binary output * Add a flag to emit binary from s2wasm NOTE: I chose to emit text by default, and binary behind a flag. This mismatches with asm2wasm (and the expectations of users of a "2wasm" tool), but doesn't break any existing users of s2wasm. If s2wasm is deprecated in favor of lld, this will be the least disruptive change, and we won't have to live with awkward defaults for too long. * Emit source maps in the binary output of s2wasm * Only emit binary with an outfile specified
* Fuzz fix: if global does not exist, report error and don't run the rest of ↵Alon Zakai2018-03-071-37/+38
| | | | the checks (#1461)
* afl-fuzz fixes for table/memory instantiation (#1460)Alon Zakai2018-03-062-19/+27
| | | | | | | | | | * replace assert with a proper trap for an invalid offset in table initialization * fix offset handling in initial table size computation: it is an unsigned value * handle traps in fuzz-exec when creating instance * optimization may remove imports - and imported table init may trap, so opts may remove that trap. check for result comparisons in the right order, so we don't get bothered by that
* wasm-reduce improvement: while function removal works, keep doing it (#1459)Alon Zakai2018-03-061-2/+6
|
* better asm2wasm error handling and reporting (#1456)Alon Zakai2018-03-051-5/+5
|
* eliminate multiple return statements for wasm2asm functions (#1448)Nathan Froyd2018-03-011-2/+3
| | | | This change eliminates one issue that prevents asm.js validation of the generated code, see #1443.
* Drop 'start' in RemoveUnusedModuleElements if the function is empty (#1449)Daniel Wirtz2018-02-281-1/+7
| | | | | | * Drop start function in RemoveUnusedModuleElements if empty * Update tests and dist files
* Fuzz parameter improvements: more params&vars (#1451)Alon Zakai2018-02-281-2/+8
|
* Flexible param numbers in asm2wasm (#1439)Alon Zakai2018-02-272-9/+43
| | | | | | | | | | * refactor BINARYEN_PASS_DEBUG code for writing byn-* files, make it easy to emit binaries instead of text * fix up bad argument numbers in asm2wasm. This can be caused by undefined behavior on the LLVM side, which happens to work natively. it's nicer to fix it up like it would be in a native build, and give a warning, instead of failing to compile * update build-js.sh * updated builds
* EM_JS binaryen support (#1410)Jacob Gravelle2018-02-262-62/+137
| | | | | | | | | | | * Emit EM_JS metadata * Include s2wasm-style em_js support * Change em_js metadata to be keyed on name * Add testcase for em_js, don't always emit emJsFuncs metadata * Better error handling for unexpectedly-formatted __em_js__ functions
* fix and implement more unary ops (#1442)Nathan Froyd2018-02-261-8/+120
| | | | | | | | | | | | | | | | | | * add tests for i32.popcnt * lower i64.popcnt * add tests for i64.extend_u/i32 * lower i64.extend_s/i32 * fix lowering i64.eqz * lower i64.eqz more efficiently * add tests for i32.clz/i32.ctz * lower i64.clz/i64.ctz
* Generate all s2wasm metadata in binaryen (#1440)Jacob Gravelle2018-02-261-11/+55
| | | | | | | | | * Extract comma-handling logic into a lambda function * Start emitting all metadata from binaryen - handle declares and externs * Add implementedFunctions and exports metadata * Remove EM_ASM calls from declares
* fix an ssa bug: we can't assume that even if all set locations assign to the ↵Alon Zakai2018-02-222-59/+29
| | | | same local that it is ok to read that local, as locals may also be written elsewhere (#1423)
* ensure unique import names for each type, by giving them a prefix, avoiding ↵Alon Zakai2018-02-221-1/+7
| | | | collisions between say a global import and a function with a name from the name section that happens to match it (#1424)
* Add i64 high bits (tempRet0) helper funcs when legalizing JS interface (#1428)Alon Zakai2018-02-221-0/+43
| | | | * add tempRet0 helpers when necessary in legalize-js-interface
* Improve name mangling of asm.js identifiers (#1433)Daniel Wirtz2018-02-214-20/+297
| | | | | | Also refactors mangling to its own file so it can be reused by generators and consumers, i.e., where it is important to know that an import must be named 'switch_' where it otherwise would be 'switch'. * Update tests and JS dist files
* wasm2asm fixes (#1436)Alon Zakai2018-02-201-12/+0
| | | | | | * don't look for asm.js compilation message if almost asm * fix wasm2asm f32 operations
* Add global initializers to wasm2asm (#1434)Daniel Wirtz2018-02-201-0/+38
| | | | Adds support for (constant i32/f32/f64) global variable initializers, which were previously ignored though get_global/set_global are supported.
* determinism fix: hash results may differ between runs (#1431)Alon Zakai2018-02-161-17/+16
| | | Hash results may differ between runs, as they can depend on pointers. In remove-duplicate-functions, that shouldn't matter, except that we only considered the first item in each hash group vs the others (to avoid O(N^2)), which is fine except for hash collisions (collisions mean 2 groups are merged into one, and considering just the first item vs the rest we miss out on the other duplicates in that single group). And hash collisions do occur (rarely) in practice. Instead, consider all comparisons in each hash group, which should be fine unless we have large amounts of hash collisions.
* better handling of float ops in wasm2asm (#1427)Nathan Froyd2018-02-151-101/+176
| | | | | | | | | | | | | | | | | | | | * explicitly handle binary float operations in processFunctionBody We weren't handling them before, but it wasn't obvious. Make the (non-) handling of them explicit in the code. We'll add handlers for them shortly. * add handling for simple binary float operations min, max, and copysign will require more sophisticated handling. * add handling for float comparisons * move float min/max handling to the correct place It was previously grouped with the i32 ops. * handle float promotion and demotion
* implement lowering for i64 subtraction (#1429)Nathan Froyd2018-02-141-8/+58
| | | | | | | | | * fix lowering of i64 adds We're not permitted to reuse the input as temporary variables for the results. Weird things happen otherwise. * add support for lowering i64 subtraction
* add wasm2asm lowering for 64-bit signed comparisons (#1421)Nathan Froyd2018-02-141-1/+50
| | | Plus some tests, to make sure we implemented things correctly.
* fix some comment typos (#1425)Nathan Froyd2018-02-141-2/+2
|
* Fold wasm-link-metadata into wasm-emscripten-finalize (#1408)Jacob Gravelle2018-02-144-136/+55
| | | | | | | * wasm-link-metadata: Use `__data_end` symbol. * Add --global-base param to emscripten-wasm-finalize to compute staticBump properly * Let ModuleWriter write to a provided Output object
* More simple math opts (#1414)Alon Zakai2018-02-144-7/+62
| | | | | | | | * optimize more simple math operations: mul of 0, or of 0, and of 0, mul of 1, mul of a power of 2, urem of a power of 2 * fix asm2wasm callImport parsing: the optimizer may get rid of the added offset to a function table * update js builds
* Fix safe-heap bounds checking (#1415)Alon Zakai2018-02-121-4/+4
| | | | | * fix safe heap check for load/store of fewer bytes than the type
* wasm-reduce tweaks and improvements (#1405)Alon Zakai2018-02-112-13/+53
| | | | | * wasm-reduce tweaks and improvements: better error messages, better validation, better function removal, etc.
* remove recursion-avoiding code in fuzzer, now that we have hang prevention ↵Alon Zakai2018-02-111-5/+0
| | | | it's useful to test infinite loops (#1404)
* Emscripten addFunction support for Wasm backend (#1395)Heejin Ahn2018-02-075-11/+168
| | | This adds necessary command line options for addFunction support, and generates required jsCall imports and generates jsCall thunk functions.
* Dedupe function names when reading a binary (#1396)Jacob Gravelle2018-02-061-8/+9
| | | | | | | | * Dedupe function names when reading a binary * More robust name deduplication, use .s instead of _s * Add name-duplicated wasm binaries
* Update wasm2asm to generate "almost asm" if grow_memory is used (#1340)Kris Selden2018-02-063-8/+230
| | | | | | | | | | * Allow wasm2asm to generate "almost asm" If grow_memory, current_memory or export memory is used then generate "almost asm" with memory growth support. * Log reason for "almost asm" to stderr
* Note isAtomic in loads and stores (#1406)Alon Zakai2018-02-051-0/+4
| | | | | | * check isAtomic in comparisons * hash isAtomic
* 'std::string &' => 'std::string& ' (#1403)Alon Zakai2018-02-0516-80/+80
| | | The & on the type is the proper convention.
* Fix -Wcatch-value from GCC 8 (#1400)Josh Stone2018-02-053-4/+4
| | | These instances may simply be caught by reference instead.
* Inlining improvements (#1397)Alon Zakai2018-02-022-27/+42
| | | | | | | Simplify inlining logic: don't special case the first iteration or change behavior based on when we are optimizing or not. Instead, use one simpler set of heuristics for both inlining and inlining-optimizing. We only run inlining-optimizing by default anyhow, no point to try to make inlining without optimizations useful by itself, it's not a realistic use case. (inlining is still useful for debugging, and if you will run optimizations anyhow later on everything, in which case inlining-optimizing might add some redundancy.) The simpler heuristics after this let us do a somewhat better job as we are no longer paranoid about inlining in multiple iterations. Also raise limit on inlining things that are obviously worth it from size 1 to size 2: things of size 2 will never lead to an increase in code size after we optimize (it takes at least 3 nodes to generate something that reads two locals and reverses their order, which would require a temp local in the outside scope etc.). Also fix infinite recursion of inlining an infinitely recursive set of calls.
* Rename WasmType => Type (#1398)Alon Zakai2018-02-0256-657/+657
| | | | * rename WasmType to Type. it's in the wasm:: namespace anyhow, and without Wasm- it fits in better alongside Index, Address, Expression, Module, etc.
* Fix hard-wired buffer limit in the JS API (#1394)Daniel Wirtz2018-02-013-22/+58
|
* Simplify ThreadPool::isRunning (#1391)Alon Zakai2018-01-302-3/+2
| | | | | | * simplify ThreadPool::isRunning: it doesn't need to be static and to go through the global unique_ptr * it's undefined behavior to access the threadpool from a shutting down thread, as the parent is being destroyed
* Add startsWith function to IString (#1393)Heejin Ahn2018-01-291-0/+9
|
* Sourcemap support for Binaryen C/JS (#1392)Daniel Wirtz2018-01-293-25/+130
| | | | | | * Initial source map support for C/JS * Also test getDebugInfoFileName
* Don't write sourceMappingURL section if URL is empty. (#1390)Yury Delendik2018-01-261-1/+1
|
* ThreadPool refactoring (#1389)Alon Zakai2018-01-262-33/+43
| | | | | | | | Refactor ThreadPool code for clarity and to fix some bugs with using the pool from different threads in parallel. We have a singleton pool, and need to ensure it is created only once and used only by one thread at a time. This model is a simple way to ensure we use a number of threads equal to the number of cores, more or less (a pool per Module might lead to number of cores * number of Modules being optimized). This refactoring adds a parent pointer in the worker threads (giving them direct access to the pool makes it simpler to make sure that pool and thread creation and teardown are threadsafe). This commit also adds proper locking around pool creation and pool usage.
* address some MSVC warnings (#1386)Nathan Froyd2018-01-252-4/+4
| | | | | | | | | | | | | | | | | | | | | | * fix unused variable warnings in wasm2asm.cpp No need to give the bad_alloc exception a name when we do nothing with it. * add appropriate casts for shift operands MSVC complains about implicitly converting results from 32 bits to 64 bits here, so we might as well make it clear that we intended the 64-bit shift to happen in the first place. * disable C4722 on MSVC We annotated Fatal::~Fatal with WASM_NORETURN, yet MSVC still warns, so take the next step and silence the warning completely. * don't warn about "deprecated" POSIX functions with MSVC Non-Windows platforms don't have the names MSVC recommends using, and everybody understands the POSIX names, so just silence the warning.
* Inlining improvements (#1375)Alon Zakai2018-01-241-11/+39
| | | | | | * inline 1-element functions when optimizing, as they will be smaller than the call we are replacing * add an extra useful vacuum after inlining+optimizing
* Threading fixes (#1377)Alon Zakai2018-01-242-6/+21
| | | | | | * threading fixes, be careful when creating the pool (more than one thread may try to) and don't create it just to check if its running in the thread constructor assertions * child threads will call ::get() - don't do initialize() under the lock
* Improve LocalGraph (#1382)Alon Zakai2018-01-248-294/+188
| | | | | This simplifies the logic there into a more standard flow operation. This is not always faster, but it is much faster on the worst cases we saw before like sqlite, and it is simpler. The rewrite also fixes a fuzz bug.