Skip to content

[NFC][MC] Use StringRef for Modifier in Inst/Asm Printers #135403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ static void printExpr(const MCExpr *Expr, raw_ostream &O) {
}

void BPFInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O, const char *Modifier) {
assert((Modifier == nullptr || Modifier[0] == 0) && "No modifiers supported");
raw_ostream &O) {
const MCOperand &Op = MI->getOperand(OpNo);
if (Op.isReg()) {
O << getRegisterName(Op.getReg());
Expand All @@ -64,8 +63,8 @@ void BPFInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
}
}

void BPFInstPrinter::printMemOperand(const MCInst *MI, int OpNo, raw_ostream &O,
const char *Modifier) {
void BPFInstPrinter::printMemOperand(const MCInst *MI, int OpNo,
raw_ostream &O) {
const MCOperand &RegOp = MI->getOperand(OpNo);
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);

Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class BPFInstPrinter : public MCInstPrinter {

void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
const MCSubtargetInfo &STI, raw_ostream &O) override;
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printMemOperand(const MCInst *MI, int OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printMemOperand(const MCInst *MI, int OpNo, raw_ostream &O);
void printImm64Operand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printBrTargetOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);

Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ void CSKYInstPrinter::printFPRRegName(raw_ostream &O, unsigned RegNo) const {
}

void CSKYInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O,
const char *Modifier) {
assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
const MCSubtargetInfo &STI, raw_ostream &O) {
const MCOperand &MO = MI->getOperand(OpNo);

if (MO.isReg()) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CSKYInstPrinter : public MCInstPrinter {
void printRegName(raw_ostream &O, MCRegister Reg) override;

void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
raw_ostream &O, const char *Modifier = nullptr);
raw_ostream &O);

void printFPRRegName(raw_ostream &O, unsigned RegNo) const;

Expand Down
12 changes: 4 additions & 8 deletions llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ void LanaiInstPrinter::printInst(const MCInst *MI, uint64_t Address,
}

void LanaiInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &OS, const char *Modifier) {
assert((Modifier == nullptr || Modifier[0] == 0) && "No modifiers supported");
raw_ostream &OS) {
const MCOperand &Op = MI->getOperand(OpNo);
if (Op.isReg())
OS << "%" << getRegisterName(Op.getReg());
Expand Down Expand Up @@ -232,8 +231,7 @@ static void printMemoryImmediateOffset(const MCAsmInfo &MAI,
}

void LanaiInstPrinter::printMemRiOperand(const MCInst *MI, int OpNo,
raw_ostream &OS,
const char * /*Modifier*/) {
raw_ostream &OS) {
const MCOperand &RegOp = MI->getOperand(OpNo);
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
const MCOperand &AluOp = MI->getOperand(OpNo + 2);
Expand All @@ -247,8 +245,7 @@ void LanaiInstPrinter::printMemRiOperand(const MCInst *MI, int OpNo,
}

void LanaiInstPrinter::printMemRrOperand(const MCInst *MI, int OpNo,
raw_ostream &OS,
const char * /*Modifier*/) {
raw_ostream &OS) {
const MCOperand &RegOp = MI->getOperand(OpNo);
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
const MCOperand &AluOp = MI->getOperand(OpNo + 2);
Expand All @@ -268,8 +265,7 @@ void LanaiInstPrinter::printMemRrOperand(const MCInst *MI, int OpNo,
}

void LanaiInstPrinter::printMemSplsOperand(const MCInst *MI, int OpNo,
raw_ostream &OS,
const char * /*Modifier*/) {
raw_ostream &OS) {
const MCOperand &RegOp = MI->getOperand(OpNo);
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
const MCOperand &AluOp = MI->getOperand(OpNo + 2);
Expand Down
12 changes: 4 additions & 8 deletions llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ class LanaiInstPrinter : public MCInstPrinter {

void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
const MCSubtargetInfo &STI, raw_ostream &O) override;
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printPredicateOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O);
void printMemRiOperand(const MCInst *MI, int OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printMemRrOperand(const MCInst *MI, int OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printMemSplsOperand(const MCInst *MI, int OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printMemRiOperand(const MCInst *MI, int OpNo, raw_ostream &O);
void printMemRrOperand(const MCInst *MI, int OpNo, raw_ostream &O);
void printMemSplsOperand(const MCInst *MI, int OpNo, raw_ostream &O);
void printCCOperand(const MCInst *MI, int OpNo, raw_ostream &O);
void printHi16ImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printHi16AndImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo,
}

void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O, const char *Modifier) {
assert((Modifier == nullptr || Modifier[0] == 0) && "No modifiers supported");
raw_ostream &O) {
const MCOperand &Op = MI->getOperand(OpNo);
if (Op.isReg()) {
O << getRegisterName(Op.getReg());
Expand All @@ -68,8 +67,7 @@ void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
}

void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O,
const char *Modifier) {
raw_ostream &O) {
const MCOperand &Base = MI->getOperand(OpNo);
const MCOperand &Disp = MI->getOperand(OpNo+1);

Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ namespace llvm {
static const char *getRegisterName(MCRegister Reg);

private:
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printPCRelImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printSrcMemOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printSrcMemOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printIndRegOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printPostIndRegOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O);
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace {
bool runOnMachineFunction(MachineFunction &MF) override;

void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override;
void printOperand(const MachineInstr *MI, int OpNum,
raw_ostream &O, const char* Modifier = nullptr);
void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
bool PrefixHash = true);
void printSrcMemOperand(const MachineInstr *MI, int OpNum,
raw_ostream &O);
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Expand All @@ -70,15 +70,15 @@ void MSP430AsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
}

void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
raw_ostream &O, const char *Modifier) {
raw_ostream &O, bool PrefixHash) {
const MachineOperand &MO = MI->getOperand(OpNum);
switch (MO.getType()) {
default: llvm_unreachable("Not implemented yet!");
case MachineOperand::MO_Register:
O << MSP430InstPrinter::getRegisterName(MO.getReg());
return;
case MachineOperand::MO_Immediate:
if (!Modifier || strcmp(Modifier, "nohash"))
if (PrefixHash)
O << '#';
O << MO.getImm();
return;
Expand All @@ -90,7 +90,7 @@ void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
// register base, we should not emit any prefix symbol here, e.g.
// mov.w glb(r1), r2
// Otherwise (!) msp430-as will silently miscompile the output :(
if (!Modifier || strcmp(Modifier, "nohash"))
if (PrefixHash)
O << '#';
PrintSymbolOperand(MO, O);
return;
Expand All @@ -108,7 +108,7 @@ void MSP430AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum,
// Imm here is in fact global address - print extra modifier.
if (Disp.isImm() && Base.getReg() == MSP430::SR)
O << '&';
printOperand(MI, OpNum+1, O, "nohash");
printOperand(MI, OpNum + 1, O, /*PrefixHash=*/false);

// Print register base field
if (Base.getReg() != MSP430::SR && Base.getReg() != MSP430::PC) {
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/Mips/MipsAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,8 @@ printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O) {
printOperand(MI, opNum+1, O);
}

void MipsAsmPrinter::
printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
const char *Modifier) {
void MipsAsmPrinter::printFCCOperand(const MachineInstr *MI, int opNum,
raw_ostream &O) {
const MachineOperand &MO = MI->getOperand(opNum);
O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm());
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Mips/MipsAsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O);
void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
const char *Modifier = nullptr);
void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O);
void emitStartOfAsmFile(Module &M) override;
void emitEndOfAsmFile(Module &M) override;
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,10 @@ void PPCInstPrinter::printInst(const MCInst *MI, uint64_t Address,

void PPCInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI,
raw_ostream &O,
const char *Modifier) {
raw_ostream &O, StringRef Modifier) {
unsigned Code = MI->getOperand(OpNo).getImm();

if (StringRef(Modifier) == "cc") {
if (Modifier == "cc") {
switch ((PPC::Predicate)Code) {
case PPC::PRED_LT_MINUS:
case PPC::PRED_LT_PLUS:
Expand Down Expand Up @@ -271,7 +270,7 @@ void PPCInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNo,
llvm_unreachable("Invalid predicate code");
}

if (StringRef(Modifier) == "pm") {
if (Modifier == "pm") {
switch ((PPC::Predicate)Code) {
case PPC::PRED_LT:
case PPC::PRED_LE:
Expand Down Expand Up @@ -309,7 +308,7 @@ void PPCInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNo,
llvm_unreachable("Invalid predicate code");
}

assert(StringRef(Modifier) == "reg" &&
assert(Modifier == "reg" &&
"Need to specify 'cc', 'pm' or 'reg' as predicate op modifier!");
printOperand(MI, OpNo + 1, STI, O);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PPCInstPrinter : public MCInstPrinter {
raw_ostream &O);
void printPredicateOperand(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O,
const char *Modifier = nullptr);
StringRef Modifier = {});
void printATBitsAsHint(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O);

Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ void RISCVInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) {
}

void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O,
const char *Modifier) {
assert((Modifier == nullptr || Modifier[0] == 0) && "No modifiers supported");
const MCSubtargetInfo &STI,
raw_ostream &O) {
const MCOperand &MO = MI->getOperand(OpNo);

if (MO.isReg()) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RISCVInstPrinter : public MCInstPrinter {
void printRegName(raw_ostream &O, MCRegister Reg) override;

void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
raw_ostream &O, const char *Modifier = nullptr);
raw_ostream &O);
void printBranchOperand(const MCInst *MI, uint64_t Address, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O);
void printCSRSystemRegister(const MCInst *MI, unsigned OpNo,
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ static void printExpr(const MCExpr *Expr, raw_ostream &O) {
}

void SPIRVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O, const char *Modifier) {
assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
raw_ostream &O) {
if (OpNo < MI->getNumOperands()) {
const MCOperand &Op = MI->getOperand(OpNo);
if (Op.isReg())
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class SPIRVInstPrinter : public MCInstPrinter {

void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
const MCSubtargetInfo &STI, raw_ostream &OS) override;
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
const char *Modifier = nullptr);
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);

void printStringImm(const MCInst *MI, unsigned OpNo, raw_ostream &O);

Expand Down
40 changes: 4 additions & 36 deletions llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,7 @@ void VEInstPrinter::printOperand(const MCInst *MI, int OpNum,

void VEInstPrinter::printMemASXOperand(const MCInst *MI, int OpNum,
const MCSubtargetInfo &STI,
raw_ostream &O, const char *Modifier) {
// If this is an ADD operand, emit it like normal operands.
if (Modifier && !strcmp(Modifier, "arith")) {
printOperand(MI, OpNum, STI, O);
O << ", ";
printOperand(MI, OpNum + 1, STI, O);
return;
}

raw_ostream &O) {
if (MI->getOperand(OpNum + 2).isImm() &&
MI->getOperand(OpNum + 2).getImm() == 0) {
// don't print "+0"
Expand Down Expand Up @@ -110,15 +102,7 @@ void VEInstPrinter::printMemASXOperand(const MCInst *MI, int OpNum,

void VEInstPrinter::printMemASOperandASX(const MCInst *MI, int OpNum,
const MCSubtargetInfo &STI,
raw_ostream &O, const char *Modifier) {
// If this is an ADD operand, emit it like normal operands.
if (Modifier && !strcmp(Modifier, "arith")) {
printOperand(MI, OpNum, STI, O);
O << ", ";
printOperand(MI, OpNum + 1, STI, O);
return;
}

raw_ostream &O) {
if (MI->getOperand(OpNum + 1).isImm() &&
MI->getOperand(OpNum + 1).getImm() == 0) {
// don't print "+0"
Expand All @@ -141,15 +125,7 @@ void VEInstPrinter::printMemASOperandASX(const MCInst *MI, int OpNum,

void VEInstPrinter::printMemASOperandRRM(const MCInst *MI, int OpNum,
const MCSubtargetInfo &STI,
raw_ostream &O, const char *Modifier) {
// If this is an ADD operand, emit it like normal operands.
if (Modifier && !strcmp(Modifier, "arith")) {
printOperand(MI, OpNum, STI, O);
O << ", ";
printOperand(MI, OpNum + 1, STI, O);
return;
}

raw_ostream &O) {
if (MI->getOperand(OpNum + 1).isImm() &&
MI->getOperand(OpNum + 1).getImm() == 0) {
// don't print "+0"
Expand All @@ -172,15 +148,7 @@ void VEInstPrinter::printMemASOperandRRM(const MCInst *MI, int OpNum,

void VEInstPrinter::printMemASOperandHM(const MCInst *MI, int OpNum,
const MCSubtargetInfo &STI,
raw_ostream &O, const char *Modifier) {
// If this is an ADD operand, emit it like normal operands.
if (Modifier && !strcmp(Modifier, "arith")) {
printOperand(MI, OpNum, STI, O);
O << ", ";
printOperand(MI, OpNum + 1, STI, O);
return;
}

raw_ostream &O) {
if (MI->getOperand(OpNum + 1).isImm() &&
MI->getOperand(OpNum + 1).getImm() == 0) {
// don't print "+0"
Expand Down
12 changes: 4 additions & 8 deletions llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,13 @@ class VEInstPrinter : public MCInstPrinter {
void printOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI,
raw_ostream &OS);
void printMemASXOperand(const MCInst *MI, int OpNum,
const MCSubtargetInfo &STI, raw_ostream &OS,
const char *Modifier = nullptr);
const MCSubtargetInfo &STI, raw_ostream &OS);
void printMemASOperandASX(const MCInst *MI, int OpNum,
const MCSubtargetInfo &STI, raw_ostream &OS,
const char *Modifier = nullptr);
const MCSubtargetInfo &STI, raw_ostream &OS);
void printMemASOperandRRM(const MCInst *MI, int OpNum,
const MCSubtargetInfo &STI, raw_ostream &OS,
const char *Modifier = nullptr);
const MCSubtargetInfo &STI, raw_ostream &OS);
void printMemASOperandHM(const MCInst *MI, int OpNum,
const MCSubtargetInfo &STI, raw_ostream &OS,
const char *Modifier = nullptr);
const MCSubtargetInfo &STI, raw_ostream &OS);
void printMImmOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI,
raw_ostream &OS);
void printCCOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI,
Expand Down
Loading