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