1 //===- TargetSelectionDAG.td - Common code for DAG isels ---*- 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 by SelectionDAG
10 // instruction selection generators.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Selection DAG Type Constraint definitions.
17 // Note that the semantics of these constraints are hard coded into tblgen. To
18 // modify or add constraints, you have to hack tblgen.
21 class SDTypeConstraint<int opnum> {
22 int OperandNum = opnum;
25 // SDTCisVT - The specified operand has exactly this VT.
26 class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
30 class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
32 // SDTCisInt - The specified operand has integer type.
33 class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
35 // SDTCisFP - The specified operand has floating-point type.
36 class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
38 // SDTCisVec - The specified operand has a vector type.
39 class SDTCisVec<int OpNum> : SDTypeConstraint<OpNum>;
41 // SDTCisSameAs - The two specified operands have identical types.
42 class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
43 int OtherOperandNum = OtherOp;
46 // SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
47 // smaller than the 'Other' operand.
48 class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
49 int OtherOperandNum = OtherOp;
52 class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
53 int BigOperandNum = BigOp;
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.
58 class SDTCisEltOfVec<int ThisOp, int OtherOp>
59 : SDTypeConstraint<ThisOp> {
60 int OtherOpNum = OtherOp;
63 /// SDTCisSubVecOfVec - This indicates that ThisOp is a vector type
64 /// with length less that of OtherOp, which is a vector type.
65 class SDTCisSubVecOfVec<int ThisOp, int OtherOp>
66 : SDTypeConstraint<ThisOp> {
67 int OtherOpNum = OtherOp;
70 // SDTCVecEltisVT - The specified operand is vector type with element type
72 class SDTCVecEltisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
76 // SDTCisSameNumEltsAs - The two specified operands have identical number
78 class SDTCisSameNumEltsAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
79 int OtherOperandNum = OtherOp;
82 // SDTCisSameSizeAs - The two specified operands have identical size.
83 class SDTCisSameSizeAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
84 int OtherOperandNum = OtherOp;
87 //===----------------------------------------------------------------------===//
88 // Selection DAG Type Profile definitions.
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.
95 // SDTypeProfile - This profile describes the type requirements of a Selection
97 class SDTypeProfile<int numresults, int numoperands,
98 list<SDTypeConstraint> constraints> {
99 int NumResults = numresults;
100 int NumOperands = numoperands;
101 list<SDTypeConstraint> Constraints = constraints;
105 def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
106 def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
107 def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
108 def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
109 def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
110 def SDTUnaryOp : SDTypeProfile<1, 1, []>; // for bitconvert.
112 def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
113 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
115 def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
116 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
118 def SDTIntShiftDOp: SDTypeProfile<1, 3, [ // fshl, fshr
119 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisInt<3>
121 def SDTIntSatNoShOp : SDTypeProfile<1, 2, [ // ssat with no shift
122 SDTCisSameAs<0, 1>, SDTCisInt<2>
124 def SDTIntBinHiLoOp : SDTypeProfile<2, 2, [ // mulhi, mullo, sdivrem, udivrem
125 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,SDTCisInt<0>
127 def SDTIntScaledBinOp : SDTypeProfile<1, 3, [ // smulfix, umulfix
128 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisInt<3>
131 def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
132 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
134 def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
135 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
137 def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
138 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
140 def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // bitreverse
141 SDTCisSameAs<0, 1>, SDTCisInt<0>
143 def SDTIntBitCountUnaryOp : SDTypeProfile<1, 1, [ // ctlz, cttz
144 SDTCisInt<0>, SDTCisInt<1>
146 def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
147 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
149 def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
150 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
152 def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
153 SDTCisSameAs<0, 1>, SDTCisFP<0>
155 def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
156 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
158 def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
159 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
161 def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
162 SDTCisFP<0>, SDTCisInt<1>, SDTCisSameNumEltsAs<0, 1>
164 def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
165 SDTCisInt<0>, SDTCisFP<1>, SDTCisSameNumEltsAs<0, 1>
167 def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
168 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
169 SDTCisVTSmallerThanOp<2, 1>
171 def SDTExtInvec : SDTypeProfile<1, 1, [ // sext_invec
172 SDTCisInt<0>, SDTCisVec<0>, SDTCisInt<1>, SDTCisVec<1>,
173 SDTCisOpSmallerThanOp<1, 0>
176 def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
177 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
180 def SDTSelect : SDTypeProfile<1, 3, [ // select
181 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
184 def SDTVSelect : SDTypeProfile<1, 3, [ // vselect
185 SDTCisVec<0>, SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>, SDTCisSameNumEltsAs<0, 1>
188 def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
189 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
193 def SDTBr : SDTypeProfile<0, 1, [ // br
197 def SDTBrCC : SDTypeProfile<0, 4, [ // brcc
198 SDTCisVT<0, OtherVT>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
201 def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
202 SDTCisInt<0>, SDTCisVT<1, OtherVT>
205 def SDTBrind : SDTypeProfile<0, 1, [ // brind
209 def SDTCatchret : SDTypeProfile<0, 2, [ // catchret
210 SDTCisVT<0, OtherVT>, SDTCisVT<1, OtherVT>
213 def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
215 def SDTLoad : SDTypeProfile<1, 1, [ // load
219 def SDTStore : SDTypeProfile<0, 2, [ // store
223 def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
224 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
227 def SDTMaskedStore: SDTypeProfile<0, 3, [ // masked store
228 SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVec<2>, SDTCisSameNumEltsAs<0, 2>
231 def SDTMaskedLoad: SDTypeProfile<1, 3, [ // masked load
232 SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVec<2>, SDTCisSameAs<0, 3>,
233 SDTCisSameNumEltsAs<0, 2>
236 def SDTVecShuffle : SDTypeProfile<1, 2, [
237 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>
239 def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
240 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
242 def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
243 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
245 def SDTVecReduce : SDTypeProfile<1, 1, [ // vector reduction
246 SDTCisInt<0>, SDTCisVec<1>
249 def SDTSubVecExtract : SDTypeProfile<1, 2, [// subvector extract
250 SDTCisSubVecOfVec<0,1>, SDTCisInt<2>
252 def SDTSubVecInsert : SDTypeProfile<1, 3, [ // subvector insert
253 SDTCisSubVecOfVec<2, 1>, SDTCisSameAs<0,1>, SDTCisInt<3>
256 def SDTPrefetch : SDTypeProfile<0, 4, [ // prefetch
257 SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisSameAs<1, 3>, SDTCisInt<1>
260 def SDTMemBarrier : SDTypeProfile<0, 5, [ // memory barrier
261 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
264 def SDTAtomicFence : SDTypeProfile<0, 2, [
265 SDTCisSameAs<0,1>, SDTCisPtrTy<0>
267 def SDTAtomic3 : SDTypeProfile<1, 3, [
268 SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
270 def SDTAtomic2 : SDTypeProfile<1, 2, [
271 SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
274 def SDTFPAtomic2 : SDTypeProfile<1, 2, [
275 SDTCisSameAs<0,2>, SDTCisFP<0>, SDTCisPtrTy<1>
278 def SDTAtomicStore : SDTypeProfile<0, 2, [
279 SDTCisPtrTy<0>, SDTCisInt<1>
281 def SDTAtomicLoad : SDTypeProfile<1, 1, [
282 SDTCisInt<0>, SDTCisPtrTy<1>
285 def SDTConvertOp : SDTypeProfile<1, 5, [ //cvtss, su, us, uu, ff, fs, fu, sf, su
286 SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>, SDTCisPtrTy<4>, SDTCisPtrTy<5>
289 class SDCallSeqStart<list<SDTypeConstraint> constraints> :
290 SDTypeProfile<0, 2, constraints>;
291 class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
292 SDTypeProfile<0, 2, constraints>;
294 //===----------------------------------------------------------------------===//
295 // Selection DAG Node definitions.
297 class SDNode<string opcode, SDTypeProfile typeprof,
298 list<SDNodeProperty> props = [], string sdclass = "SDNode">
299 : SDPatternOperator {
300 string Opcode = opcode;
301 string SDClass = sdclass;
302 let Properties = props;
303 SDTypeProfile TypeProfile = typeprof;
306 // Special TableGen-recognized dag nodes
312 def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
313 def timm : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
314 def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
315 def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
316 def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
317 def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
318 def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
319 def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
320 "GlobalAddressSDNode">;
321 def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
322 "GlobalAddressSDNode">;
323 def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
324 "GlobalAddressSDNode">;
325 def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
326 "GlobalAddressSDNode">;
327 def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
328 "ConstantPoolSDNode">;
329 def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
330 "ConstantPoolSDNode">;
331 def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
333 def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
335 def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
337 def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
339 def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
340 "ExternalSymbolSDNode">;
341 def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
342 "ExternalSymbolSDNode">;
343 def mcsym: SDNode<"ISD::MCSymbol", SDTPtrLeaf, [], "MCSymbolSDNode">;
344 def blockaddress : SDNode<"ISD::BlockAddress", SDTPtrLeaf, [],
345 "BlockAddressSDNode">;
346 def tblockaddress: SDNode<"ISD::TargetBlockAddress", SDTPtrLeaf, [],
347 "BlockAddressSDNode">;
349 def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
350 [SDNPCommutative, SDNPAssociative]>;
351 def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
352 def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
353 [SDNPCommutative, SDNPAssociative]>;
354 def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
355 def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
356 def smullohi : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
357 def umullohi : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
358 def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
359 def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
360 def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
361 def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
362 def sdivrem : SDNode<"ISD::SDIVREM" , SDTIntBinHiLoOp>;
363 def udivrem : SDNode<"ISD::UDIVREM" , SDTIntBinHiLoOp>;
364 def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
365 def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
366 def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
367 def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
368 def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
369 def fshl : SDNode<"ISD::FSHL" , SDTIntShiftDOp>;
370 def fshr : SDNode<"ISD::FSHR" , SDTIntShiftDOp>;
371 def and : SDNode<"ISD::AND" , SDTIntBinOp,
372 [SDNPCommutative, SDNPAssociative]>;
373 def or : SDNode<"ISD::OR" , SDTIntBinOp,
374 [SDNPCommutative, SDNPAssociative]>;
375 def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
376 [SDNPCommutative, SDNPAssociative]>;
377 def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
378 [SDNPCommutative, SDNPOutGlue]>;
379 def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
380 [SDNPCommutative, SDNPOutGlue, SDNPInGlue]>;
381 def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
383 def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
384 [SDNPOutGlue, SDNPInGlue]>;
385 def smin : SDNode<"ISD::SMIN" , SDTIntBinOp,
386 [SDNPCommutative, SDNPAssociative]>;
387 def smax : SDNode<"ISD::SMAX" , SDTIntBinOp,
388 [SDNPCommutative, SDNPAssociative]>;
389 def umin : SDNode<"ISD::UMIN" , SDTIntBinOp,
390 [SDNPCommutative, SDNPAssociative]>;
391 def umax : SDNode<"ISD::UMAX" , SDTIntBinOp,
392 [SDNPCommutative, SDNPAssociative]>;
394 def saddsat : SDNode<"ISD::SADDSAT" , SDTIntBinOp, [SDNPCommutative]>;
395 def uaddsat : SDNode<"ISD::UADDSAT" , SDTIntBinOp, [SDNPCommutative]>;
396 def ssubsat : SDNode<"ISD::SSUBSAT" , SDTIntBinOp>;
397 def usubsat : SDNode<"ISD::USUBSAT" , SDTIntBinOp>;
399 def smulfix : SDNode<"ISD::SMULFIX" , SDTIntScaledBinOp, [SDNPCommutative]>;
400 def smulfixsat : SDNode<"ISD::SMULFIXSAT", SDTIntScaledBinOp, [SDNPCommutative]>;
401 def umulfix : SDNode<"ISD::UMULFIX" , SDTIntScaledBinOp, [SDNPCommutative]>;
402 def umulfixsat : SDNode<"ISD::UMULFIXSAT", SDTIntScaledBinOp, [SDNPCommutative]>;
404 def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
405 def sext_invec : SDNode<"ISD::SIGN_EXTEND_VECTOR_INREG", SDTExtInvec>;
406 def zext_invec : SDNode<"ISD::ZERO_EXTEND_VECTOR_INREG", SDTExtInvec>;
408 def abs : SDNode<"ISD::ABS" , SDTIntUnaryOp>;
409 def bitreverse : SDNode<"ISD::BITREVERSE" , SDTIntUnaryOp>;
410 def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
411 def ctlz : SDNode<"ISD::CTLZ" , SDTIntBitCountUnaryOp>;
412 def cttz : SDNode<"ISD::CTTZ" , SDTIntBitCountUnaryOp>;
413 def ctpop : SDNode<"ISD::CTPOP" , SDTIntBitCountUnaryOp>;
414 def ctlz_zero_undef : SDNode<"ISD::CTLZ_ZERO_UNDEF", SDTIntBitCountUnaryOp>;
415 def cttz_zero_undef : SDNode<"ISD::CTTZ_ZERO_UNDEF", SDTIntBitCountUnaryOp>;
416 def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
417 def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
418 def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
419 def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
420 def bitconvert : SDNode<"ISD::BITCAST" , SDTUnaryOp>;
421 def addrspacecast : SDNode<"ISD::ADDRSPACECAST", SDTUnaryOp>;
422 def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
423 def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
425 def vecreduce_add : SDNode<"ISD::VECREDUCE_ADD", SDTVecReduce>;
426 def vecreduce_smax : SDNode<"ISD::VECREDUCE_SMAX", SDTVecReduce>;
427 def vecreduce_umax : SDNode<"ISD::VECREDUCE_UMAX", SDTVecReduce>;
428 def vecreduce_smin : SDNode<"ISD::VECREDUCE_SMIN", SDTVecReduce>;
429 def vecreduce_umin : SDNode<"ISD::VECREDUCE_UMIN", SDTVecReduce>;
431 def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
432 def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
433 def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
434 def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
435 def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
436 def fma : SDNode<"ISD::FMA" , SDTFPTernaryOp>;
437 def fmad : SDNode<"ISD::FMAD" , SDTFPTernaryOp>;
438 def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
439 def fminnum : SDNode<"ISD::FMINNUM" , SDTFPBinOp,
440 [SDNPCommutative, SDNPAssociative]>;
441 def fmaxnum : SDNode<"ISD::FMAXNUM" , SDTFPBinOp,
442 [SDNPCommutative, SDNPAssociative]>;
443 def fminnum_ieee : SDNode<"ISD::FMINNUM_IEEE", SDTFPBinOp,
445 def fmaxnum_ieee : SDNode<"ISD::FMAXNUM_IEEE", SDTFPBinOp,
447 def fminimum : SDNode<"ISD::FMINIMUM" , SDTFPBinOp,
448 [SDNPCommutative, SDNPAssociative]>;
449 def fmaximum : SDNode<"ISD::FMAXIMUM" , SDTFPBinOp,
450 [SDNPCommutative, SDNPAssociative]>;
451 def fgetsign : SDNode<"ISD::FGETSIGN" , SDTFPToIntOp>;
452 def fcanonicalize : SDNode<"ISD::FCANONICALIZE", SDTFPUnaryOp>;
453 def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
454 def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
455 def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
456 def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
457 def fexp2 : SDNode<"ISD::FEXP2" , SDTFPUnaryOp>;
458 def fpow : SDNode<"ISD::FPOW" , SDTFPBinOp>;
459 def flog2 : SDNode<"ISD::FLOG2" , SDTFPUnaryOp>;
460 def frint : SDNode<"ISD::FRINT" , SDTFPUnaryOp>;
461 def ftrunc : SDNode<"ISD::FTRUNC" , SDTFPUnaryOp>;
462 def fceil : SDNode<"ISD::FCEIL" , SDTFPUnaryOp>;
463 def ffloor : SDNode<"ISD::FFLOOR" , SDTFPUnaryOp>;
464 def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
465 def fround : SDNode<"ISD::FROUND" , SDTFPUnaryOp>;
467 def lround : SDNode<"ISD::LROUND" , SDTFPToIntOp>;
468 def llround : SDNode<"ISD::LLROUND" , SDTFPToIntOp>;
469 def lrint : SDNode<"ISD::LRINT" , SDTFPToIntOp>;
470 def llrint : SDNode<"ISD::LLRINT" , SDTFPToIntOp>;
472 def fpround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
473 def fpextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
474 def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
476 def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
477 def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
478 def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
479 def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
480 def f16_to_fp : SDNode<"ISD::FP16_TO_FP" , SDTIntToFPOp>;
481 def fp_to_f16 : SDNode<"ISD::FP_TO_FP16" , SDTFPToIntOp>;
483 def strict_fadd : SDNode<"ISD::STRICT_FADD",
484 SDTFPBinOp, [SDNPHasChain, SDNPCommutative]>;
485 def strict_fsub : SDNode<"ISD::STRICT_FSUB",
486 SDTFPBinOp, [SDNPHasChain]>;
487 def strict_fmul : SDNode<"ISD::STRICT_FMUL",
488 SDTFPBinOp, [SDNPHasChain, SDNPCommutative]>;
489 def strict_fdiv : SDNode<"ISD::STRICT_FDIV",
490 SDTFPBinOp, [SDNPHasChain]>;
491 def strict_frem : SDNode<"ISD::STRICT_FREM",
492 SDTFPBinOp, [SDNPHasChain]>;
493 def strict_fma : SDNode<"ISD::STRICT_FMA",
494 SDTFPTernaryOp, [SDNPHasChain]>;
495 def strict_fsqrt : SDNode<"ISD::STRICT_FSQRT",
496 SDTFPUnaryOp, [SDNPHasChain]>;
497 def strict_fsin : SDNode<"ISD::STRICT_FSIN",
498 SDTFPUnaryOp, [SDNPHasChain]>;
499 def strict_fcos : SDNode<"ISD::STRICT_FCOS",
500 SDTFPUnaryOp, [SDNPHasChain]>;
501 def strict_fexp2 : SDNode<"ISD::STRICT_FEXP2",
502 SDTFPUnaryOp, [SDNPHasChain]>;
503 def strict_fpow : SDNode<"ISD::STRICT_FPOW",
504 SDTFPBinOp, [SDNPHasChain]>;
505 def strict_flog2 : SDNode<"ISD::STRICT_FLOG2",
506 SDTFPUnaryOp, [SDNPHasChain]>;
507 def strict_frint : SDNode<"ISD::STRICT_FRINT",
508 SDTFPUnaryOp, [SDNPHasChain]>;
509 def strict_lrint : SDNode<"ISD::STRICT_LRINT",
510 SDTFPToIntOp, [SDNPHasChain]>;
511 def strict_llrint : SDNode<"ISD::STRICT_LLRINT",
512 SDTFPToIntOp, [SDNPHasChain]>;
513 def strict_fnearbyint : SDNode<"ISD::STRICT_FNEARBYINT",
514 SDTFPUnaryOp, [SDNPHasChain]>;
515 def strict_fceil : SDNode<"ISD::STRICT_FCEIL",
516 SDTFPUnaryOp, [SDNPHasChain]>;
517 def strict_ffloor : SDNode<"ISD::STRICT_FFLOOR",
518 SDTFPUnaryOp, [SDNPHasChain]>;
519 def strict_lround : SDNode<"ISD::STRICT_LROUND",
520 SDTFPToIntOp, [SDNPHasChain]>;
521 def strict_llround : SDNode<"ISD::STRICT_LLROUND",
522 SDTFPToIntOp, [SDNPHasChain]>;
523 def strict_fround : SDNode<"ISD::STRICT_FROUND",
524 SDTFPUnaryOp, [SDNPHasChain]>;
525 def strict_ftrunc : SDNode<"ISD::STRICT_FTRUNC",
526 SDTFPUnaryOp, [SDNPHasChain]>;
527 def strict_fminnum : SDNode<"ISD::STRICT_FMINNUM",
528 SDTFPBinOp, [SDNPHasChain,
529 SDNPCommutative, SDNPAssociative]>;
530 def strict_fmaxnum : SDNode<"ISD::STRICT_FMAXNUM",
531 SDTFPBinOp, [SDNPHasChain,
532 SDNPCommutative, SDNPAssociative]>;
533 def strict_fpround : SDNode<"ISD::STRICT_FP_ROUND",
534 SDTFPRoundOp, [SDNPHasChain]>;
535 def strict_fpextend : SDNode<"ISD::STRICT_FP_EXTEND",
536 SDTFPExtendOp, [SDNPHasChain]>;
537 def strict_fp_to_sint : SDNode<"ISD::STRICT_FP_TO_SINT",
538 SDTFPToIntOp, [SDNPHasChain]>;
539 def strict_fp_to_uint : SDNode<"ISD::STRICT_FP_TO_UINT",
540 SDTFPToIntOp, [SDNPHasChain]>;
542 def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
543 def select : SDNode<"ISD::SELECT" , SDTSelect>;
544 def vselect : SDNode<"ISD::VSELECT" , SDTVSelect>;
545 def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
547 def brcc : SDNode<"ISD::BR_CC" , SDTBrCC, [SDNPHasChain]>;
548 def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
549 def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
550 def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
551 def catchret : SDNode<"ISD::CATCHRET" , SDTCatchret,
552 [SDNPHasChain, SDNPSideEffect]>;
553 def cleanupret : SDNode<"ISD::CLEANUPRET" , SDTNone, [SDNPHasChain]>;
554 def catchpad : SDNode<"ISD::CATCHPAD" , SDTNone,
555 [SDNPHasChain, SDNPSideEffect]>;
557 def trap : SDNode<"ISD::TRAP" , SDTNone,
558 [SDNPHasChain, SDNPSideEffect]>;
559 def debugtrap : SDNode<"ISD::DEBUGTRAP" , SDTNone,
560 [SDNPHasChain, SDNPSideEffect]>;
562 def prefetch : SDNode<"ISD::PREFETCH" , SDTPrefetch,
563 [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
566 def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
567 [SDNPHasChain, SDNPSideEffect]>;
569 def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
570 [SDNPHasChain, SDNPSideEffect]>;
572 def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
573 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
574 def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
575 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
576 def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
577 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
578 def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
579 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
580 def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
581 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
582 def atomic_load_clr : SDNode<"ISD::ATOMIC_LOAD_CLR" , SDTAtomic2,
583 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
584 def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
585 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
586 def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
587 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
588 def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
589 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
590 def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
591 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
592 def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
593 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
594 def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
595 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
596 def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
597 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
598 def atomic_load_fadd : SDNode<"ISD::ATOMIC_LOAD_FADD" , SDTFPAtomic2,
599 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
600 def atomic_load_fsub : SDNode<"ISD::ATOMIC_LOAD_FSUB" , SDTFPAtomic2,
601 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
603 def atomic_load : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
604 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
605 def atomic_store : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
606 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
608 def masked_st : SDNode<"ISD::MSTORE", SDTMaskedStore,
609 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
610 def masked_ld : SDNode<"ISD::MLOAD", SDTMaskedLoad,
611 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
613 // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
614 // and truncst (see below).
615 def ld : SDNode<"ISD::LOAD" , SDTLoad,
616 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
617 def st : SDNode<"ISD::STORE" , SDTStore,
618 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
619 def ist : SDNode<"ISD::STORE" , SDTIStore,
620 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
622 def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
623 def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
624 def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
627 // vector_extract/vector_insert are deprecated. extractelt/insertelt
629 def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
630 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
631 def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
632 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
633 def concat_vectors : SDNode<"ISD::CONCAT_VECTORS",
634 SDTypeProfile<1, 2, [SDTCisSubVecOfVec<1, 0>, SDTCisSameAs<1, 2>]>,[]>;
636 // This operator does not do subvector type checking. The ARM
637 // backend, at least, needs it.
638 def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
639 SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
642 // This operator does subvector type checking.
643 def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
644 def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
646 // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
647 // these internally. Don't reference these directly.
648 def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
649 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
651 def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
652 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
654 def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
655 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
657 def SDT_assertext : SDTypeProfile<1, 1,
658 [SDTCisInt<0>, SDTCisInt<1>, SDTCisSameAs<1, 0>]>;
659 def assertsext : SDNode<"ISD::AssertSext", SDT_assertext>;
660 def assertzext : SDNode<"ISD::AssertZext", SDT_assertext>;
663 //===----------------------------------------------------------------------===//
664 // Selection DAG Condition Codes
666 class CondCode<string fcmpName = "", string icmpName = ""> {
667 string ICmpPredicate = icmpName;
668 string FCmpPredicate = fcmpName;
671 // ISD::CondCode enums, and mapping to CmpInst::Predicate names
672 def SETOEQ : CondCode<"FCMP_OEQ">;
673 def SETOGT : CondCode<"FCMP_OGT">;
674 def SETOGE : CondCode<"FCMP_OGE">;
675 def SETOLT : CondCode<"FCMP_OLT">;
676 def SETOLE : CondCode<"FCMP_OLE">;
677 def SETONE : CondCode<"FCMP_ONE">;
678 def SETO : CondCode<"FCMP_ORD">;
679 def SETUO : CondCode<"FCMP_UNO">;
680 def SETUEQ : CondCode<"FCMP_UEQ">;
681 def SETUGT : CondCode<"FCMP_UGT", "ICMP_UGT">;
682 def SETUGE : CondCode<"FCMP_UGE", "ICMP_UGE">;
683 def SETULT : CondCode<"FCMP_ULT", "ICMP_ULT">;
684 def SETULE : CondCode<"FCMP_ULE", "ICMP_ULE">;
685 def SETUNE : CondCode<"FCMP_UNE">;
686 def SETEQ : CondCode<"", "ICMP_EQ">;
687 def SETGT : CondCode<"", "ICMP_SGT">;
688 def SETGE : CondCode<"", "ICMP_SGE">;
689 def SETLT : CondCode<"", "ICMP_SLT">;
690 def SETLE : CondCode<"", "ICMP_SLE">;
691 def SETNE : CondCode<"", "ICMP_NE">;
693 //===----------------------------------------------------------------------===//
694 // Selection DAG Node Transformation Functions.
696 // This mechanism allows targets to manipulate nodes in the output DAG once a
697 // match has been formed. This is typically used to manipulate immediate
700 class SDNodeXForm<SDNode opc, code xformFunction> {
702 code XFormFunction = xformFunction;
705 def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
707 //===----------------------------------------------------------------------===//
708 // PatPred Subclasses.
710 // These allow specifying different sorts of predicates that control whether a
715 class CodePatPred<code predicate> : PatPred {
716 code PredicateCode = predicate;
720 //===----------------------------------------------------------------------===//
721 // Selection DAG Pattern Fragments.
723 // Pattern fragments are reusable chunks of dags that match specific things.
724 // They can take arguments and have C++ predicates that control whether they
725 // match. They are intended to make the patterns for common instructions more
726 // compact and readable.
729 /// PatFrags - Represents a set of pattern fragments. Each single fragment
730 /// can match something on the DAG, from a single node to multiple nested other
731 /// fragments. The whole set of fragments matches if any of the single
732 /// fragemnts match. This allows e.g. matching and "add with overflow" and
733 /// a regular "add" with the same fragment set.
735 class PatFrags<dag ops, list<dag> frags, code pred = [{}],
736 SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
738 list<dag> Fragments = frags;
739 code PredicateCode = pred;
740 code GISelPredicateCode = [{}];
741 code ImmediateCode = [{}];
742 SDNodeXForm OperandTransform = xform;
744 // When this is set, the PredicateCode may refer to a constant Operands
745 // vector which contains the captured nodes of the DAG, in the order listed
746 // by the Operands field above.
748 // This is useful when Fragments involves associative / commutative
749 // operators: a single piece of code can easily refer to all operands even
750 // when re-associated / commuted variants of the fragment are matched.
751 bit PredicateCodeUsesOperands = 0;
753 // Define a few pre-packaged predicates. This helps GlobalISel import
754 // existing rules from SelectionDAG for many common cases.
755 // They will be tested prior to the code in pred and must not be used in
756 // ImmLeaf and its subclasses.
758 // Is the desired pre-packaged predicate for a load?
760 // Is the desired pre-packaged predicate for a store?
762 // Is the desired pre-packaged predicate for an atomic?
765 // cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
766 // cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
769 // cast<LoadSDNode>(N)->getExtensionType() != ISD::NON_EXTLOAD
770 bit IsNonExtLoad = ?;
771 // cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
772 bit IsAnyExtLoad = ?;
773 // cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
774 bit IsSignExtLoad = ?;
775 // cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
776 bit IsZeroExtLoad = ?;
777 // !cast<StoreSDNode>(N)->isTruncatingStore();
778 // cast<StoreSDNode>(N)->isTruncatingStore();
779 bit IsTruncStore = ?;
781 // cast<MemSDNode>(N)->getAddressSpace() ==
782 // If this empty, accept any address space.
783 list<int> AddressSpaces = ?;
785 // cast<MemSDNode>(N)->getAlignment() >=
786 // If this is empty, accept any alignment.
787 int MinAlignment = ?;
789 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Monotonic
790 bit IsAtomicOrderingMonotonic = ?;
791 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Acquire
792 bit IsAtomicOrderingAcquire = ?;
793 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Release
794 bit IsAtomicOrderingRelease = ?;
795 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::AcquireRelease
796 bit IsAtomicOrderingAcquireRelease = ?;
797 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::SequentiallyConsistent
798 bit IsAtomicOrderingSequentiallyConsistent = ?;
800 // isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
801 // !isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
802 bit IsAtomicOrderingAcquireOrStronger = ?;
804 // isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
805 // !isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
806 bit IsAtomicOrderingReleaseOrStronger = ?;
808 // cast<LoadSDNode>(N)->getMemoryVT() == MVT::<VT>;
809 // cast<StoreSDNode>(N)->getMemoryVT() == MVT::<VT>;
810 ValueType MemoryVT = ?;
811 // cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
812 // cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
813 ValueType ScalarMemoryVT = ?;
816 // PatFrag - A version of PatFrags matching only a single fragment.
817 class PatFrag<dag ops, dag frag, code pred = [{}],
818 SDNodeXForm xform = NOOP_SDNodeXForm>
819 : PatFrags<ops, [frag], pred, xform>;
821 // OutPatFrag is a pattern fragment that is used as part of an output pattern
822 // (not an input pattern). These do not have predicates or transforms, but are
823 // used to avoid repeated subexpressions in output patterns.
824 class OutPatFrag<dag ops, dag frag>
825 : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;
827 // PatLeaf's are pattern fragments that have no operands. This is just a helper
828 // to define immediates and other common things concisely.
829 class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
830 : PatFrag<(ops), frag, pred, xform>;
833 // ImmLeaf is a pattern fragment with a constraint on the immediate. The
834 // constraint is a function that is run on the immediate (always with the value
835 // sign extended out to an int64_t) as Imm. For example:
837 // def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
839 // this is a more convenient form to match 'imm' nodes in than PatLeaf and also
840 // is preferred over using PatLeaf because it allows the code generator to
841 // reason more about the constraint.
843 // If FastIsel should ignore all instructions that have an operand of this type,
844 // the FastIselShouldIgnore flag can be set. This is an optimization to reduce
845 // the code size of the generated fast instruction selector.
846 class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
847 SDNode ImmNode = imm>
848 : PatFrag<(ops), (vt ImmNode), [{}], xform> {
849 let ImmediateCode = pred;
850 bit FastIselShouldIgnore = 0;
852 // Is the data type of the immediate an APInt?
855 // Is the data type of the immediate an APFloat?
859 // Convenience wrapper for ImmLeaf to use timm/TargetConstant instead
861 class TImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
862 SDNode ImmNode = timm> : ImmLeaf<vt, pred, xform, ImmNode>;
864 // An ImmLeaf except that Imm is an APInt. This is useful when you need to
865 // zero-extend the immediate instead of sign-extend it.
867 // Note that FastISel does not currently understand IntImmLeaf and will not
868 // generate code for rules that make use of it. As such, it does not make sense
869 // to replace ImmLeaf with IntImmLeaf. However, replacing PatLeaf with an
870 // IntImmLeaf will allow GlobalISel to import the rule.
871 class IntImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
872 : ImmLeaf<vt, pred, xform> {
874 let FastIselShouldIgnore = 1;
877 // An ImmLeaf except that Imm is an APFloat.
879 // Note that FastISel does not currently understand FPImmLeaf and will not
880 // generate code for rules that make use of it.
881 class FPImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
882 : ImmLeaf<vt, pred, xform, fpimm> {
884 let FastIselShouldIgnore = 1;
889 def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
890 def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
892 // Use ISD::isBuildVectorAllOnes or ISD::isBuildVectorAllZeros to look for
893 // the corresponding build_vector. Will look through bitcasts except when used
894 // as a pattern root.
895 def immAllOnesV; // ISD::isBuildVectorAllOnes
896 def immAllZerosV; // ISD::isBuildVectorAllZeros
898 // Other helper fragments.
899 def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
900 def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
901 def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
903 // null_frag - The null pattern operator is used in multiclass instantiations
904 // which accept an SDPatternOperator for use in matching patterns for internal
905 // definitions. When expanding a pattern, if the null fragment is referenced
906 // in the expansion, the pattern is discarded and it is as-if '[]' had been
907 // specified. This allows multiclasses to have the isel patterns be optional.
908 def null_frag : SDPatternOperator;
911 def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr)> {
915 def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
917 let IsNonExtLoad = 1;
920 // extending load fragments.
921 def extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
923 let IsAnyExtLoad = 1;
925 def sextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
927 let IsSignExtLoad = 1;
929 def zextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
931 let IsZeroExtLoad = 1;
934 def extloadi1 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
938 def extloadi8 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
942 def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
946 def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
950 def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
954 def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
959 def sextloadi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
963 def sextloadi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
967 def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
971 def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
976 def zextloadi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
980 def zextloadi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
984 def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
988 def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
993 def extloadvi1 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
995 let ScalarMemoryVT = i1;
997 def extloadvi8 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
999 let ScalarMemoryVT = i8;
1001 def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1003 let ScalarMemoryVT = i16;
1005 def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1007 let ScalarMemoryVT = i32;
1009 def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1011 let ScalarMemoryVT = f32;
1013 def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1015 let ScalarMemoryVT = f64;
1018 def sextloadvi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1020 let ScalarMemoryVT = i1;
1022 def sextloadvi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1024 let ScalarMemoryVT = i8;
1026 def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1028 let ScalarMemoryVT = i16;
1030 def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1032 let ScalarMemoryVT = i32;
1035 def zextloadvi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1037 let ScalarMemoryVT = i1;
1039 def zextloadvi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1041 let ScalarMemoryVT = i8;
1043 def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1045 let ScalarMemoryVT = i16;
1047 def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1049 let ScalarMemoryVT = i32;
1053 def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
1054 (st node:$val, node:$ptr)> {
1056 let IsUnindexed = 1;
1058 def store : PatFrag<(ops node:$val, node:$ptr),
1059 (unindexedstore node:$val, node:$ptr)> {
1061 let IsTruncStore = 0;
1064 // truncstore fragments.
1065 def truncstore : PatFrag<(ops node:$val, node:$ptr),
1066 (unindexedstore node:$val, node:$ptr)> {
1068 let IsTruncStore = 1;
1070 def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
1071 (truncstore node:$val, node:$ptr)> {
1075 def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
1076 (truncstore node:$val, node:$ptr)> {
1080 def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
1081 (truncstore node:$val, node:$ptr)> {
1085 def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
1086 (truncstore node:$val, node:$ptr)> {
1090 def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
1091 (truncstore node:$val, node:$ptr)> {
1096 def truncstorevi8 : PatFrag<(ops node:$val, node:$ptr),
1097 (truncstore node:$val, node:$ptr)> {
1099 let ScalarMemoryVT = i8;
1102 def truncstorevi16 : PatFrag<(ops node:$val, node:$ptr),
1103 (truncstore node:$val, node:$ptr)> {
1105 let ScalarMemoryVT = i16;
1108 def truncstorevi32 : PatFrag<(ops node:$val, node:$ptr),
1109 (truncstore node:$val, node:$ptr)> {
1111 let ScalarMemoryVT = i32;
1114 // indexed store fragments.
1115 def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
1116 (ist node:$val, node:$base, node:$offset)> {
1118 let IsTruncStore = 0;
1121 def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
1122 (istore node:$val, node:$base, node:$offset), [{
1123 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1124 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1127 def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
1128 (ist node:$val, node:$base, node:$offset)> {
1130 let IsTruncStore = 1;
1132 def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1133 (itruncstore node:$val, node:$base, node:$offset), [{
1134 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1135 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1137 def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1138 (pre_truncst node:$val, node:$base, node:$offset)> {
1142 def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1143 (pre_truncst node:$val, node:$base, node:$offset)> {
1147 def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1148 (pre_truncst node:$val, node:$base, node:$offset)> {
1152 def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1153 (pre_truncst node:$val, node:$base, node:$offset)> {
1157 def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1158 (pre_truncst node:$val, node:$base, node:$offset)> {
1162 def pre_truncstvi8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1163 (pre_truncst node:$val, node:$base, node:$offset)> {
1165 let ScalarMemoryVT = i8;
1167 def pre_truncstvi16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1168 (pre_truncst node:$val, node:$base, node:$offset)> {
1170 let ScalarMemoryVT = i16;
1173 def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
1174 (istore node:$val, node:$ptr, node:$offset), [{
1175 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1176 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1179 def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1180 (itruncstore node:$val, node:$base, node:$offset), [{
1181 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1182 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1184 def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1185 (post_truncst node:$val, node:$base, node:$offset)> {
1189 def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1190 (post_truncst node:$val, node:$base, node:$offset)> {
1194 def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1195 (post_truncst node:$val, node:$base, node:$offset)> {
1199 def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1200 (post_truncst node:$val, node:$base, node:$offset)> {
1204 def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1205 (post_truncst node:$val, node:$base, node:$offset)> {
1209 def post_truncstvi8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1210 (post_truncst node:$val, node:$base, node:$offset)> {
1212 let ScalarMemoryVT = i8;
1214 def post_truncstvi16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1215 (post_truncst node:$val, node:$base, node:$offset)> {
1217 let ScalarMemoryVT = i16;
1220 // TODO: Split these into volatile and unordered flavors to enable
1221 // selectively legal optimizations for each. (See D66309)
1222 def simple_load : PatFrag<(ops node:$ptr),
1223 (load node:$ptr), [{
1224 return cast<LoadSDNode>(N)->isSimple();
1226 def simple_store : PatFrag<(ops node:$val, node:$ptr),
1227 (store node:$val, node:$ptr), [{
1228 return cast<StoreSDNode>(N)->isSimple();
1231 // nontemporal store fragments.
1232 def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1233 (store node:$val, node:$ptr), [{
1234 return cast<StoreSDNode>(N)->isNonTemporal();
1237 def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1238 (nontemporalstore node:$val, node:$ptr), [{
1239 StoreSDNode *St = cast<StoreSDNode>(N);
1240 return St->getAlignment() >= St->getMemoryVT().getStoreSize();
1243 def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1244 (nontemporalstore node:$val, node:$ptr), [{
1245 StoreSDNode *St = cast<StoreSDNode>(N);
1246 return St->getAlignment() < St->getMemoryVT().getStoreSize();
1249 // nontemporal load fragments.
1250 def nontemporalload : PatFrag<(ops node:$ptr),
1251 (load node:$ptr), [{
1252 return cast<LoadSDNode>(N)->isNonTemporal();
1255 def alignednontemporalload : PatFrag<(ops node:$ptr),
1256 (nontemporalload node:$ptr), [{
1257 LoadSDNode *Ld = cast<LoadSDNode>(N);
1258 return Ld->getAlignment() >= Ld->getMemoryVT().getStoreSize();
1261 // setcc convenience fragments.
1262 def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
1263 (setcc node:$lhs, node:$rhs, SETOEQ)>;
1264 def setogt : PatFrag<(ops node:$lhs, node:$rhs),
1265 (setcc node:$lhs, node:$rhs, SETOGT)>;
1266 def setoge : PatFrag<(ops node:$lhs, node:$rhs),
1267 (setcc node:$lhs, node:$rhs, SETOGE)>;
1268 def setolt : PatFrag<(ops node:$lhs, node:$rhs),
1269 (setcc node:$lhs, node:$rhs, SETOLT)>;
1270 def setole : PatFrag<(ops node:$lhs, node:$rhs),
1271 (setcc node:$lhs, node:$rhs, SETOLE)>;
1272 def setone : PatFrag<(ops node:$lhs, node:$rhs),
1273 (setcc node:$lhs, node:$rhs, SETONE)>;
1274 def seto : PatFrag<(ops node:$lhs, node:$rhs),
1275 (setcc node:$lhs, node:$rhs, SETO)>;
1276 def setuo : PatFrag<(ops node:$lhs, node:$rhs),
1277 (setcc node:$lhs, node:$rhs, SETUO)>;
1278 def setueq : PatFrag<(ops node:$lhs, node:$rhs),
1279 (setcc node:$lhs, node:$rhs, SETUEQ)>;
1280 def setugt : PatFrag<(ops node:$lhs, node:$rhs),
1281 (setcc node:$lhs, node:$rhs, SETUGT)>;
1282 def setuge : PatFrag<(ops node:$lhs, node:$rhs),
1283 (setcc node:$lhs, node:$rhs, SETUGE)>;
1284 def setult : PatFrag<(ops node:$lhs, node:$rhs),
1285 (setcc node:$lhs, node:$rhs, SETULT)>;
1286 def setule : PatFrag<(ops node:$lhs, node:$rhs),
1287 (setcc node:$lhs, node:$rhs, SETULE)>;
1288 def setune : PatFrag<(ops node:$lhs, node:$rhs),
1289 (setcc node:$lhs, node:$rhs, SETUNE)>;
1290 def seteq : PatFrag<(ops node:$lhs, node:$rhs),
1291 (setcc node:$lhs, node:$rhs, SETEQ)>;
1292 def setgt : PatFrag<(ops node:$lhs, node:$rhs),
1293 (setcc node:$lhs, node:$rhs, SETGT)>;
1294 def setge : PatFrag<(ops node:$lhs, node:$rhs),
1295 (setcc node:$lhs, node:$rhs, SETGE)>;
1296 def setlt : PatFrag<(ops node:$lhs, node:$rhs),
1297 (setcc node:$lhs, node:$rhs, SETLT)>;
1298 def setle : PatFrag<(ops node:$lhs, node:$rhs),
1299 (setcc node:$lhs, node:$rhs, SETLE)>;
1300 def setne : PatFrag<(ops node:$lhs, node:$rhs),
1301 (setcc node:$lhs, node:$rhs, SETNE)>;
1303 // We don't have strict FP extended loads as single DAG nodes, but we can
1304 // still provide convenience fragments to match those operations.
1305 def strict_extloadf32 : PatFrag<(ops node:$ptr),
1306 (strict_fpextend (f32 (load node:$ptr)))>;
1307 def strict_extloadf64 : PatFrag<(ops node:$ptr),
1308 (strict_fpextend (f64 (load node:$ptr)))>;
1310 // Convenience fragments to match both strict and non-strict fp operations
1311 def any_fadd : PatFrags<(ops node:$lhs, node:$rhs),
1312 [(strict_fadd node:$lhs, node:$rhs),
1313 (fadd node:$lhs, node:$rhs)]>;
1314 def any_fsub : PatFrags<(ops node:$lhs, node:$rhs),
1315 [(strict_fsub node:$lhs, node:$rhs),
1316 (fsub node:$lhs, node:$rhs)]>;
1317 def any_fmul : PatFrags<(ops node:$lhs, node:$rhs),
1318 [(strict_fmul node:$lhs, node:$rhs),
1319 (fmul node:$lhs, node:$rhs)]>;
1320 def any_fdiv : PatFrags<(ops node:$lhs, node:$rhs),
1321 [(strict_fdiv node:$lhs, node:$rhs),
1322 (fdiv node:$lhs, node:$rhs)]>;
1323 def any_frem : PatFrags<(ops node:$lhs, node:$rhs),
1324 [(strict_frem node:$lhs, node:$rhs),
1325 (frem node:$lhs, node:$rhs)]>;
1326 def any_fma : PatFrags<(ops node:$src1, node:$src2, node:$src3),
1327 [(strict_fma node:$src1, node:$src2, node:$src3),
1328 (fma node:$src1, node:$src2, node:$src3)]>;
1329 def any_fsqrt : PatFrags<(ops node:$src),
1330 [(strict_fsqrt node:$src),
1331 (fsqrt node:$src)]>;
1332 def any_fsin : PatFrags<(ops node:$src),
1333 [(strict_fsin node:$src),
1335 def any_fcos : PatFrags<(ops node:$src),
1336 [(strict_fcos node:$src),
1338 def any_fexp2 : PatFrags<(ops node:$src),
1339 [(strict_fexp2 node:$src),
1340 (fexp2 node:$src)]>;
1341 def any_fpow : PatFrags<(ops node:$lhs, node:$rhs),
1342 [(strict_fpow node:$lhs, node:$rhs),
1343 (fpow node:$lhs, node:$rhs)]>;
1344 def any_flog2 : PatFrags<(ops node:$src),
1345 [(strict_flog2 node:$src),
1346 (flog2 node:$src)]>;
1347 def any_frint : PatFrags<(ops node:$src),
1348 [(strict_frint node:$src),
1349 (frint node:$src)]>;
1350 def any_lrint : PatFrags<(ops node:$src),
1351 [(strict_lrint node:$src),
1352 (lrint node:$src)]>;
1353 def any_llrint : PatFrags<(ops node:$src),
1354 [(strict_llrint node:$src),
1355 (llrint node:$src)]>;
1356 def any_fnearbyint : PatFrags<(ops node:$src),
1357 [(strict_fnearbyint node:$src),
1358 (fnearbyint node:$src)]>;
1359 def any_fceil : PatFrags<(ops node:$src),
1360 [(strict_fceil node:$src),
1361 (fceil node:$src)]>;
1362 def any_ffloor : PatFrags<(ops node:$src),
1363 [(strict_ffloor node:$src),
1364 (ffloor node:$src)]>;
1365 def any_lround : PatFrags<(ops node:$src),
1366 [(strict_lround node:$src),
1367 (lround node:$src)]>;
1368 def any_llround : PatFrags<(ops node:$src),
1369 [(strict_llround node:$src),
1370 (llround node:$src)]>;
1371 def any_fround : PatFrags<(ops node:$src),
1372 [(strict_fround node:$src),
1373 (fround node:$src)]>;
1374 def any_ftrunc : PatFrags<(ops node:$src),
1375 [(strict_ftrunc node:$src),
1376 (ftrunc node:$src)]>;
1377 def any_fmaxnum : PatFrags<(ops node:$lhs, node:$rhs),
1378 [(strict_fmaxnum node:$lhs, node:$rhs),
1379 (fmaxnum node:$lhs, node:$rhs)]>;
1380 def any_fminnum : PatFrags<(ops node:$lhs, node:$rhs),
1381 [(strict_fminnum node:$lhs, node:$rhs),
1382 (fminnum node:$lhs, node:$rhs)]>;
1383 def any_fpround : PatFrags<(ops node:$src),
1384 [(strict_fpround node:$src),
1385 (fpround node:$src)]>;
1386 def any_fpextend : PatFrags<(ops node:$src),
1387 [(strict_fpextend node:$src),
1388 (fpextend node:$src)]>;
1389 def any_extloadf32 : PatFrags<(ops node:$ptr),
1390 [(strict_extloadf32 node:$ptr),
1391 (extloadf32 node:$ptr)]>;
1392 def any_extloadf64 : PatFrags<(ops node:$ptr),
1393 [(strict_extloadf64 node:$ptr),
1394 (extloadf64 node:$ptr)]>;
1395 def any_fp_to_sint : PatFrags<(ops node:$src),
1396 [(strict_fp_to_sint node:$src),
1397 (fp_to_sint node:$src)]>;
1398 def any_fp_to_uint : PatFrags<(ops node:$src),
1399 [(strict_fp_to_uint node:$src),
1400 (fp_to_uint node:$src)]>;
1402 multiclass binary_atomic_op_ord<SDNode atomic_op> {
1403 def #NAME#_monotonic : PatFrag<(ops node:$ptr, node:$val),
1404 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1406 let IsAtomicOrderingMonotonic = 1;
1408 def #NAME#_acquire : PatFrag<(ops node:$ptr, node:$val),
1409 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1411 let IsAtomicOrderingAcquire = 1;
1413 def #NAME#_release : PatFrag<(ops node:$ptr, node:$val),
1414 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1416 let IsAtomicOrderingRelease = 1;
1418 def #NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$val),
1419 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1421 let IsAtomicOrderingAcquireRelease = 1;
1423 def #NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$val),
1424 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1426 let IsAtomicOrderingSequentiallyConsistent = 1;
1430 multiclass ternary_atomic_op_ord<SDNode atomic_op> {
1431 def #NAME#_monotonic : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1432 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1434 let IsAtomicOrderingMonotonic = 1;
1436 def #NAME#_acquire : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1437 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1439 let IsAtomicOrderingAcquire = 1;
1441 def #NAME#_release : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1442 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1444 let IsAtomicOrderingRelease = 1;
1446 def #NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1447 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1449 let IsAtomicOrderingAcquireRelease = 1;
1451 def #NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1452 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1454 let IsAtomicOrderingSequentiallyConsistent = 1;
1458 multiclass binary_atomic_op<SDNode atomic_op, bit IsInt = 1> {
1459 def _8 : PatFrag<(ops node:$ptr, node:$val),
1460 (atomic_op node:$ptr, node:$val)> {
1462 let MemoryVT = !if(IsInt, i8, ?);
1464 def _16 : PatFrag<(ops node:$ptr, node:$val),
1465 (atomic_op node:$ptr, node:$val)> {
1467 let MemoryVT = !if(IsInt, i16, f16);
1469 def _32 : PatFrag<(ops node:$ptr, node:$val),
1470 (atomic_op node:$ptr, node:$val)> {
1472 let MemoryVT = !if(IsInt, i32, f32);
1474 def _64 : PatFrag<(ops node:$ptr, node:$val),
1475 (atomic_op node:$ptr, node:$val)> {
1477 let MemoryVT = !if(IsInt, i64, f64);
1480 defm NAME#_8 : binary_atomic_op_ord<atomic_op>;
1481 defm NAME#_16 : binary_atomic_op_ord<atomic_op>;
1482 defm NAME#_32 : binary_atomic_op_ord<atomic_op>;
1483 defm NAME#_64 : binary_atomic_op_ord<atomic_op>;
1486 multiclass ternary_atomic_op<SDNode atomic_op> {
1487 def _8 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1488 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1492 def _16 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1493 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1497 def _32 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1498 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1502 def _64 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1503 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1508 defm NAME#_8 : ternary_atomic_op_ord<atomic_op>;
1509 defm NAME#_16 : ternary_atomic_op_ord<atomic_op>;
1510 defm NAME#_32 : ternary_atomic_op_ord<atomic_op>;
1511 defm NAME#_64 : ternary_atomic_op_ord<atomic_op>;
1514 defm atomic_load_add : binary_atomic_op<atomic_load_add>;
1515 defm atomic_swap : binary_atomic_op<atomic_swap>;
1516 defm atomic_load_sub : binary_atomic_op<atomic_load_sub>;
1517 defm atomic_load_and : binary_atomic_op<atomic_load_and>;
1518 defm atomic_load_clr : binary_atomic_op<atomic_load_clr>;
1519 defm atomic_load_or : binary_atomic_op<atomic_load_or>;
1520 defm atomic_load_xor : binary_atomic_op<atomic_load_xor>;
1521 defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
1522 defm atomic_load_min : binary_atomic_op<atomic_load_min>;
1523 defm atomic_load_max : binary_atomic_op<atomic_load_max>;
1524 defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
1525 defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
1526 defm atomic_store : binary_atomic_op<atomic_store>;
1527 defm atomic_cmp_swap : ternary_atomic_op<atomic_cmp_swap>;
1530 PatFrag<(ops node:$ptr),
1531 (atomic_load node:$ptr)> {
1535 def atomic_load_16 :
1536 PatFrag<(ops node:$ptr),
1537 (atomic_load node:$ptr)> {
1541 def atomic_load_32 :
1542 PatFrag<(ops node:$ptr),
1543 (atomic_load node:$ptr)> {
1547 def atomic_load_64 :
1548 PatFrag<(ops node:$ptr),
1549 (atomic_load node:$ptr)> {
1554 //===----------------------------------------------------------------------===//
1555 // Selection DAG Pattern Support.
1557 // Patterns are what are actually matched against by the target-flavored
1558 // instruction selection DAG. Instructions defined by the target implicitly
1559 // define patterns in most cases, but patterns can also be explicitly added when
1560 // an operation is defined by a sequence of instructions (e.g. loading a large
1561 // immediate value on RISC targets that do not support immediates as large as
1565 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
1566 dag PatternToMatch = patternToMatch;
1567 list<dag> ResultInstrs = resultInstrs;
1568 list<Predicate> Predicates = []; // See class Instruction in Target.td.
1569 int AddedComplexity = 0; // See class Instruction in Target.td.
1572 // Pat - A simple (but common) form of a pattern, which produces a simple result
1573 // not needing a full list.
1574 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
1576 //===----------------------------------------------------------------------===//
1577 // Complex pattern definitions.
1580 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
1581 // in C++. NumOperands is the number of operands returned by the select function;
1582 // SelectFunc is the name of the function used to pattern match the max. pattern;
1583 // RootNodes are the list of possible root nodes of the sub-dags to match.
1584 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
1586 class ComplexPattern<ValueType ty, int numops, string fn,
1587 list<SDNode> roots = [], list<SDNodeProperty> props = [],
1588 int complexity = -1> {
1590 int NumOperands = numops;
1591 string SelectFunc = fn;
1592 list<SDNode> RootNodes = roots;
1593 list<SDNodeProperty> Properties = props;
1594 int Complexity = complexity;