@@ -192,6 +192,17 @@ struct DecoderTableInfo {
192
192
DecoderSet Decoders;
193
193
194
194
bool isOutermostScope () const { return FixupStack.size () == 1 ; }
195
+
196
+ void pushScope () { FixupStack.emplace_back (); }
197
+
198
+ void popScope () {
199
+ // Resolve any remaining fixups in the current scope before popping it.
200
+ // All fixups resolve to the current location.
201
+ uint32_t DestIdx = Table.size ();
202
+ for (uint32_t FixupIdx : FixupStack.back ())
203
+ Table.patchNumToSkip (FixupIdx, DestIdx);
204
+ FixupStack.pop_back ();
205
+ }
195
206
};
196
207
197
208
struct EncodingAndInst {
@@ -726,14 +737,6 @@ void Filter::recurse() {
726
737
}
727
738
}
728
739
729
- static void resolveTableFixups (DecoderTable &Table, const FixupList &Fixups,
730
- uint32_t DestIdx) {
731
- // Any NumToSkip fixups in the current scope can resolve to the
732
- // current location.
733
- for (uint32_t FixupIdx : Fixups)
734
- Table.patchNumToSkip (FixupIdx, DestIdx);
735
- }
736
-
737
740
// Emit table entries to decode instructions given a segment or segments
738
741
// of bits.
739
742
void Filter::emitTableEntry (DecoderTableInfo &TableInfo) const {
@@ -753,7 +756,7 @@ void Filter::emitTableEntry(DecoderTableInfo &TableInfo) const {
753
756
const uint64_t LastFilter = FilterChooserMap.rbegin ()->first ;
754
757
bool HasFallthrough = LastFilter == NO_FIXED_SEGMENTS_SENTINEL;
755
758
if (HasFallthrough)
756
- TableInfo.FixupStack . emplace_back ();
759
+ TableInfo.pushScope ();
757
760
758
761
DecoderTable &Table = TableInfo.Table ;
759
762
@@ -765,13 +768,7 @@ void Filter::emitTableEntry(DecoderTableInfo &TableInfo) const {
765
768
// Each scope should always have at least one filter value to check
766
769
// for.
767
770
assert (PrevFilter != 0 && " empty filter set!" );
768
- FixupList &CurScope = TableInfo.FixupStack .back ();
769
- // Resolve any NumToSkip fixups in the current scope.
770
- resolveTableFixups (Table, CurScope, Table.size ());
771
-
772
- // Delete the scope we have added here.
773
- TableInfo.FixupStack .pop_back ();
774
-
771
+ TableInfo.popScope ();
775
772
PrevFilter = 0 ; // Don't re-process the filter's fallthrough.
776
773
} else {
777
774
// The last filtervalue emitted can be OPC_FilterValue if we are at
@@ -1515,13 +1512,9 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
1515
1512
1516
1513
// complex singletons need predicate checks from the first singleton
1517
1514
// to refer forward to the variable filterchooser that follows.
1518
- TableInfo.FixupStack .emplace_back ();
1519
-
1515
+ TableInfo.pushScope ();
1520
1516
emitSingletonTableEntry (TableInfo, Opc);
1521
-
1522
- resolveTableFixups (TableInfo.Table , TableInfo.FixupStack .back (),
1523
- TableInfo.Table .size ());
1524
- TableInfo.FixupStack .pop_back ();
1517
+ TableInfo.popScope ();
1525
1518
1526
1519
Best.getVariableFC ().emitTableEntries (TableInfo);
1527
1520
}
@@ -2623,16 +2616,12 @@ namespace {
2623
2616
// predicates and decoders themselves, however, are shared across all
2624
2617
// decoders to give more opportunities for uniqueing.
2625
2618
TableInfo.Table .clear ();
2626
- TableInfo.FixupStack .clear ();
2627
- TableInfo.FixupStack .emplace_back ();
2619
+ TableInfo.pushScope ();
2628
2620
FC.emitTableEntries (TableInfo);
2629
2621
// Any NumToSkip fixups in the top level scope can resolve to the
2630
2622
// OPC_Fail at the end of the table.
2631
- assert (TableInfo.FixupStack .size () == 1 && " fixup stack phasing error!" );
2632
- // Resolve any NumToSkip fixups in the current scope.
2633
- resolveTableFixups (TableInfo.Table , TableInfo.FixupStack .back (),
2634
- TableInfo.Table .size ());
2635
- TableInfo.FixupStack .clear ();
2623
+ assert (TableInfo.isOutermostScope () && " fixup stack phasing error!" );
2624
+ TableInfo.popScope ();
2636
2625
2637
2626
TableInfo.Table .push_back (MCD::OPC_Fail);
2638
2627
0 commit comments