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