1 //===- TargetGlobalISel.td - Common code for GlobalISel ----*- tablegen -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
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.
17 //===----------------------------------------------------------------------===//
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.
22 class GINodeEquiv<Instruction i, SDNode node> {
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;
31 // SelectionDAG has one node for all loads and uses predicates to
32 // differentiate them. GlobalISel on the other hand uses separate opcodes.
33 // When this is true, the resulting opcode is G_LOAD/G_SEXTLOAD/G_ZEXTLOAD
34 // depending on the predicates on the node.
35 Instruction IfSignExtend = ?;
36 Instruction IfZeroExtend = ?;
38 // SelectionDAG has one setcc for all compares. This differentiates
39 // for G_ICMP and G_FCMP.
40 Instruction IfFloatingPoint = ?;
43 // These are defined in the same order as the G_* instructions.
44 def : GINodeEquiv<G_ANYEXT, anyext>;
45 def : GINodeEquiv<G_SEXT, sext>;
46 def : GINodeEquiv<G_ZEXT, zext>;
47 def : GINodeEquiv<G_TRUNC, trunc>;
48 def : GINodeEquiv<G_BITCAST, bitconvert>;
49 // G_INTTOPTR - SelectionDAG has no equivalent.
50 // G_PTRTOINT - SelectionDAG has no equivalent.
51 def : GINodeEquiv<G_CONSTANT, imm>;
52 def : GINodeEquiv<G_FCONSTANT, fpimm>;
53 def : GINodeEquiv<G_IMPLICIT_DEF, undef>;
54 def : GINodeEquiv<G_ADD, add>;
55 def : GINodeEquiv<G_SUB, sub>;
56 def : GINodeEquiv<G_MUL, mul>;
57 def : GINodeEquiv<G_UMULH, mulhu>;
58 def : GINodeEquiv<G_SMULH, mulhs>;
59 def : GINodeEquiv<G_SDIV, sdiv>;
60 def : GINodeEquiv<G_UDIV, udiv>;
61 def : GINodeEquiv<G_SREM, srem>;
62 def : GINodeEquiv<G_UREM, urem>;
63 def : GINodeEquiv<G_AND, and>;
64 def : GINodeEquiv<G_OR, or>;
65 def : GINodeEquiv<G_XOR, xor>;
66 def : GINodeEquiv<G_SHL, shl>;
67 def : GINodeEquiv<G_LSHR, srl>;
68 def : GINodeEquiv<G_ASHR, sra>;
69 def : GINodeEquiv<G_SELECT, select>;
70 def : GINodeEquiv<G_FNEG, fneg>;
71 def : GINodeEquiv<G_FPEXT, fpextend>;
72 def : GINodeEquiv<G_FPTRUNC, fpround>;
73 def : GINodeEquiv<G_FPTOSI, fp_to_sint>;
74 def : GINodeEquiv<G_FPTOUI, fp_to_uint>;
75 def : GINodeEquiv<G_SITOFP, sint_to_fp>;
76 def : GINodeEquiv<G_UITOFP, uint_to_fp>;
77 def : GINodeEquiv<G_FADD, fadd>;
78 def : GINodeEquiv<G_FSUB, fsub>;
79 def : GINodeEquiv<G_FMA, fma>;
80 def : GINodeEquiv<G_FMUL, fmul>;
81 def : GINodeEquiv<G_FDIV, fdiv>;
82 def : GINodeEquiv<G_FREM, frem>;
83 def : GINodeEquiv<G_FPOW, fpow>;
84 def : GINodeEquiv<G_FEXP2, fexp2>;
85 def : GINodeEquiv<G_FLOG2, flog2>;
86 def : GINodeEquiv<G_FCANONICALIZE, fcanonicalize>;
87 def : GINodeEquiv<G_INTRINSIC, intrinsic_wo_chain>;
88 // ISD::INTRINSIC_VOID can also be handled with G_INTRINSIC_W_SIDE_EFFECTS.
89 def : GINodeEquiv<G_INTRINSIC_W_SIDE_EFFECTS, intrinsic_void>;
90 def : GINodeEquiv<G_INTRINSIC_W_SIDE_EFFECTS, intrinsic_w_chain>;
91 def : GINodeEquiv<G_BR, br>;
92 def : GINodeEquiv<G_BSWAP, bswap>;
93 def : GINodeEquiv<G_BITREVERSE, bitreverse>;
94 def : GINodeEquiv<G_CTLZ, ctlz>;
95 def : GINodeEquiv<G_CTTZ, cttz>;
96 def : GINodeEquiv<G_CTLZ_ZERO_UNDEF, ctlz_zero_undef>;
97 def : GINodeEquiv<G_CTTZ_ZERO_UNDEF, cttz_zero_undef>;
98 def : GINodeEquiv<G_CTPOP, ctpop>;
99 def : GINodeEquiv<G_EXTRACT_VECTOR_ELT, vector_extract>;
100 def : GINodeEquiv<G_CONCAT_VECTORS, concat_vectors>;
101 def : GINodeEquiv<G_FCEIL, fceil>;
102 def : GINodeEquiv<G_FCOS, fcos>;
103 def : GINodeEquiv<G_FSIN, fsin>;
104 def : GINodeEquiv<G_FABS, fabs>;
105 def : GINodeEquiv<G_FSQRT, fsqrt>;
106 def : GINodeEquiv<G_FFLOOR, ffloor>;
107 def : GINodeEquiv<G_FRINT, frint>;
108 def : GINodeEquiv<G_FNEARBYINT, fnearbyint>;
109 def : GINodeEquiv<G_FCOPYSIGN, fcopysign>;
110 def : GINodeEquiv<G_SMIN, smin>;
111 def : GINodeEquiv<G_SMAX, smax>;
112 def : GINodeEquiv<G_UMIN, umin>;
113 def : GINodeEquiv<G_UMAX, umax>;
114 def : GINodeEquiv<G_FMINNUM, fminnum>;
115 def : GINodeEquiv<G_FMAXNUM, fmaxnum>;
116 def : GINodeEquiv<G_FMINNUM_IEEE, fminnum_ieee>;
117 def : GINodeEquiv<G_FMAXNUM_IEEE, fmaxnum_ieee>;
119 // Broadly speaking G_LOAD is equivalent to ISD::LOAD but there are some
120 // complications that tablegen must take care of. For example, Predicates such
121 // as isSignExtLoad require that this is not a perfect 1:1 mapping since a
122 // sign-extending load is (G_SEXTLOAD x) in GlobalISel. Additionally,
123 // G_LOAD handles both atomic and non-atomic loads where as SelectionDAG had
124 // separate nodes for them. This GINodeEquiv maps the non-atomic loads to
125 // G_LOAD with a non-atomic MachineMemOperand.
126 def : GINodeEquiv<G_LOAD, ld> {
127 let CheckMMOIsNonAtomic = 1;
128 let IfSignExtend = G_SEXTLOAD;
129 let IfZeroExtend = G_ZEXTLOAD;
132 def : GINodeEquiv<G_ICMP, setcc> {
133 let IfFloatingPoint = G_FCMP;
136 // Broadly speaking G_STORE is equivalent to ISD::STORE but there are some
137 // complications that tablegen must take care of. For example, predicates such
138 // as isTruncStore require that this is not a perfect 1:1 mapping since a
139 // truncating store is (G_STORE (G_TRUNCATE x)) in GlobalISel. Additionally,
140 // G_STORE handles both atomic and non-atomic stores where as SelectionDAG had
141 // separate nodes for them. This GINodeEquiv maps the non-atomic stores to
142 // G_STORE with a non-atomic MachineMemOperand.
143 def : GINodeEquiv<G_STORE, st> { let CheckMMOIsNonAtomic = 1; }
145 def : GINodeEquiv<G_ATOMIC_CMPXCHG, atomic_cmp_swap>;
146 def : GINodeEquiv<G_ATOMICRMW_XCHG, atomic_swap>;
147 def : GINodeEquiv<G_ATOMICRMW_ADD, atomic_load_add>;
148 def : GINodeEquiv<G_ATOMICRMW_SUB, atomic_load_sub>;
149 def : GINodeEquiv<G_ATOMICRMW_AND, atomic_load_and>;
150 def : GINodeEquiv<G_ATOMICRMW_NAND, atomic_load_nand>;
151 def : GINodeEquiv<G_ATOMICRMW_OR, atomic_load_or>;
152 def : GINodeEquiv<G_ATOMICRMW_XOR, atomic_load_xor>;
153 def : GINodeEquiv<G_ATOMICRMW_MIN, atomic_load_min>;
154 def : GINodeEquiv<G_ATOMICRMW_MAX, atomic_load_max>;
155 def : GINodeEquiv<G_ATOMICRMW_UMIN, atomic_load_umin>;
156 def : GINodeEquiv<G_ATOMICRMW_UMAX, atomic_load_umax>;
157 def : GINodeEquiv<G_ATOMICRMW_FADD, atomic_load_fadd>;
158 def : GINodeEquiv<G_ATOMICRMW_FSUB, atomic_load_fsub>;
159 def : GINodeEquiv<G_FENCE, atomic_fence>;
161 // Specifies the GlobalISel equivalents for SelectionDAG's ComplexPattern.
162 // Should be used on defs that subclass GIComplexOperandMatcher<>.
163 class GIComplexPatternEquiv<ComplexPattern seldag> {
164 ComplexPattern SelDAGEquivalent = seldag;
167 // Specifies the GlobalISel equivalents for SelectionDAG's SDNodeXForm.
168 // Should be used on defs that subclass GICustomOperandRenderer<>.
169 class GISDNodeXFormEquiv<SDNodeXForm seldag> {
170 SDNodeXForm SelDAGEquivalent = seldag;