6 Commits

Author SHA1 Message Date
Mingming Liu
1cec6be8d6
[StaticDataLayout] Reconcile data hotness based on PGO counters and data access profiles (#163325)
This PR enhances the `StaticDataProfileInfo::getConstantSectionPrefix`
pass to reconcile data hotness information from both PGO counters and
data access profiles. When both profiles are available for a global
variable, the pass will now use the "hotter" of the two to determine the
variable's section placement.

This is a follow-up patch of
https://github.com/llvm/llvm-project/pull/162388
2025-10-15 10:24:09 -07:00
Mingming Liu
c63002eb9a
[NFC][StaticDataProfileInfo] Refactor StaticDataProfileInfo::getConstantSectionPrefix and extract analysis based on PGO-counter to be a helper function (#162388)
`StaticDataProfileInfo::getConstantSectionPrefix` is used twice in
codegen ([1] and [2]) to emit section prefix for constants.

Before this patch, its implementation does analysis using PGO-counters,
and PGO-counters are only available on module-internal constants.

After this patch, the PGO-counter analysis are extracted to a helper
function, and returns enum rather than StringPrefix. This way, the
follow up patch https://github.com/llvm/llvm-project/pull/163325 can
extend this function to use global variable section prefix and compute a
max (the hotter one).

[1]
975fba1b49/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (L3014-L3019)
[2]
975fba1b49/llvm/lib/CodeGen/StaticDataAnnotator.cpp (L77-L84)
2025-10-14 21:15:31 -07:00
Mingming Liu
e313bc834e
[StaticDataLayout] Factor out a helper function for section prefix eligibility and use it in both optimizer and codegen (#162348)
This change introduces new helper functions to check if a global
variable is eligible for section prefix annotation.

This shared logic is used by both MemProfUse and StaticDataSplitter to
avoid annotating ineligible variables.

This is the 2nd patch as a split of
https://github.com/llvm/llvm-project/pull/155337
2025-10-13 18:26:16 +00:00
Kazu Hirata
0918361d8b
[Analysis] Remove unused includes (NFC) (#141319)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-23 23:59:56 -07:00
Rahul Joshi
99e4b3927c
[LLVM] Cleanup pass initialization for Analysis passes (#135858)
- Do not call pass initialization from pass constructors.
- Instead, pass initialization should happen in the `initializeAnalysis`
function.
- https://github.com/llvm/llvm-project/issues/111767
2025-04-21 12:36:34 -07:00
Mingming Liu
c8a70f4c6e
[CodeGen][StaticDataPartitioning]Place local-linkage global variables in hot or unlikely prefixed sections based on profile information (#125756)
In this PR, static-data-splitter pass finds out the local-linkage global
variables in {`.rodata`, `.data.rel.ro`, `bss`, `.data`} sections by
analyzing machine instruction operands, and aggregates their accesses
from code across functions.

A follow-up item is to analyze global variable initializers and count
for access from data.
* This limitation is demonstrated by `bss2` and `data3` in
`llvm/test/CodeGen/X86/global-variable-partition.ll`.

Some stats of static-data-splitter with this patch:

**section**|**bss**|**rodata**|**data**
:-----:|:-----:|:-----:|:-----:
hot-prefixed section coverage|99.75%|97.71%|91.30%
unlikely-prefixed section size percentage|67.94%|39.37%|63.10%

1. The coverage is defined as `#perf-sample-in-hot-prefixed <data>
section / #perf-sample in <data.*> section` for each <data> section.
* The perf command samples
`MEM_INST_RETIRED.ALL_LOADS:u:pinned:precise=2` events at a high
frequency (`perf -c 2251`) for 30 seconds. The profiled binary is built
as non-PIE so `data.rel.ro` coverage data is not available.
2. The unlikely-prefixed `<data>` section size percentage is defined as
`unlikely <data> section size / the sum size of <data>.* sections` for
each `<data>` section
2025-03-28 16:31:46 -07:00