aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/DecoderEmitter.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2025-03-07 11:09:34 -0800
committerGitHub <noreply@github.com>2025-03-07 11:09:34 -0800
commit6a42dc694cffb4658ef72db308cfae7bfbba16b5 (patch)
treeac05af00a5841988fd553c5d5b4b385bf91050ea /llvm/utils/TableGen/DecoderEmitter.cpp
parent813bbe055df2357efd42eaf1f3e7f5926a071941 (diff)
downloadllvm-6a42dc694cffb4658ef72db308cfae7bfbba16b5.zip
llvm-6a42dc694cffb4658ef72db308cfae7bfbba16b5.tar.gz
llvm-6a42dc694cffb4658ef72db308cfae7bfbba16b5.tar.bz2
[TableGen] Simplify emitULEB128 in DecoderEmitter.cpp. NFC (#130214)
Instead of returning the number of bytes emitted, just take the iterator by reference so the increments in emitULEB128 will update the copy in the caller. Also pass the iterator by reference to emitNumToSkip so we don't need a separate I += 3 in the caller.
Diffstat (limited to 'llvm/utils/TableGen/DecoderEmitter.cpp')
-rw-r--r--llvm/utils/TableGen/DecoderEmitter.cpp28
1 files changed, 10 insertions, 18 deletions
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 8947e887..0b07c700 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -808,19 +808,15 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
Indent += 2;
// Emit ULEB128 encoded value to OS, returning the number of bytes emitted.
- auto emitULEB128 = [](DecoderTable::const_iterator I,
+ auto emitULEB128 = [](DecoderTable::const_iterator &I,
formatted_raw_ostream &OS) {
- unsigned Len = 0;
- while (*I >= 128) {
+ while (*I >= 128)
OS << (unsigned)*I++ << ", ";
- Len++;
- }
OS << (unsigned)*I++ << ", ";
- return Len + 1;
};
// Emit 24-bit numtoskip value to OS, returning the NumToSkip value.
- auto emitNumToSkip = [](DecoderTable::const_iterator I,
+ auto emitNumToSkip = [](DecoderTable::const_iterator &I,
formatted_raw_ostream &OS) {
uint8_t Byte = *I++;
uint32_t NumToSkip = Byte;
@@ -857,7 +853,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
unsigned Start = decodeULEB128(Table.data() + Pos + 1, nullptr,
Table.data() + Table.size(), &ErrMsg);
assert(ErrMsg == nullptr && "ULEB128 value too large!");
- I += emitULEB128(I, OS);
+ emitULEB128(I, OS);
unsigned Len = *I++;
OS << Len << ", // Inst{";
@@ -870,11 +866,10 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
++I;
OS << Indent << "MCD::OPC_FilterValue, ";
// The filter value is ULEB128 encoded.
- I += emitULEB128(I, OS);
+ emitULEB128(I, OS);
// 24-bit numtoskip value.
uint32_t NumToSkip = emitNumToSkip(I, OS);
- I += 3;
OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n";
break;
}
@@ -882,27 +877,25 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
++I;
OS << Indent << "MCD::OPC_CheckField, ";
// ULEB128 encoded start value.
- I += emitULEB128(I, OS);
+ emitULEB128(I, OS);
// 8-bit length.
unsigned Len = *I++;
OS << Len << ", ";
// ULEB128 encoded field value.
- I += emitULEB128(I, OS);
+ emitULEB128(I, OS);
// 24-bit numtoskip value.
uint32_t NumToSkip = emitNumToSkip(I, OS);
- I += 3;
OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n";
break;
}
case MCD::OPC_CheckPredicate: {
++I;
OS << Indent << "MCD::OPC_CheckPredicate, ";
- I += emitULEB128(I, OS);
+ emitULEB128(I, OS);
// 24-bit numtoskip value.
uint32_t NumToSkip = emitNumToSkip(I, OS);
- I += 3;
OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n";
break;
}
@@ -917,10 +910,10 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
assert(ErrMsg == nullptr && "ULEB128 value too large!");
OS << Indent << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, ";
- I += emitULEB128(I, OS);
+ emitULEB128(I, OS);
// Decoder index.
- I += emitULEB128(I, OS);
+ emitULEB128(I, OS);
auto EncI = OpcodeToEncodingID.find(Opc);
assert(EncI != OpcodeToEncodingID.end() && "no encoding entry");
@@ -935,7 +928,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
// 24-bit numtoskip value.
uint32_t NumToSkip = emitNumToSkip(I, OS);
- I += 3;
OS << "// Opcode: " << NumberedEncodings[EncodingID]
<< ", skip to: " << ((I - Table.begin()) + NumToSkip) << "\n";