Skip to content

Commit 864fcfc

Browse files
authored
[RISCV] Combine RVBUnary and RVKUnary into classes that are more similar to ALU(W)_r(r/i). NFC (#111279)
Create Unary_r and UnaryW_r that use OP_IMM and OP_IMM_32.
1 parent 4986510 commit 864fcfc

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,16 @@ class Priv_rr<string opcodestr, bits<7> funct7>
606606
let rd = 0;
607607
}
608608

609+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
610+
class Unary_r<bits<12> imm12, bits<3> funct3, string opcodestr>
611+
: RVInstIUnary<imm12, funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1),
612+
opcodestr, "$rd, $rs1">;
613+
614+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
615+
class UnaryW_r<bits<12> imm12, bits<3> funct3, string opcodestr>
616+
: RVInstIUnary<imm12, funct3, OPC_OP_IMM_32, (outs GPR:$rd), (ins GPR:$rs1),
617+
opcodestr, "$rd, $rs1">;
618+
609619
//===----------------------------------------------------------------------===//
610620
// Instructions
611621
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,6 @@ class RVBUnaryR<bits<7> funct7, bits<3> funct3,
232232
let rs2 = 0;
233233
}
234234

235-
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
236-
class RVBUnary<bits<12> imm12, bits<3> funct3,
237-
RISCVOpcode opcode, string opcodestr>
238-
: RVInstIUnary<imm12, funct3, opcode, (outs GPR:$rd), (ins GPR:$rs1),
239-
opcodestr, "$rd, $rs1">;
240-
241235
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
242236
class RVBShift_ri<bits<5> imm11_7, bits<3> funct3, RISCVOpcode opcode,
243237
string opcodestr>
@@ -333,27 +327,27 @@ def XPERM8 : ALU_rr<0b0010100, 0b100, "xperm8">,
333327
} // Predicates = [HasStdExtZbkx]
334328

335329
let Predicates = [HasStdExtZbb], IsSignExtendingOpW = 1 in {
336-
def CLZ : RVBUnary<0b011000000000, 0b001, OPC_OP_IMM, "clz">,
330+
def CLZ : Unary_r<0b011000000000, 0b001, "clz">,
337331
Sched<[WriteCLZ, ReadCLZ]>;
338-
def CTZ : RVBUnary<0b011000000001, 0b001, OPC_OP_IMM, "ctz">,
332+
def CTZ : Unary_r<0b011000000001, 0b001, "ctz">,
339333
Sched<[WriteCTZ, ReadCTZ]>;
340-
def CPOP : RVBUnary<0b011000000010, 0b001, OPC_OP_IMM, "cpop">,
334+
def CPOP : Unary_r<0b011000000010, 0b001, "cpop">,
341335
Sched<[WriteCPOP, ReadCPOP]>;
342336
} // Predicates = [HasStdExtZbb]
343337

344338
let Predicates = [HasStdExtZbb, IsRV64], IsSignExtendingOpW = 1 in {
345-
def CLZW : RVBUnary<0b011000000000, 0b001, OPC_OP_IMM_32, "clzw">,
346-
Sched<[WriteCLZ32, ReadCLZ32]>;
347-
def CTZW : RVBUnary<0b011000000001, 0b001, OPC_OP_IMM_32, "ctzw">,
348-
Sched<[WriteCTZ32, ReadCTZ32]>;
349-
def CPOPW : RVBUnary<0b011000000010, 0b001, OPC_OP_IMM_32, "cpopw">,
350-
Sched<[WriteCPOP32, ReadCPOP32]>;
339+
def CLZW : UnaryW_r<0b011000000000, 0b001, "clzw">,
340+
Sched<[WriteCLZ32, ReadCLZ32]>;
341+
def CTZW : UnaryW_r<0b011000000001, 0b001, "ctzw">,
342+
Sched<[WriteCTZ32, ReadCTZ32]>;
343+
def CPOPW : UnaryW_r<0b011000000010, 0b001, "cpopw">,
344+
Sched<[WriteCPOP32, ReadCPOP32]>;
351345
} // Predicates = [HasStdExtZbb, IsRV64]
352346

353347
let Predicates = [HasStdExtZbb], IsSignExtendingOpW = 1 in {
354-
def SEXT_B : RVBUnary<0b011000000100, 0b001, OPC_OP_IMM, "sext.b">,
348+
def SEXT_B : Unary_r<0b011000000100, 0b001, "sext.b">,
355349
Sched<[WriteIALU, ReadIALU]>;
356-
def SEXT_H : RVBUnary<0b011000000101, 0b001, OPC_OP_IMM, "sext.h">,
350+
def SEXT_H : Unary_r<0b011000000101, 0b001, "sext.h">,
357351
Sched<[WriteIALU, ReadIALU]>;
358352
} // Predicates = [HasStdExtZbb]
359353

@@ -403,28 +397,28 @@ def ZEXT_H_RV64 : RVBUnaryR<0b0000100, 0b100, OPC_OP_32, "zext.h">,
403397
} // Predicates = [HasStdExtZbb, IsRV64]
404398

405399
let Predicates = [HasStdExtZbbOrZbkb, IsRV32] in {
406-
def REV8_RV32 : RVBUnary<0b011010011000, 0b101, OPC_OP_IMM, "rev8">,
400+
def REV8_RV32 : Unary_r<0b011010011000, 0b101, "rev8">,
407401
Sched<[WriteREV8, ReadREV8]>;
408402
} // Predicates = [HasStdExtZbbOrZbkb, IsRV32]
409403

410404
let Predicates = [HasStdExtZbbOrZbkb, IsRV64] in {
411-
def REV8_RV64 : RVBUnary<0b011010111000, 0b101, OPC_OP_IMM, "rev8">,
405+
def REV8_RV64 : Unary_r<0b011010111000, 0b101, "rev8">,
412406
Sched<[WriteREV8, ReadREV8]>;
413407
} // Predicates = [HasStdExtZbbOrZbkb, IsRV64]
414408

415409
let Predicates = [HasStdExtZbb] in {
416-
def ORC_B : RVBUnary<0b001010000111, 0b101, OPC_OP_IMM, "orc.b">,
410+
def ORC_B : Unary_r<0b001010000111, 0b101, "orc.b">,
417411
Sched<[WriteORCB, ReadORCB]>;
418412
} // Predicates = [HasStdExtZbb]
419413

420414
let Predicates = [HasStdExtZbkb] in
421-
def BREV8 : RVBUnary<0b011010000111, 0b101, OPC_OP_IMM, "brev8">,
415+
def BREV8 : Unary_r<0b011010000111, 0b101, "brev8">,
422416
Sched<[WriteBREV8, ReadBREV8]>;
423417

424418
let Predicates = [HasStdExtZbkb, IsRV32] in {
425-
def ZIP_RV32 : RVBUnary<0b000010001111, 0b001, OPC_OP_IMM, "zip">,
419+
def ZIP_RV32 : Unary_r<0b000010001111, 0b001, "zip">,
426420
Sched<[WriteZIP, ReadZIP]>;
427-
def UNZIP_RV32 : RVBUnary<0b000010001111, 0b101, OPC_OP_IMM, "unzip">,
421+
def UNZIP_RV32 : Unary_r<0b000010001111, 0b101, "unzip">,
428422
Sched<[WriteZIP, ReadZIP]>;
429423
} // Predicates = [HasStdExtZbkb, IsRV32]
430424

llvm/lib/Target/RISCV/RISCVInstrInfoZk.td

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ def byteselect : RISCVOp<i32>, TImmLeaf<i32, [{return isUInt<2>(Imm);}]> {
5252
//===----------------------------------------------------------------------===//
5353
// Instruction class templates
5454
//===----------------------------------------------------------------------===//
55-
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
56-
class RVKUnary<bits<12> imm12, bits<3> funct3, string opcodestr>
57-
: RVInstIUnary<imm12, funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1),
58-
opcodestr, "$rd, $rs1">;
5955

6056
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
6157
class RVKByteSelect<bits<5> funct5, string opcodestr>
@@ -88,7 +84,7 @@ let Predicates = [HasStdExtZknd, IsRV64] in {
8884
def AES64DS : ALU_rr<0b0011101, 0b000, "aes64ds">;
8985
def AES64DSM : ALU_rr<0b0011111, 0b000, "aes64dsm">;
9086

91-
def AES64IM : RVKUnary<0b001100000000, 0b001, "aes64im">;
87+
def AES64IM : Unary_r<0b001100000000, 0b001, "aes64im">;
9288
} // Predicates = [HasStdExtZknd, IsRV64]
9389

9490
let Predicates = [HasStdExtZkndOrZkne, IsRV64] in {
@@ -108,10 +104,10 @@ def AES64ESM : ALU_rr<0b0011011, 0b000, "aes64esm">;
108104
} // Predicates = [HasStdExtZkne, IsRV64]
109105

110106
let Predicates = [HasStdExtZknh], IsSignExtendingOpW = 1 in {
111-
def SHA256SIG0 : RVKUnary<0b000100000010, 0b001, "sha256sig0">;
112-
def SHA256SIG1 : RVKUnary<0b000100000011, 0b001, "sha256sig1">;
113-
def SHA256SUM0 : RVKUnary<0b000100000000, 0b001, "sha256sum0">;
114-
def SHA256SUM1 : RVKUnary<0b000100000001, 0b001, "sha256sum1">;
107+
def SHA256SIG0 : Unary_r<0b000100000010, 0b001, "sha256sig0">;
108+
def SHA256SIG1 : Unary_r<0b000100000011, 0b001, "sha256sig1">;
109+
def SHA256SUM0 : Unary_r<0b000100000000, 0b001, "sha256sum0">;
110+
def SHA256SUM1 : Unary_r<0b000100000001, 0b001, "sha256sum1">;
115111
} // Predicates = [HasStdExtZknh]
116112

117113
let Predicates = [HasStdExtZknh, IsRV32] in {
@@ -124,10 +120,10 @@ def SHA512SUM1R : ALU_rr<0b0101001, 0b000, "sha512sum1r">;
124120
} // [HasStdExtZknh, IsRV32]
125121

126122
let Predicates = [HasStdExtZknh, IsRV64] in {
127-
def SHA512SIG0 : RVKUnary<0b000100000110, 0b001, "sha512sig0">;
128-
def SHA512SIG1 : RVKUnary<0b000100000111, 0b001, "sha512sig1">;
129-
def SHA512SUM0 : RVKUnary<0b000100000100, 0b001, "sha512sum0">;
130-
def SHA512SUM1 : RVKUnary<0b000100000101, 0b001, "sha512sum1">;
123+
def SHA512SIG0 : Unary_r<0b000100000110, 0b001, "sha512sig0">;
124+
def SHA512SIG1 : Unary_r<0b000100000111, 0b001, "sha512sig1">;
125+
def SHA512SUM0 : Unary_r<0b000100000100, 0b001, "sha512sum0">;
126+
def SHA512SUM1 : Unary_r<0b000100000101, 0b001, "sha512sum1">;
131127
} // Predicates = [HasStdExtZknh, IsRV64]
132128

133129
let Predicates = [HasStdExtZksed], IsSignExtendingOpW = 1 in {
@@ -136,8 +132,8 @@ def SM4KS : RVKByteSelect<0b11010, "sm4ks">;
136132
} // Predicates = [HasStdExtZksed]
137133

138134
let Predicates = [HasStdExtZksh], IsSignExtendingOpW = 1 in {
139-
def SM3P0 : RVKUnary<0b000100001000, 0b001, "sm3p0">;
140-
def SM3P1 : RVKUnary<0b000100001001, 0b001, "sm3p1">;
135+
def SM3P0 : Unary_r<0b000100001000, 0b001, "sm3p0">;
136+
def SM3P1 : Unary_r<0b000100001001, 0b001, "sm3p1">;
141137
} // Predicates = [HasStdExtZksh]
142138

143139
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)