Skip to content

Commit 71043d3

Browse files
committed
[NFC][LLVM] Use StringRef for Modifier in Inst/ASM Printers
- 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.
1 parent 22c3dac commit 71043d3

File tree

21 files changed

+73
-78
lines changed

21 files changed

+73
-78
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ 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, StringRef Modifier) {
55+
assert(Modifier.empty() && "No modifiers supported");
5656
const MCOperand &Op = MI->getOperand(OpNo);
5757
if (Op.isReg()) {
5858
O << getRegisterName(Op.getReg());
@@ -65,7 +65,7 @@ void BPFInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
6565
}
6666

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class BPFInstPrinter : public MCInstPrinter {
2525
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
2626
const MCSubtargetInfo &STI, raw_ostream &O) override;
2727
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
28-
const char *Modifier = nullptr);
28+
StringRef Modifier = {});
2929
void printMemOperand(const MCInst *MI, int OpNo, raw_ostream &O,
30-
const char *Modifier = nullptr);
30+
StringRef Modifier = {});
3131
void printImm64Operand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
3232
void printBrTargetOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
3333

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void CSKYInstPrinter::printFPRRegName(raw_ostream &O, unsigned RegNo) const {
9999

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

106106
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, StringRef Modifier = {});
3838

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

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ 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, StringRef Modifier) {
148+
assert(Modifier.empty() && "No modifiers supported");
149149
const MCOperand &Op = MI->getOperand(OpNo);
150150
if (Op.isReg())
151151
OS << "%" << getRegisterName(Op.getReg());
@@ -233,7 +233,7 @@ static void printMemoryImmediateOffset(const MCAsmInfo &MAI,
233233

234234
void LanaiInstPrinter::printMemRiOperand(const MCInst *MI, int OpNo,
235235
raw_ostream &OS,
236-
const char * /*Modifier*/) {
236+
StringRef /*Modifier*/) {
237237
const MCOperand &RegOp = MI->getOperand(OpNo);
238238
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
239239
const MCOperand &AluOp = MI->getOperand(OpNo + 2);
@@ -248,7 +248,7 @@ void LanaiInstPrinter::printMemRiOperand(const MCInst *MI, int OpNo,
248248

249249
void LanaiInstPrinter::printMemRrOperand(const MCInst *MI, int OpNo,
250250
raw_ostream &OS,
251-
const char * /*Modifier*/) {
251+
StringRef /*Modifier*/) {
252252
const MCOperand &RegOp = MI->getOperand(OpNo);
253253
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
254254
const MCOperand &AluOp = MI->getOperand(OpNo + 2);
@@ -269,7 +269,7 @@ void LanaiInstPrinter::printMemRrOperand(const MCInst *MI, int OpNo,
269269

270270
void LanaiInstPrinter::printMemSplsOperand(const MCInst *MI, int OpNo,
271271
raw_ostream &OS,
272-
const char * /*Modifier*/) {
272+
StringRef /*Modifier*/) {
273273
const MCOperand &RegOp = MI->getOperand(OpNo);
274274
const MCOperand &OffsetOp = MI->getOperand(OpNo + 1);
275275
const MCOperand &AluOp = MI->getOperand(OpNo + 2);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ class LanaiInstPrinter : public MCInstPrinter {
2727
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
2828
const MCSubtargetInfo &STI, raw_ostream &O) override;
2929
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
30-
const char *Modifier = nullptr);
30+
StringRef Modifier = {});
3131
void printPredicateOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O);
3232
void printMemRiOperand(const MCInst *MI, int OpNo, raw_ostream &O,
33-
const char *Modifier = nullptr);
33+
StringRef Modifier = {});
3434
void printMemRrOperand(const MCInst *MI, int OpNo, raw_ostream &O,
35-
const char *Modifier = nullptr);
35+
StringRef Modifier = {});
3636
void printMemSplsOperand(const MCInst *MI, int OpNo, raw_ostream &O,
37-
const char *Modifier = nullptr);
37+
StringRef Modifier = {});
3838
void printCCOperand(const MCInst *MI, int OpNo, raw_ostream &O);
3939
void printHi16ImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
4040
void printHi16AndImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ 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, StringRef Modifier) {
57+
assert(Modifier.empty() && "No modifiers supported");
5858
const MCOperand &Op = MI->getOperand(OpNo);
5959
if (Op.isReg()) {
6060
O << getRegisterName(Op.getReg());
@@ -69,7 +69,7 @@ void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
6969

7070
void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
7171
raw_ostream &O,
72-
const char *Modifier) {
72+
StringRef /*Modifier*/) {
7373
const MCOperand &Base = MI->getOperand(OpNo);
7474
const MCOperand &Disp = MI->getOperand(OpNo+1);
7575

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ namespace llvm {
3939

4040
private:
4141
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
42-
const char *Modifier = nullptr);
42+
StringRef Modifier = {});
4343
void printPCRelImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
4444
void printSrcMemOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
45-
const char *Modifier = nullptr);
45+
StringRef Modifier = {});
4646
void printIndRegOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
4747
void printPostIndRegOperand(const MCInst *MI, unsigned OpNo,
4848
raw_ostream &O);

llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp

Lines changed: 5 additions & 5 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+
StringRef Modifier = {});
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, StringRef Modifier) {
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 (Modifier != "nohash")
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 (Modifier != "nohash")
9494
O << '#';
9595
PrintSymbolOperand(MO, O);
9696
return;

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, StringRef /*Modifier*/) {
720719
const MachineOperand &MO = MI->getOperand(opNum);
721720
O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm());
722721
}

0 commit comments

Comments
 (0)