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