From 2c7ece2e8cf58d607f870ca9f02302df8aaa75d4 Mon Sep 17 00:00:00 2001 From: Akshat Oke Date: Fri, 6 Dec 2024 15:16:07 +0530 Subject: [CodeGen][NewPM] Port LiveStacks analysis to NPM (#118778) --- llvm/lib/CodeGen/CodeGen.cpp | 2 +- llvm/lib/CodeGen/InlineSpiller.cpp | 4 +-- llvm/lib/CodeGen/LiveStacks.cpp | 45 +++++++++++++++++++++++++++------- llvm/lib/CodeGen/MachineVerifier.cpp | 5 ++-- llvm/lib/CodeGen/RegAllocBasic.cpp | 6 ++--- llvm/lib/CodeGen/RegAllocGreedy.cpp | 6 ++--- llvm/lib/CodeGen/RegAllocPBQP.cpp | 6 ++--- llvm/lib/CodeGen/StackSlotColoring.cpp | 6 ++--- llvm/lib/CodeGen/VirtRegMap.cpp | 6 ++--- 9 files changed, 57 insertions(+), 29 deletions(-) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp index 5942881..8efe540 100644 --- a/llvm/lib/CodeGen/CodeGen.cpp +++ b/llvm/lib/CodeGen/CodeGen.cpp @@ -62,7 +62,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) { initializeLiveDebugVariablesWrapperLegacyPass(Registry); initializeLiveIntervalsWrapperPassPass(Registry); initializeLiveRangeShrinkPass(Registry); - initializeLiveStacksPass(Registry); + initializeLiveStacksWrapperLegacyPass(Registry); initializeLiveVariablesWrapperPassPass(Registry); initializeLocalStackSlotPassPass(Registry); initializeLowerGlobalDtorsLegacyPassPass(Registry); diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp index e8f7c68..64f290f 100644 --- a/llvm/lib/CodeGen/InlineSpiller.cpp +++ b/llvm/lib/CodeGen/InlineSpiller.cpp @@ -131,7 +131,7 @@ public: HoistSpillHelper(MachineFunctionPass &pass, MachineFunction &mf, VirtRegMap &vrm) : MF(mf), LIS(pass.getAnalysis().getLIS()), - LSS(pass.getAnalysis()), + LSS(pass.getAnalysis().getLS()), MDT(pass.getAnalysis().getDomTree()), VRM(vrm), MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()), TRI(*mf.getSubtarget().getRegisterInfo()), @@ -193,7 +193,7 @@ public: InlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, VirtRegMap &VRM, VirtRegAuxInfo &VRAI) : MF(MF), LIS(Pass.getAnalysis().getLIS()), - LSS(Pass.getAnalysis()), + LSS(Pass.getAnalysis().getLS()), MDT(Pass.getAnalysis().getDomTree()), VRM(VRM), MRI(MF.getRegInfo()), TII(*MF.getSubtarget().getInstrInfo()), TRI(*MF.getSubtarget().getRegisterInfo()), diff --git a/llvm/lib/CodeGen/LiveStacks.cpp b/llvm/lib/CodeGen/LiveStacks.cpp index 6228a4d..92cc669 100644 --- a/llvm/lib/CodeGen/LiveStacks.cpp +++ b/llvm/lib/CodeGen/LiveStacks.cpp @@ -15,20 +15,21 @@ #include "llvm/CodeGen/LiveStacks.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/IR/Function.h" using namespace llvm; #define DEBUG_TYPE "livestacks" -char LiveStacks::ID = 0; -INITIALIZE_PASS_BEGIN(LiveStacks, DEBUG_TYPE, - "Live Stack Slot Analysis", false, false) +char LiveStacksWrapperLegacy::ID = 0; +INITIALIZE_PASS_BEGIN(LiveStacksWrapperLegacy, DEBUG_TYPE, + "Live Stack Slot Analysis", false, false) INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass) -INITIALIZE_PASS_END(LiveStacks, DEBUG_TYPE, - "Live Stack Slot Analysis", false, false) +INITIALIZE_PASS_END(LiveStacksWrapperLegacy, DEBUG_TYPE, + "Live Stack Slot Analysis", false, false) -char &llvm::LiveStacksID = LiveStacks::ID; +char &llvm::LiveStacksID = LiveStacksWrapperLegacy::ID; -void LiveStacks::getAnalysisUsage(AnalysisUsage &AU) const { +void LiveStacksWrapperLegacy::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addPreserved(); AU.addRequiredTransitive(); @@ -42,11 +43,10 @@ void LiveStacks::releaseMemory() { S2RCMap.clear(); } -bool LiveStacks::runOnMachineFunction(MachineFunction &MF) { +void LiveStacks::init(MachineFunction &MF) { TRI = MF.getSubtarget().getRegisterInfo(); // FIXME: No analysis is being done right now. We are relying on the // register allocators to provide the information. - return false; } LiveInterval & @@ -68,6 +68,33 @@ LiveStacks::getOrCreateInterval(int Slot, const TargetRegisterClass *RC) { return I->second; } +AnalysisKey LiveStacksAnalysis::Key; + +LiveStacks LiveStacksAnalysis::run(MachineFunction &MF, + MachineFunctionAnalysisManager &) { + LiveStacks Impl; + Impl.init(MF); + return Impl; +} +PreservedAnalyses +LiveStacksPrinterPass::run(MachineFunction &MF, + MachineFunctionAnalysisManager &AM) { + AM.getResult(MF).print(OS, MF.getFunction().getParent()); + return PreservedAnalyses::all(); +} + +bool LiveStacksWrapperLegacy::runOnMachineFunction(MachineFunction &MF) { + Impl = LiveStacks(); + Impl.init(MF); + return false; +} + +void LiveStacksWrapperLegacy::releaseMemory() { Impl = LiveStacks(); } + +void LiveStacksWrapperLegacy::print(raw_ostream &OS, const Module *) const { + Impl.print(OS); +} + /// print - Implement the dump method. void LiveStacks::print(raw_ostream &OS, const Module*) const { diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp index 8e64e40..fb4d96f 100644 --- a/llvm/lib/CodeGen/MachineVerifier.cpp +++ b/llvm/lib/CodeGen/MachineVerifier.cpp @@ -369,7 +369,7 @@ struct MachineVerifierLegacyPass : public MachineFunctionPass { } void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addUsedIfAvailable(); + AU.addUsedIfAvailable(); AU.addUsedIfAvailable(); AU.addUsedIfAvailable(); AU.addUsedIfAvailable(); @@ -491,7 +491,8 @@ bool MachineVerifier::verify(const MachineFunction &MF) { auto *LVWrapper = PASS->getAnalysisIfAvailable(); if (!LiveInts) LiveVars = LVWrapper ? &LVWrapper->getLV() : nullptr; - LiveStks = PASS->getAnalysisIfAvailable(); + auto *LSWrapper = PASS->getAnalysisIfAvailable(); + LiveStks = LSWrapper ? &LSWrapper->getLS() : nullptr; auto *SIWrapper = PASS->getAnalysisIfAvailable(); Indexes = SIWrapper ? &SIWrapper->getSI() : nullptr; } diff --git a/llvm/lib/CodeGen/RegAllocBasic.cpp b/llvm/lib/CodeGen/RegAllocBasic.cpp index 7ee24c9..c05aa1e 100644 --- a/llvm/lib/CodeGen/RegAllocBasic.cpp +++ b/llvm/lib/CodeGen/RegAllocBasic.cpp @@ -135,7 +135,7 @@ INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass) INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass) INITIALIZE_PASS_DEPENDENCY(RegisterCoalescer) INITIALIZE_PASS_DEPENDENCY(MachineScheduler) -INITIALIZE_PASS_DEPENDENCY(LiveStacks) +INITIALIZE_PASS_DEPENDENCY(LiveStacksWrapperLegacy) INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass) @@ -182,8 +182,8 @@ void RABasic::getAnalysisUsage(AnalysisUsage &AU) const { AU.addPreserved(); AU.addRequired(); AU.addPreserved(); - AU.addRequired(); - AU.addPreserved(); + AU.addRequired(); + AU.addPreserved(); AU.addRequired(); AU.addRequired(); AU.addPreserved(); diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp index 8564fd8..cb29218 100644 --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -156,7 +156,7 @@ INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass) INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass) INITIALIZE_PASS_DEPENDENCY(RegisterCoalescer) INITIALIZE_PASS_DEPENDENCY(MachineScheduler) -INITIALIZE_PASS_DEPENDENCY(LiveStacks) +INITIALIZE_PASS_DEPENDENCY(LiveStacksWrapperLegacy) INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy) @@ -206,8 +206,8 @@ void RAGreedy::getAnalysisUsage(AnalysisUsage &AU) const { AU.addPreserved(); AU.addRequired(); AU.addPreserved(); - AU.addRequired(); - AU.addPreserved(); + AU.addRequired(); + AU.addPreserved(); AU.addRequired(); AU.addPreserved(); AU.addRequired(); diff --git a/llvm/lib/CodeGen/RegAllocPBQP.cpp b/llvm/lib/CodeGen/RegAllocPBQP.cpp index 261e93a..696c312 100644 --- a/llvm/lib/CodeGen/RegAllocPBQP.cpp +++ b/llvm/lib/CodeGen/RegAllocPBQP.cpp @@ -121,7 +121,7 @@ public: : MachineFunctionPass(ID), customPassID(cPassID) { initializeSlotIndexesWrapperPassPass(*PassRegistry::getPassRegistry()); initializeLiveIntervalsWrapperPassPass(*PassRegistry::getPassRegistry()); - initializeLiveStacksPass(*PassRegistry::getPassRegistry()); + initializeLiveStacksWrapperLegacyPass(*PassRegistry::getPassRegistry()); initializeVirtRegMapWrapperLegacyPass(*PassRegistry::getPassRegistry()); } @@ -550,8 +550,8 @@ void RegAllocPBQP::getAnalysisUsage(AnalysisUsage &au) const { //au.addRequiredID(SplitCriticalEdgesID); if (customPassID) au.addRequiredID(*customPassID); - au.addRequired(); - au.addPreserved(); + au.addRequired(); + au.addPreserved(); au.addRequired(); au.addPreserved(); au.addRequired(); diff --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp index cdc5306..4dc5dc8 100644 --- a/llvm/lib/CodeGen/StackSlotColoring.cpp +++ b/llvm/lib/CodeGen/StackSlotColoring.cpp @@ -149,7 +149,7 @@ namespace { AU.setPreservesCFG(); AU.addRequired(); AU.addPreserved(); - AU.addRequired(); + AU.addRequired(); AU.addRequired(); AU.addPreserved(); AU.addPreservedID(MachineDominatorsID); @@ -185,7 +185,7 @@ char &llvm::StackSlotColoringID = StackSlotColoring::ID; INITIALIZE_PASS_BEGIN(StackSlotColoring, DEBUG_TYPE, "Stack Slot Coloring", false, false) INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass) -INITIALIZE_PASS_DEPENDENCY(LiveStacks) +INITIALIZE_PASS_DEPENDENCY(LiveStacksWrapperLegacy) INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass) INITIALIZE_PASS_END(StackSlotColoring, DEBUG_TYPE, "Stack Slot Coloring", false, false) @@ -522,7 +522,7 @@ bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) { MFI = &MF.getFrameInfo(); TII = MF.getSubtarget().getInstrInfo(); - LS = &getAnalysis(); + LS = &getAnalysis().getLS(); MBFI = &getAnalysis().getMBFI(); Indexes = &getAnalysis().getSI(); diff --git a/llvm/lib/CodeGen/VirtRegMap.cpp b/llvm/lib/CodeGen/VirtRegMap.cpp index 2084e68..1352102 100644 --- a/llvm/lib/CodeGen/VirtRegMap.cpp +++ b/llvm/lib/CodeGen/VirtRegMap.cpp @@ -253,7 +253,7 @@ INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass) INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass) INITIALIZE_PASS_DEPENDENCY(LiveDebugVariablesWrapperLegacy) INITIALIZE_PASS_DEPENDENCY(LiveRegMatrixWrapperLegacy) -INITIALIZE_PASS_DEPENDENCY(LiveStacks) +INITIALIZE_PASS_DEPENDENCY(LiveStacksWrapperLegacy) INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy) INITIALIZE_PASS_END(VirtRegRewriter, "virtregrewriter", "Virtual Register Rewriter", false, false) @@ -265,8 +265,8 @@ void VirtRegRewriter::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); AU.addPreserved(); AU.addRequired(); - AU.addRequired(); - AU.addPreserved(); + AU.addRequired(); + AU.addPreserved(); AU.addRequired(); AU.addRequired(); -- cgit v1.1