Skip to content

[CodeGen][NewPM] Port machine post dominator tree analysis to new pass manager #96378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions llvm/include/llvm/CodeGen/MachinePostDominators.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/Passes/MachinePassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down
28 changes: 28 additions & 0 deletions llvm/lib/CodeGen/MachinePostDominators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading