[llvm] [MemProf] Extend MemProfUse pass to make use of data access profiles to partition data (PR #151238)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 22:12:33 PDT 2025


================
@@ -752,3 +773,58 @@ PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
 
   return PreservedAnalyses::none();
 }
+
+bool MemProfUsePass::annotateGlobalVariables(
+    Module &M, const memprof::DataAccessProfData *DataAccessProf) {
+  if (!AnnotationStaticDataPrefix || M.globals().empty() || !DataAccessProf)
+    return false;
+
+  bool Changed = false;
+  for (GlobalVariable &GVar : M.globals()) {
+    assert(!GVar.getSectionPrefix().has_value() &&
----------------
mingmingl-llvm wrote:

https://github.com/llvm/llvm-project/pull/151238/commits/291bae73e1508eb0cfe2dd866c7ab679c93eb13d implements the change and test.

https://gcc.godbolt.org/z/3c59K3rqM is a small C++ example to illustrate how source code section names ([section attribute](https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate) and[ `#pragma clang section` directive](https://clang.llvm.org/docs/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section)) affects section name in asm. From the asm output,  we can see that `a` and `b` has `sec1` and `sec2` respectively.



https://github.com/llvm/llvm-project/pull/151238


More information about the llvm-commits mailing list