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