mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-12 16:25:18 +00:00
Keep track of phi join registers explicitly in LiveVariables.
Previously, LiveIntervalAnalysis would infer phi joins by looking for multiply defined registers. That doesn't work if the phi join is implicitly defined in all but one of the predecessors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96994 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -329,24 +329,43 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
|
||||
DEBUG(dbgs() << " +" << NewLR);
|
||||
interval.addRange(NewLR);
|
||||
|
||||
// Iterate over all of the blocks that the variable is completely
|
||||
// live in, adding [insrtIndex(begin), instrIndex(end)+4) to the
|
||||
// live interval.
|
||||
for (SparseBitVector<>::iterator I = vi.AliveBlocks.begin(),
|
||||
E = vi.AliveBlocks.end(); I != E; ++I) {
|
||||
MachineBasicBlock *aliveBlock = mf_->getBlockNumbered(*I);
|
||||
LiveRange LR(getMBBStartIdx(aliveBlock), getMBBEndIdx(aliveBlock), ValNo);
|
||||
interval.addRange(LR);
|
||||
DEBUG(dbgs() << " +" << LR);
|
||||
bool PHIJoin = lv_->isPHIJoin(interval.reg);
|
||||
|
||||
if (PHIJoin) {
|
||||
// A phi join register is killed at the end of the MBB and revived as a new
|
||||
// valno in the killing blocks.
|
||||
assert(vi.AliveBlocks.empty() && "Phi join can't pass through blocks");
|
||||
DEBUG(dbgs() << " phi-join");
|
||||
ValNo->addKill(indexes_->getTerminatorGap(mbb));
|
||||
ValNo->setHasPHIKill(true);
|
||||
} else {
|
||||
// Iterate over all of the blocks that the variable is completely
|
||||
// live in, adding [insrtIndex(begin), instrIndex(end)+4) to the
|
||||
// live interval.
|
||||
for (SparseBitVector<>::iterator I = vi.AliveBlocks.begin(),
|
||||
E = vi.AliveBlocks.end(); I != E; ++I) {
|
||||
MachineBasicBlock *aliveBlock = mf_->getBlockNumbered(*I);
|
||||
LiveRange LR(getMBBStartIdx(aliveBlock), getMBBEndIdx(aliveBlock), ValNo);
|
||||
interval.addRange(LR);
|
||||
DEBUG(dbgs() << " +" << LR);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, this virtual register is live from the start of any killing
|
||||
// block to the 'use' slot of the killing instruction.
|
||||
for (unsigned i = 0, e = vi.Kills.size(); i != e; ++i) {
|
||||
MachineInstr *Kill = vi.Kills[i];
|
||||
SlotIndex killIdx =
|
||||
getInstructionIndex(Kill).getDefIndex();
|
||||
LiveRange LR(getMBBStartIdx(Kill->getParent()), killIdx, ValNo);
|
||||
SlotIndex Start = getMBBStartIdx(Kill->getParent());
|
||||
SlotIndex killIdx = getInstructionIndex(Kill).getDefIndex();
|
||||
|
||||
// Create interval with one of a NEW value number. Note that this value
|
||||
// number isn't actually defined by an instruction, weird huh? :)
|
||||
if (PHIJoin) {
|
||||
ValNo = interval.getNextValue(SlotIndex(Start, true), 0, false,
|
||||
VNInfoAllocator);
|
||||
ValNo->setIsPHIDef(true);
|
||||
}
|
||||
LiveRange LR(Start, killIdx, ValNo);
|
||||
interval.addRange(LR);
|
||||
ValNo->addKill(killIdx);
|
||||
DEBUG(dbgs() << " +" << LR);
|
||||
@@ -409,48 +428,11 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
|
||||
interval.print(dbgs(), tri_);
|
||||
});
|
||||
} else {
|
||||
// Otherwise, this must be because of phi elimination. If this is the
|
||||
// first redefinition of the vreg that we have seen, go back and change
|
||||
// the live range in the PHI block to be a different value number.
|
||||
if (interval.containsOneValue()) {
|
||||
|
||||
VNInfo *VNI = interval.getValNumInfo(0);
|
||||
// Phi elimination may have reused the register for multiple identical
|
||||
// phi nodes. There will be a kill per phi. Remove the old ranges that
|
||||
// we now know have an incorrect number.
|
||||
for (unsigned ki=0, ke=vi.Kills.size(); ki != ke; ++ki) {
|
||||
MachineInstr *Killer = vi.Kills[ki];
|
||||
SlotIndex Start = getMBBStartIdx(Killer->getParent());
|
||||
SlotIndex End = getInstructionIndex(Killer).getDefIndex();
|
||||
DEBUG({
|
||||
dbgs() << "\n\t\trenaming [" << Start << "," << End << "] in: ";
|
||||
interval.print(dbgs(), tri_);
|
||||
});
|
||||
interval.removeRange(Start, End);
|
||||
|
||||
// Replace the interval with one of a NEW value number. Note that
|
||||
// this value number isn't actually defined by an instruction, weird
|
||||
// huh? :)
|
||||
LiveRange LR(Start, End,
|
||||
interval.getNextValue(SlotIndex(Start, true),
|
||||
0, false, VNInfoAllocator));
|
||||
LR.valno->setIsPHIDef(true);
|
||||
interval.addRange(LR);
|
||||
LR.valno->addKill(End);
|
||||
}
|
||||
|
||||
MachineBasicBlock *killMBB = getMBBFromIndex(VNI->def);
|
||||
VNI->addKill(indexes_->getTerminatorGap(killMBB));
|
||||
VNI->setHasPHIKill(true);
|
||||
DEBUG({
|
||||
dbgs() << " RESULT: ";
|
||||
interval.print(dbgs(), tri_);
|
||||
});
|
||||
}
|
||||
|
||||
assert(lv_->isPHIJoin(interval.reg) && "Multiply defined register");
|
||||
// In the case of PHI elimination, each variable definition is only
|
||||
// live until the end of the block. We've already taken care of the
|
||||
// rest of the live range.
|
||||
|
||||
SlotIndex defIndex = MIIdx.getDefIndex();
|
||||
if (MO.isEarlyClobber())
|
||||
defIndex = MIIdx.getUseIndex();
|
||||
@@ -468,7 +450,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
|
||||
interval.addRange(LR);
|
||||
ValNo->addKill(indexes_->getTerminatorGap(mbb));
|
||||
ValNo->setHasPHIKill(true);
|
||||
DEBUG(dbgs() << " +" << LR);
|
||||
DEBUG(dbgs() << " phi-join +" << LR);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user