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