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