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