28#define DEBUG_TYPE "asm-printer"
30#define PRINT_ALIAS_INSTR
31#include "PPCGenAsmWriter.inc"
36 CLOpts(
PPC_MC::getCLOpts(
MAI.getTargetOptions())), TT(
T) {}
51 (
MI->getOpcode() == PPC::ADDIS8 ||
MI->getOpcode() == PPC::ADDIS) &&
52 MI->getOperand(2).isExpr()) {
53 assert((
MI->getOperand(0).isReg() &&
MI->getOperand(1).isReg()) &&
54 "The first and the second operand of an addis instruction"
55 " should be registers.");
58 "The third operand of an addis instruction should be a symbol "
59 "reference expression if it is an expression at all.");
74 unsigned LastOp =
MI->getNumOperands() - 1;
75 if (
MI->getNumOperands() > 1) {
84 if (
MI->getOpcode() == PPC::PLDpc) {
87 Symbol.print(O, &
MAI);
92 Symbol.print(O, &
MAI);
93 O <<
"-8,R_PPC64_PCREL_OPT,.-(";
94 Symbol.print(O, &
MAI);
102 if (
MI->getOpcode() == PPC::RLWINM) {
103 unsigned char SH =
MI->getOperand(2).getImm();
104 unsigned char MB =
MI->getOperand(3).getImm();
105 unsigned char ME =
MI->getOperand(4).getImm();
106 bool useSubstituteMnemonic =
false;
107 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
108 O <<
"\tslwi "; useSubstituteMnemonic =
true;
110 if (SH <= 31 && MB == (32-SH) && ME == 31) {
111 O <<
"\tsrwi "; useSubstituteMnemonic =
true;
114 if (useSubstituteMnemonic) {
118 O <<
", " << (
unsigned int)SH;
125 if (
MI->getOpcode() == PPC::RLDICR ||
126 MI->getOpcode() == PPC::RLDICR_32) {
127 unsigned char SH =
MI->getOperand(2).getImm();
128 unsigned char ME =
MI->getOperand(3).getImm();
135 O <<
", " << (
unsigned int)SH;
151 if ((
MI->getOpcode() == PPC::DCBT ||
MI->getOpcode() == PPC::DCBTST) &&
152 (!TT.isOSAIX() || STI.
hasFeature(PPC::FeatureModernAIXAs))) {
153 unsigned char TH =
MI->getOperand(0).getImm();
155 if (
MI->getOpcode() == PPC::DCBTST)
161 bool IsBookE = STI.
hasFeature(PPC::FeatureBookE);
162 if (IsBookE && TH != 0 && TH != 16)
163 O << (
unsigned int) TH <<
", ";
169 if (!IsBookE && TH != 0 && TH != 16)
170 O <<
", " << (
unsigned int) TH;
176 if (
MI->getOpcode() == PPC::DCBF) {
177 unsigned char L =
MI->getOperand(0).getImm();
178 if (!L || L == 1 || L == 3 || L == 4 || L == 6) {
209 unsigned Code =
MI->getOperand(OpNo).getImm();
211 if (Modifier ==
"cc") {
260 if (Modifier ==
"pm") {
298 assert(Modifier ==
"reg" &&
299 "Need to specify 'cc', 'pm' or 'reg' as predicate op modifier!");
306 unsigned Code =
MI->getOperand(OpNo).getImm();
315template <
unsigned W
idth>
319 unsigned int Value =
MI->getOperand(OpNo).getImm();
320 assert(
Value <= ((1ULL << Width) - 1) &&
"Invalid uimm argument!");
321 O << (
unsigned int)
Value;
326template <
unsigned W
idth>
330 int Value =
MI->getOperand(OpNo).getImm();
338 unsigned int Value =
MI->getOperand(OpNo).getImm();
340 O << (
unsigned int)
Value;
349 unsigned char Value =
MI->getOperand(OpNo).getImm();
350 O << (
unsigned int)
Value;
356 if (
MI->getOperand(OpNo).isImm())
357 O << (short)
MI->getOperand(OpNo).getImm();
365 if (
MI->getOperand(OpNo).isImm()) {
366 long long Value =
MI->getOperand(OpNo).getImm();
368 O << (
long long)
Value;
376 if (
MI->getOperand(OpNo).isImm()) {
377 long long Value =
MI->getOperand(OpNo).getImm();
379 O << (
long long)
Value;
387 if (
MI->getOperand(OpNo).isImm()) {
388 long long Value =
MI->getOperand(OpNo).getImm();
390 O << (
long long)
Value;
399 if (
MI->getOperand(OpNo).isImm())
400 O << (
unsigned short)
MI->getOperand(OpNo).getImm();
409 if (!
MI->getOperand(OpNo).isImm())
435 if (!
MI->getOperand(OpNo).isImm())
438 uint64_t
Imm =
static_cast<uint64_t
>(
MI->getOperand(OpNo).
getImm()) << 2;
448 switch (CCReg.
id()) {
450 case PPC::CR0: RegNo = 0;
break;
451 case PPC::CR1: RegNo = 1;
break;
452 case PPC::CR2: RegNo = 2;
break;
453 case PPC::CR3: RegNo = 3;
break;
454 case PPC::CR4: RegNo = 4;
break;
455 case PPC::CR5: RegNo = 5;
break;
456 case PPC::CR6: RegNo = 6;
break;
457 case PPC::CR7: RegNo = 7;
break;
459 O << (0x80 >> RegNo);
467 if (
MI->getOperand(OpNo+1).getReg() == PPC::R0)
477 O <<
MI->getOperand(OpNo).getImm();
507 if (
MI->getOperand(OpNo).getReg() == PPC::R0)
521 const MCExpr *Rhs =
nullptr;
524 Rhs = BinExpr->getRHS();
534 O <<
'@' <<
MAI.getSpecifierName(RefExp->
getKind());
540 O <<
'@' <<
MAI.getSpecifierName(RefExp->
getKind());
544 MAI.printExpr(Tmp, *Rhs);
553bool PPCInstPrinter::showRegistersWithPercentPrefix(
const char *
RegName)
const {
574 unsigned RegEncoding)
const {
575 if (!CLOpts.asm_full_reg_names && !
MAI.useFullRegisterNames())
579 const char *CRBits[] = {
580 "lt",
"gt",
"eq",
"un",
581 "4*cr1+lt",
"4*cr1+gt",
"4*cr1+eq",
"4*cr1+un",
582 "4*cr2+lt",
"4*cr2+gt",
"4*cr2+eq",
"4*cr2+un",
583 "4*cr3+lt",
"4*cr3+gt",
"4*cr3+eq",
"4*cr3+un",
584 "4*cr4+lt",
"4*cr4+gt",
"4*cr4+eq",
"4*cr4+un",
585 "4*cr5+lt",
"4*cr5+gt",
"4*cr5+eq",
"4*cr5+un",
586 "4*cr6+lt",
"4*cr6+gt",
"4*cr6+eq",
"4*cr6+un",
587 "4*cr7+lt",
"4*cr7+gt",
"4*cr7+eq",
"4*cr7+un"
589 return CRBits[RegEncoding];
594bool PPCInstPrinter::showRegistersWithPrefix()
const {
595 return CLOpts.reg_with_percent_prefix || CLOpts.asm_full_reg_names ||
596 MAI.useFullRegisterNames();
604 if (!CLOpts.vsr_nums_as_vr)
608 RegName = getVerboseConditionRegName(Reg,
MRI.getEncodingValue(Reg));
611 if (showRegistersWithPercentPrefix(
RegName))
613 if (!showRegistersWithPrefix())
625 assert(
Op.isExpr() &&
"unknown operand kind in printOperand");
626 MAI.printExpr(O, *
Op.getExpr());
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This class is intended to be used as a base class for asm properties and features specific to the tar...
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.
MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii, const MCRegisterInfo &mri)
Instances of this class represent a single low-level machine instruction.
Interface to description of machine instruction set.
Instances of this class represent operands of the MCInst class.
const MCExpr * getExpr() const
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
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 printS32ImmOperand(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 printPredicateOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O, StringRef Modifier={})
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)
PPCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI, Triple T)
void printNegS32ImmOperand(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 printMemRegImm34(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 printSImmOperand(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 printUImmOperand(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 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 printU8ImmOperandTrunc(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O)
void printMemRegImmHash(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...
Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
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.
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)