[C++] Use 'nullptr'. Target edition.
[oota-llvm.git] / lib / Target / ARM64 / InstPrinter / ARM64InstPrinter.cpp
1 //===-- ARM64InstPrinter.cpp - Convert ARM64 MCInst to assembly syntax ----===//
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 // This class prints an ARM64 MCInst to a .s file.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARM64InstPrinter.h"
15 #include "MCTargetDesc/ARM64AddressingModes.h"
16 #include "Utils/ARM64BaseInfo.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCExpr.h"
21 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/Support/Format.h"
23 #include "llvm/Support/raw_ostream.h"
24 using namespace llvm;
25
26 #define DEBUG_TYPE "asm-printer"
27
28 #define GET_INSTRUCTION_NAME
29 #define PRINT_ALIAS_INSTR
30 #include "ARM64GenAsmWriter.inc"
31 #define GET_INSTRUCTION_NAME
32 #define PRINT_ALIAS_INSTR
33 #include "ARM64GenAsmWriter1.inc"
34
35 ARM64InstPrinter::ARM64InstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
36                                    const MCRegisterInfo &MRI,
37                                    const MCSubtargetInfo &STI)
38     : MCInstPrinter(MAI, MII, MRI) {
39   // Initialize the set of available features.
40   setAvailableFeatures(STI.getFeatureBits());
41 }
42
43 ARM64AppleInstPrinter::ARM64AppleInstPrinter(const MCAsmInfo &MAI,
44                                              const MCInstrInfo &MII,
45                                              const MCRegisterInfo &MRI,
46                                              const MCSubtargetInfo &STI)
47     : ARM64InstPrinter(MAI, MII, MRI, STI) {}
48
49 void ARM64InstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
50   // This is for .cfi directives.
51   OS << getRegisterName(RegNo);
52 }
53
54 void ARM64InstPrinter::printInst(const MCInst *MI, raw_ostream &O,
55                                  StringRef Annot) {
56   // Check for special encodings and print the canonical alias instead.
57
58   unsigned Opcode = MI->getOpcode();
59
60   if (Opcode == ARM64::SYSxt)
61     if (printSysAlias(MI, O)) {
62       printAnnotation(O, Annot);
63       return;
64     }
65
66   // TBZ/TBNZ should print the register operand as a Wreg if the bit
67   // number is < 32.
68   if ((Opcode == ARM64::TBNZ || Opcode == ARM64::TBZ) &&
69       MI->getOperand(1).getImm() < 32) {
70     MCInst newMI = *MI;
71     unsigned Reg = MI->getOperand(0).getReg();
72     newMI.getOperand(0).setReg(getWRegFromXReg(Reg));
73     printInstruction(&newMI, O);
74     printAnnotation(O, Annot);
75     return;
76   }
77
78   // SBFM/UBFM should print to a nicer aliased form if possible.
79   if (Opcode == ARM64::SBFMXri || Opcode == ARM64::SBFMWri ||
80       Opcode == ARM64::UBFMXri || Opcode == ARM64::UBFMWri) {
81     const MCOperand &Op0 = MI->getOperand(0);
82     const MCOperand &Op1 = MI->getOperand(1);
83     const MCOperand &Op2 = MI->getOperand(2);
84     const MCOperand &Op3 = MI->getOperand(3);
85
86     if (Op2.isImm() && Op2.getImm() == 0 && Op3.isImm()) {
87       bool IsSigned = (Opcode == ARM64::SBFMXri || Opcode == ARM64::SBFMWri);
88       const char *AsmMnemonic = nullptr;
89
90       switch (Op3.getImm()) {
91       default:
92         break;
93       case 7:
94         AsmMnemonic = IsSigned ? "sxtb" : "uxtb";
95         break;
96       case 15:
97         AsmMnemonic = IsSigned ? "sxth" : "uxth";
98         break;
99       case 31:
100         // *xtw is only valid for 64-bit operations.
101         if (Opcode == ARM64::SBFMXri || Opcode == ARM64::UBFMXri)
102           AsmMnemonic = IsSigned ? "sxtw" : "uxtw";
103         break;
104       }
105
106       if (AsmMnemonic) {
107         O << '\t' << AsmMnemonic << '\t' << getRegisterName(Op0.getReg())
108           << ", " << getRegisterName(getWRegFromXReg(Op1.getReg()));
109         printAnnotation(O, Annot);
110         return;
111       }
112     }
113
114     // All immediate shifts are aliases, implemented using the Bitfield
115     // instruction. In all cases the immediate shift amount shift must be in
116     // the range 0 to (reg.size -1).
117     if (Op2.isImm() && Op3.isImm()) {
118       const char *AsmMnemonic = nullptr;
119       int shift = 0;
120       int64_t immr = Op2.getImm();
121       int64_t imms = Op3.getImm();
122       if (Opcode == ARM64::UBFMWri && imms != 0x1F && ((imms + 1) == immr)) {
123         AsmMnemonic = "lsl";
124         shift = 31 - imms;
125       } else if (Opcode == ARM64::UBFMXri && imms != 0x3f &&
126                  ((imms + 1 == immr))) {
127         AsmMnemonic = "lsl";
128         shift = 63 - imms;
129       } else if (Opcode == ARM64::UBFMWri && imms == 0x1f) {
130         AsmMnemonic = "lsr";
131         shift = immr;
132       } else if (Opcode == ARM64::UBFMXri && imms == 0x3f) {
133         AsmMnemonic = "lsr";
134         shift = immr;
135       } else if (Opcode == ARM64::SBFMWri && imms == 0x1f) {
136         AsmMnemonic = "asr";
137         shift = immr;
138       } else if (Opcode == ARM64::SBFMXri && imms == 0x3f) {
139         AsmMnemonic = "asr";
140         shift = immr;
141       }
142       if (AsmMnemonic) {
143         O << '\t' << AsmMnemonic << '\t' << getRegisterName(Op0.getReg())
144           << ", " << getRegisterName(Op1.getReg()) << ", #" << shift;
145         printAnnotation(O, Annot);
146         return;
147       }
148     }
149   }
150
151   // Symbolic operands for MOVZ, MOVN and MOVK already imply a shift
152   // (e.g. :gottprel_g1: is always going to be "lsl #16") so it should not be
153   // printed.
154   if ((Opcode == ARM64::MOVZXi || Opcode == ARM64::MOVZWi ||
155        Opcode == ARM64::MOVNXi || Opcode == ARM64::MOVNWi) &&
156       MI->getOperand(1).isExpr()) {
157     if (Opcode == ARM64::MOVZXi || Opcode == ARM64::MOVZWi)
158       O << "\tmovz\t";
159     else
160       O << "\tmovn\t";
161
162     O << getRegisterName(MI->getOperand(0).getReg()) << ", #"
163       << *MI->getOperand(1).getExpr();
164     return;
165   }
166
167   if ((Opcode == ARM64::MOVKXi || Opcode == ARM64::MOVKWi) &&
168       MI->getOperand(2).isExpr()) {
169     O << "\tmovk\t" << getRegisterName(MI->getOperand(0).getReg()) << ", #"
170       << *MI->getOperand(2).getExpr();
171     return;
172   }
173
174   // ANDS WZR, Wn, #imm ==> TST Wn, #imm
175   // ANDS XZR, Xn, #imm ==> TST Xn, #imm
176   if (Opcode == ARM64::ANDSWri && MI->getOperand(0).getReg() == ARM64::WZR) {
177     O << "\ttst\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
178     printLogicalImm32(MI, 2, O);
179     return;
180   }
181   if (Opcode == ARM64::ANDSXri && MI->getOperand(0).getReg() == ARM64::XZR) {
182     O << "\ttst\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
183     printLogicalImm64(MI, 2, O);
184     return;
185   }
186   // ANDS WZR, Wn, Wm{, lshift #imm} ==> TST Wn{, lshift #imm}
187   // ANDS XZR, Xn, Xm{, lshift #imm} ==> TST Xn{, lshift #imm}
188   if ((Opcode == ARM64::ANDSWrs && MI->getOperand(0).getReg() == ARM64::WZR) ||
189       (Opcode == ARM64::ANDSXrs && MI->getOperand(0).getReg() == ARM64::XZR)) {
190     O << "\ttst\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
191     printShiftedRegister(MI, 2, O);
192     return;
193   }
194
195   // ORN Wn, WZR, Wm{, lshift #imm} ==> MVN Wn, Wm{, lshift #imm}
196   // ORN Xn, XZR, Xm{, lshift #imm} ==> MVN Xn, Xm{, lshift #imm}
197   if ((Opcode == ARM64::ORNWrs && MI->getOperand(1).getReg() == ARM64::WZR) ||
198       (Opcode == ARM64::ORNXrs && MI->getOperand(1).getReg() == ARM64::XZR)) {
199     O << "\tmvn\t" << getRegisterName(MI->getOperand(0).getReg()) << ", ";
200     printShiftedRegister(MI, 2, O);
201     return;
202   }
203   // SUBS WZR, Wn, #imm ==> CMP Wn, #imm
204   // SUBS XZR, Xn, #imm ==> CMP Xn, #imm
205   if ((Opcode == ARM64::SUBSWri && MI->getOperand(0).getReg() == ARM64::WZR) ||
206       (Opcode == ARM64::SUBSXri && MI->getOperand(0).getReg() == ARM64::XZR)) {
207     O << "\tcmp\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
208     printAddSubImm(MI, 2, O);
209     return;
210   }
211   // SUBS WZR, Wn, Wm{, lshift #imm} ==> CMP Wn, Wm{, lshift #imm}
212   // SUBS XZR, Xn, Xm{, lshift #imm} ==> CMP Xn, Xm{, lshift #imm}
213   if ((Opcode == ARM64::SUBSWrs && MI->getOperand(0).getReg() == ARM64::WZR) ||
214       (Opcode == ARM64::SUBSXrs && MI->getOperand(0).getReg() == ARM64::XZR)) {
215     O << "\tcmp\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
216     printShiftedRegister(MI, 2, O);
217     return;
218   }
219   // SUBS XZR, Xn, Wm, uxtb #imm ==> CMP Xn, uxtb #imm
220   // SUBS WZR, Wn, Xm, uxtb #imm ==> CMP Wn, uxtb #imm
221   if ((Opcode == ARM64::SUBSXrx && MI->getOperand(0).getReg() == ARM64::XZR) ||
222       (Opcode == ARM64::SUBSWrx && MI->getOperand(0).getReg() == ARM64::WZR)) {
223     O << "\tcmp\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
224     printExtendedRegister(MI, 2, O);
225     return;
226   }
227   // SUBS XZR, Xn, Xm, uxtx #imm ==> CMP Xn, uxtb #imm
228   if (Opcode == ARM64::SUBSXrx64 && MI->getOperand(0).getReg() == ARM64::XZR) {
229     O << "\tcmp\t" << getRegisterName(MI->getOperand(1).getReg()) << ", "
230       << getRegisterName(MI->getOperand(2).getReg());
231     printExtend(MI, 3, O);
232     return;
233   }
234
235   // ADDS WZR, Wn, #imm ==> CMN Wn, #imm
236   // ADDS XZR, Xn, #imm ==> CMN Xn, #imm
237   if ((Opcode == ARM64::ADDSWri && MI->getOperand(0).getReg() == ARM64::WZR) ||
238       (Opcode == ARM64::ADDSXri && MI->getOperand(0).getReg() == ARM64::XZR)) {
239     O << "\tcmn\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
240     printAddSubImm(MI, 2, O);
241     return;
242   }
243   // ADDS WZR, Wn, Wm{, lshift #imm} ==> CMN Wn, Wm{, lshift #imm}
244   // ADDS XZR, Xn, Xm{, lshift #imm} ==> CMN Xn, Xm{, lshift #imm}
245   if ((Opcode == ARM64::ADDSWrs && MI->getOperand(0).getReg() == ARM64::WZR) ||
246       (Opcode == ARM64::ADDSXrs && MI->getOperand(0).getReg() == ARM64::XZR)) {
247     O << "\tcmn\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
248     printShiftedRegister(MI, 2, O);
249     return;
250   }
251   // ADDS XZR, Xn, Wm, uxtb #imm ==> CMN Xn, uxtb #imm
252   if (Opcode == ARM64::ADDSXrx && MI->getOperand(0).getReg() == ARM64::XZR) {
253     O << "\tcmn\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
254     printExtendedRegister(MI, 2, O);
255     return;
256   }
257   // ADDS XZR, Xn, Xm, uxtx #imm ==> CMN Xn, uxtb #imm
258   if (Opcode == ARM64::ADDSXrx64 && MI->getOperand(0).getReg() == ARM64::XZR) {
259     O << "\tcmn\t" << getRegisterName(MI->getOperand(1).getReg()) << ", "
260       << getRegisterName(MI->getOperand(2).getReg());
261     printExtend(MI, 3, O);
262     return;
263   }
264   // ADD WSP, Wn, #0 ==> MOV WSP, Wn
265   if (Opcode == ARM64::ADDWri && (MI->getOperand(0).getReg() == ARM64::WSP ||
266                                   MI->getOperand(1).getReg() == ARM64::WSP) &&
267       MI->getOperand(2).getImm() == 0 &&
268       ARM64_AM::getShiftValue(MI->getOperand(3).getImm()) == 0) {
269     O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg())
270       << ", " << getRegisterName(MI->getOperand(1).getReg());
271     return;
272   }
273   // ADD XSP, Wn, #0 ==> MOV XSP, Wn
274   if (Opcode == ARM64::ADDXri && (MI->getOperand(0).getReg() == ARM64::SP ||
275                                   MI->getOperand(1).getReg() == ARM64::SP) &&
276       MI->getOperand(2).getImm() == 0 &&
277       ARM64_AM::getShiftValue(MI->getOperand(3).getImm()) == 0) {
278     O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg())
279       << ", " << getRegisterName(MI->getOperand(1).getReg());
280     return;
281   }
282   // ORR Wn, WZR, Wm ==> MOV Wn, Wm
283   if (Opcode == ARM64::ORRWrs && MI->getOperand(1).getReg() == ARM64::WZR &&
284       MI->getOperand(3).getImm() == 0) {
285     O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg())
286       << ", " << getRegisterName(MI->getOperand(2).getReg());
287     return;
288   }
289   // ORR Xn, XZR, Xm ==> MOV Xn, Xm
290   if (Opcode == ARM64::ORRXrs && MI->getOperand(1).getReg() == ARM64::XZR &&
291       MI->getOperand(3).getImm() == 0) {
292     O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg())
293       << ", " << getRegisterName(MI->getOperand(2).getReg());
294     return;
295   }
296
297   if (!printAliasInstr(MI, O))
298     printInstruction(MI, O);
299
300   printAnnotation(O, Annot);
301 }
302
303 static bool isTblTbxInstruction(unsigned Opcode, StringRef &Layout,
304                                 bool &IsTbx) {
305   switch (Opcode) {
306   case ARM64::TBXv8i8One:
307   case ARM64::TBXv8i8Two:
308   case ARM64::TBXv8i8Three:
309   case ARM64::TBXv8i8Four:
310     IsTbx = true;
311     Layout = ".8b";
312     return true;
313   case ARM64::TBLv8i8One:
314   case ARM64::TBLv8i8Two:
315   case ARM64::TBLv8i8Three:
316   case ARM64::TBLv8i8Four:
317     IsTbx = false;
318     Layout = ".8b";
319     return true;
320   case ARM64::TBXv16i8One:
321   case ARM64::TBXv16i8Two:
322   case ARM64::TBXv16i8Three:
323   case ARM64::TBXv16i8Four:
324     IsTbx = true;
325     Layout = ".16b";
326     return true;
327   case ARM64::TBLv16i8One:
328   case ARM64::TBLv16i8Two:
329   case ARM64::TBLv16i8Three:
330   case ARM64::TBLv16i8Four:
331     IsTbx = false;
332     Layout = ".16b";
333     return true;
334   default:
335     return false;
336   }
337 }
338
339 struct LdStNInstrDesc {
340   unsigned Opcode;
341   const char *Mnemonic;
342   const char *Layout;
343   int LaneOperand;
344   int NaturalOffset;
345 };
346
347 static LdStNInstrDesc LdStNInstInfo[] = {
348   { ARM64::LD1i8,             "ld1",  ".b",     2, 0  },
349   { ARM64::LD1i16,            "ld1",  ".h",     2, 0  },
350   { ARM64::LD1i32,            "ld1",  ".s",     2, 0  },
351   { ARM64::LD1i64,            "ld1",  ".d",     2, 0  },
352   { ARM64::LD1i8_POST,        "ld1",  ".b",     2, 1  },
353   { ARM64::LD1i16_POST,       "ld1",  ".h",     2, 2  },
354   { ARM64::LD1i32_POST,       "ld1",  ".s",     2, 4  },
355   { ARM64::LD1i64_POST,       "ld1",  ".d",     2, 8  },
356   { ARM64::LD1Rv16b,          "ld1r", ".16b",   0, 0  },
357   { ARM64::LD1Rv8h,           "ld1r", ".8h",    0, 0  },
358   { ARM64::LD1Rv4s,           "ld1r", ".4s",    0, 0  },
359   { ARM64::LD1Rv2d,           "ld1r", ".2d",    0, 0  },
360   { ARM64::LD1Rv8b,           "ld1r", ".8b",    0, 0  },
361   { ARM64::LD1Rv4h,           "ld1r", ".4h",    0, 0  },
362   { ARM64::LD1Rv2s,           "ld1r", ".2s",    0, 0  },
363   { ARM64::LD1Rv1d,           "ld1r", ".1d",    0, 0  },
364   { ARM64::LD1Rv16b_POST,     "ld1r", ".16b",   0, 1  },
365   { ARM64::LD1Rv8h_POST,      "ld1r", ".8h",    0, 2  },
366   { ARM64::LD1Rv4s_POST,      "ld1r", ".4s",    0, 4  },
367   { ARM64::LD1Rv2d_POST,      "ld1r", ".2d",    0, 8  },
368   { ARM64::LD1Rv8b_POST,      "ld1r", ".8b",    0, 1  },
369   { ARM64::LD1Rv4h_POST,      "ld1r", ".4h",    0, 2  },
370   { ARM64::LD1Rv2s_POST,      "ld1r", ".2s",    0, 4  },
371   { ARM64::LD1Rv1d_POST,      "ld1r", ".1d",    0, 8  },
372   { ARM64::LD1Onev16b,        "ld1",  ".16b",   0, 0  },
373   { ARM64::LD1Onev8h,         "ld1",  ".8h",    0, 0  },
374   { ARM64::LD1Onev4s,         "ld1",  ".4s",    0, 0  },
375   { ARM64::LD1Onev2d,         "ld1",  ".2d",    0, 0  },
376   { ARM64::LD1Onev8b,         "ld1",  ".8b",    0, 0  },
377   { ARM64::LD1Onev4h,         "ld1",  ".4h",    0, 0  },
378   { ARM64::LD1Onev2s,         "ld1",  ".2s",    0, 0  },
379   { ARM64::LD1Onev1d,         "ld1",  ".1d",    0, 0  },
380   { ARM64::LD1Onev16b_POST,   "ld1",  ".16b",   0, 16 },
381   { ARM64::LD1Onev8h_POST,    "ld1",  ".8h",    0, 16 },
382   { ARM64::LD1Onev4s_POST,    "ld1",  ".4s",    0, 16 },
383   { ARM64::LD1Onev2d_POST,    "ld1",  ".2d",    0, 16 },
384   { ARM64::LD1Onev8b_POST,    "ld1",  ".8b",    0, 8  },
385   { ARM64::LD1Onev4h_POST,    "ld1",  ".4h",    0, 8  },
386   { ARM64::LD1Onev2s_POST,    "ld1",  ".2s",    0, 8  },
387   { ARM64::LD1Onev1d_POST,    "ld1",  ".1d",    0, 8  },
388   { ARM64::LD1Twov16b,        "ld1",  ".16b",   0, 0  },
389   { ARM64::LD1Twov8h,         "ld1",  ".8h",    0, 0  },
390   { ARM64::LD1Twov4s,         "ld1",  ".4s",    0, 0  },
391   { ARM64::LD1Twov2d,         "ld1",  ".2d",    0, 0  },
392   { ARM64::LD1Twov8b,         "ld1",  ".8b",    0, 0  },
393   { ARM64::LD1Twov4h,         "ld1",  ".4h",    0, 0  },
394   { ARM64::LD1Twov2s,         "ld1",  ".2s",    0, 0  },
395   { ARM64::LD1Twov1d,         "ld1",  ".1d",    0, 0  },
396   { ARM64::LD1Twov16b_POST,   "ld1",  ".16b",   0, 32 },
397   { ARM64::LD1Twov8h_POST,    "ld1",  ".8h",    0, 32 },
398   { ARM64::LD1Twov4s_POST,    "ld1",  ".4s",    0, 32 },
399   { ARM64::LD1Twov2d_POST,    "ld1",  ".2d",    0, 32 },
400   { ARM64::LD1Twov8b_POST,    "ld1",  ".8b",    0, 16 },
401   { ARM64::LD1Twov4h_POST,    "ld1",  ".4h",    0, 16 },
402   { ARM64::LD1Twov2s_POST,    "ld1",  ".2s",    0, 16 },
403   { ARM64::LD1Twov1d_POST,    "ld1",  ".1d",    0, 16 },
404   { ARM64::LD1Threev16b,      "ld1",  ".16b",   0, 0  },
405   { ARM64::LD1Threev8h,       "ld1",  ".8h",    0, 0  },
406   { ARM64::LD1Threev4s,       "ld1",  ".4s",    0, 0  },
407   { ARM64::LD1Threev2d,       "ld1",  ".2d",    0, 0  },
408   { ARM64::LD1Threev8b,       "ld1",  ".8b",    0, 0  },
409   { ARM64::LD1Threev4h,       "ld1",  ".4h",    0, 0  },
410   { ARM64::LD1Threev2s,       "ld1",  ".2s",    0, 0  },
411   { ARM64::LD1Threev1d,       "ld1",  ".1d",    0, 0  },
412   { ARM64::LD1Threev16b_POST, "ld1",  ".16b",   0, 48 },
413   { ARM64::LD1Threev8h_POST,  "ld1",  ".8h",    0, 48 },
414   { ARM64::LD1Threev4s_POST,  "ld1",  ".4s",    0, 48 },
415   { ARM64::LD1Threev2d_POST,  "ld1",  ".2d",    0, 48 },
416   { ARM64::LD1Threev8b_POST,  "ld1",  ".8b",    0, 24 },
417   { ARM64::LD1Threev4h_POST,  "ld1",  ".4h",    0, 24 },
418   { ARM64::LD1Threev2s_POST,  "ld1",  ".2s",    0, 24 },
419   { ARM64::LD1Threev1d_POST,  "ld1",  ".1d",    0, 24 },
420   { ARM64::LD1Fourv16b,       "ld1",  ".16b",   0, 0  },
421   { ARM64::LD1Fourv8h,        "ld1",  ".8h",    0, 0  },
422   { ARM64::LD1Fourv4s,        "ld1",  ".4s",    0, 0  },
423   { ARM64::LD1Fourv2d,        "ld1",  ".2d",    0, 0  },
424   { ARM64::LD1Fourv8b,        "ld1",  ".8b",    0, 0  },
425   { ARM64::LD1Fourv4h,        "ld1",  ".4h",    0, 0  },
426   { ARM64::LD1Fourv2s,        "ld1",  ".2s",    0, 0  },
427   { ARM64::LD1Fourv1d,        "ld1",  ".1d",    0, 0  },
428   { ARM64::LD1Fourv16b_POST,  "ld1",  ".16b",   0, 64 },
429   { ARM64::LD1Fourv8h_POST,   "ld1",  ".8h",    0, 64 },
430   { ARM64::LD1Fourv4s_POST,   "ld1",  ".4s",    0, 64 },
431   { ARM64::LD1Fourv2d_POST,   "ld1",  ".2d",    0, 64 },
432   { ARM64::LD1Fourv8b_POST,   "ld1",  ".8b",    0, 32 },
433   { ARM64::LD1Fourv4h_POST,   "ld1",  ".4h",    0, 32 },
434   { ARM64::LD1Fourv2s_POST,   "ld1",  ".2s",    0, 32 },
435   { ARM64::LD1Fourv1d_POST,   "ld1",  ".1d",    0, 32 },
436   { ARM64::LD2i8,             "ld2",  ".b",     2, 0  },
437   { ARM64::LD2i16,            "ld2",  ".h",     2, 0  },
438   { ARM64::LD2i32,            "ld2",  ".s",     2, 0  },
439   { ARM64::LD2i64,            "ld2",  ".d",     2, 0  },
440   { ARM64::LD2i8_POST,        "ld2",  ".b",     2, 2  },
441   { ARM64::LD2i16_POST,       "ld2",  ".h",     2, 4  },
442   { ARM64::LD2i32_POST,       "ld2",  ".s",     2, 8  },
443   { ARM64::LD2i64_POST,       "ld2",  ".d",     2, 16  },
444   { ARM64::LD2Rv16b,          "ld2r", ".16b",   0, 0  },
445   { ARM64::LD2Rv8h,           "ld2r", ".8h",    0, 0  },
446   { ARM64::LD2Rv4s,           "ld2r", ".4s",    0, 0  },
447   { ARM64::LD2Rv2d,           "ld2r", ".2d",    0, 0  },
448   { ARM64::LD2Rv8b,           "ld2r", ".8b",    0, 0  },
449   { ARM64::LD2Rv4h,           "ld2r", ".4h",    0, 0  },
450   { ARM64::LD2Rv2s,           "ld2r", ".2s",    0, 0  },
451   { ARM64::LD2Rv1d,           "ld2r", ".1d",    0, 0  },
452   { ARM64::LD2Rv16b_POST,     "ld2r", ".16b",   0, 2  },
453   { ARM64::LD2Rv8h_POST,      "ld2r", ".8h",    0, 4  },
454   { ARM64::LD2Rv4s_POST,      "ld2r", ".4s",    0, 8  },
455   { ARM64::LD2Rv2d_POST,      "ld2r", ".2d",    0, 16 },
456   { ARM64::LD2Rv8b_POST,      "ld2r", ".8b",    0, 2  },
457   { ARM64::LD2Rv4h_POST,      "ld2r", ".4h",    0, 4  },
458   { ARM64::LD2Rv2s_POST,      "ld2r", ".2s",    0, 8  },
459   { ARM64::LD2Rv1d_POST,      "ld2r", ".1d",    0, 16 },
460   { ARM64::LD2Twov16b,        "ld2",  ".16b",   0, 0  },
461   { ARM64::LD2Twov8h,         "ld2",  ".8h",    0, 0  },
462   { ARM64::LD2Twov4s,         "ld2",  ".4s",    0, 0  },
463   { ARM64::LD2Twov2d,         "ld2",  ".2d",    0, 0  },
464   { ARM64::LD2Twov8b,         "ld2",  ".8b",    0, 0  },
465   { ARM64::LD2Twov4h,         "ld2",  ".4h",    0, 0  },
466   { ARM64::LD2Twov2s,         "ld2",  ".2s",    0, 0  },
467   { ARM64::LD2Twov16b_POST,   "ld2",  ".16b",   0, 32 },
468   { ARM64::LD2Twov8h_POST,    "ld2",  ".8h",    0, 32 },
469   { ARM64::LD2Twov4s_POST,    "ld2",  ".4s",    0, 32 },
470   { ARM64::LD2Twov2d_POST,    "ld2",  ".2d",    0, 32 },
471   { ARM64::LD2Twov8b_POST,    "ld2",  ".8b",    0, 16 },
472   { ARM64::LD2Twov4h_POST,    "ld2",  ".4h",    0, 16 },
473   { ARM64::LD2Twov2s_POST,    "ld2",  ".2s",    0, 16 },
474   { ARM64::LD3i8,             "ld3",  ".b",     2, 0  },
475   { ARM64::LD3i16,            "ld3",  ".h",     2, 0  },
476   { ARM64::LD3i32,            "ld3",  ".s",     2, 0  },
477   { ARM64::LD3i64,            "ld3",  ".d",     2, 0  },
478   { ARM64::LD3i8_POST,        "ld3",  ".b",     2, 3  },
479   { ARM64::LD3i16_POST,       "ld3",  ".h",     2, 6  },
480   { ARM64::LD3i32_POST,       "ld3",  ".s",     2, 12  },
481   { ARM64::LD3i64_POST,       "ld3",  ".d",     2, 24  },
482   { ARM64::LD3Rv16b,          "ld3r", ".16b",   0, 0  },
483   { ARM64::LD3Rv8h,           "ld3r", ".8h",    0, 0  },
484   { ARM64::LD3Rv4s,           "ld3r", ".4s",    0, 0  },
485   { ARM64::LD3Rv2d,           "ld3r", ".2d",    0, 0  },
486   { ARM64::LD3Rv8b,           "ld3r", ".8b",    0, 0  },
487   { ARM64::LD3Rv4h,           "ld3r", ".4h",    0, 0  },
488   { ARM64::LD3Rv2s,           "ld3r", ".2s",    0, 0  },
489   { ARM64::LD3Rv1d,           "ld3r", ".1d",    0, 0  },
490   { ARM64::LD3Rv16b_POST,     "ld3r", ".16b",   0, 3  },
491   { ARM64::LD3Rv8h_POST,      "ld3r", ".8h",    0, 6  },
492   { ARM64::LD3Rv4s_POST,      "ld3r", ".4s",    0, 12 },
493   { ARM64::LD3Rv2d_POST,      "ld3r", ".2d",    0, 24 },
494   { ARM64::LD3Rv8b_POST,      "ld3r", ".8b",    0, 3  },
495   { ARM64::LD3Rv4h_POST,      "ld3r", ".4h",    0, 6  },
496   { ARM64::LD3Rv2s_POST,      "ld3r", ".2s",    0, 12 },
497   { ARM64::LD3Rv1d_POST,      "ld3r", ".1d",    0, 24 },
498   { ARM64::LD3Threev16b,      "ld3",  ".16b",   0, 0  },
499   { ARM64::LD3Threev8h,       "ld3",  ".8h",    0, 0  },
500   { ARM64::LD3Threev4s,       "ld3",  ".4s",    0, 0  },
501   { ARM64::LD3Threev2d,       "ld3",  ".2d",    0, 0  },
502   { ARM64::LD3Threev8b,       "ld3",  ".8b",    0, 0  },
503   { ARM64::LD3Threev4h,       "ld3",  ".4h",    0, 0  },
504   { ARM64::LD3Threev2s,       "ld3",  ".2s",    0, 0  },
505   { ARM64::LD3Threev16b_POST, "ld3",  ".16b",   0, 48 },
506   { ARM64::LD3Threev8h_POST,  "ld3",  ".8h",    0, 48 },
507   { ARM64::LD3Threev4s_POST,  "ld3",  ".4s",    0, 48 },
508   { ARM64::LD3Threev2d_POST,  "ld3",  ".2d",    0, 48 },
509   { ARM64::LD3Threev8b_POST,  "ld3",  ".8b",    0, 24 },
510   { ARM64::LD3Threev4h_POST,  "ld3",  ".4h",    0, 24 },
511   { ARM64::LD3Threev2s_POST,  "ld3",  ".2s",    0, 24 },
512   { ARM64::LD4i8,             "ld4",  ".b",     2, 0  },
513   { ARM64::LD4i16,            "ld4",  ".h",     2, 0  },
514   { ARM64::LD4i32,            "ld4",  ".s",     2, 0  },
515   { ARM64::LD4i64,            "ld4",  ".d",     2, 0  },
516   { ARM64::LD4i8_POST,        "ld4",  ".b",     2, 4  },
517   { ARM64::LD4i16_POST,       "ld4",  ".h",     2, 8  },
518   { ARM64::LD4i32_POST,       "ld4",  ".s",     2, 16 },
519   { ARM64::LD4i64_POST,       "ld4",  ".d",     2, 32 },
520   { ARM64::LD4Rv16b,          "ld4r", ".16b",   0, 0  },
521   { ARM64::LD4Rv8h,           "ld4r", ".8h",    0, 0  },
522   { ARM64::LD4Rv4s,           "ld4r", ".4s",    0, 0  },
523   { ARM64::LD4Rv2d,           "ld4r", ".2d",    0, 0  },
524   { ARM64::LD4Rv8b,           "ld4r", ".8b",    0, 0  },
525   { ARM64::LD4Rv4h,           "ld4r", ".4h",    0, 0  },
526   { ARM64::LD4Rv2s,           "ld4r", ".2s",    0, 0  },
527   { ARM64::LD4Rv1d,           "ld4r", ".1d",    0, 0  },
528   { ARM64::LD4Rv16b_POST,     "ld4r", ".16b",   0, 4  },
529   { ARM64::LD4Rv8h_POST,      "ld4r", ".8h",    0, 8  },
530   { ARM64::LD4Rv4s_POST,      "ld4r", ".4s",    0, 16 },
531   { ARM64::LD4Rv2d_POST,      "ld4r", ".2d",    0, 32 },
532   { ARM64::LD4Rv8b_POST,      "ld4r", ".8b",    0, 4  },
533   { ARM64::LD4Rv4h_POST,      "ld4r", ".4h",    0, 8  },
534   { ARM64::LD4Rv2s_POST,      "ld4r", ".2s",    0, 16 },
535   { ARM64::LD4Rv1d_POST,      "ld4r", ".1d",    0, 32 },
536   { ARM64::LD4Fourv16b,       "ld4",  ".16b",   0, 0  },
537   { ARM64::LD4Fourv8h,        "ld4",  ".8h",    0, 0  },
538   { ARM64::LD4Fourv4s,        "ld4",  ".4s",    0, 0  },
539   { ARM64::LD4Fourv2d,        "ld4",  ".2d",    0, 0  },
540   { ARM64::LD4Fourv8b,        "ld4",  ".8b",    0, 0  },
541   { ARM64::LD4Fourv4h,        "ld4",  ".4h",    0, 0  },
542   { ARM64::LD4Fourv2s,        "ld4",  ".2s",    0, 0  },
543   { ARM64::LD4Fourv16b_POST,  "ld4",  ".16b",   0, 64 },
544   { ARM64::LD4Fourv8h_POST,   "ld4",  ".8h",    0, 64 },
545   { ARM64::LD4Fourv4s_POST,   "ld4",  ".4s",    0, 64 },
546   { ARM64::LD4Fourv2d_POST,   "ld4",  ".2d",    0, 64 },
547   { ARM64::LD4Fourv8b_POST,   "ld4",  ".8b",    0, 32 },
548   { ARM64::LD4Fourv4h_POST,   "ld4",  ".4h",    0, 32 },
549   { ARM64::LD4Fourv2s_POST,   "ld4",  ".2s",    0, 32 },
550   { ARM64::ST1i8,             "st1",  ".b",     1, 0  },
551   { ARM64::ST1i16,            "st1",  ".h",     1, 0  },
552   { ARM64::ST1i32,            "st1",  ".s",     1, 0  },
553   { ARM64::ST1i64,            "st1",  ".d",     1, 0  },
554   { ARM64::ST1i8_POST,        "st1",  ".b",     1, 1  },
555   { ARM64::ST1i16_POST,       "st1",  ".h",     1, 2  },
556   { ARM64::ST1i32_POST,       "st1",  ".s",     1, 4  },
557   { ARM64::ST1i64_POST,       "st1",  ".d",     1, 8  },
558   { ARM64::ST1Onev16b,        "st1",  ".16b",   0, 0  },
559   { ARM64::ST1Onev8h,         "st1",  ".8h",    0, 0  },
560   { ARM64::ST1Onev4s,         "st1",  ".4s",    0, 0  },
561   { ARM64::ST1Onev2d,         "st1",  ".2d",    0, 0  },
562   { ARM64::ST1Onev8b,         "st1",  ".8b",    0, 0  },
563   { ARM64::ST1Onev4h,         "st1",  ".4h",    0, 0  },
564   { ARM64::ST1Onev2s,         "st1",  ".2s",    0, 0  },
565   { ARM64::ST1Onev1d,         "st1",  ".1d",    0, 0  },
566   { ARM64::ST1Onev16b_POST,   "st1",  ".16b",   0, 16 },
567   { ARM64::ST1Onev8h_POST,    "st1",  ".8h",    0, 16 },
568   { ARM64::ST1Onev4s_POST,    "st1",  ".4s",    0, 16 },
569   { ARM64::ST1Onev2d_POST,    "st1",  ".2d",    0, 16 },
570   { ARM64::ST1Onev8b_POST,    "st1",  ".8b",    0, 8  },
571   { ARM64::ST1Onev4h_POST,    "st1",  ".4h",    0, 8  },
572   { ARM64::ST1Onev2s_POST,    "st1",  ".2s",    0, 8  },
573   { ARM64::ST1Onev1d_POST,    "st1",  ".1d",    0, 8  },
574   { ARM64::ST1Twov16b,        "st1",  ".16b",   0, 0  },
575   { ARM64::ST1Twov8h,         "st1",  ".8h",    0, 0  },
576   { ARM64::ST1Twov4s,         "st1",  ".4s",    0, 0  },
577   { ARM64::ST1Twov2d,         "st1",  ".2d",    0, 0  },
578   { ARM64::ST1Twov8b,         "st1",  ".8b",    0, 0  },
579   { ARM64::ST1Twov4h,         "st1",  ".4h",    0, 0  },
580   { ARM64::ST1Twov2s,         "st1",  ".2s",    0, 0  },
581   { ARM64::ST1Twov1d,         "st1",  ".1d",    0, 0  },
582   { ARM64::ST1Twov16b_POST,   "st1",  ".16b",   0, 32 },
583   { ARM64::ST1Twov8h_POST,    "st1",  ".8h",    0, 32 },
584   { ARM64::ST1Twov4s_POST,    "st1",  ".4s",    0, 32 },
585   { ARM64::ST1Twov2d_POST,    "st1",  ".2d",    0, 32 },
586   { ARM64::ST1Twov8b_POST,    "st1",  ".8b",    0, 16 },
587   { ARM64::ST1Twov4h_POST,    "st1",  ".4h",    0, 16 },
588   { ARM64::ST1Twov2s_POST,    "st1",  ".2s",    0, 16 },
589   { ARM64::ST1Twov1d_POST,    "st1",  ".1d",    0, 16 },
590   { ARM64::ST1Threev16b,      "st1",  ".16b",   0, 0  },
591   { ARM64::ST1Threev8h,       "st1",  ".8h",    0, 0  },
592   { ARM64::ST1Threev4s,       "st1",  ".4s",    0, 0  },
593   { ARM64::ST1Threev2d,       "st1",  ".2d",    0, 0  },
594   { ARM64::ST1Threev8b,       "st1",  ".8b",    0, 0  },
595   { ARM64::ST1Threev4h,       "st1",  ".4h",    0, 0  },
596   { ARM64::ST1Threev2s,       "st1",  ".2s",    0, 0  },
597   { ARM64::ST1Threev1d,       "st1",  ".1d",    0, 0  },
598   { ARM64::ST1Threev16b_POST, "st1",  ".16b",   0, 48 },
599   { ARM64::ST1Threev8h_POST,  "st1",  ".8h",    0, 48 },
600   { ARM64::ST1Threev4s_POST,  "st1",  ".4s",    0, 48 },
601   { ARM64::ST1Threev2d_POST,  "st1",  ".2d",    0, 48 },
602   { ARM64::ST1Threev8b_POST,  "st1",  ".8b",    0, 24 },
603   { ARM64::ST1Threev4h_POST,  "st1",  ".4h",    0, 24 },
604   { ARM64::ST1Threev2s_POST,  "st1",  ".2s",    0, 24 },
605   { ARM64::ST1Threev1d_POST,  "st1",  ".1d",    0, 24 },
606   { ARM64::ST1Fourv16b,       "st1",  ".16b",   0, 0  },
607   { ARM64::ST1Fourv8h,        "st1",  ".8h",    0, 0  },
608   { ARM64::ST1Fourv4s,        "st1",  ".4s",    0, 0  },
609   { ARM64::ST1Fourv2d,        "st1",  ".2d",    0, 0  },
610   { ARM64::ST1Fourv8b,        "st1",  ".8b",    0, 0  },
611   { ARM64::ST1Fourv4h,        "st1",  ".4h",    0, 0  },
612   { ARM64::ST1Fourv2s,        "st1",  ".2s",    0, 0  },
613   { ARM64::ST1Fourv1d,        "st1",  ".1d",    0, 0  },
614   { ARM64::ST1Fourv16b_POST,  "st1",  ".16b",   0, 64 },
615   { ARM64::ST1Fourv8h_POST,   "st1",  ".8h",    0, 64 },
616   { ARM64::ST1Fourv4s_POST,   "st1",  ".4s",    0, 64 },
617   { ARM64::ST1Fourv2d_POST,   "st1",  ".2d",    0, 64 },
618   { ARM64::ST1Fourv8b_POST,   "st1",  ".8b",    0, 32 },
619   { ARM64::ST1Fourv4h_POST,   "st1",  ".4h",    0, 32 },
620   { ARM64::ST1Fourv2s_POST,   "st1",  ".2s",    0, 32 },
621   { ARM64::ST1Fourv1d_POST,   "st1",  ".1d",    0, 32 },
622   { ARM64::ST2i8,             "st2",  ".b",     1, 0  },
623   { ARM64::ST2i16,            "st2",  ".h",     1, 0  },
624   { ARM64::ST2i32,            "st2",  ".s",     1, 0  },
625   { ARM64::ST2i64,            "st2",  ".d",     1, 0  },
626   { ARM64::ST2i8_POST,        "st2",  ".b",     1, 2  },
627   { ARM64::ST2i16_POST,       "st2",  ".h",     1, 4  },
628   { ARM64::ST2i32_POST,       "st2",  ".s",     1, 8  },
629   { ARM64::ST2i64_POST,       "st2",  ".d",     1, 16 },
630   { ARM64::ST2Twov16b,        "st2",  ".16b",   0, 0  },
631   { ARM64::ST2Twov8h,         "st2",  ".8h",    0, 0  },
632   { ARM64::ST2Twov4s,         "st2",  ".4s",    0, 0  },
633   { ARM64::ST2Twov2d,         "st2",  ".2d",    0, 0  },
634   { ARM64::ST2Twov8b,         "st2",  ".8b",    0, 0  },
635   { ARM64::ST2Twov4h,         "st2",  ".4h",    0, 0  },
636   { ARM64::ST2Twov2s,         "st2",  ".2s",    0, 0  },
637   { ARM64::ST2Twov16b_POST,   "st2",  ".16b",   0, 32 },
638   { ARM64::ST2Twov8h_POST,    "st2",  ".8h",    0, 32 },
639   { ARM64::ST2Twov4s_POST,    "st2",  ".4s",    0, 32 },
640   { ARM64::ST2Twov2d_POST,    "st2",  ".2d",    0, 32 },
641   { ARM64::ST2Twov8b_POST,    "st2",  ".8b",    0, 16 },
642   { ARM64::ST2Twov4h_POST,    "st2",  ".4h",    0, 16 },
643   { ARM64::ST2Twov2s_POST,    "st2",  ".2s",    0, 16 },
644   { ARM64::ST3i8,             "st3",  ".b",     1, 0  },
645   { ARM64::ST3i16,            "st3",  ".h",     1, 0  },
646   { ARM64::ST3i32,            "st3",  ".s",     1, 0  },
647   { ARM64::ST3i64,            "st3",  ".d",     1, 0  },
648   { ARM64::ST3i8_POST,        "st3",  ".b",     1, 3  },
649   { ARM64::ST3i16_POST,       "st3",  ".h",     1, 6  },
650   { ARM64::ST3i32_POST,       "st3",  ".s",     1, 12 },
651   { ARM64::ST3i64_POST,       "st3",  ".d",     1, 24 },
652   { ARM64::ST3Threev16b,      "st3",  ".16b",   0, 0  },
653   { ARM64::ST3Threev8h,       "st3",  ".8h",    0, 0  },
654   { ARM64::ST3Threev4s,       "st3",  ".4s",    0, 0  },
655   { ARM64::ST3Threev2d,       "st3",  ".2d",    0, 0  },
656   { ARM64::ST3Threev8b,       "st3",  ".8b",    0, 0  },
657   { ARM64::ST3Threev4h,       "st3",  ".4h",    0, 0  },
658   { ARM64::ST3Threev2s,       "st3",  ".2s",    0, 0  },
659   { ARM64::ST3Threev16b_POST, "st3",  ".16b",   0, 48 },
660   { ARM64::ST3Threev8h_POST,  "st3",  ".8h",    0, 48 },
661   { ARM64::ST3Threev4s_POST,  "st3",  ".4s",    0, 48 },
662   { ARM64::ST3Threev2d_POST,  "st3",  ".2d",    0, 48 },
663   { ARM64::ST3Threev8b_POST,  "st3",  ".8b",    0, 24 },
664   { ARM64::ST3Threev4h_POST,  "st3",  ".4h",    0, 24 },
665   { ARM64::ST3Threev2s_POST,  "st3",  ".2s",    0, 24 },
666   { ARM64::ST4i8,             "st4",  ".b",     1, 0  },
667   { ARM64::ST4i16,            "st4",  ".h",     1, 0  },
668   { ARM64::ST4i32,            "st4",  ".s",     1, 0  },
669   { ARM64::ST4i64,            "st4",  ".d",     1, 0  },
670   { ARM64::ST4i8_POST,        "st4",  ".b",     1, 4  },
671   { ARM64::ST4i16_POST,       "st4",  ".h",     1, 8  },
672   { ARM64::ST4i32_POST,       "st4",  ".s",     1, 16 },
673   { ARM64::ST4i64_POST,       "st4",  ".d",     1, 32 },
674   { ARM64::ST4Fourv16b,       "st4",  ".16b",   0, 0  },
675   { ARM64::ST4Fourv8h,        "st4",  ".8h",    0, 0  },
676   { ARM64::ST4Fourv4s,        "st4",  ".4s",    0, 0  },
677   { ARM64::ST4Fourv2d,        "st4",  ".2d",    0, 0  },
678   { ARM64::ST4Fourv8b,        "st4",  ".8b",    0, 0  },
679   { ARM64::ST4Fourv4h,        "st4",  ".4h",    0, 0  },
680   { ARM64::ST4Fourv2s,        "st4",  ".2s",    0, 0  },
681   { ARM64::ST4Fourv16b_POST,  "st4",  ".16b",   0, 64 },
682   { ARM64::ST4Fourv8h_POST,   "st4",  ".8h",    0, 64 },
683   { ARM64::ST4Fourv4s_POST,   "st4",  ".4s",    0, 64 },
684   { ARM64::ST4Fourv2d_POST,   "st4",  ".2d",    0, 64 },
685   { ARM64::ST4Fourv8b_POST,   "st4",  ".8b",    0, 32 },
686   { ARM64::ST4Fourv4h_POST,   "st4",  ".4h",    0, 32 },
687   { ARM64::ST4Fourv2s_POST,   "st4",  ".2s",    0, 32 },
688 };
689
690 static LdStNInstrDesc *getLdStNInstrDesc(unsigned Opcode) {
691   unsigned Idx;
692   for (Idx = 0; Idx != array_lengthof(LdStNInstInfo); ++Idx)
693     if (LdStNInstInfo[Idx].Opcode == Opcode)
694       return &LdStNInstInfo[Idx];
695
696   return nullptr;
697 }
698
699 void ARM64AppleInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
700                                       StringRef Annot) {
701   unsigned Opcode = MI->getOpcode();
702   StringRef Layout, Mnemonic;
703
704   bool IsTbx;
705   if (isTblTbxInstruction(MI->getOpcode(), Layout, IsTbx)) {
706     O << "\t" << (IsTbx ? "tbx" : "tbl") << Layout << '\t'
707       << getRegisterName(MI->getOperand(0).getReg(), ARM64::vreg) << ", ";
708
709     unsigned ListOpNum = IsTbx ? 2 : 1;
710     printVectorList(MI, ListOpNum, O, "");
711
712     O << ", "
713       << getRegisterName(MI->getOperand(ListOpNum + 1).getReg(), ARM64::vreg);
714     printAnnotation(O, Annot);
715     return;
716   }
717
718   if (LdStNInstrDesc *LdStDesc = getLdStNInstrDesc(Opcode)) {
719     O << "\t" << LdStDesc->Mnemonic << LdStDesc->Layout << '\t';
720
721     // Now onto the operands: first a vector list with possible lane
722     // specifier. E.g. { v0 }[2]
723     printVectorList(MI, 0, O, "");
724
725     if (LdStDesc->LaneOperand != 0)
726       O << '[' << MI->getOperand(LdStDesc->LaneOperand).getImm() << ']';
727
728     // Next the address: [xN]
729     unsigned AddrOpNum = LdStDesc->LaneOperand + 1;
730     unsigned AddrReg = MI->getOperand(AddrOpNum).getReg();
731     O << ", [" << getRegisterName(AddrReg) << ']';
732
733     // Finally, there might be a post-indexed offset.
734     if (LdStDesc->NaturalOffset != 0) {
735       unsigned Reg = MI->getOperand(AddrOpNum + 1).getReg();
736       if (Reg != ARM64::XZR)
737         O << ", " << getRegisterName(Reg);
738       else {
739         assert(LdStDesc->NaturalOffset && "no offset on post-inc instruction?");
740         O << ", #" << LdStDesc->NaturalOffset;
741       }
742     }
743
744     printAnnotation(O, Annot);
745     return;
746   }
747
748   ARM64InstPrinter::printInst(MI, O, Annot);
749 }
750
751 bool ARM64InstPrinter::printSysAlias(const MCInst *MI, raw_ostream &O) {
752 #ifndef NDEBUG
753   unsigned Opcode = MI->getOpcode();
754   assert(Opcode == ARM64::SYSxt && "Invalid opcode for SYS alias!");
755 #endif
756
757   const char *Asm = nullptr;
758   const MCOperand &Op1 = MI->getOperand(0);
759   const MCOperand &Cn = MI->getOperand(1);
760   const MCOperand &Cm = MI->getOperand(2);
761   const MCOperand &Op2 = MI->getOperand(3);
762
763   unsigned Op1Val = Op1.getImm();
764   unsigned CnVal = Cn.getImm();
765   unsigned CmVal = Cm.getImm();
766   unsigned Op2Val = Op2.getImm();
767
768   if (CnVal == 7) {
769     switch (CmVal) {
770     default:
771       break;
772
773     // IC aliases
774     case 1:
775       if (Op1Val == 0 && Op2Val == 0)
776         Asm = "ic\tialluis";
777       break;
778     case 5:
779       if (Op1Val == 0 && Op2Val == 0)
780         Asm = "ic\tiallu";
781       else if (Op1Val == 3 && Op2Val == 1)
782         Asm = "ic\tivau";
783       break;
784
785     // DC aliases
786     case 4:
787       if (Op1Val == 3 && Op2Val == 1)
788         Asm = "dc\tzva";
789       break;
790     case 6:
791       if (Op1Val == 0 && Op2Val == 1)
792         Asm = "dc\tivac";
793       if (Op1Val == 0 && Op2Val == 2)
794         Asm = "dc\tisw";
795       break;
796     case 10:
797       if (Op1Val == 3 && Op2Val == 1)
798         Asm = "dc\tcvac";
799       else if (Op1Val == 0 && Op2Val == 2)
800         Asm = "dc\tcsw";
801       break;
802     case 11:
803       if (Op1Val == 3 && Op2Val == 1)
804         Asm = "dc\tcvau";
805       break;
806     case 14:
807       if (Op1Val == 3 && Op2Val == 1)
808         Asm = "dc\tcivac";
809       else if (Op1Val == 0 && Op2Val == 2)
810         Asm = "dc\tcisw";
811       break;
812
813     // AT aliases
814     case 8:
815       switch (Op1Val) {
816       default:
817         break;
818       case 0:
819         switch (Op2Val) {
820         default:
821           break;
822         case 0: Asm = "at\ts1e1r"; break;
823         case 1: Asm = "at\ts1e1w"; break;
824         case 2: Asm = "at\ts1e0r"; break;
825         case 3: Asm = "at\ts1e0w"; break;
826         }
827         break;
828       case 4:
829         switch (Op2Val) {
830         default:
831           break;
832         case 0: Asm = "at\ts1e2r"; break;
833         case 1: Asm = "at\ts1e2w"; break;
834         case 4: Asm = "at\ts12e1r"; break;
835         case 5: Asm = "at\ts12e1w"; break;
836         case 6: Asm = "at\ts12e0r"; break;
837         case 7: Asm = "at\ts12e0w"; break;
838         }
839         break;
840       case 6:
841         switch (Op2Val) {
842         default:
843           break;
844         case 0: Asm = "at\ts1e3r"; break;
845         case 1: Asm = "at\ts1e3w"; break;
846         }
847         break;
848       }
849       break;
850     }
851   } else if (CnVal == 8) {
852     // TLBI aliases
853     switch (CmVal) {
854     default:
855       break;
856     case 3:
857       switch (Op1Val) {
858       default:
859         break;
860       case 0:
861         switch (Op2Val) {
862         default:
863           break;
864         case 0: Asm = "tlbi\tvmalle1is"; break;
865         case 1: Asm = "tlbi\tvae1is"; break;
866         case 2: Asm = "tlbi\taside1is"; break;
867         case 3: Asm = "tlbi\tvaae1is"; break;
868         case 5: Asm = "tlbi\tvale1is"; break;
869         case 7: Asm = "tlbi\tvaale1is"; break;
870         }
871         break;
872       case 4:
873         switch (Op2Val) {
874         default:
875           break;
876         case 0: Asm = "tlbi\talle2is"; break;
877         case 1: Asm = "tlbi\tvae2is"; break;
878         case 4: Asm = "tlbi\talle1is"; break;
879         case 5: Asm = "tlbi\tvale2is"; break;
880         case 6: Asm = "tlbi\tvmalls12e1is"; break;
881         }
882         break;
883       case 6:
884         switch (Op2Val) {
885         default:
886           break;
887         case 0: Asm = "tlbi\talle3is"; break;
888         case 1: Asm = "tlbi\tvae3is"; break;
889         case 5: Asm = "tlbi\tvale3is"; break;
890         }
891         break;
892       }
893       break;
894     case 0:
895       switch (Op1Val) {
896       default:
897         break;
898       case 4:
899         switch (Op2Val) {
900         default:
901           break;
902         case 1: Asm = "tlbi\tipas2e1is"; break;
903         case 5: Asm = "tlbi\tipas2le1is"; break;
904         }
905         break;
906       }
907       break;
908     case 4:
909       switch (Op1Val) {
910       default:
911         break;
912       case 4:
913         switch (Op2Val) {
914         default:
915           break;
916         case 1: Asm = "tlbi\tipas2e1"; break;
917         case 5: Asm = "tlbi\tipas2le1"; break;
918         }
919         break;
920       }
921       break;
922     case 7:
923       switch (Op1Val) {
924       default:
925         break;
926       case 0:
927         switch (Op2Val) {
928         default:
929           break;
930         case 0: Asm = "tlbi\tvmalle1"; break;
931         case 1: Asm = "tlbi\tvae1"; break;
932         case 2: Asm = "tlbi\taside1"; break;
933         case 3: Asm = "tlbi\tvaae1"; break;
934         case 5: Asm = "tlbi\tvale1"; break;
935         case 7: Asm = "tlbi\tvaale1"; break;
936         }
937         break;
938       case 4:
939         switch (Op2Val) {
940         default:
941           break;
942         case 0: Asm = "tlbi\talle2"; break;
943         case 1: Asm = "tlbi\tvae2"; break;
944         case 4: Asm = "tlbi\talle1"; break;
945         case 5: Asm = "tlbi\tvale2"; break;
946         case 6: Asm = "tlbi\tvmalls12e1"; break;
947         }
948         break;
949       case 6:
950         switch (Op2Val) {
951         default:
952           break;
953         case 0: Asm = "tlbi\talle3"; break;
954         case 1: Asm = "tlbi\tvae3";  break;
955         case 5: Asm = "tlbi\tvale3"; break;
956         }
957         break;
958       }
959       break;
960     }
961   }
962
963   if (Asm) {
964     unsigned Reg = MI->getOperand(4).getReg();
965
966     O << '\t' << Asm;
967     if (StringRef(Asm).lower().find("all") == StringRef::npos)
968       O << ", " << getRegisterName(Reg);
969   }
970
971   return Asm != nullptr;
972 }
973
974 void ARM64InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
975                                     raw_ostream &O) {
976   const MCOperand &Op = MI->getOperand(OpNo);
977   if (Op.isReg()) {
978     unsigned Reg = Op.getReg();
979     O << getRegisterName(Reg);
980   } else if (Op.isImm()) {
981     O << '#' << Op.getImm();
982   } else {
983     assert(Op.isExpr() && "unknown operand kind in printOperand");
984     O << *Op.getExpr();
985   }
986 }
987
988 void ARM64InstPrinter::printPostIncOperand(const MCInst *MI, unsigned OpNo,
989                                            unsigned Imm, raw_ostream &O) {
990   const MCOperand &Op = MI->getOperand(OpNo);
991   if (Op.isReg()) {
992     unsigned Reg = Op.getReg();
993     if (Reg == ARM64::XZR)
994       O << "#" << Imm;
995     else
996       O << getRegisterName(Reg);
997   } else
998     assert(0 && "unknown operand kind in printPostIncOperand64");
999 }
1000
1001 void ARM64InstPrinter::printPostIncOperand1(const MCInst *MI, unsigned OpNo,
1002                                             raw_ostream &O) {
1003   printPostIncOperand(MI, OpNo, 1, O);
1004 }
1005
1006 void ARM64InstPrinter::printPostIncOperand2(const MCInst *MI, unsigned OpNo,
1007                                             raw_ostream &O) {
1008   printPostIncOperand(MI, OpNo, 2, O);
1009 }
1010
1011 void ARM64InstPrinter::printPostIncOperand3(const MCInst *MI, unsigned OpNo,
1012                                             raw_ostream &O) {
1013   printPostIncOperand(MI, OpNo, 3, O);
1014 }
1015
1016 void ARM64InstPrinter::printPostIncOperand4(const MCInst *MI, unsigned OpNo,
1017                                             raw_ostream &O) {
1018   printPostIncOperand(MI, OpNo, 4, O);
1019 }
1020
1021 void ARM64InstPrinter::printPostIncOperand6(const MCInst *MI, unsigned OpNo,
1022                                             raw_ostream &O) {
1023   printPostIncOperand(MI, OpNo, 6, O);
1024 }
1025
1026 void ARM64InstPrinter::printPostIncOperand8(const MCInst *MI, unsigned OpNo,
1027                                             raw_ostream &O) {
1028   printPostIncOperand(MI, OpNo, 8, O);
1029 }
1030
1031 void ARM64InstPrinter::printPostIncOperand12(const MCInst *MI, unsigned OpNo,
1032                                              raw_ostream &O) {
1033   printPostIncOperand(MI, OpNo, 12, O);
1034 }
1035
1036 void ARM64InstPrinter::printPostIncOperand16(const MCInst *MI, unsigned OpNo,
1037                                              raw_ostream &O) {
1038   printPostIncOperand(MI, OpNo, 16, O);
1039 }
1040
1041 void ARM64InstPrinter::printPostIncOperand24(const MCInst *MI, unsigned OpNo,
1042                                              raw_ostream &O) {
1043   printPostIncOperand(MI, OpNo, 24, O);
1044 }
1045
1046 void ARM64InstPrinter::printPostIncOperand32(const MCInst *MI, unsigned OpNo,
1047                                              raw_ostream &O) {
1048   printPostIncOperand(MI, OpNo, 32, O);
1049 }
1050
1051 void ARM64InstPrinter::printPostIncOperand48(const MCInst *MI, unsigned OpNo,
1052                                              raw_ostream &O) {
1053   printPostIncOperand(MI, OpNo, 48, O);
1054 }
1055
1056 void ARM64InstPrinter::printPostIncOperand64(const MCInst *MI, unsigned OpNo,
1057                                              raw_ostream &O) {
1058   printPostIncOperand(MI, OpNo, 64, O);
1059 }
1060
1061 void ARM64InstPrinter::printVRegOperand(const MCInst *MI, unsigned OpNo,
1062                                         raw_ostream &O) {
1063   const MCOperand &Op = MI->getOperand(OpNo);
1064   assert(Op.isReg() && "Non-register vreg operand!");
1065   unsigned Reg = Op.getReg();
1066   O << getRegisterName(Reg, ARM64::vreg);
1067 }
1068
1069 void ARM64InstPrinter::printSysCROperand(const MCInst *MI, unsigned OpNo,
1070                                          raw_ostream &O) {
1071   const MCOperand &Op = MI->getOperand(OpNo);
1072   assert(Op.isImm() && "System instruction C[nm] operands must be immediates!");
1073   O << "c" << Op.getImm();
1074 }
1075
1076 void ARM64InstPrinter::printAddSubImm(const MCInst *MI, unsigned OpNum,
1077                                       raw_ostream &O) {
1078   const MCOperand &MO = MI->getOperand(OpNum);
1079   if (MO.isImm()) {
1080     unsigned Val = (MO.getImm() & 0xfff);
1081     assert(Val == MO.getImm() && "Add/sub immediate out of range!");
1082     unsigned Shift =
1083         ARM64_AM::getShiftValue(MI->getOperand(OpNum + 1).getImm());
1084     O << '#' << (Val << Shift);
1085     // Distinguish "0, lsl #12" from "0, lsl #0".
1086     if (Val == 0 && Shift != 0)
1087       printShifter(MI, OpNum + 1, O);
1088   } else {
1089     assert(MO.isExpr() && "Unexpected operand type!");
1090     O << *MO.getExpr();
1091     printShifter(MI, OpNum + 1, O);
1092   }
1093 }
1094
1095 void ARM64InstPrinter::printLogicalImm32(const MCInst *MI, unsigned OpNum,
1096                                          raw_ostream &O) {
1097   uint64_t Val = MI->getOperand(OpNum).getImm();
1098   O << "#0x";
1099   O.write_hex(ARM64_AM::decodeLogicalImmediate(Val, 32));
1100 }
1101
1102 void ARM64InstPrinter::printLogicalImm64(const MCInst *MI, unsigned OpNum,
1103                                          raw_ostream &O) {
1104   uint64_t Val = MI->getOperand(OpNum).getImm();
1105   O << "#0x";
1106   O.write_hex(ARM64_AM::decodeLogicalImmediate(Val, 64));
1107 }
1108
1109 void ARM64InstPrinter::printShifter(const MCInst *MI, unsigned OpNum,
1110                                     raw_ostream &O) {
1111   unsigned Val = MI->getOperand(OpNum).getImm();
1112   // LSL #0 should not be printed.
1113   if (ARM64_AM::getShiftType(Val) == ARM64_AM::LSL &&
1114       ARM64_AM::getShiftValue(Val) == 0)
1115     return;
1116   O << ", " << ARM64_AM::getShiftName(ARM64_AM::getShiftType(Val)) << " #"
1117     << ARM64_AM::getShiftValue(Val);
1118 }
1119
1120 void ARM64InstPrinter::printShiftedRegister(const MCInst *MI, unsigned OpNum,
1121                                             raw_ostream &O) {
1122   O << getRegisterName(MI->getOperand(OpNum).getReg());
1123   printShifter(MI, OpNum + 1, O);
1124 }
1125
1126 void ARM64InstPrinter::printExtendedRegister(const MCInst *MI, unsigned OpNum,
1127                                              raw_ostream &O) {
1128   O << getRegisterName(MI->getOperand(OpNum).getReg());
1129   printExtend(MI, OpNum + 1, O);
1130 }
1131
1132 void ARM64InstPrinter::printExtend(const MCInst *MI, unsigned OpNum,
1133                                    raw_ostream &O) {
1134   unsigned Val = MI->getOperand(OpNum).getImm();
1135   ARM64_AM::ExtendType ExtType = ARM64_AM::getArithExtendType(Val);
1136   unsigned ShiftVal = ARM64_AM::getArithShiftValue(Val);
1137
1138   // If the destination or first source register operand is [W]SP, print
1139   // UXTW/UXTX as LSL, and if the shift amount is also zero, print nothing at
1140   // all.
1141   if (ExtType == ARM64_AM::UXTW || ExtType == ARM64_AM::UXTX) {
1142     unsigned Dest = MI->getOperand(0).getReg();
1143     unsigned Src1 = MI->getOperand(1).getReg();
1144     if ( ((Dest == ARM64::SP || Src1 == ARM64::SP) &&
1145           ExtType == ARM64_AM::UXTX) ||
1146          ((Dest == ARM64::WSP || Src1 == ARM64::WSP) &&
1147           ExtType == ARM64_AM::UXTW) ) {
1148       if (ShiftVal != 0)
1149         O << ", lsl #" << ShiftVal;
1150       return;
1151     }
1152   }
1153   O << ", " << ARM64_AM::getExtendName(ExtType);
1154   if (ShiftVal != 0)
1155     O << " #" << ShiftVal;
1156 }
1157
1158 void ARM64InstPrinter::printDotCondCode(const MCInst *MI, unsigned OpNum,
1159                                         raw_ostream &O) {
1160   ARM64CC::CondCode CC = (ARM64CC::CondCode)MI->getOperand(OpNum).getImm();
1161   O << '.' << ARM64CC::getCondCodeName(CC);
1162 }
1163
1164 void ARM64InstPrinter::printCondCode(const MCInst *MI, unsigned OpNum,
1165                                      raw_ostream &O) {
1166   ARM64CC::CondCode CC = (ARM64CC::CondCode)MI->getOperand(OpNum).getImm();
1167   O << ARM64CC::getCondCodeName(CC);
1168 }
1169
1170 void ARM64InstPrinter::printAMNoIndex(const MCInst *MI, unsigned OpNum,
1171                                       raw_ostream &O) {
1172   O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']';
1173 }
1174
1175 void ARM64InstPrinter::printImmScale4(const MCInst *MI, unsigned OpNum,
1176                                       raw_ostream &O) {
1177   O << '#' << 4 * MI->getOperand(OpNum).getImm();
1178 }
1179
1180 void ARM64InstPrinter::printImmScale8(const MCInst *MI, unsigned OpNum,
1181                                       raw_ostream &O) {
1182   O << '#' << 8 * MI->getOperand(OpNum).getImm();
1183 }
1184
1185 void ARM64InstPrinter::printImmScale16(const MCInst *MI, unsigned OpNum,
1186                                        raw_ostream &O) {
1187   O << '#' << 16 * MI->getOperand(OpNum).getImm();
1188 }
1189
1190 void ARM64InstPrinter::printAMIndexed(const MCInst *MI, unsigned OpNum,
1191                                       unsigned Scale, raw_ostream &O) {
1192   const MCOperand MO1 = MI->getOperand(OpNum + 1);
1193   O << '[' << getRegisterName(MI->getOperand(OpNum).getReg());
1194   if (MO1.isImm()) {
1195     if (MO1.getImm() != 0)
1196       O << ", #" << (MO1.getImm() * Scale);
1197   } else {
1198     assert(MO1.isExpr() && "Unexpected operand type!");
1199     O << ", " << *MO1.getExpr();
1200   }
1201   O << ']';
1202 }
1203
1204 void ARM64InstPrinter::printAMIndexedWB(const MCInst *MI, unsigned OpNum,
1205                                         unsigned Scale, raw_ostream &O) {
1206   const MCOperand MO1 = MI->getOperand(OpNum + 1);
1207   O << '[' << getRegisterName(MI->getOperand(OpNum).getReg());
1208   if (MO1.isImm()) {
1209       O << ", #" << (MO1.getImm() * Scale);
1210   } else {
1211     assert(MO1.isExpr() && "Unexpected operand type!");
1212     O << ", " << *MO1.getExpr();
1213   }
1214   O << ']';
1215 }
1216
1217 void ARM64InstPrinter::printPrefetchOp(const MCInst *MI, unsigned OpNum,
1218                                        raw_ostream &O) {
1219   unsigned prfop = MI->getOperand(OpNum).getImm();
1220   bool Valid;
1221   StringRef Name = ARM64PRFM::PRFMMapper().toString(prfop, Valid);
1222   if (Valid)
1223     O << Name;
1224   else
1225     O << '#' << prfop;
1226 }
1227
1228 void ARM64InstPrinter::printMemoryPostIndexed32(const MCInst *MI,
1229                                                 unsigned OpNum,
1230                                                 raw_ostream &O) {
1231   O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']' << ", #"
1232     << 4 * MI->getOperand(OpNum + 1).getImm();
1233 }
1234
1235 void ARM64InstPrinter::printMemoryPostIndexed64(const MCInst *MI,
1236                                                 unsigned OpNum,
1237                                                 raw_ostream &O) {
1238   O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']' << ", #"
1239     << 8 * MI->getOperand(OpNum + 1).getImm();
1240 }
1241
1242 void ARM64InstPrinter::printMemoryPostIndexed128(const MCInst *MI,
1243                                                  unsigned OpNum,
1244                                                  raw_ostream &O) {
1245   O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']' << ", #"
1246     << 16 * MI->getOperand(OpNum + 1).getImm();
1247 }
1248
1249 void ARM64InstPrinter::printMemoryPostIndexed(const MCInst *MI, unsigned OpNum,
1250                                               raw_ostream &O) {
1251   O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']' << ", #"
1252     << MI->getOperand(OpNum + 1).getImm();
1253 }
1254
1255 void ARM64InstPrinter::printMemoryRegOffset(const MCInst *MI, unsigned OpNum,
1256                                             raw_ostream &O, int LegalShiftAmt) {
1257   unsigned Val = MI->getOperand(OpNum + 2).getImm();
1258   ARM64_AM::ExtendType ExtType = ARM64_AM::getMemExtendType(Val);
1259
1260   O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ", ";
1261   if (ExtType == ARM64_AM::UXTW || ExtType == ARM64_AM::SXTW)
1262     O << getRegisterName(getWRegFromXReg(MI->getOperand(OpNum + 1).getReg()));
1263   else
1264     O << getRegisterName(MI->getOperand(OpNum + 1).getReg());
1265
1266   bool DoShift = ARM64_AM::getMemDoShift(Val);
1267
1268   if (ExtType == ARM64_AM::UXTX) {
1269     if (DoShift)
1270       O << ", lsl";
1271   } else
1272     O << ", " << ARM64_AM::getExtendName(ExtType);
1273
1274   if (DoShift)
1275     O << " #" << LegalShiftAmt;
1276
1277   O << "]";
1278 }
1279
1280 void ARM64InstPrinter::printMemoryRegOffset8(const MCInst *MI, unsigned OpNum,
1281                                              raw_ostream &O) {
1282   printMemoryRegOffset(MI, OpNum, O, 0);
1283 }
1284
1285 void ARM64InstPrinter::printMemoryRegOffset16(const MCInst *MI, unsigned OpNum,
1286                                               raw_ostream &O) {
1287   printMemoryRegOffset(MI, OpNum, O, 1);
1288 }
1289
1290 void ARM64InstPrinter::printMemoryRegOffset32(const MCInst *MI, unsigned OpNum,
1291                                               raw_ostream &O) {
1292   printMemoryRegOffset(MI, OpNum, O, 2);
1293 }
1294
1295 void ARM64InstPrinter::printMemoryRegOffset64(const MCInst *MI, unsigned OpNum,
1296                                               raw_ostream &O) {
1297   printMemoryRegOffset(MI, OpNum, O, 3);
1298 }
1299
1300 void ARM64InstPrinter::printMemoryRegOffset128(const MCInst *MI, unsigned OpNum,
1301                                                raw_ostream &O) {
1302   printMemoryRegOffset(MI, OpNum, O, 4);
1303 }
1304
1305 void ARM64InstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
1306                                          raw_ostream &O) {
1307   const MCOperand &MO = MI->getOperand(OpNum);
1308   O << '#';
1309   if (MO.isFPImm())
1310     // FIXME: Should this ever happen?
1311     O << MO.getFPImm();
1312   else
1313     O << ARM64_AM::getFPImmFloat(MO.getImm());
1314 }
1315
1316 static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride = 1) {
1317   while (Stride--) {
1318     switch (Reg) {
1319     default:
1320       assert(0 && "Vector register expected!");
1321     case ARM64::Q0:  Reg = ARM64::Q1;  break;
1322     case ARM64::Q1:  Reg = ARM64::Q2;  break;
1323     case ARM64::Q2:  Reg = ARM64::Q3;  break;
1324     case ARM64::Q3:  Reg = ARM64::Q4;  break;
1325     case ARM64::Q4:  Reg = ARM64::Q5;  break;
1326     case ARM64::Q5:  Reg = ARM64::Q6;  break;
1327     case ARM64::Q6:  Reg = ARM64::Q7;  break;
1328     case ARM64::Q7:  Reg = ARM64::Q8;  break;
1329     case ARM64::Q8:  Reg = ARM64::Q9;  break;
1330     case ARM64::Q9:  Reg = ARM64::Q10; break;
1331     case ARM64::Q10: Reg = ARM64::Q11; break;
1332     case ARM64::Q11: Reg = ARM64::Q12; break;
1333     case ARM64::Q12: Reg = ARM64::Q13; break;
1334     case ARM64::Q13: Reg = ARM64::Q14; break;
1335     case ARM64::Q14: Reg = ARM64::Q15; break;
1336     case ARM64::Q15: Reg = ARM64::Q16; break;
1337     case ARM64::Q16: Reg = ARM64::Q17; break;
1338     case ARM64::Q17: Reg = ARM64::Q18; break;
1339     case ARM64::Q18: Reg = ARM64::Q19; break;
1340     case ARM64::Q19: Reg = ARM64::Q20; break;
1341     case ARM64::Q20: Reg = ARM64::Q21; break;
1342     case ARM64::Q21: Reg = ARM64::Q22; break;
1343     case ARM64::Q22: Reg = ARM64::Q23; break;
1344     case ARM64::Q23: Reg = ARM64::Q24; break;
1345     case ARM64::Q24: Reg = ARM64::Q25; break;
1346     case ARM64::Q25: Reg = ARM64::Q26; break;
1347     case ARM64::Q26: Reg = ARM64::Q27; break;
1348     case ARM64::Q27: Reg = ARM64::Q28; break;
1349     case ARM64::Q28: Reg = ARM64::Q29; break;
1350     case ARM64::Q29: Reg = ARM64::Q30; break;
1351     case ARM64::Q30: Reg = ARM64::Q31; break;
1352     // Vector lists can wrap around.
1353     case ARM64::Q31:
1354       Reg = ARM64::Q0;
1355       break;
1356     }
1357   }
1358   return Reg;
1359 }
1360
1361 void ARM64InstPrinter::printVectorList(const MCInst *MI, unsigned OpNum,
1362                                        raw_ostream &O, StringRef LayoutSuffix) {
1363   unsigned Reg = MI->getOperand(OpNum).getReg();
1364
1365   O << "{ ";
1366
1367   // Work out how many registers there are in the list (if there is an actual
1368   // list).
1369   unsigned NumRegs = 1;
1370   if (MRI.getRegClass(ARM64::DDRegClassID).contains(Reg) ||
1371       MRI.getRegClass(ARM64::QQRegClassID).contains(Reg))
1372     NumRegs = 2;
1373   else if (MRI.getRegClass(ARM64::DDDRegClassID).contains(Reg) ||
1374            MRI.getRegClass(ARM64::QQQRegClassID).contains(Reg))
1375     NumRegs = 3;
1376   else if (MRI.getRegClass(ARM64::DDDDRegClassID).contains(Reg) ||
1377            MRI.getRegClass(ARM64::QQQQRegClassID).contains(Reg))
1378     NumRegs = 4;
1379
1380   // Now forget about the list and find out what the first register is.
1381   if (unsigned FirstReg = MRI.getSubReg(Reg, ARM64::dsub0))
1382     Reg = FirstReg;
1383   else if (unsigned FirstReg = MRI.getSubReg(Reg, ARM64::qsub0))
1384     Reg = FirstReg;
1385
1386   // If it's a D-reg, we need to promote it to the equivalent Q-reg before
1387   // printing (otherwise getRegisterName fails).
1388   if (MRI.getRegClass(ARM64::FPR64RegClassID).contains(Reg)) {
1389     const MCRegisterClass &FPR128RC = MRI.getRegClass(ARM64::FPR128RegClassID);
1390     Reg = MRI.getMatchingSuperReg(Reg, ARM64::dsub, &FPR128RC);
1391   }
1392
1393   for (unsigned i = 0; i < NumRegs; ++i, Reg = getNextVectorRegister(Reg)) {
1394     O << getRegisterName(Reg, ARM64::vreg) << LayoutSuffix;
1395     if (i + 1 != NumRegs)
1396       O << ", ";
1397   }
1398
1399   O << " }";
1400 }
1401
1402 void ARM64InstPrinter::printImplicitlyTypedVectorList(const MCInst *MI,
1403                                                       unsigned OpNum,
1404                                                       raw_ostream &O) {
1405   printVectorList(MI, OpNum, O, "");
1406 }
1407
1408 template <unsigned NumLanes, char LaneKind>
1409 void ARM64InstPrinter::printTypedVectorList(const MCInst *MI, unsigned OpNum,
1410                                             raw_ostream &O) {
1411   std::string Suffix(".");
1412   if (NumLanes)
1413     Suffix += itostr(NumLanes) + LaneKind;
1414   else
1415     Suffix += LaneKind;
1416
1417   printVectorList(MI, OpNum, O, Suffix);
1418 }
1419
1420 void ARM64InstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
1421                                         raw_ostream &O) {
1422   O << "[" << MI->getOperand(OpNum).getImm() << "]";
1423 }
1424
1425 void ARM64InstPrinter::printAlignedLabel(const MCInst *MI, unsigned OpNum,
1426                                          raw_ostream &O) {
1427   const MCOperand &Op = MI->getOperand(OpNum);
1428
1429   // If the label has already been resolved to an immediate offset (say, when
1430   // we're running the disassembler), just print the immediate.
1431   if (Op.isImm()) {
1432     O << "#" << (Op.getImm() << 2);
1433     return;
1434   }
1435
1436   // If the branch target is simply an address then print it in hex.
1437   const MCConstantExpr *BranchTarget =
1438       dyn_cast<MCConstantExpr>(MI->getOperand(OpNum).getExpr());
1439   int64_t Address;
1440   if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
1441     O << "0x";
1442     O.write_hex(Address);
1443   } else {
1444     // Otherwise, just print the expression.
1445     O << *MI->getOperand(OpNum).getExpr();
1446   }
1447 }
1448
1449 void ARM64InstPrinter::printAdrpLabel(const MCInst *MI, unsigned OpNum,
1450                                       raw_ostream &O) {
1451   const MCOperand &Op = MI->getOperand(OpNum);
1452
1453   // If the label has already been resolved to an immediate offset (say, when
1454   // we're running the disassembler), just print the immediate.
1455   if (Op.isImm()) {
1456     O << "#" << (Op.getImm() << 12);
1457     return;
1458   }
1459
1460   // Otherwise, just print the expression.
1461   O << *MI->getOperand(OpNum).getExpr();
1462 }
1463
1464 void ARM64InstPrinter::printBarrierOption(const MCInst *MI, unsigned OpNo,
1465                                           raw_ostream &O) {
1466   unsigned Val = MI->getOperand(OpNo).getImm();
1467   unsigned Opcode = MI->getOpcode();
1468
1469   bool Valid;
1470   StringRef Name;
1471   if (Opcode == ARM64::ISB)
1472     Name = ARM64ISB::ISBMapper().toString(Val, Valid);
1473   else
1474     Name = ARM64DB::DBarrierMapper().toString(Val, Valid);
1475   if (Valid)
1476     O << Name;
1477   else
1478     O << "#" << Val;
1479 }
1480
1481 void ARM64InstPrinter::printMRSSystemRegister(const MCInst *MI, unsigned OpNo,
1482                                            raw_ostream &O) {
1483   unsigned Val = MI->getOperand(OpNo).getImm();
1484
1485   bool Valid;
1486   auto Mapper = ARM64SysReg::MRSMapper();
1487   std::string Name = Mapper.toString(Val, Valid);
1488
1489   if (Valid)
1490     O << StringRef(Name).upper();
1491 }
1492
1493 void ARM64InstPrinter::printMSRSystemRegister(const MCInst *MI, unsigned OpNo,
1494                                            raw_ostream &O) {
1495   unsigned Val = MI->getOperand(OpNo).getImm();
1496
1497   bool Valid;
1498   auto Mapper = ARM64SysReg::MSRMapper();
1499   std::string Name = Mapper.toString(Val, Valid);
1500
1501   if (Valid)
1502     O << StringRef(Name).upper();
1503 }
1504
1505 void ARM64InstPrinter::printSystemCPSRField(const MCInst *MI, unsigned OpNo,
1506                                             raw_ostream &O) {
1507   unsigned Val = MI->getOperand(OpNo).getImm();
1508
1509   bool Valid;
1510   StringRef Name = ARM64PState::PStateMapper().toString(Val, Valid);
1511   if (Valid)
1512     O << StringRef(Name.str()).upper();
1513   else
1514     O << "#" << Val;
1515 }
1516
1517 void ARM64InstPrinter::printSIMDType10Operand(const MCInst *MI, unsigned OpNo,
1518                                               raw_ostream &O) {
1519   unsigned RawVal = MI->getOperand(OpNo).getImm();
1520   uint64_t Val = ARM64_AM::decodeAdvSIMDModImmType10(RawVal);
1521   O << format("#%#016llx", Val);
1522 }