xref: /netbsd-src/external/apache2/llvm/dist/llvm/include/llvm/Target/TargetSelectionDAG.td (revision 82d56013d7b633d116a93943de88e08335357a7c)
1//===- TargetSelectionDAG.td - Common code for DAG isels ---*- 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 by SelectionDAG
10// instruction selection generators.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Selection DAG Type Constraint definitions.
16//
17// Note that the semantics of these constraints are hard coded into tblgen.  To
18// modify or add constraints, you have to hack tblgen.
19//
20
21class SDTypeConstraint<int opnum> {
22  int OperandNum = opnum;
23}
24
25// SDTCisVT - The specified operand has exactly this VT.
26class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
27  ValueType VT = vt;
28}
29
30class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
31
32// SDTCisInt - The specified operand has integer type.
33class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
34
35// SDTCisFP - The specified operand has floating-point type.
36class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
37
38// SDTCisVec - The specified operand has a vector type.
39class SDTCisVec<int OpNum> : SDTypeConstraint<OpNum>;
40
41// SDTCisSameAs - The two specified operands have identical types.
42class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
43  int OtherOperandNum = OtherOp;
44}
45
46// SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
47// smaller than the 'Other' operand.
48class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
49  int OtherOperandNum = OtherOp;
50}
51
52class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
53  int BigOperandNum = BigOp;
54}
55
56/// SDTCisEltOfVec - This indicates that ThisOp is a scalar type of the same
57/// type as the element type of OtherOp, which is a vector type.
58class SDTCisEltOfVec<int ThisOp, int OtherOp>
59  : SDTypeConstraint<ThisOp> {
60  int OtherOpNum = OtherOp;
61}
62
63/// SDTCisSubVecOfVec - This indicates that ThisOp is a vector type
64/// with length less that of OtherOp, which is a vector type.
65class SDTCisSubVecOfVec<int ThisOp, int OtherOp>
66  : SDTypeConstraint<ThisOp> {
67  int OtherOpNum = OtherOp;
68}
69
70// SDTCVecEltisVT - The specified operand is vector type with element type
71// of VT.
72class SDTCVecEltisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
73  ValueType VT = vt;
74}
75
76// SDTCisSameNumEltsAs - The two specified operands have identical number
77// of elements.
78class SDTCisSameNumEltsAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
79  int OtherOperandNum = OtherOp;
80}
81
82// SDTCisSameSizeAs - The two specified operands have identical size.
83class SDTCisSameSizeAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
84  int OtherOperandNum = OtherOp;
85}
86
87//===----------------------------------------------------------------------===//
88// Selection DAG Type Profile definitions.
89//
90// These use the constraints defined above to describe the type requirements of
91// the various nodes.  These are not hard coded into tblgen, allowing targets to
92// add their own if needed.
93//
94
95// SDTypeProfile - This profile describes the type requirements of a Selection
96// DAG node.
97class SDTypeProfile<int numresults, int numoperands,
98                    list<SDTypeConstraint> constraints> {
99  int NumResults = numresults;
100  int NumOperands = numoperands;
101  list<SDTypeConstraint> Constraints = constraints;
102}
103
104// Builtin profiles.
105def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>;         // for 'imm'.
106def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>;          // for 'fpimm'.
107def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;       // for '&g'.
108def SDTOther  : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
109def SDTUNDEF  : SDTypeProfile<1, 0, []>;                     // for 'undef'.
110def SDTUnaryOp  : SDTypeProfile<1, 1, []>;                   // for bitconvert.
111
112def SDTIntBinOp : SDTypeProfile<1, 2, [     // add, and, or, xor, udiv, etc.
113  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
114]>;
115def SDTIntShiftOp : SDTypeProfile<1, 2, [   // shl, sra, srl
116  SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
117]>;
118def SDTIntShiftDOp: SDTypeProfile<1, 3, [   // fshl, fshr
119  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisInt<3>
120]>;
121def SDTIntSatNoShOp : SDTypeProfile<1, 2, [   // ssat with no shift
122  SDTCisSameAs<0, 1>, SDTCisInt<2>
123]>;
124def SDTIntBinHiLoOp : SDTypeProfile<2, 2, [ // mulhi, mullo, sdivrem, udivrem
125  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,SDTCisInt<0>
126]>;
127def SDTIntScaledBinOp : SDTypeProfile<1, 3, [  // smulfix, sdivfix, etc
128  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisInt<3>
129]>;
130
131def SDTFPBinOp : SDTypeProfile<1, 2, [      // fadd, fmul, etc.
132  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
133]>;
134def SDTFPSignOp : SDTypeProfile<1, 2, [     // fcopysign.
135  SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
136]>;
137def SDTFPTernaryOp : SDTypeProfile<1, 3, [  // fmadd, fnmsub, etc.
138  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
139]>;
140def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // bitreverse
141  SDTCisSameAs<0, 1>, SDTCisInt<0>
142]>;
143def SDTIntBitCountUnaryOp : SDTypeProfile<1, 1, [   // ctlz, cttz
144  SDTCisInt<0>, SDTCisInt<1>
145]>;
146def SDTIntExtendOp : SDTypeProfile<1, 1, [  // sext, zext, anyext
147  SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
148]>;
149def SDTIntTruncOp  : SDTypeProfile<1, 1, [  // trunc
150  SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
151]>;
152def SDTFPUnaryOp  : SDTypeProfile<1, 1, [   // fneg, fsqrt, etc
153  SDTCisSameAs<0, 1>, SDTCisFP<0>
154]>;
155def SDTFPRoundOp  : SDTypeProfile<1, 1, [   // fpround
156  SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
157]>;
158def SDTFPExtendOp  : SDTypeProfile<1, 1, [  // fpextend
159  SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
160]>;
161def SDTIntToFPOp : SDTypeProfile<1, 1, [    // [su]int_to_fp
162  SDTCisFP<0>, SDTCisInt<1>, SDTCisSameNumEltsAs<0, 1>
163]>;
164def SDTFPToIntOp : SDTypeProfile<1, 1, [    // fp_to_[su]int
165  SDTCisInt<0>, SDTCisFP<1>, SDTCisSameNumEltsAs<0, 1>
166]>;
167def SDTFPToIntSatOp : SDTypeProfile<1, 2, [    // fp_to_[su]int_sat
168  SDTCisInt<0>, SDTCisFP<1>, SDTCisSameNumEltsAs<0, 1>, SDTCisVT<2, OtherVT>
169]>;
170def SDTExtInreg : SDTypeProfile<1, 2, [     // sext_inreg
171  SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
172  SDTCisVTSmallerThanOp<2, 1>
173]>;
174def SDTExtInvec : SDTypeProfile<1, 1, [     // sext_invec
175  SDTCisInt<0>, SDTCisVec<0>, SDTCisInt<1>, SDTCisVec<1>,
176  SDTCisOpSmallerThanOp<1, 0>
177]>;
178
179def SDTSetCC : SDTypeProfile<1, 3, [        // setcc
180  SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
181]>;
182
183def SDTSelect : SDTypeProfile<1, 3, [       // select
184  SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
185]>;
186
187def SDTVSelect : SDTypeProfile<1, 3, [       // vselect
188  SDTCisVec<0>, SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>, SDTCisSameNumEltsAs<0, 1>
189]>;
190
191def SDTSelectCC : SDTypeProfile<1, 5, [     // select_cc
192  SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
193  SDTCisVT<5, OtherVT>
194]>;
195
196def SDTBr : SDTypeProfile<0, 1, [           // br
197  SDTCisVT<0, OtherVT>
198]>;
199
200def SDTBrCC : SDTypeProfile<0, 4, [       // brcc
201  SDTCisVT<0, OtherVT>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
202]>;
203
204def SDTBrcond : SDTypeProfile<0, 2, [       // brcond
205  SDTCisInt<0>, SDTCisVT<1, OtherVT>
206]>;
207
208def SDTBrind : SDTypeProfile<0, 1, [        // brind
209  SDTCisPtrTy<0>
210]>;
211
212def SDTCatchret : SDTypeProfile<0, 2, [     // catchret
213  SDTCisVT<0, OtherVT>, SDTCisVT<1, OtherVT>
214]>;
215
216def SDTNone : SDTypeProfile<0, 0, []>;      // ret, trap
217
218def SDTUBSANTrap : SDTypeProfile<0, 1, []>;      // ubsantrap
219
220def SDTLoad : SDTypeProfile<1, 1, [         // load
221  SDTCisPtrTy<1>
222]>;
223
224def SDTStore : SDTypeProfile<0, 2, [        // store
225  SDTCisPtrTy<1>
226]>;
227
228def SDTIStore : SDTypeProfile<1, 3, [       // indexed store
229  SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
230]>;
231
232def SDTMaskedStore: SDTypeProfile<0, 4, [       // masked store
233  SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisPtrTy<2>, SDTCisVec<3>, SDTCisSameNumEltsAs<0, 3>
234]>;
235
236def SDTMaskedLoad: SDTypeProfile<1, 4, [       // masked load
237  SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisPtrTy<2>, SDTCisVec<3>, SDTCisSameAs<0, 4>,
238  SDTCisSameNumEltsAs<0, 3>
239]>;
240
241def SDTVecShuffle : SDTypeProfile<1, 2, [
242  SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>
243]>;
244def SDTVecSlice : SDTypeProfile<1, 3, [     // vector splice
245  SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisInt<3>
246]>;
247def SDTVecExtract : SDTypeProfile<1, 2, [   // vector extract
248  SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
249]>;
250def SDTVecInsert : SDTypeProfile<1, 3, [    // vector insert
251  SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
252]>;
253def SDTVecReduce : SDTypeProfile<1, 1, [    // vector reduction
254  SDTCisInt<0>, SDTCisVec<1>
255]>;
256def SDTFPVecReduce : SDTypeProfile<1, 1, [  // FP vector reduction
257  SDTCisFP<0>, SDTCisVec<1>
258]>;
259
260def SDTVecReverse : SDTypeProfile<1, 1, [  // vector reverse
261  SDTCisVec<0>, SDTCisSameAs<0,1>
262]>;
263
264def SDTSubVecExtract : SDTypeProfile<1, 2, [// subvector extract
265  SDTCisSubVecOfVec<0,1>, SDTCisInt<2>
266]>;
267def SDTSubVecInsert : SDTypeProfile<1, 3, [ // subvector insert
268  SDTCisSubVecOfVec<2, 1>, SDTCisSameAs<0,1>, SDTCisInt<3>
269]>;
270
271def SDTPrefetch : SDTypeProfile<0, 4, [     // prefetch
272  SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisSameAs<1, 3>, SDTCisInt<1>
273]>;
274
275def SDTMemBarrier : SDTypeProfile<0, 5, [   // memory barrier
276  SDTCisSameAs<0,1>,  SDTCisSameAs<0,2>,  SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
277  SDTCisInt<0>
278]>;
279def SDTAtomicFence : SDTypeProfile<0, 2, [
280  SDTCisSameAs<0,1>, SDTCisPtrTy<0>
281]>;
282def SDTAtomic3 : SDTypeProfile<1, 3, [
283  SDTCisSameAs<0,2>,  SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
284]>;
285def SDTAtomic2 : SDTypeProfile<1, 2, [
286  SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
287]>;
288
289def SDTFPAtomic2 : SDTypeProfile<1, 2, [
290  SDTCisSameAs<0,2>, SDTCisFP<0>, SDTCisPtrTy<1>
291]>;
292
293def SDTAtomicStore : SDTypeProfile<0, 2, [
294  SDTCisPtrTy<0>, SDTCisInt<1>
295]>;
296def SDTAtomicLoad : SDTypeProfile<1, 1, [
297  SDTCisInt<0>, SDTCisPtrTy<1>
298]>;
299
300def SDTConvertOp : SDTypeProfile<1, 5, [ //cvtss, su, us, uu, ff, fs, fu, sf, su
301  SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>, SDTCisPtrTy<4>, SDTCisPtrTy<5>
302]>;
303
304class SDCallSeqStart<list<SDTypeConstraint> constraints> :
305        SDTypeProfile<0, 2, constraints>;
306class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
307        SDTypeProfile<0, 2, constraints>;
308
309//===----------------------------------------------------------------------===//
310// Selection DAG Node definitions.
311//
312class SDNode<string opcode, SDTypeProfile typeprof,
313             list<SDNodeProperty> props = [], string sdclass = "SDNode">
314             : SDPatternOperator {
315  string Opcode  = opcode;
316  string SDClass = sdclass;
317  let Properties = props;
318  SDTypeProfile TypeProfile = typeprof;
319}
320
321// Special TableGen-recognized dag nodes
322def set;
323def implicit;
324def node;
325def srcvalue;
326
327def imm        : SDNode<"ISD::Constant"  , SDTIntLeaf , [], "ConstantSDNode">;
328def timm       : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
329def fpimm      : SDNode<"ISD::ConstantFP", SDTFPLeaf  , [], "ConstantFPSDNode">;
330def vt         : SDNode<"ISD::VALUETYPE" , SDTOther   , [], "VTSDNode">;
331def bb         : SDNode<"ISD::BasicBlock", SDTOther   , [], "BasicBlockSDNode">;
332def cond       : SDNode<"ISD::CONDCODE"  , SDTOther   , [], "CondCodeSDNode">;
333def undef      : SDNode<"ISD::UNDEF"     , SDTUNDEF   , []>;
334def vscale     : SDNode<"ISD::VSCALE"    , SDTIntUnaryOp, []>;
335def globaladdr : SDNode<"ISD::GlobalAddress",         SDTPtrLeaf, [],
336                        "GlobalAddressSDNode">;
337def tglobaladdr : SDNode<"ISD::TargetGlobalAddress",  SDTPtrLeaf, [],
338                         "GlobalAddressSDNode">;
339def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress",         SDTPtrLeaf, [],
340                          "GlobalAddressSDNode">;
341def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress",  SDTPtrLeaf, [],
342                           "GlobalAddressSDNode">;
343def constpool   : SDNode<"ISD::ConstantPool",         SDTPtrLeaf, [],
344                         "ConstantPoolSDNode">;
345def tconstpool  : SDNode<"ISD::TargetConstantPool",   SDTPtrLeaf, [],
346                         "ConstantPoolSDNode">;
347def jumptable   : SDNode<"ISD::JumpTable",            SDTPtrLeaf, [],
348                         "JumpTableSDNode">;
349def tjumptable  : SDNode<"ISD::TargetJumpTable",      SDTPtrLeaf, [],
350                         "JumpTableSDNode">;
351def frameindex  : SDNode<"ISD::FrameIndex",           SDTPtrLeaf, [],
352                         "FrameIndexSDNode">;
353def tframeindex : SDNode<"ISD::TargetFrameIndex",     SDTPtrLeaf, [],
354                         "FrameIndexSDNode">;
355def externalsym : SDNode<"ISD::ExternalSymbol",       SDTPtrLeaf, [],
356                         "ExternalSymbolSDNode">;
357def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
358                         "ExternalSymbolSDNode">;
359def mcsym: SDNode<"ISD::MCSymbol", SDTPtrLeaf, [], "MCSymbolSDNode">;
360def blockaddress : SDNode<"ISD::BlockAddress",        SDTPtrLeaf, [],
361                         "BlockAddressSDNode">;
362def tblockaddress: SDNode<"ISD::TargetBlockAddress",  SDTPtrLeaf, [],
363                         "BlockAddressSDNode">;
364
365def add        : SDNode<"ISD::ADD"       , SDTIntBinOp   ,
366                        [SDNPCommutative, SDNPAssociative]>;
367def sub        : SDNode<"ISD::SUB"       , SDTIntBinOp>;
368def mul        : SDNode<"ISD::MUL"       , SDTIntBinOp,
369                        [SDNPCommutative, SDNPAssociative]>;
370def mulhs      : SDNode<"ISD::MULHS"     , SDTIntBinOp, [SDNPCommutative]>;
371def mulhu      : SDNode<"ISD::MULHU"     , SDTIntBinOp, [SDNPCommutative]>;
372def smullohi   : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
373def umullohi   : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
374def sdiv       : SDNode<"ISD::SDIV"      , SDTIntBinOp>;
375def udiv       : SDNode<"ISD::UDIV"      , SDTIntBinOp>;
376def srem       : SDNode<"ISD::SREM"      , SDTIntBinOp>;
377def urem       : SDNode<"ISD::UREM"      , SDTIntBinOp>;
378def sdivrem    : SDNode<"ISD::SDIVREM"   , SDTIntBinHiLoOp>;
379def udivrem    : SDNode<"ISD::UDIVREM"   , SDTIntBinHiLoOp>;
380def srl        : SDNode<"ISD::SRL"       , SDTIntShiftOp>;
381def sra        : SDNode<"ISD::SRA"       , SDTIntShiftOp>;
382def shl        : SDNode<"ISD::SHL"       , SDTIntShiftOp>;
383def rotl       : SDNode<"ISD::ROTL"      , SDTIntShiftOp>;
384def rotr       : SDNode<"ISD::ROTR"      , SDTIntShiftOp>;
385def fshl       : SDNode<"ISD::FSHL"      , SDTIntShiftDOp>;
386def fshr       : SDNode<"ISD::FSHR"      , SDTIntShiftDOp>;
387def and        : SDNode<"ISD::AND"       , SDTIntBinOp,
388                        [SDNPCommutative, SDNPAssociative]>;
389def or         : SDNode<"ISD::OR"        , SDTIntBinOp,
390                        [SDNPCommutative, SDNPAssociative]>;
391def xor        : SDNode<"ISD::XOR"       , SDTIntBinOp,
392                        [SDNPCommutative, SDNPAssociative]>;
393def addc       : SDNode<"ISD::ADDC"      , SDTIntBinOp,
394                        [SDNPCommutative, SDNPOutGlue]>;
395def adde       : SDNode<"ISD::ADDE"      , SDTIntBinOp,
396                        [SDNPCommutative, SDNPOutGlue, SDNPInGlue]>;
397def subc       : SDNode<"ISD::SUBC"      , SDTIntBinOp,
398                        [SDNPOutGlue]>;
399def sube       : SDNode<"ISD::SUBE"      , SDTIntBinOp,
400                        [SDNPOutGlue, SDNPInGlue]>;
401def smin       : SDNode<"ISD::SMIN"      , SDTIntBinOp,
402                                  [SDNPCommutative, SDNPAssociative]>;
403def smax       : SDNode<"ISD::SMAX"      , SDTIntBinOp,
404                                  [SDNPCommutative, SDNPAssociative]>;
405def umin       : SDNode<"ISD::UMIN"      , SDTIntBinOp,
406                                  [SDNPCommutative, SDNPAssociative]>;
407def umax       : SDNode<"ISD::UMAX"      , SDTIntBinOp,
408                                  [SDNPCommutative, SDNPAssociative]>;
409
410def saddsat    : SDNode<"ISD::SADDSAT"   , SDTIntBinOp, [SDNPCommutative]>;
411def uaddsat    : SDNode<"ISD::UADDSAT"   , SDTIntBinOp, [SDNPCommutative]>;
412def ssubsat    : SDNode<"ISD::SSUBSAT"   , SDTIntBinOp>;
413def usubsat    : SDNode<"ISD::USUBSAT"   , SDTIntBinOp>;
414def sshlsat    : SDNode<"ISD::SSHLSAT"   , SDTIntBinOp>;
415def ushlsat    : SDNode<"ISD::USHLSAT"   , SDTIntBinOp>;
416
417def smulfix    : SDNode<"ISD::SMULFIX"   , SDTIntScaledBinOp, [SDNPCommutative]>;
418def smulfixsat : SDNode<"ISD::SMULFIXSAT", SDTIntScaledBinOp, [SDNPCommutative]>;
419def umulfix    : SDNode<"ISD::UMULFIX"   , SDTIntScaledBinOp, [SDNPCommutative]>;
420def umulfixsat : SDNode<"ISD::UMULFIXSAT", SDTIntScaledBinOp, [SDNPCommutative]>;
421def sdivfix    : SDNode<"ISD::SDIVFIX"   , SDTIntScaledBinOp>;
422def sdivfixsat : SDNode<"ISD::SDIVFIXSAT", SDTIntScaledBinOp>;
423def udivfix    : SDNode<"ISD::UDIVFIX"   , SDTIntScaledBinOp>;
424def udivfixsat : SDNode<"ISD::UDIVFIXSAT", SDTIntScaledBinOp>;
425
426def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
427def sext_invec : SDNode<"ISD::SIGN_EXTEND_VECTOR_INREG", SDTExtInvec>;
428def zext_invec : SDNode<"ISD::ZERO_EXTEND_VECTOR_INREG", SDTExtInvec>;
429
430def abs        : SDNode<"ISD::ABS"        , SDTIntUnaryOp>;
431def bitreverse : SDNode<"ISD::BITREVERSE" , SDTIntUnaryOp>;
432def bswap      : SDNode<"ISD::BSWAP"      , SDTIntUnaryOp>;
433def ctlz       : SDNode<"ISD::CTLZ"       , SDTIntBitCountUnaryOp>;
434def cttz       : SDNode<"ISD::CTTZ"       , SDTIntBitCountUnaryOp>;
435def ctpop      : SDNode<"ISD::CTPOP"      , SDTIntBitCountUnaryOp>;
436def ctlz_zero_undef : SDNode<"ISD::CTLZ_ZERO_UNDEF", SDTIntBitCountUnaryOp>;
437def cttz_zero_undef : SDNode<"ISD::CTTZ_ZERO_UNDEF", SDTIntBitCountUnaryOp>;
438def sext       : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
439def zext       : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
440def anyext     : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
441def trunc      : SDNode<"ISD::TRUNCATE"   , SDTIntTruncOp>;
442def bitconvert : SDNode<"ISD::BITCAST"    , SDTUnaryOp>;
443def addrspacecast : SDNode<"ISD::ADDRSPACECAST", SDTUnaryOp>;
444def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
445def insertelt  : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
446
447def vecreduce_add  : SDNode<"ISD::VECREDUCE_ADD", SDTVecReduce>;
448def vecreduce_smax  : SDNode<"ISD::VECREDUCE_SMAX", SDTVecReduce>;
449def vecreduce_umax  : SDNode<"ISD::VECREDUCE_UMAX", SDTVecReduce>;
450def vecreduce_smin  : SDNode<"ISD::VECREDUCE_SMIN", SDTVecReduce>;
451def vecreduce_umin  : SDNode<"ISD::VECREDUCE_UMIN", SDTVecReduce>;
452def vecreduce_fadd  : SDNode<"ISD::VECREDUCE_FADD", SDTFPVecReduce>;
453
454def fadd       : SDNode<"ISD::FADD"       , SDTFPBinOp, [SDNPCommutative]>;
455def fsub       : SDNode<"ISD::FSUB"       , SDTFPBinOp>;
456def fmul       : SDNode<"ISD::FMUL"       , SDTFPBinOp, [SDNPCommutative]>;
457def fdiv       : SDNode<"ISD::FDIV"       , SDTFPBinOp>;
458def frem       : SDNode<"ISD::FREM"       , SDTFPBinOp>;
459def fma        : SDNode<"ISD::FMA"        , SDTFPTernaryOp, [SDNPCommutative]>;
460def fmad       : SDNode<"ISD::FMAD"       , SDTFPTernaryOp, [SDNPCommutative]>;
461def fabs       : SDNode<"ISD::FABS"       , SDTFPUnaryOp>;
462def fminnum    : SDNode<"ISD::FMINNUM"    , SDTFPBinOp,
463                                  [SDNPCommutative, SDNPAssociative]>;
464def fmaxnum    : SDNode<"ISD::FMAXNUM"    , SDTFPBinOp,
465                                  [SDNPCommutative, SDNPAssociative]>;
466def fminnum_ieee : SDNode<"ISD::FMINNUM_IEEE", SDTFPBinOp,
467                          [SDNPCommutative]>;
468def fmaxnum_ieee  : SDNode<"ISD::FMAXNUM_IEEE", SDTFPBinOp,
469                           [SDNPCommutative]>;
470def fminimum   : SDNode<"ISD::FMINIMUM"   , SDTFPBinOp,
471                        [SDNPCommutative, SDNPAssociative]>;
472def fmaximum   : SDNode<"ISD::FMAXIMUM"   , SDTFPBinOp,
473                        [SDNPCommutative, SDNPAssociative]>;
474def fgetsign   : SDNode<"ISD::FGETSIGN"   , SDTFPToIntOp>;
475def fcanonicalize : SDNode<"ISD::FCANONICALIZE", SDTFPUnaryOp>;
476def fneg       : SDNode<"ISD::FNEG"       , SDTFPUnaryOp>;
477def fsqrt      : SDNode<"ISD::FSQRT"      , SDTFPUnaryOp>;
478def fsin       : SDNode<"ISD::FSIN"       , SDTFPUnaryOp>;
479def fcos       : SDNode<"ISD::FCOS"       , SDTFPUnaryOp>;
480def fexp2      : SDNode<"ISD::FEXP2"      , SDTFPUnaryOp>;
481def fpow       : SDNode<"ISD::FPOW"       , SDTFPBinOp>;
482def flog2      : SDNode<"ISD::FLOG2"      , SDTFPUnaryOp>;
483def frint      : SDNode<"ISD::FRINT"      , SDTFPUnaryOp>;
484def ftrunc     : SDNode<"ISD::FTRUNC"     , SDTFPUnaryOp>;
485def fceil      : SDNode<"ISD::FCEIL"      , SDTFPUnaryOp>;
486def ffloor     : SDNode<"ISD::FFLOOR"     , SDTFPUnaryOp>;
487def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
488def fround     : SDNode<"ISD::FROUND"     , SDTFPUnaryOp>;
489def froundeven : SDNode<"ISD::FROUNDEVEN" , SDTFPUnaryOp>;
490
491def lround     : SDNode<"ISD::LROUND"     , SDTFPToIntOp>;
492def llround    : SDNode<"ISD::LLROUND"    , SDTFPToIntOp>;
493def lrint      : SDNode<"ISD::LRINT"      , SDTFPToIntOp>;
494def llrint     : SDNode<"ISD::LLRINT"     , SDTFPToIntOp>;
495
496def fpround    : SDNode<"ISD::FP_ROUND"   , SDTFPRoundOp>;
497def fpextend   : SDNode<"ISD::FP_EXTEND"  , SDTFPExtendOp>;
498def fcopysign  : SDNode<"ISD::FCOPYSIGN"  , SDTFPSignOp>;
499
500def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
501def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
502def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
503def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
504def fp_to_sint_sat : SDNode<"ISD::FP_TO_SINT_SAT" , SDTFPToIntSatOp>;
505def fp_to_uint_sat : SDNode<"ISD::FP_TO_UINT_SAT" , SDTFPToIntSatOp>;
506def f16_to_fp  : SDNode<"ISD::FP16_TO_FP" , SDTIntToFPOp>;
507def fp_to_f16  : SDNode<"ISD::FP_TO_FP16" , SDTFPToIntOp>;
508
509def strict_fadd       : SDNode<"ISD::STRICT_FADD",
510                               SDTFPBinOp, [SDNPHasChain, SDNPCommutative]>;
511def strict_fsub       : SDNode<"ISD::STRICT_FSUB",
512                               SDTFPBinOp, [SDNPHasChain]>;
513def strict_fmul       : SDNode<"ISD::STRICT_FMUL",
514                               SDTFPBinOp, [SDNPHasChain, SDNPCommutative]>;
515def strict_fdiv       : SDNode<"ISD::STRICT_FDIV",
516                               SDTFPBinOp, [SDNPHasChain]>;
517def strict_frem       : SDNode<"ISD::STRICT_FREM",
518                               SDTFPBinOp, [SDNPHasChain]>;
519def strict_fma        : SDNode<"ISD::STRICT_FMA",
520                               SDTFPTernaryOp, [SDNPHasChain, SDNPCommutative]>;
521def strict_fsqrt      : SDNode<"ISD::STRICT_FSQRT",
522                               SDTFPUnaryOp, [SDNPHasChain]>;
523def strict_fsin       : SDNode<"ISD::STRICT_FSIN",
524                               SDTFPUnaryOp, [SDNPHasChain]>;
525def strict_fcos       : SDNode<"ISD::STRICT_FCOS",
526                               SDTFPUnaryOp, [SDNPHasChain]>;
527def strict_fexp2      : SDNode<"ISD::STRICT_FEXP2",
528                               SDTFPUnaryOp, [SDNPHasChain]>;
529def strict_fpow       : SDNode<"ISD::STRICT_FPOW",
530                               SDTFPBinOp, [SDNPHasChain]>;
531def strict_flog2      : SDNode<"ISD::STRICT_FLOG2",
532                               SDTFPUnaryOp, [SDNPHasChain]>;
533def strict_frint      : SDNode<"ISD::STRICT_FRINT",
534                               SDTFPUnaryOp, [SDNPHasChain]>;
535def strict_lrint      : SDNode<"ISD::STRICT_LRINT",
536                               SDTFPToIntOp, [SDNPHasChain]>;
537def strict_llrint     : SDNode<"ISD::STRICT_LLRINT",
538                               SDTFPToIntOp, [SDNPHasChain]>;
539def strict_fnearbyint : SDNode<"ISD::STRICT_FNEARBYINT",
540                               SDTFPUnaryOp, [SDNPHasChain]>;
541def strict_fceil      : SDNode<"ISD::STRICT_FCEIL",
542                               SDTFPUnaryOp, [SDNPHasChain]>;
543def strict_ffloor     : SDNode<"ISD::STRICT_FFLOOR",
544                               SDTFPUnaryOp, [SDNPHasChain]>;
545def strict_lround     : SDNode<"ISD::STRICT_LROUND",
546                               SDTFPToIntOp, [SDNPHasChain]>;
547def strict_llround    : SDNode<"ISD::STRICT_LLROUND",
548                               SDTFPToIntOp, [SDNPHasChain]>;
549def strict_fround     : SDNode<"ISD::STRICT_FROUND",
550                               SDTFPUnaryOp, [SDNPHasChain]>;
551def strict_froundeven : SDNode<"ISD::STRICT_FROUNDEVEN",
552                               SDTFPUnaryOp, [SDNPHasChain]>;
553def strict_ftrunc     : SDNode<"ISD::STRICT_FTRUNC",
554                               SDTFPUnaryOp, [SDNPHasChain]>;
555def strict_fminnum    : SDNode<"ISD::STRICT_FMINNUM",
556                               SDTFPBinOp, [SDNPHasChain,
557                                            SDNPCommutative, SDNPAssociative]>;
558def strict_fmaxnum    : SDNode<"ISD::STRICT_FMAXNUM",
559                               SDTFPBinOp, [SDNPHasChain,
560                                            SDNPCommutative, SDNPAssociative]>;
561def strict_fminimum   : SDNode<"ISD::STRICT_FMINIMUM",
562                               SDTFPBinOp, [SDNPHasChain,
563                                            SDNPCommutative, SDNPAssociative]>;
564def strict_fmaximum   : SDNode<"ISD::STRICT_FMAXIMUM",
565                               SDTFPBinOp, [SDNPHasChain,
566                                            SDNPCommutative, SDNPAssociative]>;
567def strict_fpround    : SDNode<"ISD::STRICT_FP_ROUND",
568                               SDTFPRoundOp, [SDNPHasChain]>;
569def strict_fpextend   : SDNode<"ISD::STRICT_FP_EXTEND",
570                               SDTFPExtendOp, [SDNPHasChain]>;
571def strict_fp_to_sint : SDNode<"ISD::STRICT_FP_TO_SINT",
572                               SDTFPToIntOp, [SDNPHasChain]>;
573def strict_fp_to_uint : SDNode<"ISD::STRICT_FP_TO_UINT",
574                               SDTFPToIntOp, [SDNPHasChain]>;
575def strict_sint_to_fp : SDNode<"ISD::STRICT_SINT_TO_FP",
576                               SDTIntToFPOp, [SDNPHasChain]>;
577def strict_uint_to_fp : SDNode<"ISD::STRICT_UINT_TO_FP",
578                               SDTIntToFPOp, [SDNPHasChain]>;
579def strict_fsetcc  : SDNode<"ISD::STRICT_FSETCC",  SDTSetCC, [SDNPHasChain]>;
580def strict_fsetccs : SDNode<"ISD::STRICT_FSETCCS", SDTSetCC, [SDNPHasChain]>;
581
582def setcc      : SDNode<"ISD::SETCC"      , SDTSetCC>;
583def select     : SDNode<"ISD::SELECT"     , SDTSelect>;
584def vselect    : SDNode<"ISD::VSELECT"    , SDTVSelect>;
585def selectcc   : SDNode<"ISD::SELECT_CC"  , SDTSelectCC>;
586
587def brcc       : SDNode<"ISD::BR_CC"      , SDTBrCC,   [SDNPHasChain]>;
588def brcond     : SDNode<"ISD::BRCOND"     , SDTBrcond, [SDNPHasChain]>;
589def brind      : SDNode<"ISD::BRIND"      , SDTBrind,  [SDNPHasChain]>;
590def br         : SDNode<"ISD::BR"         , SDTBr,     [SDNPHasChain]>;
591def catchret   : SDNode<"ISD::CATCHRET"   , SDTCatchret,
592                        [SDNPHasChain, SDNPSideEffect]>;
593def cleanupret : SDNode<"ISD::CLEANUPRET" , SDTNone,   [SDNPHasChain]>;
594
595def trap       : SDNode<"ISD::TRAP"       , SDTNone,
596                        [SDNPHasChain, SDNPSideEffect]>;
597def debugtrap  : SDNode<"ISD::DEBUGTRAP"  , SDTNone,
598                        [SDNPHasChain, SDNPSideEffect]>;
599def ubsantrap  : SDNode<"ISD::UBSANTRAP"  , SDTUBSANTrap,
600                        [SDNPHasChain, SDNPSideEffect]>;
601
602def prefetch   : SDNode<"ISD::PREFETCH"   , SDTPrefetch,
603                        [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
604                         SDNPMemOperand]>;
605
606def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
607                     [SDNPHasChain, SDNPSideEffect]>;
608
609def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
610                          [SDNPHasChain, SDNPSideEffect]>;
611
612def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
613                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
614def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
615                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
616def atomic_swap     : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
617                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
618def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
619                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
620def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
621                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
622def atomic_load_clr : SDNode<"ISD::ATOMIC_LOAD_CLR" , SDTAtomic2,
623                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
624def atomic_load_or  : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
625                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
626def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
627                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
628def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
629                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
630def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
631                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
632def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
633                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
634def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
635                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
636def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
637                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
638def atomic_load_fadd : SDNode<"ISD::ATOMIC_LOAD_FADD" , SDTFPAtomic2,
639                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
640def atomic_load_fsub : SDNode<"ISD::ATOMIC_LOAD_FSUB" , SDTFPAtomic2,
641                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
642
643def atomic_load      : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
644                    [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
645def atomic_store     : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
646                    [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
647
648def masked_st    : SDNode<"ISD::MSTORE",  SDTMaskedStore,
649                       [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
650def masked_ld    : SDNode<"ISD::MLOAD",  SDTMaskedLoad,
651                       [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
652
653// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
654// and truncst (see below).
655def ld         : SDNode<"ISD::LOAD"       , SDTLoad,
656                        [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
657def st         : SDNode<"ISD::STORE"      , SDTStore,
658                        [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
659def ist        : SDNode<"ISD::STORE"      , SDTIStore,
660                        [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
661
662def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
663def vector_reverse : SDNode<"ISD::VECTOR_REVERSE", SDTVecReverse>;
664def vector_splice : SDNode<"ISD::VECTOR_SPLICE", SDTVecSlice, []>;
665def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
666def splat_vector : SDNode<"ISD::SPLAT_VECTOR", SDTypeProfile<1, 1, []>, []>;
667def step_vector : SDNode<"ISD::STEP_VECTOR", SDTypeProfile<1, 1,
668                       [SDTCisVec<0>, SDTCisInt<1>]>, []>;
669def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
670                              []>;
671
672// vector_extract/vector_insert are deprecated. extractelt/insertelt
673// are preferred.
674def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
675    SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
676def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
677    SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
678def concat_vectors : SDNode<"ISD::CONCAT_VECTORS",
679    SDTypeProfile<1, 2, [SDTCisSubVecOfVec<1, 0>, SDTCisSameAs<1, 2>]>,[]>;
680
681// This operator does not do subvector type checking.  The ARM
682// backend, at least, needs it.
683def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
684    SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
685    []>;
686
687// This operator does subvector type checking.
688def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
689def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
690
691// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
692// these internally.  Don't reference these directly.
693def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
694                            SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
695                            [SDNPHasChain]>;
696def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
697                               SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
698                               [SDNPHasChain]>;
699def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
700                                SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
701
702def SDT_assert : SDTypeProfile<1, 1,
703  [SDTCisInt<0>, SDTCisInt<1>, SDTCisSameAs<1, 0>]>;
704def assertsext : SDNode<"ISD::AssertSext", SDT_assert>;
705def assertzext : SDNode<"ISD::AssertZext", SDT_assert>;
706def assertalign : SDNode<"ISD::AssertAlign", SDT_assert>;
707
708
709//===----------------------------------------------------------------------===//
710// Selection DAG Condition Codes
711
712class CondCode<string fcmpName = "", string icmpName = ""> {
713  string ICmpPredicate = icmpName;
714  string FCmpPredicate = fcmpName;
715}
716
717// ISD::CondCode enums, and mapping to CmpInst::Predicate names
718def SETOEQ : CondCode<"FCMP_OEQ">;
719def SETOGT : CondCode<"FCMP_OGT">;
720def SETOGE : CondCode<"FCMP_OGE">;
721def SETOLT : CondCode<"FCMP_OLT">;
722def SETOLE : CondCode<"FCMP_OLE">;
723def SETONE : CondCode<"FCMP_ONE">;
724def SETO   : CondCode<"FCMP_ORD">;
725def SETUO  : CondCode<"FCMP_UNO">;
726def SETUEQ : CondCode<"FCMP_UEQ">;
727def SETUGT : CondCode<"FCMP_UGT", "ICMP_UGT">;
728def SETUGE : CondCode<"FCMP_UGE", "ICMP_UGE">;
729def SETULT : CondCode<"FCMP_ULT", "ICMP_ULT">;
730def SETULE : CondCode<"FCMP_ULE", "ICMP_ULE">;
731def SETUNE : CondCode<"FCMP_UNE">;
732def SETEQ : CondCode<"", "ICMP_EQ">;
733def SETGT : CondCode<"", "ICMP_SGT">;
734def SETGE : CondCode<"", "ICMP_SGE">;
735def SETLT : CondCode<"", "ICMP_SLT">;
736def SETLE : CondCode<"", "ICMP_SLE">;
737def SETNE : CondCode<"", "ICMP_NE">;
738
739//===----------------------------------------------------------------------===//
740// Selection DAG Node Transformation Functions.
741//
742// This mechanism allows targets to manipulate nodes in the output DAG once a
743// match has been formed.  This is typically used to manipulate immediate
744// values.
745//
746class SDNodeXForm<SDNode opc, code xformFunction> {
747  SDNode Opcode = opc;
748  code XFormFunction = xformFunction;
749}
750
751def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
752
753//===----------------------------------------------------------------------===//
754// Selection DAG Pattern Fragments.
755//
756// Pattern fragments are reusable chunks of dags that match specific things.
757// They can take arguments and have C++ predicates that control whether they
758// match.  They are intended to make the patterns for common instructions more
759// compact and readable.
760//
761
762/// PatFrags - Represents a set of pattern fragments.  Each single fragment
763/// can match something on the DAG, from a single node to multiple nested other
764/// fragments.   The whole set of fragments matches if any of the single
765/// fragments match.  This allows e.g. matching and "add with overflow" and
766/// a regular "add" with the same fragment set.
767///
768class PatFrags<dag ops, list<dag> frags, code pred = [{}],
769               SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
770  dag Operands = ops;
771  list<dag> Fragments = frags;
772  code PredicateCode = pred;
773  code GISelPredicateCode = [{}];
774  code ImmediateCode = [{}];
775  SDNodeXForm OperandTransform = xform;
776
777  // When this is set, the PredicateCode may refer to a constant Operands
778  // vector which contains the captured nodes of the DAG, in the order listed
779  // by the Operands field above.
780  //
781  // This is useful when Fragments involves associative / commutative
782  // operators: a single piece of code can easily refer to all operands even
783  // when re-associated / commuted variants of the fragment are matched.
784  bit PredicateCodeUsesOperands = false;
785
786  // Define a few pre-packaged predicates. This helps GlobalISel import
787  // existing rules from SelectionDAG for many common cases.
788  // They will be tested prior to the code in pred and must not be used in
789  // ImmLeaf and its subclasses.
790
791  // Is the desired pre-packaged predicate for a load?
792  bit IsLoad = ?;
793  // Is the desired pre-packaged predicate for a store?
794  bit IsStore = ?;
795  // Is the desired pre-packaged predicate for an atomic?
796  bit IsAtomic = ?;
797
798  // cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
799  // cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
800  bit IsUnindexed = ?;
801
802  // cast<LoadSDNode>(N)->getExtensionType() != ISD::NON_EXTLOAD
803  bit IsNonExtLoad = ?;
804  // cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
805  bit IsAnyExtLoad = ?;
806  // cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
807  bit IsSignExtLoad = ?;
808  // cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
809  bit IsZeroExtLoad = ?;
810  // !cast<StoreSDNode>(N)->isTruncatingStore();
811  // cast<StoreSDNode>(N)->isTruncatingStore();
812  bit IsTruncStore = ?;
813
814  // cast<MemSDNode>(N)->getAddressSpace() ==
815  // If this empty, accept any address space.
816  list<int> AddressSpaces = ?;
817
818  // cast<MemSDNode>(N)->getAlignment() >=
819  // If this is empty, accept any alignment.
820  int MinAlignment = ?;
821
822  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Monotonic
823  bit IsAtomicOrderingMonotonic = ?;
824  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Acquire
825  bit IsAtomicOrderingAcquire = ?;
826  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Release
827  bit IsAtomicOrderingRelease = ?;
828  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::AcquireRelease
829  bit IsAtomicOrderingAcquireRelease = ?;
830  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::SequentiallyConsistent
831  bit IsAtomicOrderingSequentiallyConsistent = ?;
832
833  // isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
834  // !isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
835  bit IsAtomicOrderingAcquireOrStronger = ?;
836
837  // isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
838  // !isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
839  bit IsAtomicOrderingReleaseOrStronger = ?;
840
841  // cast<LoadSDNode>(N)->getMemoryVT() == MVT::<VT>;
842  // cast<StoreSDNode>(N)->getMemoryVT() == MVT::<VT>;
843  ValueType MemoryVT = ?;
844  // cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
845  // cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
846  ValueType ScalarMemoryVT = ?;
847}
848
849// PatFrag - A version of PatFrags matching only a single fragment.
850class PatFrag<dag ops, dag frag, code pred = [{}],
851              SDNodeXForm xform = NOOP_SDNodeXForm>
852  : PatFrags<ops, [frag], pred, xform>;
853
854// OutPatFrag is a pattern fragment that is used as part of an output pattern
855// (not an input pattern). These do not have predicates or transforms, but are
856// used to avoid repeated subexpressions in output patterns.
857class OutPatFrag<dag ops, dag frag>
858 : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;
859
860// PatLeaf's are pattern fragments that have no operands.  This is just a helper
861// to define immediates and other common things concisely.
862class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
863 : PatFrag<(ops), frag, pred, xform>;
864
865
866// ImmLeaf is a pattern fragment with a constraint on the immediate.  The
867// constraint is a function that is run on the immediate (always with the value
868// sign extended out to an int64_t) as Imm.  For example:
869//
870//  def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
871//
872// this is a more convenient form to match 'imm' nodes in than PatLeaf and also
873// is preferred over using PatLeaf because it allows the code generator to
874// reason more about the constraint.
875//
876// If FastIsel should ignore all instructions that have an operand of this type,
877// the FastIselShouldIgnore flag can be set.  This is an optimization to reduce
878// the code size of the generated fast instruction selector.
879class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
880              SDNode ImmNode = imm>
881  : PatFrag<(ops), (vt ImmNode), [{}], xform> {
882  let ImmediateCode = pred;
883  bit FastIselShouldIgnore = false;
884
885  // Is the data type of the immediate an APInt?
886  bit IsAPInt = false;
887
888  // Is the data type of the immediate an APFloat?
889  bit IsAPFloat = false;
890}
891
892// Convenience wrapper for ImmLeaf to use timm/TargetConstant instead
893// of imm/Constant.
894class TImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
895  SDNode ImmNode = timm> : ImmLeaf<vt, pred, xform, ImmNode>;
896
897// An ImmLeaf except that Imm is an APInt. This is useful when you need to
898// zero-extend the immediate instead of sign-extend it.
899//
900// Note that FastISel does not currently understand IntImmLeaf and will not
901// generate code for rules that make use of it. As such, it does not make sense
902// to replace ImmLeaf with IntImmLeaf. However, replacing PatLeaf with an
903// IntImmLeaf will allow GlobalISel to import the rule.
904class IntImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
905    : ImmLeaf<vt, pred, xform> {
906  let IsAPInt = true;
907  let FastIselShouldIgnore = true;
908}
909
910// An ImmLeaf except that Imm is an APFloat.
911//
912// Note that FastISel does not currently understand FPImmLeaf and will not
913// generate code for rules that make use of it.
914class FPImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
915  : ImmLeaf<vt, pred, xform, fpimm> {
916  let IsAPFloat = true;
917  let FastIselShouldIgnore = true;
918}
919
920// Leaf fragments.
921
922def vtInt      : PatLeaf<(vt),  [{ return N->getVT().isInteger(); }]>;
923def vtFP       : PatLeaf<(vt),  [{ return N->getVT().isFloatingPoint(); }]>;
924
925// Use ISD::isConstantSplatVectorAllOnes or ISD::isConstantSplatVectorAllZeros
926// to look for the corresponding build_vector or splat_vector. Will look through
927// bitcasts and check for either opcode, except when used as a pattern root.
928// When used as a pattern root, only fixed-length build_vector and scalable
929// splat_vector are supported.
930def immAllOnesV  : SDPatternOperator; // ISD::isConstantSplatVectorAllOnes
931def immAllZerosV : SDPatternOperator; // ISD::isConstantSplatVectorAllZeros
932
933// Other helper fragments.
934def not  : PatFrag<(ops node:$in), (xor node:$in, -1)>;
935def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
936def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
937
938def zanyext : PatFrags<(ops node:$op),
939                       [(zext node:$op),
940                        (anyext node:$op)]>;
941
942// null_frag - The null pattern operator is used in multiclass instantiations
943// which accept an SDPatternOperator for use in matching patterns for internal
944// definitions. When expanding a pattern, if the null fragment is referenced
945// in the expansion, the pattern is discarded and it is as-if '[]' had been
946// specified. This allows multiclasses to have the isel patterns be optional.
947def null_frag : SDPatternOperator;
948
949// load fragments.
950def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr)> {
951  let IsLoad = true;
952  let IsUnindexed = true;
953}
954def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
955  let IsLoad = true;
956  let IsNonExtLoad = true;
957}
958
959// extending load fragments.
960def extload   : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
961  let IsLoad = true;
962  let IsAnyExtLoad = true;
963}
964def sextload  : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
965  let IsLoad = true;
966  let IsSignExtLoad = true;
967}
968def zextload  : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
969  let IsLoad = true;
970  let IsZeroExtLoad = true;
971}
972
973def extloadi1  : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
974  let IsLoad = true;
975  let MemoryVT = i1;
976}
977def extloadi8  : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
978  let IsLoad = true;
979  let MemoryVT = i8;
980}
981def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
982  let IsLoad = true;
983  let MemoryVT = i16;
984}
985def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
986  let IsLoad = true;
987  let MemoryVT = i32;
988}
989def extloadf16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
990  let IsLoad = true;
991  let MemoryVT = f16;
992}
993def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
994  let IsLoad = true;
995  let MemoryVT = f32;
996}
997def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
998  let IsLoad = true;
999  let MemoryVT = f64;
1000}
1001
1002def sextloadi1  : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1003  let IsLoad = true;
1004  let MemoryVT = i1;
1005}
1006def sextloadi8  : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1007  let IsLoad = true;
1008  let MemoryVT = i8;
1009}
1010def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1011  let IsLoad = true;
1012  let MemoryVT = i16;
1013}
1014def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1015  let IsLoad = true;
1016  let MemoryVT = i32;
1017}
1018
1019def zextloadi1  : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1020  let IsLoad = true;
1021  let MemoryVT = i1;
1022}
1023def zextloadi8  : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1024  let IsLoad = true;
1025  let MemoryVT = i8;
1026}
1027def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1028  let IsLoad = true;
1029  let MemoryVT = i16;
1030}
1031def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1032  let IsLoad = true;
1033  let MemoryVT = i32;
1034}
1035
1036def extloadvi1  : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1037  let IsLoad = true;
1038  let ScalarMemoryVT = i1;
1039}
1040def extloadvi8  : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1041  let IsLoad = true;
1042  let ScalarMemoryVT = i8;
1043}
1044def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1045  let IsLoad = true;
1046  let ScalarMemoryVT = i16;
1047}
1048def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1049  let IsLoad = true;
1050  let ScalarMemoryVT = i32;
1051}
1052def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1053  let IsLoad = true;
1054  let ScalarMemoryVT = f32;
1055}
1056def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1057  let IsLoad = true;
1058  let ScalarMemoryVT = f64;
1059}
1060
1061def sextloadvi1  : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1062  let IsLoad = true;
1063  let ScalarMemoryVT = i1;
1064}
1065def sextloadvi8  : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1066  let IsLoad = true;
1067  let ScalarMemoryVT = i8;
1068}
1069def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1070  let IsLoad = true;
1071  let ScalarMemoryVT = i16;
1072}
1073def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1074  let IsLoad = true;
1075  let ScalarMemoryVT = i32;
1076}
1077
1078def zextloadvi1  : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1079  let IsLoad = true;
1080  let ScalarMemoryVT = i1;
1081}
1082def zextloadvi8  : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1083  let IsLoad = true;
1084  let ScalarMemoryVT = i8;
1085}
1086def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1087  let IsLoad = true;
1088  let ScalarMemoryVT = i16;
1089}
1090def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1091  let IsLoad = true;
1092  let ScalarMemoryVT = i32;
1093}
1094
1095// store fragments.
1096def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
1097                             (st node:$val, node:$ptr)> {
1098  let IsStore = true;
1099  let IsUnindexed = true;
1100}
1101def store : PatFrag<(ops node:$val, node:$ptr),
1102                    (unindexedstore node:$val, node:$ptr)> {
1103  let IsStore = true;
1104  let IsTruncStore = false;
1105}
1106
1107// truncstore fragments.
1108def truncstore : PatFrag<(ops node:$val, node:$ptr),
1109                         (unindexedstore node:$val, node:$ptr)> {
1110  let IsStore = true;
1111  let IsTruncStore = true;
1112}
1113def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
1114                           (truncstore node:$val, node:$ptr)> {
1115  let IsStore = true;
1116  let MemoryVT = i8;
1117  let IsTruncStore = true;
1118}
1119def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
1120                            (truncstore node:$val, node:$ptr)> {
1121  let IsStore = true;
1122  let MemoryVT = i16;
1123  let IsTruncStore = true;
1124}
1125def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
1126                            (truncstore node:$val, node:$ptr)> {
1127  let IsStore = true;
1128  let MemoryVT = i32;
1129  let IsTruncStore = true;
1130}
1131def truncstoref16 : PatFrag<(ops node:$val, node:$ptr),
1132                            (truncstore node:$val, node:$ptr)> {
1133  let IsStore = true;
1134  let MemoryVT = f16;
1135}
1136def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
1137                            (truncstore node:$val, node:$ptr)> {
1138  let IsStore = true;
1139  let MemoryVT = f32;
1140}
1141def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
1142                            (truncstore node:$val, node:$ptr)> {
1143  let IsStore = true;
1144  let MemoryVT = f64;
1145}
1146
1147def truncstorevi8 : PatFrag<(ops node:$val, node:$ptr),
1148                            (truncstore node:$val, node:$ptr)> {
1149  let IsStore = true;
1150  let ScalarMemoryVT = i8;
1151}
1152
1153def truncstorevi16 : PatFrag<(ops node:$val, node:$ptr),
1154                             (truncstore node:$val, node:$ptr)> {
1155  let IsStore = true;
1156  let ScalarMemoryVT = i16;
1157}
1158
1159def truncstorevi32 : PatFrag<(ops node:$val, node:$ptr),
1160                             (truncstore node:$val, node:$ptr)> {
1161  let IsStore = true;
1162  let ScalarMemoryVT = i32;
1163}
1164
1165// indexed store fragments.
1166def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
1167                     (ist node:$val, node:$base, node:$offset)> {
1168  let IsStore = true;
1169  let IsTruncStore = false;
1170}
1171
1172def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
1173                        (istore node:$val, node:$base, node:$offset), [{
1174  ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1175  return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1176}]>;
1177
1178def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
1179                          (ist node:$val, node:$base, node:$offset)> {
1180  let IsStore = true;
1181  let IsTruncStore = true;
1182}
1183def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1184                          (itruncstore node:$val, node:$base, node:$offset), [{
1185  ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1186  return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1187}]>;
1188def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1189                            (pre_truncst node:$val, node:$base, node:$offset)> {
1190  let IsStore = true;
1191  let MemoryVT = i1;
1192}
1193def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1194                            (pre_truncst node:$val, node:$base, node:$offset)> {
1195  let IsStore = true;
1196  let MemoryVT = i8;
1197}
1198def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1199                             (pre_truncst node:$val, node:$base, node:$offset)> {
1200  let IsStore = true;
1201  let MemoryVT = i16;
1202}
1203def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1204                             (pre_truncst node:$val, node:$base, node:$offset)> {
1205  let IsStore = true;
1206  let MemoryVT = i32;
1207}
1208def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1209                             (pre_truncst node:$val, node:$base, node:$offset)> {
1210  let IsStore = true;
1211  let MemoryVT = f32;
1212}
1213def pre_truncstvi8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1214                             (pre_truncst node:$val, node:$base, node:$offset)> {
1215  let IsStore = true;
1216  let ScalarMemoryVT = i8;
1217}
1218def pre_truncstvi16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1219                              (pre_truncst node:$val, node:$base, node:$offset)> {
1220  let IsStore = true;
1221  let ScalarMemoryVT = i16;
1222}
1223
1224def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
1225                         (istore node:$val, node:$ptr, node:$offset), [{
1226  ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1227  return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1228}]>;
1229
1230def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1231                           (itruncstore node:$val, node:$base, node:$offset), [{
1232  ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1233  return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1234}]>;
1235def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1236                             (post_truncst node:$val, node:$base, node:$offset)> {
1237  let IsStore = true;
1238  let MemoryVT = i1;
1239}
1240def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1241                             (post_truncst node:$val, node:$base, node:$offset)> {
1242  let IsStore = true;
1243  let MemoryVT = i8;
1244}
1245def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1246                              (post_truncst node:$val, node:$base, node:$offset)> {
1247  let IsStore = true;
1248  let MemoryVT = i16;
1249}
1250def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1251                              (post_truncst node:$val, node:$base, node:$offset)> {
1252  let IsStore = true;
1253  let MemoryVT = i32;
1254}
1255def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1256                              (post_truncst node:$val, node:$base, node:$offset)> {
1257  let IsStore = true;
1258  let MemoryVT = f32;
1259}
1260def post_truncstvi8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1261                              (post_truncst node:$val, node:$base, node:$offset)> {
1262  let IsStore = true;
1263  let ScalarMemoryVT = i8;
1264}
1265def post_truncstvi16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1266                               (post_truncst node:$val, node:$base, node:$offset)> {
1267  let IsStore = true;
1268  let ScalarMemoryVT = i16;
1269}
1270
1271// TODO: Split these into volatile and unordered flavors to enable
1272// selectively legal optimizations for each.  (See D66309)
1273def simple_load : PatFrag<(ops node:$ptr),
1274                          (load node:$ptr), [{
1275  return cast<LoadSDNode>(N)->isSimple();
1276}]>;
1277def simple_store : PatFrag<(ops node:$val, node:$ptr),
1278                           (store node:$val, node:$ptr), [{
1279  return cast<StoreSDNode>(N)->isSimple();
1280}]>;
1281
1282// nontemporal store fragments.
1283def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1284                               (store node:$val, node:$ptr), [{
1285  return cast<StoreSDNode>(N)->isNonTemporal();
1286}]>;
1287
1288def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1289                                      (nontemporalstore node:$val, node:$ptr), [{
1290  StoreSDNode *St = cast<StoreSDNode>(N);
1291  return St->getAlignment() >= St->getMemoryVT().getStoreSize();
1292}]>;
1293
1294def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1295                                        (nontemporalstore node:$val, node:$ptr), [{
1296  StoreSDNode *St = cast<StoreSDNode>(N);
1297  return St->getAlignment() < St->getMemoryVT().getStoreSize();
1298}]>;
1299
1300// nontemporal load fragments.
1301def nontemporalload : PatFrag<(ops node:$ptr),
1302                               (load node:$ptr), [{
1303  return cast<LoadSDNode>(N)->isNonTemporal();
1304}]>;
1305
1306def alignednontemporalload : PatFrag<(ops node:$ptr),
1307                                      (nontemporalload node:$ptr), [{
1308  LoadSDNode *Ld = cast<LoadSDNode>(N);
1309  return Ld->getAlignment() >= Ld->getMemoryVT().getStoreSize();
1310}]>;
1311
1312// setcc convenience fragments.
1313def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
1314                     (setcc node:$lhs, node:$rhs, SETOEQ)>;
1315def setogt : PatFrag<(ops node:$lhs, node:$rhs),
1316                     (setcc node:$lhs, node:$rhs, SETOGT)>;
1317def setoge : PatFrag<(ops node:$lhs, node:$rhs),
1318                     (setcc node:$lhs, node:$rhs, SETOGE)>;
1319def setolt : PatFrag<(ops node:$lhs, node:$rhs),
1320                     (setcc node:$lhs, node:$rhs, SETOLT)>;
1321def setole : PatFrag<(ops node:$lhs, node:$rhs),
1322                     (setcc node:$lhs, node:$rhs, SETOLE)>;
1323def setone : PatFrag<(ops node:$lhs, node:$rhs),
1324                     (setcc node:$lhs, node:$rhs, SETONE)>;
1325def seto   : PatFrag<(ops node:$lhs, node:$rhs),
1326                     (setcc node:$lhs, node:$rhs, SETO)>;
1327def setuo  : PatFrag<(ops node:$lhs, node:$rhs),
1328                     (setcc node:$lhs, node:$rhs, SETUO)>;
1329def setueq : PatFrag<(ops node:$lhs, node:$rhs),
1330                     (setcc node:$lhs, node:$rhs, SETUEQ)>;
1331def setugt : PatFrag<(ops node:$lhs, node:$rhs),
1332                     (setcc node:$lhs, node:$rhs, SETUGT)>;
1333def setuge : PatFrag<(ops node:$lhs, node:$rhs),
1334                     (setcc node:$lhs, node:$rhs, SETUGE)>;
1335def setult : PatFrag<(ops node:$lhs, node:$rhs),
1336                     (setcc node:$lhs, node:$rhs, SETULT)>;
1337def setule : PatFrag<(ops node:$lhs, node:$rhs),
1338                     (setcc node:$lhs, node:$rhs, SETULE)>;
1339def setune : PatFrag<(ops node:$lhs, node:$rhs),
1340                     (setcc node:$lhs, node:$rhs, SETUNE)>;
1341def seteq  : PatFrag<(ops node:$lhs, node:$rhs),
1342                     (setcc node:$lhs, node:$rhs, SETEQ)>;
1343def setgt  : PatFrag<(ops node:$lhs, node:$rhs),
1344                     (setcc node:$lhs, node:$rhs, SETGT)>;
1345def setge  : PatFrag<(ops node:$lhs, node:$rhs),
1346                     (setcc node:$lhs, node:$rhs, SETGE)>;
1347def setlt  : PatFrag<(ops node:$lhs, node:$rhs),
1348                     (setcc node:$lhs, node:$rhs, SETLT)>;
1349def setle  : PatFrag<(ops node:$lhs, node:$rhs),
1350                     (setcc node:$lhs, node:$rhs, SETLE)>;
1351def setne  : PatFrag<(ops node:$lhs, node:$rhs),
1352                     (setcc node:$lhs, node:$rhs, SETNE)>;
1353
1354// We don't have strict FP extended loads as single DAG nodes, but we can
1355// still provide convenience fragments to match those operations.
1356def strict_extloadf32 : PatFrag<(ops node:$ptr),
1357                                (strict_fpextend (f32 (load node:$ptr)))>;
1358def strict_extloadf64 : PatFrag<(ops node:$ptr),
1359                                (strict_fpextend (f64 (load node:$ptr)))>;
1360
1361// Convenience fragments to match both strict and non-strict fp operations
1362def any_fadd       : PatFrags<(ops node:$lhs, node:$rhs),
1363                              [(strict_fadd node:$lhs, node:$rhs),
1364                               (fadd node:$lhs, node:$rhs)]>;
1365def any_fsub       : PatFrags<(ops node:$lhs, node:$rhs),
1366                              [(strict_fsub node:$lhs, node:$rhs),
1367                               (fsub node:$lhs, node:$rhs)]>;
1368def any_fmul       : PatFrags<(ops node:$lhs, node:$rhs),
1369                              [(strict_fmul node:$lhs, node:$rhs),
1370                               (fmul node:$lhs, node:$rhs)]>;
1371def any_fdiv       : PatFrags<(ops node:$lhs, node:$rhs),
1372                              [(strict_fdiv node:$lhs, node:$rhs),
1373                               (fdiv node:$lhs, node:$rhs)]>;
1374def any_frem       : PatFrags<(ops node:$lhs, node:$rhs),
1375                              [(strict_frem node:$lhs, node:$rhs),
1376                               (frem node:$lhs, node:$rhs)]>;
1377def any_fma        : PatFrags<(ops node:$src1, node:$src2, node:$src3),
1378                              [(strict_fma node:$src1, node:$src2, node:$src3),
1379                               (fma node:$src1, node:$src2, node:$src3)]>;
1380def any_fsqrt      : PatFrags<(ops node:$src),
1381                              [(strict_fsqrt node:$src),
1382                               (fsqrt node:$src)]>;
1383def any_fsin       : PatFrags<(ops node:$src),
1384                              [(strict_fsin node:$src),
1385                               (fsin node:$src)]>;
1386def any_fcos       : PatFrags<(ops node:$src),
1387                              [(strict_fcos node:$src),
1388                               (fcos node:$src)]>;
1389def any_fexp2      : PatFrags<(ops node:$src),
1390                              [(strict_fexp2 node:$src),
1391                               (fexp2 node:$src)]>;
1392def any_fpow       : PatFrags<(ops node:$lhs, node:$rhs),
1393                              [(strict_fpow node:$lhs, node:$rhs),
1394                               (fpow node:$lhs, node:$rhs)]>;
1395def any_flog2      : PatFrags<(ops node:$src),
1396                              [(strict_flog2 node:$src),
1397                               (flog2 node:$src)]>;
1398def any_frint      : PatFrags<(ops node:$src),
1399                              [(strict_frint node:$src),
1400                               (frint node:$src)]>;
1401def any_lrint      : PatFrags<(ops node:$src),
1402                              [(strict_lrint node:$src),
1403                               (lrint node:$src)]>;
1404def any_llrint     : PatFrags<(ops node:$src),
1405                              [(strict_llrint node:$src),
1406                               (llrint node:$src)]>;
1407def any_fnearbyint : PatFrags<(ops node:$src),
1408                              [(strict_fnearbyint node:$src),
1409                               (fnearbyint node:$src)]>;
1410def any_fceil      : PatFrags<(ops node:$src),
1411                              [(strict_fceil node:$src),
1412                               (fceil node:$src)]>;
1413def any_ffloor     : PatFrags<(ops node:$src),
1414                              [(strict_ffloor node:$src),
1415                               (ffloor node:$src)]>;
1416def any_lround     : PatFrags<(ops node:$src),
1417                              [(strict_lround node:$src),
1418                               (lround node:$src)]>;
1419def any_llround    : PatFrags<(ops node:$src),
1420                              [(strict_llround node:$src),
1421                               (llround node:$src)]>;
1422def any_fround     : PatFrags<(ops node:$src),
1423                              [(strict_fround node:$src),
1424                               (fround node:$src)]>;
1425def any_froundeven : PatFrags<(ops node:$src),
1426                              [(strict_froundeven node:$src),
1427                               (froundeven node:$src)]>;
1428def any_ftrunc     : PatFrags<(ops node:$src),
1429                              [(strict_ftrunc node:$src),
1430                               (ftrunc node:$src)]>;
1431def any_fmaxnum    : PatFrags<(ops node:$lhs, node:$rhs),
1432                              [(strict_fmaxnum node:$lhs, node:$rhs),
1433                               (fmaxnum node:$lhs, node:$rhs)]>;
1434def any_fminnum    : PatFrags<(ops node:$lhs, node:$rhs),
1435                              [(strict_fminnum node:$lhs, node:$rhs),
1436                               (fminnum node:$lhs, node:$rhs)]>;
1437def any_fmaximum   : PatFrags<(ops node:$lhs, node:$rhs),
1438                              [(strict_fmaximum node:$lhs, node:$rhs),
1439                               (fmaximum node:$lhs, node:$rhs)]>;
1440def any_fminimum   : PatFrags<(ops node:$lhs, node:$rhs),
1441                              [(strict_fminimum node:$lhs, node:$rhs),
1442                               (fminimum node:$lhs, node:$rhs)]>;
1443def any_fpround    : PatFrags<(ops node:$src),
1444                              [(strict_fpround node:$src),
1445                               (fpround node:$src)]>;
1446def any_fpextend   : PatFrags<(ops node:$src),
1447                              [(strict_fpextend node:$src),
1448                               (fpextend node:$src)]>;
1449def any_extloadf32 : PatFrags<(ops node:$ptr),
1450                              [(strict_extloadf32 node:$ptr),
1451                               (extloadf32 node:$ptr)]>;
1452def any_extloadf64 : PatFrags<(ops node:$ptr),
1453                              [(strict_extloadf64 node:$ptr),
1454                               (extloadf64 node:$ptr)]>;
1455def any_fp_to_sint : PatFrags<(ops node:$src),
1456                              [(strict_fp_to_sint node:$src),
1457                               (fp_to_sint node:$src)]>;
1458def any_fp_to_uint : PatFrags<(ops node:$src),
1459                              [(strict_fp_to_uint node:$src),
1460                               (fp_to_uint node:$src)]>;
1461def any_sint_to_fp : PatFrags<(ops node:$src),
1462                              [(strict_sint_to_fp node:$src),
1463                               (sint_to_fp node:$src)]>;
1464def any_uint_to_fp : PatFrags<(ops node:$src),
1465                              [(strict_uint_to_fp node:$src),
1466                               (uint_to_fp node:$src)]>;
1467def any_fsetcc : PatFrags<(ops node:$lhs, node:$rhs, node:$pred),
1468                          [(strict_fsetcc node:$lhs, node:$rhs, node:$pred),
1469                           (setcc node:$lhs, node:$rhs, node:$pred)]>;
1470def any_fsetccs : PatFrags<(ops node:$lhs, node:$rhs, node:$pred),
1471                          [(strict_fsetccs node:$lhs, node:$rhs, node:$pred),
1472                           (setcc node:$lhs, node:$rhs, node:$pred)]>;
1473
1474multiclass binary_atomic_op_ord<SDNode atomic_op> {
1475  def NAME#_monotonic : PatFrag<(ops node:$ptr, node:$val),
1476      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1477    let IsAtomic = true;
1478    let IsAtomicOrderingMonotonic = true;
1479  }
1480  def NAME#_acquire : PatFrag<(ops node:$ptr, node:$val),
1481      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1482    let IsAtomic = true;
1483    let IsAtomicOrderingAcquire = true;
1484  }
1485  def NAME#_release : PatFrag<(ops node:$ptr, node:$val),
1486      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1487    let IsAtomic = true;
1488    let IsAtomicOrderingRelease = true;
1489  }
1490  def NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$val),
1491      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1492    let IsAtomic = true;
1493    let IsAtomicOrderingAcquireRelease = true;
1494  }
1495  def NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$val),
1496      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1497    let IsAtomic = true;
1498    let IsAtomicOrderingSequentiallyConsistent = true;
1499  }
1500}
1501
1502multiclass ternary_atomic_op_ord<SDNode atomic_op> {
1503  def NAME#_monotonic : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1504      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1505    let IsAtomic = true;
1506    let IsAtomicOrderingMonotonic = true;
1507  }
1508  def NAME#_acquire : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1509      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1510    let IsAtomic = true;
1511    let IsAtomicOrderingAcquire = true;
1512  }
1513  def NAME#_release : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1514      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1515    let IsAtomic = true;
1516    let IsAtomicOrderingRelease = true;
1517  }
1518  def NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1519      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1520    let IsAtomic = true;
1521    let IsAtomicOrderingAcquireRelease = true;
1522  }
1523  def NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1524      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1525    let IsAtomic = true;
1526    let IsAtomicOrderingSequentiallyConsistent = true;
1527  }
1528}
1529
1530multiclass binary_atomic_op<SDNode atomic_op, bit IsInt = 1> {
1531  def _8 : PatFrag<(ops node:$ptr, node:$val),
1532                   (atomic_op  node:$ptr, node:$val)> {
1533    let IsAtomic = true;
1534    let MemoryVT = !if(IsInt, i8, ?);
1535  }
1536  def _16 : PatFrag<(ops node:$ptr, node:$val),
1537                    (atomic_op node:$ptr, node:$val)> {
1538    let IsAtomic = true;
1539    let MemoryVT = !if(IsInt, i16, f16);
1540  }
1541  def _32 : PatFrag<(ops node:$ptr, node:$val),
1542                    (atomic_op node:$ptr, node:$val)> {
1543    let IsAtomic = true;
1544    let MemoryVT = !if(IsInt, i32, f32);
1545  }
1546  def _64 : PatFrag<(ops node:$ptr, node:$val),
1547                    (atomic_op node:$ptr, node:$val)> {
1548    let IsAtomic = true;
1549    let MemoryVT = !if(IsInt, i64, f64);
1550  }
1551
1552  defm NAME#_8  : binary_atomic_op_ord<atomic_op>;
1553  defm NAME#_16 : binary_atomic_op_ord<atomic_op>;
1554  defm NAME#_32 : binary_atomic_op_ord<atomic_op>;
1555  defm NAME#_64 : binary_atomic_op_ord<atomic_op>;
1556}
1557
1558multiclass ternary_atomic_op<SDNode atomic_op> {
1559  def _8 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1560                   (atomic_op  node:$ptr, node:$cmp, node:$val)> {
1561    let IsAtomic = true;
1562    let MemoryVT = i8;
1563  }
1564  def _16 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1565                    (atomic_op node:$ptr, node:$cmp, node:$val)> {
1566    let IsAtomic = true;
1567    let MemoryVT = i16;
1568  }
1569  def _32 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1570                    (atomic_op node:$ptr, node:$cmp, node:$val)> {
1571    let IsAtomic = true;
1572    let MemoryVT = i32;
1573  }
1574  def _64 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1575                    (atomic_op node:$ptr, node:$cmp, node:$val)> {
1576    let IsAtomic = true;
1577    let MemoryVT = i64;
1578  }
1579
1580  defm NAME#_8  : ternary_atomic_op_ord<atomic_op>;
1581  defm NAME#_16 : ternary_atomic_op_ord<atomic_op>;
1582  defm NAME#_32 : ternary_atomic_op_ord<atomic_op>;
1583  defm NAME#_64 : ternary_atomic_op_ord<atomic_op>;
1584}
1585
1586defm atomic_load_add  : binary_atomic_op<atomic_load_add>;
1587defm atomic_swap      : binary_atomic_op<atomic_swap>;
1588defm atomic_load_sub  : binary_atomic_op<atomic_load_sub>;
1589defm atomic_load_and  : binary_atomic_op<atomic_load_and>;
1590defm atomic_load_clr  : binary_atomic_op<atomic_load_clr>;
1591defm atomic_load_or   : binary_atomic_op<atomic_load_or>;
1592defm atomic_load_xor  : binary_atomic_op<atomic_load_xor>;
1593defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
1594defm atomic_load_min  : binary_atomic_op<atomic_load_min>;
1595defm atomic_load_max  : binary_atomic_op<atomic_load_max>;
1596defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
1597defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
1598defm atomic_store     : binary_atomic_op<atomic_store>;
1599defm atomic_cmp_swap  : ternary_atomic_op<atomic_cmp_swap>;
1600
1601def atomic_load_8 :
1602  PatFrag<(ops node:$ptr),
1603          (atomic_load node:$ptr)> {
1604  let IsAtomic = true;
1605  let MemoryVT = i8;
1606}
1607def atomic_load_16 :
1608  PatFrag<(ops node:$ptr),
1609          (atomic_load node:$ptr)> {
1610  let IsAtomic = true;
1611  let MemoryVT = i16;
1612}
1613def atomic_load_32 :
1614  PatFrag<(ops node:$ptr),
1615          (atomic_load node:$ptr)> {
1616  let IsAtomic = true;
1617  let MemoryVT = i32;
1618}
1619def atomic_load_64 :
1620  PatFrag<(ops node:$ptr),
1621          (atomic_load node:$ptr)> {
1622  let IsAtomic = true;
1623  let MemoryVT = i64;
1624}
1625
1626//===----------------------------------------------------------------------===//
1627// Selection DAG Pattern Support.
1628//
1629// Patterns are what are actually matched against by the target-flavored
1630// instruction selection DAG.  Instructions defined by the target implicitly
1631// define patterns in most cases, but patterns can also be explicitly added when
1632// an operation is defined by a sequence of instructions (e.g. loading a large
1633// immediate value on RISC targets that do not support immediates as large as
1634// their GPRs).
1635//
1636
1637class Pattern<dag patternToMatch, list<dag> resultInstrs> {
1638  dag             PatternToMatch  = patternToMatch;
1639  list<dag>       ResultInstrs    = resultInstrs;
1640  list<Predicate> Predicates      = [];  // See class Instruction in Target.td.
1641  int             AddedComplexity = 0;   // See class Instruction in Target.td.
1642}
1643
1644// Pat - A simple (but common) form of a pattern, which produces a simple result
1645// not needing a full list.
1646class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
1647
1648//===----------------------------------------------------------------------===//
1649// Complex pattern definitions.
1650//
1651
1652// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
1653// in C++. NumOperands is the number of operands returned by the select function;
1654// SelectFunc is the name of the function used to pattern match the max. pattern;
1655// RootNodes are the list of possible root nodes of the sub-dags to match.
1656// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
1657//
1658class ComplexPattern<ValueType ty, int numops, string fn,
1659                     list<SDNode> roots = [], list<SDNodeProperty> props = [],
1660                     int complexity = -1> {
1661  ValueType Ty = ty;
1662  int NumOperands = numops;
1663  string SelectFunc = fn;
1664  list<SDNode> RootNodes = roots;
1665  list<SDNodeProperty> Properties = props;
1666  int Complexity = complexity;
1667}
1668