[docs][MemProf]Update compiler options for static data partitioning (#175872)

https://github.com/llvm/llvm-project/pull/124991 introduces a Clang
option for static data partitioning. Update the LLVM option with the
Clang option and some notes on how data hotness is inferred from
profiles.
This commit is contained in:
Mingming Liu 2026-01-14 15:12:21 -08:00 committed by GitHub
parent 782bf6aff6
commit f1821a50c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View File

@ -4684,7 +4684,7 @@ defm partition_static_data_sections: BoolFOption<"partition-static-data-sections
CodeGenOpts<"PartitionStaticDataSections">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
NegFlag<SetFalse, [], [ClangOption], "Disable">,
BothFlags<[], [ClangOption], " partition static data sections using profile information (x86 and aarch64 ELF)">>;
BothFlags<[], [ClangOption], " partition static data sections using PGO profile information and MemProf (x86 and aarch64 ELF). See LLVM MemProf doc for usage.">>;
defm strict_return : BoolFOption<"strict-return",
CodeGenOpts<"StrictReturn">, DefaultTrue,

View File

@ -140,18 +140,29 @@ This feature uses a hybrid approach:
To enable this feature, pass the following flags to the compiler:
* ``-memprof-annotate-static-data-prefix``: Enables annotation of global variables in IR.
* ``-split-static-data``: Enables partitioning of other data (like jump tables) in the backend.
* ``-Wl,-z,keep-data-section-prefix``: Instructs the linker (LLD) to group hot and cold data sections together.
* ``-fpartition-static-data-sections``: Instructs the compiler to generate `.hot` and `.unlikely` section prefixes for hot and cold static data respectively in the relocatable object files.
* ``-Wl,-z,keep-data-section-prefix``: Informs the LLD linker that `.data.rel.ro.hot` and `.data.rel.ro.unlikely` as relro sections. LLD requires all relro sections to be contiguous and this flag allows us to interleave the hotness-suffixed `.data.rel.ro` sections with other relro sections.
* ``-Wl,-script=<linker_script>``: Group hot and/or cold data sections, and order the data sections.
.. code-block:: bash
clang++ -fmemory-profile-use=memprof.memprofdata -mllvm -memprof-annotate-static-data-prefix -mllvm -split-static-data -fuse-ld=lld -Wl,-z,keep-data-section-prefix -O2 source.cpp -o optimized_app
clang++ -fmemory-profile-use=memprof.memprofdata -fpartition-static-data-sections -fuse-ld=lld -Wl,-z,keep-data-section-prefix -O2 source.cpp -o optimized_app
The optimized layout clusters hot static data, improving dTLB and cache efficiency.
.. note::
For an LTO build -split-static-data needs to be passed to the LTO backend via the linker using ``-Wl,-mllvm,-split-static-data``.
When both PGO profiles and memory profiles are provided (using
``-fprofile-use`` and ``-fmemory-profile-use``), global variable hotness are
inferred from a combination of PGO profile and data access profile:
* For data covered by both profiles (e.g., module-internal data with symbols
in the executable), the hotness is the max of PGO profile hotness and data
access profile hotness.
* For data covered by only one profile, the hotness is inferred from that
profile. Most notably, symbolizable data with external linkage is only
covered by data access profile, and module-internal unsymbolizable data is
only covered by PGO profile.
Developer Manual
================