From e2c66e961d9792a58d7a86f8f882df98bf2c30d0 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 20 Feb 2025 09:03:26 -0800 Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC) This patch eliminates repeated hash lookups at three levels: - RegToSlotIdx of DenseMap - Reloads of DenseMap - Reloads[MBB] of SmallSet --- .../CodeGen/FixupStatepointCallerSaved.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp index edb85d212a4d4..0d6ec8975689b 100644 --- a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp +++ b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp @@ -179,19 +179,11 @@ class RegReloadCache { public: RegReloadCache() = default; - // Record reload of Reg from FI in block MBB - void recordReload(Register Reg, int FI, const MachineBasicBlock *MBB) { + // Record reload of Reg from FI in block MBB if not present yet. + // Return true if the reload is successfully recorded. + bool tryRecordReload(Register Reg, int FI, const MachineBasicBlock *MBB) { RegSlotPair RSP(Reg, FI); - auto Res = Reloads[MBB].insert(RSP); - (void)Res; - assert(Res.second && "reload already exists"); - } - - // Does basic block MBB contains reload of Reg from FI? - bool hasReload(Register Reg, int FI, const MachineBasicBlock *MBB) { - RegSlotPair RSP(Reg, FI); - auto It = Reloads.find(MBB); - return It != Reloads.end() && It->second.count(RSP); + return Reloads[MBB].insert(RSP).second; } }; @@ -459,8 +451,7 @@ class StatepointState { LLVM_DEBUG(dbgs() << "Reloading " << printReg(Reg, &TRI) << " from FI " << RegToSlotIdx[Reg] << " after statepoint\n"); - if (EHPad && !RC.hasReload(Reg, RegToSlotIdx[Reg], EHPad)) { - RC.recordReload(Reg, RegToSlotIdx[Reg], EHPad); + if (EHPad && RC.tryRecordReload(Reg, RegToSlotIdx[Reg], EHPad)) { auto EHPadInsertPoint = EHPad->SkipPHIsLabelsAndDebug(EHPad->begin(), Reg); insertReloadBefore(Reg, EHPadInsertPoint, EHPad);