mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Remove some unneeded code for LiveInterval joining, and fix a bug in the Phi elimination algorithm where we were accidentally reasoning about
the source rather than the destination. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48936 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -406,12 +406,9 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) {
|
|||||||
// before the current one.
|
// before the current one.
|
||||||
std::set<unsigned> ProcessedNames;
|
std::set<unsigned> ProcessedNames;
|
||||||
|
|
||||||
MachineBasicBlock::iterator FirstNonPHI = MBB->begin();
|
|
||||||
while (FirstNonPHI->getOpcode() == TargetInstrInfo::PHI) FirstNonPHI++;
|
|
||||||
|
|
||||||
// Iterate over all the PHI nodes in this block
|
// Iterate over all the PHI nodes in this block
|
||||||
MachineBasicBlock::iterator P = MBB->begin();
|
MachineBasicBlock::iterator P = MBB->begin();
|
||||||
while (P != FirstNonPHI && P->getOpcode() == TargetInstrInfo::PHI) {
|
while (P->getOpcode() == TargetInstrInfo::PHI) {
|
||||||
unsigned DestReg = P->getOperand(0).getReg();
|
unsigned DestReg = P->getOperand(0).getReg();
|
||||||
|
|
||||||
// Don't both doing PHI elimination for dead PHI's.
|
// Don't both doing PHI elimination for dead PHI's.
|
||||||
@@ -421,7 +418,7 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LiveInterval& PI = LI.getOrCreateInterval(DestReg);
|
LiveInterval& PI = LI.getOrCreateInterval(DestReg);
|
||||||
unsigned pIdx = LI.getInstructionIndex(FirstNonPHI);
|
unsigned pIdx = LI.getDefIndex(LI.getInstructionIndex(P));
|
||||||
VNInfo* PVN = PI.getLiveRangeContaining(pIdx)->valno;
|
VNInfo* PVN = PI.getLiveRangeContaining(pIdx)->valno;
|
||||||
PhiValueNumber.insert(std::make_pair(DestReg, PVN->id));
|
PhiValueNumber.insert(std::make_pair(DestReg, PVN->id));
|
||||||
|
|
||||||
@@ -632,7 +629,7 @@ void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB,
|
|||||||
map.insert(std::make_pair(I->first, I->first));
|
map.insert(std::make_pair(I->first, I->first));
|
||||||
map.insert(std::make_pair(I->second, I->second));
|
map.insert(std::make_pair(I->second, I->second));
|
||||||
|
|
||||||
if (!UsedByAnother.count(I->first)) {
|
if (!UsedByAnother.count(I->second)) {
|
||||||
worklist.insert(*I);
|
worklist.insert(*I);
|
||||||
|
|
||||||
// Avoid iterator invalidation
|
// Avoid iterator invalidation
|
||||||
@@ -808,8 +805,6 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary,
|
|||||||
// coalesced.
|
// coalesced.
|
||||||
SmallVector<int, 16> LHSValNoAssignments;
|
SmallVector<int, 16> LHSValNoAssignments;
|
||||||
SmallVector<int, 16> RHSValNoAssignments;
|
SmallVector<int, 16> RHSValNoAssignments;
|
||||||
DenseMap<VNInfo*, VNInfo*> LHSValsDefinedFromRHS;
|
|
||||||
DenseMap<VNInfo*, VNInfo*> RHSValsDefinedFromLHS;
|
|
||||||
SmallVector<VNInfo*, 16> NewVNInfo;
|
SmallVector<VNInfo*, 16> NewVNInfo;
|
||||||
|
|
||||||
LHSValNoAssignments.resize(LHS.getNumValNums(), -1);
|
LHSValNoAssignments.resize(LHS.getNumValNums(), -1);
|
||||||
@@ -822,9 +817,9 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary,
|
|||||||
unsigned VN = VNI->id;
|
unsigned VN = VNI->id;
|
||||||
if (LHSValNoAssignments[VN] >= 0 || VNI->def == ~1U)
|
if (LHSValNoAssignments[VN] >= 0 || VNI->def == ~1U)
|
||||||
continue;
|
continue;
|
||||||
ComputeUltimateVN(VNI, NewVNInfo,
|
|
||||||
LHSValsDefinedFromRHS, RHSValsDefinedFromLHS,
|
NewVNInfo.push_back(VNI);
|
||||||
LHSValNoAssignments, RHSValNoAssignments);
|
LHSValNoAssignments[VN] = NewVNInfo.size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LiveInterval::vni_iterator I = RHS.vni_begin(), E = RHS.vni_end();
|
for (LiveInterval::vni_iterator I = RHS.vni_begin(), E = RHS.vni_end();
|
||||||
@@ -833,51 +828,26 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary,
|
|||||||
unsigned VN = VNI->id;
|
unsigned VN = VNI->id;
|
||||||
if (RHSValNoAssignments[VN] >= 0 || VNI->def == ~1U)
|
if (RHSValNoAssignments[VN] >= 0 || VNI->def == ~1U)
|
||||||
continue;
|
continue;
|
||||||
// If this value number isn't a copy from the LHS, it's a new number.
|
|
||||||
if (RHSValsDefinedFromLHS.find(VNI) == RHSValsDefinedFromLHS.end()) {
|
NewVNInfo.push_back(VNI);
|
||||||
NewVNInfo.push_back(VNI);
|
RHSValNoAssignments[VN] = NewVNInfo.size()-1;
|
||||||
RHSValNoAssignments[VN] = NewVNInfo.size()-1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ComputeUltimateVN(VNI, NewVNInfo,
|
|
||||||
RHSValsDefinedFromLHS, LHSValsDefinedFromRHS,
|
|
||||||
RHSValNoAssignments, LHSValNoAssignments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update kill info. Some live ranges are extended due to copy coalescing.
|
|
||||||
for (DenseMap<VNInfo*, VNInfo*>::iterator I = LHSValsDefinedFromRHS.begin(),
|
|
||||||
E = LHSValsDefinedFromRHS.end(); I != E; ++I) {
|
|
||||||
VNInfo *VNI = I->first;
|
|
||||||
unsigned LHSValID = LHSValNoAssignments[VNI->id];
|
|
||||||
LiveInterval::removeKill(NewVNInfo[LHSValID], VNI->def);
|
|
||||||
NewVNInfo[LHSValID]->hasPHIKill |= VNI->hasPHIKill;
|
|
||||||
RHS.addKills(NewVNInfo[LHSValID], VNI->kills);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update kill info. Some live ranges are extended due to copy coalescing.
|
|
||||||
for (DenseMap<VNInfo*, VNInfo*>::iterator I = RHSValsDefinedFromLHS.begin(),
|
|
||||||
E = RHSValsDefinedFromLHS.end(); I != E; ++I) {
|
|
||||||
VNInfo *VNI = I->first;
|
|
||||||
unsigned RHSValID = RHSValNoAssignments[VNI->id];
|
|
||||||
LiveInterval::removeKill(NewVNInfo[RHSValID], VNI->def);
|
|
||||||
NewVNInfo[RHSValID]->hasPHIKill |= VNI->hasPHIKill;
|
|
||||||
LHS.addKills(NewVNInfo[RHSValID], VNI->kills);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the VNInfo we collected earlier to ensure that the phi copy is
|
|
||||||
// merged correctly.
|
|
||||||
// FIXME: This is not working correctly yet.
|
|
||||||
// RHSValNoAssignments[secondaryVN] = primaryVN;
|
|
||||||
|
|
||||||
// If we get here, we know that we can coalesce the live ranges. Ask the
|
// If we get here, we know that we can coalesce the live ranges. Ask the
|
||||||
// intervals to coalesce themselves now.
|
// intervals to coalesce themselves now.
|
||||||
|
|
||||||
LHS.join(RHS, &LHSValNoAssignments[0], &RHSValNoAssignments[0], NewVNInfo);
|
LHS.join(RHS, &LHSValNoAssignments[0], &RHSValNoAssignments[0], NewVNInfo);
|
||||||
LI.removeInterval(secondary);
|
LI.removeInterval(secondary);
|
||||||
|
|
||||||
|
// The valno that was previously the input to the PHI node
|
||||||
|
// now has a PHIKill.
|
||||||
|
LHS.getValNumInfo(RHSValNoAssignments[secondaryVN])->hasPHIKill = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
||||||
|
|
||||||
|
LiveIntervals& LI = getAnalysis<LiveIntervals>();
|
||||||
|
|
||||||
// Compute DFS numbers of each block
|
// Compute DFS numbers of each block
|
||||||
computeDFS(Fn);
|
computeDFS(Fn);
|
||||||
|
|
||||||
@@ -913,29 +883,26 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
|||||||
phis.push_back(BI);
|
phis.push_back(BI);
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveIntervals& LI = getAnalysis<LiveIntervals>();
|
|
||||||
|
|
||||||
for (std::vector<MachineInstr*>::iterator I = phis.begin(), E = phis.end();
|
for (std::vector<MachineInstr*>::iterator I = phis.begin(), E = phis.end();
|
||||||
I != E; ++I) {
|
I != E; ) {
|
||||||
|
MachineInstr* PInstr = *(I++);
|
||||||
|
|
||||||
// If this is a dead PHI node, then remove it from LiveIntervals.
|
// If this is a dead PHI node, then remove it from LiveIntervals.
|
||||||
unsigned DestReg = (*I)->getOperand(0).getReg();
|
unsigned DestReg = PInstr->getOperand(0).getReg();
|
||||||
if ((*I)->registerDefIsDead(DestReg)) {
|
if (PInstr->registerDefIsDead(DestReg)) {
|
||||||
LiveInterval& PI = LI.getInterval(DestReg);
|
LiveInterval& PI = LI.getInterval(DestReg);
|
||||||
|
|
||||||
if (PI.containsOneValue()) {
|
if (PI.containsOneValue()) {
|
||||||
LI.removeInterval(DestReg);
|
LI.removeInterval(DestReg);
|
||||||
} else {
|
} else {
|
||||||
MachineBasicBlock::iterator PIter = *I;
|
unsigned idx = LI.getDefIndex(LI.getInstructionIndex(PInstr));
|
||||||
while (PIter->getOpcode() == TargetInstrInfo::PHI) ++PIter;
|
|
||||||
unsigned idx = LI.getInstructionIndex(PIter);
|
|
||||||
|
|
||||||
PI.removeRange(*PI.getLiveRangeContaining(idx), true);
|
PI.removeRange(*PI.getLiveRangeContaining(idx), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LI.RemoveMachineInstrFromMaps(*I);
|
LI.RemoveMachineInstrFromMaps(PInstr);
|
||||||
(*I)->eraseFromParent();
|
PInstr->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user