Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

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

@kazutakahirata kazutakahirata requested a review from htyu September 9, 2024 01:59
@kazutakahirata kazutakahirata merged commit ab95ed5 into llvm:main Sep 9, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_ProfiledCallGraph branch September 9, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants