[llvm-dev] Computing block profile weights

Jonas Wagner via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 6 06:19:32 PST 2016


Hello,

I've implemented my idea; a patch is attached. My code computes block
weights as follows:

    w = f[bb] / sum(f[b] for b in func) * sum(s[b] for b in func)

Where `f` is the frequency of a basic block (as computed by
BlockFrequencyInfo), `func` is the function that contains `bb`, and `s` is
the number of profiling samples in a block.

Previously, the computation was done as follows:

    w = f[bb] / f[entry] * s[entry]

Where `entry` is the entry block of the function containing `bb`.

At first glance, block weights look more stable. There are fewer cases
where weights are zero, because there is a sufficient number of samples in
all functions of interest. There are also fewer cases where block weights
are unrealistically high, because the weight of a block is now limited to
the total number of samples in the function.

Questions to the community:

- What do you think about this method of computing block weights?
- There are some cases where I'm unsure how this method behaves, e.g., with
inlining. Thoughts about this are welcome.
- (since this is the first time I'm upstreaming a change to LLVM) What
would it take to get this into LLVM?

Best,
Jonas


On Fri, Dec 2, 2016 at 10:43 AM Jonas Wagner <jonas.wagner at epfl.ch> wrote:

An addendum to fix a mistake in terminology:

2) Compute a block's weight as `function_samples * block_weight /
sum_of_block_weights_in_function`


This should be `function_samples * block_frequency /
sum_of_block_frequencies_in_function`

Cheers,
Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161206/bc05776a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Use-profile-samples-to-compute-block-weight.patch
Type: text/x-patch
Size: 37436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161206/bc05776a/attachment.bin>


More information about the llvm-dev mailing list