1 //===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the target-independent interfaces used by SelectionDAG
11 // instruction selection generators.
13 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
16 // Selection DAG Type Constraint definitions.
18 // Note that the semantics of these constraints are hard coded into tblgen. To
19 // modify or add constraints, you have to hack tblgen.
22 class SDTypeConstraint<int opnum> {
23 int OperandNum = opnum;
26 // SDTCisVT - The specified operand has exactly this VT.
27 class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
31 class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
33 // SDTCisInt - The specified operand has integer type.
34 class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
36 // SDTCisFP - The specified operand has floating-point type.
37 class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
39 // SDTCisVec - The specified operand has a vector type.
40 class SDTCisVec<int OpNum> : SDTypeConstraint<OpNum>;
42 // SDTCisSameAs - The two specified operands have identical types.
43 class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
44 int OtherOperandNum = OtherOp;
47 // SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
48 // smaller than the 'Other' operand.
49 class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
50 int OtherOperandNum = OtherOp;
53 class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
54 int BigOperandNum = BigOp;
57 /// SDTCisEltOfVec - This indicates that ThisOp is a scalar type of the same
58 /// type as the element type of OtherOp, which is a vector type.
59 class SDTCisEltOfVec<int ThisOp, int OtherOp>
60 : SDTypeConstraint<ThisOp> {
61 int OtherOpNum = OtherOp;
64 /// SDTCisSubVecOfVec - This indicates that ThisOp is a vector type
65 /// with length less that of OtherOp, which is a vector type.
66 class SDTCisSubVecOfVec<int ThisOp, int OtherOp>
67 : SDTypeConstraint<ThisOp> {
68 int OtherOpNum = OtherOp;
71 //===----------------------------------------------------------------------===//
72 // Selection DAG Type Profile definitions.
74 // These use the constraints defined above to describe the type requirements of
75 // the various nodes. These are not hard coded into tblgen, allowing targets to
76 // add their own if needed.
79 // SDTypeProfile - This profile describes the type requirements of a Selection
81 class SDTypeProfile<int numresults, int numoperands,
82 list<SDTypeConstraint> constraints> {
83 int NumResults = numresults;
84 int NumOperands = numoperands;
85 list<SDTypeConstraint> Constraints = constraints;
89 def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
90 def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
91 def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
92 def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
93 def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
94 def SDTUnaryOp : SDTypeProfile<1, 1, []>; // for bitconvert.
96 def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
97 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
99 def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
100 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
102 def SDTIntBinHiLoOp : SDTypeProfile<2, 2, [ // mulhi, mullo, sdivrem, udivrem
103 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,SDTCisInt<0>
106 def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
107 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
109 def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
110 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
112 def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
113 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
115 def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz
116 SDTCisSameAs<0, 1>, SDTCisInt<0>
118 def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
119 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>
121 def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
122 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>
124 def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
125 SDTCisSameAs<0, 1>, SDTCisFP<0>
127 def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
128 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>
130 def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
131 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>
133 def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
134 SDTCisFP<0>, SDTCisInt<1>
136 def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
137 SDTCisInt<0>, SDTCisFP<1>
139 def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
140 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
141 SDTCisVTSmallerThanOp<2, 1>
144 def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
145 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
148 def SDTSelect : SDTypeProfile<1, 3, [ // select
149 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
152 def SDTVSelect : SDTypeProfile<1, 3, [ // vselect
153 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
156 def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
157 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
161 def SDTBr : SDTypeProfile<0, 1, [ // br
165 def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
166 SDTCisInt<0>, SDTCisVT<1, OtherVT>
169 def SDTBrind : SDTypeProfile<0, 1, [ // brind
173 def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
175 def SDTLoad : SDTypeProfile<1, 1, [ // load
179 def SDTStore : SDTypeProfile<0, 2, [ // store
183 def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
184 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
187 def SDTVecShuffle : SDTypeProfile<1, 2, [
188 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>
190 def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
191 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
193 def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
194 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
197 def SDTSubVecExtract : SDTypeProfile<1, 2, [// subvector extract
198 SDTCisSubVecOfVec<0,1>, SDTCisInt<2>
200 def SDTSubVecInsert : SDTypeProfile<1, 3, [ // subvector insert
201 SDTCisSubVecOfVec<2, 1>, SDTCisSameAs<0,1>, SDTCisInt<3>
204 def SDTPrefetch : SDTypeProfile<0, 4, [ // prefetch
205 SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisSameAs<1, 3>, SDTCisInt<1>
208 def SDTMemBarrier : SDTypeProfile<0, 5, [ // memory barier
209 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
212 def SDTAtomicFence : SDTypeProfile<0, 2, [
213 SDTCisSameAs<0,1>, SDTCisPtrTy<0>
215 def SDTAtomic3 : SDTypeProfile<1, 3, [
216 SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
218 def SDTAtomic2 : SDTypeProfile<1, 2, [
219 SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
221 def SDTAtomicStore : SDTypeProfile<0, 2, [
222 SDTCisPtrTy<0>, SDTCisInt<1>
224 def SDTAtomicLoad : SDTypeProfile<1, 1, [
225 SDTCisInt<0>, SDTCisPtrTy<1>
228 def SDTConvertOp : SDTypeProfile<1, 5, [ //cvtss, su, us, uu, ff, fs, fu, sf, su
229 SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>, SDTCisPtrTy<4>, SDTCisPtrTy<5>
232 class SDCallSeqStart<list<SDTypeConstraint> constraints> :
233 SDTypeProfile<0, 1, constraints>;
234 class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
235 SDTypeProfile<0, 2, constraints>;
237 //===----------------------------------------------------------------------===//
238 // Selection DAG Node Properties.
240 // Note: These are hard coded into tblgen.
242 class SDNodeProperty;
243 def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
244 def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
245 def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
246 def SDNPOutGlue : SDNodeProperty; // Write a flag result
247 def SDNPInGlue : SDNodeProperty; // Read a flag operand
248 def SDNPOptInGlue : SDNodeProperty; // Optionally read a flag operand
249 def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
250 def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
251 def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
252 def SDNPMemOperand : SDNodeProperty; // Touches memory, has assoc MemOperand
253 def SDNPVariadic : SDNodeProperty; // Node has variable arguments.
254 def SDNPWantRoot : SDNodeProperty; // ComplexPattern gets the root of match
255 def SDNPWantParent : SDNodeProperty; // ComplexPattern gets the parent
257 //===----------------------------------------------------------------------===//
258 // Selection DAG Pattern Operations
259 class SDPatternOperator;
261 //===----------------------------------------------------------------------===//
262 // Selection DAG Node definitions.
264 class SDNode<string opcode, SDTypeProfile typeprof,
265 list<SDNodeProperty> props = [], string sdclass = "SDNode">
266 : SDPatternOperator {
267 string Opcode = opcode;
268 string SDClass = sdclass;
269 list<SDNodeProperty> Properties = props;
270 SDTypeProfile TypeProfile = typeprof;
273 // Special TableGen-recognized dag nodes
279 def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
280 def timm : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
281 def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
282 def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
283 def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
284 def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
285 def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
286 def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
287 "GlobalAddressSDNode">;
288 def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
289 "GlobalAddressSDNode">;
290 def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
291 "GlobalAddressSDNode">;
292 def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
293 "GlobalAddressSDNode">;
294 def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
295 "ConstantPoolSDNode">;
296 def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
297 "ConstantPoolSDNode">;
298 def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
300 def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
302 def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
304 def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
306 def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
307 "ExternalSymbolSDNode">;
308 def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
309 "ExternalSymbolSDNode">;
310 def blockaddress : SDNode<"ISD::BlockAddress", SDTPtrLeaf, [],
311 "BlockAddressSDNode">;
312 def tblockaddress: SDNode<"ISD::TargetBlockAddress", SDTPtrLeaf, [],
313 "BlockAddressSDNode">;
315 def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
316 [SDNPCommutative, SDNPAssociative]>;
317 def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
318 def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
319 [SDNPCommutative, SDNPAssociative]>;
320 def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
321 def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
322 def smullohi : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
323 def umullohi : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
324 def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
325 def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
326 def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
327 def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
328 def sdivrem : SDNode<"ISD::SDIVREM" , SDTIntBinHiLoOp>;
329 def udivrem : SDNode<"ISD::UDIVREM" , SDTIntBinHiLoOp>;
330 def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
331 def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
332 def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
333 def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
334 def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
335 def and : SDNode<"ISD::AND" , SDTIntBinOp,
336 [SDNPCommutative, SDNPAssociative]>;
337 def or : SDNode<"ISD::OR" , SDTIntBinOp,
338 [SDNPCommutative, SDNPAssociative]>;
339 def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
340 [SDNPCommutative, SDNPAssociative]>;
341 def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
342 [SDNPCommutative, SDNPOutGlue]>;
343 def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
344 [SDNPCommutative, SDNPOutGlue, SDNPInGlue]>;
345 def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
347 def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
348 [SDNPOutGlue, SDNPInGlue]>;
350 def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
351 def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
352 def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
353 def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
354 def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
355 def ctlz_zero_undef : SDNode<"ISD::CTLZ_ZERO_UNDEF", SDTIntUnaryOp>;
356 def cttz_zero_undef : SDNode<"ISD::CTTZ_ZERO_UNDEF", SDTIntUnaryOp>;
357 def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
358 def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
359 def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
360 def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
361 def bitconvert : SDNode<"ISD::BITCAST" , SDTUnaryOp>;
362 def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
363 def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
366 def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
367 def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
368 def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
369 def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
370 def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
371 def fma : SDNode<"ISD::FMA" , SDTFPTernaryOp>;
372 def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
373 def fgetsign : SDNode<"ISD::FGETSIGN" , SDTFPToIntOp>;
374 def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
375 def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
376 def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
377 def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
378 def fexp2 : SDNode<"ISD::FEXP2" , SDTFPUnaryOp>;
379 def flog2 : SDNode<"ISD::FLOG2" , SDTFPUnaryOp>;
380 def frint : SDNode<"ISD::FRINT" , SDTFPUnaryOp>;
381 def ftrunc : SDNode<"ISD::FTRUNC" , SDTFPUnaryOp>;
382 def fceil : SDNode<"ISD::FCEIL" , SDTFPUnaryOp>;
383 def ffloor : SDNode<"ISD::FFLOOR" , SDTFPUnaryOp>;
384 def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
386 def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
387 def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
388 def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
390 def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
391 def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
392 def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
393 def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
394 def f16_to_f32 : SDNode<"ISD::FP16_TO_FP32", SDTIntToFPOp>;
395 def f32_to_f16 : SDNode<"ISD::FP32_TO_FP16", SDTFPToIntOp>;
397 def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
398 def select : SDNode<"ISD::SELECT" , SDTSelect>;
399 def vselect : SDNode<"ISD::VSELECT" , SDTVSelect>;
400 def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
402 def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
403 def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
404 def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
405 def trap : SDNode<"ISD::TRAP" , SDTNone,
406 [SDNPHasChain, SDNPSideEffect]>;
407 def debugtrap : SDNode<"ISD::DEBUGTRAP" , SDTNone,
408 [SDNPHasChain, SDNPSideEffect]>;
410 def prefetch : SDNode<"ISD::PREFETCH" , SDTPrefetch,
411 [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
414 def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
415 [SDNPHasChain, SDNPSideEffect]>;
417 def membarrier : SDNode<"ISD::MEMBARRIER" , SDTMemBarrier,
418 [SDNPHasChain, SDNPSideEffect]>;
420 def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
421 [SDNPHasChain, SDNPSideEffect]>;
423 def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
424 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
425 def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
426 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
427 def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
428 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
429 def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
430 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
431 def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
432 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
433 def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
434 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
435 def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
436 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
437 def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
438 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
439 def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
440 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
441 def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
442 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
443 def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
444 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
445 def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
446 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
447 def atomic_load : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
448 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
449 def atomic_store : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
450 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
452 // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
453 // and truncst (see below).
454 def ld : SDNode<"ISD::LOAD" , SDTLoad,
455 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
456 def st : SDNode<"ISD::STORE" , SDTStore,
457 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
458 def ist : SDNode<"ISD::STORE" , SDTIStore,
459 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
461 def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
462 def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
463 def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
465 def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
466 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
467 def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
468 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
470 // This operator does not do subvector type checking. The ARM
471 // backend, at least, needs it.
472 def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
473 SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
476 // This operator does subvector type checking.
477 def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
478 def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
480 // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
481 // these internally. Don't reference these directly.
482 def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
483 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
485 def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
486 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
488 def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
489 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
491 // Do not use cvt directly. Use cvt forms below
492 def cvt : SDNode<"ISD::CONVERT_RNDSAT", SDTConvertOp>;
494 //===----------------------------------------------------------------------===//
495 // Selection DAG Condition Codes
497 class CondCode; // ISD::CondCode enums
498 def SETOEQ : CondCode; def SETOGT : CondCode;
499 def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
500 def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
501 def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
502 def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
504 def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
505 def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
508 //===----------------------------------------------------------------------===//
509 // Selection DAG Node Transformation Functions.
511 // This mechanism allows targets to manipulate nodes in the output DAG once a
512 // match has been formed. This is typically used to manipulate immediate
515 class SDNodeXForm<SDNode opc, code xformFunction> {
517 code XFormFunction = xformFunction;
520 def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
522 //===----------------------------------------------------------------------===//
523 // PatPred Subclasses.
525 // These allow specifying different sorts of predicates that control whether a
530 class CodePatPred<code predicate> : PatPred {
531 code PredicateCode = predicate;
535 //===----------------------------------------------------------------------===//
536 // Selection DAG Pattern Fragments.
538 // Pattern fragments are reusable chunks of dags that match specific things.
539 // They can take arguments and have C++ predicates that control whether they
540 // match. They are intended to make the patterns for common instructions more
541 // compact and readable.
544 /// PatFrag - Represents a pattern fragment. This can match something on the
545 /// DAG, from a single node to multiple nested other fragments.
547 class PatFrag<dag ops, dag frag, code pred = [{}],
548 SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
551 code PredicateCode = pred;
552 code ImmediateCode = [{}];
553 SDNodeXForm OperandTransform = xform;
556 // PatLeaf's are pattern fragments that have no operands. This is just a helper
557 // to define immediates and other common things concisely.
558 class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
559 : PatFrag<(ops), frag, pred, xform>;
562 // ImmLeaf is a pattern fragment with a constraint on the immediate. The
563 // constraint is a function that is run on the immediate (always with the value
564 // sign extended out to an int64_t) as Imm. For example:
566 // def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
568 // this is a more convenient form to match 'imm' nodes in than PatLeaf and also
569 // is preferred over using PatLeaf because it allows the code generator to
570 // reason more about the constraint.
572 // If FastIsel should ignore all instructions that have an operand of this type,
573 // the FastIselShouldIgnore flag can be set. This is an optimization to reduce
574 // the code size of the generated fast instruction selector.
575 class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
576 : PatFrag<(ops), (vt imm), [{}], xform> {
577 let ImmediateCode = pred;
578 bit FastIselShouldIgnore = 0;
584 def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
585 def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
587 def immAllOnesV: PatLeaf<(build_vector), [{
588 return ISD::isBuildVectorAllOnes(N);
590 def immAllZerosV: PatLeaf<(build_vector), [{
591 return ISD::isBuildVectorAllZeros(N);
596 // Other helper fragments.
597 def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
598 def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
599 def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
601 // null_frag - The null pattern operator is used in multiclass instantiations
602 // which accept an SDPatternOperator for use in matching patterns for internal
603 // definitions. When expanding a pattern, if the null fragment is referenced
604 // in the expansion, the pattern is discarded and it is as-if '[]' had been
605 // specified. This allows multiclasses to have the isel patterns be optional.
606 def null_frag : SDPatternOperator;
609 def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
610 return cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
612 def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
613 return cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
616 // extending load fragments.
617 def extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
618 return cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
620 def sextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
621 return cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
623 def zextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
624 return cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
627 def extloadi1 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
628 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
630 def extloadi8 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
631 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
633 def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
634 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
636 def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
637 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
639 def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
640 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::f32;
642 def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
643 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::f64;
646 def sextloadi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
647 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
649 def sextloadi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
650 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
652 def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
653 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
655 def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
656 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
659 def zextloadi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
660 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
662 def zextloadi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
663 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
665 def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
666 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
668 def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
669 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
672 def extloadvi1 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
673 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
675 def extloadvi8 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
676 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
678 def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
679 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
681 def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
682 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
684 def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
685 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::f32;
687 def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
688 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::f64;
691 def sextloadvi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
692 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
694 def sextloadvi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
695 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
697 def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
698 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
700 def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
701 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
704 def zextloadvi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
705 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
707 def zextloadvi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
708 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
710 def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
711 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
713 def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
714 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
718 def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
719 (st node:$val, node:$ptr), [{
720 return cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
722 def store : PatFrag<(ops node:$val, node:$ptr),
723 (unindexedstore node:$val, node:$ptr), [{
724 return !cast<StoreSDNode>(N)->isTruncatingStore();
727 // truncstore fragments.
728 def truncstore : PatFrag<(ops node:$val, node:$ptr),
729 (unindexedstore node:$val, node:$ptr), [{
730 return cast<StoreSDNode>(N)->isTruncatingStore();
732 def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
733 (truncstore node:$val, node:$ptr), [{
734 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
736 def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
737 (truncstore node:$val, node:$ptr), [{
738 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
740 def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
741 (truncstore node:$val, node:$ptr), [{
742 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
744 def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
745 (truncstore node:$val, node:$ptr), [{
746 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
748 def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
749 (truncstore node:$val, node:$ptr), [{
750 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f64;
753 // indexed store fragments.
754 def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
755 (ist node:$val, node:$base, node:$offset), [{
756 return !cast<StoreSDNode>(N)->isTruncatingStore();
759 def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
760 (istore node:$val, node:$base, node:$offset), [{
761 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
762 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
765 def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
766 (ist node:$val, node:$base, node:$offset), [{
767 return cast<StoreSDNode>(N)->isTruncatingStore();
769 def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
770 (itruncstore node:$val, node:$base, node:$offset), [{
771 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
772 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
774 def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
775 (pre_truncst node:$val, node:$base, node:$offset), [{
776 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i1;
778 def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
779 (pre_truncst node:$val, node:$base, node:$offset), [{
780 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
782 def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
783 (pre_truncst node:$val, node:$base, node:$offset), [{
784 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
786 def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
787 (pre_truncst node:$val, node:$base, node:$offset), [{
788 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
790 def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
791 (pre_truncst node:$val, node:$base, node:$offset), [{
792 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
795 def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
796 (istore node:$val, node:$ptr, node:$offset), [{
797 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
798 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
801 def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
802 (itruncstore node:$val, node:$base, node:$offset), [{
803 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
804 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
806 def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
807 (post_truncst node:$val, node:$base, node:$offset), [{
808 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i1;
810 def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
811 (post_truncst node:$val, node:$base, node:$offset), [{
812 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
814 def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
815 (post_truncst node:$val, node:$base, node:$offset), [{
816 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
818 def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
819 (post_truncst node:$val, node:$base, node:$offset), [{
820 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
822 def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
823 (post_truncst node:$val, node:$base, node:$offset), [{
824 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
827 // setcc convenience fragments.
828 def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
829 (setcc node:$lhs, node:$rhs, SETOEQ)>;
830 def setogt : PatFrag<(ops node:$lhs, node:$rhs),
831 (setcc node:$lhs, node:$rhs, SETOGT)>;
832 def setoge : PatFrag<(ops node:$lhs, node:$rhs),
833 (setcc node:$lhs, node:$rhs, SETOGE)>;
834 def setolt : PatFrag<(ops node:$lhs, node:$rhs),
835 (setcc node:$lhs, node:$rhs, SETOLT)>;
836 def setole : PatFrag<(ops node:$lhs, node:$rhs),
837 (setcc node:$lhs, node:$rhs, SETOLE)>;
838 def setone : PatFrag<(ops node:$lhs, node:$rhs),
839 (setcc node:$lhs, node:$rhs, SETONE)>;
840 def seto : PatFrag<(ops node:$lhs, node:$rhs),
841 (setcc node:$lhs, node:$rhs, SETO)>;
842 def setuo : PatFrag<(ops node:$lhs, node:$rhs),
843 (setcc node:$lhs, node:$rhs, SETUO)>;
844 def setueq : PatFrag<(ops node:$lhs, node:$rhs),
845 (setcc node:$lhs, node:$rhs, SETUEQ)>;
846 def setugt : PatFrag<(ops node:$lhs, node:$rhs),
847 (setcc node:$lhs, node:$rhs, SETUGT)>;
848 def setuge : PatFrag<(ops node:$lhs, node:$rhs),
849 (setcc node:$lhs, node:$rhs, SETUGE)>;
850 def setult : PatFrag<(ops node:$lhs, node:$rhs),
851 (setcc node:$lhs, node:$rhs, SETULT)>;
852 def setule : PatFrag<(ops node:$lhs, node:$rhs),
853 (setcc node:$lhs, node:$rhs, SETULE)>;
854 def setune : PatFrag<(ops node:$lhs, node:$rhs),
855 (setcc node:$lhs, node:$rhs, SETUNE)>;
856 def seteq : PatFrag<(ops node:$lhs, node:$rhs),
857 (setcc node:$lhs, node:$rhs, SETEQ)>;
858 def setgt : PatFrag<(ops node:$lhs, node:$rhs),
859 (setcc node:$lhs, node:$rhs, SETGT)>;
860 def setge : PatFrag<(ops node:$lhs, node:$rhs),
861 (setcc node:$lhs, node:$rhs, SETGE)>;
862 def setlt : PatFrag<(ops node:$lhs, node:$rhs),
863 (setcc node:$lhs, node:$rhs, SETLT)>;
864 def setle : PatFrag<(ops node:$lhs, node:$rhs),
865 (setcc node:$lhs, node:$rhs, SETLE)>;
866 def setne : PatFrag<(ops node:$lhs, node:$rhs),
867 (setcc node:$lhs, node:$rhs, SETNE)>;
869 def atomic_cmp_swap_8 :
870 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
871 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
872 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
874 def atomic_cmp_swap_16 :
875 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
876 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
877 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
879 def atomic_cmp_swap_32 :
880 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
881 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
882 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
884 def atomic_cmp_swap_64 :
885 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
886 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
887 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
890 multiclass binary_atomic_op<SDNode atomic_op> {
891 def _8 : PatFrag<(ops node:$ptr, node:$val),
892 (atomic_op node:$ptr, node:$val), [{
893 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
895 def _16 : PatFrag<(ops node:$ptr, node:$val),
896 (atomic_op node:$ptr, node:$val), [{
897 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
899 def _32 : PatFrag<(ops node:$ptr, node:$val),
900 (atomic_op node:$ptr, node:$val), [{
901 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
903 def _64 : PatFrag<(ops node:$ptr, node:$val),
904 (atomic_op node:$ptr, node:$val), [{
905 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
909 defm atomic_load_add : binary_atomic_op<atomic_load_add>;
910 defm atomic_swap : binary_atomic_op<atomic_swap>;
911 defm atomic_load_sub : binary_atomic_op<atomic_load_sub>;
912 defm atomic_load_and : binary_atomic_op<atomic_load_and>;
913 defm atomic_load_or : binary_atomic_op<atomic_load_or>;
914 defm atomic_load_xor : binary_atomic_op<atomic_load_xor>;
915 defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
916 defm atomic_load_min : binary_atomic_op<atomic_load_min>;
917 defm atomic_load_max : binary_atomic_op<atomic_load_max>;
918 defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
919 defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
920 defm atomic_store : binary_atomic_op<atomic_store>;
923 PatFrag<(ops node:$ptr),
924 (atomic_load node:$ptr), [{
925 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
928 PatFrag<(ops node:$ptr),
929 (atomic_load node:$ptr), [{
930 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
933 PatFrag<(ops node:$ptr),
934 (atomic_load node:$ptr), [{
935 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
938 PatFrag<(ops node:$ptr),
939 (atomic_load node:$ptr), [{
940 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
943 //===----------------------------------------------------------------------===//
944 // Selection DAG CONVERT_RNDSAT patterns
946 def cvtff : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
947 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
948 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FF;
951 def cvtss : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
952 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
953 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SS;
956 def cvtsu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
957 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
958 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SU;
961 def cvtus : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
962 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
963 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_US;
966 def cvtuu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
967 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
968 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_UU;
971 def cvtsf : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
972 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
973 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SF;
976 def cvtuf : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
977 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
978 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_UF;
981 def cvtfs : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
982 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
983 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FS;
986 def cvtfu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
987 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
988 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FU;
991 //===----------------------------------------------------------------------===//
992 // Selection DAG Pattern Support.
994 // Patterns are what are actually matched against by the target-flavored
995 // instruction selection DAG. Instructions defined by the target implicitly
996 // define patterns in most cases, but patterns can also be explicitly added when
997 // an operation is defined by a sequence of instructions (e.g. loading a large
998 // immediate value on RISC targets that do not support immediates as large as
1002 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
1003 dag PatternToMatch = patternToMatch;
1004 list<dag> ResultInstrs = resultInstrs;
1005 list<Predicate> Predicates = []; // See class Instruction in Target.td.
1006 int AddedComplexity = 0; // See class Instruction in Target.td.
1009 // Pat - A simple (but common) form of a pattern, which produces a simple result
1010 // not needing a full list.
1011 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
1013 //===----------------------------------------------------------------------===//
1014 // Complex pattern definitions.
1017 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
1018 // in C++. NumOperands is the number of operands returned by the select function;
1019 // SelectFunc is the name of the function used to pattern match the max. pattern;
1020 // RootNodes are the list of possible root nodes of the sub-dags to match.
1021 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
1023 class ComplexPattern<ValueType ty, int numops, string fn,
1024 list<SDNode> roots = [], list<SDNodeProperty> props = []> {
1026 int NumOperands = numops;
1027 string SelectFunc = fn;
1028 list<SDNode> RootNodes = roots;
1029 list<SDNodeProperty> Properties = props;