From e46611e6bc41bb6e7256e03b42b4796033167b91 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Mon, 24 Mar 2008 04:11:27 +0000 Subject: [PATCH] Be sure to remove intervals after we've joined them. Also, remove some duplicated code. With this pass, StrongPHIElim can compile very simple testcases correctly. There's still a ways to go before it's ready for prime time, though. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48719 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/StrongPHIElimination.cpp | 64 ++++++++-------------------- 1 file changed, 18 insertions(+), 46 deletions(-) diff --git a/lib/CodeGen/StrongPHIElimination.cpp b/lib/CodeGen/StrongPHIElimination.cpp index ca083e25376..81be6c21db8 100644 --- a/lib/CodeGen/StrongPHIElimination.cpp +++ b/lib/CodeGen/StrongPHIElimination.cpp @@ -136,7 +136,8 @@ namespace { std::vector& DF, std::vector >& locals); void ScheduleCopies(MachineBasicBlock* MBB, std::set& pushed); - void InsertCopies(MachineBasicBlock* MBB, std::set& v); + void InsertCopies(MachineBasicBlock* MBB, + SmallPtrSet& v); void mergeLiveIntervals(unsigned primary, unsigned secondary, unsigned VN); }; @@ -423,7 +424,7 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) { // is refinded over the course of this function. UnionedBlocks is the set // of corresponding MBBs. std::map PHIUnion; - std::set UnionedBlocks; + SmallPtrSet UnionedBlocks; // Iterate over the operands of the PHI node for (int i = P->getNumOperands() - 1; i >= 2; i-=2) { @@ -708,7 +709,7 @@ void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB, /// InsertCopies - insert copies into MBB and all of its successors void StrongPHIElimination::InsertCopies(MachineBasicBlock* MBB, - std::set& visited) { + SmallPtrSet& visited) { visited.insert(MBB); std::set pushed; @@ -789,9 +790,11 @@ static unsigned ComputeUltimateVN(VNInfo *VNI, return ThisValNoAssignments[VN] = UltimateVN; } +#include + void StrongPHIElimination::mergeLiveIntervals(unsigned primary, - unsigned secondary, unsigned secondaryVN) { - unsigned primaryVN = PhiValueNumber[primary]; + unsigned secondary, + unsigned secondaryVN) { LiveIntervals& LI = getAnalysis(); LiveInterval& LHS = LI.getOrCreateInterval(primary); @@ -805,44 +808,6 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary, DenseMap RHSValsDefinedFromLHS; SmallVector NewVNInfo; - LHSValNoAssignments.resize(LHS.getNumValNums(), -1); - RHSValNoAssignments.resize(RHS.getNumValNums(), -1); - NewVNInfo.resize(LHS.getNumValNums(), NULL); - - // Loop over the value numbers of the LHS, seeing if any are defined from - // the RHS. - for (LiveInterval::vni_iterator I = LHS.vni_begin(), E = LHS.vni_end(); - I != E; ++E) { - VNInfo *VNI = *I; - if (VNI->def == ~1U || VNI->copy == 0) // Src not defined by a copy? - continue; - - // DstReg is known to be a register in the LHS interval. If the src is - // from the RHS interval, we can use its value #. - if (LI.getVNInfoSourceReg(VNI) != RHS.reg) - continue; - - // Figure out the value # from the RHS. - LHSValsDefinedFromRHS[VNI]=RHS.getLiveRangeContaining(VNI->def-1)->valno; - } - - // Loop over the value numbers of the RHS, seeing if any are defined from - // the LHS. - for (LiveInterval::vni_iterator i = RHS.vni_begin(), e = RHS.vni_end(); - i != e; ++i) { - VNInfo *VNI = *i; - if (VNI->def == ~1U || VNI->copy == 0) // Src not defined by a copy? - continue; - - // DstReg is known to be a register in the RHS interval. If the src is - // from the LHS interval, we can use its value #. - if (LI.getVNInfoSourceReg(VNI) != LHS.reg) - continue; - - // Figure out the value # from the LHS. - RHSValsDefinedFromLHS[VNI]=LHS.getLiveRangeContaining(VNI->def-1)->valno; - } - LHSValNoAssignments.resize(LHS.getNumValNums(), -1); RHSValNoAssignments.resize(RHS.getNumValNums(), -1); NewVNInfo.reserve(LHS.getNumValNums() + RHS.getNumValNums()); @@ -898,7 +863,8 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary, // Use the VNInfo we collected earlier to ensure that the phi copy is // merged correctly. - RHSValNoAssignments[secondaryVN] = primaryVN; + // FIXME: This is not working correctly yet. + // RHSValNoAssignments[secondaryVN] = primaryVN; // If we get here, we know that we can coalesce the live ranges. Ask the // intervals to coalesce themselves now. @@ -906,8 +872,10 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary, TargetRegisterInfo::isVirtualRegister(LHS.reg)) || TargetRegisterInfo::isPhysicalRegister(RHS.reg)) { RHS.join(LHS, &RHSValNoAssignments[0], &LHSValNoAssignments[0], NewVNInfo); + LI.removeInterval(primary); } else { LHS.join(RHS, &LHSValNoAssignments[0], &RHSValNoAssignments[0], NewVNInfo); + LI.removeInterval(secondary); } } @@ -923,7 +891,7 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) { // Insert copies // FIXME: This process should probably preserve LiveVariables - std::set visited; + SmallPtrSet visited; InsertCopies(Fn.begin(), visited); // Perform renaming @@ -947,9 +915,13 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) { phis.push_back(BI); } + LiveIntervals& LI = getAnalysis(); + for (std::vector::iterator I = phis.begin(), E = phis.end(); - I != E; ++I) + I != E; ++I) { + LI.RemoveMachineInstrFromMaps(*I); (*I)->eraseFromParent(); + } return false; }