72e99b1c19f23677a96798dc55dbb72a44194691
[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, 2, [SDTCisInt<0>, SDTCisPtrTy<1>,
48                                                  SDTCisInt<2>]>;
49
50 def SDT_ARMMEMBARRIERV7  : SDTypeProfile<0, 0, []>;
51 def SDT_ARMSYNCBARRIERV7 : SDTypeProfile<0, 0, []>;
52 def SDT_ARMMEMBARRIERV6  : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
53 def SDT_ARMSYNCBARRIERV6 : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
54
55 // Node definitions.
56 def ARMWrapper       : SDNode<"ARMISD::Wrapper",     SDTIntUnaryOp>;
57 def ARMWrapperJT     : SDNode<"ARMISD::WrapperJT",   SDTIntBinOp>;
58
59 def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
60                               [SDNPHasChain, SDNPOutFlag]>;
61 def ARMcallseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_ARMCallSeqEnd,
62                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
63
64 def ARMcall          : SDNode<"ARMISD::CALL", SDT_ARMcall,
65                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
66 def ARMcall_pred    : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
67                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
68 def ARMcall_nolink   : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
69                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
70
71 def ARMretflag       : SDNode<"ARMISD::RET_FLAG", SDTNone,
72                               [SDNPHasChain, SDNPOptInFlag]>;
73
74 def ARMcmov          : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
75                               [SDNPInFlag]>;
76 def ARMcneg          : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
77                               [SDNPInFlag]>;
78
79 def ARMbrcond        : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
80                               [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
81
82 def ARMbrjt          : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
83                               [SDNPHasChain]>;
84 def ARMbr2jt         : SDNode<"ARMISD::BR2_JT", SDT_ARMBr2JT,
85                               [SDNPHasChain]>;
86
87 def ARMcmp           : SDNode<"ARMISD::CMP", SDT_ARMCmp,
88                               [SDNPOutFlag]>;
89
90 def ARMcmpZ          : SDNode<"ARMISD::CMPZ", SDT_ARMCmp,
91                               [SDNPOutFlag,SDNPCommutative]>;
92
93 def ARMpic_add       : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
94
95 def ARMsrl_flag      : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
96 def ARMsra_flag      : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
97 def ARMrrx           : SDNode<"ARMISD::RRX"     , SDTIntUnaryOp, [SDNPInFlag ]>;
98
99 def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
100 def ARMeh_sjlj_setjmp: SDNode<"ARMISD::EH_SJLJ_SETJMP", SDT_ARMEH_SJLJ_Setjmp>;
101
102 def ARMMemBarrierV7  : SDNode<"ARMISD::MEMBARRIER", SDT_ARMMEMBARRIERV7,
103                               [SDNPHasChain]>;
104 def ARMSyncBarrierV7 : SDNode<"ARMISD::SYNCBARRIER", SDT_ARMMEMBARRIERV7,
105                               [SDNPHasChain]>;
106 def ARMMemBarrierV6  : SDNode<"ARMISD::MEMBARRIER", SDT_ARMMEMBARRIERV6,
107                               [SDNPHasChain]>;
108 def ARMSyncBarrierV6 : SDNode<"ARMISD::SYNCBARRIER", SDT_ARMMEMBARRIERV6,
109                               [SDNPHasChain]>;
110
111 def ARMrbit          : SDNode<"ARMISD::RBIT", SDTIntUnaryOp>;
112
113 //===----------------------------------------------------------------------===//
114 // ARM Instruction Predicate Definitions.
115 //
116 def HasV5T    : Predicate<"Subtarget->hasV5TOps()">;
117 def HasV5TE   : Predicate<"Subtarget->hasV5TEOps()">;
118 def HasV6     : Predicate<"Subtarget->hasV6Ops()">;
119 def HasV6T2   : Predicate<"Subtarget->hasV6T2Ops()">;
120 def NoV6T2    : Predicate<"!Subtarget->hasV6T2Ops()">;
121 def HasV7     : Predicate<"Subtarget->hasV7Ops()">;
122 def HasVFP2   : Predicate<"Subtarget->hasVFP2()">;
123 def HasVFP3   : Predicate<"Subtarget->hasVFP3()">;
124 def HasNEON   : Predicate<"Subtarget->hasNEON()">;
125 def UseNEONForFP : Predicate<"Subtarget->useNEONForSinglePrecisionFP()">;
126 def DontUseNEONForFP : Predicate<"!Subtarget->useNEONForSinglePrecisionFP()">;
127 def IsThumb   : Predicate<"Subtarget->isThumb()">;
128 def IsThumb1Only : Predicate<"Subtarget->isThumb1Only()">;
129 def IsThumb2  : Predicate<"Subtarget->isThumb2()">;
130 def IsARM     : Predicate<"!Subtarget->isThumb()">;
131 def IsDarwin    : Predicate<"Subtarget->isTargetDarwin()">;
132 def IsNotDarwin : Predicate<"!Subtarget->isTargetDarwin()">;
133 def CarryDefIsUnused : Predicate<"!N->hasAnyUseOfValue(1)">;
134 def CarryDefIsUsed   : Predicate<"N->hasAnyUseOfValue(1)">;
135
136 // FIXME: Eventually this will be just "hasV6T2Ops".
137 def UseMovt   : Predicate<"Subtarget->useMovt()">;
138 def DontUseMovt : Predicate<"!Subtarget->useMovt()">;
139
140 //===----------------------------------------------------------------------===//
141 // ARM Flag Definitions.
142
143 class RegConstraint<string C> {
144   string Constraints = C;
145 }
146
147 //===----------------------------------------------------------------------===//
148 //  ARM specific transformation functions and pattern fragments.
149 //
150
151 // so_imm_neg_XFORM - Return a so_imm value packed into the format described for
152 // so_imm_neg def below.
153 def so_imm_neg_XFORM : SDNodeXForm<imm, [{
154   return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
155 }]>;
156
157 // so_imm_not_XFORM - Return a so_imm value packed into the format described for
158 // so_imm_not def below.
159 def so_imm_not_XFORM : SDNodeXForm<imm, [{
160   return CurDAG->getTargetConstant(~(int)N->getZExtValue(), MVT::i32);
161 }]>;
162
163 // rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
164 def rot_imm : PatLeaf<(i32 imm), [{
165   int32_t v = (int32_t)N->getZExtValue();
166   return v == 8 || v == 16 || v == 24;
167 }]>;
168
169 /// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
170 def imm1_15 : PatLeaf<(i32 imm), [{
171   return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 16;
172 }]>;
173
174 /// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
175 def imm16_31 : PatLeaf<(i32 imm), [{
176   return (int32_t)N->getZExtValue() >= 16 && (int32_t)N->getZExtValue() < 32;
177 }]>;
178
179 def so_imm_neg : 
180   PatLeaf<(imm), [{
181     return ARM_AM::getSOImmVal(-(int)N->getZExtValue()) != -1;
182   }], so_imm_neg_XFORM>;
183
184 def so_imm_not :
185   PatLeaf<(imm), [{
186     return ARM_AM::getSOImmVal(~(int)N->getZExtValue()) != -1;
187   }], so_imm_not_XFORM>;
188
189 // sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
190 def sext_16_node : PatLeaf<(i32 GPR:$a), [{
191   return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
192 }]>;
193
194 /// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
195 /// e.g., 0xf000ffff
196 def bf_inv_mask_imm : Operand<i32>,
197                       PatLeaf<(imm), [{ 
198   uint32_t v = (uint32_t)N->getZExtValue();
199   if (v == 0xffffffff)
200     return 0;
201   // there can be 1's on either or both "outsides", all the "inside"
202   // bits must be 0's
203   unsigned int lsb = 0, msb = 31;
204   while (v & (1 << msb)) --msb;
205   while (v & (1 << lsb)) ++lsb;
206   for (unsigned int i = lsb; i <= msb; ++i) {
207     if (v & (1 << i))
208       return 0;
209   }
210   return 1;
211 }] > {
212   let PrintMethod = "printBitfieldInvMaskImmOperand";
213 }
214
215 /// Split a 32-bit immediate into two 16 bit parts.
216 def lo16 : SDNodeXForm<imm, [{
217   return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() & 0xffff,
218                                    MVT::i32);
219 }]>;
220
221 def hi16 : SDNodeXForm<imm, [{
222   return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
223 }]>;
224
225 def lo16AllZero : PatLeaf<(i32 imm), [{
226   // Returns true if all low 16-bits are 0.
227   return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
228 }], hi16>;
229
230 /// imm0_65535 predicate - True if the 32-bit immediate is in the range 
231 /// [0.65535].
232 def imm0_65535 : PatLeaf<(i32 imm), [{
233   return (uint32_t)N->getZExtValue() < 65536;
234 }]>;
235
236 class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
237 class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
238
239 //===----------------------------------------------------------------------===//
240 // Operand Definitions.
241 //
242
243 // Branch target.
244 def brtarget : Operand<OtherVT>;
245
246 // A list of registers separated by comma. Used by load/store multiple.
247 def reglist : Operand<i32> {
248   let PrintMethod = "printRegisterList";
249 }
250
251 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
252 def cpinst_operand : Operand<i32> {
253   let PrintMethod = "printCPInstOperand";
254 }
255
256 def jtblock_operand : Operand<i32> {
257   let PrintMethod = "printJTBlockOperand";
258 }
259 def jt2block_operand : Operand<i32> {
260   let PrintMethod = "printJT2BlockOperand";
261 }
262
263 // Local PC labels.
264 def pclabel : Operand<i32> {
265   let PrintMethod = "printPCLabel";
266 }
267
268 // shifter_operand operands: so_reg and so_imm.
269 def so_reg : Operand<i32>,    // reg reg imm
270             ComplexPattern<i32, 3, "SelectShifterOperandReg",
271                             [shl,srl,sra,rotr]> {
272   let PrintMethod = "printSORegOperand";
273   let MIOperandInfo = (ops GPR, GPR, i32imm);
274 }
275
276 // so_imm - Match a 32-bit shifter_operand immediate operand, which is an
277 // 8-bit immediate rotated by an arbitrary number of bits.  so_imm values are
278 // represented in the imm field in the same 12-bit form that they are encoded
279 // into so_imm instructions: the 8-bit immediate is the least significant bits
280 // [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
281 def so_imm : Operand<i32>,
282              PatLeaf<(imm), [{
283       return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
284     }]> {
285   let PrintMethod = "printSOImmOperand";
286 }
287
288 // Break so_imm's up into two pieces.  This handles immediates with up to 16
289 // bits set in them.  This uses so_imm2part to match and so_imm2part_[12] to
290 // get the first/second pieces.
291 def so_imm2part : Operand<i32>,
292                   PatLeaf<(imm), [{
293       return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
294     }]> {
295   let PrintMethod = "printSOImm2PartOperand";
296 }
297
298 def so_imm2part_1 : SDNodeXForm<imm, [{
299   unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getZExtValue());
300   return CurDAG->getTargetConstant(V, MVT::i32);
301 }]>;
302
303 def so_imm2part_2 : SDNodeXForm<imm, [{
304   unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getZExtValue());
305   return CurDAG->getTargetConstant(V, MVT::i32);
306 }]>;
307
308 def so_neg_imm2part : Operand<i32>, PatLeaf<(imm), [{
309       return ARM_AM::isSOImmTwoPartVal(-(int)N->getZExtValue());
310     }]> {
311   let PrintMethod = "printSOImm2PartOperand";
312 }
313
314 def so_neg_imm2part_1 : SDNodeXForm<imm, [{
315   unsigned V = ARM_AM::getSOImmTwoPartFirst(-(int)N->getZExtValue());
316   return CurDAG->getTargetConstant(V, MVT::i32);
317 }]>;
318
319 def so_neg_imm2part_2 : SDNodeXForm<imm, [{
320   unsigned V = ARM_AM::getSOImmTwoPartSecond(-(int)N->getZExtValue());
321   return CurDAG->getTargetConstant(V, MVT::i32);
322 }]>;
323
324 /// imm0_31 predicate - True if the 32-bit immediate is in the range [0,31].
325 def imm0_31 : Operand<i32>, PatLeaf<(imm), [{
326   return (int32_t)N->getZExtValue() < 32;
327 }]>;
328
329 // Define ARM specific addressing modes.
330
331 // addrmode2 := reg +/- reg shop imm
332 // addrmode2 := reg +/- imm12
333 //
334 def addrmode2 : Operand<i32>,
335                 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
336   let PrintMethod = "printAddrMode2Operand";
337   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
338 }
339
340 def am2offset : Operand<i32>,
341                 ComplexPattern<i32, 2, "SelectAddrMode2Offset", []> {
342   let PrintMethod = "printAddrMode2OffsetOperand";
343   let MIOperandInfo = (ops GPR, i32imm);
344 }
345
346 // addrmode3 := reg +/- reg
347 // addrmode3 := reg +/- imm8
348 //
349 def addrmode3 : Operand<i32>,
350                 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
351   let PrintMethod = "printAddrMode3Operand";
352   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
353 }
354
355 def am3offset : Operand<i32>,
356                 ComplexPattern<i32, 2, "SelectAddrMode3Offset", []> {
357   let PrintMethod = "printAddrMode3OffsetOperand";
358   let MIOperandInfo = (ops GPR, i32imm);
359 }
360
361 // addrmode4 := reg, <mode|W>
362 //
363 def addrmode4 : Operand<i32>,
364                 ComplexPattern<i32, 2, "SelectAddrMode4", []> {
365   let PrintMethod = "printAddrMode4Operand";
366   let MIOperandInfo = (ops GPR, i32imm);
367 }
368
369 // addrmode5 := reg +/- imm8*4
370 //
371 def addrmode5 : Operand<i32>,
372                 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
373   let PrintMethod = "printAddrMode5Operand";
374   let MIOperandInfo = (ops GPR, i32imm);
375 }
376
377 // addrmode6 := reg with optional writeback
378 //
379 def addrmode6 : Operand<i32>,
380                 ComplexPattern<i32, 4, "SelectAddrMode6", []> {
381   let PrintMethod = "printAddrMode6Operand";
382   let MIOperandInfo = (ops GPR:$addr, GPR:$upd, i32imm, i32imm);
383 }
384
385 // addrmodepc := pc + reg
386 //
387 def addrmodepc : Operand<i32>,
388                  ComplexPattern<i32, 2, "SelectAddrModePC", []> {
389   let PrintMethod = "printAddrModePCOperand";
390   let MIOperandInfo = (ops GPR, i32imm);
391 }
392
393 def nohash_imm : Operand<i32> {
394   let PrintMethod = "printNoHashImmediate";
395 }
396
397 //===----------------------------------------------------------------------===//
398
399 include "ARMInstrFormats.td"
400
401 //===----------------------------------------------------------------------===//
402 // Multiclass helpers...
403 //
404
405 /// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
406 /// binop that produces a value.
407 multiclass AsI1_bin_irs<bits<4> opcod, string opc, PatFrag opnode,
408                         bit Commutable = 0> {
409   def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
410                IIC_iALUi, opc, "\t$dst, $a, $b",
411                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]> {
412     let Inst{25} = 1;
413   }
414   def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
415                IIC_iALUr, opc, "\t$dst, $a, $b",
416                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]> {
417     let Inst{11-4} = 0b00000000;
418     let Inst{25} = 0;
419     let isCommutable = Commutable;
420   }
421   def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
422                IIC_iALUsr, opc, "\t$dst, $a, $b",
423                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]> {
424     let Inst{25} = 0;
425   }
426 }
427
428 /// AI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
429 /// instruction modifies the CPSR register.
430 let Defs = [CPSR] in {
431 multiclass AI1_bin_s_irs<bits<4> opcod, string opc, PatFrag opnode,
432                          bit Commutable = 0> {
433   def ri : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
434                IIC_iALUi, opc, "\t$dst, $a, $b",
435                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]> {
436     let Inst{20} = 1;
437     let Inst{25} = 1;
438   }
439   def rr : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
440                IIC_iALUr, opc, "\t$dst, $a, $b",
441                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]> {
442     let isCommutable = Commutable;
443     let Inst{11-4} = 0b00000000;
444     let Inst{20} = 1;
445     let Inst{25} = 0;
446   }
447   def rs : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
448                IIC_iALUsr, opc, "\t$dst, $a, $b",
449                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]> {
450     let Inst{20} = 1;
451     let Inst{25} = 0;
452   }
453 }
454 }
455
456 /// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
457 /// patterns. Similar to AsI1_bin_irs except the instruction does not produce
458 /// a explicit result, only implicitly set CPSR.
459 let Defs = [CPSR] in {
460 multiclass AI1_cmp_irs<bits<4> opcod, string opc, PatFrag opnode,
461                        bit Commutable = 0> {
462   def ri : AI1<opcod, (outs), (ins GPR:$a, so_imm:$b), DPFrm, IIC_iCMPi,
463                opc, "\t$a, $b",
464                [(opnode GPR:$a, so_imm:$b)]> {
465     let Inst{20} = 1;
466     let Inst{25} = 1;
467   }
468   def rr : AI1<opcod, (outs), (ins GPR:$a, GPR:$b), DPFrm, IIC_iCMPr,
469                opc, "\t$a, $b",
470                [(opnode GPR:$a, GPR:$b)]> {
471     let Inst{11-4} = 0b00000000;
472     let Inst{20} = 1;
473     let Inst{25} = 0;
474     let isCommutable = Commutable;
475   }
476   def rs : AI1<opcod, (outs), (ins GPR:$a, so_reg:$b), DPSoRegFrm, IIC_iCMPsr,
477                opc, "\t$a, $b",
478                [(opnode GPR:$a, so_reg:$b)]> {
479     let Inst{20} = 1;
480     let Inst{25} = 0;
481   }
482 }
483 }
484
485 /// AI_unary_rrot - A unary operation with two forms: one whose operand is a
486 /// register and one whose operand is a register rotated by 8/16/24.
487 /// FIXME: Remove the 'r' variant. Its rot_imm is zero.
488 multiclass AI_unary_rrot<bits<8> opcod, string opc, PatFrag opnode> {
489   def r     : AExtI<opcod, (outs GPR:$dst), (ins GPR:$src),
490                  IIC_iUNAr, opc, "\t$dst, $src",
491                  [(set GPR:$dst, (opnode GPR:$src))]>,
492               Requires<[IsARM, HasV6]> {
493     let Inst{11-10} = 0b00;
494     let Inst{19-16} = 0b1111;
495   }
496   def r_rot : AExtI<opcod, (outs GPR:$dst), (ins GPR:$src, i32imm:$rot),
497                  IIC_iUNAsi, opc, "\t$dst, $src, ror $rot",
498                  [(set GPR:$dst, (opnode (rotr GPR:$src, rot_imm:$rot)))]>,
499               Requires<[IsARM, HasV6]> {
500     let Inst{19-16} = 0b1111;
501   }
502 }
503
504 /// AI_bin_rrot - A binary operation with two forms: one whose operand is a
505 /// register and one whose operand is a register rotated by 8/16/24.
506 multiclass AI_bin_rrot<bits<8> opcod, string opc, PatFrag opnode> {
507   def rr     : AExtI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
508                   IIC_iALUr, opc, "\t$dst, $LHS, $RHS",
509                   [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
510                Requires<[IsARM, HasV6]> {
511     let Inst{11-10} = 0b00;
512   }
513   def rr_rot : AExtI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
514                   IIC_iALUsi, opc, "\t$dst, $LHS, $RHS, ror $rot",
515                   [(set GPR:$dst, (opnode GPR:$LHS,
516                                           (rotr GPR:$RHS, rot_imm:$rot)))]>,
517                   Requires<[IsARM, HasV6]>;
518 }
519
520 /// AI1_adde_sube_irs - Define instructions and patterns for adde and sube.
521 let Uses = [CPSR] in {
522 multiclass AI1_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
523                              bit Commutable = 0> {
524   def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
525                 DPFrm, IIC_iALUi, opc, "\t$dst, $a, $b",
526                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>,
527                Requires<[IsARM, CarryDefIsUnused]> {
528     let Inst{25} = 1;
529   }
530   def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
531                 DPFrm, IIC_iALUr, opc, "\t$dst, $a, $b",
532                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>,
533                Requires<[IsARM, CarryDefIsUnused]> {
534     let isCommutable = Commutable;
535     let Inst{11-4} = 0b00000000;
536     let Inst{25} = 0;
537   }
538   def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
539                 DPSoRegFrm, IIC_iALUsr, opc, "\t$dst, $a, $b",
540                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>,
541                Requires<[IsARM, CarryDefIsUnused]> {
542     let Inst{25} = 0;
543   }
544 }
545 // Carry setting variants
546 let Defs = [CPSR] in {
547 multiclass AI1_adde_sube_s_irs<bits<4> opcod, string opc, PatFrag opnode,
548                              bit Commutable = 0> {
549   def Sri : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
550                 DPFrm, IIC_iALUi, !strconcat(opc, "\t$dst, $a, $b"),
551                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>,
552                Requires<[IsARM, CarryDefIsUsed]> {
553     let Defs = [CPSR];
554     let Inst{20} = 1;
555     let Inst{25} = 1;
556   }
557   def Srr : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
558                 DPFrm, IIC_iALUr, !strconcat(opc, "\t$dst, $a, $b"),
559                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>,
560                Requires<[IsARM, CarryDefIsUsed]> {
561     let Defs = [CPSR];
562     let Inst{11-4} = 0b00000000;
563     let Inst{20} = 1;
564     let Inst{25} = 0;
565   }
566   def Srs : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
567                 DPSoRegFrm, IIC_iALUsr, !strconcat(opc, "\t$dst, $a, $b"),
568                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>,
569                Requires<[IsARM, CarryDefIsUsed]> {
570     let Defs = [CPSR];
571     let Inst{20} = 1;
572     let Inst{25} = 0;
573   }
574 }
575 }
576 }
577
578 //===----------------------------------------------------------------------===//
579 // Instructions
580 //===----------------------------------------------------------------------===//
581
582 //===----------------------------------------------------------------------===//
583 //  Miscellaneous Instructions.
584 //
585
586 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
587 /// the function.  The first operand is the ID# for this instruction, the second
588 /// is the index into the MachineConstantPool that this is, the third is the
589 /// size in bytes of this constant pool entry.
590 let neverHasSideEffects = 1, isNotDuplicable = 1 in
591 def CONSTPOOL_ENTRY :
592 PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
593                     i32imm:$size), NoItinerary,
594            "${instid:label} ${cpidx:cpentry}", []>;
595
596 let Defs = [SP], Uses = [SP] in {
597 def ADJCALLSTACKUP :
598 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p), NoItinerary,
599            "@ ADJCALLSTACKUP $amt1",
600            [(ARMcallseq_end timm:$amt1, timm:$amt2)]>;
601
602 def ADJCALLSTACKDOWN : 
603 PseudoInst<(outs), (ins i32imm:$amt, pred:$p), NoItinerary,
604            "@ ADJCALLSTACKDOWN $amt",
605            [(ARMcallseq_start timm:$amt)]>;
606 }
607
608 def NOP : AI<(outs), (ins), Pseudo, NoItinerary, "nop", "",
609              [/* For disassembly only; pattern left blank */]>,
610           Requires<[IsARM, HasV6T2]> {
611   let Inst{27-16} = 0b001100100000;
612   let Inst{7-0} = 0b00000000;
613 }
614
615 // The i32imm operand $val can be used by a debugger to store more information
616 // about the breakpoint.
617 def BKPT : AI<(outs), (ins i32imm:$val), Pseudo, NoItinerary, "bkpt", "\t$val",
618               [/* For disassembly only; pattern left blank */]>,
619            Requires<[IsARM]> {
620   let Inst{27-20} = 0b00010010;
621   let Inst{7-4} = 0b0111;
622 }
623
624 def DBG : AI<(outs), (ins i32imm:$opt), Pseudo, NoItinerary, "dbg", "\t$opt",
625              [/* For disassembly only; pattern left blank */]>,
626           Requires<[IsARM, HasV7]> {
627   let Inst{27-16} = 0b001100100000;
628   let Inst{7-4} = 0b1111;
629 }
630
631 // A5.4 Permanently UNDEFINED instructions.
632 def TRAP : AI<(outs), (ins), Pseudo, NoItinerary, "trap", "",
633               [/* For disassembly only; pattern left blank */]>,
634            Requires<[IsARM]> {
635   let Inst{27-25} = 0b011;
636   let Inst{24-20} = 0b11111;
637   let Inst{7-5} = 0b111;
638   let Inst{4} = 0b1;
639 }
640
641 // Address computation and loads and stores in PIC mode.
642 let isNotDuplicable = 1 in {
643 def PICADD : AXI1<0b0100, (outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
644                   Pseudo, IIC_iALUr, "\n$cp:\n\tadd$p\t$dst, pc, $a",
645                    [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
646
647 let AddedComplexity = 10 in {
648 def PICLDR  : AXI2ldw<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
649                   Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldr$p\t$dst, $addr",
650                   [(set GPR:$dst, (load addrmodepc:$addr))]>;
651
652 def PICLDRH : AXI3ldh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
653                 Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldrh${p}\t$dst, $addr",
654                   [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
655
656 def PICLDRB : AXI2ldb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
657                 Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldrb${p}\t$dst, $addr",
658                   [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
659
660 def PICLDRSH : AXI3ldsh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
661                Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldrsh${p}\t$dst, $addr",
662                   [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
663
664 def PICLDRSB : AXI3ldsb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
665                Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldrsb${p}\t$dst, $addr",
666                   [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
667 }
668 let AddedComplexity = 10 in {
669 def PICSTR  : AXI2stw<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
670                Pseudo, IIC_iStorer, "\n${addr:label}:\n\tstr$p\t$src, $addr",
671                [(store GPR:$src, addrmodepc:$addr)]>;
672
673 def PICSTRH : AXI3sth<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
674                Pseudo, IIC_iStorer, "\n${addr:label}:\n\tstrh${p}\t$src, $addr",
675                [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
676
677 def PICSTRB : AXI2stb<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
678                Pseudo, IIC_iStorer, "\n${addr:label}:\n\tstrb${p}\t$src, $addr",
679                [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
680 }
681 } // isNotDuplicable = 1
682
683
684 // LEApcrel - Load a pc-relative address into a register without offending the
685 // assembler.
686 def LEApcrel : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, pred:$p),
687                     Pseudo, IIC_iALUi,
688            !strconcat(!strconcat(".set ${:private}PCRELV${:uid}, ($label-(",
689                                  "${:private}PCRELL${:uid}+8))\n"),
690                       !strconcat("${:private}PCRELL${:uid}:\n\t",
691                                  "add$p\t$dst, pc, #${:private}PCRELV${:uid}")),
692                    []>;
693
694 def LEApcrelJT : AXI1<0x0, (outs GPR:$dst),
695                            (ins i32imm:$label, nohash_imm:$id, pred:$p),
696           Pseudo, IIC_iALUi,
697    !strconcat(!strconcat(".set ${:private}PCRELV${:uid}, "
698                          "(${label}_${id}-(",
699                                   "${:private}PCRELL${:uid}+8))\n"),
700                        !strconcat("${:private}PCRELL${:uid}:\n\t",
701                                   "add$p\t$dst, pc, #${:private}PCRELV${:uid}")),
702                    []> {
703     let Inst{25} = 1;
704 }
705
706 //===----------------------------------------------------------------------===//
707 //  Control Flow Instructions.
708 //
709
710 let isReturn = 1, isTerminator = 1, isBarrier = 1 in
711   def BX_RET : AI<(outs), (ins), BrMiscFrm, IIC_Br, 
712                   "bx", "\tlr", [(ARMretflag)]> {
713   let Inst{3-0}   = 0b1110;
714   let Inst{7-4}   = 0b0001;
715   let Inst{19-8}  = 0b111111111111;
716   let Inst{27-20} = 0b00010010;
717 }
718
719 // Indirect branches
720 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
721   def BRIND : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "bx\t$dst",
722                   [(brind GPR:$dst)]> {
723     let Inst{7-4}   = 0b0001;
724     let Inst{19-8}  = 0b111111111111;
725     let Inst{27-20} = 0b00010010;
726     let Inst{31-28} = 0b1110;
727   }
728 }
729
730 // FIXME: remove when we have a way to marking a MI with these properties.
731 // FIXME: Should pc be an implicit operand like PICADD, etc?
732 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
733     hasExtraDefRegAllocReq = 1 in
734   def LDM_RET : AXI4ld<(outs),
735                     (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
736                     LdStMulFrm, IIC_Br, "ldm${addr:submode}${p}\t$addr, $wb",
737                     []>;
738
739 // On non-Darwin platforms R9 is callee-saved.
740 let isCall = 1,
741   Defs = [R0,  R1,  R2,  R3,  R12, LR,
742           D0,  D1,  D2,  D3,  D4,  D5,  D6,  D7,
743           D16, D17, D18, D19, D20, D21, D22, D23,
744           D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
745   def BL  : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
746                 IIC_Br, "bl\t${func:call}",
747                 [(ARMcall tglobaladdr:$func)]>,
748             Requires<[IsARM, IsNotDarwin]> {
749     let Inst{31-28} = 0b1110;
750   }
751
752   def BL_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
753                    IIC_Br, "bl", "\t${func:call}",
754                    [(ARMcall_pred tglobaladdr:$func)]>,
755                 Requires<[IsARM, IsNotDarwin]>;
756
757   // ARMv5T and above
758   def BLX : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
759                 IIC_Br, "blx\t$func",
760                 [(ARMcall GPR:$func)]>,
761             Requires<[IsARM, HasV5T, IsNotDarwin]> {
762     let Inst{7-4}   = 0b0011;
763     let Inst{19-8}  = 0b111111111111;
764     let Inst{27-20} = 0b00010010;
765   }
766
767   // ARMv4T
768   def BX : ABXIx2<(outs), (ins GPR:$func, variable_ops),
769                   IIC_Br, "mov\tlr, pc\n\tbx\t$func",
770                   [(ARMcall_nolink GPR:$func)]>,
771            Requires<[IsARM, IsNotDarwin]> {
772     let Inst{7-4}   = 0b0001;
773     let Inst{19-8}  = 0b111111111111;
774     let Inst{27-20} = 0b00010010;
775   }
776 }
777
778 // On Darwin R9 is call-clobbered.
779 let isCall = 1,
780   Defs = [R0,  R1,  R2,  R3,  R9,  R12, LR,
781           D0,  D1,  D2,  D3,  D4,  D5,  D6,  D7,
782           D16, D17, D18, D19, D20, D21, D22, D23,
783           D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
784   def BLr9  : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
785                 IIC_Br, "bl\t${func:call}",
786                 [(ARMcall tglobaladdr:$func)]>, Requires<[IsARM, IsDarwin]> {
787     let Inst{31-28} = 0b1110;
788   }
789
790   def BLr9_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
791                    IIC_Br, "bl", "\t${func:call}",
792                    [(ARMcall_pred tglobaladdr:$func)]>,
793                   Requires<[IsARM, IsDarwin]>;
794
795   // ARMv5T and above
796   def BLXr9 : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
797                 IIC_Br, "blx\t$func",
798                 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T, IsDarwin]> {
799     let Inst{7-4}   = 0b0011;
800     let Inst{19-8}  = 0b111111111111;
801     let Inst{27-20} = 0b00010010;
802   }
803
804   // ARMv4T
805   def BXr9 : ABXIx2<(outs), (ins GPR:$func, variable_ops),
806                   IIC_Br, "mov\tlr, pc\n\tbx\t$func",
807                   [(ARMcall_nolink GPR:$func)]>, Requires<[IsARM, IsDarwin]> {
808     let Inst{7-4}   = 0b0001;
809     let Inst{19-8}  = 0b111111111111;
810     let Inst{27-20} = 0b00010010;
811   }
812 }
813
814 let isBranch = 1, isTerminator = 1 in {
815   // B is "predicable" since it can be xformed into a Bcc.
816   let isBarrier = 1 in {
817     let isPredicable = 1 in
818     def B : ABXI<0b1010, (outs), (ins brtarget:$target), IIC_Br,
819                 "b\t$target", [(br bb:$target)]>;
820
821   let isNotDuplicable = 1, isIndirectBranch = 1 in {
822   def BR_JTr : JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
823                     IIC_Br, "mov\tpc, $target \n$jt",
824                     [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]> {
825     let Inst{11-4}  = 0b00000000;
826     let Inst{15-12} = 0b1111;
827     let Inst{20}    = 0; // S Bit
828     let Inst{24-21} = 0b1101;
829     let Inst{27-25} = 0b000;
830   }
831   def BR_JTm : JTI<(outs),
832                    (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
833                    IIC_Br, "ldr\tpc, $target \n$jt",
834                    [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
835                      imm:$id)]> {
836     let Inst{15-12} = 0b1111;
837     let Inst{20}    = 1; // L bit
838     let Inst{21}    = 0; // W bit
839     let Inst{22}    = 0; // B bit
840     let Inst{24}    = 1; // P bit
841     let Inst{27-25} = 0b011;
842   }
843   def BR_JTadd : JTI<(outs),
844                    (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
845                     IIC_Br, "add\tpc, $target, $idx \n$jt",
846                     [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
847                       imm:$id)]> {
848     let Inst{15-12} = 0b1111;
849     let Inst{20}    = 0; // S bit
850     let Inst{24-21} = 0b0100;
851     let Inst{27-25} = 0b000;
852   }
853   } // isNotDuplicable = 1, isIndirectBranch = 1
854   } // isBarrier = 1
855
856   // FIXME: should be able to write a pattern for ARMBrcond, but can't use
857   // a two-value operand where a dag node expects two operands. :( 
858   def Bcc : ABI<0b1010, (outs), (ins brtarget:$target),
859                IIC_Br, "b", "\t$target",
860                [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
861 }
862
863 // Supervisor call (software interrupt) -- for disassembly only
864 let isCall = 1 in {
865 def SVC : ABI<0b1111, (outs), (ins i32imm:$svc), IIC_Br, "svc", "\t$svc",
866               [/* For disassembly only; pattern left blank */]>;
867 }
868
869 //===----------------------------------------------------------------------===//
870 //  Load / store Instructions.
871 //
872
873 // Load
874 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in 
875 def LDR  : AI2ldw<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm, IIC_iLoadr,
876                "ldr", "\t$dst, $addr",
877                [(set GPR:$dst, (load addrmode2:$addr))]>;
878
879 // Special LDR for loads from non-pc-relative constpools.
880 let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1,
881     mayHaveSideEffects = 1  in
882 def LDRcp : AI2ldw<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm, IIC_iLoadr,
883                  "ldr", "\t$dst, $addr", []>;
884
885 // Loads with zero extension
886 def LDRH  : AI3ldh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
887                   IIC_iLoadr, "ldrh", "\t$dst, $addr",
888                   [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
889
890 def LDRB  : AI2ldb<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm, 
891                   IIC_iLoadr, "ldrb", "\t$dst, $addr",
892                   [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
893
894 // Loads with sign extension
895 def LDRSH : AI3ldsh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
896                    IIC_iLoadr, "ldrsh", "\t$dst, $addr",
897                    [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
898
899 def LDRSB : AI3ldsb<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
900                    IIC_iLoadr, "ldrsb", "\t$dst, $addr",
901                    [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
902
903 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in {
904 // Load doubleword
905 def LDRD : AI3ldd<(outs GPR:$dst1, GPR:$dst2), (ins addrmode3:$addr), LdMiscFrm,
906                  IIC_iLoadr, "ldrd", "\t$dst1, $addr",
907                  []>, Requires<[IsARM, HasV5TE]>;
908
909 // Indexed loads
910 def LDR_PRE  : AI2ldwpr<(outs GPR:$dst, GPR:$base_wb),
911                      (ins addrmode2:$addr), LdFrm, IIC_iLoadru,
912                      "ldr", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
913
914 def LDR_POST : AI2ldwpo<(outs GPR:$dst, GPR:$base_wb),
915                      (ins GPR:$base, am2offset:$offset), LdFrm, IIC_iLoadru,
916                      "ldr", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
917
918 def LDRH_PRE  : AI3ldhpr<(outs GPR:$dst, GPR:$base_wb),
919                      (ins addrmode3:$addr), LdMiscFrm, IIC_iLoadru,
920                      "ldrh", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
921
922 def LDRH_POST : AI3ldhpo<(outs GPR:$dst, GPR:$base_wb),
923                      (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoadru,
924                     "ldrh", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
925
926 def LDRB_PRE  : AI2ldbpr<(outs GPR:$dst, GPR:$base_wb),
927                      (ins addrmode2:$addr), LdFrm, IIC_iLoadru,
928                      "ldrb", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
929
930 def LDRB_POST : AI2ldbpo<(outs GPR:$dst, GPR:$base_wb),
931                      (ins GPR:$base,am2offset:$offset), LdFrm, IIC_iLoadru,
932                     "ldrb", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
933
934 def LDRSH_PRE : AI3ldshpr<(outs GPR:$dst, GPR:$base_wb),
935                       (ins addrmode3:$addr), LdMiscFrm, IIC_iLoadru,
936                       "ldrsh", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
937
938 def LDRSH_POST: AI3ldshpo<(outs GPR:$dst, GPR:$base_wb),
939                       (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoadru,
940                    "ldrsh", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
941
942 def LDRSB_PRE : AI3ldsbpr<(outs GPR:$dst, GPR:$base_wb),
943                       (ins addrmode3:$addr), LdMiscFrm, IIC_iLoadru,
944                       "ldrsb", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
945
946 def LDRSB_POST: AI3ldsbpo<(outs GPR:$dst, GPR:$base_wb),
947                       (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoadru,
948                    "ldrsb", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
949 }
950
951 // LDRT and LDRBT are for disassembly only.
952
953 def LDRT : AI2ldwpo<(outs GPR:$dst, GPR:$base_wb),
954                    (ins GPR:$base, am2offset:$offset), LdFrm, IIC_iLoadru,
955                    "ldrt", "\t$dst, [$base], $offset", "$base = $base_wb", []> {
956   let Inst{21} = 1; // overwrite
957 }
958
959 def LDRBT : AI2ldbpo<(outs GPR:$dst, GPR:$base_wb),
960                    (ins GPR:$base,am2offset:$offset), LdFrm, IIC_iLoadru,
961                    "ldrb", "\t$dst, [$base], $offset", "$base = $base_wb", []> {
962   let Inst{21} = 1; // overwrite
963 }
964
965 // Store
966 def STR  : AI2stw<(outs), (ins GPR:$src, addrmode2:$addr), StFrm, IIC_iStorer,
967                "str", "\t$src, $addr",
968                [(store GPR:$src, addrmode2:$addr)]>;
969
970 // Stores with truncate
971 def STRH : AI3sth<(outs), (ins GPR:$src, addrmode3:$addr), StMiscFrm, IIC_iStorer,
972                "strh", "\t$src, $addr",
973                [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
974
975 def STRB : AI2stb<(outs), (ins GPR:$src, addrmode2:$addr), StFrm, IIC_iStorer,
976                "strb", "\t$src, $addr",
977                [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
978
979 // Store doubleword
980 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
981 def STRD : AI3std<(outs), (ins GPR:$src1, GPR:$src2, addrmode3:$addr),
982                StMiscFrm, IIC_iStorer,
983                "strd", "\t$src1, $addr", []>, Requires<[IsARM, HasV5TE]>;
984
985 // Indexed stores
986 def STR_PRE  : AI2stwpr<(outs GPR:$base_wb),
987                      (ins GPR:$src, GPR:$base, am2offset:$offset), 
988                      StFrm, IIC_iStoreru,
989                     "str", "\t$src, [$base, $offset]!", "$base = $base_wb",
990                     [(set GPR:$base_wb,
991                       (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
992
993 def STR_POST : AI2stwpo<(outs GPR:$base_wb),
994                      (ins GPR:$src, GPR:$base,am2offset:$offset), 
995                      StFrm, IIC_iStoreru,
996                     "str", "\t$src, [$base], $offset", "$base = $base_wb",
997                     [(set GPR:$base_wb,
998                       (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
999
1000 def STRH_PRE : AI3sthpr<(outs GPR:$base_wb),
1001                      (ins GPR:$src, GPR:$base,am3offset:$offset), 
1002                      StMiscFrm, IIC_iStoreru,
1003                      "strh", "\t$src, [$base, $offset]!", "$base = $base_wb",
1004                     [(set GPR:$base_wb,
1005                       (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
1006
1007 def STRH_POST: AI3sthpo<(outs GPR:$base_wb),
1008                      (ins GPR:$src, GPR:$base,am3offset:$offset), 
1009                      StMiscFrm, IIC_iStoreru,
1010                      "strh", "\t$src, [$base], $offset", "$base = $base_wb",
1011                     [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
1012                                          GPR:$base, am3offset:$offset))]>;
1013
1014 def STRB_PRE : AI2stbpr<(outs GPR:$base_wb),
1015                      (ins GPR:$src, GPR:$base,am2offset:$offset), 
1016                      StFrm, IIC_iStoreru,
1017                      "strb", "\t$src, [$base, $offset]!", "$base = $base_wb",
1018                     [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
1019                                          GPR:$base, am2offset:$offset))]>;
1020
1021 def STRB_POST: AI2stbpo<(outs GPR:$base_wb),
1022                      (ins GPR:$src, GPR:$base,am2offset:$offset), 
1023                      StFrm, IIC_iStoreru,
1024                      "strb", "\t$src, [$base], $offset", "$base = $base_wb",
1025                     [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
1026                                          GPR:$base, am2offset:$offset))]>;
1027
1028 // STRT and STRBT are for disassembly only.
1029
1030 def STRT : AI2stwpo<(outs GPR:$base_wb),
1031                     (ins GPR:$src, GPR:$base,am2offset:$offset), 
1032                     StFrm, IIC_iStoreru,
1033                     "strt", "\t$src, [$base], $offset", "$base = $base_wb",
1034                     [/* For disassembly only; pattern left blank */]> {
1035   let Inst{21} = 1; // overwrite
1036 }
1037
1038 def STRBT : AI2stbpo<(outs GPR:$base_wb),
1039                      (ins GPR:$src, GPR:$base,am2offset:$offset), 
1040                      StFrm, IIC_iStoreru,
1041                      "strbt", "\t$src, [$base], $offset", "$base = $base_wb",
1042                      [/* For disassembly only; pattern left blank */]> {
1043   let Inst{21} = 1; // overwrite
1044 }
1045
1046 //===----------------------------------------------------------------------===//
1047 //  Load / store multiple Instructions.
1048 //
1049
1050 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1051 def LDM : AXI4ld<(outs),
1052                (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
1053                LdStMulFrm, IIC_iLoadm, "ldm${addr:submode}${p}\t$addr, $wb",
1054                []>;
1055
1056 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1057 def STM : AXI4st<(outs),
1058                (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
1059                LdStMulFrm, IIC_iStorem, "stm${addr:submode}${p}\t$addr, $wb",
1060                []>;
1061
1062 //===----------------------------------------------------------------------===//
1063 //  Move Instructions.
1064 //
1065
1066 let neverHasSideEffects = 1 in
1067 def MOVr : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), DPFrm, IIC_iMOVr,
1068                 "mov", "\t$dst, $src", []>, UnaryDP {
1069   let Inst{11-4} = 0b00000000;
1070   let Inst{25} = 0;
1071 }
1072
1073 def MOVs : AsI1<0b1101, (outs GPR:$dst), (ins so_reg:$src), 
1074                 DPSoRegFrm, IIC_iMOVsr,
1075                 "mov", "\t$dst, $src", [(set GPR:$dst, so_reg:$src)]>, UnaryDP {
1076   let Inst{25} = 0;
1077 }
1078
1079 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
1080 def MOVi : AsI1<0b1101, (outs GPR:$dst), (ins so_imm:$src), DPFrm, IIC_iMOVi,
1081                 "mov", "\t$dst, $src", [(set GPR:$dst, so_imm:$src)]>, UnaryDP {
1082   let Inst{25} = 1;
1083 }
1084
1085 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
1086 def MOVi16 : AI1<0b1000, (outs GPR:$dst), (ins i32imm:$src), 
1087                  DPFrm, IIC_iMOVi,
1088                  "movw", "\t$dst, $src",
1089                  [(set GPR:$dst, imm0_65535:$src)]>,
1090                  Requires<[IsARM, HasV6T2]>, UnaryDP {
1091   let Inst{20} = 0;
1092   let Inst{25} = 1;
1093 }
1094
1095 let Constraints = "$src = $dst" in
1096 def MOVTi16 : AI1<0b1010, (outs GPR:$dst), (ins GPR:$src, i32imm:$imm),
1097                   DPFrm, IIC_iMOVi,
1098                   "movt", "\t$dst, $imm",
1099                   [(set GPR:$dst,
1100                         (or (and GPR:$src, 0xffff), 
1101                             lo16AllZero:$imm))]>, UnaryDP,
1102                   Requires<[IsARM, HasV6T2]> {
1103   let Inst{20} = 0;
1104   let Inst{25} = 1;
1105 }
1106
1107 def : ARMPat<(or GPR:$src, 0xffff0000), (MOVTi16 GPR:$src, 0xffff)>,
1108       Requires<[IsARM, HasV6T2]>;
1109
1110 let Uses = [CPSR] in
1111 def MOVrx : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo, IIC_iMOVsi,
1112                  "mov", "\t$dst, $src, rrx",
1113                  [(set GPR:$dst, (ARMrrx GPR:$src))]>, UnaryDP;
1114
1115 // These aren't really mov instructions, but we have to define them this way
1116 // due to flag operands.
1117
1118 let Defs = [CPSR] in {
1119 def MOVsrl_flag : AI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo, 
1120                       IIC_iMOVsi, "movs", "\t$dst, $src, lsr #1",
1121                       [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, UnaryDP;
1122 def MOVsra_flag : AI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
1123                       IIC_iMOVsi, "movs", "\t$dst, $src, asr #1",
1124                       [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, UnaryDP;
1125 }
1126
1127 //===----------------------------------------------------------------------===//
1128 //  Extend Instructions.
1129 //
1130
1131 // Sign extenders
1132
1133 defm SXTB  : AI_unary_rrot<0b01101010,
1134                            "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
1135 defm SXTH  : AI_unary_rrot<0b01101011,
1136                            "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
1137
1138 defm SXTAB : AI_bin_rrot<0b01101010,
1139                "sxtab", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
1140 defm SXTAH : AI_bin_rrot<0b01101011,
1141                "sxtah", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
1142
1143 // TODO: SXT(A){B|H}16
1144
1145 // Zero extenders
1146
1147 let AddedComplexity = 16 in {
1148 defm UXTB   : AI_unary_rrot<0b01101110,
1149                             "uxtb"  , UnOpFrag<(and node:$Src, 0x000000FF)>>;
1150 defm UXTH   : AI_unary_rrot<0b01101111,
1151                             "uxth"  , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1152 defm UXTB16 : AI_unary_rrot<0b01101100,
1153                             "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
1154
1155 def : ARMV6Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
1156                (UXTB16r_rot GPR:$Src, 24)>;
1157 def : ARMV6Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
1158                (UXTB16r_rot GPR:$Src, 8)>;
1159
1160 defm UXTAB : AI_bin_rrot<0b01101110, "uxtab",
1161                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
1162 defm UXTAH : AI_bin_rrot<0b01101111, "uxtah",
1163                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1164 }
1165
1166 // This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
1167 //defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
1168
1169 // TODO: UXT(A){B|H}16
1170
1171 def SBFX  : I<(outs GPR:$dst),
1172               (ins GPR:$src, imm0_31:$lsb, imm0_31:$width),
1173                AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iALUi,
1174                "sbfx", "\t$dst, $src, $lsb, $width", "", []>,
1175                Requires<[IsARM, HasV6T2]> {
1176   let Inst{27-21} = 0b0111101;
1177   let Inst{6-4}   = 0b101;
1178 }
1179
1180 def UBFX  : I<(outs GPR:$dst),
1181               (ins GPR:$src, imm0_31:$lsb, imm0_31:$width),
1182                AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iALUi,
1183                "ubfx", "\t$dst, $src, $lsb, $width", "", []>,
1184                Requires<[IsARM, HasV6T2]> {
1185   let Inst{27-21} = 0b0111111;
1186   let Inst{6-4}   = 0b101;
1187 }
1188
1189 //===----------------------------------------------------------------------===//
1190 //  Arithmetic Instructions.
1191 //
1192
1193 defm ADD  : AsI1_bin_irs<0b0100, "add",
1194                          BinOpFrag<(add  node:$LHS, node:$RHS)>, 1>;
1195 defm SUB  : AsI1_bin_irs<0b0010, "sub",
1196                          BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
1197
1198 // ADD and SUB with 's' bit set.
1199 defm ADDS : AI1_bin_s_irs<0b0100, "adds",
1200                           BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1201 defm SUBS : AI1_bin_s_irs<0b0010, "subs",
1202                           BinOpFrag<(subc node:$LHS, node:$RHS)>>;
1203
1204 defm ADC : AI1_adde_sube_irs<0b0101, "adc",
1205                              BinOpFrag<(adde node:$LHS, node:$RHS)>, 1>;
1206 defm SBC : AI1_adde_sube_irs<0b0110, "sbc",
1207                              BinOpFrag<(sube node:$LHS, node:$RHS)>>;
1208 defm ADCS : AI1_adde_sube_s_irs<0b0101, "adcs",
1209                              BinOpFrag<(adde node:$LHS, node:$RHS)>, 1>;
1210 defm SBCS : AI1_adde_sube_s_irs<0b0110, "sbcs",
1211                              BinOpFrag<(sube node:$LHS, node:$RHS)>>;
1212
1213 // These don't define reg/reg forms, because they are handled above.
1214 def RSBri : AsI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
1215                   IIC_iALUi, "rsb", "\t$dst, $a, $b",
1216                   [(set GPR:$dst, (sub so_imm:$b, GPR:$a))]> {
1217     let Inst{25} = 1;
1218 }
1219
1220 def RSBrs : AsI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
1221                   IIC_iALUsr, "rsb", "\t$dst, $a, $b",
1222                   [(set GPR:$dst, (sub so_reg:$b, GPR:$a))]> {
1223     let Inst{25} = 0;
1224 }
1225
1226 // RSB with 's' bit set.
1227 let Defs = [CPSR] in {
1228 def RSBSri : AI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
1229                  IIC_iALUi, "rsbs", "\t$dst, $a, $b",
1230                  [(set GPR:$dst, (subc so_imm:$b, GPR:$a))]> {
1231     let Inst{20} = 1;
1232     let Inst{25} = 1;
1233 }
1234 def RSBSrs : AI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
1235                  IIC_iALUsr, "rsbs", "\t$dst, $a, $b",
1236                  [(set GPR:$dst, (subc so_reg:$b, GPR:$a))]> {
1237     let Inst{20} = 1;
1238     let Inst{25} = 0;
1239 }
1240 }
1241
1242 let Uses = [CPSR] in {
1243 def RSCri : AsI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
1244                  DPFrm, IIC_iALUi, "rsc", "\t$dst, $a, $b",
1245                  [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>,
1246                  Requires<[IsARM, CarryDefIsUnused]> {
1247     let Inst{25} = 1;
1248 }
1249 def RSCrs : AsI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
1250                  DPSoRegFrm, IIC_iALUsr, "rsc", "\t$dst, $a, $b",
1251                  [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>,
1252                  Requires<[IsARM, CarryDefIsUnused]> {
1253     let Inst{25} = 0;
1254 }
1255 }
1256
1257 // FIXME: Allow these to be predicated.
1258 let Defs = [CPSR], Uses = [CPSR] in {
1259 def RSCSri : AXI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
1260                   DPFrm, IIC_iALUi, "rscs\t$dst, $a, $b",
1261                   [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>,
1262                   Requires<[IsARM, CarryDefIsUnused]> {
1263     let Inst{20} = 1;
1264     let Inst{25} = 1;
1265 }
1266 def RSCSrs : AXI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
1267                   DPSoRegFrm, IIC_iALUsr, "rscs\t$dst, $a, $b",
1268                   [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>,
1269                   Requires<[IsARM, CarryDefIsUnused]> {
1270     let Inst{20} = 1;
1271     let Inst{25} = 0;
1272 }
1273 }
1274
1275 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
1276 def : ARMPat<(add    GPR:$src, so_imm_neg:$imm),
1277              (SUBri  GPR:$src, so_imm_neg:$imm)>;
1278
1279 //def : ARMPat<(addc   GPR:$src, so_imm_neg:$imm),
1280 //             (SUBSri GPR:$src, so_imm_neg:$imm)>;
1281 //def : ARMPat<(adde   GPR:$src, so_imm_neg:$imm),
1282 //             (SBCri  GPR:$src, so_imm_neg:$imm)>;
1283
1284 // Note: These are implemented in C++ code, because they have to generate
1285 // ADD/SUBrs instructions, which use a complex pattern that a xform function
1286 // cannot produce.
1287 // (mul X, 2^n+1) -> (add (X << n), X)
1288 // (mul X, 2^n-1) -> (rsb X, (X << n))
1289
1290
1291 //===----------------------------------------------------------------------===//
1292 //  Bitwise Instructions.
1293 //
1294
1295 defm AND   : AsI1_bin_irs<0b0000, "and",
1296                           BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
1297 defm ORR   : AsI1_bin_irs<0b1100, "orr",
1298                           BinOpFrag<(or  node:$LHS, node:$RHS)>, 1>;
1299 defm EOR   : AsI1_bin_irs<0b0001, "eor",
1300                           BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
1301 defm BIC   : AsI1_bin_irs<0b1110, "bic",
1302                           BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
1303
1304 def BFC    : I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm),
1305                AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iUNAsi,
1306                "bfc", "\t$dst, $imm", "$src = $dst",
1307                [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>,
1308                Requires<[IsARM, HasV6T2]> {
1309   let Inst{27-21} = 0b0111110;
1310   let Inst{6-0}   = 0b0011111;
1311 }
1312
1313 def  MVNr  : AsI1<0b1111, (outs GPR:$dst), (ins GPR:$src), DPFrm, IIC_iMOVr,
1314                   "mvn", "\t$dst, $src",
1315                   [(set GPR:$dst, (not GPR:$src))]>, UnaryDP {
1316   let Inst{25} = 0;
1317   let Inst{11-4} = 0b00000000;
1318 }
1319 def  MVNs  : AsI1<0b1111, (outs GPR:$dst), (ins so_reg:$src), DPSoRegFrm,
1320                   IIC_iMOVsr, "mvn", "\t$dst, $src",
1321                   [(set GPR:$dst, (not so_reg:$src))]>, UnaryDP {
1322   let Inst{25} = 0;
1323 }
1324 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
1325 def  MVNi  : AsI1<0b1111, (outs GPR:$dst), (ins so_imm:$imm), DPFrm, 
1326                   IIC_iMOVi, "mvn", "\t$dst, $imm",
1327                   [(set GPR:$dst, so_imm_not:$imm)]>,UnaryDP {
1328     let Inst{25} = 1;
1329 }
1330
1331 def : ARMPat<(and   GPR:$src, so_imm_not:$imm),
1332              (BICri GPR:$src, so_imm_not:$imm)>;
1333
1334 //===----------------------------------------------------------------------===//
1335 //  Multiply Instructions.
1336 //
1337
1338 let isCommutable = 1 in
1339 def MUL   : AsMul1I<0b0000000, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1340                    IIC_iMUL32, "mul", "\t$dst, $a, $b",
1341                    [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
1342
1343 def MLA   : AsMul1I<0b0000001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1344                     IIC_iMAC32, "mla", "\t$dst, $a, $b, $c",
1345                    [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
1346
1347 def MLS   : AMul1I<0b0000011, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1348                    IIC_iMAC32, "mls", "\t$dst, $a, $b, $c",
1349                    [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>,
1350                    Requires<[IsARM, HasV6T2]>;
1351
1352 // Extra precision multiplies with low / high results
1353 let neverHasSideEffects = 1 in {
1354 let isCommutable = 1 in {
1355 def SMULL : AsMul1I<0b0000110, (outs GPR:$ldst, GPR:$hdst),
1356                                (ins GPR:$a, GPR:$b), IIC_iMUL64,
1357                     "smull", "\t$ldst, $hdst, $a, $b", []>;
1358
1359 def UMULL : AsMul1I<0b0000100, (outs GPR:$ldst, GPR:$hdst),
1360                                (ins GPR:$a, GPR:$b), IIC_iMUL64,
1361                     "umull", "\t$ldst, $hdst, $a, $b", []>;
1362 }
1363
1364 // Multiply + accumulate
1365 def SMLAL : AsMul1I<0b0000111, (outs GPR:$ldst, GPR:$hdst),
1366                                (ins GPR:$a, GPR:$b), IIC_iMAC64,
1367                     "smlal", "\t$ldst, $hdst, $a, $b", []>;
1368
1369 def UMLAL : AsMul1I<0b0000101, (outs GPR:$ldst, GPR:$hdst),
1370                                (ins GPR:$a, GPR:$b), IIC_iMAC64,
1371                     "umlal", "\t$ldst, $hdst, $a, $b", []>;
1372
1373 def UMAAL : AMul1I <0b0000010, (outs GPR:$ldst, GPR:$hdst),
1374                                (ins GPR:$a, GPR:$b), IIC_iMAC64,
1375                     "umaal", "\t$ldst, $hdst, $a, $b", []>,
1376                     Requires<[IsARM, HasV6]>;
1377 } // neverHasSideEffects
1378
1379 // Most significant word multiply
1380 def SMMUL : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1381                IIC_iMUL32, "smmul", "\t$dst, $a, $b",
1382                [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>,
1383             Requires<[IsARM, HasV6]> {
1384   let Inst{7-4}   = 0b0001;
1385   let Inst{15-12} = 0b1111;
1386 }
1387
1388 def SMMLA : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1389                IIC_iMAC32, "smmla", "\t$dst, $a, $b, $c",
1390                [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>,
1391             Requires<[IsARM, HasV6]> {
1392   let Inst{7-4}   = 0b0001;
1393 }
1394
1395
1396 def SMMLS : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1397                IIC_iMAC32, "smmls", "\t$dst, $a, $b, $c",
1398                [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
1399             Requires<[IsARM, HasV6]> {
1400   let Inst{7-4}   = 0b1101;
1401 }
1402
1403 multiclass AI_smul<string opc, PatFrag opnode> {
1404   def BB : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1405               IIC_iMUL32, !strconcat(opc, "bb"), "\t$dst, $a, $b",
1406               [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1407                                       (sext_inreg GPR:$b, i16)))]>,
1408            Requires<[IsARM, HasV5TE]> {
1409              let Inst{5} = 0;
1410              let Inst{6} = 0;
1411            }
1412
1413   def BT : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1414               IIC_iMUL32, !strconcat(opc, "bt"), "\t$dst, $a, $b",
1415               [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1416                                       (sra GPR:$b, (i32 16))))]>,
1417            Requires<[IsARM, HasV5TE]> {
1418              let Inst{5} = 0;
1419              let Inst{6} = 1;
1420            }
1421
1422   def TB : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1423               IIC_iMUL32, !strconcat(opc, "tb"), "\t$dst, $a, $b",
1424               [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
1425                                       (sext_inreg GPR:$b, i16)))]>,
1426            Requires<[IsARM, HasV5TE]> {
1427              let Inst{5} = 1;
1428              let Inst{6} = 0;
1429            }
1430
1431   def TT : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1432               IIC_iMUL32, !strconcat(opc, "tt"), "\t$dst, $a, $b",
1433               [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
1434                                       (sra GPR:$b, (i32 16))))]>,
1435             Requires<[IsARM, HasV5TE]> {
1436              let Inst{5} = 1;
1437              let Inst{6} = 1;
1438            }
1439
1440   def WB : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1441               IIC_iMUL16, !strconcat(opc, "wb"), "\t$dst, $a, $b",
1442               [(set GPR:$dst, (sra (opnode GPR:$a,
1443                                     (sext_inreg GPR:$b, i16)), (i32 16)))]>,
1444            Requires<[IsARM, HasV5TE]> {
1445              let Inst{5} = 1;
1446              let Inst{6} = 0;
1447            }
1448
1449   def WT : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1450               IIC_iMUL16, !strconcat(opc, "wt"), "\t$dst, $a, $b",
1451               [(set GPR:$dst, (sra (opnode GPR:$a,
1452                                     (sra GPR:$b, (i32 16))), (i32 16)))]>,
1453             Requires<[IsARM, HasV5TE]> {
1454              let Inst{5} = 1;
1455              let Inst{6} = 1;
1456            }
1457 }
1458
1459
1460 multiclass AI_smla<string opc, PatFrag opnode> {
1461   def BB : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1462               IIC_iMAC16, !strconcat(opc, "bb"), "\t$dst, $a, $b, $acc",
1463               [(set GPR:$dst, (add GPR:$acc,
1464                                (opnode (sext_inreg GPR:$a, i16),
1465                                        (sext_inreg GPR:$b, i16))))]>,
1466            Requires<[IsARM, HasV5TE]> {
1467              let Inst{5} = 0;
1468              let Inst{6} = 0;
1469            }
1470
1471   def BT : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1472               IIC_iMAC16, !strconcat(opc, "bt"), "\t$dst, $a, $b, $acc",
1473               [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
1474                                                      (sra GPR:$b, (i32 16)))))]>,
1475            Requires<[IsARM, HasV5TE]> {
1476              let Inst{5} = 0;
1477              let Inst{6} = 1;
1478            }
1479
1480   def TB : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1481               IIC_iMAC16, !strconcat(opc, "tb"), "\t$dst, $a, $b, $acc",
1482               [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
1483                                                  (sext_inreg GPR:$b, i16))))]>,
1484            Requires<[IsARM, HasV5TE]> {
1485              let Inst{5} = 1;
1486              let Inst{6} = 0;
1487            }
1488
1489   def TT : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1490               IIC_iMAC16, !strconcat(opc, "tt"), "\t$dst, $a, $b, $acc",
1491              [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
1492                                                     (sra GPR:$b, (i32 16)))))]>,
1493             Requires<[IsARM, HasV5TE]> {
1494              let Inst{5} = 1;
1495              let Inst{6} = 1;
1496            }
1497
1498   def WB : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1499               IIC_iMAC16, !strconcat(opc, "wb"), "\t$dst, $a, $b, $acc",
1500               [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1501                                        (sext_inreg GPR:$b, i16)), (i32 16))))]>,
1502            Requires<[IsARM, HasV5TE]> {
1503              let Inst{5} = 0;
1504              let Inst{6} = 0;
1505            }
1506
1507   def WT : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1508               IIC_iMAC16, !strconcat(opc, "wt"), "\t$dst, $a, $b, $acc",
1509               [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1510                                          (sra GPR:$b, (i32 16))), (i32 16))))]>,
1511             Requires<[IsARM, HasV5TE]> {
1512              let Inst{5} = 0;
1513              let Inst{6} = 1;
1514            }
1515 }
1516
1517 defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1518 defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1519
1520 // TODO: Halfword multiple accumulate long: SMLAL<x><y>
1521 // TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
1522
1523 //===----------------------------------------------------------------------===//
1524 //  Misc. Arithmetic Instructions.
1525 //
1526
1527 def CLZ  : AMiscA1I<0b000010110, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
1528               "clz", "\t$dst, $src",
1529               [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]> {
1530   let Inst{7-4}   = 0b0001;
1531   let Inst{11-8}  = 0b1111;
1532   let Inst{19-16} = 0b1111;
1533 }
1534
1535 def RBIT : AMiscA1I<0b01101111, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
1536               "rbit", "\t$dst, $src",
1537               [(set GPR:$dst, (ARMrbit GPR:$src))]>,
1538            Requires<[IsARM, HasV6T2]> {
1539   let Inst{7-4}   = 0b0011;
1540   let Inst{11-8}  = 0b1111;
1541   let Inst{19-16} = 0b1111;
1542 }
1543
1544 def REV  : AMiscA1I<0b01101011, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
1545               "rev", "\t$dst, $src",
1546               [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]> {
1547   let Inst{7-4}   = 0b0011;
1548   let Inst{11-8}  = 0b1111;
1549   let Inst{19-16} = 0b1111;
1550 }
1551
1552 def REV16 : AMiscA1I<0b01101011, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
1553                "rev16", "\t$dst, $src",
1554                [(set GPR:$dst,
1555                    (or (and (srl GPR:$src, (i32 8)), 0xFF),
1556                        (or (and (shl GPR:$src, (i32 8)), 0xFF00),
1557                            (or (and (srl GPR:$src, (i32 8)), 0xFF0000),
1558                                (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>,
1559                Requires<[IsARM, HasV6]> {
1560   let Inst{7-4}   = 0b1011;
1561   let Inst{11-8}  = 0b1111;
1562   let Inst{19-16} = 0b1111;
1563 }
1564
1565 def REVSH : AMiscA1I<0b01101111, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
1566                "revsh", "\t$dst, $src",
1567                [(set GPR:$dst,
1568                   (sext_inreg
1569                     (or (srl (and GPR:$src, 0xFF00), (i32 8)),
1570                         (shl GPR:$src, (i32 8))), i16))]>,
1571                Requires<[IsARM, HasV6]> {
1572   let Inst{7-4}   = 0b1011;
1573   let Inst{11-8}  = 0b1111;
1574   let Inst{19-16} = 0b1111;
1575 }
1576
1577 def PKHBT : AMiscA1I<0b01101000, (outs GPR:$dst),
1578                                  (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1579                IIC_iALUsi, "pkhbt", "\t$dst, $src1, $src2, LSL $shamt",
1580                [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1581                                    (and (shl GPR:$src2, (i32 imm:$shamt)),
1582                                         0xFFFF0000)))]>,
1583                Requires<[IsARM, HasV6]> {
1584   let Inst{6-4} = 0b001;
1585 }
1586
1587 // Alternate cases for PKHBT where identities eliminate some nodes.
1588 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1589                (PKHBT GPR:$src1, GPR:$src2, 0)>;
1590 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1591                (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
1592
1593
1594 def PKHTB : AMiscA1I<0b01101000, (outs GPR:$dst),
1595                                  (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1596                IIC_iALUsi, "pkhtb", "\t$dst, $src1, $src2, ASR $shamt",
1597                [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1598                                    (and (sra GPR:$src2, imm16_31:$shamt),
1599                                         0xFFFF)))]>, Requires<[IsARM, HasV6]> {
1600   let Inst{6-4} = 0b101;
1601 }
1602
1603 // Alternate cases for PKHTB where identities eliminate some nodes.  Note that
1604 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
1605 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, (i32 16))),
1606                (PKHTB GPR:$src1, GPR:$src2, 16)>;
1607 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1608                    (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1609                (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1610
1611 //===----------------------------------------------------------------------===//
1612 //  Comparison Instructions...
1613 //
1614
1615 defm CMP  : AI1_cmp_irs<0b1010, "cmp",
1616                         BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1617 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
1618 //       Compare-to-zero still works out, just not the relationals
1619 //defm CMN  : AI1_cmp_irs<0b1011, "cmn",
1620 //                        BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
1621
1622 // Note that TST/TEQ don't set all the same flags that CMP does!
1623 defm TST  : AI1_cmp_irs<0b1000, "tst",
1624                         BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>, 1>;
1625 defm TEQ  : AI1_cmp_irs<0b1001, "teq",
1626                         BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>, 1>;
1627
1628 defm CMPz  : AI1_cmp_irs<0b1010, "cmp",
1629                          BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
1630 defm CMNz  : AI1_cmp_irs<0b1011, "cmn",
1631                          BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
1632
1633 //def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1634 //             (CMNri  GPR:$src, so_imm_neg:$imm)>;
1635
1636 def : ARMPat<(ARMcmpZ GPR:$src, so_imm_neg:$imm),
1637              (CMNzri  GPR:$src, so_imm_neg:$imm)>;
1638
1639
1640 // Conditional moves
1641 // FIXME: should be able to write a pattern for ARMcmov, but can't use
1642 // a two-value operand where a dag node expects two operands. :( 
1643 def MOVCCr : AI1<0b1101, (outs GPR:$dst), (ins GPR:$false, GPR:$true), DPFrm,
1644                 IIC_iCMOVr, "mov", "\t$dst, $true",
1645       [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1646                 RegConstraint<"$false = $dst">, UnaryDP {
1647   let Inst{11-4} = 0b00000000;
1648   let Inst{25} = 0;
1649 }
1650
1651 def MOVCCs : AI1<0b1101, (outs GPR:$dst),
1652                         (ins GPR:$false, so_reg:$true), DPSoRegFrm, IIC_iCMOVsr,
1653                 "mov", "\t$dst, $true",
1654    [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1655                 RegConstraint<"$false = $dst">, UnaryDP {
1656   let Inst{25} = 0;
1657 }
1658
1659 def MOVCCi : AI1<0b1101, (outs GPR:$dst),
1660                         (ins GPR:$false, so_imm:$true), DPFrm, IIC_iCMOVi,
1661                 "mov", "\t$dst, $true",
1662    [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1663                 RegConstraint<"$false = $dst">, UnaryDP {
1664   let Inst{25} = 1;
1665 }
1666
1667 //===----------------------------------------------------------------------===//
1668 // Atomic operations intrinsics
1669 //
1670
1671 // memory barriers protect the atomic sequences
1672 let hasSideEffects = 1 in {
1673 def Int_MemBarrierV7 : AInoP<(outs), (ins),
1674                         Pseudo, NoItinerary,
1675                         "dmb", "",
1676                         [(ARMMemBarrierV7)]>,
1677                         Requires<[IsARM, HasV7]> {
1678   let Inst{31-4} = 0xf57ff05;
1679   // FIXME: add support for options other than a full system DMB
1680   let Inst{3-0} = 0b1111;
1681 }
1682
1683 def Int_SyncBarrierV7 : AInoP<(outs), (ins),
1684                         Pseudo, NoItinerary,
1685                         "dsb", "",
1686                         [(ARMSyncBarrierV7)]>,
1687                         Requires<[IsARM, HasV7]> {
1688   let Inst{31-4} = 0xf57ff04;
1689   // FIXME: add support for options other than a full system DSB
1690   let Inst{3-0} = 0b1111;
1691 }
1692
1693 def Int_MemBarrierV6 : AInoP<(outs), (ins GPR:$zero),
1694                        Pseudo, NoItinerary,
1695                        "mcr", "\tp15, 0, $zero, c7, c10, 5",
1696                        [(ARMMemBarrierV6 GPR:$zero)]>,
1697                        Requires<[IsARM, HasV6]> {
1698   // FIXME: add support for options other than a full system DMB
1699   // FIXME: add encoding
1700 }
1701
1702 def Int_SyncBarrierV6 : AInoP<(outs), (ins GPR:$zero),
1703                         Pseudo, NoItinerary,
1704                         "mcr", "\tp15, 0, $zero, c7, c10, 4",
1705                         [(ARMSyncBarrierV6 GPR:$zero)]>,
1706                         Requires<[IsARM, HasV6]> {
1707   // FIXME: add support for options other than a full system DSB
1708   // FIXME: add encoding
1709 }
1710 }
1711
1712 let usesCustomInserter = 1 in {
1713   let Uses = [CPSR] in {
1714     def ATOMIC_LOAD_ADD_I8 : PseudoInst<
1715       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1716       "${:comment} ATOMIC_LOAD_ADD_I8 PSEUDO!",
1717       [(set GPR:$dst, (atomic_load_add_8 GPR:$ptr, GPR:$incr))]>;
1718     def ATOMIC_LOAD_SUB_I8 : PseudoInst<
1719       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1720       "${:comment} ATOMIC_LOAD_SUB_I8 PSEUDO!",
1721       [(set GPR:$dst, (atomic_load_sub_8 GPR:$ptr, GPR:$incr))]>;
1722     def ATOMIC_LOAD_AND_I8 : PseudoInst<
1723       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1724       "${:comment} ATOMIC_LOAD_AND_I8 PSEUDO!",
1725       [(set GPR:$dst, (atomic_load_and_8 GPR:$ptr, GPR:$incr))]>;
1726     def ATOMIC_LOAD_OR_I8 : PseudoInst<
1727       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1728       "${:comment} ATOMIC_LOAD_OR_I8 PSEUDO!",
1729       [(set GPR:$dst, (atomic_load_or_8 GPR:$ptr, GPR:$incr))]>;
1730     def ATOMIC_LOAD_XOR_I8 : PseudoInst<
1731       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1732       "${:comment} ATOMIC_LOAD_XOR_I8 PSEUDO!",
1733       [(set GPR:$dst, (atomic_load_xor_8 GPR:$ptr, GPR:$incr))]>;
1734     def ATOMIC_LOAD_NAND_I8 : PseudoInst<
1735       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1736       "${:comment} ATOMIC_LOAD_NAND_I8 PSEUDO!",
1737       [(set GPR:$dst, (atomic_load_nand_8 GPR:$ptr, GPR:$incr))]>;
1738     def ATOMIC_LOAD_ADD_I16 : PseudoInst<
1739       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1740       "${:comment} ATOMIC_LOAD_ADD_I16 PSEUDO!",
1741       [(set GPR:$dst, (atomic_load_add_16 GPR:$ptr, GPR:$incr))]>;
1742     def ATOMIC_LOAD_SUB_I16 : PseudoInst<
1743       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1744       "${:comment} ATOMIC_LOAD_SUB_I16 PSEUDO!",
1745       [(set GPR:$dst, (atomic_load_sub_16 GPR:$ptr, GPR:$incr))]>;
1746     def ATOMIC_LOAD_AND_I16 : PseudoInst<
1747       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1748       "${:comment} ATOMIC_LOAD_AND_I16 PSEUDO!",
1749       [(set GPR:$dst, (atomic_load_and_16 GPR:$ptr, GPR:$incr))]>;
1750     def ATOMIC_LOAD_OR_I16 : PseudoInst<
1751       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1752       "${:comment} ATOMIC_LOAD_OR_I16 PSEUDO!",
1753       [(set GPR:$dst, (atomic_load_or_16 GPR:$ptr, GPR:$incr))]>;
1754     def ATOMIC_LOAD_XOR_I16 : PseudoInst<
1755       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1756       "${:comment} ATOMIC_LOAD_XOR_I16 PSEUDO!",
1757       [(set GPR:$dst, (atomic_load_xor_16 GPR:$ptr, GPR:$incr))]>;
1758     def ATOMIC_LOAD_NAND_I16 : PseudoInst<
1759       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1760       "${:comment} ATOMIC_LOAD_NAND_I16 PSEUDO!",
1761       [(set GPR:$dst, (atomic_load_nand_16 GPR:$ptr, GPR:$incr))]>;
1762     def ATOMIC_LOAD_ADD_I32 : PseudoInst<
1763       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1764       "${:comment} ATOMIC_LOAD_ADD_I32 PSEUDO!",
1765       [(set GPR:$dst, (atomic_load_add_32 GPR:$ptr, GPR:$incr))]>;
1766     def ATOMIC_LOAD_SUB_I32 : PseudoInst<
1767       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1768       "${:comment} ATOMIC_LOAD_SUB_I32 PSEUDO!",
1769       [(set GPR:$dst, (atomic_load_sub_32 GPR:$ptr, GPR:$incr))]>;
1770     def ATOMIC_LOAD_AND_I32 : PseudoInst<
1771       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1772       "${:comment} ATOMIC_LOAD_AND_I32 PSEUDO!",
1773       [(set GPR:$dst, (atomic_load_and_32 GPR:$ptr, GPR:$incr))]>;
1774     def ATOMIC_LOAD_OR_I32 : PseudoInst<
1775       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1776       "${:comment} ATOMIC_LOAD_OR_I32 PSEUDO!",
1777       [(set GPR:$dst, (atomic_load_or_32 GPR:$ptr, GPR:$incr))]>;
1778     def ATOMIC_LOAD_XOR_I32 : PseudoInst<
1779       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1780       "${:comment} ATOMIC_LOAD_XOR_I32 PSEUDO!",
1781       [(set GPR:$dst, (atomic_load_xor_32 GPR:$ptr, GPR:$incr))]>;
1782     def ATOMIC_LOAD_NAND_I32 : PseudoInst<
1783       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1784       "${:comment} ATOMIC_LOAD_NAND_I32 PSEUDO!",
1785       [(set GPR:$dst, (atomic_load_nand_32 GPR:$ptr, GPR:$incr))]>;
1786
1787     def ATOMIC_SWAP_I8 : PseudoInst<
1788       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
1789       "${:comment} ATOMIC_SWAP_I8 PSEUDO!",
1790       [(set GPR:$dst, (atomic_swap_8 GPR:$ptr, GPR:$new))]>;
1791     def ATOMIC_SWAP_I16 : PseudoInst<
1792       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
1793       "${:comment} ATOMIC_SWAP_I16 PSEUDO!",
1794       [(set GPR:$dst, (atomic_swap_16 GPR:$ptr, GPR:$new))]>;
1795     def ATOMIC_SWAP_I32 : PseudoInst<
1796       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
1797       "${:comment} ATOMIC_SWAP_I32 PSEUDO!",
1798       [(set GPR:$dst, (atomic_swap_32 GPR:$ptr, GPR:$new))]>;
1799
1800     def ATOMIC_CMP_SWAP_I8 : PseudoInst<
1801       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
1802       "${:comment} ATOMIC_CMP_SWAP_I8 PSEUDO!",
1803       [(set GPR:$dst, (atomic_cmp_swap_8 GPR:$ptr, GPR:$old, GPR:$new))]>;
1804     def ATOMIC_CMP_SWAP_I16 : PseudoInst<
1805       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
1806       "${:comment} ATOMIC_CMP_SWAP_I16 PSEUDO!",
1807       [(set GPR:$dst, (atomic_cmp_swap_16 GPR:$ptr, GPR:$old, GPR:$new))]>;
1808     def ATOMIC_CMP_SWAP_I32 : PseudoInst<
1809       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
1810       "${:comment} ATOMIC_CMP_SWAP_I32 PSEUDO!",
1811       [(set GPR:$dst, (atomic_cmp_swap_32 GPR:$ptr, GPR:$old, GPR:$new))]>;
1812 }
1813 }
1814
1815 let mayLoad = 1 in {
1816 def LDREXB : AIldrex<0b10, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
1817                     "ldrexb", "\t$dest, [$ptr]",
1818                     []>;
1819 def LDREXH : AIldrex<0b11, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
1820                     "ldrexh", "\t$dest, [$ptr]",
1821                     []>;
1822 def LDREX  : AIldrex<0b00, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
1823                     "ldrex", "\t$dest, [$ptr]",
1824                     []>;
1825 def LDREXD : AIldrex<0b01, (outs GPR:$dest, GPR:$dest2), (ins GPR:$ptr),
1826                     NoItinerary,
1827                     "ldrexd", "\t$dest, $dest2, [$ptr]",
1828                     []>;
1829 }
1830
1831 let mayStore = 1, Constraints = "@earlyclobber $success" in {
1832 def STREXB : AIstrex<0b10, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
1833                     NoItinerary,
1834                     "strexb", "\t$success, $src, [$ptr]",
1835                     []>;
1836 def STREXH : AIstrex<0b11, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
1837                     NoItinerary,
1838                     "strexh", "\t$success, $src, [$ptr]",
1839                     []>;
1840 def STREX  : AIstrex<0b00, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
1841                     NoItinerary,
1842                     "strex", "\t$success, $src, [$ptr]",
1843                     []>;
1844 def STREXD : AIstrex<0b01, (outs GPR:$success),
1845                     (ins GPR:$src, GPR:$src2, GPR:$ptr),
1846                     NoItinerary,
1847                     "strexd", "\t$success, $src, $src2, [$ptr]",
1848                     []>;
1849 }
1850
1851 //===----------------------------------------------------------------------===//
1852 // TLS Instructions
1853 //
1854
1855 // __aeabi_read_tp preserves the registers r1-r3.
1856 let isCall = 1,
1857   Defs = [R0, R12, LR, CPSR] in {
1858   def TPsoft : ABXI<0b1011, (outs), (ins), IIC_Br,
1859                "bl\t__aeabi_read_tp",
1860                [(set R0, ARMthread_pointer)]>;
1861 }
1862
1863 //===----------------------------------------------------------------------===//
1864 // SJLJ Exception handling intrinsics
1865 //   eh_sjlj_setjmp() is an instruction sequence to store the return
1866 //   address and save #0 in R0 for the non-longjmp case.
1867 //   Since by its nature we may be coming from some other function to get
1868 //   here, and we're using the stack frame for the containing function to
1869 //   save/restore registers, we can't keep anything live in regs across
1870 //   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
1871 //   when we get here from a longjmp(). We force everthing out of registers
1872 //   except for our own input by listing the relevant registers in Defs. By
1873 //   doing so, we also cause the prologue/epilogue code to actively preserve
1874 //   all of the callee-saved resgisters, which is exactly what we want.
1875 //   A constant value is passed in $val, and we use the location as a scratch.
1876 let Defs =
1877   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR,  D0,
1878     D1,  D2,  D3,  D4,  D5,  D6,  D7,  D8,  D9,  D10, D11, D12, D13, D14, D15,
1879     D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30,
1880     D31 ] in {
1881   def Int_eh_sjlj_setjmp : XI<(outs), (ins GPR:$src, GPR:$val),
1882                                AddrModeNone, SizeSpecial, IndexModeNone,
1883                                Pseudo, NoItinerary,
1884                                "str\tsp, [$src, #+8] @ eh_setjmp begin\n\t"
1885                                "add\t$val, pc, #8\n\t"
1886                                "str\t$val, [$src, #+4]\n\t"
1887                                "mov\tr0, #0\n\t"
1888                                "add\tpc, pc, #0\n\t"
1889                                "mov\tr0, #1 @ eh_setjmp end", "",
1890                          [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>;
1891 }
1892
1893 //===----------------------------------------------------------------------===//
1894 // Non-Instruction Patterns
1895 //
1896
1897 // Large immediate handling.
1898
1899 // Two piece so_imms.
1900 let isReMaterializable = 1 in
1901 def MOVi2pieces : AI1x2<(outs GPR:$dst), (ins so_imm2part:$src), 
1902                          Pseudo, IIC_iMOVi,
1903                          "mov", "\t$dst, $src",
1904                          [(set GPR:$dst, so_imm2part:$src)]>,
1905                   Requires<[IsARM, NoV6T2]>;
1906
1907 def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1908              (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1909                     (so_imm2part_2 imm:$RHS))>;
1910 def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1911              (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1912                     (so_imm2part_2 imm:$RHS))>;
1913 def : ARMPat<(add GPR:$LHS, so_imm2part:$RHS),
1914              (ADDri (ADDri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1915                     (so_imm2part_2 imm:$RHS))>;
1916 def : ARMPat<(add GPR:$LHS, so_neg_imm2part:$RHS),
1917              (SUBri (SUBri GPR:$LHS, (so_neg_imm2part_1 imm:$RHS)),
1918                     (so_neg_imm2part_2 imm:$RHS))>;
1919
1920 // 32-bit immediate using movw + movt.
1921 // This is a single pseudo instruction, the benefit is that it can be remat'd
1922 // as a single unit instead of having to handle reg inputs.
1923 // FIXME: Remove this when we can do generalized remat.
1924 let isReMaterializable = 1 in
1925 def MOVi32imm : AI1x2<(outs GPR:$dst), (ins i32imm:$src), Pseudo, IIC_iMOVi,
1926                     "movw", "\t$dst, ${src:lo16}\n\tmovt${p}\t$dst, ${src:hi16}",
1927                      [(set GPR:$dst, (i32 imm:$src))]>,
1928                Requires<[IsARM, HasV6T2]>;
1929
1930 // ConstantPool, GlobalAddress, and JumpTable
1931 def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>,
1932             Requires<[IsARM, DontUseMovt]>;
1933 def : ARMPat<(ARMWrapper  tconstpool  :$dst), (LEApcrel tconstpool  :$dst)>;
1934 def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (MOVi32imm tglobaladdr :$dst)>,
1935             Requires<[IsARM, UseMovt]>;
1936 def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1937              (LEApcrelJT tjumptable:$dst, imm:$id)>;
1938
1939 // TODO: add,sub,and, 3-instr forms?
1940
1941
1942 // Direct calls
1943 def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>,
1944       Requires<[IsARM, IsNotDarwin]>;
1945 def : ARMPat<(ARMcall texternalsym:$func), (BLr9 texternalsym:$func)>,
1946       Requires<[IsARM, IsDarwin]>;
1947
1948 // zextload i1 -> zextload i8
1949 def : ARMPat<(zextloadi1 addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1950
1951 // extload -> zextload
1952 def : ARMPat<(extloadi1  addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1953 def : ARMPat<(extloadi8  addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1954 def : ARMPat<(extloadi16 addrmode3:$addr),  (LDRH addrmode3:$addr)>;
1955
1956 def : ARMPat<(extloadi8  addrmodepc:$addr), (PICLDRB addrmodepc:$addr)>;
1957 def : ARMPat<(extloadi16 addrmodepc:$addr), (PICLDRH addrmodepc:$addr)>;
1958
1959 // smul* and smla*
1960 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1961                       (sra (shl GPR:$b, (i32 16)), (i32 16))),
1962                  (SMULBB GPR:$a, GPR:$b)>;
1963 def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1964                  (SMULBB GPR:$a, GPR:$b)>;
1965 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1966                       (sra GPR:$b, (i32 16))),
1967                  (SMULBT GPR:$a, GPR:$b)>;
1968 def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, (i32 16))),
1969                  (SMULBT GPR:$a, GPR:$b)>;
1970 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)),
1971                       (sra (shl GPR:$b, (i32 16)), (i32 16))),
1972                  (SMULTB GPR:$a, GPR:$b)>;
1973 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)), sext_16_node:$b),
1974                 (SMULTB GPR:$a, GPR:$b)>;
1975 def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
1976                       (i32 16)),
1977                  (SMULWB GPR:$a, GPR:$b)>;
1978 def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), (i32 16)),
1979                  (SMULWB GPR:$a, GPR:$b)>;
1980
1981 def : ARMV5TEPat<(add GPR:$acc,
1982                       (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1983                            (sra (shl GPR:$b, (i32 16)), (i32 16)))),
1984                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1985 def : ARMV5TEPat<(add GPR:$acc,
1986                       (mul sext_16_node:$a, sext_16_node:$b)),
1987                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1988 def : ARMV5TEPat<(add GPR:$acc,
1989                       (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1990                            (sra GPR:$b, (i32 16)))),
1991                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1992 def : ARMV5TEPat<(add GPR:$acc,
1993                       (mul sext_16_node:$a, (sra GPR:$b, (i32 16)))),
1994                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1995 def : ARMV5TEPat<(add GPR:$acc,
1996                       (mul (sra GPR:$a, (i32 16)),
1997                            (sra (shl GPR:$b, (i32 16)), (i32 16)))),
1998                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1999 def : ARMV5TEPat<(add GPR:$acc,
2000                       (mul (sra GPR:$a, (i32 16)), sext_16_node:$b)),
2001                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
2002 def : ARMV5TEPat<(add GPR:$acc,
2003                       (sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
2004                            (i32 16))),
2005                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
2006 def : ARMV5TEPat<(add GPR:$acc,
2007                       (sra (mul GPR:$a, sext_16_node:$b), (i32 16))),
2008                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
2009
2010 //===----------------------------------------------------------------------===//
2011 // Thumb Support
2012 //
2013
2014 include "ARMInstrThumb.td"
2015
2016 //===----------------------------------------------------------------------===//
2017 // Thumb2 Support
2018 //
2019
2020 include "ARMInstrThumb2.td"
2021
2022 //===----------------------------------------------------------------------===//
2023 // Floating Point Support
2024 //
2025
2026 include "ARMInstrVFP.td"
2027
2028 //===----------------------------------------------------------------------===//
2029 // Advanced SIMD (NEON) Support
2030 //
2031
2032 include "ARMInstrNEON.td"
2033
2034 //===----------------------------------------------------------------------===//
2035 // Coprocessor Instructions.  For disassembly only.
2036 //
2037
2038 def CDP : ABI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
2039             nohash_imm:$CRd, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
2040             NoItinerary, "cdp", "\tp$cop, $opc1, cr$CRd, cr$CRn, cr$CRm, $opc2",
2041               [/* For disassembly only; pattern left blank */]> {
2042   let Inst{4} = 0;
2043 }
2044
2045 def CDP2 : ABXI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
2046                nohash_imm:$CRd, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
2047                NoItinerary, "cdp2\tp$cop, $opc1, cr$CRd, cr$CRn, cr$CRm, $opc2",
2048                [/* For disassembly only; pattern left blank */]> {
2049   let Inst{31-28} = 0b1111;
2050   let Inst{4} = 0;
2051 }
2052
2053 def MCR : ABI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
2054               GPR:$Rt, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
2055               NoItinerary, "mcr", "\tp$cop, $opc1, $Rt, cr$CRn, cr$CRm, $opc2",
2056               [/* For disassembly only; pattern left blank */]> {
2057   let Inst{20} = 0;
2058   let Inst{4} = 1;
2059 }
2060
2061 def MCR2 : ABXI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
2062                 GPR:$Rt, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
2063                 NoItinerary, "mcr2\tp$cop, $opc1, $Rt, cr$CRn, cr$CRm, $opc2",
2064                 [/* For disassembly only; pattern left blank */]> {
2065   let Inst{31-28} = 0b1111;
2066   let Inst{20} = 0;
2067   let Inst{4} = 1;
2068 }
2069
2070 def MRC : ABI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
2071               GPR:$Rt, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
2072               NoItinerary, "mrc", "\tp$cop, $opc1, $Rt, cr$CRn, cr$CRm, $opc2",
2073               [/* For disassembly only; pattern left blank */]> {
2074   let Inst{20} = 1;
2075   let Inst{4} = 1;
2076 }
2077
2078 def MRC2 : ABXI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
2079                 GPR:$Rt, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
2080                 NoItinerary, "mrc2\tp$cop, $opc1, $Rt, cr$CRn, cr$CRm, $opc2",
2081                 [/* For disassembly only; pattern left blank */]> {
2082   let Inst{31-28} = 0b1111;
2083   let Inst{20} = 1;
2084   let Inst{4} = 1;
2085 }
2086
2087 def MCRR : ABI<0b1100, (outs), (ins nohash_imm:$cop, i32imm:$opc,
2088                GPR:$Rt, GPR:$Rt2, nohash_imm:$CRm),
2089                NoItinerary, "mcrr", "\tp$cop, $opc, $Rt, $Rt2, cr$CRm",
2090                [/* For disassembly only; pattern left blank */]> {
2091   let Inst{23-20} = 0b0100;
2092 }
2093
2094 def MCRR2 : ABXI<0b1100, (outs), (ins nohash_imm:$cop, i32imm:$opc,
2095                  GPR:$Rt, GPR:$Rt2, nohash_imm:$CRm),
2096                  NoItinerary, "mcrr2\tp$cop, $opc, $Rt, $Rt2, cr$CRm",
2097                  [/* For disassembly only; pattern left blank */]> {
2098   let Inst{31-28} = 0b1111;
2099   let Inst{23-20} = 0b0100;
2100 }
2101
2102 def MRRC : ABI<0b1100, (outs), (ins nohash_imm:$cop, i32imm:$opc,
2103                GPR:$Rt, GPR:$Rt2, nohash_imm:$CRm),
2104                NoItinerary, "mrrc", "\tp$cop, $opc, $Rt, $Rt2, cr$CRm",
2105                [/* For disassembly only; pattern left blank */]> {
2106   let Inst{23-20} = 0b0101;
2107 }
2108
2109 def MRRC2 : ABXI<0b1100, (outs), (ins nohash_imm:$cop, i32imm:$opc,
2110                  GPR:$Rt, GPR:$Rt2, nohash_imm:$CRm),
2111                  NoItinerary, "mrrc2\tp$cop, $opc, $Rt, $Rt2, cr$CRm",
2112                  [/* For disassembly only; pattern left blank */]> {
2113   let Inst{31-28} = 0b1111;
2114   let Inst{23-20} = 0b0101;
2115 }
2116