Skip to content

Commit f7af184

Browse files
committed
[NFC][DecoderEmitter] Code cleanup in DecoderEmitter::emitTable
Several code cleanup changes in code to emit decoder tables: - Start comments on each line at a fixed column for readibility. - Combine reperated code to decode and emit ULEB128 into a single function. - Add helper `getDecoderOpName` to print decoder op. - Print Filter/CheckField/predicate index values with those opcodes.
1 parent 983c8b6 commit f7af184

File tree

17 files changed

+236
-205
lines changed

17 files changed

+236
-205
lines changed

llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <cstdint>
2727

2828
using namespace llvm;
29+
using namespace llvm::MCD;
2930

3031
#define DEBUG_TYPE "bpf-disassembler"
3132

llvm/lib/Target/CSKY/Disassembler/CSKYDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/Support/Endian.h"
2727

2828
using namespace llvm;
29+
using namespace llvm::MCD;
2930

3031
#define DEBUG_TYPE "csky-disassembler"
3132

llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define DEBUG_TYPE "hexagon-disassembler"
3535

3636
using namespace llvm;
37+
using namespace llvm::MCD;
3738
using namespace Hexagon;
3839

3940
using DecodeStatus = MCDisassembler::DecodeStatus;

llvm/lib/Target/Lanai/Disassembler/LanaiDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define DEBUG_TYPE "lanai-disassembler"
2929

3030
using namespace llvm;
31+
using namespace llvm::MCD;
3132

3233
typedef MCDisassembler::DecodeStatus DecodeStatus;
3334

llvm/lib/Target/LoongArch/Disassembler/LoongArchDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/Support/Endian.h"
2525

2626
using namespace llvm;
27+
using namespace llvm::MCD;
2728

2829
#define DEBUG_TYPE "loongarch-disassembler"
2930

llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Support/Endian.h"
1919

2020
using namespace llvm;
21+
using namespace llvm::MCD;
2122

2223
DEFINE_PPC_REGCLASSES
2324

llvm/lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cstdint>
2121

2222
using namespace llvm;
23+
using namespace llvm::MCD;
2324

2425
#define DEBUG_TYPE "systemz-disassembler"
2526

llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Support/Endian.h"
2626

2727
using namespace llvm;
28+
using namespace llvm::MCD;
2829

2930
#define DEBUG_TYPE "Xtensa-disassembler"
3031

llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@ class I<dag out_ops, dag in_ops> : Instruction {
3030
let OutOperandList = out_ops;
3131
}
3232

33-
// CHECK: /* 0 */ MCD::OPC_ExtractField, 12, 4, // Inst{15-12} ...
34-
// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 0, 15, 0, // Skip to: 22
35-
// CHECK-NEXT: /* 7 */ MCD::OPC_Scope, 8, 0, // Skip to: 18
36-
// CHECK-NEXT: /* 10 */ MCD::OPC_CheckField, 6, 6, 0,
37-
// CHECK-NEXT: /* 14 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
38-
// CHECK-NEXT: /* 18 */ MCD::OPC_TryDecode, {{[0-9]+}}, 2, 1,
39-
// CHECK-NEXT: /* 22 */ MCD::OPC_FilterValueOrSkip, 1, 15, 0, // Skip to: 41
40-
// CHECK-NEXT: /* 26 */ MCD::OPC_Scope, 8, 0, // Skip to: 37
41-
// CHECK-NEXT: /* 29 */ MCD::OPC_CheckField, 6, 6, 0,
42-
// CHECK-NEXT: /* 33 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
43-
// CHECK-NEXT: /* 37 */ MCD::OPC_TryDecode, {{[0-9]+}}, 2, 1,
44-
// CHECK-NEXT: /* 41 */ MCD::OPC_FilterValueOrSkip, 2, 15, 0, // Skip to: 60
45-
// CHECK-NEXT: /* 45 */ MCD::OPC_Scope, 8, 0, // Skip to: 56
46-
// CHECK-NEXT: /* 48 */ MCD::OPC_CheckField, 6, 6, 0,
47-
// CHECK-NEXT: /* 52 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
48-
// CHECK-NEXT: /* 56 */ MCD::OPC_TryDecode, {{[0-9]+}}, 2, 1,
49-
// CHECK-NEXT: /* 60 */ MCD::OPC_FilterValue, 3,
50-
// CHECK-NEXT: /* 62 */ MCD::OPC_Scope, 8, 0, // Skip to: 73
51-
// CHECK-NEXT: /* 65 */ MCD::OPC_CheckField, 6, 6, 0,
52-
// CHECK-NEXT: /* 69 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
53-
// CHECK-NEXT: /* 73 */ MCD::OPC_TryDecode, {{[0-9]+}}, 2, 1,
33+
// CHECK: /* 0 */ OPC_ExtractField, 12, 4, // Field = Inst{15-12}
34+
// CHECK-NEXT: /* 3 */ OPC_FilterValueOrSkip, 0, 15, 0, // if Field != 0x0 skip to 22
35+
// CHECK-NEXT: /* 7 */ OPC_Scope, 8, 0, // skip to 18
36+
// CHECK-NEXT: /* 10 */ OPC_CheckField, 6, 6, 0, // if Inst{11-6} != 0x0
37+
// CHECK-NEXT: /* 14 */ OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
38+
// CHECK-NEXT: /* 18 */ OPC_TryDecode, {{[0-9]+}}, 2, 1, // Opcode: SHIFT0, DecodeIdx: 1
39+
// CHECK-NEXT: /* 22 */ OPC_FilterValueOrSkip, 1, 15, 0, // if Field != 0x1 skip to 41
40+
// CHECK-NEXT: /* 26 */ OPC_Scope, 8, 0, // skip to 37
41+
// CHECK-NEXT: /* 29 */ OPC_CheckField, 6, 6, 0, // if Inst{11-6} != 0x0
42+
// CHECK-NEXT: /* 33 */ OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
43+
// CHECK-NEXT: /* 37 */ OPC_TryDecode, {{[0-9]+}}, 2, 1, // Opcode: SHIFT1, DecodeIdx: 1
44+
// CHECK-NEXT: /* 41 */ OPC_FilterValueOrSkip, 2, 15, 0, // if Field != 0x2 skip to 60
45+
// CHECK-NEXT: /* 45 */ OPC_Scope, 8, 0, // skip to 56
46+
// CHECK-NEXT: /* 48 */ OPC_CheckField, 6, 6, 0, // if Inst{11-6} != 0x0
47+
// CHECK-NEXT: /* 52 */ OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
48+
// CHECK-NEXT: /* 56 */ OPC_TryDecode, {{[0-9]+}}, 2, 1, // Opcode: SHIFT2, DecodeIdx: 1
49+
// CHECK-NEXT: /* 60 */ OPC_FilterValue, 3, // if Field != 0x3
50+
// CHECK-NEXT: /* 62 */ OPC_Scope, 8, 0, // skip to 73
51+
// CHECK-NEXT: /* 65 */ OPC_CheckField, 6, 6, 0, // if Inst{11-6} != 0x0
52+
// CHECK-NEXT: /* 69 */ OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
53+
// CHECK-NEXT: /* 73 */ OPC_TryDecode, {{[0-9]+}}, 2, 1, // Opcode: SHIFT3, DecodeIdx: 1
5454

5555

5656
class SHIFT<bits<2> opc> : I<(outs), (ins ShAmtOp:$shamt)>, EncSHIFT<opc>;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ class I : Instruction {
1212
// Check that a 64-bit filter with all bits set does not confuse DecoderEmitter.
1313
//
1414
// CHECK-LABEL: static const uint8_t DecoderTable128[34] = {
15-
// CHECK-NEXT: /* 0 */ MCD::OPC_ExtractField, 0, 64, // Inst{63-0} ...
16-
// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 1, 8, 0, // Skip to: 15
17-
// CHECK-NEXT: /* 7 */ MCD::OPC_CheckField, 127, 1, 1,
18-
// CHECK-NEXT: /* 11 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I2, DecodeIdx: 0
19-
// CHECK-NEXT: /* 15 */ MCD::OPC_FilterValue, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1,
20-
// CHECK-NEXT: /* 26 */ MCD::OPC_CheckField, 127, 1, 0,
21-
// CHECK-NEXT: /* 30 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I1, DecodeIdx: 0
15+
// CHECK-NEXT: /* 0 */ OPC_ExtractField, 0, 64, // Field = Inst{63-0}
16+
// CHECK-NEXT: /* 3 */ OPC_FilterValueOrSkip, 1, 8, 0, // if Field != 0x1 skip to 15
17+
// CHECK-NEXT: /* 7 */ OPC_CheckField, 127, 1, 1, // if Inst{127} != 0x1
18+
// CHECK-NEXT: /* 11 */ OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I2, DecodeIdx: 0
19+
// CHECK-NEXT: /* 15 */ OPC_FilterValue, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, // if Field != 0xffffffffffffffff
20+
// CHECK-NEXT: /* 26 */ OPC_CheckField, 127, 1, 0, // if Inst{127} != 0x0
21+
// CHECK-NEXT: /* 30 */ OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I1, DecodeIdx: 0
2222
// CHECK-NEXT: };
2323

2424
def I1 : I {

0 commit comments

Comments
 (0)