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, [ // ctlz, cttz
141 SDTCisSameAs<0, 1>, SDTCisInt<0>
143 def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
144 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
146 def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
147 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
149 def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
150 SDTCisSameAs<0, 1>, SDTCisFP<0>
152 def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
153 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
155 def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
156 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
158 def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
159 SDTCisFP<0>, SDTCisInt<1>, SDTCisSameNumEltsAs<0, 1>
161 def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
162 SDTCisInt<0>, SDTCisFP<1>, SDTCisSameNumEltsAs<0, 1>
164 def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
165 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
166 SDTCisVTSmallerThanOp<2, 1>
168 def SDTExtInvec : SDTypeProfile<1, 1, [ // sext_invec
169 SDTCisInt<0>, SDTCisVec<0>, SDTCisInt<1>, SDTCisVec<1>,
170 SDTCisOpSmallerThanOp<1, 0>
173 def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
174 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
177 def SDTSelect : SDTypeProfile<1, 3, [ // select
178 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
181 def SDTVSelect : SDTypeProfile<1, 3, [ // vselect
182 SDTCisVec<0>, SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>, SDTCisSameNumEltsAs<0, 1>
185 def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
186 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
190 def SDTBr : SDTypeProfile<0, 1, [ // br
194 def SDTBrCC : SDTypeProfile<0, 4, [ // brcc
195 SDTCisVT<0, OtherVT>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
198 def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
199 SDTCisInt<0>, SDTCisVT<1, OtherVT>
202 def SDTBrind : SDTypeProfile<0, 1, [ // brind
206 def SDTCatchret : SDTypeProfile<0, 2, [ // catchret
207 SDTCisVT<0, OtherVT>, SDTCisVT<1, OtherVT>
210 def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
212 def SDTLoad : SDTypeProfile<1, 1, [ // load
216 def SDTStore : SDTypeProfile<0, 2, [ // store
220 def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
221 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
224 def SDTMaskedStore: SDTypeProfile<0, 3, [ // masked store
225 SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVec<2>, SDTCisSameNumEltsAs<0, 2>
228 def SDTMaskedLoad: SDTypeProfile<1, 3, [ // masked load
229 SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVec<2>, SDTCisSameAs<0, 3>,
230 SDTCisSameNumEltsAs<0, 2>
233 def SDTVecShuffle : SDTypeProfile<1, 2, [
234 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>
236 def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
237 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
239 def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
240 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
243 def SDTSubVecExtract : SDTypeProfile<1, 2, [// subvector extract
244 SDTCisSubVecOfVec<0,1>, SDTCisInt<2>
246 def SDTSubVecInsert : SDTypeProfile<1, 3, [ // subvector insert
247 SDTCisSubVecOfVec<2, 1>, SDTCisSameAs<0,1>, SDTCisInt<3>
250 def SDTPrefetch : SDTypeProfile<0, 4, [ // prefetch
251 SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisSameAs<1, 3>, SDTCisInt<1>
254 def SDTMemBarrier : SDTypeProfile<0, 5, [ // memory barrier
255 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
258 def SDTAtomicFence : SDTypeProfile<0, 2, [
259 SDTCisSameAs<0,1>, SDTCisPtrTy<0>
261 def SDTAtomic3 : SDTypeProfile<1, 3, [
262 SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
264 def SDTAtomic2 : SDTypeProfile<1, 2, [
265 SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
268 def SDTFPAtomic2 : SDTypeProfile<1, 2, [
269 SDTCisSameAs<0,2>, SDTCisFP<0>, SDTCisPtrTy<1>
272 def SDTAtomicStore : SDTypeProfile<0, 2, [
273 SDTCisPtrTy<0>, SDTCisInt<1>
275 def SDTAtomicLoad : SDTypeProfile<1, 1, [
276 SDTCisInt<0>, SDTCisPtrTy<1>
279 def SDTConvertOp : SDTypeProfile<1, 5, [ //cvtss, su, us, uu, ff, fs, fu, sf, su
280 SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>, SDTCisPtrTy<4>, SDTCisPtrTy<5>
283 class SDCallSeqStart<list<SDTypeConstraint> constraints> :
284 SDTypeProfile<0, 2, constraints>;
285 class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
286 SDTypeProfile<0, 2, constraints>;
288 //===----------------------------------------------------------------------===//
289 // Selection DAG Node definitions.
291 class SDNode<string opcode, SDTypeProfile typeprof,
292 list<SDNodeProperty> props = [], string sdclass = "SDNode">
293 : SDPatternOperator {
294 string Opcode = opcode;
295 string SDClass = sdclass;
296 let Properties = props;
297 SDTypeProfile TypeProfile = typeprof;
300 // Special TableGen-recognized dag nodes
306 def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
307 def timm : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
308 def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
309 def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
310 def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
311 def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
312 def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
313 def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
314 "GlobalAddressSDNode">;
315 def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
316 "GlobalAddressSDNode">;
317 def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
318 "GlobalAddressSDNode">;
319 def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
320 "GlobalAddressSDNode">;
321 def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
322 "ConstantPoolSDNode">;
323 def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
324 "ConstantPoolSDNode">;
325 def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
327 def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
329 def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
331 def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
333 def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
334 "ExternalSymbolSDNode">;
335 def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
336 "ExternalSymbolSDNode">;
337 def mcsym: SDNode<"ISD::MCSymbol", SDTPtrLeaf, [], "MCSymbolSDNode">;
338 def blockaddress : SDNode<"ISD::BlockAddress", SDTPtrLeaf, [],
339 "BlockAddressSDNode">;
340 def tblockaddress: SDNode<"ISD::TargetBlockAddress", SDTPtrLeaf, [],
341 "BlockAddressSDNode">;
343 def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
344 [SDNPCommutative, SDNPAssociative]>;
345 def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
346 def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
347 [SDNPCommutative, SDNPAssociative]>;
348 def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
349 def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
350 def smullohi : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
351 def umullohi : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
352 def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
353 def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
354 def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
355 def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
356 def sdivrem : SDNode<"ISD::SDIVREM" , SDTIntBinHiLoOp>;
357 def udivrem : SDNode<"ISD::UDIVREM" , SDTIntBinHiLoOp>;
358 def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
359 def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
360 def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
361 def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
362 def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
363 def fshl : SDNode<"ISD::FSHL" , SDTIntShiftDOp>;
364 def fshr : SDNode<"ISD::FSHR" , SDTIntShiftDOp>;
365 def and : SDNode<"ISD::AND" , SDTIntBinOp,
366 [SDNPCommutative, SDNPAssociative]>;
367 def or : SDNode<"ISD::OR" , SDTIntBinOp,
368 [SDNPCommutative, SDNPAssociative]>;
369 def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
370 [SDNPCommutative, SDNPAssociative]>;
371 def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
372 [SDNPCommutative, SDNPOutGlue]>;
373 def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
374 [SDNPCommutative, SDNPOutGlue, SDNPInGlue]>;
375 def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
377 def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
378 [SDNPOutGlue, SDNPInGlue]>;
379 def smin : SDNode<"ISD::SMIN" , SDTIntBinOp,
380 [SDNPCommutative, SDNPAssociative]>;
381 def smax : SDNode<"ISD::SMAX" , SDTIntBinOp,
382 [SDNPCommutative, SDNPAssociative]>;
383 def umin : SDNode<"ISD::UMIN" , SDTIntBinOp,
384 [SDNPCommutative, SDNPAssociative]>;
385 def umax : SDNode<"ISD::UMAX" , SDTIntBinOp,
386 [SDNPCommutative, SDNPAssociative]>;
388 def saddsat : SDNode<"ISD::SADDSAT" , SDTIntBinOp, [SDNPCommutative]>;
389 def uaddsat : SDNode<"ISD::UADDSAT" , SDTIntBinOp, [SDNPCommutative]>;
390 def ssubsat : SDNode<"ISD::SSUBSAT" , SDTIntBinOp>;
391 def usubsat : SDNode<"ISD::USUBSAT" , SDTIntBinOp>;
393 def smulfix : SDNode<"ISD::SMULFIX" , SDTIntScaledBinOp, [SDNPCommutative]>;
394 def umulfix : SDNode<"ISD::UMULFIX" , SDTIntScaledBinOp, [SDNPCommutative]>;
396 def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
397 def sext_invec : SDNode<"ISD::SIGN_EXTEND_VECTOR_INREG", SDTExtInvec>;
398 def zext_invec : SDNode<"ISD::ZERO_EXTEND_VECTOR_INREG", SDTExtInvec>;
400 def abs : SDNode<"ISD::ABS" , SDTIntUnaryOp>;
401 def bitreverse : SDNode<"ISD::BITREVERSE" , SDTIntUnaryOp>;
402 def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
403 def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
404 def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
405 def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
406 def ctlz_zero_undef : SDNode<"ISD::CTLZ_ZERO_UNDEF", SDTIntUnaryOp>;
407 def cttz_zero_undef : SDNode<"ISD::CTTZ_ZERO_UNDEF", SDTIntUnaryOp>;
408 def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
409 def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
410 def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
411 def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
412 def bitconvert : SDNode<"ISD::BITCAST" , SDTUnaryOp>;
413 def addrspacecast : SDNode<"ISD::ADDRSPACECAST", SDTUnaryOp>;
414 def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
415 def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
417 def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
418 def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
419 def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
420 def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
421 def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
422 def fma : SDNode<"ISD::FMA" , SDTFPTernaryOp>;
423 def fmad : SDNode<"ISD::FMAD" , SDTFPTernaryOp>;
424 def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
425 def fminnum : SDNode<"ISD::FMINNUM" , SDTFPBinOp,
426 [SDNPCommutative, SDNPAssociative]>;
427 def fmaxnum : SDNode<"ISD::FMAXNUM" , SDTFPBinOp,
428 [SDNPCommutative, SDNPAssociative]>;
429 def fminnum_ieee : SDNode<"ISD::FMINNUM_IEEE", SDTFPBinOp,
431 def fmaxnum_ieee : SDNode<"ISD::FMAXNUM_IEEE", SDTFPBinOp,
433 def fminimum : SDNode<"ISD::FMINIMUM" , SDTFPBinOp,
434 [SDNPCommutative, SDNPAssociative]>;
435 def fmaximum : SDNode<"ISD::FMAXIMUM" , SDTFPBinOp,
436 [SDNPCommutative, SDNPAssociative]>;
437 def fgetsign : SDNode<"ISD::FGETSIGN" , SDTFPToIntOp>;
438 def fcanonicalize : SDNode<"ISD::FCANONICALIZE", SDTFPUnaryOp>;
439 def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
440 def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
441 def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
442 def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
443 def fexp2 : SDNode<"ISD::FEXP2" , SDTFPUnaryOp>;
444 def fpow : SDNode<"ISD::FPOW" , SDTFPBinOp>;
445 def flog2 : SDNode<"ISD::FLOG2" , SDTFPUnaryOp>;
446 def frint : SDNode<"ISD::FRINT" , SDTFPUnaryOp>;
447 def ftrunc : SDNode<"ISD::FTRUNC" , SDTFPUnaryOp>;
448 def fceil : SDNode<"ISD::FCEIL" , SDTFPUnaryOp>;
449 def ffloor : SDNode<"ISD::FFLOOR" , SDTFPUnaryOp>;
450 def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
451 def fround : SDNode<"ISD::FROUND" , SDTFPUnaryOp>;
453 def fpround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
454 def fpextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
455 def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
457 def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
458 def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
459 def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
460 def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
461 def f16_to_fp : SDNode<"ISD::FP16_TO_FP" , SDTIntToFPOp>;
462 def fp_to_f16 : SDNode<"ISD::FP_TO_FP16" , SDTFPToIntOp>;
464 def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
465 def select : SDNode<"ISD::SELECT" , SDTSelect>;
466 def vselect : SDNode<"ISD::VSELECT" , SDTVSelect>;
467 def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
469 def brcc : SDNode<"ISD::BR_CC" , SDTBrCC, [SDNPHasChain]>;
470 def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
471 def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
472 def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
473 def catchret : SDNode<"ISD::CATCHRET" , SDTCatchret,
474 [SDNPHasChain, SDNPSideEffect]>;
475 def cleanupret : SDNode<"ISD::CLEANUPRET" , SDTNone, [SDNPHasChain]>;
476 def catchpad : SDNode<"ISD::CATCHPAD" , SDTNone,
477 [SDNPHasChain, SDNPSideEffect]>;
479 def trap : SDNode<"ISD::TRAP" , SDTNone,
480 [SDNPHasChain, SDNPSideEffect]>;
481 def debugtrap : SDNode<"ISD::DEBUGTRAP" , SDTNone,
482 [SDNPHasChain, SDNPSideEffect]>;
484 def prefetch : SDNode<"ISD::PREFETCH" , SDTPrefetch,
485 [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
488 def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
489 [SDNPHasChain, SDNPSideEffect]>;
491 def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
492 [SDNPHasChain, SDNPSideEffect]>;
494 def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
495 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
496 def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
497 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
498 def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
499 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
500 def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
501 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
502 def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
503 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
504 def atomic_load_clr : SDNode<"ISD::ATOMIC_LOAD_CLR" , SDTAtomic2,
505 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
506 def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
507 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
508 def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
509 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
510 def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
511 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
512 def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
513 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
514 def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
515 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
516 def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
517 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
518 def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
519 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
520 def atomic_load_fadd : SDNode<"ISD::ATOMIC_LOAD_FADD" , SDTFPAtomic2,
521 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
522 def atomic_load_fsub : SDNode<"ISD::ATOMIC_LOAD_FSUB" , SDTFPAtomic2,
523 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
525 def atomic_load : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
526 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
527 def atomic_store : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
528 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
530 def masked_store : SDNode<"ISD::MSTORE", SDTMaskedStore,
531 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
532 def masked_load : SDNode<"ISD::MLOAD", SDTMaskedLoad,
533 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
535 // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
536 // and truncst (see below).
537 def ld : SDNode<"ISD::LOAD" , SDTLoad,
538 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
539 def st : SDNode<"ISD::STORE" , SDTStore,
540 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
541 def ist : SDNode<"ISD::STORE" , SDTIStore,
542 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
544 def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
545 def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
546 def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
549 // vector_extract/vector_insert are deprecated. extractelt/insertelt
551 def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
552 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
553 def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
554 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
555 def concat_vectors : SDNode<"ISD::CONCAT_VECTORS",
556 SDTypeProfile<1, 2, [SDTCisSubVecOfVec<1, 0>, SDTCisSameAs<1, 2>]>,[]>;
558 // This operator does not do subvector type checking. The ARM
559 // backend, at least, needs it.
560 def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
561 SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
564 // This operator does subvector type checking.
565 def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
566 def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
568 // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
569 // these internally. Don't reference these directly.
570 def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
571 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
573 def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
574 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
576 def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
577 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
579 def SDT_assertext : SDTypeProfile<1, 1,
580 [SDTCisInt<0>, SDTCisInt<1>, SDTCisSameAs<1, 0>]>;
581 def assertsext : SDNode<"ISD::AssertSext", SDT_assertext>;
582 def assertzext : SDNode<"ISD::AssertZext", SDT_assertext>;
585 //===----------------------------------------------------------------------===//
586 // Selection DAG Condition Codes
588 class CondCode; // ISD::CondCode enums
589 def SETOEQ : CondCode; def SETOGT : CondCode;
590 def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
591 def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
592 def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
593 def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
595 def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
596 def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
599 //===----------------------------------------------------------------------===//
600 // Selection DAG Node Transformation Functions.
602 // This mechanism allows targets to manipulate nodes in the output DAG once a
603 // match has been formed. This is typically used to manipulate immediate
606 class SDNodeXForm<SDNode opc, code xformFunction> {
608 code XFormFunction = xformFunction;
611 def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
613 //===----------------------------------------------------------------------===//
614 // PatPred Subclasses.
616 // These allow specifying different sorts of predicates that control whether a
621 class CodePatPred<code predicate> : PatPred {
622 code PredicateCode = predicate;
626 //===----------------------------------------------------------------------===//
627 // Selection DAG Pattern Fragments.
629 // Pattern fragments are reusable chunks of dags that match specific things.
630 // They can take arguments and have C++ predicates that control whether they
631 // match. They are intended to make the patterns for common instructions more
632 // compact and readable.
635 /// PatFrags - Represents a set of pattern fragments. Each single fragment
636 /// can match something on the DAG, from a single node to multiple nested other
637 /// fragments. The whole set of fragments matches if any of the single
638 /// fragemnts match. This allows e.g. matching and "add with overflow" and
639 /// a regular "add" with the same fragment set.
641 class PatFrags<dag ops, list<dag> frags, code pred = [{}],
642 SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
644 list<dag> Fragments = frags;
645 code PredicateCode = pred;
646 code GISelPredicateCode = [{}];
647 code ImmediateCode = [{}];
648 SDNodeXForm OperandTransform = xform;
650 // When this is set, the PredicateCode may refer to a constant Operands
651 // vector which contains the captured nodes of the DAG, in the order listed
652 // by the Operands field above.
654 // This is useful when Fragments involves associative / commutative
655 // operators: a single piece of code can easily refer to all operands even
656 // when re-associated / commuted variants of the fragment are matched.
657 bit PredicateCodeUsesOperands = 0;
659 // Define a few pre-packaged predicates. This helps GlobalISel import
660 // existing rules from SelectionDAG for many common cases.
661 // They will be tested prior to the code in pred and must not be used in
662 // ImmLeaf and its subclasses.
664 // Is the desired pre-packaged predicate for a load?
666 // Is the desired pre-packaged predicate for a store?
668 // Is the desired pre-packaged predicate for an atomic?
671 // cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
672 // cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
675 // cast<LoadSDNode>(N)->getExtensionType() != ISD::NON_EXTLOAD
676 bit IsNonExtLoad = ?;
677 // cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
678 bit IsAnyExtLoad = ?;
679 // cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
680 bit IsSignExtLoad = ?;
681 // cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
682 bit IsZeroExtLoad = ?;
683 // !cast<StoreSDNode>(N)->isTruncatingStore();
684 // cast<StoreSDNode>(N)->isTruncatingStore();
685 bit IsTruncStore = ?;
687 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Monotonic
688 bit IsAtomicOrderingMonotonic = ?;
689 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Acquire
690 bit IsAtomicOrderingAcquire = ?;
691 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Release
692 bit IsAtomicOrderingRelease = ?;
693 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::AcquireRelease
694 bit IsAtomicOrderingAcquireRelease = ?;
695 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::SequentiallyConsistent
696 bit IsAtomicOrderingSequentiallyConsistent = ?;
698 // isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
699 // !isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
700 bit IsAtomicOrderingAcquireOrStronger = ?;
702 // isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
703 // !isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
704 bit IsAtomicOrderingReleaseOrStronger = ?;
706 // cast<LoadSDNode>(N)->getMemoryVT() == MVT::<VT>;
707 // cast<StoreSDNode>(N)->getMemoryVT() == MVT::<VT>;
708 ValueType MemoryVT = ?;
709 // cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
710 // cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
711 ValueType ScalarMemoryVT = ?;
714 // PatFrag - A version of PatFrags matching only a single fragment.
715 class PatFrag<dag ops, dag frag, code pred = [{}],
716 SDNodeXForm xform = NOOP_SDNodeXForm>
717 : PatFrags<ops, [frag], pred, xform>;
719 // OutPatFrag is a pattern fragment that is used as part of an output pattern
720 // (not an input pattern). These do not have predicates or transforms, but are
721 // used to avoid repeated subexpressions in output patterns.
722 class OutPatFrag<dag ops, dag frag>
723 : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;
725 // PatLeaf's are pattern fragments that have no operands. This is just a helper
726 // to define immediates and other common things concisely.
727 class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
728 : PatFrag<(ops), frag, pred, xform>;
731 // ImmLeaf is a pattern fragment with a constraint on the immediate. The
732 // constraint is a function that is run on the immediate (always with the value
733 // sign extended out to an int64_t) as Imm. For example:
735 // def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
737 // this is a more convenient form to match 'imm' nodes in than PatLeaf and also
738 // is preferred over using PatLeaf because it allows the code generator to
739 // reason more about the constraint.
741 // If FastIsel should ignore all instructions that have an operand of this type,
742 // the FastIselShouldIgnore flag can be set. This is an optimization to reduce
743 // the code size of the generated fast instruction selector.
744 class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
745 SDNode ImmNode = imm>
746 : PatFrag<(ops), (vt ImmNode), [{}], xform> {
747 let ImmediateCode = pred;
748 bit FastIselShouldIgnore = 0;
750 // Is the data type of the immediate an APInt?
753 // Is the data type of the immediate an APFloat?
757 // An ImmLeaf except that Imm is an APInt. This is useful when you need to
758 // zero-extend the immediate instead of sign-extend it.
760 // Note that FastISel does not currently understand IntImmLeaf and will not
761 // generate code for rules that make use of it. As such, it does not make sense
762 // to replace ImmLeaf with IntImmLeaf. However, replacing PatLeaf with an
763 // IntImmLeaf will allow GlobalISel to import the rule.
764 class IntImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
765 : ImmLeaf<vt, pred, xform> {
767 let FastIselShouldIgnore = 1;
770 // An ImmLeaf except that Imm is an APFloat.
772 // Note that FastISel does not currently understand FPImmLeaf and will not
773 // generate code for rules that make use of it.
774 class FPImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
775 : ImmLeaf<vt, pred, xform, fpimm> {
777 let FastIselShouldIgnore = 1;
782 def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
783 def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
785 def immAllOnesV: PatLeaf<(build_vector), [{
786 return ISD::isBuildVectorAllOnes(N);
788 def immAllZerosV: PatLeaf<(build_vector), [{
789 return ISD::isBuildVectorAllZeros(N);
794 // Other helper fragments.
795 def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
796 def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
797 def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
799 // null_frag - The null pattern operator is used in multiclass instantiations
800 // which accept an SDPatternOperator for use in matching patterns for internal
801 // definitions. When expanding a pattern, if the null fragment is referenced
802 // in the expansion, the pattern is discarded and it is as-if '[]' had been
803 // specified. This allows multiclasses to have the isel patterns be optional.
804 def null_frag : SDPatternOperator;
807 def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr)> {
811 def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
813 let IsNonExtLoad = 1;
816 // extending load fragments.
817 def extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
819 let IsAnyExtLoad = 1;
821 def sextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
823 let IsSignExtLoad = 1;
825 def zextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
827 let IsZeroExtLoad = 1;
830 def extloadi1 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
834 def extloadi8 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
838 def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
842 def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
846 def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
850 def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
855 def sextloadi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
859 def sextloadi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
863 def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
867 def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
872 def zextloadi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
876 def zextloadi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
880 def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
884 def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
889 def extloadvi1 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
891 let ScalarMemoryVT = i1;
893 def extloadvi8 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
895 let ScalarMemoryVT = i8;
897 def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
899 let ScalarMemoryVT = i16;
901 def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
903 let ScalarMemoryVT = i32;
905 def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
907 let ScalarMemoryVT = f32;
909 def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
911 let ScalarMemoryVT = f64;
914 def sextloadvi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
916 let ScalarMemoryVT = i1;
918 def sextloadvi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
920 let ScalarMemoryVT = i8;
922 def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
924 let ScalarMemoryVT = i16;
926 def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
928 let ScalarMemoryVT = i32;
931 def zextloadvi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
933 let ScalarMemoryVT = i1;
935 def zextloadvi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
937 let ScalarMemoryVT = i8;
939 def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
941 let ScalarMemoryVT = i16;
943 def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
945 let ScalarMemoryVT = i32;
949 def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
950 (st node:$val, node:$ptr)> {
954 def store : PatFrag<(ops node:$val, node:$ptr),
955 (unindexedstore node:$val, node:$ptr)> {
957 let IsTruncStore = 0;
960 // truncstore fragments.
961 def truncstore : PatFrag<(ops node:$val, node:$ptr),
962 (unindexedstore node:$val, node:$ptr)> {
964 let IsTruncStore = 1;
966 def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
967 (truncstore node:$val, node:$ptr)> {
971 def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
972 (truncstore node:$val, node:$ptr)> {
976 def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
977 (truncstore node:$val, node:$ptr)> {
981 def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
982 (truncstore node:$val, node:$ptr)> {
986 def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
987 (truncstore node:$val, node:$ptr)> {
992 def truncstorevi8 : PatFrag<(ops node:$val, node:$ptr),
993 (truncstore node:$val, node:$ptr)> {
995 let ScalarMemoryVT = i8;
998 def truncstorevi16 : PatFrag<(ops node:$val, node:$ptr),
999 (truncstore node:$val, node:$ptr)> {
1001 let ScalarMemoryVT = i16;
1004 def truncstorevi32 : PatFrag<(ops node:$val, node:$ptr),
1005 (truncstore node:$val, node:$ptr)> {
1007 let ScalarMemoryVT = i32;
1010 // indexed store fragments.
1011 def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
1012 (ist node:$val, node:$base, node:$offset)> {
1014 let IsTruncStore = 0;
1017 def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
1018 (istore node:$val, node:$base, node:$offset), [{
1019 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1020 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1023 def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
1024 (ist node:$val, node:$base, node:$offset)> {
1026 let IsTruncStore = 1;
1028 def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1029 (itruncstore node:$val, node:$base, node:$offset), [{
1030 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1031 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1033 def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1034 (pre_truncst node:$val, node:$base, node:$offset)> {
1038 def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1039 (pre_truncst node:$val, node:$base, node:$offset)> {
1043 def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1044 (pre_truncst node:$val, node:$base, node:$offset)> {
1048 def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1049 (pre_truncst node:$val, node:$base, node:$offset)> {
1053 def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1054 (pre_truncst node:$val, node:$base, node:$offset)> {
1059 def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
1060 (istore node:$val, node:$ptr, node:$offset), [{
1061 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1062 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1065 def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1066 (itruncstore node:$val, node:$base, node:$offset), [{
1067 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1068 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1070 def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1071 (post_truncst node:$val, node:$base, node:$offset)> {
1075 def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1076 (post_truncst node:$val, node:$base, node:$offset)> {
1080 def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1081 (post_truncst node:$val, node:$base, node:$offset)> {
1085 def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1086 (post_truncst node:$val, node:$base, node:$offset)> {
1090 def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1091 (post_truncst node:$val, node:$base, node:$offset)> {
1096 def nonvolatile_load : PatFrag<(ops node:$ptr),
1097 (load node:$ptr), [{
1098 return !cast<LoadSDNode>(N)->isVolatile();
1100 def nonvolatile_store : PatFrag<(ops node:$val, node:$ptr),
1101 (store node:$val, node:$ptr), [{
1102 return !cast<StoreSDNode>(N)->isVolatile();
1105 // nontemporal store fragments.
1106 def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1107 (store node:$val, node:$ptr), [{
1108 return cast<StoreSDNode>(N)->isNonTemporal();
1111 def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1112 (nontemporalstore node:$val, node:$ptr), [{
1113 StoreSDNode *St = cast<StoreSDNode>(N);
1114 return St->getAlignment() >= St->getMemoryVT().getStoreSize();
1117 def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1118 (nontemporalstore node:$val, node:$ptr), [{
1119 StoreSDNode *St = cast<StoreSDNode>(N);
1120 return St->getAlignment() < St->getMemoryVT().getStoreSize();
1123 // nontemporal load fragments.
1124 def nontemporalload : PatFrag<(ops node:$ptr),
1125 (load node:$ptr), [{
1126 return cast<LoadSDNode>(N)->isNonTemporal();
1129 def alignednontemporalload : PatFrag<(ops node:$ptr),
1130 (nontemporalload node:$ptr), [{
1131 LoadSDNode *Ld = cast<LoadSDNode>(N);
1132 return Ld->getAlignment() >= Ld->getMemoryVT().getStoreSize();
1135 // setcc convenience fragments.
1136 def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
1137 (setcc node:$lhs, node:$rhs, SETOEQ)>;
1138 def setogt : PatFrag<(ops node:$lhs, node:$rhs),
1139 (setcc node:$lhs, node:$rhs, SETOGT)>;
1140 def setoge : PatFrag<(ops node:$lhs, node:$rhs),
1141 (setcc node:$lhs, node:$rhs, SETOGE)>;
1142 def setolt : PatFrag<(ops node:$lhs, node:$rhs),
1143 (setcc node:$lhs, node:$rhs, SETOLT)>;
1144 def setole : PatFrag<(ops node:$lhs, node:$rhs),
1145 (setcc node:$lhs, node:$rhs, SETOLE)>;
1146 def setone : PatFrag<(ops node:$lhs, node:$rhs),
1147 (setcc node:$lhs, node:$rhs, SETONE)>;
1148 def seto : PatFrag<(ops node:$lhs, node:$rhs),
1149 (setcc node:$lhs, node:$rhs, SETO)>;
1150 def setuo : PatFrag<(ops node:$lhs, node:$rhs),
1151 (setcc node:$lhs, node:$rhs, SETUO)>;
1152 def setueq : PatFrag<(ops node:$lhs, node:$rhs),
1153 (setcc node:$lhs, node:$rhs, SETUEQ)>;
1154 def setugt : PatFrag<(ops node:$lhs, node:$rhs),
1155 (setcc node:$lhs, node:$rhs, SETUGT)>;
1156 def setuge : PatFrag<(ops node:$lhs, node:$rhs),
1157 (setcc node:$lhs, node:$rhs, SETUGE)>;
1158 def setult : PatFrag<(ops node:$lhs, node:$rhs),
1159 (setcc node:$lhs, node:$rhs, SETULT)>;
1160 def setule : PatFrag<(ops node:$lhs, node:$rhs),
1161 (setcc node:$lhs, node:$rhs, SETULE)>;
1162 def setune : PatFrag<(ops node:$lhs, node:$rhs),
1163 (setcc node:$lhs, node:$rhs, SETUNE)>;
1164 def seteq : PatFrag<(ops node:$lhs, node:$rhs),
1165 (setcc node:$lhs, node:$rhs, SETEQ)>;
1166 def setgt : PatFrag<(ops node:$lhs, node:$rhs),
1167 (setcc node:$lhs, node:$rhs, SETGT)>;
1168 def setge : PatFrag<(ops node:$lhs, node:$rhs),
1169 (setcc node:$lhs, node:$rhs, SETGE)>;
1170 def setlt : PatFrag<(ops node:$lhs, node:$rhs),
1171 (setcc node:$lhs, node:$rhs, SETLT)>;
1172 def setle : PatFrag<(ops node:$lhs, node:$rhs),
1173 (setcc node:$lhs, node:$rhs, SETLE)>;
1174 def setne : PatFrag<(ops node:$lhs, node:$rhs),
1175 (setcc node:$lhs, node:$rhs, SETNE)>;
1177 multiclass binary_atomic_op_ord<SDNode atomic_op> {
1178 def #NAME#_monotonic : PatFrag<(ops node:$ptr, node:$val),
1179 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1181 let IsAtomicOrderingMonotonic = 1;
1183 def #NAME#_acquire : PatFrag<(ops node:$ptr, node:$val),
1184 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1186 let IsAtomicOrderingAcquire = 1;
1188 def #NAME#_release : PatFrag<(ops node:$ptr, node:$val),
1189 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1191 let IsAtomicOrderingRelease = 1;
1193 def #NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$val),
1194 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1196 let IsAtomicOrderingAcquireRelease = 1;
1198 def #NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$val),
1199 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1201 let IsAtomicOrderingSequentiallyConsistent = 1;
1205 multiclass ternary_atomic_op_ord<SDNode atomic_op> {
1206 def #NAME#_monotonic : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1207 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1209 let IsAtomicOrderingMonotonic = 1;
1211 def #NAME#_acquire : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1212 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1214 let IsAtomicOrderingAcquire = 1;
1216 def #NAME#_release : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1217 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1219 let IsAtomicOrderingRelease = 1;
1221 def #NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1222 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1224 let IsAtomicOrderingAcquireRelease = 1;
1226 def #NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1227 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1229 let IsAtomicOrderingSequentiallyConsistent = 1;
1233 multiclass binary_atomic_op<SDNode atomic_op> {
1234 def _8 : PatFrag<(ops node:$ptr, node:$val),
1235 (atomic_op node:$ptr, node:$val)> {
1239 def _16 : PatFrag<(ops node:$ptr, node:$val),
1240 (atomic_op node:$ptr, node:$val)> {
1244 def _32 : PatFrag<(ops node:$ptr, node:$val),
1245 (atomic_op node:$ptr, node:$val)> {
1249 def _64 : PatFrag<(ops node:$ptr, node:$val),
1250 (atomic_op node:$ptr, node:$val)> {
1255 defm NAME#_8 : binary_atomic_op_ord<atomic_op>;
1256 defm NAME#_16 : binary_atomic_op_ord<atomic_op>;
1257 defm NAME#_32 : binary_atomic_op_ord<atomic_op>;
1258 defm NAME#_64 : binary_atomic_op_ord<atomic_op>;
1261 multiclass ternary_atomic_op<SDNode atomic_op> {
1262 def _8 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1263 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1267 def _16 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1268 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1272 def _32 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1273 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1277 def _64 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1278 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1283 defm NAME#_8 : ternary_atomic_op_ord<atomic_op>;
1284 defm NAME#_16 : ternary_atomic_op_ord<atomic_op>;
1285 defm NAME#_32 : ternary_atomic_op_ord<atomic_op>;
1286 defm NAME#_64 : ternary_atomic_op_ord<atomic_op>;
1289 defm atomic_load_add : binary_atomic_op<atomic_load_add>;
1290 defm atomic_swap : binary_atomic_op<atomic_swap>;
1291 defm atomic_load_sub : binary_atomic_op<atomic_load_sub>;
1292 defm atomic_load_and : binary_atomic_op<atomic_load_and>;
1293 defm atomic_load_clr : binary_atomic_op<atomic_load_clr>;
1294 defm atomic_load_or : binary_atomic_op<atomic_load_or>;
1295 defm atomic_load_xor : binary_atomic_op<atomic_load_xor>;
1296 defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
1297 defm atomic_load_min : binary_atomic_op<atomic_load_min>;
1298 defm atomic_load_max : binary_atomic_op<atomic_load_max>;
1299 defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
1300 defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
1301 defm atomic_store : binary_atomic_op<atomic_store>;
1302 defm atomic_cmp_swap : ternary_atomic_op<atomic_cmp_swap>;
1305 PatFrag<(ops node:$ptr),
1306 (atomic_load node:$ptr)> {
1310 def atomic_load_16 :
1311 PatFrag<(ops node:$ptr),
1312 (atomic_load node:$ptr)> {
1316 def atomic_load_32 :
1317 PatFrag<(ops node:$ptr),
1318 (atomic_load node:$ptr)> {
1322 def atomic_load_64 :
1323 PatFrag<(ops node:$ptr),
1324 (atomic_load node:$ptr)> {
1329 //===----------------------------------------------------------------------===//
1330 // Selection DAG Pattern Support.
1332 // Patterns are what are actually matched against by the target-flavored
1333 // instruction selection DAG. Instructions defined by the target implicitly
1334 // define patterns in most cases, but patterns can also be explicitly added when
1335 // an operation is defined by a sequence of instructions (e.g. loading a large
1336 // immediate value on RISC targets that do not support immediates as large as
1340 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
1341 dag PatternToMatch = patternToMatch;
1342 list<dag> ResultInstrs = resultInstrs;
1343 list<Predicate> Predicates = []; // See class Instruction in Target.td.
1344 int AddedComplexity = 0; // See class Instruction in Target.td.
1347 // Pat - A simple (but common) form of a pattern, which produces a simple result
1348 // not needing a full list.
1349 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
1351 //===----------------------------------------------------------------------===//
1352 // Complex pattern definitions.
1355 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
1356 // in C++. NumOperands is the number of operands returned by the select function;
1357 // SelectFunc is the name of the function used to pattern match the max. pattern;
1358 // RootNodes are the list of possible root nodes of the sub-dags to match.
1359 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
1361 class ComplexPattern<ValueType ty, int numops, string fn,
1362 list<SDNode> roots = [], list<SDNodeProperty> props = [],
1363 int complexity = -1> {
1365 int NumOperands = numops;
1366 string SelectFunc = fn;
1367 list<SDNode> RootNodes = roots;
1368 list<SDNodeProperty> Properties = props;
1369 int Complexity = complexity;