[llvm] 82956de - [SampleFDO] Fix a bug when appending function symbol into the Callees set of

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Tue May 4 10:06:25 PDT 2021


Author: Wei Mi
Date: 2021-05-04T10:05:59-07:00
New Revision: 82956de05f9d63e5fbc170702649e5d978b51b80

URL: https://github.com/llvm/llvm-project/commit/82956de05f9d63e5fbc170702649e5d978b51b80
DIFF: https://github.com/llvm/llvm-project/commit/82956de05f9d63e5fbc170702649e5d978b51b80.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h b/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
index 02279d8514738..921432282cb62 100644
--- a/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
+++ b/llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
@@ -87,8 +87,8 @@ 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.
-      Root.Callees.insert(&ProfiledFunctions[Name]);
       ProfiledFunctions[Name] = ProfiledCallGraphNode(Name);
+      Root.Callees.insert(&ProfiledFunctions[Name]);
     }
   }
 


        


More information about the llvm-commits mailing list