Skip to content

Commit 75210df

Browse files
[AMDGPU] Avoid repeated map lookups (NFC) (#132877)
1 parent cca0f81 commit 75210df

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

llvm/lib/Target/AMDGPU/SIMachineScheduler.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -806,15 +806,11 @@ void SIScheduleBlockCreator::colorComputeReservedDependencies() {
806806
CurrentTopDownReservedDependencyColoring[SU->NodeNum] =
807807
*SUColors.begin();
808808
else {
809-
std::map<std::set<unsigned>, unsigned>::iterator Pos =
810-
ColorCombinations.find(SUColors);
811-
if (Pos != ColorCombinations.end()) {
812-
CurrentTopDownReservedDependencyColoring[SU->NodeNum] = Pos->second;
813-
} else {
814-
CurrentTopDownReservedDependencyColoring[SU->NodeNum] =
815-
NextNonReservedID;
816-
ColorCombinations[SUColors] = NextNonReservedID++;
817-
}
809+
auto [Pos, Inserted] =
810+
ColorCombinations.try_emplace(SUColors, NextNonReservedID);
811+
if (Inserted)
812+
++NextNonReservedID;
813+
CurrentTopDownReservedDependencyColoring[SU->NodeNum] = Pos->second;
818814
}
819815
}
820816

@@ -1176,14 +1172,15 @@ void SIScheduleBlockCreator::createBlocksForVariant(SISchedulerBlockCreatorVaria
11761172
for (unsigned i = 0, e = DAGSize; i != e; ++i) {
11771173
SUnit *SU = &DAG->SUnits[i];
11781174
unsigned Color = CurrentColoring[SU->NodeNum];
1179-
if (RealID.find(Color) == RealID.end()) {
1175+
auto [It, Inserted] = RealID.try_emplace(Color);
1176+
if (Inserted) {
11801177
int ID = CurrentBlocks.size();
11811178
BlockPtrs.push_back(std::make_unique<SIScheduleBlock>(DAG, this, ID));
11821179
CurrentBlocks.push_back(BlockPtrs.rbegin()->get());
1183-
RealID[Color] = ID;
1180+
It->second = ID;
11841181
}
1185-
CurrentBlocks[RealID[Color]]->addUnit(SU);
1186-
Node2CurrentBlock[SU->NodeNum] = RealID[Color];
1182+
CurrentBlocks[It->second]->addUnit(SU);
1183+
Node2CurrentBlock[SU->NodeNum] = It->second;
11871184
}
11881185

11891186
// Build dependencies between blocks.

0 commit comments

Comments
 (0)