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 115ca0bacaSJF Bastien/// \brief 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 { 22e2a7a827SDan Gohmandef ADJCALLSTACKDOWN : I<(outs), (ins i32imm:$amt), 23af111db8SJF Bastien [(WebAssemblycallseq_start timm:$amt)]>; 24e2a7a827SDan Gohmandef ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt), 2535bfb24cSDan Gohman [(WebAssemblycallseq_end timm:$amt, undef)]>; 26af111db8SJF Bastien} // isCodeGenOnly = 1 27af111db8SJF Bastien 28*c7c04454SDan Gohmanmulticlass CALL<WebAssemblyRegClass vt, string prefix> { 29e2a7a827SDan Gohman def CALL_#vt : I<(outs vt:$dst), (ins i32imm:$callee, variable_ops), 30e2a7a827SDan Gohman [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))], 31*c7c04454SDan Gohman !strconcat(prefix, "call\t$dst, $callee")>; 3205a17aa8SDan Gohman def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops), 33cf4748f1SDan Gohman [(set vt:$dst, (WebAssemblycall1 I32:$callee))], 34*c7c04454SDan Gohman !strconcat(prefix, "call_indirect\t$dst, $callee")>; 35af111db8SJF Bastien} 36af111db8SJF Bastienlet Uses = [SP32, SP64], isCall = 1 in { 37*c7c04454SDan Gohman defm : CALL<I32, "i32.">; 38*c7c04454SDan Gohman defm : CALL<I64, "i64.">; 39*c7c04454SDan Gohman defm : CALL<F32, "f32.">; 40*c7c04454SDan Gohman defm : CALL<F64, "f64.">; 41f71abef7SDan Gohman 42e2a7a827SDan Gohman def CALL_VOID : I<(outs), (ins i32imm:$callee, variable_ops), 43e2a7a827SDan Gohman [(WebAssemblycall0 (i32 imm:$callee))], 441031d4a8SDan Gohman "call \t$callee">; 4505a17aa8SDan Gohman def CALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops), 46cf4748f1SDan Gohman [(WebAssemblycall0 I32:$callee)], 471031d4a8SDan Gohman "call_indirect\t$callee">; 48af111db8SJF Bastien} // Uses = [SP32,SP64], isCall = 1 49fb3e0594SDan Gohman 50fb3e0594SDan Gohman} // Defs = [ARGUMENTS] 51e2a7a827SDan Gohman 52e2a7a827SDan Gohman// Patterns for matching a direct call to a global address. 53e2a7a827SDan Gohmandef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 54e2a7a827SDan Gohman (CALL_I32 tglobaladdr:$callee)>; 55e2a7a827SDan Gohmandef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 56e2a7a827SDan Gohman (CALL_I64 tglobaladdr:$callee)>; 57e2a7a827SDan Gohmandef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 58e2a7a827SDan Gohman (CALL_F32 tglobaladdr:$callee)>; 59e2a7a827SDan Gohmandef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 60e2a7a827SDan Gohman (CALL_F64 tglobaladdr:$callee)>; 61e2a7a827SDan Gohmandef : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)), 62e2a7a827SDan Gohman (CALL_VOID tglobaladdr:$callee)>; 63e2a7a827SDan Gohman 64e2a7a827SDan Gohman// Patterns for matching a direct call to an external symbol. 65e2a7a827SDan Gohmandef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 66e2a7a827SDan Gohman (CALL_I32 texternalsym:$callee)>; 67e2a7a827SDan Gohmandef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 68e2a7a827SDan Gohman (CALL_I64 texternalsym:$callee)>; 69e2a7a827SDan Gohmandef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 70e2a7a827SDan Gohman (CALL_F32 texternalsym:$callee)>; 71e2a7a827SDan Gohmandef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 72e2a7a827SDan Gohman (CALL_F64 texternalsym:$callee)>; 73e2a7a827SDan Gohmandef : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)), 74e2a7a827SDan Gohman (CALL_VOID texternalsym:$callee)>; 75