Skip to content

Commit 721571b

Browse files
committed
[RISCV] Introduce a common tablegen base class for RVInst and RVInst16.
This gives us a common place to put the TSFlags and the Namespace. Removes TSFlags declaration duplication for D155690. Reviewed By: wangpc Differential Revision: https://reviews.llvm.org/D155744
1 parent 6de2735 commit 721571b

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

llvm/lib/Target/RISCV/RISCVInstrFormats.td

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,9 @@ def OPC_SYSTEM : RISCVOpcode<"SYSTEM", 0b1110011>;
156156
def OPC_OP_P : RISCVOpcode<"OP_P", 0b1110111>;
157157
def OPC_CUSTOM_3 : RISCVOpcode<"CUSTOM_3", 0b1111011>;
158158

159-
class RVInst<dag outs, dag ins, string opcodestr, string argstr,
160-
list<dag> pattern, InstFormat format>
161-
: Instruction {
162-
field bits<32> Inst;
163-
// SoftFail is a field the disassembler can use to provide a way for
164-
// instructions to not match without killing the whole decode process. It is
165-
// mainly used for ARM, but Tablegen expects this field to exist or it fails
166-
// to build the decode table.
167-
field bits<32> SoftFail = 0;
168-
let Size = 4;
169-
170-
bits<7> Opcode = 0;
171-
172-
let Inst{6-0} = Opcode;
173-
159+
class RVInstCommon<InstFormat format> : Instruction {
174160
let Namespace = "RISCV";
175161

176-
dag OutOperandList = outs;
177-
dag InOperandList = ins;
178-
let AsmString = opcodestr # "\t" # argstr;
179-
let Pattern = pattern;
180-
181162
let TSFlags{4-0} = format.Value;
182163

183164
// Defaults
@@ -227,6 +208,27 @@ class RVInst<dag outs, dag ins, string opcodestr, string argstr,
227208
let TSFlags{20} = UsesVXRM;
228209
}
229210

211+
class RVInst<dag outs, dag ins, string opcodestr, string argstr,
212+
list<dag> pattern, InstFormat format>
213+
: RVInstCommon<format> {
214+
field bits<32> Inst;
215+
// SoftFail is a field the disassembler can use to provide a way for
216+
// instructions to not match without killing the whole decode process. It is
217+
// mainly used for ARM, but Tablegen expects this field to exist or it fails
218+
// to build the decode table.
219+
field bits<32> SoftFail = 0;
220+
let Size = 4;
221+
222+
bits<7> Opcode = 0;
223+
224+
let Inst{6-0} = Opcode;
225+
226+
dag OutOperandList = outs;
227+
dag InOperandList = ins;
228+
let AsmString = opcodestr # "\t" # argstr;
229+
let Pattern = pattern;
230+
}
231+
230232
// Pseudo instructions
231233
class Pseudo<dag outs, dag ins, list<dag> pattern, string opcodestr = "", string argstr = "">
232234
: RVInst<outs, ins, opcodestr, argstr, pattern, InstFormatPseudo> {

llvm/lib/Target/RISCV/RISCVInstrFormatsC.td

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class RVInst16<dag outs, dag ins, string opcodestr, string argstr,
1414
list<dag> pattern, InstFormat format>
15-
: Instruction {
15+
: RVInstCommon<format> {
1616
field bits<16> Inst;
1717
// SoftFail is a field the disassembler can use to provide a way for
1818
// instructions to not match without killing the whole decode process. It is
@@ -23,14 +23,10 @@ class RVInst16<dag outs, dag ins, string opcodestr, string argstr,
2323

2424
bits<2> Opcode = 0;
2525

26-
let Namespace = "RISCV";
27-
2826
dag OutOperandList = outs;
2927
dag InOperandList = ins;
3028
let AsmString = opcodestr # "\t" # argstr;
3129
let Pattern = pattern;
32-
33-
let TSFlags{4-0} = format.Value;
3430
}
3531

3632
class RVInst16CR<bits<4> funct4, bits<2> opcode, dag outs, dag ins,

0 commit comments

Comments
 (0)