[LLVMdev] Is there a "callback optimization"?

Kenneth Uildriks kennethuil at gmail.com
Fri Jun 4 11:47:32 PDT 2010

On Fri, Jun 4, 2010 at 1:35 PM, Eugene Toder <eltoder at gmail.com> wrote:
> It should be relatively simple to write a pass that turns each call
> that has constant argument(s) into a call to specialized version of
> the callee. To devirtualize C++ calls it needs to be smarter, since
> the argument is not a constant, but a pointer to a struct that points
> to a constant. However, the trick here is
> 1) Knowing when to perform specialization. If the call was not inlined
> the function is probably big. Getting this wrong will generate *a lot*
> of code for very small (if not negative) speed gain.
> 2) Sharing of specializations from different call sites that have the
> same constants.
> Getting 1) right is crucial but hard. Easy cases are already taken by
> inline and dead argument elimination. If some good profiling
> information is available it can be used for speed/space trade off
> estimation (specialize calls from hot code).

As the number of callsites using the same constant grows, inlining
gets more expensive while specializing does not - the cost of
specializing only grows with the number of unique constants combos
specialized.  So cases where you'd want to specialize but not inline
shouldn't be all that uncommon, and different cost calculations are
needed to set the threshold.

I didn't see the partial specialization pass in the docs, but I'll
take a look at it now.

More information about the llvm-dev mailing list