@@ -222,8 +222,9 @@ class DecoderEmitter {
222
222
DecoderEmitter (const RecordKeeper &R, StringRef PredicateNamespace)
223
223
: RK(R), Target(R), PredicateNamespace(PredicateNamespace) {}
224
224
225
- // Emit the decoder state machine table.
226
- void emitTable (formatted_raw_ostream &OS, DecoderTable &Table, indent Indent,
225
+ // Emit the decoder state machine table. Return true if any `TryDecode` ops
226
+ // were generated.
227
+ bool emitTable (formatted_raw_ostream &OS, DecoderTable &Table, indent Indent,
227
228
unsigned BitWidth, StringRef Namespace,
228
229
const EncodingIDsVec &EncodingIDs) const ;
229
230
void emitInstrLenTable (formatted_raw_ostream &OS,
@@ -827,7 +828,7 @@ unsigned Filter::usefulness() const {
827
828
// ////////////////////////////////
828
829
829
830
// Emit the decoder state machine table.
830
- void DecoderEmitter::emitTable (formatted_raw_ostream &OS, DecoderTable &Table,
831
+ bool DecoderEmitter::emitTable (formatted_raw_ostream &OS, DecoderTable &Table,
831
832
indent Indent, unsigned BitWidth,
832
833
StringRef Namespace,
833
834
const EncodingIDsVec &EncodingIDs) const {
@@ -884,6 +885,8 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
884
885
OS << " (Fail)" ;
885
886
};
886
887
888
+ bool HasTryDecode = false ;
889
+
887
890
while (I != E) {
888
891
assert (I < E && " incomplete decode table entry!" );
889
892
@@ -964,6 +967,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
964
967
case MCD::OPC_TryDecodeOrFail: {
965
968
bool IsFail = DecoderOp == MCD::OPC_TryDecodeOrFail;
966
969
bool IsTry = DecoderOp == MCD::OPC_TryDecode || IsFail;
970
+ HasTryDecode |= IsTry;
967
971
// Decode the Opcode value.
968
972
const char *ErrMsg = nullptr ;
969
973
unsigned Opc = decodeULEB128 (&*I, nullptr , EndPtr, &ErrMsg);
@@ -1027,6 +1031,8 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
1027
1031
Indent -= 2 ;
1028
1032
1029
1033
OS << Indent << " };\n\n " ;
1034
+
1035
+ return HasTryDecode;
1030
1036
}
1031
1037
1032
1038
void DecoderEmitter::emitInstrLenTable (formatted_raw_ostream &OS,
@@ -2217,8 +2223,8 @@ static void insertBits(InsnType &field, InsnType bits, unsigned startBit,
2217
2223
2218
2224
// emitDecodeInstruction - Emit the templated helper function
2219
2225
// decodeInstruction().
2220
- static void emitDecodeInstruction (formatted_raw_ostream &OS,
2221
- bool IsVarLenInst ) {
2226
+ static void emitDecodeInstruction (formatted_raw_ostream &OS, bool IsVarLenInst,
2227
+ bool HasTryDecode ) {
2222
2228
OS << R"(
2223
2229
static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
2224
2230
unsigned NumToSkip = *Ptr++;
@@ -2364,7 +2370,9 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
2364
2370
<< ", using decoder " << DecodeIdx << ": "
2365
2371
<< (S != MCDisassembler::Fail ? "PASS\n" : "FAIL\n"));
2366
2372
return S;
2367
- }
2373
+ })" ;
2374
+ if (HasTryDecode) {
2375
+ OS << R"(
2368
2376
case MCD::OPC_TryDecode:
2369
2377
case MCD::OPC_TryDecodeOrFail: {
2370
2378
bool IsFail = DecoderOp == MCD::OPC_TryDecodeOrFail;
@@ -2399,7 +2407,9 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
2399
2407
// set before the decode attempt.
2400
2408
S = MCDisassembler::Success;
2401
2409
break;
2402
- }
2410
+ })" ;
2411
+ }
2412
+ OS << R"(
2403
2413
case MCD::OPC_SoftFail: {
2404
2414
// Decode the mask values.
2405
2415
uint64_t PositiveMask = decodeULEB128AndIncUnsafe(Ptr);
@@ -2609,6 +2619,7 @@ namespace {
2609
2619
}
2610
2620
2611
2621
DecoderTableInfo TableInfo;
2622
+ bool HasTryDecode = false ;
2612
2623
for (const auto &Opc : OpcMap) {
2613
2624
// Emit the decoder for this namespace+width combination.
2614
2625
ArrayRef<EncodingAndInst> NumberedEncodingsRef (NumberedEncodings.data (),
@@ -2634,8 +2645,8 @@ namespace {
2634
2645
TableInfo.Table .push_back (MCD::OPC_Fail);
2635
2646
2636
2647
// Print the table to the output stream.
2637
- emitTable (OS, TableInfo.Table , indent (0 ), FC.getBitWidth (), Opc. first . first ,
2638
- Opc.second );
2648
+ HasTryDecode |= emitTable (OS, TableInfo.Table , indent (0 ), FC.getBitWidth (),
2649
+ Opc. first . first , Opc.second );
2639
2650
}
2640
2651
2641
2652
// For variable instruction, we emit a instruction length table
@@ -2650,7 +2661,7 @@ namespace {
2650
2661
emitDecoderFunction (OS, TableInfo.Decoders , indent (0 ));
2651
2662
2652
2663
// Emit the main entry point for the decoder, decodeInstruction().
2653
- emitDecodeInstruction (OS, IsVarLenInst);
2664
+ emitDecodeInstruction (OS, IsVarLenInst, HasTryDecode );
2654
2665
2655
2666
OS << " \n } // namespace\n " ;
2656
2667
}
0 commit comments