28#define DEBUG_TYPE "asm-printer"
34 cl::desc(
"Use full register names when printing assembly"));
39 cl::desc(
"Prints full register names with vs{31-63} as v{0-31}"));
45 cl::desc(
"Prints full register names with percent"));
47#define PRINT_ALIAS_INSTR
48#include "PPCGenAsmWriter.inc"
63 (
MI->getOpcode() == PPC::ADDIS8 ||
MI->getOpcode() == PPC::ADDIS) &&
64 MI->getOperand(2).isExpr()) {
65 assert((
MI->getOperand(0).isReg() &&
MI->getOperand(1).isReg()) &&
66 "The first and the second operand of an addis instruction"
67 " should be registers.");
69 assert(isa<MCSymbolRefExpr>(
MI->getOperand(2).getExpr()) &&
70 "The third operand of an addis instruction should be a symbol "
71 "reference expression if it is an expression at all.");
86 unsigned LastOp =
MI->getNumOperands() - 1;
87 if (
MI->getNumOperands() > 1) {
96 if (
MI->getOpcode() == PPC::PLDpc) {
99 Symbol.print(O, &
MAI);
104 Symbol.print(O, &
MAI);
105 O <<
"-8,R_PPC64_PCREL_OPT,.-(";
106 Symbol.print(O, &
MAI);
114 if (
MI->getOpcode() == PPC::RLWINM) {
115 unsigned char SH =
MI->getOperand(2).getImm();
116 unsigned char MB =
MI->getOperand(3).getImm();
117 unsigned char ME =
MI->getOperand(4).getImm();
118 bool useSubstituteMnemonic =
false;
119 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
120 O <<
"\tslwi "; useSubstituteMnemonic =
true;
122 if (SH <= 31 && MB == (32-SH) && ME == 31) {
123 O <<
"\tsrwi "; useSubstituteMnemonic =
true;
126 if (useSubstituteMnemonic) {
130 O <<
", " << (
unsigned int)SH;
137 if (
MI->getOpcode() == PPC::RLDICR ||
138 MI->getOpcode() == PPC::RLDICR_32) {
139 unsigned char SH =
MI->getOperand(2).getImm();
140 unsigned char ME =
MI->getOperand(3).getImm();
147 O <<
", " << (
unsigned int)SH;
163 if ((
MI->getOpcode() == PPC::DCBT ||
MI->getOpcode() == PPC::DCBTST) &&
165 unsigned char TH =
MI->getOperand(0).getImm();
167 if (
MI->getOpcode() == PPC::DCBTST)
173 bool IsBookE = STI.
hasFeature(PPC::FeatureBookE);
174 if (IsBookE && TH != 0 && TH != 16)
175 O << (
unsigned int) TH <<
", ";
181 if (!IsBookE && TH != 0 && TH != 16)
182 O <<
", " << (
unsigned int) TH;
188 if (
MI->getOpcode() == PPC::DCBF) {
189 unsigned char L =
MI->getOperand(0).getImm();
190 if (!L || L == 1 || L == 3 || L == 4 || L == 6) {
221 const char *Modifier) {
222 unsigned Code =
MI->getOperand(OpNo).getImm();
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();
438 assert(isInt<34>(
Value) &&
"Invalid s34imm argument!");
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())
460 int32_t Imm = SignExtend32<32>((
unsigned)
MI->getOperand(OpNo).getImm() << 2);
484 if (!
MI->getOperand(OpNo).isImm())
495 unsigned CCReg =
MI->getOperand(OpNo).getReg();
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;
571 if (
const MCBinaryExpr *BinExpr = dyn_cast<MCBinaryExpr>(
Op.getExpr())) {
572 RefExp = cast<MCSymbolRefExpr>(BinExpr->getLHS());
573 Rhs = BinExpr->getRHS();
575 RefExp = cast<MCSymbolRefExpr>(
Op.getExpr());
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 {
651 unsigned Reg =
Op.getReg();
659 if (showRegistersWithPercentPrefix(
RegName))
661 if (!showRegistersWithPrefix())
673 assert(
Op.isExpr() &&
"unknown operand kind in printOperand");
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"))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents an Operation in the Expression.
bool print(raw_ostream &OS, DIDumpOptions DumpOpts, const DWARFExpression *Expr, DWARFUnit *U) const
bool useFullRegisterNames() const
Binary assembler expressions.
Base class for the full range of assembler expressions which are needed for parsing.
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
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.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Instances of this class represent operands of the MCInst class.
const MCExpr * getExpr() const
uint16_t getEncodingValue(MCRegister RegNo) const
Returns the encoding for RegNo.
Wrapper class representing physical registers. Should be passed by value.
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
static StringRef getVariantKindName(VariantKind Kind)
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 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 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 printRegName(raw_ostream &OS, MCRegister Reg) const override
Print the assembler register name.
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 printPredicateOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O, const char *Modifier=nullptr)
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.
Target - Wrapper for Target specific information.
OSType getOS() const
Get the parsed operating system type of this triple.
bool isOSAIX() const
Tests whether the OS is AIX.
bool isPPC64() const
Tests whether the target is 64-bit PowerPC (little and big endian).
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...
unsigned getRegNumForOperand(const MCInstrDesc &Desc, unsigned 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.