JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 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 | /// \brief WebAssembly Call operand code-gen constructs. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 15 | // TODO: addr64: These currently assume the callee address is 32-bit. |
| 16 | |
Dan Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 17 | let Defs = [ARGUMENTS] in { |
| 18 | |
Dan Gohman | 905bef5 | 2015-12-05 19:43:19 +0000 | [diff] [blame] | 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. |
Derek Schuff | 5a14306 | 2015-12-11 18:55:34 +0000 | [diff] [blame] | 21 | let Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in { |
Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 22 | def ADJCALLSTACKDOWN : I<(outs), (ins i32imm:$amt), |
Dan Gohman | 541841e | 2015-12-04 17:19:44 +0000 | [diff] [blame] | 23 | [(WebAssemblycallseq_start timm:$amt)]>; |
Derek Schuff | 8bb5f29 | 2015-12-16 23:21:30 +0000 | [diff] [blame] | 24 | def ADJCALLSTACKUP : I<(outs), (ins i32imm:$amt, i32imm:$amt2), |
| 25 | [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 26 | } // isCodeGenOnly = 1 |
| 27 | |
Dan Gohman | c7c0445 | 2015-12-14 22:56:51 +0000 | [diff] [blame] | 28 | multiclass CALL<WebAssemblyRegClass vt, string prefix> { |
Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 29 | def CALL_#vt : I<(outs vt:$dst), (ins i32imm:$callee, variable_ops), |
| 30 | [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))], |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 31 | !strconcat(prefix, "call\t$dst, $callee"), |
| 32 | 0x10>; |
Derek Schuff | 6f69783 | 2016-10-21 16:38:07 +0000 | [diff] [blame] | 33 | let isCodeGenOnly = 1 in { |
| 34 | def PCALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops), |
| 35 | [(set vt:$dst, (WebAssemblycall1 I32:$callee))], |
| 36 | "PSEUDO CALL INDIRECT\t$callee">; |
| 37 | } // isCodeGenOnly = 1 |
Dan Gohman | f50d964 | 2016-10-25 16:55:52 +0000 | [diff] [blame] | 38 | |
| 39 | def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins i32imm:$flags, variable_ops), |
Derek Schuff | 6f69783 | 2016-10-21 16:38:07 +0000 | [diff] [blame] | 40 | [], |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 41 | !strconcat(prefix, "call_indirect\t$dst"), |
| 42 | 0x11>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 43 | } |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 44 | |
| 45 | multiclass SIMD_CALL<ValueType vt, string prefix> { |
| 46 | def CALL_#vt : SIMD_I<(outs V128:$dst), (ins i32imm:$callee, variable_ops), |
| 47 | [(set (vt V128:$dst), |
| 48 | (WebAssemblycall1 (i32 imm:$callee)))], |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 49 | !strconcat(prefix, "call\t$dst, $callee"), |
| 50 | 0x10>; |
Derek Schuff | 6f69783 | 2016-10-21 16:38:07 +0000 | [diff] [blame] | 51 | let isCodeGenOnly = 1 in { |
| 52 | def PCALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst), |
| 53 | (ins I32:$callee, variable_ops), |
| 54 | [(set (vt V128:$dst), |
| 55 | (WebAssemblycall1 I32:$callee))], |
| 56 | "PSEUDO CALL INDIRECT\t$callee">; |
| 57 | } // isCodeGenOnly = 1 |
Dan Gohman | f50d964 | 2016-10-25 16:55:52 +0000 | [diff] [blame] | 58 | |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 59 | def CALL_INDIRECT_#vt : SIMD_I<(outs V128:$dst), |
Dan Gohman | f50d964 | 2016-10-25 16:55:52 +0000 | [diff] [blame] | 60 | (ins i32imm:$flags, variable_ops), |
Derek Schuff | 6f69783 | 2016-10-21 16:38:07 +0000 | [diff] [blame] | 61 | [], |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 62 | !strconcat(prefix, "call_indirect\t$dst"), |
| 63 | 0x11>; |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 64 | } |
| 65 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 66 | let Uses = [SP32, SP64], isCall = 1 in { |
Dan Gohman | c7c0445 | 2015-12-14 22:56:51 +0000 | [diff] [blame] | 67 | defm : CALL<I32, "i32.">; |
| 68 | defm : CALL<I64, "i64.">; |
| 69 | defm : CALL<F32, "f32.">; |
| 70 | defm : CALL<F64, "f64.">; |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 71 | defm : SIMD_CALL<v16i8, "i8x16.">; |
| 72 | defm : SIMD_CALL<v8i16, "i16x8.">; |
| 73 | defm : SIMD_CALL<v4i32, "i32x4.">; |
| 74 | defm : SIMD_CALL<v4f32, "f32x4.">; |
Dan Gohman | f71abef | 2015-09-09 16:13:47 +0000 | [diff] [blame] | 75 | |
Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 76 | def CALL_VOID : I<(outs), (ins i32imm:$callee, variable_ops), |
| 77 | [(WebAssemblycall0 (i32 imm:$callee))], |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 78 | "call \t$callee", 0x10>; |
Derek Schuff | 6f69783 | 2016-10-21 16:38:07 +0000 | [diff] [blame] | 79 | let isCodeGenOnly = 1 in { |
| 80 | def PCALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops), |
| 81 | [(WebAssemblycall0 I32:$callee)], |
| 82 | "PSEUDO CALL INDIRECT\t$callee">; |
| 83 | } // isCodeGenOnly = 1 |
Dan Gohman | f50d964 | 2016-10-25 16:55:52 +0000 | [diff] [blame] | 84 | |
| 85 | def CALL_INDIRECT_VOID : I<(outs), (ins i32imm:$flags, variable_ops), |
Derek Schuff | 6f69783 | 2016-10-21 16:38:07 +0000 | [diff] [blame] | 86 | [], |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 87 | "call_indirect\t", 0x11>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 88 | } // Uses = [SP32,SP64], isCall = 1 |
Dan Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 89 | |
| 90 | } // Defs = [ARGUMENTS] |
Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 91 | |
| 92 | // Patterns for matching a direct call to a global address. |
| 93 | def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 94 | (CALL_I32 tglobaladdr:$callee)>; |
| 95 | def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 96 | (CALL_I64 tglobaladdr:$callee)>; |
| 97 | def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 98 | (CALL_F32 tglobaladdr:$callee)>; |
| 99 | def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 100 | (CALL_F64 tglobaladdr:$callee)>; |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 101 | def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 102 | (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| 103 | def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 104 | (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| 105 | def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 106 | (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
| 107 | def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), |
| 108 | (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>; |
Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 109 | def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)), |
| 110 | (CALL_VOID tglobaladdr:$callee)>; |
| 111 | |
| 112 | // Patterns for matching a direct call to an external symbol. |
| 113 | def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 114 | (CALL_I32 texternalsym:$callee)>; |
| 115 | def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 116 | (CALL_I64 texternalsym:$callee)>; |
| 117 | def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 118 | (CALL_F32 texternalsym:$callee)>; |
| 119 | def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 120 | (CALL_F64 texternalsym:$callee)>; |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 121 | def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 122 | (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| 123 | def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 124 | (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| 125 | def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 126 | (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
| 127 | def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), |
| 128 | (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>; |
Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 129 | def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)), |
| 130 | (CALL_VOID texternalsym:$callee)>; |