AArch64InstPrinter.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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, unsigned RegNo) const override;
  27. // Autogenerated by tblgen.
  28. std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
  29. virtual void printInstruction(const MCInst *MI, uint64_t Address,
  30. const MCSubtargetInfo &STI, raw_ostream &O);
  31. virtual bool printAliasInstr(const MCInst *MI, uint64_t Address,
  32. const MCSubtargetInfo &STI, raw_ostream &O);
  33. virtual void printCustomAliasOperand(const MCInst *MI, uint64_t Address,
  34. unsigned OpIdx, unsigned PrintMethodIdx,
  35. const MCSubtargetInfo &STI,
  36. raw_ostream &O);
  37. virtual StringRef getRegName(unsigned RegNo) const {
  38. return getRegisterName(RegNo);
  39. }
  40. static const char *getRegisterName(unsigned RegNo,
  41. unsigned AltIdx = AArch64::NoRegAltName);
  42. protected:
  43. bool printSysAlias(const MCInst *MI, const MCSubtargetInfo &STI,
  44. raw_ostream &O);
  45. // Operand printers
  46. void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
  47. raw_ostream &O);
  48. void printImm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
  49. raw_ostream &O);
  50. void printImmHex(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
  51. raw_ostream &O);
  52. template <int Size>
  53. void printSImm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
  54. raw_ostream &O);
  55. template <typename T> void printImmSVE(T Value, raw_ostream &O);
  56. void printPostIncOperand(const MCInst *MI, unsigned OpNo, unsigned Imm,
  57. raw_ostream &O);
  58. template <int Amount>
  59. void printPostIncOperand(const MCInst *MI, unsigned OpNo,
  60. const MCSubtargetInfo &STI, raw_ostream &O) {
  61. printPostIncOperand(MI, OpNo, Amount, O);
  62. }
  63. void printVRegOperand(const MCInst *MI, unsigned OpNo,
  64. const MCSubtargetInfo &STI, raw_ostream &O);
  65. void printSysCROperand(const MCInst *MI, unsigned OpNo,
  66. const MCSubtargetInfo &STI, raw_ostream &O);
  67. void printAddSubImm(const MCInst *MI, unsigned OpNum,
  68. const MCSubtargetInfo &STI, raw_ostream &O);
  69. template <typename T>
  70. void printLogicalImm(const MCInst *MI, unsigned OpNum,
  71. const MCSubtargetInfo &STI, raw_ostream &O);
  72. void printShifter(const MCInst *MI, unsigned OpNum,
  73. const MCSubtargetInfo &STI, raw_ostream &O);
  74. void printShiftedRegister(const MCInst *MI, unsigned OpNum,
  75. const MCSubtargetInfo &STI, raw_ostream &O);
  76. void printExtendedRegister(const MCInst *MI, unsigned OpNum,
  77. const MCSubtargetInfo &STI, raw_ostream &O);
  78. void printArithExtend(const MCInst *MI, unsigned OpNum,
  79. const MCSubtargetInfo &STI, raw_ostream &O);
  80. void printMemExtend(const MCInst *MI, unsigned OpNum, raw_ostream &O,
  81. char SrcRegKind, unsigned Width);
  82. template <char SrcRegKind, unsigned Width>
  83. void printMemExtend(const MCInst *MI, unsigned OpNum,
  84. const MCSubtargetInfo &STI, raw_ostream &O) {
  85. printMemExtend(MI, OpNum, O, SrcRegKind, Width);
  86. }
  87. template <bool SignedExtend, int ExtWidth, char SrcRegKind, char Suffix>
  88. void printRegWithShiftExtend(const MCInst *MI, unsigned OpNum,
  89. const MCSubtargetInfo &STI, raw_ostream &O);
  90. void printCondCode(const MCInst *MI, unsigned OpNum,
  91. const MCSubtargetInfo &STI, raw_ostream &O);
  92. void printInverseCondCode(const MCInst *MI, unsigned OpNum,
  93. const MCSubtargetInfo &STI, raw_ostream &O);
  94. void printAlignedLabel(const MCInst *MI, uint64_t Address, unsigned OpNum,
  95. const MCSubtargetInfo &STI, raw_ostream &O);
  96. void printUImm12Offset(const MCInst *MI, unsigned OpNum, unsigned Scale,
  97. raw_ostream &O);
  98. void printAMIndexedWB(const MCInst *MI, unsigned OpNum, unsigned Scale,
  99. raw_ostream &O);
  100. template <int Scale>
  101. void printUImm12Offset(const MCInst *MI, unsigned OpNum,
  102. const MCSubtargetInfo &STI, raw_ostream &O) {
  103. printUImm12Offset(MI, OpNum, Scale, O);
  104. }
  105. template <int BitWidth>
  106. void printAMIndexedWB(const MCInst *MI, unsigned OpNum,
  107. const MCSubtargetInfo &STI, raw_ostream &O) {
  108. printAMIndexedWB(MI, OpNum, BitWidth / 8, O);
  109. }
  110. void printAMNoIndex(const MCInst *MI, unsigned OpNum,
  111. const MCSubtargetInfo &STI, raw_ostream &O);
  112. template <int Scale>
  113. void printImmScale(const MCInst *MI, unsigned OpNum,
  114. const MCSubtargetInfo &STI, raw_ostream &O);
  115. template <bool IsSVEPrefetch = false>
  116. void printPrefetchOp(const MCInst *MI, unsigned OpNum,
  117. const MCSubtargetInfo &STI, raw_ostream &O);
  118. void printPSBHintOp(const MCInst *MI, unsigned OpNum,
  119. const MCSubtargetInfo &STI, raw_ostream &O);
  120. void printBTIHintOp(const MCInst *MI, unsigned OpNum,
  121. const MCSubtargetInfo &STI, raw_ostream &O);
  122. void printFPImmOperand(const MCInst *MI, unsigned OpNum,
  123. const MCSubtargetInfo &STI, raw_ostream &O);
  124. void printVectorList(const MCInst *MI, unsigned OpNum,
  125. const MCSubtargetInfo &STI, raw_ostream &O,
  126. StringRef LayoutSuffix);
  127. void printMatrixTileList(const MCInst *MI, unsigned OpNum,
  128. const MCSubtargetInfo &STI, raw_ostream &O);
  129. /// Print a list of vector registers where the type suffix is implicit
  130. /// (i.e. attached to the instruction rather than the registers).
  131. void printImplicitlyTypedVectorList(const MCInst *MI, unsigned OpNum,
  132. const MCSubtargetInfo &STI,
  133. raw_ostream &O);
  134. template <unsigned NumLanes, char LaneKind>
  135. void printTypedVectorList(const MCInst *MI, unsigned OpNum,
  136. const MCSubtargetInfo &STI, raw_ostream &O);
  137. void printVectorIndex(const MCInst *MI, unsigned OpNum,
  138. const MCSubtargetInfo &STI, raw_ostream &O);
  139. void printMatrixIndex(const MCInst *MI, unsigned OpNum,
  140. const MCSubtargetInfo &STI, raw_ostream &O);
  141. void printAdrpLabel(const MCInst *MI, uint64_t Address, unsigned OpNum,
  142. const MCSubtargetInfo &STI, raw_ostream &O);
  143. void printBarrierOption(const MCInst *MI, unsigned OpNum,
  144. const MCSubtargetInfo &STI, raw_ostream &O);
  145. void printBarriernXSOption(const MCInst *MI, unsigned OpNum,
  146. const MCSubtargetInfo &STI, raw_ostream &O);
  147. void printMSRSystemRegister(const MCInst *MI, unsigned OpNum,
  148. const MCSubtargetInfo &STI, raw_ostream &O);
  149. void printMRSSystemRegister(const MCInst *MI, unsigned OpNum,
  150. const MCSubtargetInfo &STI, raw_ostream &O);
  151. void printSystemPStateField(const MCInst *MI, unsigned OpNum,
  152. const MCSubtargetInfo &STI, raw_ostream &O);
  153. void printSIMDType10Operand(const MCInst *MI, unsigned OpNum,
  154. const MCSubtargetInfo &STI, raw_ostream &O);
  155. template<int64_t Angle, int64_t Remainder>
  156. void printComplexRotationOp(const MCInst *MI, unsigned OpNo,
  157. const MCSubtargetInfo &STI, raw_ostream &O);
  158. template<unsigned size>
  159. void printGPRSeqPairsClassOperand(const MCInst *MI, unsigned OpNum,
  160. const MCSubtargetInfo &STI,
  161. raw_ostream &O);
  162. template <typename T>
  163. void printImm8OptLsl(const MCInst *MI, unsigned OpNum,
  164. const MCSubtargetInfo &STI, raw_ostream &O);
  165. template <typename T>
  166. void printSVELogicalImm(const MCInst *MI, unsigned OpNum,
  167. const MCSubtargetInfo &STI, raw_ostream &O);
  168. void printSVEPattern(const MCInst *MI, unsigned OpNum,
  169. const MCSubtargetInfo &STI, raw_ostream &O);
  170. template <bool IsVertical>
  171. void printMatrixTileVector(const MCInst *MI, unsigned OpNum,
  172. const MCSubtargetInfo &STI, raw_ostream &O);
  173. void printMatrixTile(const MCInst *MI, unsigned OpNum,
  174. const MCSubtargetInfo &STI, raw_ostream &O);
  175. template <int EltSize>
  176. void printMatrix(const MCInst *MI, unsigned OpNum, const MCSubtargetInfo &STI,
  177. raw_ostream &O);
  178. void printSVCROp(const MCInst *MI, unsigned OpNum, const MCSubtargetInfo &STI,
  179. raw_ostream &O);
  180. template <char = 0>
  181. void printSVERegOp(const MCInst *MI, unsigned OpNum,
  182. const MCSubtargetInfo &STI, raw_ostream &O);
  183. void printGPR64as32(const MCInst *MI, unsigned OpNum,
  184. const MCSubtargetInfo &STI, raw_ostream &O);
  185. void printGPR64x8(const MCInst *MI, unsigned OpNum,
  186. const MCSubtargetInfo &STI, raw_ostream &O);
  187. template <int Width>
  188. void printZPRasFPR(const MCInst *MI, unsigned OpNum,
  189. const MCSubtargetInfo &STI, raw_ostream &O);
  190. template <unsigned ImmIs0, unsigned ImmIs1>
  191. void printExactFPImm(const MCInst *MI, unsigned OpNum,
  192. const MCSubtargetInfo &STI, raw_ostream &O);
  193. };
  194. class AArch64AppleInstPrinter : public AArch64InstPrinter {
  195. public:
  196. AArch64AppleInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
  197. const MCRegisterInfo &MRI);
  198. void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
  199. const MCSubtargetInfo &STI, raw_ostream &O) override;
  200. std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
  201. void printInstruction(const MCInst *MI, uint64_t Address,
  202. const MCSubtargetInfo &STI, raw_ostream &O) override;
  203. bool printAliasInstr(const MCInst *MI, uint64_t Address,
  204. const MCSubtargetInfo &STI, raw_ostream &O) override;
  205. void printCustomAliasOperand(const MCInst *MI, uint64_t Address,
  206. unsigned OpIdx, unsigned PrintMethodIdx,
  207. const MCSubtargetInfo &STI,
  208. raw_ostream &O) override;
  209. StringRef getRegName(unsigned RegNo) const override {
  210. return getRegisterName(RegNo);
  211. }
  212. static const char *getRegisterName(unsigned RegNo,
  213. unsigned AltIdx = AArch64::NoRegAltName);
  214. };
  215. } // end namespace llvm
  216. #endif // LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64INSTPRINTER_H