diff --git a/llvm/lib/Target/RISCV/RISCVInstrFormats.td b/llvm/lib/Target/RISCV/RISCVInstrFormats.td --- a/llvm/lib/Target/RISCV/RISCVInstrFormats.td +++ b/llvm/lib/Target/RISCV/RISCVInstrFormats.td @@ -236,8 +236,25 @@ let Opcode = opcode.Value; } -class RVInstR4 funct2, RISCVOpcode opcode, dag outs, dag ins, - string opcodestr, string argstr> +class RVInstR4 funct2, bits<3> funct3, RISCVOpcode opcode, dag outs, + dag ins, string opcodestr, string argstr> + : RVInst { + bits<5> rs3; + bits<5> rs2; + bits<5> rs1; + bits<5> rd; + + let Inst{31-27} = rs3; + let Inst{26-25} = funct2; + let Inst{24-20} = rs2; + let Inst{19-15} = rs1; + let Inst{14-12} = funct3; + let Inst{11-7} = rd; + let Opcode = opcode.Value; +} + +class RVInstR4Frm funct2, RISCVOpcode opcode, dag outs, dag ins, + string opcodestr, string argstr> : RVInst { bits<5> rs3; bits<5> rs2; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoB.td b/llvm/lib/Target/RISCV/RISCVInstrInfoB.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoB.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoB.td @@ -125,42 +125,49 @@ "$rd, $rs1, $shamt">; let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in -class RVBTernaryR funct2, bits<3> funct3_b, RISCVOpcode opcode, +class RVBTernaryR funct2, bits<3> funct3, RISCVOpcode opcode, string opcodestr, string argstr> - : RVInstR4 { - let Inst{14-12} = funct3_b; -} + : RVInstR4; // Currently used by FSRI only let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in -class RVBTernaryImm6 funct3_b, RISCVOpcode opcode, +class RVBTernaryImm6 funct3, RISCVOpcode opcode, string opcodestr, string argstr> - : RVInstR4<0b10, opcode, (outs GPR:$rd), - (ins GPR:$rs1, GPR:$rs3, uimmlog2xlen:$shamt), - opcodestr, argstr> { + : RVInst<(outs GPR:$rd), (ins GPR:$rs1, GPR:$rs3, uimmlog2xlen:$shamt), + opcodestr, argstr, [], InstFormatR4> { + bits<5> rs3; bits<6> shamt; + bits<5> rs1; + bits<5> rd; - // NOTE: the first argument of RVInstR4 is hardcoded to 0b10 like the other - // funnel shift instructions. The second bit of the argument though is - // overwritten by the shamt as the encoding of this particular instruction - // requires. This is to obtain op(26) = 1 as required by funnel shift - // instructions without the need of a confusing argument in the definition - // of the instruction. + let Inst{31-27} = rs3; + let Inst{26} = 1; let Inst{25-20} = shamt; - let Inst{14-12} = funct3_b; + let Inst{19-15} = rs1; + let Inst{14-12} = funct3; + let Inst{11-7} = rd; + let Opcode = opcode.Value; } // Currently used by FSRIW only let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in -class RVBTernaryImm5 funct2, bits<3> funct3_b, RISCVOpcode opcode, +class RVBTernaryImm5 funct2, bits<3> funct3, RISCVOpcode opcode, string opcodestr, string argstr> - : RVInstR4 { + : RVInst<(outs GPR:$rd), (ins GPR:$rs1, GPR:$rs3, uimm5:$shamt), + opcodestr, argstr, [], InstFormatR4> { + bits<5> rs3; bits<5> shamt; + bits<5> rs1; + bits<5> rd; + let Inst{31-27} = rs3; + let Inst{26-25} = funct2; let Inst{24-20} = shamt; - let Inst{14-12} = funct3_b; + let Inst{19-15} = rs1; + let Inst{14-12} = funct3; + let Inst{11-7} = rd; + let Opcode = opcode.Value; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoD.td b/llvm/lib/Target/RISCV/RISCVInstrInfoD.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoD.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoD.td @@ -31,9 +31,9 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in class FPFMAD_rrr_frm - : RVInstR4<0b01, opcode, (outs FPR64:$rd), - (ins FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, frmarg:$funct3), - opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">; + : RVInstR4Frm<0b01, opcode, (outs FPR64:$rd), + (ins FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, frmarg:$funct3), + opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">; class FPFMADDynFrmAlias : InstAlias - : RVInstR4<0b00, opcode, (outs FPR32:$rd), - (ins FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, frmarg:$funct3), - opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">; + : RVInstR4Frm<0b00, opcode, (outs FPR32:$rd), + (ins FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, frmarg:$funct3), + opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">; class FPFMASDynFrmAlias : InstAlias - : RVInstR4<0b10, opcode, (outs FPR16:$rd), - (ins FPR16:$rs1, FPR16:$rs2, FPR16:$rs3, frmarg:$funct3), - opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">; + : RVInstR4Frm<0b10, opcode, (outs FPR16:$rd), + (ins FPR16:$rs1, FPR16:$rs2, FPR16:$rs3, frmarg:$funct3), + opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">; class FPFMAHDynFrmAlias : InstAlias