From 1acb17cb8392dce33079fe45f383944ec6616757 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 2 Sep 2006 05:32:53 +0000 Subject: [PATCH] Iteration is required for some cases, even if they don't occur in crafty. Restore it, which re-fixes X86/2006-08-21-ExtraMovInst.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30050 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/LiveIntervalAnalysis.h | 18 ++++++++-- lib/CodeGen/LiveIntervalAnalysis.cpp | 37 +++++++++++++-------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/include/llvm/CodeGen/LiveIntervalAnalysis.h b/include/llvm/CodeGen/LiveIntervalAnalysis.h index 030b3cfea04..4b31766285b 100644 --- a/include/llvm/CodeGen/LiveIntervalAnalysis.h +++ b/include/llvm/CodeGen/LiveIntervalAnalysis.h @@ -53,6 +53,17 @@ namespace llvm { std::vector allocatableRegs_; public: + struct CopyRec { + MachineInstr *MI; + unsigned SrcReg, DstReg; + }; + CopyRec getCopyRec(MachineInstr *MI, unsigned SrcReg, unsigned DstReg) { + CopyRec R; + R.MI = MI; + R.SrcReg = SrcReg; + R.DstReg = DstReg; + return R; + } struct InstrSlots { enum { LOAD = 0, @@ -150,9 +161,10 @@ namespace llvm { /// joinIntervals - join compatible live intervals void joinIntervals(); - /// CopyCoallesceInMBB - Coallsece copies in the specified MBB. - void CopyCoallesceInMBB(MachineBasicBlock *MBB); - + /// CopyCoallesceInMBB - Coallsece copies in the specified MBB, putting + /// copies that cannot yet be coallesced into the "TryAgain" list. + void CopyCoallesceInMBB(MachineBasicBlock *MBB, + std::vector &TryAgain); /// JoinCopy - Attempt to join intervals corresponding to SrcReg/DstReg, /// which are the src/dst of the copy instruction CopyMI. This returns true /// if the copy was successfully coallesced away, or if it is never possible diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 5f010a6070a..fc9015ee999 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -883,12 +883,6 @@ static unsigned ComputeUltimateVN(unsigned VN, return ThisValNoAssignments[VN] = UltimateVN; } -Statistic<> A("x", "a"); -Statistic<> B("x", "b"); -Statistic<> C("x", "c"); -Statistic<> D("x", "d"); - - static bool InVector(unsigned Val, const SmallVector &V) { return std::find(V.begin(), V.end(), Val) != V.end(); } @@ -1048,13 +1042,11 @@ bool LiveIntervals::JoinIntervals(LiveInterval &LHS, LiveInterval &RHS) { } else { RHSValNoInfo = RHS.getValNumInfo(0); } - ++A; } else { // It was defined as a copy from the LHS, find out what value # it is. unsigned ValInst = RHS.getInstForValNum(0); RHSValID = LHS.getLiveRangeContaining(ValInst-1)->ValId; RHSValNoInfo = LHS.getValNumInfo(RHSValID); - ++B; } LHSValNoAssignments.resize(LHS.getNumValNums(), -1); @@ -1093,7 +1085,6 @@ bool LiveIntervals::JoinIntervals(LiveInterval &LHS, LiveInterval &RHS) { RHSValNoAssignments[0] = RHSValID; } else { - ++D; // Loop over the value numbers of the LHS, seeing if any are defined from // the RHS. SmallVector LHSValsDefinedFromRHS; @@ -1223,7 +1214,8 @@ namespace { } -void LiveIntervals::CopyCoallesceInMBB(MachineBasicBlock *MBB) { +void LiveIntervals::CopyCoallesceInMBB(MachineBasicBlock *MBB, + std::vector &TryAgain) { DEBUG(std::cerr << ((Value*)MBB->getBasicBlock())->getName() << ":\n"); for (MachineBasicBlock::iterator MII = MBB->begin(), E = MBB->end(); @@ -1234,7 +1226,8 @@ void LiveIntervals::CopyCoallesceInMBB(MachineBasicBlock *MBB) { unsigned SrcReg, DstReg; if (!tii_->isMoveInstr(*Inst, SrcReg, DstReg)) continue; - JoinCopy(Inst, SrcReg, DstReg); + if (!JoinCopy(Inst, SrcReg, DstReg)) + TryAgain.push_back(getCopyRec(Inst, SrcReg, DstReg)); } } @@ -1242,12 +1235,14 @@ void LiveIntervals::CopyCoallesceInMBB(MachineBasicBlock *MBB) { void LiveIntervals::joinIntervals() { DEBUG(std::cerr << "********** JOINING INTERVALS ***********\n"); + std::vector TryAgainList; + const LoopInfo &LI = getAnalysis(); if (LI.begin() == LI.end()) { // If there are no loops in the function, join intervals in function order. for (MachineFunction::iterator I = mf_->begin(), E = mf_->end(); I != E; ++I) - CopyCoallesceInMBB(I); + CopyCoallesceInMBB(I, TryAgainList); } else { // Otherwise, join intervals in inner loops before other intervals. // Unfortunately we can't just iterate over loop hierarchy here because @@ -1262,7 +1257,23 @@ void LiveIntervals::joinIntervals() { // Finally, join intervals in loop nest order. for (unsigned i = 0, e = MBBs.size(); i != e; ++i) - CopyCoallesceInMBB(MBBs[i].second); + CopyCoallesceInMBB(MBBs[i].second, TryAgainList); + } + + // Joining intervals can allow other intervals to be joined. Iteratively join + // until we make no progress. + bool ProgressMade = true; + while (ProgressMade) { + ProgressMade = false; + + for (unsigned i = 0, e = TryAgainList.size(); i != e; ++i) { + CopyRec &TheCopy = TryAgainList[i]; + if (TheCopy.MI && + JoinCopy(TheCopy.MI, TheCopy.SrcReg, TheCopy.DstReg)) { + TheCopy.MI = 0; // Mark this one as done. + ProgressMade = true; + } + } } DEBUG(std::cerr << "*** Register mapping ***\n");