Add mcr*2 and mr*c2 support to thumb2 targets
[oota-llvm.git] / lib / Target / ARM / ARMInstrFormats.td
1 //===- ARMInstrFormats.td - ARM Instruction Formats ----------*- tablegen -*-=//
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 //===----------------------------------------------------------------------===//
11 //
12 // ARM Instruction Format Definitions.
13 //
14
15 // Format specifies the encoding used by the instruction.  This is part of the
16 // ad-hoc solution used to emit machine instruction encodings by our machine
17 // code emitter.
18 class Format<bits<6> val> {
19   bits<6> Value = val;
20 }
21
22 def Pseudo        : Format<0>;
23 def MulFrm        : Format<1>;
24 def BrFrm         : Format<2>;
25 def BrMiscFrm     : Format<3>;
26
27 def DPFrm         : Format<4>;
28 def DPSoRegFrm    : Format<5>;
29
30 def LdFrm         : Format<6>;
31 def StFrm         : Format<7>;
32 def LdMiscFrm     : Format<8>;
33 def StMiscFrm     : Format<9>;
34 def LdStMulFrm    : Format<10>;
35
36 def LdStExFrm     : Format<11>;
37
38 def ArithMiscFrm  : Format<12>;
39 def SatFrm        : Format<13>;
40 def ExtFrm        : Format<14>;
41
42 def VFPUnaryFrm   : Format<15>;
43 def VFPBinaryFrm  : Format<16>;
44 def VFPConv1Frm   : Format<17>;
45 def VFPConv2Frm   : Format<18>;
46 def VFPConv3Frm   : Format<19>;
47 def VFPConv4Frm   : Format<20>;
48 def VFPConv5Frm   : Format<21>;
49 def VFPLdStFrm    : Format<22>;
50 def VFPLdStMulFrm : Format<23>;
51 def VFPMiscFrm    : Format<24>;
52
53 def ThumbFrm      : Format<25>;
54 def MiscFrm       : Format<26>;
55
56 def NGetLnFrm     : Format<27>;
57 def NSetLnFrm     : Format<28>;
58 def NDupFrm       : Format<29>;
59 def NLdStFrm      : Format<30>;
60 def N1RegModImmFrm: Format<31>;
61 def N2RegFrm      : Format<32>;
62 def NVCVTFrm      : Format<33>;
63 def NVDupLnFrm    : Format<34>;
64 def N2RegVShLFrm  : Format<35>;
65 def N2RegVShRFrm  : Format<36>;
66 def N3RegFrm      : Format<37>;
67 def N3RegVShFrm   : Format<38>;
68 def NVExtFrm      : Format<39>;
69 def NVMulSLFrm    : Format<40>;
70 def NVTBLFrm      : Format<41>;
71
72 // Misc flags.
73
74 // The instruction has an Rn register operand.
75 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
76 // it doesn't have a Rn operand.
77 class UnaryDP    { bit isUnaryDataProc = 1; }
78
79 // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
80 // a 16-bit Thumb instruction if certain conditions are met.
81 class Xform16Bit { bit canXformTo16Bit = 1; }
82
83 //===----------------------------------------------------------------------===//
84 // ARM Instruction flags.  These need to match ARMBaseInstrInfo.h.
85 //
86
87 // FIXME: Once the JIT is MC-ized, these can go away.
88 // Addressing mode.
89 class AddrMode<bits<5> val> {
90   bits<5> Value = val;
91 }
92 def AddrModeNone    : AddrMode<0>;
93 def AddrMode1       : AddrMode<1>;
94 def AddrMode2       : AddrMode<2>;
95 def AddrMode3       : AddrMode<3>;
96 def AddrMode4       : AddrMode<4>;
97 def AddrMode5       : AddrMode<5>;
98 def AddrMode6       : AddrMode<6>;
99 def AddrModeT1_1    : AddrMode<7>;
100 def AddrModeT1_2    : AddrMode<8>;
101 def AddrModeT1_4    : AddrMode<9>;
102 def AddrModeT1_s    : AddrMode<10>;
103 def AddrModeT2_i12  : AddrMode<11>;
104 def AddrModeT2_i8   : AddrMode<12>;
105 def AddrModeT2_so   : AddrMode<13>;
106 def AddrModeT2_pc   : AddrMode<14>;
107 def AddrModeT2_i8s4 : AddrMode<15>;
108 def AddrMode_i12    : AddrMode<16>;
109
110 // Instruction size.
111 class SizeFlagVal<bits<3> val> {
112   bits<3> Value = val;
113 }
114 def SizeInvalid  : SizeFlagVal<0>;  // Unset.
115 def SizeSpecial  : SizeFlagVal<1>;  // Pseudo or special.
116 def Size8Bytes   : SizeFlagVal<2>;
117 def Size4Bytes   : SizeFlagVal<3>;
118 def Size2Bytes   : SizeFlagVal<4>;
119
120 // Load / store index mode.
121 class IndexMode<bits<2> val> {
122   bits<2> Value = val;
123 }
124 def IndexModeNone : IndexMode<0>;
125 def IndexModePre  : IndexMode<1>;
126 def IndexModePost : IndexMode<2>;
127 def IndexModeUpd  : IndexMode<3>;
128
129 // Instruction execution domain.
130 class Domain<bits<2> val> {
131   bits<2> Value = val;
132 }
133 def GenericDomain : Domain<0>;
134 def VFPDomain     : Domain<1>; // Instructions in VFP domain only
135 def NeonDomain    : Domain<2>; // Instructions in Neon domain only
136 def VFPNeonDomain : Domain<3>; // Instructions in both VFP & Neon domains
137
138 //===----------------------------------------------------------------------===//
139 // ARM special operands.
140 //
141
142 def CondCodeOperand : AsmOperandClass {
143   let Name = "CondCode";
144   let SuperClasses = [];
145 }
146
147 def CCOutOperand : AsmOperandClass {
148   let Name = "CCOut";
149   let SuperClasses = [];
150 }
151
152 // ARM Predicate operand. Default to 14 = always (AL). Second part is CC
153 // register whose default is 0 (no register).
154 def pred : PredicateOperand<OtherVT, (ops i32imm, CCR),
155                                      (ops (i32 14), (i32 zero_reg))> {
156   let PrintMethod = "printPredicateOperand";
157   let ParserMatchClass = CondCodeOperand;
158 }
159
160 // Conditional code result for instructions whose 's' bit is set, e.g. subs.
161 def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
162   let EncoderMethod = "getCCOutOpValue";
163   let PrintMethod = "printSBitModifierOperand";
164   let ParserMatchClass = CCOutOperand;
165 }
166
167 // Same as cc_out except it defaults to setting CPSR.
168 def s_cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 CPSR))> {
169   let EncoderMethod = "getCCOutOpValue";
170   let PrintMethod = "printSBitModifierOperand";
171   let ParserMatchClass = CCOutOperand;
172 }
173
174 // ARM special operands for disassembly only.
175 //
176 def setend_op : Operand<i32> {
177   let PrintMethod = "printSetendOperand";
178 }
179
180 def cps_opt : Operand<i32> {
181   let PrintMethod = "printCPSOptionOperand";
182 }
183
184 def msr_mask : Operand<i32> {
185   let PrintMethod = "printMSRMaskOperand";
186 }
187
188 // A8.6.117, A8.6.118.  Different instructions are generated for #0 and #-0.
189 // The neg_zero operand translates -0 to -1, -1 to -2, ..., etc.
190 def neg_zero : Operand<i32> {
191   let PrintMethod = "printNegZeroOperand";
192 }
193
194 //===----------------------------------------------------------------------===//
195 // ARM Instruction templates.
196 //
197
198 class InstTemplate<AddrMode am, SizeFlagVal sz, IndexMode im,
199                    Format f, Domain d, string cstr, InstrItinClass itin>
200   : Instruction {
201   let Namespace = "ARM";
202
203   AddrMode AM = am;
204   SizeFlagVal SZ = sz;
205   IndexMode IM = im;
206   bits<2> IndexModeBits = IM.Value;
207   Format F = f;
208   bits<6> Form = F.Value;
209   Domain D = d;
210   bit isUnaryDataProc = 0;
211   bit canXformTo16Bit = 0;
212
213   // If this is a pseudo instruction, mark it isCodeGenOnly.
214   let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
215
216   // The layout of TSFlags should be kept in sync with ARMBaseInstrInfo.h.
217   let TSFlags{4-0}   = AM.Value;
218   let TSFlags{7-5}   = SZ.Value;
219   let TSFlags{9-8}   = IndexModeBits;
220   let TSFlags{15-10} = Form;
221   let TSFlags{16}    = isUnaryDataProc;
222   let TSFlags{17}    = canXformTo16Bit;
223   let TSFlags{19-18} = D.Value;
224
225   let Constraints = cstr;
226   let Itinerary = itin;
227 }
228
229 class Encoding {
230   field bits<32> Inst;
231 }
232
233 class InstARM<AddrMode am, SizeFlagVal sz, IndexMode im,
234               Format f, Domain d, string cstr, InstrItinClass itin>
235   : InstTemplate<am, sz, im, f, d, cstr, itin>, Encoding;
236
237 // This Encoding-less class is used by Thumb1 to specify the encoding bits later
238 // on by adding flavors to specific instructions.
239 class InstThumb<AddrMode am, SizeFlagVal sz, IndexMode im,
240                 Format f, Domain d, string cstr, InstrItinClass itin>
241   : InstTemplate<am, sz, im, f, d, cstr, itin>;
242
243 class PseudoInst<dag oops, dag iops, InstrItinClass itin, list<dag> pattern>
244   // FIXME: This really should derive from InstTemplate instead, as pseudos
245   //        don't need encoding information. TableGen doesn't like that
246   //        currently. Need to figure out why and fix it.
247   : InstARM<AddrModeNone, SizeSpecial, IndexModeNone, Pseudo, GenericDomain,
248             "", itin> {
249   let OutOperandList = oops;
250   let InOperandList = iops;
251   let Pattern = pattern;
252 }
253
254 // PseudoInst that's ARM-mode only.
255 class ARMPseudoInst<dag oops, dag iops, SizeFlagVal sz, InstrItinClass itin,
256                     list<dag> pattern>
257   : PseudoInst<oops, iops, itin, pattern> {
258   let SZ = sz;
259   list<Predicate> Predicates = [IsARM];
260 }
261
262 // PseudoInst that's Thumb-mode only.
263 class tPseudoInst<dag oops, dag iops, SizeFlagVal sz, InstrItinClass itin,
264                     list<dag> pattern>
265   : PseudoInst<oops, iops, itin, pattern> {
266   let SZ = sz;
267   list<Predicate> Predicates = [IsThumb];
268 }
269
270 // PseudoInst that's Thumb2-mode only.
271 class t2PseudoInst<dag oops, dag iops, SizeFlagVal sz, InstrItinClass itin,
272                     list<dag> pattern>
273   : PseudoInst<oops, iops, itin, pattern> {
274   let SZ = sz;
275   list<Predicate> Predicates = [IsThumb2];
276 }
277 // Almost all ARM instructions are predicable.
278 class I<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
279         IndexMode im, Format f, InstrItinClass itin,
280         string opc, string asm, string cstr,
281         list<dag> pattern>
282   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
283   bits<4> p;
284   let Inst{31-28} = p;
285   let OutOperandList = oops;
286   let InOperandList = !con(iops, (ins pred:$p));
287   let AsmString = !strconcat(opc, "${p}", asm);
288   let Pattern = pattern;
289   list<Predicate> Predicates = [IsARM];
290 }
291
292 // A few are not predicable
293 class InoP<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
294            IndexMode im, Format f, InstrItinClass itin,
295            string opc, string asm, string cstr,
296            list<dag> pattern>
297   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
298   let OutOperandList = oops;
299   let InOperandList = iops;
300   let AsmString = !strconcat(opc, asm);
301   let Pattern = pattern;
302   let isPredicable = 0;
303   list<Predicate> Predicates = [IsARM];
304 }
305
306 // Same as I except it can optionally modify CPSR. Note it's modeled as an input
307 // operand since by default it's a zero register. It will become an implicit def
308 // once it's "flipped".
309 class sI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
310          IndexMode im, Format f, InstrItinClass itin,
311          string opc, string asm, string cstr,
312          list<dag> pattern>
313   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
314   bits<4> p; // Predicate operand
315   bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
316   let Inst{31-28} = p;
317   let Inst{20} = s;
318
319   let OutOperandList = oops;
320   let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
321   let AsmString = !strconcat(opc, "${s}${p}", asm);
322   let Pattern = pattern;
323   list<Predicate> Predicates = [IsARM];
324 }
325
326 // Special cases
327 class XI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
328          IndexMode im, Format f, InstrItinClass itin,
329          string asm, string cstr, list<dag> pattern>
330   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
331   let OutOperandList = oops;
332   let InOperandList = iops;
333   let AsmString = asm;
334   let Pattern = pattern;
335   list<Predicate> Predicates = [IsARM];
336 }
337
338 class AI<dag oops, dag iops, Format f, InstrItinClass itin,
339          string opc, string asm, list<dag> pattern>
340   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, itin,
341       opc, asm, "", pattern>;
342 class AsI<dag oops, dag iops, Format f, InstrItinClass itin,
343           string opc, string asm, list<dag> pattern>
344   : sI<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, itin,
345        opc, asm, "", pattern>;
346 class AXI<dag oops, dag iops, Format f, InstrItinClass itin,
347           string asm, list<dag> pattern>
348   : XI<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, itin,
349        asm, "", pattern>;
350 class AInoP<dag oops, dag iops, Format f, InstrItinClass itin,
351             string opc, string asm, list<dag> pattern>
352   : InoP<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, itin,
353          opc, asm, "", pattern>;
354
355 // Ctrl flow instructions
356 class ABI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
357           string opc, string asm, list<dag> pattern>
358   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, BrFrm, itin,
359       opc, asm, "", pattern> {
360   let Inst{27-24} = opcod;
361 }
362 class ABXI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
363            string asm, list<dag> pattern>
364   : XI<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, BrFrm, itin,
365        asm, "", pattern> {
366   let Inst{27-24} = opcod;
367 }
368
369 // BR_JT instructions
370 class JTI<dag oops, dag iops, InstrItinClass itin,
371           string asm, list<dag> pattern>
372   : XI<oops, iops, AddrModeNone, SizeSpecial, IndexModeNone, BrMiscFrm, itin,
373        asm, "", pattern>;
374
375 // Atomic load/store instructions
376 class AIldrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
377               string opc, string asm, list<dag> pattern>
378   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, LdStExFrm, itin,
379       opc, asm, "", pattern> {
380   bits<4> Rt;
381   bits<4> Rn;
382   let Inst{27-23} = 0b00011;
383   let Inst{22-21} = opcod;
384   let Inst{20}    = 1;
385   let Inst{19-16} = Rn;
386   let Inst{15-12} = Rt;
387   let Inst{11-0}  = 0b111110011111;
388 }
389 class AIstrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
390               string opc, string asm, list<dag> pattern>
391   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, LdStExFrm, itin,
392       opc, asm, "", pattern> {
393   bits<4> Rd;
394   bits<4> Rt;
395   bits<4> Rn;
396   let Inst{27-23} = 0b00011;
397   let Inst{22-21} = opcod;
398   let Inst{20}    = 0;
399   let Inst{19-16} = Rn;
400   let Inst{15-12} = Rd;
401   let Inst{11-4}  = 0b11111001;
402   let Inst{3-0}   = Rt;
403 }
404 class AIswp<bit b, dag oops, dag iops, string opc, list<dag> pattern>
405   : AI<oops, iops, MiscFrm, NoItinerary, opc, "\t$Rt, $Rt2, [$Rn]", pattern> {
406   bits<4> Rt;
407   bits<4> Rt2;
408   bits<4> Rn;
409   let Inst{27-23} = 0b00010;
410   let Inst{22} = b;
411   let Inst{21-20} = 0b00;
412   let Inst{19-16} = Rn;
413   let Inst{15-12} = Rt;
414   let Inst{11-4} = 0b00001001;
415   let Inst{3-0} = Rt2;
416 }
417
418 // addrmode1 instructions
419 class AI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
420           string opc, string asm, list<dag> pattern>
421   : I<oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, itin,
422       opc, asm, "", pattern> {
423   let Inst{24-21} = opcod;
424   let Inst{27-26} = 0b00;
425 }
426 class AsI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
427            string opc, string asm, list<dag> pattern>
428   : sI<oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, itin,
429        opc, asm, "", pattern> {
430   let Inst{24-21} = opcod;
431   let Inst{27-26} = 0b00;
432 }
433 class AXI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
434            string asm, list<dag> pattern>
435   : XI<oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, itin,
436        asm, "", pattern> {
437   let Inst{24-21} = opcod;
438   let Inst{27-26} = 0b00;
439 }
440
441 // loads
442
443 // LDR/LDRB/STR/STRB/...
444 class AI2ldst<bits<3> op, bit isLd, bit isByte, dag oops, dag iops, AddrMode am,
445              Format f, InstrItinClass itin, string opc, string asm,
446              list<dag> pattern>
447   : I<oops, iops, am, Size4Bytes, IndexModeNone, f, itin, opc, asm,
448       "", pattern> {
449   let Inst{27-25} = op;
450   let Inst{24} = 1;  // 24 == P
451   // 23 == U
452   let Inst{22} = isByte;
453   let Inst{21} = 0;  // 21 == W
454   let Inst{20} = isLd;
455 }
456 // Indexed load/stores
457 class AI2ldstidx<bit isLd, bit isByte, bit isPre, dag oops, dag iops,
458                 IndexMode im, Format f, InstrItinClass itin, string opc,
459                 string asm, string cstr, list<dag> pattern>
460   : I<oops, iops, AddrMode2, Size4Bytes, im, f, itin,
461       opc, asm, cstr, pattern> {
462   bits<4> Rt;
463   let Inst{27-26} = 0b01;
464   let Inst{24}    = isPre; // P bit
465   let Inst{22}    = isByte; // B bit
466   let Inst{21}    = isPre; // W bit
467   let Inst{20}    = isLd; // L bit
468   let Inst{15-12} = Rt;
469 }
470 class AI2stridx<bit isByte, bit isPre, dag oops, dag iops,
471                 IndexMode im, Format f, InstrItinClass itin, string opc,
472                 string asm, string cstr, list<dag> pattern>
473   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
474                pattern> {
475   // AM2 store w/ two operands: (GPR, am2offset)
476   // {13}     1 == Rm, 0 == imm12
477   // {12}     isAdd
478   // {11-0}   imm12/Rm
479   bits<14> offset;
480   bits<4> Rn;
481   let Inst{25} = offset{13};
482   let Inst{23} = offset{12};
483   let Inst{19-16} = Rn;
484   let Inst{11-0} = offset{11-0};
485 }
486
487 // addrmode3 instructions
488 class AI3ld<bits<4> op, bit op20, dag oops, dag iops, Format f,
489             InstrItinClass itin, string opc, string asm, list<dag> pattern>
490   : I<oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, itin,
491       opc, asm, "", pattern> {
492   bits<14> addr;
493   bits<4> Rt;
494   let Inst{27-25} = 0b000;
495   let Inst{24}    = 1;            // P bit
496   let Inst{23}    = addr{8};      // U bit
497   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
498   let Inst{21}    = 0;            // W bit
499   let Inst{20}    = op20;         // L bit
500   let Inst{19-16} = addr{12-9};   // Rn
501   let Inst{15-12} = Rt;           // Rt
502   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
503   let Inst{7-4}   = op;
504   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
505 }
506
507 class AI3ldstidx<bits<4> op, bit op20, bit isLd, bit isPre, dag oops, dag iops,
508                 IndexMode im, Format f, InstrItinClass itin, string opc,
509                 string asm, string cstr, list<dag> pattern>
510   : I<oops, iops, AddrMode3, Size4Bytes, im, f, itin,
511       opc, asm, cstr, pattern> {
512   bits<4> Rt;
513   let Inst{27-25} = 0b000;
514   let Inst{24}    = isPre;        // P bit
515   let Inst{21}    = isPre;        // W bit
516   let Inst{20}    = op20;         // L bit
517   let Inst{15-12} = Rt;           // Rt
518   let Inst{7-4}   = op;
519 }
520 class AI3stridx<bits<4> op, bit isByte, bit isPre, dag oops, dag iops,
521                 IndexMode im, Format f, InstrItinClass itin, string opc,
522                 string asm, string cstr, list<dag> pattern>
523   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
524                pattern> {
525   // AM3 store w/ two operands: (GPR, am3offset)
526   bits<14> offset;
527   bits<4> Rt;
528   bits<4> Rn;
529   let Inst{27-25} = 0b000;
530   let Inst{23}    = offset{8};
531   let Inst{22}    = offset{9};
532   let Inst{19-16} = Rn;
533   let Inst{15-12} = Rt;           // Rt
534   let Inst{11-8}  = offset{7-4};  // imm7_4/zero
535   let Inst{7-4}   = op;
536   let Inst{3-0}   = offset{3-0};  // imm3_0/Rm
537 }
538
539 // stores
540 class AI3str<bits<4> op, dag oops, dag iops, Format f, InstrItinClass itin,
541              string opc, string asm, list<dag> pattern>
542   : I<oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, itin,
543       opc, asm, "", pattern> {
544   bits<14> addr;
545   bits<4> Rt;
546   let Inst{27-25} = 0b000;
547   let Inst{24}    = 1;            // P bit
548   let Inst{23}    = addr{8};      // U bit
549   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
550   let Inst{21}    = 0;            // W bit
551   let Inst{20}    = 0;            // L bit
552   let Inst{19-16} = addr{12-9};   // Rn
553   let Inst{15-12} = Rt;           // Rt
554   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
555   let Inst{7-4}   = op;
556   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
557 }
558
559 // Pre-indexed stores
560 class AI3sthpr<dag oops, dag iops, Format f, InstrItinClass itin,
561                string opc, string asm, string cstr, list<dag> pattern>
562   : I<oops, iops, AddrMode3, Size4Bytes, IndexModePre, f, itin,
563       opc, asm, cstr, pattern> {
564   let Inst{4}     = 1;
565   let Inst{5}     = 1; // H bit
566   let Inst{6}     = 0; // S bit
567   let Inst{7}     = 1;
568   let Inst{20}    = 0; // L bit
569   let Inst{21}    = 1; // W bit
570   let Inst{24}    = 1; // P bit
571   let Inst{27-25} = 0b000;
572 }
573 class AI3stdpr<dag oops, dag iops, Format f, InstrItinClass itin,
574              string opc, string asm, string cstr, list<dag> pattern>
575   : I<oops, iops, AddrMode3, Size4Bytes, IndexModePre, f, itin,
576       opc, asm, cstr, pattern> {
577   let Inst{4}     = 1;
578   let Inst{5}     = 1; // H bit
579   let Inst{6}     = 1; // S bit
580   let Inst{7}     = 1;
581   let Inst{20}    = 0; // L bit
582   let Inst{21}    = 1; // W bit
583   let Inst{24}    = 1; // P bit
584   let Inst{27-25} = 0b000;
585 }
586
587 // Post-indexed stores
588 class AI3sthpo<dag oops, dag iops, Format f, InstrItinClass itin,
589                string opc, string asm, string cstr, list<dag> pattern>
590   : I<oops, iops, AddrMode3, Size4Bytes, IndexModePost, f, itin,
591       opc, asm, cstr,pattern> {
592   let Inst{4}     = 1;
593   let Inst{5}     = 1; // H bit
594   let Inst{6}     = 0; // S bit
595   let Inst{7}     = 1;
596   let Inst{20}    = 0; // L bit
597   let Inst{21}    = 0; // W bit
598   let Inst{24}    = 0; // P bit
599   let Inst{27-25} = 0b000;
600 }
601 class AI3stdpo<dag oops, dag iops, Format f, InstrItinClass itin,
602              string opc, string asm, string cstr, list<dag> pattern>
603   : I<oops, iops, AddrMode3, Size4Bytes, IndexModePost, f, itin,
604       opc, asm, cstr, pattern> {
605   let Inst{4}     = 1;
606   let Inst{5}     = 1; // H bit
607   let Inst{6}     = 1; // S bit
608   let Inst{7}     = 1;
609   let Inst{20}    = 0; // L bit
610   let Inst{21}    = 0; // W bit
611   let Inst{24}    = 0; // P bit
612   let Inst{27-25} = 0b000;
613 }
614
615 // addrmode4 instructions
616 class AXI4<dag oops, dag iops, IndexMode im, Format f, InstrItinClass itin,
617            string asm, string cstr, list<dag> pattern>
618   : XI<oops, iops, AddrMode4, Size4Bytes, im, f, itin, asm, cstr, pattern> {
619   bits<4>  p;
620   bits<16> regs;
621   bits<4>  Rn;
622   let Inst{31-28} = p;
623   let Inst{27-25} = 0b100;
624   let Inst{22}    = 0; // S bit
625   let Inst{19-16} = Rn;
626   let Inst{15-0}  = regs;
627 }
628
629 // Unsigned multiply, multiply-accumulate instructions.
630 class AMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
631              string opc, string asm, list<dag> pattern>
632   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, MulFrm, itin,
633       opc, asm, "", pattern> {
634   let Inst{7-4}   = 0b1001;
635   let Inst{20}    = 0; // S bit
636   let Inst{27-21} = opcod;
637 }
638 class AsMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
639               string opc, string asm, list<dag> pattern>
640   : sI<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, MulFrm, itin,
641        opc, asm, "", pattern> {
642   let Inst{7-4}   = 0b1001;
643   let Inst{27-21} = opcod;
644 }
645
646 // Most significant word multiply
647 class AMul2I<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
648              InstrItinClass itin, string opc, string asm, list<dag> pattern>
649   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, MulFrm, itin,
650       opc, asm, "", pattern> {
651   bits<4> Rd;
652   bits<4> Rn;
653   bits<4> Rm;
654   let Inst{7-4}   = opc7_4;
655   let Inst{20}    = 1;
656   let Inst{27-21} = opcod;
657   let Inst{19-16} = Rd;
658   let Inst{11-8}  = Rm;
659   let Inst{3-0}   = Rn;
660 }
661 // MSW multiple w/ Ra operand
662 class AMul2Ia<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
663               InstrItinClass itin, string opc, string asm, list<dag> pattern>
664   : AMul2I<opcod, opc7_4, oops, iops, itin, opc, asm, pattern> {
665   bits<4> Ra;
666   let Inst{15-12} = Ra;
667 }
668
669 // SMUL<x><y> / SMULW<y> / SMLA<x><y> / SMLAW<x><y>
670 class AMulxyIbase<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
671               InstrItinClass itin, string opc, string asm, list<dag> pattern>
672   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, MulFrm, itin,
673       opc, asm, "", pattern> {
674   bits<4> Rn;
675   bits<4> Rm;
676   let Inst{4}     = 0;
677   let Inst{7}     = 1;
678   let Inst{20}    = 0;
679   let Inst{27-21} = opcod;
680   let Inst{6-5}   = bit6_5;
681   let Inst{11-8}  = Rm;
682   let Inst{3-0}   = Rn;
683 }
684 class AMulxyI<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
685               InstrItinClass itin, string opc, string asm, list<dag> pattern>
686   : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
687   bits<4> Rd;
688   let Inst{19-16} = Rd;
689 }
690
691 // AMulxyI with Ra operand
692 class AMulxyIa<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
693               InstrItinClass itin, string opc, string asm, list<dag> pattern>
694   : AMulxyI<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
695   bits<4> Ra;
696   let Inst{15-12} = Ra;
697 }
698 // SMLAL*
699 class AMulxyI64<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
700               InstrItinClass itin, string opc, string asm, list<dag> pattern>
701   : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
702   bits<4> RdLo;
703   bits<4> RdHi;
704   let Inst{19-16} = RdHi;
705   let Inst{15-12} = RdLo;
706 }
707
708 // Extend instructions.
709 class AExtI<bits<8> opcod, dag oops, dag iops, InstrItinClass itin,
710             string opc, string asm, list<dag> pattern>
711   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, ExtFrm, itin,
712       opc, asm, "", pattern> {
713   // All AExtI instructions have Rd and Rm register operands.
714   bits<4> Rd;
715   bits<4> Rm;
716   let Inst{15-12} = Rd;
717   let Inst{3-0}   = Rm;
718   let Inst{7-4}   = 0b0111;
719   let Inst{9-8}   = 0b00;
720   let Inst{27-20} = opcod;
721 }
722
723 // Misc Arithmetic instructions.
724 class AMiscA1I<bits<8> opcod, bits<4> opc7_4, dag oops, dag iops,
725                InstrItinClass itin, string opc, string asm, list<dag> pattern>
726   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, ArithMiscFrm, itin,
727       opc, asm, "", pattern> {
728   bits<4> Rd;
729   bits<4> Rm;
730   let Inst{27-20} = opcod;
731   let Inst{19-16} = 0b1111;
732   let Inst{15-12} = Rd;
733   let Inst{11-8}  = 0b1111;
734   let Inst{7-4}   = opc7_4;
735   let Inst{3-0}   = Rm;
736 }
737
738 // PKH instructions
739 class APKHI<bits<8> opcod, bit tb, dag oops, dag iops, InstrItinClass itin,
740             string opc, string asm, list<dag> pattern>
741   : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, ArithMiscFrm, itin,
742       opc, asm, "", pattern> {
743   bits<4> Rd;
744   bits<4> Rn;
745   bits<4> Rm;
746   bits<8> sh;
747   let Inst{27-20} = opcod;
748   let Inst{19-16} = Rn;
749   let Inst{15-12} = Rd;
750   let Inst{11-7}  = sh{7-3};
751   let Inst{6}     = tb;
752   let Inst{5-4}   = 0b01;
753   let Inst{3-0}   = Rm;
754 }
755
756 //===----------------------------------------------------------------------===//
757
758 // ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
759 class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
760   list<Predicate> Predicates = [IsARM];
761 }
762 class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
763   list<Predicate> Predicates = [IsARM, HasV5TE];
764 }
765 class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
766   list<Predicate> Predicates = [IsARM, HasV6];
767 }
768
769 //===----------------------------------------------------------------------===//
770 // Thumb Instruction Format Definitions.
771 //
772
773 class ThumbI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
774              InstrItinClass itin, string asm, string cstr, list<dag> pattern>
775   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
776   let OutOperandList = oops;
777   let InOperandList = iops;
778   let AsmString = asm;
779   let Pattern = pattern;
780   list<Predicate> Predicates = [IsThumb];
781 }
782
783 // TI - Thumb instruction.
784 class TI<dag oops, dag iops, InstrItinClass itin, string asm, list<dag> pattern>
785   : ThumbI<oops, iops, AddrModeNone, Size2Bytes, itin, asm, "", pattern>;
786
787 // Two-address instructions
788 class TIt<dag oops, dag iops, InstrItinClass itin, string asm,
789           list<dag> pattern>
790   : ThumbI<oops, iops, AddrModeNone, Size2Bytes, itin, asm, "$lhs = $dst",
791            pattern>;
792
793 // tBL, tBX 32-bit instructions
794 class TIx2<bits<5> opcod1, bits<2> opcod2, bit opcod3,
795            dag oops, dag iops, InstrItinClass itin, string asm,
796            list<dag> pattern>
797     : ThumbI<oops, iops, AddrModeNone, Size4Bytes, itin, asm, "", pattern>,
798       Encoding {
799   let Inst{31-27} = opcod1;
800   let Inst{15-14} = opcod2;
801   let Inst{12}    = opcod3;
802 }
803
804 // Move to/from coprocessor instructions
805 class T1Cop<dag oops, dag iops, string asm, list<dag> pattern>
806   : ThumbI<oops, iops, AddrModeNone, Size4Bytes, NoItinerary, asm, "", pattern>,
807     Encoding, Requires<[IsThumb, HasV6]> {
808   let Inst{31-28} = 0b1110;
809 }
810
811 // BR_JT instructions
812 class TJTI<dag oops, dag iops, InstrItinClass itin, string asm,
813            list<dag> pattern>
814   : ThumbI<oops, iops, AddrModeNone, SizeSpecial, itin, asm, "", pattern>;
815
816 // Thumb1 only
817 class Thumb1I<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
818               InstrItinClass itin, string asm, string cstr, list<dag> pattern>
819   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
820   let OutOperandList = oops;
821   let InOperandList = iops;
822   let AsmString = asm;
823   let Pattern = pattern;
824   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
825 }
826
827 class T1I<dag oops, dag iops, InstrItinClass itin,
828           string asm, list<dag> pattern>
829   : Thumb1I<oops, iops, AddrModeNone, Size2Bytes, itin, asm, "", pattern>;
830 class T1Ix2<dag oops, dag iops, InstrItinClass itin,
831             string asm, list<dag> pattern>
832   : Thumb1I<oops, iops, AddrModeNone, Size4Bytes, itin, asm, "", pattern>;
833
834 // Two-address instructions
835 class T1It<dag oops, dag iops, InstrItinClass itin,
836            string asm, string cstr, list<dag> pattern>
837   : Thumb1I<oops, iops, AddrModeNone, Size2Bytes, itin,
838             asm, cstr, pattern>;
839
840 // Thumb1 instruction that can either be predicated or set CPSR.
841 class Thumb1sI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
842                InstrItinClass itin,
843                string opc, string asm, string cstr, list<dag> pattern>
844   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
845   let OutOperandList = !con(oops, (outs s_cc_out:$s));
846   let InOperandList = !con(iops, (ins pred:$p));
847   let AsmString = !strconcat(opc, "${s}${p}", asm);
848   let Pattern = pattern;
849   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
850 }
851
852 class T1sI<dag oops, dag iops, InstrItinClass itin,
853            string opc, string asm, list<dag> pattern>
854   : Thumb1sI<oops, iops, AddrModeNone, Size2Bytes, itin, opc, asm, "", pattern>;
855
856 // Two-address instructions
857 class T1sIt<dag oops, dag iops, InstrItinClass itin,
858             string opc, string asm, list<dag> pattern>
859   : Thumb1sI<oops, iops, AddrModeNone, Size2Bytes, itin, opc, asm,
860              "$Rn = $Rdn", pattern>;
861
862 // Thumb1 instruction that can be predicated.
863 class Thumb1pI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
864                InstrItinClass itin,
865                string opc, string asm, string cstr, list<dag> pattern>
866   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
867   let OutOperandList = oops;
868   let InOperandList = !con(iops, (ins pred:$p));
869   let AsmString = !strconcat(opc, "${p}", asm);
870   let Pattern = pattern;
871   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
872 }
873
874 class T1pI<dag oops, dag iops, InstrItinClass itin,
875            string opc, string asm, list<dag> pattern>
876   : Thumb1pI<oops, iops, AddrModeNone, Size2Bytes, itin, opc, asm, "", pattern>;
877
878 // Two-address instructions
879 class T1pIt<dag oops, dag iops, InstrItinClass itin,
880             string opc, string asm, list<dag> pattern>
881   : Thumb1pI<oops, iops, AddrModeNone, Size2Bytes, itin, opc, asm,
882              "$Rn = $Rdn", pattern>;
883
884 class T1pIs<dag oops, dag iops,
885             InstrItinClass itin, string opc, string asm, list<dag> pattern>
886   : Thumb1pI<oops, iops, AddrModeT1_s, Size2Bytes, itin, opc, asm, "", pattern>;
887
888 class Encoding16 : Encoding {
889   let Inst{31-16} = 0x0000;
890 }
891
892 // A6.2 16-bit Thumb instruction encoding
893 class T1Encoding<bits<6> opcode> : Encoding16 {
894   let Inst{15-10} = opcode;
895 }
896
897 // A6.2.1 Shift (immediate), add, subtract, move, and compare encoding.
898 class T1General<bits<5> opcode> : Encoding16 {
899   let Inst{15-14} = 0b00;
900   let Inst{13-9} = opcode;
901 }
902
903 // A6.2.2 Data-processing encoding.
904 class T1DataProcessing<bits<4> opcode> : Encoding16 {
905   let Inst{15-10} = 0b010000;
906   let Inst{9-6} = opcode;
907 }
908
909 // A6.2.3 Special data instructions and branch and exchange encoding.
910 class T1Special<bits<4> opcode> : Encoding16 {
911   let Inst{15-10} = 0b010001;
912   let Inst{9-6}   = opcode;
913 }
914
915 // A6.2.4 Load/store single data item encoding.
916 class T1LoadStore<bits<4> opA, bits<3> opB> : Encoding16 {
917   let Inst{15-12} = opA;
918   let Inst{11-9}  = opB;
919 }
920 class T1LdStSP<bits<3> opB>   : T1LoadStore<0b1001, opB>; // SP relative
921
922 // Helper classes to encode Thumb1 loads and stores. For immediates, the
923 // following bits are used for "opA" (see A6.2.4):
924 //
925 //   0b0110 => Immediate, 4 bytes
926 //   0b1000 => Immediate, 2 bytes
927 //   0b0111 => Immediate, 1 byte
928 class T1pILdStEncode<bits<3> opcode, dag oops, dag iops, AddrMode am,
929                      InstrItinClass itin, string opc, string asm,
930                      list<dag> pattern>
931   : Thumb1pI<oops, iops, am, Size2Bytes, itin, opc, asm, "", pattern>,
932     T1LoadStore<0b0101, opcode> {
933   bits<3> Rt;
934   bits<8> addr;
935   let Inst{8-6} = addr{5-3};    // Rm
936   let Inst{5-3} = addr{2-0};    // Rn
937   let Inst{2-0} = Rt;
938 }
939 class T1pILdStEncodeImm<bits<4> opA, bit opB, dag oops, dag iops, AddrMode am,
940                         InstrItinClass itin, string opc, string asm,
941                         list<dag> pattern>
942   : Thumb1pI<oops, iops, am, Size2Bytes, itin, opc, asm, "", pattern>,
943     T1LoadStore<opA, {opB,?,?}> {
944   bits<3> Rt;
945   bits<8> addr;
946   let Inst{10-6} = addr{7-3};   // imm5
947   let Inst{5-3}  = addr{2-0};   // Rn
948   let Inst{2-0}  = Rt;
949 }
950
951 // A6.2.5 Miscellaneous 16-bit instructions encoding.
952 class T1Misc<bits<7> opcode> : Encoding16 {
953   let Inst{15-12} = 0b1011;
954   let Inst{11-5} = opcode;
955 }
956
957 // Thumb2I - Thumb2 instruction. Almost all Thumb2 instructions are predicable.
958 class Thumb2I<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
959               InstrItinClass itin,
960               string opc, string asm, string cstr, list<dag> pattern>
961   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
962   let OutOperandList = oops;
963   let InOperandList = !con(iops, (ins pred:$p));
964   let AsmString = !strconcat(opc, "${p}", asm);
965   let Pattern = pattern;
966   list<Predicate> Predicates = [IsThumb2];
967 }
968
969 // Same as Thumb2I except it can optionally modify CPSR. Note it's modeled as an
970 // input operand since by default it's a zero register. It will become an
971 // implicit def once it's "flipped".
972 //
973 // FIXME: This uses unified syntax so {s} comes before {p}. We should make it
974 // more consistent.
975 class Thumb2sI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
976                InstrItinClass itin,
977                string opc, string asm, string cstr, list<dag> pattern>
978   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
979   bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
980   let Inst{20} = s;
981
982   let OutOperandList = oops;
983   let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
984   let AsmString = !strconcat(opc, "${s}${p}", asm);
985   let Pattern = pattern;
986   list<Predicate> Predicates = [IsThumb2];
987 }
988
989 // Special cases
990 class Thumb2XI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
991                InstrItinClass itin,
992                string asm, string cstr, list<dag> pattern>
993   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
994   let OutOperandList = oops;
995   let InOperandList = iops;
996   let AsmString = asm;
997   let Pattern = pattern;
998   list<Predicate> Predicates = [IsThumb2];
999 }
1000
1001 class ThumbXI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
1002               InstrItinClass itin,
1003               string asm, string cstr, list<dag> pattern>
1004   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1005   let OutOperandList = oops;
1006   let InOperandList = iops;
1007   let AsmString = asm;
1008   let Pattern = pattern;
1009   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1010 }
1011
1012 class T2I<dag oops, dag iops, InstrItinClass itin,
1013           string opc, string asm, list<dag> pattern>
1014   : Thumb2I<oops, iops, AddrModeNone, Size4Bytes, itin, opc, asm, "", pattern>;
1015 class T2Ii12<dag oops, dag iops, InstrItinClass itin,
1016              string opc, string asm, list<dag> pattern>
1017   : Thumb2I<oops, iops, AddrModeT2_i12, Size4Bytes, itin, opc, asm, "",pattern>;
1018 class T2Ii8<dag oops, dag iops, InstrItinClass itin,
1019             string opc, string asm, list<dag> pattern>
1020   : Thumb2I<oops, iops, AddrModeT2_i8, Size4Bytes, itin, opc, asm, "", pattern>;
1021 class T2Iso<dag oops, dag iops, InstrItinClass itin,
1022             string opc, string asm, list<dag> pattern>
1023   : Thumb2I<oops, iops, AddrModeT2_so, Size4Bytes, itin, opc, asm, "", pattern>;
1024 class T2Ipc<dag oops, dag iops, InstrItinClass itin,
1025             string opc, string asm, list<dag> pattern>
1026   : Thumb2I<oops, iops, AddrModeT2_pc, Size4Bytes, itin, opc, asm, "", pattern>;
1027 class T2Ii8s4<bit P, bit W, bit isLoad, dag oops, dag iops, InstrItinClass itin,
1028               string opc, string asm, list<dag> pattern>
1029   : Thumb2I<oops, iops, AddrModeT2_i8s4, Size4Bytes, itin, opc, asm, "",
1030             pattern> {
1031   bits<4> Rt;
1032   bits<4> Rt2;
1033   bits<13> addr;
1034   let Inst{31-25} = 0b1110100;
1035   let Inst{24}    = P;
1036   let Inst{23}    = addr{8};
1037   let Inst{22}    = 1;
1038   let Inst{21}    = W;
1039   let Inst{20}    = isLoad;
1040   let Inst{19-16} = addr{12-9};
1041   let Inst{15-12} = Rt{3-0};
1042   let Inst{11-8}  = Rt2{3-0};
1043   let Inst{7-0}   = addr{7-0};
1044 }
1045
1046 class T2sI<dag oops, dag iops, InstrItinClass itin,
1047            string opc, string asm, list<dag> pattern>
1048   : Thumb2sI<oops, iops, AddrModeNone, Size4Bytes, itin, opc, asm, "", pattern>;
1049
1050 class T2XI<dag oops, dag iops, InstrItinClass itin,
1051            string asm, list<dag> pattern>
1052   : Thumb2XI<oops, iops, AddrModeNone, Size4Bytes, itin, asm, "", pattern>;
1053 class T2JTI<dag oops, dag iops, InstrItinClass itin,
1054             string asm, list<dag> pattern>
1055   : Thumb2XI<oops, iops, AddrModeNone, SizeSpecial, itin, asm, "", pattern>;
1056
1057 // Move to/from coprocessor instructions
1058 class T2Cop<dag oops, dag iops, string asm, list<dag> pattern>
1059   : T2XI<oops, iops, NoItinerary, asm, pattern>, Requires<[IsThumb2, HasV6]> {
1060   let Inst{31-28} = 0b1111;
1061 }
1062
1063 // Two-address instructions
1064 class T2XIt<dag oops, dag iops, InstrItinClass itin,
1065             string asm, string cstr, list<dag> pattern>
1066   : Thumb2XI<oops, iops, AddrModeNone, Size4Bytes, itin, asm, cstr, pattern>;
1067
1068 // T2Iidxldst - Thumb2 indexed load / store instructions.
1069 class T2Iidxldst<bit signed, bits<2> opcod, bit load, bit pre,
1070                  dag oops, dag iops,
1071                  AddrMode am, IndexMode im, InstrItinClass itin,
1072                  string opc, string asm, string cstr, list<dag> pattern>
1073   : InstARM<am, Size4Bytes, im, ThumbFrm, GenericDomain, cstr, itin> {
1074   let OutOperandList = oops;
1075   let InOperandList = !con(iops, (ins pred:$p));
1076   let AsmString = !strconcat(opc, "${p}", asm);
1077   let Pattern = pattern;
1078   list<Predicate> Predicates = [IsThumb2];
1079   let Inst{31-27} = 0b11111;
1080   let Inst{26-25} = 0b00;
1081   let Inst{24}    = signed;
1082   let Inst{23}    = 0;
1083   let Inst{22-21} = opcod;
1084   let Inst{20}    = load;
1085   let Inst{11}    = 1;
1086   // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
1087   let Inst{10}    = pre; // The P bit.
1088   let Inst{8}     = 1; // The W bit.
1089
1090   bits<9> addr;
1091   let Inst{7-0} = addr{7-0};
1092   let Inst{9}   = addr{8}; // Sign bit
1093
1094   bits<4> Rt;
1095   bits<4> Rn;
1096   let Inst{15-12} = Rt{3-0};
1097   let Inst{19-16} = Rn{3-0};
1098 }
1099
1100 // Tv5Pat - Same as Pat<>, but requires V5T Thumb mode.
1101 class Tv5Pat<dag pattern, dag result> : Pat<pattern, result> {
1102   list<Predicate> Predicates = [IsThumb, IsThumb1Only, HasV5T];
1103 }
1104
1105 // T1Pat - Same as Pat<>, but requires that the compiler be in Thumb1 mode.
1106 class T1Pat<dag pattern, dag result> : Pat<pattern, result> {
1107   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1108 }
1109
1110 // T2Pat - Same as Pat<>, but requires that the compiler be in Thumb2 mode.
1111 class T2Pat<dag pattern, dag result> : Pat<pattern, result> {
1112   list<Predicate> Predicates = [IsThumb2];
1113 }
1114
1115 //===----------------------------------------------------------------------===//
1116
1117 //===----------------------------------------------------------------------===//
1118 // ARM VFP Instruction templates.
1119 //
1120
1121 // Almost all VFP instructions are predicable.
1122 class VFPI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
1123            IndexMode im, Format f, InstrItinClass itin,
1124            string opc, string asm, string cstr, list<dag> pattern>
1125   : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1126   bits<4> p;
1127   let Inst{31-28} = p;
1128   let OutOperandList = oops;
1129   let InOperandList = !con(iops, (ins pred:$p));
1130   let AsmString = !strconcat(opc, "${p}", asm);
1131   let Pattern = pattern;
1132   let PostEncoderMethod = "VFPThumb2PostEncoder";
1133   list<Predicate> Predicates = [HasVFP2];
1134 }
1135
1136 // Special cases
1137 class VFPXI<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
1138             IndexMode im, Format f, InstrItinClass itin,
1139             string asm, string cstr, list<dag> pattern>
1140   : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1141   bits<4> p;
1142   let Inst{31-28} = p;
1143   let OutOperandList = oops;
1144   let InOperandList = iops;
1145   let AsmString = asm;
1146   let Pattern = pattern;
1147   let PostEncoderMethod = "VFPThumb2PostEncoder";
1148   list<Predicate> Predicates = [HasVFP2];
1149 }
1150
1151 class VFPAI<dag oops, dag iops, Format f, InstrItinClass itin,
1152             string opc, string asm, list<dag> pattern>
1153   : VFPI<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, itin,
1154          opc, asm, "", pattern> {
1155   let PostEncoderMethod = "VFPThumb2PostEncoder";
1156 }
1157
1158 // ARM VFP addrmode5 loads and stores
1159 class ADI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1160            InstrItinClass itin,
1161            string opc, string asm, list<dag> pattern>
1162   : VFPI<oops, iops, AddrMode5, Size4Bytes, IndexModeNone,
1163          VFPLdStFrm, itin, opc, asm, "", pattern> {
1164   // Instruction operands.
1165   bits<5>  Dd;
1166   bits<13> addr;
1167
1168   // Encode instruction operands.
1169   let Inst{23}    = addr{8};      // U (add = (U == '1'))
1170   let Inst{22}    = Dd{4};
1171   let Inst{19-16} = addr{12-9};   // Rn
1172   let Inst{15-12} = Dd{3-0};
1173   let Inst{7-0}   = addr{7-0};    // imm8
1174
1175   // TODO: Mark the instructions with the appropriate subtarget info.
1176   let Inst{27-24} = opcod1;
1177   let Inst{21-20} = opcod2;
1178   let Inst{11-9}  = 0b101;
1179   let Inst{8}     = 1;          // Double precision
1180
1181   // 64-bit loads & stores operate on both NEON and VFP pipelines.
1182   let D = VFPNeonDomain;
1183 }
1184
1185 class ASI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1186            InstrItinClass itin,
1187            string opc, string asm, list<dag> pattern>
1188   : VFPI<oops, iops, AddrMode5, Size4Bytes, IndexModeNone,
1189          VFPLdStFrm, itin, opc, asm, "", pattern> {
1190   // Instruction operands.
1191   bits<5>  Sd;
1192   bits<13> addr;
1193
1194   // Encode instruction operands.
1195   let Inst{23}    = addr{8};      // U (add = (U == '1'))
1196   let Inst{22}    = Sd{0};
1197   let Inst{19-16} = addr{12-9};   // Rn
1198   let Inst{15-12} = Sd{4-1};
1199   let Inst{7-0}   = addr{7-0};    // imm8
1200
1201   // TODO: Mark the instructions with the appropriate subtarget info.
1202   let Inst{27-24} = opcod1;
1203   let Inst{21-20} = opcod2;
1204   let Inst{11-9}  = 0b101;
1205   let Inst{8}     = 0;          // Single precision
1206 }
1207
1208 // VFP Load / store multiple pseudo instructions.
1209 class PseudoVFPLdStM<dag oops, dag iops, InstrItinClass itin, string cstr,
1210                      list<dag> pattern>
1211   : InstARM<AddrMode4, Size4Bytes, IndexModeNone, Pseudo, VFPNeonDomain,
1212             cstr, itin> {
1213   let OutOperandList = oops;
1214   let InOperandList = !con(iops, (ins pred:$p));
1215   let Pattern = pattern;
1216   list<Predicate> Predicates = [HasVFP2];
1217 }
1218
1219 // Load / store multiple
1220 class AXDI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1221             string asm, string cstr, list<dag> pattern>
1222   : VFPXI<oops, iops, AddrMode4, Size4Bytes, im,
1223           VFPLdStMulFrm, itin, asm, cstr, pattern> {
1224   // Instruction operands.
1225   bits<4>  Rn;
1226   bits<13> regs;
1227
1228   // Encode instruction operands.
1229   let Inst{19-16} = Rn;
1230   let Inst{22}    = regs{12};
1231   let Inst{15-12} = regs{11-8};
1232   let Inst{7-0}   = regs{7-0};
1233
1234   // TODO: Mark the instructions with the appropriate subtarget info.
1235   let Inst{27-25} = 0b110;
1236   let Inst{11-9}  = 0b101;
1237   let Inst{8}     = 1;          // Double precision
1238
1239   // 64-bit loads & stores operate on both NEON and VFP pipelines.
1240   let D = VFPNeonDomain;
1241 }
1242
1243 class AXSI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1244             string asm, string cstr, list<dag> pattern>
1245   : VFPXI<oops, iops, AddrMode4, Size4Bytes, im,
1246           VFPLdStMulFrm, itin, asm, cstr, pattern> {
1247   // Instruction operands.
1248   bits<4> Rn;
1249   bits<13> regs;
1250
1251   // Encode instruction operands.
1252   let Inst{19-16} = Rn;
1253   let Inst{22}    = regs{8};
1254   let Inst{15-12} = regs{12-9};
1255   let Inst{7-0}   = regs{7-0};
1256
1257   // TODO: Mark the instructions with the appropriate subtarget info.
1258   let Inst{27-25} = 0b110;
1259   let Inst{11-9}  = 0b101;
1260   let Inst{8}     = 0;          // Single precision
1261 }
1262
1263 // Double precision, unary
1264 class ADuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1265            bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1266            string asm, list<dag> pattern>
1267   : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1268   // Instruction operands.
1269   bits<5> Dd;
1270   bits<5> Dm;
1271
1272   // Encode instruction operands.
1273   let Inst{3-0}   = Dm{3-0};
1274   let Inst{5}     = Dm{4};
1275   let Inst{15-12} = Dd{3-0};
1276   let Inst{22}    = Dd{4};
1277
1278   let Inst{27-23} = opcod1;
1279   let Inst{21-20} = opcod2;
1280   let Inst{19-16} = opcod3;
1281   let Inst{11-9}  = 0b101;
1282   let Inst{8}     = 1;          // Double precision
1283   let Inst{7-6}   = opcod4;
1284   let Inst{4}     = opcod5;
1285 }
1286
1287 // Double precision, binary
1288 class ADbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1289            dag iops, InstrItinClass itin, string opc, string asm,
1290            list<dag> pattern>
1291   : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1292   // Instruction operands.
1293   bits<5> Dd;
1294   bits<5> Dn;
1295   bits<5> Dm;
1296
1297   // Encode instruction operands.
1298   let Inst{3-0}   = Dm{3-0};
1299   let Inst{5}     = Dm{4};
1300   let Inst{19-16} = Dn{3-0};
1301   let Inst{7}     = Dn{4};
1302   let Inst{15-12} = Dd{3-0};
1303   let Inst{22}    = Dd{4};
1304
1305   let Inst{27-23} = opcod1;
1306   let Inst{21-20} = opcod2;
1307   let Inst{11-9}  = 0b101;
1308   let Inst{8}     = 1;          // Double precision
1309   let Inst{6}     = op6;
1310   let Inst{4}     = op4;
1311 }
1312
1313 // Single precision, unary
1314 class ASuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1315            bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1316            string asm, list<dag> pattern>
1317   : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1318   // Instruction operands.
1319   bits<5> Sd;
1320   bits<5> Sm;
1321
1322   // Encode instruction operands.
1323   let Inst{3-0}   = Sm{4-1};
1324   let Inst{5}     = Sm{0};
1325   let Inst{15-12} = Sd{4-1};
1326   let Inst{22}    = Sd{0};
1327
1328   let Inst{27-23} = opcod1;
1329   let Inst{21-20} = opcod2;
1330   let Inst{19-16} = opcod3;
1331   let Inst{11-9}  = 0b101;
1332   let Inst{8}     = 0;          // Single precision
1333   let Inst{7-6}   = opcod4;
1334   let Inst{4}     = opcod5;
1335 }
1336
1337 // Single precision unary, if no NEON. Same as ASuI except not available if
1338 // NEON is enabled.
1339 class ASuIn<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1340             bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1341             string asm, list<dag> pattern>
1342   : ASuI<opcod1, opcod2, opcod3, opcod4, opcod5, oops, iops, itin, opc, asm,
1343          pattern> {
1344   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1345 }
1346
1347 // Single precision, binary
1348 class ASbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
1349            InstrItinClass itin, string opc, string asm, list<dag> pattern>
1350   : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1351   // Instruction operands.
1352   bits<5> Sd;
1353   bits<5> Sn;
1354   bits<5> Sm;
1355
1356   // Encode instruction operands.
1357   let Inst{3-0}   = Sm{4-1};
1358   let Inst{5}     = Sm{0};
1359   let Inst{19-16} = Sn{4-1};
1360   let Inst{7}     = Sn{0};
1361   let Inst{15-12} = Sd{4-1};
1362   let Inst{22}    = Sd{0};
1363
1364   let Inst{27-23} = opcod1;
1365   let Inst{21-20} = opcod2;
1366   let Inst{11-9}  = 0b101;
1367   let Inst{8}     = 0;          // Single precision
1368   let Inst{6}     = op6;
1369   let Inst{4}     = op4;
1370 }
1371
1372 // Single precision binary, if no NEON. Same as ASbI except not available if
1373 // NEON is enabled.
1374 class ASbIn<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1375             dag iops, InstrItinClass itin, string opc, string asm,
1376             list<dag> pattern>
1377   : ASbI<opcod1, opcod2, op6, op4, oops, iops, itin, opc, asm, pattern> {
1378   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1379
1380   // Instruction operands.
1381   bits<5> Sd;
1382   bits<5> Sn;
1383   bits<5> Sm;
1384
1385   // Encode instruction operands.
1386   let Inst{3-0}   = Sm{4-1};
1387   let Inst{5}     = Sm{0};
1388   let Inst{19-16} = Sn{4-1};
1389   let Inst{7}     = Sn{0};
1390   let Inst{15-12} = Sd{4-1};
1391   let Inst{22}    = Sd{0};
1392 }
1393
1394 // VFP conversion instructions
1395 class AVConv1I<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
1396                dag oops, dag iops, InstrItinClass itin, string opc, string asm,
1397                list<dag> pattern>
1398   : VFPAI<oops, iops, VFPConv1Frm, itin, opc, asm, pattern> {
1399   let Inst{27-23} = opcod1;
1400   let Inst{21-20} = opcod2;
1401   let Inst{19-16} = opcod3;
1402   let Inst{11-8}  = opcod4;
1403   let Inst{6}     = 1;
1404   let Inst{4}     = 0;
1405 }
1406
1407 // VFP conversion between floating-point and fixed-point
1408 class AVConv1XI<bits<5> op1, bits<2> op2, bits<4> op3, bits<4> op4, bit op5,
1409                 dag oops, dag iops, InstrItinClass itin, string opc, string asm,
1410                 list<dag> pattern>
1411   : AVConv1I<op1, op2, op3, op4, oops, iops, itin, opc, asm, pattern> {
1412   // size (fixed-point number): sx == 0 ? 16 : 32
1413   let Inst{7} = op5; // sx
1414 }
1415
1416 // VFP conversion instructions, if no NEON
1417 class AVConv1In<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
1418                 dag oops, dag iops, InstrItinClass itin,
1419                 string opc, string asm, list<dag> pattern>
1420   : AVConv1I<opcod1, opcod2, opcod3, opcod4, oops, iops, itin, opc, asm,
1421              pattern> {
1422   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1423 }
1424
1425 class AVConvXI<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops, Format f,
1426                InstrItinClass itin,
1427                string opc, string asm, list<dag> pattern>
1428   : VFPAI<oops, iops, f, itin, opc, asm, pattern> {
1429   let Inst{27-20} = opcod1;
1430   let Inst{11-8}  = opcod2;
1431   let Inst{4}     = 1;
1432 }
1433
1434 class AVConv2I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1435                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1436   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv2Frm, itin, opc, asm, pattern>;
1437
1438 class AVConv3I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1439                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1440   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv3Frm, itin, opc, asm, pattern>;
1441
1442 class AVConv4I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1443                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1444   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv4Frm, itin, opc, asm, pattern>;
1445
1446 class AVConv5I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1447                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1448   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv5Frm, itin, opc, asm, pattern>;
1449
1450 //===----------------------------------------------------------------------===//
1451
1452 //===----------------------------------------------------------------------===//
1453 // ARM NEON Instruction templates.
1454 //
1455
1456 class NeonI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
1457             InstrItinClass itin, string opc, string dt, string asm, string cstr,
1458             list<dag> pattern>
1459   : InstARM<am, Size4Bytes, im, f, NeonDomain, cstr, itin> {
1460   let OutOperandList = oops;
1461   let InOperandList = !con(iops, (ins pred:$p));
1462   let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
1463   let Pattern = pattern;
1464   list<Predicate> Predicates = [HasNEON];
1465 }
1466
1467 // Same as NeonI except it does not have a "data type" specifier.
1468 class NeonXI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
1469              InstrItinClass itin, string opc, string asm, string cstr,
1470              list<dag> pattern>
1471   : InstARM<am, Size4Bytes, im, f, NeonDomain, cstr, itin> {
1472   let OutOperandList = oops;
1473   let InOperandList = !con(iops, (ins pred:$p));
1474   let AsmString = !strconcat(opc, "${p}", "\t", asm);
1475   let Pattern = pattern;
1476   list<Predicate> Predicates = [HasNEON];
1477 }
1478
1479 class NLdSt<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
1480             dag oops, dag iops, InstrItinClass itin,
1481             string opc, string dt, string asm, string cstr, list<dag> pattern>
1482   : NeonI<oops, iops, AddrMode6, IndexModeNone, NLdStFrm, itin, opc, dt, asm,
1483           cstr, pattern> {
1484   let Inst{31-24} = 0b11110100;
1485   let Inst{23}    = op23;
1486   let Inst{21-20} = op21_20;
1487   let Inst{11-8}  = op11_8;
1488   let Inst{7-4}   = op7_4;
1489
1490   let PostEncoderMethod = "NEONThumb2LoadStorePostEncoder";
1491
1492   bits<5> Vd;
1493   bits<6> Rn;
1494   bits<4> Rm;
1495
1496   let Inst{22}    = Vd{4};
1497   let Inst{15-12} = Vd{3-0};
1498   let Inst{19-16} = Rn{3-0};
1499   let Inst{3-0}   = Rm{3-0};
1500 }
1501
1502 class NLdStLn<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
1503             dag oops, dag iops, InstrItinClass itin,
1504             string opc, string dt, string asm, string cstr, list<dag> pattern>
1505   : NLdSt<op23, op21_20, op11_8, op7_4, oops, iops, itin, opc,
1506           dt, asm, cstr, pattern> {
1507   bits<3> lane;
1508 }
1509
1510 class PseudoNLdSt<dag oops, dag iops, InstrItinClass itin, string cstr>
1511   : InstARM<AddrMode6, Size4Bytes, IndexModeNone, Pseudo, NeonDomain, cstr,
1512             itin> {
1513   let OutOperandList = oops;
1514   let InOperandList = !con(iops, (ins pred:$p));
1515   list<Predicate> Predicates = [HasNEON];
1516 }
1517
1518 class PseudoNeonI<dag oops, dag iops, InstrItinClass itin, string cstr,
1519                   list<dag> pattern>
1520   : InstARM<AddrModeNone, Size4Bytes, IndexModeNone, Pseudo, NeonDomain, cstr,
1521             itin> {
1522   let OutOperandList = oops;
1523   let InOperandList = !con(iops, (ins pred:$p));
1524   let Pattern = pattern;
1525   list<Predicate> Predicates = [HasNEON];
1526 }
1527
1528 class NDataI<dag oops, dag iops, Format f, InstrItinClass itin,
1529              string opc, string dt, string asm, string cstr, list<dag> pattern>
1530   : NeonI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, dt, asm, cstr,
1531           pattern> {
1532   let Inst{31-25} = 0b1111001;
1533   let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
1534 }
1535
1536 class NDataXI<dag oops, dag iops, Format f, InstrItinClass itin,
1537               string opc, string asm, string cstr, list<dag> pattern>
1538   : NeonXI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, asm,
1539            cstr, pattern> {
1540   let Inst{31-25} = 0b1111001;
1541   let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
1542 }
1543
1544 // NEON "one register and a modified immediate" format.
1545 class N1ModImm<bit op23, bits<3> op21_19, bits<4> op11_8, bit op7, bit op6,
1546                bit op5, bit op4,
1547                dag oops, dag iops, InstrItinClass itin,
1548                string opc, string dt, string asm, string cstr,
1549                list<dag> pattern>
1550   : NDataI<oops, iops, N1RegModImmFrm, itin, opc, dt, asm, cstr, pattern> {
1551   let Inst{23}    = op23;
1552   let Inst{21-19} = op21_19;
1553   let Inst{11-8}  = op11_8;
1554   let Inst{7}     = op7;
1555   let Inst{6}     = op6;
1556   let Inst{5}     = op5;
1557   let Inst{4}     = op4;
1558
1559   // Instruction operands.
1560   bits<5> Vd;
1561   bits<13> SIMM;
1562
1563   let Inst{15-12} = Vd{3-0};
1564   let Inst{22}    = Vd{4};
1565   let Inst{24}    = SIMM{7};
1566   let Inst{18-16} = SIMM{6-4};
1567   let Inst{3-0}   = SIMM{3-0};
1568 }
1569
1570 // NEON 2 vector register format.
1571 class N2V<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
1572           bits<5> op11_7, bit op6, bit op4,
1573           dag oops, dag iops, InstrItinClass itin,
1574           string opc, string dt, string asm, string cstr, list<dag> pattern>
1575   : NDataI<oops, iops, N2RegFrm, itin, opc, dt, asm, cstr, pattern> {
1576   let Inst{24-23} = op24_23;
1577   let Inst{21-20} = op21_20;
1578   let Inst{19-18} = op19_18;
1579   let Inst{17-16} = op17_16;
1580   let Inst{11-7}  = op11_7;
1581   let Inst{6}     = op6;
1582   let Inst{4}     = op4;
1583
1584   // Instruction operands.
1585   bits<5> Vd;
1586   bits<5> Vm;
1587
1588   let Inst{15-12} = Vd{3-0};
1589   let Inst{22}    = Vd{4};
1590   let Inst{3-0}   = Vm{3-0};
1591   let Inst{5}     = Vm{4};
1592 }
1593
1594 // Same as N2V except it doesn't have a datatype suffix.
1595 class N2VX<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
1596            bits<5> op11_7, bit op6, bit op4,
1597            dag oops, dag iops, InstrItinClass itin,
1598            string opc, string asm, string cstr, list<dag> pattern>
1599   : NDataXI<oops, iops, N2RegFrm, itin, opc, asm, cstr, pattern> {
1600   let Inst{24-23} = op24_23;
1601   let Inst{21-20} = op21_20;
1602   let Inst{19-18} = op19_18;
1603   let Inst{17-16} = op17_16;
1604   let Inst{11-7}  = op11_7;
1605   let Inst{6}     = op6;
1606   let Inst{4}     = op4;
1607
1608   // Instruction operands.
1609   bits<5> Vd;
1610   bits<5> Vm;
1611
1612   let Inst{15-12} = Vd{3-0};
1613   let Inst{22}    = Vd{4};
1614   let Inst{3-0}   = Vm{3-0};
1615   let Inst{5}     = Vm{4};
1616 }
1617
1618 // NEON 2 vector register with immediate.
1619 class N2VImm<bit op24, bit op23, bits<4> op11_8, bit op7, bit op6, bit op4,
1620              dag oops, dag iops, Format f, InstrItinClass itin,
1621              string opc, string dt, string asm, string cstr, list<dag> pattern>
1622   : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
1623   let Inst{24}   = op24;
1624   let Inst{23}   = op23;
1625   let Inst{11-8} = op11_8;
1626   let Inst{7}    = op7;
1627   let Inst{6}    = op6;
1628   let Inst{4}    = op4;
1629
1630   // Instruction operands.
1631   bits<5> Vd;
1632   bits<5> Vm;
1633   bits<6> SIMM;
1634
1635   let Inst{15-12} = Vd{3-0};
1636   let Inst{22}    = Vd{4};
1637   let Inst{3-0}   = Vm{3-0};
1638   let Inst{5}     = Vm{4};
1639   let Inst{21-16} = SIMM{5-0};
1640 }
1641
1642 // NEON 3 vector register format.
1643 class N3V<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6, bit op4,
1644           dag oops, dag iops, Format f, InstrItinClass itin,
1645           string opc, string dt, string asm, string cstr, list<dag> pattern>
1646   : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
1647   let Inst{24}    = op24;
1648   let Inst{23}    = op23;
1649   let Inst{21-20} = op21_20;
1650   let Inst{11-8}  = op11_8;
1651   let Inst{6}     = op6;
1652   let Inst{4}     = op4;
1653
1654   // Instruction operands.
1655   bits<5> Vd;
1656   bits<5> Vn;
1657   bits<5> Vm;
1658
1659   let Inst{15-12} = Vd{3-0};
1660   let Inst{22}    = Vd{4};
1661   let Inst{19-16} = Vn{3-0};
1662   let Inst{7}     = Vn{4};
1663   let Inst{3-0}   = Vm{3-0};
1664   let Inst{5}     = Vm{4};
1665 }
1666
1667 // Same as N3V except it doesn't have a data type suffix.
1668 class N3VX<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
1669            bit op4,
1670            dag oops, dag iops, Format f, InstrItinClass itin,
1671            string opc, string asm, string cstr, list<dag> pattern>
1672   : NDataXI<oops, iops, f, itin, opc, asm, cstr, pattern> {
1673   let Inst{24}    = op24;
1674   let Inst{23}    = op23;
1675   let Inst{21-20} = op21_20;
1676   let Inst{11-8}  = op11_8;
1677   let Inst{6}     = op6;
1678   let Inst{4}     = op4;
1679
1680   // Instruction operands.
1681   bits<5> Vd;
1682   bits<5> Vn;
1683   bits<5> Vm;
1684
1685   let Inst{15-12} = Vd{3-0};
1686   let Inst{22}    = Vd{4};
1687   let Inst{19-16} = Vn{3-0};
1688   let Inst{7}     = Vn{4};
1689   let Inst{3-0}   = Vm{3-0};
1690   let Inst{5}     = Vm{4};
1691 }
1692
1693 // NEON VMOVs between scalar and core registers.
1694 class NVLaneOp<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
1695                dag oops, dag iops, Format f, InstrItinClass itin,
1696                string opc, string dt, string asm, list<dag> pattern>
1697   : InstARM<AddrModeNone, Size4Bytes, IndexModeNone, f, NeonDomain,
1698             "", itin> {
1699   let Inst{27-20} = opcod1;
1700   let Inst{11-8}  = opcod2;
1701   let Inst{6-5}   = opcod3;
1702   let Inst{4}     = 1;
1703
1704   let OutOperandList = oops;
1705   let InOperandList = !con(iops, (ins pred:$p));
1706   let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
1707   let Pattern = pattern;
1708   list<Predicate> Predicates = [HasNEON];
1709
1710   let PostEncoderMethod = "NEONThumb2DupPostEncoder";
1711
1712   bits<5> V;
1713   bits<4> R;
1714   bits<4> p;
1715   bits<4> lane;
1716
1717   let Inst{31-28} = p{3-0};
1718   let Inst{7}     = V{4};
1719   let Inst{19-16} = V{3-0};
1720   let Inst{15-12} = R{3-0};
1721 }
1722 class NVGetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
1723                 dag oops, dag iops, InstrItinClass itin,
1724                 string opc, string dt, string asm, list<dag> pattern>
1725   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NGetLnFrm, itin,
1726              opc, dt, asm, pattern>;
1727 class NVSetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
1728                 dag oops, dag iops, InstrItinClass itin,
1729                 string opc, string dt, string asm, list<dag> pattern>
1730   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NSetLnFrm, itin,
1731              opc, dt, asm, pattern>;
1732 class NVDup<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
1733             dag oops, dag iops, InstrItinClass itin,
1734             string opc, string dt, string asm, list<dag> pattern>
1735   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NDupFrm, itin,
1736              opc, dt, asm, pattern>;
1737
1738 // Vector Duplicate Lane (from scalar to all elements)
1739 class NVDupLane<bits<4> op19_16, bit op6, dag oops, dag iops,
1740                 InstrItinClass itin, string opc, string dt, string asm,
1741                 list<dag> pattern>
1742   : NDataI<oops, iops, NVDupLnFrm, itin, opc, dt, asm, "", pattern> {
1743   let Inst{24-23} = 0b11;
1744   let Inst{21-20} = 0b11;
1745   let Inst{19-16} = op19_16;
1746   let Inst{11-7}  = 0b11000;
1747   let Inst{6}     = op6;
1748   let Inst{4}     = 0;
1749
1750   bits<5> Vd;
1751   bits<5> Vm;
1752   bits<4> lane;
1753
1754   let Inst{22}     = Vd{4};
1755   let Inst{15-12} = Vd{3-0};
1756   let Inst{5}     = Vm{4};
1757   let Inst{3-0} = Vm{3-0};
1758 }
1759
1760 // NEONFPPat - Same as Pat<>, but requires that the compiler be using NEON
1761 // for single-precision FP.
1762 class NEONFPPat<dag pattern, dag result> : Pat<pattern, result> {
1763   list<Predicate> Predicates = [HasNEON,UseNEONForFP];
1764 }