Merge ISD::TRUNCSTORE to ISD::STORE. Switch to using StoreSDNode.
[oota-llvm.git] / lib / Target / TargetSelectionDAG.td
1 //===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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 is has integer type.
34 class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
35
36 // SDTCisFP - The specified operand is has floating point type.
37 class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
38
39 // SDTCisSameAs - The two specified operands have identical types.
40 class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
41   int OtherOperandNum = OtherOp;
42 }
43
44 // SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
45 // smaller than the 'Other' operand.
46 class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
47   int OtherOperandNum = OtherOp;
48 }
49
50 class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
51   int BigOperandNum = BigOp;
52 }
53
54 /// SDTCisIntVectorOfSameSize - This indicates that ThisOp and OtherOp are
55 /// packed vector types, and that ThisOp is the result of 
56 /// MVT::getIntVectorWithNumElements with the number of elements that ThisOp
57 /// has.
58 class SDTCisIntVectorOfSameSize<int ThisOp, int OtherOp>
59   : SDTypeConstraint<ThisOp> {
60   int OtherOpNum = OtherOp;
61 }
62
63 //===----------------------------------------------------------------------===//
64 // Selection DAG Type Profile definitions.
65 //
66 // These use the constraints defined above to describe the type requirements of
67 // the various nodes.  These are not hard coded into tblgen, allowing targets to
68 // add their own if needed.
69 //
70
71 // SDTypeProfile - This profile describes the type requirements of a Selection
72 // DAG node.
73 class SDTypeProfile<int numresults, int numoperands,
74                     list<SDTypeConstraint> constraints> {
75   int NumResults = numresults;
76   int NumOperands = numoperands;
77   list<SDTypeConstraint> Constraints = constraints;
78 }
79
80 // Builtin profiles.
81 def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>;      // for 'imm'.
82 def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>;       // for 'fpimm'.
83 def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;      // for '&g'.
84 def SDTOther  : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
85 def SDTUNDEF  : SDTypeProfile<1, 0, []>; // for 'undef'.
86 def SDTUnaryOp  : SDTypeProfile<1, 1, []>; // bitconvert
87
88 def SDTIntBinOp : SDTypeProfile<1, 2, [   // add, and, or, xor, udiv, etc.
89   SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
90 ]>;
91 def SDTIntShiftOp : SDTypeProfile<1, 2, [   // shl, sra, srl
92   SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
93 ]>;
94 def SDTFPBinOp : SDTypeProfile<1, 2, [      // fadd, fmul, etc.
95   SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
96 ]>;
97 def SDTFPSignOp : SDTypeProfile<1, 2, [      // fcopysign.
98   SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
99 ]>;
100 def SDTFPTernaryOp : SDTypeProfile<1, 3, [      // fmadd, fnmsub, etc.
101   SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
102 ]>;
103 def SDTIntUnaryOp : SDTypeProfile<1, 1, [   // ctlz
104   SDTCisSameAs<0, 1>, SDTCisInt<0>
105 ]>;
106 def SDTIntExtendOp : SDTypeProfile<1, 1, [  // sext, zext, anyext
107   SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>
108 ]>;
109 def SDTIntTruncOp  : SDTypeProfile<1, 1, [  // trunc
110   SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>
111 ]>;
112 def SDTFPUnaryOp  : SDTypeProfile<1, 1, [   // fneg, fsqrt, etc
113   SDTCisSameAs<0, 1>, SDTCisFP<0>
114 ]>;
115 def SDTFPRoundOp  : SDTypeProfile<1, 1, [   // fround
116   SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>
117 ]>;
118 def SDTFPExtendOp  : SDTypeProfile<1, 1, [   // fextend
119   SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>
120 ]>;
121 def SDTIntToFPOp : SDTypeProfile<1, 1, [   // [su]int_to_fp 
122   SDTCisFP<0>, SDTCisInt<1>
123 ]>;
124 def SDTFPToIntOp : SDTypeProfile<1, 1, [   // fp_to_[su]int 
125   SDTCisInt<0>, SDTCisFP<1>
126 ]>;
127 def SDTExtInreg : SDTypeProfile<1, 2, [   // sext_inreg
128   SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
129   SDTCisVTSmallerThanOp<2, 1>
130 ]>;
131
132 def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
133   SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
134 ]>;
135
136 def SDTSelect : SDTypeProfile<1, 3, [ // select 
137   SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
138 ]>;
139
140 def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
141   SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
142   SDTCisVT<5, OtherVT>
143 ]>;
144
145 def SDTBr : SDTypeProfile<0, 1, [ // br
146   SDTCisVT<0, OtherVT>
147 ]>;
148
149 def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
150   SDTCisInt<0>, SDTCisVT<1, OtherVT>
151 ]>;
152
153 def SDTBrind : SDTypeProfile<0, 1, [ // brind
154   SDTCisPtrTy<0>
155 ]>;
156
157 def SDTRet : SDTypeProfile<0, 0, []>; // ret
158
159 def SDTLoad : SDTypeProfile<1, 1, [ // load
160   SDTCisPtrTy<1>  
161 ]>;
162
163 def SDTStore : SDTypeProfile<0, 2, [ // store
164   SDTCisPtrTy<1>  
165 ]>;
166
167 def SDTVecShuffle : SDTypeProfile<1, 3, [
168   SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisIntVectorOfSameSize<3, 0>
169 ]>;
170
171 //===----------------------------------------------------------------------===//
172 // Selection DAG Node Properties.
173 //
174 // Note: These are hard coded into tblgen.
175 //
176 class SDNodeProperty;
177 def SDNPCommutative : SDNodeProperty;   // X op Y == Y op X
178 def SDNPAssociative : SDNodeProperty;   // (X op Y) op Z == X op (Y op Z)
179 def SDNPHasChain    : SDNodeProperty;   // R/W chain operand and result
180 def SDNPOutFlag     : SDNodeProperty;   // Write a flag result
181 def SDNPInFlag      : SDNodeProperty;   // Read a flag operand
182 def SDNPOptInFlag   : SDNodeProperty;   // Optionally read a flag operand
183
184 //===----------------------------------------------------------------------===//
185 // Selection DAG Node definitions.
186 //
187 class SDNode<string opcode, SDTypeProfile typeprof,
188              list<SDNodeProperty> props = [], string sdclass = "SDNode"> {
189   string Opcode  = opcode;
190   string SDClass = sdclass;
191   list<SDNodeProperty> Properties = props;
192   SDTypeProfile TypeProfile = typeprof;
193 }
194
195 def set;
196 def node;
197 def srcvalue;
198
199 def imm        : SDNode<"ISD::Constant"  , SDTIntLeaf , [], "ConstantSDNode">;
200 def fpimm      : SDNode<"ISD::TargetConstantFP",
201                          SDTFPLeaf, [], "ConstantFPSDNode">;
202 def vt         : SDNode<"ISD::VALUETYPE" , SDTOther   , [], "VTSDNode">;
203 def bb         : SDNode<"ISD::BasicBlock", SDTOther   , [], "BasicBlockSDNode">;
204 def cond       : SDNode<"ISD::CONDCODE"  , SDTOther   , [], "CondCodeSDNode">;
205 def undef      : SDNode<"ISD::UNDEF"     , SDTUNDEF   , []>;
206 def globaladdr : SDNode<"ISD::GlobalAddress",         SDTPtrLeaf, [],
207                         "GlobalAddressSDNode">;
208 def tglobaladdr : SDNode<"ISD::TargetGlobalAddress",  SDTPtrLeaf, [],
209                          "GlobalAddressSDNode">;
210 def constpool   : SDNode<"ISD::ConstantPool",         SDTPtrLeaf, [],
211                          "ConstantPoolSDNode">;
212 def tconstpool  : SDNode<"ISD::TargetConstantPool",   SDTPtrLeaf, [],
213                          "ConstantPoolSDNode">;
214 def jumptable   : SDNode<"ISD::JumpTable",            SDTPtrLeaf, [],
215                          "JumpTableSDNode">;
216 def tjumptable  : SDNode<"ISD::TargetJumpTable",      SDTPtrLeaf, [],
217                          "JumpTableSDNode">;
218 def frameindex  : SDNode<"ISD::FrameIndex",           SDTPtrLeaf, [],
219                          "FrameIndexSDNode">;
220 def tframeindex : SDNode<"ISD::TargetFrameIndex",     SDTPtrLeaf, [],
221                          "FrameIndexSDNode">;
222 def externalsym : SDNode<"ISD::ExternalSymbol",       SDTPtrLeaf, [],
223                          "ExternalSymbolSDNode">;
224 def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
225                          "ExternalSymbolSDNode">;
226
227 def add        : SDNode<"ISD::ADD"       , SDTIntBinOp   ,
228                         [SDNPCommutative, SDNPAssociative]>;
229 def sub        : SDNode<"ISD::SUB"       , SDTIntBinOp>;
230 def mul        : SDNode<"ISD::MUL"       , SDTIntBinOp,
231                         [SDNPCommutative, SDNPAssociative]>;
232 def mulhs      : SDNode<"ISD::MULHS"     , SDTIntBinOp, [SDNPCommutative]>;
233 def mulhu      : SDNode<"ISD::MULHU"     , SDTIntBinOp, [SDNPCommutative]>;
234 def sdiv       : SDNode<"ISD::SDIV"      , SDTIntBinOp>;
235 def udiv       : SDNode<"ISD::UDIV"      , SDTIntBinOp>;
236 def srem       : SDNode<"ISD::SREM"      , SDTIntBinOp>;
237 def urem       : SDNode<"ISD::UREM"      , SDTIntBinOp>;
238 def srl        : SDNode<"ISD::SRL"       , SDTIntShiftOp>;
239 def sra        : SDNode<"ISD::SRA"       , SDTIntShiftOp>;
240 def shl        : SDNode<"ISD::SHL"       , SDTIntShiftOp>;
241 def rotl       : SDNode<"ISD::ROTL"      , SDTIntShiftOp>;
242 def rotr       : SDNode<"ISD::ROTR"      , SDTIntShiftOp>;
243 def and        : SDNode<"ISD::AND"       , SDTIntBinOp,
244                         [SDNPCommutative, SDNPAssociative]>;
245 def or         : SDNode<"ISD::OR"        , SDTIntBinOp,
246                         [SDNPCommutative, SDNPAssociative]>;
247 def xor        : SDNode<"ISD::XOR"       , SDTIntBinOp,
248                         [SDNPCommutative, SDNPAssociative]>;
249 def addc       : SDNode<"ISD::ADDC"      , SDTIntBinOp,
250                         [SDNPCommutative, SDNPOutFlag]>;
251 def adde       : SDNode<"ISD::ADDE"      , SDTIntBinOp,
252                         [SDNPCommutative, SDNPOutFlag, SDNPInFlag]>;
253 def subc       : SDNode<"ISD::SUBC"      , SDTIntBinOp,
254                         [SDNPOutFlag]>;
255 def sube       : SDNode<"ISD::SUBE"      , SDTIntBinOp,
256                         [SDNPOutFlag, SDNPInFlag]>;
257                         
258 def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
259 def bswap      : SDNode<"ISD::BSWAP"      , SDTIntUnaryOp>;
260 def ctlz       : SDNode<"ISD::CTLZ"       , SDTIntUnaryOp>;
261 def cttz       : SDNode<"ISD::CTTZ"       , SDTIntUnaryOp>;
262 def ctpop      : SDNode<"ISD::CTPOP"      , SDTIntUnaryOp>;
263 def sext       : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
264 def zext       : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
265 def anyext     : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
266 def trunc      : SDNode<"ISD::TRUNCATE"   , SDTIntTruncOp>;
267 def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
268                         
269 def fadd       : SDNode<"ISD::FADD"       , SDTFPBinOp, [SDNPCommutative]>;
270 def fsub       : SDNode<"ISD::FSUB"       , SDTFPBinOp>;
271 def fmul       : SDNode<"ISD::FMUL"       , SDTFPBinOp, [SDNPCommutative]>;
272 def fdiv       : SDNode<"ISD::FDIV"       , SDTFPBinOp>;
273 def frem       : SDNode<"ISD::FREM"       , SDTFPBinOp>;
274 def fabs       : SDNode<"ISD::FABS"       , SDTFPUnaryOp>;
275 def fneg       : SDNode<"ISD::FNEG"       , SDTFPUnaryOp>;
276 def fsqrt      : SDNode<"ISD::FSQRT"      , SDTFPUnaryOp>;
277 def fsin       : SDNode<"ISD::FSIN"       , SDTFPUnaryOp>;
278 def fcos       : SDNode<"ISD::FCOS"       , SDTFPUnaryOp>;
279
280 def fround     : SDNode<"ISD::FP_ROUND"   , SDTFPRoundOp>;
281 def fextend    : SDNode<"ISD::FP_EXTEND"  , SDTFPExtendOp>;
282 def fcopysign  : SDNode<"ISD::FCOPYSIGN"  , SDTFPSignOp>;
283
284 def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
285 def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
286 def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
287 def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
288
289 def setcc      : SDNode<"ISD::SETCC"      , SDTSetCC>;
290 def select     : SDNode<"ISD::SELECT"     , SDTSelect>;
291 def selectcc   : SDNode<"ISD::SELECT_CC"  , SDTSelectCC>;
292
293 def brcond     : SDNode<"ISD::BRCOND"     , SDTBrcond, [SDNPHasChain]>;
294 def brind      : SDNode<"ISD::BRIND"      , SDTBrind,  [SDNPHasChain]>;
295 def br         : SDNode<"ISD::BR"         , SDTBr,     [SDNPHasChain]>;
296 def ret        : SDNode<"ISD::RET"        , SDTRet,    [SDNPHasChain]>;
297
298 // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
299 // and truncst (see below).
300 def ld         : SDNode<"ISD::LOAD"       , SDTLoad,  [SDNPHasChain]>;
301 def st         : SDNode<"ISD::STORE"      , SDTStore, [SDNPHasChain]>;
302
303 def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
304 def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, 0, []>, []>;
305 def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
306                               []>;
307 def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
308     SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
309 def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
310     SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
311
312 // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
313 // these internally.  Don't reference these directly.
314 def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID", 
315                             SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
316                             [SDNPHasChain]>;
317 def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN", 
318                                SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
319                                [SDNPHasChain]>;
320 def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN", 
321                                 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
322
323
324 //===----------------------------------------------------------------------===//
325 // Selection DAG Condition Codes
326
327 class CondCode; // ISD::CondCode enums
328 def SETOEQ : CondCode; def SETOGT : CondCode;
329 def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
330 def SETONE : CondCode; def SETO   : CondCode; def SETUO  : CondCode;
331 def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
332 def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
333
334 def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
335 def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
336
337
338 //===----------------------------------------------------------------------===//
339 // Selection DAG Node Transformation Functions.
340 //
341 // This mechanism allows targets to manipulate nodes in the output DAG once a
342 // match has been formed.  This is typically used to manipulate immediate
343 // values.
344 //
345 class SDNodeXForm<SDNode opc, code xformFunction> {
346   SDNode Opcode = opc;
347   code XFormFunction = xformFunction;
348 }
349
350 def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
351
352
353 //===----------------------------------------------------------------------===//
354 // Selection DAG Pattern Fragments.
355 //
356 // Pattern fragments are reusable chunks of dags that match specific things.
357 // They can take arguments and have C++ predicates that control whether they
358 // match.  They are intended to make the patterns for common instructions more
359 // compact and readable.
360 //
361
362 /// PatFrag - Represents a pattern fragment.  This can match something on the
363 /// DAG, frame a single node to multiply nested other fragments.
364 ///
365 class PatFrag<dag ops, dag frag, code pred = [{}],
366               SDNodeXForm xform = NOOP_SDNodeXForm> {
367   dag Operands = ops;
368   dag Fragment = frag;
369   code Predicate = pred;
370   SDNodeXForm OperandTransform = xform;
371 }
372
373 // PatLeaf's are pattern fragments that have no operands.  This is just a helper
374 // to define immediates and other common things concisely.
375 class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
376  : PatFrag<(ops), frag, pred, xform>;
377
378 // Leaf fragments.
379
380 def vtInt      : PatLeaf<(vt),  [{ return MVT::isInteger(N->getVT()); }]>;
381 def vtFP       : PatLeaf<(vt),  [{ return MVT::isFloatingPoint(N->getVT()); }]>;
382
383 def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
384 def immAllOnesV: PatLeaf<(build_vector), [{
385   return ISD::isBuildVectorAllOnes(N);
386 }]>;
387 def immAllZerosV: PatLeaf<(build_vector), [{
388   return ISD::isBuildVectorAllZeros(N);
389 }]>;
390
391 def immAllOnesV_bc: PatLeaf<(bitconvert), [{
392   return ISD::isBuildVectorAllOnes(N);
393 }]>;
394
395
396 // Other helper fragments.
397 def not  : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
398 def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
399 def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
400 def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
401
402 def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
403   return ISD::isNON_EXTLoad(N);
404 }]>;
405
406 // extending load fragments.
407 def extloadi1  : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
408   if (ISD::isEXTLoad(N))
409     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i1;
410   return false;
411 }]>;
412 def extloadi8  : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
413   if (ISD::isEXTLoad(N))
414     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i8;
415   return false;
416 }]>;
417 def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
418   if (ISD::isEXTLoad(N))
419     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i16;
420   return false;
421 }]>;
422 def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
423   if (ISD::isEXTLoad(N))
424     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i32;
425   return false;
426 }]>;
427 def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
428   if (ISD::isEXTLoad(N))
429     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::f32;
430   return false;
431 }]>;
432
433 def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
434   if (ISD::isSEXTLoad(N))
435     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i1;
436   return false;
437 }]>;
438 def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
439   if (ISD::isSEXTLoad(N))
440     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i8;
441   return false;
442 }]>;
443 def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
444   if (ISD::isSEXTLoad(N))
445     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i16;
446   return false;
447 }]>;
448 def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
449   if (ISD::isSEXTLoad(N))
450     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i32;
451   return false;
452 }]>;
453
454 def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
455   if (ISD::isZEXTLoad(N))
456     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i1;
457   return false;
458 }]>;
459 def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
460   if (ISD::isZEXTLoad(N))
461     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i8;
462   return false;
463 }]>;
464 def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
465   if (ISD::isZEXTLoad(N))
466     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i16;
467   return false;
468 }]>;
469 def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
470   if (ISD::isZEXTLoad(N))
471     return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i32;
472   return false;
473 }]>;
474
475 def store : PatFrag<(ops node:$val, node:$ptr),
476                     (st node:$val, node:$ptr), [{
477   return ISD::isNON_TRUNCStore(N);
478 }]>;
479
480 // truncstore fragments.
481 def truncstorei1 : PatFrag<(ops node:$val, node:$ptr),
482                            (st node:$val, node:$ptr), [{
483   if (ISD::isTRUNCStore(N))
484     return cast<StoreSDNode>(N)->getStoredVT() == MVT::i1;
485   return false;
486 }]>;
487 def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
488                            (st node:$val, node:$ptr), [{
489   if (ISD::isTRUNCStore(N))
490     return cast<StoreSDNode>(N)->getStoredVT() == MVT::i8;
491   return false;
492 }]>;
493 def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
494                             (st node:$val, node:$ptr), [{
495   if (ISD::isTRUNCStore(N))
496     return cast<StoreSDNode>(N)->getStoredVT() == MVT::i16;
497   return false;
498 }]>;
499 def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
500                             (st node:$val, node:$ptr), [{
501   if (ISD::isTRUNCStore(N))
502     return cast<StoreSDNode>(N)->getStoredVT() == MVT::i32;
503   return false;
504 }]>;
505 def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
506                             (st node:$val, node:$ptr), [{
507   if (ISD::isTRUNCStore(N))
508     return cast<StoreSDNode>(N)->getStoredVT() == MVT::f32;
509   return false;
510 }]>;
511
512 // setcc convenience fragments.
513 def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
514                      (setcc node:$lhs, node:$rhs, SETOEQ)>;
515 def setogt : PatFrag<(ops node:$lhs, node:$rhs),
516                      (setcc node:$lhs, node:$rhs, SETOGT)>;
517 def setoge : PatFrag<(ops node:$lhs, node:$rhs),
518                      (setcc node:$lhs, node:$rhs, SETOGE)>;
519 def setolt : PatFrag<(ops node:$lhs, node:$rhs),
520                      (setcc node:$lhs, node:$rhs, SETOLT)>;
521 def setole : PatFrag<(ops node:$lhs, node:$rhs),
522                      (setcc node:$lhs, node:$rhs, SETOLE)>;
523 def setone : PatFrag<(ops node:$lhs, node:$rhs),
524                      (setcc node:$lhs, node:$rhs, SETONE)>;
525 def seto   : PatFrag<(ops node:$lhs, node:$rhs),
526                      (setcc node:$lhs, node:$rhs, SETO)>;
527 def setuo  : PatFrag<(ops node:$lhs, node:$rhs),
528                      (setcc node:$lhs, node:$rhs, SETUO)>;
529 def setueq : PatFrag<(ops node:$lhs, node:$rhs),
530                      (setcc node:$lhs, node:$rhs, SETUEQ)>;
531 def setugt : PatFrag<(ops node:$lhs, node:$rhs),
532                      (setcc node:$lhs, node:$rhs, SETUGT)>;
533 def setuge : PatFrag<(ops node:$lhs, node:$rhs),
534                      (setcc node:$lhs, node:$rhs, SETUGE)>;
535 def setult : PatFrag<(ops node:$lhs, node:$rhs),
536                      (setcc node:$lhs, node:$rhs, SETULT)>;
537 def setule : PatFrag<(ops node:$lhs, node:$rhs),
538                      (setcc node:$lhs, node:$rhs, SETULE)>;
539 def setune : PatFrag<(ops node:$lhs, node:$rhs),
540                      (setcc node:$lhs, node:$rhs, SETUNE)>;
541 def seteq  : PatFrag<(ops node:$lhs, node:$rhs),
542                      (setcc node:$lhs, node:$rhs, SETEQ)>;
543 def setgt  : PatFrag<(ops node:$lhs, node:$rhs),
544                      (setcc node:$lhs, node:$rhs, SETGT)>;
545 def setge  : PatFrag<(ops node:$lhs, node:$rhs),
546                      (setcc node:$lhs, node:$rhs, SETGE)>;
547 def setlt  : PatFrag<(ops node:$lhs, node:$rhs),
548                      (setcc node:$lhs, node:$rhs, SETLT)>;
549 def setle  : PatFrag<(ops node:$lhs, node:$rhs),
550                      (setcc node:$lhs, node:$rhs, SETLE)>;
551 def setne  : PatFrag<(ops node:$lhs, node:$rhs),
552                      (setcc node:$lhs, node:$rhs, SETNE)>;
553
554 //===----------------------------------------------------------------------===//
555 // Selection DAG Pattern Support.
556 //
557 // Patterns are what are actually matched against the target-flavored
558 // instruction selection DAG.  Instructions defined by the target implicitly
559 // define patterns in most cases, but patterns can also be explicitly added when
560 // an operation is defined by a sequence of instructions (e.g. loading a large
561 // immediate value on RISC targets that do not support immediates as large as
562 // their GPRs).
563 //
564
565 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
566   dag             PatternToMatch  = patternToMatch;
567   list<dag>       ResultInstrs    = resultInstrs;
568   list<Predicate> Predicates      = [];  // See class Instruction in Target.td.
569   int             AddedComplexity = 0;  // See class Instruction in Target.td.
570 }
571
572 // Pat - A simple (but common) form of a pattern, which produces a simple result
573 // not needing a full list.
574 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
575
576 //===----------------------------------------------------------------------===//
577 // Complex pattern definitions.
578 //
579 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
580 // in C++. NumOperands is the number of operands returned by the select function;
581 // SelectFunc is the name of the function used to pattern match the max. pattern;
582 // RootNodes are the list of possible root nodes of the sub-dags to match.
583 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
584 //
585 class ComplexPattern<ValueType ty, int numops, string fn,
586                      list<SDNode> roots = [], list<SDNodeProperty> props = []> {
587   ValueType Ty = ty;
588   int NumOperands = numops;
589   string SelectFunc = fn;
590   list<SDNode> RootNodes = roots;
591   list<SDNodeProperty> Properties = props;
592 }
593
594 //===----------------------------------------------------------------------===//
595 // Dwarf support.
596 //
597 def SDT_dwarf_loc : SDTypeProfile<0, 3,
598                       [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
599 def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;
600
601 def SDT_dwarf_label : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
602 def dwarf_label : SDNode<"ISD::DEBUG_LABEL", SDT_dwarf_label,[SDNPHasChain]>;
603
604
605