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