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