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