[llvm] b044350 - [CodeGen] Avoid repeated hash lookups (NFC) (#128126)

via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 21 11:07:10 PST 2025


Author: Kazu Hirata
Date: 2025-02-21T11:07:07-08:00
New Revision: b0443507014273bb95eb90af0f9859a8fa3111c9

URL: https://github.com/llvm/llvm-project/commit/b0443507014273bb95eb90af0f9859a8fa3111c9
DIFF: https://github.com/llvm/llvm-project/commit/b0443507014273bb95eb90af0f9859a8fa3111c9.diff

LOG: [CodeGen] Avoid repeated hash lookups (NFC) (#128126)

This patch eliminates repeated hash lookups at three levels:

- RegToSlotIdx  of DenseMap
- Reloads       of DenseMap
- Reloads[MBB]  of SmallSet

Added: 
    

Modified: 
    llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp

Removed: 
    


################################################################################
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);


        


More information about the llvm-commits mailing list