Skip to content

Commit 8ede3dd

Browse files
authored
[NFC][MC] Use StringRef for Modifier in Inst/Asm Printers (#135403)
- Change various Inst/Asm Printer functions to use a StringRef for the Modifier parameter (instead of a const char *). - This simplifies various string comparisons used within these functions. - Remove these params for print functions that do not use them.
1 parent 9f7aac1 commit 8ede3dd

File tree

21 files changed

+66
-128
lines changed

21 files changed

+66
-128
lines changed

llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ static void printExpr(const MCExpr *Expr, raw_ostream &O) {
5151
}
5252

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

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

llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ class BPFInstPrinter : public MCInstPrinter {
2424

2525
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
2626
const MCSubtargetInfo &STI, raw_ostream &O) override;
27-
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
28-
const char *Modifier = nullptr);
29-
void printMemOperand(const MCInst *MI, int OpNo, raw_ostream &O,
30-
const char *Modifier = nullptr);
27+
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
28+
void printMemOperand(const MCInst *MI, int OpNo, raw_ostream &O);
3129
void printImm64Operand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
3230
void printBrTargetOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
3331

llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ void CSKYInstPrinter::printFPRRegName(raw_ostream &O, unsigned RegNo) const {
9898
}
9999

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

106104
if (MO.isReg()) {

llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CSKYInstPrinter : public MCInstPrinter {
3434
void printRegName(raw_ostream &O, MCRegister Reg) override;
3535

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

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

llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ void LanaiInstPrinter::printInst(const MCInst *MI, uint64_t Address,
144144
}
145145

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

234233
void LanaiInstPrinter::printMemRiOperand(const MCInst *MI, int OpNo,
235-
raw_ostream &OS,
236-
const char * /*Modifier*/) {
234+
raw_ostream &OS) {
237235
const MCOperand &RegOp = MI->getOperand(OpNo);
238236
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
239237
const MCOperand &AluOp = MI->getOperand(OpNo + 2);
@@ -247,8 +245,7 @@ void LanaiInstPrinter::printMemRiOperand(const MCInst *MI, int OpNo,
247245
}
248246

249247
void LanaiInstPrinter::printMemRrOperand(const MCInst *MI, int OpNo,
250-
raw_ostream &OS,
251-
const char * /*Modifier*/) {
248+
raw_ostream &OS) {
252249
const MCOperand &RegOp = MI->getOperand(OpNo);
253250
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
254251
const MCOperand &AluOp = MI->getOperand(OpNo + 2);
@@ -268,8 +265,7 @@ void LanaiInstPrinter::printMemRrOperand(const MCInst *MI, int OpNo,
268265
}
269266

270267
void LanaiInstPrinter::printMemSplsOperand(const MCInst *MI, int OpNo,
271-
raw_ostream &OS,
272-
const char * /*Modifier*/) {
268+
raw_ostream &OS) {
273269
const MCOperand &RegOp = MI->getOperand(OpNo);
274270
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
275271
const MCOperand &AluOp = MI->getOperand(OpNo + 2);

llvm/lib/Target/Lanai/MCTargetDesc/LanaiInstPrinter.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,11 @@ class LanaiInstPrinter : public MCInstPrinter {
2626

2727
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
2828
const MCSubtargetInfo &STI, raw_ostream &O) override;
29-
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
30-
const char *Modifier = nullptr);
29+
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
3130
void printPredicateOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O);
32-
void printMemRiOperand(const MCInst *MI, int OpNo, raw_ostream &O,
33-
const char *Modifier = nullptr);
34-
void printMemRrOperand(const MCInst *MI, int OpNo, raw_ostream &O,
35-
const char *Modifier = nullptr);
36-
void printMemSplsOperand(const MCInst *MI, int OpNo, raw_ostream &O,
37-
const char *Modifier = nullptr);
31+
void printMemRiOperand(const MCInst *MI, int OpNo, raw_ostream &O);
32+
void printMemRrOperand(const MCInst *MI, int OpNo, raw_ostream &O);
33+
void printMemSplsOperand(const MCInst *MI, int OpNo, raw_ostream &O);
3834
void printCCOperand(const MCInst *MI, int OpNo, raw_ostream &O);
3935
void printHi16ImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
4036
void printHi16AndImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);

llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo,
5353
}
5454

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

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

llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ namespace llvm {
3838
static const char *getRegisterName(MCRegister Reg);
3939

4040
private:
41-
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
42-
const char *Modifier = nullptr);
41+
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
4342
void printPCRelImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
44-
void printSrcMemOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
45-
const char *Modifier = nullptr);
43+
void printSrcMemOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
4644
void printIndRegOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
4745
void printPostIndRegOperand(const MCInst *MI, unsigned OpNo,
4846
raw_ostream &O);

llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ namespace {
4343
bool runOnMachineFunction(MachineFunction &MF) override;
4444

4545
void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override;
46-
void printOperand(const MachineInstr *MI, int OpNum,
47-
raw_ostream &O, const char* Modifier = nullptr);
46+
void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
47+
bool PrefixHash = true);
4848
void printSrcMemOperand(const MachineInstr *MI, int OpNum,
4949
raw_ostream &O);
5050
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
@@ -70,15 +70,15 @@ void MSP430AsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
7070
}
7171

7272
void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
73-
raw_ostream &O, const char *Modifier) {
73+
raw_ostream &O, bool PrefixHash) {
7474
const MachineOperand &MO = MI->getOperand(OpNum);
7575
switch (MO.getType()) {
7676
default: llvm_unreachable("Not implemented yet!");
7777
case MachineOperand::MO_Register:
7878
O << MSP430InstPrinter::getRegisterName(MO.getReg());
7979
return;
8080
case MachineOperand::MO_Immediate:
81-
if (!Modifier || strcmp(Modifier, "nohash"))
81+
if (PrefixHash)
8282
O << '#';
8383
O << MO.getImm();
8484
return;
@@ -90,7 +90,7 @@ void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
9090
// register base, we should not emit any prefix symbol here, e.g.
9191
// mov.w glb(r1), r2
9292
// Otherwise (!) msp430-as will silently miscompile the output :(
93-
if (!Modifier || strcmp(Modifier, "nohash"))
93+
if (PrefixHash)
9494
O << '#';
9595
PrintSymbolOperand(MO, O);
9696
return;
@@ -108,7 +108,7 @@ void MSP430AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum,
108108
// Imm here is in fact global address - print extra modifier.
109109
if (Disp.isImm() && Base.getReg() == MSP430::SR)
110110
O << '&';
111-
printOperand(MI, OpNum+1, O, "nohash");
111+
printOperand(MI, OpNum + 1, O, /*PrefixHash=*/false);
112112

113113
// Print register base field
114114
if (Base.getReg() != MSP430::SR && Base.getReg() != MSP430::PC) {

llvm/lib/Target/Mips/MipsAsmPrinter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,8 @@ printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O) {
714714
printOperand(MI, opNum+1, O);
715715
}
716716

717-
void MipsAsmPrinter::
718-
printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
719-
const char *Modifier) {
717+
void MipsAsmPrinter::printFCCOperand(const MachineInstr *MI, int opNum,
718+
raw_ostream &O) {
720719
const MachineOperand &MO = MI->getOperand(opNum);
721720
O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm());
722721
}

0 commit comments

Comments
 (0)