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