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