Skip to content

Commit 58323be

Browse files
committed
[RISCV] Cleanup instruction formats used for B extension ternary operations.
Rename RVInstR4 as used by F/D/Zfh extensions to RVInstR4Frm. Introduce new RVInstR4 that takes funct3 as a parameter. Add new format classes for FSRI and FSRIW instead of trying to bend RVInstR4 to use a shamt overlayed on rs2 and funct2. Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D100427
1 parent 2e0ee68 commit 58323be

File tree

5 files changed

+55
-31
lines changed

5 files changed

+55
-31
lines changed

llvm/lib/Target/RISCV/RISCVInstrFormats.td

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,25 @@ class RVInstR<bits<7> funct7, bits<3> funct3, RISCVOpcode opcode, dag outs,
236236
let Opcode = opcode.Value;
237237
}
238238

239-
class RVInstR4<bits<2> funct2, RISCVOpcode opcode, dag outs, dag ins,
240-
string opcodestr, string argstr>
239+
class RVInstR4<bits<2> funct2, bits<3> funct3, RISCVOpcode opcode, dag outs,
240+
dag ins, string opcodestr, string argstr>
241+
: RVInst<outs, ins, opcodestr, argstr, [], InstFormatR4> {
242+
bits<5> rs3;
243+
bits<5> rs2;
244+
bits<5> rs1;
245+
bits<5> rd;
246+
247+
let Inst{31-27} = rs3;
248+
let Inst{26-25} = funct2;
249+
let Inst{24-20} = rs2;
250+
let Inst{19-15} = rs1;
251+
let Inst{14-12} = funct3;
252+
let Inst{11-7} = rd;
253+
let Opcode = opcode.Value;
254+
}
255+
256+
class RVInstR4Frm<bits<2> funct2, RISCVOpcode opcode, dag outs, dag ins,
257+
string opcodestr, string argstr>
241258
: RVInst<outs, ins, opcodestr, argstr, [], InstFormatR4> {
242259
bits<5> rs3;
243260
bits<5> rs2;

llvm/lib/Target/RISCV/RISCVInstrInfoB.td

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,42 +125,49 @@ class RVBShfl_ri<bits<7> imm11_5, bits<3> funct3, RISCVOpcode opcode,
125125
"$rd, $rs1, $shamt">;
126126

127127
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
128-
class RVBTernaryR<bits<2> funct2, bits<3> funct3_b, RISCVOpcode opcode,
128+
class RVBTernaryR<bits<2> funct2, bits<3> funct3, RISCVOpcode opcode,
129129
string opcodestr, string argstr>
130-
: RVInstR4<funct2, opcode, (outs GPR:$rd),
131-
(ins GPR:$rs1, GPR:$rs2, GPR:$rs3), opcodestr, argstr> {
132-
let Inst{14-12} = funct3_b;
133-
}
130+
: RVInstR4<funct2, funct3, opcode, (outs GPR:$rd),
131+
(ins GPR:$rs1, GPR:$rs2, GPR:$rs3), opcodestr, argstr>;
134132

135133
// Currently used by FSRI only
136134
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
137-
class RVBTernaryImm6<bits<3> funct3_b, RISCVOpcode opcode,
135+
class RVBTernaryImm6<bits<3> funct3, RISCVOpcode opcode,
138136
string opcodestr, string argstr>
139-
: RVInstR4<0b10, opcode, (outs GPR:$rd),
140-
(ins GPR:$rs1, GPR:$rs3, uimmlog2xlen:$shamt),
141-
opcodestr, argstr> {
137+
: RVInst<(outs GPR:$rd), (ins GPR:$rs1, GPR:$rs3, uimmlog2xlen:$shamt),
138+
opcodestr, argstr, [], InstFormatR4> {
139+
bits<5> rs3;
142140
bits<6> shamt;
141+
bits<5> rs1;
142+
bits<5> rd;
143143

144-
// NOTE: the first argument of RVInstR4 is hardcoded to 0b10 like the other
145-
// funnel shift instructions. The second bit of the argument though is
146-
// overwritten by the shamt as the encoding of this particular instruction
147-
// requires. This is to obtain op(26) = 1 as required by funnel shift
148-
// instructions without the need of a confusing argument in the definition
149-
// of the instruction.
144+
let Inst{31-27} = rs3;
145+
let Inst{26} = 1;
150146
let Inst{25-20} = shamt;
151-
let Inst{14-12} = funct3_b;
147+
let Inst{19-15} = rs1;
148+
let Inst{14-12} = funct3;
149+
let Inst{11-7} = rd;
150+
let Opcode = opcode.Value;
152151
}
153152

154153
// Currently used by FSRIW only
155154
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
156-
class RVBTernaryImm5<bits<2> funct2, bits<3> funct3_b, RISCVOpcode opcode,
155+
class RVBTernaryImm5<bits<2> funct2, bits<3> funct3, RISCVOpcode opcode,
157156
string opcodestr, string argstr>
158-
: RVInstR4<funct2, opcode, (outs GPR:$rd),
159-
(ins GPR:$rs1, GPR:$rs3, uimm5:$shamt), opcodestr, argstr> {
157+
: RVInst<(outs GPR:$rd), (ins GPR:$rs1, GPR:$rs3, uimm5:$shamt),
158+
opcodestr, argstr, [], InstFormatR4> {
159+
bits<5> rs3;
160160
bits<5> shamt;
161+
bits<5> rs1;
162+
bits<5> rd;
161163

164+
let Inst{31-27} = rs3;
165+
let Inst{26-25} = funct2;
162166
let Inst{24-20} = shamt;
163-
let Inst{14-12} = funct3_b;
167+
let Inst{19-15} = rs1;
168+
let Inst{14-12} = funct3;
169+
let Inst{11-7} = rd;
170+
let Opcode = opcode.Value;
164171
}
165172

166173
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfoD.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def RISCVSplitF64 : SDNode<"RISCVISD::SplitF64", SDT_RISCVSplitF64>;
3131

3232
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
3333
class FPFMAD_rrr_frm<RISCVOpcode opcode, string opcodestr>
34-
: RVInstR4<0b01, opcode, (outs FPR64:$rd),
35-
(ins FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, frmarg:$funct3),
36-
opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">;
34+
: RVInstR4Frm<0b01, opcode, (outs FPR64:$rd),
35+
(ins FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, frmarg:$funct3),
36+
opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">;
3737

3838
class FPFMADDynFrmAlias<FPFMAD_rrr_frm Inst, string OpcodeStr>
3939
: InstAlias<OpcodeStr#" $rd, $rs1, $rs2, $rs3",

llvm/lib/Target/RISCV/RISCVInstrInfoF.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def frmarg : Operand<XLenVT> {
4949

5050
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
5151
class FPFMAS_rrr_frm<RISCVOpcode opcode, string opcodestr>
52-
: RVInstR4<0b00, opcode, (outs FPR32:$rd),
53-
(ins FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, frmarg:$funct3),
54-
opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">;
52+
: RVInstR4Frm<0b00, opcode, (outs FPR32:$rd),
53+
(ins FPR32:$rs1, FPR32:$rs2, FPR32:$rs3, frmarg:$funct3),
54+
opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">;
5555

5656
class FPFMASDynFrmAlias<FPFMAS_rrr_frm Inst, string OpcodeStr>
5757
: InstAlias<OpcodeStr#" $rd, $rs1, $rs2, $rs3",

llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def riscv_fmv_x_anyexth
3333

3434
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
3535
class FPFMAH_rrr_frm<RISCVOpcode opcode, string opcodestr>
36-
: RVInstR4<0b10, opcode, (outs FPR16:$rd),
37-
(ins FPR16:$rs1, FPR16:$rs2, FPR16:$rs3, frmarg:$funct3),
38-
opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">;
36+
: RVInstR4Frm<0b10, opcode, (outs FPR16:$rd),
37+
(ins FPR16:$rs1, FPR16:$rs2, FPR16:$rs3, frmarg:$funct3),
38+
opcodestr, "$rd, $rs1, $rs2, $rs3, $funct3">;
3939

4040
class FPFMAHDynFrmAlias<FPFMAH_rrr_frm Inst, string OpcodeStr>
4141
: InstAlias<OpcodeStr#" $rd, $rs1, $rs2, $rs3",

0 commit comments

Comments
 (0)