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