OSDN Git Service

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