Skip to content

Commit

Permalink
[RISCV] Enable encodng conflict framework for RISCV target.
Browse files Browse the repository at this point in the history
This PR is a follow-up of PR llvm#96174 which added the frameowrk to resolve
encoding conflicts. This PR explicitly enables this only for RISCV target.
  • Loading branch information
quic-garvgupt committed Jul 1, 2024
1 parent 314cba6 commit c184a1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
17 changes: 12 additions & 5 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1860,11 +1860,18 @@ ParseStatus RISCVAsmParser::parseCSRSystemRegister(OperandVector &Operands) {
if (CE) {
int64_t Imm = CE->getValue();
if (isUInt<12>(Imm)) {
auto SysReg = RISCVSysReg::lookupSysRegByEncoding(Imm);
// Accept an immediate representing a named or un-named Sys Reg
// if the range is valid, regardless of the required features.
Operands.push_back(
RISCVOperand::createSysReg(SysReg ? SysReg->Name : "", S, Imm));
auto Range = RISCVSysReg::lookupSysRegByEncoding(Imm);
// Accept an immediate representing a named Sys Reg if it satisfies the
// the requried features.
for (auto It : Range) {
if (It.haveRequiredFeatures(STI->getFeatureBits())) {
Operands.push_back(RISCVOperand::createSysReg(It.Name, S, Imm));
return ParseStatus::Success;
}
}
// Accept an immediate representing an un-named Sys Reg if the range is
// valid, regardless of the required features.
Operands.push_back(RISCVOperand::createSysReg("", S, Imm));
return ParseStatus::Success;
}
}
Expand Down
13 changes: 8 additions & 5 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ void RISCVInstPrinter::printCSRSystemRegister(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI,
raw_ostream &O) {
unsigned Imm = MI->getOperand(OpNo).getImm();
auto SysReg = RISCVSysReg::lookupSysRegByEncoding(Imm);
if (SysReg && SysReg->haveRequiredFeatures(STI.getFeatureBits()))
markup(O, Markup::Register) << SysReg->Name;
else
markup(O, Markup::Register) << formatImm(Imm);
auto Range = RISCVSysReg::lookupSysRegByEncoding(Imm);
for (auto It : Range) {
if (It.haveRequiredFeatures(STI.getFeatureBits())) {
markup(O, Markup::Register) << It.Name;
return;
}
}
markup(O, Markup::Register) << formatImm(Imm);
}

void RISCVInstPrinter::printFenceArg(const MCInst *MI, unsigned OpNo,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/RISCVSystemOperands.td
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def SysRegsList : GenericTable {

let PrimaryKey = [ "Encoding" ];
let PrimaryKeyName = "lookupSysRegByEncoding";
let PrimaryKeyReturnRange = false;
let PrimaryKeyReturnRange = true;
}

def lookupSysRegByName : SearchIndex {
Expand Down

0 comments on commit c184a1b

Please sign in to comment.