Skip to content

Commit 1892e3f

Browse files
committed
Print single-bit bit range in more compact form
1 parent 9905b7e commit 1892e3f

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

llvm/test/TableGen/DecoderEmitter/big-filter.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ class I : Instruction {
1414
// CHECK-LABEL: static const uint8_t DecoderTable128[32] = {
1515
// CHECK-NEXT: OPC_SwitchField, 0, 64, // 0: switch Inst[63:0] {
1616
// CHECK-NEXT: 1, 8, // 3: case 0x1: {
17-
// CHECK-NEXT: OPC_CheckField, 127, 1, 1, // 5: check Inst[127:127] == 0x1
17+
// CHECK-NEXT: OPC_CheckField, 127, 1, 1, // 5: check Inst[127] == 0x1
1818
// CHECK-NEXT: OPC_Decode, {{[0-9, ]+}}, 0, // 9: decode to I2 using decoder 0
1919
// CHECK-NEXT: // 9: }
2020
// CHECK-NEXT: 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 0,
2121
// CHECK-NEXT: // 13: case 0xffffffffffffffff: {
22-
// CHECK-NEXT: OPC_CheckField, 127, 1, 0, // 24: check Inst[127:127] == 0x0
22+
// CHECK-NEXT: OPC_CheckField, 127, 1, 0, // 24: check Inst[127] == 0x0
2323
// CHECK-NEXT: OPC_Decode, {{[0-9, ]+}}, 0, // 28: decode to I1 using decoder 0
2424
// CHECK-NEXT: // 28: }
2525
// CHECK-NEXT: // 28: } // switch Inst[63:0]

llvm/test/TableGen/DecoderEmitter/trydecode-emission2.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def InstB : TestInstruction {
3131
}
3232

3333
// CHECK-LABEL: static const uint8_t DecoderTable8[26] = {
34-
// CHECK-NEXT: OPC_CheckField, 2, 1, 0, // 0: check Inst[2:2] == 0x0
34+
// CHECK-NEXT: OPC_CheckField, 2, 1, 0, // 0: check Inst[2] == 0x0
3535
// CHECK-NEXT: OPC_CheckField, 5, 3, 0, // 4: check Inst[7:5] == 0x0
3636
// CHECK-NEXT: OPC_Scope, 8, // 8: try {
3737
// CHECK-NEXT: OPC_CheckField, 0, 2, 3, // 10: check Inst[1:0] == 0x3

llvm/test/TableGen/DecoderEmitter/var-len-conflict-1.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class I : Instruction {
1818
// 00000001 ________ I16_1
1919
// 00000010 ________ I16_2
2020

21-
// CHECK: switch Inst[0:0]
21+
// CHECK: switch Inst[0]
2222
// CHECK: decode to I8_0
2323
// CHECK: decode to I8_1
2424
// CHECK: switch Inst[15:8]

llvm/utils/TableGen/DecoderTableEmitter.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void DecoderTableEmitter::emitULEB128(uint64_t Val) {
160160
emitByte(Val);
161161
}
162162

163-
formatted_raw_ostream &DecoderTableEmitter::emitComment(indent Indent) {
163+
raw_ostream &DecoderTableEmitter::emitComment(indent Indent) {
164164
constexpr unsigned CommentColumn = 45;
165165
if (OS.getColumn() > CommentColumn)
166166
OS << '\n';
@@ -169,6 +169,23 @@ formatted_raw_ostream &DecoderTableEmitter::emitComment(indent Indent) {
169169
return OS;
170170
}
171171

172+
namespace {
173+
174+
/// Helper class for printing bit ranges.
175+
struct BitRange {
176+
unsigned MSB, LSB;
177+
178+
friend raw_ostream &operator<<(raw_ostream &OS, BitRange R) {
179+
if (R.MSB == R.LSB)
180+
OS << '[' << R.LSB << ']';
181+
else
182+
OS << '[' << R.MSB << ':' << R.LSB << ']';
183+
return OS;
184+
}
185+
};
186+
187+
} // namespace
188+
172189
void DecoderTableEmitter::emitCheckAnyNode(const CheckAnyNode *N,
173190
indent Indent) {
174191
// TODO: Single-child CheckAny node should be optimized out. For now,
@@ -210,7 +227,7 @@ void DecoderTableEmitter::emitSwitchFieldNode(const SwitchFieldNode *N,
210227
emitULEB128(LSB);
211228
emitUInt8(Width);
212229

213-
emitComment(Indent) << "switch Inst[" << MSB << ':' << LSB << "] {\n";
230+
emitComment(Indent) << "switch Inst" << BitRange{MSB, LSB} << " {\n";
214231

215232
for (auto [Val, Child] : drop_end(N->cases())) {
216233
emitStartLine();
@@ -231,7 +248,7 @@ void DecoderTableEmitter::emitSwitchFieldNode(const SwitchFieldNode *N,
231248
emitNode(Child, Indent + 1);
232249
emitComment(Indent) << "}\n";
233250

234-
emitComment(Indent) << "} // switch Inst[" << MSB << ':' << LSB << "]\n";
251+
emitComment(Indent) << "} // switch Inst" << BitRange{MSB, LSB} << "\n";
235252
}
236253

237254
void DecoderTableEmitter::emitCheckFieldNode(const CheckFieldNode *N,
@@ -246,9 +263,8 @@ void DecoderTableEmitter::emitCheckFieldNode(const CheckFieldNode *N,
246263
emitUInt8(Width);
247264
emitULEB128(Val);
248265

249-
emitComment(Indent);
250-
OS << "check Inst[" << MSB << ':' << LSB << "] == " << format_hex(Val, 0)
251-
<< '\n';
266+
emitComment(Indent) << "check Inst" << BitRange{MSB, LSB}
267+
<< " == " << format_hex(Val, 0) << '\n';
252268
}
253269

254270
void DecoderTableEmitter::emitCheckPredicateNode(const CheckPredicateNode *N,

llvm/utils/TableGen/DecoderTableEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class DecoderTableEmitter {
7272
void emitByte(uint8_t Val);
7373
void emitUInt8(unsigned Val);
7474
void emitULEB128(uint64_t Val);
75-
formatted_raw_ostream &emitComment(indent Indent);
75+
raw_ostream &emitComment(indent Indent);
7676

7777
void emitCheckAnyNode(const CheckAnyNode *N, indent Indent);
7878
void emitCheckAllNode(const CheckAllNode *N, indent Indent);

0 commit comments

Comments
 (0)