-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[NFC][DecoderEmitter] Code cleanup in DecoderEmitter::emitTable
#158014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-xtensa @llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) ChangesSeveral code cleanup changes in code to emit decoder tables:
Full diff: https://github.com/llvm/llvm-project/pull/158014.diff 6 Files Affected:
diff --git a/llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td b/llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td
index ec7e35e1ecac7..be12384cdb032 100644
--- a/llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td
+++ b/llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td
@@ -30,27 +30,27 @@ class I<dag out_ops, dag in_ops> : Instruction {
let OutOperandList = out_ops;
}
-// CHECK: /* 0 */ MCD::OPC_ExtractField, 12, 4, // Inst{15-12} ...
-// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 0, 15, 0, // Skip to: 22
-// CHECK-NEXT: /* 7 */ MCD::OPC_Scope, 8, 0, // Skip to: 18
-// CHECK-NEXT: /* 10 */ MCD::OPC_CheckField, 6, 6, 0,
-// CHECK-NEXT: /* 14 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
-// CHECK-NEXT: /* 18 */ MCD::OPC_TryDecode, 187, 2, 1,
-// CHECK-NEXT: /* 22 */ MCD::OPC_FilterValueOrSkip, 1, 15, 0, // Skip to: 41
-// CHECK-NEXT: /* 26 */ MCD::OPC_Scope, 8, 0, // Skip to: 37
-// CHECK-NEXT: /* 29 */ MCD::OPC_CheckField, 6, 6, 0,
-// CHECK-NEXT: /* 33 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
-// CHECK-NEXT: /* 37 */ MCD::OPC_TryDecode, 188, 2, 1,
-// CHECK-NEXT: /* 41 */ MCD::OPC_FilterValueOrSkip, 2, 15, 0, // Skip to: 60
-// CHECK-NEXT: /* 45 */ MCD::OPC_Scope, 8, 0, // Skip to: 56
-// CHECK-NEXT: /* 48 */ MCD::OPC_CheckField, 6, 6, 0,
-// CHECK-NEXT: /* 52 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
-// CHECK-NEXT: /* 56 */ MCD::OPC_TryDecode, 189, 2, 1,
-// CHECK-NEXT: /* 60 */ MCD::OPC_FilterValue, 3,
-// CHECK-NEXT: /* 62 */ MCD::OPC_Scope, 8, 0, // Skip to: 73
-// CHECK-NEXT: /* 65 */ MCD::OPC_CheckField, 6, 6, 0,
-// CHECK-NEXT: /* 69 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
-// CHECK-NEXT: /* 73 */ MCD::OPC_TryDecode, 190, 2, 1,
+// CHECK: /* 0 */ MCD::OPC_ExtractField, 12, 4, // Inst{15-12}
+// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 0, 15, 0, // FilterVal = 0x0, Skip to: 22
+// CHECK-NEXT: /* 7 */ MCD::OPC_Scope, 8, 0, // Skip to: 18
+// CHECK-NEXT: /* 10 */ MCD::OPC_CheckField, 6, 6, 0, // Inst{11-6} == 0x0
+// CHECK-NEXT: /* 14 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
+// CHECK-NEXT: /* 18 */ MCD::OPC_TryDecode, 187, 2, 1, // Opcode: SHIFT0, DecodeIdx: 1
+// CHECK-NEXT: /* 22 */ MCD::OPC_FilterValueOrSkip, 1, 15, 0, // FilterVal = 0x1, Skip to: 41
+// CHECK-NEXT: /* 26 */ MCD::OPC_Scope, 8, 0, // Skip to: 37
+// CHECK-NEXT: /* 29 */ MCD::OPC_CheckField, 6, 6, 0, // Inst{11-6} == 0x0
+// CHECK-NEXT: /* 33 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
+// CHECK-NEXT: /* 37 */ MCD::OPC_TryDecode, 188, 2, 1, // Opcode: SHIFT1, DecodeIdx: 1
+// CHECK-NEXT: /* 41 */ MCD::OPC_FilterValueOrSkip, 2, 15, 0, // FilterVal = 0x2, Skip to: 60
+// CHECK-NEXT: /* 45 */ MCD::OPC_Scope, 8, 0, // Skip to: 56
+// CHECK-NEXT: /* 48 */ MCD::OPC_CheckField, 6, 6, 0, // Inst{11-6} == 0x0
+// CHECK-NEXT: /* 52 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
+// CHECK-NEXT: /* 56 */ MCD::OPC_TryDecode, 189, 2, 1, // Opcode: SHIFT2, DecodeIdx: 1
+// CHECK-NEXT: /* 60 */ MCD::OPC_FilterValue, 3, // FilterVal = 0x3
+// CHECK-NEXT: /* 62 */ MCD::OPC_Scope, 8, 0, // Skip to: 73
+// CHECK-NEXT: /* 65 */ MCD::OPC_CheckField, 6, 6, 0, // Inst{11-6} == 0x0
+// CHECK-NEXT: /* 69 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP, DecodeIdx: 0
+// CHECK-NEXT: /* 73 */ MCD::OPC_TryDecode, 190, 2, 1, // Opcode: SHIFT3, DecodeIdx: 1
class SHIFT<bits<2> opc> : I<(outs), (ins ShAmtOp:$shamt)>, EncSHIFT<opc>;
diff --git a/llvm/test/TableGen/FixedLenDecoderEmitter/big-filter.td b/llvm/test/TableGen/FixedLenDecoderEmitter/big-filter.td
index 28762bfa1ec24..18e91ff947d9a 100644
--- a/llvm/test/TableGen/FixedLenDecoderEmitter/big-filter.td
+++ b/llvm/test/TableGen/FixedLenDecoderEmitter/big-filter.td
@@ -12,13 +12,13 @@ class I : Instruction {
// Check that a 64-bit filter with all bits set does not confuse DecoderEmitter.
//
// CHECK-LABEL: static const uint8_t DecoderTable128[34] = {
-// CHECK-NEXT: /* 0 */ MCD::OPC_ExtractField, 0, 64, // Inst{63-0} ...
-// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 1, 8, 0, // Skip to: 15
-// CHECK-NEXT: /* 7 */ MCD::OPC_CheckField, 127, 1, 1,
-// CHECK-NEXT: /* 11 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I2, DecodeIdx: 0
-// CHECK-NEXT: /* 15 */ MCD::OPC_FilterValue, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1,
-// CHECK-NEXT: /* 26 */ MCD::OPC_CheckField, 127, 1, 0,
-// CHECK-NEXT: /* 30 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I1, DecodeIdx: 0
+// CHECK-NEXT: /* 0 */ MCD::OPC_ExtractField, 0, 64, // Inst{63-0}
+// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 1, 8, 0, // FilterVal = 0x1, Skip to: 15
+// CHECK-NEXT: /* 7 */ MCD::OPC_CheckField, 127, 1, 1, // Inst{127} == 0x1
+// CHECK-NEXT: /* 11 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I2, DecodeIdx: 0
+// CHECK-NEXT: /* 15 */ MCD::OPC_FilterValue, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, // FilterVal = 0xffffffffffffffff
+// CHECK-NEXT: /* 26 */ MCD::OPC_CheckField, 127, 1, 0, // Inst{127} == 0x0
+// CHECK-NEXT: /* 30 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I1, DecodeIdx: 0
// CHECK-NEXT: };
def I1 : I {
diff --git a/llvm/test/TableGen/FixedLenDecoderEmitter/var-len-conflict-1.td b/llvm/test/TableGen/FixedLenDecoderEmitter/var-len-conflict-1.td
index 8afcf786f9c73..0f9f279528872 100644
--- a/llvm/test/TableGen/FixedLenDecoderEmitter/var-len-conflict-1.td
+++ b/llvm/test/TableGen/FixedLenDecoderEmitter/var-len-conflict-1.td
@@ -19,17 +19,17 @@ class I : Instruction {
// 00000010 ________ I16_2
// CHECK: /* 0 */ MCD::OPC_Scope, 17, 0, // Skip to: 20
-// CHECK-NEXT: /* 3 */ MCD::OPC_ExtractField, 0, 1, // Inst{0} ...
-// CHECK-NEXT: /* 6 */ MCD::OPC_FilterValueOrSkip, 0, 4, 0, // Skip to: 14
+// CHECK-NEXT: /* 3 */ MCD::OPC_ExtractField, 0, 1, // Inst{0}
+// CHECK-NEXT: /* 6 */ MCD::OPC_FilterValueOrSkip, 0, 4, 0, // FilterVal = 0x0, Skip to: 14
// CHECK-NEXT: /* 10 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I8_0, DecodeIdx: 0
-// CHECK-NEXT: /* 14 */ MCD::OPC_FilterValue, 1,
+// CHECK-NEXT: /* 14 */ MCD::OPC_FilterValue, 1, // FilterVal = 0x1
// CHECK-NEXT: /* 16 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: I8_1, DecodeIdx: 0
-// CHECK-NEXT: /* 20 */ MCD::OPC_ExtractField, 8, 8, // Inst{15-8} ...
-// CHECK-NEXT: /* 23 */ MCD::OPC_FilterValueOrSkip, 0, 4, 0, // Skip to: 31
+// CHECK-NEXT: /* 20 */ MCD::OPC_ExtractField, 8, 8, // Inst{15-8}
+// CHECK-NEXT: /* 23 */ MCD::OPC_FilterValueOrSkip, 0, 4, 0, // FilterVal = 0x0, Skip to: 31
// CHECK-NEXT: /* 27 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 1, // Opcode: I16_0, DecodeIdx: 1
-// CHECK-NEXT: /* 31 */ MCD::OPC_FilterValueOrSkip, 1, 4, 0, // Skip to: 39
+// CHECK-NEXT: /* 31 */ MCD::OPC_FilterValueOrSkip, 1, 4, 0, // FilterVal = 0x1, Skip to: 39
// CHECK-NEXT: /* 35 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 1, // Opcode: I16_1, DecodeIdx: 1
-// CHECK-NEXT: /* 39 */ MCD::OPC_FilterValue, 2,
+// CHECK-NEXT: /* 39 */ MCD::OPC_FilterValue, 2, // FilterVal = 0x2
// CHECK-NEXT: /* 41 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 1, // Opcode: I16_2, DecodeIdx: 1
def I8_0 : I { dag Inst = (descend (operand "$op", 7), 0b0); }
diff --git a/llvm/test/TableGen/VarLenDecoder.td b/llvm/test/TableGen/VarLenDecoder.td
index 7eda1e6e47431..93ca716b6a55f 100644
--- a/llvm/test/TableGen/VarLenDecoder.td
+++ b/llvm/test/TableGen/VarLenDecoder.td
@@ -53,17 +53,17 @@ def FOO32 : MyVarInst<MemOp32> {
// CHECK-NEXT: 43,
// CHECK-NEXT: };
-// CHECK-SMALL: /* 0 */ MCD::OPC_ExtractField, 3, 5, // Inst{7-3} ...
-// CHECK-SMALL-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 8, 4, 0, // Skip to: 11
+// CHECK-SMALL: /* 0 */ MCD::OPC_ExtractField, 3, 5, // Inst{7-3}
+// CHECK-SMALL-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 8, 4, 0, // FilterVal = 0x8, Skip to: 11
// CHECK-SMALL-NEXT: /* 7 */ MCD::OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 0, // Opcode: FOO16
-// CHECK-SMALL-NEXT: /* 11 */ MCD::OPC_FilterValue, 9,
+// CHECK-SMALL-NEXT: /* 11 */ MCD::OPC_FilterValue, 9, // FilterVal = 0x9
// CHECK-SMALL-NEXT: /* 13 */ MCD::OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: FOO32
// CHECK-SMALL-NEXT: };
-// CHECK-LARGE: /* 0 */ MCD::OPC_ExtractField, 3, 5, // Inst{7-3} ...
-// CHECK-LARGE-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 8, 4, 0, 0, // Skip to: 12
+// CHECK-LARGE: /* 0 */ MCD::OPC_ExtractField, 3, 5, // Inst{7-3}
+// CHECK-LARGE-NEXT: /* 3 */ MCD::OPC_FilterValueOrSkip, 8, 4, 0, 0, // FilterVal = 0x8, Skip to: 12
// CHECK-LARGE-NEXT: /* 8 */ MCD::OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 0, // Opcode: FOO16
-// CHECK-LARGE-NEXT: /* 12 */ MCD::OPC_FilterValue, 9,
+// CHECK-LARGE-NEXT: /* 12 */ MCD::OPC_FilterValue, 9, // FilterVal = 0x9
// CHECK-LARGE-NEXT: /* 14 */ MCD::OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: FOO32
// CHECK-LARGE-NEXT: };
diff --git a/llvm/test/TableGen/trydecode-emission.td b/llvm/test/TableGen/trydecode-emission.td
index d1cf4bf541835..47711acab4dae 100644
--- a/llvm/test/TableGen/trydecode-emission.td
+++ b/llvm/test/TableGen/trydecode-emission.td
@@ -34,11 +34,11 @@ def InstB : TestInstruction {
let hasCompleteDecoder = 0;
}
-// CHECK: /* 0 */ MCD::OPC_CheckField, 4, 4, 0,
-// CHECK-NEXT: /* 4 */ MCD::OPC_Scope, 8, 0, // Skip to: 15
-// CHECK-NEXT: /* 7 */ MCD::OPC_CheckField, 2, 2, 0,
-// CHECK-NEXT: /* 11 */ MCD::OPC_TryDecode, {{[0-9]+}}, {{[0-9]+}}, 0,
-// CHECK-NEXT: /* 15 */ MCD::OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
+// CHECK: /* 0 */ MCD::OPC_CheckField, 4, 4, 0, // Inst{7-4} == 0x0
+// CHECK-NEXT: /* 4 */ MCD::OPC_Scope, 8, 0, // Skip to: 15
+// CHECK-NEXT: /* 7 */ MCD::OPC_CheckField, 2, 2, 0, // Inst{3-2} == 0x0
+// CHECK-NEXT: /* 11 */ MCD::OPC_TryDecode, {{[0-9]+}}, {{[0-9]+}}, 0, // Opcode: InstB, DecodeIdx: 0
+// CHECK-NEXT: /* 15 */ MCD::OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
// CHECK-NEXT: };
// CHECK: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
@@ -47,11 +47,11 @@ def InstB : TestInstruction {
// CHECK-NEXT: NumToSkip |= (*Ptr++) << 8;
// CHECK-NEXT: return NumToSkip;
-// CHECK-LARGE: /* 0 */ MCD::OPC_CheckField, 4, 4, 0,
-// CHECK-LARGE-NEXT: /* 4 */ MCD::OPC_Scope, 8, 0, 0, // Skip to: 16
-// CHECK-LARGE-NEXT: /* 8 */ MCD::OPC_CheckField, 2, 2, 0,
-// CHECK-LARGE-NEXT: /* 12 */ MCD::OPC_TryDecode, {{[0-9]+}}, {{[0-9]+}}, 0,
-// CHECK-LARGE-NEXT: /* 16 */ MCD::OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
+// CHECK-LARGE: /* 0 */ MCD::OPC_CheckField, 4, 4, 0, // Inst{7-4} == 0x0
+// CHECK-LARGE-NEXT: /* 4 */ MCD::OPC_Scope, 8, 0, 0, // Skip to: 16
+// CHECK-LARGE-NEXT: /* 8 */ MCD::OPC_CheckField, 2, 2, 0, // Inst{3-2} == 0x0
+// CHECK-LARGE-NEXT: /* 12 */ MCD::OPC_TryDecode, {{[0-9]+}}, {{[0-9]+}}, 0, // Opcode: InstB, DecodeIdx: 0
+// CHECK-LARGE-NEXT: /* 16 */ MCD::OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
// CHECK-LARGE-NEXT: };
// CHECK-LARGE: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 8747d02ac892b..8d50bfab7d37f 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -722,6 +722,26 @@ unsigned Filter::usefulness() const {
// //
//////////////////////////////////
+static StringRef getDecoderOpName(uint8_t Op) {
+ // clang-format off
+ static constexpr StringLiteral Names[] = {
+ "OPC_Scope",
+ "OPC_ExtractField",
+ "OPC_FilterValueOrSkip",
+ "OPC_FilterValue",
+ "OPC_CheckField",
+ "OPC_CheckPredicate",
+ "OPC_Decode",
+ "OPC_TryDecode",
+ "OPC_SoftFail",
+ };
+ static_assert(std::size(Names) == MCD::OPC_SoftFail - MCD::OPC_Scope + 1);
+ // clang-format on
+ if (Op >= MCD::OPC_Scope && Op <= MCD::OPC_SoftFail)
+ return Names[Op - MCD::OPC_Scope];
+ llvm_unreachable("Unknown decoder op");
+}
+
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
// that were emitted.
unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
@@ -775,9 +795,20 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
DecoderTable::const_iterator E = Table.end();
const uint8_t *const EndPtr = Table.data() + Table.size();
+ constexpr uint32_t StartColumn = 14;
+
+ auto StartComment = [&OS]() {
+ constexpr uint32_t CommentColumn = 60;
+ OS.PadToColumn(CommentColumn);
+ OS << " // ";
+ };
+
auto emitNumToSkipComment = [&](uint32_t NumToSkip, bool InComment = false) {
uint32_t Index = ((I - Table.begin()) + NumToSkip);
- OS << (InComment ? ", " : "// ");
+ if (InComment)
+ OS << ", ";
+ else
+ StartComment();
OS << "Skip to: " << Index;
};
@@ -785,11 +816,22 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
// This will be used for additional checks in `decodeInstruction`.
if (SpecializeDecodersPerBitwidth) {
OS << "/* 0 */";
- OS.PadToColumn(14);
+ OS.PadToColumn(StartColumn);
emitULEB128(I, OS);
OS << " // Bitwidth " << BitWidth << '\n';
}
+ auto DecodeAndEmitULEB128 = [EndPtr,
+ &emitULEB128](DecoderTable::const_iterator &I,
+ formatted_raw_ostream &OS) {
+ const char *ErrMsg = nullptr;
+ uint64_t Value = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
+ assert(ErrMsg == nullptr && "ULEB128 value too large!");
+
+ emitULEB128(I, OS);
+ return Value;
+ };
+
unsigned OpcodeMask = 0;
while (I != E) {
@@ -797,119 +839,109 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
uint64_t Pos = I - Table.begin();
OS << "/* " << Pos << " */";
- OS.PadToColumn(12);
+ OS.PadToColumn(StartColumn);
const uint8_t DecoderOp = *I++;
OpcodeMask |= (1 << DecoderOp);
+ OS << "MCD::" << getDecoderOpName(DecoderOp) << ", ";
switch (DecoderOp) {
default:
PrintFatalError("Invalid decode table opcode: " + Twine((int)DecoderOp) +
" at index " + Twine(Pos));
case MCD::OPC_Scope: {
- OS << " MCD::OPC_Scope, ";
uint32_t NumToSkip = emitNumToSkip(I, OS);
emitNumToSkipComment(NumToSkip);
- OS << '\n';
break;
}
case MCD::OPC_ExtractField: {
- OS << " MCD::OPC_ExtractField, ";
-
// ULEB128 encoded start value.
- const char *ErrMsg = nullptr;
- unsigned Start = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
- assert(ErrMsg == nullptr && "ULEB128 value too large!");
- emitULEB128(I, OS);
-
+ unsigned Start = DecodeAndEmitULEB128(I, OS);
unsigned Len = *I++;
- OS << Len << ", // Inst{";
+ OS << Len << ',';
+ StartComment();
+ OS << "Inst{";
if (Len > 1)
- OS << (Start + Len - 1) << "-";
- OS << Start << "} ...\n";
+ OS << (Start + Len - 1) << '-';
+ OS << Start << '}';
break;
}
case MCD::OPC_FilterValueOrSkip: {
- OS << " MCD::OPC_FilterValueOrSkip, ";
// The filter value is ULEB128 encoded.
- emitULEB128(I, OS);
+ uint64_t FilterVal = DecodeAndEmitULEB128(I, OS);
uint32_t NumToSkip = emitNumToSkip(I, OS);
- emitNumToSkipComment(NumToSkip);
- OS << '\n';
+ StartComment();
+ OS << "FilterVal = 0x";
+ OS.write_hex(FilterVal);
+ emitNumToSkipComment(NumToSkip, /*InComment=*/true);
break;
}
case MCD::OPC_FilterValue: {
- OS << " MCD::OPC_FilterValue, ";
// The filter value is ULEB128 encoded.
- emitULEB128(I, OS);
- OS << '\n';
+ uint64_t FilterVal = DecodeAndEmitULEB128(I, OS);
+
+ StartComment();
+ OS << "FilterVal = 0x";
+ OS.write_hex(FilterVal);
break;
}
case MCD::OPC_CheckField: {
- OS << " MCD::OPC_CheckField, ";
// ULEB128 encoded start value.
- emitULEB128(I, OS);
+ unsigned Start = DecodeAndEmitULEB128(I, OS);
+
// 8-bit length.
unsigned Len = *I++;
OS << Len << ", ";
+
// ULEB128 encoded field value.
- emitULEB128(I, OS);
- OS << '\n';
+ uint64_t FieldVal = DecodeAndEmitULEB128(I, OS);
+
+ StartComment();
+ OS << "Inst{";
+ if (Len > 1)
+ OS << (Start + Len - 1) << '-';
+ OS << Start << "} == 0x";
+ OS.write_hex(FieldVal);
break;
}
case MCD::OPC_CheckPredicate: {
- OS << " MCD::OPC_CheckPredicate, ";
- emitULEB128(I, OS);
- OS << '\n';
+ unsigned PIdx = DecodeAndEmitULEB128(I, OS);
+ StartComment();
+ OS << "PredicateIdx " << PIdx;
break;
}
case MCD::OPC_Decode:
case MCD::OPC_TryDecode: {
- bool IsTry = DecoderOp == MCD::OPC_TryDecode;
// Decode the Opcode value.
- const char *ErrMsg = nullptr;
- unsigned Opc = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
- assert(ErrMsg == nullptr && "ULEB128 value too large!");
-
- OS << " MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, ";
- emitULEB128(I, OS);
+ unsigned Opc = DecodeAndEmitULEB128(I, OS);
// Decoder index.
- unsigned DecodeIdx = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
- assert(ErrMsg == nullptr && "ULEB128 value too large!");
- emitULEB128(I, OS);
+ unsigned DecodeIdx = DecodeAndEmitULEB128(I, OS);
auto EncI = OpcodeToEncodingID.find(Opc);
assert(EncI != OpcodeToEncodingID.end() && "no encoding entry");
auto EncodingID = EncI->second;
- if (!IsTry) {
- OS << "// Opcode: " << Encodings[EncodingID].getName()
- << ", DecodeIdx: " << DecodeIdx << '\n';
- break;
- }
- OS << '\n';
+ StartComment();
+ OS << "Opcode: " << Encodings[EncodingID].getName()
+ << ", DecodeIdx: " << DecodeIdx;
break;
}
case MCD::OPC_SoftFail: {
- OS << " MCD::OPC_SoftFail, ";
// Decode the positive mask.
- const char *ErrMsg = nullptr;
- uint64_t PositiveMask = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
- assert(ErrMsg == nullptr && "ULEB128 value too large!");
- emitULEB128(I, OS);
+ uint64_t PositiveMask = DecodeAndEmitULEB128(I, OS);
// Decode the negative mask.
- uint64_t NegativeMask = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
- assert(ErrMsg == nullptr && "ULEB128 value too large!");
- emitULEB128(I, OS);
- OS << "// +ve mask: 0x";
+ uint64_t NegativeMask = DecodeAndEmitULEB128(I, OS);
+
+ StartComment();
+ OS << "+ve mask: 0x";
OS.write_hex(PositiveMask);
OS << ", -ve mask: 0x";
OS.write_hex(NegativeMask);
- OS << '\n';
break;
}
}
+ OS << '\n';
}
OS << "};\n\n";
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits, but I think they might help clarity of the comments.
@s-barannikov any concerns? I know you have some other refactoring with pretty printing in the works |
I'll take a closer look by the end of the week if that can wait |
It can, thanks |
c10f2e7
to
d615e3c
Compare
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.
d615e3c
to
f7af184
Compare
Thanks, LG |
llvm/test/TableGen/FixedLenDecoderEmitter/var-len-conflict-1.td
Outdated
Show resolved
Hide resolved
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/23516 Here is the relevant piece of the build log for the reference
|
Several code cleanup changes in code to emit decoder tables:
getDecoderOpName
to print decoder op.