From f3b27d5e711c5ee899cc1a70d3cabe9f68bc1220 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 1 Mar 2025 08:19:26 -0800 Subject: [PATCH] [IPO] Avoid repeated hash lookups (NFC) --- llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h b/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h index 3e7cc74fcf23b..9ee92c38ffa23 100644 --- a/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h +++ b/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h @@ -135,14 +135,15 @@ class ProfiledCallGraph { ProfiledCallGraphNode *getEntryNode() { return &Root; } void addProfiledFunction(FunctionId Name) { - if (!ProfiledFunctions.count(Name)) { + auto [It, Inserted] = ProfiledFunctions.try_emplace(Name); + if (Inserted) { // Link to synthetic root to make sure every node is reachable // from root. This does not affect SCC order. // Store the pointer of the node because the map can be rehashed. auto &Node = ProfiledCallGraphNodeList.emplace_back(ProfiledCallGraphNode(Name)); - ProfiledFunctions[Name] = &Node; - Root.Edges.emplace(&Root, ProfiledFunctions[Name], 0); + It->second = &Node; + Root.Edges.emplace(&Root, It->second, 0); } }