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