Depends on D36233
Add GraphTraits definitions to the FunctionSummary and ModuleSummaryIndex classes. These GraphTraits will be used to construct find SCC's in ThinLTO analysis passes.
Differential D36311
[ThinLTO] Add GraphTraits for FunctionSummaries ncharlie on Aug 4 2017, 7:58 AM. Authored by
Details
Depends on D36233 Add GraphTraits definitions to the FunctionSummary and ModuleSummaryIndex classes. These GraphTraits will be used to construct find SCC's in ThinLTO analysis passes.
Diff Detail Event TimelineComment Actions Since this patch depends on D36233, I'm diffing against it to show minimal changes.
Comment Actions Added GraphTraits for ModuleSummaryIndex
Comment Actions For some reason, the scc_iterator isn't visiting the whole graph, and only visits the children of the entryNode. How should I move across all SCCs in the Index? Comment Actions Ah, I think I realized what the entryNode should be: I should topologically sort the nodes in the ModuleSummaryIndex and take the first FunctionSummary. Right now the entry node is arbitrary. Comment Actions I don't think I can use a topological sort in this case since the FunctionSummary callgraph isn't necessarily a DAG, so if there's a cycle it would make the sort useless. Instead, I tried using the main function as the entry node and that worked. Any suggestions on a clean way of implementing this rather than hard coding a lookup for "main" in the Index? Comment Actions No callgraph is guaranteed to be a DAG, what's a DAG is the condensed graph, where you contract every node of a component to a single vertex.
I'm not sure you're always guaranteed to have the main function as entry point of your program. Comment Actions Right - how would you recommend finding the root node of the callgraph so I can return that in the getEntryNode for the GraphTraits for the ModuleSummaryIndex? Since right now, it's just arbitrarily finding a FunctionSummary in the Index. Comment Actions I tried implementing a search to find the root nodes in the Index callgraph. But there can be multiple root nodes in the callgraph and we can only return one node from GraphTraits<ModuleSummaryIndex *>::getEntry. Since I didn't know how to pick the correct root, I didn't go with that solution. Is there any information I can find in the Index that indicates the entry point? Comment Actions Looking at how the GraphTraits is implemented for the CFG, it returns a special "ExternalCallingNode", that is created to contain edges to all functions that may be called externally (e.g. external linkage or address taken). See CallGraph::addToCallGraph() in CallGraph.cpp. Perhaps you can create such a dummy node in the index, which has edges to all the root nodes, and return that as the entry node? Comment Actions Yeah, I think that'll work! I've been staring at the CallGraph::addToCallGraph() for the last few days but didn't think to apply the same idea of a dummy root node to the Index :P Thanks! Comment Actions Maybe add an scc dumper facility for the module summary graph, which creates an scc_iterator from the module summary and just dumps the nodes in each scc, that can be checked using a Lit based test
Comment Actions
I'll look into adding this.
Comment Actions Getting there, thanks!
Comment Actions This looks really good, just a few minor comments. But I do have a concern about the test and it not showing the multiple node SCCs that I would expect. Can you investigate?
Comment Actions Sorry - didn't realize this was ready for re-review! I had a question about the tests earlier (see below). The comment wasn't marked as done. Although I see now that the test has changed a bit - did you resolve this? I will take a look this morning.
Comment Actions Ah sorry - forgot to mark it. Yeah - it's corrected now. Updated the tests accordingly. Comment Actions Just minor comments left at this point, I noted a few places where you hadn't yet addressed my previous commenting nits, plus a question about paring down the new operators, and some suggestions for minorly beefing up the matching you are doing on the test lines.
Comment Actions Sorry, I missed these being updated. Will take another pass through but it looks like you have addressed my comments. Easwaran - can this be used to do the call graph walks you need for synthetic counts propagation? If not we need to figure out why, because I see you are going in a different direction in D42311. Comment Actions LGTM with a few suggestions below that don't require a re-review. Minor update needed to the ValueInfo comparisons due to a recent patch (see the comment I left there), and a few efficiency improvements. Go ahead and submit once those are fixed and tests pass and you've uploaded the new patch here for posterity.
Comment Actions It looks like D36850 got accidentally merged into this version of the patch -make sure to remove that.
Comment Actions Hi Charles, I was just chatting with Easwaran - he's using your patch and building on top of it for frequency propagation changes. Would you be able to address my last round of comments which are all minor and don't need a re-review, and commit this soon (say in the next week)? If not, let me know if you would like one of us to commit it (attributing it to you). (Easwaran says don't worry about his comment regarding the NodeRef for this patch.) Thanks! Comment Actions Thanks! Looks like the test accidentally got left out of the commit, so please commit that as a follow-on. |
Not needed in this patch?