@@ -714,30 +714,39 @@ void Filter::emitTableEntry(DecoderTableInfo &TableInfo) const {
714
714
TableInfo.Table .insertULEB128 (StartBit);
715
715
TableInfo.Table .push_back (NumBits);
716
716
717
- // A new filter entry begins a new scope for fixup resolution.
718
- TableInfo.FixupStack .emplace_back ();
717
+ // If the NO_FIXED_SEGMENTS_SENTINEL is present, we need to add a new scope
718
+ // for this filter. Otherwise, we can skip adding a new scope and any
719
+ // patching added will automatically be added to the enclosing scope.
720
+
721
+ // If NO_FIXED_SEGMENTS_SENTINEL is present, it will be last entry in
722
+ // FilterChooserMap.
723
+
724
+ const uint64_t LastFilter = FilterChooserMap.rbegin ()->first ;
725
+ bool HasFallthrough = LastFilter == NO_FIXED_SEGMENTS_SENTINEL;
726
+ if (HasFallthrough)
727
+ TableInfo.FixupStack .emplace_back ();
719
728
720
729
DecoderTable &Table = TableInfo.Table ;
721
730
722
731
size_t PrevFilter = 0 ;
723
- bool HasFallthrough = false ;
724
- for (const auto &Filter : FilterChooserMap) {
725
- // Field value -1 implies a non-empty set of variable instructions.
726
- // See also recurse().
727
- if (Filter.first == NO_FIXED_SEGMENTS_SENTINEL) {
728
- HasFallthrough = true ;
729
-
732
+ for (const auto &[FilterVal, Delegate] : FilterChooserMap) {
733
+ // Field value NO_FIXED_SEGMENTS_SENTINEL implies a non-empty set of
734
+ // variable instructions. See also recurse().
735
+ if (FilterVal == NO_FIXED_SEGMENTS_SENTINEL) {
730
736
// Each scope should always have at least one filter value to check
731
737
// for.
732
738
assert (PrevFilter != 0 && " empty filter set!" );
733
739
FixupList &CurScope = TableInfo.FixupStack .back ();
734
740
// Resolve any NumToSkip fixups in the current scope.
735
741
resolveTableFixups (Table, CurScope, Table.size ());
736
- CurScope.clear ();
742
+
743
+ // Delete the scope we have added here.
744
+ TableInfo.FixupStack .pop_back ();
745
+
737
746
PrevFilter = 0 ; // Don't re-process the filter's fallthrough.
738
747
} else {
739
748
Table.push_back (MCD::OPC_FilterValue);
740
- Table.insertULEB128 (Filter. first );
749
+ Table.insertULEB128 (FilterVal );
741
750
// Reserve space for the NumToSkip entry. We'll backpatch the value
742
751
// later.
743
752
PrevFilter = Table.insertNumToSkip ();
@@ -747,11 +756,11 @@ void Filter::emitTableEntry(DecoderTableInfo &TableInfo) const {
747
756
// Now delegate to the sub filter chooser for further decodings.
748
757
// The case may fallthrough, which happens if the remaining well-known
749
758
// encoding bits do not match exactly.
750
- Filter. second ->emitTableEntries (TableInfo);
759
+ Delegate ->emitTableEntries (TableInfo);
751
760
752
761
// Now that we've emitted the body of the handler, update the NumToSkip
753
762
// of the filter itself to be able to skip forward when false. Subtract
754
- // two as to account for the width of the NumToSkip field itself.
763
+ // three as to account for the width of the NumToSkip field itself.
755
764
if (PrevFilter) {
756
765
uint32_t NumToSkip = Table.size () - PrevFilter - 3 ;
757
766
assert (isUInt<24 >(NumToSkip) && " disassembler decoding table too large!" );
@@ -761,13 +770,6 @@ void Filter::emitTableEntry(DecoderTableInfo &TableInfo) const {
761
770
}
762
771
}
763
772
764
- // Any remaining unresolved fixups bubble up to the parent fixup scope.
765
- assert (TableInfo.FixupStack .size () > 1 && " fixup stack underflow!" );
766
- FixupScopeList::iterator Source = TableInfo.FixupStack .end () - 1 ;
767
- FixupScopeList::iterator Dest = Source - 1 ;
768
- llvm::append_range (*Dest, *Source);
769
- TableInfo.FixupStack .pop_back ();
770
-
771
773
// If there is no fallthrough, then the final filter should get fixed
772
774
// up according to the enclosing scope rather than the current position.
773
775
if (!HasFallthrough)
0 commit comments