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