blob: 703c15d58c93adaf347b0a804339b63b580c2e91 [file] [log] [blame]
JF Bastien5ca0bac2015-07-10 18:23:10 +00001//===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*-
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
JF Bastien5ca0bac2015-07-10 18:23:10 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// WebAssembly Call operand code-gen constructs.
JF Bastien5ca0bac2015-07-10 18:23:10 +000011///
12//===----------------------------------------------------------------------===//
13
Dan Gohmane2a7a822015-12-05 20:41:36 +000014// TODO: addr64: These currently assume the callee address is 32-bit.
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000015// FIXME: add $type to first call_indirect asmstr (and maybe $flags)
Dan Gohmane2a7a822015-12-05 20:41:36 +000016
Dan Gohman905bef52015-12-05 19:43:19 +000017// Call sequence markers. These have an immediate which represents the amount of
18// stack space to allocate or free, which is used for varargs lowering.
Derek Schuff5a143062015-12-11 18:55:34 +000019let Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in {
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000020defm ADJCALLSTACKDOWN : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2),
21 [(WebAssemblycallseq_start timm:$amt, timm:$amt2)]>;
22defm ADJCALLSTACKUP : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2),
23 [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>;
Heejin Ahn43675872019-02-06 00:17:03 +000024} // Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1
JF Bastienaf111db2015-08-24 22:16:48 +000025
Thomas Livelya1d97a92019-06-26 16:17:15 +000026multiclass CALL<ValueType vt, WebAssemblyRegClass rt, string prefix,
27 list<Predicate> preds = []> {
28 defm CALL_#vt :
29 I<(outs rt:$dst), (ins function32_op:$callee, variable_ops),
30 (outs), (ins function32_op:$callee),
31 [(set (vt rt:$dst), (WebAssemblycall1 (i32 imm:$callee)))],
32 !strconcat(prefix, "call\t$dst, $callee"),
33 !strconcat(prefix, "call\t$callee"),
34 0x10>,
35 Requires<preds>;
Dan Gohmand934cb82017-02-24 23:18:00 +000036
Heejin Ahn43675872019-02-06 00:17:03 +000037 let isCodeGenOnly = 1 in
Thomas Livelya1d97a92019-06-26 16:17:15 +000038 defm PCALL_INDIRECT_#vt :
39 I<(outs rt:$dst), (ins I32:$callee, variable_ops),
40 (outs), (ins I32:$callee),
41 [(set (vt rt:$dst), (WebAssemblycall1 I32:$callee))],
42 "PSEUDO CALL INDIRECT\t$callee",
43 "PSEUDO CALL INDIRECT\t$callee">,
44 Requires<preds>;
Dan Gohmanf50d9642016-10-25 16:55:52 +000045
Thomas Livelya1d97a92019-06-26 16:17:15 +000046 defm CALL_INDIRECT_#vt :
47 I<(outs rt:$dst),
48 (ins TypeIndex:$type, i32imm:$flags, variable_ops),
49 (outs), (ins TypeIndex:$type, i32imm:$flags),
50 [],
51 !strconcat(prefix, "call_indirect\t$dst"),
52 !strconcat(prefix, "call_indirect\t$type"),
53 0x11>,
54 Requires<preds>;
Derek Schuff39bf39f2016-08-02 23:16:09 +000055}
56
JF Bastienaf111db2015-08-24 22:16:48 +000057let Uses = [SP32, SP64], isCall = 1 in {
Thomas Livelya1d97a92019-06-26 16:17:15 +000058defm "" : CALL<i32, I32, "i32.">;
59defm "" : CALL<i64, I64, "i64.">;
60defm "" : CALL<f32, F32, "f32.">;
61defm "" : CALL<f64, F64, "f64.">;
Heejin Ahn9f96a582019-07-15 22:49:25 +000062defm "" : CALL<exnref, EXNREF, "exnref.", [HasExceptionHandling]>;
Thomas Livelya1d97a92019-06-26 16:17:15 +000063defm "" : CALL<v16i8, V128, "v128.", [HasSIMD128]>;
64defm "" : CALL<v8i16, V128, "v128.", [HasSIMD128]>;
65defm "" : CALL<v4i32, V128, "v128.", [HasSIMD128]>;
66defm "" : CALL<v2i64, V128, "v128.", [HasSIMD128]>;
67defm "" : CALL<v4f32, V128, "v128.", [HasSIMD128]>;
68defm "" : CALL<v2f64, V128, "v128.", [HasSIMD128]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000069
Heejin Ahn43675872019-02-06 00:17:03 +000070let IsCanonical = 1 in {
Thomas Livelya1d97a92019-06-26 16:17:15 +000071defm CALL_VOID :
72 I<(outs), (ins function32_op:$callee, variable_ops),
73 (outs), (ins function32_op:$callee),
74 [(WebAssemblycall0 (i32 imm:$callee))],
75 "call \t$callee", "call\t$callee", 0x10>;
76
77let isReturn = 1 in
78defm RET_CALL :
79 I<(outs), (ins function32_op:$callee, variable_ops),
80 (outs), (ins function32_op:$callee),
81 [(WebAssemblyretcall (i32 imm:$callee))],
82 "return_call \t$callee", "return_call\t$callee", 0x12>,
83 Requires<[HasTailCall]>;
Dan Gohmand934cb82017-02-24 23:18:00 +000084
Heejin Ahn43675872019-02-06 00:17:03 +000085let isCodeGenOnly = 1 in
Thomas Livelya1d97a92019-06-26 16:17:15 +000086defm PCALL_INDIRECT_VOID :
87 I<(outs), (ins I32:$callee, variable_ops),
88 (outs), (ins I32:$callee),
89 [(WebAssemblycall0 I32:$callee)],
90 "PSEUDO CALL INDIRECT\t$callee",
91 "PSEUDO CALL INDIRECT\t$callee">;
Dan Gohmanf50d9642016-10-25 16:55:52 +000092
Thomas Livelya1d97a92019-06-26 16:17:15 +000093defm CALL_INDIRECT_VOID :
94 I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops),
95 (outs), (ins TypeIndex:$type, i32imm:$flags),
96 [],
97 "call_indirect\t", "call_indirect\t$type",
98 0x11>;
99
100let isReturn = 1 in
101defm RET_CALL_INDIRECT :
102 I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops),
103 (outs), (ins TypeIndex:$type, i32imm:$flags),
104 [],
105 "return_call_indirect\t", "return_call_indirect\t$type",
106 0x13>,
107 Requires<[HasTailCall]>;
108
109let isCodeGenOnly = 1, isReturn = 1 in
110defm PRET_CALL_INDIRECT:
111 I<(outs), (ins I32:$callee, variable_ops),
112 (outs), (ins I32:$callee),
113 [(WebAssemblyretcall I32:$callee)],
114 "PSEUDO RET_CALL INDIRECT\t$callee",
115 "PSEUDO RET_CALL INDIRECT\t$callee">,
116 Requires<[HasTailCall]>;
117
Heejin Ahn43675872019-02-06 00:17:03 +0000118} // IsCanonical = 1
JF Bastienaf111db2015-08-24 22:16:48 +0000119} // Uses = [SP32,SP64], isCall = 1
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000120
Dan Gohmane2a7a822015-12-05 20:41:36 +0000121// Patterns for matching a direct call to a global address.
122def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
Thomas Livelya1d97a92019-06-26 16:17:15 +0000123 (CALL_i32 tglobaladdr:$callee)>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000124def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
Thomas Livelya1d97a92019-06-26 16:17:15 +0000125 (CALL_i64 tglobaladdr:$callee)>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000126def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
Thomas Livelya1d97a92019-06-26 16:17:15 +0000127 (CALL_f32 tglobaladdr:$callee)>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000128def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
Thomas Livelya1d97a92019-06-26 16:17:15 +0000129 (CALL_f64 tglobaladdr:$callee)>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000130def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
131 (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
132def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
133 (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
134def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
135 (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
Derek Schuff51ed1312018-08-07 21:24:01 +0000136def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
137 (CALL_v2i64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000138def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
139 (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
Derek Schuff51ed1312018-08-07 21:24:01 +0000140def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
141 (CALL_v2f64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
Heejin Ahn9f96a582019-07-15 22:49:25 +0000142def : Pat<(exnref (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
143 (CALL_exnref tglobaladdr:$callee)>,
Thomas Livelya1d97a92019-06-26 16:17:15 +0000144 Requires<[HasExceptionHandling]>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000145def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)),
146 (CALL_VOID tglobaladdr:$callee)>;
Thomas Livelya1d97a92019-06-26 16:17:15 +0000147def : Pat<(WebAssemblyretcall (WebAssemblywrapper tglobaladdr:$callee)),
148 (RET_CALL tglobaladdr:$callee)>, Requires<[HasTailCall]>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000149
150// Patterns for matching a direct call to an external symbol.
151def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
Thomas Livelya1d97a92019-06-26 16:17:15 +0000152 (CALL_i32 texternalsym:$callee)>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000153def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
Thomas Livelya1d97a92019-06-26 16:17:15 +0000154 (CALL_i64 texternalsym:$callee)>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000155def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
Thomas Livelya1d97a92019-06-26 16:17:15 +0000156 (CALL_f32 texternalsym:$callee)>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000157def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
Thomas Livelya1d97a92019-06-26 16:17:15 +0000158 (CALL_f64 texternalsym:$callee)>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000159def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
160 (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>;
161def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
162 (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>;
163def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
164 (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
Derek Schuff51ed1312018-08-07 21:24:01 +0000165def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
166 (CALL_v2i64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000167def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
168 (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
Derek Schuff51ed1312018-08-07 21:24:01 +0000169def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
170 (CALL_v2f64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
Heejin Ahn9f96a582019-07-15 22:49:25 +0000171def : Pat<(exnref (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
172 (CALL_exnref texternalsym:$callee)>,
Thomas Livelya1d97a92019-06-26 16:17:15 +0000173 Requires<[HasExceptionHandling]>;
Dan Gohmane2a7a822015-12-05 20:41:36 +0000174def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)),
175 (CALL_VOID texternalsym:$callee)>;
Thomas Livelya1d97a92019-06-26 16:17:15 +0000176def : Pat<(WebAssemblyretcall (WebAssemblywrapper texternalsym:$callee)),
177 (RET_CALL texternalsym:$callee)>, Requires<[HasTailCall]>;