WebAssembly: Implement call
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyInstrInfo.td
1 // 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 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief WebAssembly Instruction definitions.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 //===----------------------------------------------------------------------===//
16 // WebAssembly Instruction Predicate Definitions.
17 //===----------------------------------------------------------------------===//
18
19 def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">;
20 def HasAddr64 : Predicate<"Subtarget->hasAddr64()">;
21 def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">,
22                            AssemblerPredicate<"FeatureSIMD128", "simd128">;
23
24 //===----------------------------------------------------------------------===//
25 // WebAssembly-specific DAG Node Types.
26 //===----------------------------------------------------------------------===//
27
28 def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>]>;
29 def SDT_WebAssemblyCallSeqEnd :
30     SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
31 def SDT_WebAssemblyCall     : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>;
32 def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>;
33 def SDT_WebAssemblyReturn   : SDTypeProfile<0, -1, []>;
34 def SDT_WebAssemblyWrapper  : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
35                                                    SDTCisPtrTy<0>]>;
36
37 //===----------------------------------------------------------------------===//
38 // WebAssembly-specific DAG Nodes.
39 //===----------------------------------------------------------------------===//
40
41 def WebAssemblycallseq_start :
42     SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart,
43            [SDNPHasChain, SDNPOutGlue]>;
44 def WebAssemblycallseq_end :
45     SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd,
46            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
47 def WebAssemblycall      : SDNode<"WebAssemblyISD::CALL",
48                                   SDT_WebAssemblyCall,
49                                   [SDNPHasChain, SDNPVariadic]>;
50 def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT",
51                                  SDT_WebAssemblyArgument>;
52 def WebAssemblyreturn   : SDNode<"WebAssemblyISD::RETURN",
53                                  SDT_WebAssemblyReturn, [SDNPHasChain]>;
54 def WebAssemblywrapper  : SDNode<"WebAssemblyISD::Wrapper",
55                                  SDT_WebAssemblyWrapper>;
56
57 //===----------------------------------------------------------------------===//
58 // WebAssembly-specific Operands.
59 //===----------------------------------------------------------------------===//
60
61 /*
62  * TODO(jfb): Add the following.
63  *
64  * get_local: read the current value of a local variable
65  * set_local: set the current value of a local variable
66 */
67
68 def global : Operand<iPTR>;
69
70 //===----------------------------------------------------------------------===//
71 // WebAssembly Instruction Format Definitions.
72 //===----------------------------------------------------------------------===//
73
74 include "WebAssemblyInstrFormats.td"
75
76 multiclass ARGUMENT<WebAssemblyRegClass vt> {
77   def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
78                        [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
79 }
80 defm : ARGUMENT<Int32>;
81 defm : ARGUMENT<Int64>;
82 defm : ARGUMENT<Float32>;
83 defm : ARGUMENT<Float64>;
84
85
86 def Immediate_I32 : I<(outs Int32:$res), (ins i32imm:$imm),
87                       [(set Int32:$res, imm:$imm)]>;
88 def Immediate_I64 : I<(outs Int64:$res), (ins i64imm:$imm),
89                       [(set Int64:$res, imm:$imm)]>;
90 def Immediate_F32 : I<(outs Float32:$res), (ins f32imm:$imm),
91                       [(set Float32:$res, fpimm:$imm)]>;
92 def Immediate_F64 : I<(outs Float64:$res), (ins f64imm:$imm),
93                       [(set Float64:$res, fpimm:$imm)]>;
94
95 // Special types of immediates.
96 def GLOBAL : I<(outs Int32:$dst), (ins global:$addr),
97                [(set Int32:$dst, (WebAssemblywrapper tglobaladdr:$addr))]>;
98
99 //===----------------------------------------------------------------------===//
100 // Additional sets of instructions.
101 //===----------------------------------------------------------------------===//
102
103 include "WebAssemblyInstrMemory.td"
104 include "WebAssemblyInstrCall.td"
105 include "WebAssemblyInstrControl.td"
106 include "WebAssemblyInstrInteger.td"
107 include "WebAssemblyInstrFloat.td"
108 include "WebAssemblyInstrConv.td"
109 include "WebAssemblyInstrAtomics.td"
110 include "WebAssemblyInstrSIMD.td"