[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port MachineCSE pass to new pass manager. (PR #106605)
Christudasan Devadasan via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Aug 29 12:00:49 PDT 2024
================
@@ -932,18 +935,55 @@ bool MachineCSE::isProfitableToHoistInto(MachineBasicBlock *CandidateBB,
MBFI->getBlockFreq(MBB) + MBFI->getBlockFreq(MBB1);
}
-bool MachineCSE::runOnMachineFunction(MachineFunction &MF) {
- if (skipFunction(MF.getFunction()))
- return false;
+void MachineCSEImpl::releaseMemory() {
+ ScopeMap.clear();
+ PREMap.clear();
+ Exps.clear();
+}
+bool MachineCSEImpl::run(MachineFunction &MF) {
TII = MF.getSubtarget().getInstrInfo();
TRI = MF.getSubtarget().getRegisterInfo();
MRI = &MF.getRegInfo();
- DT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
- MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
LookAheadLimit = TII->getMachineCSELookAheadLimit();
bool ChangedPRE, ChangedCSE;
ChangedPRE = PerformSimplePRE(DT);
ChangedCSE = PerformCSE(DT->getRootNode());
+ releaseMemory();
return ChangedPRE || ChangedCSE;
}
+
+PreservedAnalyses MachineCSEPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+ MFPropsModifier _(*this, MF);
+
+ if (MF.getFunction().hasOptNone())
+ return PreservedAnalyses::all();
+
+ MachineDominatorTree &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
+ MachineBlockFrequencyInfo &MBFI =
+ MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
+ MachineCSEImpl Impl(&MDT, &MBFI);
+ bool Changed = Impl.run(MF);
+ if (!Changed)
+ return PreservedAnalyses::all();
+
+ auto PA = getMachineFunctionPassPreservedAnalyses();
+ PA.preserve<MachineLoopAnalysis>();
+ PA.preserve<MachineDominatorTreeAnalysis>();
----------------
cdevadas wrote:
Not sure about that. I have seen similar instances (DT being preserved along with the preserveSet) in other backend passes ported to NPM.
https://github.com/llvm/llvm-project/pull/106605
More information about the llvm-branch-commits
mailing list