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