Skip to content

Commit 485ebbf

Browse files
committed
[TableGen] Use emplace_back instead of resize to size() + 1. NFC.
1 parent 192c23b commit 485ebbf

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

llvm/utils/TableGen/CodeGenRegisters.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,15 +1986,15 @@ void CodeGenRegBank::computeRegUnitSets() {
19861986
continue;
19871987

19881988
// Speculatively grow the RegUnitSets to hold the new set.
1989-
RegUnitSets.resize(RegUnitSets.size() + 1);
1990-
RegUnitSets.back().Name = RC.getName();
1989+
RegUnitSet &RUSet = RegUnitSets.emplace_back();
1990+
RUSet.Name = RC.getName();
19911991

19921992
// Compute a sorted list of units in this class.
1993-
RC.buildRegUnitSet(*this, RegUnitSets.back().Units);
1993+
RC.buildRegUnitSet(*this, RUSet.Units);
19941994

19951995
// Find an existing RegUnitSet.
19961996
std::vector<RegUnitSet>::const_iterator SetI =
1997-
findRegUnitSet(RegUnitSets, RegUnitSets.back());
1997+
findRegUnitSet(RegUnitSets, RUSet);
19981998
if (SetI != std::prev(RegUnitSets.end()))
19991999
RegUnitSets.pop_back();
20002000
}
@@ -2043,27 +2043,26 @@ void CodeGenRegBank::computeRegUnitSets() {
20432043
continue;
20442044

20452045
// Speculatively grow the RegUnitSets to hold the new set.
2046-
RegUnitSets.resize(RegUnitSets.size() + 1);
2047-
RegUnitSets.back().Name =
2046+
RegUnitSet &RUSet = RegUnitSets.emplace_back();
2047+
RUSet.Name =
20482048
RegUnitSets[Idx].Name + "_with_" + RegUnitSets[SearchIdx].Name;
20492049

20502050
std::set_union(RegUnitSets[Idx].Units.begin(),
20512051
RegUnitSets[Idx].Units.end(),
20522052
RegUnitSets[SearchIdx].Units.begin(),
20532053
RegUnitSets[SearchIdx].Units.end(),
2054-
std::inserter(RegUnitSets.back().Units,
2055-
RegUnitSets.back().Units.begin()));
2054+
std::inserter(RUSet.Units, RUSet.Units.begin()));
20562055

20572056
// Find an existing RegUnitSet, or add the union to the unique sets.
20582057
std::vector<RegUnitSet>::const_iterator SetI =
2059-
findRegUnitSet(RegUnitSets, RegUnitSets.back());
2058+
findRegUnitSet(RegUnitSets, RUSet);
20602059
if (SetI != std::prev(RegUnitSets.end()))
20612060
RegUnitSets.pop_back();
20622061
else {
20632062
LLVM_DEBUG(dbgs() << "UnitSet " << RegUnitSets.size() - 1 << " "
2064-
<< RegUnitSets.back().Name << ":";
2063+
<< RUSet.Name << ":";
20652064
for (auto &U
2066-
: RegUnitSets.back().Units) printRegUnitName(U);
2065+
: RUSet.Units) printRegUnitName(U);
20672066
dbgs() << "\n";);
20682067
}
20692068
}
@@ -2138,8 +2137,7 @@ void CodeGenRegBank::computeRegUnitSets() {
21382137
RegUnits[UnitIdx].RegClassUnitSetsIdx = RCUnitSetsIdx;
21392138
if (RCUnitSetsIdx == RegClassUnitSets.size()) {
21402139
// Create a new list of UnitSets as a "fake" register class.
2141-
RegClassUnitSets.resize(RCUnitSetsIdx + 1);
2142-
RegClassUnitSets[RCUnitSetsIdx] = std::move(RUSets);
2140+
RegClassUnitSets.push_back(std::move(RUSets));
21432141
}
21442142
}
21452143
}

llvm/utils/TableGen/CodeGenRegisters.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,7 @@ class CodeGenRegBank {
712712
// Create a native register unit that is associated with one or two root
713713
// registers.
714714
unsigned newRegUnit(CodeGenRegister *R0, CodeGenRegister *R1 = nullptr) {
715-
RegUnits.resize(RegUnits.size() + 1);
716-
RegUnit &RU = RegUnits.back();
715+
RegUnit &RU = RegUnits.emplace_back();
717716
RU.Roots[0] = R0;
718717
RU.Roots[1] = R1;
719718
RU.Artificial = R0->Artificial;
@@ -725,8 +724,8 @@ class CodeGenRegBank {
725724
// Create a new non-native register unit that can be adopted by a register
726725
// to increase its pressure. Note that NumNativeRegUnits is not increased.
727726
unsigned newRegUnit(unsigned Weight) {
728-
RegUnits.resize(RegUnits.size() + 1);
729-
RegUnits.back().Weight = Weight;
727+
RegUnit &RU = RegUnits.emplace_back();
728+
RU.Weight = Weight;
730729
return RegUnits.size() - 1;
731730
}
732731

llvm/utils/TableGen/SubtargetEmitter.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,10 @@ void SubtargetEmitter::EmitStageAndOperandCycleData(
486486
std::map<std::string, unsigned> ItinStageMap, ItinOperandMap;
487487
for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) {
488488
// Add process itinerary to the list.
489-
ProcItinLists.resize(ProcItinLists.size() + 1);
489+
std::vector<InstrItinerary> &ItinList = ProcItinLists.emplace_back();
490490

491491
// If this processor defines no itineraries, then leave the itinerary list
492492
// empty.
493-
std::vector<InstrItinerary> &ItinList = ProcItinLists.back();
494493
if (!ProcModel.hasItineraries())
495494
continue;
496495

@@ -1029,17 +1028,16 @@ void SubtargetEmitter::ExpandProcResources(
10291028
// tables. Must be called for each processor in order.
10301029
void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel,
10311030
SchedClassTables &SchedTables) {
1032-
SchedTables.ProcSchedClasses.resize(SchedTables.ProcSchedClasses.size() + 1);
1031+
std::vector<MCSchedClassDesc> &SCTab =
1032+
SchedTables.ProcSchedClasses.emplace_back();
10331033
if (!ProcModel.hasInstrSchedModel())
10341034
return;
10351035

1036-
std::vector<MCSchedClassDesc> &SCTab = SchedTables.ProcSchedClasses.back();
10371036
LLVM_DEBUG(dbgs() << "\n+++ SCHED CLASSES (GenSchedClassTables) +++\n");
10381037
for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) {
10391038
LLVM_DEBUG(SC.dump(&SchedModels));
10401039

1041-
SCTab.resize(SCTab.size() + 1);
1042-
MCSchedClassDesc &SCDesc = SCTab.back();
1040+
MCSchedClassDesc &SCDesc = SCTab.emplace_back();
10431041
// SCDesc.Name is guarded by NDEBUG
10441042
SCDesc.NumMicroOps = 0;
10451043
SCDesc.BeginGroup = false;

0 commit comments

Comments
 (0)