diff --git a/llvm/include/llvm/MC/MCInstPrinter.h b/llvm/include/llvm/MC/MCInstPrinter.h --- a/llvm/include/llvm/MC/MCInstPrinter.h +++ b/llvm/include/llvm/MC/MCInstPrinter.h @@ -16,13 +16,14 @@ class MCAsmInfo; class MCInst; -class MCOperand; -class MCInstrInfo; class MCInstrAnalysis; +class MCInstrInfo; +class MCOperand; +class MCRegister; class MCRegisterInfo; class MCSubtargetInfo; -class raw_ostream; class StringRef; +class raw_ostream; /// Convert `Bytes' to a hex string and output to `OS' void dumpBytes(ArrayRef Bytes, raw_ostream &OS); @@ -110,7 +111,7 @@ StringRef getOpcodeName(unsigned Opcode) const; /// Print the assembler register name. - virtual void printRegName(raw_ostream &OS, unsigned RegNo) const; + virtual void printRegName(raw_ostream &OS, MCRegister Reg) const; bool getUseMarkup() const { return UseMarkup; } void setUseMarkup(bool Value) { UseMarkup = Value; } diff --git a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h --- a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h +++ b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h @@ -378,7 +378,7 @@ return getParser().parsePrimaryExpr(Res, EndLoc, nullptr); } - virtual bool parseRegister(MCRegister &RegNo, SMLoc &StartLoc, + virtual bool parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) = 0; /// tryParseRegister - parse one register if possible @@ -387,7 +387,7 @@ /// location, without failing the entire parse if it can't. Must not consume /// tokens if the parse fails. virtual OperandMatchResultTy - tryParseRegister(MCRegister &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) = 0; + tryParseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) = 0; /// ParseInstruction - Parse one assembly instruction. /// diff --git a/llvm/lib/MC/MCInstPrinter.cpp b/llvm/lib/MC/MCInstPrinter.cpp --- a/llvm/lib/MC/MCInstPrinter.cpp +++ b/llvm/lib/MC/MCInstPrinter.cpp @@ -43,7 +43,7 @@ return MII.getName(Opcode); } -void MCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { +void MCInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { llvm_unreachable("Target should implement this"); } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.h --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.h @@ -29,8 +29,8 @@ void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; - void printRegName(raw_ostream &OS, unsigned RegNo) const override; - void printRegName(raw_ostream &OS, unsigned RegNo, unsigned AltIdx) const; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; + void printRegName(raw_ostream &OS, MCRegister Reg, unsigned AltIdx) const; // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; @@ -43,11 +43,9 @@ const MCSubtargetInfo &STI, raw_ostream &O); - virtual StringRef getRegName(unsigned RegNo) const { - return getRegisterName(RegNo); - } + virtual StringRef getRegName(MCRegister Reg) const; - static const char *getRegisterName(unsigned RegNo, + static const char *getRegisterName(MCRegister Reg, unsigned AltIdx = AArch64::NoRegAltName); protected: @@ -257,11 +255,9 @@ const MCSubtargetInfo &STI, raw_ostream &O) override; - StringRef getRegName(unsigned RegNo) const override { - return getRegisterName(RegNo); - } + StringRef getRegName(MCRegister Reg) const override; - static const char *getRegisterName(unsigned RegNo, + static const char *getRegisterName(MCRegister Reg, unsigned AltIdx = AArch64::NoRegAltName); }; diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp @@ -59,13 +59,17 @@ return false; } -void AArch64InstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << markup(""); +void AArch64InstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << markup(""); } -void AArch64InstPrinter::printRegName(raw_ostream &OS, unsigned RegNo, +void AArch64InstPrinter::printRegName(raw_ostream &OS, MCRegister Reg, unsigned AltIdx) const { - OS << markup(""); + OS << markup(""); +} + +StringRef AArch64InstPrinter::getRegName(MCRegister Reg) const { + return getRegisterName(Reg); } void AArch64InstPrinter::printInst(const MCInst *MI, uint64_t Address, @@ -820,6 +824,10 @@ AArch64InstPrinter::printInst(MI, Address, Annot, STI, O); } +StringRef AArch64AppleInstPrinter::getRegName(MCRegister Reg) const { + return getRegisterName(Reg); +} + bool AArch64InstPrinter::printRangePrefetchAlias(const MCInst *MI, const MCSubtargetInfo &STI, raw_ostream &O, diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h @@ -23,13 +23,13 @@ const MCInstrInfo &MII, const MCRegisterInfo &MRI) : MCInstPrinter(MAI, MII, MRI) {} - //Autogenerated by tblgen - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + // Autogenerated by tblgen std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; static void printRegOperand(unsigned RegNo, raw_ostream &O, diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp @@ -30,7 +30,7 @@ cl::init(false), cl::ReallyHidden); -void AMDGPUInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { +void AMDGPUInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { // FIXME: The current implementation of // AsmParser::parseRegisterOrRegisterNumber in MC implies we either emit this // as an integer or we provide a name which represents a physical register. @@ -43,7 +43,7 @@ // would extend MC to support parsing DWARF register names so we could do // something like `.cfi_undefined dwarf_wave32_v0`. For now we just live with // non-pretty DWARF register names in assembly text. - OS << RegNo; + OS << Reg.id(); } void AMDGPUInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/R600InstPrinter.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/R600InstPrinter.h --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/R600InstPrinter.h +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/R600InstPrinter.h @@ -23,7 +23,7 @@ const MCSubtargetInfo &STI, raw_ostream &O) override; std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); void printAbs(const MCInst *MI, unsigned OpNo, raw_ostream &O); void printBankSwizzle(const MCInst *MI, unsigned OpNo, raw_ostream &O); diff --git a/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h --- a/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h +++ b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h @@ -28,9 +28,9 @@ // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; void printCCOperand(const MCInst *MI, int OpNum, raw_ostream &O); diff --git a/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp --- a/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp +++ b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp @@ -93,8 +93,8 @@ return BadConditionCode(CC); } -void ARCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << StringRef(getRegisterName(RegNo)).lower(); +void ARCInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << StringRef(getRegisterName(Reg)).lower(); } void ARCInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -3895,7 +3895,7 @@ } // end anonymous namespace. void ARMOperand::print(raw_ostream &OS) const { - auto RegName = [](unsigned Reg) { + auto RegName = [](MCRegister Reg) { if (Reg) return ARMInstPrinter::getRegisterName(Reg); else diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.h --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.h +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.h @@ -27,7 +27,7 @@ void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; @@ -39,7 +39,7 @@ unsigned OpIdx, unsigned PrintMethodIdx, const MCSubtargetInfo &STI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo, + static const char *getRegisterName(MCRegister Reg, unsigned AltIdx = ARM::NoRegAltName); void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.cpp --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.cpp @@ -85,8 +85,8 @@ return false; } -void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << markup(""); +void ARMInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << markup(""); } void ARMInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.h b/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.h --- a/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.h +++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.h @@ -33,7 +33,7 @@ const MCSubtargetInfo &STI, raw_ostream &O) override; private: - static const char *getRegisterName(unsigned RegNo, + static const char *getRegisterName(MCRegister Reg, unsigned AltIdx = AVR::NoRegAltName); void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h b/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h @@ -34,7 +34,7 @@ // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); }; } diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp @@ -14,6 +14,7 @@ #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCRegister.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" diff --git a/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp b/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp --- a/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp +++ b/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp @@ -430,7 +430,7 @@ } void print(raw_ostream &OS) const override { - auto RegName = [](unsigned Reg) { + auto RegName = [](MCRegister Reg) { if (Reg) return CSKYInstPrinter::getRegisterName(Reg); else diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.h b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.h --- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.h +++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.h @@ -31,7 +31,7 @@ void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; - void printRegName(raw_ostream &O, unsigned RegNo) const override; + void printRegName(raw_ostream &O, MCRegister Reg) const override; void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O, const char *Modifier = nullptr); @@ -64,8 +64,8 @@ raw_ostream &O); void printFPR(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); - static const char *getRegisterName(unsigned RegNo, unsigned AltIdx); + static const char *getRegisterName(MCRegister Reg); + static const char *getRegisterName(MCRegister Reg, unsigned AltIdx); }; } // namespace llvm diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp --- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp +++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp @@ -82,12 +82,12 @@ printAnnotation(O, Annot); } -void CSKYInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const { +void CSKYInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) const { if (PrintBranchImmAsAddress) - O << getRegisterName(RegNo, ABIRegNames ? CSKY::ABIRegAltName - : CSKY::NoRegAltName); + O << getRegisterName(Reg, ABIRegNames ? CSKY::ABIRegAltName + : CSKY::NoRegAltName); else - O << getRegisterName(RegNo); + O << getRegisterName(Reg); } void CSKYInstPrinter::printFPRRegName(raw_ostream &O, unsigned RegNo) const { @@ -260,9 +260,9 @@ } } -const char *CSKYInstPrinter::getRegisterName(unsigned RegNo) { - return getRegisterName(RegNo, ArchRegNames ? CSKY::NoRegAltName - : CSKY::ABIRegAltName); +const char *CSKYInstPrinter::getRegisterName(MCRegister Reg) { + return getRegisterName(Reg, ArchRegNames ? CSKY::NoRegAltName + : CSKY::ABIRegAltName); } void CSKYInstPrinter::printFPR(const MCInst *MI, unsigned OpNo, diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h @@ -30,9 +30,9 @@ void printInst(MCInst const *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; - void printRegName(raw_ostream &O, unsigned RegNo) const override; + void printRegName(raw_ostream &O, MCRegister Reg) const override; - static char const *getRegisterName(unsigned RegNo); + static char const *getRegisterName(MCRegister Reg); std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp @@ -26,8 +26,8 @@ #define GET_INSTRUCTION_NAME #include "HexagonGenAsmWriter.inc" -void HexagonInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const { - O << getRegisterName(RegNo); +void HexagonInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) const { + O << getRegisterName(Reg); } void HexagonInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.h b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.h --- a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.h +++ b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.h @@ -48,8 +48,8 @@ void printCustomAliasOperand(const MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + static const char *getRegisterName(MCRegister Reg); + void printRegName(raw_ostream &OS, MCRegister Reg) const override; private: bool printAlias(const MCInst *MI, raw_ostream &Ostream); diff --git a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.cpp b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.cpp --- a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.cpp +++ b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.cpp @@ -31,8 +31,8 @@ #define PRINT_ALIAS_INSTR #include "LanaiGenAsmWriter.inc" -void LanaiInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << StringRef(getRegisterName(RegNo)).lower(); +void LanaiInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << StringRef(getRegisterName(Reg)).lower(); } bool LanaiInstPrinter::printInst(const MCInst *MI, raw_ostream &OS, diff --git a/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp b/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp --- a/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp +++ b/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp @@ -443,7 +443,7 @@ } void print(raw_ostream &OS) const override { - auto RegName = [](unsigned Reg) { + auto RegName = [](MCRegister Reg) { if (Reg) return LoongArchInstPrinter::getRegisterName(Reg); else diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.h b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.h --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.h +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.h @@ -26,7 +26,7 @@ void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; - void printRegName(raw_ostream &O, unsigned RegNo) const override; + void printRegName(raw_ostream &O, MCRegister Reg) const override; void printAtomicMemOp(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O); @@ -39,8 +39,8 @@ void printCustomAliasOperand(const MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, const MCSubtargetInfo &STI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); - static const char *getRegisterName(unsigned RegNo, unsigned AltIdx); + static const char *getRegisterName(MCRegister Reg); + static const char *getRegisterName(MCRegister Reg, unsigned AltIdx); private: void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.cpp --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.cpp @@ -34,8 +34,8 @@ printAnnotation(O, Annot); } -void LoongArchInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const { - O << '$' << getRegisterName(RegNo); +void LoongArchInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) const { + O << '$' << getRegisterName(Reg); } void LoongArchInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, @@ -65,7 +65,7 @@ printRegName(O, MO.getReg()); } -const char *LoongArchInstPrinter::getRegisterName(unsigned RegNo) { +const char *LoongArchInstPrinter::getRegisterName(MCRegister Reg) { // Default print reg alias name - return getRegisterName(RegNo, LoongArch::RegAliasName); + return getRegisterName(Reg, LoongArch::RegAliasName); } diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.h b/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.h --- a/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.h +++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.h @@ -28,9 +28,9 @@ // Autogenerated by tblgen. void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.cpp b/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.cpp --- a/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.cpp +++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.cpp @@ -41,8 +41,8 @@ #define PRINT_ALIAS_INSTR #include "M68kGenAsmWriter.inc" -void M68kInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << "%" << getRegisterName(RegNo); +void M68kInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << "%" << getRegisterName(Reg); } void M68kInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.h b/llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.h --- a/llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.h +++ b/llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.h @@ -32,9 +32,9 @@ void printCustomAliasOperand(const MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); -private: + private: void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O, const char *Modifier = nullptr); void printPCRelImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.h --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.h +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.h @@ -82,9 +82,9 @@ std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp @@ -71,8 +71,8 @@ llvm_unreachable("Impossible condition code!"); } -void MipsInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << markup(""); } diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.h b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.h --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.h +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.h @@ -24,14 +24,14 @@ NVPTXInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI); - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS) override; // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); // End void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp @@ -31,16 +31,16 @@ const MCRegisterInfo &MRI) : MCInstPrinter(MAI, MII, MRI) {} -void NVPTXInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { +void NVPTXInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { // Decode the virtual register // Must be kept in sync with NVPTXAsmPrinter::encodeVirtualRegister - unsigned RCId = (RegNo >> 28); + unsigned RCId = (Reg.id() >> 28); switch (RCId) { default: report_fatal_error("Bad virtual register encoding"); case 0: // This is actually a physical register, so defer to the autogenerated // register printer - OS << getRegisterName(RegNo); + OS << getRegisterName(Reg); return; case 1: OS << "%p"; @@ -68,7 +68,7 @@ break; } - unsigned VReg = RegNo & 0x0FFFFFFF; + unsigned VReg = Reg.id() & 0x0FFFFFFF; OS << VReg; } diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h @@ -31,7 +31,7 @@ const MCRegisterInfo &MRI, Triple T) : MCInstPrinter(MAI, MII, MRI), TT(T) {} - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; @@ -39,7 +39,7 @@ std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); bool printAliasInstr(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &OS); diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp @@ -47,8 +47,8 @@ #define PRINT_ALIAS_INSTR #include "PPCGenAsmWriter.inc" -void PPCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - const char *RegName = getRegisterName(RegNo); +void PPCInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + const char *RegName = getRegisterName(Reg); OS << RegName; } diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -809,7 +809,7 @@ } void print(raw_ostream &OS) const override { - auto RegName = [](unsigned Reg) { + auto RegName = [](MCRegister Reg) { if (Reg) return RISCVInstPrinter::getRegisterName(Reg); else diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h @@ -28,7 +28,7 @@ void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; - void printRegName(raw_ostream &O, unsigned RegNo) const override; + void printRegName(raw_ostream &O, MCRegister Reg) const override; void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O, const char *Modifier = nullptr); @@ -56,8 +56,8 @@ void printCustomAliasOperand(const MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, const MCSubtargetInfo &STI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); - static const char *getRegisterName(unsigned RegNo, unsigned AltIdx); + static const char *getRegisterName(MCRegister Reg); + static const char *getRegisterName(MCRegister Reg, unsigned AltIdx); }; } // namespace llvm diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp @@ -78,8 +78,8 @@ printAnnotation(O, Annot); } -void RISCVInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const { - O << getRegisterName(RegNo); +void RISCVInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) const { + O << getRegisterName(Reg); } void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, @@ -194,7 +194,7 @@ O << ".t"; } -const char *RISCVInstPrinter::getRegisterName(unsigned RegNo) { - return getRegisterName(RegNo, ArchRegNames ? RISCV::NoRegAltName - : RISCV::ABIRegAltName); +const char *RISCVInstPrinter::getRegisterName(MCRegister Reg) { + return getRegisterName(Reg, ArchRegNames ? RISCV::NoRegAltName + : RISCV::ABIRegAltName); } diff --git a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.h b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.h --- a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.h +++ b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.h @@ -48,7 +48,7 @@ // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); }; } // namespace llvm diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h b/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h @@ -23,7 +23,7 @@ const MCRegisterInfo &MRI) : MCInstPrinter(MAI, MII, MRI) {} - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; bool printSparcAliasInstr(const MCInst *MI, const MCSubtargetInfo &STI, @@ -39,7 +39,7 @@ void printCustomAliasOperand(const MCInst *MI, uint64_t Address, unsigned OpIdx, unsigned PrintMethodIdx, const MCSubtargetInfo &STI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); void printOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, raw_ostream &OS); diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp @@ -38,9 +38,8 @@ return (STI.getFeatureBits()[Sparc::FeatureV9]) != 0; } -void SparcInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const -{ - OS << '%' << StringRef(getRegisterName(RegNo)).lower(); +void SparcInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << '%' << StringRef(getRegisterName(Reg)).lower(); } void SparcInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp @@ -12,6 +12,7 @@ #include "SparcTargetStreamer.h" #include "SparcInstPrinter.h" +#include "llvm/MC/MCRegister.h" #include "llvm/Support/FormattedStream.h" using namespace llvm; diff --git a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp --- a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -55,8 +55,8 @@ void emitFunctionBodyStart() override; void emitInstruction(const MachineInstr *MI) override; - static const char *getRegisterName(unsigned RegNo) { - return SparcInstPrinter::getRegisterName(RegNo); + static const char *getRegisterName(MCRegister Reg) { + return SparcInstPrinter::getRegisterName(Reg); } bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h @@ -30,22 +30,20 @@ // Automatically generated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); // Print an address with the given base, displacement and index. - void printAddress(const MCAsmInfo *MAI, unsigned Base, - const MCOperand &DispMO, unsigned Index, raw_ostream &O); + void printAddress(const MCAsmInfo *MAI, MCRegister Base, + const MCOperand &DispMO, MCRegister Index, raw_ostream &O); // Print the given operand. void printOperand(const MCOperand &MO, const MCAsmInfo *MAI, raw_ostream &O); - void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo, + void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg, raw_ostream &O) const; // Override MCInstPrinter. - inline void printRegName(raw_ostream &O, unsigned RegNo) const override { - printFormattedRegName(&MAI, RegNo, O); - } + void printRegName(raw_ostream &O, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp @@ -9,6 +9,7 @@ #include "SystemZInstPrinter.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCRegister.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" @@ -23,8 +24,8 @@ #include "SystemZGenAsmWriter.inc" -void SystemZInstPrinter::printAddress(const MCAsmInfo *MAI, unsigned Base, - const MCOperand &DispMO, unsigned Index, +void SystemZInstPrinter::printAddress(const MCAsmInfo *MAI, MCRegister Base, + const MCOperand &DispMO, MCRegister Index, raw_ostream &O) { printOperand(DispMO, MAI, O); if (Base || Index) { @@ -57,9 +58,9 @@ } void SystemZInstPrinter::printFormattedRegName(const MCAsmInfo *MAI, - unsigned RegNo, + MCRegister Reg, raw_ostream &O) const { - const char *RegName = getRegisterName(RegNo); + const char *RegName = getRegisterName(Reg); if (MAI->getAssemblerDialect() == AD_HLASM) { // Skip register prefix so that only register number is left assert(isalpha(RegName[0]) && isdigit(RegName[1])); @@ -68,6 +69,10 @@ O << markup(""); } +void SystemZInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) const { + printFormattedRegName(&MAI, Reg, O); +} + void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) { diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.h b/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.h --- a/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.h +++ b/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.h @@ -24,7 +24,7 @@ const MCRegisterInfo &MRI) : MCInstPrinter(MAI, MII, MRI) {} - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS) override; @@ -34,7 +34,7 @@ const MCSubtargetInfo &, raw_ostream &); void printInstruction(const MCInst *, uint64_t, const MCSubtargetInfo &, raw_ostream &); - static const char *getRegisterName(unsigned RegNo, + static const char *getRegisterName(MCRegister Reg, unsigned AltIdx = VE::NoRegAltName); void printOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.cpp b/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.cpp --- a/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.cpp +++ b/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.cpp @@ -27,13 +27,13 @@ #define PRINT_ALIAS_INSTR #include "VEGenAsmWriter.inc" -void VEInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { +void VEInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { // Generic registers have identical register name among register classes. unsigned AltIdx = VE::AsmName; // Misc registers have each own name, so no use alt-names. - if (MRI.getRegClass(VE::MISCRegClassID).contains(RegNo)) + if (MRI.getRegClass(VE::MISCRegClassID).contains(Reg)) AltIdx = VE::NoRegAltName; - OS << '%' << getRegisterName(RegNo, AltIdx); + OS << '%' << getRegisterName(Reg, AltIdx); } void VEInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/VE/MCTargetDesc/VETargetStreamer.cpp b/llvm/lib/Target/VE/MCTargetDesc/VETargetStreamer.cpp --- a/llvm/lib/Target/VE/MCTargetDesc/VETargetStreamer.cpp +++ b/llvm/lib/Target/VE/MCTargetDesc/VETargetStreamer.cpp @@ -12,6 +12,7 @@ #include "VETargetStreamer.h" #include "VEInstPrinter.h" +#include "llvm/MC/MCRegister.h" using namespace llvm; diff --git a/llvm/lib/Target/VE/VEAsmPrinter.cpp b/llvm/lib/Target/VE/VEAsmPrinter.cpp --- a/llvm/lib/Target/VE/VEAsmPrinter.cpp +++ b/llvm/lib/Target/VE/VEAsmPrinter.cpp @@ -57,8 +57,8 @@ void emitInstruction(const MachineInstr *MI) override; - static const char *getRegisterName(unsigned RegNo) { - return VEInstPrinter::getRegisterName(RegNo); + static const char *getRegisterName(MCRegister Reg) { + return VEInstPrinter::getRegisterName(Reg); } void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &OS); bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h @@ -35,7 +35,7 @@ WebAssemblyInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI); - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS) override; @@ -51,7 +51,7 @@ // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); }; } // end namespace llvm diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp @@ -39,10 +39,10 @@ : MCInstPrinter(MAI, MII, MRI) {} void WebAssemblyInstPrinter::printRegName(raw_ostream &OS, - unsigned RegNo) const { - assert(RegNo != WebAssemblyFunctionInfo::UnusedReg); + MCRegister Reg) const { + assert(Reg.id() != WebAssemblyFunctionInfo::UnusedReg); // Note that there's an implicit local.get/local.set here! - OS << "$" << RegNo; + OS << "$" << Reg.id(); } void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.h b/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.h --- a/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.h +++ b/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.h @@ -23,7 +23,7 @@ const MCRegisterInfo &MRI) : X86InstPrinterCommon(MAI, MII, MRI), HasCustomInstComment(false) {} - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS) override; bool printVecCompareInstr(const MCInst *MI, raw_ostream &OS); @@ -38,7 +38,7 @@ // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &OS); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &OS) override; void printMemReference(const MCInst *MI, unsigned Op, raw_ostream &OS); diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.cpp --- a/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.cpp @@ -35,8 +35,8 @@ #define PRINT_ALIAS_INSTR #include "X86GenAsmWriter.inc" -void X86ATTInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << markup(""); +void X86ATTInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << markup(""); } void X86ATTInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp --- a/llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp @@ -252,7 +252,7 @@ return getVectorRegSize(OpReg) / ScalarSize; } -static const char *getRegName(unsigned Reg) { +static const char *getRegName(MCRegister Reg) { return X86ATTInstPrinter::getRegisterName(Reg); } diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.h b/llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.h --- a/llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.h +++ b/llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.h @@ -24,7 +24,7 @@ const MCRegisterInfo &MRI) : X86InstPrinterCommon(MAI, MII, MRI) {} - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS) override; bool printVecCompareInstr(const MCInst *MI, raw_ostream &OS); @@ -39,7 +39,7 @@ // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) override; void printMemReference(const MCInst *MI, unsigned Op, raw_ostream &O); diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.cpp --- a/llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.cpp @@ -33,8 +33,8 @@ #define PRINT_ALIAS_INSTR #include "X86GenAsmWriter1.inc" -void X86IntelInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << markup(""); +void X86IntelInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << markup(""); } void X86IntelInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -1903,8 +1903,8 @@ // names. Fortunately most people use the ATT style (outside of Windows) // and they actually agree on register naming here. Ultimately, this is // a comment, and so its OK if it isn't perfect. - auto GetRegisterName = [](unsigned RegNum) -> StringRef { - return X86ATTInstPrinter::getRegisterName(RegNum); + auto GetRegisterName = [](MCRegister Reg) -> StringRef { + return X86ATTInstPrinter::getRegisterName(Reg); }; const MachineOperand &DstOp = MI->getOperand(0); diff --git a/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.h b/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.h --- a/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.h +++ b/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.h @@ -29,9 +29,9 @@ // Autogenerated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); - void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printRegName(raw_ostream &OS, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; diff --git a/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp b/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp --- a/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp +++ b/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCRegister.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" @@ -26,8 +27,8 @@ #include "XCoreGenAsmWriter.inc" -void XCoreInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << StringRef(getRegisterName(RegNo)).lower(); +void XCoreInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { + OS << StringRef(getRegisterName(Reg)).lower(); } void XCoreInstPrinter::printInst(const MCInst *MI, uint64_t Address, diff --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h --- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h +++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h @@ -30,13 +30,13 @@ // Automatically generated by tblgen. std::pair getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); + static const char *getRegisterName(MCRegister Reg); // Print the given operand. static void printOperand(const MCOperand &MO, raw_ostream &O); // Override MCInstPrinter. - void printRegName(raw_ostream &O, unsigned RegNo) const override; + void printRegName(raw_ostream &O, MCRegister Reg) const override; void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; diff --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp --- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp +++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp @@ -16,6 +16,7 @@ #include "llvm/CodeGen/MachineOperand.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCRegister.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/Casting.h" #include "llvm/Support/raw_ostream.h" @@ -73,8 +74,8 @@ printAnnotation(O, Annot); } -void XtensaInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const { - O << getRegisterName(RegNo); +void XtensaInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) const { + O << getRegisterName(Reg); } void XtensaInstPrinter::printOperand(const MCInst *MI, int OpNum, diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp --- a/llvm/utils/TableGen/AsmWriterEmitter.cpp +++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp @@ -618,10 +618,11 @@ "/// for the specified register.\n" "const char *" << Target.getName() << ClassName << "::"; if (hasAltNames) - O << "\ngetRegisterName(unsigned RegNo, unsigned AltIdx) {\n"; + O << "\ngetRegisterName(MCRegister Reg, unsigned AltIdx) {\n"; else - O << "getRegisterName(unsigned RegNo) {\n"; - O << " assert(RegNo && RegNo < " << (Registers.size()+1) + O << "getRegisterName(MCRegister Reg) {\n"; + O << " unsigned RegNo = Reg.id();\n" + << " assert(RegNo && RegNo < " << (Registers.size() + 1) << " && \"Invalid register number!\");\n" << "\n";