Skip to content

Commit 10c3894

Browse files
authored
[RISCV] Refactor the tablegen classes for P-ext shift instructions. NFC (#150175)
-Rename based on element size suffix rather than immediate size. -Use _ri suffix like we do for shifts in the base ISA. -Push some common code to the base class. -Use shamt for the field name to enable more sharing. -Add funct3 as a parameter which we'll need for right shifts.
1 parent 56b263b commit 10c3894

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoP.td

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,37 @@ class PLI_B_i<bits<8> funct8, string opcodestr>
8989
}
9090

9191
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
92-
class RVPUnary<bits<3> f, string opcodestr, dag operands, string argstr>
93-
: RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), operands, opcodestr, argstr> {
92+
class RVPShift_ri<bits<3> f, bits<3> funct3, string opcodestr, Operand ImmType>
93+
: RVInstIBase<funct3, OPC_OP_IMM_32, (outs GPR:$rd),
94+
(ins GPR:$rs1, ImmType:$shamt), opcodestr,
95+
"$rd, $rs1, $shamt"> {
9496
let Inst{31} = 0b1;
9597
let Inst{30-28} = f;
9698
let Inst{27} = 0b0;
9799
}
98100

99-
class RVPUnaryImm5<bits<3> f, string opcodestr>
100-
: RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm5:$uimm5), "$rd, $rs1, $uimm5"> {
101-
bits<5> uimm5;
101+
class RVPShiftW_ri<bits<3> f, bits<3> funct3, string opcodestr>
102+
: RVPShift_ri<f, funct3, opcodestr, uimm5> {
103+
bits<5> shamt;
102104

103105
let Inst{26-25} = 0b01;
104-
let Inst{24-20} = uimm5;
106+
let Inst{24-20} = shamt;
105107
}
106108

107-
class RVPUnaryImm4<bits<3> f, string opcodestr>
108-
: RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm4:$uimm4), "$rd, $rs1, $uimm4"> {
109-
bits<4> uimm4;
109+
class RVPShiftH_ri<bits<3> f, bits<3> funct3, string opcodestr>
110+
: RVPShift_ri<f, funct3, opcodestr, uimm4> {
111+
bits<4> shamt;
110112

111113
let Inst{26-24} = 0b001;
112-
let Inst{23-20} = uimm4;
114+
let Inst{23-20} = shamt;
113115
}
114116

115-
class RVPUnaryImm3<bits<3> f, string opcodestr>
116-
: RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm3:$uimm3), "$rd, $rs1, $uimm3"> {
117-
bits<3> uimm3;
117+
class RVPShiftB_ri<bits<3> f, bits<3> funct3, string opcodestr>
118+
: RVPShift_ri<f, funct3, opcodestr, uimm3> {
119+
bits<3> shamt;
118120

119121
let Inst{26-23} = 0b0001;
120-
let Inst{22-20} = uimm3;
122+
let Inst{22-20} = shamt;
121123
}
122124

123125
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
@@ -149,16 +151,16 @@ def ABSW : UnaryW_r<0b011000000111, 0b001, "absw">;
149151
} // Predicates = [HasStdExtP, IsRV64]
150152

151153
let Predicates = [HasStdExtP] in {
152-
def PSLLI_B : RVPUnaryImm3<0b000, "pslli.b">;
153-
def PSLLI_H : RVPUnaryImm4<0b000, "pslli.h">;
154-
def PSSLAI_H : RVPUnaryImm4<0b101, "psslai.h">;
154+
def PSLLI_B : RVPShiftB_ri<0b000, 0b010, "pslli.b">;
155+
def PSLLI_H : RVPShiftH_ri<0b000, 0b010, "pslli.h">;
156+
def PSSLAI_H : RVPShiftH_ri<0b101, 0b010, "psslai.h">;
155157
} // Predicates = [HasStdExtP]
156158
let DecoderNamespace = "RV32Only",
157159
Predicates = [HasStdExtP, IsRV32] in
158-
def SSLAI : RVPUnaryImm5<0b101, "sslai">;
160+
def SSLAI : RVPShiftW_ri<0b101, 0b010, "sslai">;
159161
let Predicates = [HasStdExtP, IsRV64] in {
160-
def PSLLI_W : RVPUnaryImm5<0b000, "pslli.w">;
161-
def PSSLAI_W : RVPUnaryImm5<0b101, "psslai.w">;
162+
def PSLLI_W : RVPShiftW_ri<0b000, 0b010, "pslli.w">;
163+
def PSSLAI_W : RVPShiftW_ri<0b101, 0b010, "psslai.w">;
162164
} // Predicates = [HasStdExtP, IsRV64]
163165

164166
let Predicates = [HasStdExtP] in

0 commit comments

Comments
 (0)