aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/StrongPHIElimination.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2008-06-04 17:55:58 +0000
committerOwen Anderson <resistor@mac.com>2008-06-04 17:55:58 +0000
commit38b425020b102716d58c0833ff9ef56bc1d750c4 (patch)
treed2154ef9cdc8621eab41b24f982a3c1e24f8f86f /lib/CodeGen/StrongPHIElimination.cpp
parent7a315e865ab676099c660fec0b6e65f763b97e39 (diff)
downloadexternal_llvm-38b425020b102716d58c0833ff9ef56bc1d750c4.zip
external_llvm-38b425020b102716d58c0833ff9ef56bc1d750c4.tar.gz
external_llvm-38b425020b102716d58c0833ff9ef56bc1d750c4.tar.bz2
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
Diffstat (limited to 'lib/CodeGen/StrongPHIElimination.cpp')
-rw-r--r--lib/CodeGen/StrongPHIElimination.cpp39
1 files changed, 38 insertions, 1 deletions
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<unsigned>& pushed) {
- // FIXME: This function needs to update LiveVariables
+ // FIXME: This function needs to update LiveIntervals
std::map<unsigned, unsigned>& copy_set= Waiting[MBB];
std::map<unsigned, unsigned> worklist;
@@ -661,6 +663,8 @@ void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB,
MachineRegisterInfo& MRI = MF->getRegInfo();
const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
+ SmallVector<std::pair<unsigned, MachineInstr*>, 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<unsigned, unsigned>::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<unsigned> RegHandled;
+ for (SmallVector<std::pair<unsigned, MachineInstr*>, 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