[llvm] [CodeGen][NewPM] Port machine post dominator tree analysis to new pass manager (PR #96378)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 22 06:56:17 PDT 2024
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/96378
>From 92e27c8b3cd13b4a5e7f2df515d8286ad42b8456 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Tue, 18 Jun 2024 16:17:54 +0800
Subject: [PATCH] [CodeGen][NewPM] Port machine post dominator tree analysis to
new pass manager Follows #95879.
---
.../llvm/CodeGen/MachinePostDominators.h | 28 +++++++++++++++++++
.../llvm/Passes/MachinePassRegistry.def | 4 +++
llvm/lib/CodeGen/MachinePostDominators.cpp | 28 +++++++++++++++++++
llvm/lib/Passes/PassBuilder.cpp | 1 +
4 files changed, 61 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/MachinePostDominators.h b/llvm/include/llvm/CodeGen/MachinePostDominators.h
index c047e08266292..904c5fcdfc68b 100644
--- a/llvm/include/llvm/CodeGen/MachinePostDominators.h
+++ b/llvm/include/llvm/CodeGen/MachinePostDominators.h
@@ -49,6 +49,12 @@ class MachinePostDominatorTree : public PostDomTreeBase<MachineBasicBlock> {
public:
MachinePostDominatorTree() = default;
+ MachinePostDominatorTree(MachineFunction &MF) { recalculate(MF); }
+
+ /// Handle invalidation explicitly.
+ bool invalidate(MachineFunction &, const PreservedAnalyses &PA,
+ MachineFunctionAnalysisManager::Invalidator &);
+
/// Make findNearestCommonDominator(const NodeT *A, const NodeT *B) available.
using Base::findNearestCommonDominator;
@@ -58,6 +64,28 @@ class MachinePostDominatorTree : public PostDomTreeBase<MachineBasicBlock> {
findNearestCommonDominator(ArrayRef<MachineBasicBlock *> Blocks) const;
};
+class MachinePostDominatorTreeAnalysis
+ : public AnalysisInfoMixin<MachinePostDominatorTreeAnalysis> {
+ friend AnalysisInfoMixin<MachinePostDominatorTreeAnalysis>;
+
+ static AnalysisKey Key;
+
+public:
+ using Result = MachinePostDominatorTree;
+
+ Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
+};
+
+class MachinePostDominatorTreePrinterPass
+ : public PassInfoMixin<MachinePostDominatorTreePrinterPass> {
+ raw_ostream &OS;
+
+public:
+ MachinePostDominatorTreePrinterPass(raw_ostream &OS) : OS(OS) {}
+ PreservedAnalyses run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM);
+};
+
class MachinePostDominatorTreeWrapperPass : public MachineFunctionPass {
std::optional<MachinePostDominatorTree> PDT;
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index b989a1ee8306c..b43f41bb3097e 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -90,6 +90,8 @@ LOOP_PASS("loop-reduce", LoopStrengthReducePass())
#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS)
#endif
MACHINE_FUNCTION_ANALYSIS("machine-dom-tree", MachineDominatorTreeAnalysis())
+MACHINE_FUNCTION_ANALYSIS("machine-post-dom-tree",
+ MachinePostDominatorTreeAnalysis())
MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
// LiveVariables currently requires pure SSA form.
// FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
@@ -130,6 +132,8 @@ MACHINE_FUNCTION_PASS("no-op-machine-function", NoOpMachineFunctionPass())
MACHINE_FUNCTION_PASS("print", PrintMIRPass())
MACHINE_FUNCTION_PASS("print<machine-dom-tree>",
MachineDominatorTreePrinterPass(dbgs()))
+MACHINE_FUNCTION_PASS("print<machine-post-dom-tree>",
+ MachinePostDominatorTreePrinterPass(dbgs()))
MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
RequireAllMachineFunctionPropertiesPass())
MACHINE_FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
diff --git a/llvm/lib/CodeGen/MachinePostDominators.cpp b/llvm/lib/CodeGen/MachinePostDominators.cpp
index 8ba7c3180785c..51637130addc4 100644
--- a/llvm/lib/CodeGen/MachinePostDominators.cpp
+++ b/llvm/lib/CodeGen/MachinePostDominators.cpp
@@ -39,6 +39,23 @@ template bool Verify<MBBPostDomTree>(const MBBPostDomTree &DT,
extern bool VerifyMachineDomInfo;
} // namespace llvm
+AnalysisKey MachinePostDominatorTreeAnalysis::Key;
+
+MachinePostDominatorTreeAnalysis::Result
+MachinePostDominatorTreeAnalysis::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &) {
+ return MachinePostDominatorTree(MF);
+}
+
+PreservedAnalyses
+MachinePostDominatorTreePrinterPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+ OS << "MachinePostDominatorTree for machine function: " << MF.getName()
+ << '\n';
+ MFAM.getResult<MachinePostDominatorTreeAnalysis>(MF).print(OS);
+ return PreservedAnalyses::all();
+}
+
char MachinePostDominatorTreeWrapperPass::ID = 0;
//declare initializeMachinePostDominatorTreePass
@@ -64,6 +81,17 @@ void MachinePostDominatorTreeWrapperPass::getAnalysisUsage(
MachineFunctionPass::getAnalysisUsage(AU);
}
+bool MachinePostDominatorTree::invalidate(
+ MachineFunction &, const PreservedAnalyses &PA,
+ MachineFunctionAnalysisManager::Invalidator &) {
+ // Check whether the analysis, all analyses on machine functions, or the
+ // machine function's CFG have been preserved.
+ auto PAC = PA.getChecker<MachinePostDominatorTreeAnalysis>();
+ return !PAC.preserved() &&
+ !PAC.preservedSet<AllAnalysesOn<MachineFunction>>() &&
+ !PAC.preservedSet<CFGAnalyses>();
+}
+
MachineBasicBlock *MachinePostDominatorTree::findNearestCommonDominator(
ArrayRef<MachineBasicBlock *> Blocks) const {
assert(!Blocks.empty());
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index f819345f69b44..0dbcac0dd2f9d 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -96,6 +96,7 @@
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
#include "llvm/CodeGen/MachinePassManager.h"
+#include "llvm/CodeGen/MachinePostDominators.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
#include "llvm/CodeGen/RegAllocFast.h"
More information about the llvm-commits
mailing list