Skip to content

Commit 6a42dc6

Browse files
authored
[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.
1 parent 813bbe0 commit 6a42dc6

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -808,19 +808,15 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
808808
Indent += 2;
809809

810810
// Emit ULEB128 encoded value to OS, returning the number of bytes emitted.
811-
auto emitULEB128 = [](DecoderTable::const_iterator I,
811+
auto emitULEB128 = [](DecoderTable::const_iterator &I,
812812
formatted_raw_ostream &OS) {
813-
unsigned Len = 0;
814-
while (*I >= 128) {
813+
while (*I >= 128)
815814
OS << (unsigned)*I++ << ", ";
816-
Len++;
817-
}
818815
OS << (unsigned)*I++ << ", ";
819-
return Len + 1;
820816
};
821817

822818
// Emit 24-bit numtoskip value to OS, returning the NumToSkip value.
823-
auto emitNumToSkip = [](DecoderTable::const_iterator I,
819+
auto emitNumToSkip = [](DecoderTable::const_iterator &I,
824820
formatted_raw_ostream &OS) {
825821
uint8_t Byte = *I++;
826822
uint32_t NumToSkip = Byte;
@@ -857,7 +853,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
857853
unsigned Start = decodeULEB128(Table.data() + Pos + 1, nullptr,
858854
Table.data() + Table.size(), &ErrMsg);
859855
assert(ErrMsg == nullptr && "ULEB128 value too large!");
860-
I += emitULEB128(I, OS);
856+
emitULEB128(I, OS);
861857

862858
unsigned Len = *I++;
863859
OS << Len << ", // Inst{";
@@ -870,39 +866,36 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
870866
++I;
871867
OS << Indent << "MCD::OPC_FilterValue, ";
872868
// The filter value is ULEB128 encoded.
873-
I += emitULEB128(I, OS);
869+
emitULEB128(I, OS);
874870

875871
// 24-bit numtoskip value.
876872
uint32_t NumToSkip = emitNumToSkip(I, OS);
877-
I += 3;
878873
OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n";
879874
break;
880875
}
881876
case MCD::OPC_CheckField: {
882877
++I;
883878
OS << Indent << "MCD::OPC_CheckField, ";
884879
// ULEB128 encoded start value.
885-
I += emitULEB128(I, OS);
880+
emitULEB128(I, OS);
886881
// 8-bit length.
887882
unsigned Len = *I++;
888883
OS << Len << ", ";
889884
// ULEB128 encoded field value.
890-
I += emitULEB128(I, OS);
885+
emitULEB128(I, OS);
891886

892887
// 24-bit numtoskip value.
893888
uint32_t NumToSkip = emitNumToSkip(I, OS);
894-
I += 3;
895889
OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n";
896890
break;
897891
}
898892
case MCD::OPC_CheckPredicate: {
899893
++I;
900894
OS << Indent << "MCD::OPC_CheckPredicate, ";
901-
I += emitULEB128(I, OS);
895+
emitULEB128(I, OS);
902896

903897
// 24-bit numtoskip value.
904898
uint32_t NumToSkip = emitNumToSkip(I, OS);
905-
I += 3;
906899
OS << "// Skip to: " << ((I - Table.begin()) + NumToSkip) << "\n";
907900
break;
908901
}
@@ -917,10 +910,10 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
917910
assert(ErrMsg == nullptr && "ULEB128 value too large!");
918911

919912
OS << Indent << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, ";
920-
I += emitULEB128(I, OS);
913+
emitULEB128(I, OS);
921914

922915
// Decoder index.
923-
I += emitULEB128(I, OS);
916+
emitULEB128(I, OS);
924917

925918
auto EncI = OpcodeToEncodingID.find(Opc);
926919
assert(EncI != OpcodeToEncodingID.end() && "no encoding entry");
@@ -935,7 +928,6 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
935928

936929
// 24-bit numtoskip value.
937930
uint32_t NumToSkip = emitNumToSkip(I, OS);
938-
I += 3;
939931

940932
OS << "// Opcode: " << NumberedEncodings[EncodingID]
941933
<< ", skip to: " << ((I - Table.begin()) + NumToSkip) << "\n";

0 commit comments

Comments
 (0)