[PATCH] D101815: [SampleFDO] Fix a bug when appending function symbol into the Callees set of Root node in ProfiledCallGraph.

Wei Mi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 3 23:15:05 PDT 2021


wmi created this revision.
wmi added reviewers: davidxl, wenlei, hoy.
wmi requested review of this revision.
Herald added a project: LLVM.

In ProfiledCallGraph::addProfiledFunction, to add a function symbol into the ProfiledCallGraph, currently an uninitialized ProfiledCallGraphNode node is created 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 the uninitialized memory may happen to contain a name 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101815

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


Index: llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
===================================================================
--- llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
+++ llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
@@ -87,8 +87,8 @@
     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]);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101815.342651.patch
Type: text/x-patch
Size: 610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210504/9ddb8ac4/attachment.bin>


More information about the llvm-commits mailing list