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