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

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 18:57:07 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/107796.diff


1 Files Affected:

- (modified) llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h (+2-4) 


``````````diff
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);

``````````

</details>


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


More information about the llvm-commits mailing list