OSDN Git Service

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