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