Skip to content

Commit d58f572

Browse files
authored
[RISCV] Use named sub-operands to simplify encoding/decoding for CoreV Reg-Reg instructions. (#133181)
We can name the sub-operands using a DAG in the 'ins'. This allows those names to be matched to the encoding fields. This removes the need for a custom encoder/decoder that treats the 2 sub-operands as a single 10-bit value. While doing this, I noticed the base and offset names in the MIOperandInfo were swapped relative to how the operands are parsed and printed. Assuming that I've correctly understood the parsing/print format as "offset(base)".
1 parent e54f31a commit d58f572

File tree

3 files changed

+10
-48
lines changed

3 files changed

+10
-48
lines changed

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,6 @@ static DecodeStatus decodeXTHeadMemPair(MCInst &Inst, uint32_t Insn,
507507
static DecodeStatus decodeZcmpRlist(MCInst &Inst, uint32_t Imm,
508508
uint64_t Address, const void *Decoder);
509509

510-
static DecodeStatus decodeRegReg(MCInst &Inst, uint32_t Insn, uint64_t Address,
511-
const MCDisassembler *Decoder);
512-
513510
static DecodeStatus decodeZcmpSpimm(MCInst &Inst, uint32_t Imm,
514511
uint64_t Address, const void *Decoder);
515512

@@ -621,15 +618,6 @@ static DecodeStatus decodeZcmpRlist(MCInst &Inst, uint32_t Imm,
621618
return MCDisassembler::Success;
622619
}
623620

624-
static DecodeStatus decodeRegReg(MCInst &Inst, uint32_t Insn, uint64_t Address,
625-
const MCDisassembler *Decoder) {
626-
uint32_t Rs1 = fieldFromInstruction(Insn, 0, 5);
627-
uint32_t Rs2 = fieldFromInstruction(Insn, 5, 5);
628-
DecodeGPRRegisterClass(Inst, Rs1, Address, Decoder);
629-
DecodeGPRRegisterClass(Inst, Rs2, Address, Decoder);
630-
return MCDisassembler::Success;
631-
}
632-
633621
static DecodeStatus decodeZcmpSpimm(MCInst &Inst, uint32_t Imm,
634622
uint64_t Address, const void *Decoder) {
635623
Inst.addOperand(MCOperand::createImm(Imm));

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

-17
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ class RISCVMCCodeEmitter : public MCCodeEmitter {
103103
unsigned getRlistOpValue(const MCInst &MI, unsigned OpNo,
104104
SmallVectorImpl<MCFixup> &Fixups,
105105
const MCSubtargetInfo &STI) const;
106-
107-
unsigned getRegReg(const MCInst &MI, unsigned OpNo,
108-
SmallVectorImpl<MCFixup> &Fixups,
109-
const MCSubtargetInfo &STI) const;
110106
};
111107
} // end anonymous namespace
112108

@@ -621,17 +617,4 @@ unsigned RISCVMCCodeEmitter::getRlistOpValue(const MCInst &MI, unsigned OpNo,
621617
return Imm;
622618
}
623619

624-
unsigned RISCVMCCodeEmitter::getRegReg(const MCInst &MI, unsigned OpNo,
625-
SmallVectorImpl<MCFixup> &Fixups,
626-
const MCSubtargetInfo &STI) const {
627-
const MCOperand &MO = MI.getOperand(OpNo);
628-
const MCOperand &MO1 = MI.getOperand(OpNo + 1);
629-
assert(MO.isReg() && MO1.isReg() && "Expected registers.");
630-
631-
unsigned Op = Ctx.getRegisterInfo()->getEncodingValue(MO.getReg());
632-
unsigned Op1 = Ctx.getRegisterInfo()->getEncodingValue(MO1.getReg());
633-
634-
return Op | Op1 << 5;
635-
}
636-
637620
#include "RISCVGenMCCodeEmitter.inc"

llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td

+10-19
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ def CVrrAsmOperand : AsmOperandClass {
2424
def CVrr : Operand<i32>,
2525
ComplexPattern<i32, 2, "SelectAddrRegReg",[]> {
2626
let ParserMatchClass = CVrrAsmOperand;
27-
let EncoderMethod = "getRegReg";
28-
let DecoderMethod = "decodeRegReg";
2927
let PrintMethod = "printRegReg";
30-
let MIOperandInfo = (ops GPR:$base, GPR:$offset);
28+
let MIOperandInfo = (ops GPR:$offset, GPR:$base);
3129
}
3230

3331
def cv_tuimm2 : TImmLeaf<XLenVT, [{return isUInt<2>(Imm);}]>;
@@ -288,17 +286,9 @@ class CVLoad_rr_inc<bits<7> funct7, bits<3> funct3, string opcodestr>
288286
}
289287

290288
class CVLoad_rr<bits<7> funct7, bits<3> funct3, string opcodestr>
291-
: RVInstR<funct7, funct3, OPC_CUSTOM_1, (outs GPR:$rd), (ins CVrr:$cvrr),
292-
opcodestr, "$rd, $cvrr"> {
293-
bits<5> rd;
294-
bits<10> cvrr;
295-
296-
let Inst{31-25} = funct7;
297-
let Inst{24-20} = cvrr{4-0};
298-
let Inst{19-15} = cvrr{9-5};
299-
let Inst{14-12} = funct3;
300-
let Inst{11-7} = rd;
301-
}
289+
: RVInstR<funct7, funct3, OPC_CUSTOM_1, (outs GPR:$rd),
290+
(ins (CVrr $rs2, $rs1):$addr),
291+
opcodestr, "$rd, $addr">;
302292
} // hasSideEffects = 0, mayLoad = 1, mayStore = 0
303293

304294
let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in {
@@ -327,16 +317,17 @@ class CVStore_rr_inc<bits<3> funct3, bits<7> funct7, string opcodestr>
327317

328318

329319
class CVStore_rr<bits<3> funct3, bits<7> funct7, string opcodestr>
330-
: RVInst<(outs), (ins GPR:$rs2, CVrr:$cvrr), opcodestr, "$rs2, $cvrr", [],
331-
InstFormatOther> {
320+
: RVInst<(outs), (ins GPR:$rs2, (CVrr $rs3, $rs1):$addr), opcodestr,
321+
"$rs2, $addr", [], InstFormatOther> {
322+
bits<5> rs1;
332323
bits<5> rs2;
333-
bits<10> cvrr;
324+
bits<5> rs3;
334325

335326
let Inst{31-25} = funct7;
336327
let Inst{24-20} = rs2;
337-
let Inst{19-15} = cvrr{9-5};
328+
let Inst{19-15} = rs1;
338329
let Inst{14-12} = funct3;
339-
let Inst{11-7} = cvrr{4-0};
330+
let Inst{11-7} = rs3;
340331
let Inst{6-0} = OPC_CUSTOM_1.Value;
341332
}
342333
} // hasSideEffects = 0, mayLoad = 0, mayStore = 1

0 commit comments

Comments
 (0)