[all-commits] [llvm/llvm-project] a212d8: [MemProf] Memprof profile matching and annotation

Teresa Johnson via All-commits all-commits at lists.llvm.org
Thu Sep 22 12:49:24 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a212d8da94d08e229aa8d65283e4b116310bba10
  Author: Teresa Johnson <tejohnson at google.com>
  Date:   2022-09-22 (Thu, 22 Sep 2022)

  Changed paths:
    M clang/lib/Frontend/CompilerInvocation.cpp
    A clang/test/CodeGen/Inputs/memprof.exe
    A clang/test/CodeGen/Inputs/memprof.memprofraw
    A clang/test/CodeGen/memprof.cpp
    M llvm/include/llvm/Analysis/MemoryBuiltins.h
    M llvm/include/llvm/ProfileData/InstrProfReader.h
    M llvm/lib/Analysis/MemoryBuiltins.cpp
    M llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
    A llvm/test/Transforms/PGOProfile/Inputs/memprof.exe
    A llvm/test/Transforms/PGOProfile/Inputs/memprof.memprofraw
    A llvm/test/Transforms/PGOProfile/Inputs/memprof_pgo.profraw
    A llvm/test/Transforms/PGOProfile/memprof.ll
    A llvm/test/Transforms/PGOProfile/memprofmissingfunc.ll

  Log Message:
  [MemProf] Memprof profile matching and annotation

Profile matching and IR annotation for memprof profiles.

See also related RFCs:
RFC: Sanitizer-based Heap Profiler [1]
RFC: A binary serialization format for MemProf [2]
RFC: IR metadata format for MemProf [3]*

* Note that the IR metadata format has changed from the RFC during
implementation, as described in the preceeding patch adding the basic
metadata and verification support.

The matching is performed during the normal PGO annotation phase, to
ensure that the inlines applied in the IR at that point are a subset
of the inlines in the profiled binary and thus reflected in the
profile's call stacks. This is important because the call frames are
associated with functions in the profile based on the inlining in the
symbolized call stacks, and this simplifies locating the subset of
profile data relevant for matching onto each function's IR.

The PGOInstrumentationUse pass is enhanced to perform matching for
whatever combination of memprof and regular PGO profile data exists in
the profile.

Using the utilities introduced in D128854:
The memprof profile data for each context is converted to "cold" or
"notcold" based on parameterized thresholds for size, access count, and
lifetime. The memprof allocation contexts are trimmed to the minimal
amount of context required to uniquely identify whether the context is
cold or not cold. For allocations where all profiled contexts have the
same allocation type, no memprof metadata is attached and instead the
allocation call is directly annotated with an attribute specifying the
alloction type. This is the same attributed that will be applied to
allocation calls once cloned for different contexts, and later used
during LibCall simplification to emit allocation hints [4].

Depends on D128141 and D128854.

[1] https://lists.llvm.org/pipermail/llvm-dev/2020-June/142744.html
[2] https://lists.llvm.org/pipermail/llvm-dev/2021-September/153007.html
[3] https://discourse.llvm.org/t/rfc-ir-metadata-format-for-memprof/59165
[4] https://github.com/google/tcmalloc/commit/ab87cf382dc56784f783f3aaa43d6d0465d5f385

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

More information about the All-commits mailing list