[llvm] [IPO] Avoid repeated hash lookups (NFC) (PR #107796)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 18:56:37 PDT 2024


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

None

>From c195a34191899aece0de4ed9ad5b75fb746cf244 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 8 Sep 2024 09:58:10 -0700
Subject: [PATCH] [IPO] Avoid repeated hash lookups (NFC)

---
 llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h b/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
index 8bf902fc8d2841..3e7cc74fcf23b6 100644
--- a/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
+++ b/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
@@ -156,10 +156,8 @@ class ProfiledCallGraph {
     ProfiledCallGraphEdge Edge(ProfiledFunctions[CallerName],
                                CalleeIt->second, Weight);
     auto &Edges = ProfiledFunctions[CallerName]->Edges;
-    auto EdgeIt = Edges.find(Edge);
-    if (EdgeIt == Edges.end()) {
-      Edges.insert(Edge);
-    } else {
+    auto [EdgeIt, Inserted] = Edges.insert(Edge);
+    if (!Inserted) {
       // Accumulate weight to the existing edge.
       Edge.Weight += EdgeIt->Weight;
       Edges.erase(EdgeIt);



More information about the llvm-commits mailing list