On 4/7/20 2:01 PM, Erick Ochoa wrote:
Hello,
Can someone help me understand better GCC's profile driven instrumentation? I
know this can be a long topic, but I am not looking for a long discussion. I am
just trying to orient myself regarding GCC's FDO implementation.
Hello.
Sure.
1. I know that gcc uses an instrumentation based profiler. This instrumentation based profiler instruments binaries when the flag `-fprofile-use` is used.
Yes, one get instrumented binary with -fprofile-generate.
I also know that `gprof` is also a gnu profiler that can also generate
profiling information that can be consumed by gcc.
No, it's designed for a third-party consumers, where intrumented binary calls
mcount function at the
very beginning of each function. Also linux kernel uses that for various
reasons.
Does the profiler used when the flag `-fprofile-use` share some code with
`gprof`? Are they the same?
No.
2. I know that the profiler used with `-fprofile-use` can generate basic block
frequencies and branch probabilities. Does it also profile the call graph?
Yes, function entry block execution count is equal to number of calls of the
function. Similarly for calls, we
known how many times each cgraph edge is executed.
I am specifically interested in callsite edge counters with a context
sensitivity of k = 1. This is to say that if I have the following method:
```
int guard(void* (func_ptr)(void))
{
if (func_ptr == some_function)
{
func_ptr(); // call site 1
} else {
func_ptr(); // call site 2
}
}
```
profiling information should be enough to say the target of the call site 1 is
always some_function and the target of the call site 2 can be any function
which was stored in func_ptr that is not some_function.
Yes, that's exactly what speculative devirtualization for C++ does. How do you
want to leverage
information that func_ptr != some_function?
3. I know that there are other profilers that are able to generate data that can be consumed by GCC. In particular there is AutoFDO.
Yes, but the infrastructure is basically broken right now. It was developed by
Google people who moved to Clang right now.
According to the options available on GCC, this is still an option available.
Are there any other profilers that you know about that can generate profile
data used by GCC?
No.
Martin