WebAssemblyInstrInfo.td revision 321369
1285163Sdim// WebAssemblyInstrInfo.td-Describe the WebAssembly Instructions-*- tablegen -*- 2285163Sdim// 3285163Sdim// The LLVM Compiler Infrastructure 4285163Sdim// 5285163Sdim// This file is distributed under the University of Illinois Open Source 6285163Sdim// License. See LICENSE.TXT for details. 7285163Sdim// 8285163Sdim//===----------------------------------------------------------------------===// 9286684Sdim/// 10286684Sdim/// \file 11286684Sdim/// \brief WebAssembly Instruction definitions. 12286684Sdim/// 13285163Sdim//===----------------------------------------------------------------------===// 14285163Sdim 15285163Sdim//===----------------------------------------------------------------------===// 16285163Sdim// WebAssembly Instruction Predicate Definitions. 17285163Sdim//===----------------------------------------------------------------------===// 18285163Sdim 19285163Sdimdef HasAddr32 : Predicate<"!Subtarget->hasAddr64()">; 20285163Sdimdef HasAddr64 : Predicate<"Subtarget->hasAddr64()">; 21285163Sdimdef HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">, 22285163Sdim AssemblerPredicate<"FeatureSIMD128", "simd128">; 23285163Sdim 24285163Sdim//===----------------------------------------------------------------------===// 25285163Sdim// WebAssembly-specific DAG Node Types. 26285163Sdim//===----------------------------------------------------------------------===// 27285163Sdim 28321369Sdimdef SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>, 29321369Sdim SDTCisVT<1, iPTR>]>; 30296417Sdimdef SDT_WebAssemblyCallSeqEnd : 31296417Sdim SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>; 32296417Sdimdef SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; 33296417Sdimdef SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>; 34309124Sdimdef SDT_WebAssemblyBrTable : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; 35296417Sdimdef SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>; 36296417Sdimdef SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>; 37296417Sdimdef SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, 38296417Sdim SDTCisPtrTy<0>]>; 39296417Sdim 40285163Sdim//===----------------------------------------------------------------------===// 41285163Sdim// WebAssembly-specific DAG Nodes. 42285163Sdim//===----------------------------------------------------------------------===// 43285163Sdim 44296417Sdimdef WebAssemblycallseq_start : 45296417Sdim SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart, 46296417Sdim [SDNPHasChain, SDNPOutGlue]>; 47296417Sdimdef WebAssemblycallseq_end : 48296417Sdim SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd, 49296417Sdim [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; 50296417Sdimdef WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0", 51296417Sdim SDT_WebAssemblyCall0, 52296417Sdim [SDNPHasChain, SDNPVariadic]>; 53296417Sdimdef WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1", 54296417Sdim SDT_WebAssemblyCall1, 55296417Sdim [SDNPHasChain, SDNPVariadic]>; 56309124Sdimdef WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE", 57309124Sdim SDT_WebAssemblyBrTable, 58309124Sdim [SDNPHasChain, SDNPVariadic]>; 59296417Sdimdef WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT", 60296417Sdim SDT_WebAssemblyArgument>; 61296417Sdimdef WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN", 62296417Sdim SDT_WebAssemblyReturn, [SDNPHasChain]>; 63296417Sdimdef WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper", 64296417Sdim SDT_WebAssemblyWrapper>; 65296417Sdim 66285163Sdim//===----------------------------------------------------------------------===// 67285163Sdim// WebAssembly-specific Operands. 68285163Sdim//===----------------------------------------------------------------------===// 69285163Sdim 70296417Sdimlet OperandNamespace = "WebAssembly" in { 71286684Sdim 72296417Sdimlet OperandType = "OPERAND_BASIC_BLOCK" in 73296417Sdimdef bb_op : Operand<OtherVT>; 74296417Sdim 75314564Sdimlet OperandType = "OPERAND_LOCAL" in 76314564Sdimdef local_op : Operand<i32>; 77314564Sdim 78321369Sdimlet OperandType = "OPERAND_GLOBAL" in 79321369Sdimdef global_op : Operand<i32>; 80321369Sdim 81314564Sdimlet OperandType = "OPERAND_I32IMM" in 82314564Sdimdef i32imm_op : Operand<i32>; 83314564Sdim 84314564Sdimlet OperandType = "OPERAND_I64IMM" in 85314564Sdimdef i64imm_op : Operand<i64>; 86314564Sdim 87314564Sdimlet OperandType = "OPERAND_F32IMM" in 88296417Sdimdef f32imm_op : Operand<f32>; 89309124Sdim 90314564Sdimlet OperandType = "OPERAND_F64IMM" in 91296417Sdimdef f64imm_op : Operand<f64>; 92296417Sdim 93314564Sdimlet OperandType = "OPERAND_FUNCTION32" in 94314564Sdimdef function32_op : Operand<i32>; 95314564Sdim 96314564Sdimlet OperandType = "OPERAND_OFFSET32" in 97314564Sdimdef offset32_op : Operand<i32>; 98314564Sdim 99309124Sdimlet OperandType = "OPERAND_P2ALIGN" in { 100309124Sdimdef P2Align : Operand<i32> { 101309124Sdim let PrintMethod = "printWebAssemblyP2AlignOperand"; 102309124Sdim} 103309124Sdim} // OperandType = "OPERAND_P2ALIGN" 104309124Sdim 105314564Sdimlet OperandType = "OPERAND_SIGNATURE" in { 106314564Sdimdef Signature : Operand<i32> { 107314564Sdim let PrintMethod = "printWebAssemblySignatureOperand"; 108314564Sdim} 109314564Sdim} // OperandType = "OPERAND_SIGNATURE" 110314564Sdim 111321369Sdimlet OperandType = "OPERAND_TYPEINDEX" in 112321369Sdimdef TypeIndex : Operand<i32>; 113321369Sdim 114296417Sdim} // OperandNamespace = "WebAssembly" 115296417Sdim 116285163Sdim//===----------------------------------------------------------------------===// 117285163Sdim// WebAssembly Instruction Format Definitions. 118285163Sdim//===----------------------------------------------------------------------===// 119285163Sdim 120285163Sdiminclude "WebAssemblyInstrFormats.td" 121285163Sdim 122285163Sdim//===----------------------------------------------------------------------===// 123296417Sdim// Additional instructions. 124296417Sdim//===----------------------------------------------------------------------===// 125296417Sdim 126296417Sdimmulticlass ARGUMENT<WebAssemblyRegClass vt> { 127296417Sdim let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in 128296417Sdim def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno), 129296417Sdim [(set vt:$res, (WebAssemblyargument timm:$argno))]>; 130296417Sdim} 131314564Sdimmulticlass SIMD_ARGUMENT<ValueType vt> { 132314564Sdim let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in 133314564Sdim def ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno), 134314564Sdim [(set (vt V128:$res), 135314564Sdim (WebAssemblyargument timm:$argno))]>; 136314564Sdim} 137296417Sdimdefm : ARGUMENT<I32>; 138296417Sdimdefm : ARGUMENT<I64>; 139296417Sdimdefm : ARGUMENT<F32>; 140296417Sdimdefm : ARGUMENT<F64>; 141314564Sdimdefm : SIMD_ARGUMENT<v16i8>; 142314564Sdimdefm : SIMD_ARGUMENT<v8i16>; 143314564Sdimdefm : SIMD_ARGUMENT<v4i32>; 144314564Sdimdefm : SIMD_ARGUMENT<v4f32>; 145296417Sdim 146296417Sdimlet Defs = [ARGUMENTS] in { 147296417Sdim 148296417Sdim// get_local and set_local are not generated by instruction selection; they 149309124Sdim// are implied by virtual register uses and defs. 150296417Sdimmulticlass LOCAL<WebAssemblyRegClass vt> { 151309124Sdimlet hasSideEffects = 0 in { 152314564Sdim // COPY is not an actual instruction in wasm, but since we allow get_local and 153314564Sdim // set_local to be implicit during most of codegen, we can have a COPY which 154314564Sdim // is actually a no-op because all the work is done in the implied get_local 155314564Sdim // and set_local. COPYs are eliminated (and replaced with 156314564Sdim // get_local/set_local) in the ExplicitLocals pass. 157314564Sdim let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in 158314564Sdim def COPY_#vt : I<(outs vt:$res), (ins vt:$src), [], "copy_local\t$res, $src">; 159309124Sdim 160314564Sdim // TEE is similar to COPY, but writes two copies of its result. Typically 161314564Sdim // this would be used to stackify one result and write the other result to a 162314564Sdim // local. 163314564Sdim let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in 164314564Sdim def TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), [], 165314564Sdim "tee_local\t$res, $also, $src">; 166314564Sdim 167314564Sdim // This is the actual get_local instruction in wasm. These are made explicit 168314564Sdim // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm 169314564Sdim // local, which is a side effect not otherwise modeled in LLVM. 170314564Sdim let mayLoad = 1, isAsCheapAsAMove = 1 in 171314564Sdim def GET_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local), [], 172314564Sdim "get_local\t$res, $local", 0x20>; 173314564Sdim 174314564Sdim // This is the actual set_local instruction in wasm. These are made explicit 175314564Sdim // by the ExplicitLocals pass. It has mayStore because it writes to a wasm 176314564Sdim // local, which is a side effect not otherwise modeled in LLVM. 177314564Sdim let mayStore = 1, isAsCheapAsAMove = 1 in 178314564Sdim def SET_LOCAL_#vt : I<(outs), (ins local_op:$local, vt:$src), [], 179314564Sdim "set_local\t$local, $src", 0x21>; 180314564Sdim 181314564Sdim // This is the actual tee_local instruction in wasm. TEEs are turned into 182314564Sdim // TEE_LOCALs by the ExplicitLocals pass. It has mayStore for the same reason 183314564Sdim // as SET_LOCAL. 184314564Sdim let mayStore = 1, isAsCheapAsAMove = 1 in 185314564Sdim def TEE_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src), [], 186314564Sdim "tee_local\t$res, $local, $src", 0x22>; 187314564Sdim 188321369Sdim // Unused values must be dropped in some contexts. 189321369Sdim def DROP_#vt : I<(outs), (ins vt:$src), [], 190321369Sdim "drop\t$src", 0x1a>; 191321369Sdim 192321369Sdim let mayLoad = 1 in 193321369Sdim def GET_GLOBAL_#vt : I<(outs vt:$res), (ins global_op:$local), [], 194321369Sdim "get_global\t$res, $local", 0x23>; 195321369Sdim 196321369Sdim let mayStore = 1 in 197321369Sdim def SET_GLOBAL_#vt : I<(outs), (ins global_op:$local, vt:$src), [], 198321369Sdim "set_global\t$local, $src", 0x24>; 199321369Sdim 200309124Sdim} // hasSideEffects = 0 201296417Sdim} 202296417Sdimdefm : LOCAL<I32>; 203296417Sdimdefm : LOCAL<I64>; 204296417Sdimdefm : LOCAL<F32>; 205296417Sdimdefm : LOCAL<F64>; 206314564Sdimdefm : LOCAL<V128>, Requires<[HasSIMD128]>; 207296417Sdim 208309124Sdimlet isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in { 209314564Sdimdef CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm), 210296417Sdim [(set I32:$res, imm:$imm)], 211314564Sdim "i32.const\t$res, $imm", 0x41>; 212314564Sdimdef CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm), 213296417Sdim [(set I64:$res, imm:$imm)], 214314564Sdim "i64.const\t$res, $imm", 0x42>; 215296417Sdimdef CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm), 216296417Sdim [(set F32:$res, fpimm:$imm)], 217314564Sdim "f32.const\t$res, $imm", 0x43>; 218296417Sdimdef CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm), 219296417Sdim [(set F64:$res, fpimm:$imm)], 220314564Sdim "f64.const\t$res, $imm", 0x44>; 221309124Sdim} // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 222296417Sdim 223296417Sdim} // Defs = [ARGUMENTS] 224296417Sdim 225296417Sdimdef : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)), 226296417Sdim (CONST_I32 tglobaladdr:$addr)>; 227296417Sdimdef : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)), 228296417Sdim (CONST_I32 texternalsym:$addr)>; 229296417Sdim 230296417Sdim//===----------------------------------------------------------------------===// 231285163Sdim// Additional sets of instructions. 232285163Sdim//===----------------------------------------------------------------------===// 233285163Sdim 234286684Sdiminclude "WebAssemblyInstrMemory.td" 235286684Sdiminclude "WebAssemblyInstrCall.td" 236296417Sdiminclude "WebAssemblyInstrControl.td" 237286684Sdiminclude "WebAssemblyInstrInteger.td" 238296417Sdiminclude "WebAssemblyInstrConv.td" 239286684Sdiminclude "WebAssemblyInstrFloat.td" 240285163Sdiminclude "WebAssemblyInstrAtomics.td" 241285163Sdiminclude "WebAssemblyInstrSIMD.td" 242