blob: 71adcbfbe541264ae0b7e4416b9336aa711df747 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001// WebAssemblyInstrInfo.td-Describe the WebAssembly Instructions-*- tablegen -*-
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
JF Bastien5ca0bac2015-07-10 18:23:10 +00009///
10/// \file
11/// \brief WebAssembly Instruction definitions.
12///
Dan Gohman10e730a2015-06-29 23:51:55 +000013//===----------------------------------------------------------------------===//
14
15//===----------------------------------------------------------------------===//
16// WebAssembly Instruction Predicate Definitions.
17//===----------------------------------------------------------------------===//
18
JF Bastien03855df2015-07-01 23:41:25 +000019def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">;
20def HasAddr64 : Predicate<"Subtarget->hasAddr64()">;
21def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">,
22 AssemblerPredicate<"FeatureSIMD128", "simd128">;
23
Dan Gohman10e730a2015-06-29 23:51:55 +000024//===----------------------------------------------------------------------===//
25// WebAssembly-specific DAG Node Types.
26//===----------------------------------------------------------------------===//
27
JF Bastienaf111db2015-08-24 22:16:48 +000028def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>]>;
29def SDT_WebAssemblyCallSeqEnd :
30 SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000031def SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
32def SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>;
Dan Gohman950a13c2015-09-16 16:51:30 +000033def SDT_WebAssemblySwitch : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000034def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>;
JF Bastien4a2d5602015-07-31 21:04:18 +000035def SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>;
JF Bastienaf111db2015-08-24 22:16:48 +000036def SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
37 SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000038
Dan Gohman10e730a2015-06-29 23:51:55 +000039//===----------------------------------------------------------------------===//
40// WebAssembly-specific DAG Nodes.
41//===----------------------------------------------------------------------===//
42
JF Bastienaf111db2015-08-24 22:16:48 +000043def WebAssemblycallseq_start :
44 SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart,
45 [SDNPHasChain, SDNPOutGlue]>;
46def WebAssemblycallseq_end :
47 SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd,
48 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000049def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0",
50 SDT_WebAssemblyCall0,
51 [SDNPHasChain, SDNPVariadic]>;
52def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
53 SDT_WebAssemblyCall1,
54 [SDNPHasChain, SDNPVariadic]>;
Dan Gohman950a13c2015-09-16 16:51:30 +000055def WebAssemblyswitch : SDNode<"WebAssemblyISD::SWITCH",
56 SDT_WebAssemblySwitch,
57 [SDNPHasChain, SDNPVariadic]>;
JF Bastien600aee92015-07-31 17:53:38 +000058def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT",
59 SDT_WebAssemblyArgument>;
60def WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN",
JF Bastienaf111db2015-08-24 22:16:48 +000061 SDT_WebAssemblyReturn, [SDNPHasChain]>;
62def WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper",
63 SDT_WebAssemblyWrapper>;
JF Bastien600aee92015-07-31 17:53:38 +000064
Dan Gohman10e730a2015-06-29 23:51:55 +000065//===----------------------------------------------------------------------===//
66// WebAssembly-specific Operands.
67//===----------------------------------------------------------------------===//
68
JF Bastien5ca0bac2015-07-10 18:23:10 +000069/*
70 * TODO(jfb): Add the following.
71 *
72 * get_local: read the current value of a local variable
73 * set_local: set the current value of a local variable
74*/
75
Dan Gohman950a13c2015-09-16 16:51:30 +000076def bb_op : Operand<OtherVT>;
77def tjumptable_op : Operand<iPTR>;
JF Bastienaf111db2015-08-24 22:16:48 +000078def global : Operand<iPTR>;
79
Dan Gohman10e730a2015-06-29 23:51:55 +000080//===----------------------------------------------------------------------===//
81// WebAssembly Instruction Format Definitions.
82//===----------------------------------------------------------------------===//
83
84include "WebAssemblyInstrFormats.td"
85
JF Bastien8f9aea02015-08-01 04:48:44 +000086multiclass ARGUMENT<WebAssemblyRegClass vt> {
87 def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
88 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
89}
Dan Gohmand0bf9812015-09-26 01:09:44 +000090defm : ARGUMENT<I32>;
91defm : ARGUMENT<I64>;
92defm : ARGUMENT<F32>;
93defm : ARGUMENT<F64>;
JF Bastien600aee92015-07-31 17:53:38 +000094
JF Bastien4a642252015-08-10 22:36:48 +000095
Dan Gohmanda7f4282015-11-05 20:44:29 +000096def Const_I32 : I<(outs I32:$res), (ins i32imm:$imm),
97 [(set I32:$res, imm:$imm)],
98 "i32.const $res, $imm">;
99def Const_I64 : I<(outs I64:$res), (ins i64imm:$imm),
100 [(set I64:$res, imm:$imm)],
101 "i64.const $res, $imm">;
102def Const_F32 : I<(outs F32:$res), (ins f32imm:$imm),
103 [(set F32:$res, fpimm:$imm)],
104 "f32.const $res, $imm">;
105def Const_F64 : I<(outs F64:$res), (ins f64imm:$imm),
106 [(set F64:$res, fpimm:$imm)],
107 "f64.const $res, $imm">;
JF Bastien4a642252015-08-10 22:36:48 +0000108
Dan Gohman950a13c2015-09-16 16:51:30 +0000109// Special types of immediates. FIXME: Hard-coded as 32-bit for now.
Dan Gohmand0bf9812015-09-26 01:09:44 +0000110def GLOBAL : I<(outs I32:$dst), (ins global:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000111 [(set I32:$dst, (WebAssemblywrapper tglobaladdr:$addr))],
112 "global $dst, $addr">;
Dan Gohmand0bf9812015-09-26 01:09:44 +0000113def JUMP_TABLE : I<(outs I32:$dst), (ins tjumptable_op:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000114 [(set I32:$dst, (WebAssemblywrapper tjumptable:$addr))],
115 "jump_table $dst, $addr">;
JF Bastienaf111db2015-08-24 22:16:48 +0000116
Dan Gohman10e730a2015-06-29 23:51:55 +0000117//===----------------------------------------------------------------------===//
118// Additional sets of instructions.
119//===----------------------------------------------------------------------===//
120
JF Bastien5ca0bac2015-07-10 18:23:10 +0000121include "WebAssemblyInstrMemory.td"
122include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000123include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000124include "WebAssemblyInstrInteger.td"
125include "WebAssemblyInstrFloat.td"
126include "WebAssemblyInstrConv.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000127include "WebAssemblyInstrAtomics.td"
128include "WebAssemblyInstrSIMD.td"