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