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