]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/Target/WebAssembly/WebAssemblyInstrCall.td
Vendor import of llvm trunk r300422:
[FreeBSD/FreeBSD.git] / lib / Target / WebAssembly / WebAssemblyInstrCall.td
1 //===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- 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 Call operand code-gen constructs.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 // TODO: addr64: These currently assume the callee address is 32-bit.
16
17 let Defs = [ARGUMENTS] in {
18
19 // Call sequence markers. These have an immediate which represents the amount of
20 // stack space to allocate or free, which is used for varargs lowering.
21 let Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in {
22 def ADJCALLSTACKDOWN : I<(outs), (ins i32imm:$amt),
23                          [(WebAssemblycallseq_start timm:$amt)]>;
24 def ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt, i32imm:$amt2),
25                        [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>;
26 } // isCodeGenOnly = 1
27
28 multiclass CALL<WebAssemblyRegClass vt, string prefix> {
29   def CALL_#vt : I<(outs vt:$dst), (ins function32_op:$callee, variable_ops),
30                    [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))],
31                    !strconcat(prefix, "call\t$dst, $callee"),
32                    0x10>;
33
34   let isCodeGenOnly = 1 in {
35     def PCALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops),
36                               [(set vt:$dst, (WebAssemblycall1 I32:$callee))],
37                               "PSEUDO CALL INDIRECT\t$callee">;
38   } // isCodeGenOnly = 1
39
40   def CALL_INDIRECT_#vt : I<(outs vt:$dst),
41                             (ins TypeIndex:$type, i32imm:$flags, variable_ops),
42                             [],
43                             !strconcat(prefix, "call_indirect\t$dst"),
44                             0x11>;
45 }
46
47 multiclass SIMD_CALL<ValueType vt, string prefix> {
48   def CALL_#vt : SIMD_I<(outs V128:$dst), (ins function32_op:$callee, variable_ops),
49                          [(set (vt V128:$dst),
50                                (WebAssemblycall1 (i32 imm:$callee)))],
51                          !strconcat(prefix, "call\t$dst, $callee"),
52                          0x10>;
53
54   let isCodeGenOnly = 1 in {
55     def PCALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst),
56                                     (ins I32:$callee, variable_ops),
57                                     [(set (vt V128:$dst),
58                                           (WebAssemblycall1 I32:$callee))],
59                                     "PSEUDO CALL INDIRECT\t$callee">;
60   } // isCodeGenOnly = 1
61
62   def CALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst),
63                                   (ins TypeIndex:$type, i32imm:$flags,
64                                        variable_ops),
65                                   [],
66                                   !strconcat(prefix, "call_indirect\t$dst"),
67                                   0x11>;
68 }
69
70 let Uses = [SP32, SP64], isCall = 1 in {
71   defm : CALL<I32, "i32.">;
72   defm : CALL<I64, "i64.">;
73   defm : CALL<F32, "f32.">;
74   defm : CALL<F64, "f64.">;
75   defm : SIMD_CALL<v16i8, "i8x16.">;
76   defm : SIMD_CALL<v8i16, "i16x8.">;
77   defm : SIMD_CALL<v4i32, "i32x4.">;
78   defm : SIMD_CALL<v4f32, "f32x4.">;
79
80   def CALL_VOID : I<(outs), (ins function32_op:$callee, variable_ops),
81                     [(WebAssemblycall0 (i32 imm:$callee))],
82                     "call    \t$callee", 0x10>;
83
84   let isCodeGenOnly = 1 in {
85     def PCALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops),
86                       [(WebAssemblycall0 I32:$callee)],
87                       "PSEUDO CALL INDIRECT\t$callee">;
88   } // isCodeGenOnly = 1
89
90   def CALL_INDIRECT_VOID : I<(outs),
91                              (ins TypeIndex:$type, i32imm:$flags, variable_ops),
92                              [],
93                              "call_indirect\t", 0x11>;
94 } // Uses = [SP32,SP64], isCall = 1
95
96 } // Defs = [ARGUMENTS]
97
98 // Patterns for matching a direct call to a global address.
99 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
100           (CALL_I32 tglobaladdr:$callee)>;
101 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
102           (CALL_I64 tglobaladdr:$callee)>;
103 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
104           (CALL_F32 tglobaladdr:$callee)>;
105 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
106           (CALL_F64 tglobaladdr:$callee)>;
107 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
108           (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
109 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
110           (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
111 def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
112           (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
113 def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
114           (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
115 def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)),
116           (CALL_VOID tglobaladdr:$callee)>;
117
118 // Patterns for matching a direct call to an external symbol.
119 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
120           (CALL_I32 texternalsym:$callee)>;
121 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
122           (CALL_I64 texternalsym:$callee)>;
123 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
124           (CALL_F32 texternalsym:$callee)>;
125 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
126           (CALL_F64 texternalsym:$callee)>;
127 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
128           (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>;
129 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
130           (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>;
131 def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
132           (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
133 def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
134           (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
135 def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)),
136           (CALL_VOID texternalsym:$callee)>;