Skip to content

Commit 70a9800

Browse files
author
Shao-Ce SUN
committed
[RISCV] Reduce repetitive codes in flw, fsw
Trying to improve code reuse in F,D,Zfh *.td files. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D116089
1 parent 7924b38 commit 70a9800

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

Diff for: llvm/lib/Target/RISCV/RISCVInstrInfoD.td

+2-11
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,12 @@ def RISCVSplitF64 : SDNode<"RISCVISD::SplitF64", SDT_RISCVSplitF64>;
3030
//===----------------------------------------------------------------------===//
3131

3232
let Predicates = [HasStdExtD] in {
33-
34-
let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in
35-
def FLD : RVInstI<0b011, OPC_LOAD_FP, (outs FPR64:$rd),
36-
(ins GPR:$rs1, simm12:$imm12),
37-
"fld", "$rd, ${imm12}(${rs1})">,
38-
Sched<[WriteFLD64, ReadFMemBase]>;
33+
def FLD : FPLoad_r<0b011, "fld", FPR64, WriteFLD64>;
3934

4035
// Operands for stores are in the order srcreg, base, offset rather than
4136
// reflecting the order these fields are specified in the instruction
4237
// encoding.
43-
let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in
44-
def FSD : RVInstS<0b011, OPC_STORE_FP, (outs),
45-
(ins FPR64:$rs2, GPR:$rs1, simm12:$imm12),
46-
"fsd", "$rs2, ${imm12}(${rs1})">,
47-
Sched<[WriteFST64, ReadStoreData, ReadFMemBase]>;
38+
def FSD : FPStore_r<0b011, "fsd", FPR64, WriteFST64>;
4839

4940
let SchedRW = [WriteFMA64, ReadFMA64, ReadFMA64, ReadFMA64] in {
5041
def FMADD_D : FPFMA_rrr_frm<OPC_MADD, 0b01, "fmadd.d", FPR64>;

Diff for: llvm/lib/Target/RISCV/RISCVInstrInfoF.td

+18-10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ def frmarg : Operand<XLenVT> {
7373
// Instruction class templates
7474
//===----------------------------------------------------------------------===//
7575

76+
let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in
77+
class FPLoad_r<bits<3> funct3, string opcodestr, RegisterClass rty,
78+
SchedWrite sw>
79+
: RVInstI<funct3, OPC_LOAD_FP, (outs rty:$rd),
80+
(ins GPR:$rs1, simm12:$imm12),
81+
opcodestr, "$rd, ${imm12}(${rs1})">,
82+
Sched<[sw, ReadFMemBase]>;
83+
84+
let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in
85+
class FPStore_r<bits<3> funct3, string opcodestr, RegisterClass rty,
86+
SchedWrite sw>
87+
: RVInstS<funct3, OPC_STORE_FP, (outs),
88+
(ins rty:$rs2, GPR:$rs1, simm12:$imm12),
89+
opcodestr, "$rs2, ${imm12}(${rs1})">,
90+
Sched<[sw, ReadStoreData, ReadFMemBase]>;
91+
7692
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, mayRaiseFPException = 1,
7793
UseNamedOperandTable = 1, hasPostISelHook = 1 in
7894
class FPFMA_rrr_frm<RISCVOpcode opcode, bits<2> funct2, string opcodestr,
@@ -138,20 +154,12 @@ class FPCmp_rr<bits<7> funct7, bits<3> funct3, string opcodestr,
138154
//===----------------------------------------------------------------------===//
139155

140156
let Predicates = [HasStdExtF] in {
141-
let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in
142-
def FLW : RVInstI<0b010, OPC_LOAD_FP, (outs FPR32:$rd),
143-
(ins GPR:$rs1, simm12:$imm12),
144-
"flw", "$rd, ${imm12}(${rs1})">,
145-
Sched<[WriteFLD32, ReadFMemBase]>;
157+
def FLW : FPLoad_r<0b010, "flw", FPR32, WriteFLD32>;
146158

147159
// Operands for stores are in the order srcreg, base, offset rather than
148160
// reflecting the order these fields are specified in the instruction
149161
// encoding.
150-
let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in
151-
def FSW : RVInstS<0b010, OPC_STORE_FP, (outs),
152-
(ins FPR32:$rs2, GPR:$rs1, simm12:$imm12),
153-
"fsw", "$rs2, ${imm12}(${rs1})">,
154-
Sched<[WriteFST32, ReadStoreData, ReadFMemBase]>;
162+
def FSW : FPStore_r<0b010, "fsw", FPR32, WriteFST32>;
155163

156164
let SchedRW = [WriteFMA32, ReadFMA32, ReadFMA32, ReadFMA32] in {
157165
def FMADD_S : FPFMA_rrr_frm<OPC_MADD, 0b00, "fmadd.s", FPR32>;

Diff for: llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td

+2-10
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,12 @@ def riscv_fmv_x_anyexth
3232
//===----------------------------------------------------------------------===//
3333

3434
let Predicates = [HasStdExtZfhmin] in {
35-
let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in
36-
def FLH : RVInstI<0b001, OPC_LOAD_FP, (outs FPR16:$rd),
37-
(ins GPR:$rs1, simm12:$imm12),
38-
"flh", "$rd, ${imm12}(${rs1})">,
39-
Sched<[WriteFLD16, ReadFMemBase]>;
35+
def FLH : FPLoad_r<0b001, "flh", FPR16, WriteFLD16>;
4036

4137
// Operands for stores are in the order srcreg, base, offset rather than
4238
// reflecting the order these fields are specified in the instruction
4339
// encoding.
44-
let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in
45-
def FSH : RVInstS<0b001, OPC_STORE_FP, (outs),
46-
(ins FPR16:$rs2, GPR:$rs1, simm12:$imm12),
47-
"fsh", "$rs2, ${imm12}(${rs1})">,
48-
Sched<[WriteFST16, ReadStoreData, ReadFMemBase]>;
40+
def FSH : FPStore_r<0b001, "fsh", FPR16, WriteFST16>;
4941
} // Predicates = [HasStdExtZfhmin]
5042

5143
let Predicates = [HasStdExtZfh] in {

0 commit comments

Comments
 (0)