[llvm] [NewPM] Port StaticDataProfileInfo and wire into x86 AsmPrinter (PR #207550)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 4 17:47:06 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
Ports the analysis to the NewPM and wires it into the NewPM x86
AsmPrinter where we are currently just returning nullptr.
---
Full diff: https://github.com/llvm/llvm-project/pull/207550.diff
4 Files Affected:
- (modified) llvm/include/llvm/Analysis/StaticDataProfileInfo.h (+28)
- (modified) llvm/lib/Analysis/StaticDataProfileInfo.cpp (+15-2)
- (modified) llvm/lib/Target/X86/X86AsmPrinter.cpp (+15-3)
- (modified) llvm/lib/Target/X86/X86AsmPrinter.h (+1-1)
``````````diff
diff --git a/llvm/include/llvm/Analysis/StaticDataProfileInfo.h b/llvm/include/llvm/Analysis/StaticDataProfileInfo.h
index 56a3eacc973aa..c0c169fb14347 100644
--- a/llvm/include/llvm/Analysis/StaticDataProfileInfo.h
+++ b/llvm/include/llvm/Analysis/StaticDataProfileInfo.h
@@ -4,9 +4,12 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
+#include "llvm/IR/Analysis.h"
#include "llvm/IR/Constant.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
+#include <memory>
namespace llvm {
@@ -112,6 +115,31 @@ class LLVM_ABI StaticDataProfileInfoWrapperPass : public ImmutablePass {
std::unique_ptr<StaticDataProfileInfo> Info;
};
+class LLVM_ABI StaticDataProfileInfoAnalysis
+ : public AnalysisInfoMixin<StaticDataProfileInfoAnalysis> {
+public:
+ LLVM_ABI static AnalysisKey Key;
+
+ class Result {
+ std::unique_ptr<StaticDataProfileInfo> HeldInfo;
+ Result(std::unique_ptr<StaticDataProfileInfo> &&Info)
+ : HeldInfo(std::move(Info)) {}
+ friend class StaticDataProfileInfoAnalysis;
+
+ public:
+ const StaticDataProfileInfo &getStaticDataProfileInfo() const {
+ return *HeldInfo;
+ }
+
+ bool invalidate(Module &, const PreservedAnalyses &,
+ ModuleAnalysisManager::Invalidator &) {
+ return false;
+ }
+ };
+
+ Result run(Module &M, ModuleAnalysisManager &);
+};
+
} // namespace llvm
#endif // LLVM_ANALYSIS_STATICDATAPROFILEINFO_H
diff --git a/llvm/lib/Analysis/StaticDataProfileInfo.cpp b/llvm/lib/Analysis/StaticDataProfileInfo.cpp
index e7a01317ea3dc..5bc85173e0ea5 100644
--- a/llvm/lib/Analysis/StaticDataProfileInfo.cpp
+++ b/llvm/lib/Analysis/StaticDataProfileInfo.cpp
@@ -4,6 +4,7 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/InitializePasses.h"
#include "llvm/ProfileData/InstrProf.h"
@@ -188,12 +189,17 @@ StringRef StaticDataProfileInfo::getConstantSectionPrefix(
return hotnessToStr(getConstantHotnessUsingProfileCount(C, PSI, *Count));
}
-bool StaticDataProfileInfoWrapperPass::doInitialization(Module &M) {
+static std::unique_ptr<StaticDataProfileInfo>
+computeStaticDataProfileInfo(Module &M) {
bool EnableDataAccessProf = false;
if (auto *MD = mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag("EnableDataAccessProf")))
EnableDataAccessProf = MD->getZExtValue();
- Info.reset(new StaticDataProfileInfo(EnableDataAccessProf));
+ return std::make_unique<StaticDataProfileInfo>(EnableDataAccessProf);
+}
+
+bool StaticDataProfileInfoWrapperPass::doInitialization(Module &M) {
+ Info = computeStaticDataProfileInfo(M);
return false;
}
@@ -209,3 +215,10 @@ StaticDataProfileInfoWrapperPass::StaticDataProfileInfoWrapperPass()
: ImmutablePass(ID) {}
char StaticDataProfileInfoWrapperPass::ID = 0;
+
+StaticDataProfileInfoAnalysis::Result
+StaticDataProfileInfoAnalysis::run(Module &M, ModuleAnalysisManager &) {
+ return StaticDataProfileInfoAnalysis::Result(computeStaticDataProfileInfo(M));
+}
+
+AnalysisKey llvm::StaticDataProfileInfoAnalysis::Key;
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 6d213b8c213aa..4f7d16afa8a7a 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -27,6 +27,7 @@
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
+#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
#include "llvm/CodeGenTypes/MachineValueType.h"
#include "llvm/IR/DerivedTypes.h"
@@ -1162,7 +1163,10 @@ PreservedAnalyses X86AsmPrinterBeginPass::run(Module &M,
AsmPrinter.GetPSI = [&MAM](Module &M) {
return &MAM.getResult<ProfileSummaryAnalysis>(M);
};
- AsmPrinter.GetSDPI = [](Module &M) { return nullptr; };
+ AsmPrinter.GetSDPI = [&MAM](Module &M) {
+ return &MAM.getResult<StaticDataProfileInfoAnalysis>(M)
+ .getStaticDataProfileInfo();
+ };
setupModuleAsmPrinter(M, MAM, AsmPrinter);
AsmPrinter.doInitialization(M);
return PreservedAnalyses::all();
@@ -1178,7 +1182,12 @@ PreservedAnalyses X86AsmPrinterPass::run(MachineFunction &MF,
return MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF)
.getCachedResult<ProfileSummaryAnalysis>(M);
};
- AsmPrinter.GetSDPI = [](Module &M) { return nullptr; };
+ AsmPrinter.GetSDPI = [&MFAM, &MF](Module &M) {
+ return &MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF)
+ .getCachedResult<StaticDataProfileInfoAnalysis>(
+ *MF.getFunction().getParent())
+ ->getStaticDataProfileInfo();
+ };
setupMachineFunctionAsmPrinter(MFAM, MF, AsmPrinter);
AsmPrinter.runOnMachineFunction(MF);
return PreservedAnalyses::all();
@@ -1191,7 +1200,10 @@ PreservedAnalyses X86AsmPrinterEndPass::run(Module &M,
AsmPrinter.GetPSI = [&MAM](Module &M) {
return &MAM.getResult<ProfileSummaryAnalysis>(M);
};
- AsmPrinter.GetSDPI = [](Module &M) { return nullptr; };
+ AsmPrinter.GetSDPI = [&MAM](Module &M) {
+ return &MAM.getResult<StaticDataProfileInfoAnalysis>(M)
+ .getStaticDataProfileInfo();
+ };
setupModuleAsmPrinter(M, MAM, AsmPrinter);
AsmPrinter.doFinalization(M);
return PreservedAnalyses::all();
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.h b/llvm/lib/Target/X86/X86AsmPrinter.h
index 450c45e915414..2f06ed9ed11a1 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.h
+++ b/llvm/lib/Target/X86/X86AsmPrinter.h
@@ -202,7 +202,7 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
}
std::function<ProfileSummaryInfo *(Module &)> GetPSI;
- std::function<StaticDataProfileInfo *(Module &)> GetSDPI;
+ std::function<const StaticDataProfileInfo *(Module &)> GetSDPI;
};
class X86AsmPrinterBeginPass
``````````
</details>
https://github.com/llvm/llvm-project/pull/207550
More information about the llvm-commits
mailing list