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