AArch64InstPrinter.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //===-- AArch64InstPrinter.h - Convert AArch64 MCInst to assembly syntax --===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This class prints an AArch64 MCInst to a .s file.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64INSTPRINTER_H
  13. #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64INSTPRINTER_H
  14. #include "MCTargetDesc/AArch64MCTargetDesc.h"
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/MC/MCInstPrinter.h"
  17. #include "../Utils/AArch64BaseInfo.h"
  18. namespace llvm {
  19. class AArch64InstPrinter : public MCInstPrinter {
  20. public:
  21. AArch64InstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
  22. const MCRegisterInfo &MRI);
  23. bool applyTargetSpecificCLOption(StringRef Opt) override;
  24. void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
  25. const MCSubtargetInfo &STI, raw_ostream &O) override;
  26. void printRegName(raw_ostream &OS, MCRegister Reg) const override;
  27. void printRegName(raw_ostream &OS, MCRegister Reg, unsigned AltIdx) const;
  28. // Autogenerated by tblgen.
  29. std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
  30. virtual void printInstruction(const MCInst *MI, uint64_t Address,
  31. const MCSubtargetInfo &STI, raw_ostream &O);
  32. virtual bool printAliasInstr(const MCInst *MI, uint64_t Address,
  33. const MCSubtargetInfo &STI, raw_ostream &O);
  34. virtual void printCustomAliasOperand(const MCInst *MI, uint64_t Address,
  35. unsigned OpIdx, unsigned PrintMethodIdx,
  36. const MCSubtargetInfo &STI,
  37. raw_ostream &O);
  38. virtual StringRef getRegName(MCRegister Reg) const;
  39. static const char *getRegisterName(MCRegister Reg,
  40. unsigned AltIdx = AArch64::NoRegAltName);
  41. protected:
  42. bool printSysAlias(const MCInst *MI, const MCSubtargetInfo &STI,
  43. raw_ostream &O);
  44. bool printSyspAlias(const MCInst *MI, const MCSubtargetInfo &STI,
  45. raw_ostream &O);
  46. bool printRangePrefetchAlias(const MCInst *MI, const MCSubtargetInfo &STI,
  47. raw_ostream &O, StringRef Annot);
  48. // Operand printers
  49. void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
  50. raw_ostream &O);
  51. void printImm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
  52. raw_ostream &O);
  53. void printImmHex(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
  54. raw_ostream &O);
  55. template <int Size>
  56. void printSImm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
  57. raw_ostream &O);
  58. template <typename T> void printImmSVE(T Value, raw_ostream &O);
  59. void printPostIncOperand(const MCInst *MI, unsigned OpNo, unsigned Imm,
  60. raw_ostream &O);
  61. template <int Amount>
  62. void printPostIncOperand(const MCInst *MI, unsigned OpNo,
  63. const MCSubtargetInfo &STI, raw_ostream &O) {
  64. printPostIncOperand(MI, OpNo, Amount, O);
  65. }
  66. void printVRegOperand(const MCInst *MI, unsigned OpNo,
  67. const MCSubtargetInfo &STI, raw_ostream &O);
  68. void printSysCROperand(const MCInst *MI, unsigned OpNo,
  69. const MCSubtargetInfo &STI, raw_ostream &O);
  70. void printAddSubImm(const MCInst *MI, unsigned OpNum,
  71. const MCSubtargetInfo &STI, raw_ostream &O);
  72. template <typename T>
  73. void printLogicalImm(const MCInst *MI, unsigned OpNum,
  74. const MCSubtargetInfo &STI, raw_ostream &O);
  75. void printShifter(const MCInst *MI, unsigned OpNum,
  76. const MCSubtargetInfo &STI, raw_ostream &O);
  77. void printShiftedRegister(const MCInst *MI, unsigned OpNum,
  78. const MCSubtargetInfo &STI, raw_ostream &O);
  79. void printExtendedRegister(const MCInst *MI, unsigned OpNum,
  80. const MCSubtargetInfo &STI, raw_ostream &O);
  81. void printArithExtend(const MCInst *MI, unsigned OpNum,
  82. const MCSubtargetInfo &STI, raw_ostream &O);
  83. void printMemExtend(const MCInst *MI, unsigned OpNum, raw_ostream &O,
  84. char SrcRegKind, unsigned Width);
  85. template <char SrcRegKind, unsigned Width>
  86. void printMemExtend(const MCInst *MI, unsigned OpNum,
  87. const MCSubtargetInfo &STI, raw_ostream &O) {
  88. printMemExtend(MI, OpNum, O, SrcRegKind, Width);
  89. }
  90. template <bool SignedExtend, int ExtWidth, char SrcRegKind, char Suffix>
  91. void printRegWithShiftExtend(const MCInst *MI, unsigned OpNum,
  92. const MCSubtargetInfo &STI, raw_ostream &O);
  93. void printCondCode(const MCInst *MI, unsigned OpNum,
  94. const MCSubtargetInfo &STI, raw_ostream &O);
  95. void printInverseCondCode(const MCInst *MI, unsigned OpNum,
  96. const MCSubtargetInfo &STI, raw_ostream &O);
  97. void printAlignedLabel(const MCInst *MI, uint64_t Address, unsigned OpNum,
  98. const MCSubtargetInfo &STI, raw_ostream &O);
  99. void printUImm12Offset(const MCInst *MI, unsigned OpNum, unsigned Scale,
  100. raw_ostream &O);
  101. void printAMIndexedWB(const MCInst *MI, unsigned OpNum, unsigned Scale,
  102. raw_ostream &O);
  103. template <int Scale>
  104. void printUImm12Offset(const MCInst *MI, unsigned OpNum,
  105. const MCSubtargetInfo &STI, raw_ostream &O) {
  106. printUImm12Offset(MI, OpNum, Scale, O);
  107. }
  108. template <int BitWidth>
  109. void printAMIndexedWB(const MCInst *MI, unsigned OpNum,
  110. const MCSubtargetInfo &STI, raw_ostream &O) {
  111. printAMIndexedWB(MI, OpNum, BitWidth / 8, O);
  112. }
  113. void printAMNoIndex(const MCInst *MI, unsigned OpNum,
  114. const MCSubtargetInfo &STI, raw_ostream &O);
  115. template <int Scale>
  116. void printImmScale(const MCInst *MI, unsigned OpNum,
  117. const MCSubtargetInfo &STI, raw_ostream &O);
  118. template <int Scale, int Offset>
  119. void printImmRangeScale(const MCInst *MI, unsigned OpNum,
  120. const MCSubtargetInfo &STI, raw_ostream &O);
  121. template <bool IsSVEPrefetch = false>
  122. void printPrefetchOp(const MCInst *MI, unsigned OpNum,
  123. const MCSubtargetInfo &STI, raw_ostream &O);
  124. void printRPRFMOperand(const MCInst *MI, unsigned OpNum,
  125. const MCSubtargetInfo &STI, raw_ostream &O);
  126. void printPSBHintOp(const MCInst *MI, unsigned OpNum,
  127. const MCSubtargetInfo &STI, raw_ostream &O);
  128. void printBTIHintOp(const MCInst *MI, unsigned OpNum,
  129. const MCSubtargetInfo &STI, raw_ostream &O);
  130. void printFPImmOperand(const MCInst *MI, unsigned OpNum,
  131. const MCSubtargetInfo &STI, raw_ostream &O);
  132. void printVectorList(const MCInst *MI, unsigned OpNum,
  133. const MCSubtargetInfo &STI, raw_ostream &O,
  134. StringRef LayoutSuffix);
  135. void printMatrixTileList(const MCInst *MI, unsigned OpNum,
  136. const MCSubtargetInfo &STI, raw_ostream &O);
  137. /// Print a list of vector registers where the type suffix is implicit
  138. /// (i.e. attached to the instruction rather than the registers).
  139. void printImplicitlyTypedVectorList(const MCInst *MI, unsigned OpNum,
  140. const MCSubtargetInfo &STI,
  141. raw_ostream &O);
  142. template <unsigned NumLanes, char LaneKind>
  143. void printTypedVectorList(const MCInst *MI, unsigned OpNum,
  144. const MCSubtargetInfo &STI, raw_ostream &O);
  145. template <unsigned Scale = 1>
  146. void printVectorIndex(const MCInst *MI, unsigned OpNum,
  147. const MCSubtargetInfo &STI, raw_ostream &O);
  148. void printMatrixIndex(const MCInst *MI, unsigned OpNum,
  149. const MCSubtargetInfo &STI, raw_ostream &O);
  150. void printAdrpLabel(const MCInst *MI, uint64_t Address, unsigned OpNum,
  151. const MCSubtargetInfo &STI, raw_ostream &O);
  152. void printBarrierOption(const MCInst *MI, unsigned OpNum,
  153. const MCSubtargetInfo &STI, raw_ostream &O);
  154. void printBarriernXSOption(const MCInst *MI, unsigned OpNum,
  155. const MCSubtargetInfo &STI, raw_ostream &O);
  156. void printMSRSystemRegister(const MCInst *MI, unsigned OpNum,
  157. const MCSubtargetInfo &STI, raw_ostream &O);
  158. void printMRSSystemRegister(const MCInst *MI, unsigned OpNum,
  159. const MCSubtargetInfo &STI, raw_ostream &O);
  160. void printSystemPStateField(const MCInst *MI, unsigned OpNum,
  161. const MCSubtargetInfo &STI, raw_ostream &O);
  162. void printSIMDType10Operand(const MCInst *MI, unsigned OpNum,
  163. const MCSubtargetInfo &STI, raw_ostream &O);
  164. template <int EltSize>
  165. void printPredicateAsCounter(const MCInst *MI, unsigned OpNum,
  166. const MCSubtargetInfo &STI, raw_ostream &O);
  167. template<int64_t Angle, int64_t Remainder>
  168. void printComplexRotationOp(const MCInst *MI, unsigned OpNo,
  169. const MCSubtargetInfo &STI, raw_ostream &O);
  170. template<unsigned size>
  171. void printGPRSeqPairsClassOperand(const MCInst *MI, unsigned OpNum,
  172. const MCSubtargetInfo &STI,
  173. raw_ostream &O);
  174. template <typename T>
  175. void printImm8OptLsl(const MCInst *MI, unsigned OpNum,
  176. const MCSubtargetInfo &STI, raw_ostream &O);
  177. template <typename T>
  178. void printSVELogicalImm(const MCInst *MI, unsigned OpNum,
  179. const MCSubtargetInfo &STI, raw_ostream &O);
  180. void printSVEPattern(const MCInst *MI, unsigned OpNum,
  181. const MCSubtargetInfo &STI, raw_ostream &O);
  182. void printSVEVecLenSpecifier(const MCInst *MI, unsigned OpNum,
  183. const MCSubtargetInfo &STI, raw_ostream &O);
  184. template <bool IsVertical>
  185. void printMatrixTileVector(const MCInst *MI, unsigned OpNum,
  186. const MCSubtargetInfo &STI, raw_ostream &O);
  187. void printMatrixTile(const MCInst *MI, unsigned OpNum,
  188. const MCSubtargetInfo &STI, raw_ostream &O);
  189. template <int EltSize>
  190. void printMatrix(const MCInst *MI, unsigned OpNum, const MCSubtargetInfo &STI,
  191. raw_ostream &O);
  192. void printSVCROp(const MCInst *MI, unsigned OpNum, const MCSubtargetInfo &STI,
  193. raw_ostream &O);
  194. template <char = 0>
  195. void printSVERegOp(const MCInst *MI, unsigned OpNum,
  196. const MCSubtargetInfo &STI, raw_ostream &O);
  197. void printGPR64as32(const MCInst *MI, unsigned OpNum,
  198. const MCSubtargetInfo &STI, raw_ostream &O);
  199. void printGPR64x8(const MCInst *MI, unsigned OpNum,
  200. const MCSubtargetInfo &STI, raw_ostream &O);
  201. void printSyspXzrPair(const MCInst *MI, unsigned OpNum,
  202. const MCSubtargetInfo &STI, raw_ostream &O);
  203. template <int Width>
  204. void printZPRasFPR(const MCInst *MI, unsigned OpNum,
  205. const MCSubtargetInfo &STI, raw_ostream &O);
  206. template <unsigned ImmIs0, unsigned ImmIs1>
  207. void printExactFPImm(const MCInst *MI, unsigned OpNum,
  208. const MCSubtargetInfo &STI, raw_ostream &O);
  209. };
  210. class AArch64AppleInstPrinter : public AArch64InstPrinter {
  211. public:
  212. AArch64AppleInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
  213. const MCRegisterInfo &MRI);
  214. void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
  215. const MCSubtargetInfo &STI, raw_ostream &O) override;
  216. std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
  217. void printInstruction(const MCInst *MI, uint64_t Address,
  218. const MCSubtargetInfo &STI, raw_ostream &O) override;
  219. bool printAliasInstr(const MCInst *MI, uint64_t Address,
  220. const MCSubtargetInfo &STI, raw_ostream &O) override;
  221. void printCustomAliasOperand(const MCInst *MI, uint64_t Address,
  222. unsigned OpIdx, unsigned PrintMethodIdx,
  223. const MCSubtargetInfo &STI,
  224. raw_ostream &O) override;
  225. StringRef getRegName(MCRegister Reg) const override;
  226. static const char *getRegisterName(MCRegister Reg,
  227. unsigned AltIdx = AArch64::NoRegAltName);
  228. };
  229. } // end namespace llvm
  230. #endif // LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64INSTPRINTER_H