Skip to content

Commit 6a7ade0

Browse files
authored
[TableGen][DecoderEmitter] Remove redundant variable (NFC) (#154880)
`NumFiltered` is the number of elements in all vectors in a map. It is ever compared to 1, which is equivalent to checking if the map contains exactly one vector with exactly one element.
1 parent 586a713 commit 6a7ade0

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,26 +403,25 @@ class Filter {
403403
// A filter chooser for encodings that contain some '?' in the filtered range.
404404
std::unique_ptr<const FilterChooser> VariableFC;
405405

406-
// Number of instructions which fall under FilteredInstructions category.
407-
unsigned NumFiltered;
408-
409406
public:
410407
Filter(Filter &&f);
411408
Filter(const FilterChooser &owner, unsigned startBit, unsigned numBits);
412409

413410
~Filter() = default;
414411

415-
unsigned getNumFiltered() const { return NumFiltered; }
412+
bool hasSingleFilteredID() const {
413+
return FilteredIDs.size() == 1 && FilteredIDs.begin()->second.size() == 1;
414+
}
416415

417416
unsigned getSingletonEncodingID() const {
418-
assert(NumFiltered == 1);
417+
assert(hasSingleFilteredID());
419418
return FilteredIDs.begin()->second.front();
420419
}
421420

422421
// Return the filter chooser for the group of instructions without constant
423422
// segment values.
424423
const FilterChooser &getVariableFC() const {
425-
assert(NumFiltered == 1 && FilterChooserMap.empty());
424+
assert(hasSingleFilteredID() && FilterChooserMap.empty());
426425
return *VariableFC;
427426
}
428427

@@ -617,14 +616,12 @@ Filter::Filter(Filter &&f)
617616
FilteredIDs(std::move(f.FilteredIDs)),
618617
VariableIDs(std::move(f.VariableIDs)),
619618
FilterChooserMap(std::move(f.FilterChooserMap)),
620-
VariableFC(std::move(f.VariableFC)), NumFiltered(f.NumFiltered) {}
619+
VariableFC(std::move(f.VariableFC)) {}
621620

622621
Filter::Filter(const FilterChooser &owner, unsigned startBit, unsigned numBits)
623622
: Owner(owner), StartBit(startBit), NumBits(numBits) {
624623
assert(StartBit + NumBits - 1 < Owner.BitWidth);
625624

626-
NumFiltered = 0;
627-
628625
for (unsigned EncodingID : Owner.EncodingIDs) {
629626
// Populates the insn given the uid.
630627
KnownBits EncodingBits = Owner.getMandatoryEncodingBits(EncodingID);
@@ -636,7 +633,6 @@ Filter::Filter(const FilterChooser &owner, unsigned startBit, unsigned numBits)
636633
// The encoding bits are well-known. Lets add the uid of the
637634
// instruction into the bucket keyed off the constant field value.
638635
FilteredIDs[FieldBits.getConstant().getZExtValue()].push_back(EncodingID);
639-
++NumFiltered;
640636
} else {
641637
// Some of the encoding bit(s) are unspecified. This contributes to
642638
// one additional member of "Variable" instructions.
@@ -668,7 +664,7 @@ void Filter::recurse() {
668664

669665
// No need to recurse for a singleton filtered instruction.
670666
// See also Filter::emit*().
671-
if (getNumFiltered() == 1) {
667+
if (hasSingleFilteredID()) {
672668
assert(VariableFC && "Shouldn't have created a filter for one encoding!");
673669
return;
674670
}
@@ -1716,7 +1712,7 @@ void FilterChooser::emitTableEntries(DecoderTableInfo &TableInfo) const {
17161712
}
17171713

17181714
// Use the best filter to do the decoding!
1719-
if (BestFilter->getNumFiltered() == 1)
1715+
if (BestFilter->hasSingleFilteredID())
17201716
emitSingletonTableEntry(TableInfo, *BestFilter);
17211717
else
17221718
BestFilter->emitTableEntry(TableInfo);

0 commit comments

Comments
 (0)