ARMInstrThumb2.td revision 3bc8a3d3afe3ddda884a681002e24850099b719e
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// IT block predicate field
15def it_pred_asmoperand : AsmOperandClass {
16  let Name = "ITCondCode";
17  let ParserMethod = "parseITCondCode";
18}
19def it_pred : Operand<i32> {
20  let PrintMethod = "printMandatoryPredicateOperand";
21  let ParserMatchClass = it_pred_asmoperand;
22}
23
24// IT block condition mask
25def it_mask_asmoperand : AsmOperandClass { let Name = "ITMask"; }
26def it_mask : Operand<i32> {
27  let PrintMethod = "printThumbITMask";
28  let ParserMatchClass = it_mask_asmoperand;
29}
30
31// t2_shift_imm: An integer that encodes a shift amount and the type of shift
32// (asr or lsl). The 6-bit immediate encodes as:
33//    {5}     0 ==> lsl
34//            1     asr
35//    {4-0}   imm5 shift amount.
36//            asr #32 not allowed
37def t2_shift_imm : Operand<i32> {
38  let PrintMethod = "printShiftImmOperand";
39  let ParserMatchClass = ShifterImmAsmOperand;
40  let DecoderMethod = "DecodeT2ShifterImmOperand";
41}
42
43// Shifted operands. No register controlled shifts for Thumb2.
44// Note: We do not support rrx shifted operands yet.
45def t2_so_reg : Operand<i32>,    // reg imm
46                ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
47                               [shl,srl,sra,rotr]> {
48  let EncoderMethod = "getT2SORegOpValue";
49  let PrintMethod = "printT2SOOperand";
50  let DecoderMethod = "DecodeSORegImmOperand";
51  let ParserMatchClass = ShiftedImmAsmOperand;
52  let MIOperandInfo = (ops rGPR, i32imm);
53}
54
55// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
56def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
57  return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
58}]>;
59
60// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
61def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
62  return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
63}]>;
64
65// t2_so_imm - Match a 32-bit immediate operand, which is an
66// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
67// immediate splatted into multiple bytes of the word.
68def t2_so_imm_asmoperand : ImmAsmOperand { let Name = "T2SOImm"; }
69def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
70    return ARM_AM::getT2SOImmVal(Imm) != -1;
71  }]> {
72  let ParserMatchClass = t2_so_imm_asmoperand;
73  let EncoderMethod = "getT2SOImmOpValue";
74  let DecoderMethod = "DecodeT2SOImm";
75}
76
77// t2_so_imm_not - Match an immediate that is a complement
78// of a t2_so_imm.
79// Note: this pattern doesn't require an encoder method and such, as it's
80// only used on aliases (Pat<> and InstAlias<>). The actual encoding
81// is handled by the destination instructions, which use t2_so_imm.
82def t2_so_imm_not_asmoperand : AsmOperandClass { let Name = "T2SOImmNot"; }
83def t2_so_imm_not : Operand<i32>, PatLeaf<(imm), [{
84  return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
85}], t2_so_imm_not_XFORM> {
86  let ParserMatchClass = t2_so_imm_not_asmoperand;
87}
88
89// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
90def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; }
91def t2_so_imm_neg : Operand<i32>, PatLeaf<(imm), [{
92  return ARM_AM::getT2SOImmVal(-((uint32_t)N->getZExtValue())) != -1;
93}], t2_so_imm_neg_XFORM> {
94  let ParserMatchClass = t2_so_imm_neg_asmoperand;
95}
96
97/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
98def imm0_4095 : Operand<i32>,
99                ImmLeaf<i32, [{
100  return Imm >= 0 && Imm < 4096;
101}]>;
102
103def imm0_4095_neg : PatLeaf<(i32 imm), [{
104 return (uint32_t)(-N->getZExtValue()) < 4096;
105}], imm_neg_XFORM>;
106
107def imm0_255_neg : PatLeaf<(i32 imm), [{
108  return (uint32_t)(-N->getZExtValue()) < 255;
109}], imm_neg_XFORM>;
110
111def imm0_255_not : PatLeaf<(i32 imm), [{
112  return (uint32_t)(~N->getZExtValue()) < 255;
113}], imm_comp_XFORM>;
114
115def lo5AllOne : PatLeaf<(i32 imm), [{
116  // Returns true if all low 5-bits are 1.
117  return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
118}]>;
119
120// Define Thumb2 specific addressing modes.
121
122// t2addrmode_imm12  := reg + imm12
123def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";}
124def t2addrmode_imm12 : Operand<i32>,
125                       ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
126  let PrintMethod = "printAddrModeImm12Operand";
127  let EncoderMethod = "getAddrModeImm12OpValue";
128  let DecoderMethod = "DecodeT2AddrModeImm12";
129  let ParserMatchClass = t2addrmode_imm12_asmoperand;
130  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
131}
132
133// t2ldrlabel  := imm12
134def t2ldrlabel : Operand<i32> {
135  let EncoderMethod = "getAddrModeImm12OpValue";
136  let PrintMethod = "printT2LdrLabelOperand";
137}
138
139
140// ADR instruction labels.
141def t2adrlabel : Operand<i32> {
142  let EncoderMethod = "getT2AdrLabelOpValue";
143}
144
145
146// t2addrmode_posimm8  := reg + imm8
147def MemPosImm8OffsetAsmOperand : AsmOperandClass {let Name="MemPosImm8Offset";}
148def t2addrmode_posimm8 : Operand<i32> {
149  let PrintMethod = "printT2AddrModeImm8Operand";
150  let EncoderMethod = "getT2AddrModeImm8OpValue";
151  let DecoderMethod = "DecodeT2AddrModeImm8";
152  let ParserMatchClass = MemPosImm8OffsetAsmOperand;
153  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
154}
155
156// t2addrmode_negimm8  := reg - imm8
157def MemNegImm8OffsetAsmOperand : AsmOperandClass {let Name="MemNegImm8Offset";}
158def t2addrmode_negimm8 : Operand<i32>,
159                      ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
160  let PrintMethod = "printT2AddrModeImm8Operand";
161  let EncoderMethod = "getT2AddrModeImm8OpValue";
162  let DecoderMethod = "DecodeT2AddrModeImm8";
163  let ParserMatchClass = MemNegImm8OffsetAsmOperand;
164  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
165}
166
167// t2addrmode_imm8  := reg +/- imm8
168def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; }
169def t2addrmode_imm8 : Operand<i32>,
170                      ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
171  let PrintMethod = "printT2AddrModeImm8Operand";
172  let EncoderMethod = "getT2AddrModeImm8OpValue";
173  let DecoderMethod = "DecodeT2AddrModeImm8";
174  let ParserMatchClass = MemImm8OffsetAsmOperand;
175  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
176}
177
178def t2am_imm8_offset : Operand<i32>,
179                       ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
180                                      [], [SDNPWantRoot]> {
181  let PrintMethod = "printT2AddrModeImm8OffsetOperand";
182  let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
183  let DecoderMethod = "DecodeT2Imm8";
184}
185
186// t2addrmode_imm8s4  := reg +/- (imm8 << 2)
187def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";}
188def t2addrmode_imm8s4 : Operand<i32> {
189  let PrintMethod = "printT2AddrModeImm8s4Operand";
190  let EncoderMethod = "getT2AddrModeImm8s4OpValue";
191  let DecoderMethod = "DecodeT2AddrModeImm8s4";
192  let ParserMatchClass = MemImm8s4OffsetAsmOperand;
193  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
194}
195
196def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
197def t2am_imm8s4_offset : Operand<i32> {
198  let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
199  let EncoderMethod = "getT2Imm8s4OpValue";
200  let DecoderMethod = "DecodeT2Imm8S4";
201}
202
203// t2addrmode_imm0_1020s4  := reg + (imm8 << 2)
204def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
205  let Name = "MemImm0_1020s4Offset";
206}
207def t2addrmode_imm0_1020s4 : Operand<i32> {
208  let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
209  let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
210  let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
211  let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
212  let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
213}
214
215// t2addrmode_so_reg  := reg + (reg << imm2)
216def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
217def t2addrmode_so_reg : Operand<i32>,
218                        ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
219  let PrintMethod = "printT2AddrModeSoRegOperand";
220  let EncoderMethod = "getT2AddrModeSORegOpValue";
221  let DecoderMethod = "DecodeT2AddrModeSOReg";
222  let ParserMatchClass = t2addrmode_so_reg_asmoperand;
223  let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
224}
225
226// Addresses for the TBB/TBH instructions.
227def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
228def addrmode_tbb : Operand<i32> {
229  let PrintMethod = "printAddrModeTBB";
230  let ParserMatchClass = addrmode_tbb_asmoperand;
231  let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
232}
233def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
234def addrmode_tbh : Operand<i32> {
235  let PrintMethod = "printAddrModeTBH";
236  let ParserMatchClass = addrmode_tbh_asmoperand;
237  let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
238}
239
240//===----------------------------------------------------------------------===//
241// Multiclass helpers...
242//
243
244
245class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
246           string opc, string asm, list<dag> pattern>
247  : T2I<oops, iops, itin, opc, asm, pattern> {
248  bits<4> Rd;
249  bits<12> imm;
250
251  let Inst{11-8}  = Rd;
252  let Inst{26}    = imm{11};
253  let Inst{14-12} = imm{10-8};
254  let Inst{7-0}   = imm{7-0};
255}
256
257
258class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
259           string opc, string asm, list<dag> pattern>
260  : T2sI<oops, iops, itin, opc, asm, pattern> {
261  bits<4> Rd;
262  bits<4> Rn;
263  bits<12> imm;
264
265  let Inst{11-8}  = Rd;
266  let Inst{26}    = imm{11};
267  let Inst{14-12} = imm{10-8};
268  let Inst{7-0}   = imm{7-0};
269}
270
271class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
272           string opc, string asm, list<dag> pattern>
273  : T2I<oops, iops, itin, opc, asm, pattern> {
274  bits<4> Rn;
275  bits<12> imm;
276
277  let Inst{19-16}  = Rn;
278  let Inst{26}    = imm{11};
279  let Inst{14-12} = imm{10-8};
280  let Inst{7-0}   = imm{7-0};
281}
282
283
284class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
285           string opc, string asm, list<dag> pattern>
286  : T2I<oops, iops, itin, opc, asm, pattern> {
287  bits<4> Rd;
288  bits<12> ShiftedRm;
289
290  let Inst{11-8}  = Rd;
291  let Inst{3-0}   = ShiftedRm{3-0};
292  let Inst{5-4}   = ShiftedRm{6-5};
293  let Inst{14-12} = ShiftedRm{11-9};
294  let Inst{7-6}   = ShiftedRm{8-7};
295}
296
297class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
298           string opc, string asm, list<dag> pattern>
299  : T2sI<oops, iops, itin, opc, asm, pattern> {
300  bits<4> Rd;
301  bits<12> ShiftedRm;
302
303  let Inst{11-8}  = Rd;
304  let Inst{3-0}   = ShiftedRm{3-0};
305  let Inst{5-4}   = ShiftedRm{6-5};
306  let Inst{14-12} = ShiftedRm{11-9};
307  let Inst{7-6}   = ShiftedRm{8-7};
308}
309
310class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
311           string opc, string asm, list<dag> pattern>
312  : T2I<oops, iops, itin, opc, asm, pattern> {
313  bits<4> Rn;
314  bits<12> ShiftedRm;
315
316  let Inst{19-16} = Rn;
317  let Inst{3-0}   = ShiftedRm{3-0};
318  let Inst{5-4}   = ShiftedRm{6-5};
319  let Inst{14-12} = ShiftedRm{11-9};
320  let Inst{7-6}   = ShiftedRm{8-7};
321}
322
323class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
324           string opc, string asm, list<dag> pattern>
325  : T2I<oops, iops, itin, opc, asm, pattern> {
326  bits<4> Rd;
327  bits<4> Rm;
328
329  let Inst{11-8}  = Rd;
330  let Inst{3-0}   = Rm;
331}
332
333class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
334           string opc, string asm, list<dag> pattern>
335  : T2sI<oops, iops, itin, opc, asm, pattern> {
336  bits<4> Rd;
337  bits<4> Rm;
338
339  let Inst{11-8}  = Rd;
340  let Inst{3-0}   = Rm;
341}
342
343class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
344           string opc, string asm, list<dag> pattern>
345  : T2I<oops, iops, itin, opc, asm, pattern> {
346  bits<4> Rn;
347  bits<4> Rm;
348
349  let Inst{19-16} = Rn;
350  let Inst{3-0}   = Rm;
351}
352
353
354class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
355           string opc, string asm, list<dag> pattern>
356  : T2I<oops, iops, itin, opc, asm, pattern> {
357  bits<4> Rd;
358  bits<4> Rn;
359  bits<12> imm;
360
361  let Inst{11-8}  = Rd;
362  let Inst{19-16} = Rn;
363  let Inst{26}    = imm{11};
364  let Inst{14-12} = imm{10-8};
365  let Inst{7-0}   = imm{7-0};
366}
367
368class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
369           string opc, string asm, list<dag> pattern>
370  : T2sI<oops, iops, itin, opc, asm, pattern> {
371  bits<4> Rd;
372  bits<4> Rn;
373  bits<12> imm;
374
375  let Inst{11-8}  = Rd;
376  let Inst{19-16} = Rn;
377  let Inst{26}    = imm{11};
378  let Inst{14-12} = imm{10-8};
379  let Inst{7-0}   = imm{7-0};
380}
381
382class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
383           string opc, string asm, list<dag> pattern>
384  : T2I<oops, iops, itin, opc, asm, pattern> {
385  bits<4> Rd;
386  bits<4> Rm;
387  bits<5> imm;
388
389  let Inst{11-8}  = Rd;
390  let Inst{3-0}   = Rm;
391  let Inst{14-12} = imm{4-2};
392  let Inst{7-6}   = imm{1-0};
393}
394
395class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
396           string opc, string asm, list<dag> pattern>
397  : T2sI<oops, iops, itin, opc, asm, pattern> {
398  bits<4> Rd;
399  bits<4> Rm;
400  bits<5> imm;
401
402  let Inst{11-8}  = Rd;
403  let Inst{3-0}   = Rm;
404  let Inst{14-12} = imm{4-2};
405  let Inst{7-6}   = imm{1-0};
406}
407
408class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
409           string opc, string asm, list<dag> pattern>
410  : T2I<oops, iops, itin, opc, asm, pattern> {
411  bits<4> Rd;
412  bits<4> Rn;
413  bits<4> Rm;
414
415  let Inst{11-8}  = Rd;
416  let Inst{19-16} = Rn;
417  let Inst{3-0}   = Rm;
418}
419
420class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
421           string opc, string asm, list<dag> pattern>
422  : T2sI<oops, iops, itin, opc, asm, pattern> {
423  bits<4> Rd;
424  bits<4> Rn;
425  bits<4> Rm;
426
427  let Inst{11-8}  = Rd;
428  let Inst{19-16} = Rn;
429  let Inst{3-0}   = Rm;
430}
431
432class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
433           string opc, string asm, list<dag> pattern>
434  : T2I<oops, iops, itin, opc, asm, pattern> {
435  bits<4> Rd;
436  bits<4> Rn;
437  bits<12> ShiftedRm;
438
439  let Inst{11-8}  = Rd;
440  let Inst{19-16} = Rn;
441  let Inst{3-0}   = ShiftedRm{3-0};
442  let Inst{5-4}   = ShiftedRm{6-5};
443  let Inst{14-12} = ShiftedRm{11-9};
444  let Inst{7-6}   = ShiftedRm{8-7};
445}
446
447class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
448           string opc, string asm, list<dag> pattern>
449  : T2sI<oops, iops, itin, opc, asm, pattern> {
450  bits<4> Rd;
451  bits<4> Rn;
452  bits<12> ShiftedRm;
453
454  let Inst{11-8}  = Rd;
455  let Inst{19-16} = Rn;
456  let Inst{3-0}   = ShiftedRm{3-0};
457  let Inst{5-4}   = ShiftedRm{6-5};
458  let Inst{14-12} = ShiftedRm{11-9};
459  let Inst{7-6}   = ShiftedRm{8-7};
460}
461
462class T2FourReg<dag oops, dag iops, InstrItinClass itin,
463           string opc, string asm, list<dag> pattern>
464  : T2I<oops, iops, itin, opc, asm, pattern> {
465  bits<4> Rd;
466  bits<4> Rn;
467  bits<4> Rm;
468  bits<4> Ra;
469
470  let Inst{19-16} = Rn;
471  let Inst{15-12} = Ra;
472  let Inst{11-8}  = Rd;
473  let Inst{3-0}   = Rm;
474}
475
476class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
477                dag oops, dag iops, InstrItinClass itin,
478                string opc, string asm, list<dag> pattern>
479  : T2I<oops, iops, itin, opc, asm, pattern> {
480  bits<4> RdLo;
481  bits<4> RdHi;
482  bits<4> Rn;
483  bits<4> Rm;
484
485  let Inst{31-23} = 0b111110111;
486  let Inst{22-20} = opc22_20;
487  let Inst{19-16} = Rn;
488  let Inst{15-12} = RdLo;
489  let Inst{11-8}  = RdHi;
490  let Inst{7-4}   = opc7_4;
491  let Inst{3-0}   = Rm;
492}
493
494
495/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
496/// binary operation that produces a value. These are predicable and can be
497/// changed to modify CPSR.
498multiclass T2I_bin_irs<bits<4> opcod, string opc,
499                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
500                       PatFrag opnode, string baseOpc, bit Commutable = 0,
501                       string wide = ""> {
502   // shifted imm
503   def ri : T2sTwoRegImm<
504                (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
505                 opc, "\t$Rd, $Rn, $imm",
506                 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> {
507     let Inst{31-27} = 0b11110;
508     let Inst{25} = 0;
509     let Inst{24-21} = opcod;
510     let Inst{15} = 0;
511   }
512   // register
513   def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
514                 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
515                 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
516     let isCommutable = Commutable;
517     let Inst{31-27} = 0b11101;
518     let Inst{26-25} = 0b01;
519     let Inst{24-21} = opcod;
520     let Inst{14-12} = 0b000; // imm3
521     let Inst{7-6} = 0b00; // imm2
522     let Inst{5-4} = 0b00; // type
523   }
524   // shifted register
525   def rs : T2sTwoRegShiftedReg<
526                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
527                 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
528                 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> {
529     let Inst{31-27} = 0b11101;
530     let Inst{26-25} = 0b01;
531     let Inst{24-21} = opcod;
532   }
533  // Assembly aliases for optional destination operand when it's the same
534  // as the source operand.
535  def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
536     (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn,
537                                                    t2_so_imm:$imm, pred:$p,
538                                                    cc_out:$s)>;
539  def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
540     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
541                                                    rGPR:$Rm, pred:$p,
542                                                    cc_out:$s)>;
543  def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
544     (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rdn, rGPR:$Rdn,
545                                                    t2_so_reg:$shift, pred:$p,
546                                                    cc_out:$s)>;
547}
548
549/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
550//  the ".w" suffix to indicate that they are wide.
551multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
552                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
553                         PatFrag opnode, string baseOpc, bit Commutable = 0> :
554    T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, baseOpc, Commutable, ".w"> {
555  // Assembler aliases w/o the ".w" suffix.
556  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
557     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rd, rGPR:$Rn,
558                                                    rGPR:$Rm, pred:$p,
559                                                    cc_out:$s)>;
560  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
561     (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rd, rGPR:$Rn,
562                                                    t2_so_reg:$shift, pred:$p,
563                                                    cc_out:$s)>;
564
565  // and with the optional destination operand, too.
566  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
567     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
568                                                    rGPR:$Rm, pred:$p,
569                                                    cc_out:$s)>;
570  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
571     (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rdn, rGPR:$Rdn,
572                                                    t2_so_reg:$shift, pred:$p,
573                                                    cc_out:$s)>;
574}
575
576/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
577/// reversed.  The 'rr' form is only defined for the disassembler; for codegen
578/// it is equivalent to the T2I_bin_irs counterpart.
579multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
580   // shifted imm
581   def ri : T2sTwoRegImm<
582                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
583                 opc, ".w\t$Rd, $Rn, $imm",
584                 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
585     let Inst{31-27} = 0b11110;
586     let Inst{25} = 0;
587     let Inst{24-21} = opcod;
588     let Inst{15} = 0;
589   }
590   // register
591   def rr : T2sThreeReg<
592                 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
593                 opc, "\t$Rd, $Rn, $Rm",
594                 [/* For disassembly only; pattern left blank */]> {
595     let Inst{31-27} = 0b11101;
596     let Inst{26-25} = 0b01;
597     let Inst{24-21} = opcod;
598     let Inst{14-12} = 0b000; // imm3
599     let Inst{7-6} = 0b00; // imm2
600     let Inst{5-4} = 0b00; // type
601   }
602   // shifted register
603   def rs : T2sTwoRegShiftedReg<
604                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
605                 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
606                 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
607     let Inst{31-27} = 0b11101;
608     let Inst{26-25} = 0b01;
609     let Inst{24-21} = opcod;
610   }
611}
612
613/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
614/// instruction modifies the CPSR register.
615///
616/// These opcodes will be converted to the real non-S opcodes by
617/// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
618let hasPostISelHook = 1, Defs = [CPSR] in {
619multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
620                         InstrItinClass iis, PatFrag opnode,
621                         bit Commutable = 0> {
622   // shifted imm
623   def ri : t2PseudoInst<(outs rGPR:$Rd),
624                         (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
625                         4, iii,
626                         [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
627                                                t2_so_imm:$imm))]>;
628   // register
629   def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p),
630                         4, iir,
631                         [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
632                                                rGPR:$Rm))]> {
633     let isCommutable = Commutable;
634   }
635   // shifted register
636   def rs : t2PseudoInst<(outs rGPR:$Rd),
637                         (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
638                         4, iis,
639                         [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
640                                                t2_so_reg:$ShiftedRm))]>;
641}
642}
643
644/// T2I_rbin_s_is -  Same as T2I_bin_s_irs, except selection DAG
645/// operands are reversed.
646let hasPostISelHook = 1, Defs = [CPSR] in {
647multiclass T2I_rbin_s_is<PatFrag opnode> {
648   // shifted imm
649   def ri : t2PseudoInst<(outs rGPR:$Rd),
650                         (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
651                         4, IIC_iALUi,
652                         [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm,
653                                                GPRnopc:$Rn))]>;
654   // shifted register
655   def rs : t2PseudoInst<(outs rGPR:$Rd),
656                         (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
657                         4, IIC_iALUsi,
658                         [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm,
659                                                GPRnopc:$Rn))]>;
660}
661}
662
663/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
664/// patterns for a binary operation that produces a value.
665multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
666                          bit Commutable = 0> {
667   // shifted imm
668   // The register-immediate version is re-materializable. This is useful
669   // in particular for taking the address of a local.
670   let isReMaterializable = 1 in {
671   def ri : T2sTwoRegImm<
672               (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
673               opc, ".w\t$Rd, $Rn, $imm",
674               [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]> {
675     let Inst{31-27} = 0b11110;
676     let Inst{25} = 0;
677     let Inst{24} = 1;
678     let Inst{23-21} = op23_21;
679     let Inst{15} = 0;
680   }
681   }
682   // 12-bit imm
683   def ri12 : T2I<
684                  (outs GPRnopc:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
685                  !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
686                  [(set GPRnopc:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> {
687     bits<4> Rd;
688     bits<4> Rn;
689     bits<12> imm;
690     let Inst{31-27} = 0b11110;
691     let Inst{26} = imm{11};
692     let Inst{25-24} = 0b10;
693     let Inst{23-21} = op23_21;
694     let Inst{20} = 0; // The S bit.
695     let Inst{19-16} = Rn;
696     let Inst{15} = 0;
697     let Inst{14-12} = imm{10-8};
698     let Inst{11-8} = Rd;
699     let Inst{7-0} = imm{7-0};
700   }
701   // register
702   def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm),
703                 IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm",
704                 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]> {
705     let isCommutable = Commutable;
706     let Inst{31-27} = 0b11101;
707     let Inst{26-25} = 0b01;
708     let Inst{24} = 1;
709     let Inst{23-21} = op23_21;
710     let Inst{14-12} = 0b000; // imm3
711     let Inst{7-6} = 0b00; // imm2
712     let Inst{5-4} = 0b00; // type
713   }
714   // shifted register
715   def rs : T2sTwoRegShiftedReg<
716                 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
717                 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
718              [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]> {
719     let Inst{31-27} = 0b11101;
720     let Inst{26-25} = 0b01;
721     let Inst{24} = 1;
722     let Inst{23-21} = op23_21;
723   }
724}
725
726/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
727/// for a binary operation that produces a value and use the carry
728/// bit. It's not predicable.
729let Defs = [CPSR], Uses = [CPSR] in {
730multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
731                             bit Commutable = 0> {
732   // shifted imm
733   def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
734                 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
735               [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
736                 Requires<[IsThumb2]> {
737     let Inst{31-27} = 0b11110;
738     let Inst{25} = 0;
739     let Inst{24-21} = opcod;
740     let Inst{15} = 0;
741   }
742   // register
743   def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
744                 opc, ".w\t$Rd, $Rn, $Rm",
745                 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
746                 Requires<[IsThumb2]> {
747     let isCommutable = Commutable;
748     let Inst{31-27} = 0b11101;
749     let Inst{26-25} = 0b01;
750     let Inst{24-21} = opcod;
751     let Inst{14-12} = 0b000; // imm3
752     let Inst{7-6} = 0b00; // imm2
753     let Inst{5-4} = 0b00; // type
754   }
755   // shifted register
756   def rs : T2sTwoRegShiftedReg<
757                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
758                 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
759         [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
760                 Requires<[IsThumb2]> {
761     let Inst{31-27} = 0b11101;
762     let Inst{26-25} = 0b01;
763     let Inst{24-21} = opcod;
764   }
765}
766}
767
768/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
769//  rotate operation that produces a value.
770multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, PatFrag opnode,
771                     string baseOpc> {
772   // 5-bit imm
773   def ri : T2sTwoRegShiftImm<
774                 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
775                 opc, ".w\t$Rd, $Rm, $imm",
776                 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]> {
777     let Inst{31-27} = 0b11101;
778     let Inst{26-21} = 0b010010;
779     let Inst{19-16} = 0b1111; // Rn
780     let Inst{5-4} = opcod;
781   }
782   // register
783   def rr : T2sThreeReg<
784                 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
785                 opc, ".w\t$Rd, $Rn, $Rm",
786                 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
787     let Inst{31-27} = 0b11111;
788     let Inst{26-23} = 0b0100;
789     let Inst{22-21} = opcod;
790     let Inst{15-12} = 0b1111;
791     let Inst{7-4} = 0b0000;
792   }
793
794  // Optional destination register
795  def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
796     (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn,
797                                                    ty:$imm, pred:$p,
798                                                    cc_out:$s)>;
799  def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
800     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
801                                                    rGPR:$Rm, pred:$p,
802                                                    cc_out:$s)>;
803
804  // Assembler aliases w/o the ".w" suffix.
805  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
806     (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rd, rGPR:$Rn,
807                                                    ty:$imm, pred:$p,
808                                                   cc_out:$s)>;
809  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
810     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rd, rGPR:$Rn,
811                                                    rGPR:$Rm, pred:$p,
812                                                    cc_out:$s)>;
813
814  // and with the optional destination operand, too.
815  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
816     (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn,
817                                                    ty:$imm, pred:$p,
818                                                    cc_out:$s)>;
819  def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
820     (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
821                                                    rGPR:$Rm, pred:$p,
822                                                    cc_out:$s)>;
823}
824
825/// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
826/// patterns. Similar to T2I_bin_irs except the instruction does not produce
827/// a explicit result, only implicitly set CPSR.
828multiclass T2I_cmp_irs<bits<4> opcod, string opc,
829                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
830                       PatFrag opnode, string baseOpc> {
831let isCompare = 1, Defs = [CPSR] in {
832   // shifted imm
833   def ri : T2OneRegCmpImm<
834                (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), iii,
835                opc, ".w\t$Rn, $imm",
836                [(opnode GPRnopc:$Rn, t2_so_imm:$imm)]> {
837     let Inst{31-27} = 0b11110;
838     let Inst{25} = 0;
839     let Inst{24-21} = opcod;
840     let Inst{20} = 1; // The S bit.
841     let Inst{15} = 0;
842     let Inst{11-8} = 0b1111; // Rd
843   }
844   // register
845   def rr : T2TwoRegCmp<
846                (outs), (ins GPRnopc:$Rn, rGPR:$Rm), iir,
847                opc, ".w\t$Rn, $Rm",
848                [(opnode GPRnopc:$Rn, rGPR:$Rm)]> {
849     let Inst{31-27} = 0b11101;
850     let Inst{26-25} = 0b01;
851     let Inst{24-21} = opcod;
852     let Inst{20} = 1; // The S bit.
853     let Inst{14-12} = 0b000; // imm3
854     let Inst{11-8} = 0b1111; // Rd
855     let Inst{7-6} = 0b00; // imm2
856     let Inst{5-4} = 0b00; // type
857   }
858   // shifted register
859   def rs : T2OneRegCmpShiftedReg<
860                (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), iis,
861                opc, ".w\t$Rn, $ShiftedRm",
862                [(opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]> {
863     let Inst{31-27} = 0b11101;
864     let Inst{26-25} = 0b01;
865     let Inst{24-21} = opcod;
866     let Inst{20} = 1; // The S bit.
867     let Inst{11-8} = 0b1111; // Rd
868   }
869}
870
871  // Assembler aliases w/o the ".w" suffix.
872  // No alias here for 'rr' version as not all instantiations of this
873  // multiclass want one (CMP in particular, does not).
874  def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
875     (!cast<Instruction>(!strconcat(baseOpc, "ri")) GPRnopc:$Rn,
876                                                    t2_so_imm:$imm, pred:$p)>;
877  def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
878     (!cast<Instruction>(!strconcat(baseOpc, "rs")) GPRnopc:$Rn,
879                                                    t2_so_reg:$shift,
880                                                    pred:$p)>;
881}
882
883/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
884multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
885                  InstrItinClass iii, InstrItinClass iis, RegisterClass target,
886                  PatFrag opnode> {
887  def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
888                   opc, ".w\t$Rt, $addr",
889                   [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]> {
890    bits<4> Rt;
891    bits<17> addr;
892    let Inst{31-25} = 0b1111100;
893    let Inst{24} = signed;
894    let Inst{23} = 1;
895    let Inst{22-21} = opcod;
896    let Inst{20} = 1; // load
897    let Inst{19-16} = addr{16-13}; // Rn
898    let Inst{15-12} = Rt;
899    let Inst{11-0}  = addr{11-0};  // imm
900  }
901  def i8  : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
902                   opc, "\t$Rt, $addr",
903                   [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]> {
904    bits<4> Rt;
905    bits<13> addr;
906    let Inst{31-27} = 0b11111;
907    let Inst{26-25} = 0b00;
908    let Inst{24} = signed;
909    let Inst{23} = 0;
910    let Inst{22-21} = opcod;
911    let Inst{20} = 1; // load
912    let Inst{19-16} = addr{12-9}; // Rn
913    let Inst{15-12} = Rt;
914    let Inst{11} = 1;
915    // Offset: index==TRUE, wback==FALSE
916    let Inst{10} = 1; // The P bit.
917    let Inst{9}     = addr{8};    // U
918    let Inst{8} = 0; // The W bit.
919    let Inst{7-0}   = addr{7-0};  // imm
920  }
921  def s   : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
922                   opc, ".w\t$Rt, $addr",
923                   [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]> {
924    let Inst{31-27} = 0b11111;
925    let Inst{26-25} = 0b00;
926    let Inst{24} = signed;
927    let Inst{23} = 0;
928    let Inst{22-21} = opcod;
929    let Inst{20} = 1; // load
930    let Inst{11-6} = 0b000000;
931
932    bits<4> Rt;
933    let Inst{15-12} = Rt;
934
935    bits<10> addr;
936    let Inst{19-16} = addr{9-6}; // Rn
937    let Inst{3-0}   = addr{5-2}; // Rm
938    let Inst{5-4}   = addr{1-0}; // imm
939
940    let DecoderMethod = "DecodeT2LoadShift";
941  }
942
943  // FIXME: Is the pci variant actually needed?
944  def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
945                   opc, ".w\t$Rt, $addr",
946                   [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> {
947    let isReMaterializable = 1;
948    let Inst{31-27} = 0b11111;
949    let Inst{26-25} = 0b00;
950    let Inst{24} = signed;
951    let Inst{23} = ?; // add = (U == '1')
952    let Inst{22-21} = opcod;
953    let Inst{20} = 1; // load
954    let Inst{19-16} = 0b1111; // Rn
955    bits<4> Rt;
956    bits<12> addr;
957    let Inst{15-12} = Rt{3-0};
958    let Inst{11-0}  = addr{11-0};
959  }
960}
961
962/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
963multiclass T2I_st<bits<2> opcod, string opc,
964                  InstrItinClass iii, InstrItinClass iis, RegisterClass target,
965                  PatFrag opnode> {
966  def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
967                   opc, ".w\t$Rt, $addr",
968                   [(opnode target:$Rt, t2addrmode_imm12:$addr)]> {
969    let Inst{31-27} = 0b11111;
970    let Inst{26-23} = 0b0001;
971    let Inst{22-21} = opcod;
972    let Inst{20} = 0; // !load
973
974    bits<4> Rt;
975    let Inst{15-12} = Rt;
976
977    bits<17> addr;
978    let addr{12}    = 1;           // add = TRUE
979    let Inst{19-16} = addr{16-13}; // Rn
980    let Inst{23}    = addr{12};    // U
981    let Inst{11-0}  = addr{11-0};  // imm
982  }
983  def i8  : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
984                   opc, "\t$Rt, $addr",
985                   [(opnode target:$Rt, t2addrmode_negimm8:$addr)]> {
986    let Inst{31-27} = 0b11111;
987    let Inst{26-23} = 0b0000;
988    let Inst{22-21} = opcod;
989    let Inst{20} = 0; // !load
990    let Inst{11} = 1;
991    // Offset: index==TRUE, wback==FALSE
992    let Inst{10} = 1; // The P bit.
993    let Inst{8} = 0; // The W bit.
994
995    bits<4> Rt;
996    let Inst{15-12} = Rt;
997
998    bits<13> addr;
999    let Inst{19-16} = addr{12-9}; // Rn
1000    let Inst{9}     = addr{8};    // U
1001    let Inst{7-0}   = addr{7-0};  // imm
1002  }
1003  def s   : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
1004                   opc, ".w\t$Rt, $addr",
1005                   [(opnode target:$Rt, t2addrmode_so_reg:$addr)]> {
1006    let Inst{31-27} = 0b11111;
1007    let Inst{26-23} = 0b0000;
1008    let Inst{22-21} = opcod;
1009    let Inst{20} = 0; // !load
1010    let Inst{11-6} = 0b000000;
1011
1012    bits<4> Rt;
1013    let Inst{15-12} = Rt;
1014
1015    bits<10> addr;
1016    let Inst{19-16}   = addr{9-6}; // Rn
1017    let Inst{3-0} = addr{5-2}; // Rm
1018    let Inst{5-4}   = addr{1-0}; // imm
1019  }
1020}
1021
1022/// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
1023/// register and one whose operand is a register rotated by 8/16/24.
1024class T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode>
1025  : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
1026             opc, ".w\t$Rd, $Rm$rot",
1027             [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1028             Requires<[IsThumb2]> {
1029   let Inst{31-27} = 0b11111;
1030   let Inst{26-23} = 0b0100;
1031   let Inst{22-20} = opcod;
1032   let Inst{19-16} = 0b1111; // Rn
1033   let Inst{15-12} = 0b1111;
1034   let Inst{7} = 1;
1035
1036   bits<2> rot;
1037   let Inst{5-4} = rot{1-0}; // rotate
1038}
1039
1040// UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
1041class T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode>
1042  : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot),
1043             IIC_iEXTr, opc, "\t$Rd, $Rm$rot",
1044            [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1045          Requires<[HasT2ExtractPack, IsThumb2]> {
1046  bits<2> rot;
1047  let Inst{31-27} = 0b11111;
1048  let Inst{26-23} = 0b0100;
1049  let Inst{22-20} = opcod;
1050  let Inst{19-16} = 0b1111; // Rn
1051  let Inst{15-12} = 0b1111;
1052  let Inst{7} = 1;
1053  let Inst{5-4} = rot;
1054}
1055
1056// SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
1057// supported yet.
1058class T2I_ext_rrot_sxtb16<bits<3> opcod, string opc>
1059  : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
1060             opc, "\t$Rd, $Rm$rot", []>,
1061          Requires<[IsThumb2, HasT2ExtractPack]> {
1062  bits<2> rot;
1063  let Inst{31-27} = 0b11111;
1064  let Inst{26-23} = 0b0100;
1065  let Inst{22-20} = opcod;
1066  let Inst{19-16} = 0b1111; // Rn
1067  let Inst{15-12} = 0b1111;
1068  let Inst{7} = 1;
1069  let Inst{5-4} = rot;
1070}
1071
1072/// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
1073/// register and one whose operand is a register rotated by 8/16/24.
1074class T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode>
1075  : T2ThreeReg<(outs rGPR:$Rd),
1076               (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1077               IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot",
1078             [(set rGPR:$Rd, (opnode rGPR:$Rn, (rotr rGPR:$Rm,rot_imm:$rot)))]>,
1079           Requires<[HasT2ExtractPack, IsThumb2]> {
1080  bits<2> rot;
1081  let Inst{31-27} = 0b11111;
1082  let Inst{26-23} = 0b0100;
1083  let Inst{22-20} = opcod;
1084  let Inst{15-12} = 0b1111;
1085  let Inst{7} = 1;
1086  let Inst{5-4} = rot;
1087}
1088
1089class T2I_exta_rrot_np<bits<3> opcod, string opc>
1090  : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm,rot_imm:$rot),
1091               IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []> {
1092  bits<2> rot;
1093  let Inst{31-27} = 0b11111;
1094  let Inst{26-23} = 0b0100;
1095  let Inst{22-20} = opcod;
1096  let Inst{15-12} = 0b1111;
1097  let Inst{7} = 1;
1098  let Inst{5-4} = rot;
1099}
1100
1101//===----------------------------------------------------------------------===//
1102// Instructions
1103//===----------------------------------------------------------------------===//
1104
1105//===----------------------------------------------------------------------===//
1106//  Miscellaneous Instructions.
1107//
1108
1109class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1110           string asm, list<dag> pattern>
1111  : T2XI<oops, iops, itin, asm, pattern> {
1112  bits<4> Rd;
1113  bits<12> label;
1114
1115  let Inst{11-8}  = Rd;
1116  let Inst{26}    = label{11};
1117  let Inst{14-12} = label{10-8};
1118  let Inst{7-0}   = label{7-0};
1119}
1120
1121// LEApcrel - Load a pc-relative address into a register without offending the
1122// assembler.
1123def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1124              (ins t2adrlabel:$addr, pred:$p),
1125              IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []> {
1126  let Inst{31-27} = 0b11110;
1127  let Inst{25-24} = 0b10;
1128  // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1129  let Inst{22} = 0;
1130  let Inst{20} = 0;
1131  let Inst{19-16} = 0b1111; // Rn
1132  let Inst{15} = 0;
1133
1134  bits<4> Rd;
1135  bits<13> addr;
1136  let Inst{11-8} = Rd;
1137  let Inst{23}    = addr{12};
1138  let Inst{21}    = addr{12};
1139  let Inst{26}    = addr{11};
1140  let Inst{14-12} = addr{10-8};
1141  let Inst{7-0}   = addr{7-0};
1142
1143  let DecoderMethod = "DecodeT2Adr";
1144}
1145
1146let neverHasSideEffects = 1, isReMaterializable = 1 in
1147def t2LEApcrel   : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
1148                                4, IIC_iALUi, []>;
1149def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1150                                (ins i32imm:$label, nohash_imm:$id, pred:$p),
1151                                4, IIC_iALUi,
1152                                []>;
1153
1154
1155//===----------------------------------------------------------------------===//
1156//  Load / store Instructions.
1157//
1158
1159// Load
1160let canFoldAsLoad = 1, isReMaterializable = 1  in
1161defm t2LDR   : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR,
1162                      UnOpFrag<(load node:$Src)>>;
1163
1164// Loads with zero extension
1165defm t2LDRH  : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1166                      rGPR, UnOpFrag<(zextloadi16 node:$Src)>>;
1167defm t2LDRB  : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1168                      rGPR, UnOpFrag<(zextloadi8  node:$Src)>>;
1169
1170// Loads with sign extension
1171defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1172                      rGPR, UnOpFrag<(sextloadi16 node:$Src)>>;
1173defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
1174                      rGPR, UnOpFrag<(sextloadi8  node:$Src)>>;
1175
1176let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
1177// Load doubleword
1178def t2LDRDi8  : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
1179                        (ins t2addrmode_imm8s4:$addr),
1180                        IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "", []>;
1181} // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
1182
1183// zextload i1 -> zextload i8
1184def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1185            (t2LDRBi12  t2addrmode_imm12:$addr)>;
1186def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
1187            (t2LDRBi8   t2addrmode_negimm8:$addr)>;
1188def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1189            (t2LDRBs    t2addrmode_so_reg:$addr)>;
1190def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1191            (t2LDRBpci  tconstpool:$addr)>;
1192
1193// extload -> zextload
1194// FIXME: Reduce the number of patterns by legalizing extload to zextload
1195// earlier?
1196def : T2Pat<(extloadi1  t2addrmode_imm12:$addr),
1197            (t2LDRBi12  t2addrmode_imm12:$addr)>;
1198def : T2Pat<(extloadi1  t2addrmode_negimm8:$addr),
1199            (t2LDRBi8   t2addrmode_negimm8:$addr)>;
1200def : T2Pat<(extloadi1  t2addrmode_so_reg:$addr),
1201            (t2LDRBs    t2addrmode_so_reg:$addr)>;
1202def : T2Pat<(extloadi1  (ARMWrapper tconstpool:$addr)),
1203            (t2LDRBpci  tconstpool:$addr)>;
1204
1205def : T2Pat<(extloadi8  t2addrmode_imm12:$addr),
1206            (t2LDRBi12  t2addrmode_imm12:$addr)>;
1207def : T2Pat<(extloadi8  t2addrmode_negimm8:$addr),
1208            (t2LDRBi8   t2addrmode_negimm8:$addr)>;
1209def : T2Pat<(extloadi8  t2addrmode_so_reg:$addr),
1210            (t2LDRBs    t2addrmode_so_reg:$addr)>;
1211def : T2Pat<(extloadi8  (ARMWrapper tconstpool:$addr)),
1212            (t2LDRBpci  tconstpool:$addr)>;
1213
1214def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1215            (t2LDRHi12  t2addrmode_imm12:$addr)>;
1216def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
1217            (t2LDRHi8   t2addrmode_negimm8:$addr)>;
1218def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1219            (t2LDRHs    t2addrmode_so_reg:$addr)>;
1220def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1221            (t2LDRHpci  tconstpool:$addr)>;
1222
1223// FIXME: The destination register of the loads and stores can't be PC, but
1224//        can be SP. We need another regclass (similar to rGPR) to represent
1225//        that. Not a pressing issue since these are selected manually,
1226//        not via pattern.
1227
1228// Indexed loads
1229
1230let mayLoad = 1, neverHasSideEffects = 1 in {
1231def t2LDR_PRE  : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1232                            (ins t2addrmode_imm8:$addr),
1233                            AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
1234                            "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1235                            []> {
1236  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1237}
1238
1239def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1240                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1241                          AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
1242                          "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1243
1244def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1245                            (ins t2addrmode_imm8:$addr),
1246                            AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1247                            "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1248                            []> {
1249  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1250}
1251def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1252                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1253                          AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1254                          "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1255
1256def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1257                            (ins t2addrmode_imm8:$addr),
1258                            AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1259                            "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1260                            []> {
1261  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1262}
1263def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1264                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1265                          AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1266                          "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1267
1268def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1269                            (ins t2addrmode_imm8:$addr),
1270                            AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1271                            "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1272                            []> {
1273  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1274}
1275def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1276                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1277                          AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1278                          "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1279
1280def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1281                            (ins t2addrmode_imm8:$addr),
1282                            AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
1283                            "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1284                            []> {
1285  let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1286}
1287def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
1288                          (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1289                          AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
1290                          "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
1291} // mayLoad = 1, neverHasSideEffects = 1
1292
1293// LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
1294// Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
1295class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1296  : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
1297          "\t$Rt, $addr", []> {
1298  bits<4> Rt;
1299  bits<13> addr;
1300  let Inst{31-27} = 0b11111;
1301  let Inst{26-25} = 0b00;
1302  let Inst{24} = signed;
1303  let Inst{23} = 0;
1304  let Inst{22-21} = type;
1305  let Inst{20} = 1; // load
1306  let Inst{19-16} = addr{12-9};
1307  let Inst{15-12} = Rt;
1308  let Inst{11} = 1;
1309  let Inst{10-8} = 0b110; // PUW.
1310  let Inst{7-0} = addr{7-0};
1311}
1312
1313def t2LDRT   : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1314def t2LDRBT  : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1315def t2LDRHT  : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1316def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1317def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
1318
1319// Store
1320defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR,
1321                   BinOpFrag<(store node:$LHS, node:$RHS)>>;
1322defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
1323                   rGPR, BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
1324defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
1325                   rGPR, BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
1326
1327// Store doubleword
1328let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
1329def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
1330                       (ins GPR:$Rt, GPR:$Rt2, t2addrmode_imm8s4:$addr),
1331               IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "", []>;
1332
1333// Indexed stores
1334
1335let mayStore = 1, neverHasSideEffects = 1 in {
1336def t2STR_PRE  : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
1337                            (ins rGPR:$Rt, t2addrmode_imm8:$addr),
1338                            AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1339                            "str", "\t$Rt, $addr!",
1340                            "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1341  let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1342}
1343def t2STRH_PRE  : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
1344                            (ins rGPR:$Rt, t2addrmode_imm8:$addr),
1345                            AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1346                        "strh", "\t$Rt, $addr!",
1347                        "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1348  let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1349}
1350
1351def t2STRB_PRE  : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
1352                            (ins rGPR:$Rt, t2addrmode_imm8:$addr),
1353                            AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1354                        "strb", "\t$Rt, $addr!",
1355                        "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1356  let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1357}
1358} // mayStore = 1, neverHasSideEffects = 1
1359
1360def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
1361                            (ins rGPR:$Rt, addr_offset_none:$Rn,
1362                                 t2am_imm8_offset:$offset),
1363                            AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
1364                          "str", "\t$Rt, $Rn$offset",
1365                          "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1366             [(set GPRnopc:$Rn_wb,
1367                  (post_store rGPR:$Rt, addr_offset_none:$Rn,
1368                              t2am_imm8_offset:$offset))]>;
1369
1370def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
1371                            (ins rGPR:$Rt, addr_offset_none:$Rn,
1372                                 t2am_imm8_offset:$offset),
1373                            AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1374                         "strh", "\t$Rt, $Rn$offset",
1375                         "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1376       [(set GPRnopc:$Rn_wb,
1377             (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
1378                              t2am_imm8_offset:$offset))]>;
1379
1380def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
1381                            (ins rGPR:$Rt, addr_offset_none:$Rn,
1382                                 t2am_imm8_offset:$offset),
1383                            AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
1384                         "strb", "\t$Rt, $Rn$offset",
1385                         "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1386        [(set GPRnopc:$Rn_wb,
1387              (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
1388                              t2am_imm8_offset:$offset))]>;
1389
1390// Pseudo-instructions for pattern matching the pre-indexed stores. We can't
1391// put the patterns on the instruction definitions directly as ISel wants
1392// the address base and offset to be separate operands, not a single
1393// complex operand like we represent the instructions themselves. The
1394// pseudos map between the two.
1395let usesCustomInserter = 1,
1396    Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
1397def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1398               (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1399               4, IIC_iStore_ru,
1400      [(set GPRnopc:$Rn_wb,
1401            (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1402def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1403               (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1404               4, IIC_iStore_ru,
1405      [(set GPRnopc:$Rn_wb,
1406            (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1407def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1408               (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1409               4, IIC_iStore_ru,
1410      [(set GPRnopc:$Rn_wb,
1411            (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1412}
1413
1414// STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1415// only.
1416// Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
1417class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1418  : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
1419          "\t$Rt, $addr", []> {
1420  let Inst{31-27} = 0b11111;
1421  let Inst{26-25} = 0b00;
1422  let Inst{24} = 0; // not signed
1423  let Inst{23} = 0;
1424  let Inst{22-21} = type;
1425  let Inst{20} = 0; // store
1426  let Inst{11} = 1;
1427  let Inst{10-8} = 0b110; // PUW
1428
1429  bits<4> Rt;
1430  bits<13> addr;
1431  let Inst{15-12} = Rt;
1432  let Inst{19-16} = addr{12-9};
1433  let Inst{7-0}   = addr{7-0};
1434}
1435
1436def t2STRT   : T2IstT<0b10, "strt", IIC_iStore_i>;
1437def t2STRBT  : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1438def t2STRHT  : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
1439
1440// ldrd / strd pre / post variants
1441// For disassembly only.
1442
1443def t2LDRD_PRE  : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1444                 (ins t2addrmode_imm8s4:$addr), IIC_iLoad_d_ru,
1445                 "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []> {
1446  let AsmMatchConverter = "cvtT2LdrdPre";
1447  let DecoderMethod = "DecodeT2LDRDPreInstruction";
1448}
1449
1450def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1451                 (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
1452                 IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
1453                 "$addr.base = $wb", []>;
1454
1455def t2STRD_PRE  : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
1456                 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
1457                 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
1458                 "$addr.base = $wb", []> {
1459  let AsmMatchConverter = "cvtT2StrdPre";
1460  let DecoderMethod = "DecodeT2STRDPreInstruction";
1461}
1462
1463def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
1464                 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
1465                      t2am_imm8s4_offset:$imm),
1466                 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
1467                 "$addr.base = $wb", []>;
1468
1469// T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1470// data/instruction access.
1471// instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1472// (prefetch 1) -> (preload 2),  (prefetch 2) -> (preload 1).
1473multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
1474
1475  def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
1476                "\t$addr",
1477              [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
1478    let Inst{31-25} = 0b1111100;
1479    let Inst{24} = instr;
1480    let Inst{22} = 0;
1481    let Inst{21} = write;
1482    let Inst{20} = 1;
1483    let Inst{15-12} = 0b1111;
1484
1485    bits<17> addr;
1486    let addr{12}    = 1;           // add = TRUE
1487    let Inst{19-16} = addr{16-13}; // Rn
1488    let Inst{23}    = addr{12};    // U
1489    let Inst{11-0}  = addr{11-0};  // imm12
1490  }
1491
1492  def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
1493                "\t$addr",
1494            [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]> {
1495    let Inst{31-25} = 0b1111100;
1496    let Inst{24} = instr;
1497    let Inst{23} = 0; // U = 0
1498    let Inst{22} = 0;
1499    let Inst{21} = write;
1500    let Inst{20} = 1;
1501    let Inst{15-12} = 0b1111;
1502    let Inst{11-8} = 0b1100;
1503
1504    bits<13> addr;
1505    let Inst{19-16} = addr{12-9}; // Rn
1506    let Inst{7-0}   = addr{7-0};  // imm8
1507  }
1508
1509  def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
1510               "\t$addr",
1511             [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
1512    let Inst{31-25} = 0b1111100;
1513    let Inst{24} = instr;
1514    let Inst{23} = 0; // add = TRUE for T1
1515    let Inst{22} = 0;
1516    let Inst{21} = write;
1517    let Inst{20} = 1;
1518    let Inst{15-12} = 0b1111;
1519    let Inst{11-6} = 0000000;
1520
1521    bits<10> addr;
1522    let Inst{19-16} = addr{9-6}; // Rn
1523    let Inst{3-0}   = addr{5-2}; // Rm
1524    let Inst{5-4}   = addr{1-0}; // imm2
1525
1526    let DecoderMethod = "DecodeT2LoadShift";
1527  }
1528  // FIXME: We should have a separate 'pci' variant here. As-is we represent
1529  // it via the i12 variant, which it's related to, but that means we can
1530  // represent negative immediates, which aren't legal for anything except
1531  // the 'pci' case (Rn == 15).
1532}
1533
1534defm t2PLD  : T2Ipl<0, 0, "pld">,  Requires<[IsThumb2]>;
1535defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1536defm t2PLI  : T2Ipl<0, 1, "pli">,  Requires<[IsThumb2,HasV7]>;
1537
1538//===----------------------------------------------------------------------===//
1539//  Load / store multiple Instructions.
1540//
1541
1542multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
1543                            InstrItinClass itin_upd, bit L_bit> {
1544  def IA :
1545    T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1546         itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1547    bits<4>  Rn;
1548    bits<16> regs;
1549
1550    let Inst{31-27} = 0b11101;
1551    let Inst{26-25} = 0b00;
1552    let Inst{24-23} = 0b01;     // Increment After
1553    let Inst{22}    = 0;
1554    let Inst{21}    = 0;        // No writeback
1555    let Inst{20}    = L_bit;
1556    let Inst{19-16} = Rn;
1557    let Inst{15-0}  = regs;
1558  }
1559  def IA_UPD :
1560    T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1561          itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1562    bits<4>  Rn;
1563    bits<16> regs;
1564
1565    let Inst{31-27} = 0b11101;
1566    let Inst{26-25} = 0b00;
1567    let Inst{24-23} = 0b01;     // Increment After
1568    let Inst{22}    = 0;
1569    let Inst{21}    = 1;        // Writeback
1570    let Inst{20}    = L_bit;
1571    let Inst{19-16} = Rn;
1572    let Inst{15-0}  = regs;
1573  }
1574  def DB :
1575    T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1576         itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1577    bits<4>  Rn;
1578    bits<16> regs;
1579
1580    let Inst{31-27} = 0b11101;
1581    let Inst{26-25} = 0b00;
1582    let Inst{24-23} = 0b10;     // Decrement Before
1583    let Inst{22}    = 0;
1584    let Inst{21}    = 0;        // No writeback
1585    let Inst{20}    = L_bit;
1586    let Inst{19-16} = Rn;
1587    let Inst{15-0}  = regs;
1588  }
1589  def DB_UPD :
1590    T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1591          itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1592    bits<4>  Rn;
1593    bits<16> regs;
1594
1595    let Inst{31-27} = 0b11101;
1596    let Inst{26-25} = 0b00;
1597    let Inst{24-23} = 0b10;     // Decrement Before
1598    let Inst{22}    = 0;
1599    let Inst{21}    = 1;        // Writeback
1600    let Inst{20}    = L_bit;
1601    let Inst{19-16} = Rn;
1602    let Inst{15-0}  = regs;
1603  }
1604}
1605
1606let neverHasSideEffects = 1 in {
1607
1608let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1609defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1610
1611multiclass thumb2_st_mult<string asm, InstrItinClass itin,
1612                            InstrItinClass itin_upd, bit L_bit> {
1613  def IA :
1614    T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1615         itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1616    bits<4>  Rn;
1617    bits<16> regs;
1618
1619    let Inst{31-27} = 0b11101;
1620    let Inst{26-25} = 0b00;
1621    let Inst{24-23} = 0b01;     // Increment After
1622    let Inst{22}    = 0;
1623    let Inst{21}    = 0;        // No writeback
1624    let Inst{20}    = L_bit;
1625    let Inst{19-16} = Rn;
1626    let Inst{15}    = 0;
1627    let Inst{14}    = regs{14};
1628    let Inst{13}    = 0;
1629    let Inst{12-0}  = regs{12-0};
1630  }
1631  def IA_UPD :
1632    T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1633          itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1634    bits<4>  Rn;
1635    bits<16> regs;
1636
1637    let Inst{31-27} = 0b11101;
1638    let Inst{26-25} = 0b00;
1639    let Inst{24-23} = 0b01;     // Increment After
1640    let Inst{22}    = 0;
1641    let Inst{21}    = 1;        // Writeback
1642    let Inst{20}    = L_bit;
1643    let Inst{19-16} = Rn;
1644    let Inst{15}    = 0;
1645    let Inst{14}    = regs{14};
1646    let Inst{13}    = 0;
1647    let Inst{12-0}  = regs{12-0};
1648  }
1649  def DB :
1650    T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1651         itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1652    bits<4>  Rn;
1653    bits<16> regs;
1654
1655    let Inst{31-27} = 0b11101;
1656    let Inst{26-25} = 0b00;
1657    let Inst{24-23} = 0b10;     // Decrement Before
1658    let Inst{22}    = 0;
1659    let Inst{21}    = 0;        // No writeback
1660    let Inst{20}    = L_bit;
1661    let Inst{19-16} = Rn;
1662    let Inst{15}    = 0;
1663    let Inst{14}    = regs{14};
1664    let Inst{13}    = 0;
1665    let Inst{12-0}  = regs{12-0};
1666  }
1667  def DB_UPD :
1668    T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1669          itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1670    bits<4>  Rn;
1671    bits<16> regs;
1672
1673    let Inst{31-27} = 0b11101;
1674    let Inst{26-25} = 0b00;
1675    let Inst{24-23} = 0b10;     // Decrement Before
1676    let Inst{22}    = 0;
1677    let Inst{21}    = 1;        // Writeback
1678    let Inst{20}    = L_bit;
1679    let Inst{19-16} = Rn;
1680    let Inst{15}    = 0;
1681    let Inst{14}    = regs{14};
1682    let Inst{13}    = 0;
1683    let Inst{12-0}  = regs{12-0};
1684  }
1685}
1686
1687
1688let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1689defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1690
1691} // neverHasSideEffects
1692
1693
1694//===----------------------------------------------------------------------===//
1695//  Move Instructions.
1696//
1697
1698let neverHasSideEffects = 1 in
1699def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1700                   "mov", ".w\t$Rd, $Rm", []> {
1701  let Inst{31-27} = 0b11101;
1702  let Inst{26-25} = 0b01;
1703  let Inst{24-21} = 0b0010;
1704  let Inst{19-16} = 0b1111; // Rn
1705  let Inst{14-12} = 0b000;
1706  let Inst{7-4} = 0b0000;
1707}
1708def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
1709                                                pred:$p, zero_reg)>;
1710def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
1711                                                 pred:$p, CPSR)>;
1712def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
1713                                               pred:$p, CPSR)>;
1714
1715// AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
1716let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
1717    AddedComplexity = 1 in
1718def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
1719                   "mov", ".w\t$Rd, $imm",
1720                   [(set rGPR:$Rd, t2_so_imm:$imm)]> {
1721  let Inst{31-27} = 0b11110;
1722  let Inst{25} = 0;
1723  let Inst{24-21} = 0b0010;
1724  let Inst{19-16} = 0b1111; // Rn
1725  let Inst{15} = 0;
1726}
1727
1728// cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
1729// Use aliases to get that to play nice here.
1730def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1731                                                pred:$p, CPSR)>;
1732def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1733                                                pred:$p, CPSR)>;
1734
1735def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1736                                                 pred:$p, zero_reg)>;
1737def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1738                                               pred:$p, zero_reg)>;
1739
1740let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
1741def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
1742                   "movw", "\t$Rd, $imm",
1743                   [(set rGPR:$Rd, imm0_65535:$imm)]> {
1744  let Inst{31-27} = 0b11110;
1745  let Inst{25} = 1;
1746  let Inst{24-21} = 0b0010;
1747  let Inst{20} = 0; // The S bit.
1748  let Inst{15} = 0;
1749
1750  bits<4> Rd;
1751  bits<16> imm;
1752
1753  let Inst{11-8}  = Rd;
1754  let Inst{19-16} = imm{15-12};
1755  let Inst{26}    = imm{11};
1756  let Inst{14-12} = imm{10-8};
1757  let Inst{7-0}   = imm{7-0};
1758  let DecoderMethod = "DecodeT2MOVTWInstruction";
1759}
1760
1761def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1762                                (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1763
1764let Constraints = "$src = $Rd" in {
1765def t2MOVTi16 : T2I<(outs rGPR:$Rd),
1766                    (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
1767                    "movt", "\t$Rd, $imm",
1768                    [(set rGPR:$Rd,
1769                          (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
1770  let Inst{31-27} = 0b11110;
1771  let Inst{25} = 1;
1772  let Inst{24-21} = 0b0110;
1773  let Inst{20} = 0; // The S bit.
1774  let Inst{15} = 0;
1775
1776  bits<4> Rd;
1777  bits<16> imm;
1778
1779  let Inst{11-8}  = Rd;
1780  let Inst{19-16} = imm{15-12};
1781  let Inst{26}    = imm{11};
1782  let Inst{14-12} = imm{10-8};
1783  let Inst{7-0}   = imm{7-0};
1784  let DecoderMethod = "DecodeT2MOVTWInstruction";
1785}
1786
1787def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
1788                     (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1789} // Constraints
1790
1791def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
1792
1793//===----------------------------------------------------------------------===//
1794//  Extend Instructions.
1795//
1796
1797// Sign extenders
1798
1799def t2SXTB  : T2I_ext_rrot<0b100, "sxtb",
1800                              UnOpFrag<(sext_inreg node:$Src, i8)>>;
1801def t2SXTH  : T2I_ext_rrot<0b000, "sxth",
1802                              UnOpFrag<(sext_inreg node:$Src, i16)>>;
1803def t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
1804
1805def t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
1806                        BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
1807def t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
1808                        BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
1809def t2SXTAB16 : T2I_exta_rrot_np<0b010, "sxtab16">;
1810
1811// Zero extenders
1812
1813let AddedComplexity = 16 in {
1814def t2UXTB   : T2I_ext_rrot<0b101, "uxtb",
1815                               UnOpFrag<(and node:$Src, 0x000000FF)>>;
1816def t2UXTH   : T2I_ext_rrot<0b001, "uxth",
1817                               UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1818def t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
1819                               UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
1820
1821// FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1822//        The transformation should probably be done as a combiner action
1823//        instead so we can include a check for masking back in the upper
1824//        eight bits of the source into the lower eight bits of the result.
1825//def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
1826//            (t2UXTB16 rGPR:$Src, 3)>,
1827//          Requires<[HasT2ExtractPack, IsThumb2]>;
1828def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
1829            (t2UXTB16 rGPR:$Src, 1)>,
1830        Requires<[HasT2ExtractPack, IsThumb2]>;
1831
1832def t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
1833                           BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
1834def t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
1835                           BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1836def t2UXTAB16 : T2I_exta_rrot_np<0b011, "uxtab16">;
1837}
1838
1839//===----------------------------------------------------------------------===//
1840//  Arithmetic Instructions.
1841//
1842
1843defm t2ADD  : T2I_bin_ii12rs<0b000, "add",
1844                             BinOpFrag<(add  node:$LHS, node:$RHS)>, 1>;
1845defm t2SUB  : T2I_bin_ii12rs<0b101, "sub",
1846                             BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
1847
1848// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
1849//
1850// Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
1851// selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
1852// AdjustInstrPostInstrSelection where we determine whether or not to
1853// set the "s" bit based on CPSR liveness.
1854//
1855// FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
1856// support for an optional CPSR definition that corresponds to the DAG
1857// node's second value. We can then eliminate the implicit def of CPSR.
1858defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi,
1859                             BinOpFrag<(ARMaddc node:$LHS, node:$RHS)>, 1>;
1860defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi,
1861                             BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
1862
1863let hasPostISelHook = 1 in {
1864defm t2ADC  : T2I_adde_sube_irs<0b1010, "adc",
1865              BinOpWithFlagFrag<(ARMadde node:$LHS, node:$RHS, node:$FLAG)>, 1>;
1866defm t2SBC  : T2I_adde_sube_irs<0b1011, "sbc",
1867              BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>>;
1868}
1869
1870// RSB
1871defm t2RSB  : T2I_rbin_irs  <0b1110, "rsb",
1872                             BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
1873
1874// FIXME: Eliminate them if we can write def : Pat patterns which defines
1875// CPSR and the implicit def of CPSR is not needed.
1876defm t2RSBS : T2I_rbin_s_is <BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
1877
1878// (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
1879// The assume-no-carry-in form uses the negation of the input since add/sub
1880// assume opposite meanings of the carry flag (i.e., carry == !borrow).
1881// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1882// details.
1883// The AddedComplexity preferences the first variant over the others since
1884// it can be shrunk to a 16-bit wide encoding, while the others cannot.
1885let AddedComplexity = 1 in
1886def : T2Pat<(add        GPR:$src, imm0_255_neg:$imm),
1887            (t2SUBri    GPR:$src, imm0_255_neg:$imm)>;
1888def : T2Pat<(add        GPR:$src, t2_so_imm_neg:$imm),
1889            (t2SUBri    GPR:$src, t2_so_imm_neg:$imm)>;
1890def : T2Pat<(add        GPR:$src, imm0_4095_neg:$imm),
1891            (t2SUBri12  GPR:$src, imm0_4095_neg:$imm)>;
1892let AddedComplexity = 1 in
1893def : T2Pat<(ARMaddc    rGPR:$src, imm0_255_neg:$imm),
1894            (t2SUBSri   rGPR:$src, imm0_255_neg:$imm)>;
1895def : T2Pat<(ARMaddc    rGPR:$src, t2_so_imm_neg:$imm),
1896            (t2SUBSri   rGPR:$src, t2_so_imm_neg:$imm)>;
1897// The with-carry-in form matches bitwise not instead of the negation.
1898// Effectively, the inverse interpretation of the carry flag already accounts
1899// for part of the negation.
1900let AddedComplexity = 1 in
1901def : T2Pat<(ARMadde    rGPR:$src, imm0_255_not:$imm, CPSR),
1902            (t2SBCri    rGPR:$src, imm0_255_not:$imm)>;
1903def : T2Pat<(ARMadde    rGPR:$src, t2_so_imm_not:$imm, CPSR),
1904            (t2SBCri    rGPR:$src, t2_so_imm_not:$imm)>;
1905
1906// Select Bytes -- for disassembly only
1907
1908def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1909                NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []>,
1910          Requires<[IsThumb2, HasThumb2DSP]> {
1911  let Inst{31-27} = 0b11111;
1912  let Inst{26-24} = 0b010;
1913  let Inst{23} = 0b1;
1914  let Inst{22-20} = 0b010;
1915  let Inst{15-12} = 0b1111;
1916  let Inst{7} = 0b1;
1917  let Inst{6-4} = 0b000;
1918}
1919
1920// A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1921// And Miscellaneous operations -- for disassembly only
1922class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
1923              list<dag> pat = [/* For disassembly only; pattern left blank */],
1924              dag iops = (ins rGPR:$Rn, rGPR:$Rm),
1925              string asm = "\t$Rd, $Rn, $Rm">
1926  : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
1927    Requires<[IsThumb2, HasThumb2DSP]> {
1928  let Inst{31-27} = 0b11111;
1929  let Inst{26-23} = 0b0101;
1930  let Inst{22-20} = op22_20;
1931  let Inst{15-12} = 0b1111;
1932  let Inst{7-4} = op7_4;
1933
1934  bits<4> Rd;
1935  bits<4> Rn;
1936  bits<4> Rm;
1937
1938  let Inst{11-8}  = Rd;
1939  let Inst{19-16} = Rn;
1940  let Inst{3-0}   = Rm;
1941}
1942
1943// Saturating add/subtract -- for disassembly only
1944
1945def t2QADD    : T2I_pam<0b000, 0b1000, "qadd",
1946                        [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))],
1947                        (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1948def t2QADD16  : T2I_pam<0b001, 0b0001, "qadd16">;
1949def t2QADD8   : T2I_pam<0b000, 0b0001, "qadd8">;
1950def t2QASX    : T2I_pam<0b010, 0b0001, "qasx">;
1951def t2QDADD   : T2I_pam<0b000, 0b1001, "qdadd", [],
1952                        (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1953def t2QDSUB   : T2I_pam<0b000, 0b1011, "qdsub", [],
1954                        (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1955def t2QSAX    : T2I_pam<0b110, 0b0001, "qsax">;
1956def t2QSUB    : T2I_pam<0b000, 0b1010, "qsub",
1957                        [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))],
1958                        (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1959def t2QSUB16  : T2I_pam<0b101, 0b0001, "qsub16">;
1960def t2QSUB8   : T2I_pam<0b100, 0b0001, "qsub8">;
1961def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
1962def t2UQADD8  : T2I_pam<0b000, 0b0101, "uqadd8">;
1963def t2UQASX   : T2I_pam<0b010, 0b0101, "uqasx">;
1964def t2UQSAX   : T2I_pam<0b110, 0b0101, "uqsax">;
1965def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
1966def t2UQSUB8  : T2I_pam<0b100, 0b0101, "uqsub8">;
1967
1968// Signed/Unsigned add/subtract -- for disassembly only
1969
1970def t2SASX    : T2I_pam<0b010, 0b0000, "sasx">;
1971def t2SADD16  : T2I_pam<0b001, 0b0000, "sadd16">;
1972def t2SADD8   : T2I_pam<0b000, 0b0000, "sadd8">;
1973def t2SSAX    : T2I_pam<0b110, 0b0000, "ssax">;
1974def t2SSUB16  : T2I_pam<0b101, 0b0000, "ssub16">;
1975def t2SSUB8   : T2I_pam<0b100, 0b0000, "ssub8">;
1976def t2UASX    : T2I_pam<0b010, 0b0100, "uasx">;
1977def t2UADD16  : T2I_pam<0b001, 0b0100, "uadd16">;
1978def t2UADD8   : T2I_pam<0b000, 0b0100, "uadd8">;
1979def t2USAX    : T2I_pam<0b110, 0b0100, "usax">;
1980def t2USUB16  : T2I_pam<0b101, 0b0100, "usub16">;
1981def t2USUB8   : T2I_pam<0b100, 0b0100, "usub8">;
1982
1983// Signed/Unsigned halving add/subtract -- for disassembly only
1984
1985def t2SHASX   : T2I_pam<0b010, 0b0010, "shasx">;
1986def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
1987def t2SHADD8  : T2I_pam<0b000, 0b0010, "shadd8">;
1988def t2SHSAX   : T2I_pam<0b110, 0b0010, "shsax">;
1989def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
1990def t2SHSUB8  : T2I_pam<0b100, 0b0010, "shsub8">;
1991def t2UHASX   : T2I_pam<0b010, 0b0110, "uhasx">;
1992def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
1993def t2UHADD8  : T2I_pam<0b000, 0b0110, "uhadd8">;
1994def t2UHSAX   : T2I_pam<0b110, 0b0110, "uhsax">;
1995def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
1996def t2UHSUB8  : T2I_pam<0b100, 0b0110, "uhsub8">;
1997
1998// Helper class for disassembly only
1999// A6.3.16 & A6.3.17
2000// T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
2001class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2002  dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2003  : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2004  let Inst{31-27} = 0b11111;
2005  let Inst{26-24} = 0b011;
2006  let Inst{23}    = long;
2007  let Inst{22-20} = op22_20;
2008  let Inst{7-4}   = op7_4;
2009}
2010
2011class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2012  dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2013  : T2FourReg<oops, iops, itin, opc, asm, pattern> {
2014  let Inst{31-27} = 0b11111;
2015  let Inst{26-24} = 0b011;
2016  let Inst{23}    = long;
2017  let Inst{22-20} = op22_20;
2018  let Inst{7-4}   = op7_4;
2019}
2020
2021// Unsigned Sum of Absolute Differences [and Accumulate].
2022def t2USAD8   : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2023                                           (ins rGPR:$Rn, rGPR:$Rm),
2024                        NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []>,
2025          Requires<[IsThumb2, HasThumb2DSP]> {
2026  let Inst{15-12} = 0b1111;
2027}
2028def t2USADA8  : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2029                       (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
2030                        "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>,
2031          Requires<[IsThumb2, HasThumb2DSP]>;
2032
2033// Signed/Unsigned saturate.
2034class T2SatI<dag oops, dag iops, InstrItinClass itin,
2035           string opc, string asm, list<dag> pattern>
2036  : T2I<oops, iops, itin, opc, asm, pattern> {
2037  bits<4> Rd;
2038  bits<4> Rn;
2039  bits<5> sat_imm;
2040  bits<7> sh;
2041
2042  let Inst{11-8}  = Rd;
2043  let Inst{19-16} = Rn;
2044  let Inst{4-0}   = sat_imm;
2045  let Inst{21}    = sh{5};
2046  let Inst{14-12} = sh{4-2};
2047  let Inst{7-6}   = sh{1-0};
2048}
2049
2050def t2SSAT: T2SatI<
2051              (outs rGPR:$Rd),
2052              (ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2053              NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", []> {
2054  let Inst{31-27} = 0b11110;
2055  let Inst{25-22} = 0b1100;
2056  let Inst{20} = 0;
2057  let Inst{15} = 0;
2058  let Inst{5}  = 0;
2059}
2060
2061def t2SSAT16: T2SatI<
2062                (outs rGPR:$Rd), (ins imm1_16:$sat_imm, rGPR:$Rn), NoItinerary,
2063                "ssat16", "\t$Rd, $sat_imm, $Rn", []>,
2064          Requires<[IsThumb2, HasThumb2DSP]> {
2065  let Inst{31-27} = 0b11110;
2066  let Inst{25-22} = 0b1100;
2067  let Inst{20} = 0;
2068  let Inst{15} = 0;
2069  let Inst{21} = 1;        // sh = '1'
2070  let Inst{14-12} = 0b000; // imm3 = '000'
2071  let Inst{7-6} = 0b00;    // imm2 = '00'
2072  let Inst{5-4} = 0b00;
2073}
2074
2075def t2USAT: T2SatI<
2076               (outs rGPR:$Rd),
2077               (ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
2078                NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", []> {
2079  let Inst{31-27} = 0b11110;
2080  let Inst{25-22} = 0b1110;
2081  let Inst{20} = 0;
2082  let Inst{15} = 0;
2083}
2084
2085def t2USAT16: T2SatI<(outs rGPR:$Rd), (ins imm0_15:$sat_imm, rGPR:$Rn),
2086                     NoItinerary,
2087                     "usat16", "\t$Rd, $sat_imm, $Rn", []>,
2088          Requires<[IsThumb2, HasThumb2DSP]> {
2089  let Inst{31-22} = 0b1111001110;
2090  let Inst{20} = 0;
2091  let Inst{15} = 0;
2092  let Inst{21} = 1;        // sh = '1'
2093  let Inst{14-12} = 0b000; // imm3 = '000'
2094  let Inst{7-6} = 0b00;    // imm2 = '00'
2095  let Inst{5-4} = 0b00;
2096}
2097
2098def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
2099def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
2100
2101//===----------------------------------------------------------------------===//
2102//  Shift and rotate Instructions.
2103//
2104
2105defm t2LSL  : T2I_sh_ir<0b00, "lsl", imm0_31,
2106                        BinOpFrag<(shl  node:$LHS, node:$RHS)>, "t2LSL">;
2107defm t2LSR  : T2I_sh_ir<0b01, "lsr", imm_sr,
2108                        BinOpFrag<(srl  node:$LHS, node:$RHS)>, "t2LSR">;
2109defm t2ASR  : T2I_sh_ir<0b10, "asr", imm_sr,
2110                        BinOpFrag<(sra  node:$LHS, node:$RHS)>, "t2ASR">;
2111defm t2ROR  : T2I_sh_ir<0b11, "ror", imm0_31,
2112                        BinOpFrag<(rotr node:$LHS, node:$RHS)>, "t2ROR">;
2113
2114// (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
2115def : Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
2116          (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
2117
2118let Uses = [CPSR] in {
2119def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2120                   "rrx", "\t$Rd, $Rm",
2121                   [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]> {
2122  let Inst{31-27} = 0b11101;
2123  let Inst{26-25} = 0b01;
2124  let Inst{24-21} = 0b0010;
2125  let Inst{19-16} = 0b1111; // Rn
2126  let Inst{14-12} = 0b000;
2127  let Inst{7-4} = 0b0011;
2128}
2129}
2130
2131let isCodeGenOnly = 1, Defs = [CPSR] in {
2132def t2MOVsrl_flag : T2TwoRegShiftImm<
2133                        (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2134                        "lsrs", ".w\t$Rd, $Rm, #1",
2135                        [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]> {
2136  let Inst{31-27} = 0b11101;
2137  let Inst{26-25} = 0b01;
2138  let Inst{24-21} = 0b0010;
2139  let Inst{20} = 1; // The S bit.
2140  let Inst{19-16} = 0b1111; // Rn
2141  let Inst{5-4} = 0b01; // Shift type.
2142  // Shift amount = Inst{14-12:7-6} = 1.
2143  let Inst{14-12} = 0b000;
2144  let Inst{7-6} = 0b01;
2145}
2146def t2MOVsra_flag : T2TwoRegShiftImm<
2147                        (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2148                        "asrs", ".w\t$Rd, $Rm, #1",
2149                        [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]> {
2150  let Inst{31-27} = 0b11101;
2151  let Inst{26-25} = 0b01;
2152  let Inst{24-21} = 0b0010;
2153  let Inst{20} = 1; // The S bit.
2154  let Inst{19-16} = 0b1111; // Rn
2155  let Inst{5-4} = 0b10; // Shift type.
2156  // Shift amount = Inst{14-12:7-6} = 1.
2157  let Inst{14-12} = 0b000;
2158  let Inst{7-6} = 0b01;
2159}
2160}
2161
2162//===----------------------------------------------------------------------===//
2163//  Bitwise Instructions.
2164//
2165
2166defm t2AND  : T2I_bin_w_irs<0b0000, "and",
2167                            IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2168                            BinOpFrag<(and node:$LHS, node:$RHS)>, "t2AND", 1>;
2169defm t2ORR  : T2I_bin_w_irs<0b0010, "orr",
2170                            IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2171                            BinOpFrag<(or  node:$LHS, node:$RHS)>, "t2ORR", 1>;
2172defm t2EOR  : T2I_bin_w_irs<0b0100, "eor",
2173                            IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2174                            BinOpFrag<(xor node:$LHS, node:$RHS)>, "t2EOR", 1>;
2175
2176defm t2BIC  : T2I_bin_w_irs<0b0001, "bic",
2177                            IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2178                            BinOpFrag<(and node:$LHS, (not node:$RHS))>,
2179                            "t2BIC">;
2180
2181class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2182              string opc, string asm, list<dag> pattern>
2183    : T2I<oops, iops, itin, opc, asm, pattern> {
2184  bits<4> Rd;
2185  bits<5> msb;
2186  bits<5> lsb;
2187
2188  let Inst{11-8}  = Rd;
2189  let Inst{4-0}   = msb{4-0};
2190  let Inst{14-12} = lsb{4-2};
2191  let Inst{7-6}   = lsb{1-0};
2192}
2193
2194class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2195              string opc, string asm, list<dag> pattern>
2196    : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2197  bits<4> Rn;
2198
2199  let Inst{19-16} = Rn;
2200}
2201
2202let Constraints = "$src = $Rd" in
2203def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2204                IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2205                [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
2206  let Inst{31-27} = 0b11110;
2207  let Inst{26} = 0; // should be 0.
2208  let Inst{25} = 1;
2209  let Inst{24-20} = 0b10110;
2210  let Inst{19-16} = 0b1111; // Rn
2211  let Inst{15} = 0;
2212  let Inst{5} = 0; // should be 0.
2213
2214  bits<10> imm;
2215  let msb{4-0} = imm{9-5};
2216  let lsb{4-0} = imm{4-0};
2217}
2218
2219def t2SBFX: T2TwoRegBitFI<
2220                (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2221                 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2222  let Inst{31-27} = 0b11110;
2223  let Inst{25} = 1;
2224  let Inst{24-20} = 0b10100;
2225  let Inst{15} = 0;
2226}
2227
2228def t2UBFX: T2TwoRegBitFI<
2229                (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
2230                 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> {
2231  let Inst{31-27} = 0b11110;
2232  let Inst{25} = 1;
2233  let Inst{24-20} = 0b11100;
2234  let Inst{15} = 0;
2235}
2236
2237// A8.6.18  BFI - Bitfield insert (Encoding T1)
2238let Constraints = "$src = $Rd" in {
2239  def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2240                  (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2241                  IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2242                  [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2243                                   bf_inv_mask_imm:$imm))]> {
2244    let Inst{31-27} = 0b11110;
2245    let Inst{26} = 0; // should be 0.
2246    let Inst{25} = 1;
2247    let Inst{24-20} = 0b10110;
2248    let Inst{15} = 0;
2249    let Inst{5} = 0; // should be 0.
2250
2251    bits<10> imm;
2252    let msb{4-0} = imm{9-5};
2253    let lsb{4-0} = imm{4-0};
2254  }
2255}
2256
2257defm t2ORN  : T2I_bin_irs<0b0011, "orn",
2258                          IIC_iBITi, IIC_iBITr, IIC_iBITsi,
2259                          BinOpFrag<(or  node:$LHS, (not node:$RHS))>,
2260                          "t2ORN", 0, "">;
2261
2262/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
2263/// unary operation that produces a value. These are predicable and can be
2264/// changed to modify CPSR.
2265multiclass T2I_un_irs<bits<4> opcod, string opc,
2266                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
2267                      PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
2268   // shifted imm
2269   def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
2270                opc, "\t$Rd, $imm",
2271                [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]> {
2272     let isAsCheapAsAMove = Cheap;
2273     let isReMaterializable = ReMat;
2274     let Inst{31-27} = 0b11110;
2275     let Inst{25} = 0;
2276     let Inst{24-21} = opcod;
2277     let Inst{19-16} = 0b1111; // Rn
2278     let Inst{15} = 0;
2279   }
2280   // register
2281   def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
2282                opc, ".w\t$Rd, $Rm",
2283                [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
2284     let Inst{31-27} = 0b11101;
2285     let Inst{26-25} = 0b01;
2286     let Inst{24-21} = opcod;
2287     let Inst{19-16} = 0b1111; // Rn
2288     let Inst{14-12} = 0b000; // imm3
2289     let Inst{7-6} = 0b00; // imm2
2290     let Inst{5-4} = 0b00; // type
2291   }
2292   // shifted register
2293   def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
2294                opc, ".w\t$Rd, $ShiftedRm",
2295                [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]> {
2296     let Inst{31-27} = 0b11101;
2297     let Inst{26-25} = 0b01;
2298     let Inst{24-21} = opcod;
2299     let Inst{19-16} = 0b1111; // Rn
2300   }
2301}
2302
2303// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2304let AddedComplexity = 1 in
2305defm t2MVN  : T2I_un_irs <0b0011, "mvn",
2306                          IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
2307                          UnOpFrag<(not node:$Src)>, 1, 1>;
2308
2309let AddedComplexity = 1 in
2310def : T2Pat<(and     rGPR:$src, t2_so_imm_not:$imm),
2311            (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
2312
2313// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
2314def : T2Pat<(or      rGPR:$src, t2_so_imm_not:$imm),
2315            (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
2316            Requires<[IsThumb2]>;
2317
2318def : T2Pat<(t2_so_imm_not:$src),
2319            (t2MVNi t2_so_imm_not:$src)>;
2320
2321//===----------------------------------------------------------------------===//
2322//  Multiply Instructions.
2323//
2324let isCommutable = 1 in
2325def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2326                "mul", "\t$Rd, $Rn, $Rm",
2327                [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> {
2328  let Inst{31-27} = 0b11111;
2329  let Inst{26-23} = 0b0110;
2330  let Inst{22-20} = 0b000;
2331  let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2332  let Inst{7-4} = 0b0000; // Multiply
2333}
2334
2335def t2MLA: T2FourReg<
2336                (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2337                "mla", "\t$Rd, $Rn, $Rm, $Ra",
2338                [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]> {
2339  let Inst{31-27} = 0b11111;
2340  let Inst{26-23} = 0b0110;
2341  let Inst{22-20} = 0b000;
2342  let Inst{7-4} = 0b0000; // Multiply
2343}
2344
2345def t2MLS: T2FourReg<
2346                (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2347                "mls", "\t$Rd, $Rn, $Rm, $Ra",
2348                [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]> {
2349  let Inst{31-27} = 0b11111;
2350  let Inst{26-23} = 0b0110;
2351  let Inst{22-20} = 0b000;
2352  let Inst{7-4} = 0b0001; // Multiply and Subtract
2353}
2354
2355// Extra precision multiplies with low / high results
2356let neverHasSideEffects = 1 in {
2357let isCommutable = 1 in {
2358def t2SMULL : T2MulLong<0b000, 0b0000,
2359                  (outs rGPR:$RdLo, rGPR:$RdHi),
2360                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
2361                   "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2362
2363def t2UMULL : T2MulLong<0b010, 0b0000,
2364                  (outs rGPR:$RdLo, rGPR:$RdHi),
2365                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
2366                   "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2367} // isCommutable
2368
2369// Multiply + accumulate
2370def t2SMLAL : T2MulLong<0b100, 0b0000,
2371                  (outs rGPR:$RdLo, rGPR:$RdHi),
2372                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2373                  "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2374
2375def t2UMLAL : T2MulLong<0b110, 0b0000,
2376                  (outs rGPR:$RdLo, rGPR:$RdHi),
2377                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2378                  "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2379
2380def t2UMAAL : T2MulLong<0b110, 0b0110,
2381                  (outs rGPR:$RdLo, rGPR:$RdHi),
2382                  (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
2383                  "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
2384          Requires<[IsThumb2, HasThumb2DSP]>;
2385} // neverHasSideEffects
2386
2387// Rounding variants of the below included for disassembly only
2388
2389// Most significant word multiply
2390def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2391                  "smmul", "\t$Rd, $Rn, $Rm",
2392                  [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]>,
2393          Requires<[IsThumb2, HasThumb2DSP]> {
2394  let Inst{31-27} = 0b11111;
2395  let Inst{26-23} = 0b0110;
2396  let Inst{22-20} = 0b101;
2397  let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2398  let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2399}
2400
2401def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2402                  "smmulr", "\t$Rd, $Rn, $Rm", []>,
2403          Requires<[IsThumb2, HasThumb2DSP]> {
2404  let Inst{31-27} = 0b11111;
2405  let Inst{26-23} = 0b0110;
2406  let Inst{22-20} = 0b101;
2407  let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2408  let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2409}
2410
2411def t2SMMLA : T2FourReg<
2412        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2413                "smmla", "\t$Rd, $Rn, $Rm, $Ra",
2414                [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>,
2415          Requires<[IsThumb2, HasThumb2DSP]> {
2416  let Inst{31-27} = 0b11111;
2417  let Inst{26-23} = 0b0110;
2418  let Inst{22-20} = 0b101;
2419  let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2420}
2421
2422def t2SMMLAR: T2FourReg<
2423        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2424                  "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
2425          Requires<[IsThumb2, HasThumb2DSP]> {
2426  let Inst{31-27} = 0b11111;
2427  let Inst{26-23} = 0b0110;
2428  let Inst{22-20} = 0b101;
2429  let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2430}
2431
2432def t2SMMLS: T2FourReg<
2433        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2434                "smmls", "\t$Rd, $Rn, $Rm, $Ra",
2435                [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]>,
2436          Requires<[IsThumb2, HasThumb2DSP]> {
2437  let Inst{31-27} = 0b11111;
2438  let Inst{26-23} = 0b0110;
2439  let Inst{22-20} = 0b110;
2440  let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2441}
2442
2443def t2SMMLSR:T2FourReg<
2444        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2445                "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
2446          Requires<[IsThumb2, HasThumb2DSP]> {
2447  let Inst{31-27} = 0b11111;
2448  let Inst{26-23} = 0b0110;
2449  let Inst{22-20} = 0b110;
2450  let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2451}
2452
2453multiclass T2I_smul<string opc, PatFrag opnode> {
2454  def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2455              !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
2456              [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
2457                                      (sext_inreg rGPR:$Rm, i16)))]>,
2458          Requires<[IsThumb2, HasThumb2DSP]> {
2459    let Inst{31-27} = 0b11111;
2460    let Inst{26-23} = 0b0110;
2461    let Inst{22-20} = 0b001;
2462    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2463    let Inst{7-6} = 0b00;
2464    let Inst{5-4} = 0b00;
2465  }
2466
2467  def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2468              !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
2469              [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
2470                                      (sra rGPR:$Rm, (i32 16))))]>,
2471          Requires<[IsThumb2, HasThumb2DSP]> {
2472    let Inst{31-27} = 0b11111;
2473    let Inst{26-23} = 0b0110;
2474    let Inst{22-20} = 0b001;
2475    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2476    let Inst{7-6} = 0b00;
2477    let Inst{5-4} = 0b01;
2478  }
2479
2480  def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2481              !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
2482              [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
2483                                      (sext_inreg rGPR:$Rm, i16)))]>,
2484          Requires<[IsThumb2, HasThumb2DSP]> {
2485    let Inst{31-27} = 0b11111;
2486    let Inst{26-23} = 0b0110;
2487    let Inst{22-20} = 0b001;
2488    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2489    let Inst{7-6} = 0b00;
2490    let Inst{5-4} = 0b10;
2491  }
2492
2493  def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2494              !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
2495              [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
2496                                      (sra rGPR:$Rm, (i32 16))))]>,
2497          Requires<[IsThumb2, HasThumb2DSP]> {
2498    let Inst{31-27} = 0b11111;
2499    let Inst{26-23} = 0b0110;
2500    let Inst{22-20} = 0b001;
2501    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2502    let Inst{7-6} = 0b00;
2503    let Inst{5-4} = 0b11;
2504  }
2505
2506  def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2507              !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
2508              [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
2509                                    (sext_inreg rGPR:$Rm, i16)), (i32 16)))]>,
2510          Requires<[IsThumb2, HasThumb2DSP]> {
2511    let Inst{31-27} = 0b11111;
2512    let Inst{26-23} = 0b0110;
2513    let Inst{22-20} = 0b011;
2514    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2515    let Inst{7-6} = 0b00;
2516    let Inst{5-4} = 0b00;
2517  }
2518
2519  def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2520              !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
2521              [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
2522                                    (sra rGPR:$Rm, (i32 16))), (i32 16)))]>,
2523          Requires<[IsThumb2, HasThumb2DSP]> {
2524    let Inst{31-27} = 0b11111;
2525    let Inst{26-23} = 0b0110;
2526    let Inst{22-20} = 0b011;
2527    let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2528    let Inst{7-6} = 0b00;
2529    let Inst{5-4} = 0b01;
2530  }
2531}
2532
2533
2534multiclass T2I_smla<string opc, PatFrag opnode> {
2535  def BB : T2FourReg<
2536        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2537              !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
2538              [(set rGPR:$Rd, (add rGPR:$Ra,
2539                               (opnode (sext_inreg rGPR:$Rn, i16),
2540                                       (sext_inreg rGPR:$Rm, i16))))]>,
2541          Requires<[IsThumb2, HasThumb2DSP]> {
2542    let Inst{31-27} = 0b11111;
2543    let Inst{26-23} = 0b0110;
2544    let Inst{22-20} = 0b001;
2545    let Inst{7-6} = 0b00;
2546    let Inst{5-4} = 0b00;
2547  }
2548
2549  def BT : T2FourReg<
2550       (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2551             !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
2552             [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16),
2553                                                 (sra rGPR:$Rm, (i32 16)))))]>,
2554          Requires<[IsThumb2, HasThumb2DSP]> {
2555    let Inst{31-27} = 0b11111;
2556    let Inst{26-23} = 0b0110;
2557    let Inst{22-20} = 0b001;
2558    let Inst{7-6} = 0b00;
2559    let Inst{5-4} = 0b01;
2560  }
2561
2562  def TB : T2FourReg<
2563        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2564              !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
2565              [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
2566                                               (sext_inreg rGPR:$Rm, i16))))]>,
2567          Requires<[IsThumb2, HasThumb2DSP]> {
2568    let Inst{31-27} = 0b11111;
2569    let Inst{26-23} = 0b0110;
2570    let Inst{22-20} = 0b001;
2571    let Inst{7-6} = 0b00;
2572    let Inst{5-4} = 0b10;
2573  }
2574
2575  def TT : T2FourReg<
2576        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2577              !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
2578             [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
2579                                                 (sra rGPR:$Rm, (i32 16)))))]>,
2580          Requires<[IsThumb2, HasThumb2DSP]> {
2581    let Inst{31-27} = 0b11111;
2582    let Inst{26-23} = 0b0110;
2583    let Inst{22-20} = 0b001;
2584    let Inst{7-6} = 0b00;
2585    let Inst{5-4} = 0b11;
2586  }
2587
2588  def WB : T2FourReg<
2589        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2590              !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
2591              [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
2592                                    (sext_inreg rGPR:$Rm, i16)), (i32 16))))]>,
2593          Requires<[IsThumb2, HasThumb2DSP]> {
2594    let Inst{31-27} = 0b11111;
2595    let Inst{26-23} = 0b0110;
2596    let Inst{22-20} = 0b011;
2597    let Inst{7-6} = 0b00;
2598    let Inst{5-4} = 0b00;
2599  }
2600
2601  def WT : T2FourReg<
2602        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2603              !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
2604              [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
2605                                      (sra rGPR:$Rm, (i32 16))), (i32 16))))]>,
2606          Requires<[IsThumb2, HasThumb2DSP]> {
2607    let Inst{31-27} = 0b11111;
2608    let Inst{26-23} = 0b0110;
2609    let Inst{22-20} = 0b011;
2610    let Inst{7-6} = 0b00;
2611    let Inst{5-4} = 0b01;
2612  }
2613}
2614
2615defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2616defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2617
2618// Halfword multiple accumulate long: SMLAL<x><y>
2619def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd),
2620         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm",
2621           [/* For disassembly only; pattern left blank */]>,
2622          Requires<[IsThumb2, HasThumb2DSP]>;
2623def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd),
2624         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm",
2625           [/* For disassembly only; pattern left blank */]>,
2626          Requires<[IsThumb2, HasThumb2DSP]>;
2627def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd),
2628         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm",
2629           [/* For disassembly only; pattern left blank */]>,
2630          Requires<[IsThumb2, HasThumb2DSP]>;
2631def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd),
2632         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm",
2633           [/* For disassembly only; pattern left blank */]>,
2634          Requires<[IsThumb2, HasThumb2DSP]>;
2635
2636// Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2637def t2SMUAD: T2ThreeReg_mac<
2638            0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2639            IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []>,
2640          Requires<[IsThumb2, HasThumb2DSP]> {
2641  let Inst{15-12} = 0b1111;
2642}
2643def t2SMUADX:T2ThreeReg_mac<
2644            0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2645            IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []>,
2646          Requires<[IsThumb2, HasThumb2DSP]> {
2647  let Inst{15-12} = 0b1111;
2648}
2649def t2SMUSD: T2ThreeReg_mac<
2650            0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2651            IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []>,
2652          Requires<[IsThumb2, HasThumb2DSP]> {
2653  let Inst{15-12} = 0b1111;
2654}
2655def t2SMUSDX:T2ThreeReg_mac<
2656            0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
2657            IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []>,
2658          Requires<[IsThumb2, HasThumb2DSP]> {
2659  let Inst{15-12} = 0b1111;
2660}
2661def t2SMLAD   : T2FourReg_mac<
2662            0, 0b010, 0b0000, (outs rGPR:$Rd),
2663            (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad",
2664            "\t$Rd, $Rn, $Rm, $Ra", []>,
2665          Requires<[IsThumb2, HasThumb2DSP]>;
2666def t2SMLADX  : T2FourReg_mac<
2667            0, 0b010, 0b0001, (outs rGPR:$Rd),
2668            (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx",
2669            "\t$Rd, $Rn, $Rm, $Ra", []>,
2670          Requires<[IsThumb2, HasThumb2DSP]>;
2671def t2SMLSD   : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd),
2672            (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd",
2673            "\t$Rd, $Rn, $Rm, $Ra", []>,
2674          Requires<[IsThumb2, HasThumb2DSP]>;
2675def t2SMLSDX  : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd),
2676            (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx",
2677            "\t$Rd, $Rn, $Rm, $Ra", []>,
2678          Requires<[IsThumb2, HasThumb2DSP]>;
2679def t2SMLALD  : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2680                        (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, "smlald",
2681                        "\t$Ra, $Rd, $Rn, $Rm", []>,
2682          Requires<[IsThumb2, HasThumb2DSP]>;
2683def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2684                        (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaldx",
2685                        "\t$Ra, $Rd, $Rn, $Rm", []>,
2686          Requires<[IsThumb2, HasThumb2DSP]>;
2687def t2SMLSLD  : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2688                        (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlsld",
2689                        "\t$Ra, $Rd, $Rn, $Rm", []>,
2690          Requires<[IsThumb2, HasThumb2DSP]>;
2691def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2692                        (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx",
2693                        "\t$Ra, $Rd, $Rn, $Rm", []>,
2694          Requires<[IsThumb2, HasThumb2DSP]>;
2695
2696//===----------------------------------------------------------------------===//
2697//  Division Instructions.
2698//  Signed and unsigned division on v7-M
2699//
2700def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
2701                 "sdiv", "\t$Rd, $Rn, $Rm",
2702                 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
2703                 Requires<[HasDivide, IsThumb2]> {
2704  let Inst{31-27} = 0b11111;
2705  let Inst{26-21} = 0b011100;
2706  let Inst{20} = 0b1;
2707  let Inst{15-12} = 0b1111;
2708  let Inst{7-4} = 0b1111;
2709}
2710
2711def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
2712                 "udiv", "\t$Rd, $Rn, $Rm",
2713                 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
2714                 Requires<[HasDivide, IsThumb2]> {
2715  let Inst{31-27} = 0b11111;
2716  let Inst{26-21} = 0b011101;
2717  let Inst{20} = 0b1;
2718  let Inst{15-12} = 0b1111;
2719  let Inst{7-4} = 0b1111;
2720}
2721
2722//===----------------------------------------------------------------------===//
2723//  Misc. Arithmetic Instructions.
2724//
2725
2726class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2727      InstrItinClass itin, string opc, string asm, list<dag> pattern>
2728  : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2729  let Inst{31-27} = 0b11111;
2730  let Inst{26-22} = 0b01010;
2731  let Inst{21-20} = op1;
2732  let Inst{15-12} = 0b1111;
2733  let Inst{7-6} = 0b10;
2734  let Inst{5-4} = op2;
2735  let Rn{3-0} = Rm;
2736}
2737
2738def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2739                    "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>;
2740
2741def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2742                      "rbit", "\t$Rd, $Rm",
2743                      [(set rGPR:$Rd, (ARMrbit rGPR:$Rm))]>;
2744
2745def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2746                 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>;
2747
2748def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2749                       "rev16", ".w\t$Rd, $Rm",
2750                [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>;
2751
2752def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2753                       "revsh", ".w\t$Rd, $Rm",
2754                 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>;
2755
2756def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
2757                (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
2758            (t2REVSH rGPR:$Rm)>;
2759
2760def t2PKHBT : T2ThreeReg<
2761            (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
2762                  IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
2763                  [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
2764                                      (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
2765                                           0xFFFF0000)))]>,
2766                  Requires<[HasT2ExtractPack, IsThumb2]> {
2767  let Inst{31-27} = 0b11101;
2768  let Inst{26-25} = 0b01;
2769  let Inst{24-20} = 0b01100;
2770  let Inst{5} = 0; // BT form
2771  let Inst{4} = 0;
2772
2773  bits<5> sh;
2774  let Inst{14-12} = sh{4-2};
2775  let Inst{7-6}   = sh{1-0};
2776}
2777
2778// Alternate cases for PKHBT where identities eliminate some nodes.
2779def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2780            (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
2781            Requires<[HasT2ExtractPack, IsThumb2]>;
2782def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
2783            (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
2784            Requires<[HasT2ExtractPack, IsThumb2]>;
2785
2786// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2787// will match the pattern below.
2788def t2PKHTB : T2ThreeReg<
2789                  (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
2790                  IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
2791                  [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
2792                                       (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
2793                                            0xFFFF)))]>,
2794                  Requires<[HasT2ExtractPack, IsThumb2]> {
2795  let Inst{31-27} = 0b11101;
2796  let Inst{26-25} = 0b01;
2797  let Inst{24-20} = 0b01100;
2798  let Inst{5} = 1; // TB form
2799  let Inst{4} = 0;
2800
2801  bits<5> sh;
2802  let Inst{14-12} = sh{4-2};
2803  let Inst{7-6}   = sh{1-0};
2804}
2805
2806// Alternate cases for PKHTB where identities eliminate some nodes.  Note that
2807// a shift amount of 0 is *not legal* here, it is PKHBT instead.
2808def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
2809            (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
2810            Requires<[HasT2ExtractPack, IsThumb2]>;
2811def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
2812                (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
2813            (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
2814            Requires<[HasT2ExtractPack, IsThumb2]>;
2815
2816//===----------------------------------------------------------------------===//
2817//  Comparison Instructions...
2818//
2819defm t2CMP  : T2I_cmp_irs<0b1101, "cmp",
2820                          IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
2821                          BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>, "t2CMP">;
2822
2823def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, t2_so_imm:$imm),
2824            (t2CMPri  GPRnopc:$lhs, t2_so_imm:$imm)>;
2825def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, rGPR:$rhs),
2826            (t2CMPrr  GPRnopc:$lhs, rGPR:$rhs)>;
2827def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, t2_so_reg:$rhs),
2828            (t2CMPrs  GPRnopc:$lhs, t2_so_reg:$rhs)>;
2829
2830//FIXME: Disable CMN, as CCodes are backwards from compare expectations
2831//       Compare-to-zero still works out, just not the relationals
2832//defm t2CMN  : T2I_cmp_irs<0b1000, "cmn",
2833//                          BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
2834defm t2CMNz : T2I_cmp_irs<0b1000, "cmn",
2835                          IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
2836                          BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>,
2837                          "t2CMNz">;
2838
2839//def : T2Pat<(ARMcmp  GPR:$src, t2_so_imm_neg:$imm),
2840//            (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
2841
2842def : T2Pat<(ARMcmpZ  GPRnopc:$src, t2_so_imm_neg:$imm),
2843            (t2CMNzri GPRnopc:$src, t2_so_imm_neg:$imm)>;
2844
2845defm t2TST  : T2I_cmp_irs<0b0000, "tst",
2846                          IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
2847                         BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>,
2848                          "t2TST">;
2849defm t2TEQ  : T2I_cmp_irs<0b0100, "teq",
2850                          IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
2851                         BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>,
2852                          "t2TEQ">;
2853
2854// Conditional moves
2855// FIXME: should be able to write a pattern for ARMcmov, but can't use
2856// a two-value operand where a dag node expects two operands. :(
2857let neverHasSideEffects = 1 in {
2858def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
2859                            (ins rGPR:$false, rGPR:$Rm, pred:$p),
2860                            4, IIC_iCMOVr,
2861   [/*(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
2862                RegConstraint<"$false = $Rd">;
2863
2864let isMoveImm = 1 in
2865def t2MOVCCi : t2PseudoInst<(outs rGPR:$Rd),
2866                            (ins rGPR:$false, t2_so_imm:$imm, pred:$p),
2867                   4, IIC_iCMOVi,
2868[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm:$imm, imm:$cc, CCR:$ccr))*/]>,
2869                   RegConstraint<"$false = $Rd">;
2870
2871// FIXME: Pseudo-ize these. For now, just mark codegen only.
2872let isCodeGenOnly = 1 in {
2873let isMoveImm = 1 in
2874def t2MOVCCi16 : T2I<(outs rGPR:$Rd), (ins rGPR:$false, imm0_65535_expr:$imm),
2875                      IIC_iCMOVi,
2876                      "movw", "\t$Rd, $imm", []>,
2877                      RegConstraint<"$false = $Rd"> {
2878  let Inst{31-27} = 0b11110;
2879  let Inst{25} = 1;
2880  let Inst{24-21} = 0b0010;
2881  let Inst{20} = 0; // The S bit.
2882  let Inst{15} = 0;
2883
2884  bits<4> Rd;
2885  bits<16> imm;
2886
2887  let Inst{11-8}  = Rd;
2888  let Inst{19-16} = imm{15-12};
2889  let Inst{26}    = imm{11};
2890  let Inst{14-12} = imm{10-8};
2891  let Inst{7-0}   = imm{7-0};
2892}
2893
2894let isMoveImm = 1 in
2895def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
2896                               (ins rGPR:$false, i32imm:$src, pred:$p),
2897                    IIC_iCMOVix2, []>, RegConstraint<"$false = $dst">;
2898
2899let isMoveImm = 1 in
2900def t2MVNCCi : T2OneRegImm<(outs rGPR:$Rd), (ins rGPR:$false, t2_so_imm:$imm),
2901                   IIC_iCMOVi, "mvn", "\t$Rd, $imm",
2902[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm_not:$imm,
2903                   imm:$cc, CCR:$ccr))*/]>,
2904                   RegConstraint<"$false = $Rd"> {
2905  let Inst{31-27} = 0b11110;
2906  let Inst{25} = 0;
2907  let Inst{24-21} = 0b0011;
2908  let Inst{20} = 0; // The S bit.
2909  let Inst{19-16} = 0b1111; // Rn
2910  let Inst{15} = 0;
2911}
2912
2913class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
2914                   string opc, string asm, list<dag> pattern>
2915  : T2TwoRegShiftImm<oops, iops, itin, opc, asm, pattern> {
2916  let Inst{31-27} = 0b11101;
2917  let Inst{26-25} = 0b01;
2918  let Inst{24-21} = 0b0010;
2919  let Inst{20} = 0; // The S bit.
2920  let Inst{19-16} = 0b1111; // Rn
2921  let Inst{5-4} = opcod; // Shift type.
2922}
2923def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$Rd),
2924                             (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2925                             IIC_iCMOVsi, "lsl", ".w\t$Rd, $Rm, $imm", []>,
2926                 RegConstraint<"$false = $Rd">;
2927def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$Rd),
2928                             (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2929                             IIC_iCMOVsi, "lsr", ".w\t$Rd, $Rm, $imm", []>,
2930                 RegConstraint<"$false = $Rd">;
2931def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$Rd),
2932                             (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2933                             IIC_iCMOVsi, "asr", ".w\t$Rd, $Rm, $imm", []>,
2934                 RegConstraint<"$false = $Rd">;
2935def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$Rd),
2936                             (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2937                             IIC_iCMOVsi, "ror", ".w\t$Rd, $Rm, $imm", []>,
2938                 RegConstraint<"$false = $Rd">;
2939} // isCodeGenOnly = 1
2940} // neverHasSideEffects
2941
2942//===----------------------------------------------------------------------===//
2943// Atomic operations intrinsics
2944//
2945
2946// memory barriers protect the atomic sequences
2947let hasSideEffects = 1 in {
2948def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2949                  "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
2950                  Requires<[IsThumb, HasDB]> {
2951  bits<4> opt;
2952  let Inst{31-4} = 0xf3bf8f5;
2953  let Inst{3-0} = opt;
2954}
2955}
2956
2957def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2958                  "dsb", "\t$opt", []>,
2959                  Requires<[IsThumb, HasDB]> {
2960  bits<4> opt;
2961  let Inst{31-4} = 0xf3bf8f4;
2962  let Inst{3-0} = opt;
2963}
2964
2965def t2ISB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2966                  "isb", "\t$opt",
2967                  []>, Requires<[IsThumb2, HasDB]> {
2968  bits<4> opt;
2969  let Inst{31-4} = 0xf3bf8f6;
2970  let Inst{3-0} = opt;
2971}
2972
2973class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz,
2974                InstrItinClass itin, string opc, string asm, string cstr,
2975                list<dag> pattern, bits<4> rt2 = 0b1111>
2976  : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2977  let Inst{31-27} = 0b11101;
2978  let Inst{26-20} = 0b0001101;
2979  let Inst{11-8} = rt2;
2980  let Inst{7-6} = 0b01;
2981  let Inst{5-4} = opcod;
2982  let Inst{3-0} = 0b1111;
2983
2984  bits<4> addr;
2985  bits<4> Rt;
2986  let Inst{19-16} = addr;
2987  let Inst{15-12} = Rt;
2988}
2989class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz,
2990                InstrItinClass itin, string opc, string asm, string cstr,
2991                list<dag> pattern, bits<4> rt2 = 0b1111>
2992  : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2993  let Inst{31-27} = 0b11101;
2994  let Inst{26-20} = 0b0001100;
2995  let Inst{11-8} = rt2;
2996  let Inst{7-6} = 0b01;
2997  let Inst{5-4} = opcod;
2998
2999  bits<4> Rd;
3000  bits<4> addr;
3001  bits<4> Rt;
3002  let Inst{3-0}  = Rd;
3003  let Inst{19-16} = addr;
3004  let Inst{15-12} = Rt;
3005}
3006
3007let mayLoad = 1 in {
3008def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3009                         AddrModeNone, 4, NoItinerary,
3010                         "ldrexb", "\t$Rt, $addr", "", []>;
3011def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
3012                         AddrModeNone, 4, NoItinerary,
3013                         "ldrexh", "\t$Rt, $addr", "", []>;
3014def t2LDREX  : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
3015                       AddrModeNone, 4, NoItinerary,
3016                       "ldrex", "\t$Rt, $addr", "", []> {
3017  bits<4> Rt;
3018  bits<12> addr;
3019  let Inst{31-27} = 0b11101;
3020  let Inst{26-20} = 0b0000101;
3021  let Inst{19-16} = addr{11-8};
3022  let Inst{15-12} = Rt;
3023  let Inst{11-8} = 0b1111;
3024  let Inst{7-0} = addr{7-0};
3025}
3026let hasExtraDefRegAllocReq = 1 in
3027def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$Rt, rGPR:$Rt2),
3028                         (ins addr_offset_none:$addr),
3029                         AddrModeNone, 4, NoItinerary,
3030                         "ldrexd", "\t$Rt, $Rt2, $addr", "",
3031                         [], {?, ?, ?, ?}> {
3032  bits<4> Rt2;
3033  let Inst{11-8} = Rt2;
3034}
3035}
3036
3037let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
3038def t2STREXB : T2I_strex<0b00, (outs rGPR:$Rd),
3039                         (ins rGPR:$Rt, addr_offset_none:$addr),
3040                         AddrModeNone, 4, NoItinerary,
3041                         "strexb", "\t$Rd, $Rt, $addr", "", []>;
3042def t2STREXH : T2I_strex<0b01, (outs rGPR:$Rd),
3043                         (ins rGPR:$Rt, addr_offset_none:$addr),
3044                         AddrModeNone, 4, NoItinerary,
3045                         "strexh", "\t$Rd, $Rt, $addr", "", []>;
3046def t2STREX  : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3047                             t2addrmode_imm0_1020s4:$addr),
3048                  AddrModeNone, 4, NoItinerary,
3049                  "strex", "\t$Rd, $Rt, $addr", "",
3050                  []> {
3051  bits<4> Rd;
3052  bits<4> Rt;
3053  bits<12> addr;
3054  let Inst{31-27} = 0b11101;
3055  let Inst{26-20} = 0b0000100;
3056  let Inst{19-16} = addr{11-8};
3057  let Inst{15-12} = Rt;
3058  let Inst{11-8}  = Rd;
3059  let Inst{7-0} = addr{7-0};
3060}
3061}
3062
3063let hasExtraSrcRegAllocReq = 1, Constraints = "@earlyclobber $Rd" in
3064def t2STREXD : T2I_strex<0b11, (outs rGPR:$Rd),
3065                         (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
3066                         AddrModeNone, 4, NoItinerary,
3067                         "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
3068                         {?, ?, ?, ?}> {
3069  bits<4> Rt2;
3070  let Inst{11-8} = Rt2;
3071}
3072
3073def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", []>,
3074            Requires<[IsThumb2, HasV7]>  {
3075  let Inst{31-16} = 0xf3bf;
3076  let Inst{15-14} = 0b10;
3077  let Inst{13} = 0;
3078  let Inst{12} = 0;
3079  let Inst{11-8} = 0b1111;
3080  let Inst{7-4} = 0b0010;
3081  let Inst{3-0} = 0b1111;
3082}
3083
3084//===----------------------------------------------------------------------===//
3085// SJLJ Exception handling intrinsics
3086//   eh_sjlj_setjmp() is an instruction sequence to store the return
3087//   address and save #0 in R0 for the non-longjmp case.
3088//   Since by its nature we may be coming from some other function to get
3089//   here, and we're using the stack frame for the containing function to
3090//   save/restore registers, we can't keep anything live in regs across
3091//   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
3092//   when we get here from a longjmp(). We force everything out of registers
3093//   except for our own input by listing the relevant registers in Defs. By
3094//   doing so, we also cause the prologue/epilogue code to actively preserve
3095//   all of the callee-saved resgisters, which is exactly what we want.
3096//   $val is a scratch register for our use.
3097let Defs =
3098  [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR,
3099    QQQQ0, QQQQ1, QQQQ2, QQQQ3 ],
3100  hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3101  usesCustomInserter = 1 in {
3102  def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3103                               AddrModeNone, 0, NoItinerary, "", "",
3104                          [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3105                             Requires<[IsThumb2, HasVFP2]>;
3106}
3107
3108let Defs =
3109  [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR ],
3110  hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3111  usesCustomInserter = 1 in {
3112  def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
3113                               AddrModeNone, 0, NoItinerary, "", "",
3114                          [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
3115                                  Requires<[IsThumb2, NoVFP]>;
3116}
3117
3118
3119//===----------------------------------------------------------------------===//
3120// Control-Flow Instructions
3121//
3122
3123// FIXME: remove when we have a way to marking a MI with these properties.
3124// FIXME: Should pc be an implicit operand like PICADD, etc?
3125let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
3126    hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
3127def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
3128                                                   reglist:$regs, variable_ops),
3129                              4, IIC_iLoad_mBr, [],
3130            (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
3131                         RegConstraint<"$Rn = $wb">;
3132
3133let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
3134let isPredicable = 1 in
3135def t2B   : T2I<(outs), (ins uncondbrtarget:$target), IIC_Br,
3136                 "b", ".w\t$target",
3137                 [(br bb:$target)]> {
3138  let Inst{31-27} = 0b11110;
3139  let Inst{15-14} = 0b10;
3140  let Inst{12} = 1;
3141
3142  bits<20> target;
3143  let Inst{26} = target{19};
3144  let Inst{11} = target{18};
3145  let Inst{13} = target{17};
3146  let Inst{21-16} = target{16-11};
3147  let Inst{10-0} = target{10-0};
3148}
3149
3150let isNotDuplicable = 1, isIndirectBranch = 1 in {
3151def t2BR_JT : t2PseudoInst<(outs),
3152          (ins GPR:$target, GPR:$index, i32imm:$jt, i32imm:$id),
3153           0, IIC_Br,
3154          [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>;
3155
3156// FIXME: Add a non-pc based case that can be predicated.
3157def t2TBB_JT : t2PseudoInst<(outs),
3158        (ins GPR:$index, i32imm:$jt, i32imm:$id), 0, IIC_Br, []>;
3159
3160def t2TBH_JT : t2PseudoInst<(outs),
3161        (ins GPR:$index, i32imm:$jt, i32imm:$id), 0, IIC_Br, []>;
3162
3163def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
3164                    "tbb", "\t$addr", []> {
3165  bits<4> Rn;
3166  bits<4> Rm;
3167  let Inst{31-20} = 0b111010001101;
3168  let Inst{19-16} = Rn;
3169  let Inst{15-5} = 0b11110000000;
3170  let Inst{4} = 0; // B form
3171  let Inst{3-0} = Rm;
3172
3173  let DecoderMethod = "DecodeThumbTableBranch";
3174}
3175
3176def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
3177                   "tbh", "\t$addr", []> {
3178  bits<4> Rn;
3179  bits<4> Rm;
3180  let Inst{31-20} = 0b111010001101;
3181  let Inst{19-16} = Rn;
3182  let Inst{15-5} = 0b11110000000;
3183  let Inst{4} = 1; // H form
3184  let Inst{3-0} = Rm;
3185
3186  let DecoderMethod = "DecodeThumbTableBranch";
3187}
3188} // isNotDuplicable, isIndirectBranch
3189
3190} // isBranch, isTerminator, isBarrier
3191
3192// FIXME: should be able to write a pattern for ARMBrcond, but can't use
3193// a two-value operand where a dag node expects ", "two operands. :(
3194let isBranch = 1, isTerminator = 1 in
3195def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
3196                "b", ".w\t$target",
3197                [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
3198  let Inst{31-27} = 0b11110;
3199  let Inst{15-14} = 0b10;
3200  let Inst{12} = 0;
3201
3202  bits<4> p;
3203  let Inst{25-22} = p;
3204
3205  bits<21> target;
3206  let Inst{26} = target{20};
3207  let Inst{11} = target{19};
3208  let Inst{13} = target{18};
3209  let Inst{21-16} = target{17-12};
3210  let Inst{10-0} = target{11-1};
3211
3212  let DecoderMethod = "DecodeThumb2BCCInstruction";
3213}
3214
3215// Tail calls. The Darwin version of thumb tail calls uses a t2 branch, so
3216// it goes here.
3217let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3218  // Darwin version.
3219  let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
3220      Uses = [SP] in
3221  def tTAILJMPd: tPseudoExpand<(outs),
3222                   (ins uncondbrtarget:$dst, pred:$p, variable_ops),
3223                   4, IIC_Br, [],
3224                   (t2B uncondbrtarget:$dst, pred:$p)>,
3225                 Requires<[IsThumb2, IsDarwin]>;
3226}
3227
3228// IT block
3229let Defs = [ITSTATE] in
3230def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
3231                    AddrModeNone, 2,  IIC_iALUx,
3232                    "it$mask\t$cc", "", []> {
3233  // 16-bit instruction.
3234  let Inst{31-16} = 0x0000;
3235  let Inst{15-8} = 0b10111111;
3236
3237  bits<4> cc;
3238  bits<4> mask;
3239  let Inst{7-4} = cc;
3240  let Inst{3-0} = mask;
3241
3242  let DecoderMethod = "DecodeIT";
3243}
3244
3245// Branch and Exchange Jazelle -- for disassembly only
3246// Rm = Inst{19-16}
3247def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func", []> {
3248  bits<4> func;
3249  let Inst{31-27} = 0b11110;
3250  let Inst{26} = 0;
3251  let Inst{25-20} = 0b111100;
3252  let Inst{19-16} = func;
3253  let Inst{15-0} = 0b1000111100000000;
3254}
3255
3256// Compare and branch on zero / non-zero
3257let isBranch = 1, isTerminator = 1 in {
3258  def tCBZ  : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
3259                  "cbz\t$Rn, $target", []>,
3260              T1Misc<{0,0,?,1,?,?,?}>,
3261              Requires<[IsThumb2]> {
3262    // A8.6.27
3263    bits<6> target;
3264    bits<3> Rn;
3265    let Inst{9}   = target{5};
3266    let Inst{7-3} = target{4-0};
3267    let Inst{2-0} = Rn;
3268  }
3269
3270  def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
3271                  "cbnz\t$Rn, $target", []>,
3272              T1Misc<{1,0,?,1,?,?,?}>,
3273              Requires<[IsThumb2]> {
3274    // A8.6.27
3275    bits<6> target;
3276    bits<3> Rn;
3277    let Inst{9}   = target{5};
3278    let Inst{7-3} = target{4-0};
3279    let Inst{2-0} = Rn;
3280  }
3281}
3282
3283
3284// Change Processor State is a system instruction.
3285// FIXME: Since the asm parser has currently no clean way to handle optional
3286// operands, create 3 versions of the same instruction. Once there's a clean
3287// framework to represent optional operands, change this behavior.
3288class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3289            !strconcat("cps", asm_op), []> {
3290  bits<2> imod;
3291  bits<3> iflags;
3292  bits<5> mode;
3293  bit M;
3294
3295  let Inst{31-27} = 0b11110;
3296  let Inst{26}    = 0;
3297  let Inst{25-20} = 0b111010;
3298  let Inst{19-16} = 0b1111;
3299  let Inst{15-14} = 0b10;
3300  let Inst{12}    = 0;
3301  let Inst{10-9}  = imod;
3302  let Inst{8}     = M;
3303  let Inst{7-5}   = iflags;
3304  let Inst{4-0}   = mode;
3305  let DecoderMethod = "DecodeT2CPSInstruction";
3306}
3307
3308let M = 1 in
3309  def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3310                      "$imod.w\t$iflags, $mode">;
3311let mode = 0, M = 0 in
3312  def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3313                      "$imod.w\t$iflags">;
3314let imod = 0, iflags = 0, M = 1 in
3315  def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
3316
3317// A6.3.4 Branches and miscellaneous control
3318// Table A6-14 Change Processor State, and hint instructions
3319class T2I_hint<bits<8> op7_0, string opc, string asm>
3320  : T2I<(outs), (ins), NoItinerary, opc, asm, []> {
3321  let Inst{31-20} = 0xf3a;
3322  let Inst{19-16} = 0b1111;
3323  let Inst{15-14} = 0b10;
3324  let Inst{12} = 0;
3325  let Inst{10-8} = 0b000;
3326  let Inst{7-0} = op7_0;
3327}
3328
3329def t2NOP   : T2I_hint<0b00000000, "nop",   ".w">;
3330def t2YIELD : T2I_hint<0b00000001, "yield", ".w">;
3331def t2WFE   : T2I_hint<0b00000010, "wfe",   ".w">;
3332def t2WFI   : T2I_hint<0b00000011, "wfi",   ".w">;
3333def t2SEV   : T2I_hint<0b00000100, "sev",   ".w">;
3334
3335def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt", []> {
3336  bits<4> opt;
3337  let Inst{31-20} = 0b111100111010;
3338  let Inst{19-16} = 0b1111;
3339  let Inst{15-8} = 0b10000000;
3340  let Inst{7-4} = 0b1111;
3341  let Inst{3-0} = opt;
3342}
3343
3344// Secure Monitor Call is a system instruction.
3345// Option = Inst{19-16}
3346def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt", []> {
3347  let Inst{31-27} = 0b11110;
3348  let Inst{26-20} = 0b1111111;
3349  let Inst{15-12} = 0b1000;
3350
3351  bits<4> opt;
3352  let Inst{19-16} = opt;
3353}
3354
3355class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
3356            string opc, string asm, list<dag> pattern>
3357  : T2I<oops, iops, itin, opc, asm, pattern> {
3358  bits<5> mode;
3359  let Inst{31-25} = 0b1110100;
3360  let Inst{24-23} = Op;
3361  let Inst{22} = 0;
3362  let Inst{21} = W;
3363  let Inst{20-16} = 0b01101;
3364  let Inst{15-5} = 0b11000000000;
3365  let Inst{4-0} = mode{4-0};
3366}
3367
3368// Store Return State is a system instruction.
3369def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3370                        "srsdb", "\tsp!, $mode", []>;
3371def t2SRSDB  : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3372                     "srsdb","\tsp, $mode", []>;
3373def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3374                        "srsia","\tsp!, $mode", []>;
3375def t2SRSIA  : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3376                     "srsia","\tsp, $mode", []>;
3377
3378// Return From Exception is a system instruction.
3379class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
3380          string opc, string asm, list<dag> pattern>
3381  : T2I<oops, iops, itin, opc, asm, pattern> {
3382  let Inst{31-20} = op31_20{11-0};
3383
3384  bits<4> Rn;
3385  let Inst{19-16} = Rn;
3386  let Inst{15-0} = 0xc000;
3387}
3388
3389def t2RFEDBW : T2RFE<0b111010000011,
3390                   (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
3391                   [/* For disassembly only; pattern left blank */]>;
3392def t2RFEDB  : T2RFE<0b111010000001,
3393                   (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
3394                   [/* For disassembly only; pattern left blank */]>;
3395def t2RFEIAW : T2RFE<0b111010011011,
3396                   (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
3397                   [/* For disassembly only; pattern left blank */]>;
3398def t2RFEIA  : T2RFE<0b111010011001,
3399                   (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
3400                   [/* For disassembly only; pattern left blank */]>;
3401
3402//===----------------------------------------------------------------------===//
3403// Non-Instruction Patterns
3404//
3405
3406// 32-bit immediate using movw + movt.
3407// This is a single pseudo instruction to make it re-materializable.
3408// FIXME: Remove this when we can do generalized remat.
3409let isReMaterializable = 1, isMoveImm = 1 in
3410def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
3411                            [(set rGPR:$dst, (i32 imm:$src))]>,
3412                            Requires<[IsThumb, HasV6T2]>;
3413
3414// Pseudo instruction that combines movw + movt + add pc (if pic).
3415// It also makes it possible to rematerialize the instructions.
3416// FIXME: Remove this when we can do generalized remat and when machine licm
3417// can properly the instructions.
3418let isReMaterializable = 1 in {
3419def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3420                                IIC_iMOVix2addpc,
3421                          [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
3422                          Requires<[IsThumb2, UseMovt]>;
3423
3424def t2MOV_ga_dyn : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3425                              IIC_iMOVix2,
3426                          [(set rGPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
3427                          Requires<[IsThumb2, UseMovt]>;
3428}
3429
3430// ConstantPool, GlobalAddress, and JumpTable
3431def : T2Pat<(ARMWrapper  tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
3432           Requires<[IsThumb2, DontUseMovt]>;
3433def : T2Pat<(ARMWrapper  tconstpool  :$dst), (t2LEApcrel tconstpool  :$dst)>;
3434def : T2Pat<(ARMWrapper  tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
3435           Requires<[IsThumb2, UseMovt]>;
3436
3437def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
3438            (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
3439
3440// Pseudo instruction that combines ldr from constpool and add pc. This should
3441// be expanded into two instructions late to allow if-conversion and
3442// scheduling.
3443let canFoldAsLoad = 1, isReMaterializable = 1 in
3444def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
3445                   IIC_iLoadiALU,
3446              [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
3447                                           imm:$cp))]>,
3448               Requires<[IsThumb2]>;
3449
3450// Pseudo isntruction that combines movs + predicated rsbmi
3451// to implement integer ABS
3452let usesCustomInserter = 1, Defs = [CPSR] in {
3453def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
3454                       NoItinerary, []>, Requires<[IsThumb2]>;
3455}
3456
3457//===----------------------------------------------------------------------===//
3458// Coprocessor load/store -- for disassembly only
3459//
3460class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm>
3461  : T2I<oops, iops, NoItinerary, opc, asm, []> {
3462  let Inst{31-28} = op31_28;
3463  let Inst{27-25} = 0b110;
3464}
3465
3466multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm> {
3467  def _OFFSET : T2CI<op31_28,
3468                     (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
3469                     asm, "\t$cop, $CRd, $addr"> {
3470    bits<13> addr;
3471    bits<4> cop;
3472    bits<4> CRd;
3473    let Inst{24} = 1; // P = 1
3474    let Inst{23} = addr{8};
3475    let Inst{22} = Dbit;
3476    let Inst{21} = 0; // W = 0
3477    let Inst{20} = load;
3478    let Inst{19-16} = addr{12-9};
3479    let Inst{15-12} = CRd;
3480    let Inst{11-8} = cop;
3481    let Inst{7-0} = addr{7-0};
3482    let DecoderMethod = "DecodeCopMemInstruction";
3483  }
3484  def _PRE : T2CI<op31_28,
3485                  (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
3486                  asm, "\t$cop, $CRd, $addr!"> {
3487    bits<13> addr;
3488    bits<4> cop;
3489    bits<4> CRd;
3490    let Inst{24} = 1; // P = 1
3491    let Inst{23} = addr{8};
3492    let Inst{22} = Dbit;
3493    let Inst{21} = 1; // W = 1
3494    let Inst{20} = load;
3495    let Inst{19-16} = addr{12-9};
3496    let Inst{15-12} = CRd;
3497    let Inst{11-8} = cop;
3498    let Inst{7-0} = addr{7-0};
3499    let DecoderMethod = "DecodeCopMemInstruction";
3500  }
3501  def _POST: T2CI<op31_28,
3502                  (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
3503                               postidx_imm8s4:$offset),
3504                 asm, "\t$cop, $CRd, $addr, $offset"> {
3505    bits<9> offset;
3506    bits<4> addr;
3507    bits<4> cop;
3508    bits<4> CRd;
3509    let Inst{24} = 0; // P = 0
3510    let Inst{23} = offset{8};
3511    let Inst{22} = Dbit;
3512    let Inst{21} = 1; // W = 1
3513    let Inst{20} = load;
3514    let Inst{19-16} = addr;
3515    let Inst{15-12} = CRd;
3516    let Inst{11-8} = cop;
3517    let Inst{7-0} = offset{7-0};
3518    let DecoderMethod = "DecodeCopMemInstruction";
3519  }
3520  def _OPTION : T2CI<op31_28, (outs),
3521                     (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
3522                          coproc_option_imm:$option),
3523      asm, "\t$cop, $CRd, $addr, $option"> {
3524    bits<8> option;
3525    bits<4> addr;
3526    bits<4> cop;
3527    bits<4> CRd;
3528    let Inst{24} = 0; // P = 0
3529    let Inst{23} = 1; // U = 1
3530    let Inst{22} = Dbit;
3531    let Inst{21} = 0; // W = 0
3532    let Inst{20} = load;
3533    let Inst{19-16} = addr;
3534    let Inst{15-12} = CRd;
3535    let Inst{11-8} = cop;
3536    let Inst{7-0} = option;
3537    let DecoderMethod = "DecodeCopMemInstruction";
3538  }
3539}
3540
3541defm t2LDC   : t2LdStCop<0b1110, 1, 0, "ldc">;
3542defm t2LDCL  : t2LdStCop<0b1110, 1, 1, "ldcl">;
3543defm t2STC   : t2LdStCop<0b1110, 0, 0, "stc">;
3544defm t2STCL  : t2LdStCop<0b1110, 0, 1, "stcl">;
3545defm t2LDC2  : t2LdStCop<0b1111, 1, 0, "ldc2">;
3546defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l">;
3547defm t2STC2  : t2LdStCop<0b1111, 0, 0, "stc2">;
3548defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l">;
3549
3550
3551//===----------------------------------------------------------------------===//
3552// Move between special register and ARM core register -- for disassembly only
3553//
3554// Move to ARM core register from Special Register
3555
3556// A/R class MRS.
3557//
3558// A/R class can only move from CPSR or SPSR.
3559def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr", []>,
3560               Requires<[IsThumb2,IsARClass]> {
3561  bits<4> Rd;
3562  let Inst{31-12} = 0b11110011111011111000;
3563  let Inst{11-8} = Rd;
3564  let Inst{7-0} = 0b0000;
3565}
3566
3567def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
3568
3569def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr", []>,
3570                 Requires<[IsThumb2,IsARClass]> {
3571  bits<4> Rd;
3572  let Inst{31-12} = 0b11110011111111111000;
3573  let Inst{11-8} = Rd;
3574  let Inst{7-0} = 0b0000;
3575}
3576
3577// M class MRS.
3578//
3579// This MRS has a mask field in bits 7-0 and can take more values than
3580// the A/R class (a full msr_mask).
3581def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$mask), NoItinerary,
3582                  "mrs", "\t$Rd, $mask", []>,
3583              Requires<[IsThumb2,IsMClass]> {
3584  bits<4> Rd;
3585  bits<8> mask;
3586  let Inst{31-12} = 0b11110011111011111000;
3587  let Inst{11-8} = Rd;
3588  let Inst{19-16} = 0b1111;
3589  let Inst{7-0} = mask;
3590}
3591
3592
3593// Move from ARM core register to Special Register
3594//
3595// A/R class MSR.
3596//
3597// No need to have both system and application versions, the encodings are the
3598// same and the assembly parser has no way to distinguish between them. The mask
3599// operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
3600// the mask with the fields to be accessed in the special register.
3601def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
3602                   NoItinerary, "msr", "\t$mask, $Rn", []>,
3603               Requires<[IsThumb2,IsARClass]> {
3604  bits<5> mask;
3605  bits<4> Rn;
3606  let Inst{31-21} = 0b11110011100;
3607  let Inst{20}    = mask{4}; // R Bit
3608  let Inst{19-16} = Rn;
3609  let Inst{15-12} = 0b1000;
3610  let Inst{11-8}  = mask{3-0};
3611  let Inst{7-0}   = 0;
3612}
3613
3614// M class MSR.
3615//
3616// Move from ARM core register to Special Register
3617def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
3618                  NoItinerary, "msr", "\t$SYSm, $Rn", []>,
3619              Requires<[IsThumb2,IsMClass]> {
3620  bits<8> SYSm;
3621  bits<4> Rn;
3622  let Inst{31-21} = 0b11110011100;
3623  let Inst{20}    = 0b0;
3624  let Inst{19-16} = Rn;
3625  let Inst{15-12} = 0b1000;
3626  let Inst{7-0}  = SYSm;
3627}
3628
3629
3630//===----------------------------------------------------------------------===//
3631// Move between coprocessor and ARM core register
3632//
3633
3634class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
3635                  list<dag> pattern>
3636  : T2Cop<Op, oops, iops,
3637          !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
3638          pattern> {
3639  let Inst{27-24} = 0b1110;
3640  let Inst{20} = direction;
3641  let Inst{4} = 1;
3642
3643  bits<4> Rt;
3644  bits<4> cop;
3645  bits<3> opc1;
3646  bits<3> opc2;
3647  bits<4> CRm;
3648  bits<4> CRn;
3649
3650  let Inst{15-12} = Rt;
3651  let Inst{11-8}  = cop;
3652  let Inst{23-21} = opc1;
3653  let Inst{7-5}   = opc2;
3654  let Inst{3-0}   = CRm;
3655  let Inst{19-16} = CRn;
3656}
3657
3658class t2MovRRCopro<bits<4> Op, string opc, bit direction,
3659                   list<dag> pattern = []>
3660  : T2Cop<Op, (outs),
3661          (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
3662          !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
3663  let Inst{27-24} = 0b1100;
3664  let Inst{23-21} = 0b010;
3665  let Inst{20} = direction;
3666
3667  bits<4> Rt;
3668  bits<4> Rt2;
3669  bits<4> cop;
3670  bits<4> opc1;
3671  bits<4> CRm;
3672
3673  let Inst{15-12} = Rt;
3674  let Inst{19-16} = Rt2;
3675  let Inst{11-8}  = cop;
3676  let Inst{7-4}   = opc1;
3677  let Inst{3-0}   = CRm;
3678}
3679
3680/* from ARM core register to coprocessor */
3681def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
3682           (outs),
3683           (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3684                c_imm:$CRm, imm0_7:$opc2),
3685           [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3686                         imm:$CRm, imm:$opc2)]>;
3687def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
3688             (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3689                          c_imm:$CRm, imm0_7:$opc2),
3690             [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3691                            imm:$CRm, imm:$opc2)]>;
3692
3693/* from coprocessor to ARM core register */
3694def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
3695             (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3696                                  c_imm:$CRm, imm0_7:$opc2), []>;
3697
3698def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
3699             (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3700                                  c_imm:$CRm, imm0_7:$opc2), []>;
3701
3702def : T2v6Pat<(int_arm_mrc  imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
3703              (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3704
3705def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
3706              (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3707
3708
3709/* from ARM core register to coprocessor */
3710def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0,
3711                        [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
3712                                       imm:$CRm)]>;
3713def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0,
3714                           [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt,
3715                                           GPR:$Rt2, imm:$CRm)]>;
3716/* from coprocessor to ARM core register */
3717def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1>;
3718
3719def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1>;
3720
3721//===----------------------------------------------------------------------===//
3722// Other Coprocessor Instructions.
3723//
3724
3725def tCDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
3726                 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
3727                 "cdp\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
3728                 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3729                               imm:$CRm, imm:$opc2)]> {
3730  let Inst{27-24} = 0b1110;
3731
3732  bits<4> opc1;
3733  bits<4> CRn;
3734  bits<4> CRd;
3735  bits<4> cop;
3736  bits<3> opc2;
3737  bits<4> CRm;
3738
3739  let Inst{3-0}   = CRm;
3740  let Inst{4}     = 0;
3741  let Inst{7-5}   = opc2;
3742  let Inst{11-8}  = cop;
3743  let Inst{15-12} = CRd;
3744  let Inst{19-16} = CRn;
3745  let Inst{23-20} = opc1;
3746}
3747
3748def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
3749                   c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
3750                   "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
3751                   [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3752                                  imm:$CRm, imm:$opc2)]> {
3753  let Inst{27-24} = 0b1110;
3754
3755  bits<4> opc1;
3756  bits<4> CRn;
3757  bits<4> CRd;
3758  bits<4> cop;
3759  bits<3> opc2;
3760  bits<4> CRm;
3761
3762  let Inst{3-0}   = CRm;
3763  let Inst{4}     = 0;
3764  let Inst{7-5}   = opc2;
3765  let Inst{11-8}  = cop;
3766  let Inst{15-12} = CRd;
3767  let Inst{19-16} = CRn;
3768  let Inst{23-20} = opc1;
3769}
3770
3771
3772
3773//===----------------------------------------------------------------------===//
3774// Non-Instruction Patterns
3775//
3776
3777// SXT/UXT with no rotate
3778let AddedComplexity = 16 in {
3779def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
3780           Requires<[IsThumb2]>;
3781def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
3782           Requires<[IsThumb2]>;
3783def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
3784           Requires<[HasT2ExtractPack, IsThumb2]>;
3785def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
3786            (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
3787           Requires<[HasT2ExtractPack, IsThumb2]>;
3788def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
3789            (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
3790           Requires<[HasT2ExtractPack, IsThumb2]>;
3791}
3792
3793def : T2Pat<(sext_inreg rGPR:$Src, i8),  (t2SXTB rGPR:$Src, 0)>,
3794           Requires<[IsThumb2]>;
3795def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
3796           Requires<[IsThumb2]>;
3797def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
3798            (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
3799           Requires<[HasT2ExtractPack, IsThumb2]>;
3800def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
3801            (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
3802           Requires<[HasT2ExtractPack, IsThumb2]>;
3803
3804// Atomic load/store patterns
3805def : T2Pat<(atomic_load_8   t2addrmode_imm12:$addr),
3806            (t2LDRBi12  t2addrmode_imm12:$addr)>;
3807def : T2Pat<(atomic_load_8   t2addrmode_negimm8:$addr),
3808            (t2LDRBi8   t2addrmode_negimm8:$addr)>;
3809def : T2Pat<(atomic_load_8   t2addrmode_so_reg:$addr),
3810            (t2LDRBs    t2addrmode_so_reg:$addr)>;
3811def : T2Pat<(atomic_load_16  t2addrmode_imm12:$addr),
3812            (t2LDRHi12  t2addrmode_imm12:$addr)>;
3813def : T2Pat<(atomic_load_16  t2addrmode_negimm8:$addr),
3814            (t2LDRHi8   t2addrmode_negimm8:$addr)>;
3815def : T2Pat<(atomic_load_16  t2addrmode_so_reg:$addr),
3816            (t2LDRHs    t2addrmode_so_reg:$addr)>;
3817def : T2Pat<(atomic_load_32  t2addrmode_imm12:$addr),
3818            (t2LDRi12   t2addrmode_imm12:$addr)>;
3819def : T2Pat<(atomic_load_32  t2addrmode_negimm8:$addr),
3820            (t2LDRi8    t2addrmode_negimm8:$addr)>;
3821def : T2Pat<(atomic_load_32  t2addrmode_so_reg:$addr),
3822            (t2LDRs     t2addrmode_so_reg:$addr)>;
3823def : T2Pat<(atomic_store_8  t2addrmode_imm12:$addr, GPR:$val),
3824            (t2STRBi12  GPR:$val, t2addrmode_imm12:$addr)>;
3825def : T2Pat<(atomic_store_8  t2addrmode_negimm8:$addr, GPR:$val),
3826            (t2STRBi8   GPR:$val, t2addrmode_negimm8:$addr)>;
3827def : T2Pat<(atomic_store_8  t2addrmode_so_reg:$addr, GPR:$val),
3828            (t2STRBs    GPR:$val, t2addrmode_so_reg:$addr)>;
3829def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
3830            (t2STRHi12  GPR:$val, t2addrmode_imm12:$addr)>;
3831def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
3832            (t2STRHi8   GPR:$val, t2addrmode_negimm8:$addr)>;
3833def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
3834            (t2STRHs    GPR:$val, t2addrmode_so_reg:$addr)>;
3835def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
3836            (t2STRi12   GPR:$val, t2addrmode_imm12:$addr)>;
3837def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
3838            (t2STRi8    GPR:$val, t2addrmode_negimm8:$addr)>;
3839def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
3840            (t2STRs     GPR:$val, t2addrmode_so_reg:$addr)>;
3841
3842
3843//===----------------------------------------------------------------------===//
3844// Assembler aliases
3845//
3846
3847// Aliases for ADC without the ".w" optional width specifier.
3848def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
3849                  (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3850def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
3851                  (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
3852                           pred:$p, cc_out:$s)>;
3853
3854// Aliases for SBC without the ".w" optional width specifier.
3855def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
3856                  (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3857def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
3858                  (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
3859                           pred:$p, cc_out:$s)>;
3860
3861// Aliases for ADD without the ".w" optional width specifier.
3862def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
3863        (t2ADDri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3864def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
3865           (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
3866def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
3867              (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3868def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
3869                  (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
3870                           pred:$p, cc_out:$s)>;
3871// ... and with the destination and source register combined.
3872def : t2InstAlias<"add${s}${p} $Rdn, $imm",
3873      (t2ADDri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3874def : t2InstAlias<"add${p} $Rdn, $imm",
3875           (t2ADDri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
3876def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
3877            (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3878def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
3879                  (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
3880                           pred:$p, cc_out:$s)>;
3881
3882// Aliases for SUB without the ".w" optional width specifier.
3883def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
3884        (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3885def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
3886           (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
3887def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
3888              (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3889def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
3890                  (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
3891                           pred:$p, cc_out:$s)>;
3892// ... and with the destination and source register combined.
3893def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
3894      (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3895def : t2InstAlias<"sub${p} $Rdn, $imm",
3896           (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
3897def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
3898            (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3899def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
3900                  (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
3901                           pred:$p, cc_out:$s)>;
3902
3903
3904// Alias for compares without the ".w" optional width specifier.
3905def : t2InstAlias<"cmn${p} $Rn, $Rm",
3906                  (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
3907def : t2InstAlias<"teq${p} $Rn, $Rm",
3908                  (t2TEQrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
3909def : t2InstAlias<"tst${p} $Rn, $Rm",
3910                  (t2TSTrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
3911
3912// Memory barriers
3913def : InstAlias<"dmb", (t2DMB 0xf)>, Requires<[IsThumb2, HasDB]>;
3914def : InstAlias<"dsb", (t2DSB 0xf)>, Requires<[IsThumb2, HasDB]>;
3915def : InstAlias<"isb", (t2ISB 0xf)>, Requires<[IsThumb2, HasDB]>;
3916
3917// Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
3918// width specifier.
3919def : t2InstAlias<"ldr${p} $Rt, $addr",
3920                  (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3921def : t2InstAlias<"ldrb${p} $Rt, $addr",
3922                  (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3923def : t2InstAlias<"ldrh${p} $Rt, $addr",
3924                  (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3925def : t2InstAlias<"ldrsb${p} $Rt, $addr",
3926                  (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3927def : t2InstAlias<"ldrsh${p} $Rt, $addr",
3928                  (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
3929
3930def : t2InstAlias<"ldr${p} $Rt, $addr",
3931                  (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3932def : t2InstAlias<"ldrb${p} $Rt, $addr",
3933                  (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3934def : t2InstAlias<"ldrh${p} $Rt, $addr",
3935                  (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3936def : t2InstAlias<"ldrsb${p} $Rt, $addr",
3937                  (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3938def : t2InstAlias<"ldrsh${p} $Rt, $addr",
3939                  (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
3940
3941def : t2InstAlias<"ldr${p} $Rt, $addr",
3942                  (t2LDRpci GPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
3943def : t2InstAlias<"ldrb${p} $Rt, $addr",
3944                  (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
3945def : t2InstAlias<"ldrh${p} $Rt, $addr",
3946                  (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
3947def : t2InstAlias<"ldrsb${p} $Rt, $addr",
3948                  (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
3949def : t2InstAlias<"ldrsh${p} $Rt, $addr",
3950                  (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
3951
3952// Alias for MVN with(out) the ".w" optional width specifier.
3953def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
3954           (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
3955def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
3956           (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
3957def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
3958           (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
3959
3960// PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT when the
3961// shift amount is zero (i.e., unspecified).
3962def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
3963                (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
3964            Requires<[HasT2ExtractPack, IsThumb2]>;
3965def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
3966                (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
3967            Requires<[HasT2ExtractPack, IsThumb2]>;
3968
3969// PUSH/POP aliases for STM/LDM
3970def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
3971def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
3972def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
3973def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
3974
3975// STMIA/STMIA_UPD aliases w/o the optional .w suffix
3976def : t2InstAlias<"stm${p} $Rn, $regs",
3977                  (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
3978def : t2InstAlias<"stm${p} $Rn!, $regs",
3979                  (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
3980
3981// LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
3982def : t2InstAlias<"ldm${p} $Rn, $regs",
3983                  (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
3984def : t2InstAlias<"ldm${p} $Rn!, $regs",
3985                  (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
3986
3987// STMDB/STMDB_UPD aliases w/ the optional .w suffix
3988def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
3989                  (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
3990def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
3991                  (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
3992
3993// LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
3994def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
3995                  (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
3996def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
3997                  (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
3998
3999// Alias for REV/REV16/REVSH without the ".w" optional width specifier.
4000def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4001def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4002def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4003
4004
4005// Alias for RSB without the ".w" optional width specifier, and with optional
4006// implied destination register.
4007def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
4008           (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4009def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
4010           (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4011def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
4012           (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4013def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
4014           (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
4015                    cc_out:$s)>;
4016
4017// SSAT/USAT optional shift operand.
4018def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
4019                  (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4020def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
4021                  (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4022
4023// STM w/o the .w suffix.
4024def : t2InstAlias<"stm${p} $Rn, $regs",
4025                  (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4026
4027// Alias for STR, STRB, and STRH without the ".w" optional
4028// width specifier.
4029def : t2InstAlias<"str${p} $Rt, $addr",
4030                  (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4031def : t2InstAlias<"strb${p} $Rt, $addr",
4032                  (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4033def : t2InstAlias<"strh${p} $Rt, $addr",
4034                  (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4035
4036def : t2InstAlias<"str${p} $Rt, $addr",
4037                  (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4038def : t2InstAlias<"strb${p} $Rt, $addr",
4039                  (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4040def : t2InstAlias<"strh${p} $Rt, $addr",
4041                  (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4042
4043// Extend instruction optional rotate operand.
4044def : t2InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
4045                (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4046def : t2InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
4047                (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4048def : t2InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
4049                (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4050
4051def : t2InstAlias<"sxtb${p} $Rd, $Rm",
4052                (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4053def : t2InstAlias<"sxtb16${p} $Rd, $Rm",
4054                (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4055def : t2InstAlias<"sxth${p} $Rd, $Rm",
4056                (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4057def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
4058                (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4059def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
4060                (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4061
4062def : t2InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
4063                (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4064def : t2InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
4065                (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4066def : t2InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
4067                (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4068def : t2InstAlias<"uxtb${p} $Rd, $Rm",
4069                (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4070def : t2InstAlias<"uxtb16${p} $Rd, $Rm",
4071                (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4072def : t2InstAlias<"uxth${p} $Rd, $Rm",
4073                (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4074
4075def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
4076                (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4077def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
4078                (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4079
4080// Extend instruction w/o the ".w" optional width specifier.
4081def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
4082                  (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4083def : t2InstAlias<"uxtb16${p} $Rd, $Rm$rot",
4084                  (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4085def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
4086                  (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4087
4088def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
4089                  (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4090def : t2InstAlias<"sxtb16${p} $Rd, $Rm$rot",
4091                  (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4092def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
4093                  (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4094
4095
4096// "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
4097// for isel.
4098def : t2InstAlias<"mov${p} $Rd, $imm",
4099                  (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
4100// Likewise, "add Rd, so_imm_neg" -> sub
4101def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
4102                  (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
4103                           pred:$p, cc_out:$s)>;
4104def : t2InstAlias<"add${s}${p} $Rd, $imm",
4105                  (t2SUBri GPRnopc:$Rd, GPRnopc:$Rd, t2_so_imm_neg:$imm,
4106                           pred:$p, cc_out:$s)>;
4107
4108
4109// Wide 'mul' encoding can be specified with only two operands.
4110def : t2InstAlias<"mul${p} $Rn, $Rm",
4111                  (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
4112