228 Commits

Author SHA1 Message Date
Derek Schuff
561fb73b85 [WebAssembly] Emit type signatures for declared functions
Under emscripten, C code can take the address of a function implemented
in Javascript (which is exposed via an import in wasm). Because imports
do not have linear memory address in wasm, we need to generate a thunk
to be the target of the indirect call; it call the import directly.

To make this possible, LLVM needs to emit the type signatures for these
functions, because they may not be called directly or referred to other
than where the address is taken.

This uses s new .s directive (.functype) which specifies the signature.

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

Re-apply r271599 but instead of bailing with an error when a declared
function has multiple returns, replace it with a pointer argument. Also
add the test case I forgot to 'git add' last time around.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271703 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-03 18:34:36 +00:00
Derek Schuff
13e11d741a Revert "[WebAssembly] Emit type signatures for declared functions"
This reverts r271599, it broke the integration tests.
More places than I expected had nontrival return types in imports, or
else the check was wrong.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271606 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-02 23:02:44 +00:00
Derek Schuff
1fa45c8fb6 [WebAssembly] Emit type signatures for declared functions
Under emscripten, C code can take the address of a function implemented
in Javascript (which is exposed via an import in wasm). Because imports
do not have linear memory address in wasm, we need to generate a thunk
to be the target of the indirect call; it call the import directly.

To make this possible, LLVM needs to emit the type signatures for these
functions, because they may not be called directly or referred to other
than where the address is taken.

This uses s new .s directive (.functype) which specifies the signature.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271599 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-02 21:34:18 +00:00
Dan Gohman
04c5ee8513 [WebAssembly] Put __stack_pointer in the offset field of loads and stores.
Instead of this:

i32.const       $push10=, __stack_pointer
i32.load        $push11=, 0($pop10)

Emit this:

i32.const       $push10=, 0
i32.load        $push11=, __stack_pointer($pop10)

It's not currently clear which is better, though there's a chance the second
form may be better at overall compression. We can revisit this when we have
more data; for now it makes sense to make PEI consistent with isel.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270635 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-24 23:47:41 +00:00
Dan Gohman
1a513a6964 [WebAssembly] Optimize away return instructions using fallthroughs.
This saves a small amount of code size, and is a first small step toward
passing values on the stack across block boundaries.

Differential Review: http://reviews.llvm.org/D20450


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270294 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-21 00:21:56 +00:00
Dan Gohman
783e35acb8 [WebAssembly] Make several CHECK lines less fragile using regexes and CHECK-DAG.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270011 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-19 01:52:56 +00:00
Dan Gohman
da38a6d070 [WebAssembly] Don't expand divisions by constants.
Don't expand divisions by constants if it would require multiple instructions.
The current assumption is that engines will perform the desired optimizations.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269930 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18 14:29:42 +00:00
Dan Gohman
51510adcfa [WebAssembly] Rename $discard to $drop in the assembly output.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269862 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 23:19:03 +00:00
Dan Gohman
b9fa981c8a [WebAssembly] Model the stack evaluation order more precisely.
We currently don't represent get_local and set_local explicitly; they
are just implied by virtual register use and def. This avoids a lot of
clutter, but it does complicate stackifying: get_locals read their
operands at their position in the stack evaluation order, rather than
at their parent instruction. This patch adds code to walk the stack to
determine the precise ordering, when needed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269854 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 22:24:18 +00:00
Dan Gohman
e5abbb2bf0 [WebAssembly] Don't stackify calls past stack pointer modifications.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269843 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 21:14:26 +00:00
Dan Gohman
f9336ec145 [WebAssembly] Stackify induction variable increment instructions.
This handles instructions where the defined register is also used, as in
"x = x + 1".


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269830 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 20:19:47 +00:00
Dan Gohman
c1fd522352 [WebAssembly] Improve the precision of memory and side effect dependence tracking.
MachineInstr::isSafeToMove is more conservative than is needed here;
use a more explicit check, and incorporate knowledge of some
WebAssembly-specific opcodes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269736 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 04:05:31 +00:00
Dan Gohman
594d70d5cc [WebAssembly] Mark COPY_LOCAL and TEE_LOCAL instructions has having no side effects.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269683 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-16 19:16:32 +00:00
Dan Gohman
b57691df7a [WebAssembly] Use eqz to negate a branch conditions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269681 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-16 18:59:34 +00:00
Dan Gohman
c40a684451 [WebAssembly] Fix legalization of i128 shifts.
compiler-rt/libgcc shift routines expect the shift count to be an i32, so
use i32 as the shift count for shifts that are legalized to libcalls. This
also reverts r268991, now that the signatures are correct.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269531 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-14 02:15:47 +00:00
Dan Gohman
ca8feb05bb [WebAssembly] Fast-isel support for calls, arguments, and selects.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269273 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-12 04:19:09 +00:00
Dan Gohman
9cc168109a [WebAssembl] Implement enough of fast-isel to run the comparison tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269203 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-11 16:32:42 +00:00
Dan Gohman
f02416f9ad [WebAssembly] Preliminary fast-isel support.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269083 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-10 17:39:48 +00:00
Dan Gohman
01a542927d [WebAssembly] Move register stackification and coloring to a late phase.
Move the register stackification and coloring passes to run very late, after
PEI, tail duplication, and most other passes. This means that all code emitted
and expanded by those passes is now exposed to these passes. This also
eliminates the need for prologue/epilogue code to be manually stackified,
which significantly simplifies the code.

This does require running LiveIntervals a second time. It's useful to think
of these late passes not as late optimization passes, but as a domain-specific
compression algorithm based on knowledge of liveness information. It's used to
compress the code after all conventional optimizations are complete, which is
why it uses LiveIntervals at a phase when actual optimization passes don't
typically need it.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269012 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-10 04:24:02 +00:00
Dan Gohman
9281534899 [WebAssembly] Don't emit epilogue code in the middle of stackified code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268679 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-05 20:41:15 +00:00
Derek Schuff
1e477250a6 [WebAssembly] Rename memory_size intrinsic to current_memory
This follows the recent renaming in the wasm spec.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268255 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-02 17:25:22 +00:00
Dan Gohman
1a09f22368 [WebAssembly] Account for implicit operands when computing operand indices.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267511 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-26 01:40:56 +00:00
Dan Gohman
e0dd87a040 [WebAssembly] Limit alignment hints to natural alignment.
This follows the current binary format rules.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267082 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-21 23:59:48 +00:00
Adrian Prantl
8f148cdabd Let the DISubprogram in this test point to the right compile unit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266468 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-15 19:38:14 +00:00
Adrian Prantl
2fee4f2d2e Update testcase to new debug metadata format.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266467 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-15 19:32:22 +00:00
Derek Schuff
83c1c10eb3 [WebAssembly] Fix debug info in reg-stackify.ll test
It lacked a CU and thus became invalid with r266102

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266114 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-12 20:12:05 +00:00
JF Bastien
01d8b6a2ac WebAssembly: fix cfg-stackify test
It was broken by reshuffling induced by r265397 'Don't delete empty preheaders in CodeGenPrepare if it would create a critical edge'.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265415 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-05 17:01:52 +00:00
Dan Gohman
35d7235fd8 [WebAssembly] Implement the rotate instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264076 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 18:01:49 +00:00
Dan Gohman
c13556c771 [WebAssembly] Implement the eqz instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263976 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-21 19:54:41 +00:00
Derek Schuff
3d15212029 [WebAssembly] Stackify code emitted by eliminateFrameIndex and SP writeback
Summary:
MRI::eliminateFrameIndex can emit several instructions to do address
calculations; these can usually be stackified. Because instructions with
FI operands can have subsequent operands which may be expression trees,
find the top of the leftmost tree and insert the code before it, to keep
the LIFO property.

Also use stackified registers when writing back the SP value to memory
in the epilog; it's unnecessary because SP will not be used after the
epilog, and it results in better code.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263725 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-17 17:00:29 +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
2d88e345fe [WebAssembly] Update for spec change from tableswitch to br_table.
Also note that the operand order changed; the default label is now listed
after the regular labels.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262903 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-08 03:18:12 +00:00
JF Bastien
f65b510d67 WebAssembly: fix test
Operand order seems to have changed, the new one is nicer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262180 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-28 15:44:54 +00:00
Derek Schuff
e5a3819fc8 Revert "[WebAssembly] Stackify code emitted by eliminateFrameIndex"
This reverts r261685 due to wasm test breakage.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261702 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-23 22:13:21 +00:00
Derek Schuff
64f8810499 [WebAssembly] Stackify code emitted by eliminateFrameIndex
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261685 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-23 21:25:17 +00:00
Derek Schuff
8ff73c1307 [WebAssembly] Implement red zone for user stack
Implements a mostly-conventional redzone for the userspace
stack. Because we have unsigned load/store offsets we continue to use a
local SP subtracted from the incoming SP but do not write it back to
memory.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261662 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-23 18:13:07 +00:00
Derek Schuff
718d992d1f [WebAssembly] Fix writeback of stack pointer with dynamic alloca
Previously the stack pointer was only written back to memory in the
prolog. But this is wrong for dynamic allocas, for which
target-independent codegen handles SP updates after the prolog (and
possibly even in another BB). Instead update the SP global in
ADJCALLSTACKDOWN which is generated after the SP update sequence.
This will have further refinements when we add red zone support.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261579 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-22 21:57:17 +00:00
Dan Gohman
1b10833563 [WebAssembly] Teach address folding to fold bitwise-or nodes.
LLVM converts adds into ors when it can prove that the operands don't share
any non-zero bits. Teach address folding to recognize or instructions with
constant operands with this property that can be folded into addresses as
if they were adds.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261562 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-22 20:04:02 +00:00
Dan Gohman
125ad6e3d9 [WebAssembly] Properly ignore llvm.dbg.value instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261538 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-22 17:45:20 +00:00
Dan Gohman
a96dc7d5ad [WebAssembly] Support physical registers in the rewrite-to-discard optimization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261465 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-21 03:27:22 +00:00
Dan Gohman
772074148f [WebAssembly] Handle CopyToReg nodes with flag results in LowerCopyToReg.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261457 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-20 23:09:44 +00:00
Derek Schuff
545c0902d4 [WebAssembly] Write stack pointer back to memory when FP is used
The stack pointer is bumped when there is a frame pointer or when there
are static-size objects, but was only getting written back when there
were static-size objects.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261453 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-20 22:18:47 +00:00
Derek Schuff
37d3f7f35c [WebAssembly] Stackify function prologs and epilogs
The instructions are the same, but fewer locals are used.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261452 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-20 21:46:50 +00:00
Dan Gohman
07e5326d7d [WebAssembly] Don't use setRequiresStructuredCFG(true).
While we still do want reducible control flow, the RequiresStructuredCFG
flag imposes more strict structure constraints than WebAssembly wants.
Unsetting this flag enables critical edge splitting and tail merging.

Also, disable TailDuplication explicitly, as it doesn't support virtual
registers, and was previously only disabled by the RequiresStructuredCFG
flag.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261190 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-18 06:32:53 +00:00
Dan Gohman
1a8392e483 [WebAssembly] Call memcpy for large byval copies.
This fixes very slow compilation on
test/CodeGen/Generic/2010-11-04-BigByval.ll . Note that MaxStoresPerMemcpy
and friends are not yet carefully tuned so the cutoff point is currently
somewhat arbitrary. However, it's important that there be a cutoff point
so that we don't emit unbounded quantities of loads and stores.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261050 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-17 01:43:37 +00:00
Dan Gohman
f3e241c3c2 [WebAssembly] Implement __builtin_frame_address.
Differential Revision: http://reviews.llvm.org/D17307


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261032 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-16 23:48:04 +00:00
Derek Schuff
7ea47333dc [WebAssemly] Don't move calls or stores past intervening loads
The register stackifier currently checks for intervening stores (and
loads that may alias them) but doesn't account for the fact that the
instruction being moved may affect intervening loads.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261014 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-16 21:44:19 +00:00
Derek Schuff
cd66f7a1e9 [WebAssembly] Insert COPY_LOCAL between CopyToReg and FrameIndex DAG nodes
CopyToReg nodes don't support FrameIndex operands. Other targets select
the FI to some LEA-like instruction, but since we don't have that, we
need to insert some kind of instruction that can take an FI operand and
produces a value usable by CopyToReg (i.e. in a vreg). So insert a dummy
copy_local between Op and its FI operand. This results in a redundant
copy which we should optimize away later (maybe in the post-FI-lowering
peephole pass).

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260987 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-16 18:18:36 +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
0f54412dec [WebAssembly] Create new registers instead of reusing old ones in RegStackify.
This avoids some complications updating LiveIntervals to be aware of the new
register lifetimes, because we can just compute new intervals from scratch
rather than describe how the old ones have been changed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260971 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-16 15:17:21 +00:00