1 //===- ARMInstPrinter.h - Convert ARM MCInst to assembly syntax -*- C++ -*-===// 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 ARM MCInst to a .s file. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMINSTPRINTER_H 14 #define LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMINSTPRINTER_H 15 16 #include "MCTargetDesc/ARMMCTargetDesc.h" 17 #include "llvm/MC/MCInstPrinter.h" 18 19 namespace llvm { 20 21 class ARMInstPrinter : public MCInstPrinter { 22 public: 23 ARMInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, 24 const MCRegisterInfo &MRI); 25 26 bool applyTargetSpecificCLOption(StringRef Opt) override; 27 28 void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, 29 const MCSubtargetInfo &STI, raw_ostream &O) override; 30 void printRegName(raw_ostream &OS, unsigned RegNo) const override; 31 32 // Autogenerated by tblgen. 33 std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override; 34 void printInstruction(const MCInst *MI, uint64_t Address, 35 const MCSubtargetInfo &STI, raw_ostream &O); 36 virtual bool printAliasInstr(const MCInst *MI, uint64_t Address, 37 const MCSubtargetInfo &STI, raw_ostream &O); 38 virtual void printCustomAliasOperand(const MCInst *MI, uint64_t Address, 39 unsigned OpIdx, unsigned PrintMethodIdx, 40 const MCSubtargetInfo &STI, 41 raw_ostream &O); 42 static const char *getRegisterName(unsigned RegNo, 43 unsigned AltIdx = ARM::NoRegAltName); 44 45 void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, 46 raw_ostream &O); 47 void printOperand(const MCInst *MI, uint64_t /*Address*/, unsigned OpNum, 48 const MCSubtargetInfo &STI, raw_ostream &O) { 49 printOperand(MI, OpNum, STI, O); 50 } 51 52 void printSORegRegOperand(const MCInst *MI, unsigned OpNum, 53 const MCSubtargetInfo &STI, raw_ostream &O); 54 void printSORegImmOperand(const MCInst *MI, unsigned OpNum, 55 const MCSubtargetInfo &STI, raw_ostream &O); 56 57 void printAddrModeTBB(const MCInst *MI, unsigned OpNum, 58 const MCSubtargetInfo &STI, raw_ostream &O); 59 void printAddrModeTBH(const MCInst *MI, unsigned OpNum, 60 const MCSubtargetInfo &STI, raw_ostream &O); 61 void printAddrMode2Operand(const MCInst *MI, unsigned OpNum, 62 const MCSubtargetInfo &STI, raw_ostream &O); 63 void printAM2PostIndexOp(const MCInst *MI, unsigned OpNum, 64 const MCSubtargetInfo &STI, raw_ostream &O); 65 void printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned OpNum, 66 const MCSubtargetInfo &STI, raw_ostream &O); 67 void printAddrMode2OffsetOperand(const MCInst *MI, unsigned OpNum, 68 const MCSubtargetInfo &STI, raw_ostream &O); 69 template <bool AlwaysPrintImm0> 70 void printAddrMode3Operand(const MCInst *MI, unsigned OpNum, 71 const MCSubtargetInfo &STI, raw_ostream &O); 72 void printAddrMode3OffsetOperand(const MCInst *MI, unsigned OpNum, 73 const MCSubtargetInfo &STI, raw_ostream &O); 74 void printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op, raw_ostream &O, 75 bool AlwaysPrintImm0); 76 void printPostIdxImm8Operand(const MCInst *MI, unsigned OpNum, 77 const MCSubtargetInfo &STI, raw_ostream &O); 78 void printPostIdxRegOperand(const MCInst *MI, unsigned OpNum, 79 const MCSubtargetInfo &STI, raw_ostream &O); 80 void printPostIdxImm8s4Operand(const MCInst *MI, unsigned OpNum, 81 const MCSubtargetInfo &STI, raw_ostream &O); 82 83 void printLdStmModeOperand(const MCInst *MI, unsigned OpNum, 84 const MCSubtargetInfo &STI, raw_ostream &O); 85 template <bool AlwaysPrintImm0> 86 void printAddrMode5Operand(const MCInst *MI, unsigned OpNum, 87 const MCSubtargetInfo &STI, raw_ostream &O); 88 template <bool AlwaysPrintImm0> 89 void printAddrMode5FP16Operand(const MCInst *MI, unsigned OpNum, 90 const MCSubtargetInfo &STI, raw_ostream &O); 91 void printAddrMode6Operand(const MCInst *MI, unsigned OpNum, 92 const MCSubtargetInfo &STI, raw_ostream &O); 93 void printAddrMode7Operand(const MCInst *MI, unsigned OpNum, 94 const MCSubtargetInfo &STI, raw_ostream &O); 95 void printAddrMode6OffsetOperand(const MCInst *MI, unsigned OpNum, 96 const MCSubtargetInfo &STI, raw_ostream &O); 97 98 void printBitfieldInvMaskImmOperand(const MCInst *MI, unsigned OpNum, 99 const MCSubtargetInfo &STI, 100 raw_ostream &O); 101 void printMemBOption(const MCInst *MI, unsigned OpNum, 102 const MCSubtargetInfo &STI, raw_ostream &O); 103 void printInstSyncBOption(const MCInst *MI, unsigned OpNum, 104 const MCSubtargetInfo &STI, raw_ostream &O); 105 void printTraceSyncBOption(const MCInst *MI, unsigned OpNum, 106 const MCSubtargetInfo &STI, raw_ostream &O); 107 void printShiftImmOperand(const MCInst *MI, unsigned OpNum, 108 const MCSubtargetInfo &STI, raw_ostream &O); 109 void printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum, 110 const MCSubtargetInfo &STI, raw_ostream &O); 111 void printPKHASRShiftImm(const MCInst *MI, unsigned OpNum, 112 const MCSubtargetInfo &STI, raw_ostream &O); 113 114 template <unsigned scale> 115 void printAdrLabelOperand(const MCInst *MI, unsigned OpNum, 116 const MCSubtargetInfo &STI, raw_ostream &O); 117 template <unsigned scale> 118 void printAdrLabelOperand(const MCInst *MI, uint64_t /*Address*/, 119 unsigned OpNum, const MCSubtargetInfo &STI, 120 raw_ostream &O) { 121 printAdrLabelOperand<scale>(MI, OpNum, STI, O); 122 } 123 void printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum, 124 const MCSubtargetInfo &STI, raw_ostream &O); 125 void printThumbSRImm(const MCInst *MI, unsigned OpNum, 126 const MCSubtargetInfo &STI, raw_ostream &O); 127 void printThumbITMask(const MCInst *MI, unsigned OpNum, 128 const MCSubtargetInfo &STI, raw_ostream &O); 129 void printThumbAddrModeRROperand(const MCInst *MI, unsigned OpNum, 130 const MCSubtargetInfo &STI, raw_ostream &O); 131 void printThumbAddrModeImm5SOperand(const MCInst *MI, unsigned OpNum, 132 const MCSubtargetInfo &STI, 133 raw_ostream &O, unsigned Scale); 134 void printThumbAddrModeImm5S1Operand(const MCInst *MI, unsigned OpNum, 135 const MCSubtargetInfo &STI, 136 raw_ostream &O); 137 void printThumbAddrModeImm5S2Operand(const MCInst *MI, unsigned OpNum, 138 const MCSubtargetInfo &STI, 139 raw_ostream &O); 140 void printThumbAddrModeImm5S4Operand(const MCInst *MI, unsigned OpNum, 141 const MCSubtargetInfo &STI, 142 raw_ostream &O); 143 void printThumbAddrModeSPOperand(const MCInst *MI, unsigned OpNum, 144 const MCSubtargetInfo &STI, raw_ostream &O); 145 146 void printT2SOOperand(const MCInst *MI, unsigned OpNum, 147 const MCSubtargetInfo &STI, raw_ostream &O); 148 template <bool AlwaysPrintImm0> 149 void printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum, 150 const MCSubtargetInfo &STI, raw_ostream &O); 151 template <bool AlwaysPrintImm0> 152 void printT2AddrModeImm8Operand(const MCInst *MI, unsigned OpNum, 153 const MCSubtargetInfo &STI, raw_ostream &O); 154 template <bool AlwaysPrintImm0> 155 void printT2AddrModeImm8s4Operand(const MCInst *MI, unsigned OpNum, 156 const MCSubtargetInfo &STI, raw_ostream &O); 157 void printT2AddrModeImm0_1020s4Operand(const MCInst *MI, unsigned OpNum, 158 const MCSubtargetInfo &STI, 159 raw_ostream &O); 160 void printT2AddrModeImm8OffsetOperand(const MCInst *MI, unsigned OpNum, 161 const MCSubtargetInfo &STI, 162 raw_ostream &O); 163 void printT2AddrModeImm8s4OffsetOperand(const MCInst *MI, unsigned OpNum, 164 const MCSubtargetInfo &STI, 165 raw_ostream &O); 166 void printT2AddrModeSoRegOperand(const MCInst *MI, unsigned OpNum, 167 const MCSubtargetInfo &STI, raw_ostream &O); 168 169 void printSetendOperand(const MCInst *MI, unsigned OpNum, 170 const MCSubtargetInfo &STI, raw_ostream &O); 171 void printCPSIMod(const MCInst *MI, unsigned OpNum, 172 const MCSubtargetInfo &STI, raw_ostream &O); 173 void printCPSIFlag(const MCInst *MI, unsigned OpNum, 174 const MCSubtargetInfo &STI, raw_ostream &O); 175 void printMSRMaskOperand(const MCInst *MI, unsigned OpNum, 176 const MCSubtargetInfo &STI, raw_ostream &O); 177 void printBankedRegOperand(const MCInst *MI, unsigned OpNum, 178 const MCSubtargetInfo &STI, raw_ostream &O); 179 void printPredicateOperand(const MCInst *MI, unsigned OpNum, 180 const MCSubtargetInfo &STI, raw_ostream &O); 181 void printMandatoryPredicateOperand(const MCInst *MI, unsigned OpNum, 182 const MCSubtargetInfo &STI, 183 raw_ostream &O); 184 void printMandatoryRestrictedPredicateOperand(const MCInst *MI, 185 unsigned OpNum, 186 const MCSubtargetInfo &STI, 187 raw_ostream &O); 188 void printMandatoryInvertedPredicateOperand(const MCInst *MI, unsigned OpNum, 189 const MCSubtargetInfo &STI, 190 raw_ostream &O); 191 void printSBitModifierOperand(const MCInst *MI, unsigned OpNum, 192 const MCSubtargetInfo &STI, raw_ostream &O); 193 void printRegisterList(const MCInst *MI, unsigned OpNum, 194 const MCSubtargetInfo &STI, raw_ostream &O); 195 void printNoHashImmediate(const MCInst *MI, unsigned OpNum, 196 const MCSubtargetInfo &STI, raw_ostream &O); 197 void printPImmediate(const MCInst *MI, unsigned OpNum, 198 const MCSubtargetInfo &STI, raw_ostream &O); 199 void printCImmediate(const MCInst *MI, unsigned OpNum, 200 const MCSubtargetInfo &STI, raw_ostream &O); 201 void printCoprocOptionImm(const MCInst *MI, unsigned OpNum, 202 const MCSubtargetInfo &STI, raw_ostream &O); 203 void printFPImmOperand(const MCInst *MI, unsigned OpNum, 204 const MCSubtargetInfo &STI, raw_ostream &O); 205 void printVMOVModImmOperand(const MCInst *MI, unsigned OpNum, 206 const MCSubtargetInfo &STI, raw_ostream &O); 207 void printImmPlusOneOperand(const MCInst *MI, unsigned OpNum, 208 const MCSubtargetInfo &STI, raw_ostream &O); 209 void printRotImmOperand(const MCInst *MI, unsigned OpNum, 210 const MCSubtargetInfo &STI, raw_ostream &O); 211 void printModImmOperand(const MCInst *MI, unsigned OpNum, 212 const MCSubtargetInfo &STI, raw_ostream &O); 213 void printGPRPairOperand(const MCInst *MI, unsigned OpNum, 214 const MCSubtargetInfo &STI, raw_ostream &O); 215 216 void printPCLabel(const MCInst *MI, unsigned OpNum, 217 const MCSubtargetInfo &STI, raw_ostream &O); 218 void printThumbLdrLabelOperand(const MCInst *MI, unsigned OpNum, 219 const MCSubtargetInfo &STI, raw_ostream &O); 220 void printThumbLdrLabelOperand(const MCInst *MI, uint64_t /*Address*/, 221 unsigned OpNum, const MCSubtargetInfo &STI, 222 raw_ostream &O) { 223 printThumbLdrLabelOperand(MI, OpNum, STI, O); 224 } 225 void printFBits16(const MCInst *MI, unsigned OpNum, 226 const MCSubtargetInfo &STI, raw_ostream &O); 227 void printFBits32(const MCInst *MI, unsigned OpNum, 228 const MCSubtargetInfo &STI, raw_ostream &O); 229 void printVectorIndex(const MCInst *MI, unsigned OpNum, 230 const MCSubtargetInfo &STI, raw_ostream &O); 231 void printVectorListOne(const MCInst *MI, unsigned OpNum, 232 const MCSubtargetInfo &STI, raw_ostream &O); 233 void printVectorListTwo(const MCInst *MI, unsigned OpNum, 234 const MCSubtargetInfo &STI, raw_ostream &O); 235 void printVectorListTwoSpaced(const MCInst *MI, unsigned OpNum, 236 const MCSubtargetInfo &STI, raw_ostream &O); 237 void printVectorListThree(const MCInst *MI, unsigned OpNum, 238 const MCSubtargetInfo &STI, raw_ostream &O); 239 void printVectorListFour(const MCInst *MI, unsigned OpNum, 240 const MCSubtargetInfo &STI, raw_ostream &O); 241 void printVectorListOneAllLanes(const MCInst *MI, unsigned OpNum, 242 const MCSubtargetInfo &STI, raw_ostream &O); 243 void printVectorListTwoAllLanes(const MCInst *MI, unsigned OpNum, 244 const MCSubtargetInfo &STI, raw_ostream &O); 245 void printVectorListThreeAllLanes(const MCInst *MI, unsigned OpNum, 246 const MCSubtargetInfo &STI, raw_ostream &O); 247 void printVectorListFourAllLanes(const MCInst *MI, unsigned OpNum, 248 const MCSubtargetInfo &STI, raw_ostream &O); 249 void printVectorListTwoSpacedAllLanes(const MCInst *MI, unsigned OpNum, 250 const MCSubtargetInfo &STI, 251 raw_ostream &O); 252 void printVectorListThreeSpacedAllLanes(const MCInst *MI, unsigned OpNum, 253 const MCSubtargetInfo &STI, 254 raw_ostream &O); 255 void printVectorListFourSpacedAllLanes(const MCInst *MI, unsigned OpNum, 256 const MCSubtargetInfo &STI, 257 raw_ostream &O); 258 void printVectorListThreeSpaced(const MCInst *MI, unsigned OpNum, 259 const MCSubtargetInfo &STI, raw_ostream &O); 260 void printVectorListFourSpaced(const MCInst *MI, unsigned OpNum, 261 const MCSubtargetInfo &STI, raw_ostream &O); 262 template<unsigned NumRegs> 263 void printMVEVectorList(const MCInst *MI, unsigned OpNum, 264 const MCSubtargetInfo &STI, raw_ostream &O); 265 template<int64_t Angle, int64_t Remainder> 266 void printComplexRotationOp(const MCInst *MI, unsigned OpNum, 267 const MCSubtargetInfo &STI, raw_ostream &O); 268 // MVE 269 void printVPTPredicateOperand(const MCInst *MI, unsigned OpNum, 270 const MCSubtargetInfo &STI, 271 raw_ostream &O); 272 void printVPTMask(const MCInst *MI, unsigned OpNum, 273 const MCSubtargetInfo &STI, raw_ostream &O); 274 template<int shift> 275 void printMveAddrModeRQOperand(const MCInst *MI, unsigned OpNum, 276 const MCSubtargetInfo &STI, raw_ostream &O); 277 void printMveAddrModeQOperand(const MCInst *MI, unsigned OpNum, 278 const MCSubtargetInfo &STI, raw_ostream &O); 279 void printMveSaturateOp(const MCInst *MI, unsigned OpNum, 280 const MCSubtargetInfo &STI, raw_ostream &O); 281 private: 282 unsigned DefaultAltIdx = ARM::NoRegAltName; 283 }; 284 285 } // end namespace llvm 286 287 #endif // LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMINSTPRINTER_H 288