15ca0bacaSJF Bastien//===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*- 25ca0bacaSJF Bastien// 35ca0bacaSJF Bastien// The LLVM Compiler Infrastructure 45ca0bacaSJF Bastien// 55ca0bacaSJF Bastien// This file is distributed under the University of Illinois Open Source 65ca0bacaSJF Bastien// License. See LICENSE.TXT for details. 75ca0bacaSJF Bastien// 85ca0bacaSJF Bastien//===----------------------------------------------------------------------===// 95ca0bacaSJF Bastien/// 105ca0bacaSJF Bastien/// \file 115f8f34e4SAdrian Prantl/// WebAssembly Call operand code-gen constructs. 125ca0bacaSJF Bastien/// 135ca0bacaSJF Bastien//===----------------------------------------------------------------------===// 145ca0bacaSJF Bastien 15e2a7a827SDan Gohman// TODO: addr64: These currently assume the callee address is 32-bit. 16e2a7a827SDan Gohman 17fb3e0594SDan Gohmanlet Defs = [ARGUMENTS] in { 18fb3e0594SDan Gohman 19905bef5cSDan Gohman// Call sequence markers. These have an immediate which represents the amount of 20905bef5cSDan Gohman// stack space to allocate or free, which is used for varargs lowering. 215a143063SDerek Schufflet Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in { 22d526b13eSSerge Pavlovdef ADJCALLSTACKDOWN : I<(outs), (ins i32imm:$amt, i32imm:$amt2), 23d526b13eSSerge Pavlov [(WebAssemblycallseq_start timm:$amt, timm:$amt2)]>; 248bb5f292SDerek Schuffdef ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt, i32imm:$amt2), 258bb5f292SDerek Schuff [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>; 26af111db8SJF Bastien} // isCodeGenOnly = 1 27af111db8SJF Bastien 28c7c04454SDan Gohmanmulticlass CALL<WebAssemblyRegClass vt, string prefix> { 2900d734d8SDan Gohman def CALL_#vt : I<(outs vt:$dst), (ins function32_op:$callee, variable_ops), 30e2a7a827SDan Gohman [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))], 313acb187dSDan Gohman !strconcat(prefix, "call\t$dst, $callee"), 323acb187dSDan Gohman 0x10>; 33d934cb88SDan Gohman 346f69783fSDerek Schuff let isCodeGenOnly = 1 in { 356f69783fSDerek Schuff def PCALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops), 36cf4748f1SDan Gohman [(set vt:$dst, (WebAssemblycall1 I32:$callee))], 376f69783fSDerek Schuff "PSEUDO CALL INDIRECT\t$callee">; 386f69783fSDerek Schuff } // isCodeGenOnly = 1 39f50d964bSDan Gohman 40d934cb88SDan Gohman def CALL_INDIRECT_#vt : I<(outs vt:$dst), 41d934cb88SDan Gohman (ins TypeIndex:$type, i32imm:$flags, variable_ops), 426f69783fSDerek Schuff [], 433acb187dSDan Gohman !strconcat(prefix, "call_indirect\t$dst"), 443acb187dSDan Gohman 0x11>; 45af111db8SJF Bastien} 4639bf39f3SDerek Schuff 4739bf39f3SDerek Schuffmulticlass SIMD_CALL<ValueType vt, string prefix> { 4800d734d8SDan Gohman def CALL_#vt : SIMD_I<(outs V128:$dst), (ins function32_op:$callee, variable_ops), 4939bf39f3SDerek Schuff [(set (vt V128:$dst), 5039bf39f3SDerek Schuff (WebAssemblycall1 (i32 imm:$callee)))], 513acb187dSDan Gohman !strconcat(prefix, "call\t$dst, $callee"), 523acb187dSDan Gohman 0x10>; 53d934cb88SDan Gohman 546f69783fSDerek Schuff let isCodeGenOnly = 1 in { 556f69783fSDerek Schuff def PCALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst), 5639bf39f3SDerek Schuff (ins I32:$callee, variable_ops), 5739bf39f3SDerek Schuff [(set (vt V128:$dst), 5839bf39f3SDerek Schuff (WebAssemblycall1 I32:$callee))], 596f69783fSDerek Schuff "PSEUDO CALL INDIRECT\t$callee">; 606f69783fSDerek Schuff } // isCodeGenOnly = 1 61f50d964bSDan Gohman 626f69783fSDerek Schuff def CALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst), 63d934cb88SDan Gohman (ins TypeIndex:$type, i32imm:$flags, 64d934cb88SDan Gohman variable_ops), 656f69783fSDerek Schuff [], 663acb187dSDan Gohman !strconcat(prefix, "call_indirect\t$dst"), 673acb187dSDan Gohman 0x11>; 6839bf39f3SDerek Schuff} 6939bf39f3SDerek Schuff 70af111db8SJF Bastienlet Uses = [SP32, SP64], isCall = 1 in { 71*537afe6fSSam Clegg defm "" : CALL<I32, "i32.">; 72*537afe6fSSam Clegg defm "" : CALL<I64, "i64.">; 73*537afe6fSSam Clegg defm "" : CALL<F32, "f32.">; 74*537afe6fSSam Clegg defm "" : CALL<F64, "f64.">; 75*537afe6fSSam Clegg defm "" : CALL<EXCEPT_REF, "except_ref.">; 76*537afe6fSSam Clegg defm "" : SIMD_CALL<v16i8, "i8x16.">; 77*537afe6fSSam Clegg defm "" : SIMD_CALL<v8i16, "i16x8.">; 78*537afe6fSSam Clegg defm "" : SIMD_CALL<v4i32, "i32x4.">; 79*537afe6fSSam Clegg defm "" : SIMD_CALL<v4f32, "f32x4.">; 80f71abef7SDan Gohman 8100d734d8SDan Gohman def CALL_VOID : I<(outs), (ins function32_op:$callee, variable_ops), 82e2a7a827SDan Gohman [(WebAssemblycall0 (i32 imm:$callee))], 833acb187dSDan Gohman "call \t$callee", 0x10>; 84d934cb88SDan Gohman 856f69783fSDerek Schuff let isCodeGenOnly = 1 in { 866f69783fSDerek Schuff def PCALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops), 87cf4748f1SDan Gohman [(WebAssemblycall0 I32:$callee)], 886f69783fSDerek Schuff "PSEUDO CALL INDIRECT\t$callee">; 896f69783fSDerek Schuff } // isCodeGenOnly = 1 90f50d964bSDan Gohman 91d934cb88SDan Gohman def CALL_INDIRECT_VOID : I<(outs), 92d934cb88SDan Gohman (ins TypeIndex:$type, i32imm:$flags, variable_ops), 936f69783fSDerek Schuff [], 943acb187dSDan Gohman "call_indirect\t", 0x11>; 95af111db8SJF Bastien} // Uses = [SP32,SP64], isCall = 1 96fb3e0594SDan Gohman 97fb3e0594SDan Gohman} // Defs = [ARGUMENTS] 98e2a7a827SDan Gohman 99e2a7a827SDan Gohman// Patterns for matching a direct call to a global address. 100e2a7a827SDan Gohmandef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 101e2a7a827SDan Gohman (CALL_I32 tglobaladdr:$callee)>; 102e2a7a827SDan Gohmandef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 103e2a7a827SDan Gohman (CALL_I64 tglobaladdr:$callee)>; 104e2a7a827SDan Gohmandef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 105e2a7a827SDan Gohman (CALL_F32 tglobaladdr:$callee)>; 106e2a7a827SDan Gohmandef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 107e2a7a827SDan Gohman (CALL_F64 tglobaladdr:$callee)>; 10839bf39f3SDerek Schuffdef : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 10939bf39f3SDerek Schuff (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 11039bf39f3SDerek Schuffdef : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 11139bf39f3SDerek Schuff (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 11239bf39f3SDerek Schuffdef : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 11339bf39f3SDerek Schuff (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 11439bf39f3SDerek Schuffdef : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 11539bf39f3SDerek Schuff (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 1160de58729SHeejin Ahndef : Pat<(ExceptRef 1170de58729SHeejin Ahn (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 1180de58729SHeejin Ahn (CALL_EXCEPT_REF tglobaladdr:$callee)>; 119e2a7a827SDan Gohmandef : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)), 120e2a7a827SDan Gohman (CALL_VOID tglobaladdr:$callee)>; 121e2a7a827SDan Gohman 122e2a7a827SDan Gohman// Patterns for matching a direct call to an external symbol. 123e2a7a827SDan Gohmandef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 124e2a7a827SDan Gohman (CALL_I32 texternalsym:$callee)>; 125e2a7a827SDan Gohmandef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 126e2a7a827SDan Gohman (CALL_I64 texternalsym:$callee)>; 127e2a7a827SDan Gohmandef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 128e2a7a827SDan Gohman (CALL_F32 texternalsym:$callee)>; 129e2a7a827SDan Gohmandef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 130e2a7a827SDan Gohman (CALL_F64 texternalsym:$callee)>; 13139bf39f3SDerek Schuffdef : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 13239bf39f3SDerek Schuff (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>; 13339bf39f3SDerek Schuffdef : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 13439bf39f3SDerek Schuff (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>; 13539bf39f3SDerek Schuffdef : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 13639bf39f3SDerek Schuff (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>; 13739bf39f3SDerek Schuffdef : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 13839bf39f3SDerek Schuff (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>; 1390de58729SHeejin Ahndef : Pat<(ExceptRef 1400de58729SHeejin Ahn (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 1410de58729SHeejin Ahn (CALL_EXCEPT_REF texternalsym:$callee)>; 142e2a7a827SDan Gohmandef : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)), 143e2a7a827SDan Gohman (CALL_VOID texternalsym:$callee)>; 144