[PATCH] D22118: Implement callsite-hotness based inline cost for Sample-based PGO

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 16:07:48 PDT 2016


danielcdh created this revision.
danielcdh added reviewers: davidxl, eraman, dnovillo.
danielcdh added a subscriber: llvm-commits.

For sample-based PGO, using BFI to calculate callsite count is sometime not accurate. This is because with sampling based approach, if a callsite resides in a hot loop deeply nested in a bunch of cold branches, the callsite's BFI frequency would be inaccurately calculated due to lack of samples in the cold branch.

E.g.

if (A1 && A2 && A3 && ..... && A10) {
  for (i=0; i < 100000000; i++) {
    callsite();
  }
}

Assume that A1 to A100 are all 100% taken, and callsite has 1000 samples and thus is considerred hot. Because the loop's trip count is huge, it's normal that all branches outside the loop has no sample at all. As a result, we can only use static branch probability to derive the the frequency of the loop header. Assuming that static heuristic thinks each branch is 50% taken, then the count calculated from BFI will be 1/(2^10) of the actual value.

In order to get more accurate callsite count, we directly annotate the weight on the call instruction, and directly use it when checking callsite hotness.

Note that this mechanism can also be shared by instrumentation based callsite hotness analysis. The side benefit is that it breaks the dependency from Inliner to BFI as call count is embedded in the IR.

http://reviews.llvm.org/D22118

Files:
  include/llvm/IR/Instruction.h
  lib/Analysis/InlineCost.cpp
  lib/IR/Metadata.cpp
  lib/Transforms/IPO/SampleProfile.cpp
  test/Transforms/Inline/inline-hot-callsite.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22118.63154.patch
Type: text/x-patch
Size: 5271 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160707/3b84c145/attachment.bin>


More information about the llvm-commits mailing list