OSDN Git Service

[CSSPGO][llvm-profgen] Compress recursive cycles in calling context
authorwlei <wlei@fb.com>
Fri, 29 Jan 2021 23:00:08 +0000 (15:00 -0800)
committerTom Stellard <tstellar@redhat.com>
Sat, 20 Feb 2021 05:21:11 +0000 (21:21 -0800)
commit6209b0756d5df805f6279d3dadc8d2ba8648c3eb
tree266db450d346f3aa66e530afb4749004f1981cd6
parent78b35e278a9f62c2a6cfe3c974155a7e9bb60361
[CSSPGO][llvm-profgen] Compress recursive cycles in calling context

This change compresses the context string by removing cycles due to recursive function for CS profile generation. Removing recursion cycles is a way to normalize the calling context which will be better for the sample aggregation and also make the context promoting deterministic.
Specifically for implementation, we recognize adjacent repeated frames as cycles and deduplicated them through multiple round of iteration.
For example:
Considering a input context string stack:
[“a”, “a”, “b”, “c”, “a”, “b”, “c”, “b”, “c”, “d”]
For first iteration,, it removed all adjacent repeated frames of size 1:
[“a”, “b”, “c”, “a”, “b”, “c”, “b”, “c”, “d”]
For second iteration, it removed all adjacent repeated frames of size 2:
[“a”, “b”, “c”, “a”, “b”, “c”, “d”]
So in the end, we get compressed output:
[“a”, “b”, “c”, “d”]

Compression will be called in two place: one for sample's context key right after unwinding, one is for the eventual context string id in the ProfileGenerator.
Added a switch `compress-recursion` to control the size of duplicated frames, default -1 means no size limit.
Added unit tests and regression test for this.

Differential Revision: https://reviews.llvm.org/D93556
16 files changed:
llvm/test/tools/llvm-profgen/Inputs/recursion-compression-noprobe.perfbin [new file with mode: 0755]
llvm/test/tools/llvm-profgen/Inputs/recursion-compression-noprobe.perfscript [new file with mode: 0644]
llvm/test/tools/llvm-profgen/Inputs/recursion-compression-pseudoprobe.perfbin [new file with mode: 0755]
llvm/test/tools/llvm-profgen/Inputs/recursion-compression-pseudoprobe.perfscript [new file with mode: 0644]
llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test [new file with mode: 0644]
llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test [new file with mode: 0644]
llvm/tools/llvm-profgen/PerfReader.cpp
llvm/tools/llvm-profgen/ProfileGenerator.cpp
llvm/tools/llvm-profgen/ProfileGenerator.h
llvm/tools/llvm-profgen/ProfiledBinary.cpp
llvm/tools/llvm-profgen/ProfiledBinary.h
llvm/tools/llvm-profgen/PseudoProbe.cpp
llvm/tools/llvm-profgen/PseudoProbe.h
llvm/unittests/tools/CMakeLists.txt
llvm/unittests/tools/llvm-profgen/CMakeLists.txt [new file with mode: 0644]
llvm/unittests/tools/llvm-profgen/ContextCompressionTest.cpp [new file with mode: 0644]