[llvm] [llvm][AsmPrinter] Add direct calls to callgraph section (PR #155706)

Prabhu Rajasekaran via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 17 18:46:24 PDT 2025


Prabhuk wrote:

> > > > so, you emit a label at every call site, right? and then you write out the address of the label w/ each callee symbol?
> > > > So if I have a hundred calls to foo in my function, I get 100 entries? Am I understanding that right?
> > > 
> > > 
> > > Yes. That is correct.
> > 
> > 
> > That seems very unfortunate. I'm not sure we should really be doing that. A call graph doesn't exactly care about where a call is coming from, and AFAIK there are no plans to ever make use of that kind of information. What you record in the section should be the set of things that are called, and there should be no duplicates. As it is, I expect this section to be large, so I'd prefer we don't bloat it in the first place. Especially since IO is rather costly.
> 
> The change to record the unique callees only and not recording the callsite addresses sounds sensible to be. This brings up another question which I hadn't thought of originally. If all the direct calls to a given function is removed from a function, we do not currently have a way of pruning it out from our callgraph info. We can address this partially by first swapping how we store direct call info. Instead of storing all callees of a given function in per-function callgraph info, we can store all callers of a given function. If a function is completely GC'd it will help us drop those edges in a straightforward way. But the question still remains regarding how to prune a direct callee when all direct calls to it from a given function is removed but the callee is not garbage collected entirely.

I had some time to think about this and updated the patch. The current revision only maintains a unique list of direct callees for each function in the .callgraph section which addresses the original concern raised in the review. The other things I brought up about optimizations are not valid concerns as the codegen ASMPrinter pass is run after all the optimizations are completed. I believe this design works correctly. PTAL.

https://github.com/llvm/llvm-project/pull/155706


More information about the llvm-commits mailing list