Index: lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h =================================================================== --- lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h +++ lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h @@ -14,29 +14,32 @@ #ifndef LLVM_LIB_TARGET_POWERPC_INSTPRINTER_PPCINSTPRINTER_H #define LLVM_LIB_TARGET_POWERPC_INSTPRINTER_PPCINSTPRINTER_H +#include "llvm/ADT/Triple.h" #include "llvm/MC/MCInstPrinter.h" namespace llvm { class PPCInstPrinter : public MCInstPrinter { - bool IsDarwin; + Triple TripleInfo; +private: + bool showRegistersWithPercentPrefix(const char *RegName); + bool showRegistersWithoutPrefix(const char *RegName); + const char *stripRegisterPrefix(const char *RegName); + const char *getFullRegisterName(const char *RegName, unsigned RegNum, + unsigned RegEncoding); public: PPCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, - const MCRegisterInfo &MRI, bool isDarwin) - : MCInstPrinter(MAI, MII, MRI), IsDarwin(isDarwin) {} - - bool isDarwinSyntax() const { - return IsDarwin; - } - + const MCRegisterInfo &MRI, Triple T) + : MCInstPrinter(MAI, MII, MRI), TripleInfo(T) {} + void printRegName(raw_ostream &OS, unsigned RegNo) const override; void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot, const MCSubtargetInfo &STI) override; - + // Autogenerated by tblgen. void printInstruction(const MCInst *MI, raw_ostream &O); static const char *getRegisterName(unsigned RegNo); - + bool printAliasInstr(const MCInst *MI, raw_ostream &OS); void printCustomAliasOperand(const MCInst *MI, unsigned OpIdx, unsigned PrintMethodIdx, Index: lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp =================================================================== --- lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp +++ lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp @@ -39,6 +39,12 @@ ShowVSRNumsAsVR("ppc-vsr-nums-as-vr", cl::Hidden, cl::init(false), cl::desc("Prints full register names with vs{31-63} as v{0-31}")); +// Prints full register names with percent symbol. +static cl::opt +FullRegNamesWithPercent("print-reg-with-percent-prefix", + cl::Hidden, cl::init(false), + cl::desc("Prints full register names with percent")); + #define PRINT_ALIAS_INSTR #include "PPCGenAsmWriter.inc" @@ -445,11 +451,26 @@ O << '@' << MCSymbolRefExpr::getVariantKindName(refExp.getKind()); } - /// stripRegisterPrefix - This method strips the character prefix from a /// register name so that only the number is left. Used by for linux asm. -static const char *stripRegisterPrefix(const char *RegName, unsigned RegNum, - unsigned RegEncoding) { +const char *PPCInstPrinter::stripRegisterPrefix(const char *RegName) { + switch (RegName[0]) { + case 'r': + case 'f': + case 'q': // for QPX + case 'v': + if (RegName[1] == 's') + return RegName + 2; + return RegName + 1; + case 'c': if (RegName[1] == 'r') return RegName + 2; + } + + return RegName; +} + +/// Get full register name. +const char *PPCInstPrinter::getFullRegisterName(const char *RegName, + unsigned RegNum, unsigned RegEncoding) { if (FullRegNames) { if (RegNum >= PPC::CR0EQ && RegNum <= PPC::CR7UN) { const char *CRBits[] = @@ -464,21 +485,32 @@ }; return CRBits[RegEncoding]; } - return RegName; } - switch (RegName[0]) { - case 'r': - case 'f': - case 'q': // for QPX - case 'v': - if (RegName[1] == 's') - return RegName + 2; - return RegName + 1; - case 'c': if (RegName[1] == 'r') return RegName + 2; + return RegName; +} + +/// showRegistersWithPercentPrefix - Check if register name accepts percent +/// symbol in its prefix. +bool PPCInstPrinter::showRegistersWithPercentPrefix( + const char *RegName) { + if (FullRegNamesWithPercent && !TripleInfo.isOSDarwin()) { + switch (RegName[0]) { + case 'r': + case 'f': + case 'q': + case 'v': + case 'c': + return true; + } } - return RegName; + return false; +} + +/// showRegistersWithPercentPrefix - Check if register prefix can be removed. +bool PPCInstPrinter::showRegistersWithoutPrefix(const char *RegName) { + return !FullRegNames && !TripleInfo.isOSDarwin(); } void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, @@ -503,9 +535,17 @@ } const char *RegName = getRegisterName(Reg); - // The linux and AIX assembler does not take register prefixes. - if (!isDarwinSyntax()) - RegName = stripRegisterPrefix(RegName, Reg, MRI.getEncodingValue(Reg)); + + if (showRegistersWithPercentPrefix(RegName)) { + // Print register with percent symbol and prefix. + O << "%"; + } else if (showRegistersWithoutPrefix(RegName)) { + // Print register without prefix. + RegName = stripRegisterPrefix(RegName); + } else { + // Print register with full name. + RegName = getFullRegisterName(RegName, Reg, MRI.getEncodingValue(Reg)); + } O << RegName; return; Index: lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp =================================================================== --- lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp +++ lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp @@ -239,7 +239,7 @@ const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) { - return new PPCInstPrinter(MAI, MII, MRI, T.isOSDarwin()); + return new PPCInstPrinter(MAI, MII, MRI, T); } extern "C" void LLVMInitializePowerPCTargetMC() {