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