106 Commits

Author SHA1 Message Date
Dan Gohman
d39c38d2bc [WebAssembly] Reapply r252858, with svn add for the new file.
Switch to MC for instruction printing.

This encompasses several changes which are all interconnected:
 - Use the MC framework for printing almost all instructions.
 - AsmStrings are now live.
 - This introduces an indirection between LLVM vregs and WebAssembly registers,
   and a new pass, WebAssemblyRegNumbering, for computing a basic the mapping.
   This addresses some basic issues with argument registers and unused registers.
 - The way ARGUMENT instructions are handled no longer generates redundant
   get_local+set_local for every argument.

This also changes the assembly syntax somewhat; most notably, MC's printing
does not use sigils on label names, so those are no longer present, and
push/pop now have a sigil to keep them unambiguous.

The usage of set_local/get_local/$push/$pop will continue to evolve
significantly. This patch is just one step of a larger change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252910 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-12 17:04:33 +00:00
Hans Wennborg
e8073938cf Revert r252858: "[WebAssembly] Switch to MC for instruction printing."
It broke the CMake build:

"Cannot find source file: WebAssemblyRegNumbering.cpp"

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252897 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-12 14:37:56 +00:00
Dan Gohman
41e2c98842 [WebAssembly] Switch to MC for instruction printing.
This encompasses several changes which are all interconnected:
 - Use the MC framework for printing almost all instructions.
 - AsmStrings are now live.
 - This introduces an indirection between LLVM vregs and WebAssembly registers,
   and a new pass, WebAssemblyRegNumbering, for computing a basic the mapping.
   This addresses some basic issues with argument registers and unused registers.
 - The way ARGUMENT instructions are handled no longer generates redundant
   get_local+set_local for every argument.

This also changes the assembly syntax somewhat; most notably, MC's printing
use sigils on label names, so those are no longer present, and push/pop now
have a sigil to keep them unambiguous.

The usage of set_local/get_local/$push/$pop will continue to evolve
significantly. This patch is just one step of a larger change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252858 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-12 06:10:03 +00:00
Dan Gohman
cf35a1b84d [WebAssembly] Support non-legal argument and return types.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252687 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-11 01:33:02 +00:00
Dan Gohman
5f742d2fb4 [WebAssembly] Remove special cases for things that are no longer special. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252656 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-10 21:48:21 +00:00
Dan Gohman
51cc8a7d2d [WebAssembly] Support for floating point min and max.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252653 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-10 21:40:21 +00:00
Derek Schuff
537330de82 [WebAssembly] Support 'unreachable' expression
Lower LLVM's 'unreachable' terminator to ISD::TRAP, and lower ISD::TRAP to
wasm's 'unreachable' expression.

WebAssembly type-checks expressions, but a noreturn function with a
return type that doesn't match the context will cause a check
failure. So we lower LLVM 'unreachable' to ISD::TRAP and then lower that
to WebAssembly's 'unreachable' expression, which typechecks in any
context and causes a trap if executed.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252566 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-10 00:30:57 +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
11228e360e [WebAssembly] Make expression-stack pushing explicit
Modelling of the expression stack is evolving. This patch takes another
step by making pushes explicit.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252334 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-06 19:45:01 +00:00
Dan Gohman
e6d3aa4a49 [WebAssembly] Fix copypasta.
Noticed by dschff in http://reviews.llvm.org/rL252203


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252208 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-05 20:59:49 +00:00
Dan Gohman
154081af53 [WebAssembly] Rename Immediate instructions to Const.
This more closely reflects the naming convention in the spec.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252204 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-05 20:44:29 +00:00
Dan Gohman
651ccf4012 [WebAssembly] Add AsmString strings for most instructions.
Mangling type information into MachineInstr opcode names was a temporary
measure, and it's starting to get hairy. At the same time, the MC instruction
printer wants to use AsmString strings for printing. This patch takes the
first step, starting the process of adding AsmStrings for instructions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252203 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-05 20:42:30 +00:00
Dan Gohman
ae31b98bc3 [WebAssembly] Update wasm builtin functions to match spec changes.
The page_size operator has been removed from the spec, and the resize_memory
operator has been changed to grow_memory.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252202 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-05 20:16:59 +00:00
Dan Gohman
251dff3d1b [WebAssembly] Add WebAssemblyMCInstLower.cpp.
This isn't used yet; it's just a start towards eventually using MC to
do instruction printing, and eventually binary encoding.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252194 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-05 19:28:16 +00:00
Derek Schuff
f284162906 [WebAssembly] Rename ior operator to or to match the spec
Summary: The spec uses "or" for inclusive-or and "xor" for exclusive-or

Reviewers: sunfish

Subscribers: jfb, llvm-commits, dschuff

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252174 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-05 17:08:11 +00:00
Derek Schuff
4f71e3c355 Align whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252003 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-03 22:40:43 +00:00
Derek Schuff
05d7d32e12 [WebAssembly] Support wasm select operator
Summary:
Add support for wasm's select operator, and lower LLVM's select DAG node
to it.

Reviewers: sunfish

Subscribers: dschuff, llvm-commits, jfb

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252002 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-03 22:40:40 +00:00
Derek Schuff
93508f2241 [WebAssembly] Make WebAssemblyCodeGen depend on WebAssemblyAsmPrinter
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251859 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-02 23:23:16 +00:00
JF Bastien
677d6a3a87 [WebAssembly] Fix import statement
Summary:
Imports should be generated like (param i32 f32...) not (param i32) (param f32) ...

Author: binji
Reviewers: jfb
Subscribers: jfb, dschuff

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251714 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-30 16:41:21 +00:00
JF Bastien
0c4ea613c4 [WebAssembly] Update opcode name format for conversions
Summary:
Conversion opcode name format should be f64.convert_u/i64 not f64_convert_u

Author: s3ththompson
Reviewers: jfb
Subscribers: sunfish, jfb, llvm-commits, dschuff
Differential Revision: http://reviews.llvm.org/D14160

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251613 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-29 04:10:52 +00:00
JF Bastien
55a57a7674 WebAssembly: fix more syntax
br_if shouldn't start with a dot.
div and rem went from prefix u/s to suffix.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250972 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-22 02:32:50 +00:00
JF Bastien
3aa0189bfe WebAssembly: support imports
C/C++ code can declare an extern function, which will show up as an import in WebAssembly's output. It's expected that the linker will resolve these, and mark unresolved imports as call_import (I have a patch which does this in wasmate).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250875 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-21 02:23:09 +00:00
JF Bastien
175c683f63 WebAssembly: fix call/return syntax.
They are now typeless, unlike other operations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250793 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-20 01:26:54 +00:00
JF Bastien
9f16772a3d WebAssembly: fix syntax for br_if.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250777 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-20 00:37:42 +00:00
JF Bastien
1c068abaef WebAssembly: don't omit dead vregs from locals
Summary:
This is a temporary hack until we get around to remapping the vreg
numbers to local numbers. Dead vregs cause bad numbering and make
consumers sad.

We could also just look at debug info an use named locals instead, but
vregs have to work properly anyways so there!

Reviewers: binji, sunfish

Subscribers: jfb, llvm-commits, dschuff

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250594 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-17 00:25:38 +00:00
JF Bastien
065515c76c WebAssembly: fix the syntax for comparisons
Summary: It has also slightly changed.

Reviewers: binji

Subscribers: jfb, dschuff, llvm-commits, sunfish

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250591 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-17 00:12:29 +00:00
JF Bastien
d433cde1a1 WebAssembly: fix load/store syntax
Summary: The syntax has changed a bit recently.

Reviewers: binji

Subscribers: llvm-commits, jfb, sunfish, dschuff

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250535 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-16 18:24:42 +00:00
JF Bastien
8de4d0170e WebAssembly: relooper analysis pass
Summary: Make the relooper an analysis pass, to convert CFG to AST.

Reviewers: sunfish

Subscribers: jfb, dschuff

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250524 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-16 16:35:49 +00:00
JF Bastien
8cafdf539b WebAssembly: update syntax
Summary:
Follow the same syntax as for the spec repo. Both have evolved slightly
independently and need to converge again.

This, along with wasmate changes, allows me to do the following:

  echo "int add(int a, int b) { return a + b; }" > add.c
  ./out/bin/clang -O2 -S --target=wasm32-unknown-unknown add.c -o add.wack
  ./experimental/prototype-wasmate/wasmate.py add.wack > add.wast
  ./sexpr-wasm-prototype/out/sexpr-wasm add.wast -o add.wasm
  ./sexpr-wasm-prototype/third_party/v8-native-prototype/v8/v8/out/Release/d8 -e "print(WASM.instantiateModule(readbuffer('add.wasm'), {print:print}).add(42, 1337));"

As you'd expect, the d8 shell prints out the right value.

Reviewers: sunfish

Subscribers: jfb, llvm-commits, dschuff

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250480 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-16 00:53:49 +00:00
Dan Gohman
3e6689ff8a [WebAssembly] Remove a TODO comment which is no longer needed. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250233 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-13 22:06:40 +00:00
Dan Gohman
822d42fa8b [WebAssembly] Rename floating-point operators to match their spec names.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249859 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-09 17:50:00 +00:00
Dan Gohman
2d3e3ef1c7 [WebAssembly] Switch to a more traditional assembly syntax
This new syntax is built around putting each instruction on its own line
in a "mnemonic op, op, op" like syntax. It also uses conventional data
section directives like ".byte" and so on rather than requiring everything
to be in hierarchical S-expression format. This is a more natural syntax
for a ".s" file format from the perspective of LLVM MC and related tools,
while remaining easy to translate into other forms as needed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249364 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-06 00:27:55 +00:00
Dan Gohman
645be3e5fe [WebAssembly] Implement the remaining conversion operations.
This is a temporary assembly syntax that will likely evolve along with
broader upcoming syntax changes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249225 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-03 02:10:28 +00:00
Dan Gohman
de786c9b89 [WebAssembly] Rename setlocal to set_local to match the spec.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249218 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-03 00:01:53 +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
a05446bfec [WebAssembly] Support calls marked as "tail", fastcc, and coldcc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249184 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-02 20:54:23 +00:00
Dan Gohman
216303e8fd [WebAssembly] Add a resize_memory intrinsic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249178 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-02 20:10:26 +00:00
Dan Gohman
7eb00c4bc2 [WebAssembly] Add a memory_size intrinsic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249171 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-02 19:21:15 +00:00
Dan Gohman
ec9e44d1d4 [WebAssembly] Support for direct call and call_indirect.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248716 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-28 16:22:39 +00:00
Dan Gohman
24b507c2c1 [WebAssembly] Rename several functions and types according to the new spec.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248644 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-26 01:09:44 +00:00
Dan Gohman
44f9959a95 [WebAssembly] Fix hasAddr64 being used before being initializer.
This reverts r248388 and fixes the underlying bug: hasAddr64 was initialized
in runOnMachineFunction, but runOnMachineFunction isn't ever called in
CodeGen/WebAssembly/global.ll since that testcase has no functions. The fix
here is to use AsmPrinter's getPointerSize() as needed to determine the
pointer size instead.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248394 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-23 16:59:10 +00:00
Alexander Kornienko
b2d0e28941 Fix CodeGen/WebAssembly/global.ll test under ASAN.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248388 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-23 15:41:25 +00:00
Hans Wennborg
33dfebdcfa Try to fix WebAssembly build after r247864
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247870 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-16 23:59:57 +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
Dan Gohman
270e6f8a27 [WebAssembly] Implement int64-to-int32 conversion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247649 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-15 00:55:19 +00:00
Dan Gohman
85ef3e393d [WebAssembly] Implement calls with void return types.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247158 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-09 16:13:47 +00:00
Dan Gohman
9f73ec9d15 [WebAssembly] Tidy up some unneeded newline characters.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247152 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-09 15:13:36 +00:00
Dan Gohman
307756e77e [WebAssembly] Fix lowering of calls with more than one argument.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247118 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-09 01:52:45 +00:00
Dan Gohman
48a473e770 [WebAssembly] Implement WebAssemblyInstrInfo::copyPhysReg
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247110 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-09 00:52:47 +00:00
Dan Gohman
21b2bb4054 [WebAssembly] Support running without a register allocator in the default CodeGen passes
This allows backends which don't use a traditional register allocator,
but do need PHI lowering and other passes, to use the default
TargetPassConfig::addFastRegAlloc and
TargetPassConfig::addOptimizedRegAlloc implementations.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247065 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-08 20:36:33 +00:00