OSDN Git Service

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