[CSSPGO] Track and use context-sensitive post-optimization function size to drive...
authorWenlei He <aktoon@gmail.com>
Tue, 17 Aug 2021 01:29:07 +0000 (18:29 -0700)
committerWenlei He <aktoon@gmail.com>
Thu, 19 Aug 2021 05:50:57 +0000 (22:50 -0700)
commiteca03d27684d076b960bac280ef6e4fa37fd8bbd
treea38869b24dbb7f92e84f3cb0e9e9220c1b45599b
parentf5d5f17d3ad455de2fbb9448acea66cbc09561c5
[CSSPGO] Track and use context-sensitive post-optimization function size to drive global pre-inliner in llvm-profgen

This change enables llvm-profgen to use accurate context-sensitive post-optimization function byte size as a cost proxy to drive global preinline decisions.

To do this, BinarySizeContextTracker is introduced to track function byte size under different inline context during disassembling. In preinliner, we can not query context byte size under switch `context-cost-for-preinliner`. The tracker uses a reverse trie to keep size of functions under different context (callee as parent, caller as child), and it can give best/longest possible matching context size for given input context.

The new size cost is off by default. There're a few TODOs that needs to addressed: 1) avoid dangling string from `Offset2LocStackMap`, which will be addressed in split context work; 2) using inlinee's entry probe to make sure we have correct zero size for inlinee that's completely optimized away after inlining. Some tuning is also needed.

Differential Revision: https://reviews.llvm.org/D108180
llvm/include/llvm/ProfileData/SampleProf.h
llvm/include/llvm/Transforms/IPO/SampleContextTracker.h
llvm/lib/Transforms/IPO/SampleContextTracker.cpp
llvm/test/tools/llvm-profgen/Inputs/cs-preinline-cost.perfbin [new file with mode: 0755]
llvm/test/tools/llvm-profgen/Inputs/cs-preinline-cost.perfscript [new file with mode: 0644]
llvm/test/tools/llvm-profgen/cs-preinline-cost.test [new file with mode: 0644]
llvm/tools/llvm-profgen/CSPreInliner.cpp
llvm/tools/llvm-profgen/CSPreInliner.h
llvm/tools/llvm-profgen/ProfileGenerator.cpp
llvm/tools/llvm-profgen/ProfiledBinary.cpp
llvm/tools/llvm-profgen/ProfiledBinary.h