26 Commits

Author SHA1 Message Date
Dan Gohman
01b89435ec [WebAssembly] Implement more WebAssembly binary encoding.
This changes locals from being declared by the emitLocal hook in
WebAssemblyTargetStreamer, rather than with an instruction. After exploring
the infastructure in LLVM more, this seems to make more sense since
declaring locals doesn't use an encoded opcode.

This also adds more 0xd opcodes, type encodings, and miscellaneous
binary encoding bits.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285040 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-24 23:27:49 +00:00
Dan Gohman
1871c0f455 [WebAssembly] Add an option to make get_local/set_local explicit.
This patch adds a pass, controlled by an option and off by default for
now, for making implicit get_local/set_local explicit. This simplifies
emitting wasm with MC.

Differential Revision: https://reviews.llvm.org/D25836


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285009 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-24 19:49:43 +00:00
Dan Gohman
12bd3d1963 [WebAssemby] Implement block signatures.
Per spec changes, this implements block signatures, and adds just enough
logic to produce correct block signatures at the ends of functions.

Differential Revision: https://reviews.llvm.org/D25144


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283503 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-06 22:29:32 +00:00
Dan Gohman
d8d953ef76 [WebAssembly] Remove loop's bottom label.
Per spec changes, loop constructs no longer have a bottom label.

https://reviews.llvm.org/D25118


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283502 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-06 22:10:23 +00:00
Dan Gohman
3f22f87fb5 [WebAssembly] Update to more stack-machine-oriented terminology.
WebAssembly has officially switched from being an AST to being a stack
machine. Update various bits of terminology and README.md entries
accordingly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283154 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-03 22:43:53 +00:00
Mehdi Amini
67f335d992 Use StringRef in Pass/PassManager APIs (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283004 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-01 02:56:57 +00:00
Benjamin Kramer
7e3e982267 [WebAssembly] Unbreak the build.
Not sure why ADL isn't working here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280656 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-05 12:06:47 +00:00
Duncan P. N. Exon Smith
a3dcb9e3b4 WebAssembly: Avoid implicit iterator conversions, NFC
Avoid implicit conversions from MachineInstrBundleIterator to
MachineInstr* in the WebAssembly backend by preferring MachineInstr&
over MachineInstr*.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274912 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-08 19:36:40 +00:00
Dan Gohman
09588765a8 [WebAssembly] Implement irreducible control flow.
This implements a very simple conservative transformation that doesn't
require more than linear code size growth. There's room for much more
optimization in this space.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262982 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-09 02:01:14 +00:00
Dan Gohman
2ed76660d2 [WebAssembly] Switch from RPO sorting to topological sorting.
WebAssembly doesn't require full RPO; topological sorting is sufficient and
can preserve more of the MachineBlockPlacement ordering. Unfortunately, this
still depends a lot on heuristics, because while we use the
MachineBlockPlacement ordering as a guide, we can't use it in places where
it isn't topologically ordered. This area will require further attention.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260978 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-16 16:22:41 +00:00
Dan Gohman
73cd89a6f2 [WebAssembly] Fix insertion of a BLOCK in a loop header that also ends a BLOCK.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260737 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-12 21:19:25 +00:00
Dan Gohman
af25d0139c [WebAssembly] Refine block placement to insert blocks between trees.
Refine the test for whether an instruction is in an expression tree so that
it detects when one tree ends and another begins, so we can place a block
at that point, rather than continuing to find the first instruction not in
a tree at all.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259294 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-30 05:01:06 +00:00
Derek Schuff
caaa234ccf [WebAssemly] Invalidate liveness in CFG stackifier
WebAssemblyCFGStackify does not track liveness for EXPR_STACK, causing
verifier failure if liveness has not already been invalidated.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257620 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-13 17:10:28 +00:00
Dan Gohman
b58587dac1 [WebAssembly] Make CFG stackification independent of basic-block labels.
This patch changes the way labels are referenced. Instead of referencing the
basic-block label name (eg. .LBB0_0), instructions now just have an immediate
which indicates the depth in the control-flow stack to find a label to jump to.
This makes them much closer to what we expect to have in the binary encoding,
and avoids the problem of basic-block label names not being explicit in the
binary encoding.

Also, it terminates blocks and loops with end_block and end_loop instructions,
rather than basic-block label names, for similar reasons.

This will also fix problems where two constructs appear to have the same label,
because we no longer explicitly use labels, so consumers that need labels will
presumably create their own labels, and presumably they won't reuse labels
when they do.

This patch does make the code a little more awkward to read; as a partial
mitigation, this patch also introduces comments showing where the labels are,
and comments on each branch showing where it's branching to.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257505 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-12 19:14:46 +00:00
Dan Gohman
2c2e12150f [WebAssembly] Minor code cleanups. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257128 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-08 01:06:00 +00:00
Dan Gohman
005cc9c500 [WebAssembly] Fix handling of COPY instructions in WebAssemblyRegStackify.
Move RegStackify after coalescing and teach it to use LiveIntervals instead
of depending on SSA form. This avoids a problem where a register in a COPY
instruction is stackified and then subsequently coalesced with a register
that is not stackified.

This also puts it after the scheduler, which allows us to simplify the
EXPR_STACK constraint, as we no longer have instructions being reordered
after stackification and before coloring.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256402 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-25 00:31:02 +00:00
Dan Gohman
fd7b160a14 [WebAssembly] Fix the CFG Stackifier to handle unoptimized branches
If a branch both branches to and falls through to the same block, treat it as
an explicit branch.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255803 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-16 19:06:41 +00:00
Dan Gohman
4fe3f079fb [WebAssembly] Implement a new algorithm for placing BLOCK markers
Implement a new BLOCK scope placement algorithm which better handles
early-return blocks and early exists from nested scopes.

Differential Revision: http://reviews.llvm.org/D15368


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255564 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-14 22:51:54 +00:00
Dan Gohman
454061bf3a [WebAssembly] Fix comments to say "LIFO" instead of "FIFO" when describing a stack.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254523 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-02 18:08:49 +00:00
Dan Gohman
8dc6e6c3bb [WebAssembly] Fix a few minor compiler warnings. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254311 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-30 18:42:08 +00:00
Dan Gohman
85d0f9ca6d [WebAssembly] Minor clang-format and selected clang-tidy cleanups. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254267 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-29 22:32:02 +00:00
Dan Gohman
5aafb6def5 [WebAssembly] Always print loop end labels
WebAssembly is currently using labels to end scopes, so for example a
loop scope looks like this:

BB0_0:
  loop BB0_1
  ...
BB0_1:

with BB0_0 being the label of the first block not in the loop. This
requires that the label be printed even when it's only reachable via
fallthrough. To arrange this, insert a no-op LOOP_END instruction in
such cases at the end of the loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253901 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-23 19:12:37 +00:00
Dan Gohman
96bd946285 [WebAssembly] Use dominator information to improve BLOCK placement
Always starting blocks at the top of their containing loops works, but creates
unnecessarily deep nesting because it makes all blocks in a loop overlap.
Refine the BLOCK placement algorithm to start blocks at nearest common
dominating points instead, which significantly shrinks them and reduces
overlapping.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253876 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-23 16:19:56 +00:00
Nico Weber
d5e4538cdc Try to fix build more -- like r252392 but for WebAssembly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252394 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-07 02:47:31 +00:00
Dan Gohman
e865fa75b6 [WebAssembly] Fix CFG stackification of nested loops.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249187 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-02 21:11:36 +00:00
Dan Gohman
7146e900e8 [WebAssembly] Check in an initial CFG Stackifier pass
This pass implements a simple algorithm for conversion from CFG to
wasm's structured control flow. It doesn't yet handle multiple-entry
loops; that will be added in a future patch.

It also adds initial support for switch statements.

Differential Revision: http://reviews.llvm.org/D12735


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247818 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-16 16:51:30 +00:00