[llvm] a09fd9c - [CodeGen][NPM] Port MachineBlockPlacementStats to NPM (#129853)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 17 02:54:50 PDT 2025
Author: Akshat Oke
Date: 2025-04-17T15:24:46+05:30
New Revision: a09fd9c6536b746deea651b796978285ed161a00
URL: https://github.com/llvm/llvm-project/commit/a09fd9c6536b746deea651b796978285ed161a00
DIFF: https://github.com/llvm/llvm-project/commit/a09fd9c6536b746deea651b796978285ed161a00.diff
LOG: [CodeGen][NPM] Port MachineBlockPlacementStats to NPM (#129853)
Added:
Modified:
llvm/include/llvm/CodeGen/MachineBlockPlacement.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/Passes/MachinePassRegistry.def
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/MachineBlockPlacement.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineBlockPlacement.h b/llvm/include/llvm/CodeGen/MachineBlockPlacement.h
index 733d24ab719a8..f88e72c2a177b 100644
--- a/llvm/include/llvm/CodeGen/MachineBlockPlacement.h
+++ b/llvm/include/llvm/CodeGen/MachineBlockPlacement.h
@@ -30,6 +30,15 @@ class MachineBlockPlacementPass
function_ref<StringRef(StringRef)> MapClassName2PassName) const;
};
+class MachineBlockPlacementStatsPass
+ : public PassInfoMixin<MachineBlockPlacementStatsPass> {
+
+public:
+ PreservedAnalyses run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM);
+ static bool isRequired() { return true; }
+};
+
} // namespace llvm
#endif // LLVM_CODEGEN_MACHINEBLOCKPLACEMENT_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index ea6afbfdc7861..9fd8f8228a717 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -185,7 +185,7 @@ void initializeMIRNamerPass(PassRegistry &);
void initializeMIRPrintingPassPass(PassRegistry &);
void initializeMachineBlockFrequencyInfoWrapperPassPass(PassRegistry &);
void initializeMachineBlockPlacementLegacyPass(PassRegistry &);
-void initializeMachineBlockPlacementStatsPass(PassRegistry &);
+void initializeMachineBlockPlacementStatsLegacyPass(PassRegistry &);
void initializeMachineBranchProbabilityInfoWrapperPassPass(PassRegistry &);
void initializeMachineCFGPrinterPass(PassRegistry &);
void initializeMachineCSELegacyPass(PassRegistry &);
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 3ba2d259fe78c..fff5083caad1a 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -137,6 +137,7 @@ MACHINE_FUNCTION_ANALYSIS("virtregmap", VirtRegMapAnalysis())
#ifndef MACHINE_FUNCTION_PASS
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
#endif
+MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass())
MACHINE_FUNCTION_PASS("branch-relaxation", BranchRelaxationPass())
MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass())
MACHINE_FUNCTION_PASS("detect-dead-lanes", DetectDeadLanesPass())
@@ -281,7 +282,6 @@ DUMMY_MACHINE_MODULE_PASS("mir-strip-debug", StripDebugMachineModulePass)
#endif
DUMMY_MACHINE_FUNCTION_PASS("bbsections-prepare", BasicBlockSectionsPass)
DUMMY_MACHINE_FUNCTION_PASS("bbsections-profile-reader", BasicBlockSectionsProfileReaderPass)
-DUMMY_MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass)
DUMMY_MACHINE_FUNCTION_PASS("break-false-deps", BreakFalseDepsPass)
DUMMY_MACHINE_FUNCTION_PASS("cfguard-longjmp", CFGuardLongjmpPass)
DUMMY_MACHINE_FUNCTION_PASS("cfi-fixup", CFIFixupPass)
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index dd04b2e81a2a7..2b0e93803971f 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -73,7 +73,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeMIRProfileLoaderPassPass(Registry);
initializeMachineBlockFrequencyInfoWrapperPassPass(Registry);
initializeMachineBlockPlacementLegacyPass(Registry);
- initializeMachineBlockPlacementStatsPass(Registry);
+ initializeMachineBlockPlacementStatsLegacyPass(Registry);
initializeMachineCFGPrinterPass(Registry);
initializeMachineCSELegacyPass(Registry);
initializeMachineCombinerPass(Registry);
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 47213ede3a33e..bd777db0791b7 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -3839,21 +3839,35 @@ namespace {
/// placement. This is separate from the actual placement pass so that they can
/// be computed in the absence of any placement transformations or when using
/// alternative placement strategies.
-class MachineBlockPlacementStats : public MachineFunctionPass {
+class MachineBlockPlacementStats {
/// A handle to the branch probability pass.
const MachineBranchProbabilityInfo *MBPI;
/// A handle to the function-wide block frequency pass.
const MachineBlockFrequencyInfo *MBFI;
+public:
+ MachineBlockPlacementStats(const MachineBranchProbabilityInfo *MBPI,
+ const MachineBlockFrequencyInfo *MBFI)
+ : MBPI(MBPI), MBFI(MBFI) {}
+ bool run(MachineFunction &MF);
+};
+
+class MachineBlockPlacementStatsLegacy : public MachineFunctionPass {
public:
static char ID; // Pass identification, replacement for typeid
- MachineBlockPlacementStats() : MachineFunctionPass(ID) {
- initializeMachineBlockPlacementStatsPass(*PassRegistry::getPassRegistry());
+ MachineBlockPlacementStatsLegacy() : MachineFunctionPass(ID) {
+ initializeMachineBlockPlacementStatsLegacyPass(
+ *PassRegistry::getPassRegistry());
}
- bool runOnMachineFunction(MachineFunction &F) override;
+ bool runOnMachineFunction(MachineFunction &F) override {
+ auto *MBPI =
+ &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
+ auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
+ return MachineBlockPlacementStats(MBPI, MBFI).run(F);
+ }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
@@ -3865,18 +3879,28 @@ class MachineBlockPlacementStats : public MachineFunctionPass {
} // end anonymous namespace
-char MachineBlockPlacementStats::ID = 0;
+char MachineBlockPlacementStatsLegacy::ID = 0;
-char &llvm::MachineBlockPlacementStatsID = MachineBlockPlacementStats::ID;
+char &llvm::MachineBlockPlacementStatsID = MachineBlockPlacementStatsLegacy::ID;
-INITIALIZE_PASS_BEGIN(MachineBlockPlacementStats, "block-placement-stats",
+INITIALIZE_PASS_BEGIN(MachineBlockPlacementStatsLegacy, "block-placement-stats",
"Basic Block Placement Stats", false, false)
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfoWrapperPass)
-INITIALIZE_PASS_END(MachineBlockPlacementStats, "block-placement-stats",
+INITIALIZE_PASS_END(MachineBlockPlacementStatsLegacy, "block-placement-stats",
"Basic Block Placement Stats", false, false)
-bool MachineBlockPlacementStats::runOnMachineFunction(MachineFunction &F) {
+PreservedAnalyses
+MachineBlockPlacementStatsPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+ auto &MBPI = MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
+ auto &MBFI = MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
+
+ MachineBlockPlacementStats(&MBPI, &MBFI).run(MF);
+ return PreservedAnalyses::all();
+}
+
+bool MachineBlockPlacementStats::run(MachineFunction &F) {
// Check for single-block functions and skip them.
if (std::next(F.begin()) == F.end())
return false;
@@ -3884,9 +3908,6 @@ bool MachineBlockPlacementStats::runOnMachineFunction(MachineFunction &F) {
if (!isFunctionInPrintList(F.getName()))
return false;
- MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
- MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
-
for (MachineBasicBlock &MBB : F) {
BlockFrequency BlockFreq = MBFI->getBlockFreq(&MBB);
Statistic &NumBranches =
More information about the llvm-commits
mailing list