Skip to content

Conversation

@mingmingl-llvm
Copy link
Contributor

TODO: regression test coverage.

mingmingl-llvm added a commit that referenced this pull request Aug 28, 2025
…to partition data (#151238)

f3f2832
introduces the data access profile format as a payload inside
[memprof](https://llvm.org/docs/InstrProfileFormat.html#memprof-profile-data),
and the MemProfUse pass reads the memprof payload.

This change extends the MemProfUse pass to read the data access profiles
to annotate global variables' section prefix.
1. If there are samples for a global variable, it's annotated as hot.
2. If a global variable is seen in the profiled binary file but doesn't
have access samples, it's annotated as unlikely.

Introduce an option `annotate-static-data-prefix` to flag-gate the
global-variable annotation path, and make it false by default.
#155337 is the (WIP) draft
change to "reconcile" two sources of hotness.
Base automatically changed from users/mingmingl-llvm/memprofuse to main August 28, 2025 03:43
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Aug 28, 2025
…s profiles to partition data (#151238)

llvm/llvm-project@f3f2832
introduces the data access profile format as a payload inside
[memprof](https://llvm.org/docs/InstrProfileFormat.html#memprof-profile-data),
and the MemProfUse pass reads the memprof payload.

This change extends the MemProfUse pass to read the data access profiles
to annotate global variables' section prefix.
1. If there are samples for a global variable, it's annotated as hot.
2. If a global variable is seen in the profiled binary file but doesn't
have access samples, it's annotated as unlikely.

Introduce an option `annotate-static-data-prefix` to flag-gate the
global-variable annotation path, and make it false by default.
llvm/llvm-project#155337 is the (WIP) draft
change to "reconcile" two sources of hotness.
@github-actions
Copy link

github-actions bot commented Sep 14, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/Analysis/StaticDataProfileInfo.h llvm/lib/Analysis/StaticDataProfileInfo.cpp llvm/lib/CodeGen/StaticDataAnnotator.cpp llvm/lib/CodeGen/StaticDataSplitter.cpp llvm/lib/ProfileData/DataAccessProf.cpp llvm/lib/Transforms/Instrumentation/MemProfUse.cpp

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/lib/CodeGen/StaticDataSplitter.cpp b/llvm/lib/CodeGen/StaticDataSplitter.cpp
index 97aa833cf..8192adb86 100644
--- a/llvm/lib/CodeGen/StaticDataSplitter.cpp
+++ b/llvm/lib/CodeGen/StaticDataSplitter.cpp
@@ -133,7 +133,8 @@ StaticDataSplitter::getConstant(const MachineOperand &Op,
     // Skip 'llvm.'-prefixed global variables conservatively because they are
     // often handled specially, and skip those not in static data
     // sections.
-    if (!GV || llvm::IsReservedGlobalVariable(*GV) || !inStaticDataSection(*GV, TM))
+    if (!GV || llvm::IsReservedGlobalVariable(*GV) ||
+        !inStaticDataSection(*GV, TM))
       return nullptr;
     return GV;
   }

mingmingl-llvm added a commit that referenced this pull request Oct 13, 2025
…ta access profiles by module flag. (#162333)

The codegen pass in the pipeline can read the module flag to tell
whether the IR is compiled with data access profile, to support two use
cases when `memprof-annotate-static-data-prefix=true` is enabled

1. The binary is compiled with data access profiles. 
- The module flag will have value 1, and codegen pass should regard an
empty section prefix as 'unknown' and conservatively not placing the
data into `.unlikely` data sections.

2. The binary is compiled without data access profiles (e.g., during
incremental rollout, etc)
- The module flag will have value 0, and codegen pass can override an
empty section prefix based on PGO counters.

#155337 shows the motivating
use case in function `StaticDataProfileInfo::getConstantSectionPrefix`
in `llvm/lib/Analysis/StaticDataProfileInfo.cpp`

This is the 1st patch as a split of
#155337
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 13, 2025
…led with data access profiles by module flag. (#162333)

The codegen pass in the pipeline can read the module flag to tell
whether the IR is compiled with data access profile, to support two use
cases when `memprof-annotate-static-data-prefix=true` is enabled

1. The binary is compiled with data access profiles.
- The module flag will have value 1, and codegen pass should regard an
empty section prefix as 'unknown' and conservatively not placing the
data into `.unlikely` data sections.

2. The binary is compiled without data access profiles (e.g., during
incremental rollout, etc)
- The module flag will have value 0, and codegen pass can override an
empty section prefix based on PGO counters.

llvm/llvm-project#155337 shows the motivating
use case in function `StaticDataProfileInfo::getConstantSectionPrefix`
in `llvm/lib/Analysis/StaticDataProfileInfo.cpp`

This is the 1st patch as a split of
llvm/llvm-project#155337
mingmingl-llvm added a commit that referenced this pull request Oct 13, 2025
…igibility 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
#155337
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 13, 2025
…n 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
llvm/llvm-project#155337
mingmingl-llvm added a commit that referenced this pull request Oct 13, 2025
…gen (#162349)

The section prefix validation was initially added when global variable's
section prefix is only added in the codegen pass.

Now the optimizer pass MemProfUse can annotate data section prefix by
making use of data access profiles, so we can remove the validation.
Also calls `setSectionPrefix` which returns whether section prefix is
updated.

This is the 3rd patch as a split of
#155337
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 13, 2025
…ion in codegen (#162349)

The section prefix validation was initially added when global variable's
section prefix is only added in the codegen pass.

Now the optimizer pass MemProfUse can annotate data section prefix by
making use of data access profiles, so we can remove the validation.
Also calls `setSectionPrefix` which returns whether section prefix is
updated.

This is the 3rd patch as a split of
llvm/llvm-project#155337
akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
…ta access profiles by module flag. (llvm#162333)

The codegen pass in the pipeline can read the module flag to tell
whether the IR is compiled with data access profile, to support two use
cases when `memprof-annotate-static-data-prefix=true` is enabled

1. The binary is compiled with data access profiles. 
- The module flag will have value 1, and codegen pass should regard an
empty section prefix as 'unknown' and conservatively not placing the
data into `.unlikely` data sections.

2. The binary is compiled without data access profiles (e.g., during
incremental rollout, etc)
- The module flag will have value 0, and codegen pass can override an
empty section prefix based on PGO counters.

llvm#155337 shows the motivating
use case in function `StaticDataProfileInfo::getConstantSectionPrefix`
in `llvm/lib/Analysis/StaticDataProfileInfo.cpp`

This is the 1st patch as a split of
llvm#155337
akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
…igibility and use it in both optimizer and codegen (llvm#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
llvm#155337
akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
…gen (llvm#162349)

The section prefix validation was initially added when global variable's
section prefix is only added in the codegen pass.

Now the optimizer pass MemProfUse can annotate data section prefix by
making use of data access profiles, so we can remove the validation.
Also calls `setSectionPrefix` which returns whether section prefix is
updated.

This is the 3rd patch as a split of
llvm#155337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants