Add the Object Code Emitter class. Original patch by Aaron Gray, I did some
[oota-llvm.git] / lib / Target / ARM / ARMInstrThumb2.td
1 //===- ARMInstrThumb2.td - Thumb2 support for ARM -------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the Thumb2 instruction set.
11 //
12 //===----------------------------------------------------------------------===//
13
14 // Shifted operands. No register controlled shifts for Thumb2.
15 // Note: We do not support rrx shifted operands yet.
16 def t2_so_reg : Operand<i32>,    // reg imm
17                 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
18                                [shl,srl,sra,rotr]> {
19   let PrintMethod = "printT2SOOperand";
20   let MIOperandInfo = (ops GPR, i32imm);
21 }
22
23 // t2_so_imm_XFORM - Return a t2_so_imm value packed into the format 
24 // described for t2_so_imm def below.
25 def t2_so_imm_XFORM : SDNodeXForm<imm, [{
26   return CurDAG->getTargetConstant(
27         ARM_AM::getT2SOImmVal(N->getZExtValue()), MVT::i32);
28 }]>;
29
30 // t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
31 def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
32     return CurDAG->getTargetConstant(
33         ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())), MVT::i32);
34 }]>;
35
36 // t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
37 def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
38     return CurDAG->getTargetConstant(
39         ARM_AM::getT2SOImmVal(-((int)N->getZExtValue())), MVT::i32);
40 }]>;
41
42 // t2_so_imm - Match a 32-bit immediate operand, which is an
43 // 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
44 // immediate splatted into multiple bytes of the word. t2_so_imm values are
45 // represented in the imm field in the same 12-bit form that they are encoded
46 // into t2_so_imm instructions: the 8-bit immediate is the least significant bits
47 // [bits 0-7], the 4-bit shift/splat amount is the next 4 bits [bits 8-11].
48 def t2_so_imm : Operand<i32>,
49                 PatLeaf<(imm), [{
50        return ARM_AM::getT2SOImmVal((uint32_t)N->getZExtValue()) != -1;
51      }], t2_so_imm_XFORM> {
52   let PrintMethod = "printT2SOImmOperand";
53 }
54
55 // t2_so_imm_not - Match an immediate that is a complement 
56 // of a t2_so_imm.
57 def t2_so_imm_not : Operand<i32>,
58                     PatLeaf<(imm), [{
59        return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
60      }], t2_so_imm_not_XFORM> {
61   let PrintMethod = "printT2SOImmOperand";
62 }
63
64 // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
65 def t2_so_imm_neg : Operand<i32>,
66                     PatLeaf<(imm), [{
67        return ARM_AM::getT2SOImmVal(-((int)N->getZExtValue())) != -1;
68      }], t2_so_imm_neg_XFORM> {
69   let PrintMethod = "printT2SOImmOperand";
70 }
71
72 /// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
73 def imm1_31 : PatLeaf<(i32 imm), [{
74   return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 32;
75 }]>;
76
77 /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
78 def imm0_4095 : PatLeaf<(i32 imm), [{
79   return (uint32_t)N->getZExtValue() < 4096;
80 }]>;
81
82 def imm0_4095_neg : PatLeaf<(i32 imm), [{ 
83  return (uint32_t)(-N->getZExtValue()) < 4096; 
84 }], imm_neg_XFORM>; 
85
86 /// imm0_65535 predicate - True if the 32-bit immediate is in the range 
87 /// [0.65535].
88 def imm0_65535 : PatLeaf<(i32 imm), [{
89   return (uint32_t)N->getZExtValue() < 65536;
90 }]>;
91
92 /// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
93 /// e.g., 0xf000ffff
94 def bf_inv_mask_imm : Operand<i32>,
95                       PatLeaf<(imm), [{ 
96   uint32_t v = (uint32_t)N->getZExtValue();
97   if (v == 0xffffffff)
98     return 0;
99   // naive checker. should do better, but simple is best for now since it's
100   // more likely to be correct.
101   while (v & 1) v >>= 1;    // shift off the leading 1's
102   if (v)
103     {
104       while (!(v & 1)) v >>=1;  // shift off the mask
105       while (v & 1) v >>= 1;    // shift off the trailing 1's
106     }
107   // if this is a mask for clearing a bitfield, what's left should be zero.
108   return (v == 0);
109 }] > {
110   let PrintMethod = "printBitfieldInvMaskImmOperand";
111 }
112
113 /// Split a 32-bit immediate into two 16 bit parts.
114 def t2_lo16 : SDNodeXForm<imm, [{
115   return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() & 0xffff,
116                                    MVT::i32);
117 }]>;
118
119 def t2_hi16 : SDNodeXForm<imm, [{
120   return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
121 }]>;
122
123 def t2_lo16AllZero : PatLeaf<(i32 imm), [{
124   // Returns true if all low 16-bits are 0.
125   return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
126   }], t2_hi16>;
127
128
129 // Define Thumb2 specific addressing modes.
130
131 // t2addrmode_imm12  := reg + imm12
132 def t2addrmode_imm12 : Operand<i32>,
133                        ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
134   let PrintMethod = "printT2AddrModeImm12Operand";
135   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
136 }
137
138 // t2addrmode_imm8  := reg - imm8
139 def t2addrmode_imm8 : Operand<i32>,
140                       ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
141   let PrintMethod = "printT2AddrModeImm8Operand";
142   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
143 }
144
145 def t2am_imm8_offset : Operand<i32>,
146                        ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset", []>{
147   let PrintMethod = "printT2AddrModeImm8OffsetOperand";
148 }
149
150 // t2addrmode_imm8s4  := reg + (imm8 << 2)
151 def t2addrmode_imm8s4 : Operand<i32>,
152                         ComplexPattern<i32, 2, "SelectT2AddrModeImm8s4", []> {
153   let PrintMethod = "printT2AddrModeImm8Operand";
154   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
155 }
156
157 // t2addrmode_so_reg  := reg + reg << imm2
158 def t2addrmode_so_reg : Operand<i32>,
159                         ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
160   let PrintMethod = "printT2AddrModeSoRegOperand";
161   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
162 }
163
164
165 //===----------------------------------------------------------------------===//
166 // Multiclass helpers...
167 //
168
169 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
170 /// unary operation that produces a value. These are predicable and can be
171 /// changed to modify CPSR.
172 multiclass T2I_un_irs<string opc, PatFrag opnode, bit Cheap = 0, bit ReMat = 0>{
173    // shifted imm
174    def i : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
175                 opc, " $dst, $src",
176                 [(set GPR:$dst, (opnode t2_so_imm:$src))]> {
177      let isAsCheapAsAMove = Cheap;
178      let isReMaterializable = ReMat;
179    }
180    // register
181    def r : T2I<(outs GPR:$dst), (ins GPR:$src),
182                opc, " $dst, $src",
183                 [(set GPR:$dst, (opnode GPR:$src))]>;
184    // shifted register
185    def s : T2I<(outs GPR:$dst), (ins t2_so_reg:$src),
186                opc, " $dst, $src",
187                [(set GPR:$dst, (opnode t2_so_reg:$src))]>;
188 }
189
190 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
191 //  binary operation that produces a value. These are predicable and can be
192 /// changed to modify CPSR.
193 multiclass T2I_bin_irs<string opc, PatFrag opnode, bit Commutable = 0> {
194    // shifted imm
195    def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
196                  opc, " $dst, $lhs, $rhs",
197                  [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
198    // register
199    def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
200                  opc, " $dst, $lhs, $rhs",
201                  [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
202      let isCommutable = Commutable;
203    }
204    // shifted register
205    def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
206                  opc, " $dst, $lhs, $rhs",
207                  [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
208 }
209
210 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
211 /// reversed. It doesn't define the 'rr' form since it's handled by its
212 /// T2I_bin_irs counterpart.
213 multiclass T2I_rbin_is<string opc, PatFrag opnode> {
214    // shifted imm
215    def ri : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
216                 opc, " $dst, $rhs, $lhs",
217                 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
218    // shifted register
219    def rs : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
220                 opc, " $dst, $rhs, $lhs",
221                 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
222 }
223
224 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
225 /// instruction modifies the CPSR register.
226 let Defs = [CPSR] in {
227 multiclass T2I_bin_s_irs<string opc, PatFrag opnode, bit Commutable = 0> {
228    // shifted imm
229    def ri : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
230                 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
231                 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
232    // register
233    def rr : T2I<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
234                 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
235                 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
236      let isCommutable = Commutable;
237    }
238    // shifted register
239    def rs : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
240                 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
241                 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
242 }
243 }
244
245 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
246 /// patterns for a binary operation that produces a value.
247 multiclass T2I_bin_ii12rs<string opc, PatFrag opnode, bit Commutable = 0> {
248    // shifted imm
249    def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
250                  opc, " $dst, $lhs, $rhs",
251                  [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
252    // 12-bit imm
253    def ri12 : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
254                    !strconcat(opc, "w"), " $dst, $lhs, $rhs",
255                    [(set GPR:$dst, (opnode GPR:$lhs, imm0_4095:$rhs))]>;
256    // register
257    def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
258                  opc, " $dst, $lhs, $rhs",
259                  [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
260      let isCommutable = Commutable;
261    }
262    // shifted register
263    def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
264                  opc, " $dst, $lhs, $rhs",
265                  [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
266 }
267
268 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
269 /// binary operation that produces a value and use and define the carry bit.
270 /// It's not predicable.
271 let Uses = [CPSR] in {
272 multiclass T2I_adde_sube_irs<string opc, PatFrag opnode, bit Commutable = 0> {
273    // shifted imm
274    def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
275                  opc, " $dst, $lhs, $rhs",
276                  [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
277                  Requires<[IsThumb2, CarryDefIsUnused]>;
278    // register
279    def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
280                  opc, " $dst, $lhs, $rhs",
281                  [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
282                  Requires<[IsThumb2, CarryDefIsUnused]> {
283      let isCommutable = Commutable;
284    }
285    // shifted register
286    def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
287                  opc, " $dst, $lhs, $rhs",
288                  [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
289                  Requires<[IsThumb2, CarryDefIsUnused]>;
290    // Carry setting variants
291    // shifted imm
292    def Sri : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
293                   !strconcat(opc, "s $dst, $lhs, $rhs"),
294                   [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
295                   Requires<[IsThumb2, CarryDefIsUsed]> {
296                     let Defs = [CPSR];
297                   }
298    // register
299    def Srr : T2XI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
300                   !strconcat(opc, "s $dst, $lhs, $rhs"),
301                   [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
302                   Requires<[IsThumb2, CarryDefIsUsed]> {
303                     let Defs = [CPSR];
304                     let isCommutable = Commutable;
305    }
306    // shifted register
307    def Srs : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
308                   !strconcat(opc, "s $dst, $lhs, $rhs"),
309                   [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
310                   Requires<[IsThumb2, CarryDefIsUsed]> {
311                     let Defs = [CPSR];
312    }
313 }
314 }
315
316 /// T2I_rsc_is - Same as T2I_adde_sube_irs except the order of operands are
317 /// reversed. It doesn't define the 'rr' form since it's handled by its
318 /// T2I_adde_sube_irs counterpart.
319 let Defs = [CPSR], Uses = [CPSR] in {
320 multiclass T2I_rsc_is<string opc, PatFrag opnode> {
321    // shifted imm
322    def ri : T2sI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
323                  opc, " $dst, $rhs, $lhs",
324                  [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>,
325                  Requires<[IsThumb2, CarryDefIsUnused]>;
326    // shifted register
327    def rs : T2sI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
328                  opc, " $dst, $rhs, $lhs",
329                  [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>,
330                  Requires<[IsThumb2, CarryDefIsUnused]>;
331    // shifted imm
332    def Sri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
333                  !strconcat(opc, "s $dst, $rhs, $lhs"),
334                  [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>,
335                  Requires<[IsThumb2, CarryDefIsUsed]> {
336                    let Defs = [CPSR];
337    }
338    // shifted register
339    def Srs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
340                  !strconcat(opc, "s $dst, $rhs, $lhs"),
341                  [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>,
342                  Requires<[IsThumb2, CarryDefIsUsed]> {
343                    let Defs = [CPSR];
344    }
345 }
346 }
347
348 /// T2I_rbin_s_is - Same as T2I_bin_s_irs except the order of operands are
349 /// reversed. It doesn't define the 'rr' form since it's handled by its
350 /// T2I_bin_s_irs counterpart.
351 let Defs = [CPSR] in {
352 multiclass T2I_rbin_s_is<string opc, PatFrag opnode> {
353    // shifted imm
354    def ri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs, cc_out:$s),
355                  !strconcat(opc, "${s} $dst, $rhs, $lhs"),
356                  [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
357    // shifted register
358    def rs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs, cc_out:$s),
359                  !strconcat(opc, "${s} $dst, $rhs, $lhs"),
360                  [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
361 }
362 }
363
364 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
365 //  rotate operation that produces a value.
366 multiclass T2I_sh_ir<string opc, PatFrag opnode> {
367    // 5-bit imm
368    def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
369                  opc, " $dst, $lhs, $rhs",
370                  [(set GPR:$dst, (opnode GPR:$lhs, imm1_31:$rhs))]>;
371    // register
372    def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
373                  opc, " $dst, $lhs, $rhs",
374                  [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>;
375 }
376
377 /// T21_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
378 /// patterns. Similar to T2I_bin_irs except the instruction does not produce
379 /// a explicit result, only implicitly set CPSR.
380 let Uses = [CPSR] in {
381 multiclass T2I_cmp_is<string opc, PatFrag opnode> {
382    // shifted imm
383    def ri : T2I<(outs), (ins GPR:$lhs, t2_so_imm:$rhs),
384                 opc, " $lhs, $rhs",
385                 [(opnode GPR:$lhs, t2_so_imm:$rhs)]>;
386    // register
387    def rr : T2I<(outs), (ins GPR:$lhs, GPR:$rhs),
388                 opc, " $lhs, $rhs",
389                 [(opnode GPR:$lhs, GPR:$rhs)]>;
390    // shifted register
391    def rs : T2I<(outs), (ins GPR:$lhs, t2_so_reg:$rhs),
392                 opc, " $lhs, $rhs",
393                 [(opnode GPR:$lhs, t2_so_reg:$rhs)]>;
394 }
395 }
396
397 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
398 multiclass T2I_ld<string opc, PatFrag opnode> {
399   def i12 : T2Ii12<(outs GPR:$dst), (ins t2addrmode_imm12:$addr),
400                    opc, " $dst, $addr",
401                    [(set GPR:$dst, (opnode t2addrmode_imm12:$addr))]>;
402   def i8  : T2Ii8 <(outs GPR:$dst), (ins t2addrmode_imm8:$addr),
403                    opc, " $dst, $addr",
404                    [(set GPR:$dst, (opnode t2addrmode_imm8:$addr))]>;
405   def s   : T2Iso <(outs GPR:$dst), (ins t2addrmode_so_reg:$addr),
406                    opc, " $dst, $addr",
407                    [(set GPR:$dst, (opnode t2addrmode_so_reg:$addr))]>;
408   def pci : T2Ipc <(outs GPR:$dst), (ins i32imm:$addr),
409                    opc, " $dst, $addr",
410                    [(set GPR:$dst, (opnode (ARMWrapper tconstpool:$addr)))]>;
411 }
412
413 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
414 multiclass T2I_st<string opc, PatFrag opnode> {
415   def i12 : T2Ii12<(outs), (ins GPR:$src, t2addrmode_imm12:$addr),
416                    opc, " $src, $addr",
417                    [(opnode GPR:$src, t2addrmode_imm12:$addr)]>;
418   def i8  : T2Ii8 <(outs), (ins GPR:$src, t2addrmode_imm8:$addr),
419                    opc, " $src, $addr",
420                    [(opnode GPR:$src, t2addrmode_imm8:$addr)]>;
421   def s   : T2Iso <(outs), (ins GPR:$src, t2addrmode_so_reg:$addr),
422                    opc, " $src, $addr",
423                    [(opnode GPR:$src, t2addrmode_so_reg:$addr)]>;
424 }
425
426 /// T2I_picld - Defines the PIC load pattern.
427 class T2I_picld<string opc, PatFrag opnode> :
428       T2I<(outs GPR:$dst), (ins addrmodepc:$addr),
429           !strconcat("${addr:label}:\n\t", opc), " $dst, $addr",
430           [(set GPR:$dst, (opnode addrmodepc:$addr))]>;
431
432 /// T2I_picst - Defines the PIC store pattern.
433 class T2I_picst<string opc, PatFrag opnode> :
434       T2I<(outs), (ins GPR:$src, addrmodepc:$addr),
435           !strconcat("${addr:label}:\n\t", opc), " $src, $addr",
436           [(opnode GPR:$src, addrmodepc:$addr)]>;
437
438
439 /// T2I_unary_rrot - A unary operation with two forms: one whose operand is a
440 /// register and one whose operand is a register rotated by 8/16/24.
441 multiclass T2I_unary_rrot<string opc, PatFrag opnode> {
442   def r     : T2I<(outs GPR:$dst), (ins GPR:$Src),
443                   opc, " $dst, $Src",
444                  [(set GPR:$dst, (opnode GPR:$Src))]>;
445   def r_rot : T2I<(outs GPR:$dst), (ins GPR:$Src, i32imm:$rot),
446                   opc, " $dst, $Src, ror $rot",
447                  [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>;
448 }
449
450 /// T2I_bin_rrot - A binary operation with two forms: one whose operand is a
451 /// register and one whose operand is a register rotated by 8/16/24.
452 multiclass T2I_bin_rrot<string opc, PatFrag opnode> {
453   def rr     : T2I<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
454                   opc, " $dst, $LHS, $RHS",
455                   [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>;
456   def rr_rot : T2I<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
457                   opc, " $dst, $LHS, $RHS, ror $rot",
458                   [(set GPR:$dst, (opnode GPR:$LHS,
459                                           (rotr GPR:$RHS, rot_imm:$rot)))]>;
460 }
461
462 //===----------------------------------------------------------------------===//
463 // Instructions
464 //===----------------------------------------------------------------------===//
465
466 //===----------------------------------------------------------------------===//
467 //  Miscellaneous Instructions.
468 //
469
470 let isNotDuplicable = 1 in
471 def t2PICADD : T2XI<(outs tGPR:$dst), (ins tGPR:$lhs, pclabel:$cp),
472                     "$cp:\n\tadd $dst, pc",
473                     [(set tGPR:$dst, (ARMpic_add tGPR:$lhs, imm:$cp))]>;
474
475
476 // LEApcrel - Load a pc-relative address into a register without offending the
477 // assembler.
478 def t2LEApcrel : T2XI<(outs GPR:$dst), (ins i32imm:$label, pred:$p),
479                    !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
480                                          "${:private}PCRELL${:uid}+8))\n"),
481                               !strconcat("${:private}PCRELL${:uid}:\n\t",
482                                          "add$p $dst, pc, #PCRELV${:uid}")),
483                    []>;
484
485 def t2LEApcrelJT : T2XI<(outs GPR:$dst),
486                        (ins i32imm:$label, i32imm:$id, pred:$p),
487           !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
488                                          "${:private}PCRELL${:uid}+8))\n"),
489                               !strconcat("${:private}PCRELL${:uid}:\n\t",
490                                          "add$p $dst, pc, #PCRELV${:uid}")),
491                    []>;
492
493 // ADD rd, sp, #so_imm
494 def t2ADDrSPi : T2XI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
495                      "add $dst, $sp, $imm",
496                      []>;
497
498 // ADD rd, sp, #imm12
499 def t2ADDrSPi12 : T2XI<(outs GPR:$dst), (ins GPR:$sp, i32imm:$imm),
500                        "addw $dst, $sp, $imm",
501                        []>;
502
503 def t2ADDrSPs : T2XI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
504                      "addw $dst, $sp, $rhs",
505                      []>;
506
507
508 //===----------------------------------------------------------------------===//
509 //  Load / store Instructions.
510 //
511
512 // Load
513 let canFoldAsLoad = 1 in
514 defm t2LDR   : T2I_ld<"ldr",  UnOpFrag<(load node:$Src)>>;
515
516 // Loads with zero extension
517 defm t2LDRH  : T2I_ld<"ldrh", UnOpFrag<(zextloadi16 node:$Src)>>;
518 defm t2LDRB  : T2I_ld<"ldrb", UnOpFrag<(zextloadi8  node:$Src)>>;
519
520 // Loads with sign extension
521 defm t2LDRSH : T2I_ld<"ldrsh", UnOpFrag<(sextloadi16 node:$Src)>>;
522 defm t2LDRSB : T2I_ld<"ldrsb", UnOpFrag<(sextloadi8  node:$Src)>>;
523
524 let mayLoad = 1 in {
525 // Load doubleword
526 def t2LDRDi8 : T2Ii8s4<(outs GPR:$dst), (ins t2addrmode_imm8s4:$addr),
527                        "ldrd", " $dst, $addr", []>;
528 def t2LDRDpci : T2Ii8s4<(outs GPR:$dst), (ins i32imm:$addr),
529                        "ldrd", " $dst, $addr", []>;
530 }
531
532 // zextload i1 -> zextload i8
533 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
534             (t2LDRBi12  t2addrmode_imm12:$addr)>;
535 def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
536             (t2LDRBi8   t2addrmode_imm8:$addr)>;
537 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
538             (t2LDRBs    t2addrmode_so_reg:$addr)>;
539 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
540             (t2LDRBpci  tconstpool:$addr)>;
541
542 // extload -> zextload
543 // FIXME: Reduce the number of patterns by legalizing extload to zextload
544 // earlier?
545 def : T2Pat<(extloadi1  t2addrmode_imm12:$addr),
546             (t2LDRBi12  t2addrmode_imm12:$addr)>;
547 def : T2Pat<(extloadi1  t2addrmode_imm8:$addr),
548             (t2LDRBi8   t2addrmode_imm8:$addr)>;
549 def : T2Pat<(extloadi1  t2addrmode_so_reg:$addr),
550             (t2LDRBs    t2addrmode_so_reg:$addr)>;
551 def : T2Pat<(extloadi1  (ARMWrapper tconstpool:$addr)),
552             (t2LDRBpci  tconstpool:$addr)>;
553
554 def : T2Pat<(extloadi8  t2addrmode_imm12:$addr),
555             (t2LDRBi12  t2addrmode_imm12:$addr)>;
556 def : T2Pat<(extloadi8  t2addrmode_imm8:$addr),
557             (t2LDRBi8   t2addrmode_imm8:$addr)>;
558 def : T2Pat<(extloadi8  t2addrmode_so_reg:$addr),
559             (t2LDRBs    t2addrmode_so_reg:$addr)>;
560 def : T2Pat<(extloadi8  (ARMWrapper tconstpool:$addr)),
561             (t2LDRBpci  tconstpool:$addr)>;
562
563 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
564             (t2LDRHi12  t2addrmode_imm12:$addr)>;
565 def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
566             (t2LDRHi8   t2addrmode_imm8:$addr)>;
567 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
568             (t2LDRHs    t2addrmode_so_reg:$addr)>;
569 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
570             (t2LDRHpci  tconstpool:$addr)>;
571
572 // Indexed loads
573 let mayLoad = 1 in {
574 def t2LDR_PRE  : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
575                             (ins t2addrmode_imm8:$addr),
576                             AddrModeT2_i8, IndexModePre,
577                             "ldr", " $dst, $addr!", "$addr.base = $base_wb",
578                             []>;
579
580 def t2LDR_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
581                             (ins GPR:$base, t2am_imm8_offset:$offset),
582                             AddrModeT2_i8, IndexModePost,
583                            "ldr", " $dst, [$base], $offset", "$base = $base_wb",
584                             []>;
585
586 def t2LDRB_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
587                             (ins t2addrmode_imm8:$addr),
588                             AddrModeT2_i8, IndexModePre,
589                             "ldrb", " $dst, $addr!", "$addr.base = $base_wb",
590                             []>;
591 def t2LDRB_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
592                             (ins GPR:$base, t2am_imm8_offset:$offset),
593                             AddrModeT2_i8, IndexModePost,
594                           "ldrb", " $dst, [$base], $offset", "$base = $base_wb",
595                             []>;
596
597 def t2LDRH_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
598                             (ins t2addrmode_imm8:$addr),
599                             AddrModeT2_i8, IndexModePre,
600                             "ldrh", " $dst, $addr!", "$addr.base = $base_wb",
601                             []>;
602 def t2LDRH_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
603                             (ins GPR:$base, t2am_imm8_offset:$offset),
604                             AddrModeT2_i8, IndexModePost,
605                           "ldrh", " $dst, [$base], $offset", "$base = $base_wb",
606                             []>;
607
608 def t2LDRSB_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
609                             (ins t2addrmode_imm8:$addr),
610                             AddrModeT2_i8, IndexModePre,
611                             "ldrsb", " $dst, $addr!", "$addr.base = $base_wb",
612                             []>;
613 def t2LDRSB_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
614                             (ins GPR:$base, t2am_imm8_offset:$offset),
615                             AddrModeT2_i8, IndexModePost,
616                          "ldrsb", " $dst, [$base], $offset", "$base = $base_wb",
617                             []>;
618
619 def t2LDRSH_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
620                             (ins t2addrmode_imm8:$addr),
621                             AddrModeT2_i8, IndexModePre,
622                             "ldrsh", " $dst, $addr!", "$addr.base = $base_wb",
623                             []>;
624 def t2LDRSH_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
625                             (ins GPR:$base, t2am_imm8_offset:$offset),
626                             AddrModeT2_i8, IndexModePost,
627                          "ldrsh", " $dst, [$base], $offset", "$base = $base_wb",
628                             []>;
629 }
630
631 // Store
632 defm t2STR   : T2I_st<"str",  BinOpFrag<(store node:$LHS, node:$RHS)>>;
633 defm t2STRB  : T2I_st<"strb", BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
634 defm t2STRH  : T2I_st<"strh", BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
635
636 // Store doubleword
637 let mayLoad = 1 in
638 def t2STRDi8 : T2Ii8s4<(outs), (ins GPR:$src, t2addrmode_imm8s4:$addr),
639                         "strd", " $src, $addr", []>;
640
641 // Indexed stores
642 def t2STR_PRE  : T2Iidxldst<(outs GPR:$base_wb),
643                             (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
644                             AddrModeT2_i8, IndexModePre,
645                           "str", " $src, [$base, $offset]!", "$base = $base_wb",
646              [(set GPR:$base_wb,
647                    (pre_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
648
649 def t2STR_POST : T2Iidxldst<(outs GPR:$base_wb),
650                             (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
651                             AddrModeT2_i8, IndexModePost,
652                            "str", " $src, [$base], $offset", "$base = $base_wb",
653              [(set GPR:$base_wb,
654                    (post_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
655
656 def t2STRH_PRE  : T2Iidxldst<(outs GPR:$base_wb),
657                             (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
658                             AddrModeT2_i8, IndexModePre,
659                          "strh", " $src, [$base, $offset]!", "$base = $base_wb",
660         [(set GPR:$base_wb,
661               (pre_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
662
663 def t2STRH_POST : T2Iidxldst<(outs GPR:$base_wb),
664                             (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
665                             AddrModeT2_i8, IndexModePost,
666                           "strh", " $src, [$base], $offset", "$base = $base_wb",
667        [(set GPR:$base_wb,
668              (post_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
669
670 def t2STRB_PRE  : T2Iidxldst<(outs GPR:$base_wb),
671                             (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
672                             AddrModeT2_i8, IndexModePre,
673                          "strb", " $src, [$base, $offset]!", "$base = $base_wb",
674          [(set GPR:$base_wb,
675                (pre_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
676
677 def t2STRB_POST : T2Iidxldst<(outs GPR:$base_wb),
678                             (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
679                             AddrModeT2_i8, IndexModePost,
680                           "strb", " $src, [$base], $offset", "$base = $base_wb",
681         [(set GPR:$base_wb,
682               (post_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
683
684
685 // Address computation and loads and stores in PIC mode.
686 let isNotDuplicable = 1, AddedComplexity = 10 in {
687 let canFoldAsLoad = 1 in
688 def t2PICLDR   : T2I_picld<"ldr",  UnOpFrag<(load node:$Src)>>;
689
690 def t2PICLDRH  : T2I_picld<"ldrh", UnOpFrag<(zextloadi16 node:$Src)>>;
691 def t2PICLDRB  : T2I_picld<"ldrb", UnOpFrag<(zextloadi8 node:$Src)>>;
692 def t2PICLDRSH : T2I_picld<"ldrsh", UnOpFrag<(sextloadi16 node:$Src)>>;
693 def t2PICLDRSB : T2I_picld<"ldrsb", UnOpFrag<(sextloadi8 node:$Src)>>;
694
695 def t2PICSTR   : T2I_picst<"str", BinOpFrag<(store node:$LHS, node:$RHS)>>;
696 def t2PICSTRH  : T2I_picst<"strh", BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
697 def t2PICSTRB  : T2I_picst<"strb", BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
698 } // isNotDuplicable = 1, AddedComplexity = 10
699
700
701 //===----------------------------------------------------------------------===//
702 //  Load / store multiple Instructions.
703 //
704
705 let mayLoad = 1 in
706 def t2LDM : T2XI<(outs),
707                  (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
708                  "ldm${p}${addr:submode} $addr, $dst1", []>;
709
710 let mayStore = 1 in
711 def t2STM : T2XI<(outs),
712                  (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
713                  "stm${p}${addr:submode} $addr, $src1", []>;
714
715 //===----------------------------------------------------------------------===//
716 //  Move Instructions.
717 //
718
719 let neverHasSideEffects = 1 in
720 def t2MOVr : T2sI<(outs GPR:$dst), (ins GPR:$src),
721                    "mov", " $dst, $src", []>;
722
723 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
724 def t2MOVi : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
725                    "mov", " $dst, $src",
726                    [(set GPR:$dst, t2_so_imm:$src)]>;
727
728 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
729 def t2MOVi16 : T2I<(outs GPR:$dst), (ins i32imm:$src),
730                    "movw", " $dst, $src",
731                    [(set GPR:$dst, imm0_65535:$src)]>;
732
733 // FIXME: Also available in ARM mode.
734 let Constraints = "$src = $dst" in
735 def t2MOVTi16 : T2sI<(outs GPR:$dst), (ins GPR:$src, i32imm:$imm),
736                      "movt", " $dst, $imm",
737                      [(set GPR:$dst,
738                            (or (and GPR:$src, 0xffff), t2_lo16AllZero:$imm))]>;
739
740 //===----------------------------------------------------------------------===//
741 //  Extend Instructions.
742 //
743
744 // Sign extenders
745
746 defm t2SXTB  : T2I_unary_rrot<"sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
747 defm t2SXTH  : T2I_unary_rrot<"sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
748
749 defm t2SXTAB : T2I_bin_rrot<"sxtab",
750                         BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
751 defm t2SXTAH : T2I_bin_rrot<"sxtah",
752                         BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
753
754 // TODO: SXT(A){B|H}16
755
756 // Zero extenders
757
758 let AddedComplexity = 16 in {
759 defm t2UXTB   : T2I_unary_rrot<"uxtb"  , UnOpFrag<(and node:$Src, 0x000000FF)>>;
760 defm t2UXTH   : T2I_unary_rrot<"uxth"  , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
761 defm t2UXTB16 : T2I_unary_rrot<"uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
762
763 def : T2Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
764             (t2UXTB16r_rot GPR:$Src, 24)>;
765 def : T2Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
766             (t2UXTB16r_rot GPR:$Src, 8)>;
767
768 defm t2UXTAB : T2I_bin_rrot<"uxtab",
769                             BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
770 defm t2UXTAH : T2I_bin_rrot<"uxtah",
771                             BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
772 }
773
774 //===----------------------------------------------------------------------===//
775 //  Arithmetic Instructions.
776 //
777
778 defm t2ADD  : T2I_bin_ii12rs<"add", BinOpFrag<(add  node:$LHS, node:$RHS)>, 1>;
779 defm t2SUB  : T2I_bin_ii12rs<"sub", BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
780
781 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
782 defm t2ADDS : T2I_bin_s_irs <"add",  BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
783 defm t2SUBS : T2I_bin_s_irs <"sub",  BinOpFrag<(subc node:$LHS, node:$RHS)>>;
784
785 defm t2ADC  : T2I_adde_sube_irs<"adc",BinOpFrag<(adde node:$LHS, node:$RHS)>,1>;
786 defm t2SBC  : T2I_adde_sube_irs<"sbc",BinOpFrag<(sube node:$LHS, node:$RHS)>>;
787
788 // RSB, RSC
789 defm t2RSB  : T2I_rbin_is   <"rsb", BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
790 defm t2RSBS : T2I_rbin_s_is <"rsb", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
791 defm t2RSC  : T2I_rsc_is    <"rsc", BinOpFrag<(sube node:$LHS, node:$RHS)>>;
792
793 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
794 def : T2Pat<(add       GPR:$src, t2_so_imm_neg:$imm),
795             (t2SUBri   GPR:$src, t2_so_imm_neg:$imm)>;
796 def : T2Pat<(add       GPR:$src, imm0_4095_neg:$imm),
797             (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
798
799
800 //===----------------------------------------------------------------------===//
801 //  Shift and rotate Instructions.
802 //
803
804 defm t2LSL  : T2I_sh_ir<"lsl", BinOpFrag<(shl  node:$LHS, node:$RHS)>>;
805 defm t2LSR  : T2I_sh_ir<"lsr", BinOpFrag<(srl  node:$LHS, node:$RHS)>>;
806 defm t2ASR  : T2I_sh_ir<"asr", BinOpFrag<(sra  node:$LHS, node:$RHS)>>;
807 defm t2ROR  : T2I_sh_ir<"ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
808
809 def t2MOVrx : T2sI<(outs GPR:$dst), (ins GPR:$src),
810                    "mov", " $dst, $src, rrx",
811                    [(set GPR:$dst, (ARMrrx GPR:$src))]>;
812
813 //===----------------------------------------------------------------------===//
814 //  Bitwise Instructions.
815 //
816
817 defm t2AND  : T2I_bin_irs<"and", BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
818 defm t2ORR  : T2I_bin_irs<"orr", BinOpFrag<(or  node:$LHS, node:$RHS)>, 1>;
819 defm t2EOR  : T2I_bin_irs<"eor", BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
820
821 defm t2BIC  : T2I_bin_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
822
823 def : T2Pat<(and     GPR:$src, t2_so_imm_not:$imm),
824             (t2BICri GPR:$src, t2_so_imm_not:$imm)>;
825
826 defm t2ORN  : T2I_bin_irs<"orn", BinOpFrag<(or  node:$LHS, (not node:$RHS))>>;
827
828 def : T2Pat<(or      GPR:$src, t2_so_imm_not:$imm),
829             (t2ORNri GPR:$src, t2_so_imm_not:$imm)>;
830
831 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
832 let AddedComplexity = 1 in
833 defm t2MVN  : T2I_un_irs  <"mvn", UnOpFrag<(not node:$Src)>, 1, 1>;
834
835 def : T2Pat<(t2_so_imm_not:$src),
836             (t2MVNi t2_so_imm_not:$src)>;
837
838 // A8.6.17  BFC - Bitfield clear
839 // FIXME: Also available in ARM mode.
840 let Constraints = "$src = $dst" in
841 def t2BFC : T2I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm),
842                 "bfc", " $dst, $imm",
843                 [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>;
844
845 // FIXME: A8.6.18  BFI - Bitfield insert (Encoding T1)
846
847 //===----------------------------------------------------------------------===//
848 //  Multiply Instructions.
849 //
850 let isCommutable = 1 in
851 def t2MUL: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
852                 "mul", " $dst, $a, $b",
853                 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
854
855 def t2MLA: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
856                 "mla", " $dst, $a, $b, $c",
857                 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
858
859 def t2MLS: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
860                 "mls", " $dst, $a, $b, $c",
861                 [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>;
862
863 // FIXME: SMULL, etc.
864
865 //===----------------------------------------------------------------------===//
866 //  Misc. Arithmetic Instructions.
867 //
868
869 def t2CLZ : T2I<(outs GPR:$dst), (ins GPR:$src),
870                 "clz", " $dst, $src",
871                 [(set GPR:$dst, (ctlz GPR:$src))]>;
872
873 def t2REV : T2I<(outs GPR:$dst), (ins GPR:$src),
874                 "rev", " $dst, $src",
875                 [(set GPR:$dst, (bswap GPR:$src))]>;
876
877 def t2REV16 : T2I<(outs GPR:$dst), (ins GPR:$src),
878                 "rev16", " $dst, $src",
879                 [(set GPR:$dst,
880                     (or (and (srl GPR:$src, (i32 8)), 0xFF),
881                         (or (and (shl GPR:$src, (i32 8)), 0xFF00),
882                             (or (and (srl GPR:$src, (i32 8)), 0xFF0000),
883                                 (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>;
884
885 /////
886 /// A8.6.137  REVSH
887 /////
888 def t2REVSH : T2I<(outs GPR:$dst), (ins GPR:$src),
889                  "revsh", " $dst, $src",
890                  [(set GPR:$dst,
891                     (sext_inreg
892                       (or (srl (and GPR:$src, 0xFFFF), (i32 8)),
893                           (shl GPR:$src, (i32 8))), i16))]>;
894
895 // FIXME: PKHxx etc.
896
897 //===----------------------------------------------------------------------===//
898 //  Comparison Instructions...
899 //
900
901 defm t2CMP   : T2I_cmp_is<"cmp",
902                           BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
903 defm t2CMPz : T2I_cmp_is<"cmp",
904                          BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
905
906 defm t2CMN   : T2I_cmp_is<"cmn",
907                           BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
908 defm t2CMNz : T2I_cmp_is<"cmn",
909                          BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
910
911 def : T2Pat<(ARMcmp  GPR:$src, t2_so_imm_neg:$imm),
912             (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
913
914 def : T2Pat<(ARMcmpZ  GPR:$src, t2_so_imm_neg:$imm),
915             (t2CMNri   GPR:$src, t2_so_imm_neg:$imm)>;
916
917 defm t2TST  : T2I_cmp_is<"tst",
918                          BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>>;
919 defm t2TEQ  : T2I_cmp_is<"teq",
920                          BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>>;
921
922 // A8.6.27  CBNZ, CBZ - Compare and branch on (non)zero.
923 // Short range conditional branch. Looks awesome for loops. Need to figure
924 // out how to use this one.
925
926 // FIXME: Conditional moves
927
928 //===----------------------------------------------------------------------===//
929 // Control-Flow Instructions
930 //
931
932 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
933 let isPredicable = 1 in
934 def t2B   : T2XI<(outs), (ins brtarget:$target),
935                  "b $target",
936                  [(br bb:$target)]>;
937
938 let isNotDuplicable = 1, isIndirectBranch = 1 in {
939 def t2BR_JTr : T2JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
940                      "mov pc, $target \n$jt",
941                      [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
942
943 def t2BR_JTm : 
944     T2JTI<(outs),
945           (ins t2addrmode_so_reg:$target, jtblock_operand:$jt, i32imm:$id),
946           "ldr pc, $target \n$jt",
947           [(ARMbrjt (i32 (load t2addrmode_so_reg:$target)), tjumptable:$jt,
948              imm:$id)]>;
949
950 def t2BR_JTadd : 
951     T2JTI<(outs),
952           (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
953           "add pc, $target, $idx \n$jt",
954           [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt, imm:$id)]>;
955 } // isNotDuplicate, isIndirectBranch
956 } // isBranch, isTerminator, isBarrier
957
958 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
959 // a two-value operand where a dag node expects two operands. :(
960 let isBranch = 1, isTerminator = 1 in
961 def t2Bcc : T2I<(outs), (ins brtarget:$target), 
962                 "b", " $target",
963                 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
964
965 //===----------------------------------------------------------------------===//
966 // Non-Instruction Patterns
967 //
968
969 // ConstantPool, GlobalAddress, and JumpTable
970 def : T2Pat<(ARMWrapper  tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>;
971 def : T2Pat<(ARMWrapper  tconstpool  :$dst), (t2LEApcrel tconstpool  :$dst)>;
972 def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
973             (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
974
975 // Large immediate handling.
976
977 def : T2Pat<(i32 imm:$src),
978             (t2MOVTi16 (t2MOVi16 (t2_lo16 imm:$src)), (t2_hi16 imm:$src))>;