WebAssemblyInstrControl.td revision 314564
1//===- WebAssemblyInstrControl.td-WebAssembly control-flow ------*- 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 control-flow code-gen constructs. 12/// 13//===----------------------------------------------------------------------===// 14 15let Defs = [ARGUMENTS] in { 16 17let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in { 18// The condition operand is a boolean value which WebAssembly represents as i32. 19def BR_IF : I<(outs), (ins bb_op:$dst, I32:$cond), 20 [(brcond I32:$cond, bb:$dst)], 21 "br_if \t$dst, $cond", 0x0d>; 22let isCodeGenOnly = 1 in 23def BR_UNLESS : I<(outs), (ins bb_op:$dst, I32:$cond), []>; 24let isBarrier = 1 in { 25def BR : I<(outs), (ins bb_op:$dst), 26 [(br bb:$dst)], 27 "br \t$dst", 0x0c>; 28} // isBarrier = 1 29} // isBranch = 1, isTerminator = 1, hasCtrlDep = 1 30 31} // Defs = [ARGUMENTS] 32 33def : Pat<(brcond (i32 (setne I32:$cond, 0)), bb:$dst), 34 (BR_IF bb_op:$dst, I32:$cond)>; 35def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst), 36 (BR_UNLESS bb_op:$dst, I32:$cond)>; 37 38let Defs = [ARGUMENTS] in { 39 40// TODO: SelectionDAG's lowering insists on using a pointer as the index for 41// jump tables, so in practice we don't ever use BR_TABLE_I64 in wasm32 mode 42// currently. 43// Set TSFlags{0} to 1 to indicate that the variable_ops are immediates. 44// Set TSFlags{1} to 1 to indicate that the immediates represent labels. 45let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { 46def BR_TABLE_I32 : I<(outs), (ins I32:$index, variable_ops), 47 [(WebAssemblybr_table I32:$index)], 48 "br_table \t$index", 0x0e> { 49 let TSFlags{0} = 1; 50 let TSFlags{1} = 1; 51} 52def BR_TABLE_I64 : I<(outs), (ins I64:$index, variable_ops), 53 [(WebAssemblybr_table I64:$index)], 54 "br_table \t$index"> { 55 let TSFlags{0} = 1; 56 let TSFlags{1} = 1; 57} 58} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 59 60// Placemarkers to indicate the start or end of a block or loop scope. These 61// use/clobber VALUE_STACK to prevent them from being moved into the middle of 62// an expression tree. 63let Uses = [VALUE_STACK], Defs = [VALUE_STACK] in { 64def BLOCK : I<(outs), (ins Signature:$sig), [], "block \t$sig", 0x02>; 65def LOOP : I<(outs), (ins Signature:$sig), [], "loop \t$sig", 0x03>; 66 67// END_BLOCK and END_LOOP are represented with the same opcode in wasm. 68def END_BLOCK : I<(outs), (ins), [], "end_block", 0x0b>; 69def END_LOOP : I<(outs), (ins), [], "end_loop", 0x0b>; 70} // Uses = [VALUE_STACK], Defs = [VALUE_STACK] 71 72multiclass RETURN<WebAssemblyRegClass vt> { 73 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)], 74 "return \t$val", 0x0f>; 75 // Equivalent to RETURN_#vt, for use at the end of a function when wasm 76 // semantics return by falling off the end of the block. 77 let isCodeGenOnly = 1 in 78 def FALLTHROUGH_RETURN_#vt : I<(outs), (ins vt:$val), []>; 79} 80 81multiclass SIMD_RETURN<ValueType vt> { 82 def RETURN_#vt : SIMD_I<(outs), (ins V128:$val), 83 [(WebAssemblyreturn (vt V128:$val))], 84 "return \t$val", 0x0f>; 85 // Equivalent to RETURN_#vt, for use at the end of a function when wasm 86 // semantics return by falling off the end of the block. 87 let isCodeGenOnly = 1 in 88 def FALLTHROUGH_RETURN_#vt : SIMD_I<(outs), (ins V128:$val), []>; 89} 90 91let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { 92 93let isReturn = 1 in { 94 defm : RETURN<I32>; 95 defm : RETURN<I64>; 96 defm : RETURN<F32>; 97 defm : RETURN<F64>; 98 defm : SIMD_RETURN<v16i8>; 99 defm : SIMD_RETURN<v8i16>; 100 defm : SIMD_RETURN<v4i32>; 101 defm : SIMD_RETURN<v4f32>; 102 103 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return", 0x0f>; 104 105 // This is to RETURN_VOID what FALLTHROUGH_RETURN_#vt is to RETURN_#vt. 106 let isCodeGenOnly = 1 in 107 def FALLTHROUGH_RETURN_VOID : I<(outs), (ins), []>; 108} // isReturn = 1 109 110def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable", 0x00>; 111 112} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 113 114} // Defs = [ARGUMENTS] 115