[llvm] db9e1fb - [MachineLICM] Avoid repeated hash lookups (NFC) (#110452)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 06:49:08 PDT 2024
Author: Kazu Hirata
Date: 2024-09-30T06:49:04-07:00
New Revision: db9e1fb3bcc8ab950cd9b0282a29be7943ce185e
URL: https://github.com/llvm/llvm-project/commit/db9e1fb3bcc8ab950cd9b0282a29be7943ce185e
DIFF: https://github.com/llvm/llvm-project/commit/db9e1fb3bcc8ab950cd9b0282a29be7943ce185e.diff
LOG: [MachineLICM] Avoid repeated hash lookups (NFC) (#110452)
Added:
Modified:
llvm/lib/CodeGen/MachineLICM.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp
index 3289a692221ba6..793ad75759ccb8 100644
--- a/llvm/lib/CodeGen/MachineLICM.cpp
+++ b/llvm/lib/CodeGen/MachineLICM.cpp
@@ -148,13 +148,13 @@ namespace {
DenseMap<MachineLoop *, SmallVector<MachineBasicBlock *, 8>> ExitBlockMap;
bool isExitBlock(MachineLoop *CurLoop, const MachineBasicBlock *MBB) {
- if (ExitBlockMap.contains(CurLoop))
- return is_contained(ExitBlockMap[CurLoop], MBB);
-
- SmallVector<MachineBasicBlock *, 8> ExitBlocks;
- CurLoop->getExitBlocks(ExitBlocks);
- ExitBlockMap[CurLoop] = ExitBlocks;
- return is_contained(ExitBlocks, MBB);
+ auto [It, Inserted] = ExitBlockMap.try_emplace(CurLoop);
+ if (Inserted) {
+ SmallVector<MachineBasicBlock *, 8> ExitBlocks;
+ CurLoop->getExitBlocks(ExitBlocks);
+ It->second = ExitBlocks;
+ }
+ return is_contained(It->second, MBB);
}
// Track 'estimated' register pressure.
@@ -1010,12 +1010,8 @@ MachineLICMImpl::calcRegisterCost(const MachineInstr *MI, bool ConsiderSeen,
if (RCCost == 0)
continue;
const int *PS = TRI->getRegClassPressureSets(RC);
- for (; *PS != -1; ++PS) {
- if (!Cost.contains(*PS))
- Cost[*PS] = RCCost;
- else
- Cost[*PS] += RCCost;
- }
+ for (; *PS != -1; ++PS)
+ Cost[*PS] += RCCost;
}
return Cost;
}
More information about the llvm-commits
mailing list