29#define DEBUG_TYPE "asm-printer"
35 cl::desc(
"Use full register names when printing assembly"));
40 cl::desc(
"Prints full register names with vs{31-63} as v{0-31}"));
46 cl::desc(
"Prints full register names with percent"));
48#define PRINT_ALIAS_INSTR
49#include "PPCGenAsmWriter.inc"
64 (
MI->getOpcode() == PPC::ADDIS8 ||
MI->getOpcode() == PPC::ADDIS) &&
65 MI->getOperand(2).isExpr()) {
66 assert((
MI->getOperand(0).isReg() &&
MI->getOperand(1).isReg()) &&
67 "The first and the second operand of an addis instruction"
68 " should be registers.");
71 "The third operand of an addis instruction should be a symbol "
72 "reference expression if it is an expression at all.");
87 unsigned LastOp =
MI->getNumOperands() - 1;
88 if (
MI->getNumOperands() > 1) {
97 if (
MI->getOpcode() == PPC::PLDpc) {
100 Symbol.print(O, &
MAI);
105 Symbol.print(O, &
MAI);
106 O <<
"-8,R_PPC64_PCREL_OPT,.-(";
107 Symbol.print(O, &
MAI);
115 if (
MI->getOpcode() == PPC::RLWINM) {
116 unsigned char SH =
MI->getOperand(2).getImm();
117 unsigned char MB =
MI->getOperand(3).getImm();
118 unsigned char ME =
MI->getOperand(4).getImm();
119 bool useSubstituteMnemonic =
false;
120 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
121 O <<
"\tslwi "; useSubstituteMnemonic =
true;
123 if (SH <= 31 && MB == (32-SH) && ME == 31) {
124 O <<
"\tsrwi "; useSubstituteMnemonic =
true;
127 if (useSubstituteMnemonic) {
131 O <<
", " << (
unsigned int)SH;
138 if (
MI->getOpcode() == PPC::RLDICR ||
139 MI->getOpcode() == PPC::RLDICR_32) {
140 unsigned char SH =
MI->getOperand(2).getImm();
141 unsigned char ME =
MI->getOperand(3).getImm();
148 O <<
", " << (
unsigned int)SH;
164 if ((
MI->getOpcode() == PPC::DCBT ||
MI->getOpcode() == PPC::DCBTST) &&
165 (!TT.isOSAIX() || STI.
hasFeature(PPC::FeatureModernAIXAs))) {
166 unsigned char TH =
MI->getOperand(0).getImm();
168 if (
MI->getOpcode() == PPC::DCBTST)
174 bool IsBookE = STI.
hasFeature(PPC::FeatureBookE);
175 if (IsBookE && TH != 0 && TH != 16)
176 O << (
unsigned int) TH <<
", ";
182 if (!IsBookE && TH != 0 && TH != 16)
183 O <<
", " << (
unsigned int) TH;
189 if (
MI->getOpcode() == PPC::DCBF) {
190 unsigned char L =
MI->getOperand(0).getImm();
191 if (!L || L == 1 || L == 3 || L == 4 || L == 6) {
222 unsigned Code =
MI->getOperand(OpNo).getImm();
224 if (Modifier ==
"cc") {
273 if (Modifier ==
"pm") {
311 assert(Modifier ==
"reg" &&
312 "Need to specify 'cc', 'pm' or 'reg' as predicate op modifier!");
319 unsigned Code =
MI->getOperand(OpNo).getImm();
329 unsigned int Value =
MI->getOperand(OpNo).getImm();
331 O << (
unsigned int)
Value;
337 unsigned int Value =
MI->getOperand(OpNo).getImm();
339 O << (
unsigned int)
Value;
345 unsigned int Value =
MI->getOperand(OpNo).getImm();
347 O << (
unsigned int)
Value;
353 unsigned int Value =
MI->getOperand(OpNo).getImm();
355 O << (
unsigned int)
Value;
361 int Value =
MI->getOperand(OpNo).getImm();
369 unsigned int Value =
MI->getOperand(OpNo).getImm();
371 O << (
unsigned int)
Value;
377 unsigned int Value =
MI->getOperand(OpNo).getImm();
379 O << (
unsigned int)
Value;
385 unsigned int Value =
MI->getOperand(OpNo).getImm();
387 O << (
unsigned int)
Value;
393 unsigned int Value =
MI->getOperand(OpNo).getImm();
395 O << (
unsigned int)
Value;
404 unsigned char Value =
MI->getOperand(OpNo).getImm();
405 O << (
unsigned int)
Value;
411 unsigned short Value =
MI->getOperand(OpNo).getImm();
412 assert(
Value <= 1023 &&
"Invalid u10imm argument!");
413 O << (
unsigned short)
Value;
419 unsigned short Value =
MI->getOperand(OpNo).getImm();
420 assert(
Value <= 4095 &&
"Invalid u12imm argument!");
421 O << (
unsigned short)
Value;
427 if (
MI->getOperand(OpNo).isImm())
428 O << (short)
MI->getOperand(OpNo).getImm();
436 if (
MI->getOperand(OpNo).isImm()) {
437 long long Value =
MI->getOperand(OpNo).getImm();
439 O << (
long long)
Value;
448 if (
MI->getOperand(OpNo).isImm())
449 O << (
unsigned short)
MI->getOperand(OpNo).getImm();
458 if (!
MI->getOperand(OpNo).isImm())
484 if (!
MI->getOperand(OpNo).isImm())
497 switch (CCReg.
id()) {
499 case PPC::CR0: RegNo = 0;
break;
500 case PPC::CR1: RegNo = 1;
break;
501 case PPC::CR2: RegNo = 2;
break;
502 case PPC::CR3: RegNo = 3;
break;
503 case PPC::CR4: RegNo = 4;
break;
504 case PPC::CR5: RegNo = 5;
break;
505 case PPC::CR6: RegNo = 6;
break;
506 case PPC::CR7: RegNo = 7;
break;
508 O << (0x80 >> RegNo);
516 if (
MI->getOperand(OpNo+1).getReg() == PPC::R0)
526 O <<
MI->getOperand(OpNo).getImm();
556 if (
MI->getOperand(OpNo).getReg() == PPC::R0)
570 const MCExpr *Rhs =
nullptr;
573 Rhs = BinExpr->getRHS();
583 O <<
'@' <<
MAI.getSpecifierName(RefExp->
getKind());
589 O <<
'@' <<
MAI.getSpecifierName(RefExp->
getKind());
593 MAI.printExpr(Tmp, *Rhs);
602bool PPCInstPrinter::showRegistersWithPercentPrefix(
const char *
RegName)
const {
622PPCInstPrinter::getVerboseConditionRegName(
unsigned RegNum,
623 unsigned RegEncoding)
const {
626 if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
628 const char *CRBits[] = {
629 "lt",
"gt",
"eq",
"un",
630 "4*cr1+lt",
"4*cr1+gt",
"4*cr1+eq",
"4*cr1+un",
631 "4*cr2+lt",
"4*cr2+gt",
"4*cr2+eq",
"4*cr2+un",
632 "4*cr3+lt",
"4*cr3+gt",
"4*cr3+eq",
"4*cr3+un",
633 "4*cr4+lt",
"4*cr4+gt",
"4*cr4+eq",
"4*cr4+un",
634 "4*cr5+lt",
"4*cr5+gt",
"4*cr5+eq",
"4*cr5+un",
635 "4*cr6+lt",
"4*cr6+gt",
"4*cr6+eq",
"4*cr6+un",
636 "4*cr7+lt",
"4*cr7+gt",
"4*cr7+eq",
"4*cr7+un"
638 return CRBits[RegEncoding];
643bool PPCInstPrinter::showRegistersWithPrefix()
const {
656 RegName = getVerboseConditionRegName(Reg,
MRI.getEncodingValue(Reg));
659 if (showRegistersWithPercentPrefix(
RegName))
661 if (!showRegistersWithPrefix())
673 assert(
Op.isExpr() &&
"unknown operand kind in printOperand");
674 MAI.printExpr(O, *
Op.getExpr());
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > 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}"))
static cl::opt< bool > FullRegNamesWithPercent("ppc-reg-with-percent-prefix", cl::Hidden, cl::init(false), cl::desc("Prints full register names with percent"))
static cl::opt< bool > FullRegNames("ppc-asm-full-reg-names", cl::Hidden, cl::init(false), cl::desc("Use full register names when printing assembly"))
bool useFullRegisterNames() const
Binary assembler expressions.
Base class for the full range of assembler expressions which are needed for parsing.
format_object< int64_t > formatHex(int64_t Value) const
const MCRegisterInfo & MRI
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
bool PrintBranchImmAsAddress
If true, a branch immediate (e.g.
Instances of this class represent a single low-level machine instruction.
Instances of this class represent operands of the MCInst class.
const MCExpr * getExpr() const
Wrapper class representing physical registers. Should be passed by value.
constexpr unsigned id() const
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
VariantKind getKind() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
StringRef getName() const
getName - Get the symbol name.
void printMemRegImm34PCRel(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printcrbitm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printU6ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
bool printAliasInstr(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &OS)
void printMemRegReg(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printU1ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printPredicateOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O, StringRef Modifier={})
void printU4ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printS34ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printS16ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printRegName(raw_ostream &OS, MCRegister Reg) override
Print the assembler register name.
void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printU12ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override
Print the specified MCInst to the specified raw_ostream.
void printU5ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printMemRegImm34(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printU7ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
static const char * getRegisterName(MCRegister Reg)
void printU16ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printMemRegImm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printImmZeroOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printATBitsAsHint(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printAbsBranchOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printBranchOperand(const MCInst *MI, uint64_t Address, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printU3ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printU8ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printTLSCall(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printInstruction(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &O)
void printS5ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printMemRegImmHash(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printU2ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printU10ImmOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
OSType getOS() const
Get the parsed operating system type of this triple.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
const char * stripRegisterPrefix(const char *RegName)
stripRegisterPrefix - This method strips the character prefix from a register name so that only the n...
MCRegister getRegNumForOperand(const MCInstrDesc &Desc, MCRegister Reg, unsigned OpNo)
getRegNumForOperand - some operands use different numbering schemes for the same registers.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
constexpr int32_t SignExtend32(uint32_t X)
Sign-extend the number in the bottom B bits of X to a 32-bit integer.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
static uint16_t getSpecifier(const MCSymbolRefExpr *SRE)