Fix naming inconsistencies.
[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 was developed by the "Instituto Nokia de Tecnologia" and
6 // is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This file describes the ARM instructions in TableGen format.
12 //
13 //===----------------------------------------------------------------------===//
14
15 //===----------------------------------------------------------------------===//
16 // ARM specific DAG Nodes.
17 //
18
19 // Type profiles.
20 def SDT_ARMCallSeq : SDTypeProfile<0, 1, [ SDTCisVT<0, 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 // Node definitions.
43 def ARMWrapper       : SDNode<"ARMISD::Wrapper",     SDTIntUnaryOp>;
44 def ARMWrapperJT     : SDNode<"ARMISD::WrapperJT",   SDTIntBinOp>;
45
46 def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeq,
47                               [SDNPHasChain, SDNPOutFlag]>;
48 def ARMcallseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_ARMCallSeq,
49                               [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
50
51 def ARMcall          : SDNode<"ARMISD::CALL", SDT_ARMcall,
52                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
53 def ARMcall_nolink   : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
54                               [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
55
56 def ARMretflag       : SDNode<"ARMISD::RET_FLAG", SDTRet,
57                               [SDNPHasChain, SDNPOptInFlag]>;
58
59 def ARMcmov          : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
60                               [SDNPInFlag]>;
61 def ARMcneg          : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
62                               [SDNPInFlag]>;
63
64 def ARMbrcond        : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
65                               [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
66
67 def ARMbrjt          : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
68                               [SDNPHasChain]>;
69
70 def ARMcmp           : SDNode<"ARMISD::CMP", SDT_ARMCmp,
71                               [SDNPOutFlag]>;
72
73 def ARMpic_add       : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
74
75 def ARMsrl_flag      : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
76 def ARMsra_flag      : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
77 def ARMrrx           : SDNode<"ARMISD::RRX"     , SDTIntUnaryOp, [SDNPInFlag ]>;
78
79 //===----------------------------------------------------------------------===//
80 // ARM Instruction Predicate Definitions.
81 //
82 def HasV5T  : Predicate<"Subtarget->hasV5TOps()">;
83 def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">;
84 def HasV6   : Predicate<"Subtarget->hasV6Ops()">;
85 def IsThumb : Predicate<"Subtarget->isThumb()">;
86 def IsARM   : Predicate<"!Subtarget->isThumb()">;
87
88 //===----------------------------------------------------------------------===//
89 // ARM Flag Definitions.
90
91 class RegConstraint<string C> {
92   string Constraints = C;
93 }
94
95 //===----------------------------------------------------------------------===//
96 //  ARM specific transformation functions and pattern fragments.
97 //
98
99 // so_imm_XFORM - Return a so_imm value packed into the format described for
100 // so_imm def below.
101 def so_imm_XFORM : SDNodeXForm<imm, [{
102   return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(N->getValue()),
103                                    MVT::i32);
104 }]>;
105
106 // so_imm_neg_XFORM - Return a so_imm value packed into the format described for
107 // so_imm_neg def below.
108 def so_imm_neg_XFORM : SDNodeXForm<imm, [{
109   return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(-(int)N->getValue()),
110                                    MVT::i32);
111 }]>;
112
113 // so_imm_not_XFORM - Return a so_imm value packed into the format described for
114 // so_imm_not def below.
115 def so_imm_not_XFORM : SDNodeXForm<imm, [{
116   return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(~(int)N->getValue()),
117                                    MVT::i32);
118 }]>;
119
120 // rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
121 def rot_imm : PatLeaf<(i32 imm), [{
122   int32_t v = (int32_t)N->getValue();
123   return v == 8 || v == 16 || v == 24;
124 }]>;
125
126 /// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
127 def imm1_15 : PatLeaf<(i32 imm), [{
128   return (int32_t)N->getValue() >= 1 && (int32_t)N->getValue() < 16;
129 }]>;
130
131 /// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
132 def imm16_31 : PatLeaf<(i32 imm), [{
133   return (int32_t)N->getValue() >= 16 && (int32_t)N->getValue() < 32;
134 }]>;
135
136 def so_imm_neg : 
137   PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(-(int)N->getValue()) != -1; }],
138           so_imm_neg_XFORM>;
139
140 def so_imm_not :
141   PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(~(int)N->getValue()) != -1; }],
142           so_imm_not_XFORM>;
143
144 // sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
145 def sext_16_node : PatLeaf<(i32 GPR:$a), [{
146   return TLI.ComputeNumSignBits(SDOperand(N,0)) >= 17;
147 }]>;
148
149
150 // Break so_imm's up into two pieces.  This handles immediates with up to 16
151 // bits set in them.  This uses so_imm2part to match and so_imm2part_[12] to
152 // get the first/second pieces.
153 def so_imm2part : PatLeaf<(imm), [{
154   return ARM_AM::isSOImmTwoPartVal((unsigned)N->getValue());
155 }]>;
156
157 def so_imm2part_1 : SDNodeXForm<imm, [{
158   unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getValue());
159   return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
160 }]>;
161
162 def so_imm2part_2 : SDNodeXForm<imm, [{
163   unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getValue());
164   return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
165 }]>;
166
167
168
169 //===----------------------------------------------------------------------===//
170 // Operand Definitions.
171 //
172
173 // Branch target.
174 def brtarget : Operand<OtherVT>;
175
176 // Operand for printing out a condition code.
177 def CCOp : Operand<i32> {
178   let PrintMethod = "printCCOperand";
179 }
180
181 // A list of registers separated by comma. Used by load/store multiple.
182 def reglist : Operand<i32> {
183   let PrintMethod = "printRegisterList";
184 }
185
186 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
187 def cpinst_operand : Operand<i32> {
188   let PrintMethod = "printCPInstOperand";
189 }
190
191 def jtblock_operand : Operand<i32> {
192   let PrintMethod = "printJTBlockOperand";
193 }
194
195 // Local PC labels.
196 def pclabel : Operand<i32> {
197   let PrintMethod = "printPCLabel";
198 }
199
200 // shifter_operand operands: so_reg and so_imm.
201 def so_reg : Operand<i32>,    // reg reg imm
202             ComplexPattern<i32, 3, "SelectShifterOperandReg",
203                             [shl,srl,sra,rotr]> {
204   let PrintMethod = "printSORegOperand";
205   let MIOperandInfo = (ops GPR, GPR, i32imm);
206 }
207
208 // so_imm - Match a 32-bit shifter_operand immediate operand, which is an
209 // 8-bit immediate rotated by an arbitrary number of bits.  so_imm values are
210 // represented in the imm field in the same 12-bit form that they are encoded
211 // into so_imm instructions: the 8-bit immediate is the least significant bits
212 // [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
213 def so_imm : Operand<i32>,
214              PatLeaf<(imm),
215                      [{ return ARM_AM::getSOImmVal(N->getValue()) != -1; }],
216                      so_imm_XFORM> {
217   let PrintMethod = "printSOImmOperand";
218 }
219
220
221 // Define ARM specific addressing modes.
222
223 // addrmode2 := reg +/- reg shop imm
224 // addrmode2 := reg +/- imm12
225 //
226 def addrmode2 : Operand<i32>,
227                 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
228   let PrintMethod = "printAddrMode2Operand";
229   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
230 }
231
232 def am2offset : Operand<i32>,
233                 ComplexPattern<i32, 2, "SelectAddrMode2Offset", []> {
234   let PrintMethod = "printAddrMode2OffsetOperand";
235   let MIOperandInfo = (ops GPR, i32imm);
236 }
237
238 // addrmode3 := reg +/- reg
239 // addrmode3 := reg +/- imm8
240 //
241 def addrmode3 : Operand<i32>,
242                 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
243   let PrintMethod = "printAddrMode3Operand";
244   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
245 }
246
247 def am3offset : Operand<i32>,
248                 ComplexPattern<i32, 2, "SelectAddrMode3Offset", []> {
249   let PrintMethod = "printAddrMode3OffsetOperand";
250   let MIOperandInfo = (ops GPR, i32imm);
251 }
252
253 // addrmode4 := reg, <mode|W>
254 //
255 def addrmode4 : Operand<i32>,
256                 ComplexPattern<i32, 2, "", []> {
257   let PrintMethod = "printAddrMode4Operand";
258   let MIOperandInfo = (ops GPR, i32imm);
259 }
260
261 // addrmode5 := reg +/- imm8*4
262 //
263 def addrmode5 : Operand<i32>,
264                 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
265   let PrintMethod = "printAddrMode5Operand";
266   let MIOperandInfo = (ops GPR, i32imm);
267 }
268
269 // addrmodepc := pc + reg
270 //
271 def addrmodepc : Operand<i32>,
272                  ComplexPattern<i32, 2, "SelectAddrModePC", []> {
273   let PrintMethod = "printAddrModePCOperand";
274   let MIOperandInfo = (ops GPR, i32imm);
275 }
276
277 //===----------------------------------------------------------------------===//
278 // ARM Instruction flags.  These need to match ARMInstrInfo.h.
279 //
280
281 // Addressing mode.
282 class AddrMode<bits<4> val> {
283   bits<4> Value = val;
284 }
285 def AddrModeNone : AddrMode<0>;
286 def AddrMode1    : AddrMode<1>;
287 def AddrMode2    : AddrMode<2>;
288 def AddrMode3    : AddrMode<3>;
289 def AddrMode4    : AddrMode<4>;
290 def AddrMode5    : AddrMode<5>;
291 def AddrModeT1   : AddrMode<6>;
292 def AddrModeT2   : AddrMode<7>;
293 def AddrModeT4   : AddrMode<8>;
294 def AddrModeTs   : AddrMode<9>;
295
296 // Instruction size.
297 class SizeFlagVal<bits<3> val> {
298   bits<3> Value = val;
299 }
300 def SizeInvalid  : SizeFlagVal<0>;  // Unset.
301 def SizeSpecial  : SizeFlagVal<1>;  // Pseudo or special.
302 def Size8Bytes   : SizeFlagVal<2>;
303 def Size4Bytes   : SizeFlagVal<3>;
304 def Size2Bytes   : SizeFlagVal<4>;
305
306 // Load / store index mode.
307 class IndexMode<bits<2> val> {
308   bits<2> Value = val;
309 }
310 def IndexModeNone : IndexMode<0>;
311 def IndexModePre  : IndexMode<1>;
312 def IndexModePost : IndexMode<2>;
313
314 //===----------------------------------------------------------------------===//
315 // ARM Instruction templates.
316 //
317
318 // ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
319 class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
320   list<Predicate> Predicates = [IsARM];
321 }
322 class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
323   list<Predicate> Predicates = [IsARM, HasV5TE];
324 }
325 class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
326   list<Predicate> Predicates = [IsARM, HasV6];
327 }
328
329 class InstARM<bits<4> opcod, AddrMode am, SizeFlagVal sz, IndexMode im,
330               dag ops, string asmstr, string cstr>
331   : Instruction {
332   let Namespace = "ARM";
333
334   bits<4> Opcode = opcod;
335   AddrMode AM = am;
336   bits<4> AddrModeBits = AM.Value;
337   
338   SizeFlagVal SZ = sz;
339   bits<3> SizeFlag = SZ.Value;
340
341   IndexMode IM = im;
342   bits<2> IndexModeBits = IM.Value;
343   
344   dag OperandList = ops;
345   let AsmString   = asmstr;
346   let Constraints = cstr;
347 }
348
349 class PseudoInst<dag ops, string asm, list<dag> pattern>
350   : InstARM<0, AddrModeNone, SizeSpecial, IndexModeNone, ops, asm, ""> {
351   let Pattern = pattern;
352 }
353
354 class I<dag ops, AddrMode am, SizeFlagVal sz, IndexMode im,
355         string asm, string cstr, list<dag> pattern>
356   // FIXME: Set all opcodes to 0 for now.
357   : InstARM<0, am, sz, im, ops, asm, cstr> {
358   let Pattern = pattern;
359   list<Predicate> Predicates = [IsARM];
360 }
361
362 class AI<dag ops, string asm, list<dag> pattern>
363   : I<ops, AddrModeNone, Size4Bytes, IndexModeNone, asm, "", pattern>;
364 class AI1<dag ops, string asm, list<dag> pattern>
365   : I<ops, AddrMode1, Size4Bytes, IndexModeNone, asm, "", pattern>;
366 class AI2<dag ops, string asm, list<dag> pattern>
367   : I<ops, AddrMode2, Size4Bytes, IndexModeNone, asm, "", pattern>;
368 class AI3<dag ops, string asm, list<dag> pattern>
369   : I<ops, AddrMode3, Size4Bytes, IndexModeNone, asm, "", pattern>;
370 class AI4<dag ops, string asm, list<dag> pattern>
371   : I<ops, AddrMode4, Size4Bytes, IndexModeNone, asm, "", pattern>;
372 class AIx2<dag ops, string asm, list<dag> pattern>
373   : I<ops, AddrModeNone, Size8Bytes, IndexModeNone, asm, "", pattern>;
374
375 // Pre-indexed ops
376 class AI2pr<dag ops, string asm, string cstr, list<dag> pattern>
377   : I<ops, AddrMode2, Size4Bytes, IndexModePre, asm, cstr, pattern>;
378 class AI3pr<dag ops, string asm, string cstr, list<dag> pattern>
379   : I<ops, AddrMode3, Size4Bytes, IndexModePre, asm, cstr, pattern>;
380
381 // Post-indexed ops
382 class AI2po<dag ops, string asm, string cstr, list<dag> pattern>
383   : I<ops, AddrMode2, Size4Bytes, IndexModePost, asm, cstr, pattern>;
384 class AI3po<dag ops, string asm, string cstr, list<dag> pattern>
385   : I<ops, AddrMode3, Size4Bytes, IndexModePost, asm, cstr, pattern>;
386
387 // BR_JT instructions
388 class JTI<dag ops, string asm, list<dag> pattern>
389   : I<ops, AddrModeNone, SizeSpecial, IndexModeNone, asm, "", pattern>;
390 class JTI1<dag ops, string asm, list<dag> pattern>
391   : I<ops, AddrMode1, SizeSpecial, IndexModeNone, asm, "", pattern>;
392 class JTI2<dag ops, string asm, list<dag> pattern>
393   : I<ops, AddrMode2, SizeSpecial, IndexModeNone, asm, "", pattern>;
394
395
396 class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
397 class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
398
399
400 /// AI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
401 /// binop that produces a value.
402 multiclass AI1_bin_irs<string opc, PatFrag opnode> {
403   def ri : AI1<(ops GPR:$dst, GPR:$a, so_imm:$b),
404                !strconcat(opc, " $dst, $a, $b"),
405                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
406   def rr : AI1<(ops GPR:$dst, GPR:$a, GPR:$b),
407                !strconcat(opc, " $dst, $a, $b"),
408                [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
409   def rs : AI1<(ops GPR:$dst, GPR:$a, so_reg:$b),
410                !strconcat(opc, " $dst, $a, $b"),
411                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
412 }
413
414 /// AI1_bin0_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns.
415 /// Similar to AI1_bin_irs except the instruction does not produce a result.
416 multiclass AI1_bin0_irs<string opc, PatFrag opnode> {
417   def ri : AI1<(ops GPR:$a, so_imm:$b),
418                !strconcat(opc, " $a, $b"),
419                [(opnode GPR:$a, so_imm:$b)]>;
420   def rr : AI1<(ops GPR:$a, GPR:$b),
421                !strconcat(opc, " $a, $b"),
422                [(opnode GPR:$a, GPR:$b)]>;
423   def rs : AI1<(ops GPR:$a, so_reg:$b),
424                !strconcat(opc, " $a, $b"),
425                [(opnode GPR:$a, so_reg:$b)]>;
426 }
427
428 /// AI1_bin_is - Defines a set of (op r, {so_imm|so_reg}) patterns for a binop.
429 multiclass AI1_bin_is<string opc, PatFrag opnode> {
430   def ri : AI1<(ops GPR:$dst, GPR:$a, so_imm:$b),
431                !strconcat(opc, " $dst, $a, $b"),
432                [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
433   def rs : AI1<(ops GPR:$dst, GPR:$a, so_reg:$b),
434                !strconcat(opc, " $dst, $a, $b"),
435                [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
436 }
437
438 /// AI1_unary_irs - Defines a set of (op {so_imm|r|so_reg}) patterns for unary
439 /// ops.
440 multiclass AI1_unary_irs<string opc, PatFrag opnode> {
441   def i : AI1<(ops GPR:$dst, so_imm:$a),
442               !strconcat(opc, " $dst, $a"),
443               [(set GPR:$dst, (opnode so_imm:$a))]>;
444   def r : AI1<(ops GPR:$dst, GPR:$a),
445               !strconcat(opc, " $dst, $a"),
446               [(set GPR:$dst, (opnode GPR:$a))]>;
447   def s : AI1<(ops GPR:$dst, so_reg:$a),
448               !strconcat(opc, " $dst, $a"),
449               [(set GPR:$dst, (opnode so_reg:$a))]>;
450 }
451
452 /// AI_unary_rrot - A unary operation with two forms: one whose operand is a
453 /// register and one whose operand is a register rotated by 8/16/24.
454 multiclass AI_unary_rrot<string opc, PatFrag opnode> {
455   def r     : AI<(ops GPR:$dst, GPR:$Src),
456                  !strconcat(opc, " $dst, $Src"),
457                  [(set GPR:$dst, (opnode GPR:$Src))]>, Requires<[IsARM, HasV6]>;
458   def r_rot : AI<(ops GPR:$dst, GPR:$Src, i32imm:$rot),
459                  !strconcat(opc, " $dst, $Src, ror $rot"),
460                  [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>,
461               Requires<[IsARM, HasV6]>;
462 }
463
464 /// AI_bin_rrot - A binary operation with two forms: one whose operand is a
465 /// register and one whose operand is a register rotated by 8/16/24.
466 multiclass AI_bin_rrot<string opc, PatFrag opnode> {
467   def rr     : AI<(ops GPR:$dst, GPR:$LHS, GPR:$RHS),
468                   !strconcat(opc, " $dst, $LHS, $RHS"),
469                   [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
470                   Requires<[IsARM, HasV6]>;
471   def rr_rot : AI<(ops GPR:$dst, GPR:$LHS, GPR:$RHS, i32imm:$rot),
472                   !strconcat(opc, " $dst, $LHS, $RHS, ror $rot"),
473                   [(set GPR:$dst, (opnode GPR:$LHS,
474                                           (rotr GPR:$RHS, rot_imm:$rot)))]>,
475                   Requires<[IsARM, HasV6]>;
476 }
477
478
479 //===----------------------------------------------------------------------===//
480 // Instructions
481 //===----------------------------------------------------------------------===//
482
483 //===----------------------------------------------------------------------===//
484 //  Miscellaneous Instructions.
485 //
486 def IMPLICIT_DEF_GPR : 
487 PseudoInst<(ops GPR:$rD),
488            "@ IMPLICIT_DEF_GPR $rD",
489            [(set GPR:$rD, (undef))]>;
490
491
492 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
493 /// the function.  The first operand is the ID# for this instruction, the second
494 /// is the index into the MachineConstantPool that this is, the third is the
495 /// size in bytes of this constant pool entry.
496 def CONSTPOOL_ENTRY :
497 PseudoInst<(ops cpinst_operand:$instid, cpinst_operand:$cpidx, i32imm:$size),
498            "${instid:label} ${cpidx:cpentry}", []>;
499
500 def ADJCALLSTACKUP :
501 PseudoInst<(ops i32imm:$amt),
502            "@ ADJCALLSTACKUP $amt",
503            [(ARMcallseq_end imm:$amt)]>, Imp<[SP],[SP]>;
504
505 def ADJCALLSTACKDOWN : 
506 PseudoInst<(ops i32imm:$amt),
507            "@ ADJCALLSTACKDOWN $amt",
508            [(ARMcallseq_start imm:$amt)]>, Imp<[SP],[SP]>;
509
510 def DWARF_LOC :
511 PseudoInst<(ops i32imm:$line, i32imm:$col, i32imm:$file),
512            ".loc $file, $line, $col",
513            [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
514
515 def PICADD : AI1<(ops GPR:$dst, GPR:$a, pclabel:$cp),
516                   "$cp:\n\tadd $dst, pc, $a",
517                   [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
518 let AddedComplexity = 10 in
519 def PICLD : AI2<(ops GPR:$dst, addrmodepc:$addr),
520                   "${addr:label}:\n\tldr $dst, $addr",
521                   [(set GPR:$dst, (load addrmodepc:$addr))]>;
522
523 //===----------------------------------------------------------------------===//
524 //  Control Flow Instructions.
525 //
526
527 let isReturn = 1, isTerminator = 1 in
528   def BX_RET : AI<(ops), "bx lr", [(ARMretflag)]>;
529
530 // FIXME: remove when we have a way to marking a MI with these properties.
531 let isLoad = 1, isReturn = 1, isTerminator = 1 in
532   def LDM_RET : AI4<(ops addrmode4:$addr, reglist:$dst1, variable_ops),
533                     "ldm${addr:submode} $addr, $dst1",
534                     []>;
535
536 let isCall = 1, noResults = 1, 
537   Defs = [R0, R1, R2, R3, R12, LR,
538           D0, D1, D2, D3, D4, D5, D6, D7] in {
539   def BL  : AI<(ops i32imm:$func, variable_ops),
540                "bl ${func:call}",
541                [(ARMcall tglobaladdr:$func)]>;
542   // ARMv5T and above
543   def BLX : AI<(ops GPR:$dst, variable_ops),
544                "blx $dst",
545                [(ARMcall GPR:$dst)]>, Requires<[IsARM, HasV5T]>;
546   // ARMv4T
547   def BX : AIx2<(ops GPR:$dst, variable_ops),
548                 "mov lr, pc\n\tbx $dst",
549                 [(ARMcall_nolink GPR:$dst)]>;
550 }
551
552 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
553   def B : AI<(ops brtarget:$dst), "b $dst",
554              [(br bb:$dst)]>;
555
556   def BR_JTr : JTI<(ops GPR:$dst, jtblock_operand:$jt, i32imm:$id),
557                     "mov pc, $dst \n$jt",
558                     [(ARMbrjt GPR:$dst, tjumptable:$jt, imm:$id)]>;
559   def BR_JTm : JTI2<(ops addrmode2:$dst, jtblock_operand:$jt, i32imm:$id),
560                      "ldr pc, $dst \n$jt",
561                      [(ARMbrjt (i32 (load addrmode2:$dst)), tjumptable:$jt,
562                        imm:$id)]>;
563   def BR_JTadd : JTI1<(ops GPR:$dst, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
564                        "add pc, $dst, $idx \n$jt",
565                        [(ARMbrjt (add GPR:$dst, GPR:$idx), tjumptable:$jt,
566                          imm:$id)]>;
567 }
568
569 let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
570   def Bcc : AI<(ops brtarget:$dst, CCOp:$cc), "b$cc $dst",
571                 [(ARMbrcond bb:$dst, imm:$cc)]>;
572
573 //===----------------------------------------------------------------------===//
574 //  Load / store Instructions.
575 //
576
577 // Load
578 let isLoad = 1 in {
579 def LDR  : AI2<(ops GPR:$dst, addrmode2:$addr),
580                "ldr $dst, $addr",
581                [(set GPR:$dst, (load addrmode2:$addr))]>;
582
583 // Special LDR for loads from non-pc-relative constpools.
584 let isReMaterializable = 1 in
585 def LDRcp : AI2<(ops GPR:$dst, addrmode2:$addr),
586                  "ldr $dst, $addr", []>;
587
588 // Loads with zero extension
589 def LDRH  : AI3<(ops GPR:$dst, addrmode3:$addr),
590                  "ldrh $dst, $addr",
591                 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
592
593 def LDRB  : AI2<(ops GPR:$dst, addrmode2:$addr),
594                  "ldrb $dst, $addr",
595                 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
596
597 // Loads with sign extension
598 def LDRSH : AI3<(ops GPR:$dst, addrmode3:$addr),
599                  "ldrsh $dst, $addr",
600                 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
601
602 def LDRSB : AI3<(ops GPR:$dst, addrmode3:$addr),
603                  "ldrsb $dst, $addr",
604                 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
605
606 // Load doubleword
607 def LDRD  : AI3<(ops GPR:$dst, addrmode3:$addr),
608                  "ldrd $dst, $addr",
609                 []>, Requires<[IsARM, HasV5T]>;
610
611 // Indexed loads
612 def LDR_PRE  : AI2pr<(ops GPR:$dst, GPR:$base_wb, addrmode2:$addr),
613                     "ldr $dst, $addr!", "$addr.base = $base_wb", []>;
614
615 def LDR_POST : AI2po<(ops GPR:$dst, GPR:$base_wb, GPR:$base, am2offset:$offset),
616                     "ldr $dst, [$base], $offset", "$base = $base_wb", []>;
617
618 def LDRH_PRE  : AI3pr<(ops GPR:$dst, GPR:$base_wb, addrmode3:$addr),
619                      "ldrh $dst, $addr!", "$addr.base = $base_wb", []>;
620
621 def LDRH_POST : AI3po<(ops GPR:$dst, GPR:$base_wb, GPR:$base,am3offset:$offset),
622                      "ldrh $dst, [$base], $offset", "$base = $base_wb", []>;
623
624 def LDRB_PRE  : AI2pr<(ops GPR:$dst, GPR:$base_wb, addrmode2:$addr),
625                      "ldrb $dst, $addr!", "$addr.base = $base_wb", []>;
626
627 def LDRB_POST : AI2po<(ops GPR:$dst, GPR:$base_wb, GPR:$base,am2offset:$offset),
628                      "ldrb $dst, [$base], $offset", "$base = $base_wb", []>;
629
630 def LDRSH_PRE : AI3pr<(ops GPR:$dst, GPR:$base_wb, addrmode3:$addr),
631                       "ldrsh $dst, $addr!", "$addr.base = $base_wb", []>;
632
633 def LDRSH_POST: AI3po<(ops GPR:$dst, GPR:$base_wb, GPR:$base,am3offset:$offset),
634                       "ldrsh $dst, [$base], $offset", "$base = $base_wb", []>;
635
636 def LDRSB_PRE : AI3pr<(ops GPR:$dst, GPR:$base_wb, addrmode3:$addr),
637                       "ldrsb $dst, $addr!", "$addr.base = $base_wb", []>;
638
639 def LDRSB_POST: AI3po<(ops GPR:$dst, GPR:$base_wb, GPR:$base,am3offset:$offset),
640                       "ldrsb $dst, [$base], $offset", "$base = $base_wb", []>;
641 } // isLoad
642
643 // Store
644 let isStore = 1 in {
645 def STR  : AI2<(ops GPR:$src, addrmode2:$addr),
646                "str $src, $addr",
647                [(store GPR:$src, addrmode2:$addr)]>;
648
649 // Stores with truncate
650 def STRH : AI3<(ops GPR:$src, addrmode3:$addr),
651                "strh $src, $addr",
652                [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
653
654 def STRB : AI2<(ops GPR:$src, addrmode2:$addr),
655                "strb $src, $addr",
656                [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
657
658 // Store doubleword
659 def STRD : AI3<(ops GPR:$src, addrmode3:$addr),
660                "strd $src, $addr",
661                []>, Requires<[IsARM, HasV5T]>;
662
663 // Indexed stores
664 def STR_PRE  : AI2pr<(ops GPR:$base_wb, GPR:$src, GPR:$base, am2offset:$offset),
665                     "str $src, [$base, $offset]!", "$base = $base_wb",
666                     [(set GPR:$base_wb,
667                       (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
668
669 def STR_POST : AI2po<(ops  GPR:$base_wb, GPR:$src, GPR:$base,am2offset:$offset),
670                     "str $src, [$base], $offset", "$base = $base_wb",
671                     [(set GPR:$base_wb,
672                       (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
673
674 def STRH_PRE : AI3pr<(ops  GPR:$base_wb, GPR:$src, GPR:$base,am3offset:$offset),
675                      "strh $src, [$base, $offset]!", "$base = $base_wb",
676                     [(set GPR:$base_wb,
677                       (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
678
679 def STRH_POST: AI3po<(ops  GPR:$base_wb, GPR:$src, GPR:$base,am3offset:$offset),
680                      "strh $src, [$base], $offset", "$base = $base_wb",
681                     [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
682                                          GPR:$base, am3offset:$offset))]>;
683
684 def STRB_PRE : AI2pr<(ops  GPR:$base_wb, GPR:$src, GPR:$base,am2offset:$offset),
685                      "strb $src, [$base, $offset]!", "$base = $base_wb",
686                     [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
687                                          GPR:$base, am2offset:$offset))]>;
688
689 def STRB_POST: AI2po<(ops  GPR:$base_wb, GPR:$src, GPR:$base,am2offset:$offset),
690                      "strb $src, [$base], $offset", "$base = $base_wb",
691                     [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
692                                          GPR:$base, am2offset:$offset))]>;
693 } // isStore
694
695 //===----------------------------------------------------------------------===//
696 //  Load / store multiple Instructions.
697 //
698
699 let isLoad = 1 in
700 def LDM : AI4<(ops addrmode4:$addr, reglist:$dst1, variable_ops),
701               "ldm${addr:submode} $addr, $dst1",
702               []>;
703
704 let isStore = 1 in
705 def STM : AI4<(ops addrmode4:$addr, reglist:$src1, variable_ops),
706               "stm${addr:submode} $addr, $src1",
707               []>;
708
709 //===----------------------------------------------------------------------===//
710 //  Move Instructions.
711 //
712
713 def MOVr : AI1<(ops GPR:$dst, GPR:$src),
714                 "mov $dst, $src", []>;
715 def MOVs : AI1<(ops GPR:$dst, so_reg:$src),
716                 "mov $dst, $src", [(set GPR:$dst, so_reg:$src)]>;
717
718 let isReMaterializable = 1 in
719 def MOVi : AI1<(ops GPR:$dst, so_imm:$src),
720                 "mov $dst, $src", [(set GPR:$dst, so_imm:$src)]>;
721
722 // These aren't really mov instructions, but we have to define them this way
723 // due to flag operands.
724
725 def MOVsrl_flag : AI1<(ops GPR:$dst, GPR:$src),
726                       "movs $dst, $src, lsr #1",
727                       [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>;
728 def MOVsra_flag : AI1<(ops GPR:$dst, GPR:$src),
729                       "movs $dst, $src, asr #1",
730                       [(set GPR:$dst, (ARMsra_flag GPR:$src))]>;
731 def MOVrx       : AI1<(ops GPR:$dst, GPR:$src),
732                       "mov $dst, $src, rrx",
733                       [(set GPR:$dst, (ARMrrx GPR:$src))]>;
734
735
736 //===----------------------------------------------------------------------===//
737 //  Extend Instructions.
738 //
739
740 // Sign extenders
741
742 defm SXTB  : AI_unary_rrot<"sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
743 defm SXTH  : AI_unary_rrot<"sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
744
745 defm SXTAB : AI_bin_rrot<"sxtab",
746                         BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
747 defm SXTAH : AI_bin_rrot<"sxtah",
748                         BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
749
750 // TODO: SXT(A){B|H}16
751
752 // Zero extenders
753
754 let AddedComplexity = 16 in {
755 defm UXTB   : AI_unary_rrot<"uxtb"  , UnOpFrag<(and node:$Src, 0x000000FF)>>;
756 defm UXTH   : AI_unary_rrot<"uxth"  , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
757 defm UXTB16 : AI_unary_rrot<"uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
758
759 def : ARMV6Pat<(and (shl GPR:$Src, 8), 0xFF00FF),
760                (UXTB16r_rot GPR:$Src, 24)>;
761 def : ARMV6Pat<(and (srl GPR:$Src, 8), 0xFF00FF),
762                (UXTB16r_rot GPR:$Src, 8)>;
763
764 defm UXTAB : AI_bin_rrot<"uxtab",
765                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
766 defm UXTAH : AI_bin_rrot<"uxtah",
767                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
768 }
769
770 // This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
771 //defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
772
773 // TODO: UXT(A){B|H}16
774
775 //===----------------------------------------------------------------------===//
776 //  Arithmetic Instructions.
777 //
778
779 defm ADD  : AI1_bin_irs<"add" , BinOpFrag<(add  node:$LHS, node:$RHS)>>;
780 defm ADDS : AI1_bin_irs<"adds", BinOpFrag<(addc node:$LHS, node:$RHS)>>;
781 defm ADC  : AI1_bin_irs<"adc" , BinOpFrag<(adde node:$LHS, node:$RHS)>>;
782 defm SUB  : AI1_bin_irs<"sub" , BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
783 defm SUBS : AI1_bin_irs<"subs", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
784 defm SBC  : AI1_bin_irs<"sbc" , BinOpFrag<(sube node:$LHS, node:$RHS)>>;
785
786 // These don't define reg/reg forms, because they are handled above.
787 defm RSB  : AI1_bin_is <"rsb" , BinOpFrag<(sub  node:$RHS, node:$LHS)>>;
788 defm RSBS : AI1_bin_is <"rsbs", BinOpFrag<(subc node:$RHS, node:$LHS)>>;
789 defm RSC  : AI1_bin_is <"rsc" , BinOpFrag<(sube node:$RHS, node:$LHS)>>;
790
791 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
792 def : ARMPat<(add    GPR:$src, so_imm_neg:$imm),
793              (SUBri  GPR:$src, so_imm_neg:$imm)>;
794
795 //def : ARMPat<(addc   GPR:$src, so_imm_neg:$imm),
796 //             (SUBSri GPR:$src, so_imm_neg:$imm)>;
797 //def : ARMPat<(adde   GPR:$src, so_imm_neg:$imm),
798 //             (SBCri  GPR:$src, so_imm_neg:$imm)>;
799
800 // Note: These are implemented in C++ code, because they have to generate
801 // ADD/SUBrs instructions, which use a complex pattern that a xform function
802 // cannot produce.
803 // (mul X, 2^n+1) -> (add (X << n), X)
804 // (mul X, 2^n-1) -> (rsb X, (X << n))
805
806
807 //===----------------------------------------------------------------------===//
808 //  Bitwise Instructions.
809 //
810
811 defm AND   : AI1_bin_irs<"and", BinOpFrag<(and node:$LHS, node:$RHS)>>;
812 defm ORR   : AI1_bin_irs<"orr", BinOpFrag<(or  node:$LHS, node:$RHS)>>;
813 defm EOR   : AI1_bin_irs<"eor", BinOpFrag<(xor node:$LHS, node:$RHS)>>;
814 defm BIC   : AI1_bin_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
815
816 def  MVNr  : AI<(ops GPR:$dst, GPR:$src),
817                 "mvn $dst, $src", [(set GPR:$dst, (not GPR:$src))]>;
818 def  MVNs  : AI<(ops GPR:$dst, so_reg:$src),
819                 "mvn $dst, $src", [(set GPR:$dst, (not so_reg:$src))]>;
820 let isReMaterializable = 1 in
821 def  MVNi  : AI<(ops GPR:$dst, so_imm:$imm),
822                 "mvn $dst, $imm", [(set GPR:$dst, so_imm_not:$imm)]>;
823
824 def : ARMPat<(and   GPR:$src, so_imm_not:$imm),
825              (BICri GPR:$src, so_imm_not:$imm)>;
826
827 //===----------------------------------------------------------------------===//
828 //  Multiply Instructions.
829 //
830
831 // AI_orr - Defines a (op r, r) pattern.
832 class AI_orr<string opc, SDNode opnode>
833   : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
834        !strconcat(opc, " $dst, $a, $b"),
835        [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
836
837 // AI_oorr - Defines a (op (op r, r), r) pattern.
838 class AI_oorr<string opc, SDNode opnode1, SDNode opnode2>
839   : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$c),
840        !strconcat(opc, " $dst, $a, $b, $c"),
841        [(set GPR:$dst, (opnode1 (opnode2 GPR:$a, GPR:$b), GPR:$c))]>;
842
843 def MUL  : AI_orr<"mul", mul>;
844 def MLA  : AI_oorr<"mla", add, mul>;
845
846 // Extra precision multiplies with low / high results
847 def SMULL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
848                "smull $ldst, $hdst, $a, $b",
849                []>;
850
851 def UMULL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
852                "umull $ldst, $hdst, $a, $b",
853                []>;
854
855 // Multiply + accumulate
856 def SMLAL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
857                "smlal $ldst, $hdst, $a, $b",
858                []>;
859
860 def UMLAL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
861                "umlal $ldst, $hdst, $a, $b",
862                []>;
863
864 def UMAAL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
865                "umaal $ldst, $hdst, $a, $b",
866                []>, Requires<[IsARM, HasV6]>;
867
868 // Most significant word multiply
869 def SMMUL : AI_orr<"smmul", mulhs>, Requires<[IsARM, HasV6]>;
870 def SMMLA : AI_oorr<"smmla", add, mulhs>, Requires<[IsARM, HasV6]>;
871
872
873 def SMMLS : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$c),
874                "smmls $dst, $a, $b, $c",
875                [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
876                Requires<[IsARM, HasV6]>;
877
878 multiclass AI_smul<string opc, PatFrag opnode> {
879   def BB : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
880               !strconcat(opc, "bb $dst, $a, $b"),
881               [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
882                                       (sext_inreg GPR:$b, i16)))]>,
883            Requires<[IsARM, HasV5TE]>;
884   def BT : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
885               !strconcat(opc, "bt $dst, $a, $b"),
886               [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
887                                       (sra GPR:$b, 16)))]>,
888            Requires<[IsARM, HasV5TE]>;
889   def TB : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
890               !strconcat(opc, "tb $dst, $a, $b"),
891               [(set GPR:$dst, (opnode (sra GPR:$a, 16),
892                                       (sext_inreg GPR:$b, i16)))]>,
893            Requires<[IsARM, HasV5TE]>;
894   def TT : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
895               !strconcat(opc, "tt $dst, $a, $b"),
896               [(set GPR:$dst, (opnode (sra GPR:$a, 16),
897                                       (sra GPR:$b, 16)))]>,
898             Requires<[IsARM, HasV5TE]>;
899   def WB : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
900               !strconcat(opc, "wb $dst, $a, $b"),
901               [(set GPR:$dst, (sra (opnode GPR:$a,
902                                     (sext_inreg GPR:$b, i16)), 16))]>,
903            Requires<[IsARM, HasV5TE]>;
904   def WT : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
905               !strconcat(opc, "wt $dst, $a, $b"),
906               [(set GPR:$dst, (sra (opnode GPR:$a,
907                                     (sra GPR:$b, 16)), 16))]>,
908             Requires<[IsARM, HasV5TE]>;
909 }
910
911 multiclass AI_smla<string opc, PatFrag opnode> {
912   def BB : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
913               !strconcat(opc, "bb $dst, $a, $b, $acc"),
914               [(set GPR:$dst, (add GPR:$acc,
915                                (opnode (sext_inreg GPR:$a, i16),
916                                        (sext_inreg GPR:$b, i16))))]>,
917            Requires<[IsARM, HasV5TE]>;
918   def BT : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
919               !strconcat(opc, "bt $dst, $a, $b, $acc"),
920               [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
921                                                      (sra GPR:$b, 16))))]>,
922            Requires<[IsARM, HasV5TE]>;
923   def TB : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
924               !strconcat(opc, "tb $dst, $a, $b, $acc"),
925               [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
926                                                  (sext_inreg GPR:$b, i16))))]>,
927            Requires<[IsARM, HasV5TE]>;
928   def TT : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
929               !strconcat(opc, "tt $dst, $a, $b, $acc"),
930               [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
931                                                      (sra GPR:$b, 16))))]>,
932             Requires<[IsARM, HasV5TE]>;
933
934   def WB : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
935               !strconcat(opc, "wb $dst, $a, $b, $acc"),
936               [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
937                                             (sext_inreg GPR:$b, i16)), 16)))]>,
938            Requires<[IsARM, HasV5TE]>;
939   def WT : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
940               !strconcat(opc, "wt $dst, $a, $b, $acc"),
941               [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
942                                                    (sra GPR:$b, 16)), 16)))]>,
943             Requires<[IsARM, HasV5TE]>;
944 }
945
946 defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
947 defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
948
949 // TODO: Halfword multiple accumulate long: SMLAL<x><y>
950 // TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
951
952 //===----------------------------------------------------------------------===//
953 //  Misc. Arithmetic Instructions.
954 //
955
956 def CLZ  : AI<(ops GPR:$dst, GPR:$src),
957               "clz $dst, $src",
958               [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]>;
959
960 def REV  : AI<(ops GPR:$dst, GPR:$src),
961               "rev $dst, $src",
962               [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]>;
963
964 def REV16 : AI<(ops GPR:$dst, GPR:$src),
965                "rev16 $dst, $src",
966                [(set GPR:$dst,
967                    (or (and (srl GPR:$src, 8), 0xFF),
968                        (or (and (shl GPR:$src, 8), 0xFF00),
969                            (or (and (srl GPR:$src, 8), 0xFF0000),
970                                (and (shl GPR:$src, 8), 0xFF000000)))))]>,
971                Requires<[IsARM, HasV6]>;
972
973 def REVSH : AI<(ops GPR:$dst, GPR:$src),
974                "revsh $dst, $src",
975                [(set GPR:$dst,
976                   (sext_inreg
977                     (or (srl (and GPR:$src, 0xFFFF), 8),
978                         (shl GPR:$src, 8)), i16))]>,
979                Requires<[IsARM, HasV6]>;
980
981 def PKHBT : AI<(ops GPR:$dst, GPR:$src1, GPR:$src2, i32imm:$shamt),
982                "pkhbt $dst, $src1, $src2, LSL $shamt",
983                [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
984                                    (and (shl GPR:$src2, (i32 imm:$shamt)),
985                                         0xFFFF0000)))]>,
986                Requires<[IsARM, HasV6]>;
987
988 // Alternate cases for PKHBT where identities eliminate some nodes.
989 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
990                (PKHBT GPR:$src1, GPR:$src2, 0)>;
991 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
992                (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
993
994
995 def PKHTB : AI<(ops  GPR:$dst, GPR:$src1, GPR:$src2, i32imm:$shamt),
996                "pkhtb $dst, $src1, $src2, ASR $shamt",
997                [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
998                                    (and (sra GPR:$src2, imm16_31:$shamt),
999                                         0xFFFF)))]>, Requires<[IsARM, HasV6]>;
1000
1001 // Alternate cases for PKHTB where identities eliminate some nodes.  Note that
1002 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
1003 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, 16)),
1004                (PKHTB GPR:$src1, GPR:$src2, 16)>;
1005 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1006                    (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1007                (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1008
1009
1010 //===----------------------------------------------------------------------===//
1011 //  Comparison Instructions...
1012 //
1013
1014 defm CMP  : AI1_bin0_irs<"cmp", BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1015 defm CMN  : AI1_bin0_irs<"cmn", BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
1016
1017 def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1018              (CMNri  GPR:$src, so_imm_neg:$imm)>;
1019
1020 // Note that TST/TEQ don't set all the same flags that CMP does!
1021 def TSTrr : AI1<(ops GPR:$a, so_reg:$b), "tst $a, $b", []>;
1022 def TSTri : AI1<(ops GPR:$a, so_imm:$b), "tst $a, $b", []>;
1023 def TEQrr : AI1<(ops GPR:$a, so_reg:$b), "teq $a, $b", []>;
1024 def TEQri : AI1<(ops GPR:$a, so_imm:$b), "teq $a, $b", []>;
1025
1026 // Conditional moves
1027 def MOVCCr : AI<(ops GPR:$dst, GPR:$false, GPR:$true, CCOp:$cc),
1028                 "mov$cc $dst, $true",
1029                 [(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))]>,
1030                 RegConstraint<"$false = $dst">;
1031
1032 def MOVCCs : AI<(ops GPR:$dst, GPR:$false, so_reg:$true, CCOp:$cc),
1033                 "mov$cc $dst, $true",
1034                 [(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true,imm:$cc))]>,
1035                 RegConstraint<"$false = $dst">;
1036
1037 def MOVCCi : AI<(ops GPR:$dst, GPR:$false, so_imm:$true, CCOp:$cc),
1038                 "mov$cc $dst, $true",
1039                 [(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true,imm:$cc))]>,
1040                 RegConstraint<"$false = $dst">;
1041
1042
1043 // LEApcrel - Load a pc-relative address into a register without offending the
1044 // assembler.
1045 def LEApcrel : AI1<(ops GPR:$dst, i32imm:$label),
1046                    !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
1047                                          "${:private}PCRELL${:uid}+8))\n"),
1048                               !strconcat("${:private}PCRELL${:uid}:\n\t",
1049                                          "add $dst, pc, #PCRELV${:uid}")),
1050                    []>;
1051
1052 def LEApcrelJT : AI1<(ops GPR:$dst, i32imm:$label, i32imm:$id),
1053           !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
1054                                          "${:private}PCRELL${:uid}+8))\n"),
1055                               !strconcat("${:private}PCRELL${:uid}:\n\t",
1056                                          "add $dst, pc, #PCRELV${:uid}")),
1057                    []>;
1058
1059 //===----------------------------------------------------------------------===//
1060 // Non-Instruction Patterns
1061 //
1062
1063 // ConstantPool, GlobalAddress, and JumpTable
1064 def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>;
1065 def : ARMPat<(ARMWrapper  tconstpool  :$dst), (LEApcrel tconstpool  :$dst)>;
1066 def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1067           (LEApcrelJT tjumptable:$dst, imm:$id)>;
1068
1069 // Large immediate handling.
1070
1071 // Two piece so_imms.
1072 def : ARMPat<(i32 so_imm2part:$src),
1073              (ORRri (MOVi (so_imm2part_1 imm:$src)),
1074                     (so_imm2part_2 imm:$src))>;
1075
1076 def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1077               (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1078                      (so_imm2part_2 imm:$RHS))>;
1079 def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1080               (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1081                      (so_imm2part_2 imm:$RHS))>;
1082
1083 // TODO: add,sub,and, 3-instr forms?
1084
1085
1086 // Direct calls
1087 def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>;
1088
1089 // zextload i1 -> zextload i8
1090 def : ARMPat<(zextloadi1 addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1091
1092 // extload -> zextload
1093 def : ARMPat<(extloadi1  addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1094 def : ARMPat<(extloadi8  addrmode2:$addr),  (LDRB addrmode2:$addr)>;
1095 def : ARMPat<(extloadi16 addrmode3:$addr),  (LDRH addrmode3:$addr)>;
1096
1097 // truncstore i1 -> truncstore i8
1098 def : Pat<(truncstorei1 GPR:$src, addrmode2:$dst), 
1099           (STRB GPR:$src, addrmode2:$dst)>;
1100 def : Pat<(pre_truncsti1 GPR:$src, GPR:$base, am2offset:$offset), 
1101           (STRB_PRE GPR:$src, GPR:$base, am2offset:$offset)>;
1102 def : Pat<(post_truncsti1 GPR:$src, GPR:$base, am2offset:$offset), 
1103           (STRB_POST GPR:$src, GPR:$base, am2offset:$offset)>;
1104
1105 // smul* and smla*
1106 def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra (shl GPR:$b, 16), 16)),
1107                  (SMULBB GPR:$a, GPR:$b)>;
1108 def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1109                  (SMULBB GPR:$a, GPR:$b)>;
1110 def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16)),
1111                  (SMULBT GPR:$a, GPR:$b)>;
1112 def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, 16)),
1113                  (SMULBT GPR:$a, GPR:$b)>;
1114 def : ARMV5TEPat<(mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16)),
1115                  (SMULTB GPR:$a, GPR:$b)>;
1116 def : ARMV5TEPat<(mul (sra GPR:$a, 16), sext_16_node:$b),
1117                 (SMULTB GPR:$a, GPR:$b)>;
1118 def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16),
1119                  (SMULWB GPR:$a, GPR:$b)>;
1120 def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), 16),
1121                  (SMULWB GPR:$a, GPR:$b)>;
1122
1123 def : ARMV5TEPat<(add GPR:$acc,
1124                       (mul (sra (shl GPR:$a, 16), 16),
1125                            (sra (shl GPR:$b, 16), 16))),
1126                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1127 def : ARMV5TEPat<(add GPR:$acc,
1128                       (mul sext_16_node:$a, sext_16_node:$b)),
1129                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1130 def : ARMV5TEPat<(add GPR:$acc,
1131                       (mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16))),
1132                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1133 def : ARMV5TEPat<(add GPR:$acc,
1134                       (mul sext_16_node:$a, (sra GPR:$b, 16))),
1135                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1136 def : ARMV5TEPat<(add GPR:$acc,
1137                       (mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16))),
1138                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1139 def : ARMV5TEPat<(add GPR:$acc,
1140                       (mul (sra GPR:$a, 16), sext_16_node:$b)),
1141                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1142 def : ARMV5TEPat<(add GPR:$acc,
1143                       (sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16)),
1144                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1145 def : ARMV5TEPat<(add GPR:$acc,
1146                       (sra (mul GPR:$a, sext_16_node:$b), 16)),
1147                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1148
1149 //===----------------------------------------------------------------------===//
1150 // Thumb Support
1151 //
1152
1153 include "ARMInstrThumb.td"
1154
1155 //===----------------------------------------------------------------------===//
1156 // Floating Point Support
1157 //
1158
1159 include "ARMInstrVFP.td"