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