1*9880d681SAndroid Build Coastguard Worker//===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*- 2*9880d681SAndroid Build Coastguard Worker// 3*9880d681SAndroid Build Coastguard Worker// The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker// 5*9880d681SAndroid Build Coastguard Worker// This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker// License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker// 8*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker/// 10*9880d681SAndroid Build Coastguard Worker/// \file 11*9880d681SAndroid Build Coastguard Worker/// \brief WebAssembly Call operand code-gen constructs. 12*9880d681SAndroid Build Coastguard Worker/// 13*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===// 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker// TODO: addr64: These currently assume the callee address is 32-bit. 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Workerlet Defs = [ARGUMENTS] in { 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker// Call sequence markers. These have an immediate which represents the amount of 20*9880d681SAndroid Build Coastguard Worker// stack space to allocate or free, which is used for varargs lowering. 21*9880d681SAndroid Build Coastguard Workerlet Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in { 22*9880d681SAndroid Build Coastguard Workerdef ADJCALLSTACKDOWN : I<(outs), (ins i32imm:$amt), 23*9880d681SAndroid Build Coastguard Worker [(WebAssemblycallseq_start timm:$amt)]>; 24*9880d681SAndroid Build Coastguard Workerdef ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt, i32imm:$amt2), 25*9880d681SAndroid Build Coastguard Worker [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>; 26*9880d681SAndroid Build Coastguard Worker} // isCodeGenOnly = 1 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Workermulticlass CALL<WebAssemblyRegClass vt, string prefix> { 29*9880d681SAndroid Build Coastguard Worker def CALL_#vt : I<(outs vt:$dst), (ins i32imm:$callee, variable_ops), 30*9880d681SAndroid Build Coastguard Worker [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))], 31*9880d681SAndroid Build Coastguard Worker !strconcat(prefix, "call\t$dst, $callee")>; 32*9880d681SAndroid Build Coastguard Worker def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops), 33*9880d681SAndroid Build Coastguard Worker [(set vt:$dst, (WebAssemblycall1 I32:$callee))], 34*9880d681SAndroid Build Coastguard Worker !strconcat(prefix, "call_indirect\t$dst, $callee")>; 35*9880d681SAndroid Build Coastguard Worker} 36*9880d681SAndroid Build Coastguard Workerlet Uses = [SP32, SP64], isCall = 1 in { 37*9880d681SAndroid Build Coastguard Worker defm : CALL<I32, "i32.">; 38*9880d681SAndroid Build Coastguard Worker defm : CALL<I64, "i64.">; 39*9880d681SAndroid Build Coastguard Worker defm : CALL<F32, "f32.">; 40*9880d681SAndroid Build Coastguard Worker defm : CALL<F64, "f64.">; 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker def CALL_VOID : I<(outs), (ins i32imm:$callee, variable_ops), 43*9880d681SAndroid Build Coastguard Worker [(WebAssemblycall0 (i32 imm:$callee))], 44*9880d681SAndroid Build Coastguard Worker "call \t$callee">; 45*9880d681SAndroid Build Coastguard Worker def CALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops), 46*9880d681SAndroid Build Coastguard Worker [(WebAssemblycall0 I32:$callee)], 47*9880d681SAndroid Build Coastguard Worker "call_indirect\t$callee">; 48*9880d681SAndroid Build Coastguard Worker} // Uses = [SP32,SP64], isCall = 1 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Worker} // Defs = [ARGUMENTS] 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Worker// Patterns for matching a direct call to a global address. 53*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 54*9880d681SAndroid Build Coastguard Worker (CALL_I32 tglobaladdr:$callee)>; 55*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 56*9880d681SAndroid Build Coastguard Worker (CALL_I64 tglobaladdr:$callee)>; 57*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 58*9880d681SAndroid Build Coastguard Worker (CALL_F32 tglobaladdr:$callee)>; 59*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 60*9880d681SAndroid Build Coastguard Worker (CALL_F64 tglobaladdr:$callee)>; 61*9880d681SAndroid Build Coastguard Workerdef : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)), 62*9880d681SAndroid Build Coastguard Worker (CALL_VOID tglobaladdr:$callee)>; 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker// Patterns for matching a direct call to an external symbol. 65*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 66*9880d681SAndroid Build Coastguard Worker (CALL_I32 texternalsym:$callee)>; 67*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 68*9880d681SAndroid Build Coastguard Worker (CALL_I64 texternalsym:$callee)>; 69*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 70*9880d681SAndroid Build Coastguard Worker (CALL_F32 texternalsym:$callee)>; 71*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 72*9880d681SAndroid Build Coastguard Worker (CALL_F64 texternalsym:$callee)>; 73*9880d681SAndroid Build Coastguard Workerdef : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)), 74*9880d681SAndroid Build Coastguard Worker (CALL_VOID texternalsym:$callee)>; 75