<div dir="ltr"><p dir="ltr">Look at the LazyCallGraph pass? This is going to be the basis of the new pass manager, and I designed it specifically to help deal with these kinds of issues. I'd be interested if it just directly addresses the call graph issue without the need for any special handling. If not, I'd like to understand why not.</p><p>I'll think some about the inliner side of this...</p>
<br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 16, 2015, 19:24 Sanjoy Das <<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've been looking at inlining invokes / calls done through statepoints<br>
and I want to have a design discussion before I sink too much time<br>
into something I'll have to throw away. I'm not actively working on<br>
adding inlining support to patchpoints, but I suspect these issues are<br>
applicable towards teaching LLVM to inline through patchpoints as<br>
well.<br>
<br>
<br>
There are two distinct problems to solve before LLVM can inline<br>
through statepoints:<br>
<br>
# Managing data flow for the extra metadata args.<br>
<br>
LLVM needs some logic to "transfer" the extra live values attached to<br>
a statepoint/patchpoint into the body of the inlinee somehow. How<br>
this is handled depends on the semantics of the live values (something<br>
the frontend knows). There needs to be a clean way for the frontend<br>
to communicate this information to LLVM, or we need to devise a<br>
convention that is sensible for the kinds of frontends we wish to<br>
support. Initially I plan to sidestep this problem by only inlining<br>
through statepoints have *no* extra live values / gc pointers.<br>
<br>
<br>
# Managing the call graph<br>
<br>
This is the problem we need to solve first. Currently LLVM views the<br>
a statepoint or patchpoint call as<br>
<br>
1. A call to an intrisic. This does not add an edge to the call<br>
graph (not even to the dedicated external node).<br>
<br>
2. An escaping use of the callee.<br>
<br>
IIUC, (2) is (conservatively) imprecise and (1) is incorrect. (1)<br>
makes LLVM believe that a function that calls @f via a statepoint does<br>
not call @f at all. (2) makes LLVM believe that @f is visible<br>
externally, even if it has internal linkage.<br>
<br>
Given this starting point, I can think of three ways to model<br>
statepoint's (and patchpoint's) control flow semantics within a call<br>
graph:<br>
<br>
1. Model calls to statepoint, patchpoint and stackmap intrinsics as<br>
calling the external node. Teach the inliner pass to<br>
"devirtualize" calls through statepoints when posssible, except<br>
that the "devirtualization" is only a facade (i.e. we don't<br>
mutate the IR to change the statepoint to a direct call). We add<br>
some abstraction to the inlining utility functions to inline<br>
through something more general than a CallSite.<br>
<br>
2. Introduce a new abstraction InlineSite (bikeshedding on the name<br>
is welcome). InlineSite sits on top of a CallSite and knows how<br>
to extract the semantic call out of a statepoint or a patchpoint<br>
(similar to the llvm::Statepoint class). The inliner and the<br>
call graph analysis works on top of this InlineSite abstraction<br>
instead of the CallSite abstraction.<br>
<br>
3. Change all the places that matter (CallGraph, CallGraphSCCPass<br>
etc.) from<br>
<br>
if (CallSite CS = ...)<br>
<br>
to<br>
<br>
if (Statepoint SP = ...)<br>
...<br>
else if (CallSite CS = ...)<br>
<br>
or something equivalent to this.<br>
<br>
Personally, I'd prefer going with (1) if it is viable, and (2) if not.<br>
<br>
What do you think?<br>
<br>
-- Sanjoy<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div></div>