On 12/16/2010 6:25 AM, David Gilbert wrote:
If Profile Guiding could spot that a particular callsite to say strlen() was often associated with strings of at least 'n' characters we could call a different implementation.
I don't believe this is possible current profile-guided optimization, but certainly it could be done.
Ideally, we would avoid hard-coding something about strlen into the compiler.
Instead, something like this:
* Have the compiler expose an API for recording information about the value of arguments to a function when profiling. For integer arguments, this might be the minimum, maximum, and average. For pointers, NULL vs. non-NULL. Etc.
* Plumb this through the profiler and analysis tools.
* Provide a plug-in that allows the user to instrument particular functions (e.g., strlen) by providing profiling rules:
- instrument length argument to strlen at all callsites - if length < 8: replace with call to strlen_short
This is obviously more work than a special-purpose hack for strlen, but this is the sort of thing where exposing the rules outside of the compiler proper would be very helpful because the right answers are going to change depending on the application and on the core.