Skip to content

Commit 695a007

Browse files
[X86] Avoid repeated hash lookups (NFC) (#131725)
1 parent 2c56383 commit 695a007

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

llvm/lib/Target/X86/X86PadShortFunction.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,9 @@ void PadShortFunc::findReturns(MachineBasicBlock *MBB, unsigned int Cycles) {
181181
bool PadShortFunc::cyclesUntilReturn(MachineBasicBlock *MBB,
182182
unsigned int &Cycles) {
183183
// Return cached result if BB was previously visited
184-
DenseMap<MachineBasicBlock*, VisitedBBInfo>::iterator it
185-
= VisitedBBs.find(MBB);
186-
if (it != VisitedBBs.end()) {
187-
VisitedBBInfo BBInfo = it->second;
184+
auto [It, Inserted] = VisitedBBs.try_emplace(MBB);
185+
if (!Inserted) {
186+
VisitedBBInfo BBInfo = It->second;
188187
Cycles += BBInfo.Cycles;
189188
return BBInfo.HasReturn;
190189
}
@@ -196,15 +195,15 @@ bool PadShortFunc::cyclesUntilReturn(MachineBasicBlock *MBB,
196195
// functions do not count because the called function will be padded,
197196
// if necessary.
198197
if (MI.isReturn() && !MI.isCall()) {
199-
VisitedBBs[MBB] = VisitedBBInfo(true, CyclesToEnd);
198+
It->second = VisitedBBInfo(true, CyclesToEnd);
200199
Cycles += CyclesToEnd;
201200
return true;
202201
}
203202

204203
CyclesToEnd += TSM.computeInstrLatency(&MI);
205204
}
206205

207-
VisitedBBs[MBB] = VisitedBBInfo(false, CyclesToEnd);
206+
It->second = VisitedBBInfo(false, CyclesToEnd);
208207
Cycles += CyclesToEnd;
209208
return false;
210209
}

0 commit comments

Comments
 (0)