Skip to content

Commit 633728f

Browse files
authored
[NFC][TableGen][DecoderEmitter] Eliminate indent for a few functions (#148718)
Eliminate the `indent` argument for functions which are always called with `indent(0)`.
1 parent 9987573 commit 633728f

File tree

1 file changed

+55
-71
lines changed

1 file changed

+55
-71
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 55 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ class DecoderEmitter {
227227
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
228228
// that were emitted.
229229
unsigned emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
230-
indent Indent, unsigned BitWidth, StringRef Namespace,
230+
unsigned BitWidth, StringRef Namespace,
231231
const EncodingIDsVec &EncodingIDs) const;
232232
void emitInstrLenTable(formatted_raw_ostream &OS,
233233
ArrayRef<unsigned> InstrLen) const;
234234
void emitPredicateFunction(formatted_raw_ostream &OS,
235-
PredicateSet &Predicates, indent Indent) const;
236-
void emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders,
237-
indent Indent) const;
235+
PredicateSet &Predicates) const;
236+
void emitDecoderFunction(formatted_raw_ostream &OS,
237+
DecoderSet &Decoders) const;
238238

239239
// run - Output the code emitter
240240
void run(raw_ostream &o);
@@ -833,8 +833,8 @@ unsigned Filter::usefulness() const {
833833
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
834834
// that were emitted.
835835
unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
836-
DecoderTable &Table, indent Indent,
837-
unsigned BitWidth, StringRef Namespace,
836+
DecoderTable &Table, unsigned BitWidth,
837+
StringRef Namespace,
838838
const EncodingIDsVec &EncodingIDs) const {
839839
// We'll need to be able to map from a decoded opcode into the corresponding
840840
// EncodingID for this specific combination of BitWidth and Namespace. This
@@ -844,11 +844,9 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
844844
for (const auto &EI : EncodingIDs)
845845
OpcodeToEncodingID[EI.Opcode] = EI.EncodingID;
846846

847-
OS << Indent << "static const uint8_t DecoderTable" << Namespace << BitWidth
847+
OS << "static const uint8_t DecoderTable" << Namespace << BitWidth
848848
<< "[] = {\n";
849849

850-
Indent += 2;
851-
852850
// Emit ULEB128 encoded value to OS, returning the number of bytes emitted.
853851
auto emitULEB128 = [](DecoderTable::const_iterator &I,
854852
formatted_raw_ostream &OS) {
@@ -905,7 +903,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
905903
PrintFatalError("Invalid decode table opcode: " + Twine((int)DecoderOp) +
906904
" at index " + Twine(Pos));
907905
case MCD::OPC_ExtractField: {
908-
OS << Indent << "MCD::OPC_ExtractField, ";
906+
OS << " MCD::OPC_ExtractField, ";
909907

910908
// ULEB128 encoded start value.
911909
const char *ErrMsg = nullptr;
@@ -923,7 +921,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
923921
case MCD::OPC_FilterValue:
924922
case MCD::OPC_FilterValueOrFail: {
925923
bool IsFail = DecoderOp == MCD::OPC_FilterValueOrFail;
926-
OS << Indent << "MCD::OPC_FilterValue" << (IsFail ? "OrFail, " : ", ");
924+
OS << " MCD::OPC_FilterValue" << (IsFail ? "OrFail, " : ", ");
927925
// The filter value is ULEB128 encoded.
928926
emitULEB128(I, OS);
929927

@@ -937,7 +935,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
937935
case MCD::OPC_CheckField:
938936
case MCD::OPC_CheckFieldOrFail: {
939937
bool IsFail = DecoderOp == MCD::OPC_CheckFieldOrFail;
940-
OS << Indent << "MCD::OPC_CheckField" << (IsFail ? "OrFail, " : ", ");
938+
OS << " MCD::OPC_CheckField" << (IsFail ? "OrFail, " : ", ");
941939
// ULEB128 encoded start value.
942940
emitULEB128(I, OS);
943941
// 8-bit length.
@@ -957,7 +955,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
957955
case MCD::OPC_CheckPredicateOrFail: {
958956
bool IsFail = DecoderOp == MCD::OPC_CheckPredicateOrFail;
959957

960-
OS << Indent << "MCD::OPC_CheckPredicate" << (IsFail ? "OrFail, " : ", ");
958+
OS << " MCD::OPC_CheckPredicate" << (IsFail ? "OrFail, " : ", ");
961959
emitULEB128(I, OS);
962960

963961
if (!IsFail) {
@@ -977,7 +975,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
977975
unsigned Opc = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
978976
assert(ErrMsg == nullptr && "ULEB128 value too large!");
979977

980-
OS << Indent << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode"
978+
OS << " MCD::OPC_" << (IsTry ? "Try" : "") << "Decode"
981979
<< (IsFail ? "OrFail, " : ", ");
982980
emitULEB128(I, OS);
983981

@@ -1007,7 +1005,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
10071005
break;
10081006
}
10091007
case MCD::OPC_SoftFail: {
1010-
OS << Indent << "MCD::OPC_SoftFail, ";
1008+
OS << " MCD::OPC_SoftFail, ";
10111009
// Decode the positive mask.
10121010
const char *ErrMsg = nullptr;
10131011
uint64_t PositiveMask = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
@@ -1026,15 +1024,12 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
10261024
break;
10271025
}
10281026
case MCD::OPC_Fail:
1029-
OS << Indent << "MCD::OPC_Fail,\n";
1027+
OS << " MCD::OPC_Fail,\n";
10301028
break;
10311029
}
10321030
}
1033-
OS << Indent << "0\n";
1034-
1035-
Indent -= 2;
1036-
1037-
OS << Indent << "};\n\n";
1031+
OS << " 0\n";
1032+
OS << "};\n\n";
10381033

10391034
return OpcodeMask;
10401035
}
@@ -1048,27 +1043,23 @@ void DecoderEmitter::emitInstrLenTable(formatted_raw_ostream &OS,
10481043
}
10491044

10501045
void DecoderEmitter::emitPredicateFunction(formatted_raw_ostream &OS,
1051-
PredicateSet &Predicates,
1052-
indent Indent) const {
1046+
PredicateSet &Predicates) const {
10531047
// The predicate function is just a big switch statement based on the
10541048
// input predicate index.
1055-
OS << Indent << "static bool checkDecoderPredicate(unsigned Idx, "
1056-
<< "const FeatureBitset &Bits) {\n";
1057-
Indent += 2;
1058-
OS << Indent << "switch (Idx) {\n";
1059-
OS << Indent << "default: llvm_unreachable(\"Invalid index!\");\n";
1049+
OS << "static bool checkDecoderPredicate(unsigned Idx, const FeatureBitset "
1050+
"&Bits) {\n";
1051+
OS << " switch (Idx) {\n";
1052+
OS << " default: llvm_unreachable(\"Invalid index!\");\n";
10601053
for (const auto &[Index, Predicate] : enumerate(Predicates)) {
1061-
OS << Indent << "case " << Index << ":\n";
1062-
OS << Indent + 2 << "return (" << Predicate << ");\n";
1054+
OS << " case " << Index << ":\n";
1055+
OS << " return (" << Predicate << ");\n";
10631056
}
1064-
OS << Indent << "}\n";
1065-
Indent -= 2;
1066-
OS << Indent << "}\n\n";
1057+
OS << " }\n";
1058+
OS << "}\n\n";
10671059
}
10681060

10691061
void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
1070-
DecoderSet &Decoders,
1071-
indent Indent) const {
1062+
DecoderSet &Decoders) const {
10721063
// The decoder function is just a big switch statement or a table of function
10731064
// pointers based on the input decoder index.
10741065

@@ -1085,53 +1076,46 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
10851076
if (UseFnTableInDecodeToMCInst) {
10861077
// Emit a function for each case first.
10871078
for (const auto &[Index, Decoder] : enumerate(Decoders)) {
1088-
OS << Indent << "template <typename InsnType>\n";
1089-
OS << Indent << "DecodeStatus decodeFn" << Index << "(" << DecodeParams
1090-
<< ") {\n";
1091-
Indent += 2;
1092-
OS << Indent << TmpTypeDecl;
1093-
OS << Indent << "[[maybe_unused]] TmpType tmp;\n";
1079+
OS << "template <typename InsnType>\n";
1080+
OS << "DecodeStatus decodeFn" << Index << "(" << DecodeParams << ") {\n";
1081+
OS << " " << TmpTypeDecl;
1082+
OS << " [[maybe_unused]] TmpType tmp;\n";
10941083
OS << Decoder;
1095-
OS << Indent << "return S;\n";
1096-
Indent -= 2;
1097-
OS << Indent << "}\n\n";
1084+
OS << " return S;\n";
1085+
OS << "}\n\n";
10981086
}
10991087
}
11001088

1101-
OS << Indent << "// Handling " << Decoders.size() << " cases.\n";
1102-
OS << Indent << "template <typename InsnType>\n";
1103-
OS << Indent << "static DecodeStatus decodeToMCInst(unsigned Idx, "
1104-
<< DecodeParams << ") {\n";
1105-
Indent += 2;
1106-
OS << Indent << "DecodeComplete = true;\n";
1089+
OS << "// Handling " << Decoders.size() << " cases.\n";
1090+
OS << "template <typename InsnType>\n";
1091+
OS << "static DecodeStatus decodeToMCInst(unsigned Idx, " << DecodeParams
1092+
<< ") {\n";
1093+
OS << " DecodeComplete = true;\n";
11071094

11081095
if (UseFnTableInDecodeToMCInst) {
11091096
// Build a table of function pointers.
1110-
OS << Indent << "using DecodeFnTy = DecodeStatus (*)(" << DecodeParams
1111-
<< ");\n";
1112-
OS << Indent << "static constexpr DecodeFnTy decodeFnTable[] = {\n";
1097+
OS << " using DecodeFnTy = DecodeStatus (*)(" << DecodeParams << ");\n";
1098+
OS << " static constexpr DecodeFnTy decodeFnTable[] = {\n";
11131099
for (size_t Index : llvm::seq(Decoders.size()))
1114-
OS << Indent + 2 << "decodeFn" << Index << ",\n";
1115-
OS << Indent << "};\n";
1116-
OS << Indent << "if (Idx >= " << Decoders.size() << ")\n";
1117-
OS << Indent + 2 << "llvm_unreachable(\"Invalid index!\");\n";
1118-
OS << Indent
1119-
<< "return decodeFnTable[Idx](S, insn, MI, Address, Decoder, "
1100+
OS << " decodeFn" << Index << ",\n";
1101+
OS << " };\n";
1102+
OS << " if (Idx >= " << Decoders.size() << ")\n";
1103+
OS << " llvm_unreachable(\"Invalid index!\");\n";
1104+
OS << " return decodeFnTable[Idx](S, insn, MI, Address, Decoder, "
11201105
"DecodeComplete);\n";
11211106
} else {
1122-
OS << Indent << TmpTypeDecl;
1123-
OS << Indent << "TmpType tmp;\n";
1124-
OS << Indent << "switch (Idx) {\n";
1125-
OS << Indent << "default: llvm_unreachable(\"Invalid index!\");\n";
1107+
OS << " " << TmpTypeDecl;
1108+
OS << " TmpType tmp;\n";
1109+
OS << " switch (Idx) {\n";
1110+
OS << " default: llvm_unreachable(\"Invalid index!\");\n";
11261111
for (const auto &[Index, Decoder] : enumerate(Decoders)) {
1127-
OS << Indent << "case " << Index << ":\n";
1112+
OS << " case " << Index << ":\n";
11281113
OS << Decoder;
1129-
OS << Indent + 2 << "return S;\n";
1114+
OS << " return S;\n";
11301115
}
1131-
OS << Indent << "}\n";
1116+
OS << " }\n";
11321117
}
1133-
Indent -= 2;
1134-
OS << Indent << "}\n";
1118+
OS << "}\n";
11351119
}
11361120

11371121
// Populates the field of the insn given the start position and the number of
@@ -2673,7 +2657,7 @@ namespace {
26732657
TableInfo.Table.push_back(MCD::OPC_Fail);
26742658

26752659
// Print the table to the output stream.
2676-
OpcodeMask |= emitTable(OS, TableInfo.Table, indent(0), FC.getBitWidth(),
2660+
OpcodeMask |= emitTable(OS, TableInfo.Table, FC.getBitWidth(),
26772661
DecoderNamespace, EncodingIDs);
26782662
}
26792663

@@ -2689,10 +2673,10 @@ namespace {
26892673

26902674
// Emit the predicate function.
26912675
if (HasCheckPredicate)
2692-
emitPredicateFunction(OS, TableInfo.Predicates, indent(0));
2676+
emitPredicateFunction(OS, TableInfo.Predicates);
26932677

26942678
// Emit the decoder function.
2695-
emitDecoderFunction(OS, TableInfo.Decoders, indent(0));
2679+
emitDecoderFunction(OS, TableInfo.Decoders);
26962680

26972681
// Emit the main entry point for the decoder, decodeInstruction().
26982682
emitDecodeInstruction(OS, IsVarLenInst, OpcodeMask);

0 commit comments

Comments
 (0)