Skip to content

[RISCV] Reduce the amount of similar code in RISCVInstPrinter::printRlist. NFC #92053

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
May 14, 2024
Merged
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
70 changes: 26 additions & 44 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,62 +216,44 @@ void RISCVInstPrinter::printVTypeI(const MCInst *MI, unsigned OpNo,
RISCVVType::printVType(Imm, O);
}

// Print a Zcmp RList. If we are printing architectural register names rather
// than ABI register names, we need to print "{x1, x8-x9, x18-x27}" for all
// registers. Otherwise, we print "{ra, s0-s11}".
void RISCVInstPrinter::printRlist(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O) {
unsigned Imm = MI->getOperand(OpNo).getImm();
O << "{";
switch (Imm) {
case RISCVZC::RLISTENCODE::RA:
printRegName(O, RISCV::X1);
break;
case RISCVZC::RLISTENCODE::RA_S0:
printRegName(O, RISCV::X1);
O << ", ";
printRegName(O, RISCV::X8);
break;
case RISCVZC::RLISTENCODE::RA_S0_S1:
printRegName(O, RISCV::X1);
O << ", ";
printRegName(O, RISCV::X8);
O << '-';
printRegName(O, RISCV::X9);
break;
case RISCVZC::RLISTENCODE::RA_S0_S2:
printRegName(O, RISCV::X1);
O << ", ";
printRegName(O, RISCV::X8);
O << '-';
if (ArchRegNames) {
printRegName(O, RISCV::X9);
O << ", ";
}
printRegName(O, RISCV::X18);
break;
case RISCVZC::RLISTENCODE::RA_S0_S3:
case RISCVZC::RLISTENCODE::RA_S0_S4:
case RISCVZC::RLISTENCODE::RA_S0_S5:
case RISCVZC::RLISTENCODE::RA_S0_S6:
case RISCVZC::RLISTENCODE::RA_S0_S7:
case RISCVZC::RLISTENCODE::RA_S0_S8:
case RISCVZC::RLISTENCODE::RA_S0_S9:
case RISCVZC::RLISTENCODE::RA_S0_S11:
printRegName(O, RISCV::X1);
printRegName(O, RISCV::X1);

if (Imm >= RISCVZC::RLISTENCODE::RA_S0) {
O << ", ";
printRegName(O, RISCV::X8);
}

if (Imm >= RISCVZC::RLISTENCODE::RA_S0_S1) {
O << '-';
if (ArchRegNames) {
if (Imm == RISCVZC::RLISTENCODE::RA_S0_S1 || ArchRegNames)
printRegName(O, RISCV::X9);
}

if (Imm >= RISCVZC::RLISTENCODE::RA_S0_S2) {
if (ArchRegNames)
O << ", ";
if (Imm == RISCVZC::RLISTENCODE::RA_S0_S2 || ArchRegNames)
printRegName(O, RISCV::X18);
}

if (Imm >= RISCVZC::RLISTENCODE::RA_S0_S3) {
if (ArchRegNames)
O << '-';
}
printRegName(O, RISCV::X19 + (Imm == RISCVZC::RLISTENCODE::RA_S0_S11
? 8
: Imm - RISCVZC::RLISTENCODE::RA_S0_S3));
break;
default:
llvm_unreachable("invalid register list");
unsigned Offset = (Imm - RISCVZC::RLISTENCODE::RA_S0_S3);
// Encodings for S3-S9 are contiguous. There is no encoding for S10, so we
// must skip to S11(X27).
if (Imm == RISCVZC::RLISTENCODE::RA_S0_S11)
++Offset;
printRegName(O, RISCV::X19 + Offset);
}

O << "}";
}

Expand Down
Loading