[llvm] [LiveDebugValues] Avoid repeated hash lookups (NFC) (PR #109242)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 23:19:49 PDT 2024


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

None

>From 78141aaec1d00e2f0f49aa89bbe934fea9531b13 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 17 Sep 2024 00:28:10 -0700
Subject: [PATCH] [LiveDebugValues] Avoid repeated hash lookups (NFC)

---
 .../LiveDebugValues/InstrRefBasedImpl.h       | 22 +++++++------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
index d9851ad13eab24..5c095e79599f6a 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
@@ -484,22 +484,16 @@ class DbgOpIDMap {
 
 private:
   DbgOpID insertConstOp(MachineOperand &MO) {
-    auto ExistingIt = ConstOpToID.find(MO);
-    if (ExistingIt != ConstOpToID.end())
-      return ExistingIt->second;
-    DbgOpID ID(true, ConstOps.size());
-    ConstOpToID.insert(std::make_pair(MO, ID));
-    ConstOps.push_back(MO);
-    return ID;
+    auto [It, Inserted] = ConstOpToID.try_emplace(MO, true, ConstOps.size());
+    if (Inserted)
+      ConstOps.push_back(MO);
+    return It->second;
   }
   DbgOpID insertValueOp(ValueIDNum VID) {
-    auto ExistingIt = ValueOpToID.find(VID);
-    if (ExistingIt != ValueOpToID.end())
-      return ExistingIt->second;
-    DbgOpID ID(false, ValueOps.size());
-    ValueOpToID.insert(std::make_pair(VID, ID));
-    ValueOps.push_back(VID);
-    return ID;
+    auto [It, Inserted] = ValueOpToID.try_emplace(VID, false, ValueOps.size());
+    if (Inserted)
+      ValueOps.push_back(VID);
+    return It->second;
   }
 };
 



More information about the llvm-commits mailing list