1 //===- TargetGlobalISel.td - Common code for GlobalISel ----*- 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 // This file defines the target-independent interfaces used to support 11 // SelectionDAG instruction selection patterns (specified in 12 // TargetSelectionDAG.td) when generating GlobalISel instruction selectors. 13 // 14 // This is intended as a compatibility layer, to enable reuse of target 15 // descriptions written for SelectionDAG without requiring explicit GlobalISel 16 // support. It will eventually supersede SelectionDAG patterns. 17 // 18 //===----------------------------------------------------------------------===// 19 20 // Declare that a generic Instruction is 'equivalent' to an SDNode, that is, 21 // SelectionDAG patterns involving the SDNode can be transformed to match the 22 // Instruction instead. 23 class GINodeEquiv<Instruction i, SDNode node> { 24 Instruction I = i; 25 SDNode Node = node; 26 27 // SelectionDAG has separate nodes for atomic and non-atomic memory operations 28 // (ISD::LOAD, ISD::ATOMIC_LOAD, ISD::STORE, ISD::ATOMIC_STORE) but GlobalISel 29 // stores this information in the MachineMemoryOperand. 30 bit CheckMMOIsNonAtomic = 0; 31 } 32 33 // These are defined in the same order as the G_* instructions. 34 def : GINodeEquiv<G_ANYEXT, anyext>; 35 def : GINodeEquiv<G_SEXT, sext>; 36 def : GINodeEquiv<G_ZEXT, zext>; 37 def : GINodeEquiv<G_TRUNC, trunc>; 38 def : GINodeEquiv<G_BITCAST, bitconvert>; 39 // G_INTTOPTR - SelectionDAG has no equivalent. 40 // G_PTRTOINT - SelectionDAG has no equivalent. 41 def : GINodeEquiv<G_CONSTANT, imm>; 42 def : GINodeEquiv<G_FCONSTANT, fpimm>; 43 def : GINodeEquiv<G_ADD, add>; 44 def : GINodeEquiv<G_SUB, sub>; 45 def : GINodeEquiv<G_MUL, mul>; 46 def : GINodeEquiv<G_SDIV, sdiv>; 47 def : GINodeEquiv<G_UDIV, udiv>; 48 def : GINodeEquiv<G_SREM, srem>; 49 def : GINodeEquiv<G_UREM, urem>; 50 def : GINodeEquiv<G_AND, and>; 51 def : GINodeEquiv<G_OR, or>; 52 def : GINodeEquiv<G_XOR, xor>; 53 def : GINodeEquiv<G_SHL, shl>; 54 def : GINodeEquiv<G_LSHR, srl>; 55 def : GINodeEquiv<G_ASHR, sra>; 56 def : GINodeEquiv<G_SELECT, select>; 57 def : GINodeEquiv<G_FNEG, fneg>; 58 def : GINodeEquiv<G_FPEXT, fpextend>; 59 def : GINodeEquiv<G_FPTRUNC, fpround>; 60 def : GINodeEquiv<G_FPTOSI, fp_to_sint>; 61 def : GINodeEquiv<G_FPTOUI, fp_to_uint>; 62 def : GINodeEquiv<G_SITOFP, sint_to_fp>; 63 def : GINodeEquiv<G_UITOFP, uint_to_fp>; 64 def : GINodeEquiv<G_FADD, fadd>; 65 def : GINodeEquiv<G_FSUB, fsub>; 66 def : GINodeEquiv<G_FMA, fma>; 67 def : GINodeEquiv<G_FMUL, fmul>; 68 def : GINodeEquiv<G_FDIV, fdiv>; 69 def : GINodeEquiv<G_FREM, frem>; 70 def : GINodeEquiv<G_FPOW, fpow>; 71 def : GINodeEquiv<G_FEXP2, fexp2>; 72 def : GINodeEquiv<G_FLOG2, flog2>; 73 def : GINodeEquiv<G_INTRINSIC, intrinsic_wo_chain>; 74 // ISD::INTRINSIC_VOID can also be handled with G_INTRINSIC_W_SIDE_EFFECTS. 75 def : GINodeEquiv<G_INTRINSIC_W_SIDE_EFFECTS, intrinsic_void>; 76 def : GINodeEquiv<G_INTRINSIC_W_SIDE_EFFECTS, intrinsic_w_chain>; 77 def : GINodeEquiv<G_BR, br>; 78 def : GINodeEquiv<G_BSWAP, bswap>; 79 80 // Broadly speaking G_LOAD is equivalent to ISD::LOAD but there are some 81 // complications that tablegen must take care of. For example, Predicates such 82 // as isSignExtLoad require that this is not a perfect 1:1 mapping since a 83 // sign-extending load is (G_SEXT (G_LOAD x)) in GlobalISel. Additionally, 84 // G_LOAD handles both atomic and non-atomic loads where as SelectionDAG had 85 // separate nodes for them. This GINodeEquiv maps the non-atomic loads to 86 // G_LOAD with a non-atomic MachineMemOperand. 87 def : GINodeEquiv<G_LOAD, ld> { let CheckMMOIsNonAtomic = 1; } 88 // Broadly speaking G_STORE is equivalent to ISD::STORE but there are some 89 // complications that tablegen must take care of. For example, predicates such 90 // as isTruncStore require that this is not a perfect 1:1 mapping since a 91 // truncating store is (G_STORE (G_TRUNCATE x)) in GlobalISel. Additionally, 92 // G_STORE handles both atomic and non-atomic stores where as SelectionDAG had 93 // separate nodes for them. This GINodeEquiv maps the non-atomic stores to 94 // G_STORE with a non-atomic MachineMemOperand. 95 def : GINodeEquiv<G_STORE, st> { let CheckMMOIsNonAtomic = 1; } 96 97 // Specifies the GlobalISel equivalents for SelectionDAG's ComplexPattern. 98 // Should be used on defs that subclass GIComplexOperandMatcher<>. 99 class GIComplexPatternEquiv<ComplexPattern seldag> { 100 ComplexPattern SelDAGEquivalent = seldag; 101 } 102