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 // SDTCVecEltisVT - The specified operand is vector type with element type
73 class SDTCVecEltisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
77 // SDTCisSameNumEltsAs - The two specified operands have identical number
79 class SDTCisSameNumEltsAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
80 int OtherOperandNum = OtherOp;
83 //===----------------------------------------------------------------------===//
84 // Selection DAG Type Profile definitions.
86 // These use the constraints defined above to describe the type requirements of
87 // the various nodes. These are not hard coded into tblgen, allowing targets to
88 // add their own if needed.
91 // SDTypeProfile - This profile describes the type requirements of a Selection
93 class SDTypeProfile<int numresults, int numoperands,
94 list<SDTypeConstraint> constraints> {
95 int NumResults = numresults;
96 int NumOperands = numoperands;
97 list<SDTypeConstraint> Constraints = constraints;
101 def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
102 def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
103 def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
104 def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
105 def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
106 def SDTUnaryOp : SDTypeProfile<1, 1, []>; // for bitconvert.
108 def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
109 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
111 def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
112 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
114 def SDTIntBinHiLoOp : SDTypeProfile<2, 2, [ // mulhi, mullo, sdivrem, udivrem
115 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,SDTCisInt<0>
118 def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
119 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
121 def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
122 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
124 def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
125 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
127 def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz
128 SDTCisSameAs<0, 1>, SDTCisInt<0>
130 def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
131 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>
133 def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
134 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>
136 def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
137 SDTCisSameAs<0, 1>, SDTCisFP<0>
139 def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
140 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>
142 def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
143 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>
145 def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
146 SDTCisFP<0>, SDTCisInt<1>
148 def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
149 SDTCisInt<0>, SDTCisFP<1>
151 def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
152 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
153 SDTCisVTSmallerThanOp<2, 1>
156 def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
157 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
160 def SDTSelect : SDTypeProfile<1, 3, [ // select
161 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
164 def SDTVSelect : SDTypeProfile<1, 3, [ // vselect
165 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
168 def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
169 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
173 def SDTBr : SDTypeProfile<0, 1, [ // br
177 def SDTBrCC : SDTypeProfile<0, 4, [ // brcc
178 SDTCisVT<0, OtherVT>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
181 def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
182 SDTCisInt<0>, SDTCisVT<1, OtherVT>
185 def SDTBrind : SDTypeProfile<0, 1, [ // brind
189 def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
191 def SDTLoad : SDTypeProfile<1, 1, [ // load
195 def SDTStore : SDTypeProfile<0, 2, [ // store
199 def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
200 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
203 def SDTMaskedStore: SDTypeProfile<0, 3, [ // masked store
204 SDTCisPtrTy<0>, SDTCisVec<1>, SDTCisVec<2>
207 def SDTMaskedLoad: SDTypeProfile<1, 3, [ // masked load
208 SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVec<2>, SDTCisSameAs<0, 3>
211 def SDTMaskedGather: SDTypeProfile<2, 3, [ // masked gather
212 SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<1, 3>,
213 SDTCisPtrTy<4>, SDTCVecEltisVT<1, i1>, SDTCisSameNumEltsAs<0, 1>
216 def SDTMaskedScatter: SDTypeProfile<1, 3, [ // masked scatter
217 SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<0, 2>, SDTCisSameNumEltsAs<0, 1>,
218 SDTCVecEltisVT<0, i1>, SDTCisPtrTy<3>
221 def SDTVecShuffle : SDTypeProfile<1, 2, [
222 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>
224 def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
225 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
227 def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
228 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
231 def SDTSubVecExtract : SDTypeProfile<1, 2, [// subvector extract
232 SDTCisSubVecOfVec<0,1>, SDTCisInt<2>
234 def SDTSubVecInsert : SDTypeProfile<1, 3, [ // subvector insert
235 SDTCisSubVecOfVec<2, 1>, SDTCisSameAs<0,1>, SDTCisInt<3>
238 def SDTPrefetch : SDTypeProfile<0, 4, [ // prefetch
239 SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisSameAs<1, 3>, SDTCisInt<1>
242 def SDTMemBarrier : SDTypeProfile<0, 5, [ // memory barrier
243 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
246 def SDTAtomicFence : SDTypeProfile<0, 2, [
247 SDTCisSameAs<0,1>, SDTCisPtrTy<0>
249 def SDTAtomic3 : SDTypeProfile<1, 3, [
250 SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
252 def SDTAtomic2 : SDTypeProfile<1, 2, [
253 SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
255 def SDTAtomicStore : SDTypeProfile<0, 2, [
256 SDTCisPtrTy<0>, SDTCisInt<1>
258 def SDTAtomicLoad : SDTypeProfile<1, 1, [
259 SDTCisInt<0>, SDTCisPtrTy<1>
262 def SDTConvertOp : SDTypeProfile<1, 5, [ //cvtss, su, us, uu, ff, fs, fu, sf, su
263 SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>, SDTCisPtrTy<4>, SDTCisPtrTy<5>
266 class SDCallSeqStart<list<SDTypeConstraint> constraints> :
267 SDTypeProfile<0, 1, constraints>;
268 class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
269 SDTypeProfile<0, 2, constraints>;
271 //===----------------------------------------------------------------------===//
272 // Selection DAG Node Properties.
274 // Note: These are hard coded into tblgen.
276 class SDNodeProperty;
277 def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
278 def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
279 def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
280 def SDNPOutGlue : SDNodeProperty; // Write a flag result
281 def SDNPInGlue : SDNodeProperty; // Read a flag operand
282 def SDNPOptInGlue : SDNodeProperty; // Optionally read a flag operand
283 def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
284 def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
285 def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
286 def SDNPMemOperand : SDNodeProperty; // Touches memory, has assoc MemOperand
287 def SDNPVariadic : SDNodeProperty; // Node has variable arguments.
288 def SDNPWantRoot : SDNodeProperty; // ComplexPattern gets the root of match
289 def SDNPWantParent : SDNodeProperty; // ComplexPattern gets the parent
291 //===----------------------------------------------------------------------===//
292 // Selection DAG Pattern Operations
293 class SDPatternOperator;
295 //===----------------------------------------------------------------------===//
296 // Selection DAG Node definitions.
298 class SDNode<string opcode, SDTypeProfile typeprof,
299 list<SDNodeProperty> props = [], string sdclass = "SDNode">
300 : SDPatternOperator {
301 string Opcode = opcode;
302 string SDClass = sdclass;
303 list<SDNodeProperty> Properties = props;
304 SDTypeProfile TypeProfile = typeprof;
307 // Special TableGen-recognized dag nodes
313 def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
314 def timm : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
315 def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
316 def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
317 def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
318 def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
319 def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
320 def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
321 "GlobalAddressSDNode">;
322 def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
323 "GlobalAddressSDNode">;
324 def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
325 "GlobalAddressSDNode">;
326 def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
327 "GlobalAddressSDNode">;
328 def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
329 "ConstantPoolSDNode">;
330 def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
331 "ConstantPoolSDNode">;
332 def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
334 def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
336 def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
338 def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
340 def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
341 "ExternalSymbolSDNode">;
342 def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
343 "ExternalSymbolSDNode">;
344 def mcsym: SDNode<"ISD::MCSymbol", SDTPtrLeaf, [], "MCSymbolSDNode">;
345 def blockaddress : SDNode<"ISD::BlockAddress", SDTPtrLeaf, [],
346 "BlockAddressSDNode">;
347 def tblockaddress: SDNode<"ISD::TargetBlockAddress", SDTPtrLeaf, [],
348 "BlockAddressSDNode">;
350 def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
351 [SDNPCommutative, SDNPAssociative]>;
352 def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
353 def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
354 [SDNPCommutative, SDNPAssociative]>;
355 def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
356 def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
357 def smullohi : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
358 def umullohi : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
359 def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
360 def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
361 def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
362 def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
363 def sdivrem : SDNode<"ISD::SDIVREM" , SDTIntBinHiLoOp>;
364 def udivrem : SDNode<"ISD::UDIVREM" , SDTIntBinHiLoOp>;
365 def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
366 def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
367 def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
368 def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
369 def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
370 def and : SDNode<"ISD::AND" , SDTIntBinOp,
371 [SDNPCommutative, SDNPAssociative]>;
372 def or : SDNode<"ISD::OR" , SDTIntBinOp,
373 [SDNPCommutative, SDNPAssociative]>;
374 def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
375 [SDNPCommutative, SDNPAssociative]>;
376 def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
377 [SDNPCommutative, SDNPOutGlue]>;
378 def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
379 [SDNPCommutative, SDNPOutGlue, SDNPInGlue]>;
380 def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
382 def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
383 [SDNPOutGlue, SDNPInGlue]>;
384 def smin : SDNode<"ISD::SMIN" , SDTIntBinOp>;
385 def smax : SDNode<"ISD::SMAX" , SDTIntBinOp>;
386 def umin : SDNode<"ISD::UMIN" , SDTIntBinOp>;
387 def umax : SDNode<"ISD::UMAX" , SDTIntBinOp>;
389 def sabsdiff : SDNode<"ISD::SABSDIFF" , SDTIntBinOp>;
390 def uabsdiff : SDNode<"ISD::UABSDIFF" , SDTIntBinOp>;
391 def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
392 def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
393 def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
394 def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
395 def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
396 def ctlz_zero_undef : SDNode<"ISD::CTLZ_ZERO_UNDEF", SDTIntUnaryOp>;
397 def cttz_zero_undef : SDNode<"ISD::CTTZ_ZERO_UNDEF", SDTIntUnaryOp>;
398 def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
399 def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
400 def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
401 def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
402 def bitconvert : SDNode<"ISD::BITCAST" , SDTUnaryOp>;
403 def addrspacecast : SDNode<"ISD::ADDRSPACECAST", SDTUnaryOp>;
404 def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
405 def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
407 def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
408 def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
409 def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
410 def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
411 def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
412 def fma : SDNode<"ISD::FMA" , SDTFPTernaryOp>;
413 def fmad : SDNode<"ISD::FMAD" , SDTFPTernaryOp>;
414 def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
415 def fminnum : SDNode<"ISD::FMINNUM" , SDTFPBinOp>;
416 def fmaxnum : SDNode<"ISD::FMAXNUM" , SDTFPBinOp>;
417 def fgetsign : SDNode<"ISD::FGETSIGN" , SDTFPToIntOp>;
418 def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
419 def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
420 def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
421 def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
422 def fexp2 : SDNode<"ISD::FEXP2" , SDTFPUnaryOp>;
423 def fpow : SDNode<"ISD::FPOW" , SDTFPBinOp>;
424 def flog2 : SDNode<"ISD::FLOG2" , SDTFPUnaryOp>;
425 def frint : SDNode<"ISD::FRINT" , SDTFPUnaryOp>;
426 def ftrunc : SDNode<"ISD::FTRUNC" , SDTFPUnaryOp>;
427 def fceil : SDNode<"ISD::FCEIL" , SDTFPUnaryOp>;
428 def ffloor : SDNode<"ISD::FFLOOR" , SDTFPUnaryOp>;
429 def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
430 def frnd : SDNode<"ISD::FROUND" , SDTFPUnaryOp>;
432 def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
433 def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
434 def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
436 def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
437 def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
438 def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
439 def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
440 def f16_to_fp : SDNode<"ISD::FP16_TO_FP" , SDTIntToFPOp>;
441 def fp_to_f16 : SDNode<"ISD::FP_TO_FP16" , SDTFPToIntOp>;
443 def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
444 def select : SDNode<"ISD::SELECT" , SDTSelect>;
445 def vselect : SDNode<"ISD::VSELECT" , SDTVSelect>;
446 def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
448 def brcc : SDNode<"ISD::BR_CC" , SDTBrCC, [SDNPHasChain]>;
449 def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
450 def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
451 def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
452 def trap : SDNode<"ISD::TRAP" , SDTNone,
453 [SDNPHasChain, SDNPSideEffect]>;
454 def debugtrap : SDNode<"ISD::DEBUGTRAP" , SDTNone,
455 [SDNPHasChain, SDNPSideEffect]>;
457 def prefetch : SDNode<"ISD::PREFETCH" , SDTPrefetch,
458 [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
461 def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
462 [SDNPHasChain, SDNPSideEffect]>;
464 def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
465 [SDNPHasChain, SDNPSideEffect]>;
467 def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
468 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
469 def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
470 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
471 def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
472 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
473 def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
474 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
475 def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
476 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
477 def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
478 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
479 def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
480 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
481 def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
482 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
483 def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
484 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
485 def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
486 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
487 def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
488 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
489 def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
490 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
491 def atomic_load : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
492 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
493 def atomic_store : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
494 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
496 // Do not use mld, mst directly. Use masked_store masked_load, masked_truncstore
497 def mst : SDNode<"ISD::MSTORE", SDTMaskedStore,
498 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
499 def mld : SDNode<"ISD::MLOAD", SDTMaskedLoad,
500 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
501 def masked_scatter : SDNode<"ISD::MSCATTER", SDTMaskedScatter,
502 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
503 def masked_gather : SDNode<"ISD::MGATHER", SDTMaskedGather,
504 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
506 // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
507 // and truncst (see below).
508 def ld : SDNode<"ISD::LOAD" , SDTLoad,
509 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
510 def st : SDNode<"ISD::STORE" , SDTStore,
511 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
512 def ist : SDNode<"ISD::STORE" , SDTIStore,
513 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
515 def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
516 def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
517 def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
519 def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
520 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
521 def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
522 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
523 def concat_vectors : SDNode<"ISD::CONCAT_VECTORS",
524 SDTypeProfile<1, 2, [SDTCisSubVecOfVec<1, 0>, SDTCisSameAs<1, 2>]>,[]>;
526 // This operator does not do subvector type checking. The ARM
527 // backend, at least, needs it.
528 def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
529 SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
532 // This operator does subvector type checking.
533 def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
534 def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
536 // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
537 // these internally. Don't reference these directly.
538 def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
539 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
541 def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
542 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
544 def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
545 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
547 // Do not use cvt directly. Use cvt forms below
548 def cvt : SDNode<"ISD::CONVERT_RNDSAT", SDTConvertOp>;
550 def SDT_assertext : SDTypeProfile<1, 1,
551 [SDTCisInt<0>, SDTCisInt<1>, SDTCisSameAs<1, 0>]>;
552 def assertsext : SDNode<"ISD::AssertSext", SDT_assertext>;
553 def assertzext : SDNode<"ISD::AssertZext", SDT_assertext>;
556 //===----------------------------------------------------------------------===//
557 // Selection DAG Condition Codes
559 class CondCode; // ISD::CondCode enums
560 def SETOEQ : CondCode; def SETOGT : CondCode;
561 def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
562 def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
563 def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
564 def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
566 def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
567 def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
570 //===----------------------------------------------------------------------===//
571 // Selection DAG Node Transformation Functions.
573 // This mechanism allows targets to manipulate nodes in the output DAG once a
574 // match has been formed. This is typically used to manipulate immediate
577 class SDNodeXForm<SDNode opc, code xformFunction> {
579 code XFormFunction = xformFunction;
582 def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
584 //===----------------------------------------------------------------------===//
585 // PatPred Subclasses.
587 // These allow specifying different sorts of predicates that control whether a
592 class CodePatPred<code predicate> : PatPred {
593 code PredicateCode = predicate;
597 //===----------------------------------------------------------------------===//
598 // Selection DAG Pattern Fragments.
600 // Pattern fragments are reusable chunks of dags that match specific things.
601 // They can take arguments and have C++ predicates that control whether they
602 // match. They are intended to make the patterns for common instructions more
603 // compact and readable.
606 /// PatFrag - Represents a pattern fragment. This can match something on the
607 /// DAG, from a single node to multiple nested other fragments.
609 class PatFrag<dag ops, dag frag, code pred = [{}],
610 SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
613 code PredicateCode = pred;
614 code ImmediateCode = [{}];
615 SDNodeXForm OperandTransform = xform;
618 // OutPatFrag is a pattern fragment that is used as part of an output pattern
619 // (not an input pattern). These do not have predicates or transforms, but are
620 // used to avoid repeated subexpressions in output patterns.
621 class OutPatFrag<dag ops, dag frag>
622 : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;
624 // PatLeaf's are pattern fragments that have no operands. This is just a helper
625 // to define immediates and other common things concisely.
626 class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
627 : PatFrag<(ops), frag, pred, xform>;
630 // ImmLeaf is a pattern fragment with a constraint on the immediate. The
631 // constraint is a function that is run on the immediate (always with the value
632 // sign extended out to an int64_t) as Imm. For example:
634 // def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
636 // this is a more convenient form to match 'imm' nodes in than PatLeaf and also
637 // is preferred over using PatLeaf because it allows the code generator to
638 // reason more about the constraint.
640 // If FastIsel should ignore all instructions that have an operand of this type,
641 // the FastIselShouldIgnore flag can be set. This is an optimization to reduce
642 // the code size of the generated fast instruction selector.
643 class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
644 : PatFrag<(ops), (vt imm), [{}], xform> {
645 let ImmediateCode = pred;
646 bit FastIselShouldIgnore = 0;
652 def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
653 def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
655 def immAllOnesV: PatLeaf<(build_vector), [{
656 return ISD::isBuildVectorAllOnes(N);
658 def immAllZerosV: PatLeaf<(build_vector), [{
659 return ISD::isBuildVectorAllZeros(N);
664 // Other helper fragments.
665 def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
666 def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
667 def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
669 // null_frag - The null pattern operator is used in multiclass instantiations
670 // which accept an SDPatternOperator for use in matching patterns for internal
671 // definitions. When expanding a pattern, if the null fragment is referenced
672 // in the expansion, the pattern is discarded and it is as-if '[]' had been
673 // specified. This allows multiclasses to have the isel patterns be optional.
674 def null_frag : SDPatternOperator;
677 def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
678 return cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
680 def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
681 return cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
684 // masked load fragments.
685 def masked_load : PatFrag<(ops node:$src1, node:$src2, node:$src3),
686 (mld node:$src1, node:$src2, node:$src3), [{
687 return cast<MaskedLoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
690 // extending load fragments.
691 def extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
692 return cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
694 def sextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
695 return cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
697 def zextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
698 return cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
701 def extloadi1 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
702 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
704 def extloadi8 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
705 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
707 def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
708 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
710 def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
711 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
713 def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
714 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::f32;
716 def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
717 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::f64;
720 def sextloadi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
721 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
723 def sextloadi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
724 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
726 def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
727 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
729 def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
730 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
733 def zextloadi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
734 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
736 def zextloadi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
737 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
739 def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
740 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
742 def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
743 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
746 def extloadvi1 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
747 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
749 def extloadvi8 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
750 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
752 def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
753 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
755 def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
756 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
758 def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
759 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::f32;
761 def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
762 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::f64;
765 def sextloadvi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
766 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
768 def sextloadvi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
769 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
771 def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
772 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
774 def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
775 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
778 def zextloadvi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
779 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
781 def zextloadvi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
782 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
784 def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
785 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
787 def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
788 return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
792 def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
793 (st node:$val, node:$ptr), [{
794 return cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
796 def store : PatFrag<(ops node:$val, node:$ptr),
797 (unindexedstore node:$val, node:$ptr), [{
798 return !cast<StoreSDNode>(N)->isTruncatingStore();
801 // masked store fragments.
802 def masked_store : PatFrag<(ops node:$src1, node:$src2, node:$src3),
803 (mst node:$src1, node:$src2, node:$src3), [{
804 return !cast<MaskedStoreSDNode>(N)->isTruncatingStore();
807 // truncstore fragments.
808 def truncstore : PatFrag<(ops node:$val, node:$ptr),
809 (unindexedstore node:$val, node:$ptr), [{
810 return cast<StoreSDNode>(N)->isTruncatingStore();
812 def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
813 (truncstore node:$val, node:$ptr), [{
814 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
816 def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
817 (truncstore node:$val, node:$ptr), [{
818 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
820 def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
821 (truncstore node:$val, node:$ptr), [{
822 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
824 def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
825 (truncstore node:$val, node:$ptr), [{
826 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
828 def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
829 (truncstore node:$val, node:$ptr), [{
830 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f64;
833 def truncstorevi8 : PatFrag<(ops node:$val, node:$ptr),
834 (truncstore node:$val, node:$ptr), [{
835 return cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
838 def truncstorevi16 : PatFrag<(ops node:$val, node:$ptr),
839 (truncstore node:$val, node:$ptr), [{
840 return cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
843 def truncstorevi32 : PatFrag<(ops node:$val, node:$ptr),
844 (truncstore node:$val, node:$ptr), [{
845 return cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
848 // indexed store fragments.
849 def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
850 (ist node:$val, node:$base, node:$offset), [{
851 return !cast<StoreSDNode>(N)->isTruncatingStore();
854 def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
855 (istore node:$val, node:$base, node:$offset), [{
856 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
857 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
860 def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
861 (ist node:$val, node:$base, node:$offset), [{
862 return cast<StoreSDNode>(N)->isTruncatingStore();
864 def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
865 (itruncstore node:$val, node:$base, node:$offset), [{
866 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
867 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
869 def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
870 (pre_truncst node:$val, node:$base, node:$offset), [{
871 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i1;
873 def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
874 (pre_truncst node:$val, node:$base, node:$offset), [{
875 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
877 def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
878 (pre_truncst node:$val, node:$base, node:$offset), [{
879 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
881 def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
882 (pre_truncst node:$val, node:$base, node:$offset), [{
883 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
885 def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
886 (pre_truncst node:$val, node:$base, node:$offset), [{
887 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
890 def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
891 (istore node:$val, node:$ptr, node:$offset), [{
892 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
893 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
896 def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
897 (itruncstore node:$val, node:$base, node:$offset), [{
898 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
899 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
901 def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
902 (post_truncst node:$val, node:$base, node:$offset), [{
903 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i1;
905 def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
906 (post_truncst node:$val, node:$base, node:$offset), [{
907 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
909 def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
910 (post_truncst node:$val, node:$base, node:$offset), [{
911 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
913 def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
914 (post_truncst node:$val, node:$base, node:$offset), [{
915 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
917 def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
918 (post_truncst node:$val, node:$base, node:$offset), [{
919 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
922 // masked truncstore fragments
923 def masked_truncstore : PatFrag<(ops node:$src1, node:$src2, node:$src3),
924 (mst node:$src1, node:$src2, node:$src3), [{
925 return cast<MaskedStoreSDNode>(N)->isTruncatingStore();
927 def masked_truncstorevi8 :
928 PatFrag<(ops node:$src1, node:$src2, node:$src3),
929 (masked_truncstore node:$src1, node:$src2, node:$src3), [{
930 return cast<MaskedStoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
932 def masked_truncstorevi16 :
933 PatFrag<(ops node:$src1, node:$src2, node:$src3),
934 (masked_truncstore node:$src1, node:$src2, node:$src3), [{
935 return cast<MaskedStoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
937 def masked_truncstorevi32 :
938 PatFrag<(ops node:$src1, node:$src2, node:$src3),
939 (masked_truncstore node:$src1, node:$src2, node:$src3), [{
940 return cast<MaskedStoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
943 // setcc convenience fragments.
944 def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
945 (setcc node:$lhs, node:$rhs, SETOEQ)>;
946 def setogt : PatFrag<(ops node:$lhs, node:$rhs),
947 (setcc node:$lhs, node:$rhs, SETOGT)>;
948 def setoge : PatFrag<(ops node:$lhs, node:$rhs),
949 (setcc node:$lhs, node:$rhs, SETOGE)>;
950 def setolt : PatFrag<(ops node:$lhs, node:$rhs),
951 (setcc node:$lhs, node:$rhs, SETOLT)>;
952 def setole : PatFrag<(ops node:$lhs, node:$rhs),
953 (setcc node:$lhs, node:$rhs, SETOLE)>;
954 def setone : PatFrag<(ops node:$lhs, node:$rhs),
955 (setcc node:$lhs, node:$rhs, SETONE)>;
956 def seto : PatFrag<(ops node:$lhs, node:$rhs),
957 (setcc node:$lhs, node:$rhs, SETO)>;
958 def setuo : PatFrag<(ops node:$lhs, node:$rhs),
959 (setcc node:$lhs, node:$rhs, SETUO)>;
960 def setueq : PatFrag<(ops node:$lhs, node:$rhs),
961 (setcc node:$lhs, node:$rhs, SETUEQ)>;
962 def setugt : PatFrag<(ops node:$lhs, node:$rhs),
963 (setcc node:$lhs, node:$rhs, SETUGT)>;
964 def setuge : PatFrag<(ops node:$lhs, node:$rhs),
965 (setcc node:$lhs, node:$rhs, SETUGE)>;
966 def setult : PatFrag<(ops node:$lhs, node:$rhs),
967 (setcc node:$lhs, node:$rhs, SETULT)>;
968 def setule : PatFrag<(ops node:$lhs, node:$rhs),
969 (setcc node:$lhs, node:$rhs, SETULE)>;
970 def setune : PatFrag<(ops node:$lhs, node:$rhs),
971 (setcc node:$lhs, node:$rhs, SETUNE)>;
972 def seteq : PatFrag<(ops node:$lhs, node:$rhs),
973 (setcc node:$lhs, node:$rhs, SETEQ)>;
974 def setgt : PatFrag<(ops node:$lhs, node:$rhs),
975 (setcc node:$lhs, node:$rhs, SETGT)>;
976 def setge : PatFrag<(ops node:$lhs, node:$rhs),
977 (setcc node:$lhs, node:$rhs, SETGE)>;
978 def setlt : PatFrag<(ops node:$lhs, node:$rhs),
979 (setcc node:$lhs, node:$rhs, SETLT)>;
980 def setle : PatFrag<(ops node:$lhs, node:$rhs),
981 (setcc node:$lhs, node:$rhs, SETLE)>;
982 def setne : PatFrag<(ops node:$lhs, node:$rhs),
983 (setcc node:$lhs, node:$rhs, SETNE)>;
985 def atomic_cmp_swap_8 :
986 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
987 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
988 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
990 def atomic_cmp_swap_16 :
991 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
992 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
993 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
995 def atomic_cmp_swap_32 :
996 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
997 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
998 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
1000 def atomic_cmp_swap_64 :
1001 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
1002 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
1003 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
1006 multiclass binary_atomic_op<SDNode atomic_op> {
1007 def _8 : PatFrag<(ops node:$ptr, node:$val),
1008 (atomic_op node:$ptr, node:$val), [{
1009 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
1011 def _16 : PatFrag<(ops node:$ptr, node:$val),
1012 (atomic_op node:$ptr, node:$val), [{
1013 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
1015 def _32 : PatFrag<(ops node:$ptr, node:$val),
1016 (atomic_op node:$ptr, node:$val), [{
1017 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
1019 def _64 : PatFrag<(ops node:$ptr, node:$val),
1020 (atomic_op node:$ptr, node:$val), [{
1021 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
1025 defm atomic_load_add : binary_atomic_op<atomic_load_add>;
1026 defm atomic_swap : binary_atomic_op<atomic_swap>;
1027 defm atomic_load_sub : binary_atomic_op<atomic_load_sub>;
1028 defm atomic_load_and : binary_atomic_op<atomic_load_and>;
1029 defm atomic_load_or : binary_atomic_op<atomic_load_or>;
1030 defm atomic_load_xor : binary_atomic_op<atomic_load_xor>;
1031 defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
1032 defm atomic_load_min : binary_atomic_op<atomic_load_min>;
1033 defm atomic_load_max : binary_atomic_op<atomic_load_max>;
1034 defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
1035 defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
1036 defm atomic_store : binary_atomic_op<atomic_store>;
1039 PatFrag<(ops node:$ptr),
1040 (atomic_load node:$ptr), [{
1041 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
1043 def atomic_load_16 :
1044 PatFrag<(ops node:$ptr),
1045 (atomic_load node:$ptr), [{
1046 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
1048 def atomic_load_32 :
1049 PatFrag<(ops node:$ptr),
1050 (atomic_load node:$ptr), [{
1051 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
1053 def atomic_load_64 :
1054 PatFrag<(ops node:$ptr),
1055 (atomic_load node:$ptr), [{
1056 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
1059 //===----------------------------------------------------------------------===//
1060 // Selection DAG CONVERT_RNDSAT patterns
1062 def cvtff : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1063 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1064 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FF;
1067 def cvtss : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1068 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1069 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SS;
1072 def cvtsu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1073 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1074 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SU;
1077 def cvtus : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1078 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1079 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_US;
1082 def cvtuu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1083 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1084 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_UU;
1087 def cvtsf : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1088 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1089 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SF;
1092 def cvtuf : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1093 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1094 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_UF;
1097 def cvtfs : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1098 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1099 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FS;
1102 def cvtfu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
1103 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
1104 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FU;
1107 //===----------------------------------------------------------------------===//
1108 // Selection DAG Pattern Support.
1110 // Patterns are what are actually matched against by the target-flavored
1111 // instruction selection DAG. Instructions defined by the target implicitly
1112 // define patterns in most cases, but patterns can also be explicitly added when
1113 // an operation is defined by a sequence of instructions (e.g. loading a large
1114 // immediate value on RISC targets that do not support immediates as large as
1118 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
1119 dag PatternToMatch = patternToMatch;
1120 list<dag> ResultInstrs = resultInstrs;
1121 list<Predicate> Predicates = []; // See class Instruction in Target.td.
1122 int AddedComplexity = 0; // See class Instruction in Target.td.
1125 // Pat - A simple (but common) form of a pattern, which produces a simple result
1126 // not needing a full list.
1127 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
1129 //===----------------------------------------------------------------------===//
1130 // Complex pattern definitions.
1133 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
1134 // in C++. NumOperands is the number of operands returned by the select function;
1135 // SelectFunc is the name of the function used to pattern match the max. pattern;
1136 // RootNodes are the list of possible root nodes of the sub-dags to match.
1137 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
1139 class ComplexPattern<ValueType ty, int numops, string fn,
1140 list<SDNode> roots = [], list<SDNodeProperty> props = []> {
1142 int NumOperands = numops;
1143 string SelectFunc = fn;
1144 list<SDNode> RootNodes = roots;
1145 list<SDNodeProperty> Properties = props;