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