15ca0bacaSJF Bastien//===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*-
25ca0bacaSJF Bastien//
35ca0bacaSJF Bastien//                     The LLVM Compiler Infrastructure
45ca0bacaSJF Bastien//
55ca0bacaSJF Bastien// This file is distributed under the University of Illinois Open Source
65ca0bacaSJF Bastien// License. See LICENSE.TXT for details.
75ca0bacaSJF Bastien//
85ca0bacaSJF Bastien//===----------------------------------------------------------------------===//
95ca0bacaSJF Bastien///
105ca0bacaSJF Bastien/// \file
115ca0bacaSJF Bastien/// \brief WebAssembly Call operand code-gen constructs.
125ca0bacaSJF Bastien///
135ca0bacaSJF Bastien//===----------------------------------------------------------------------===//
145ca0bacaSJF Bastien
15e2a7a827SDan Gohman// TODO: addr64: These currently assume the callee address is 32-bit.
16e2a7a827SDan Gohman
17fb3e0594SDan Gohmanlet Defs = [ARGUMENTS] in {
18fb3e0594SDan Gohman
19905bef5cSDan Gohman// Call sequence markers. These have an immediate which represents the amount of
20905bef5cSDan Gohman// stack space to allocate or free, which is used for varargs lowering.
215a143063SDerek Schufflet Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in {
22e2a7a827SDan Gohmandef ADJCALLSTACKDOWN : I<(outs), (ins i32imm:$amt),
23af111db8SJF Bastien                         [(WebAssemblycallseq_start timm:$amt)]>;
248bb5f292SDerek Schuffdef ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt, i32imm:$amt2),
258bb5f292SDerek Schuff                       [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>;
26af111db8SJF Bastien} // isCodeGenOnly = 1
27af111db8SJF Bastien
28c7c04454SDan Gohmanmulticlass CALL<WebAssemblyRegClass vt, string prefix> {
29e2a7a827SDan Gohman  def CALL_#vt : I<(outs vt:$dst), (ins i32imm:$callee, variable_ops),
30e2a7a827SDan Gohman                   [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))],
31c7c04454SDan Gohman                   !strconcat(prefix, "call\t$dst, $callee")>;
3205a17aa8SDan Gohman  def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops),
33cf4748f1SDan Gohman                            [(set vt:$dst, (WebAssemblycall1 I32:$callee))],
34c7c04454SDan Gohman                            !strconcat(prefix, "call_indirect\t$dst, $callee")>;
35af111db8SJF Bastien}
36*39bf39f3SDerek Schuff
37*39bf39f3SDerek Schuffmulticlass SIMD_CALL<ValueType vt, string prefix> {
38*39bf39f3SDerek Schuff  def CALL_#vt : SIMD_I<(outs V128:$dst), (ins i32imm:$callee, variable_ops),
39*39bf39f3SDerek Schuff                         [(set (vt V128:$dst),
40*39bf39f3SDerek Schuff                               (WebAssemblycall1 (i32 imm:$callee)))],
41*39bf39f3SDerek Schuff                         !strconcat(prefix, "call\t$dst, $callee")>;
42*39bf39f3SDerek Schuff  def CALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst),
43*39bf39f3SDerek Schuff                                  (ins I32:$callee, variable_ops),
44*39bf39f3SDerek Schuff                                  [(set (vt V128:$dst),
45*39bf39f3SDerek Schuff                                        (WebAssemblycall1 I32:$callee))],
46*39bf39f3SDerek Schuff                                  !strconcat(prefix,
47*39bf39f3SDerek Schuff                                             "call_indirect\t$dst, $callee")>;
48*39bf39f3SDerek Schuff}
49*39bf39f3SDerek Schuff
50af111db8SJF Bastienlet Uses = [SP32, SP64], isCall = 1 in {
51c7c04454SDan Gohman  defm : CALL<I32, "i32.">;
52c7c04454SDan Gohman  defm : CALL<I64, "i64.">;
53c7c04454SDan Gohman  defm : CALL<F32, "f32.">;
54c7c04454SDan Gohman  defm : CALL<F64, "f64.">;
55*39bf39f3SDerek Schuff  defm : SIMD_CALL<v16i8, "i8x16.">;
56*39bf39f3SDerek Schuff  defm : SIMD_CALL<v8i16, "i16x8.">;
57*39bf39f3SDerek Schuff  defm : SIMD_CALL<v4i32, "i32x4.">;
58*39bf39f3SDerek Schuff  defm : SIMD_CALL<v4f32, "f32x4.">;
59f71abef7SDan Gohman
60e2a7a827SDan Gohman  def CALL_VOID : I<(outs), (ins i32imm:$callee, variable_ops),
61e2a7a827SDan Gohman                    [(WebAssemblycall0 (i32 imm:$callee))],
621031d4a8SDan Gohman                    "call    \t$callee">;
6305a17aa8SDan Gohman  def CALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops),
64cf4748f1SDan Gohman                             [(WebAssemblycall0 I32:$callee)],
651031d4a8SDan Gohman                             "call_indirect\t$callee">;
66af111db8SJF Bastien} // Uses = [SP32,SP64], isCall = 1
67fb3e0594SDan Gohman
68fb3e0594SDan Gohman} // Defs = [ARGUMENTS]
69e2a7a827SDan Gohman
70e2a7a827SDan Gohman// Patterns for matching a direct call to a global address.
71e2a7a827SDan Gohmandef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
72e2a7a827SDan Gohman          (CALL_I32 tglobaladdr:$callee)>;
73e2a7a827SDan Gohmandef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
74e2a7a827SDan Gohman          (CALL_I64 tglobaladdr:$callee)>;
75e2a7a827SDan Gohmandef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
76e2a7a827SDan Gohman          (CALL_F32 tglobaladdr:$callee)>;
77e2a7a827SDan Gohmandef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
78e2a7a827SDan Gohman          (CALL_F64 tglobaladdr:$callee)>;
79*39bf39f3SDerek Schuffdef : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
80*39bf39f3SDerek Schuff          (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
81*39bf39f3SDerek Schuffdef : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
82*39bf39f3SDerek Schuff          (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
83*39bf39f3SDerek Schuffdef : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
84*39bf39f3SDerek Schuff          (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
85*39bf39f3SDerek Schuffdef : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
86*39bf39f3SDerek Schuff          (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
87e2a7a827SDan Gohmandef : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)),
88e2a7a827SDan Gohman          (CALL_VOID tglobaladdr:$callee)>;
89e2a7a827SDan Gohman
90e2a7a827SDan Gohman// Patterns for matching a direct call to an external symbol.
91e2a7a827SDan Gohmandef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
92e2a7a827SDan Gohman          (CALL_I32 texternalsym:$callee)>;
93e2a7a827SDan Gohmandef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
94e2a7a827SDan Gohman          (CALL_I64 texternalsym:$callee)>;
95e2a7a827SDan Gohmandef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
96e2a7a827SDan Gohman          (CALL_F32 texternalsym:$callee)>;
97e2a7a827SDan Gohmandef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
98e2a7a827SDan Gohman          (CALL_F64 texternalsym:$callee)>;
99*39bf39f3SDerek Schuffdef : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
100*39bf39f3SDerek Schuff          (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>;
101*39bf39f3SDerek Schuffdef : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
102*39bf39f3SDerek Schuff          (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>;
103*39bf39f3SDerek Schuffdef : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
104*39bf39f3SDerek Schuff          (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
105*39bf39f3SDerek Schuffdef : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
106*39bf39f3SDerek Schuff          (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
107e2a7a827SDan Gohmandef : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)),
108e2a7a827SDan Gohman          (CALL_VOID texternalsym:$callee)>;
109