aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LiveVariables.cpp
diff options
context:
space:
mode:
authorpaperchalice <liujunchang97@outlook.com>2024-07-09 10:50:43 +0800
committerGitHub <noreply@github.com>2024-07-09 10:50:43 +0800
commitac0b2814c34959ebaa8f054db019bd287fdff54d (patch)
tree9e1b742258464c471c2b869c7ab694ba280e6db1 /llvm/lib/CodeGen/LiveVariables.cpp
parent366eb8f025f03f00ed1188dccfd3d527b8c82892 (diff)
downloadllvm-ac0b2814c34959ebaa8f054db019bd287fdff54d.zip
llvm-ac0b2814c34959ebaa8f054db019bd287fdff54d.tar.gz
llvm-ac0b2814c34959ebaa8f054db019bd287fdff54d.tar.bz2
[CodeGen][NewPM] Port `LiveVariables` to new pass manager (#97880)
- Port `LiveVariables` to new pass manager. - Convert to `LiveVariablesWrapperPass` in legacy pass manager.
Diffstat (limited to 'llvm/lib/CodeGen/LiveVariables.cpp')
-rw-r--r--llvm/lib/CodeGen/LiveVariables.cpp66
1 files changed, 47 insertions, 19 deletions
diff --git a/llvm/lib/CodeGen/LiveVariables.cpp b/llvm/lib/CodeGen/LiveVariables.cpp
index f44db57..f17d60dc 100644
--- a/llvm/lib/CodeGen/LiveVariables.cpp
+++ b/llvm/lib/CodeGen/LiveVariables.cpp
@@ -41,21 +41,49 @@
#include <algorithm>
using namespace llvm;
-char LiveVariables::ID = 0;
-char &llvm::LiveVariablesID = LiveVariables::ID;
-INITIALIZE_PASS_BEGIN(LiveVariables, "livevars",
- "Live Variable Analysis", false, false)
-INITIALIZE_PASS_DEPENDENCY(UnreachableMachineBlockElim)
-INITIALIZE_PASS_END(LiveVariables, "livevars",
- "Live Variable Analysis", false, false)
+AnalysisKey LiveVariablesAnalysis::Key;
+
+LiveVariablesAnalysis::Result
+LiveVariablesAnalysis::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &) {
+ return Result(MF);
+}
+
+PreservedAnalyses
+LiveVariablesPrinterPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+ OS << "Live variables in machine function: " << MF.getName() << '\n';
+ MFAM.getResult<LiveVariablesAnalysis>(MF).print(OS);
+ return PreservedAnalyses::all();
+}
+char LiveVariablesWrapperPass::ID = 0;
+char &llvm::LiveVariablesID = LiveVariablesWrapperPass::ID;
+INITIALIZE_PASS_BEGIN(LiveVariablesWrapperPass, "livevars",
+ "Live Variable Analysis", false, false)
+INITIALIZE_PASS_DEPENDENCY(UnreachableMachineBlockElim)
+INITIALIZE_PASS_END(LiveVariablesWrapperPass, "livevars",
+ "Live Variable Analysis", false, false)
-void LiveVariables::getAnalysisUsage(AnalysisUsage &AU) const {
+void LiveVariablesWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequiredID(UnreachableMachineBlockElimID);
AU.setPreservesAll();
MachineFunctionPass::getAnalysisUsage(AU);
}
+LiveVariables::LiveVariables(MachineFunction &MF)
+ : MF(&MF), MRI(&MF.getRegInfo()), TRI(MF.getSubtarget().getRegisterInfo()) {
+ analyze(MF);
+}
+
+void LiveVariables::print(raw_ostream &OS) const {
+ for (size_t I = 0, E = VirtRegInfo.size(); I != E; ++I) {
+ const Register Reg = Register::index2VirtReg(I);
+ OS << "Virtual register '%" << I << "':\n";
+ VirtRegInfo[Reg].print(OS);
+ }
+}
+
MachineInstr *
LiveVariables::VarInfo::findKill(const MachineBasicBlock *MBB) const {
for (MachineInstr *MI : Kills)
@@ -64,20 +92,22 @@ LiveVariables::VarInfo::findKill(const MachineBasicBlock *MBB) const {
return nullptr;
}
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-LLVM_DUMP_METHOD void LiveVariables::VarInfo::dump() const {
- dbgs() << " Alive in blocks: ";
+void LiveVariables::VarInfo::print(raw_ostream &OS) const {
+ OS << " Alive in blocks: ";
for (unsigned AB : AliveBlocks)
- dbgs() << AB << ", ";
- dbgs() << "\n Killed by:";
+ OS << AB << ", ";
+ OS << "\n Killed by:";
if (Kills.empty())
- dbgs() << " No instructions.\n";
+ OS << " No instructions.\n\n";
else {
for (unsigned i = 0, e = Kills.size(); i != e; ++i)
- dbgs() << "\n #" << i << ": " << *Kills[i];
- dbgs() << "\n";
+ OS << "\n #" << i << ": " << *Kills[i];
+ OS << "\n";
}
}
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void LiveVariables::VarInfo::dump() const { print(dbgs()); }
#endif
/// getVarInfo - Get (possibly creating) a VarInfo object for the given vreg.
@@ -595,7 +625,7 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
HandlePhysRegDef(i, nullptr, Defs);
}
-bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
+void LiveVariables::analyze(MachineFunction &mf) {
MF = &mf;
MRI = &mf.getRegInfo();
TRI = MF->getSubtarget().getRegisterInfo();
@@ -649,8 +679,6 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
PhysRegDef.clear();
PhysRegUse.clear();
PHIVarInfo.clear();
-
- return false;
}
void LiveVariables::recomputeForSingleDefVirtReg(Register Reg) {