15ca0bacaSJF Bastien//===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*- 25ca0bacaSJF Bastien// 32946cd70SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth// See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65ca0bacaSJF Bastien// 75ca0bacaSJF Bastien//===----------------------------------------------------------------------===// 85ca0bacaSJF Bastien/// 95ca0bacaSJF Bastien/// \file 105f8f34e4SAdrian Prantl/// WebAssembly Call operand code-gen constructs. 115ca0bacaSJF Bastien/// 125ca0bacaSJF Bastien//===----------------------------------------------------------------------===// 135ca0bacaSJF Bastien 14e2a7a827SDan Gohman// TODO: addr64: These currently assume the callee address is 32-bit. 1548dac310SWouter van Oortmerssen// FIXME: add $type to first call_indirect asmstr (and maybe $flags) 16e2a7a827SDan Gohman 17905bef5cSDan Gohman// Call sequence markers. These have an immediate which represents the amount of 18905bef5cSDan Gohman// stack space to allocate or free, which is used for varargs lowering. 195a143063SDerek Schufflet Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in { 2048dac310SWouter van Oortmerssendefm ADJCALLSTACKDOWN : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2), 21d526b13eSSerge Pavlov [(WebAssemblycallseq_start timm:$amt, timm:$amt2)]>; 2248dac310SWouter van Oortmerssendefm ADJCALLSTACKUP : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2), 238bb5f292SDerek Schuff [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>; 244367587fSHeejin Ahn} // Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 25af111db8SJF Bastien 26*a1d97a96SThomas Livelymulticlass CALL<ValueType vt, WebAssemblyRegClass rt, string prefix, 27*a1d97a96SThomas Lively list<Predicate> preds = []> { 28*a1d97a96SThomas Lively defm CALL_#vt : 29*a1d97a96SThomas Lively I<(outs rt:$dst), (ins function32_op:$callee, variable_ops), 3048dac310SWouter van Oortmerssen (outs), (ins function32_op:$callee), 31*a1d97a96SThomas Lively [(set (vt rt:$dst), (WebAssemblycall1 (i32 imm:$callee)))], 323acb187dSDan Gohman !strconcat(prefix, "call\t$dst, $callee"), 3348dac310SWouter van Oortmerssen !strconcat(prefix, "call\t$callee"), 34c9c711a0SHeejin Ahn 0x10>, 35*a1d97a96SThomas Lively Requires<preds>; 36d934cb88SDan Gohman 374367587fSHeejin Ahn let isCodeGenOnly = 1 in 38*a1d97a96SThomas Lively defm PCALL_INDIRECT_#vt : 39*a1d97a96SThomas Lively I<(outs rt:$dst), (ins I32:$callee, variable_ops), 4048dac310SWouter van Oortmerssen (outs), (ins I32:$callee), 41*a1d97a96SThomas Lively [(set (vt rt:$dst), (WebAssemblycall1 I32:$callee))], 4248dac310SWouter van Oortmerssen "PSEUDO CALL INDIRECT\t$callee", 43c9c711a0SHeejin Ahn "PSEUDO CALL INDIRECT\t$callee">, 44*a1d97a96SThomas Lively Requires<preds>; 45f50d964bSDan Gohman 46*a1d97a96SThomas Lively defm CALL_INDIRECT_#vt : 47*a1d97a96SThomas Lively I<(outs rt:$dst), 48c9c711a0SHeejin Ahn (ins TypeIndex:$type, i32imm:$flags, variable_ops), 4948dac310SWouter van Oortmerssen (outs), (ins TypeIndex:$type, i32imm:$flags), 506f69783fSDerek Schuff [], 51c9c711a0SHeejin Ahn !strconcat(prefix, "call_indirect\t$dst"), 5248dac310SWouter van Oortmerssen !strconcat(prefix, "call_indirect\t$type"), 53c9c711a0SHeejin Ahn 0x11>, 54*a1d97a96SThomas Lively Requires<preds>; 5539bf39f3SDerek Schuff} 5639bf39f3SDerek Schuff 57af111db8SJF Bastienlet Uses = [SP32, SP64], isCall = 1 in { 58*a1d97a96SThomas Livelydefm "" : CALL<i32, I32, "i32.">; 59*a1d97a96SThomas Livelydefm "" : CALL<i64, I64, "i64.">; 60*a1d97a96SThomas Livelydefm "" : CALL<f32, F32, "f32.">; 61*a1d97a96SThomas Livelydefm "" : CALL<f64, F64, "f64.">; 62*a1d97a96SThomas Livelydefm "" : CALL<ExceptRef, EXCEPT_REF, "except_ref.", [HasExceptionHandling]>; 63*a1d97a96SThomas Livelydefm "" : CALL<v16i8, V128, "v128.", [HasSIMD128]>; 64*a1d97a96SThomas Livelydefm "" : CALL<v8i16, V128, "v128.", [HasSIMD128]>; 65*a1d97a96SThomas Livelydefm "" : CALL<v4i32, V128, "v128.", [HasSIMD128]>; 66*a1d97a96SThomas Livelydefm "" : CALL<v2i64, V128, "v128.", [HasSIMD128]>; 67*a1d97a96SThomas Livelydefm "" : CALL<v4f32, V128, "v128.", [HasSIMD128]>; 68*a1d97a96SThomas Livelydefm "" : CALL<v2f64, V128, "v128.", [HasSIMD128]>; 69f71abef7SDan Gohman 701a91cb04SWouter van Oortmerssenlet IsCanonical = 1 in { 71*a1d97a96SThomas Livelydefm CALL_VOID : 72*a1d97a96SThomas Lively I<(outs), (ins function32_op:$callee, variable_ops), 7348dac310SWouter van Oortmerssen (outs), (ins function32_op:$callee), 74e2a7a827SDan Gohman [(WebAssemblycall0 (i32 imm:$callee))], 7548dac310SWouter van Oortmerssen "call \t$callee", "call\t$callee", 0x10>; 76d934cb88SDan Gohman 77*a1d97a96SThomas Livelylet isReturn = 1 in 78*a1d97a96SThomas Livelydefm RET_CALL : 79*a1d97a96SThomas Lively I<(outs), (ins function32_op:$callee, variable_ops), 80*a1d97a96SThomas Lively (outs), (ins function32_op:$callee), 81*a1d97a96SThomas Lively [(WebAssemblyretcall (i32 imm:$callee))], 82*a1d97a96SThomas Lively "return_call \t$callee", "return_call\t$callee", 0x12>, 83*a1d97a96SThomas Lively Requires<[HasTailCall]>; 84*a1d97a96SThomas Lively 854367587fSHeejin Ahnlet isCodeGenOnly = 1 in 86*a1d97a96SThomas Livelydefm PCALL_INDIRECT_VOID : 87*a1d97a96SThomas Lively I<(outs), (ins I32:$callee, variable_ops), 8848dac310SWouter van Oortmerssen (outs), (ins I32:$callee), 89cf4748f1SDan Gohman [(WebAssemblycall0 I32:$callee)], 9048dac310SWouter van Oortmerssen "PSEUDO CALL INDIRECT\t$callee", 916f69783fSDerek Schuff "PSEUDO CALL INDIRECT\t$callee">; 92f50d964bSDan Gohman 93*a1d97a96SThomas Livelydefm CALL_INDIRECT_VOID : 94*a1d97a96SThomas Lively I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops), 9548dac310SWouter van Oortmerssen (outs), (ins TypeIndex:$type, i32imm:$flags), 966f69783fSDerek Schuff [], 9748dac310SWouter van Oortmerssen "call_indirect\t", "call_indirect\t$type", 9848dac310SWouter van Oortmerssen 0x11>; 99*a1d97a96SThomas Lively 100*a1d97a96SThomas Livelylet isReturn = 1 in 101*a1d97a96SThomas Livelydefm RET_CALL_INDIRECT : 102*a1d97a96SThomas Lively I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops), 103*a1d97a96SThomas Lively (outs), (ins TypeIndex:$type, i32imm:$flags), 104*a1d97a96SThomas Lively [], 105*a1d97a96SThomas Lively "return_call_indirect\t", "return_call_indirect\t$type", 106*a1d97a96SThomas Lively 0x13>, 107*a1d97a96SThomas Lively Requires<[HasTailCall]>; 108*a1d97a96SThomas Lively 109*a1d97a96SThomas Livelylet isCodeGenOnly = 1, isReturn = 1 in 110*a1d97a96SThomas Livelydefm PRET_CALL_INDIRECT: 111*a1d97a96SThomas Lively I<(outs), (ins I32:$callee, variable_ops), 112*a1d97a96SThomas Lively (outs), (ins I32:$callee), 113*a1d97a96SThomas Lively [(WebAssemblyretcall I32:$callee)], 114*a1d97a96SThomas Lively "PSEUDO RET_CALL INDIRECT\t$callee", 115*a1d97a96SThomas Lively "PSEUDO RET_CALL INDIRECT\t$callee">, 116*a1d97a96SThomas Lively Requires<[HasTailCall]>; 117*a1d97a96SThomas Lively 1184367587fSHeejin Ahn} // IsCanonical = 1 119af111db8SJF Bastien} // Uses = [SP32,SP64], isCall = 1 120fb3e0594SDan Gohman 121e2a7a827SDan Gohman// Patterns for matching a direct call to a global address. 122e2a7a827SDan Gohmandef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 123*a1d97a96SThomas Lively (CALL_i32 tglobaladdr:$callee)>; 124e2a7a827SDan Gohmandef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 125*a1d97a96SThomas Lively (CALL_i64 tglobaladdr:$callee)>; 126e2a7a827SDan Gohmandef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 127*a1d97a96SThomas Lively (CALL_f32 tglobaladdr:$callee)>; 128e2a7a827SDan Gohmandef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 129*a1d97a96SThomas Lively (CALL_f64 tglobaladdr:$callee)>; 13039bf39f3SDerek Schuffdef : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 13139bf39f3SDerek Schuff (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 13239bf39f3SDerek Schuffdef : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 13339bf39f3SDerek Schuff (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 13439bf39f3SDerek Schuffdef : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 13539bf39f3SDerek Schuff (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 13651ed131eSDerek Schuffdef : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 13751ed131eSDerek Schuff (CALL_v2i64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 13839bf39f3SDerek Schuffdef : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 13939bf39f3SDerek Schuff (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 14051ed131eSDerek Schuffdef : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 14151ed131eSDerek Schuff (CALL_v2f64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 1420de58729SHeejin Ahndef : Pat<(ExceptRef 1430de58729SHeejin Ahn (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 144*a1d97a96SThomas Lively (CALL_ExceptRef tglobaladdr:$callee)>, 145*a1d97a96SThomas Lively Requires<[HasExceptionHandling]>; 146e2a7a827SDan Gohmandef : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)), 147e2a7a827SDan Gohman (CALL_VOID tglobaladdr:$callee)>; 148*a1d97a96SThomas Livelydef : Pat<(WebAssemblyretcall (WebAssemblywrapper tglobaladdr:$callee)), 149*a1d97a96SThomas Lively (RET_CALL tglobaladdr:$callee)>, Requires<[HasTailCall]>; 150e2a7a827SDan Gohman 151e2a7a827SDan Gohman// Patterns for matching a direct call to an external symbol. 152e2a7a827SDan Gohmandef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 153*a1d97a96SThomas Lively (CALL_i32 texternalsym:$callee)>; 154e2a7a827SDan Gohmandef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 155*a1d97a96SThomas Lively (CALL_i64 texternalsym:$callee)>; 156e2a7a827SDan Gohmandef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 157*a1d97a96SThomas Lively (CALL_f32 texternalsym:$callee)>; 158e2a7a827SDan Gohmandef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 159*a1d97a96SThomas Lively (CALL_f64 texternalsym:$callee)>; 16039bf39f3SDerek Schuffdef : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 16139bf39f3SDerek Schuff (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>; 16239bf39f3SDerek Schuffdef : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 16339bf39f3SDerek Schuff (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>; 16439bf39f3SDerek Schuffdef : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 16539bf39f3SDerek Schuff (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>; 16651ed131eSDerek Schuffdef : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 16751ed131eSDerek Schuff (CALL_v2i64 texternalsym:$callee)>, Requires<[HasSIMD128]>; 16839bf39f3SDerek Schuffdef : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 16939bf39f3SDerek Schuff (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>; 17051ed131eSDerek Schuffdef : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 17151ed131eSDerek Schuff (CALL_v2f64 texternalsym:$callee)>, Requires<[HasSIMD128]>; 1720de58729SHeejin Ahndef : Pat<(ExceptRef 1730de58729SHeejin Ahn (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 174*a1d97a96SThomas Lively (CALL_ExceptRef texternalsym:$callee)>, 175*a1d97a96SThomas Lively Requires<[HasExceptionHandling]>; 176e2a7a827SDan Gohmandef : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)), 177e2a7a827SDan Gohman (CALL_VOID texternalsym:$callee)>; 178*a1d97a96SThomas Livelydef : Pat<(WebAssemblyretcall (WebAssemblywrapper texternalsym:$callee)), 179*a1d97a96SThomas Lively (RET_CALL texternalsym:$callee)>, Requires<[HasTailCall]>; 180