Skip to content

Commit 7198c3d

Browse files
authored
[RISCV] Reduce the amount of similar code in RISCVInstPrinter::printRlist. NFC (#92053)
Remove the switch statement and instead do range checks to know which pieces we need to print.
1 parent b7adba8 commit 7198c3d

File tree

1 file changed

+26
-44
lines changed

1 file changed

+26
-44
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -216,62 +216,44 @@ void RISCVInstPrinter::printVTypeI(const MCInst *MI, unsigned OpNo,
216216
RISCVVType::printVType(Imm, O);
217217
}
218218

219+
// Print a Zcmp RList. If we are printing architectural register names rather
220+
// than ABI register names, we need to print "{x1, x8-x9, x18-x27}" for all
221+
// registers. Otherwise, we print "{ra, s0-s11}".
219222
void RISCVInstPrinter::printRlist(const MCInst *MI, unsigned OpNo,
220223
const MCSubtargetInfo &STI, raw_ostream &O) {
221224
unsigned Imm = MI->getOperand(OpNo).getImm();
222225
O << "{";
223-
switch (Imm) {
224-
case RISCVZC::RLISTENCODE::RA:
225-
printRegName(O, RISCV::X1);
226-
break;
227-
case RISCVZC::RLISTENCODE::RA_S0:
228-
printRegName(O, RISCV::X1);
229-
O << ", ";
230-
printRegName(O, RISCV::X8);
231-
break;
232-
case RISCVZC::RLISTENCODE::RA_S0_S1:
233-
printRegName(O, RISCV::X1);
234-
O << ", ";
235-
printRegName(O, RISCV::X8);
236-
O << '-';
237-
printRegName(O, RISCV::X9);
238-
break;
239-
case RISCVZC::RLISTENCODE::RA_S0_S2:
240-
printRegName(O, RISCV::X1);
241-
O << ", ";
242-
printRegName(O, RISCV::X8);
243-
O << '-';
244-
if (ArchRegNames) {
245-
printRegName(O, RISCV::X9);
246-
O << ", ";
247-
}
248-
printRegName(O, RISCV::X18);
249-
break;
250-
case RISCVZC::RLISTENCODE::RA_S0_S3:
251-
case RISCVZC::RLISTENCODE::RA_S0_S4:
252-
case RISCVZC::RLISTENCODE::RA_S0_S5:
253-
case RISCVZC::RLISTENCODE::RA_S0_S6:
254-
case RISCVZC::RLISTENCODE::RA_S0_S7:
255-
case RISCVZC::RLISTENCODE::RA_S0_S8:
256-
case RISCVZC::RLISTENCODE::RA_S0_S9:
257-
case RISCVZC::RLISTENCODE::RA_S0_S11:
258-
printRegName(O, RISCV::X1);
226+
printRegName(O, RISCV::X1);
227+
228+
if (Imm >= RISCVZC::RLISTENCODE::RA_S0) {
259229
O << ", ";
260230
printRegName(O, RISCV::X8);
231+
}
232+
233+
if (Imm >= RISCVZC::RLISTENCODE::RA_S0_S1) {
261234
O << '-';
262-
if (ArchRegNames) {
235+
if (Imm == RISCVZC::RLISTENCODE::RA_S0_S1 || ArchRegNames)
263236
printRegName(O, RISCV::X9);
237+
}
238+
239+
if (Imm >= RISCVZC::RLISTENCODE::RA_S0_S2) {
240+
if (ArchRegNames)
264241
O << ", ";
242+
if (Imm == RISCVZC::RLISTENCODE::RA_S0_S2 || ArchRegNames)
265243
printRegName(O, RISCV::X18);
244+
}
245+
246+
if (Imm >= RISCVZC::RLISTENCODE::RA_S0_S3) {
247+
if (ArchRegNames)
266248
O << '-';
267-
}
268-
printRegName(O, RISCV::X19 + (Imm == RISCVZC::RLISTENCODE::RA_S0_S11
269-
? 8
270-
: Imm - RISCVZC::RLISTENCODE::RA_S0_S3));
271-
break;
272-
default:
273-
llvm_unreachable("invalid register list");
249+
unsigned Offset = (Imm - RISCVZC::RLISTENCODE::RA_S0_S3);
250+
// Encodings for S3-S9 are contiguous. There is no encoding for S10, so we
251+
// must skip to S11(X27).
252+
if (Imm == RISCVZC::RLISTENCODE::RA_S0_S11)
253+
++Offset;
254+
printRegName(O, RISCV::X19 + Offset);
274255
}
256+
275257
O << "}";
276258
}
277259

0 commit comments

Comments
 (0)