@@ -609,19 +609,19 @@ class FilterChooser {
609609 void emitDecoder (raw_ostream &OS, indent Indent, unsigned EncodingID) const ;
610610 unsigned getDecoderIndex (DecoderSet &Decoders, unsigned EncodingID) const ;
611611
612- // Assign a single filter and run with it.
613- void runSingleFilter (unsigned startBit, unsigned numBit);
614-
615612 // reportRegion is a helper function for filterProcessor to mark a region as
616613 // eligible for use as a filter region.
617614 void reportRegion (std::vector<std::unique_ptr<Filter>> &Filters, bitAttr_t RA,
618- unsigned StartBit, unsigned BitIndex, bool AllowMixed);
615+ unsigned StartBit, unsigned BitIndex,
616+ bool AllowMixed) const ;
617+
618+ // / Scans the well-known encoding bits of the encodings and, builds up a list
619+ // / of candidate filters, and then returns the best one, if any.
620+ std::unique_ptr<Filter> findBestFilter (ArrayRef<bitAttr_t> BitAttrs,
621+ bool AllowMixed,
622+ bool Greedy = true ) const ;
619623
620- // FilterProcessor scans the well-known encoding bits of the instructions and
621- // builds up a list of candidate filters. It chooses the best filter and
622- // recursively descends down the decoding tree.
623- bool filterProcessor (ArrayRef<bitAttr_t> BitAttrs, bool AllowMixed,
624- bool Greedy = true );
624+ std::unique_ptr<Filter> findBestFilter () const ;
625625
626626 // Decides on the best configuration of filter(s) to use in order to decode
627627 // the instructions. A conflict of instructions may occur, in which case we
@@ -632,6 +632,8 @@ class FilterChooser {
632632 // emitTableEntries - Emit state machine entries to decode our share of
633633 // instructions.
634634 void emitTableEntries (DecoderTableInfo &TableInfo) const ;
635+
636+ void dump () const ;
635637};
636638
637639} // end anonymous namespace
@@ -1446,28 +1448,19 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
14461448 Best.getVariableFC ().emitTableEntries (TableInfo);
14471449}
14481450
1449- // Assign a single filter and run with it. Top level API client can initialize
1450- // with a single filter to start the filtering process.
1451- void FilterChooser::runSingleFilter (unsigned startBit, unsigned numBit) {
1452- BestFilter = std::make_unique<Filter>(*this , startBit, numBit);
1453- BestFilter->recurse ();
1454- }
1455-
14561451// reportRegion is a helper function for filterProcessor to mark a region as
14571452// eligible for use as a filter region.
14581453void FilterChooser::reportRegion (std::vector<std::unique_ptr<Filter>> &Filters,
14591454 bitAttr_t RA, unsigned StartBit,
1460- unsigned BitIndex, bool AllowMixed) {
1455+ unsigned BitIndex, bool AllowMixed) const {
14611456 if (AllowMixed ? RA == ATTR_MIXED : RA == ATTR_ALL_SET)
14621457 Filters.push_back (
14631458 std::make_unique<Filter>(*this , StartBit, BitIndex - StartBit));
14641459}
14651460
1466- // FilterProcessor scans the well-known encoding bits of the instructions and
1467- // builds up a list of candidate filters. It chooses the best filter and
1468- // recursively descends down the decoding tree.
1469- bool FilterChooser::filterProcessor (ArrayRef<bitAttr_t> BitAttrs,
1470- bool AllowMixed, bool Greedy) {
1461+ std::unique_ptr<Filter>
1462+ FilterChooser::findBestFilter (ArrayRef<bitAttr_t> BitAttrs, bool AllowMixed,
1463+ bool Greedy) const {
14711464 assert (EncodingIDs.size () >= 2 && " Nothing to filter" );
14721465
14731466 // Heuristics. See also doFilter()'s "Heuristics" comment when num of
@@ -1483,8 +1476,8 @@ bool FilterChooser::filterProcessor(ArrayRef<bitAttr_t> BitAttrs,
14831476 std::vector<Island> Islands = getIslands (EncodingBits);
14841477 if (!Islands.empty ()) {
14851478 // Found an instruction with island(s). Now just assign a filter.
1486- runSingleFilter (Islands[ 0 ]. StartBit , Islands[0 ].NumBits );
1487- return true ;
1479+ return std::make_unique<Filter>(* this , Islands[0 ].StartBit ,
1480+ Islands[ 0 ]. NumBits ) ;
14881481 }
14891482 }
14901483 }
@@ -1623,24 +1616,12 @@ bool FilterChooser::filterProcessor(ArrayRef<bitAttr_t> BitAttrs,
16231616 }
16241617
16251618 if (AllUseless)
1626- return false ;
1627-
1628- BestFilter = std::move (Filters[BestIndex]);
1629- BestFilter->recurse ();
1630- return true ;
1631-
1632- } // end of FilterChooser::filterProcessor(bool)
1633-
1634- // Decides on the best configuration of filter(s) to use in order to decode
1635- // the instructions. A conflict of instructions may occur, in which case we
1636- // dump the conflict set to the standard error.
1637- void FilterChooser::doFilter () {
1638- assert (!EncodingIDs.empty () && " FilterChooser created with no instructions" );
1619+ return nullptr ;
16391620
1640- // No filter needed.
1641- if (EncodingIDs.size () < 2 )
1642- return ;
1621+ return std::move (Filters[BestIndex]);
1622+ }
16431623
1624+ std::unique_ptr<Filter> FilterChooser::findBestFilter () const {
16441625 // We maintain BIT_WIDTH copies of the bitAttrs automaton.
16451626 // The automaton consumes the corresponding bit from each
16461627 // instruction.
@@ -1696,32 +1677,56 @@ void FilterChooser::doFilter() {
16961677 }
16971678
16981679 // Try regions of consecutive known bit values first.
1699- if (filterProcessor (BitAttrs, /* AllowMixed=*/ false ))
1700- return ;
1680+ if (std::unique_ptr<Filter> F =
1681+ findBestFilter (BitAttrs, /* AllowMixed=*/ false ))
1682+ return F;
17011683
17021684 // Then regions of mixed bits (both known and unitialized bit values allowed).
1703- if (filterProcessor (BitAttrs, /* AllowMixed=*/ true ))
1704- return ;
1685+ if (std::unique_ptr<Filter> F = findBestFilter (BitAttrs, /* AllowMixed=*/ true ))
1686+ return F ;
17051687
17061688 // Heuristics to cope with conflict set {t2CMPrs, t2SUBSrr, t2SUBSrs} where
17071689 // no single instruction for the maximum ATTR_MIXED region Inst{14-4} has a
17081690 // well-known encoding pattern. In such case, we backtrack and scan for the
17091691 // the very first consecutive ATTR_ALL_SET region and assign a filter to it.
1710- if (EncodingIDs.size () == 3 &&
1711- filterProcessor (BitAttrs, /* AllowMixed=*/ true , /* Greedy=*/ false ))
1692+ if (EncodingIDs.size () == 3 ) {
1693+ if (std::unique_ptr<Filter> F =
1694+ findBestFilter (BitAttrs, /* AllowMixed=*/ true , /* Greedy=*/ false ))
1695+ return F;
1696+ }
1697+
1698+ // There is a conflict we could not resolve.
1699+ return nullptr ;
1700+ }
1701+
1702+ // Decides on the best configuration of filter(s) to use in order to decode
1703+ // the instructions. A conflict of instructions may occur, in which case we
1704+ // dump the conflict set to the standard error.
1705+ void FilterChooser::doFilter () {
1706+ assert (!EncodingIDs.empty () && " FilterChooser created with no instructions" );
1707+
1708+ // No filter needed.
1709+ if (EncodingIDs.size () < 2 )
17121710 return ;
17131711
1714- // We don't know how to decode these instructions! Dump the
1715- // conflict set and bail.
1716- assert (!BestFilter);
1712+ BestFilter = findBestFilter ();
1713+ if (BestFilter) {
1714+ BestFilter->recurse ();
1715+ return ;
1716+ }
17171717
17181718 // Print out useful conflict information for postmortem analysis.
17191719 errs () << " Decoding Conflict:\n " ;
1720+ dump ();
1721+ PrintFatalError (" Decoding conflict encountered" );
1722+ }
17201723
1721- // Dump filters.
1724+ void FilterChooser::dump () const {
17221725 indent Indent (4 );
17231726 // Helps to keep the output right-justified.
17241727 unsigned PadToWidth = getMaxEncodingWidth ();
1728+
1729+ // Dump filter stack.
17251730 dumpStack (errs (), Indent, PadToWidth);
17261731
17271732 // Dump encodings.
@@ -1731,7 +1736,6 @@ void FilterChooser::doFilter() {
17311736 printKnownBits (errs (), Encoding.getMandatoryBits (), ' _' );
17321737 errs () << " " << Encoding.getName () << ' \n ' ;
17331738 }
1734- PrintFatalError (" Decoding conflict encountered" );
17351739}
17361740
17371741// emitTableEntries - Emit state machine entries to decode our share of
0 commit comments