blob: e9cad01f9df4285e6435988d08360c12324a40f8 [file] [log] [blame]
JF Bastien5ca0bac2015-07-10 18:23:10 +00001//===- 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
Dan Gohmane2a7a822015-12-05 20:41:36 +000015// TODO: addr64: These currently assume the callee address is 32-bit.
16
Dan Gohmanfb3e0592015-11-25 19:36:19 +000017let Defs = [ARGUMENTS] in {
18
Dan Gohman905bef52015-12-05 19:43:19 +000019// 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.
Derek Schuff5a143062015-12-11 18:55:34 +000021let Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in {
Dan Gohmane2a7a822015-12-05 20:41:36 +000022def ADJCALLSTACKDOWN : I<(outs), (ins i32imm:$amt),
Dan Gohman541841e2015-12-04 17:19:44 +000023 [(WebAssemblycallseq_start timm:$amt)]>;
Dan Gohmane2a7a822015-12-05 20:41:36 +000024def ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt),
Dan Gohman35bfb242015-12-04 23:22:35 +000025 [(WebAssemblycallseq_end timm:$amt, undef)]>;
JF Bastienaf111db2015-08-24 22:16:48 +000026} // isCodeGenOnly = 1
27
Dan Gohmanc7c04452015-12-14 22:56:51 +000028multiclass CALL<WebAssemblyRegClass vt, string prefix> {
Dan Gohmane2a7a822015-12-05 20:41:36 +000029 def CALL_#vt : I<(outs vt:$dst), (ins i32imm:$callee, variable_ops),
30 [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))],
Dan Gohmanc7c04452015-12-14 22:56:51 +000031 !strconcat(prefix, "call\t$dst, $callee")>;
Dan Gohman05a17aa2015-09-28 16:22:39 +000032 def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops),
Dan Gohmancf4748f2015-11-12 17:04:33 +000033 [(set vt:$dst, (WebAssemblycall1 I32:$callee))],
Dan Gohmanc7c04452015-12-14 22:56:51 +000034 !strconcat(prefix, "call_indirect\t$dst, $callee")>;
JF Bastienaf111db2015-08-24 22:16:48 +000035}
36let Uses = [SP32, SP64], isCall = 1 in {
Dan Gohmanc7c04452015-12-14 22:56:51 +000037 defm : CALL<I32, "i32.">;
38 defm : CALL<I64, "i64.">;
39 defm : CALL<F32, "f32.">;
40 defm : CALL<F64, "f64.">;
Dan Gohmanf71abef2015-09-09 16:13:47 +000041
Dan Gohmane2a7a822015-12-05 20:41:36 +000042 def CALL_VOID : I<(outs), (ins i32imm:$callee, variable_ops),
43 [(WebAssemblycall0 (i32 imm:$callee))],
Dan Gohman94ef41f2015-11-18 17:05:35 +000044 "call \t$callee">;
Dan Gohman05a17aa2015-09-28 16:22:39 +000045 def CALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops),
Dan Gohmancf4748f2015-11-12 17:04:33 +000046 [(WebAssemblycall0 I32:$callee)],
Dan Gohman1031d4a2015-11-15 15:34:19 +000047 "call_indirect\t$callee">;
JF Bastienaf111db2015-08-24 22:16:48 +000048} // Uses = [SP32,SP64], isCall = 1
Dan Gohmanfb3e0592015-11-25 19:36:19 +000049
50} // Defs = [ARGUMENTS]
Dan Gohmane2a7a822015-12-05 20:41:36 +000051
52// Patterns for matching a direct call to a global address.
53def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
54 (CALL_I32 tglobaladdr:$callee)>;
55def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
56 (CALL_I64 tglobaladdr:$callee)>;
57def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
58 (CALL_F32 tglobaladdr:$callee)>;
59def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
60 (CALL_F64 tglobaladdr:$callee)>;
61def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)),
62 (CALL_VOID tglobaladdr:$callee)>;
63
64// Patterns for matching a direct call to an external symbol.
65def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
66 (CALL_I32 texternalsym:$callee)>;
67def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
68 (CALL_I64 texternalsym:$callee)>;
69def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
70 (CALL_F32 texternalsym:$callee)>;
71def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
72 (CALL_F64 texternalsym:$callee)>;
73def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)),
74 (CALL_VOID texternalsym:$callee)>;