1 //===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*-
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief WebAssembly Call operand code-gen constructs.
13 //===----------------------------------------------------------------------===//
15 // TODO: addr64: These currently assume the callee address is 32-bit.
17 let Defs = [ARGUMENTS] in {
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, i32imm:$amt2),
23 [(WebAssemblycallseq_start timm:$amt, timm:$amt2)]>;
24 def ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt, i32imm:$amt2),
25 [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>;
26 } // isCodeGenOnly = 1
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"),
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
40 def CALL_INDIRECT_#vt : I<(outs vt:$dst),
41 (ins TypeIndex:$type, i32imm:$flags, variable_ops),
43 !strconcat(prefix, "call_indirect\t$dst"),
47 multiclass SIMD_CALL<ValueType vt, string prefix> {
48 def CALL_#vt : SIMD_I<(outs V128:$dst), (ins function32_op:$callee, variable_ops),
50 (WebAssemblycall1 (i32 imm:$callee)))],
51 !strconcat(prefix, "call\t$dst, $callee"),
54 let isCodeGenOnly = 1 in {
55 def PCALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst),
56 (ins I32:$callee, variable_ops),
58 (WebAssemblycall1 I32:$callee))],
59 "PSEUDO CALL INDIRECT\t$callee">;
60 } // isCodeGenOnly = 1
62 def CALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst),
63 (ins TypeIndex:$type, i32imm:$flags,
66 !strconcat(prefix, "call_indirect\t$dst"),
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.">;
80 def CALL_VOID : I<(outs), (ins function32_op:$callee, variable_ops),
81 [(WebAssemblycall0 (i32 imm:$callee))],
82 "call \t$callee", 0x10>;
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
90 def CALL_INDIRECT_VOID : I<(outs),
91 (ins TypeIndex:$type, i32imm:$flags, variable_ops),
93 "call_indirect\t", 0x11>;
94 } // Uses = [SP32,SP64], isCall = 1
96 } // Defs = [ARGUMENTS]
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)>;
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)>;