[all-commits] [llvm/llvm-project] b9db70: [CSSPGO] Split context string to deduplicate funct...

Hongtao Yu via All-commits all-commits at lists.llvm.org
Mon Aug 30 20:10:06 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b9db70369b7799887b817e13109801795e4d70fc
      https://github.com/llvm/llvm-project/commit/b9db70369b7799887b817e13109801795e4d70fc
  Author: Hongtao Yu <hoy at fb.com>
  Date:   2021-08-30 (Mon, 30 Aug 2021)

  Changed paths:
    M llvm/include/llvm/MC/MCPseudoProbe.h
    M llvm/include/llvm/ProfileData/ProfileCommon.h
    M llvm/include/llvm/ProfileData/SampleProf.h
    M llvm/include/llvm/ProfileData/SampleProfReader.h
    M llvm/include/llvm/ProfileData/SampleProfWriter.h
    M llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
    M llvm/include/llvm/Transforms/IPO/SampleContextTracker.h
    M llvm/lib/MC/MCPseudoProbe.cpp
    M llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
    M llvm/lib/ProfileData/SampleProf.cpp
    M llvm/lib/ProfileData/SampleProfReader.cpp
    M llvm/lib/ProfileData/SampleProfWriter.cpp
    M llvm/lib/Transforms/IPO/SampleContextTracker.cpp
    R llvm/test/Transforms/SampleProfile/Inputs/csspgo-import-list.prof.extbin
    M llvm/test/Transforms/SampleProfile/csspgo-import-list.ll
    M llvm/test/Transforms/SampleProfile/profile-context-tracker-debug.ll
    M llvm/test/tools/llvm-profdata/Inputs/cs-sample.proftext
    M llvm/test/tools/llvm-profgen/cs-interrupt.test
    M llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test
    M llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test
    M llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test
    M llvm/tools/llvm-profdata/llvm-profdata.cpp
    M llvm/tools/llvm-profgen/CSPreInliner.cpp
    M llvm/tools/llvm-profgen/CSPreInliner.h
    M llvm/tools/llvm-profgen/CallContext.h
    M llvm/tools/llvm-profgen/PerfReader.cpp
    M llvm/tools/llvm-profgen/PerfReader.h
    M llvm/tools/llvm-profgen/ProfileGenerator.cpp
    M llvm/tools/llvm-profgen/ProfileGenerator.h
    M llvm/tools/llvm-profgen/ProfiledBinary.cpp
    M llvm/tools/llvm-profgen/ProfiledBinary.h
    M llvm/unittests/ProfileData/SampleProfTest.cpp

  Log Message:
  -----------
  [CSSPGO] Split context string to deduplicate function name used in the context.

Currently context strings contain a lot of duplicated function names and that significantly increase the profile size. This change split the context into a series of {name, offset, discriminator} tuples so function names used in the context can be replaced by the index into the name table and that significantly reduce the size consumed by context.

A follow-up improvement made in the compiler and profiling tools is to avoid reconstructing full context strings which is  time- and memory- consuming. Instead a context vector of `StringRef` is adopted to represent the full context in all scenarios. As a result, the previous prevalent profile map which was implemented as a `StringRef` is now engineered as an unordered map keyed by `SampleContext`. `SampleContext` is reshaped to using an `ArrayRef` to represent a full context for CS profile. For non-CS profile, it falls back to use `StringRef` to represent a contextless function name. Both the `ArrayRef` and `StringRef` objects are underpinned by real array and string objects that are stored in producer buffers. For compiler, they are maintained by the sample reader. For llvm-profgen, they are maintained in `ProfiledBinary` and `ProfileGenerator`. Full context strings can be generated only in those cases of debugging and printing.

When it comes to profile format, nothing has changed to the text format, though internally CS context is implemented as a vector. Extbinary format is only changed for CS profile, with an additional `SecCSNameTable` section which stores all full contexts logically in the form of `vector<int>`, which each element as an offset points to `SecNameTable`. All occurrences of contexts elsewhere are redirected to using the offset of `SecCSNameTable`.

Testing
This is no-diff change in terms of code quality and profile content (for text profile).

For our internal large service (aka ads), the profile generation is cut to half, with a 20x smaller string-based extbinary format generated.

The compile time of ads is dropped by 25%.

Differential Revision: https://reviews.llvm.org/D107299




More information about the All-commits mailing list