Skip to content
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

[Sample Profile Loader] Fix potential invalidated reference #73181

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ class ProfiledCallGraph {
if (!ProfiledFunctions.count(Name)) {
// Link to synthetic root to make sure every node is reachable
// from root. This does not affect SCC order.
ProfiledFunctions[Name] = ProfiledCallGraphNode(Name);
Root.Edges.emplace(&Root, &ProfiledFunctions[Name], 0);
// 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);
}
}

Expand All @@ -152,9 +155,9 @@ class ProfiledCallGraph {
auto CalleeIt = ProfiledFunctions.find(CalleeName);
if (CalleeIt == ProfiledFunctions.end())
return;
ProfiledCallGraphEdge Edge(&ProfiledFunctions[CallerName],
&CalleeIt->second, Weight);
auto &Edges = ProfiledFunctions[CallerName].Edges;
ProfiledCallGraphEdge Edge(ProfiledFunctions[CallerName],
CalleeIt->second, Weight);
auto &Edges = ProfiledFunctions[CallerName]->Edges;
auto EdgeIt = Edges.find(Edge);
if (EdgeIt == Edges.end()) {
Edges.insert(Edge);
Expand Down Expand Up @@ -193,7 +196,7 @@ class ProfiledCallGraph {
return;

for (auto &Node : ProfiledFunctions) {
auto &Edges = Node.second.Edges;
auto &Edges = Node.second->Edges;
auto I = Edges.begin();
while (I != Edges.end()) {
if (I->Weight <= Threshold)
Expand All @@ -205,7 +208,9 @@ class ProfiledCallGraph {
}

ProfiledCallGraphNode Root;
HashKeyMap<std::unordered_map, FunctionId, ProfiledCallGraphNode>
// backing buffer for ProfiledCallGraphNodes.
std::list<ProfiledCallGraphNode> ProfiledCallGraphNodeList;
HashKeyMap<llvm::DenseMap, FunctionId, ProfiledCallGraphNode*>
ProfiledFunctions;
};

Expand Down