From: Owen Anderson Date: Thu, 24 Jul 2008 17:12:16 +0000 (+0000) Subject: Store the predecessor MBB in the PHIUnion, rather than an index, since the indices... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c12417edc9fe88918e09b58716bdb26bd9618239;p=oota-llvm.git Store the predecessor MBB in the PHIUnion, rather than an index, since the indices will change after renumbering. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53985 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/StrongPHIElimination.cpp b/lib/CodeGen/StrongPHIElimination.cpp index 5267d91d44e..a2bb8185111 100644 --- a/lib/CodeGen/StrongPHIElimination.cpp +++ b/lib/CodeGen/StrongPHIElimination.cpp @@ -53,9 +53,9 @@ namespace { std::set UsedByAnother; // RenameSets are the is a map from a PHI-defined register - // to the input registers to be coalesced along with the index - // of the input registers. - std::map > RenameSets; + // to the input registers to be coalesced along with the + // predecessor block for those input registers. + std::map > RenameSets; // PhiValueNumber holds the ID numbers of the VNs for each phi that we're // eliminating, indexed by the register defined by that phi. @@ -131,16 +131,18 @@ namespace { void computeDFS(MachineFunction& MF); void processBlock(MachineBasicBlock* MBB); - std::vector computeDomForest(std::map& instrs, + std::vector computeDomForest( + std::map& instrs, MachineRegisterInfo& MRI); void processPHIUnion(MachineInstr* Inst, - std::map& PHIUnion, + std::map& PHIUnion, std::vector& DF, std::vector >& locals); void ScheduleCopies(MachineBasicBlock* MBB, std::set& pushed); void InsertCopies(MachineBasicBlock* MBB, SmallPtrSet& v); - void mergeLiveIntervals(unsigned primary, unsigned secondary, unsigned VN); + void mergeLiveIntervals(unsigned primary, unsigned secondary, + MachineBasicBlock* pred); }; } @@ -229,7 +231,8 @@ public: /// computeDomForest - compute the subforest of the DomTree corresponding /// to the defining blocks of the registers in question std::vector -StrongPHIElimination::computeDomForest(std::map& regs, +StrongPHIElimination::computeDomForest( + std::map& regs, MachineRegisterInfo& MRI) { // Begin by creating a virtual root node, since the actual results // may well be a forest. Assume this node has maximum DFS-out number. @@ -239,8 +242,8 @@ StrongPHIElimination::computeDomForest(std::map& regs, // Populate a worklist with the registers std::vector worklist; worklist.reserve(regs.size()); - for (std::map::iterator I = regs.begin(), E = regs.end(); - I != E; ++I) + for (std::map::iterator I = regs.begin(), + E = regs.end(); I != E; ++I) worklist.push_back(I->first); // Sort the registers by the DFS-in number of their defining block @@ -433,7 +436,7 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) { // are going to be renames rather than having copies inserted. This set // is refinded over the course of this function. UnionedBlocks is the set // of corresponding MBBs. - std::map PHIUnion; + std::map PHIUnion; SmallPtrSet UnionedBlocks; // Iterate over the operands of the PHI node @@ -467,11 +470,7 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) { UsedByAnother.insert(SrcReg); } else { // Otherwise, add it to the renaming set - // We need to subtract one from the index because live ranges are open - // at the end. - unsigned idx = LI.getMBBEndIdx(P->getOperand(i).getMBB()) - 1; - - PHIUnion.insert(std::make_pair(SrcReg, idx)); + PHIUnion.insert(std::make_pair(SrcReg,P->getOperand(i).getMBB())); UnionedBlocks.insert(MRI.getVRegDef(SrcReg)->getParent()); } } @@ -491,7 +490,7 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) { // If one of the inputs is defined in the same block as the current PHI // then we need to check for a local interference between that input and // the PHI. - for (std::map::iterator I = PHIUnion.begin(), + for (std::map::iterator I = PHIUnion.begin(), E = PHIUnion.end(); I != E; ++I) if (MRI.getVRegDef(I->first)->getParent() == P->getParent()) localInterferences.push_back(std::make_pair(I->first, @@ -546,7 +545,7 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) { // Remember which registers are already renamed, so that we don't try to // rename them for another PHI node in this block - for (std::map::iterator I = PHIUnion.begin(), + for (std::map::iterator I = PHIUnion.begin(), E = PHIUnion.end(); I != E; ++I) ProcessedNames.insert(I->first); @@ -559,7 +558,7 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) { /// that are known to interfere, and flag others that need to be checked for /// local interferences. void StrongPHIElimination::processPHIUnion(MachineInstr* Inst, - std::map& PHIUnion, + std::map& PHIUnion, std::vector& DF, std::vector >& locals) { @@ -780,7 +779,7 @@ void StrongPHIElimination::InsertCopies(MachineBasicBlock* MBB, void StrongPHIElimination::mergeLiveIntervals(unsigned primary, unsigned secondary, - unsigned secondaryIdx) { + MachineBasicBlock* pred) { LiveIntervals& LI = getAnalysis(); LiveInterval& LHS = LI.getOrCreateInterval(primary); @@ -788,13 +787,15 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary, LI.computeNumbering(); - const LiveRange* RangeMergingIn = RHS.getLiveRangeContaining(secondaryIdx); - VNInfo* NewVN = LHS.getNextValue(secondaryIdx, RangeMergingIn->valno->copy, - LI.getVNInfoAllocator()); + const LiveRange* RangeMergingIn = + RHS.getLiveRangeContaining(LI.getMBBEndIdx(pred)); + VNInfo* NewVN = LHS.getNextValue(RangeMergingIn->valno->def, + RangeMergingIn->valno->copy, + LI.getVNInfoAllocator()); NewVN->hasPHIKill = true; LiveRange NewRange(RangeMergingIn->start, RangeMergingIn->end, NewVN); - LHS.addRange(NewRange); RHS.removeRange(RangeMergingIn->start, RangeMergingIn->end, true); + LHS.addRange(NewRange); } bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) { @@ -815,11 +816,12 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) { InsertCopies(Fn.begin(), visited); // Perform renaming - typedef std::map > RenameSetType; + typedef std::map > + RenameSetType; for (RenameSetType::iterator I = RenameSets.begin(), E = RenameSets.end(); I != E; ++I) - for (std::map::iterator SI = I->second.begin(), - SE = I->second.end(); SI != SE; ++SI) { + for (std::map::iterator SI = + I->second.begin(), SE = I->second.end(); SI != SE; ++SI) { mergeLiveIntervals(I->first, SI->first, SI->second); Fn.getRegInfo().replaceRegWith(SI->first, I->first); }