OSDN Git Service

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