1//===- TargetGlobalISel.td - Common code for GlobalISel ----*- tablegen -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file defines the target-independent interfaces used to support 10// SelectionDAG instruction selection patterns (specified in 11// TargetSelectionDAG.td) when generating GlobalISel instruction selectors. 12// 13// This is intended as a compatibility layer, to enable reuse of target 14// descriptions written for SelectionDAG without requiring explicit GlobalISel 15// support. It will eventually supersede SelectionDAG patterns. 16// 17//===----------------------------------------------------------------------===// 18 19// Declare that a generic Instruction is 'equivalent' to an SDNode, that is, 20// SelectionDAG patterns involving the SDNode can be transformed to match the 21// Instruction instead. 22class GINodeEquiv<Instruction i, SDNode node> { 23 Instruction I = i; 24 SDNode Node = node; 25 26 // SelectionDAG has separate nodes for atomic and non-atomic memory operations 27 // (ISD::LOAD, ISD::ATOMIC_LOAD, ISD::STORE, ISD::ATOMIC_STORE) but GlobalISel 28 // stores this information in the MachineMemoryOperand. 29 bit CheckMMOIsNonAtomic = 0; 30 bit CheckMMOIsAtomic = 0; 31 32 // SelectionDAG has one node for all loads and uses predicates to 33 // differentiate them. GlobalISel on the other hand uses separate opcodes. 34 // When this is true, the resulting opcode is G_LOAD/G_SEXTLOAD/G_ZEXTLOAD 35 // depending on the predicates on the node. 36 Instruction IfSignExtend = ?; 37 Instruction IfZeroExtend = ?; 38 39 // SelectionDAG has one setcc for all compares. This differentiates 40 // for G_ICMP and G_FCMP. 41 Instruction IfFloatingPoint = ?; 42} 43 44// These are defined in the same order as the G_* instructions. 45def : GINodeEquiv<G_ANYEXT, anyext>; 46def : GINodeEquiv<G_SEXT, sext>; 47def : GINodeEquiv<G_ZEXT, zext>; 48def : GINodeEquiv<G_TRUNC, trunc>; 49def : GINodeEquiv<G_BITCAST, bitconvert>; 50// G_INTTOPTR - SelectionDAG has no equivalent. 51// G_PTRTOINT - SelectionDAG has no equivalent. 52def : GINodeEquiv<G_CONSTANT, imm>; 53def : GINodeEquiv<G_FCONSTANT, fpimm>; 54def : GINodeEquiv<G_IMPLICIT_DEF, undef>; 55def : GINodeEquiv<G_ADD, add>; 56def : GINodeEquiv<G_SUB, sub>; 57def : GINodeEquiv<G_MUL, mul>; 58def : GINodeEquiv<G_UMULH, mulhu>; 59def : GINodeEquiv<G_SMULH, mulhs>; 60def : GINodeEquiv<G_SDIV, sdiv>; 61def : GINodeEquiv<G_UDIV, udiv>; 62def : GINodeEquiv<G_SREM, srem>; 63def : GINodeEquiv<G_UREM, urem>; 64def : GINodeEquiv<G_AND, and>; 65def : GINodeEquiv<G_OR, or>; 66def : GINodeEquiv<G_XOR, xor>; 67def : GINodeEquiv<G_SHL, shl>; 68def : GINodeEquiv<G_LSHR, srl>; 69def : GINodeEquiv<G_ASHR, sra>; 70def : GINodeEquiv<G_SADDSAT, saddsat>; 71def : GINodeEquiv<G_UADDSAT, uaddsat>; 72def : GINodeEquiv<G_SSUBSAT, ssubsat>; 73def : GINodeEquiv<G_USUBSAT, usubsat>; 74def : GINodeEquiv<G_SELECT, select>; 75def : GINodeEquiv<G_FNEG, fneg>; 76def : GINodeEquiv<G_FPEXT, fpextend>; 77def : GINodeEquiv<G_FPTRUNC, fpround>; 78def : GINodeEquiv<G_FPTOSI, fp_to_sint>; 79def : GINodeEquiv<G_FPTOUI, fp_to_uint>; 80def : GINodeEquiv<G_SITOFP, sint_to_fp>; 81def : GINodeEquiv<G_UITOFP, uint_to_fp>; 82def : GINodeEquiv<G_FADD, fadd>; 83def : GINodeEquiv<G_FSUB, fsub>; 84def : GINodeEquiv<G_FMA, fma>; 85def : GINodeEquiv<G_FMAD, fmad>; 86def : GINodeEquiv<G_FMUL, fmul>; 87def : GINodeEquiv<G_FDIV, fdiv>; 88def : GINodeEquiv<G_FREM, frem>; 89def : GINodeEquiv<G_FPOW, fpow>; 90def : GINodeEquiv<G_FEXP2, fexp2>; 91def : GINodeEquiv<G_FLOG2, flog2>; 92def : GINodeEquiv<G_FCANONICALIZE, fcanonicalize>; 93def : GINodeEquiv<G_INTRINSIC, intrinsic_wo_chain>; 94// ISD::INTRINSIC_VOID can also be handled with G_INTRINSIC_W_SIDE_EFFECTS. 95def : GINodeEquiv<G_INTRINSIC_W_SIDE_EFFECTS, intrinsic_void>; 96def : GINodeEquiv<G_INTRINSIC_W_SIDE_EFFECTS, intrinsic_w_chain>; 97def : GINodeEquiv<G_BR, br>; 98def : GINodeEquiv<G_BSWAP, bswap>; 99def : GINodeEquiv<G_BITREVERSE, bitreverse>; 100def : GINodeEquiv<G_FSHL, fshl>; 101def : GINodeEquiv<G_FSHR, fshr>; 102def : GINodeEquiv<G_CTLZ, ctlz>; 103def : GINodeEquiv<G_CTTZ, cttz>; 104def : GINodeEquiv<G_CTLZ_ZERO_UNDEF, ctlz_zero_undef>; 105def : GINodeEquiv<G_CTTZ_ZERO_UNDEF, cttz_zero_undef>; 106def : GINodeEquiv<G_CTPOP, ctpop>; 107def : GINodeEquiv<G_EXTRACT_VECTOR_ELT, vector_extract>; 108def : GINodeEquiv<G_CONCAT_VECTORS, concat_vectors>; 109def : GINodeEquiv<G_BUILD_VECTOR, build_vector>; 110def : GINodeEquiv<G_FCEIL, fceil>; 111def : GINodeEquiv<G_FCOS, fcos>; 112def : GINodeEquiv<G_FSIN, fsin>; 113def : GINodeEquiv<G_FABS, fabs>; 114def : GINodeEquiv<G_FSQRT, fsqrt>; 115def : GINodeEquiv<G_FFLOOR, ffloor>; 116def : GINodeEquiv<G_FRINT, frint>; 117def : GINodeEquiv<G_FNEARBYINT, fnearbyint>; 118def : GINodeEquiv<G_INTRINSIC_TRUNC, ftrunc>; 119def : GINodeEquiv<G_INTRINSIC_ROUND, fround>; 120def : GINodeEquiv<G_FCOPYSIGN, fcopysign>; 121def : GINodeEquiv<G_SMIN, smin>; 122def : GINodeEquiv<G_SMAX, smax>; 123def : GINodeEquiv<G_UMIN, umin>; 124def : GINodeEquiv<G_UMAX, umax>; 125def : GINodeEquiv<G_FMINNUM, fminnum>; 126def : GINodeEquiv<G_FMAXNUM, fmaxnum>; 127def : GINodeEquiv<G_FMINNUM_IEEE, fminnum_ieee>; 128def : GINodeEquiv<G_FMAXNUM_IEEE, fmaxnum_ieee>; 129def : GINodeEquiv<G_READCYCLECOUNTER, readcyclecounter>; 130 131def : GINodeEquiv<G_STRICT_FADD, strict_fadd>; 132def : GINodeEquiv<G_STRICT_FSUB, strict_fsub>; 133def : GINodeEquiv<G_STRICT_FMUL, strict_fmul>; 134def : GINodeEquiv<G_STRICT_FDIV, strict_fdiv>; 135def : GINodeEquiv<G_STRICT_FREM, strict_frem>; 136def : GINodeEquiv<G_STRICT_FMA, strict_fma>; 137def : GINodeEquiv<G_STRICT_FSQRT, strict_fsqrt>; 138 139// Broadly speaking G_LOAD is equivalent to ISD::LOAD but there are some 140// complications that tablegen must take care of. For example, Predicates such 141// as isSignExtLoad require that this is not a perfect 1:1 mapping since a 142// sign-extending load is (G_SEXTLOAD x) in GlobalISel. Additionally, 143// G_LOAD handles both atomic and non-atomic loads where as SelectionDAG had 144// separate nodes for them. This GINodeEquiv maps the non-atomic loads to 145// G_LOAD with a non-atomic MachineMemOperand. 146def : GINodeEquiv<G_LOAD, ld> { 147 let CheckMMOIsNonAtomic = 1; 148 let IfSignExtend = G_SEXTLOAD; 149 let IfZeroExtend = G_ZEXTLOAD; 150} 151 152def : GINodeEquiv<G_ICMP, setcc> { 153 let IfFloatingPoint = G_FCMP; 154} 155 156// Broadly speaking G_STORE is equivalent to ISD::STORE but there are some 157// complications that tablegen must take care of. For example, predicates such 158// as isTruncStore require that this is not a perfect 1:1 mapping since a 159// truncating store is (G_STORE (G_TRUNCATE x)) in GlobalISel. Additionally, 160// G_STORE handles both atomic and non-atomic stores where as SelectionDAG had 161// separate nodes for them. This GINodeEquiv maps the non-atomic stores to 162// G_STORE with a non-atomic MachineMemOperand. 163def : GINodeEquiv<G_STORE, st> { let CheckMMOIsNonAtomic = 1; } 164 165def : GINodeEquiv<G_LOAD, atomic_load> { 166 let CheckMMOIsNonAtomic = 0; 167 let CheckMMOIsAtomic = 1; 168} 169 170def : GINodeEquiv<G_ATOMIC_CMPXCHG, atomic_cmp_swap>; 171def : GINodeEquiv<G_ATOMICRMW_XCHG, atomic_swap>; 172def : GINodeEquiv<G_ATOMICRMW_ADD, atomic_load_add>; 173def : GINodeEquiv<G_ATOMICRMW_SUB, atomic_load_sub>; 174def : GINodeEquiv<G_ATOMICRMW_AND, atomic_load_and>; 175def : GINodeEquiv<G_ATOMICRMW_NAND, atomic_load_nand>; 176def : GINodeEquiv<G_ATOMICRMW_OR, atomic_load_or>; 177def : GINodeEquiv<G_ATOMICRMW_XOR, atomic_load_xor>; 178def : GINodeEquiv<G_ATOMICRMW_MIN, atomic_load_min>; 179def : GINodeEquiv<G_ATOMICRMW_MAX, atomic_load_max>; 180def : GINodeEquiv<G_ATOMICRMW_UMIN, atomic_load_umin>; 181def : GINodeEquiv<G_ATOMICRMW_UMAX, atomic_load_umax>; 182def : GINodeEquiv<G_ATOMICRMW_FADD, atomic_load_fadd>; 183def : GINodeEquiv<G_ATOMICRMW_FSUB, atomic_load_fsub>; 184def : GINodeEquiv<G_FENCE, atomic_fence>; 185 186// Specifies the GlobalISel equivalents for SelectionDAG's ComplexPattern. 187// Should be used on defs that subclass GIComplexOperandMatcher<>. 188class GIComplexPatternEquiv<ComplexPattern seldag> { 189 ComplexPattern SelDAGEquivalent = seldag; 190} 191 192// Specifies the GlobalISel equivalents for SelectionDAG's SDNodeXForm. 193// Should be used on defs that subclass GICustomOperandRenderer<>. 194class GISDNodeXFormEquiv<SDNodeXForm seldag> { 195 SDNodeXForm SelDAGEquivalent = seldag; 196} 197