Skip to content

Commit db9e1fb

Browse files
[MachineLICM] Avoid repeated hash lookups (NFC) (#110452)
1 parent 47b2230 commit db9e1fb

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

llvm/lib/CodeGen/MachineLICM.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ namespace {
148148
DenseMap<MachineLoop *, SmallVector<MachineBasicBlock *, 8>> ExitBlockMap;
149149

150150
bool isExitBlock(MachineLoop *CurLoop, const MachineBasicBlock *MBB) {
151-
if (ExitBlockMap.contains(CurLoop))
152-
return is_contained(ExitBlockMap[CurLoop], MBB);
153-
154-
SmallVector<MachineBasicBlock *, 8> ExitBlocks;
155-
CurLoop->getExitBlocks(ExitBlocks);
156-
ExitBlockMap[CurLoop] = ExitBlocks;
157-
return is_contained(ExitBlocks, MBB);
151+
auto [It, Inserted] = ExitBlockMap.try_emplace(CurLoop);
152+
if (Inserted) {
153+
SmallVector<MachineBasicBlock *, 8> ExitBlocks;
154+
CurLoop->getExitBlocks(ExitBlocks);
155+
It->second = ExitBlocks;
156+
}
157+
return is_contained(It->second, MBB);
158158
}
159159

160160
// Track 'estimated' register pressure.
@@ -1010,12 +1010,8 @@ MachineLICMImpl::calcRegisterCost(const MachineInstr *MI, bool ConsiderSeen,
10101010
if (RCCost == 0)
10111011
continue;
10121012
const int *PS = TRI->getRegClassPressureSets(RC);
1013-
for (; *PS != -1; ++PS) {
1014-
if (!Cost.contains(*PS))
1015-
Cost[*PS] = RCCost;
1016-
else
1017-
Cost[*PS] += RCCost;
1018-
}
1013+
for (; *PS != -1; ++PS)
1014+
Cost[*PS] += RCCost;
10191015
}
10201016
return Cost;
10211017
}

0 commit comments

Comments
 (0)