Skip to content

Commit 1f90af1

Browse files
committed
[TableGen] Do not speculatively grow RegUnitSets. NFC.
This seems to be a trick to avoid copying a RegUnitSet, but it can be done more simply using std::move.
1 parent 11fcae6 commit 1f90af1

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

llvm/utils/TableGen/CodeGenRegisters.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,18 +1985,14 @@ void CodeGenRegBank::computeRegUnitSets() {
19851985
if (!RC.Allocatable || RC.Artificial || !RC.GeneratePressureSet)
19861986
continue;
19871987

1988-
// Speculatively grow the RegUnitSets to hold the new set.
1989-
RegUnitSet &RUSet = RegUnitSets.emplace_back();
1990-
RUSet.Name = RC.getName();
1991-
19921988
// Compute a sorted list of units in this class.
1989+
RegUnitSet RUSet;
1990+
RUSet.Name = RC.getName();
19931991
RC.buildRegUnitSet(*this, RUSet.Units);
19941992

19951993
// Find an existing RegUnitSet.
1996-
std::vector<RegUnitSet>::const_iterator SetI =
1997-
findRegUnitSet(RegUnitSets, RUSet);
1998-
if (SetI != std::prev(RegUnitSets.end()))
1999-
RegUnitSets.pop_back();
1994+
if (findRegUnitSet(RegUnitSets, RUSet) == RegUnitSets.end())
1995+
RegUnitSets.push_back(std::move(RUSet));
20001996
}
20011997

20021998
if (RegUnitSets.empty())
@@ -2042,28 +2038,23 @@ void CodeGenRegBank::computeRegUnitSets() {
20422038
if (Intersection.empty())
20432039
continue;
20442040

2045-
// Speculatively grow the RegUnitSets to hold the new set.
2046-
RegUnitSet &RUSet = RegUnitSets.emplace_back();
2041+
RegUnitSet RUSet;
20472042
RUSet.Name =
20482043
RegUnitSets[Idx].Name + "_with_" + RegUnitSets[SearchIdx].Name;
2049-
20502044
std::set_union(RegUnitSets[Idx].Units.begin(),
20512045
RegUnitSets[Idx].Units.end(),
20522046
RegUnitSets[SearchIdx].Units.begin(),
20532047
RegUnitSets[SearchIdx].Units.end(),
20542048
std::inserter(RUSet.Units, RUSet.Units.begin()));
20552049

20562050
// Find an existing RegUnitSet, or add the union to the unique sets.
2057-
std::vector<RegUnitSet>::const_iterator SetI =
2058-
findRegUnitSet(RegUnitSets, RUSet);
2059-
if (SetI != std::prev(RegUnitSets.end()))
2060-
RegUnitSets.pop_back();
2061-
else {
2062-
LLVM_DEBUG(dbgs() << "UnitSet " << RegUnitSets.size() - 1 << " "
2051+
if (findRegUnitSet(RegUnitSets, RUSet) == RegUnitSets.end()) {
2052+
LLVM_DEBUG(dbgs() << "UnitSet " << RegUnitSets.size() << " "
20632053
<< RUSet.Name << ":";
20642054
for (auto &U
20652055
: RUSet.Units) printRegUnitName(U);
20662056
dbgs() << "\n";);
2057+
RegUnitSets.push_back(std::move(RUSet));
20672058
}
20682059
}
20692060
}

0 commit comments

Comments
 (0)