OSDN Git Service

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