| 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 | c7c0445 | 2015-12-14 22:56:51 +0000 | [diff] [blame] | 31 | !strconcat(prefix, "call\t$dst, $callee")>; | 
| Dan Gohman | 05a17aa | 2015-09-28 16:22:39 +0000 | [diff] [blame] | 32 | def CALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops), | 
| Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 33 | [(set vt:$dst, (WebAssemblycall1 I32:$callee))], | 
| Dan Gohman | c7c0445 | 2015-12-14 22:56:51 +0000 | [diff] [blame] | 34 | !strconcat(prefix, "call_indirect\t$dst, $callee")>; | 
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 35 | } | 
|  | 36 | let Uses = [SP32, SP64], isCall = 1 in { | 
| Dan Gohman | c7c0445 | 2015-12-14 22:56:51 +0000 | [diff] [blame] | 37 | defm : CALL<I32, "i32.">; | 
|  | 38 | defm : CALL<I64, "i64.">; | 
|  | 39 | defm : CALL<F32, "f32.">; | 
|  | 40 | defm : CALL<F64, "f64.">; | 
| Dan Gohman | f71abef | 2015-09-09 16:13:47 +0000 | [diff] [blame] | 41 |  | 
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 42 | def CALL_VOID : I<(outs), (ins i32imm:$callee, variable_ops), | 
|  | 43 | [(WebAssemblycall0 (i32 imm:$callee))], | 
| Dan Gohman | 94ef41f | 2015-11-18 17:05:35 +0000 | [diff] [blame] | 44 | "call    \t$callee">; | 
| Dan Gohman | 05a17aa | 2015-09-28 16:22:39 +0000 | [diff] [blame] | 45 | def CALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops), | 
| Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 46 | [(WebAssemblycall0 I32:$callee)], | 
| Dan Gohman | 1031d4a | 2015-11-15 15:34:19 +0000 | [diff] [blame] | 47 | "call_indirect\t$callee">; | 
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 48 | } // Uses = [SP32,SP64], isCall = 1 | 
| Dan Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 49 |  | 
|  | 50 | } // Defs = [ARGUMENTS] | 
| Dan Gohman | e2a7a82 | 2015-12-05 20:41:36 +0000 | [diff] [blame] | 51 |  | 
|  | 52 | // Patterns for matching a direct call to a global address. | 
|  | 53 | def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), | 
|  | 54 | (CALL_I32 tglobaladdr:$callee)>; | 
|  | 55 | def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), | 
|  | 56 | (CALL_I64 tglobaladdr:$callee)>; | 
|  | 57 | def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), | 
|  | 58 | (CALL_F32 tglobaladdr:$callee)>; | 
|  | 59 | def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))), | 
|  | 60 | (CALL_F64 tglobaladdr:$callee)>; | 
|  | 61 | def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)), | 
|  | 62 | (CALL_VOID tglobaladdr:$callee)>; | 
|  | 63 |  | 
|  | 64 | // Patterns for matching a direct call to an external symbol. | 
|  | 65 | def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), | 
|  | 66 | (CALL_I32 texternalsym:$callee)>; | 
|  | 67 | def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), | 
|  | 68 | (CALL_I64 texternalsym:$callee)>; | 
|  | 69 | def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), | 
|  | 70 | (CALL_F32 texternalsym:$callee)>; | 
|  | 71 | def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))), | 
|  | 72 | (CALL_F64 texternalsym:$callee)>; | 
|  | 73 | def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)), | 
|  | 74 | (CALL_VOID texternalsym:$callee)>; |