summaryrefslogtreecommitdiff
path: root/src/wasm.h
Commit message (Collapse)AuthorAgeFilesLines
...
* Refactor Features code (#1848)Alon Zakai2019-01-021-1/+5
| | | Add features.h which centralizes all the feature detection code. (I'll need this in another place than the validator which is where it was til now.)
* Rename `idx` to `index` in SIMD code for consistency (#1836)Thomas Lively2018-12-181-2/+2
|
* SIMD (#1820)Thomas Lively2018-12-131-2/+108
| | | | | | | | | Implement and test the following functionality for SIMD. - Parsing and printing - Assembling and disassembling - Interpretation - C API - JS API
* Create API for feature dependent picking in fuzzer (#1821)Thomas Lively2018-12-121-12/+6
|
* Implement nontrapping float-to-int instructions (#1780)Thomas Lively2018-12-041-0/+3
|
* Feature options (#1797)Thomas Lively2018-12-031-6/+34
| | | | Add feature flags and struct interface. Default feature set has all feature enabled.
* Add --strip that removes debug info (#1787)Alon Zakai2018-12-031-0/+5
| | | | This is sort of like --strip on a native binary. The more specific use case for us is e.g. you link with a library that has -g in its CFLAGS, but you don't want debug info in your final executable (I hit this with poppler now). We can make emcc pass this to binaryen if emcc is not building an output with intended debug info.
* Add support for a mutable globals as a Feature (#1785)Sam Clegg2018-11-301-0/+1
| | | | | This picks up from #1644 and indeed borrows the test case from there.
* Support 4GB Memories (#1702)Alon Zakai2018-10-151-3/+7
| | | This fixes asm2wasm parsing of the max to allow 4GB, and also changes the internal Memory::kMaxValue values to reflect that. We used to use kMaxValue to also represent "no limit", so I split that out into kUnlimitedValue.
* Unify imported and non-imported things (#1678)Alon Zakai2018-09-191-43/+23
| | | | | | | | | | | | | | Fixes #1649 This moves us to a single object for functions, which can be imported or nor, and likewise for globals (as a result, GetGlobals do not need to check if the global is imported or not, etc.). All imported things now inherit from Importable, which has the module and base of the import, and if they are set then it is an import. For convenient iteration, there are a few helpers like ModuleUtils::iterDefinedGlobals(wasm, [&](Global* global) { .. use global .. }); as often iteration only cares about imported or defined (non-imported) things.
* Add debug information locations to the function prolog/epilog (#1674)Yury Delendik2018-09-171-1/+7
| | | | | | | The current patch: * Preserves the debug locations from function prolog and epilog * Preserves the debug locations of the nested blocks
* remove PageSize and HasFeature, which wasm removed a while back (#1667)Alon Zakai2018-09-121-1/+1
| | | From #1665 (a fuzz bug noticed they were not handled in stack.h).
* Stack IR (#1623)Alon Zakai2018-07-301-22/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a new IR, "Stack IR". This represents wasm at a very low level, as a simple stream of instructions, basically the same as wasm's binary format. This is unlike Binaryen IR which is structured and in a tree format. This gives some small wins on binary sizes, less than 1% in most cases, usually 0.25-0.50% or so. That's not much by itself, but looking forward this prepares us for multi-value, which we really need an IR like this to be able to optimize well. Also, it's possible there is more we can do already - currently there are just a few stack IR optimizations implemented, DCE local2stack - check if a set_local/get_local pair can be removed, which keeps the set's value on the stack, which if the stars align it can be popped instead of the get. Block removal - remove any blocks with no branches, as they are valid in wasm binary format. Implementation-wise, the IR is defined in wasm-stack.h. A new StackInst is defined, representing a single instruction. Most are simple reflections of Binaryen IR (an add, a load, etc.), and just pointers to them. Control flow constructs are expanded into multiple instructions, like a block turns into a block begin and end, and we may also emit extra unreachables to handle the fact Binaryen IR has unreachable blocks/ifs/loops but wasm does not. Overall, all the Binaryen IR differences with wasm vanish on the way to stack IR. Where this IR lives: Each Function now has a unique_ptr to stack IR, that is, a function may have stack IR alongside the main IR. If the stack IR is present, we write it out during binary writing; if not, we do the same binaryen IR => wasm binary process as before (this PR should not affect speed there). This design lets us use normal Passes on stack IR, in particular this PR defines 3 passes: Generate stack IR Optimize stack IR (might be worth splitting out into separate passes eventually) Print stack IR for debugging purposes Having these as normal passes is convenient as then they can run in parallel across functions and all the other conveniences of our current Pass system. However, a downside of keeping the second IR as an option on Functions, and using normal Passes to operate on it, means that we may get out of sync: if you generate stack IR, then modify binaryen IR, then the stack IR may no longer be valid (for example, maybe you removed locals or modified instructions in place etc.). To avoid that, Passes now define if they modify Binaryen IR or not; if they do, we throw away the stack IR. Miscellaneous notes: Just writing Stack IR, then writing to binary - no optimizations - is 20% slower than going directly to binary, which is one reason why we still support direct writing. This does lead to some "fun" C++ template code to make that convenient: there is a single StackWriter class, templated over the "mode", which is either Binaryen2Binary (direct writing), Binaryen2Stack, or Stack2Binary. This avoids a lot of boilerplate as the 3 modes share a lot of code in overlapping ways. Stack IR does not support source maps / debug info. We just don't use that IR if debug info is present. A tiny text format comment (if emitting non-minified text) indicates stack IR is present, if it is ((; has Stack IR ;)). This may help with debugging, just in case people forget. There is also a pass to print out the stack IR for debug purposes, as mentioned above. The sieve binaryen.js test was actually not validating all along - these new opts broke it in a more noticeable manner. Fixed. Added extra checks in pass-debug mode, to verify that if stack IR should have been thrown out, it was. This should help avoid any confusion with the IR being invalid. Added a comment about the possible future of stack IR as the main IR, depending on optimization results, following some discussion earlier today.
* More reducer improvements (#1533)Alon Zakai2018-05-081-1/+1
| | | | | | * Add a helper class to iterate over all a node's children, and use that when attempting to replace a node with its children. * If a child has a different type than the parent, try to replace the parent with a conversion + the child (for example, a call may receive two f32 inputs and return an i32; we can try to replace the call with one of those f32s and a conversion to an i32). * When possible, try to replace the function body with a child even if the child has a different type, by changing the function return value.
* Some simple integer math opts (#1504)Alon Zakai2018-04-111-0/+4
| | | | | | | | | Stuff like x + 5 != 2 => x != -3. Also some cleanups of utility functions I noticed while writing this, isTypeFloat => isFloatType. Inspired by https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/generic.rules
* when creating blocks in binary format parsing, we know if a block has a ↵Alon Zakai2018-04-051-3/+10
| | | | break to it - use that to avoid rescanning blocks for unreachability purposes (#1495)
* Rename WasmType => Type (#1398)Alon Zakai2018-02-021-14/+14
| | | | * rename WasmType to Type. it's in the wasm:: namespace anyhow, and without Wasm- it fits in better alongside Index, Address, Expression, Module, etc.
* Atomic wait/wake fixes (#1383)Alon Zakai2018-01-221-0/+2
| | | | | | | | * fix wait and wake binary format support, they have alignments and offsets * don't emit unreachable parts of atomic operations, for simplicity and to avoid special handling * don't emit atomic waits by default in the fuzzer, they hang in native vm support
* Global optimization fixes (#1360)Alon Zakai2018-01-171-0/+1
| | | | | | | | | | | | | | | | * 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
* Add Features enum to IR (#1250)Derek Schuff2017-10-271-0/+7
| | | | | | | | | | | | 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).
* fuzzing improvements:Alon Zakai2017-09-271-2/+2
| | | | | | | | * randomize initial memory * low chance to have tiny blocks * decent chance to have a branch back to the loop top
* Make localNames into a map (#1189)Thomas Lively2017-09-231-1/+1
|
* Update text syntax for shared memory limits (#1197)Derek Schuff2017-09-221-0/+2
| | | | Following WebAssembly/threads#58 e.g. (memory $0 23 256 shared) is now (memory $0 (shared 23 256))
* Add support for sign-extension operators from threading proposal (#1167)Derek Schuff2017-09-061-0/+4
| | | These are not atomic operations, but are added with the atomic operations to keep from having to define atomic versions of all the sign-extending loads (an atomic zero-extending load + signext operation can be used instead).
* wasm-reduce tool (#1139)Alon Zakai2017-09-011-0/+1
| | | 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.
* i64 to i32 lowering for wasm2asm (#1134)Thomas Lively2017-09-011-1/+0
|
* Add support for atomic wait and wake operators (#1140)Derek Schuff2017-08-241-0/+26
| | | According to spec at https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-wake-operators
* Initial asm.js output for binaryen-c / binaryen.js (#1136)Daniel Wirtz2017-08-241-0/+1
| | | | * Added BinaryenModulePrintAsmjs (using wasm2asm) + Module#emitAsmjs JS binding
* fix Const finalization and use it properly in br finalization in PrecomputeAlon Zakai (kripken)2017-07-111-0/+2
|
* Add IR, parsing, printing, and binary for atomic cmpxchg (#1083)Derek Schuff2017-07-101-1/+10
|
* Add IR, parsing and binary support for AtomicRMW instructions from wasm ↵Derek Schuff2017-07-061-7/+24
| | | | | threads proposal (#1082) Also leave a stub (but valid) visitAtomicRMW in the visitor template so that not all visitors need to implement this function yet.
* Add atomic loads and stores (#1077)Derek Schuff2017-06-281-0/+10
| | | | | Add IR, wast and binary support for atomic loads and stores. Currently all IR generated by means other than parsing wast and binary files always generates non-atomic accesses, and optimizations have not yet been made aware of atomics, so they are certainly not ready to be used yet.
* Add shared memories (#1069)Derek Schuff2017-06-271-1/+2
| | | | | Begin to implement wasm threading proposal in https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md This PR just has shared memory attribute with wast and binary support.
* Update binaryen-c/binaryen.js, fixes #1028, fixes #1029 (#1030)Daniel Wirtz2017-06-071-0/+1
| | | This PR adds global variable support (addGlobal, getGlobal, setGlobal), host operations (currentMemory, growMemory), a few utility functions (removeImport, removeExport, getFunctionTypeBySignature with the latter being scheduled for removal once a better alternative is in place) and it introduces an additional argument to specify the result type in BinaryenBlock (effectively breaking the C-API but retaining previous behaviour by introducing the BinaryenUndefined() type for this purpose). Additionally, it enables compilation with exception support in build-js.sh as exceptions are thrown and caught when optimizing endless loops, intentionally resulting in an unreachable opcode. Affected test cases have been updated accordingly.
* Exporting/importing debug location information from .wast/.asm.js/.s formats ↵Yury Delendik2017-06-011-1/+3
| | | | | | | | (#1017) * Extends wasm-as, wasm-dis and s2wasm to consume debug locations. * Exports source map from asm2wasm
* Unreachable typing fixes (#1004)Alon Zakai2017-05-091-0/+14
| | | | | | | | | | | | * fix type of drop, set_local, set_global, load, etc: when operand is unreachable, so is the node itself * support binary tests properly in test/passes * fix unreachable typing of blocks with no name and an unreachable child * fix continue emitting in asm2wasm * properly handle emitting of unreachable load
* fix unreachable typing: for all nodes, if they are not reached - e.g., a ↵Alon Zakai (kripken)2017-05-021-0/+2
| | | | binary with either side unreachable - then they are unreachable. this makes our usage of the unreachable type consistent
* wasm-merge tool (#919)Alon Zakai2017-04-171-0/+1
| | | | wasm-merge tool: combines two wasm files into a larger one, handling collisions, and aware of the dynamic linking conventions. it does not do full static linking, but may eventually.
* Replace text annotations with explicit file/line for debug info (#967)Derek Schuff2017-04-131-2/+5
| | | Rather than storing debug info as text annotations, store explicit file and line information. This will make it easier to experiment with outputting other serializations or representations (e.g. source maps), and will allow outputting debug info for binaries as well.
* Wasm h to cpp (#926)jgravelle-google2017-03-101-987/+53
| | | | | | | | | | | | | | | | | | | | | | | | * Move WasmType function implementations to wasm.cpp * Move Literal methods to wasm.cpp * Reorder wasm.cpp shared constants back to top * Move expression functions to wasm.cpp * Finish moving things to wasm.cpp * Split out Literal into its own .h/.cpp. Also factor out common wasm-type module * Remove unneeded/transitive includes from wasm.h * Add comment to try/check methods * Rename tryX/checkX methods to getXOrNull * Add missing include that should fix appveyor build breakage * More appveyor
* Fully handle EM_ASM in s2wasm (#910)jgravelle-google2017-02-231-26/+1
| | | | | | | | | | | | * Fully handle EM_ASM in s2wasm * Iterate with size_ts, remember to erase from importsMap as well * Fix dot_s test EM_ASM signatures * Move Name out to its own file, support/name.h * Move removeImportsWithSubstring out of Module class
* read unknown users sections as binary data stored on the Module (#918)Alon Zakai2017-02-211-0/+10
|
* clean up raw pointer import->functionType, make it a Name like everything ↵Alon Zakai2017-02-171-2/+2
| | | | else (#915)
* asm2wasm debuginfo (#895)Alon Zakai2017-02-071-0/+3
| | | | | | | | | | | | * parse file/line comments in asm.js into debug intrinsics * convert debug intrinsics into annotations, and print them * ignore --debuginfo if not emitting text, as wasm binaries don't support that yet * emit full debug info when -g and emitting text; when -g and emitting binary, all we can do is the Names section * update wasm.js
* add a RemoveUnusedModuleElements pass, and make LegalizeJSInterface create ↵Alon Zakai2016-12-071-3/+19
| | | | TempRet0 if needed (otherwise we might remove it before we use it)
* more consistent placement of & and *, on the type (#848)Alon Zakai2016-11-281-28/+34
|
* Don't create a memory section for an imported memory; fixes #772 (#773)Benjamin Bouvier2016-10-131-1/+5
|
* Don't create table sections for imported tables (#756)Derek Schuff2016-10-111-1/+2
| | | Previously the Print pass searched the imports for a table import and skipped printing a local table declaration if found. Instead this refactors to make importation explicit, and also create importation records (previously we were inconsistent about whether such records were created in the IR depending on the wast syntax).
* More binary updates for 0xc (#733)Derek Schuff2016-10-031-1/+4
| | | | | | | | | | | | | | | Refine tables to explicitly exist or not. Previously they were printed or encoded if it had any segments, or an initial or max size. However tables can be defined but empty, so we had a special hack that defined an empty segment when we really just wanted an empty table. Now, just make the existence explicit. Update Function table encoding for 0xc (Table and Element sections) Add end opcodes after function bodies (these are consumed by getMaybeBlock with the same behavior that it had before when it reached the function end, so no explicit decode) Update call_indirect encoding for 0xc (no arity, call target is last)
* Refactor Import::Kind and Export::Kind into an ExternalKind enum class (#725)Alon Zakai2016-10-031-16/+9
|