[llvm] 2d1634f - [ExecutionEngine] Avoid repeated map lookups (NFC) (#130461)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 9 00:47:46 PST 2025


Author: Kazu Hirata
Date: 2025-03-09T00:47:42-08:00
New Revision: 2d1634fab716f3200990e3e5d7a102466509f202

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

LOG: [ExecutionEngine] Avoid repeated map lookups (NFC) (#130461)

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index 06fc2eb32f3bd..def117448ab6a 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -1680,16 +1680,16 @@ RuntimeDyldELF::processRelocationRef(
       SectionEntry &Section = Sections[SectionID];
 
       // Look for an existing stub.
-      StubMap::const_iterator i = Stubs.find(Value);
-      if (i != Stubs.end()) {
+      auto [It, Inserted] = Stubs.try_emplace(Value);
+      if (!Inserted) {
         resolveRelocation(Section, Offset,
-                          Section.getLoadAddressWithOffset(i->second), RelType,
+                          Section.getLoadAddressWithOffset(It->second), RelType,
                           0);
         LLVM_DEBUG(dbgs() << " Stub function found\n");
       } else {
         // Create a new stub function.
         LLVM_DEBUG(dbgs() << " Create a new stub function\n");
-        Stubs[Value] = Section.getStubOffset();
+        It->second = Section.getStubOffset();
         uint8_t *StubTargetAddr = createStubFunction(
             Section.getAddressWithOffset(Section.getStubOffset()));
         RelocationEntry RE(SectionID, StubTargetAddr - Section.getAddress(),
@@ -1745,15 +1745,15 @@ RuntimeDyldELF::processRelocationRef(
       Value.Addend += Addend;
 
       //  Look up for existing stub.
-      StubMap::const_iterator i = Stubs.find(Value);
-      if (i != Stubs.end()) {
-        RelocationEntry RE(SectionID, Offset, RelType, i->second);
+      auto [It, Inserted] = Stubs.try_emplace(Value);
+      if (!Inserted) {
+        RelocationEntry RE(SectionID, Offset, RelType, It->second);
         addRelocationForSection(RE, SectionID);
         LLVM_DEBUG(dbgs() << " Stub function found\n");
       } else {
         // Create a new stub function.
         LLVM_DEBUG(dbgs() << " Create a new stub function\n");
-        Stubs[Value] = Section.getStubOffset();
+        It->second = Section.getStubOffset();
 
         unsigned AbiVariant = Obj.getPlatformFlags();
 
@@ -1945,17 +1945,17 @@ RuntimeDyldELF::processRelocationRef(
           RangeOverflow) {
         // It is an external symbol (either Value.SymbolName is set, or
         // SymType is SymbolRef::ST_Unknown) or out of range.
-        StubMap::const_iterator i = Stubs.find(Value);
-        if (i != Stubs.end()) {
+        auto [It, Inserted] = Stubs.try_emplace(Value);
+        if (!Inserted) {
           // Symbol function stub already created, just relocate to it
           resolveRelocation(Section, Offset,
-                            Section.getLoadAddressWithOffset(i->second),
+                            Section.getLoadAddressWithOffset(It->second),
                             RelType, 0);
           LLVM_DEBUG(dbgs() << " Stub function found\n");
         } else {
           // Create a new stub function.
           LLVM_DEBUG(dbgs() << " Create a new stub function\n");
-          Stubs[Value] = Section.getStubOffset();
+          It->second = Section.getStubOffset();
           uint8_t *StubTargetAddr = createStubFunction(
               Section.getAddressWithOffset(Section.getStubOffset()),
               AbiVariant);
@@ -2127,10 +2127,10 @@ RuntimeDyldELF::processRelocationRef(
         // This is a call to an external function.
         // Look for an existing stub.
         SectionEntry *Section = &Sections[SectionID];
-        StubMap::const_iterator i = Stubs.find(Value);
+        auto [It, Inserted] = Stubs.try_emplace(Value);
         uintptr_t StubAddress;
-        if (i != Stubs.end()) {
-          StubAddress = uintptr_t(Section->getAddress()) + i->second;
+        if (!Inserted) {
+          StubAddress = uintptr_t(Section->getAddress()) + It->second;
           LLVM_DEBUG(dbgs() << " Stub function found\n");
         } else {
           // Create a new stub function (equivalent to a PLT entry).
@@ -2140,7 +2140,7 @@ RuntimeDyldELF::processRelocationRef(
           StubAddress = alignTo(BaseAddress + Section->getStubOffset(),
                                 getStubAlignment());
           unsigned StubOffset = StubAddress - BaseAddress;
-          Stubs[Value] = StubOffset;
+          It->second = StubOffset;
           createStubFunction((uint8_t *)StubAddress);
 
           // Bump our stub offset counter


        


More information about the llvm-commits mailing list