LDM_RET should be marked mayLoad.
[oota-llvm.git] / lib / Target / ARM / ARMInstrInfo.td
1 //===- ARMInstrInfo.td - Target Description for ARM Target -*- 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 describes the ARM instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // ARM specific DAG Nodes.
16 //
17
18 // Type profiles.
19 def SDT_ARMCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
20 def SDT_ARMCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>;
21
22 def SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
23
24 def SDT_ARMcall    : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
25
26 def SDT_ARMCMov    : SDTypeProfile<1, 3,
27                                    [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
28                                     SDTCisVT<3, i32>]>;
29
30 def SDT_ARMBrcond  : SDTypeProfile<0, 2,
31                                    [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
32
33 def SDT_ARMBrJT    : SDTypeProfile<0, 3,
34                                   [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
35                                    SDTCisVT<2, i32>]>;
36
37 def SDT_ARMCmp     : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
38
39 def SDT_ARMPICAdd  : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
40                                           SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
41
42 def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
43 def SDT_ARMEH_SJLJ_Setjmp : SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
44
45 // Node definitions.
46 def ARMWrapper       : SDNode<"ARMISD::Wrapper",     SDTIntUnaryOp>;
47 def ARMWrapperJT     : SDNode<"ARMISD::WrapperJT",   SDTIntBinOp>;
48
49 def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
50                               [SDNPHasChain, SDNPOutFlag]>;
51 def ARMcallseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_ARMCallSeqEnd,
52                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
53
54 def ARMcall          : SDNode<"ARMISD::CALL", SDT_ARMcall,
55                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
56 def ARMcall_pred    : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
57                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
58 def ARMcall_nolink   : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
59                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
60
61 def ARMretflag       : SDNode<"ARMISD::RET_FLAG", SDTNone,
62                               [SDNPHasChain, SDNPOptInFlag]>;
63
64 def ARMcmov          : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
65                               [SDNPInFlag]>;
66 def ARMcneg          : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
67                               [SDNPInFlag]>;
68
69 def ARMbrcond        : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
70                               [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
71
72 def ARMbrjt          : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
73                               [SDNPHasChain]>;
74
75 def ARMcmp           : SDNode<"ARMISD::CMP", SDT_ARMCmp,
76                               [SDNPOutFlag]>;
77
78 def ARMcmpZ          : SDNode<"ARMISD::CMPZ", SDT_ARMCmp,
79                               [SDNPOutFlag,SDNPCommutative]>;
80
81 def ARMpic_add       : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
82
83 def ARMsrl_flag      : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
84 def ARMsra_flag      : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
85 def ARMrrx           : SDNode<"ARMISD::RRX"     , SDTIntUnaryOp, [SDNPInFlag ]>;
86
87 def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
88 def ARMeh_sjlj_setjmp: SDNode<"ARMISD::EH_SJLJ_SETJMP", SDT_ARMEH_SJLJ_Setjmp>;
89
90 //===----------------------------------------------------------------------===//
91 // ARM Instruction Predicate Definitions.
92 //
93 def HasV5T    : Predicate<"Subtarget->hasV5TOps()">;
94 def HasV5TE   : Predicate<"Subtarget->hasV5TEOps()">;
95 def HasV6     : Predicate<"Subtarget->hasV6Ops()">;
96 def HasV6T2   : Predicate<"Subtarget->hasV6T2Ops()">;
97 def HasV7     : Predicate<"Subtarget->hasV7Ops()">;
98 def HasVFP2   : Predicate<"Subtarget->hasVFP2()">;
99 def HasVFP3   : Predicate<"Subtarget->hasVFP3()">;
100 def HasNEON   : Predicate<"Subtarget->hasNEON()">;
101 def IsThumb   : Predicate<"Subtarget->isThumb()">;
102 def IsThumb1Only : Predicate<"Subtarget->isThumb1Only()">;
103 def IsThumb2  : Predicate<"Subtarget->isThumb2()">;
104 def IsARM     : Predicate<"!Subtarget->isThumb()">;
105 def IsDarwin    : Predicate<"Subtarget->isTargetDarwin()">;
106 def IsNotDarwin : Predicate<"!Subtarget->isTargetDarwin()">;
107 def CarryDefIsUnused : Predicate<"!N.getNode()->hasAnyUseOfValue(1)">;
108 def CarryDefIsUsed   : Predicate<"N.getNode()->hasAnyUseOfValue(1)">;
109
110 //===----------------------------------------------------------------------===//
111 // ARM Flag Definitions.
112
113 class RegConstraint<string C> {
114   string Constraints = C;
115 }
116
117 //===----------------------------------------------------------------------===//
118 //  ARM specific transformation functions and pattern fragments.
119 //
120
121 // so_imm_neg_XFORM - Return a so_imm value packed into the format described for
122 // so_imm_neg def below.
123 def so_imm_neg_XFORM : SDNodeXForm<imm, [{
124   return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
125 }]>;
126
127 // so_imm_not_XFORM - Return a so_imm value packed into the format described for
128 // so_imm_not def below.
129 def so_imm_not_XFORM : SDNodeXForm<imm, [{
130   return CurDAG->getTargetConstant(~(int)N->getZExtValue(), MVT::i32);
131 }]>;
132
133 // rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
134 def rot_imm : PatLeaf<(i32 imm), [{
135   int32_t v = (int32_t)N->getZExtValue();
136   return v == 8 || v == 16 || v == 24;
137 }]>;
138
139 /// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
140 def imm1_15 : PatLeaf<(i32 imm), [{
141   return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 16;
142 }]>;
143
144 /// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
145 def imm16_31 : PatLeaf<(i32 imm), [{
146   return (int32_t)N->getZExtValue() >= 16 && (int32_t)N->getZExtValue() < 32;
147 }]>;
148
149 def so_imm_neg : 
150   PatLeaf<(imm), [{
151     return ARM_AM::getSOImmVal(-(int)N->getZExtValue()) != -1;
152   }], so_imm_neg_XFORM>;
153
154 def so_imm_not :
155   PatLeaf<(imm), [{
156     return ARM_AM::getSOImmVal(~(int)N->getZExtValue()) != -1;
157   }], so_imm_not_XFORM>;
158
159 // sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
160 def sext_16_node : PatLeaf<(i32 GPR:$a), [{
161   return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
162 }]>;
163
164 /// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
165 /// e.g., 0xf000ffff
166 def bf_inv_mask_imm : Operand<i32>,
167                       PatLeaf<(imm), [{ 
168   uint32_t v = (uint32_t)N->getZExtValue();
169   if (v == 0xffffffff)
170     return 0;
171   // naive checker. should do better, but simple is best for now since it's
172   // more likely to be correct.
173   while (v & 1) v >>= 1;    // shift off the leading 1's
174   if (v)
175     {
176       while (!(v & 1)) v >>=1;  // shift off the mask
177       while (v & 1) v >>= 1;    // shift off the trailing 1's
178     }
179   // if this is a mask for clearing a bitfield, what's left should be zero.
180   return (v == 0);
181 }] > {
182   let PrintMethod = "printBitfieldInvMaskImmOperand";
183 }
184
185 class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
186 class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
187
188 //===----------------------------------------------------------------------===//
189 // Operand Definitions.
190 //
191
192 // Branch target.
193 def brtarget : Operand<OtherVT>;
194
195 // A list of registers separated by comma. Used by load/store multiple.
196 def reglist : Operand<i32> {
197   let PrintMethod = "printRegisterList";
198 }
199
200 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
201 def cpinst_operand : Operand<i32> {
202   let PrintMethod = "printCPInstOperand";
203 }
204
205 def jtblock_operand : Operand<i32> {
206   let PrintMethod = "printJTBlockOperand";
207 }
208
209 // Local PC labels.
210 def pclabel : Operand<i32> {
211   let PrintMethod = "printPCLabel";
212 }
213
214 // shifter_operand operands: so_reg and so_imm.
215 def so_reg : Operand<i32>,    // reg reg imm
216             ComplexPattern<i32, 3, "SelectShifterOperandReg",
217                             [shl,srl,sra,rotr]> {
218   let PrintMethod = "printSORegOperand";
219   let MIOperandInfo = (ops GPR, GPR, i32imm);
220 }
221
222 // so_imm - Match a 32-bit shifter_operand immediate operand, which is an
223 // 8-bit immediate rotated by an arbitrary number of bits.  so_imm values are
224 // represented in the imm field in the same 12-bit form that they are encoded
225 // into so_imm instructions: the 8-bit immediate is the least significant bits
226 // [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
227 def so_imm : Operand<i32>,
228              PatLeaf<(imm), [{
229       return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
230     }]> {
231   let PrintMethod = "printSOImmOperand";
232 }
233
234 // Break so_imm's up into two pieces.  This handles immediates with up to 16
235 // bits set in them.  This uses so_imm2part to match and so_imm2part_[12] to
236 // get the first/second pieces.
237 def so_imm2part : Operand<i32>,
238                   PatLeaf<(imm), [{
239       return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
240     }]> {
241   let PrintMethod = "printSOImm2PartOperand";
242 }
243
244 def so_imm2part_1 : SDNodeXForm<imm, [{
245   unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getZExtValue());
246   return CurDAG->getTargetConstant(V, MVT::i32);
247 }]>;
248
249 def so_imm2part_2 : SDNodeXForm<imm, [{
250   unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getZExtValue());
251   return CurDAG->getTargetConstant(V, MVT::i32);
252 }]>;
253
254
255 // Define ARM specific addressing modes.
256
257 // addrmode2 := reg +/- reg shop imm
258 // addrmode2 := reg +/- imm12
259 //
260 def addrmode2 : Operand<i32>,
261                 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
262   let PrintMethod = "printAddrMode2Operand";
263   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
264 }
265
266 def am2offset : Operand<i32>,
267                 ComplexPattern<i32, 2, "SelectAddrMode2Offset", []> {
268   let PrintMethod = "printAddrMode2OffsetOperand";
269   let MIOperandInfo = (ops GPR, i32imm);
270 }
271
272 // addrmode3 := reg +/- reg
273 // addrmode3 := reg +/- imm8
274 //
275 def addrmode3 : Operand<i32>,
276                 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
277   let PrintMethod = "printAddrMode3Operand";
278   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
279 }
280
281 def am3offset : Operand<i32>,
282                 ComplexPattern<i32, 2, "SelectAddrMode3Offset", []> {
283   let PrintMethod = "printAddrMode3OffsetOperand";
284   let MIOperandInfo = (ops GPR, i32imm);
285 }
286
287 // addrmode4 := reg, <mode|W>
288 //
289 def addrmode4 : Operand<i32>,
290                 ComplexPattern<i32, 2, "", []> {
291   let PrintMethod = "printAddrMode4Operand";
292   let MIOperandInfo = (ops GPR, i32imm);
293 }
294
295 // addrmode5 := reg +/- imm8*4
296 //
297 def addrmode5 : Operand<i32>,
298                 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
299   let PrintMethod = "printAddrMode5Operand";
300   let MIOperandInfo = (ops GPR, i32imm);
301 }
302
303 // addrmode6 := reg with optional writeback
304 //
305 def addrmode6 : Operand<i32>,
306                 ComplexPattern<i32, 3, "SelectAddrMode6", []> {
307   let PrintMethod = "printAddrMode6Operand";
308   let MIOperandInfo = (ops GPR:$addr, GPR:$upd, i32imm);
309 }
310
311 // addrmodepc := pc + reg
312 //
313 def addrmodepc : Operand<i32>,
314                  ComplexPattern<i32, 2, "SelectAddrModePC", []> {
315   let PrintMethod = "printAddrModePCOperand";
316   let MIOperandInfo = (ops GPR, i32imm);
317 }
318
319 // ARM Predicate operand. Default to 14 = always (AL). Second part is CC
320 // register whose default is 0 (no register).
321 def pred : PredicateOperand<OtherVT, (ops i32imm, CCR),
322                                      (ops (i32 14), (i32 zero_reg))> {
323   let PrintMethod = "printPredicateOperand";
324 }
325
326 // Conditional code result for instructions whose 's' bit is set, e.g. subs.
327 //
328 def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
329   let PrintMethod = "printSBitModifierOperand";
330 }
331
332 //===----------------------------------------------------------------------===//
333
334 include "ARMInstrFormats.td"
335
336 //===----------------------------------------------------------------------===//
337 // Multiclass helpers...
338 //
339
340 /// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
341 /// binop that produces a value.
342 multiclass AsI1_bin_irs<bits<4> opcod, string opc, PatFrag opnode,
343                         bit Commutable = 0> {
344   def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
345                opc, " $dst, $a, $b",
346                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]> {
347     let Inst{25} = 1;
348   }
349   def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
350                opc, " $dst, $a, $b",
351                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]> {
352     let Inst{25} = 0;
353     let isCommutable = Commutable;
354   }
355   def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
356                opc, " $dst, $a, $b",
357                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]> {
358     let Inst{25} = 0;
359   }
360 }
361
362 /// AI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
363 /// instruction modifies the CSPR register.
364 let Defs = [CPSR] in {
365 multiclass AI1_bin_s_irs<bits<4> opcod, string opc, PatFrag opnode,
366                          bit Commutable = 0> {
367   def ri : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
368                opc, "s $dst, $a, $b",
369                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]> {
370     let Inst{25} = 1;
371   }
372   def rr : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
373                opc, "s $dst, $a, $b",
374                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]> {
375     let isCommutable = Commutable;
376         let Inst{25} = 0;
377   }
378   def rs : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
379                opc, "s $dst, $a, $b",
380                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]> {
381     let Inst{25} = 0;
382   }
383 }
384 }
385
386 /// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
387 /// patterns. Similar to AsI1_bin_irs except the instruction does not produce
388 /// a explicit result, only implicitly set CPSR.
389 let Defs = [CPSR] in {
390 multiclass AI1_cmp_irs<bits<4> opcod, string opc, PatFrag opnode,
391                        bit Commutable = 0> {
392   def ri : AI1<opcod, (outs), (ins GPR:$a, so_imm:$b), DPFrm,
393                opc, " $a, $b",
394                [(opnode GPR:$a, so_imm:$b)]> {
395     let Inst{25} = 1;
396   }
397   def rr : AI1<opcod, (outs), (ins GPR:$a, GPR:$b), DPFrm,
398                opc, " $a, $b",
399                [(opnode GPR:$a, GPR:$b)]> {
400     let Inst{25} = 0;
401     let isCommutable = Commutable;
402   }
403   def rs : AI1<opcod, (outs), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
404                opc, " $a, $b",
405                [(opnode GPR:$a, so_reg:$b)]> {
406     let Inst{25} = 0;
407   }
408 }
409 }
410
411 /// AI_unary_rrot - A unary operation with two forms: one whose operand is a
412 /// register and one whose operand is a register rotated by 8/16/24.
413 /// FIXME: Remove the 'r' variant. Its rot_imm is zero.
414 multiclass AI_unary_rrot<bits<8> opcod, string opc, PatFrag opnode> {
415   def r     : AExtI<opcod, (outs GPR:$dst), (ins GPR:$Src),
416                  opc, " $dst, $Src",
417                  [(set GPR:$dst, (opnode GPR:$Src))]>,
418               Requires<[IsARM, HasV6]> {
419                 let Inst{19-16} = 0b1111;
420               }
421   def r_rot : AExtI<opcod, (outs GPR:$dst), (ins GPR:$Src, i32imm:$rot),
422                  opc, " $dst, $Src, ror $rot",
423                  [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>,
424               Requires<[IsARM, HasV6]> {
425                 let Inst{19-16} = 0b1111;
426               }
427 }
428
429 /// AI_bin_rrot - A binary operation with two forms: one whose operand is a
430 /// register and one whose operand is a register rotated by 8/16/24.
431 multiclass AI_bin_rrot<bits<8> opcod, string opc, PatFrag opnode> {
432   def rr     : AExtI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
433                   opc, " $dst, $LHS, $RHS",
434                   [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
435                   Requires<[IsARM, HasV6]>;
436   def rr_rot : AExtI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
437                   opc, " $dst, $LHS, $RHS, ror $rot",
438                   [(set GPR:$dst, (opnode GPR:$LHS,
439                                           (rotr GPR:$RHS, rot_imm:$rot)))]>,
440                   Requires<[IsARM, HasV6]>;
441 }
442
443 /// AI1_adde_sube_irs - Define instructions and patterns for adde and sube.
444 let Uses = [CPSR] in {
445 multiclass AI1_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
446                              bit Commutable = 0> {
447   def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
448                 DPFrm, opc, " $dst, $a, $b",
449                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>,
450                Requires<[IsARM, CarryDefIsUnused]> {
451     let Inst{25} = 1;
452   }
453   def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
454                 DPFrm, opc, " $dst, $a, $b",
455                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>,
456                Requires<[IsARM, CarryDefIsUnused]> {
457     let isCommutable = Commutable;
458     let Inst{25} = 0;
459   }
460   def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
461                 DPSoRegFrm, opc, " $dst, $a, $b",
462                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>,
463                Requires<[IsARM, CarryDefIsUnused]> {
464     let Inst{25} = 0;
465   }
466   // Carry setting variants
467   def Sri : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
468                 DPFrm, !strconcat(opc, "s $dst, $a, $b"),
469                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>,
470                Requires<[IsARM, CarryDefIsUsed]> {
471     let Defs = [CPSR];
472     let Inst{25} = 1;
473   }
474   def Srr : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
475                 DPFrm, !strconcat(opc, "s $dst, $a, $b"),
476                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>,
477                Requires<[IsARM, CarryDefIsUsed]> {
478     let Defs = [CPSR];
479     let Inst{25} = 0;
480   }
481   def Srs : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
482                 DPSoRegFrm, !strconcat(opc, "s $dst, $a, $b"),
483                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>,
484                Requires<[IsARM, CarryDefIsUsed]> {
485     let Defs = [CPSR];
486     let Inst{25} = 0;
487   }
488 }
489 }
490
491 //===----------------------------------------------------------------------===//
492 // Instructions
493 //===----------------------------------------------------------------------===//
494
495 //===----------------------------------------------------------------------===//
496 //  Miscellaneous Instructions.
497 //
498
499 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
500 /// the function.  The first operand is the ID# for this instruction, the second
501 /// is the index into the MachineConstantPool that this is, the third is the
502 /// size in bytes of this constant pool entry.
503 let neverHasSideEffects = 1, isNotDuplicable = 1 in
504 def CONSTPOOL_ENTRY :
505 PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
506                     i32imm:$size),
507            "${instid:label} ${cpidx:cpentry}", []>;
508
509 let Defs = [SP], Uses = [SP] in {
510 def ADJCALLSTACKUP :
511 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p),
512            "@ ADJCALLSTACKUP $amt1",
513            [(ARMcallseq_end timm:$amt1, timm:$amt2)]>;
514
515 def ADJCALLSTACKDOWN : 
516 PseudoInst<(outs), (ins i32imm:$amt, pred:$p),
517            "@ ADJCALLSTACKDOWN $amt",
518            [(ARMcallseq_start timm:$amt)]>;
519 }
520
521 def DWARF_LOC :
522 PseudoInst<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
523            ".loc $file, $line, $col",
524            [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
525
526
527 // Address computation and loads and stores in PIC mode.
528 let isNotDuplicable = 1 in {
529 def PICADD : AXI1<0b0100, (outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
530                   Pseudo, "$cp:\n\tadd$p $dst, pc, $a",
531                    [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
532
533 let AddedComplexity = 10 in {
534 let canFoldAsLoad = 1 in
535 def PICLDR  : AXI2ldw<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
536                   Pseudo, "${addr:label}:\n\tldr$p $dst, $addr",
537                   [(set GPR:$dst, (load addrmodepc:$addr))]>;
538
539 def PICLDRH : AXI3ldh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
540                   Pseudo, "${addr:label}:\n\tldr${p}h $dst, $addr",
541                   [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
542
543 def PICLDRB : AXI2ldb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
544                   Pseudo, "${addr:label}:\n\tldr${p}b $dst, $addr",
545                   [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
546
547 def PICLDRSH : AXI3ldsh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
548                   Pseudo, "${addr:label}:\n\tldr${p}sh $dst, $addr",
549                   [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
550
551 def PICLDRSB : AXI3ldsb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
552                   Pseudo, "${addr:label}:\n\tldr${p}sb $dst, $addr",
553                   [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
554 }
555 let AddedComplexity = 10 in {
556 def PICSTR  : AXI2stw<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
557                Pseudo, "${addr:label}:\n\tstr$p $src, $addr",
558                [(store GPR:$src, addrmodepc:$addr)]>;
559
560 def PICSTRH : AXI3sth<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
561                Pseudo, "${addr:label}:\n\tstr${p}h $src, $addr",
562                [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
563
564 def PICSTRB : AXI2stb<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
565                Pseudo, "${addr:label}:\n\tstr${p}b $src, $addr",
566                [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
567 }
568 } // isNotDuplicable = 1
569
570
571 // LEApcrel - Load a pc-relative address into a register without offending the
572 // assembler.
573 def LEApcrel : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, pred:$p), Pseudo,
574                    !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
575                                          "${:private}PCRELL${:uid}+8))\n"),
576                               !strconcat("${:private}PCRELL${:uid}:\n\t",
577                                          "add$p $dst, pc, #PCRELV${:uid}")),
578                    []>;
579
580 def LEApcrelJT : AXI1<0x0, (outs GPR:$dst),
581                            (ins i32imm:$label, i32imm:$id, pred:$p),
582           Pseudo,
583           !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
584                                          "${:private}PCRELL${:uid}+8))\n"),
585                               !strconcat("${:private}PCRELL${:uid}:\n\t",
586                                          "add$p $dst, pc, #PCRELV${:uid}")),
587                    []> {
588     let Inst{25} = 1;
589 }
590
591 //===----------------------------------------------------------------------===//
592 //  Control Flow Instructions.
593 //
594
595 let isReturn = 1, isTerminator = 1 in
596   def BX_RET : AI<(outs), (ins), BrMiscFrm, "bx", " lr", [(ARMretflag)]> {
597   let Inst{7-4}   = 0b0001;
598   let Inst{19-8}  = 0b111111111111;
599   let Inst{27-20} = 0b00010010;
600 }
601
602 // FIXME: remove when we have a way to marking a MI with these properties.
603 // FIXME: $dst1 should be a def. But the extra ops must be in the end of the
604 // operand list.
605 // FIXME: Should pc be an implicit operand like PICADD, etc?
606 let isReturn = 1, isTerminator = 1, mayLoad = 1 in
607   def LDM_RET : AXI4ld<(outs),
608                     (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
609                     LdStMulFrm, "ldm${p}${addr:submode} $addr, $dst1",
610                     []>;
611
612 // On non-Darwin platforms R9 is callee-saved.
613 let isCall = 1, Itinerary = IIC_Br,
614   Defs = [R0, R1, R2, R3, R12, LR,
615           D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
616   def BL  : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
617                 "bl ${func:call}",
618                 [(ARMcall tglobaladdr:$func)]>, Requires<[IsNotDarwin]>;
619
620   def BL_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
621                    "bl", " ${func:call}",
622                    [(ARMcall_pred tglobaladdr:$func)]>, Requires<[IsNotDarwin]>;
623
624   // ARMv5T and above
625   def BLX : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
626                 "blx $func",
627                 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T, IsNotDarwin]> {
628     let Inst{7-4}   = 0b0011;
629     let Inst{19-8}  = 0b111111111111;
630     let Inst{27-20} = 0b00010010;
631   }
632
633   let Uses = [LR] in {
634     // ARMv4T
635     def BX : ABXIx2<(outs), (ins GPR:$func, variable_ops),
636                      "mov lr, pc\n\tbx $func",
637                     [(ARMcall_nolink GPR:$func)]>, Requires<[IsNotDarwin]> {
638       let Inst{7-4}   = 0b0001;
639       let Inst{19-8}  = 0b111111111111;
640       let Inst{27-20} = 0b00010010;
641     }
642   }
643 }
644
645 // On Darwin R9 is call-clobbered.
646 let isCall = 1, Itinerary = IIC_Br,
647   Defs = [R0, R1, R2, R3, R9, R12, LR,
648           D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
649   def BLr9  : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
650                 "bl ${func:call}",
651                 [(ARMcall tglobaladdr:$func)]>, Requires<[IsDarwin]>;
652
653   def BLr9_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
654                    "bl", " ${func:call}",
655                    [(ARMcall_pred tglobaladdr:$func)]>, Requires<[IsDarwin]>;
656
657   // ARMv5T and above
658   def BLXr9 : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
659                 "blx $func",
660                 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T, IsDarwin]> {
661     let Inst{7-4}   = 0b0011;
662     let Inst{19-8}  = 0b111111111111;
663     let Inst{27-20} = 0b00010010;
664   }
665
666   let Uses = [LR] in {
667     // ARMv4T
668     def BXr9 : ABXIx2<(outs), (ins GPR:$func, variable_ops),
669                      "mov lr, pc\n\tbx $func",
670                     [(ARMcall_nolink GPR:$func)]>, Requires<[IsDarwin]> {
671       let Inst{7-4}   = 0b0001;
672       let Inst{19-8}  = 0b111111111111;
673       let Inst{27-20} = 0b00010010;
674     }
675   }
676 }
677
678 let isBranch = 1, isTerminator = 1, Itinerary = IIC_Br in {
679   // B is "predicable" since it can be xformed into a Bcc.
680   let isBarrier = 1 in {
681     let isPredicable = 1 in
682     def B : ABXI<0b1010, (outs), (ins brtarget:$target), "b $target",
683                 [(br bb:$target)]>;
684
685   let isNotDuplicable = 1, isIndirectBranch = 1 in {
686   def BR_JTr : JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
687                     "mov pc, $target \n$jt",
688                     [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]> {
689     let Inst{20}    = 0; // S Bit
690     let Inst{24-21} = 0b1101;
691     let Inst{27-25} = 0b000;
692   }
693   def BR_JTm : JTI<(outs),
694                    (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
695                    "ldr pc, $target \n$jt",
696                   [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
697                     imm:$id)]> {
698     let Inst{20}    = 1; // L bit
699     let Inst{21}    = 0; // W bit
700     let Inst{22}    = 0; // B bit
701     let Inst{24}    = 1; // P bit
702     let Inst{27-25} = 0b011;
703   }
704   def BR_JTadd : JTI<(outs),
705                    (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
706                      "add pc, $target, $idx \n$jt",
707                     [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
708                       imm:$id)]> {
709     let Inst{20}    = 0; // S bit
710     let Inst{24-21} = 0b0100;
711     let Inst{27-25} = 0b000;
712   }
713   } // isNotDuplicable = 1, isIndirectBranch = 1
714   } // isBarrier = 1
715
716   // FIXME: should be able to write a pattern for ARMBrcond, but can't use
717   // a two-value operand where a dag node expects two operands. :( 
718   def Bcc : ABI<0b1010, (outs), (ins brtarget:$target),
719                "b", " $target",
720                [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
721 }
722
723 //===----------------------------------------------------------------------===//
724 //  Load / store Instructions.
725 //
726
727 // Load
728 let canFoldAsLoad = 1 in 
729 def LDR  : AI2ldw<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
730                "ldr", " $dst, $addr",
731                [(set GPR:$dst, (load addrmode2:$addr))]>;
732
733 // Special LDR for loads from non-pc-relative constpools.
734 let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1 in
735 def LDRcp : AI2ldw<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
736                  "ldr", " $dst, $addr", []>;
737
738 // Loads with zero extension
739 def LDRH  : AI3ldh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
740                  "ldr", "h $dst, $addr",
741                 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
742
743 def LDRB  : AI2ldb<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
744                  "ldr", "b $dst, $addr",
745                 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
746
747 // Loads with sign extension
748 def LDRSH : AI3ldsh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
749                  "ldr", "sh $dst, $addr",
750                 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
751
752 def LDRSB : AI3ldsb<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
753                  "ldr", "sb $dst, $addr",
754                 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
755
756 let mayLoad = 1 in {
757 // Load doubleword
758 def LDRD : AI3ldd<(outs GPR:$dst1, GPR:$dst2), (ins addrmode3:$addr), LdMiscFrm,
759                 "ldr", "d $dst1, $addr", []>, Requires<[IsARM, HasV5T]>;
760
761 // Indexed loads
762 def LDR_PRE  : AI2ldwpr<(outs GPR:$dst, GPR:$base_wb),
763                      (ins addrmode2:$addr), LdFrm,
764                      "ldr", " $dst, $addr!", "$addr.base = $base_wb", []>;
765
766 def LDR_POST : AI2ldwpo<(outs GPR:$dst, GPR:$base_wb),
767                      (ins GPR:$base, am2offset:$offset), LdFrm,
768                      "ldr", " $dst, [$base], $offset", "$base = $base_wb", []>;
769
770 def LDRH_PRE  : AI3ldhpr<(outs GPR:$dst, GPR:$base_wb),
771                      (ins addrmode3:$addr), LdMiscFrm,
772                      "ldr", "h $dst, $addr!", "$addr.base = $base_wb", []>;
773
774 def LDRH_POST : AI3ldhpo<(outs GPR:$dst, GPR:$base_wb),
775                      (ins GPR:$base,am3offset:$offset), LdMiscFrm,
776                      "ldr", "h $dst, [$base], $offset", "$base = $base_wb", []>;
777
778 def LDRB_PRE  : AI2ldbpr<(outs GPR:$dst, GPR:$base_wb),
779                      (ins addrmode2:$addr), LdFrm,
780                      "ldr", "b $dst, $addr!", "$addr.base = $base_wb", []>;
781
782 def LDRB_POST : AI2ldbpo<(outs GPR:$dst, GPR:$base_wb),
783                      (ins GPR:$base,am2offset:$offset), LdFrm,
784                      "ldr", "b $dst, [$base], $offset", "$base = $base_wb", []>;
785
786 def LDRSH_PRE : AI3ldshpr<(outs GPR:$dst, GPR:$base_wb),
787                       (ins addrmode3:$addr), LdMiscFrm,
788                       "ldr", "sh $dst, $addr!", "$addr.base = $base_wb", []>;
789
790 def LDRSH_POST: AI3ldshpo<(outs GPR:$dst, GPR:$base_wb),
791                       (ins GPR:$base,am3offset:$offset), LdMiscFrm,
792                     "ldr", "sh $dst, [$base], $offset", "$base = $base_wb", []>;
793
794 def LDRSB_PRE : AI3ldsbpr<(outs GPR:$dst, GPR:$base_wb),
795                       (ins addrmode3:$addr), LdMiscFrm,
796                       "ldr", "sb $dst, $addr!", "$addr.base = $base_wb", []>;
797
798 def LDRSB_POST: AI3ldsbpo<(outs GPR:$dst, GPR:$base_wb),
799                       (ins GPR:$base,am3offset:$offset), LdMiscFrm,
800                     "ldr", "sb $dst, [$base], $offset", "$base = $base_wb", []>;
801 }
802
803 // Store
804 def STR  : AI2stw<(outs), (ins GPR:$src, addrmode2:$addr), StFrm,
805                "str", " $src, $addr",
806                [(store GPR:$src, addrmode2:$addr)]>;
807
808 // Stores with truncate
809 def STRH : AI3sth<(outs), (ins GPR:$src, addrmode3:$addr), StMiscFrm,
810                "str", "h $src, $addr",
811                [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
812
813 def STRB : AI2stb<(outs), (ins GPR:$src, addrmode2:$addr), StFrm,
814                "str", "b $src, $addr",
815                [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
816
817 // Store doubleword
818 let mayStore = 1 in
819 def STRD : AI3std<(outs), (ins GPR:$src1, GPR:$src2, addrmode3:$addr),StMiscFrm,
820                "str", "d $src1, $addr", []>, Requires<[IsARM, HasV5T]>;
821
822 // Indexed stores
823 def STR_PRE  : AI2stwpr<(outs GPR:$base_wb),
824                      (ins GPR:$src, GPR:$base, am2offset:$offset), StFrm,
825                     "str", " $src, [$base, $offset]!", "$base = $base_wb",
826                     [(set GPR:$base_wb,
827                       (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
828
829 def STR_POST : AI2stwpo<(outs GPR:$base_wb),
830                      (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
831                     "str", " $src, [$base], $offset", "$base = $base_wb",
832                     [(set GPR:$base_wb,
833                       (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
834
835 def STRH_PRE : AI3sthpr<(outs GPR:$base_wb),
836                      (ins GPR:$src, GPR:$base,am3offset:$offset), StMiscFrm,
837                      "str", "h $src, [$base, $offset]!", "$base = $base_wb",
838                     [(set GPR:$base_wb,
839                       (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
840
841 def STRH_POST: AI3sthpo<(outs GPR:$base_wb),
842                      (ins GPR:$src, GPR:$base,am3offset:$offset), StMiscFrm,
843                      "str", "h $src, [$base], $offset", "$base = $base_wb",
844                     [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
845                                          GPR:$base, am3offset:$offset))]>;
846
847 def STRB_PRE : AI2stbpr<(outs GPR:$base_wb),
848                      (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
849                      "str", "b $src, [$base, $offset]!", "$base = $base_wb",
850                     [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
851                                          GPR:$base, am2offset:$offset))]>;
852
853 def STRB_POST: AI2stbpo<(outs GPR:$base_wb),
854                      (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
855                      "str", "b $src, [$base], $offset", "$base = $base_wb",
856                     [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
857                                          GPR:$base, am2offset:$offset))]>;
858
859 //===----------------------------------------------------------------------===//
860 //  Load / store multiple Instructions.
861 //
862
863 // FIXME: $dst1 should be a def.
864 let mayLoad = 1 in
865 def LDM : AXI4ld<(outs),
866                (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
867                LdStMulFrm, "ldm${p}${addr:submode} $addr, $dst1",
868                []>;
869
870 let mayStore = 1 in
871 def STM : AXI4st<(outs),
872                (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
873                LdStMulFrm, "stm${p}${addr:submode} $addr, $src1",
874                []>;
875
876 //===----------------------------------------------------------------------===//
877 //  Move Instructions.
878 //
879
880 let neverHasSideEffects = 1 in
881 def MOVr : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), DPFrm,
882                  "mov", " $dst, $src", []>, UnaryDP;
883 def MOVs : AsI1<0b1101, (outs GPR:$dst), (ins so_reg:$src), DPSoRegFrm,
884                  "mov", " $dst, $src", [(set GPR:$dst, so_reg:$src)]>, UnaryDP;
885
886 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
887 def MOVi : AsI1<0b1101, (outs GPR:$dst), (ins so_imm:$src), DPFrm,
888                  "mov", " $dst, $src", [(set GPR:$dst, so_imm:$src)]>, UnaryDP;
889
890 def MOVrx : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
891                  "mov", " $dst, $src, rrx",
892                  [(set GPR:$dst, (ARMrrx GPR:$src))]>, UnaryDP;
893
894 // These aren't really mov instructions, but we have to define them this way
895 // due to flag operands.
896
897 let Defs = [CPSR] in {
898 def MOVsrl_flag : AI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
899                       "mov", "s $dst, $src, lsr #1",
900                       [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, UnaryDP;
901 def MOVsra_flag : AI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
902                       "mov", "s $dst, $src, asr #1",
903                       [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, UnaryDP;
904 }
905
906 //===----------------------------------------------------------------------===//
907 //  Extend Instructions.
908 //
909
910 // Sign extenders
911
912 defm SXTB  : AI_unary_rrot<0b01101010,
913                            "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
914 defm SXTH  : AI_unary_rrot<0b01101011,
915                            "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
916
917 defm SXTAB : AI_bin_rrot<0b01101010,
918                "sxtab", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
919 defm SXTAH : AI_bin_rrot<0b01101011,
920                "sxtah", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
921
922 // TODO: SXT(A){B|H}16
923
924 // Zero extenders
925
926 let AddedComplexity = 16 in {
927 defm UXTB   : AI_unary_rrot<0b01101110,
928                             "uxtb"  , UnOpFrag<(and node:$Src, 0x000000FF)>>;
929 defm UXTH   : AI_unary_rrot<0b01101111,
930                             "uxth"  , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
931 defm UXTB16 : AI_unary_rrot<0b01101100,
932                             "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
933
934 def : ARMV6Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
935                (UXTB16r_rot GPR:$Src, 24)>;
936 def : ARMV6Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
937                (UXTB16r_rot GPR:$Src, 8)>;
938
939 defm UXTAB : AI_bin_rrot<0b01101110, "uxtab",
940                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
941 defm UXTAH : AI_bin_rrot<0b01101111, "uxtah",
942                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
943 }
944
945 // This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
946 //defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
947
948 // TODO: UXT(A){B|H}16
949
950 //===----------------------------------------------------------------------===//
951 //  Arithmetic Instructions.
952 //
953
954 defm ADD  : AsI1_bin_irs<0b0100, "add",
955                          BinOpFrag<(add  node:$LHS, node:$RHS)>, 1>;
956 defm SUB  : AsI1_bin_irs<0b0010, "sub",
957                          BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
958
959 // ADD and SUB with 's' bit set.
960 defm ADDS : AI1_bin_s_irs<0b0100, "add",
961                           BinOpFrag<(addc node:$LHS, node:$RHS)>>;
962 defm SUBS : AI1_bin_s_irs<0b0010, "sub",
963                           BinOpFrag<(subc node:$LHS, node:$RHS)>>;
964
965 defm ADC : AI1_adde_sube_irs<0b0101, "adc",
966                              BinOpFrag<(adde node:$LHS, node:$RHS)>, 1>;
967 defm SBC : AI1_adde_sube_irs<0b0110, "sbc",
968                              BinOpFrag<(sube node:$LHS, node:$RHS)>>;
969
970 // These don't define reg/reg forms, because they are handled above.
971 def RSBri : AsI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
972                   "rsb", " $dst, $a, $b",
973                   [(set GPR:$dst, (sub so_imm:$b, GPR:$a))]>;
974
975 def RSBrs : AsI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
976                   "rsb", " $dst, $a, $b",
977                   [(set GPR:$dst, (sub so_reg:$b, GPR:$a))]>;
978
979 // RSB with 's' bit set.
980 let Defs = [CPSR] in {
981 def RSBSri : AI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
982                  "rsb", "s $dst, $a, $b",
983                  [(set GPR:$dst, (subc so_imm:$b, GPR:$a))]>;
984 def RSBSrs : AI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
985                  "rsb", "s $dst, $a, $b",
986                  [(set GPR:$dst, (subc so_reg:$b, GPR:$a))]>;
987 }
988
989 let Uses = [CPSR] in {
990 def RSCri : AsI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
991                  DPFrm, "rsc", " $dst, $a, $b",
992                  [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>,
993                  Requires<[IsARM, CarryDefIsUnused]>;
994 def RSCrs : AsI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
995                  DPSoRegFrm, "rsc", " $dst, $a, $b",
996                  [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>,
997                  Requires<[IsARM, CarryDefIsUnused]>;
998 }
999
1000 // FIXME: Allow these to be predicated.
1001 let Defs = [CPSR], Uses = [CPSR] in {
1002 def RSCSri : AXI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
1003                   DPFrm, "rscs $dst, $a, $b",
1004                   [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>,
1005                   Requires<[IsARM, CarryDefIsUnused]>;
1006 def RSCSrs : AXI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
1007                   DPSoRegFrm, "rscs $dst, $a, $b",
1008                   [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>,
1009                   Requires<[IsARM, CarryDefIsUnused]>;
1010 }
1011
1012 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
1013 def : ARMPat<(add    GPR:$src, so_imm_neg:$imm),
1014              (SUBri  GPR:$src, so_imm_neg:$imm)>;
1015
1016 //def : ARMPat<(addc   GPR:$src, so_imm_neg:$imm),
1017 //             (SUBSri GPR:$src, so_imm_neg:$imm)>;
1018 //def : ARMPat<(adde   GPR:$src, so_imm_neg:$imm),
1019 //             (SBCri  GPR:$src, so_imm_neg:$imm)>;
1020
1021 // Note: These are implemented in C++ code, because they have to generate
1022 // ADD/SUBrs instructions, which use a complex pattern that a xform function
1023 // cannot produce.
1024 // (mul X, 2^n+1) -> (add (X << n), X)
1025 // (mul X, 2^n-1) -> (rsb X, (X << n))
1026
1027
1028 //===----------------------------------------------------------------------===//
1029 //  Bitwise Instructions.
1030 //
1031
1032 defm AND   : AsI1_bin_irs<0b0000, "and",
1033                           BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
1034 defm ORR   : AsI1_bin_irs<0b1100, "orr",
1035                           BinOpFrag<(or  node:$LHS, node:$RHS)>, 1>;
1036 defm EOR   : AsI1_bin_irs<0b0001, "eor",
1037                           BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
1038 defm BIC   : AsI1_bin_irs<0b1110, "bic",
1039                           BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
1040
1041 def BFC    : I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm),
1042                AddrMode1, Size4Bytes, IndexModeNone, DPFrm,
1043                "bfc", " $dst, $imm", "$src = $dst",
1044                [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>,
1045                Requires<[IsARM, HasV6T2]> {
1046   let Inst{27-21} = 0b0111110;
1047   let Inst{6-0}   = 0b0011111;
1048 }
1049
1050 def  MVNr  : AsI1<0b1111, (outs GPR:$dst), (ins GPR:$src), DPFrm,
1051                   "mvn", " $dst, $src",
1052                   [(set GPR:$dst, (not GPR:$src))]>, UnaryDP;
1053 def  MVNs  : AsI1<0b1111, (outs GPR:$dst), (ins so_reg:$src), DPSoRegFrm,
1054                   "mvn", " $dst, $src",
1055                   [(set GPR:$dst, (not so_reg:$src))]>, UnaryDP;
1056 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
1057 def  MVNi  : AsI1<0b1111, (outs GPR:$dst), (ins so_imm:$imm), DPFrm,
1058                   "mvn", " $dst, $imm",
1059                   [(set GPR:$dst, so_imm_not:$imm)]>,UnaryDP;
1060
1061 def : ARMPat<(and   GPR:$src, so_imm_not:$imm),
1062              (BICri GPR:$src, so_imm_not:$imm)>;
1063
1064 //===----------------------------------------------------------------------===//
1065 //  Multiply Instructions.
1066 //
1067
1068 let isCommutable = 1 in
1069 def MUL   : AsMul1I<0b0000000, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1070                     "mul", " $dst, $a, $b",
1071                    [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
1072
1073 def MLA   : AsMul1I<0b0000001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1074                     "mla", " $dst, $a, $b, $c",
1075                    [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
1076
1077 def MLS   : AMul1I <0b0000011, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1078                     "mls", " $dst, $a, $b, $c",
1079                    [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>,
1080                    Requires<[IsARM, HasV6T2]>;
1081
1082 // Extra precision multiplies with low / high results
1083 let neverHasSideEffects = 1 in {
1084 let isCommutable = 1 in {
1085 def SMULL : AsMul1I<0b0000110, (outs GPR:$ldst, GPR:$hdst),
1086                                (ins GPR:$a, GPR:$b),
1087                     "smull", " $ldst, $hdst, $a, $b", []>;
1088
1089 def UMULL : AsMul1I<0b0000100, (outs GPR:$ldst, GPR:$hdst),
1090                                (ins GPR:$a, GPR:$b),
1091                     "umull", " $ldst, $hdst, $a, $b", []>;
1092 }
1093
1094 // Multiply + accumulate
1095 def SMLAL : AsMul1I<0b0000111, (outs GPR:$ldst, GPR:$hdst),
1096                                (ins GPR:$a, GPR:$b),
1097                     "smlal", " $ldst, $hdst, $a, $b", []>;
1098
1099 def UMLAL : AsMul1I<0b0000101, (outs GPR:$ldst, GPR:$hdst),
1100                                (ins GPR:$a, GPR:$b),
1101                     "umlal", " $ldst, $hdst, $a, $b", []>;
1102
1103 def UMAAL : AMul1I <0b0000010, (outs GPR:$ldst, GPR:$hdst),
1104                                (ins GPR:$a, GPR:$b),
1105                     "umaal", " $ldst, $hdst, $a, $b", []>,
1106                     Requires<[IsARM, HasV6]>;
1107 } // neverHasSideEffects
1108
1109 // Most significant word multiply
1110 def SMMUL : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1111                "smmul", " $dst, $a, $b",
1112                [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>,
1113             Requires<[IsARM, HasV6]> {
1114   let Inst{7-4}   = 0b0001;
1115   let Inst{15-12} = 0b1111;
1116 }
1117
1118 def SMMLA : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1119                "smmla", " $dst, $a, $b, $c",
1120                [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>,
1121             Requires<[IsARM, HasV6]> {
1122   let Inst{7-4}   = 0b0001;
1123 }
1124
1125
1126 def SMMLS : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1127                "smmls", " $dst, $a, $b, $c",
1128                [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
1129             Requires<[IsARM, HasV6]> {
1130   let Inst{7-4}   = 0b1101;
1131 }
1132
1133 multiclass AI_smul<string opc, PatFrag opnode> {
1134   def BB : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1135               !strconcat(opc, "bb"), " $dst, $a, $b",
1136               [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1137                                       (sext_inreg GPR:$b, i16)))]>,
1138            Requires<[IsARM, HasV5TE]> {
1139              let Inst{5} = 0;
1140              let Inst{6} = 0;
1141            }
1142
1143   def BT : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1144               !strconcat(opc, "bt"), " $dst, $a, $b",
1145               [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1146                                       (sra GPR:$b, (i32 16))))]>,
1147            Requires<[IsARM, HasV5TE]> {
1148              let Inst{5} = 0;
1149              let Inst{6} = 1;
1150            }
1151
1152   def TB : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1153               !strconcat(opc, "tb"), " $dst, $a, $b",
1154               [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
1155                                       (sext_inreg GPR:$b, i16)))]>,
1156            Requires<[IsARM, HasV5TE]> {
1157              let Inst{5} = 1;
1158              let Inst{6} = 0;
1159            }
1160
1161   def TT : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1162               !strconcat(opc, "tt"), " $dst, $a, $b",
1163               [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
1164                                       (sra GPR:$b, (i32 16))))]>,
1165             Requires<[IsARM, HasV5TE]> {
1166              let Inst{5} = 1;
1167              let Inst{6} = 1;
1168            }
1169
1170   def WB : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1171               !strconcat(opc, "wb"), " $dst, $a, $b",
1172               [(set GPR:$dst, (sra (opnode GPR:$a,
1173                                     (sext_inreg GPR:$b, i16)), (i32 16)))]>,
1174            Requires<[IsARM, HasV5TE]> {
1175              let Inst{5} = 1;
1176              let Inst{6} = 0;
1177            }
1178
1179   def WT : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1180               !strconcat(opc, "wt"), " $dst, $a, $b",
1181               [(set GPR:$dst, (sra (opnode GPR:$a,
1182                                     (sra GPR:$b, (i32 16))), (i32 16)))]>,
1183             Requires<[IsARM, HasV5TE]> {
1184              let Inst{5} = 1;
1185              let Inst{6} = 1;
1186            }
1187 }
1188
1189
1190 multiclass AI_smla<string opc, PatFrag opnode> {
1191   def BB : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1192               !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
1193               [(set GPR:$dst, (add GPR:$acc,
1194                                (opnode (sext_inreg GPR:$a, i16),
1195                                        (sext_inreg GPR:$b, i16))))]>,
1196            Requires<[IsARM, HasV5TE]> {
1197              let Inst{5} = 0;
1198              let Inst{6} = 0;
1199            }
1200
1201   def BT : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1202               !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
1203               [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
1204                                                      (sra GPR:$b, (i32 16)))))]>,
1205            Requires<[IsARM, HasV5TE]> {
1206              let Inst{5} = 0;
1207              let Inst{6} = 1;
1208            }
1209
1210   def TB : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1211               !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
1212               [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
1213                                                  (sext_inreg GPR:$b, i16))))]>,
1214            Requires<[IsARM, HasV5TE]> {
1215              let Inst{5} = 1;
1216              let Inst{6} = 0;
1217            }
1218
1219   def TT : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1220               !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
1221               [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
1222                                                      (sra GPR:$b, (i32 16)))))]>,
1223             Requires<[IsARM, HasV5TE]> {
1224              let Inst{5} = 1;
1225              let Inst{6} = 1;
1226            }
1227
1228   def WB : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1229               !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
1230               [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1231                                        (sext_inreg GPR:$b, i16)), (i32 16))))]>,
1232            Requires<[IsARM, HasV5TE]> {
1233              let Inst{5} = 0;
1234              let Inst{6} = 0;
1235            }
1236
1237   def WT : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1238               !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
1239               [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1240                                          (sra GPR:$b, (i32 16))), (i32 16))))]>,
1241             Requires<[IsARM, HasV5TE]> {
1242              let Inst{5} = 0;
1243              let Inst{6} = 1;
1244            }
1245 }
1246
1247 defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1248 defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1249
1250 // TODO: Halfword multiple accumulate long: SMLAL<x><y>
1251 // TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
1252
1253 //===----------------------------------------------------------------------===//
1254 //  Misc. Arithmetic Instructions.
1255 //
1256
1257 def CLZ  : AMiscA1I<0b000010110, (outs GPR:$dst), (ins GPR:$src),
1258               "clz", " $dst, $src",
1259               [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]> {
1260   let Inst{7-4}   = 0b0001;
1261   let Inst{11-8}  = 0b1111;
1262   let Inst{19-16} = 0b1111;
1263 }
1264
1265 def REV  : AMiscA1I<0b01101011, (outs GPR:$dst), (ins GPR:$src),
1266               "rev", " $dst, $src",
1267               [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]> {
1268   let Inst{7-4}   = 0b0011;
1269   let Inst{11-8}  = 0b1111;
1270   let Inst{19-16} = 0b1111;
1271 }
1272
1273 def REV16 : AMiscA1I<0b01101011, (outs GPR:$dst), (ins GPR:$src),
1274                "rev16", " $dst, $src",
1275                [(set GPR:$dst,
1276                    (or (and (srl GPR:$src, (i32 8)), 0xFF),
1277                        (or (and (shl GPR:$src, (i32 8)), 0xFF00),
1278                            (or (and (srl GPR:$src, (i32 8)), 0xFF0000),
1279                                (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>,
1280                Requires<[IsARM, HasV6]> {
1281   let Inst{7-4}   = 0b1011;
1282   let Inst{11-8}  = 0b1111;
1283   let Inst{19-16} = 0b1111;
1284 }
1285
1286 def REVSH : AMiscA1I<0b01101111, (outs GPR:$dst), (ins GPR:$src),
1287                "revsh", " $dst, $src",
1288                [(set GPR:$dst,
1289                   (sext_inreg
1290                     (or (srl (and GPR:$src, 0xFF00), (i32 8)),
1291                         (shl GPR:$src, (i32 8))), i16))]>,
1292                Requires<[IsARM, HasV6]> {
1293   let Inst{7-4}   = 0b1011;
1294   let Inst{11-8}  = 0b1111;
1295   let Inst{19-16} = 0b1111;
1296 }
1297
1298 def PKHBT : AMiscA1I<0b01101000, (outs GPR:$dst),
1299                                  (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1300                "pkhbt", " $dst, $src1, $src2, LSL $shamt",
1301                [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1302                                    (and (shl GPR:$src2, (i32 imm:$shamt)),
1303                                         0xFFFF0000)))]>,
1304                Requires<[IsARM, HasV6]> {
1305   let Inst{6-4} = 0b001;
1306 }
1307
1308 // Alternate cases for PKHBT where identities eliminate some nodes.
1309 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1310                (PKHBT GPR:$src1, GPR:$src2, 0)>;
1311 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1312                (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
1313
1314
1315 def PKHTB : AMiscA1I<0b01101000, (outs GPR:$dst),
1316                                  (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1317                "pkhtb", " $dst, $src1, $src2, ASR $shamt",
1318                [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1319                                    (and (sra GPR:$src2, imm16_31:$shamt),
1320                                         0xFFFF)))]>, Requires<[IsARM, HasV6]> {
1321   let Inst{6-4} = 0b101;
1322 }
1323
1324 // Alternate cases for PKHTB where identities eliminate some nodes.  Note that
1325 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
1326 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, (i32 16))),
1327                (PKHTB GPR:$src1, GPR:$src2, 16)>;
1328 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1329                    (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1330                (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1331
1332 //===----------------------------------------------------------------------===//
1333 //  Comparison Instructions...
1334 //
1335
1336 defm CMP  : AI1_cmp_irs<0b1010, "cmp",
1337                         BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1338 defm CMN  : AI1_cmp_irs<0b1011, "cmn",
1339                         BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
1340
1341 // Note that TST/TEQ don't set all the same flags that CMP does!
1342 defm TST  : AI1_cmp_irs<0b1000, "tst",
1343                         BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>, 1>;
1344 defm TEQ  : AI1_cmp_irs<0b1001, "teq",
1345                         BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>, 1>;
1346
1347 defm CMPz  : AI1_cmp_irs<0b1010, "cmp",
1348                          BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
1349 defm CMNz  : AI1_cmp_irs<0b1011, "cmn",
1350                          BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
1351
1352 def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1353              (CMNri  GPR:$src, so_imm_neg:$imm)>;
1354
1355 def : ARMPat<(ARMcmpZ GPR:$src, so_imm_neg:$imm),
1356              (CMNri  GPR:$src, so_imm_neg:$imm)>;
1357
1358
1359 // Conditional moves
1360 // FIXME: should be able to write a pattern for ARMcmov, but can't use
1361 // a two-value operand where a dag node expects two operands. :( 
1362 def MOVCCr : AI1<0b1101, (outs GPR:$dst), (ins GPR:$false, GPR:$true), DPFrm,
1363                 "mov", " $dst, $true",
1364       [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1365                 RegConstraint<"$false = $dst">, UnaryDP;
1366
1367 def MOVCCs : AI1<0b1101, (outs GPR:$dst),
1368                         (ins GPR:$false, so_reg:$true), DPSoRegFrm,
1369                 "mov", " $dst, $true",
1370    [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1371                 RegConstraint<"$false = $dst">, UnaryDP;
1372
1373 def MOVCCi : AI1<0b1101, (outs GPR:$dst),
1374                         (ins GPR:$false, so_imm:$true), DPFrm,
1375                 "mov", " $dst, $true",
1376    [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1377                 RegConstraint<"$false = $dst">, UnaryDP;
1378
1379
1380 //===----------------------------------------------------------------------===//
1381 // TLS Instructions
1382 //
1383
1384 // __aeabi_read_tp preserves the registers r1-r3.
1385 let isCall = 1,
1386   Defs = [R0, R12, LR, CPSR] in {
1387   def TPsoft : ABXI<0b1011, (outs), (ins),
1388                "bl __aeabi_read_tp",
1389                [(set R0, ARMthread_pointer)]>;
1390 }
1391
1392 //===----------------------------------------------------------------------===//
1393 // SJLJ Exception handling intrinsics
1394 //   eh_sjlj_setjmp() is a three instruction sequence to store the return 
1395 //   address and save #0 in R0 for the non-longjmp case.
1396 //   Since by its nature we may be coming from some other function to get
1397 //   here, and we're using the stack frame for the containing function to
1398 //   save/restore registers, we can't keep anything live in regs across
1399 //   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
1400 //   when we get here from a longjmp(). We force everthing out of registers
1401 //   except for our own input by listing the relevant registers in Defs. By
1402 //   doing so, we also cause the prologue/epilogue code to actively preserve
1403 //   all of the callee-saved resgisters, which is exactly what we want.
1404 let Defs = 
1405   [ R0, R1, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR,
1406     D0, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15 ] in {
1407   def Int_eh_sjlj_setjmp : XI<(outs), (ins GPR:$src),
1408                                AddrModeNone, SizeSpecial, IndexModeNone, Pseudo,
1409                                "add r0, pc, #4\n\t"
1410                                "str r0, [$src, #+4]\n\t"
1411                                "mov r0, #0 @ eh_setjmp", "",
1412                                [(set R0, (ARMeh_sjlj_setjmp GPR:$src))]>;
1413 }
1414
1415 //===----------------------------------------------------------------------===//
1416 // Non-Instruction Patterns
1417 //
1418
1419 // ConstantPool, GlobalAddress, and JumpTable
1420 def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>;
1421 def : ARMPat<(ARMWrapper  tconstpool  :$dst), (LEApcrel tconstpool  :$dst)>;
1422 def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1423              (LEApcrelJT tjumptable:$dst, imm:$id)>;
1424
1425 // Large immediate handling.
1426
1427 // Two piece so_imms.
1428 let isReMaterializable = 1 in
1429 def MOVi2pieces : AI1x2<(outs GPR:$dst), (ins so_imm2part:$src), Pseudo,
1430                          "mov", " $dst, $src",
1431                          [(set GPR:$dst, so_imm2part:$src)]>;
1432
1433 def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1434              (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1435                     (so_imm2part_2 imm:$RHS))>;
1436 def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1437              (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1438                     (so_imm2part_2 imm:$RHS))>;
1439
1440 // TODO: add,sub,and, 3-instr forms?
1441
1442
1443 // Direct calls
1444 def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>,
1445       Requires<[IsNotDarwin]>;
1446 def : ARMPat<(ARMcall texternalsym:$func), (BLr9 texternalsym:$func)>,
1447       Requires<[IsDarwin]>;
1448
1449 // zextload i1 -> zextload i8
1450 def : ARMPat<(zextloadi1 addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1451
1452 // extload -> zextload
1453 def : ARMPat<(extloadi1  addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1454 def : ARMPat<(extloadi8  addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1455 def : ARMPat<(extloadi16 addrmode3:$addr),  (LDRH addrmode3:$addr)>;
1456
1457 def : ARMPat<(extloadi8  addrmodepc:$addr), (PICLDRB addrmodepc:$addr)>;
1458 def : ARMPat<(extloadi16 addrmodepc:$addr), (PICLDRH addrmodepc:$addr)>;
1459
1460 // smul* and smla*
1461 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1462                       (sra (shl GPR:$b, (i32 16)), (i32 16))),
1463                  (SMULBB GPR:$a, GPR:$b)>;
1464 def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1465                  (SMULBB GPR:$a, GPR:$b)>;
1466 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1467                       (sra GPR:$b, (i32 16))),
1468                  (SMULBT GPR:$a, GPR:$b)>;
1469 def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, (i32 16))),
1470                  (SMULBT GPR:$a, GPR:$b)>;
1471 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)),
1472                       (sra (shl GPR:$b, (i32 16)), (i32 16))),
1473                  (SMULTB GPR:$a, GPR:$b)>;
1474 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)), sext_16_node:$b),
1475                 (SMULTB GPR:$a, GPR:$b)>;
1476 def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
1477                       (i32 16)),
1478                  (SMULWB GPR:$a, GPR:$b)>;
1479 def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), (i32 16)),
1480                  (SMULWB GPR:$a, GPR:$b)>;
1481
1482 def : ARMV5TEPat<(add GPR:$acc,
1483                       (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1484                            (sra (shl GPR:$b, (i32 16)), (i32 16)))),
1485                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1486 def : ARMV5TEPat<(add GPR:$acc,
1487                       (mul sext_16_node:$a, sext_16_node:$b)),
1488                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1489 def : ARMV5TEPat<(add GPR:$acc,
1490                       (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1491                            (sra GPR:$b, (i32 16)))),
1492                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1493 def : ARMV5TEPat<(add GPR:$acc,
1494                       (mul sext_16_node:$a, (sra GPR:$b, (i32 16)))),
1495                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1496 def : ARMV5TEPat<(add GPR:$acc,
1497                       (mul (sra GPR:$a, (i32 16)),
1498                            (sra (shl GPR:$b, (i32 16)), (i32 16)))),
1499                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1500 def : ARMV5TEPat<(add GPR:$acc,
1501                       (mul (sra GPR:$a, (i32 16)), sext_16_node:$b)),
1502                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1503 def : ARMV5TEPat<(add GPR:$acc,
1504                       (sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
1505                            (i32 16))),
1506                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1507 def : ARMV5TEPat<(add GPR:$acc,
1508                       (sra (mul GPR:$a, sext_16_node:$b), (i32 16))),
1509                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1510
1511 //===----------------------------------------------------------------------===//
1512 // Thumb Support
1513 //
1514
1515 include "ARMInstrThumb.td"
1516
1517 //===----------------------------------------------------------------------===//
1518 // Thumb2 Support
1519 //
1520
1521 include "ARMInstrThumb2.td"
1522
1523 //===----------------------------------------------------------------------===//
1524 // Floating Point Support
1525 //
1526
1527 include "ARMInstrVFP.td"
1528
1529 //===----------------------------------------------------------------------===//
1530 // Advanced SIMD (NEON) Support
1531 //
1532
1533 include "ARMInstrNEON.td"