blob: 7ba8f7e3f7e916539b12f34636f11f64507980ec [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the target-independent interfaces used by SelectionDAG
11// instruction selection generators.
12//
13//===----------------------------------------------------------------------===//
14
15//===----------------------------------------------------------------------===//
16// Selection DAG Type Constraint definitions.
17//
18// Note that the semantics of these constraints are hard coded into tblgen. To
19// modify or add constraints, you have to hack tblgen.
20//
21
22class SDTypeConstraint<int opnum> {
23 int OperandNum = opnum;
24}
25
26// SDTCisVT - The specified operand has exactly this VT.
27class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
28 ValueType VT = vt;
29}
30
31class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
32
33// SDTCisInt - The specified operand has integer type.
34class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
35
36// SDTCisFP - The specified operand has floating-point type.
37class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
38
39// SDTCisVec - The specified operand has a vector type.
40class SDTCisVec<int OpNum> : SDTypeConstraint<OpNum>;
41
42// SDTCisSameAs - The two specified operands have identical types.
43class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
44 int OtherOperandNum = OtherOp;
45}
46
47// SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
48// smaller than the 'Other' operand.
49class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
50 int OtherOperandNum = OtherOp;
51}
52
53class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
54 int BigOperandNum = BigOp;
55}
56
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.
59class SDTCisEltOfVec<int ThisOp, int OtherOp>
60 : SDTypeConstraint<ThisOp> {
61 int OtherOpNum = OtherOp;
62}
63
64/// SDTCisSubVecOfVec - This indicates that ThisOp is a vector type
65/// with length less that of OtherOp, which is a vector type.
66class SDTCisSubVecOfVec<int ThisOp, int OtherOp>
67 : SDTypeConstraint<ThisOp> {
68 int OtherOpNum = OtherOp;
69}
70
71// SDTCVecEltisVT - The specified operand is vector type with element type
72// of VT.
73class SDTCVecEltisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
74 ValueType VT = vt;
75}
76
77// SDTCisSameNumEltsAs - The two specified operands have identical number
78// of elements.
79class SDTCisSameNumEltsAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
80 int OtherOperandNum = OtherOp;
81}
82
83// SDTCisSameSizeAs - The two specified operands have identical size.
84class SDTCisSameSizeAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
85 int OtherOperandNum = OtherOp;
86}
87
88//===----------------------------------------------------------------------===//
89// Selection DAG Type Profile definitions.
90//
91// These use the constraints defined above to describe the type requirements of
92// the various nodes. These are not hard coded into tblgen, allowing targets to
93// add their own if needed.
94//
95
96// SDTypeProfile - This profile describes the type requirements of a Selection
97// DAG node.
98class SDTypeProfile<int numresults, int numoperands,
99 list<SDTypeConstraint> constraints> {
100 int NumResults = numresults;
101 int NumOperands = numoperands;
102 list<SDTypeConstraint> Constraints = constraints;
103}
104
105// Builtin profiles.
106def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
107def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
108def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
109def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
110def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
111def SDTUnaryOp : SDTypeProfile<1, 1, []>; // for bitconvert.
112
113def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
114 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
115]>;
116def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
117 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
118]>;
119def SDTIntSatNoShOp : SDTypeProfile<1, 2, [ // ssat with no shift
120 SDTCisSameAs<0, 1>, SDTCisInt<2>
121]>;
122def SDTIntBinHiLoOp : SDTypeProfile<2, 2, [ // mulhi, mullo, sdivrem, udivrem
123 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,SDTCisInt<0>
124]>;
125
126def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
127 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
128]>;
129def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
130 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
131]>;
132def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
133 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
134]>;
135def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz, cttz
136 SDTCisSameAs<0, 1>, SDTCisInt<0>
137]>;
138def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
139 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
140]>;
141def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
142 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
143]>;
144def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
145 SDTCisSameAs<0, 1>, SDTCisFP<0>
146]>;
147def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
148 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
149]>;
150def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
151 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
152]>;
153def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
154 SDTCisFP<0>, SDTCisInt<1>, SDTCisSameNumEltsAs<0, 1>
155]>;
156def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
157 SDTCisInt<0>, SDTCisFP<1>, SDTCisSameNumEltsAs<0, 1>
158]>;
159def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
160 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
161 SDTCisVTSmallerThanOp<2, 1>
162]>;
163def SDTExtInvec : SDTypeProfile<1, 1, [ // sext_invec
164 SDTCisInt<0>, SDTCisVec<0>, SDTCisInt<1>, SDTCisVec<1>,
165 SDTCisOpSmallerThanOp<1, 0>, SDTCisSameSizeAs<0,1>
166]>;
167
168def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
169 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
170]>;
171
172def SDTSelect : SDTypeProfile<1, 3, [ // select
173 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
174]>;
175
176def SDTVSelect : SDTypeProfile<1, 3, [ // vselect
177 SDTCisVec<0>, SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>, SDTCisSameNumEltsAs<0, 1>
178]>;
179
180def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
181 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
182 SDTCisVT<5, OtherVT>
183]>;
184
185def SDTBr : SDTypeProfile<0, 1, [ // br
186 SDTCisVT<0, OtherVT>
187]>;
188
189def SDTBrCC : SDTypeProfile<0, 4, [ // brcc
190 SDTCisVT<0, OtherVT>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
191]>;
192
193def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
194 SDTCisInt<0>, SDTCisVT<1, OtherVT>
195]>;
196
197def SDTBrind : SDTypeProfile<0, 1, [ // brind
198 SDTCisPtrTy<0>
199]>;
200
201def SDTCatchret : SDTypeProfile<0, 2, [ // catchret
202 SDTCisVT<0, OtherVT>, SDTCisVT<1, OtherVT>
203]>;
204
205def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
206
207def SDTLoad : SDTypeProfile<1, 1, [ // load
208 SDTCisPtrTy<1>
209]>;
210
211def SDTStore : SDTypeProfile<0, 2, [ // store
212 SDTCisPtrTy<1>
213]>;
214
215def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
216 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
217]>;
218
219def SDTMaskedStore: SDTypeProfile<0, 3, [ // masked store
220 SDTCisPtrTy<0>, SDTCisVec<1>, SDTCisVec<2>, SDTCisSameNumEltsAs<1, 2>
221]>;
222
223def SDTMaskedLoad: SDTypeProfile<1, 3, [ // masked load
224 SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVec<2>, SDTCisSameAs<0, 3>,
225 SDTCisSameNumEltsAs<0, 2>
226]>;
227
228def SDTMaskedGather: SDTypeProfile<2, 3, [ // masked gather
229 SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<1, 3>,
230 SDTCisPtrTy<4>, SDTCVecEltisVT<1, i1>, SDTCisSameNumEltsAs<0, 1>
231]>;
232
233def SDTMaskedScatter: SDTypeProfile<1, 3, [ // masked scatter
234 SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<0, 2>, SDTCisSameNumEltsAs<0, 1>,
235 SDTCVecEltisVT<0, i1>, SDTCisPtrTy<3>
236]>;
237
238def SDTVecShuffle : SDTypeProfile<1, 2, [
239 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>
240]>;
241def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
242 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
243]>;
244def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
245 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
246]>;
247
248def SDTSubVecExtract : SDTypeProfile<1, 2, [// subvector extract
249 SDTCisSubVecOfVec<0,1>, SDTCisInt<2>
250]>;
251def SDTSubVecInsert : SDTypeProfile<1, 3, [ // subvector insert
252 SDTCisSubVecOfVec<2, 1>, SDTCisSameAs<0,1>, SDTCisInt<3>
253]>;
254
255def SDTPrefetch : SDTypeProfile<0, 4, [ // prefetch
256 SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisSameAs<1, 3>, SDTCisInt<1>
257]>;
258
259def SDTMemBarrier : SDTypeProfile<0, 5, [ // memory barrier
260 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
261 SDTCisInt<0>
262]>;
263def SDTAtomicFence : SDTypeProfile<0, 2, [
264 SDTCisSameAs<0,1>, SDTCisPtrTy<0>
265]>;
266def SDTAtomic3 : SDTypeProfile<1, 3, [
267 SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
268]>;
269def SDTAtomic2 : SDTypeProfile<1, 2, [
270 SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
271]>;
272def SDTAtomicStore : SDTypeProfile<0, 2, [
273 SDTCisPtrTy<0>, SDTCisInt<1>
274]>;
275def SDTAtomicLoad : SDTypeProfile<1, 1, [
276 SDTCisInt<0>, SDTCisPtrTy<1>
277]>;
278
279def SDTConvertOp : SDTypeProfile<1, 5, [ //cvtss, su, us, uu, ff, fs, fu, sf, su
280 SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>, SDTCisPtrTy<4>, SDTCisPtrTy<5>
281]>;
282
283class SDCallSeqStart<list<SDTypeConstraint> constraints> :
284 SDTypeProfile<0, 2, constraints>;
285class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
286 SDTypeProfile<0, 2, constraints>;
287
288//===----------------------------------------------------------------------===//
289// Selection DAG Node definitions.
290//
291class 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;
298}
299
300// Special TableGen-recognized dag nodes
301def set;
302def implicit;
303def node;
304def srcvalue;
305
306def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
307def timm : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
308def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
309def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
310def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
311def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
312def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
313def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
314 "GlobalAddressSDNode">;
315def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
316 "GlobalAddressSDNode">;
317def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
318 "GlobalAddressSDNode">;
319def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
320 "GlobalAddressSDNode">;
321def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
322 "ConstantPoolSDNode">;
323def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
324 "ConstantPoolSDNode">;
325def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
326 "JumpTableSDNode">;
327def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
328 "JumpTableSDNode">;
329def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
330 "FrameIndexSDNode">;
331def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
332 "FrameIndexSDNode">;
333def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
334 "ExternalSymbolSDNode">;
335def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
336 "ExternalSymbolSDNode">;
337def mcsym: SDNode<"ISD::MCSymbol", SDTPtrLeaf, [], "MCSymbolSDNode">;
338def blockaddress : SDNode<"ISD::BlockAddress", SDTPtrLeaf, [],
339 "BlockAddressSDNode">;
340def tblockaddress: SDNode<"ISD::TargetBlockAddress", SDTPtrLeaf, [],
341 "BlockAddressSDNode">;
342
343def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
344 [SDNPCommutative, SDNPAssociative]>;
345def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
346def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
347 [SDNPCommutative, SDNPAssociative]>;
348def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
349def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
350def smullohi : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
351def umullohi : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
352def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
353def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
354def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
355def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
356def sdivrem : SDNode<"ISD::SDIVREM" , SDTIntBinHiLoOp>;
357def udivrem : SDNode<"ISD::UDIVREM" , SDTIntBinHiLoOp>;
358def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
359def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
360def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
361def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
362def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
363def and : SDNode<"ISD::AND" , SDTIntBinOp,
364 [SDNPCommutative, SDNPAssociative]>;
365def or : SDNode<"ISD::OR" , SDTIntBinOp,
366 [SDNPCommutative, SDNPAssociative]>;
367def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
368 [SDNPCommutative, SDNPAssociative]>;
369def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
370 [SDNPCommutative, SDNPOutGlue]>;
371def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
372 [SDNPCommutative, SDNPOutGlue, SDNPInGlue]>;
373def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
374 [SDNPOutGlue]>;
375def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
376 [SDNPOutGlue, SDNPInGlue]>;
377def smin : SDNode<"ISD::SMIN" , SDTIntBinOp,
378 [SDNPCommutative, SDNPAssociative]>;
379def smax : SDNode<"ISD::SMAX" , SDTIntBinOp,
380 [SDNPCommutative, SDNPAssociative]>;
381def umin : SDNode<"ISD::UMIN" , SDTIntBinOp,
382 [SDNPCommutative, SDNPAssociative]>;
383def umax : SDNode<"ISD::UMAX" , SDTIntBinOp,
384 [SDNPCommutative, SDNPAssociative]>;
385
386def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
387def sext_invec : SDNode<"ISD::SIGN_EXTEND_VECTOR_INREG", SDTExtInvec>;
388def zext_invec : SDNode<"ISD::ZERO_EXTEND_VECTOR_INREG", SDTExtInvec>;
389
390def abs : SDNode<"ISD::ABS" , SDTIntUnaryOp>;
391def bitreverse : SDNode<"ISD::BITREVERSE" , SDTIntUnaryOp>;
392def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
393def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
394def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
395def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
396def ctlz_zero_undef : SDNode<"ISD::CTLZ_ZERO_UNDEF", SDTIntUnaryOp>;
397def cttz_zero_undef : SDNode<"ISD::CTTZ_ZERO_UNDEF", SDTIntUnaryOp>;
398def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
399def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
400def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
401def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
402def bitconvert : SDNode<"ISD::BITCAST" , SDTUnaryOp>;
403def addrspacecast : SDNode<"ISD::ADDRSPACECAST", SDTUnaryOp>;
404def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
405def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
406
407def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
408def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
409def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
410def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
411def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
412def fma : SDNode<"ISD::FMA" , SDTFPTernaryOp>;
413def fmad : SDNode<"ISD::FMAD" , SDTFPTernaryOp>;
414def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
415def fminnum : SDNode<"ISD::FMINNUM" , SDTFPBinOp,
416 [SDNPCommutative, SDNPAssociative]>;
417def fmaxnum : SDNode<"ISD::FMAXNUM" , SDTFPBinOp,
418 [SDNPCommutative, SDNPAssociative]>;
419def fminnan : SDNode<"ISD::FMINNAN" , SDTFPBinOp>;
420def fmaxnan : SDNode<"ISD::FMAXNAN" , SDTFPBinOp>;
421def fgetsign : SDNode<"ISD::FGETSIGN" , SDTFPToIntOp>;
422def fcanonicalize : SDNode<"ISD::FCANONICALIZE", SDTFPUnaryOp>;
423def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
424def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
425def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
426def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
427def fexp2 : SDNode<"ISD::FEXP2" , SDTFPUnaryOp>;
428def fpow : SDNode<"ISD::FPOW" , SDTFPBinOp>;
429def flog2 : SDNode<"ISD::FLOG2" , SDTFPUnaryOp>;
430def frint : SDNode<"ISD::FRINT" , SDTFPUnaryOp>;
431def ftrunc : SDNode<"ISD::FTRUNC" , SDTFPUnaryOp>;
432def fceil : SDNode<"ISD::FCEIL" , SDTFPUnaryOp>;
433def ffloor : SDNode<"ISD::FFLOOR" , SDTFPUnaryOp>;
434def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
435def fround : SDNode<"ISD::FROUND" , SDTFPUnaryOp>;
436
437def fpround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
438def fpextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
439def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
440
441def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
442def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
443def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
444def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
445def f16_to_fp : SDNode<"ISD::FP16_TO_FP" , SDTIntToFPOp>;
446def fp_to_f16 : SDNode<"ISD::FP_TO_FP16" , SDTFPToIntOp>;
447
448def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
449def select : SDNode<"ISD::SELECT" , SDTSelect>;
450def vselect : SDNode<"ISD::VSELECT" , SDTVSelect>;
451def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
452
453def brcc : SDNode<"ISD::BR_CC" , SDTBrCC, [SDNPHasChain]>;
454def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
455def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
456def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
457def catchret : SDNode<"ISD::CATCHRET" , SDTCatchret,
458 [SDNPHasChain, SDNPSideEffect]>;
459def cleanupret : SDNode<"ISD::CLEANUPRET" , SDTNone, [SDNPHasChain]>;
460def catchpad : SDNode<"ISD::CATCHPAD" , SDTNone,
461 [SDNPHasChain, SDNPSideEffect]>;
462
463def trap : SDNode<"ISD::TRAP" , SDTNone,
464 [SDNPHasChain, SDNPSideEffect]>;
465def debugtrap : SDNode<"ISD::DEBUGTRAP" , SDTNone,
466 [SDNPHasChain, SDNPSideEffect]>;
467
468def prefetch : SDNode<"ISD::PREFETCH" , SDTPrefetch,
469 [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
470 SDNPMemOperand]>;
471
472def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
473 [SDNPHasChain, SDNPSideEffect]>;
474
475def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
476 [SDNPHasChain, SDNPSideEffect]>;
477
478def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
479 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
480def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
481 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
482def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
483 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
484def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
485 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
486def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
487 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
488def atomic_load_clr : SDNode<"ISD::ATOMIC_LOAD_CLR" , SDTAtomic2,
489 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
490def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
491 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
492def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
493 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
494def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
495 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
496def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
497 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
498def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
499 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
500def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
501 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
502def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
503 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
504def atomic_load : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
505 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
506def atomic_store : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
507 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
508
509def masked_store : SDNode<"ISD::MSTORE", SDTMaskedStore,
510 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
511def masked_load : SDNode<"ISD::MLOAD", SDTMaskedLoad,
512 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
513def masked_scatter : SDNode<"ISD::MSCATTER", SDTMaskedScatter,
514 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
515def masked_gather : SDNode<"ISD::MGATHER", SDTMaskedGather,
516 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
517
518// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
519// and truncst (see below).
520def ld : SDNode<"ISD::LOAD" , SDTLoad,
521 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
522def st : SDNode<"ISD::STORE" , SDTStore,
523 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
524def ist : SDNode<"ISD::STORE" , SDTIStore,
525 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
526
527def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
528def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
529def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
530 []>;
531
532// vector_extract/vector_insert are deprecated. extractelt/insertelt
533// are preferred.
534def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
535 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
536def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
537 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
538def concat_vectors : SDNode<"ISD::CONCAT_VECTORS",
539 SDTypeProfile<1, 2, [SDTCisSubVecOfVec<1, 0>, SDTCisSameAs<1, 2>]>,[]>;
540
541// This operator does not do subvector type checking. The ARM
542// backend, at least, needs it.
543def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
544 SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
545 []>;
546
547// This operator does subvector type checking.
548def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
549def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
550
551// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
552// these internally. Don't reference these directly.
553def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
554 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
555 [SDNPHasChain]>;
556def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
557 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
558 [SDNPHasChain]>;
559def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
560 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
561
562def SDT_assertext : SDTypeProfile<1, 1,
563 [SDTCisInt<0>, SDTCisInt<1>, SDTCisSameAs<1, 0>]>;
564def assertsext : SDNode<"ISD::AssertSext", SDT_assertext>;
565def assertzext : SDNode<"ISD::AssertZext", SDT_assertext>;
566
567
568//===----------------------------------------------------------------------===//
569// Selection DAG Condition Codes
570
571class CondCode; // ISD::CondCode enums
572def SETOEQ : CondCode; def SETOGT : CondCode;
573def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
574def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
575def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
576def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
577
578def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
579def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
580
581
582//===----------------------------------------------------------------------===//
583// Selection DAG Node Transformation Functions.
584//
585// This mechanism allows targets to manipulate nodes in the output DAG once a
586// match has been formed. This is typically used to manipulate immediate
587// values.
588//
589class SDNodeXForm<SDNode opc, code xformFunction> {
590 SDNode Opcode = opc;
591 code XFormFunction = xformFunction;
592}
593
594def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
595
596//===----------------------------------------------------------------------===//
597// PatPred Subclasses.
598//
599// These allow specifying different sorts of predicates that control whether a
600// node is matched.
601//
602class PatPred;
603
604class CodePatPred<code predicate> : PatPred {
605 code PredicateCode = predicate;
606}
607
608
609//===----------------------------------------------------------------------===//
610// Selection DAG Pattern Fragments.
611//
612// Pattern fragments are reusable chunks of dags that match specific things.
613// They can take arguments and have C++ predicates that control whether they
614// match. They are intended to make the patterns for common instructions more
615// compact and readable.
616//
617
618/// PatFrag - Represents a pattern fragment. This can match something on the
619/// DAG, from a single node to multiple nested other fragments.
620///
621class PatFrag<dag ops, dag frag, code pred = [{}],
622 SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
623 dag Operands = ops;
624 dag Fragment = frag;
625 code PredicateCode = pred;
626 code ImmediateCode = [{}];
627 SDNodeXForm OperandTransform = xform;
628
629 // Define a few pre-packaged predicates. This helps GlobalISel import
630 // existing rules from SelectionDAG for many common cases.
631 // They will be tested prior to the code in pred and must not be used in
632 // ImmLeaf and its subclasses.
633
634 // Is the desired pre-packaged predicate for a load?
635 bit IsLoad = ?;
636 // Is the desired pre-packaged predicate for a store?
637 bit IsStore = ?;
638 // Is the desired pre-packaged predicate for an atomic?
639 bit IsAtomic = ?;
640
641 // cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
642 // cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
643 bit IsUnindexed = ?;
644
645 // cast<LoadSDNode>(N)->getExtensionType() != ISD::NON_EXTLOAD
646 bit IsNonExtLoad = ?;
647 // cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
648 bit IsAnyExtLoad = ?;
649 // cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
650 bit IsSignExtLoad = ?;
651 // cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
652 bit IsZeroExtLoad = ?;
653 // !cast<StoreSDNode>(N)->isTruncatingStore();
654 // cast<StoreSDNode>(N)->isTruncatingStore();
655 bit IsTruncStore = ?;
656
657 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Monotonic
658 bit IsAtomicOrderingMonotonic = ?;
659 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Acquire
660 bit IsAtomicOrderingAcquire = ?;
661 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Release
662 bit IsAtomicOrderingRelease = ?;
663 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::AcquireRelease
664 bit IsAtomicOrderingAcquireRelease = ?;
665 // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::SequentiallyConsistent
666 bit IsAtomicOrderingSequentiallyConsistent = ?;
667
668 // isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
669 // !isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
670 bit IsAtomicOrderingAcquireOrStronger = ?;
671
672 // isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
673 // !isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
674 bit IsAtomicOrderingReleaseOrStronger = ?;
675
676 // cast<LoadSDNode>(N)->getMemoryVT() == MVT::<VT>;
677 // cast<StoreSDNode>(N)->getMemoryVT() == MVT::<VT>;
678 ValueType MemoryVT = ?;
679 // cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
680 // cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
681 ValueType ScalarMemoryVT = ?;
682}
683
684// OutPatFrag is a pattern fragment that is used as part of an output pattern
685// (not an input pattern). These do not have predicates or transforms, but are
686// used to avoid repeated subexpressions in output patterns.
687class OutPatFrag<dag ops, dag frag>
688 : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;
689
690// PatLeaf's are pattern fragments that have no operands. This is just a helper
691// to define immediates and other common things concisely.
692class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
693 : PatFrag<(ops), frag, pred, xform>;
694
695
696// ImmLeaf is a pattern fragment with a constraint on the immediate. The
697// constraint is a function that is run on the immediate (always with the value
698// sign extended out to an int64_t) as Imm. For example:
699//
700// def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
701//
702// this is a more convenient form to match 'imm' nodes in than PatLeaf and also
703// is preferred over using PatLeaf because it allows the code generator to
704// reason more about the constraint.
705//
706// If FastIsel should ignore all instructions that have an operand of this type,
707// the FastIselShouldIgnore flag can be set. This is an optimization to reduce
708// the code size of the generated fast instruction selector.
709class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
710 SDNode ImmNode = imm>
711 : PatFrag<(ops), (vt ImmNode), [{}], xform> {
712 let ImmediateCode = pred;
713 bit FastIselShouldIgnore = 0;
714
715 // Is the data type of the immediate an APInt?
716 bit IsAPInt = 0;
717
718 // Is the data type of the immediate an APFloat?
719 bit IsAPFloat = 0;
720}
721
722// An ImmLeaf except that Imm is an APInt. This is useful when you need to
723// zero-extend the immediate instead of sign-extend it.
724//
725// Note that FastISel does not currently understand IntImmLeaf and will not
726// generate code for rules that make use of it. As such, it does not make sense
727// to replace ImmLeaf with IntImmLeaf. However, replacing PatLeaf with an
728// IntImmLeaf will allow GlobalISel to import the rule.
729class IntImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
730 : ImmLeaf<vt, pred, xform> {
731 let IsAPInt = 1;
732 let FastIselShouldIgnore = 1;
733}
734
735// An ImmLeaf except that Imm is an APFloat.
736//
737// Note that FastISel does not currently understand FPImmLeaf and will not
738// generate code for rules that make use of it.
739class FPImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
740 : ImmLeaf<vt, pred, xform, fpimm> {
741 let IsAPFloat = 1;
742 let FastIselShouldIgnore = 1;
743}
744
745// Leaf fragments.
746
747def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
748def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
749
750def immAllOnesV: PatLeaf<(build_vector), [{
751 return ISD::isBuildVectorAllOnes(N);
752}]>;
753def immAllZerosV: PatLeaf<(build_vector), [{
754 return ISD::isBuildVectorAllZeros(N);
755}]>;
756
757
758
759// Other helper fragments.
760def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
761def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
762def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
763
764// null_frag - The null pattern operator is used in multiclass instantiations
765// which accept an SDPatternOperator for use in matching patterns for internal
766// definitions. When expanding a pattern, if the null fragment is referenced
767// in the expansion, the pattern is discarded and it is as-if '[]' had been
768// specified. This allows multiclasses to have the isel patterns be optional.
769def null_frag : SDPatternOperator;
770
771// load fragments.
772def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr)> {
773 let IsLoad = 1;
774 let IsUnindexed = 1;
775}
776def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
777 let IsLoad = 1;
778 let IsNonExtLoad = 1;
779}
780
781// extending load fragments.
782def extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
783 let IsLoad = 1;
784 let IsAnyExtLoad = 1;
785}
786def sextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
787 let IsLoad = 1;
788 let IsSignExtLoad = 1;
789}
790def zextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
791 let IsLoad = 1;
792 let IsZeroExtLoad = 1;
793}
794
795def extloadi1 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
796 let IsLoad = 1;
797 let MemoryVT = i1;
798}
799def extloadi8 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
800 let IsLoad = 1;
801 let MemoryVT = i8;
802}
803def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
804 let IsLoad = 1;
805 let MemoryVT = i16;
806}
807def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
808 let IsLoad = 1;
809 let MemoryVT = i32;
810}
811def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
812 let IsLoad = 1;
813 let MemoryVT = f32;
814}
815def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
816 let IsLoad = 1;
817 let MemoryVT = f64;
818}
819
820def sextloadi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
821 let IsLoad = 1;
822 let MemoryVT = i1;
823}
824def sextloadi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
825 let IsLoad = 1;
826 let MemoryVT = i8;
827}
828def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
829 let IsLoad = 1;
830 let MemoryVT = i16;
831}
832def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
833 let IsLoad = 1;
834 let MemoryVT = i32;
835}
836
837def zextloadi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
838 let IsLoad = 1;
839 let MemoryVT = i1;
840}
841def zextloadi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
842 let IsLoad = 1;
843 let MemoryVT = i8;
844}
845def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
846 let IsLoad = 1;
847 let MemoryVT = i16;
848}
849def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
850 let IsLoad = 1;
851 let MemoryVT = i32;
852}
853
854def extloadvi1 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
855 let IsLoad = 1;
856 let ScalarMemoryVT = i1;
857}
858def extloadvi8 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
859 let IsLoad = 1;
860 let ScalarMemoryVT = i8;
861}
862def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
863 let IsLoad = 1;
864 let ScalarMemoryVT = i16;
865}
866def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
867 let IsLoad = 1;
868 let ScalarMemoryVT = i32;
869}
870def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
871 let IsLoad = 1;
872 let ScalarMemoryVT = f32;
873}
874def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
875 let IsLoad = 1;
876 let ScalarMemoryVT = f64;
877}
878
879def sextloadvi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
880 let IsLoad = 1;
881 let ScalarMemoryVT = i1;
882}
883def sextloadvi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
884 let IsLoad = 1;
885 let ScalarMemoryVT = i8;
886}
887def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
888 let IsLoad = 1;
889 let ScalarMemoryVT = i16;
890}
891def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
892 let IsLoad = 1;
893 let ScalarMemoryVT = i32;
894}
895
896def zextloadvi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
897 let IsLoad = 1;
898 let ScalarMemoryVT = i1;
899}
900def zextloadvi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
901 let IsLoad = 1;
902 let ScalarMemoryVT = i8;
903}
904def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
905 let IsLoad = 1;
906 let ScalarMemoryVT = i16;
907}
908def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
909 let IsLoad = 1;
910 let ScalarMemoryVT = i32;
911}
912
913// store fragments.
914def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
915 (st node:$val, node:$ptr)> {
916 let IsStore = 1;
917 let IsUnindexed = 1;
918}
919def store : PatFrag<(ops node:$val, node:$ptr),
920 (unindexedstore node:$val, node:$ptr)> {
921 let IsStore = 1;
922 let IsTruncStore = 0;
923}
924
925// truncstore fragments.
926def truncstore : PatFrag<(ops node:$val, node:$ptr),
927 (unindexedstore node:$val, node:$ptr)> {
928 let IsStore = 1;
929 let IsTruncStore = 1;
930}
931def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
932 (truncstore node:$val, node:$ptr)> {
933 let IsStore = 1;
934 let MemoryVT = i8;
935}
936def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
937 (truncstore node:$val, node:$ptr)> {
938 let IsStore = 1;
939 let MemoryVT = i16;
940}
941def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
942 (truncstore node:$val, node:$ptr)> {
943 let IsStore = 1;
944 let MemoryVT = i32;
945}
946def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
947 (truncstore node:$val, node:$ptr)> {
948 let IsStore = 1;
949 let MemoryVT = f32;
950}
951def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
952 (truncstore node:$val, node:$ptr)> {
953 let IsStore = 1;
954 let MemoryVT = f64;
955}
956
957def truncstorevi8 : PatFrag<(ops node:$val, node:$ptr),
958 (truncstore node:$val, node:$ptr)> {
959 let IsStore = 1;
960 let ScalarMemoryVT = i8;
961}
962
963def truncstorevi16 : PatFrag<(ops node:$val, node:$ptr),
964 (truncstore node:$val, node:$ptr)> {
965 let IsStore = 1;
966 let ScalarMemoryVT = i16;
967}
968
969def truncstorevi32 : PatFrag<(ops node:$val, node:$ptr),
970 (truncstore node:$val, node:$ptr)> {
971 let IsStore = 1;
972 let ScalarMemoryVT = i32;
973}
974
975// indexed store fragments.
976def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
977 (ist node:$val, node:$base, node:$offset)> {
978 let IsStore = 1;
979 let IsTruncStore = 0;
980}
981
982def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
983 (istore node:$val, node:$base, node:$offset), [{
984 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
985 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
986}]>;
987
988def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
989 (ist node:$val, node:$base, node:$offset)> {
990 let IsStore = 1;
991 let IsTruncStore = 1;
992}
993def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
994 (itruncstore node:$val, node:$base, node:$offset), [{
995 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
996 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
997}]>;
998def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
999 (pre_truncst node:$val, node:$base, node:$offset)> {
1000 let IsStore = 1;
1001 let MemoryVT = i1;
1002}
1003def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1004 (pre_truncst node:$val, node:$base, node:$offset)> {
1005 let IsStore = 1;
1006 let MemoryVT = i8;
1007}
1008def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1009 (pre_truncst node:$val, node:$base, node:$offset)> {
1010 let IsStore = 1;
1011 let MemoryVT = i16;
1012}
1013def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1014 (pre_truncst node:$val, node:$base, node:$offset)> {
1015 let IsStore = 1;
1016 let MemoryVT = i32;
1017}
1018def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1019 (pre_truncst node:$val, node:$base, node:$offset)> {
1020 let IsStore = 1;
1021 let MemoryVT = f32;
1022}
1023
1024def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
1025 (istore node:$val, node:$ptr, node:$offset), [{
1026 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1027 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1028}]>;
1029
1030def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1031 (itruncstore node:$val, node:$base, node:$offset), [{
1032 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1033 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1034}]>;
1035def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1036 (post_truncst node:$val, node:$base, node:$offset)> {
1037 let IsStore = 1;
1038 let MemoryVT = i1;
1039}
1040def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1041 (post_truncst node:$val, node:$base, node:$offset)> {
1042 let IsStore = 1;
1043 let MemoryVT = i8;
1044}
1045def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1046 (post_truncst node:$val, node:$base, node:$offset)> {
1047 let IsStore = 1;
1048 let MemoryVT = i16;
1049}
1050def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1051 (post_truncst node:$val, node:$base, node:$offset)> {
1052 let IsStore = 1;
1053 let MemoryVT = i32;
1054}
1055def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1056 (post_truncst node:$val, node:$base, node:$offset)> {
1057 let IsStore = 1;
1058 let MemoryVT = f32;
1059}
1060
1061// nontemporal store fragments.
1062def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1063 (store node:$val, node:$ptr), [{
1064 return cast<StoreSDNode>(N)->isNonTemporal();
1065}]>;
1066
1067def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1068 (nontemporalstore node:$val, node:$ptr), [{
1069 StoreSDNode *St = cast<StoreSDNode>(N);
1070 return St->getAlignment() >= St->getMemoryVT().getStoreSize();
1071}]>;
1072
1073def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1074 (nontemporalstore node:$val, node:$ptr), [{
1075 StoreSDNode *St = cast<StoreSDNode>(N);
1076 return St->getAlignment() < St->getMemoryVT().getStoreSize();
1077}]>;
1078
1079// nontemporal load fragments.
1080def nontemporalload : PatFrag<(ops node:$ptr),
1081 (load node:$ptr), [{
1082 return cast<LoadSDNode>(N)->isNonTemporal();
1083}]>;
1084
1085def alignednontemporalload : PatFrag<(ops node:$ptr),
1086 (nontemporalload node:$ptr), [{
1087 LoadSDNode *Ld = cast<LoadSDNode>(N);
1088 return Ld->getAlignment() >= Ld->getMemoryVT().getStoreSize();
1089}]>;
1090
1091// setcc convenience fragments.
1092def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
1093 (setcc node:$lhs, node:$rhs, SETOEQ)>;
1094def setogt : PatFrag<(ops node:$lhs, node:$rhs),
1095 (setcc node:$lhs, node:$rhs, SETOGT)>;
1096def setoge : PatFrag<(ops node:$lhs, node:$rhs),
1097 (setcc node:$lhs, node:$rhs, SETOGE)>;
1098def setolt : PatFrag<(ops node:$lhs, node:$rhs),
1099 (setcc node:$lhs, node:$rhs, SETOLT)>;
1100def setole : PatFrag<(ops node:$lhs, node:$rhs),
1101 (setcc node:$lhs, node:$rhs, SETOLE)>;
1102def setone : PatFrag<(ops node:$lhs, node:$rhs),
1103 (setcc node:$lhs, node:$rhs, SETONE)>;
1104def seto : PatFrag<(ops node:$lhs, node:$rhs),
1105 (setcc node:$lhs, node:$rhs, SETO)>;
1106def setuo : PatFrag<(ops node:$lhs, node:$rhs),
1107 (setcc node:$lhs, node:$rhs, SETUO)>;
1108def setueq : PatFrag<(ops node:$lhs, node:$rhs),
1109 (setcc node:$lhs, node:$rhs, SETUEQ)>;
1110def setugt : PatFrag<(ops node:$lhs, node:$rhs),
1111 (setcc node:$lhs, node:$rhs, SETUGT)>;
1112def setuge : PatFrag<(ops node:$lhs, node:$rhs),
1113 (setcc node:$lhs, node:$rhs, SETUGE)>;
1114def setult : PatFrag<(ops node:$lhs, node:$rhs),
1115 (setcc node:$lhs, node:$rhs, SETULT)>;
1116def setule : PatFrag<(ops node:$lhs, node:$rhs),
1117 (setcc node:$lhs, node:$rhs, SETULE)>;
1118def setune : PatFrag<(ops node:$lhs, node:$rhs),
1119 (setcc node:$lhs, node:$rhs, SETUNE)>;
1120def seteq : PatFrag<(ops node:$lhs, node:$rhs),
1121 (setcc node:$lhs, node:$rhs, SETEQ)>;
1122def setgt : PatFrag<(ops node:$lhs, node:$rhs),
1123 (setcc node:$lhs, node:$rhs, SETGT)>;
1124def setge : PatFrag<(ops node:$lhs, node:$rhs),
1125 (setcc node:$lhs, node:$rhs, SETGE)>;
1126def setlt : PatFrag<(ops node:$lhs, node:$rhs),
1127 (setcc node:$lhs, node:$rhs, SETLT)>;
1128def setle : PatFrag<(ops node:$lhs, node:$rhs),
1129 (setcc node:$lhs, node:$rhs, SETLE)>;
1130def setne : PatFrag<(ops node:$lhs, node:$rhs),
1131 (setcc node:$lhs, node:$rhs, SETNE)>;
1132
1133multiclass binary_atomic_op_ord<SDNode atomic_op> {
1134 def #NAME#_monotonic : PatFrag<(ops node:$ptr, node:$val),
1135 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1136 let IsAtomic = 1;
1137 let IsAtomicOrderingMonotonic = 1;
1138 }
1139 def #NAME#_acquire : PatFrag<(ops node:$ptr, node:$val),
1140 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1141 let IsAtomic = 1;
1142 let IsAtomicOrderingAcquire = 1;
1143 }
1144 def #NAME#_release : PatFrag<(ops node:$ptr, node:$val),
1145 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1146 let IsAtomic = 1;
1147 let IsAtomicOrderingRelease = 1;
1148 }
1149 def #NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$val),
1150 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1151 let IsAtomic = 1;
1152 let IsAtomicOrderingAcquireRelease = 1;
1153 }
1154 def #NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$val),
1155 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$val)> {
1156 let IsAtomic = 1;
1157 let IsAtomicOrderingSequentiallyConsistent = 1;
1158 }
1159}
1160
1161multiclass ternary_atomic_op_ord<SDNode atomic_op> {
1162 def #NAME#_monotonic : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1163 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1164 let IsAtomic = 1;
1165 let IsAtomicOrderingMonotonic = 1;
1166 }
1167 def #NAME#_acquire : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1168 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1169 let IsAtomic = 1;
1170 let IsAtomicOrderingAcquire = 1;
1171 }
1172 def #NAME#_release : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1173 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1174 let IsAtomic = 1;
1175 let IsAtomicOrderingRelease = 1;
1176 }
1177 def #NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1178 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1179 let IsAtomic = 1;
1180 let IsAtomicOrderingAcquireRelease = 1;
1181 }
1182 def #NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1183 (!cast<SDPatternOperator>(#NAME) node:$ptr, node:$cmp, node:$val)> {
1184 let IsAtomic = 1;
1185 let IsAtomicOrderingSequentiallyConsistent = 1;
1186 }
1187}
1188
1189multiclass binary_atomic_op<SDNode atomic_op> {
1190 def _8 : PatFrag<(ops node:$ptr, node:$val),
1191 (atomic_op node:$ptr, node:$val)> {
1192 let IsAtomic = 1;
1193 let MemoryVT = i8;
1194 }
1195 def _16 : PatFrag<(ops node:$ptr, node:$val),
1196 (atomic_op node:$ptr, node:$val)> {
1197 let IsAtomic = 1;
1198 let MemoryVT = i16;
1199 }
1200 def _32 : PatFrag<(ops node:$ptr, node:$val),
1201 (atomic_op node:$ptr, node:$val)> {
1202 let IsAtomic = 1;
1203 let MemoryVT = i32;
1204 }
1205 def _64 : PatFrag<(ops node:$ptr, node:$val),
1206 (atomic_op node:$ptr, node:$val)> {
1207 let IsAtomic = 1;
1208 let MemoryVT = i64;
1209 }
1210
1211 defm NAME#_8 : binary_atomic_op_ord<atomic_op>;
1212 defm NAME#_16 : binary_atomic_op_ord<atomic_op>;
1213 defm NAME#_32 : binary_atomic_op_ord<atomic_op>;
1214 defm NAME#_64 : binary_atomic_op_ord<atomic_op>;
1215}
1216
1217multiclass ternary_atomic_op<SDNode atomic_op> {
1218 def _8 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1219 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1220 let IsAtomic = 1;
1221 let MemoryVT = i8;
1222 }
1223 def _16 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1224 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1225 let IsAtomic = 1;
1226 let MemoryVT = i16;
1227 }
1228 def _32 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1229 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1230 let IsAtomic = 1;
1231 let MemoryVT = i32;
1232 }
1233 def _64 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1234 (atomic_op node:$ptr, node:$cmp, node:$val)> {
1235 let IsAtomic = 1;
1236 let MemoryVT = i64;
1237 }
1238
1239 defm NAME#_8 : ternary_atomic_op_ord<atomic_op>;
1240 defm NAME#_16 : ternary_atomic_op_ord<atomic_op>;
1241 defm NAME#_32 : ternary_atomic_op_ord<atomic_op>;
1242 defm NAME#_64 : ternary_atomic_op_ord<atomic_op>;
1243}
1244
1245defm atomic_load_add : binary_atomic_op<atomic_load_add>;
1246defm atomic_swap : binary_atomic_op<atomic_swap>;
1247defm atomic_load_sub : binary_atomic_op<atomic_load_sub>;
1248defm atomic_load_and : binary_atomic_op<atomic_load_and>;
1249defm atomic_load_clr : binary_atomic_op<atomic_load_clr>;
1250defm atomic_load_or : binary_atomic_op<atomic_load_or>;
1251defm atomic_load_xor : binary_atomic_op<atomic_load_xor>;
1252defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
1253defm atomic_load_min : binary_atomic_op<atomic_load_min>;
1254defm atomic_load_max : binary_atomic_op<atomic_load_max>;
1255defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
1256defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
1257defm atomic_store : binary_atomic_op<atomic_store>;
1258defm atomic_cmp_swap : ternary_atomic_op<atomic_cmp_swap>;
1259
1260def atomic_load_8 :
1261 PatFrag<(ops node:$ptr),
1262 (atomic_load node:$ptr)> {
1263 let IsAtomic = 1;
1264 let MemoryVT = i8;
1265}
1266def atomic_load_16 :
1267 PatFrag<(ops node:$ptr),
1268 (atomic_load node:$ptr)> {
1269 let IsAtomic = 1;
1270 let MemoryVT = i16;
1271}
1272def atomic_load_32 :
1273 PatFrag<(ops node:$ptr),
1274 (atomic_load node:$ptr)> {
1275 let IsAtomic = 1;
1276 let MemoryVT = i32;
1277}
1278def atomic_load_64 :
1279 PatFrag<(ops node:$ptr),
1280 (atomic_load node:$ptr)> {
1281 let IsAtomic = 1;
1282 let MemoryVT = i64;
1283}
1284
1285//===----------------------------------------------------------------------===//
1286// Selection DAG Pattern Support.
1287//
1288// Patterns are what are actually matched against by the target-flavored
1289// instruction selection DAG. Instructions defined by the target implicitly
1290// define patterns in most cases, but patterns can also be explicitly added when
1291// an operation is defined by a sequence of instructions (e.g. loading a large
1292// immediate value on RISC targets that do not support immediates as large as
1293// their GPRs).
1294//
1295
1296class Pattern<dag patternToMatch, list<dag> resultInstrs> {
1297 dag PatternToMatch = patternToMatch;
1298 list<dag> ResultInstrs = resultInstrs;
1299 list<Predicate> Predicates = []; // See class Instruction in Target.td.
1300 int AddedComplexity = 0; // See class Instruction in Target.td.
1301}
1302
1303// Pat - A simple (but common) form of a pattern, which produces a simple result
1304// not needing a full list.
1305class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
1306
1307//===----------------------------------------------------------------------===//
1308// Complex pattern definitions.
1309//
1310
1311// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
1312// in C++. NumOperands is the number of operands returned by the select function;
1313// SelectFunc is the name of the function used to pattern match the max. pattern;
1314// RootNodes are the list of possible root nodes of the sub-dags to match.
1315// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
1316//
1317class ComplexPattern<ValueType ty, int numops, string fn,
1318 list<SDNode> roots = [], list<SDNodeProperty> props = [],
1319 int complexity = -1> {
1320 ValueType Ty = ty;
1321 int NumOperands = numops;
1322 string SelectFunc = fn;
1323 list<SDNode> RootNodes = roots;
1324 list<SDNodeProperty> Properties = props;
1325 int Complexity = complexity;
1326}