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