[compiler-rt] [llvm] [AIX] PGO codegen changes for function-sections. (PR #139761)
Amy Kwan via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 10:22:12 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() &&
+ "profiling data symbol must have an initializer");
+ assert(isa<ConstantStruct>(GV->getInitializer()) &&
+ "expect the initializer for a profiling data symbol to be a struct");
+ const ConstantStruct *Initializer =
+ cast<ConstantStruct>(GV->getInitializer());
+
+ // The initializer structure is: { i64, i64, i32, ptr, ptr, i32, [4 x i16] }
+ // and the reference to the global variable for the counters is in the
+ // first i32 member.
+ const Constant *Member = Initializer->getAggregateElement(2);
+ assert(Member && "profiling data symbol has more then 3 elements");
+
+ // Want to decompose a constant expression of the form:
+ // sub (ptrtoint (ptr @__profc_sym), ptrtoint (ptr @__profd_sym))
+ // to get the GlobalVariable for the '@__profc_sym` symbol.
+ assert(isa<ConstantExpr>(Member) &&
+ "expected member initializer is a constant expression.");
+ const ConstantExpr *CExpr = cast<ConstantExpr>(Member);
+ assert(CExpr->getOpcode() == Instruction::Sub &&
+ "expected member intializer is a sub expression.");
----------------
amy-kwan wrote:
```suggestion
"expected member initializer is a sub expression.");
```
https://github.com/llvm/llvm-project/pull/139761
More information about the llvm-commits
mailing list