summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Avoid segfault when printing null nameThomas Lively2018-11-151-3/+3
| | | | `strpbrk` segfaults when `name.str` is nullptr, so check first.
* Suppress the 'has StackIR' comment when printing StackIR (#1726)Daniel Wirtz2018-11-041-1/+1
| | | Follow-up to #1717
* Emit imports before defined things in text format (#1715)Alon Zakai2018-11-011-4/+13
| | | | | That is the correct order in the text format, wabt errors otherwise. See AssemblyScript/assemblyscript#310
* Unify imported and non-imported things (#1678)Alon Zakai2018-09-191-50/+83
| | | | | | | | | | | | | | 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-9/+34
| | | | | | | 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-7/+0
| | | From #1665 (a fuzz bug noticed they were not handled in stack.h).
* Print Stack IR in proper .wat format (#1630)Alon Zakai2018-08-141-340/+593
| | | This now makes --generate-stack-ir --print-stack-ir emit a fully valid .wat wasm file, in stacky format.
* Stack IR (#1623)Alon Zakai2018-07-301-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Clean up printing code (#1548)Alon Zakai2018-05-151-4/+27
| | | | | * make the iostream overrides receive a reference, not a pointer (i.e., like e.g. LLVM IR printing works, and avoiding overriding printing of pointer addresses which is sort of odd) * move more code out of headers, especially unrelated headers.
* In full-printing mode, print comments for control flow endings, to help ↵Alon Zakai2018-05-141-0/+22
| | | | | | | | | | | readability (#1552) Like this: (block $x .. ) ;; end block $x Also fix some current breakage on master.
* Fix MSVC warnings when compiling the binaryen target (#1535)Daniel Wirtz2018-05-091-3/+3
|
* Rename WasmType => Type (#1398)Alon Zakai2018-02-021-23/+23
| | | | * 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/+6
| | | | | | | | * 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
* Optimize out memory and table when possible (#1352)Alon Zakai2018-01-101-0/+2
| | | 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.
* support fixed (non-relocatable) segments in wasm-merge. also a few printing ↵Alon Zakai2017-12-051-4/+2
| | | | fixes for multiple segments, which we never really printed that prettily (#1316)
* Update call_indirect text syntax to match spec update (#1281)Derek Schuff2017-11-131-1/+1
| | | | Function type gets its own element rather than being a part of the call_indirect (see WebAssembly/spec#599)
* notation change: AST => IR (#1245)Alon Zakai2017-10-241-1/+1
| | | 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).
* Emit binary function index in comment in text format, for convenience (#1232)Alon Zakai2017-10-201-0/+11
|
* Atomics support in interpreter + optimizer + fuzz fixes for that (#1227)Alon Zakai2017-10-201-1/+3
|
* Update text syntax for shared memory limits (#1197)Derek Schuff2017-09-221-3/+4
| | | | 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/+5
| | | 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).
* Add support for atomic wait and wake operators (#1140)Derek Schuff2017-08-241-2/+21
| | | According to spec at https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-wake-operators
* Add IR, parsing, printing, and binary for atomic cmpxchg (#1083)Derek Schuff2017-07-101-7/+24
|
* Add IR, parsing and binary support for AtomicRMW instructions from wasm ↵Derek Schuff2017-07-061-0/+33
| | | | | 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-2/+6
| | | | | 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-0/+1
| | | | | 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.
* Support new result syntax for if/loop/block (#1047)Sam Clegg2017-06-121-3/+3
| | | | | | Support both syntax formats in input since the old spec tests still need to be parsable.
* Exporting/importing debug location information from .wast/.asm.js/.s formats ↵Yury Delendik2017-06-011-2/+7
| | | | | | | | (#1017) * Extends wasm-as, wasm-dis and s2wasm to consume debug locations. * Exports source map from asm2wasm
* Address review feedback for #1014 (#1016)Alon Zakai2017-05-181-3/+3
| | | | | | * address review feedback for #1014
* Validate finalization (#1014)Alon Zakai2017-05-181-4/+9
| | | | | | | * 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.
* Replace text annotations with explicit file/line for debug info (#967)Derek Schuff2017-04-131-4/+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-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | * 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
* read unknown users sections as binary data stored on the Module (#918)Alon Zakai2017-02-211-0/+5
|
* clean up raw pointer import->functionType, make it a Name like everything ↵Alon Zakai2017-02-171-1/+1
| | | | else (#915)
* asm2wasm debuginfo (#895)Alon Zakai2017-02-071-0/+13
| | | | | | | | | | | | * 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
* emit globals before table and memory, because they may use a global for ↵Alon Zakai2016-12-301-4/+4
| | | | their element/segment offsets
* Don't create a memory section for an imported memory; fixes #772 (#773)Benjamin Bouvier2016-10-131-8/+1
|
* allow a maximum 0 size for a tableAlon Zakai2016-10-111-1/+1
|
* Don't create table sections for imported tables (#756)Derek Schuff2016-10-111-11/+4
| | | 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).
* Change print order of top-level module components (#751)Derek Schuff2016-10-071-12/+13
| | | | | | | | In wast files, the spec and WABT require imports to appear before any non-import definitions (see also https://github.com/WebAssembly/wabt/issues/152). This patch re-orders visitModule in the wast printer to meet this requirement, and more or less match the order of the binary sections. Also remove extraneous whitespace around table definitions.
* Update i64 stores for 0xc (#731)jgravelle-google2016-10-041-1/+1
| | | | | | | | | | * Update i64 stores for 0xc * Update autogenerated LLVM tests * Update known torture test failures * Add i64.store32 test to unit.wast
* More binary updates for 0xc (#733)Derek Schuff2016-10-031-1/+1
| | | | | | | | | | | | | | | 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-10/+10
|
* Make the linker always create a table segment (#722)Derek Schuff2016-09-301-0/+2
| | | | | | | Previously a table was only created if there were any address-taken functions. New module validation rules require the existence of a table for any call-indirects to validate (even if they are dead and never called). However this use case seems common enough that we might want to make it continue to work. So the linker now always creates an empty table segment (indicating an empty table).
* Print the name of memory along with size (#720)Derek Schuff2016-09-281-0/+1
| | | | | Otherwise when we export it as "$0" it's an undefined name. The spec interpreter actually rejects this, although I think it's intended to work, given the tests in export.wast. wabt also accepts it.
* Type check block/loop/if sigs (#717)Alon Zakai2016-09-281-0/+3
| | | | | | * type check using block/loop/if types provided in text and binary formats. * print if and loop sigs which were missing. * remove dsl from OptimizeInstructions as after those changes it needs rethinking.
* Update binary encoding for block, loop, and if signatures (#711)Derek Schuff2016-09-271-0/+3
| | | | | | Also updates the tests and has a few other changes for binary 0xc: Update nop/unrechable opcodes Fix for "name" section
* memory and table printing fixesAlon Zakai2016-09-201-8/+36
|
* globals mutability fixesAlon Zakai2016-09-191-1/+5
|
* block signaturesAlon Zakai2016-09-161-0/+3
|