[compiler-rt] [llvm] [AIX] PGO codegen changes for function-sections. (PR #139761)

Wael Yehia via llvm-commits llvm-commits at lists.llvm.org
Tue May 27 07:26:21 PDT 2025


================
@@ -2810,6 +2826,57 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) {
   MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
       getObjFileLowering().SectionForGlobal(GV, GVKind, TM));
 
+  // When compiling with function sections enabled, we need some special
+  // codegen to rename the CSECTs. For each profiling data symbol find its
+  // associated profiling counters.
+  if (TM.getFunctionSections() &&
+      Csect->getName().starts_with("__llvm_prf_data.")) {
+    // Unraveling the initializer to find the related counters variable. The
+    // initializer is a structure whose third member is a subtract expression
+    // between the counters label and the label for the start of this structure.
+    // Use the subtract expression to get the GlobalValue for the counters
+    // global.
+    assert(GV->hasInitializer() &&
----------------
w2yehia wrote:

> What do you think of an alternative approach where we could use a metadata node to explicitly attach to dependancy info to the data symbol?

that will have to happen early in the pipeline, when the profd's initializer is created. Then that metadata will have to be maintained by passes until object/asm generation. No strong objection to it, but I slightly prefer to just refactor this into a utility function in InstrProf.h: 
```
const GlobalVariable *getInstrProfCounterGV(const GlobalVariable *ProfDataVar)

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


More information about the llvm-commits mailing list