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.
18class Format<bits<6> val> {
19  bits<6> Value = val;
20}
21
22def Pseudo        : Format<0>;
23def MulFrm        : Format<1>;
24def BrFrm         : Format<2>;
25def BrMiscFrm     : Format<3>;
26
27def DPFrm         : Format<4>;
28def DPSoRegRegFrm    : Format<5>;
29
30def LdFrm         : Format<6>;
31def StFrm         : Format<7>;
32def LdMiscFrm     : Format<8>;
33def StMiscFrm     : Format<9>;
34def LdStMulFrm    : Format<10>;
35
36def LdStExFrm     : Format<11>;
37
38def ArithMiscFrm  : Format<12>;
39def SatFrm        : Format<13>;
40def ExtFrm        : Format<14>;
41
42def VFPUnaryFrm   : Format<15>;
43def VFPBinaryFrm  : Format<16>;
44def VFPConv1Frm   : Format<17>;
45def VFPConv2Frm   : Format<18>;
46def VFPConv3Frm   : Format<19>;
47def VFPConv4Frm   : Format<20>;
48def VFPConv5Frm   : Format<21>;
49def VFPLdStFrm    : Format<22>;
50def VFPLdStMulFrm : Format<23>;
51def VFPMiscFrm    : Format<24>;
52
53def ThumbFrm      : Format<25>;
54def MiscFrm       : Format<26>;
55
56def NGetLnFrm     : Format<27>;
57def NSetLnFrm     : Format<28>;
58def NDupFrm       : Format<29>;
59def NLdStFrm      : Format<30>;
60def N1RegModImmFrm: Format<31>;
61def N2RegFrm      : Format<32>;
62def NVCVTFrm      : Format<33>;
63def NVDupLnFrm    : Format<34>;
64def N2RegVShLFrm  : Format<35>;
65def N2RegVShRFrm  : Format<36>;
66def N3RegFrm      : Format<37>;
67def N3RegVShFrm   : Format<38>;
68def NVExtFrm      : Format<39>;
69def NVMulSLFrm    : Format<40>;
70def NVTBLFrm      : Format<41>;
71def 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.
78class 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.
82class 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.
90class AddrMode<bits<5> val> {
91  bits<5> Value = val;
92}
93def AddrModeNone    : AddrMode<0>;
94def AddrMode1       : AddrMode<1>;
95def AddrMode2       : AddrMode<2>;
96def AddrMode3       : AddrMode<3>;
97def AddrMode4       : AddrMode<4>;
98def AddrMode5       : AddrMode<5>;
99def AddrMode6       : AddrMode<6>;
100def AddrModeT1_1    : AddrMode<7>;
101def AddrModeT1_2    : AddrMode<8>;
102def AddrModeT1_4    : AddrMode<9>;
103def AddrModeT1_s    : AddrMode<10>;
104def AddrModeT2_i12  : AddrMode<11>;
105def AddrModeT2_i8   : AddrMode<12>;
106def AddrModeT2_so   : AddrMode<13>;
107def AddrModeT2_pc   : AddrMode<14>;
108def AddrModeT2_i8s4 : AddrMode<15>;
109def AddrMode_i12    : AddrMode<16>;
110
111// Load / store index mode.
112class IndexMode<bits<2> val> {
113  bits<2> Value = val;
114}
115def IndexModeNone : IndexMode<0>;
116def IndexModePre  : IndexMode<1>;
117def IndexModePost : IndexMode<2>;
118def IndexModeUpd  : IndexMode<3>;
119
120// Instruction execution domain.
121class Domain<bits<3> val> {
122  bits<3> Value = val;
123}
124def GenericDomain : Domain<0>;
125def VFPDomain     : Domain<1>; // Instructions in VFP domain only
126def NeonDomain    : Domain<2>; // Instructions in Neon domain only
127def VFPNeonDomain : Domain<3>; // Instructions in both VFP & Neon domains
128def VFPNeonA8Domain : Domain<5>; // Instructions in VFP & Neon under A8
129
130//===----------------------------------------------------------------------===//
131// ARM special operands.
132//
133
134// ARM imod and iflag operands, used only by the CPS instruction.
135def imod_op : Operand<i32> {
136  let PrintMethod = "printCPSIMod";
137}
138
139def ProcIFlagsOperand : AsmOperandClass {
140  let Name = "ProcIFlags";
141  let ParserMethod = "parseProcIFlagsOperand";
142}
143def iflags_op : Operand<i32> {
144  let PrintMethod = "printCPSIFlag";
145  let ParserMatchClass = ProcIFlagsOperand;
146}
147
148// ARM Predicate operand. Default to 14 = always (AL). Second part is CC
149// register whose default is 0 (no register).
150def CondCodeOperand : AsmOperandClass { let Name = "CondCode"; }
151def pred : PredicateOperand<OtherVT, (ops i32imm, i32imm),
152                                     (ops (i32 14), (i32 zero_reg))> {
153  let PrintMethod = "printPredicateOperand";
154  let ParserMatchClass = CondCodeOperand;
155  let DecoderMethod = "DecodePredicateOperand";
156}
157
158// Selectable predicate operand for CMOV instructions. We can't use a normal
159// predicate because the default values interfere with instruction selection. In
160// all other respects it is identical though: pseudo-instruction expansion
161// relies on the MachineOperands being compatible.
162def cmovpred : Operand<i32>, PredicateOp,
163               ComplexPattern<i32, 2, "SelectCMOVPred"> {
164  let MIOperandInfo = (ops i32imm, i32imm);
165  let PrintMethod = "printPredicateOperand";
166}
167
168// Conditional code result for instructions whose 's' bit is set, e.g. subs.
169def CCOutOperand : AsmOperandClass { let Name = "CCOut"; }
170def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
171  let EncoderMethod = "getCCOutOpValue";
172  let PrintMethod = "printSBitModifierOperand";
173  let ParserMatchClass = CCOutOperand;
174  let DecoderMethod = "DecodeCCOutOperand";
175}
176
177// Same as cc_out except it defaults to setting CPSR.
178def s_cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 CPSR))> {
179  let EncoderMethod = "getCCOutOpValue";
180  let PrintMethod = "printSBitModifierOperand";
181  let ParserMatchClass = CCOutOperand;
182  let DecoderMethod = "DecodeCCOutOperand";
183}
184
185// ARM special operands for disassembly only.
186//
187def SetEndAsmOperand : ImmAsmOperand {
188  let Name = "SetEndImm";
189  let ParserMethod = "parseSetEndImm";
190}
191def setend_op : Operand<i32> {
192  let PrintMethod = "printSetendOperand";
193  let ParserMatchClass = SetEndAsmOperand;
194}
195
196def MSRMaskOperand : AsmOperandClass {
197  let Name = "MSRMask";
198  let ParserMethod = "parseMSRMaskOperand";
199}
200def msr_mask : Operand<i32> {
201  let PrintMethod = "printMSRMaskOperand";
202  let DecoderMethod = "DecodeMSRMask";
203  let ParserMatchClass = MSRMaskOperand;
204}
205
206def BankedRegOperand : AsmOperandClass {
207  let Name = "BankedReg";
208  let ParserMethod = "parseBankedRegOperand";
209}
210def banked_reg : Operand<i32> {
211  let PrintMethod = "printBankedRegOperand";
212  let DecoderMethod = "DecodeBankedReg";
213  let ParserMatchClass = BankedRegOperand;
214}
215
216// Shift Right Immediate - A shift right immediate is encoded differently from
217// other shift immediates. The imm6 field is encoded like so:
218//
219//    Offset    Encoding
220//     8        imm6<5:3> = '001', 8 - <imm> is encoded in imm6<2:0>
221//     16       imm6<5:4> = '01', 16 - <imm> is encoded in imm6<3:0>
222//     32       imm6<5> = '1', 32 - <imm> is encoded in imm6<4:0>
223//     64       64 - <imm> is encoded in imm6<5:0>
224def shr_imm8_asm_operand : ImmAsmOperand { let Name = "ShrImm8"; }
225def shr_imm8  : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 8; }]> {
226  let EncoderMethod = "getShiftRight8Imm";
227  let DecoderMethod = "DecodeShiftRight8Imm";
228  let ParserMatchClass = shr_imm8_asm_operand;
229}
230def shr_imm16_asm_operand : ImmAsmOperand { let Name = "ShrImm16"; }
231def shr_imm16 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 16; }]> {
232  let EncoderMethod = "getShiftRight16Imm";
233  let DecoderMethod = "DecodeShiftRight16Imm";
234  let ParserMatchClass = shr_imm16_asm_operand;
235}
236def shr_imm32_asm_operand : ImmAsmOperand { let Name = "ShrImm32"; }
237def shr_imm32 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]> {
238  let EncoderMethod = "getShiftRight32Imm";
239  let DecoderMethod = "DecodeShiftRight32Imm";
240  let ParserMatchClass = shr_imm32_asm_operand;
241}
242def shr_imm64_asm_operand : ImmAsmOperand { let Name = "ShrImm64"; }
243def shr_imm64 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 64; }]> {
244  let EncoderMethod = "getShiftRight64Imm";
245  let DecoderMethod = "DecodeShiftRight64Imm";
246  let ParserMatchClass = shr_imm64_asm_operand;
247}
248
249
250// ARM Assembler operand for ldr Rd, =expression which generates an offset
251// to a constant pool entry or a MOV depending on the value of expression
252def const_pool_asm_operand : AsmOperandClass { let Name = "ConstPoolAsmImm"; }
253def const_pool_asm_imm : Operand<i32> {
254  let ParserMatchClass = const_pool_asm_operand;
255}
256
257
258//===----------------------------------------------------------------------===//
259// ARM Assembler alias templates.
260//
261// Note: When EmitPriority == 1, the alias will be used for printing
262class ARMInstAlias<string Asm, dag Result, bit EmitPriority = 0>
263      : InstAlias<Asm, Result, EmitPriority>, Requires<[IsARM]>;
264class  tInstAlias<string Asm, dag Result, bit EmitPriority = 0>
265      : InstAlias<Asm, Result, EmitPriority>, Requires<[IsThumb]>;
266class t2InstAlias<string Asm, dag Result, bit EmitPriority = 0>
267      : InstAlias<Asm, Result, EmitPriority>, Requires<[IsThumb2]>;
268class VFP2InstAlias<string Asm, dag Result, bit EmitPriority = 0>
269      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP2]>;
270class VFP2DPInstAlias<string Asm, dag Result, bit EmitPriority = 0>
271      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP2,HasDPVFP]>;
272class VFP3InstAlias<string Asm, dag Result, bit EmitPriority = 0>
273      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP3]>;
274class NEONInstAlias<string Asm, dag Result, bit EmitPriority = 0>
275      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasNEON]>;
276
277
278class VFP2MnemonicAlias<string src, string dst> : MnemonicAlias<src, dst>,
279          Requires<[HasVFP2]>;
280class NEONMnemonicAlias<string src, string dst> : MnemonicAlias<src, dst>,
281          Requires<[HasNEON]>;
282
283//===----------------------------------------------------------------------===//
284// ARM Instruction templates.
285//
286
287
288class InstTemplate<AddrMode am, int sz, IndexMode im,
289                   Format f, Domain d, string cstr, InstrItinClass itin>
290  : Instruction {
291  let Namespace = "ARM";
292
293  AddrMode AM = am;
294  int Size = sz;
295  IndexMode IM = im;
296  bits<2> IndexModeBits = IM.Value;
297  Format F = f;
298  bits<6> Form = F.Value;
299  Domain D = d;
300  bit isUnaryDataProc = 0;
301  bit canXformTo16Bit = 0;
302  // The instruction is a 16-bit flag setting Thumb instruction. Used
303  // by the parser to determine whether to require the 'S' suffix on the
304  // mnemonic (when not in an IT block) or preclude it (when in an IT block).
305  bit thumbArithFlagSetting = 0;
306
307  // If this is a pseudo instruction, mark it isCodeGenOnly.
308  let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
309
310  // The layout of TSFlags should be kept in sync with ARMBaseInfo.h.
311  let TSFlags{4-0}   = AM.Value;
312  let TSFlags{6-5}   = IndexModeBits;
313  let TSFlags{12-7} = Form;
314  let TSFlags{13}    = isUnaryDataProc;
315  let TSFlags{14}    = canXformTo16Bit;
316  let TSFlags{17-15} = D.Value;
317  let TSFlags{18}    = thumbArithFlagSetting;
318
319  let Constraints = cstr;
320  let Itinerary = itin;
321}
322
323class Encoding {
324  field bits<32> Inst;
325  // Mask of bits that cause an encoding to be UNPREDICTABLE.
326  // If a bit is set, then if the corresponding bit in the
327  // target encoding differs from its value in the "Inst" field,
328  // the instruction is UNPREDICTABLE (SoftFail in abstract parlance).
329  field bits<32> Unpredictable = 0;
330  // SoftFail is the generic name for this field, but we alias it so
331  // as to make it more obvious what it means in ARM-land.
332  field bits<32> SoftFail = Unpredictable;
333}
334
335class InstARM<AddrMode am, int sz, IndexMode im,
336              Format f, Domain d, string cstr, InstrItinClass itin>
337  : InstTemplate<am, sz, im, f, d, cstr, itin>, Encoding {
338  let DecoderNamespace = "ARM";
339}
340
341// This Encoding-less class is used by Thumb1 to specify the encoding bits later
342// on by adding flavors to specific instructions.
343class InstThumb<AddrMode am, int sz, IndexMode im,
344                Format f, Domain d, string cstr, InstrItinClass itin>
345  : InstTemplate<am, sz, im, f, d, cstr, itin> {
346  let DecoderNamespace = "Thumb";
347}
348
349// Pseudo-instructions for alternate assembly syntax (never used by codegen).
350// These are aliases that require C++ handling to convert to the target
351// instruction, while InstAliases can be handled directly by tblgen.
352class AsmPseudoInst<string asm, dag iops, dag oops = (outs)>
353  : InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
354                 "", NoItinerary> {
355  let OutOperandList = oops;
356  let InOperandList = iops;
357  let Pattern = [];
358  let isCodeGenOnly = 0; // So we get asm matcher for it.
359  let AsmString = asm;
360  let isPseudo = 1;
361}
362
363class ARMAsmPseudo<string asm, dag iops, dag oops = (outs)>
364  : AsmPseudoInst<asm, iops, oops>, Requires<[IsARM]>;
365class tAsmPseudo<string asm, dag iops, dag oops = (outs)>
366  : AsmPseudoInst<asm, iops, oops>, Requires<[IsThumb]>;
367class t2AsmPseudo<string asm, dag iops, dag oops = (outs)>
368  : AsmPseudoInst<asm, iops, oops>, Requires<[IsThumb2]>;
369class VFP2AsmPseudo<string asm, dag iops, dag oops = (outs)>
370  : AsmPseudoInst<asm, iops, oops>, Requires<[HasVFP2]>;
371class NEONAsmPseudo<string asm, dag iops, dag oops = (outs)>
372  : AsmPseudoInst<asm, iops, oops>, Requires<[HasNEON]>;
373
374// Pseudo instructions for the code generator.
375class PseudoInst<dag oops, dag iops, InstrItinClass itin, list<dag> pattern>
376  : InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo,
377                 GenericDomain, "", itin> {
378  let OutOperandList = oops;
379  let InOperandList = iops;
380  let Pattern = pattern;
381  let isCodeGenOnly = 1;
382  let isPseudo = 1;
383}
384
385// PseudoInst that's ARM-mode only.
386class ARMPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
387                    list<dag> pattern>
388  : PseudoInst<oops, iops, itin, pattern> {
389  let Size = sz;
390  list<Predicate> Predicates = [IsARM];
391}
392
393// PseudoInst that's Thumb-mode only.
394class tPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
395                    list<dag> pattern>
396  : PseudoInst<oops, iops, itin, pattern> {
397  let Size = sz;
398  list<Predicate> Predicates = [IsThumb];
399}
400
401// PseudoInst that's in ARMv8-M baseline (Somewhere between Thumb and Thumb2)
402class t2basePseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
403                    list<dag> pattern>
404  : PseudoInst<oops, iops, itin, pattern> {
405  let Size = sz;
406  list<Predicate> Predicates = [IsThumb,HasV8MBaseline];
407}
408
409// PseudoInst that's Thumb2-mode only.
410class t2PseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
411                    list<dag> pattern>
412  : PseudoInst<oops, iops, itin, pattern> {
413  let Size = sz;
414  list<Predicate> Predicates = [IsThumb2];
415}
416
417class ARMPseudoExpand<dag oops, dag iops, int sz,
418                      InstrItinClass itin, list<dag> pattern,
419                      dag Result>
420  : ARMPseudoInst<oops, iops, sz, itin, pattern>,
421    PseudoInstExpansion<Result>;
422
423class tPseudoExpand<dag oops, dag iops, int sz,
424                    InstrItinClass itin, list<dag> pattern,
425                    dag Result>
426  : tPseudoInst<oops, iops, sz, itin, pattern>,
427    PseudoInstExpansion<Result>;
428
429class t2PseudoExpand<dag oops, dag iops, int sz,
430                    InstrItinClass itin, list<dag> pattern,
431                    dag Result>
432  : t2PseudoInst<oops, iops, sz, itin, pattern>,
433    PseudoInstExpansion<Result>;
434
435// Almost all ARM instructions are predicable.
436class I<dag oops, dag iops, AddrMode am, int sz,
437        IndexMode im, Format f, InstrItinClass itin,
438        string opc, string asm, string cstr,
439        list<dag> pattern>
440  : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
441  bits<4> p;
442  let Inst{31-28} = p;
443  let OutOperandList = oops;
444  let InOperandList = !con(iops, (ins pred:$p));
445  let AsmString = !strconcat(opc, "${p}", asm);
446  let Pattern = pattern;
447  list<Predicate> Predicates = [IsARM];
448}
449
450// A few are not predicable
451class InoP<dag oops, dag iops, AddrMode am, int sz,
452           IndexMode im, Format f, InstrItinClass itin,
453           string opc, string asm, string cstr,
454           list<dag> pattern>
455  : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
456  let OutOperandList = oops;
457  let InOperandList = iops;
458  let AsmString = !strconcat(opc, asm);
459  let Pattern = pattern;
460  let isPredicable = 0;
461  list<Predicate> Predicates = [IsARM];
462}
463
464// Same as I except it can optionally modify CPSR. Note it's modeled as an input
465// operand since by default it's a zero register. It will become an implicit def
466// once it's "flipped".
467class sI<dag oops, dag iops, AddrMode am, int sz,
468         IndexMode im, Format f, InstrItinClass itin,
469         string opc, string asm, string cstr,
470         list<dag> pattern>
471  : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
472  bits<4> p; // Predicate operand
473  bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
474  let Inst{31-28} = p;
475  let Inst{20} = s;
476
477  let OutOperandList = oops;
478  let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
479  let AsmString = !strconcat(opc, "${s}${p}", asm);
480  let Pattern = pattern;
481  list<Predicate> Predicates = [IsARM];
482}
483
484// Special cases
485class XI<dag oops, dag iops, AddrMode am, int sz,
486         IndexMode im, Format f, InstrItinClass itin,
487         string asm, string cstr, list<dag> pattern>
488  : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
489  let OutOperandList = oops;
490  let InOperandList = iops;
491  let AsmString = asm;
492  let Pattern = pattern;
493  list<Predicate> Predicates = [IsARM];
494}
495
496class AI<dag oops, dag iops, Format f, InstrItinClass itin,
497         string opc, string asm, list<dag> pattern>
498  : I<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
499      opc, asm, "", pattern>;
500class AsI<dag oops, dag iops, Format f, InstrItinClass itin,
501          string opc, string asm, list<dag> pattern>
502  : sI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
503       opc, asm, "", pattern>;
504class AXI<dag oops, dag iops, Format f, InstrItinClass itin,
505          string asm, list<dag> pattern>
506  : XI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
507       asm, "", pattern>;
508class AXIM<dag oops, dag iops, AddrMode am, Format f, InstrItinClass itin,
509          string asm, list<dag> pattern>
510  : XI<oops, iops, am, 4, IndexModeNone, f, itin,
511       asm, "", pattern>;
512class AInoP<dag oops, dag iops, Format f, InstrItinClass itin,
513            string opc, string asm, list<dag> pattern>
514  : InoP<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
515         opc, asm, "", pattern>;
516
517// Ctrl flow instructions
518class ABI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
519          string opc, string asm, list<dag> pattern>
520  : I<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
521      opc, asm, "", pattern> {
522  let Inst{27-24} = opcod;
523}
524class ABXI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
525           string asm, list<dag> pattern>
526  : XI<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
527       asm, "", pattern> {
528  let Inst{27-24} = opcod;
529}
530
531// BR_JT instructions
532class JTI<dag oops, dag iops, InstrItinClass itin,
533          string asm, list<dag> pattern>
534  : XI<oops, iops, AddrModeNone, 0, IndexModeNone, BrMiscFrm, itin,
535       asm, "", pattern>;
536
537class AIldr_ex_or_acq<bits<2> opcod, bits<2> opcod2, dag oops, dag iops, InstrItinClass itin,
538              string opc, string asm, list<dag> pattern>
539  : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
540      opc, asm, "", pattern> {
541  bits<4> Rt;
542  bits<4> addr;
543  let Inst{27-23} = 0b00011;
544  let Inst{22-21} = opcod;
545  let Inst{20}    = 1;
546  let Inst{19-16} = addr;
547  let Inst{15-12} = Rt;
548  let Inst{11-10} = 0b11;
549  let Inst{9-8}   = opcod2;
550  let Inst{7-0}   = 0b10011111;
551}
552class AIstr_ex_or_rel<bits<2> opcod, bits<2> opcod2, dag oops, dag iops, InstrItinClass itin,
553              string opc, string asm, list<dag> pattern>
554  : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
555      opc, asm, "", pattern> {
556  bits<4> Rt;
557  bits<4> addr;
558  let Inst{27-23} = 0b00011;
559  let Inst{22-21} = opcod;
560  let Inst{20}    = 0;
561  let Inst{19-16} = addr;
562  let Inst{11-10} = 0b11;
563  let Inst{9-8}   = opcod2;
564  let Inst{7-4}   = 0b1001;
565  let Inst{3-0}   = Rt;
566}
567// Atomic load/store instructions
568class AIldrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
569              string opc, string asm, list<dag> pattern>
570  : AIldr_ex_or_acq<opcod, 0b11, oops, iops, itin, opc, asm, pattern>;
571
572class AIstrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
573              string opc, string asm, list<dag> pattern>
574  : AIstr_ex_or_rel<opcod, 0b11, oops, iops, itin, opc, asm, pattern> {
575  bits<4> Rd;
576  let Inst{15-12} = Rd;
577}
578
579// Exclusive load/store instructions
580
581class AIldaex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
582              string opc, string asm, list<dag> pattern>
583  : AIldr_ex_or_acq<opcod, 0b10, oops, iops, itin, opc, asm, pattern>,
584    Requires<[IsARM, HasAcquireRelease, HasV7Clrex]>;
585
586class AIstlex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
587              string opc, string asm, list<dag> pattern>
588  : AIstr_ex_or_rel<opcod, 0b10, oops, iops, itin, opc, asm, pattern>,
589    Requires<[IsARM, HasAcquireRelease, HasV7Clrex]> {
590  bits<4> Rd;
591  let Inst{15-12} = Rd;
592}
593
594class AIswp<bit b, dag oops, dag iops, string opc, list<dag> pattern>
595  : AI<oops, iops, MiscFrm, NoItinerary, opc, "\t$Rt, $Rt2, $addr", pattern> {
596  bits<4> Rt;
597  bits<4> Rt2;
598  bits<4> addr;
599  let Inst{27-23} = 0b00010;
600  let Inst{22} = b;
601  let Inst{21-20} = 0b00;
602  let Inst{19-16} = addr;
603  let Inst{15-12} = Rt;
604  let Inst{11-4} = 0b00001001;
605  let Inst{3-0} = Rt2;
606
607  let Unpredictable{11-8} = 0b1111;
608  let DecoderMethod = "DecodeSwap";
609}
610// Acquire/Release load/store instructions
611class AIldracq<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
612              string opc, string asm, list<dag> pattern>
613  : AIldr_ex_or_acq<opcod, 0b00, oops, iops, itin, opc, asm, pattern>,
614    Requires<[IsARM, HasAcquireRelease]>;
615
616class AIstrrel<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
617              string opc, string asm, list<dag> pattern>
618  : AIstr_ex_or_rel<opcod, 0b00, oops, iops, itin, opc, asm, pattern>,
619    Requires<[IsARM, HasAcquireRelease]> {
620  let Inst{15-12}   = 0b1111;
621}
622
623// addrmode1 instructions
624class AI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
625          string opc, string asm, list<dag> pattern>
626  : I<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
627      opc, asm, "", pattern> {
628  let Inst{24-21} = opcod;
629  let Inst{27-26} = 0b00;
630}
631class AsI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
632           string opc, string asm, list<dag> pattern>
633  : sI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
634       opc, asm, "", pattern> {
635  let Inst{24-21} = opcod;
636  let Inst{27-26} = 0b00;
637}
638class AXI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
639           string asm, list<dag> pattern>
640  : XI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
641       asm, "", pattern> {
642  let Inst{24-21} = opcod;
643  let Inst{27-26} = 0b00;
644}
645
646// loads
647
648// LDR/LDRB/STR/STRB/...
649class AI2ldst<bits<3> op, bit isLd, bit isByte, dag oops, dag iops, AddrMode am,
650             Format f, InstrItinClass itin, string opc, string asm,
651             list<dag> pattern>
652  : I<oops, iops, am, 4, IndexModeNone, f, itin, opc, asm,
653      "", pattern> {
654  let Inst{27-25} = op;
655  let Inst{24} = 1;  // 24 == P
656  // 23 == U
657  let Inst{22} = isByte;
658  let Inst{21} = 0;  // 21 == W
659  let Inst{20} = isLd;
660}
661// Indexed load/stores
662class AI2ldstidx<bit isLd, bit isByte, bit isPre, dag oops, dag iops,
663                IndexMode im, Format f, InstrItinClass itin, string opc,
664                string asm, string cstr, list<dag> pattern>
665  : I<oops, iops, AddrMode2, 4, im, f, itin,
666      opc, asm, cstr, pattern> {
667  bits<4> Rt;
668  let Inst{27-26} = 0b01;
669  let Inst{24}    = isPre; // P bit
670  let Inst{22}    = isByte; // B bit
671  let Inst{21}    = isPre; // W bit
672  let Inst{20}    = isLd; // L bit
673  let Inst{15-12} = Rt;
674}
675class AI2stridx_reg<bit isByte, bit isPre, dag oops, dag iops,
676                IndexMode im, Format f, InstrItinClass itin, string opc,
677                string asm, string cstr, list<dag> pattern>
678  : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
679               pattern> {
680  // AM2 store w/ two operands: (GPR, am2offset)
681  // {12}     isAdd
682  // {11-0}   imm12/Rm
683  bits<14> offset;
684  bits<4> Rn;
685  let Inst{25} = 1;
686  let Inst{23} = offset{12};
687  let Inst{19-16} = Rn;
688  let Inst{11-5} = offset{11-5};
689  let Inst{4} = 0;
690  let Inst{3-0} = offset{3-0};
691}
692
693class AI2stridx_imm<bit isByte, bit isPre, dag oops, dag iops,
694                IndexMode im, Format f, InstrItinClass itin, string opc,
695                string asm, string cstr, list<dag> pattern>
696  : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
697               pattern> {
698  // AM2 store w/ two operands: (GPR, am2offset)
699  // {12}     isAdd
700  // {11-0}   imm12/Rm
701  bits<14> offset;
702  bits<4> Rn;
703  let Inst{25} = 0;
704  let Inst{23} = offset{12};
705  let Inst{19-16} = Rn;
706  let Inst{11-0} = offset{11-0};
707}
708
709
710// FIXME: Merge with the above class when addrmode2 gets used for STR, STRB
711// but for now use this class for STRT and STRBT.
712class AI2stridxT<bit isByte, bit isPre, dag oops, dag iops,
713                IndexMode im, Format f, InstrItinClass itin, string opc,
714                string asm, string cstr, list<dag> pattern>
715  : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
716               pattern> {
717  // AM2 store w/ two operands: (GPR, am2offset)
718  // {17-14}  Rn
719  // {13}     1 == Rm, 0 == imm12
720  // {12}     isAdd
721  // {11-0}   imm12/Rm
722  bits<18> addr;
723  let Inst{25} = addr{13};
724  let Inst{23} = addr{12};
725  let Inst{19-16} = addr{17-14};
726  let Inst{11-0} = addr{11-0};
727}
728
729// addrmode3 instructions
730class AI3ld<bits<4> op, bit op20, dag oops, dag iops, Format f,
731            InstrItinClass itin, string opc, string asm, list<dag> pattern>
732  : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
733      opc, asm, "", pattern> {
734  bits<14> addr;
735  bits<4> Rt;
736  let Inst{27-25} = 0b000;
737  let Inst{24}    = 1;            // P bit
738  let Inst{23}    = addr{8};      // U bit
739  let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
740  let Inst{21}    = 0;            // W bit
741  let Inst{20}    = op20;         // L bit
742  let Inst{19-16} = addr{12-9};   // Rn
743  let Inst{15-12} = Rt;           // Rt
744  let Inst{11-8}  = addr{7-4};    // imm7_4/zero
745  let Inst{7-4}   = op;
746  let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
747
748  let DecoderMethod = "DecodeAddrMode3Instruction";
749}
750
751class AI3ldstidx<bits<4> op, bit op20, bit isPre, dag oops, dag iops,
752                IndexMode im, Format f, InstrItinClass itin, string opc,
753                string asm, string cstr, list<dag> pattern>
754  : I<oops, iops, AddrMode3, 4, im, f, itin,
755      opc, asm, cstr, pattern> {
756  bits<4> Rt;
757  let Inst{27-25} = 0b000;
758  let Inst{24}    = isPre;        // P bit
759  let Inst{21}    = isPre;        // W bit
760  let Inst{20}    = op20;         // L bit
761  let Inst{15-12} = Rt;           // Rt
762  let Inst{7-4}   = op;
763}
764
765// FIXME: Merge with the above class when addrmode2 gets used for LDR, LDRB
766// but for now use this class for LDRSBT, LDRHT, LDSHT.
767class AI3ldstidxT<bits<4> op, bit isLoad, dag oops, dag iops,
768                  IndexMode im, Format f, InstrItinClass itin, string opc,
769                  string asm, string cstr, list<dag> pattern>
770  : I<oops, iops, AddrMode3, 4, im, f, itin, opc, asm, cstr, pattern> {
771  // {13}     1 == imm8, 0 == Rm
772  // {12-9}   Rn
773  // {8}      isAdd
774  // {7-4}    imm7_4/zero
775  // {3-0}    imm3_0/Rm
776  bits<4> addr;
777  bits<4> Rt;
778  let Inst{27-25} = 0b000;
779  let Inst{24}    = 0;            // P bit
780  let Inst{21}    = 1;
781  let Inst{20}    = isLoad;       // L bit
782  let Inst{19-16} = addr;         // Rn
783  let Inst{15-12} = Rt;           // Rt
784  let Inst{7-4}   = op;
785}
786
787// stores
788class AI3str<bits<4> op, dag oops, dag iops, Format f, InstrItinClass itin,
789             string opc, string asm, list<dag> pattern>
790  : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
791      opc, asm, "", pattern> {
792  bits<14> addr;
793  bits<4> Rt;
794  let Inst{27-25} = 0b000;
795  let Inst{24}    = 1;            // P bit
796  let Inst{23}    = addr{8};      // U bit
797  let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
798  let Inst{21}    = 0;            // W bit
799  let Inst{20}    = 0;            // L bit
800  let Inst{19-16} = addr{12-9};   // Rn
801  let Inst{15-12} = Rt;           // Rt
802  let Inst{11-8}  = addr{7-4};    // imm7_4/zero
803  let Inst{7-4}   = op;
804  let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
805  let DecoderMethod = "DecodeAddrMode3Instruction";
806}
807
808// addrmode4 instructions
809class AXI4<dag oops, dag iops, IndexMode im, Format f, InstrItinClass itin,
810           string asm, string cstr, list<dag> pattern>
811  : XI<oops, iops, AddrMode4, 4, im, f, itin, asm, cstr, pattern> {
812  bits<4>  p;
813  bits<16> regs;
814  bits<4>  Rn;
815  let Inst{31-28} = p;
816  let Inst{27-25} = 0b100;
817  let Inst{22}    = 0; // S bit
818  let Inst{19-16} = Rn;
819  let Inst{15-0}  = regs;
820}
821
822// Unsigned multiply, multiply-accumulate instructions.
823class AMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
824             string opc, string asm, list<dag> pattern>
825  : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
826      opc, asm, "", pattern> {
827  let Inst{7-4}   = 0b1001;
828  let Inst{20}    = 0; // S bit
829  let Inst{27-21} = opcod;
830}
831class AsMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
832              string opc, string asm, list<dag> pattern>
833  : sI<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
834       opc, asm, "", pattern> {
835  let Inst{7-4}   = 0b1001;
836  let Inst{27-21} = opcod;
837}
838
839// Most significant word multiply
840class AMul2I<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
841             InstrItinClass itin, string opc, string asm, list<dag> pattern>
842  : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
843      opc, asm, "", pattern> {
844  bits<4> Rd;
845  bits<4> Rn;
846  bits<4> Rm;
847  let Inst{7-4}   = opc7_4;
848  let Inst{20}    = 1;
849  let Inst{27-21} = opcod;
850  let Inst{19-16} = Rd;
851  let Inst{11-8}  = Rm;
852  let Inst{3-0}   = Rn;
853}
854// MSW multiple w/ Ra operand
855class AMul2Ia<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
856              InstrItinClass itin, string opc, string asm, list<dag> pattern>
857  : AMul2I<opcod, opc7_4, oops, iops, itin, opc, asm, pattern> {
858  bits<4> Ra;
859  let Inst{15-12} = Ra;
860}
861
862// SMUL<x><y> / SMULW<y> / SMLA<x><y> / SMLAW<x><y>
863class AMulxyIbase<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
864              InstrItinClass itin, string opc, string asm, list<dag> pattern>
865  : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
866      opc, asm, "", pattern> {
867  bits<4> Rn;
868  bits<4> Rm;
869  let Inst{4}     = 0;
870  let Inst{7}     = 1;
871  let Inst{20}    = 0;
872  let Inst{27-21} = opcod;
873  let Inst{6-5}   = bit6_5;
874  let Inst{11-8}  = Rm;
875  let Inst{3-0}   = Rn;
876}
877class AMulxyI<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
878              InstrItinClass itin, string opc, string asm, list<dag> pattern>
879  : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
880  bits<4> Rd;
881  let Inst{19-16} = Rd;
882}
883
884// AMulxyI with Ra operand
885class AMulxyIa<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
886              InstrItinClass itin, string opc, string asm, list<dag> pattern>
887  : AMulxyI<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
888  bits<4> Ra;
889  let Inst{15-12} = Ra;
890}
891// SMLAL*
892class AMulxyI64<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
893              InstrItinClass itin, string opc, string asm, list<dag> pattern>
894  : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
895  bits<4> RdLo;
896  bits<4> RdHi;
897  let Inst{19-16} = RdHi;
898  let Inst{15-12} = RdLo;
899}
900
901// Extend instructions.
902class AExtI<bits<8> opcod, dag oops, dag iops, InstrItinClass itin,
903            string opc, string asm, list<dag> pattern>
904  : I<oops, iops, AddrModeNone, 4, IndexModeNone, ExtFrm, itin,
905      opc, asm, "", pattern> {
906  // All AExtI instructions have Rd and Rm register operands.
907  bits<4> Rd;
908  bits<4> Rm;
909  let Inst{15-12} = Rd;
910  let Inst{3-0}   = Rm;
911  let Inst{7-4}   = 0b0111;
912  let Inst{9-8}   = 0b00;
913  let Inst{27-20} = opcod;
914
915  let Unpredictable{9-8} = 0b11;
916}
917
918// Misc Arithmetic instructions.
919class AMiscA1I<bits<8> opcod, bits<4> opc7_4, dag oops, dag iops,
920               InstrItinClass itin, string opc, string asm, list<dag> pattern>
921  : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
922      opc, asm, "", pattern> {
923  bits<4> Rd;
924  bits<4> Rm;
925  let Inst{27-20} = opcod;
926  let Inst{19-16} = 0b1111;
927  let Inst{15-12} = Rd;
928  let Inst{11-8}  = 0b1111;
929  let Inst{7-4}   = opc7_4;
930  let Inst{3-0}   = Rm;
931}
932
933// Division instructions.
934class ADivA1I<bits<3> opcod, dag oops, dag iops,
935              InstrItinClass itin, string opc, string asm, list<dag> pattern>
936  : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
937      opc, asm, "", pattern> {
938  bits<4> Rd;
939  bits<4> Rn;
940  bits<4> Rm;
941  let Inst{27-23} = 0b01110;
942  let Inst{22-20} = opcod;
943  let Inst{19-16} = Rd;
944  let Inst{15-12} = 0b1111;
945  let Inst{11-8}  = Rm;
946  let Inst{7-4}   = 0b0001;
947  let Inst{3-0}   = Rn;
948}
949
950// PKH instructions
951def PKHLSLAsmOperand : ImmAsmOperand {
952  let Name = "PKHLSLImm";
953  let ParserMethod = "parsePKHLSLImm";
954}
955def pkh_lsl_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 32; }]>{
956  let PrintMethod = "printPKHLSLShiftImm";
957  let ParserMatchClass = PKHLSLAsmOperand;
958}
959def PKHASRAsmOperand : AsmOperandClass {
960  let Name = "PKHASRImm";
961  let ParserMethod = "parsePKHASRImm";
962}
963def pkh_asr_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]>{
964  let PrintMethod = "printPKHASRShiftImm";
965  let ParserMatchClass = PKHASRAsmOperand;
966}
967
968class APKHI<bits<8> opcod, bit tb, dag oops, dag iops, InstrItinClass itin,
969            string opc, string asm, list<dag> pattern>
970  : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
971      opc, asm, "", pattern> {
972  bits<4> Rd;
973  bits<4> Rn;
974  bits<4> Rm;
975  bits<5> sh;
976  let Inst{27-20} = opcod;
977  let Inst{19-16} = Rn;
978  let Inst{15-12} = Rd;
979  let Inst{11-7}  = sh;
980  let Inst{6}     = tb;
981  let Inst{5-4}   = 0b01;
982  let Inst{3-0}   = Rm;
983}
984
985//===----------------------------------------------------------------------===//
986
987// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
988class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
989  list<Predicate> Predicates = [IsARM];
990}
991class ARMV5TPat<dag pattern, dag result> : Pat<pattern, result> {
992  list<Predicate> Predicates = [IsARM, HasV5T];
993}
994class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
995  list<Predicate> Predicates = [IsARM, HasV5TE];
996}
997// ARMV5MOPat - Same as ARMV5TEPat with UseMulOps.
998class ARMV5MOPat<dag pattern, dag result> : Pat<pattern, result> {
999  list<Predicate> Predicates = [IsARM, HasV5TE, UseMulOps];
1000}
1001class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
1002  list<Predicate> Predicates = [IsARM, HasV6];
1003}
1004class VFPPat<dag pattern, dag result> : Pat<pattern, result> {
1005  list<Predicate> Predicates = [HasVFP2];
1006}
1007class VFPNoNEONPat<dag pattern, dag result> : Pat<pattern, result> {
1008  list<Predicate> Predicates = [HasVFP2, DontUseNEONForFP];
1009}
1010class Thumb2DSPPat<dag pattern, dag result> : Pat<pattern, result> {
1011  list<Predicate> Predicates = [IsThumb2, HasDSP];
1012}
1013class Thumb2DSPMulPat<dag pattern, dag result> : Pat<pattern, result> {
1014  list<Predicate> Predicates = [IsThumb2, UseMulOps, HasDSP];
1015}
1016class Thumb2ExtractPat<dag pattern, dag result> : Pat<pattern, result> {
1017  list<Predicate> Predicates = [IsThumb2, HasT2ExtractPack];
1018}
1019//===----------------------------------------------------------------------===//
1020// Thumb Instruction Format Definitions.
1021//
1022
1023class ThumbI<dag oops, dag iops, AddrMode am, int sz,
1024             InstrItinClass itin, string asm, string cstr, list<dag> pattern>
1025  : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1026  let OutOperandList = oops;
1027  let InOperandList = iops;
1028  let AsmString = asm;
1029  let Pattern = pattern;
1030  list<Predicate> Predicates = [IsThumb];
1031}
1032
1033// TI - Thumb instruction.
1034class TI<dag oops, dag iops, InstrItinClass itin, string asm, list<dag> pattern>
1035  : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
1036
1037// Two-address instructions
1038class TIt<dag oops, dag iops, InstrItinClass itin, string asm,
1039          list<dag> pattern>
1040  : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "$lhs = $dst",
1041           pattern>;
1042
1043// tBL, tBX 32-bit instructions
1044class TIx2<bits<5> opcod1, bits<2> opcod2, bit opcod3,
1045           dag oops, dag iops, InstrItinClass itin, string asm,
1046           list<dag> pattern>
1047    : ThumbI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>,
1048      Encoding {
1049  let Inst{31-27} = opcod1;
1050  let Inst{15-14} = opcod2;
1051  let Inst{12}    = opcod3;
1052}
1053
1054// BR_JT instructions
1055class TJTI<dag oops, dag iops, InstrItinClass itin, string asm,
1056           list<dag> pattern>
1057  : ThumbI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
1058
1059// Thumb1 only
1060class Thumb1I<dag oops, dag iops, AddrMode am, int sz,
1061              InstrItinClass itin, string asm, string cstr, list<dag> pattern>
1062  : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1063  let OutOperandList = oops;
1064  let InOperandList = iops;
1065  let AsmString = asm;
1066  let Pattern = pattern;
1067  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1068}
1069
1070class T1I<dag oops, dag iops, InstrItinClass itin,
1071          string asm, list<dag> pattern>
1072  : Thumb1I<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
1073class T1Ix2<dag oops, dag iops, InstrItinClass itin,
1074            string asm, list<dag> pattern>
1075  : Thumb1I<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
1076
1077// Two-address instructions
1078class T1It<dag oops, dag iops, InstrItinClass itin,
1079           string asm, string cstr, list<dag> pattern>
1080  : Thumb1I<oops, iops, AddrModeNone, 2, itin,
1081            asm, cstr, pattern>;
1082
1083// Thumb1 instruction that can either be predicated or set CPSR.
1084class Thumb1sI<dag oops, dag iops, AddrMode am, int sz,
1085               InstrItinClass itin,
1086               string opc, string asm, string cstr, list<dag> pattern>
1087  : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1088  let OutOperandList = !con(oops, (outs s_cc_out:$s));
1089  let InOperandList = !con(iops, (ins pred:$p));
1090  let AsmString = !strconcat(opc, "${s}${p}", asm);
1091  let Pattern = pattern;
1092  let thumbArithFlagSetting = 1;
1093  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1094  let DecoderNamespace = "ThumbSBit";
1095}
1096
1097class T1sI<dag oops, dag iops, InstrItinClass itin,
1098           string opc, string asm, list<dag> pattern>
1099  : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
1100
1101// Two-address instructions
1102class T1sIt<dag oops, dag iops, InstrItinClass itin,
1103            string opc, string asm, list<dag> pattern>
1104  : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm,
1105             "$Rn = $Rdn", pattern>;
1106
1107// Thumb1 instruction that can be predicated.
1108class Thumb1pI<dag oops, dag iops, AddrMode am, int sz,
1109               InstrItinClass itin,
1110               string opc, string asm, string cstr, list<dag> pattern>
1111  : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1112  let OutOperandList = oops;
1113  let InOperandList = !con(iops, (ins pred:$p));
1114  let AsmString = !strconcat(opc, "${p}", asm);
1115  let Pattern = pattern;
1116  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1117}
1118
1119class T1pI<dag oops, dag iops, InstrItinClass itin,
1120           string opc, string asm, list<dag> pattern>
1121  : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
1122
1123// Two-address instructions
1124class T1pIt<dag oops, dag iops, InstrItinClass itin,
1125            string opc, string asm, list<dag> pattern>
1126  : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm,
1127             "$Rn = $Rdn", pattern>;
1128
1129class T1pIs<dag oops, dag iops,
1130            InstrItinClass itin, string opc, string asm, list<dag> pattern>
1131  : Thumb1pI<oops, iops, AddrModeT1_s, 2, itin, opc, asm, "", pattern>;
1132
1133class Encoding16 : Encoding {
1134  let Inst{31-16} = 0x0000;
1135}
1136
1137// A6.2 16-bit Thumb instruction encoding
1138class T1Encoding<bits<6> opcode> : Encoding16 {
1139  let Inst{15-10} = opcode;
1140}
1141
1142// A6.2.1 Shift (immediate), add, subtract, move, and compare encoding.
1143class T1General<bits<5> opcode> : Encoding16 {
1144  let Inst{15-14} = 0b00;
1145  let Inst{13-9} = opcode;
1146}
1147
1148// A6.2.2 Data-processing encoding.
1149class T1DataProcessing<bits<4> opcode> : Encoding16 {
1150  let Inst{15-10} = 0b010000;
1151  let Inst{9-6} = opcode;
1152}
1153
1154// A6.2.3 Special data instructions and branch and exchange encoding.
1155class T1Special<bits<4> opcode> : Encoding16 {
1156  let Inst{15-10} = 0b010001;
1157  let Inst{9-6}   = opcode;
1158}
1159
1160// A6.2.4 Load/store single data item encoding.
1161class T1LoadStore<bits<4> opA, bits<3> opB> : Encoding16 {
1162  let Inst{15-12} = opA;
1163  let Inst{11-9}  = opB;
1164}
1165class T1LdStSP<bits<3> opB>   : T1LoadStore<0b1001, opB>; // SP relative
1166
1167class T1BranchCond<bits<4> opcode> : Encoding16 {
1168  let Inst{15-12} = opcode;
1169}
1170
1171// Helper classes to encode Thumb1 loads and stores. For immediates, the
1172// following bits are used for "opA" (see A6.2.4):
1173//
1174//   0b0110 => Immediate, 4 bytes
1175//   0b1000 => Immediate, 2 bytes
1176//   0b0111 => Immediate, 1 byte
1177class T1pILdStEncode<bits<3> opcode, dag oops, dag iops, AddrMode am,
1178                     InstrItinClass itin, string opc, string asm,
1179                     list<dag> pattern>
1180  : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
1181    T1LoadStore<0b0101, opcode> {
1182  bits<3> Rt;
1183  bits<8> addr;
1184  let Inst{8-6} = addr{5-3};    // Rm
1185  let Inst{5-3} = addr{2-0};    // Rn
1186  let Inst{2-0} = Rt;
1187}
1188class T1pILdStEncodeImm<bits<4> opA, bit opB, dag oops, dag iops, AddrMode am,
1189                        InstrItinClass itin, string opc, string asm,
1190                        list<dag> pattern>
1191  : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
1192    T1LoadStore<opA, {opB,?,?}> {
1193  bits<3> Rt;
1194  bits<8> addr;
1195  let Inst{10-6} = addr{7-3};   // imm5
1196  let Inst{5-3}  = addr{2-0};   // Rn
1197  let Inst{2-0}  = Rt;
1198}
1199
1200// A6.2.5 Miscellaneous 16-bit instructions encoding.
1201class T1Misc<bits<7> opcode> : Encoding16 {
1202  let Inst{15-12} = 0b1011;
1203  let Inst{11-5} = opcode;
1204}
1205
1206// Thumb2I - Thumb2 instruction. Almost all Thumb2 instructions are predicable.
1207class Thumb2I<dag oops, dag iops, AddrMode am, int sz,
1208              InstrItinClass itin,
1209              string opc, string asm, string cstr, list<dag> pattern>
1210  : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1211  let OutOperandList = oops;
1212  let InOperandList = !con(iops, (ins pred:$p));
1213  let AsmString = !strconcat(opc, "${p}", asm);
1214  let Pattern = pattern;
1215  list<Predicate> Predicates = [IsThumb2];
1216  let DecoderNamespace = "Thumb2";
1217}
1218
1219// Same as Thumb2I except it can optionally modify CPSR. Note it's modeled as an
1220// input operand since by default it's a zero register. It will become an
1221// implicit def once it's "flipped".
1222//
1223// FIXME: This uses unified syntax so {s} comes before {p}. We should make it
1224// more consistent.
1225class Thumb2sI<dag oops, dag iops, AddrMode am, int sz,
1226               InstrItinClass itin,
1227               string opc, string asm, string cstr, list<dag> pattern>
1228  : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1229  bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
1230  let Inst{20} = s;
1231
1232  let OutOperandList = oops;
1233  let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
1234  let AsmString = !strconcat(opc, "${s}${p}", asm);
1235  let Pattern = pattern;
1236  list<Predicate> Predicates = [IsThumb2];
1237  let DecoderNamespace = "Thumb2";
1238}
1239
1240// Special cases
1241class Thumb2XI<dag oops, dag iops, AddrMode am, int sz,
1242               InstrItinClass itin,
1243               string asm, string cstr, list<dag> pattern>
1244  : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1245  let OutOperandList = oops;
1246  let InOperandList = iops;
1247  let AsmString = asm;
1248  let Pattern = pattern;
1249  list<Predicate> Predicates = [IsThumb2];
1250  let DecoderNamespace = "Thumb2";
1251}
1252
1253class ThumbXI<dag oops, dag iops, AddrMode am, int sz,
1254              InstrItinClass itin,
1255              string asm, string cstr, list<dag> pattern>
1256  : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1257  let OutOperandList = oops;
1258  let InOperandList = iops;
1259  let AsmString = asm;
1260  let Pattern = pattern;
1261  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1262  let DecoderNamespace = "Thumb";
1263}
1264
1265class T2I<dag oops, dag iops, InstrItinClass itin,
1266          string opc, string asm, list<dag> pattern>
1267  : Thumb2I<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
1268class T2Ii12<dag oops, dag iops, InstrItinClass itin,
1269             string opc, string asm, list<dag> pattern>
1270  : Thumb2I<oops, iops, AddrModeT2_i12, 4, itin, opc, asm, "",pattern>;
1271class T2Ii8<dag oops, dag iops, InstrItinClass itin,
1272            string opc, string asm, list<dag> pattern>
1273  : Thumb2I<oops, iops, AddrModeT2_i8, 4, itin, opc, asm, "", pattern>;
1274class T2Iso<dag oops, dag iops, InstrItinClass itin,
1275            string opc, string asm, list<dag> pattern>
1276  : Thumb2I<oops, iops, AddrModeT2_so, 4, itin, opc, asm, "", pattern>;
1277class T2Ipc<dag oops, dag iops, InstrItinClass itin,
1278            string opc, string asm, list<dag> pattern>
1279  : Thumb2I<oops, iops, AddrModeT2_pc, 4, itin, opc, asm, "", pattern>;
1280class T2Ii8s4<bit P, bit W, bit isLoad, dag oops, dag iops, InstrItinClass itin,
1281              string opc, string asm, string cstr, list<dag> pattern>
1282  : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, cstr,
1283            pattern> {
1284  bits<4> Rt;
1285  bits<4> Rt2;
1286  bits<13> addr;
1287  let Inst{31-25} = 0b1110100;
1288  let Inst{24}    = P;
1289  let Inst{23}    = addr{8};
1290  let Inst{22}    = 1;
1291  let Inst{21}    = W;
1292  let Inst{20}    = isLoad;
1293  let Inst{19-16} = addr{12-9};
1294  let Inst{15-12} = Rt{3-0};
1295  let Inst{11-8}  = Rt2{3-0};
1296  let Inst{7-0}   = addr{7-0};
1297}
1298class T2Ii8s4post<bit P, bit W, bit isLoad, dag oops, dag iops,
1299                  InstrItinClass itin, string opc, string asm, string cstr,
1300                  list<dag> pattern>
1301  : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, cstr,
1302            pattern> {
1303  bits<4> Rt;
1304  bits<4> Rt2;
1305  bits<4> addr;
1306  bits<9> imm;
1307  let Inst{31-25} = 0b1110100;
1308  let Inst{24}    = P;
1309  let Inst{23}    = imm{8};
1310  let Inst{22}    = 1;
1311  let Inst{21}    = W;
1312  let Inst{20}    = isLoad;
1313  let Inst{19-16} = addr;
1314  let Inst{15-12} = Rt{3-0};
1315  let Inst{11-8}  = Rt2{3-0};
1316  let Inst{7-0}   = imm{7-0};
1317}
1318
1319class T2sI<dag oops, dag iops, InstrItinClass itin,
1320           string opc, string asm, list<dag> pattern>
1321  : Thumb2sI<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
1322
1323class T2XI<dag oops, dag iops, InstrItinClass itin,
1324           string asm, list<dag> pattern>
1325  : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
1326class T2JTI<dag oops, dag iops, InstrItinClass itin,
1327            string asm, list<dag> pattern>
1328  : Thumb2XI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
1329
1330// Move to/from coprocessor instructions
1331class T2Cop<bits<4> opc, dag oops, dag iops, string opcstr, string asm,
1332            list<dag> pattern>
1333  : T2I <oops, iops, NoItinerary, opcstr, asm, pattern>, Requires<[IsThumb2]> {
1334  let Inst{31-28} = opc;
1335}
1336
1337// Two-address instructions
1338class T2XIt<dag oops, dag iops, InstrItinClass itin,
1339            string asm, string cstr, list<dag> pattern>
1340  : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, cstr, pattern>;
1341
1342// T2Ipreldst - Thumb2 pre-indexed load / store instructions.
1343class T2Ipreldst<bit signed, bits<2> opcod, bit load, bit pre,
1344                 dag oops, dag iops,
1345                 AddrMode am, IndexMode im, InstrItinClass itin,
1346                 string opc, string asm, string cstr, list<dag> pattern>
1347  : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
1348  let OutOperandList = oops;
1349  let InOperandList = !con(iops, (ins pred:$p));
1350  let AsmString = !strconcat(opc, "${p}", asm);
1351  let Pattern = pattern;
1352  list<Predicate> Predicates = [IsThumb2];
1353  let DecoderNamespace = "Thumb2";
1354
1355  bits<4> Rt;
1356  bits<13> addr;
1357  let Inst{31-27} = 0b11111;
1358  let Inst{26-25} = 0b00;
1359  let Inst{24}    = signed;
1360  let Inst{23}    = 0;
1361  let Inst{22-21} = opcod;
1362  let Inst{20}    = load;
1363  let Inst{19-16} = addr{12-9};
1364  let Inst{15-12} = Rt{3-0};
1365  let Inst{11}    = 1;
1366  // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
1367  let Inst{10}    = pre; // The P bit.
1368  let Inst{9}     = addr{8}; // Sign bit
1369  let Inst{8}     = 1; // The W bit.
1370  let Inst{7-0}   = addr{7-0};
1371
1372  let DecoderMethod = "DecodeT2LdStPre";
1373}
1374
1375// T2Ipostldst - Thumb2 post-indexed load / store instructions.
1376class T2Ipostldst<bit signed, bits<2> opcod, bit load, bit pre,
1377                 dag oops, dag iops,
1378                 AddrMode am, IndexMode im, InstrItinClass itin,
1379                 string opc, string asm, string cstr, list<dag> pattern>
1380  : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
1381  let OutOperandList = oops;
1382  let InOperandList = !con(iops, (ins pred:$p));
1383  let AsmString = !strconcat(opc, "${p}", asm);
1384  let Pattern = pattern;
1385  list<Predicate> Predicates = [IsThumb2];
1386  let DecoderNamespace = "Thumb2";
1387
1388  bits<4> Rt;
1389  bits<4> Rn;
1390  bits<9> offset;
1391  let Inst{31-27} = 0b11111;
1392  let Inst{26-25} = 0b00;
1393  let Inst{24}    = signed;
1394  let Inst{23}    = 0;
1395  let Inst{22-21} = opcod;
1396  let Inst{20}    = load;
1397  let Inst{19-16} = Rn;
1398  let Inst{15-12} = Rt{3-0};
1399  let Inst{11}    = 1;
1400  // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
1401  let Inst{10}    = pre; // The P bit.
1402  let Inst{9}     = offset{8}; // Sign bit
1403  let Inst{8}     = 1; // The W bit.
1404  let Inst{7-0}   = offset{7-0};
1405
1406  let DecoderMethod = "DecodeT2LdStPre";
1407}
1408
1409// T1Pat - Same as Pat<>, but requires that the compiler be in Thumb1 mode.
1410class T1Pat<dag pattern, dag result> : Pat<pattern, result> {
1411  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1412}
1413
1414// T2v6Pat - Same as Pat<>, but requires V6T2 Thumb2 mode.
1415class T2v6Pat<dag pattern, dag result> : Pat<pattern, result> {
1416  list<Predicate> Predicates = [IsThumb2, HasV6T2];
1417}
1418
1419// T2Pat - Same as Pat<>, but requires that the compiler be in Thumb2 mode.
1420class T2Pat<dag pattern, dag result> : Pat<pattern, result> {
1421  list<Predicate> Predicates = [IsThumb2];
1422}
1423
1424//===----------------------------------------------------------------------===//
1425
1426//===----------------------------------------------------------------------===//
1427// ARM VFP Instruction templates.
1428//
1429
1430// Almost all VFP instructions are predicable.
1431class VFPI<dag oops, dag iops, AddrMode am, int sz,
1432           IndexMode im, Format f, InstrItinClass itin,
1433           string opc, string asm, string cstr, list<dag> pattern>
1434  : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1435  bits<4> p;
1436  let Inst{31-28} = p;
1437  let OutOperandList = oops;
1438  let InOperandList = !con(iops, (ins pred:$p));
1439  let AsmString = !strconcat(opc, "${p}", asm);
1440  let Pattern = pattern;
1441  let PostEncoderMethod = "VFPThumb2PostEncoder";
1442  let DecoderNamespace = "VFP";
1443  list<Predicate> Predicates = [HasVFP2];
1444}
1445
1446// Special cases
1447class VFPXI<dag oops, dag iops, AddrMode am, int sz,
1448            IndexMode im, Format f, InstrItinClass itin,
1449            string asm, string cstr, list<dag> pattern>
1450  : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1451  bits<4> p;
1452  let Inst{31-28} = p;
1453  let OutOperandList = oops;
1454  let InOperandList = iops;
1455  let AsmString = asm;
1456  let Pattern = pattern;
1457  let PostEncoderMethod = "VFPThumb2PostEncoder";
1458  let DecoderNamespace = "VFP";
1459  list<Predicate> Predicates = [HasVFP2];
1460}
1461
1462class VFPAI<dag oops, dag iops, Format f, InstrItinClass itin,
1463            string opc, string asm, list<dag> pattern>
1464  : VFPI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
1465         opc, asm, "", pattern> {
1466  let PostEncoderMethod = "VFPThumb2PostEncoder";
1467}
1468
1469// ARM VFP addrmode5 loads and stores
1470class ADI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1471           InstrItinClass itin,
1472           string opc, string asm, list<dag> pattern>
1473  : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1474         VFPLdStFrm, itin, opc, asm, "", pattern> {
1475  // Instruction operands.
1476  bits<5>  Dd;
1477  bits<13> addr;
1478
1479  // Encode instruction operands.
1480  let Inst{23}    = addr{8};      // U (add = (U == '1'))
1481  let Inst{22}    = Dd{4};
1482  let Inst{19-16} = addr{12-9};   // Rn
1483  let Inst{15-12} = Dd{3-0};
1484  let Inst{7-0}   = addr{7-0};    // imm8
1485
1486  let Inst{27-24} = opcod1;
1487  let Inst{21-20} = opcod2;
1488  let Inst{11-9}  = 0b101;
1489  let Inst{8}     = 1;          // Double precision
1490
1491  // Loads & stores operate on both NEON and VFP pipelines.
1492  let D = VFPNeonDomain;
1493}
1494
1495class ASI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1496           InstrItinClass itin,
1497           string opc, string asm, list<dag> pattern>
1498  : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1499         VFPLdStFrm, itin, opc, asm, "", pattern> {
1500  // Instruction operands.
1501  bits<5>  Sd;
1502  bits<13> addr;
1503
1504  // Encode instruction operands.
1505  let Inst{23}    = addr{8};      // U (add = (U == '1'))
1506  let Inst{22}    = Sd{0};
1507  let Inst{19-16} = addr{12-9};   // Rn
1508  let Inst{15-12} = Sd{4-1};
1509  let Inst{7-0}   = addr{7-0};    // imm8
1510
1511  let Inst{27-24} = opcod1;
1512  let Inst{21-20} = opcod2;
1513  let Inst{11-9}  = 0b101;
1514  let Inst{8}     = 0;          // Single precision
1515
1516  // Loads & stores operate on both NEON and VFP pipelines.
1517  let D = VFPNeonDomain;
1518}
1519
1520class AHI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1521           InstrItinClass itin,
1522           string opc, string asm, list<dag> pattern>
1523  : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1524         VFPLdStFrm, itin, opc, asm, "", pattern> {
1525  list<Predicate> Predicates = [HasFullFP16];
1526
1527  // Instruction operands.
1528  bits<5>  Sd;
1529  bits<13> addr;
1530
1531  // Encode instruction operands.
1532  let Inst{23}    = addr{8};      // U (add = (U == '1'))
1533  let Inst{22}    = Sd{0};
1534  let Inst{19-16} = addr{12-9};   // Rn
1535  let Inst{15-12} = Sd{4-1};
1536  let Inst{7-0}   = addr{7-0};    // imm8
1537
1538  let Inst{27-24} = opcod1;
1539  let Inst{21-20} = opcod2;
1540  let Inst{11-8}  = 0b1001;     // Half precision
1541
1542  // Loads & stores operate on both NEON and VFP pipelines.
1543  let D = VFPNeonDomain;
1544}
1545
1546// VFP Load / store multiple pseudo instructions.
1547class PseudoVFPLdStM<dag oops, dag iops, InstrItinClass itin, string cstr,
1548                     list<dag> pattern>
1549  : InstARM<AddrMode4, 4, IndexModeNone, Pseudo, VFPNeonDomain,
1550            cstr, itin> {
1551  let OutOperandList = oops;
1552  let InOperandList = !con(iops, (ins pred:$p));
1553  let Pattern = pattern;
1554  list<Predicate> Predicates = [HasVFP2];
1555}
1556
1557// Load / store multiple
1558
1559// Unknown precision
1560class AXXI4<dag oops, dag iops, IndexMode im,
1561            string asm, string cstr, list<dag> pattern>
1562  : VFPXI<oops, iops, AddrMode4, 4, im,
1563          VFPLdStFrm, NoItinerary, asm, cstr, pattern> {
1564  // Instruction operands.
1565  bits<4>  Rn;
1566  bits<13> regs;
1567
1568  // Encode instruction operands.
1569  let Inst{19-16} = Rn;
1570  let Inst{22}    = 0;
1571  let Inst{15-12} = regs{11-8};
1572  let Inst{7-1}   = regs{7-1};
1573
1574  let Inst{27-25} = 0b110;
1575  let Inst{11-8}  = 0b1011;
1576  let Inst{0}     = 1;
1577}
1578
1579// Double precision
1580class AXDI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1581            string asm, string cstr, list<dag> pattern>
1582  : VFPXI<oops, iops, AddrMode4, 4, im,
1583          VFPLdStMulFrm, itin, asm, cstr, pattern> {
1584  // Instruction operands.
1585  bits<4>  Rn;
1586  bits<13> regs;
1587
1588  // Encode instruction operands.
1589  let Inst{19-16} = Rn;
1590  let Inst{22}    = regs{12};
1591  let Inst{15-12} = regs{11-8};
1592  let Inst{7-1}   = regs{7-1};
1593
1594  let Inst{27-25} = 0b110;
1595  let Inst{11-9}  = 0b101;
1596  let Inst{8}     = 1;          // Double precision
1597  let Inst{0}     = 0;
1598}
1599
1600// Single Precision
1601class AXSI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1602            string asm, string cstr, list<dag> pattern>
1603  : VFPXI<oops, iops, AddrMode4, 4, im,
1604          VFPLdStMulFrm, itin, asm, cstr, pattern> {
1605  // Instruction operands.
1606  bits<4> Rn;
1607  bits<13> regs;
1608
1609  // Encode instruction operands.
1610  let Inst{19-16} = Rn;
1611  let Inst{22}    = regs{8};
1612  let Inst{15-12} = regs{12-9};
1613  let Inst{7-0}   = regs{7-0};
1614
1615  let Inst{27-25} = 0b110;
1616  let Inst{11-9}  = 0b101;
1617  let Inst{8}     = 0;          // Single precision
1618}
1619
1620// Double precision, unary
1621class ADuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1622           bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1623           string asm, list<dag> pattern>
1624  : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1625  // Instruction operands.
1626  bits<5> Dd;
1627  bits<5> Dm;
1628
1629  // Encode instruction operands.
1630  let Inst{3-0}   = Dm{3-0};
1631  let Inst{5}     = Dm{4};
1632  let Inst{15-12} = Dd{3-0};
1633  let Inst{22}    = Dd{4};
1634
1635  let Inst{27-23} = opcod1;
1636  let Inst{21-20} = opcod2;
1637  let Inst{19-16} = opcod3;
1638  let Inst{11-9}  = 0b101;
1639  let Inst{8}     = 1;          // Double precision
1640  let Inst{7-6}   = opcod4;
1641  let Inst{4}     = opcod5;
1642
1643  let Predicates = [HasVFP2, HasDPVFP];
1644}
1645
1646// Double precision, unary, not-predicated
1647class ADuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1648           bit opcod5, dag oops, dag iops, InstrItinClass itin,
1649           string asm, list<dag> pattern>
1650  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone, VFPUnaryFrm, itin, asm, "", pattern> {
1651  // Instruction operands.
1652  bits<5> Dd;
1653  bits<5> Dm;
1654
1655  let Inst{31-28} = 0b1111;
1656
1657  // Encode instruction operands.
1658  let Inst{3-0}   = Dm{3-0};
1659  let Inst{5}     = Dm{4};
1660  let Inst{15-12} = Dd{3-0};
1661  let Inst{22}    = Dd{4};
1662
1663  let Inst{27-23} = opcod1;
1664  let Inst{21-20} = opcod2;
1665  let Inst{19-16} = opcod3;
1666  let Inst{11-9}  = 0b101;
1667  let Inst{8}     = 1;          // Double precision
1668  let Inst{7-6}   = opcod4;
1669  let Inst{4}     = opcod5;
1670}
1671
1672// Double precision, binary
1673class ADbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1674           dag iops, InstrItinClass itin, string opc, string asm,
1675           list<dag> pattern>
1676  : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1677  // Instruction operands.
1678  bits<5> Dd;
1679  bits<5> Dn;
1680  bits<5> Dm;
1681
1682  // Encode instruction operands.
1683  let Inst{3-0}   = Dm{3-0};
1684  let Inst{5}     = Dm{4};
1685  let Inst{19-16} = Dn{3-0};
1686  let Inst{7}     = Dn{4};
1687  let Inst{15-12} = Dd{3-0};
1688  let Inst{22}    = Dd{4};
1689
1690  let Inst{27-23} = opcod1;
1691  let Inst{21-20} = opcod2;
1692  let Inst{11-9}  = 0b101;
1693  let Inst{8}     = 1;          // Double precision
1694  let Inst{6}     = op6;
1695  let Inst{4}     = op4;
1696
1697  let Predicates = [HasVFP2, HasDPVFP];
1698}
1699
1700// FP, binary, not predicated
1701class ADbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
1702           InstrItinClass itin, string asm, list<dag> pattern>
1703  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone, VFPBinaryFrm, itin,
1704          asm, "", pattern>
1705{
1706  // Instruction operands.
1707  bits<5> Dd;
1708  bits<5> Dn;
1709  bits<5> Dm;
1710
1711  let Inst{31-28} = 0b1111;
1712
1713  // Encode instruction operands.
1714  let Inst{3-0}   = Dm{3-0};
1715  let Inst{5}     = Dm{4};
1716  let Inst{19-16} = Dn{3-0};
1717  let Inst{7}     = Dn{4};
1718  let Inst{15-12} = Dd{3-0};
1719  let Inst{22}    = Dd{4};
1720
1721  let Inst{27-23} = opcod1;
1722  let Inst{21-20} = opcod2;
1723  let Inst{11-9}  = 0b101;
1724  let Inst{8}     = 1; // double precision
1725  let Inst{6}     = opcod3;
1726  let Inst{4}     = 0;
1727
1728  let Predicates = [HasVFP2, HasDPVFP];
1729}
1730
1731// Single precision, unary, predicated
1732class ASuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1733           bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1734           string asm, list<dag> pattern>
1735  : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1736  // Instruction operands.
1737  bits<5> Sd;
1738  bits<5> Sm;
1739
1740  // Encode instruction operands.
1741  let Inst{3-0}   = Sm{4-1};
1742  let Inst{5}     = Sm{0};
1743  let Inst{15-12} = Sd{4-1};
1744  let Inst{22}    = Sd{0};
1745
1746  let Inst{27-23} = opcod1;
1747  let Inst{21-20} = opcod2;
1748  let Inst{19-16} = opcod3;
1749  let Inst{11-9}  = 0b101;
1750  let Inst{8}     = 0;          // Single precision
1751  let Inst{7-6}   = opcod4;
1752  let Inst{4}     = opcod5;
1753}
1754
1755// Single precision, unary, non-predicated
1756class ASuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1757             bit opcod5, dag oops, dag iops, InstrItinClass itin,
1758             string asm, list<dag> pattern>
1759  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
1760          VFPUnaryFrm, itin, asm, "", pattern> {
1761  // Instruction operands.
1762  bits<5> Sd;
1763  bits<5> Sm;
1764
1765  let Inst{31-28} = 0b1111;
1766
1767  // Encode instruction operands.
1768  let Inst{3-0}   = Sm{4-1};
1769  let Inst{5}     = Sm{0};
1770  let Inst{15-12} = Sd{4-1};
1771  let Inst{22}    = Sd{0};
1772
1773  let Inst{27-23} = opcod1;
1774  let Inst{21-20} = opcod2;
1775  let Inst{19-16} = opcod3;
1776  let Inst{11-9}  = 0b101;
1777  let Inst{8}     = 0;          // Single precision
1778  let Inst{7-6}   = opcod4;
1779  let Inst{4}     = opcod5;
1780}
1781
1782// Single precision unary, if no NEON. Same as ASuI except not available if
1783// NEON is enabled.
1784class ASuIn<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1785            bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1786            string asm, list<dag> pattern>
1787  : ASuI<opcod1, opcod2, opcod3, opcod4, opcod5, oops, iops, itin, opc, asm,
1788         pattern> {
1789  list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1790}
1791
1792// Single precision, binary
1793class ASbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
1794           InstrItinClass itin, string opc, string asm, list<dag> pattern>
1795  : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1796  // Instruction operands.
1797  bits<5> Sd;
1798  bits<5> Sn;
1799  bits<5> Sm;
1800
1801  // Encode instruction operands.
1802  let Inst{3-0}   = Sm{4-1};
1803  let Inst{5}     = Sm{0};
1804  let Inst{19-16} = Sn{4-1};
1805  let Inst{7}     = Sn{0};
1806  let Inst{15-12} = Sd{4-1};
1807  let Inst{22}    = Sd{0};
1808
1809  let Inst{27-23} = opcod1;
1810  let Inst{21-20} = opcod2;
1811  let Inst{11-9}  = 0b101;
1812  let Inst{8}     = 0;          // Single precision
1813  let Inst{6}     = op6;
1814  let Inst{4}     = op4;
1815}
1816
1817// Single precision, binary, not predicated
1818class ASbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
1819           InstrItinClass itin, string asm, list<dag> pattern>
1820  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
1821          VFPBinaryFrm, itin, asm, "", pattern>
1822{
1823  // Instruction operands.
1824  bits<5> Sd;
1825  bits<5> Sn;
1826  bits<5> Sm;
1827
1828  let Inst{31-28} = 0b1111;
1829
1830  // Encode instruction operands.
1831  let Inst{3-0}   = Sm{4-1};
1832  let Inst{5}     = Sm{0};
1833  let Inst{19-16} = Sn{4-1};
1834  let Inst{7}     = Sn{0};
1835  let Inst{15-12} = Sd{4-1};
1836  let Inst{22}    = Sd{0};
1837
1838  let Inst{27-23} = opcod1;
1839  let Inst{21-20} = opcod2;
1840  let Inst{11-9}  = 0b101;
1841  let Inst{8}     = 0; // Single precision
1842  let Inst{6}     = opcod3;
1843  let Inst{4}     = 0;
1844}
1845
1846// Single precision binary, if no NEON. Same as ASbI except not available if
1847// NEON is enabled.
1848class ASbIn<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1849            dag iops, InstrItinClass itin, string opc, string asm,
1850            list<dag> pattern>
1851  : ASbI<opcod1, opcod2, op6, op4, oops, iops, itin, opc, asm, pattern> {
1852  list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1853
1854  // Instruction operands.
1855  bits<5> Sd;
1856  bits<5> Sn;
1857  bits<5> Sm;
1858
1859  // Encode instruction operands.
1860  let Inst{3-0}   = Sm{4-1};
1861  let Inst{5}     = Sm{0};
1862  let Inst{19-16} = Sn{4-1};
1863  let Inst{7}     = Sn{0};
1864  let Inst{15-12} = Sd{4-1};
1865  let Inst{22}    = Sd{0};
1866}
1867
1868// Half precision, unary, predicated
1869class AHuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1870           bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1871           string asm, list<dag> pattern>
1872  : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1873  list<Predicate> Predicates = [HasFullFP16];
1874
1875  // Instruction operands.
1876  bits<5> Sd;
1877  bits<5> Sm;
1878
1879  // Encode instruction operands.
1880  let Inst{3-0}   = Sm{4-1};
1881  let Inst{5}     = Sm{0};
1882  let Inst{15-12} = Sd{4-1};
1883  let Inst{22}    = Sd{0};
1884
1885  let Inst{27-23} = opcod1;
1886  let Inst{21-20} = opcod2;
1887  let Inst{19-16} = opcod3;
1888  let Inst{11-8}  = 0b1001;   // Half precision
1889  let Inst{7-6}   = opcod4;
1890  let Inst{4}     = opcod5;
1891}
1892
1893// Half precision, unary, non-predicated
1894class AHuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1895             bit opcod5, dag oops, dag iops, InstrItinClass itin,
1896             string asm, list<dag> pattern>
1897  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
1898          VFPUnaryFrm, itin, asm, "", pattern> {
1899  list<Predicate> Predicates = [HasFullFP16];
1900
1901  // Instruction operands.
1902  bits<5> Sd;
1903  bits<5> Sm;
1904
1905  let Inst{31-28} = 0b1111;
1906
1907  // Encode instruction operands.
1908  let Inst{3-0}   = Sm{4-1};
1909  let Inst{5}     = Sm{0};
1910  let Inst{15-12} = Sd{4-1};
1911  let Inst{22}    = Sd{0};
1912
1913  let Inst{27-23} = opcod1;
1914  let Inst{21-20} = opcod2;
1915  let Inst{19-16} = opcod3;
1916  let Inst{11-8}  = 0b1001;   // Half precision
1917  let Inst{7-6}   = opcod4;
1918  let Inst{4}     = opcod5;
1919}
1920
1921// Half precision, binary
1922class AHbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
1923           InstrItinClass itin, string opc, string asm, list<dag> pattern>
1924  : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1925  list<Predicate> Predicates = [HasFullFP16];
1926
1927  // Instruction operands.
1928  bits<5> Sd;
1929  bits<5> Sn;
1930  bits<5> Sm;
1931
1932  // Encode instruction operands.
1933  let Inst{3-0}   = Sm{4-1};
1934  let Inst{5}     = Sm{0};
1935  let Inst{19-16} = Sn{4-1};
1936  let Inst{7}     = Sn{0};
1937  let Inst{15-12} = Sd{4-1};
1938  let Inst{22}    = Sd{0};
1939
1940  let Inst{27-23} = opcod1;
1941  let Inst{21-20} = opcod2;
1942  let Inst{11-8}  = 0b1001;   // Half precision
1943  let Inst{6}     = op6;
1944  let Inst{4}     = op4;
1945}
1946
1947// Half precision, binary, not predicated
1948class AHbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
1949           InstrItinClass itin, string asm, list<dag> pattern>
1950  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
1951          VFPBinaryFrm, itin, asm, "", pattern> {
1952  list<Predicate> Predicates = [HasFullFP16];
1953
1954  // Instruction operands.
1955  bits<5> Sd;
1956  bits<5> Sn;
1957  bits<5> Sm;
1958
1959  let Inst{31-28} = 0b1111;
1960
1961  // Encode instruction operands.
1962  let Inst{3-0}   = Sm{4-1};
1963  let Inst{5}     = Sm{0};
1964  let Inst{19-16} = Sn{4-1};
1965  let Inst{7}     = Sn{0};
1966  let Inst{15-12} = Sd{4-1};
1967  let Inst{22}    = Sd{0};
1968
1969  let Inst{27-23} = opcod1;
1970  let Inst{21-20} = opcod2;
1971  let Inst{11-8}  = 0b1001;   // Half precision
1972  let Inst{6}     = opcod3;
1973  let Inst{4}     = 0;
1974}
1975
1976// VFP conversion instructions
1977class AVConv1I<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
1978               dag oops, dag iops, InstrItinClass itin, string opc, string asm,
1979               list<dag> pattern>
1980  : VFPAI<oops, iops, VFPConv1Frm, itin, opc, asm, pattern> {
1981  let Inst{27-23} = opcod1;
1982  let Inst{21-20} = opcod2;
1983  let Inst{19-16} = opcod3;
1984  let Inst{11-8}  = opcod4;
1985  let Inst{6}     = 1;
1986  let Inst{4}     = 0;
1987}
1988
1989// VFP conversion between floating-point and fixed-point
1990class AVConv1XI<bits<5> op1, bits<2> op2, bits<4> op3, bits<4> op4, bit op5,
1991                dag oops, dag iops, InstrItinClass itin, string opc, string asm,
1992                list<dag> pattern>
1993  : AVConv1I<op1, op2, op3, op4, oops, iops, itin, opc, asm, pattern> {
1994  bits<5> fbits;
1995  // size (fixed-point number): sx == 0 ? 16 : 32
1996  let Inst{7} = op5; // sx
1997  let Inst{5} = fbits{0};
1998  let Inst{3-0} = fbits{4-1};
1999}
2000
2001// VFP conversion instructions, if no NEON
2002class AVConv1In<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
2003                dag oops, dag iops, InstrItinClass itin,
2004                string opc, string asm, list<dag> pattern>
2005  : AVConv1I<opcod1, opcod2, opcod3, opcod4, oops, iops, itin, opc, asm,
2006             pattern> {
2007  list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
2008}
2009
2010class AVConvXI<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops, Format f,
2011               InstrItinClass itin,
2012               string opc, string asm, list<dag> pattern>
2013  : VFPAI<oops, iops, f, itin, opc, asm, pattern> {
2014  let Inst{27-20} = opcod1;
2015  let Inst{11-8}  = opcod2;
2016  let Inst{4}     = 1;
2017}
2018
2019class AVConv2I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
2020               InstrItinClass itin, string opc, string asm, list<dag> pattern>
2021  : AVConvXI<opcod1, opcod2, oops, iops, VFPConv2Frm, itin, opc, asm, pattern>;
2022
2023class AVConv3I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
2024               InstrItinClass itin, string opc, string asm, list<dag> pattern>
2025  : AVConvXI<opcod1, opcod2, oops, iops, VFPConv3Frm, itin, opc, asm, pattern>;
2026
2027class AVConv4I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
2028               InstrItinClass itin, string opc, string asm, list<dag> pattern>
2029  : AVConvXI<opcod1, opcod2, oops, iops, VFPConv4Frm, itin, opc, asm, pattern>;
2030
2031class AVConv5I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
2032               InstrItinClass itin, string opc, string asm, list<dag> pattern>
2033  : AVConvXI<opcod1, opcod2, oops, iops, VFPConv5Frm, itin, opc, asm, pattern>;
2034
2035//===----------------------------------------------------------------------===//
2036
2037//===----------------------------------------------------------------------===//
2038// ARM NEON Instruction templates.
2039//
2040
2041class NeonI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
2042            InstrItinClass itin, string opc, string dt, string asm, string cstr,
2043            list<dag> pattern>
2044  : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
2045  let OutOperandList = oops;
2046  let InOperandList = !con(iops, (ins pred:$p));
2047  let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
2048  let Pattern = pattern;
2049  list<Predicate> Predicates = [HasNEON];
2050  let DecoderNamespace = "NEON";
2051}
2052
2053// Same as NeonI except it does not have a "data type" specifier.
2054class NeonXI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
2055             InstrItinClass itin, string opc, string asm, string cstr,
2056             list<dag> pattern>
2057  : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
2058  let OutOperandList = oops;
2059  let InOperandList = !con(iops, (ins pred:$p));
2060  let AsmString = !strconcat(opc, "${p}", "\t", asm);
2061  let Pattern = pattern;
2062  list<Predicate> Predicates = [HasNEON];
2063  let DecoderNamespace = "NEON";
2064}
2065
2066// Same as NeonI except it is not predicated
2067class NeonInp<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
2068            InstrItinClass itin, string opc, string dt, string asm, string cstr,
2069            list<dag> pattern>
2070  : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
2071  let OutOperandList = oops;
2072  let InOperandList = iops;
2073  let AsmString = !strconcat(opc, ".", dt, "\t", asm);
2074  let Pattern = pattern;
2075  list<Predicate> Predicates = [HasNEON];
2076  let DecoderNamespace = "NEON";
2077
2078  let Inst{31-28} = 0b1111;
2079}
2080
2081class NLdSt<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
2082            dag oops, dag iops, InstrItinClass itin,
2083            string opc, string dt, string asm, string cstr, list<dag> pattern>
2084  : NeonI<oops, iops, AddrMode6, IndexModeNone, NLdStFrm, itin, opc, dt, asm,
2085          cstr, pattern> {
2086  let Inst{31-24} = 0b11110100;
2087  let Inst{23}    = op23;
2088  let Inst{21-20} = op21_20;
2089  let Inst{11-8}  = op11_8;
2090  let Inst{7-4}   = op7_4;
2091
2092  let PostEncoderMethod = "NEONThumb2LoadStorePostEncoder";
2093  let DecoderNamespace = "NEONLoadStore";
2094
2095  bits<5> Vd;
2096  bits<6> Rn;
2097  bits<4> Rm;
2098
2099  let Inst{22}    = Vd{4};
2100  let Inst{15-12} = Vd{3-0};
2101  let Inst{19-16} = Rn{3-0};
2102  let Inst{3-0}   = Rm{3-0};
2103}
2104
2105class NLdStLn<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
2106            dag oops, dag iops, InstrItinClass itin,
2107            string opc, string dt, string asm, string cstr, list<dag> pattern>
2108  : NLdSt<op23, op21_20, op11_8, op7_4, oops, iops, itin, opc,
2109          dt, asm, cstr, pattern> {
2110  bits<3> lane;
2111}
2112
2113class PseudoNLdSt<dag oops, dag iops, InstrItinClass itin, string cstr>
2114  : InstARM<AddrMode6, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
2115            itin> {
2116  let OutOperandList = oops;
2117  let InOperandList = !con(iops, (ins pred:$p));
2118  list<Predicate> Predicates = [HasNEON];
2119}
2120
2121class PseudoNeonI<dag oops, dag iops, InstrItinClass itin, string cstr,
2122                  list<dag> pattern>
2123  : InstARM<AddrModeNone, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
2124            itin> {
2125  let OutOperandList = oops;
2126  let InOperandList = !con(iops, (ins pred:$p));
2127  let Pattern = pattern;
2128  list<Predicate> Predicates = [HasNEON];
2129}
2130
2131class NDataI<dag oops, dag iops, Format f, InstrItinClass itin,
2132             string opc, string dt, string asm, string cstr, list<dag> pattern>
2133  : NeonI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, dt, asm, cstr,
2134          pattern> {
2135  let Inst{31-25} = 0b1111001;
2136  let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
2137  let DecoderNamespace = "NEONData";
2138}
2139
2140class NDataXI<dag oops, dag iops, Format f, InstrItinClass itin,
2141              string opc, string asm, string cstr, list<dag> pattern>
2142  : NeonXI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, asm,
2143           cstr, pattern> {
2144  let Inst{31-25} = 0b1111001;
2145  let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
2146  let DecoderNamespace = "NEONData";
2147}
2148
2149// NEON "one register and a modified immediate" format.
2150class N1ModImm<bit op23, bits<3> op21_19, bits<4> op11_8, bit op7, bit op6,
2151               bit op5, bit op4,
2152               dag oops, dag iops, InstrItinClass itin,
2153               string opc, string dt, string asm, string cstr,
2154               list<dag> pattern>
2155  : NDataI<oops, iops, N1RegModImmFrm, itin, opc, dt, asm, cstr, pattern> {
2156  let Inst{23}    = op23;
2157  let Inst{21-19} = op21_19;
2158  let Inst{11-8}  = op11_8;
2159  let Inst{7}     = op7;
2160  let Inst{6}     = op6;
2161  let Inst{5}     = op5;
2162  let Inst{4}     = op4;
2163
2164  // Instruction operands.
2165  bits<5> Vd;
2166  bits<13> SIMM;
2167
2168  let Inst{15-12} = Vd{3-0};
2169  let Inst{22}    = Vd{4};
2170  let Inst{24}    = SIMM{7};
2171  let Inst{18-16} = SIMM{6-4};
2172  let Inst{3-0}   = SIMM{3-0};
2173  let DecoderMethod = "DecodeNEONModImmInstruction";
2174}
2175
2176// NEON 2 vector register format.
2177class N2V<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
2178          bits<5> op11_7, bit op6, bit op4,
2179          dag oops, dag iops, InstrItinClass itin,
2180          string opc, string dt, string asm, string cstr, list<dag> pattern>
2181  : NDataI<oops, iops, N2RegFrm, itin, opc, dt, asm, cstr, pattern> {
2182  let Inst{24-23} = op24_23;
2183  let Inst{21-20} = op21_20;
2184  let Inst{19-18} = op19_18;
2185  let Inst{17-16} = op17_16;
2186  let Inst{11-7}  = op11_7;
2187  let Inst{6}     = op6;
2188  let Inst{4}     = op4;
2189
2190  // Instruction operands.
2191  bits<5> Vd;
2192  bits<5> Vm;
2193
2194  let Inst{15-12} = Vd{3-0};
2195  let Inst{22}    = Vd{4};
2196  let Inst{3-0}   = Vm{3-0};
2197  let Inst{5}     = Vm{4};
2198}
2199
2200// Same as N2V but not predicated.
2201class N2Vnp<bits<2> op19_18, bits<2> op17_16, bits<3> op10_8, bit op7, bit op6,
2202            dag oops, dag iops, InstrItinClass itin, string OpcodeStr,
2203            string Dt, list<dag> pattern>
2204   : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N2RegFrm, itin,
2205             OpcodeStr, Dt, "$Vd, $Vm", "", pattern> {
2206  bits<5> Vd;
2207  bits<5> Vm;
2208
2209  // Encode instruction operands
2210  let Inst{22}    = Vd{4};
2211  let Inst{15-12} = Vd{3-0};
2212  let Inst{5}     = Vm{4};
2213  let Inst{3-0}   = Vm{3-0};
2214
2215  // Encode constant bits
2216  let Inst{27-23} = 0b00111;
2217  let Inst{21-20} = 0b11;
2218  let Inst{19-18} = op19_18;
2219  let Inst{17-16} = op17_16;
2220  let Inst{11} = 0;
2221  let Inst{10-8} = op10_8;
2222  let Inst{7} = op7;
2223  let Inst{6} = op6;
2224  let Inst{4} = 0;
2225
2226  let DecoderNamespace = "NEON";
2227}
2228
2229// Same as N2V except it doesn't have a datatype suffix.
2230class N2VX<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
2231           bits<5> op11_7, bit op6, bit op4,
2232           dag oops, dag iops, InstrItinClass itin,
2233           string opc, string asm, string cstr, list<dag> pattern>
2234  : NDataXI<oops, iops, N2RegFrm, itin, opc, asm, cstr, pattern> {
2235  let Inst{24-23} = op24_23;
2236  let Inst{21-20} = op21_20;
2237  let Inst{19-18} = op19_18;
2238  let Inst{17-16} = op17_16;
2239  let Inst{11-7}  = op11_7;
2240  let Inst{6}     = op6;
2241  let Inst{4}     = op4;
2242
2243  // Instruction operands.
2244  bits<5> Vd;
2245  bits<5> Vm;
2246
2247  let Inst{15-12} = Vd{3-0};
2248  let Inst{22}    = Vd{4};
2249  let Inst{3-0}   = Vm{3-0};
2250  let Inst{5}     = Vm{4};
2251}
2252
2253// NEON 2 vector register with immediate.
2254class N2VImm<bit op24, bit op23, bits<4> op11_8, bit op7, bit op6, bit op4,
2255             dag oops, dag iops, Format f, InstrItinClass itin,
2256             string opc, string dt, string asm, string cstr, list<dag> pattern>
2257  : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2258  let Inst{24}   = op24;
2259  let Inst{23}   = op23;
2260  let Inst{11-8} = op11_8;
2261  let Inst{7}    = op7;
2262  let Inst{6}    = op6;
2263  let Inst{4}    = op4;
2264
2265  // Instruction operands.
2266  bits<5> Vd;
2267  bits<5> Vm;
2268  bits<6> SIMM;
2269
2270  let Inst{15-12} = Vd{3-0};
2271  let Inst{22}    = Vd{4};
2272  let Inst{3-0}   = Vm{3-0};
2273  let Inst{5}     = Vm{4};
2274  let Inst{21-16} = SIMM{5-0};
2275}
2276
2277// NEON 3 vector register format.
2278
2279class N3VCommon<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2280                bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2281                string opc, string dt, string asm, string cstr,
2282                list<dag> pattern>
2283  : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2284  let Inst{24}    = op24;
2285  let Inst{23}    = op23;
2286  let Inst{21-20} = op21_20;
2287  let Inst{11-8}  = op11_8;
2288  let Inst{6}     = op6;
2289  let Inst{4}     = op4;
2290}
2291
2292class N3V<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6, bit op4,
2293          dag oops, dag iops, Format f, InstrItinClass itin,
2294          string opc, string dt, string asm, string cstr, list<dag> pattern>
2295  : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2296              oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2297  // Instruction operands.
2298  bits<5> Vd;
2299  bits<5> Vn;
2300  bits<5> Vm;
2301
2302  let Inst{15-12} = Vd{3-0};
2303  let Inst{22}    = Vd{4};
2304  let Inst{19-16} = Vn{3-0};
2305  let Inst{7}     = Vn{4};
2306  let Inst{3-0}   = Vm{3-0};
2307  let Inst{5}     = Vm{4};
2308}
2309
2310class N3Vnp<bits<5> op27_23, bits<2> op21_20, bits<4> op11_8, bit op6,
2311                bit op4, dag oops, dag iops,Format f, InstrItinClass itin,
2312                string OpcodeStr, string Dt, list<dag> pattern>
2313  : NeonInp<oops, iops, AddrModeNone, IndexModeNone, f, itin, OpcodeStr,
2314            Dt, "$Vd, $Vn, $Vm", "", pattern> {
2315  bits<5> Vd;
2316  bits<5> Vn;
2317  bits<5> Vm;
2318
2319  // Encode instruction operands
2320  let Inst{22} = Vd{4};
2321  let Inst{15-12} = Vd{3-0};
2322  let Inst{19-16} = Vn{3-0};
2323  let Inst{7} = Vn{4};
2324  let Inst{5} = Vm{4};
2325  let Inst{3-0} = Vm{3-0};
2326
2327  // Encode constant bits
2328  let Inst{27-23} = op27_23;
2329  let Inst{21-20} = op21_20;
2330  let Inst{11-8}  = op11_8;
2331  let Inst{6}     = op6;
2332  let Inst{4}     = op4;
2333}
2334
2335class N3VLane32<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2336                bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2337                string opc, string dt, string asm, string cstr,
2338                list<dag> pattern>
2339  : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2340              oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2341
2342  // Instruction operands.
2343  bits<5> Vd;
2344  bits<5> Vn;
2345  bits<5> Vm;
2346  bit lane;
2347
2348  let Inst{15-12} = Vd{3-0};
2349  let Inst{22}    = Vd{4};
2350  let Inst{19-16} = Vn{3-0};
2351  let Inst{7}     = Vn{4};
2352  let Inst{3-0}   = Vm{3-0};
2353  let Inst{5}     = lane;
2354}
2355
2356class N3VLane16<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2357                bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2358                string opc, string dt, string asm, string cstr,
2359                list<dag> pattern>
2360  : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2361              oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2362
2363  // Instruction operands.
2364  bits<5> Vd;
2365  bits<5> Vn;
2366  bits<5> Vm;
2367  bits<2> lane;
2368
2369  let Inst{15-12} = Vd{3-0};
2370  let Inst{22}    = Vd{4};
2371  let Inst{19-16} = Vn{3-0};
2372  let Inst{7}     = Vn{4};
2373  let Inst{2-0}   = Vm{2-0};
2374  let Inst{5}     = lane{1};
2375  let Inst{3}     = lane{0};
2376}
2377
2378// Same as N3V except it doesn't have a data type suffix.
2379class N3VX<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2380           bit op4,
2381           dag oops, dag iops, Format f, InstrItinClass itin,
2382           string opc, string asm, string cstr, list<dag> pattern>
2383  : NDataXI<oops, iops, f, itin, opc, asm, cstr, pattern> {
2384  let Inst{24}    = op24;
2385  let Inst{23}    = op23;
2386  let Inst{21-20} = op21_20;
2387  let Inst{11-8}  = op11_8;
2388  let Inst{6}     = op6;
2389  let Inst{4}     = op4;
2390
2391  // Instruction operands.
2392  bits<5> Vd;
2393  bits<5> Vn;
2394  bits<5> Vm;
2395
2396  let Inst{15-12} = Vd{3-0};
2397  let Inst{22}    = Vd{4};
2398  let Inst{19-16} = Vn{3-0};
2399  let Inst{7}     = Vn{4};
2400  let Inst{3-0}   = Vm{3-0};
2401  let Inst{5}     = Vm{4};
2402}
2403
2404// NEON VMOVs between scalar and core registers.
2405class NVLaneOp<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2406               dag oops, dag iops, Format f, InstrItinClass itin,
2407               string opc, string dt, string asm, list<dag> pattern>
2408  : InstARM<AddrModeNone, 4, IndexModeNone, f, NeonDomain,
2409            "", itin> {
2410  let Inst{27-20} = opcod1;
2411  let Inst{11-8}  = opcod2;
2412  let Inst{6-5}   = opcod3;
2413  let Inst{4}     = 1;
2414  // A8.6.303, A8.6.328, A8.6.329
2415  let Inst{3-0}   = 0b0000;
2416
2417  let OutOperandList = oops;
2418  let InOperandList = !con(iops, (ins pred:$p));
2419  let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
2420  let Pattern = pattern;
2421  list<Predicate> Predicates = [HasNEON];
2422
2423  let PostEncoderMethod = "NEONThumb2DupPostEncoder";
2424  let DecoderNamespace = "NEONDup";
2425
2426  bits<5> V;
2427  bits<4> R;
2428  bits<4> p;
2429  bits<4> lane;
2430
2431  let Inst{31-28} = p{3-0};
2432  let Inst{7}     = V{4};
2433  let Inst{19-16} = V{3-0};
2434  let Inst{15-12} = R{3-0};
2435}
2436class NVGetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2437                dag oops, dag iops, InstrItinClass itin,
2438                string opc, string dt, string asm, list<dag> pattern>
2439  : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NGetLnFrm, itin,
2440             opc, dt, asm, pattern>;
2441class NVSetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2442                dag oops, dag iops, InstrItinClass itin,
2443                string opc, string dt, string asm, list<dag> pattern>
2444  : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NSetLnFrm, itin,
2445             opc, dt, asm, pattern>;
2446class NVDup<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2447            dag oops, dag iops, InstrItinClass itin,
2448            string opc, string dt, string asm, list<dag> pattern>
2449  : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NDupFrm, itin,
2450             opc, dt, asm, pattern>;
2451
2452// Vector Duplicate Lane (from scalar to all elements)
2453class NVDupLane<bits<4> op19_16, bit op6, dag oops, dag iops,
2454                InstrItinClass itin, string opc, string dt, string asm,
2455                list<dag> pattern>
2456  : NDataI<oops, iops, NVDupLnFrm, itin, opc, dt, asm, "", pattern> {
2457  let Inst{24-23} = 0b11;
2458  let Inst{21-20} = 0b11;
2459  let Inst{19-16} = op19_16;
2460  let Inst{11-7}  = 0b11000;
2461  let Inst{6}     = op6;
2462  let Inst{4}     = 0;
2463
2464  bits<5> Vd;
2465  bits<5> Vm;
2466
2467  let Inst{22}     = Vd{4};
2468  let Inst{15-12} = Vd{3-0};
2469  let Inst{5}     = Vm{4};
2470  let Inst{3-0} = Vm{3-0};
2471}
2472
2473// NEONFPPat - Same as Pat<>, but requires that the compiler be using NEON
2474// for single-precision FP.
2475class NEONFPPat<dag pattern, dag result> : Pat<pattern, result> {
2476  list<Predicate> Predicates = [HasNEON,UseNEONForFP];
2477}
2478
2479// VFP/NEON Instruction aliases for type suffices.
2480// Note: When EmitPriority == 1, the alias will be used for printing
2481class VFPDataTypeInstAlias<string opc, string dt, string asm, dag Result, bit EmitPriority = 0> :
2482  InstAlias<!strconcat(opc, dt, "\t", asm), Result, EmitPriority>, Requires<[HasVFP2]>;
2483
2484// Note: When EmitPriority == 1, the alias will be used for printing
2485multiclass VFPDTAnyInstAlias<string opc, string asm, dag Result, bit EmitPriority = 0> {
2486  def : VFPDataTypeInstAlias<opc, ".8", asm, Result, EmitPriority>;
2487  def : VFPDataTypeInstAlias<opc, ".16", asm, Result, EmitPriority>;
2488  def : VFPDataTypeInstAlias<opc, ".32", asm, Result, EmitPriority>;
2489  def : VFPDataTypeInstAlias<opc, ".64", asm, Result, EmitPriority>;
2490}
2491
2492// Note: When EmitPriority == 1, the alias will be used for printing
2493multiclass NEONDTAnyInstAlias<string opc, string asm, dag Result, bit EmitPriority = 0> {
2494  let Predicates = [HasNEON] in {
2495  def : VFPDataTypeInstAlias<opc, ".8", asm, Result, EmitPriority>;
2496  def : VFPDataTypeInstAlias<opc, ".16", asm, Result, EmitPriority>;
2497  def : VFPDataTypeInstAlias<opc, ".32", asm, Result, EmitPriority>;
2498  def : VFPDataTypeInstAlias<opc, ".64", asm, Result, EmitPriority>;
2499}
2500}
2501
2502// The same alias classes using AsmPseudo instead, for the more complex
2503// stuff in NEON that InstAlias can't quite handle.
2504// Note that we can't use anonymous defm references here like we can
2505// above, as we care about the ultimate instruction enum names generated, unlike
2506// for instalias defs.
2507class NEONDataTypeAsmPseudoInst<string opc, string dt, string asm, dag iops> :
2508  AsmPseudoInst<!strconcat(opc, dt, "\t", asm), iops>, Requires<[HasNEON]>;
2509
2510// Data type suffix token aliases. Implements Table A7-3 in the ARM ARM.
2511def : TokenAlias<".s8", ".i8">;
2512def : TokenAlias<".u8", ".i8">;
2513def : TokenAlias<".s16", ".i16">;
2514def : TokenAlias<".u16", ".i16">;
2515def : TokenAlias<".s32", ".i32">;
2516def : TokenAlias<".u32", ".i32">;
2517def : TokenAlias<".s64", ".i64">;
2518def : TokenAlias<".u64", ".i64">;
2519
2520def : TokenAlias<".i8", ".8">;
2521def : TokenAlias<".i16", ".16">;
2522def : TokenAlias<".i32", ".32">;
2523def : TokenAlias<".i64", ".64">;
2524
2525def : TokenAlias<".p8", ".8">;
2526def : TokenAlias<".p16", ".16">;
2527
2528def : TokenAlias<".f32", ".32">;
2529def : TokenAlias<".f64", ".64">;
2530def : TokenAlias<".f", ".f32">;
2531def : TokenAlias<".d", ".f64">;
2532