From 82956de05f9d63e5fbc170702649e5d978b51b80 Mon Sep 17 00:00:00 2001 From: Wei Mi Date: Mon, 3 May 2021 22:55:53 -0700 Subject: [PATCH] [SampleFDO] Fix a bug when appending function symbol into the Callees set of Root node in ProfiledCallGraph. In ProfiledCallGraph::addProfiledFunction, to add a function symbol into the ProfiledCallGraph, currently an uninitialized ProfiledCallGraphNode node is created by ProfiledFunctions[Name] and inserted into Callees set of Root node before the node is initialized. The Callees set use ProfiledCallGraphNodeComparer as its comparator so the uninitialized ProfiledCallGraphNode may fail to be inserted into Callees set if it happens to contain a name in memory which has been inserted into the Callees set before. The problem will prevent some function symbols from being annotated with profiles and cause performance regression. The patch fixes the problem. Differential Revision: https://reviews.llvm.org/D101815 --- llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h b/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h index 02279d8..9214322 100644 --- a/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h +++ b/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h @@ -87,8 +87,8 @@ public: if (!ProfiledFunctions.count(Name)) { // Link to synthetic root to make sure every node is reachable // from root. This does not affect SCC order. - Root.Callees.insert(&ProfiledFunctions[Name]); ProfiledFunctions[Name] = ProfiledCallGraphNode(Name); + Root.Callees.insert(&ProfiledFunctions[Name]); } } -- 2.7.4