[llvm] 3874620 - [CodeGen] Avoid repeated hash lookups (NFC) (#125025)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 30 17:58:53 PST 2025


Author: Kazu Hirata
Date: 2025-01-30T17:58:51-08:00
New Revision: 3874620ef7477c47abb07b7b68c410c1a9ed1b53

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

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

Added: 
    

Modified: 
    llvm/lib/CodeGen/StackColoring.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index b77b8dbdd6e595..27c65d234a618c 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -914,10 +914,10 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
     if (!VI.Var || !VI.inStackSlot())
       continue;
     int Slot = VI.getStackSlot();
-    if (SlotRemap.count(Slot)) {
+    if (auto It = SlotRemap.find(Slot); It != SlotRemap.end()) {
       LLVM_DEBUG(dbgs() << "Remapping debug info for ["
                         << cast<DILocalVariable>(VI.Var)->getName() << "].\n");
-      VI.updateStackSlot(SlotRemap[Slot]);
+      VI.updateStackSlot(It->second);
       FixedDbg++;
     }
   }
@@ -1004,10 +1004,11 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
         if (!AI)
           continue;
 
-        if (!Allocas.count(AI))
+        auto It = Allocas.find(AI);
+        if (It == Allocas.end())
           continue;
 
-        MMO->setValue(Allocas[AI]);
+        MMO->setValue(It->second);
         FixedMemOp++;
       }
 
@@ -1173,8 +1174,8 @@ void StackColoring::expungeSlotMap(DenseMap<int, int> &SlotRemap,
   // Expunge slot remap map.
   for (unsigned i=0; i < NumSlots; ++i) {
     // If we are remapping i
-    if (SlotRemap.count(i)) {
-      int Target = SlotRemap[i];
+    if (auto It = SlotRemap.find(i); It != SlotRemap.end()) {
+      int Target = It->second;
       // As long as our target is mapped to something else, follow it.
       while (SlotRemap.count(Target)) {
         Target = SlotRemap[Target];


        


More information about the llvm-commits mailing list