Skip to content

Commit a01bc11

Browse files
committed
[CodeGen][NPM] Port MachineBlockPlacementStats to NPM
1 parent 316c784 commit a01bc11

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

llvm/include/llvm/CodeGen/MachineBlockPlacement.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class MachineBlockPlacementPass
2525
MachineFunctionAnalysisManager &MFAM);
2626
};
2727

28+
class MachineBlockPlacementStatsPass
29+
: public PassInfoMixin<MachineBlockPlacementStatsPass> {
30+
31+
public:
32+
PreservedAnalyses run(MachineFunction &MF,
33+
MachineFunctionAnalysisManager &MFAM);
34+
};
35+
2836
} // namespace llvm
2937

3038
#endif // LLVM_CODEGEN_MACHINEBLOCKPLACEMENT_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void initializeMIRNamerPass(PassRegistry &);
185185
void initializeMIRPrintingPassPass(PassRegistry &);
186186
void initializeMachineBlockFrequencyInfoWrapperPassPass(PassRegistry &);
187187
void initializeMachineBlockPlacementLegacyPass(PassRegistry &);
188-
void initializeMachineBlockPlacementStatsPass(PassRegistry &);
188+
void initializeMachineBlockPlacementStatsLegacyPass(PassRegistry &);
189189
void initializeMachineBranchProbabilityInfoWrapperPassPass(PassRegistry &);
190190
void initializeMachineCFGPrinterPass(PassRegistry &);
191191
void initializeMachineCSELegacyPass(PassRegistry &);

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ MACHINE_FUNCTION_ANALYSIS("virtregmap", VirtRegMapAnalysis())
137137
#ifndef MACHINE_FUNCTION_PASS
138138
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
139139
#endif
140+
MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass())
140141
MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass())
141142
MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
142143
MACHINE_FUNCTION_PASS("early-machinelicm", EarlyMachineLICMPass())
@@ -250,7 +251,6 @@ DUMMY_MACHINE_MODULE_PASS("mir-strip-debug", StripDebugMachineModulePass)
250251
#endif
251252
DUMMY_MACHINE_FUNCTION_PASS("bbsections-prepare", BasicBlockSectionsPass)
252253
DUMMY_MACHINE_FUNCTION_PASS("bbsections-profile-reader", BasicBlockSectionsProfileReaderPass)
253-
DUMMY_MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass)
254254
DUMMY_MACHINE_FUNCTION_PASS("branch-folder", BranchFolderPass)
255255
DUMMY_MACHINE_FUNCTION_PASS("break-false-deps", BreakFalseDepsPass)
256256
DUMMY_MACHINE_FUNCTION_PASS("cfguard-longjmp", CFGuardLongjmpPass)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
7373
initializeMIRProfileLoaderPassPass(Registry);
7474
initializeMachineBlockFrequencyInfoWrapperPassPass(Registry);
7575
initializeMachineBlockPlacementLegacyPass(Registry);
76-
initializeMachineBlockPlacementStatsPass(Registry);
76+
initializeMachineBlockPlacementStatsLegacyPass(Registry);
7777
initializeMachineCFGPrinterPass(Registry);
7878
initializeMachineCSELegacyPass(Registry);
7979
initializeMachineCombinerPass(Registry);

llvm/lib/CodeGen/MachineBlockPlacement.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,21 +3829,35 @@ namespace {
38293829
/// placement. This is separate from the actual placement pass so that they can
38303830
/// be computed in the absence of any placement transformations or when using
38313831
/// alternative placement strategies.
3832-
class MachineBlockPlacementStats : public MachineFunctionPass {
3832+
class MachineBlockPlacementStats {
38333833
/// A handle to the branch probability pass.
38343834
const MachineBranchProbabilityInfo *MBPI;
38353835

38363836
/// A handle to the function-wide block frequency pass.
38373837
const MachineBlockFrequencyInfo *MBFI;
38383838

3839+
public:
3840+
MachineBlockPlacementStats(const MachineBranchProbabilityInfo *MBPI,
3841+
const MachineBlockFrequencyInfo *MBFI)
3842+
: MBPI(MBPI), MBFI(MBFI) {}
3843+
bool run(MachineFunction &MF);
3844+
};
3845+
3846+
class MachineBlockPlacementStatsLegacy : public MachineFunctionPass {
38393847
public:
38403848
static char ID; // Pass identification, replacement for typeid
38413849

3842-
MachineBlockPlacementStats() : MachineFunctionPass(ID) {
3843-
initializeMachineBlockPlacementStatsPass(*PassRegistry::getPassRegistry());
3850+
MachineBlockPlacementStatsLegacy() : MachineFunctionPass(ID) {
3851+
initializeMachineBlockPlacementStatsLegacyPass(
3852+
*PassRegistry::getPassRegistry());
38443853
}
38453854

3846-
bool runOnMachineFunction(MachineFunction &F) override;
3855+
bool runOnMachineFunction(MachineFunction &F) override {
3856+
auto *MBPI =
3857+
&getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
3858+
auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
3859+
return MachineBlockPlacementStats(MBPI, MBFI).run(F);
3860+
}
38473861

38483862
void getAnalysisUsage(AnalysisUsage &AU) const override {
38493863
AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
@@ -3855,28 +3869,35 @@ class MachineBlockPlacementStats : public MachineFunctionPass {
38553869

38563870
} // end anonymous namespace
38573871

3858-
char MachineBlockPlacementStats::ID = 0;
3872+
char MachineBlockPlacementStatsLegacy::ID = 0;
38593873

3860-
char &llvm::MachineBlockPlacementStatsID = MachineBlockPlacementStats::ID;
3874+
char &llvm::MachineBlockPlacementStatsID = MachineBlockPlacementStatsLegacy::ID;
38613875

3862-
INITIALIZE_PASS_BEGIN(MachineBlockPlacementStats, "block-placement-stats",
3876+
INITIALIZE_PASS_BEGIN(MachineBlockPlacementStatsLegacy, "block-placement-stats",
38633877
"Basic Block Placement Stats", false, false)
38643878
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
38653879
INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfoWrapperPass)
3866-
INITIALIZE_PASS_END(MachineBlockPlacementStats, "block-placement-stats",
3880+
INITIALIZE_PASS_END(MachineBlockPlacementStatsLegacy, "block-placement-stats",
38673881
"Basic Block Placement Stats", false, false)
38683882

3869-
bool MachineBlockPlacementStats::runOnMachineFunction(MachineFunction &F) {
3883+
PreservedAnalyses
3884+
MachineBlockPlacementStatsPass::run(MachineFunction &MF,
3885+
MachineFunctionAnalysisManager &MFAM) {
3886+
auto &MBPI = MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
3887+
auto &MBFI = MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
3888+
3889+
MachineBlockPlacementStats(&MBPI, &MBFI).run(MF);
3890+
return PreservedAnalyses::all();
3891+
}
3892+
3893+
bool MachineBlockPlacementStats::run(MachineFunction &F) {
38703894
// Check for single-block functions and skip them.
38713895
if (std::next(F.begin()) == F.end())
38723896
return false;
38733897

38743898
if (!isFunctionInPrintList(F.getName()))
38753899
return false;
38763900

3877-
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
3878-
MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
3879-
38803901
for (MachineBasicBlock &MBB : F) {
38813902
BlockFrequency BlockFreq = MBFI->getBlockFreq(&MBB);
38823903
Statistic &NumBranches =

0 commit comments

Comments
 (0)