Skip to content

Commit 1545f11

Browse files
authored
[NFC][NVPTX] Use StringRef for Modifier arg in NVPTXInstPrinter (#135793)
- Use StringRef type for Modifier instead of const char *. - Remove Modifier arg from functions that do not need them.
1 parent 3192ecf commit 1545f11

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ void NVPTXInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
9595
}
9696

9797
void NVPTXInstPrinter::printCvtMode(const MCInst *MI, int OpNum, raw_ostream &O,
98-
const char *M) {
98+
StringRef Modifier) {
9999
const MCOperand &MO = MI->getOperand(OpNum);
100100
int64_t Imm = MO.getImm();
101-
llvm::StringRef Modifier(M);
102101

103102
if (Modifier == "ftz") {
104103
// FTZ flag
@@ -155,10 +154,9 @@ void NVPTXInstPrinter::printCvtMode(const MCInst *MI, int OpNum, raw_ostream &O,
155154
}
156155

157156
void NVPTXInstPrinter::printCmpMode(const MCInst *MI, int OpNum, raw_ostream &O,
158-
const char *M) {
157+
StringRef Modifier) {
159158
const MCOperand &MO = MI->getOperand(OpNum);
160159
int64_t Imm = MO.getImm();
161-
llvm::StringRef Modifier(M);
162160

163161
if (Modifier == "ftz") {
164162
// FTZ flag
@@ -229,8 +227,7 @@ void NVPTXInstPrinter::printCmpMode(const MCInst *MI, int OpNum, raw_ostream &O,
229227
}
230228

231229
void NVPTXInstPrinter::printLdStCode(const MCInst *MI, int OpNum,
232-
raw_ostream &O, const char *M) {
233-
llvm::StringRef Modifier(M);
230+
raw_ostream &O, StringRef Modifier) {
234231
const MCOperand &MO = MI->getOperand(OpNum);
235232
int Imm = (int)MO.getImm();
236233
if (Modifier == "sem") {
@@ -329,10 +326,9 @@ void NVPTXInstPrinter::printLdStCode(const MCInst *MI, int OpNum,
329326
}
330327

331328
void NVPTXInstPrinter::printMmaCode(const MCInst *MI, int OpNum, raw_ostream &O,
332-
const char *M) {
329+
StringRef Modifier) {
333330
const MCOperand &MO = MI->getOperand(OpNum);
334331
int Imm = (int)MO.getImm();
335-
llvm::StringRef Modifier(M);
336332
if (Modifier.empty() || Modifier == "version") {
337333
O << Imm; // Just print out PTX version
338334
return;
@@ -346,9 +342,8 @@ void NVPTXInstPrinter::printMmaCode(const MCInst *MI, int OpNum, raw_ostream &O,
346342
}
347343

348344
void NVPTXInstPrinter::printMemOperand(const MCInst *MI, int OpNum,
349-
raw_ostream &O, const char *M) {
345+
raw_ostream &O, StringRef Modifier) {
350346
printOperand(MI, OpNum, O);
351-
llvm::StringRef Modifier(M);
352347

353348
if (Modifier == "add") {
354349
O << ", ";
@@ -363,7 +358,7 @@ void NVPTXInstPrinter::printMemOperand(const MCInst *MI, int OpNum,
363358
}
364359

365360
void NVPTXInstPrinter::printOffseti32imm(const MCInst *MI, int OpNum,
366-
raw_ostream &O, const char *Modifier) {
361+
raw_ostream &O) {
367362
auto &Op = MI->getOperand(OpNum);
368363
assert(Op.isImm() && "Invalid operand");
369364
if (Op.getImm() != 0) {
@@ -373,13 +368,13 @@ void NVPTXInstPrinter::printOffseti32imm(const MCInst *MI, int OpNum,
373368
}
374369

375370
void NVPTXInstPrinter::printHexu32imm(const MCInst *MI, int OpNum,
376-
raw_ostream &O, const char *Modifier) {
371+
raw_ostream &O) {
377372
int64_t Imm = MI->getOperand(OpNum).getImm();
378373
O << formatHex(Imm) << "U";
379374
}
380375

381376
void NVPTXInstPrinter::printProtoIdent(const MCInst *MI, int OpNum,
382-
raw_ostream &O, const char *Modifier) {
377+
raw_ostream &O) {
383378
const MCOperand &Op = MI->getOperand(OpNum);
384379
assert(Op.isExpr() && "Call prototype is not an MCExpr?");
385380
const MCExpr *Expr = Op.getExpr();
@@ -388,7 +383,7 @@ void NVPTXInstPrinter::printProtoIdent(const MCInst *MI, int OpNum,
388383
}
389384

390385
void NVPTXInstPrinter::printPrmtMode(const MCInst *MI, int OpNum,
391-
raw_ostream &O, const char *Modifier) {
386+
raw_ostream &O) {
392387
const MCOperand &MO = MI->getOperand(OpNum);
393388
int64_t Imm = MO.getImm();
394389

@@ -419,10 +414,9 @@ void NVPTXInstPrinter::printPrmtMode(const MCInst *MI, int OpNum,
419414
}
420415

421416
void NVPTXInstPrinter::printTmaReductionMode(const MCInst *MI, int OpNum,
422-
raw_ostream &O,
423-
const char *Modifier) {
417+
raw_ostream &O) {
424418
const MCOperand &MO = MI->getOperand(OpNum);
425-
using RedTy = llvm::nvvm::TMAReductionOp;
419+
using RedTy = nvvm::TMAReductionOp;
426420

427421
switch (static_cast<RedTy>(MO.getImm())) {
428422
case RedTy::ADD:

llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,20 @@ class NVPTXInstPrinter : public MCInstPrinter {
3737

3838
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
3939
void printCvtMode(const MCInst *MI, int OpNum, raw_ostream &O,
40-
const char *Modifier = nullptr);
40+
StringRef Modifier = {});
4141
void printCmpMode(const MCInst *MI, int OpNum, raw_ostream &O,
42-
const char *Modifier = nullptr);
43-
void printLdStCode(const MCInst *MI, int OpNum,
44-
raw_ostream &O, const char *Modifier = nullptr);
42+
StringRef Modifier = {});
43+
void printLdStCode(const MCInst *MI, int OpNum, raw_ostream &O,
44+
StringRef Modifier = {});
4545
void printMmaCode(const MCInst *MI, int OpNum, raw_ostream &O,
46-
const char *Modifier = nullptr);
47-
void printMemOperand(const MCInst *MI, int OpNum,
48-
raw_ostream &O, const char *Modifier = nullptr);
49-
void printOffseti32imm(const MCInst *MI, int OpNum, raw_ostream &O,
50-
const char *Modifier = nullptr);
51-
void printHexu32imm(const MCInst *MI, int OpNum, raw_ostream &O,
52-
const char *Modifier = nullptr);
53-
void printProtoIdent(const MCInst *MI, int OpNum,
54-
raw_ostream &O, const char *Modifier = nullptr);
55-
void printPrmtMode(const MCInst *MI, int OpNum, raw_ostream &O,
56-
const char *Modifier = nullptr);
57-
void printTmaReductionMode(const MCInst *MI, int OpNum, raw_ostream &O,
58-
const char *Modifier = nullptr);
46+
StringRef Modifier = {});
47+
void printMemOperand(const MCInst *MI, int OpNum, raw_ostream &O,
48+
StringRef Modifier = {});
49+
void printOffseti32imm(const MCInst *MI, int OpNum, raw_ostream &O);
50+
void printHexu32imm(const MCInst *MI, int OpNum, raw_ostream &O);
51+
void printProtoIdent(const MCInst *MI, int OpNum, raw_ostream &O);
52+
void printPrmtMode(const MCInst *MI, int OpNum, raw_ostream &O);
53+
void printTmaReductionMode(const MCInst *MI, int OpNum, raw_ostream &O);
5954
};
6055

6156
}

0 commit comments

Comments
 (0)