| JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 1 | //===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*- |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // 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 Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// WebAssembly Call operand code-gen constructs. |
| JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 14 | // TODO: addr64: These currently assume the callee address is 32-bit. |
| Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 15 | // FIXME: add $type to first call_indirect asmstr (and maybe $flags) |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 16 | |
| Dan Gohman | 905bef5 | 2015-12-05 19:43:19 +0000 | [diff] [blame] | 17 | // 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 Schuff | 5a14306 | 2015-12-11 18:55:34 +0000 | [diff] [blame] | 19 | let Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in { |
| Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 20 | defm ADJCALLSTACKDOWN : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2), |
| 21 | [(WebAssemblycallseq_start timm:$amt, timm:$amt2)]>; |
| 22 | defm ADJCALLSTACKUP : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2), |
| 23 | [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>; |
| Heejin Ahn | 4367587 | 2019-02-06 00:17:03 +0000 | [diff] [blame] | 24 | } // Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 25 | |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 26 | multiclass 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 Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 36 | |
| Heejin Ahn | 4367587 | 2019-02-06 00:17:03 +0000 | [diff] [blame] | 37 | let isCodeGenOnly = 1 in |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 38 | 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 Gohman | f50d964 | 2016-10-25 16:55:52 +0000 | [diff] [blame] | 45 | |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 46 | 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 Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 57 | let Uses = [SP32, SP64], isCall = 1 in { |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 58 | defm "" : CALL<i32, I32, "i32.">; |
| 59 | defm "" : CALL<i64, I64, "i64.">; |
| 60 | defm "" : CALL<f32, F32, "f32.">; |
| 61 | defm "" : CALL<f64, F64, "f64.">; |
| Heejin Ahn | 9f96a58 | 2019-07-15 22:49:25 +0000 | [diff] [blame] | 62 | defm "" : CALL<exnref, EXNREF, "exnref.", [HasExceptionHandling]>; |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 63 | defm "" : CALL<v16i8, V128, "v128.", [HasSIMD128]>; |
| 64 | defm "" : CALL<v8i16, V128, "v128.", [HasSIMD128]>; |
| 65 | defm "" : CALL<v4i32, V128, "v128.", [HasSIMD128]>; |
| 66 | defm "" : CALL<v2i64, V128, "v128.", [HasSIMD128]>; |
| 67 | defm "" : CALL<v4f32, V128, "v128.", [HasSIMD128]>; |
| 68 | defm "" : CALL<v2f64, V128, "v128.", [HasSIMD128]>; |
| Dan Gohman | f71abef | 2015-09-09 16:13:47 +0000 | [diff] [blame] | 69 | |
| Heejin Ahn | 4367587 | 2019-02-06 00:17:03 +0000 | [diff] [blame] | 70 | let IsCanonical = 1 in { |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 71 | defm 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 | |
| 77 | let isReturn = 1 in |
| 78 | defm 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 Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 84 | |
| Heejin Ahn | 4367587 | 2019-02-06 00:17:03 +0000 | [diff] [blame] | 85 | let isCodeGenOnly = 1 in |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 86 | defm 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 Gohman | f50d964 | 2016-10-25 16:55:52 +0000 | [diff] [blame] | 92 | |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 93 | defm 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 | |
| 100 | let isReturn = 1 in |
| 101 | defm 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 | |
| 109 | let isCodeGenOnly = 1, isReturn = 1 in |
| 110 | defm 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 Ahn | 4367587 | 2019-02-06 00:17:03 +0000 | [diff] [blame] | 118 | } // IsCanonical = 1 |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 119 | } // Uses = [SP32,SP64], isCall = 1 |
| Dan Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 120 | |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 121 | // Patterns for matching a direct call to a global address. |
| 122 | def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 123 | (CALL_i32 tglobaladdr:$callee)>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 124 | def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 125 | (CALL_i64 tglobaladdr:$callee)>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 126 | def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 127 | (CALL_f32 tglobaladdr:$callee)>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 128 | def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 129 | (CALL_f64 tglobaladdr:$callee)>; |
| Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 130 | def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 131 | (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| 132 | def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 133 | (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| 134 | def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 135 | (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| Derek Schuff | 51ed131 | 2018-08-07 21:24:01 +0000 | [diff] [blame] | 136 | def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 137 | (CALL_v2i64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 138 | def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 139 | (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| Derek Schuff | 51ed131 | 2018-08-07 21:24:01 +0000 | [diff] [blame] | 140 | def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 141 | (CALL_v2f64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| Heejin Ahn | 9f96a58 | 2019-07-15 22:49:25 +0000 | [diff] [blame] | 142 | def : Pat<(exnref (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 143 | (CALL_exnref tglobaladdr:$callee)>, |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 144 | Requires<[HasExceptionHandling]>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 145 | def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)), |
| 146 | (CALL_VOID tglobaladdr:$callee)>; |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 147 | def : Pat<(WebAssemblyretcall (WebAssemblywrapper tglobaladdr:$callee)), |
| 148 | (RET_CALL tglobaladdr:$callee)>, Requires<[HasTailCall]>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 149 | |
| 150 | // Patterns for matching a direct call to an external symbol. |
| 151 | def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 152 | (CALL_i32 texternalsym:$callee)>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 153 | def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 154 | (CALL_i64 texternalsym:$callee)>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 155 | def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 156 | (CALL_f32 texternalsym:$callee)>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 157 | def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 158 | (CALL_f64 texternalsym:$callee)>; |
| Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 159 | def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 160 | (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| 161 | def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 162 | (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| 163 | def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 164 | (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| Derek Schuff | 51ed131 | 2018-08-07 21:24:01 +0000 | [diff] [blame] | 165 | def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 166 | (CALL_v2i64 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 167 | def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 168 | (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| Derek Schuff | 51ed131 | 2018-08-07 21:24:01 +0000 | [diff] [blame] | 169 | def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 170 | (CALL_v2f64 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| Heejin Ahn | 9f96a58 | 2019-07-15 22:49:25 +0000 | [diff] [blame] | 171 | def : Pat<(exnref (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 172 | (CALL_exnref texternalsym:$callee)>, |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 173 | Requires<[HasExceptionHandling]>; |
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 174 | def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)), |
| 175 | (CALL_VOID texternalsym:$callee)>; |
| Thomas Lively | a1d97a9 | 2019-06-26 16:17:15 +0000 | [diff] [blame] | 176 | def : Pat<(WebAssemblyretcall (WebAssemblywrapper texternalsym:$callee)), |
| 177 | (RET_CALL texternalsym:$callee)>, Requires<[HasTailCall]>; |