Skip to content

Commit

Permalink
[docs] Document MemProf metadata in LangRef
Browse files Browse the repository at this point in the history
Add documentation for memprof and callsite metadata in LangRef.

Differential Revision: https://reviews.llvm.org/D146007
  • Loading branch information
teresajohnson committed Mar 14, 2023
1 parent 084e413 commit 1f884ef
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions llvm/docs/LangRef.rst
Expand Up @@ -7459,6 +7459,72 @@ Example:
Clang emits ``kcfi_type`` metadata nodes for address-taken functions with
``-fsanitize=kcfi``.

.. _md_memprof:

'``memprof``' Metadata
^^^^^^^^^^^^^^^^^^^^^^^^

The ``memprof`` metadata is used to record memory profile data on heap
allocation calls. Multiple context-sensitive profiles can be represented
with a single ``memprof`` metadata attachment.

Example:

.. code-block:: text

%call = call ptr @_Znam(i64 10), !memprof !0, !callsite !5
!0 = !{!1, !3}
!1 = !{!2, !"cold"}
!2 = !{i64 4854880825882961848, i64 1905834578520680781}
!3 = !{!4, !"notcold"}
!4 = !{i64 4854880825882961848, i64 -6528110295079665978}
!5 = !{i64 4854880825882961848}

Each operand in the ``memprof`` metadata attachment describes the profiled
behavior of memory allocated by the associated allocation for a given context.
In the above example, there were 2 profiled contexts, one allocating memory
that was typically cold and one allocating memory that was typically not cold.

The format of the metadata describing a context specific profile (e.g.
``!1`` and ``!3`` above) requires a first operand that is a metadata node
describing the context, followed by a list of string metadata tags describing
the profile behavior (e.g. ``cold`` and ``notcold``) above. The metadata nodes
describing the context (e.g. ``!2`` and ``!4`` above) are unique ids
corresponding to callsites, which can be matched to associated IR calls via
:ref:`callsite metadata<md_callsite>`. In practice these ids are formed via
a hash of the callsite's debug info, and the associated call may be in a
different module. The contexts are listed in order from leaf-most call (the
allocation itself) to the outermost callsite context required for uniquely
identifying the described profile behavior (note this may not be the top of
the profiled call stack).

.. _md_callsite:

'``callsite``' Metadata
^^^^^^^^^^^^^^^^^^^^^^^^

The ``callsite`` metadata is used to identify callsites involved in memory
profile contexts described in :ref:`memprof metadata<md_memprof>`.

It is attached both to the profile allocation calls (see the example in
:ref:`memprof metadata<md_memprof>`), as well as to other callsites
in profiled contexts described in heap allocation ``memprof`` metadata.

Example:

.. code-block:: text

%call = call ptr @_Z1Bb(void), !callsite !0
!0 = !{i64 -6528110295079665978, i64 5462047985461644151}

Each operand in the ``callsite`` metadata attachment is a unique id
corresponding to a callsite (possibly inlined). In practice these ids are
formed via a hash of the callsite's debug info. If the call was not inlined
into any callers it will contain a single operand (id). If it was inlined
it will contain a list of ids, including the ids of the callsites in the
full inline sequence, in order from the leaf-most call's id to the outermost
inlined call.

Module Flags Metadata
=====================

Expand Down

0 comments on commit 1f884ef

Please sign in to comment.