llvm-project/llvm/tools/llvm-profgen
wlei 7e86b13c63 [CSSPGO][llvm-profgen] Reimplement SampleContextTracker using context trie
This is the followup patch to https://reviews.llvm.org/D125246 for the `SampleContextTracker` part. Before the promotion and merging of the context is based on the SampleContext(the array of frame), this causes a lot of cost to the memory. This patch detaches the tracker from using the array ref instead to use the context trie itself. This can save a lot of memory usage and benefit both the compiler's CS inliner and llvm-profgen's pre-inliner.

One structure needs to be specially treated is the `FuncToCtxtProfiles`, this is used to get all the functionSamples for one function to do the merging and promoting. Before it search each functions' context and traverse the trie to get the node of the context. Now we don't have the context inside the profile, instead we directly use an auxiliary map `ProfileToNodeMap` for profile , it initialize to create the FunctionSamples to TrieNode relations and keep updating it during promoting and merging the node.

Moreover, I was expecting the results before and after remain the same, but I found that the order of FuncToCtxtProfiles matter and affect the results. This can happen on recursive context case, but the difference should be small. Now we don't have the context, so I just used a vector for the order, the result is still deterministic.

Measured on one huge size(12GB) profile from one of our internal service. The profile similarity difference is 99.999%, and the running time is improved by 3X(debug mode) and the memory is reduced from 170GB to 90GB.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D127031
2022-06-27 23:22:21 -07:00
..
CMakeLists.txt [llvm-profgen] Switch to DWARF-based symbol and ranges 2021-10-29 09:59:12 -07:00
CSPreInliner.cpp [CSSPGO][llvm-profgen] Reimplement SampleContextTracker using context trie 2022-06-27 23:22:21 -07:00
CSPreInliner.h [CSSPGO][llvm-profgen] Reimplement SampleContextTracker using context trie 2022-06-27 23:22:21 -07:00
CallContext.h [CSSPGO] Rename the field of SampleContextFrame 2021-10-04 19:06:59 -07:00
ErrorHandling.h [llvm-profgen] Fix bug of setting function entry 2021-11-12 12:18:43 -08:00
PerfReader.cpp Replace to_hexString by touhexstr [NFC] 2022-06-16 17:29:50 +02:00
PerfReader.h [llvm-profgen] Filter out oversized LBR ranges. 2022-05-12 10:58:50 -07:00
ProfileGenerator.cpp [CSSPGO][llvm-profgen] Reimplement SampleContextTracker using context trie 2022-06-27 23:22:21 -07:00
ProfileGenerator.h [CSSPGO][llvm-profgen] Reimplement computeSummaryAndThreshold using context trie 2022-06-27 23:22:21 -07:00
ProfiledBinary.cpp [CSSPGO][llvm-profgen] Reimplement SampleContextTracker using context trie 2022-06-27 23:22:21 -07:00
ProfiledBinary.h [CSSPGO][llvm-profgen] Reimplement SampleContextTracker using context trie 2022-06-27 23:22:21 -07:00
llvm-profgen.cpp [CSSPGO][llvm-profgen] Reimplement computeSummaryAndThreshold using context trie 2022-06-27 23:22:21 -07:00