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