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