mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-06 20:27:42 +00:00
Add initial support for inserting last minute copies.
llvm-svn: 56485
This commit is contained in:
parent
5bf702d20a
commit
5405b59bcd
@ -142,7 +142,7 @@ namespace {
|
|||||||
void ScheduleCopies(MachineBasicBlock* MBB, std::set<unsigned>& pushed);
|
void ScheduleCopies(MachineBasicBlock* MBB, std::set<unsigned>& pushed);
|
||||||
void InsertCopies(MachineDomTreeNode* MBB,
|
void InsertCopies(MachineDomTreeNode* MBB,
|
||||||
SmallPtrSet<MachineBasicBlock*, 16>& v);
|
SmallPtrSet<MachineBasicBlock*, 16>& v);
|
||||||
void mergeLiveIntervals(unsigned primary, unsigned secondary);
|
bool mergeLiveIntervals(unsigned primary, unsigned secondary);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,7 +844,7 @@ void StrongPHIElimination::InsertCopies(MachineDomTreeNode* MDTN,
|
|||||||
Stacks[*I].pop_back();
|
Stacks[*I].pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StrongPHIElimination::mergeLiveIntervals(unsigned primary,
|
bool StrongPHIElimination::mergeLiveIntervals(unsigned primary,
|
||||||
unsigned secondary) {
|
unsigned secondary) {
|
||||||
|
|
||||||
LiveIntervals& LI = getAnalysis<LiveIntervals>();
|
LiveIntervals& LI = getAnalysis<LiveIntervals>();
|
||||||
@ -859,32 +859,35 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary,
|
|||||||
|
|
||||||
unsigned Start = R.start;
|
unsigned Start = R.start;
|
||||||
unsigned End = R.end;
|
unsigned End = R.end;
|
||||||
if (LHS.liveAt(Start))
|
if (LHS.getLiveRangeContaining(Start))
|
||||||
LHS.removeRange(Start, End, true);
|
return false;
|
||||||
|
|
||||||
if (const LiveRange* ER = LHS.getLiveRangeContaining(End))
|
if (LHS.getLiveRangeContaining(End))
|
||||||
End = ER->start;
|
return false;
|
||||||
|
|
||||||
LiveInterval::iterator RI = std::upper_bound(LHS.begin(), LHS.end(), R);
|
LiveInterval::iterator RI = std::upper_bound(LHS.begin(), LHS.end(), R);
|
||||||
if (RI != LHS.end() && RI->start < End)
|
if (RI != LHS.end() && RI->start < End)
|
||||||
End = RI->start;
|
return false;
|
||||||
|
}
|
||||||
if (Start != End) {
|
|
||||||
VNInfo* OldVN = R.valno;
|
for (LiveInterval::iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
|
||||||
VNInfo*& NewVN = VNMap[OldVN];
|
LiveRange R = *I;
|
||||||
if (!NewVN) {
|
VNInfo* OldVN = R.valno;
|
||||||
NewVN = LHS.getNextValue(OldVN->def,
|
VNInfo*& NewVN = VNMap[OldVN];
|
||||||
OldVN->copy,
|
if (!NewVN) {
|
||||||
LI.getVNInfoAllocator());
|
NewVN = LHS.getNextValue(OldVN->def,
|
||||||
NewVN->kills = OldVN->kills;
|
OldVN->copy,
|
||||||
}
|
LI.getVNInfoAllocator());
|
||||||
|
NewVN->kills = OldVN->kills;
|
||||||
LiveRange LR (Start, End, NewVN);
|
|
||||||
LHS.addRange(LR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveRange LR (R.start, R.end, NewVN);
|
||||||
|
LHS.addRange(LR);
|
||||||
}
|
}
|
||||||
|
|
||||||
LI.removeInterval(RHS.reg);
|
LI.removeInterval(RHS.reg);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
||||||
@ -936,21 +939,43 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
|||||||
DOUT << "Renaming: " << SI->first << " -> " << I->first << "\n";
|
DOUT << "Renaming: " << SI->first << " -> " << I->first << "\n";
|
||||||
|
|
||||||
if (SI->first != I->first) {
|
if (SI->first != I->first) {
|
||||||
mergeLiveIntervals(I->first, SI->first);
|
if (mergeLiveIntervals(I->first, SI->first)) {
|
||||||
Fn.getRegInfo().replaceRegWith(SI->first, I->first);
|
Fn.getRegInfo().replaceRegWith(SI->first, I->first);
|
||||||
|
|
||||||
if (RenameSets.count(SI->first)) {
|
if (RenameSets.count(SI->first)) {
|
||||||
I->second.insert(RenameSets[SI->first].begin(),
|
I->second.insert(RenameSets[SI->first].begin(),
|
||||||
RenameSets[SI->first].end());
|
RenameSets[SI->first].end());
|
||||||
RenameSets.erase(SI->first);
|
RenameSets.erase(SI->first);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Insert a last-minute copy if a conflict was detected.
|
||||||
|
const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo();
|
||||||
|
const TargetRegisterClass *RC = Fn.getRegInfo().getRegClass(I->first);
|
||||||
|
TII->copyRegToReg(*SI->second, SI->second->getFirstTerminator(),
|
||||||
|
I->first, SI->first, RC, RC);
|
||||||
|
|
||||||
|
LI.computeNumbering();
|
||||||
|
|
||||||
|
LiveInterval& Int = LI.getOrCreateInterval(I->first);
|
||||||
|
unsigned instrIdx =
|
||||||
|
LI.getInstructionIndex(--SI->second->getFirstTerminator());
|
||||||
|
if (Int.liveAt(LiveIntervals::getDefIndex(instrIdx)))
|
||||||
|
Int.removeRange(LiveIntervals::getDefIndex(instrIdx),
|
||||||
|
LI.getMBBEndIdx(SI->second)+1, true);
|
||||||
|
|
||||||
|
LiveRange R = LI.addLiveRangeToEndOfBlock(I->first,
|
||||||
|
--SI->second->getFirstTerminator());
|
||||||
|
R.valno->copy = --SI->second->getFirstTerminator();
|
||||||
|
R.valno->def = LiveIntervals::getDefIndex(instrIdx);
|
||||||
|
|
||||||
|
DOUT << "Renaming failed: " << SI->first << " -> "
|
||||||
|
<< I->first << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
I->second.erase(SI->first);
|
I->second.erase(SI->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Insert last-minute copies
|
|
||||||
|
|
||||||
// Remove PHIs
|
// Remove PHIs
|
||||||
std::vector<MachineInstr*> phis;
|
std::vector<MachineInstr*> phis;
|
||||||
for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
|
for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user