1//===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*- 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9/// 10/// \file 11/// WebAssembly Call operand code-gen constructs. 12/// 13//===----------------------------------------------------------------------===// 14 15// TODO: addr64: These currently assume the callee address is 32-bit. 16 17let Defs = [ARGUMENTS] in { 18 19// Call sequence markers. These have an immediate which represents the amount of 20// stack space to allocate or free, which is used for varargs lowering. 21let Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in { 22def ADJCALLSTACKDOWN : I<(outs), (ins i32imm:$amt, i32imm:$amt2), 23 [(WebAssemblycallseq_start timm:$amt, timm:$amt2)]>; 24def ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt, i32imm:$amt2), 25 [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>; 26} // isCodeGenOnly = 1 27 28multiclass CALL<WebAssemblyRegClass vt, string prefix> { 29 def CALL_#vt : I<(outs vt:$dst), (ins function32_op:$callee, variable_ops), 30 [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))], 31 !strconcat(prefix, "call\t$dst, $callee"), 32 0x10>; 33 34 let isCodeGenOnly = 1 in { 35 def PCALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops), 36 [(set vt:$dst, (WebAssemblycall1 I32:$callee))], 37 "PSEUDO CALL INDIRECT\t$callee">; 38 } // isCodeGenOnly = 1 39 40 def CALL_INDIRECT_#vt : I<(outs vt:$dst), 41 (ins TypeIndex:$type, i32imm:$flags, variable_ops), 42 [], 43 !strconcat(prefix, "call_indirect\t$dst"), 44 0x11>; 45} 46 47multiclass SIMD_CALL<ValueType vt, string prefix> { 48 def CALL_#vt : SIMD_I<(outs V128:$dst), (ins function32_op:$callee, variable_ops), 49 [(set (vt V128:$dst), 50 (WebAssemblycall1 (i32 imm:$callee)))], 51 !strconcat(prefix, "call\t$dst, $callee"), 52 0x10>; 53 54 let isCodeGenOnly = 1 in { 55 def PCALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst), 56 (ins I32:$callee, variable_ops), 57 [(set (vt V128:$dst), 58 (WebAssemblycall1 I32:$callee))], 59 "PSEUDO CALL INDIRECT\t$callee">; 60 } // isCodeGenOnly = 1 61 62 def CALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst), 63 (ins TypeIndex:$type, i32imm:$flags, 64 variable_ops), 65 [], 66 !strconcat(prefix, "call_indirect\t$dst"), 67 0x11>; 68} 69 70let Uses = [SP32, SP64], isCall = 1 in { 71 defm : CALL<I32, "i32.">; 72 defm : CALL<I64, "i64.">; 73 defm : CALL<F32, "f32.">; 74 defm : CALL<F64, "f64.">; 75 defm : CALL<EXCEPT_REF, "except_ref.">; 76 defm : SIMD_CALL<v16i8, "i8x16.">; 77 defm : SIMD_CALL<v8i16, "i16x8.">; 78 defm : SIMD_CALL<v4i32, "i32x4.">; 79 defm : SIMD_CALL<v4f32, "f32x4.">; 80 81 def CALL_VOID : I<(outs), (ins function32_op:$callee, variable_ops), 82 [(WebAssemblycall0 (i32 imm:$callee))], 83 "call \t$callee", 0x10>; 84 85 let isCodeGenOnly = 1 in { 86 def PCALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops), 87 [(WebAssemblycall0 I32:$callee)], 88 "PSEUDO CALL INDIRECT\t$callee">; 89 } // isCodeGenOnly = 1 90 91 def CALL_INDIRECT_VOID : I<(outs), 92 (ins TypeIndex:$type, i32imm:$flags, variable_ops), 93 [], 94 "call_indirect\t", 0x11>; 95} // Uses = [SP32,SP64], isCall = 1 96 97} // Defs = [ARGUMENTS] 98 99// Patterns for matching a direct call to a global address. 100def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 101 (CALL_I32 tglobaladdr:$callee)>; 102def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 103 (CALL_I64 tglobaladdr:$callee)>; 104def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 105 (CALL_F32 tglobaladdr:$callee)>; 106def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 107 (CALL_F64 tglobaladdr:$callee)>; 108def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 109 (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 110def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 111 (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 112def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 113 (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 114def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 115 (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; 116def : Pat<(ExceptRef 117 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), 118 (CALL_EXCEPT_REF tglobaladdr:$callee)>; 119def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)), 120 (CALL_VOID tglobaladdr:$callee)>; 121 122// Patterns for matching a direct call to an external symbol. 123def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 124 (CALL_I32 texternalsym:$callee)>; 125def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 126 (CALL_I64 texternalsym:$callee)>; 127def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 128 (CALL_F32 texternalsym:$callee)>; 129def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 130 (CALL_F64 texternalsym:$callee)>; 131def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 132 (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>; 133def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 134 (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>; 135def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 136 (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>; 137def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 138 (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>; 139def : Pat<(ExceptRef 140 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), 141 (CALL_EXCEPT_REF texternalsym:$callee)>; 142def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)), 143 (CALL_VOID texternalsym:$callee)>; 144