From 38b425020b102716d58c0833ff9ef56bc1d750c4 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Wed, 4 Jun 2008 17:55:58 +0000 Subject: Correctly construct live intervals for the copies we inserted into the predecessors of a block containing a PHI. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51950 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/StrongPHIElimination.cpp | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/StrongPHIElimination.cpp') diff --git a/lib/CodeGen/StrongPHIElimination.cpp b/lib/CodeGen/StrongPHIElimination.cpp index ab95387..5abab30 100644 --- a/lib/CodeGen/StrongPHIElimination.cpp +++ b/lib/CodeGen/StrongPHIElimination.cpp @@ -467,6 +467,8 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) { } else { // Otherwise, add it to the renaming set LiveInterval& I = LI.getOrCreateInterval(SrcReg); + // 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; VNInfo* VN = I.getLiveRangeContaining(idx)->valno; @@ -632,7 +634,7 @@ void StrongPHIElimination::processPHIUnion(MachineInstr* Inst, /// of Static Single Assignment Form" by Briggs, et al. void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB, std::set& pushed) { - // FIXME: This function needs to update LiveVariables + // FIXME: This function needs to update LiveIntervals std::map& copy_set= Waiting[MBB]; std::map worklist; @@ -661,6 +663,8 @@ void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB, MachineRegisterInfo& MRI = MF->getRegInfo(); const TargetInstrInfo *TII = MF->getTarget().getInstrInfo(); + SmallVector, 4> InsertedPHIDests; + // Iterate over the worklist, inserting copies while (!worklist.empty() || !copy_set.empty()) { while (!worklist.empty()) { @@ -691,6 +695,11 @@ void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB, map[curr.first], RC, RC); map[curr.first] = curr.second; + // Push this copy onto InsertedPHICopies so we can + // update LiveIntervals with it. + MachineBasicBlock::iterator MI = MBB->getFirstTerminator(); + InsertedPHIDests.push_back(std::make_pair(curr.second, --MI)); + // If curr.first is a destination in copy_set... for (std::map::iterator I = copy_set.begin(), E = copy_set.end(); I != E; ) @@ -723,6 +732,34 @@ void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB, worklist.insert(curr); } } + + // Renumber the instructions so that we can perform the index computations + // needed to create new live intervals. + LI.computeNumbering(); + + // For copies that we inserted at the ends of predecessors, we construct + // live intervals. This is pretty easy, since we know that the destination + // register cannot have be in live at that point previously. We just have + // to make sure that, for registers that serve as inputs to more than one + // PHI, we don't create multiple overlapping live intervals. + std::set RegHandled; + for (SmallVector, 4>::iterator I = + InsertedPHIDests.begin(), E = InsertedPHIDests.end(); I != E; ++I) { + if (!RegHandled.count(I->first)) { + LiveInterval& Interval = LI.getOrCreateInterval(I->first); + VNInfo* VN = Interval.getNextValue( + LI.getInstructionIndex(I->second) + LiveIntervals::InstrSlots::DEF, + I->second, LI.getVNInfoAllocator()); + VN->hasPHIKill = true; + VN->kills.push_back(LI.getMBBEndIdx(I->second->getParent())); + LiveRange LR(LI.getInstructionIndex(I->second) + + LiveIntervals::InstrSlots::DEF, + LI.getMBBEndIdx(I->second->getParent()) + 1, VN); + Interval.addRange(LR); + + RegHandled.insert(I->first); + } + } } /// InsertCopies - insert copies into MBB and all of its successors -- cgit v1.1