[llvm] [ExecutionEngine] Avoid repeated hash lookups (NFC) (PR #130239)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 6 20:50:13 PST 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/130239

None

>From e6667b64e8fc1822c84197e8f6d46ab0374afe62 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 6 Mar 2025 09:01:19 -0800
Subject: [PATCH] [ExecutionEngine] Avoid repeated hash lookups (NFC)

---
 .../RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h            | 6 +++---
 .../RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h             | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
index f54ed0eae0076..3ca6309874de5 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
@@ -121,13 +121,13 @@ class RuntimeDyldCOFFAArch64 : public RuntimeDyldCOFF {
     OriginalRelValueRef.Addend = Addend;
     OriginalRelValueRef.SymbolName = TargetName.data();
 
-    auto Stub = Stubs.find(OriginalRelValueRef);
-    if (Stub == Stubs.end()) {
+    auto [Stub, Inserted] = Stubs.try_emplace(OriginalRelValueRef);
+    if (Inserted) {
       LLVM_DEBUG(dbgs() << " Create a new stub function for "
                         << TargetName.data() << "\n");
 
       StubOffset = Section.getStubOffset();
-      Stubs[OriginalRelValueRef] = StubOffset;
+      Stub->second = StubOffset;
       createStubFunction(Section.getAddressWithOffset(StubOffset));
       Section.advanceStubOffset(getMaxStubSize());
     } else {
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
index 984a8d765c845..2a45535f68fa0 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
@@ -160,13 +160,13 @@ class RuntimeDyldCOFFX86_64 : public RuntimeDyldCOFF {
     OriginalRelValueRef.Addend = Addend;
     OriginalRelValueRef.SymbolName = TargetName.data();
 
-    auto Stub = Stubs.find(OriginalRelValueRef);
-    if (Stub == Stubs.end()) {
+    auto [Stub, Inserted] = Stubs.try_emplace(OriginalRelValueRef);
+    if (Inserted) {
       LLVM_DEBUG(dbgs() << " Create a new stub function for "
                         << TargetName.data() << "\n");
 
       StubOffset = Section.getStubOffset();
-      Stubs[OriginalRelValueRef] = StubOffset;
+      Stub->second = StubOffset;
       createStubFunction(Section.getAddressWithOffset(StubOffset));
       Section.advanceStubOffset(getMaxStubSize());
     } else {



More information about the llvm-commits mailing list