@@ -227,14 +227,14 @@ class DecoderEmitter {
227
227
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
228
228
// that were emitted.
229
229
unsigned emitTable (formatted_raw_ostream &OS, DecoderTable &Table,
230
- indent Indent, unsigned BitWidth, StringRef Namespace,
230
+ unsigned BitWidth, StringRef Namespace,
231
231
const EncodingIDsVec &EncodingIDs) const ;
232
232
void emitInstrLenTable (formatted_raw_ostream &OS,
233
233
ArrayRef<unsigned > InstrLen) const ;
234
234
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 ;
238
238
239
239
// run - Output the code emitter
240
240
void run (raw_ostream &o);
@@ -833,8 +833,8 @@ unsigned Filter::usefulness() const {
833
833
// Emit the decoder state machine table. Returns a mask of MCD decoder ops
834
834
// that were emitted.
835
835
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,
838
838
const EncodingIDsVec &EncodingIDs) const {
839
839
// We'll need to be able to map from a decoded opcode into the corresponding
840
840
// EncodingID for this specific combination of BitWidth and Namespace. This
@@ -844,11 +844,9 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
844
844
for (const auto &EI : EncodingIDs)
845
845
OpcodeToEncodingID[EI.Opcode ] = EI.EncodingID ;
846
846
847
- OS << Indent << " static const uint8_t DecoderTable" << Namespace << BitWidth
847
+ OS << " static const uint8_t DecoderTable" << Namespace << BitWidth
848
848
<< " [] = {\n " ;
849
849
850
- Indent += 2 ;
851
-
852
850
// Emit ULEB128 encoded value to OS, returning the number of bytes emitted.
853
851
auto emitULEB128 = [](DecoderTable::const_iterator &I,
854
852
formatted_raw_ostream &OS) {
@@ -905,7 +903,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
905
903
PrintFatalError (" Invalid decode table opcode: " + Twine ((int )DecoderOp) +
906
904
" at index " + Twine (Pos));
907
905
case MCD::OPC_ExtractField: {
908
- OS << Indent << " MCD::OPC_ExtractField, " ;
906
+ OS << " MCD::OPC_ExtractField, " ;
909
907
910
908
// ULEB128 encoded start value.
911
909
const char *ErrMsg = nullptr ;
@@ -923,7 +921,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
923
921
case MCD::OPC_FilterValue:
924
922
case MCD::OPC_FilterValueOrFail: {
925
923
bool IsFail = DecoderOp == MCD::OPC_FilterValueOrFail;
926
- OS << Indent << " MCD::OPC_FilterValue" << (IsFail ? " OrFail, " : " , " );
924
+ OS << " MCD::OPC_FilterValue" << (IsFail ? " OrFail, " : " , " );
927
925
// The filter value is ULEB128 encoded.
928
926
emitULEB128 (I, OS);
929
927
@@ -937,7 +935,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
937
935
case MCD::OPC_CheckField:
938
936
case MCD::OPC_CheckFieldOrFail: {
939
937
bool IsFail = DecoderOp == MCD::OPC_CheckFieldOrFail;
940
- OS << Indent << " MCD::OPC_CheckField" << (IsFail ? " OrFail, " : " , " );
938
+ OS << " MCD::OPC_CheckField" << (IsFail ? " OrFail, " : " , " );
941
939
// ULEB128 encoded start value.
942
940
emitULEB128 (I, OS);
943
941
// 8-bit length.
@@ -957,7 +955,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
957
955
case MCD::OPC_CheckPredicateOrFail: {
958
956
bool IsFail = DecoderOp == MCD::OPC_CheckPredicateOrFail;
959
957
960
- OS << Indent << " MCD::OPC_CheckPredicate" << (IsFail ? " OrFail, " : " , " );
958
+ OS << " MCD::OPC_CheckPredicate" << (IsFail ? " OrFail, " : " , " );
961
959
emitULEB128 (I, OS);
962
960
963
961
if (!IsFail) {
@@ -977,7 +975,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
977
975
unsigned Opc = decodeULEB128 (&*I, nullptr , EndPtr, &ErrMsg);
978
976
assert (ErrMsg == nullptr && " ULEB128 value too large!" );
979
977
980
- OS << Indent << " MCD::OPC_" << (IsTry ? " Try" : " " ) << " Decode"
978
+ OS << " MCD::OPC_" << (IsTry ? " Try" : " " ) << " Decode"
981
979
<< (IsFail ? " OrFail, " : " , " );
982
980
emitULEB128 (I, OS);
983
981
@@ -1007,7 +1005,7 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
1007
1005
break ;
1008
1006
}
1009
1007
case MCD::OPC_SoftFail: {
1010
- OS << Indent << " MCD::OPC_SoftFail, " ;
1008
+ OS << " MCD::OPC_SoftFail, " ;
1011
1009
// Decode the positive mask.
1012
1010
const char *ErrMsg = nullptr ;
1013
1011
uint64_t PositiveMask = decodeULEB128 (&*I, nullptr , EndPtr, &ErrMsg);
@@ -1026,15 +1024,12 @@ unsigned DecoderEmitter::emitTable(formatted_raw_ostream &OS,
1026
1024
break ;
1027
1025
}
1028
1026
case MCD::OPC_Fail:
1029
- OS << Indent << " MCD::OPC_Fail,\n " ;
1027
+ OS << " MCD::OPC_Fail,\n " ;
1030
1028
break ;
1031
1029
}
1032
1030
}
1033
- OS << Indent << " 0\n " ;
1034
-
1035
- Indent -= 2 ;
1036
-
1037
- OS << Indent << " };\n\n " ;
1031
+ OS << " 0\n " ;
1032
+ OS << " };\n\n " ;
1038
1033
1039
1034
return OpcodeMask;
1040
1035
}
@@ -1048,27 +1043,23 @@ void DecoderEmitter::emitInstrLenTable(formatted_raw_ostream &OS,
1048
1043
}
1049
1044
1050
1045
void DecoderEmitter::emitPredicateFunction (formatted_raw_ostream &OS,
1051
- PredicateSet &Predicates,
1052
- indent Indent) const {
1046
+ PredicateSet &Predicates) const {
1053
1047
// The predicate function is just a big switch statement based on the
1054
1048
// 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 " ;
1060
1053
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 " ;
1063
1056
}
1064
- OS << Indent << " }\n " ;
1065
- Indent -= 2 ;
1066
- OS << Indent << " }\n\n " ;
1057
+ OS << " }\n " ;
1058
+ OS << " }\n\n " ;
1067
1059
}
1068
1060
1069
1061
void DecoderEmitter::emitDecoderFunction (formatted_raw_ostream &OS,
1070
- DecoderSet &Decoders,
1071
- indent Indent) const {
1062
+ DecoderSet &Decoders) const {
1072
1063
// The decoder function is just a big switch statement or a table of function
1073
1064
// pointers based on the input decoder index.
1074
1065
@@ -1085,53 +1076,46 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
1085
1076
if (UseFnTableInDecodeToMCInst) {
1086
1077
// Emit a function for each case first.
1087
1078
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 " ;
1094
1083
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 " ;
1098
1086
}
1099
1087
}
1100
1088
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 " ;
1107
1094
1108
1095
if (UseFnTableInDecodeToMCInst) {
1109
1096
// 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 " ;
1113
1099
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, "
1120
1105
" DecodeComplete);\n " ;
1121
1106
} 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 " ;
1126
1111
for (const auto &[Index, Decoder] : enumerate(Decoders)) {
1127
- OS << Indent << " case " << Index << " :\n " ;
1112
+ OS << " case " << Index << " :\n " ;
1128
1113
OS << Decoder;
1129
- OS << Indent + 2 << " return S;\n " ;
1114
+ OS << " return S;\n " ;
1130
1115
}
1131
- OS << Indent << " }\n " ;
1116
+ OS << " }\n " ;
1132
1117
}
1133
- Indent -= 2 ;
1134
- OS << Indent << " }\n " ;
1118
+ OS << " }\n " ;
1135
1119
}
1136
1120
1137
1121
// Populates the field of the insn given the start position and the number of
@@ -2673,7 +2657,7 @@ namespace {
2673
2657
TableInfo.Table .push_back (MCD::OPC_Fail);
2674
2658
2675
2659
// 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 (),
2677
2661
DecoderNamespace, EncodingIDs);
2678
2662
}
2679
2663
@@ -2689,10 +2673,10 @@ namespace {
2689
2673
2690
2674
// Emit the predicate function.
2691
2675
if (HasCheckPredicate)
2692
- emitPredicateFunction (OS, TableInfo.Predicates , indent ( 0 ) );
2676
+ emitPredicateFunction (OS, TableInfo.Predicates );
2693
2677
2694
2678
// Emit the decoder function.
2695
- emitDecoderFunction (OS, TableInfo.Decoders , indent ( 0 ) );
2679
+ emitDecoderFunction (OS, TableInfo.Decoders );
2696
2680
2697
2681
// Emit the main entry point for the decoder, decodeInstruction().
2698
2682
emitDecodeInstruction (OS, IsVarLenInst, OpcodeMask);
0 commit comments