Skip to content

Commit 1966207

Browse files
committed
[CodeGen][NPM] Port MachineBlockPlacementStats to NPM
1 parent e18d4c2 commit 1966207

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
@@ -30,6 +30,14 @@ class MachineBlockPlacementPass
3030
function_ref<StringRef(StringRef)> MapClassName2PassName) const;
3131
};
3232

33+
class MachineBlockPlacementStatsPass
34+
: public PassInfoMixin<MachineBlockPlacementStatsPass> {
35+
36+
public:
37+
PreservedAnalyses run(MachineFunction &MF,
38+
MachineFunctionAnalysisManager &MFAM);
39+
};
40+
3341
} // namespace llvm
3442

3543
#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())
@@ -251,7 +252,6 @@ DUMMY_MACHINE_MODULE_PASS("mir-strip-debug", StripDebugMachineModulePass)
251252
#endif
252253
DUMMY_MACHINE_FUNCTION_PASS("bbsections-prepare", BasicBlockSectionsPass)
253254
DUMMY_MACHINE_FUNCTION_PASS("bbsections-profile-reader", BasicBlockSectionsProfileReaderPass)
254-
DUMMY_MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass)
255255
DUMMY_MACHINE_FUNCTION_PASS("branch-folder", BranchFolderPass)
256256
DUMMY_MACHINE_FUNCTION_PASS("break-false-deps", BreakFalseDepsPass)
257257
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
@@ -3837,21 +3837,35 @@ namespace {
38373837
/// placement. This is separate from the actual placement pass so that they can
38383838
/// be computed in the absence of any placement transformations or when using
38393839
/// alternative placement strategies.
3840-
class MachineBlockPlacementStats : public MachineFunctionPass {
3840+
class MachineBlockPlacementStats {
38413841
/// A handle to the branch probability pass.
38423842
const MachineBranchProbabilityInfo *MBPI;
38433843

38443844
/// A handle to the function-wide block frequency pass.
38453845
const MachineBlockFrequencyInfo *MBFI;
38463846

3847+
public:
3848+
MachineBlockPlacementStats(const MachineBranchProbabilityInfo *MBPI,
3849+
const MachineBlockFrequencyInfo *MBFI)
3850+
: MBPI(MBPI), MBFI(MBFI) {}
3851+
bool run(MachineFunction &MF);
3852+
};
3853+
3854+
class MachineBlockPlacementStatsLegacy : public MachineFunctionPass {
38473855
public:
38483856
static char ID; // Pass identification, replacement for typeid
38493857

3850-
MachineBlockPlacementStats() : MachineFunctionPass(ID) {
3851-
initializeMachineBlockPlacementStatsPass(*PassRegistry::getPassRegistry());
3858+
MachineBlockPlacementStatsLegacy() : MachineFunctionPass(ID) {
3859+
initializeMachineBlockPlacementStatsLegacyPass(
3860+
*PassRegistry::getPassRegistry());
38523861
}
38533862

3854-
bool runOnMachineFunction(MachineFunction &F) override;
3863+
bool runOnMachineFunction(MachineFunction &F) override {
3864+
auto *MBPI =
3865+
&getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
3866+
auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
3867+
return MachineBlockPlacementStats(MBPI, MBFI).run(F);
3868+
}
38553869

38563870
void getAnalysisUsage(AnalysisUsage &AU) const override {
38573871
AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
@@ -3863,28 +3877,35 @@ class MachineBlockPlacementStats : public MachineFunctionPass {
38633877

38643878
} // end anonymous namespace
38653879

3866-
char MachineBlockPlacementStats::ID = 0;
3880+
char MachineBlockPlacementStatsLegacy::ID = 0;
38673881

3868-
char &llvm::MachineBlockPlacementStatsID = MachineBlockPlacementStats::ID;
3882+
char &llvm::MachineBlockPlacementStatsID = MachineBlockPlacementStatsLegacy::ID;
38693883

3870-
INITIALIZE_PASS_BEGIN(MachineBlockPlacementStats, "block-placement-stats",
3884+
INITIALIZE_PASS_BEGIN(MachineBlockPlacementStatsLegacy, "block-placement-stats",
38713885
"Basic Block Placement Stats", false, false)
38723886
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
38733887
INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfoWrapperPass)
3874-
INITIALIZE_PASS_END(MachineBlockPlacementStats, "block-placement-stats",
3888+
INITIALIZE_PASS_END(MachineBlockPlacementStatsLegacy, "block-placement-stats",
38753889
"Basic Block Placement Stats", false, false)
38763890

3877-
bool MachineBlockPlacementStats::runOnMachineFunction(MachineFunction &F) {
3891+
PreservedAnalyses
3892+
MachineBlockPlacementStatsPass::run(MachineFunction &MF,
3893+
MachineFunctionAnalysisManager &MFAM) {
3894+
auto &MBPI = MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
3895+
auto &MBFI = MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
3896+
3897+
MachineBlockPlacementStats(&MBPI, &MBFI).run(MF);
3898+
return PreservedAnalyses::all();
3899+
}
3900+
3901+
bool MachineBlockPlacementStats::run(MachineFunction &F) {
38783902
// Check for single-block functions and skip them.
38793903
if (std::next(F.begin()) == F.end())
38803904
return false;
38813905

38823906
if (!isFunctionInPrintList(F.getName()))
38833907
return false;
38843908

3885-
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
3886-
MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
3887-
38883909
for (MachineBasicBlock &MBB : F) {
38893910
BlockFrequency BlockFreq = MBFI->getBlockFreq(&MBB);
38903911
Statistic &NumBranches =

0 commit comments

Comments
 (0)