Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | // WebAssemblyInstrInfo.td-Describe the WebAssembly Instructions-*- 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 | //===----------------------------------------------------------------------===// |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// \brief WebAssembly Instruction definitions. |
| 12 | /// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | // WebAssembly Instruction Predicate Definitions. |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
JF Bastien | 03855df | 2015-07-01 23:41:25 +0000 | [diff] [blame] | 19 | def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">; |
| 20 | def HasAddr64 : Predicate<"Subtarget->hasAddr64()">; |
| 21 | def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">, |
| 22 | AssemblerPredicate<"FeatureSIMD128", "simd128">; |
| 23 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 24 | //===----------------------------------------------------------------------===// |
| 25 | // WebAssembly-specific DAG Node Types. |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 28 | def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>]>; |
| 29 | def SDT_WebAssemblyCallSeqEnd : |
| 30 | SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>; |
Dan Gohman | f71abef | 2015-09-09 16:13:47 +0000 | [diff] [blame] | 31 | def SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; |
| 32 | def SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 33 | def SDT_WebAssemblySwitch : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 34 | def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>; |
JF Bastien | 4a2d560 | 2015-07-31 21:04:18 +0000 | [diff] [blame] | 35 | def SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 36 | def SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, |
| 37 | SDTCisPtrTy<0>]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 38 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 39 | //===----------------------------------------------------------------------===// |
| 40 | // WebAssembly-specific DAG Nodes. |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 43 | def WebAssemblycallseq_start : |
| 44 | SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart, |
| 45 | [SDNPHasChain, SDNPOutGlue]>; |
| 46 | def WebAssemblycallseq_end : |
| 47 | SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd, |
| 48 | [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; |
Dan Gohman | f71abef | 2015-09-09 16:13:47 +0000 | [diff] [blame] | 49 | def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0", |
| 50 | SDT_WebAssemblyCall0, |
| 51 | [SDNPHasChain, SDNPVariadic]>; |
| 52 | def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1", |
| 53 | SDT_WebAssemblyCall1, |
| 54 | [SDNPHasChain, SDNPVariadic]>; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 55 | def WebAssemblyswitch : SDNode<"WebAssemblyISD::SWITCH", |
| 56 | SDT_WebAssemblySwitch, |
| 57 | [SDNPHasChain, SDNPVariadic]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 58 | def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT", |
| 59 | SDT_WebAssemblyArgument>; |
| 60 | def WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN", |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 61 | SDT_WebAssemblyReturn, [SDNPHasChain]>; |
| 62 | def WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper", |
| 63 | SDT_WebAssemblyWrapper>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 64 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 65 | //===----------------------------------------------------------------------===// |
| 66 | // WebAssembly-specific Operands. |
| 67 | //===----------------------------------------------------------------------===// |
| 68 | |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 69 | /* |
| 70 | * TODO(jfb): Add the following. |
| 71 | * |
| 72 | * get_local: read the current value of a local variable |
| 73 | * set_local: set the current value of a local variable |
| 74 | */ |
| 75 | |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 76 | def bb_op : Operand<OtherVT>; |
| 77 | def tjumptable_op : Operand<iPTR>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 78 | def global : Operand<iPTR>; |
| 79 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 80 | //===----------------------------------------------------------------------===// |
| 81 | // WebAssembly Instruction Format Definitions. |
| 82 | //===----------------------------------------------------------------------===// |
| 83 | |
| 84 | include "WebAssemblyInstrFormats.td" |
| 85 | |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 86 | multiclass ARGUMENT<WebAssemblyRegClass vt> { |
| 87 | def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno), |
| 88 | [(set vt:$res, (WebAssemblyargument timm:$argno))]>; |
| 89 | } |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 90 | defm : ARGUMENT<I32>; |
| 91 | defm : ARGUMENT<I64>; |
| 92 | defm : ARGUMENT<F32>; |
| 93 | defm : ARGUMENT<F64>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 94 | |
JF Bastien | 4a64225 | 2015-08-10 22:36:48 +0000 | [diff] [blame] | 95 | |
Dan Gohman | da7f428 | 2015-11-05 20:44:29 +0000 | [diff] [blame^] | 96 | def Const_I32 : I<(outs I32:$res), (ins i32imm:$imm), |
| 97 | [(set I32:$res, imm:$imm)], |
| 98 | "i32.const $res, $imm">; |
| 99 | def Const_I64 : I<(outs I64:$res), (ins i64imm:$imm), |
| 100 | [(set I64:$res, imm:$imm)], |
| 101 | "i64.const $res, $imm">; |
| 102 | def Const_F32 : I<(outs F32:$res), (ins f32imm:$imm), |
| 103 | [(set F32:$res, fpimm:$imm)], |
| 104 | "f32.const $res, $imm">; |
| 105 | def Const_F64 : I<(outs F64:$res), (ins f64imm:$imm), |
| 106 | [(set F64:$res, fpimm:$imm)], |
| 107 | "f64.const $res, $imm">; |
JF Bastien | 4a64225 | 2015-08-10 22:36:48 +0000 | [diff] [blame] | 108 | |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 109 | // Special types of immediates. FIXME: Hard-coded as 32-bit for now. |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 110 | def GLOBAL : I<(outs I32:$dst), (ins global:$addr), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 111 | [(set I32:$dst, (WebAssemblywrapper tglobaladdr:$addr))], |
| 112 | "global $dst, $addr">; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 113 | def JUMP_TABLE : I<(outs I32:$dst), (ins tjumptable_op:$addr), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 114 | [(set I32:$dst, (WebAssemblywrapper tjumptable:$addr))], |
| 115 | "jump_table $dst, $addr">; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 116 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 117 | //===----------------------------------------------------------------------===// |
| 118 | // Additional sets of instructions. |
| 119 | //===----------------------------------------------------------------------===// |
| 120 | |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 121 | include "WebAssemblyInstrMemory.td" |
| 122 | include "WebAssemblyInstrCall.td" |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 123 | include "WebAssemblyInstrControl.td" |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 124 | include "WebAssemblyInstrInteger.td" |
| 125 | include "WebAssemblyInstrFloat.td" |
| 126 | include "WebAssemblyInstrConv.td" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 127 | include "WebAssemblyInstrAtomics.td" |
| 128 | include "WebAssemblyInstrSIMD.td" |