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

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Wed May 14 11:01:37 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() &&
----------------
petrhosek wrote:

I agree, this is really brittle and may force developers changing `InstrProfiling` to also change the `PowerPC` backend and they may not have the necessary expertise or a way to test their changes.

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


More information about the llvm-commits mailing list