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