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