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_fnearbyint : SDNode<"ISD::STRICT_FNEARBYINT",
510 SDTFPUnaryOp, [SDNPHasChain]>;
511 def strict_fceil : SDNode<"ISD::STRICT_FCEIL",
512 SDTFPUnaryOp, [SDNPHasChain]>;
513 def strict_ffloor : SDNode<"ISD::STRICT_FFLOOR",
514 SDTFPUnaryOp, [SDNPHasChain]>;
515 def strict_fround : SDNode<"ISD::STRICT_FROUND",
516 SDTFPUnaryOp, [SDNPHasChain]>;
517 def strict_ftrunc : SDNode<"ISD::STRICT_FTRUNC",
518 SDTFPUnaryOp, [SDNPHasChain]>;
519 def strict_fminnum : SDNode<"ISD::STRICT_FMINNUM",
520 SDTFPBinOp, [SDNPHasChain,
521 SDNPCommutative, SDNPAssociative]>;
522 def strict_fmaxnum : SDNode<"ISD::STRICT_FMAXNUM",
523 SDTFPBinOp, [SDNPHasChain,
524 SDNPCommutative, SDNPAssociative]>;
525 def strict_fpround : SDNode<"ISD::STRICT_FP_ROUND",
526 SDTFPRoundOp, [SDNPHasChain]>;
527 def strict_fpextend : SDNode<"ISD::STRICT_FP_EXTEND",
528 SDTFPExtendOp, [SDNPHasChain]>;
529 def strict_fp_to_sint : SDNode<"ISD::STRICT_FP_TO_SINT",
530 SDTFPToIntOp, [SDNPHasChain]>;
531 def strict_fp_to_uint : SDNode<"ISD::STRICT_FP_TO_UINT",
532 SDTFPToIntOp, [SDNPHasChain]>;
534 def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
535 def select : SDNode<"ISD::SELECT" , SDTSelect>;
536 def vselect : SDNode<"ISD::VSELECT" , SDTVSelect>;
537 def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
539 def brcc : SDNode<"ISD::BR_CC" , SDTBrCC, [SDNPHasChain]>;
540 def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
541 def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
542 def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
543 def catchret : SDNode<"ISD::CATCHRET" , SDTCatchret,
544 [SDNPHasChain, SDNPSideEffect]>;
545 def cleanupret : SDNode<"ISD::CLEANUPRET" , SDTNone, [SDNPHasChain]>;
546 def catchpad : SDNode<"ISD::CATCHPAD" , SDTNone,
547 [SDNPHasChain, SDNPSideEffect]>;
549 def trap : SDNode<"ISD::TRAP" , SDTNone,
550 [SDNPHasChain, SDNPSideEffect]>;
551 def debugtrap : SDNode<"ISD::DEBUGTRAP" , SDTNone,
552 [SDNPHasChain, SDNPSideEffect]>;
554 def prefetch : SDNode<"ISD::PREFETCH" , SDTPrefetch,
555 [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
558 def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
559 [SDNPHasChain, SDNPSideEffect]>;
561 def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
562 [SDNPHasChain, SDNPSideEffect]>;
564 def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
565 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
566 def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
567 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
568 def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
569 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
570 def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
571 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
572 def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
573 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
574 def atomic_load_clr : SDNode<"ISD::ATOMIC_LOAD_CLR" , SDTAtomic2,
575 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
576 def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
577 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
578 def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
579 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
580 def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
581 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
582 def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
583 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
584 def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
585 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
586 def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
587 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
588 def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
589 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
590 def atomic_load_fadd : SDNode<"ISD::ATOMIC_LOAD_FADD" , SDTFPAtomic2,
591 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
592 def atomic_load_fsub : SDNode<"ISD::ATOMIC_LOAD_FSUB" , SDTFPAtomic2,
593 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
595 def atomic_load : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
596 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
597 def atomic_store : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
598 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
600 def masked_st : SDNode<"ISD::MSTORE", SDTMaskedStore,
601 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
602 def masked_ld : SDNode<"ISD::MLOAD", SDTMaskedLoad,
603 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
605 // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
606 // and truncst (see below).
607 def ld : SDNode<"ISD::LOAD" , SDTLoad,
608 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
609 def st : SDNode<"ISD::STORE" , SDTStore,
610 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
611 def ist : SDNode<"ISD::STORE" , SDTIStore,
612 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
614 def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
615 def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
616 def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
619 // vector_extract/vector_insert are deprecated. extractelt/insertelt
621 def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
622 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
623 def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
624 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
625 def concat_vectors : SDNode<"ISD::CONCAT_VECTORS",
626 SDTypeProfile<1, 2, [SDTCisSubVecOfVec<1, 0>, SDTCisSameAs<1, 2>]>,[]>;
628 // This operator does not do subvector type checking. The ARM
629 // backend, at least, needs it.
630 def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
631 SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
634 // This operator does subvector type checking.
635 def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
636 def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
638 // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
639 // these internally. Don't reference these directly.
640 def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
641 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
643 def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
644 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
646 def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
647 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
649 def SDT_assertext : SDTypeProfile<1, 1,
650 [SDTCisInt<0>, SDTCisInt<1>, SDTCisSameAs<1, 0>]>;
651 def assertsext : SDNode<"ISD::AssertSext", SDT_assertext>;
652 def assertzext : SDNode<"ISD::AssertZext", SDT_assertext>;
655 //===----------------------------------------------------------------------===//
656 // Selection DAG Condition Codes
658 class CondCode<string fcmpName = "", string icmpName = ""> {
659 string ICmpPredicate = icmpName;
660 string FCmpPredicate = fcmpName;
663 // ISD::CondCode enums, and mapping to CmpInst::Predicate names
664 def SETOEQ : CondCode<"FCMP_OEQ">;
665 def SETOGT : CondCode<"FCMP_OGT">;
666 def SETOGE : CondCode<"FCMP_OGE">;
667 def SETOLT : CondCode<"FCMP_OLT">;
668 def SETOLE : CondCode<"FCMP_OLE">;
669 def SETONE : CondCode<"FCMP_ONE">;
670 def SETO : CondCode<"FCMP_ORD">;
671 def SETUO : CondCode<"FCMP_UNO">;
672 def SETUEQ : CondCode<"FCMP_UEQ">;
673 def SETUGT : CondCode<"FCMP_UGT", "ICMP_UGT">;
674 def SETUGE : CondCode<"FCMP_UGE", "ICMP_UGE">;
675 def SETULT : CondCode<"FCMP_ULT", "ICMP_ULT">;
676 def SETULE : CondCode<"FCMP_ULE", "ICMP_ULE">;
677 def SETUNE : CondCode<"FCMP_UNE">;
678 def SETEQ : CondCode<"", "ICMP_EQ">;
679 def SETGT : CondCode<"", "ICMP_SGT">;
680 def SETGE : CondCode<"", "ICMP_SGE">;
681 def SETLT : CondCode<"", "ICMP_SLT">;
682 def SETLE : CondCode<"", "ICMP_SLE">;
683 def SETNE : CondCode<"", "ICMP_NE">;
685 //===----------------------------------------------------------------------===//
686 // Selection DAG Node Transformation Functions.
688 // This mechanism allows targets to manipulate nodes in the output DAG once a
689 // match has been formed. This is typically used to manipulate immediate
692 class SDNodeXForm<SDNode opc, code xformFunction> {
694 code XFormFunction = xformFunction;
697 def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
699 //===----------------------------------------------------------------------===//
700 // PatPred Subclasses.
702 // These allow specifying different sorts of predicates that control whether a
707 class CodePatPred<code predicate> : PatPred {
708 code PredicateCode = predicate;
712 //===----------------------------------------------------------------------===//
713 // Selection DAG Pattern Fragments.
715 // Pattern fragments are reusable chunks of dags that match specific things.
716 // They can take arguments and have C++ predicates that control whether they
717 // match. They are intended to make the patterns for common instructions more
718 // compact and readable.
721 /// PatFrags - Represents a set of pattern fragments. Each single fragment
722 /// can match something on the DAG, from a single node to multiple nested other
723 /// fragments. The whole set of fragments matches if any of the single
724 /// fragemnts match. This allows e.g. matching and "add with overflow" and
725 /// a regular "add" with the same fragment set.
727 class PatFrags<dag ops, list<dag> frags, code pred = [{}],
728 SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
730 list<dag> Fragments = frags;
731 code PredicateCode = pred;
732 code GISelPredicateCode = [{}];
733 code ImmediateCode = [{}];
734 SDNodeXForm OperandTransform = xform;
736 // When this is set, the PredicateCode may refer to a constant Operands
737 // vector which contains the captured nodes of the DAG, in the order listed
738 // by the Operands field above.
740 // This is useful when Fragments involves associative / commutative
741 // operators: a single piece of code can easily refer to all operands even
742 // when re-associated / commuted variants of the fragment are matched.
743 bit PredicateCodeUsesOperands = 0;
745 // Define a few pre-packaged predicates. This helps GlobalISel import
746 // existing rules from SelectionDAG for many common cases.
747 // They will be tested prior to the code in pred and must not be used in
748 // ImmLeaf and its subclasses.
750 // Is the desired pre-packaged predicate for a load?
752 // Is the desired pre-packaged predicate for a store?
754 // Is the desired pre-packaged predicate for an atomic?
757 // cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
758 // cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
761 // cast<LoadSDNode>(N)->getExtensionType() != ISD::NON_EXTLOAD
762 bit IsNonExtLoad = ?;
763 // cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
764 bit IsAnyExtLoad = ?;
765 // cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
766 bit IsSignExtLoad = ?;
767 // cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
768 bit IsZeroExtLoad = ?;
769 // !cast<StoreSDNode>(N)->isTruncatingStore();
770 // cast<StoreSDNode>(N)->isTruncatingStore();
771 bit IsTruncStore = ?;
773 // cast<MemSDNode>(N)->getAddressSpace() ==
774 // If this empty, accept any address space.
775 list<int> AddressSpaces = ?;
777 // cast<MemSDNode>(N)->getAlignment() >=
778 // If this is empty, accept any alignment.
779 int MinAlignment = ?;
781 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Monotonic
782 bit IsAtomicOrderingMonotonic = ?;
783 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Acquire
784 bit IsAtomicOrderingAcquire = ?;
785 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Release
786 bit IsAtomicOrderingRelease = ?;
787 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::AcquireRelease
788 bit IsAtomicOrderingAcquireRelease = ?;
789 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::SequentiallyConsistent
790 bit IsAtomicOrderingSequentiallyConsistent = ?;
792 // isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
793 // !isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
794 bit IsAtomicOrderingAcquireOrStronger = ?;
796 // isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
797 // !isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
798 bit IsAtomicOrderingReleaseOrStronger = ?;
800 // cast<LoadSDNode>(N)->getMemoryVT() == MVT::<VT>;
801 // cast<StoreSDNode>(N)->getMemoryVT() == MVT::<VT>;
802 ValueType MemoryVT = ?;
803 // cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
804 // cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
805 ValueType ScalarMemoryVT = ?;
808 // PatFrag - A version of PatFrags matching only a single fragment.
809 class PatFrag<dag ops, dag frag, code pred = [{}],
810 SDNodeXForm xform = NOOP_SDNodeXForm>
811 : PatFrags<ops, [frag], pred, xform>;
813 // OutPatFrag is a pattern fragment that is used as part of an output pattern
814 // (not an input pattern). These do not have predicates or transforms, but are
815 // used to avoid repeated subexpressions in output patterns.
816 class OutPatFrag<dag ops, dag frag>
817 : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;
819 // PatLeaf's are pattern fragments that have no operands. This is just a helper
820 // to define immediates and other common things concisely.
821 class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
822 : PatFrag<(ops), frag, pred, xform>;
825 // ImmLeaf is a pattern fragment with a constraint on the immediate. The
826 // constraint is a function that is run on the immediate (always with the value
827 // sign extended out to an int64_t) as Imm. For example:
829 // def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
831 // this is a more convenient form to match 'imm' nodes in than PatLeaf and also
832 // is preferred over using PatLeaf because it allows the code generator to
833 // reason more about the constraint.
835 // If FastIsel should ignore all instructions that have an operand of this type,
836 // the FastIselShouldIgnore flag can be set. This is an optimization to reduce
837 // the code size of the generated fast instruction selector.
838 class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
839 SDNode ImmNode = imm>
840 : PatFrag<(ops), (vt ImmNode), [{}], xform> {
841 let ImmediateCode = pred;
842 bit FastIselShouldIgnore = 0;
844 // Is the data type of the immediate an APInt?
847 // Is the data type of the immediate an APFloat?
851 // Convenience wrapper for ImmLeaf to use timm/TargetConstant instead
853 class TImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
854 SDNode ImmNode = timm> : ImmLeaf<vt, pred, xform, ImmNode>;
856 // An ImmLeaf except that Imm is an APInt. This is useful when you need to
857 // zero-extend the immediate instead of sign-extend it.
859 // Note that FastISel does not currently understand IntImmLeaf and will not
860 // generate code for rules that make use of it. As such, it does not make sense
861 // to replace ImmLeaf with IntImmLeaf. However, replacing PatLeaf with an
862 // IntImmLeaf will allow GlobalISel to import the rule.
863 class IntImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
864 : ImmLeaf<vt, pred, xform> {
866 let FastIselShouldIgnore = 1;
869 // An ImmLeaf except that Imm is an APFloat.
871 // Note that FastISel does not currently understand FPImmLeaf and will not
872 // generate code for rules that make use of it.
873 class FPImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
874 : ImmLeaf<vt, pred, xform, fpimm> {
876 let FastIselShouldIgnore = 1;
881 def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
882 def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
884 // Use ISD::isBuildVectorAllOnes or ISD::isBuildVectorAllZeros to look for
885 // the corresponding build_vector. Will look through bitcasts except when used
886 // as a pattern root.
887 def immAllOnesV; // ISD::isBuildVectorAllOnes
888 def immAllZerosV; // ISD::isBuildVectorAllZeros
890 // Other helper fragments.
891 def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
892 def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
893 def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
895 // null_frag - The null pattern operator is used in multiclass instantiations
896 // which accept an SDPatternOperator for use in matching patterns for internal
897 // definitions. When expanding a pattern, if the null fragment is referenced
898 // in the expansion, the pattern is discarded and it is as-if '[]' had been
899 // specified. This allows multiclasses to have the isel patterns be optional.
900 def null_frag : SDPatternOperator;
903 def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr)> {
907 def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
909 let IsNonExtLoad = 1;
912 // extending load fragments.
913 def extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
915 let IsAnyExtLoad = 1;
917 def sextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
919 let IsSignExtLoad = 1;
921 def zextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
923 let IsZeroExtLoad = 1;
926 def extloadi1 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
930 def extloadi8 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
934 def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
938 def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
942 def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
946 def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
951 def sextloadi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
955 def sextloadi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
959 def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
963 def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
968 def zextloadi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
972 def zextloadi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
976 def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
980 def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
985 def extloadvi1 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
987 let ScalarMemoryVT = i1;
989 def extloadvi8 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
991 let ScalarMemoryVT = i8;
993 def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
995 let ScalarMemoryVT = i16;
997 def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
999 let ScalarMemoryVT = i32;
1001 def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1003 let ScalarMemoryVT = f32;
1005 def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1007 let ScalarMemoryVT = f64;
1010 def sextloadvi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1012 let ScalarMemoryVT = i1;
1014 def sextloadvi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1016 let ScalarMemoryVT = i8;
1018 def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1020 let ScalarMemoryVT = i16;
1022 def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1024 let ScalarMemoryVT = i32;
1027 def zextloadvi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1029 let ScalarMemoryVT = i1;
1031 def zextloadvi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1033 let ScalarMemoryVT = i8;
1035 def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1037 let ScalarMemoryVT = i16;
1039 def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1041 let ScalarMemoryVT = i32;
1045 def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
1046 (st node:$val, node:$ptr)> {
1048 let IsUnindexed = 1;
1050 def store : PatFrag<(ops node:$val, node:$ptr),
1051 (unindexedstore node:$val, node:$ptr)> {
1053 let IsTruncStore = 0;
1056 // truncstore fragments.
1057 def truncstore : PatFrag<(ops node:$val, node:$ptr),
1058 (unindexedstore node:$val, node:$ptr)> {
1060 let IsTruncStore = 1;
1062 def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
1063 (truncstore node:$val, node:$ptr)> {
1067 def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
1068 (truncstore node:$val, node:$ptr)> {
1072 def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
1073 (truncstore node:$val, node:$ptr)> {
1077 def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
1078 (truncstore node:$val, node:$ptr)> {
1082 def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
1083 (truncstore node:$val, node:$ptr)> {
1088 def truncstorevi8 : PatFrag<(ops node:$val, node:$ptr),
1089 (truncstore node:$val, node:$ptr)> {
1091 let ScalarMemoryVT = i8;
1094 def truncstorevi16 : PatFrag<(ops node:$val, node:$ptr),
1095 (truncstore node:$val, node:$ptr)> {
1097 let ScalarMemoryVT = i16;
1100 def truncstorevi32 : PatFrag<(ops node:$val, node:$ptr),
1101 (truncstore node:$val, node:$ptr)> {
1103 let ScalarMemoryVT = i32;
1106 // indexed store fragments.
1107 def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
1108 (ist node:$val, node:$base, node:$offset)> {
1110 let IsTruncStore = 0;
1113 def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
1114 (istore node:$val, node:$base, node:$offset), [{
1115 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1116 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1119 def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
1120 (ist node:$val, node:$base, node:$offset)> {
1122 let IsTruncStore = 1;
1124 def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1125 (itruncstore node:$val, node:$base, node:$offset), [{
1126 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1127 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1129 def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1130 (pre_truncst node:$val, node:$base, node:$offset)> {
1134 def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1135 (pre_truncst node:$val, node:$base, node:$offset)> {
1139 def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1140 (pre_truncst node:$val, node:$base, node:$offset)> {
1144 def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1145 (pre_truncst node:$val, node:$base, node:$offset)> {
1149 def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1150 (pre_truncst node:$val, node:$base, node:$offset)> {
1154 def pre_truncstvi8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1155 (pre_truncst node:$val, node:$base, node:$offset)> {
1157 let ScalarMemoryVT = i8;
1159 def pre_truncstvi16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1160 (pre_truncst node:$val, node:$base, node:$offset)> {
1162 let ScalarMemoryVT = i16;
1165 def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
1166 (istore node:$val, node:$ptr, node:$offset), [{
1167 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1168 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1171 def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1172 (itruncstore node:$val, node:$base, node:$offset), [{
1173 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1174 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1176 def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1177 (post_truncst node:$val, node:$base, node:$offset)> {
1181 def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1182 (post_truncst node:$val, node:$base, node:$offset)> {
1186 def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1187 (post_truncst node:$val, node:$base, node:$offset)> {
1191 def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1192 (post_truncst node:$val, node:$base, node:$offset)> {
1196 def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1197 (post_truncst node:$val, node:$base, node:$offset)> {
1201 def post_truncstvi8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1202 (post_truncst node:$val, node:$base, node:$offset)> {
1204 let ScalarMemoryVT = i8;
1206 def post_truncstvi16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1207 (post_truncst node:$val, node:$base, node:$offset)> {
1209 let ScalarMemoryVT = i16;
1212 // TODO: Split these into volatile and unordered flavors to enable
1213 // selectively legal optimizations for each. (See D66309)
1214 def simple_load : PatFrag<(ops node:$ptr),
1215 (load node:$ptr), [{
1216 return cast<LoadSDNode>(N)->isSimple();
1218 def simple_store : PatFrag<(ops node:$val, node:$ptr),
1219 (store node:$val, node:$ptr), [{
1220 return cast<StoreSDNode>(N)->isSimple();
1223 // nontemporal store fragments.
1224 def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1225 (store node:$val, node:$ptr), [{
1226 return cast<StoreSDNode>(N)->isNonTemporal();
1229 def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1230 (nontemporalstore node:$val, node:$ptr), [{
1231 StoreSDNode *St = cast<StoreSDNode>(N);
1232 return St->getAlignment() >= St->getMemoryVT().getStoreSize();
1235 def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1236 (nontemporalstore node:$val, node:$ptr), [{
1237 StoreSDNode *St = cast<StoreSDNode>(N);
1238 return St->getAlignment() < St->getMemoryVT().getStoreSize();
1241 // nontemporal load fragments.
1242 def nontemporalload : PatFrag<(ops node:$ptr),
1243 (load node:$ptr), [{
1244 return cast<LoadSDNode>(N)->isNonTemporal();
1247 def alignednontemporalload : PatFrag<(ops node:$ptr),
1248 (nontemporalload node:$ptr), [{
1249 LoadSDNode *Ld = cast<LoadSDNode>(N);
1250 return Ld->getAlignment() >= Ld->getMemoryVT().getStoreSize();
1253 // setcc convenience fragments.
1254 def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
1255 (setcc node:$lhs, node:$rhs, SETOEQ)>;
1256 def setogt : PatFrag<(ops node:$lhs, node:$rhs),
1257 (setcc node:$lhs, node:$rhs, SETOGT)>;
1258 def setoge : PatFrag<(ops node:$lhs, node:$rhs),
1259 (setcc node:$lhs, node:$rhs, SETOGE)>;
1260 def setolt : PatFrag<(ops node:$lhs, node:$rhs),
1261 (setcc node:$lhs, node:$rhs, SETOLT)>;
1262 def setole : PatFrag<(ops node:$lhs, node:$rhs),
1263 (setcc node:$lhs, node:$rhs, SETOLE)>;
1264 def setone : PatFrag<(ops node:$lhs, node:$rhs),
1265 (setcc node:$lhs, node:$rhs, SETONE)>;
1266 def seto : PatFrag<(ops node:$lhs, node:$rhs),
1267 (setcc node:$lhs, node:$rhs, SETO)>;
1268 def setuo : PatFrag<(ops node:$lhs, node:$rhs),
1269 (setcc node:$lhs, node:$rhs, SETUO)>;
1270 def setueq : PatFrag<(ops node:$lhs, node:$rhs),
1271 (setcc node:$lhs, node:$rhs, SETUEQ)>;
1272 def setugt : PatFrag<(ops node:$lhs, node:$rhs),
1273 (setcc node:$lhs, node:$rhs, SETUGT)>;
1274 def setuge : PatFrag<(ops node:$lhs, node:$rhs),
1275 (setcc node:$lhs, node:$rhs, SETUGE)>;
1276 def setult : PatFrag<(ops node:$lhs, node:$rhs),
1277 (setcc node:$lhs, node:$rhs, SETULT)>;
1278 def setule : PatFrag<(ops node:$lhs, node:$rhs),
1279 (setcc node:$lhs, node:$rhs, SETULE)>;
1280 def setune : PatFrag<(ops node:$lhs, node:$rhs),
1281 (setcc node:$lhs, node:$rhs, SETUNE)>;
1282 def seteq : PatFrag<(ops node:$lhs, node:$rhs),
1283 (setcc node:$lhs, node:$rhs, SETEQ)>;
1284 def setgt : PatFrag<(ops node:$lhs, node:$rhs),
1285 (setcc node:$lhs, node:$rhs, SETGT)>;
1286 def setge : PatFrag<(ops node:$lhs, node:$rhs),
1287 (setcc node:$lhs, node:$rhs, SETGE)>;
1288 def setlt : PatFrag<(ops node:$lhs, node:$rhs),
1289 (setcc node:$lhs, node:$rhs, SETLT)>;
1290 def setle : PatFrag<(ops node:$lhs, node:$rhs),
1291 (setcc node:$lhs, node:$rhs, SETLE)>;
1292 def setne : PatFrag<(ops node:$lhs, node:$rhs),
1293 (setcc node:$lhs, node:$rhs, SETNE)>;
1295 // We don't have strict FP extended loads as single DAG nodes, but we can
1296 // still provide convenience fragments to match those operations.
1297 def strict_extloadf32 : PatFrag<(ops node:$ptr),
1298 (strict_fpextend (f32 (load node:$ptr)))>;
1299 def strict_extloadf64 : PatFrag<(ops node:$ptr),
1300 (strict_fpextend (f64 (load node:$ptr)))>;
1302 // Convenience fragments to match both strict and non-strict fp operations
1303 def any_fadd : PatFrags<(ops node:$lhs, node:$rhs),
1304 [(strict_fadd node:$lhs, node:$rhs),
1305 (fadd node:$lhs, node:$rhs)]>;
1306 def any_fsub : PatFrags<(ops node:$lhs, node:$rhs),
1307 [(strict_fsub node:$lhs, node:$rhs),
1308 (fsub node:$lhs, node:$rhs)]>;
1309 def any_fmul : PatFrags<(ops node:$lhs, node:$rhs),
1310 [(strict_fmul node:$lhs, node:$rhs),
1311 (fmul node:$lhs, node:$rhs)]>;
1312 def any_fdiv : PatFrags<(ops node:$lhs, node:$rhs),
1313 [(strict_fdiv node:$lhs, node:$rhs),
1314 (fdiv node:$lhs, node:$rhs)]>;
1315 def any_frem : PatFrags<(ops node:$lhs, node:$rhs),
1316 [(strict_frem node:$lhs, node:$rhs),
1317 (frem node:$lhs, node:$rhs)]>;
1318 def any_fma : PatFrags<(ops node:$src1, node:$src2, node:$src3),
1319 [(strict_fma node:$src1, node:$src2, node:$src3),
1320 (fma node:$src1, node:$src2, node:$src3)]>;
1321 def any_fsqrt : PatFrags<(ops node:$src),
1322 [(strict_fsqrt node:$src),
1323 (fsqrt node:$src)]>;
1324 def any_fsin : PatFrags<(ops node:$src),
1325 [(strict_fsin node:$src),
1327 def any_fcos : PatFrags<(ops node:$src),
1328 [(strict_fcos node:$src),
1330 def any_fexp2 : PatFrags<(ops node:$src),
1331 [(strict_fexp2 node:$src),
1332 (fexp2 node:$src)]>;
1333 def any_fpow : PatFrags<(ops node:$lhs, node:$rhs),
1334 [(strict_fpow node:$lhs, node:$rhs),
1335 (fpow node:$lhs, node:$rhs)]>;
1336 def any_flog2 : PatFrags<(ops node:$src),
1337 [(strict_flog2 node:$src),
1338 (flog2 node:$src)]>;
1339 def any_frint : PatFrags<(ops node:$src),
1340 [(strict_frint node:$src),
1341 (frint node:$src)]>;
1342 def any_fnearbyint : PatFrags<(ops node:$src),
1343 [(strict_fnearbyint node:$src),
1344 (fnearbyint node:$src)]>;
1345 def any_fceil : PatFrags<(ops node:$src),
1346 [(strict_fceil node:$src),
1347 (fceil node:$src)]>;
1348 def any_ffloor : PatFrags<(ops node:$src),
1349 [(strict_ffloor node:$src),
1350 (ffloor node:$src)]>;
1351 def any_fround : PatFrags<(ops node:$src),
1352 [(strict_fround node:$src),
1353 (fround node:$src)]>;
1354 def any_ftrunc : PatFrags<(ops node:$src),
1355 [(strict_ftrunc node:$src),
1356 (ftrunc node:$src)]>;
1357 def any_fmaxnum : PatFrags<(ops node:$lhs, node:$rhs),
1358 [(strict_fmaxnum node:$lhs, node:$rhs),
1359 (fmaxnum node:$lhs, node:$rhs)]>;
1360 def any_fminnum : PatFrags<(ops node:$lhs, node:$rhs),
1361 [(strict_fminnum node:$lhs, node:$rhs),
1362 (fminnum node:$lhs, node:$rhs)]>;
1363 def any_fpround : PatFrags<(ops node:$src),
1364 [(strict_fpround node:$src),
1365 (fpround node:$src)]>;
1366 def any_fpextend : PatFrags<(ops node:$src),
1367 [(strict_fpextend node:$src),
1368 (fpextend node:$src)]>;
1369 def any_extloadf32 : PatFrags<(ops node:$ptr),
1370 [(strict_extloadf32 node:$ptr),
1371 (extloadf32 node:$ptr)]>;
1372 def any_extloadf64 : PatFrags<(ops node:$ptr),
1373 [(strict_extloadf64 node:$ptr),
1374 (extloadf64 node:$ptr)]>;
1375 def any_fp_to_sint : PatFrags<(ops node:$src),
1376 [(strict_fp_to_sint node:$src),
1377 (fp_to_sint node:$src)]>;
1378 def any_fp_to_uint : PatFrags<(ops node:$src),
1379 [(strict_fp_to_uint node:$src),
1380 (fp_to_uint node:$src)]>;
1382 multiclass binary_atomic_op_ord<SDNode atomic_op> {
1383 def #NAME#_monotonic : PatFrag<(ops node:$ptr, node:$val),
1384 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1386 let IsAtomicOrderingMonotonic = 1;
1388 def #NAME#_acquire : PatFrag<(ops node:$ptr, node:$val),
1389 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1391 let IsAtomicOrderingAcquire = 1;
1393 def #NAME#_release : PatFrag<(ops node:$ptr, node:$val),
1394 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1396 let IsAtomicOrderingRelease = 1;
1398 def #NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$val),
1399 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1401 let IsAtomicOrderingAcquireRelease = 1;
1403 def #NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$val),
1404 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1406 let IsAtomicOrderingSequentiallyConsistent = 1;
1410 multiclass ternary_atomic_op_ord<SDNode atomic_op> {
1411 def #NAME#_monotonic : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1412 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1414 let IsAtomicOrderingMonotonic = 1;
1416 def #NAME#_acquire : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1417 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1419 let IsAtomicOrderingAcquire = 1;
1421 def #NAME#_release : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1422 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1424 let IsAtomicOrderingRelease = 1;
1426 def #NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1427 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1429 let IsAtomicOrderingAcquireRelease = 1;
1431 def #NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1432 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1434 let IsAtomicOrderingSequentiallyConsistent = 1;
1438 multiclass binary_atomic_op<SDNode atomic_op, bit IsInt = 1> {
1439 def _8 : PatFrag<(ops node:$ptr, node:$val),
1440 (atomic_op node:$ptr, node:$val)> {
1442 let MemoryVT = !if(IsInt, i8, ?);
1444 def _16 : PatFrag<(ops node:$ptr, node:$val),
1445 (atomic_op node:$ptr, node:$val)> {
1447 let MemoryVT = !if(IsInt, i16, f16);
1449 def _32 : PatFrag<(ops node:$ptr, node:$val),
1450 (atomic_op node:$ptr, node:$val)> {
1452 let MemoryVT = !if(IsInt, i32, f32);
1454 def _64 : PatFrag<(ops node:$ptr, node:$val),
1455 (atomic_op node:$ptr, node:$val)> {
1457 let MemoryVT = !if(IsInt, i64, f64);
1460 defm NAME#_8 : binary_atomic_op_ord<atomic_op>;
1461 defm NAME#_16 : binary_atomic_op_ord<atomic_op>;
1462 defm NAME#_32 : binary_atomic_op_ord<atomic_op>;
1463 defm NAME#_64 : binary_atomic_op_ord<atomic_op>;
1466 multiclass ternary_atomic_op<SDNode atomic_op> {
1467 def _8 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1468 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1472 def _16 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1473 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1477 def _32 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1478 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1482 def _64 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1483 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1488 defm NAME#_8 : ternary_atomic_op_ord<atomic_op>;
1489 defm NAME#_16 : ternary_atomic_op_ord<atomic_op>;
1490 defm NAME#_32 : ternary_atomic_op_ord<atomic_op>;
1491 defm NAME#_64 : ternary_atomic_op_ord<atomic_op>;
1494 defm atomic_load_add : binary_atomic_op<atomic_load_add>;
1495 defm atomic_swap : binary_atomic_op<atomic_swap>;
1496 defm atomic_load_sub : binary_atomic_op<atomic_load_sub>;
1497 defm atomic_load_and : binary_atomic_op<atomic_load_and>;
1498 defm atomic_load_clr : binary_atomic_op<atomic_load_clr>;
1499 defm atomic_load_or : binary_atomic_op<atomic_load_or>;
1500 defm atomic_load_xor : binary_atomic_op<atomic_load_xor>;
1501 defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
1502 defm atomic_load_min : binary_atomic_op<atomic_load_min>;
1503 defm atomic_load_max : binary_atomic_op<atomic_load_max>;
1504 defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
1505 defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
1506 defm atomic_store : binary_atomic_op<atomic_store>;
1507 defm atomic_cmp_swap : ternary_atomic_op<atomic_cmp_swap>;
1510 PatFrag<(ops node:$ptr),
1511 (atomic_load node:$ptr)> {
1515 def atomic_load_16 :
1516 PatFrag<(ops node:$ptr),
1517 (atomic_load node:$ptr)> {
1521 def atomic_load_32 :
1522 PatFrag<(ops node:$ptr),
1523 (atomic_load node:$ptr)> {
1527 def atomic_load_64 :
1528 PatFrag<(ops node:$ptr),
1529 (atomic_load node:$ptr)> {
1534 //===----------------------------------------------------------------------===//
1535 // Selection DAG Pattern Support.
1537 // Patterns are what are actually matched against by the target-flavored
1538 // instruction selection DAG. Instructions defined by the target implicitly
1539 // define patterns in most cases, but patterns can also be explicitly added when
1540 // an operation is defined by a sequence of instructions (e.g. loading a large
1541 // immediate value on RISC targets that do not support immediates as large as
1545 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
1546 dag PatternToMatch = patternToMatch;
1547 list<dag> ResultInstrs = resultInstrs;
1548 list<Predicate> Predicates = []; // See class Instruction in Target.td.
1549 int AddedComplexity = 0; // See class Instruction in Target.td.
1552 // Pat - A simple (but common) form of a pattern, which produces a simple result
1553 // not needing a full list.
1554 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
1556 //===----------------------------------------------------------------------===//
1557 // Complex pattern definitions.
1560 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
1561 // in C++. NumOperands is the number of operands returned by the select function;
1562 // SelectFunc is the name of the function used to pattern match the max. pattern;
1563 // RootNodes are the list of possible root nodes of the sub-dags to match.
1564 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
1566 class ComplexPattern<ValueType ty, int numops, string fn,
1567 list<SDNode> roots = [], list<SDNodeProperty> props = [],
1568 int complexity = -1> {
1570 int NumOperands = numops;
1571 string SelectFunc = fn;
1572 list<SDNode> RootNodes = roots;
1573 list<SDNodeProperty> Properties = props;
1574 int Complexity = complexity;