@@ -35,12 +35,40 @@ def InstFormatPseudo : InstFormat<0>;
35
35
def InstFormatR : InstFormat<1>;
36
36
def InstFormatI : InstFormat<2>;
37
37
def InstFormatS : InstFormat<3>;
38
- def InstFormatSB : InstFormat<4>;
38
+ def InstFormatB : InstFormat<4>;
39
39
def InstFormatU : InstFormat<5>;
40
- def InstFormatOther : InstFormat<6>;
40
+ def InstFormatJ : InstFormat<6>;
41
+ def InstFormatOther : InstFormat<7>;
41
42
42
- class RISCVInst<dag outs, dag ins, string asmstr, list<dag> pattern,
43
- InstFormat format>
43
+ // The following opcode names and match those given in Table 19.1 in the
44
+ // RISC-V User-level ISA specification ("RISC-V base opcode map").
45
+ class RISCVOpcode<bits<7> val> {
46
+ bits<7> Value = val;
47
+ }
48
+ def OPC_LOAD : RISCVOpcode<0b0000011>;
49
+ def OPC_LOAD_FP : RISCVOpcode<0b0000111>;
50
+ def OPC_MISC_MEM : RISCVOpcode<0b0001111>;
51
+ def OPC_OP_IMM : RISCVOpcode<0b0010011>;
52
+ def OPC_AUIPC : RISCVOpcode<0b0010111>;
53
+ def OPC_OP_IMM_32 : RISCVOpcode<0b0011011>;
54
+ def OPC_STORE : RISCVOpcode<0b0100011>;
55
+ def OPC_STORE_FP : RISCVOpcode<0b0100111>;
56
+ def OPC_AMO : RISCVOpcode<0b0101111>;
57
+ def OPC_OP : RISCVOpcode<0b0110011>;
58
+ def OPC_LUI : RISCVOpcode<0b0110111>;
59
+ def OPC_OP_32 : RISCVOpcode<0b0111011>;
60
+ def OPC_MADD : RISCVOpcode<0b1000011>;
61
+ def OPC_MSUB : RISCVOpcode<0b1000111>;
62
+ def OPC_NMSUB : RISCVOpcode<0b1001011>;
63
+ def OPC_NMADD : RISCVOpcode<0b1001111>;
64
+ def OPC_OP_FP : RISCVOpcode<0b1010011>;
65
+ def OPC_BRANCH : RISCVOpcode<0b1100011>;
66
+ def OPC_JALR : RISCVOpcode<0b1100111>;
67
+ def OPC_JAL : RISCVOpcode<0b1101111>;
68
+ def OPC_SYSTEM : RISCVOpcode<0b1110011>;
69
+
70
+ class RVInst<dag outs, dag ins, string opcodestr, string argstr,
71
+ list<dag> pattern, InstFormat format>
44
72
: Instruction {
45
73
field bits<32> Inst;
46
74
// SoftFail is a field the disassembler can use to provide a way for
@@ -58,22 +86,26 @@ class RISCVInst<dag outs, dag ins, string asmstr, list<dag> pattern,
58
86
59
87
dag OutOperandList = outs;
60
88
dag InOperandList = ins;
61
- let AsmString = asmstr ;
89
+ let AsmString = opcodestr # "\t" # argstr ;
62
90
let Pattern = pattern;
63
91
64
92
let TSFlags{3-0} = format.Value;
65
93
}
66
94
67
95
// Pseudo instructions
68
96
class Pseudo<dag outs, dag ins, list<dag> pattern>
69
- : RISCVInst <outs, ins, "", pattern, InstFormatPseudo> {
97
+ : RVInst <outs, ins, "" , "", pattern, InstFormatPseudo> {
70
98
let isPseudo = 1;
71
99
let isCodeGenOnly = 1;
72
100
}
73
101
74
- class FR<bits<7> funct7, bits<3> funct3, bits<7> opcode, dag outs, dag ins,
75
- string asmstr, list<dag> pattern> : RISCVInst<outs, ins, asmstr, pattern, InstFormatR>
76
- {
102
+ // Instruction formats are listed in the order they appear in the RISC-V
103
+ // instruction set manual (R, I, S, B, U, J) with sub-formats (e.g. RVInstR4,
104
+ // RVInstRAtomic) sorted alphabetically.
105
+
106
+ class RVInstR<bits<7> funct7, bits<3> funct3, RISCVOpcode opcode, dag outs,
107
+ dag ins, string opcodestr, string argstr>
108
+ : RVInst<outs, ins, opcodestr, argstr, [], InstFormatR> {
77
109
bits<5> rs2;
78
110
bits<5> rs1;
79
111
bits<5> rd;
@@ -83,12 +115,12 @@ class FR<bits<7> funct7, bits<3> funct3, bits<7> opcode, dag outs, dag ins,
83
115
let Inst{19-15} = rs1;
84
116
let Inst{14-12} = funct3;
85
117
let Inst{11-7} = rd;
86
- let Opcode = opcode;
118
+ let Opcode = opcode.Value ;
87
119
}
88
120
89
- class FI <bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
90
- : RISCVInst<outs, ins, asmstr, pattern, InstFormatI >
91
- {
121
+ class RVInstI <bits<3> funct3, RISCVOpcode opcode, dag outs, dag ins,
122
+ string opcodestr, string argstr >
123
+ : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> {
92
124
bits<12> imm12;
93
125
bits<5> rs1;
94
126
bits<5> rd;
@@ -97,12 +129,12 @@ class FI<bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<
97
129
let Inst{19-15} = rs1;
98
130
let Inst{14-12} = funct3;
99
131
let Inst{11-7} = rd;
100
- let Opcode = opcode;
132
+ let Opcode = opcode.Value ;
101
133
}
102
134
103
- class FI32Shift <bit arithshift, bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
104
- : RISCVInst< outs, ins, asmstr, pattern, InstFormatI >
105
- {
135
+ class RVInstIShift <bit arithshift, bits<3> funct3, RISCVOpcode opcode,
136
+ dag outs, dag ins, string opcodestr, string argstr >
137
+ : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> {
106
138
bits<5> shamt;
107
139
bits<5> rs1;
108
140
bits<5> rd;
@@ -114,12 +146,12 @@ class FI32Shift<bit arithshift, bits<3> funct3, bits<7> opcode, dag outs, dag in
114
146
let Inst{19-15} = rs1;
115
147
let Inst{14-12} = funct3;
116
148
let Inst{11-7} = rd;
117
- let Opcode = opcode;
149
+ let Opcode = opcode.Value ;
118
150
}
119
151
120
- class FS <bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
121
- : RISCVInst<outs, ins, asmstr, pattern, InstFormatS >
122
- {
152
+ class RVInstS <bits<3> funct3, RISCVOpcode opcode, dag outs, dag ins,
153
+ string opcodestr, string argstr >
154
+ : RVInst<outs, ins, opcodestr, argstr, [], InstFormatS> {
123
155
bits<12> imm12;
124
156
bits<5> rs2;
125
157
bits<5> rs1;
@@ -129,12 +161,12 @@ class FS<bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<
129
161
let Inst{19-15} = rs1;
130
162
let Inst{14-12} = funct3;
131
163
let Inst{11-7} = imm12{4-0};
132
- let Opcode = opcode;
164
+ let Opcode = opcode.Value ;
133
165
}
134
166
135
- class FSB <bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
136
- : RISCVInst<outs, ins, asmstr, pattern, InstFormatSB >
137
- {
167
+ class RVInstB <bits<3> funct3, RISCVOpcode opcode, dag outs, dag ins,
168
+ string opcodestr, string argstr >
169
+ : RVInst<outs, ins, opcodestr, argstr, [], InstFormatB> {
138
170
bits<12> imm12;
139
171
bits<5> rs2;
140
172
bits<5> rs1;
@@ -146,23 +178,23 @@ class FSB<bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list
146
178
let Inst{14-12} = funct3;
147
179
let Inst{11-8} = imm12{3-0};
148
180
let Inst{7} = imm12{10};
149
- let Opcode = opcode;
181
+ let Opcode = opcode.Value ;
150
182
}
151
183
152
- class FU<bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
153
- : RISCVInst<outs, ins, asmstr, pattern, InstFormatU >
154
- {
184
+ class RVInstU<RISCVOpcode opcode, dag outs, dag ins, string opcodestr,
185
+ string argstr >
186
+ : RVInst<outs, ins, opcodestr, argstr, [], InstFormatU> {
155
187
bits<20> imm20;
156
188
bits<5> rd;
157
189
158
190
let Inst{31-12} = imm20;
159
191
let Inst{11-7} = rd;
160
- let Opcode = opcode;
192
+ let Opcode = opcode.Value ;
161
193
}
162
194
163
- class FUJ<bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
164
- : RISCVInst<outs, ins, asmstr, pattern, InstFormatU >
165
- {
195
+ class RVInstJ<RISCVOpcode opcode, dag outs, dag ins, string opcodestr,
196
+ string argstr >
197
+ : RVInst<outs, ins, opcodestr, argstr, [], InstFormatJ> {
166
198
bits<20> imm20;
167
199
bits<5> rd;
168
200
@@ -171,5 +203,5 @@ class FUJ<bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
171
203
let Inst{20} = imm20{10};
172
204
let Inst{19-12} = imm20{18-11};
173
205
let Inst{11-7} = rd;
174
- let Opcode = opcode;
206
+ let Opcode = opcode.Value ;
175
207
}
0 commit comments