mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
Significant improvements to the logic for merging live intervals. This code can't
just use LI::MergeValueAsValue, as its behavior in the presence of overlapping ranges isn't what StrongPHIElimination wants. llvm-svn: 56472
This commit is contained in:
parent
3722f4c14c
commit
67df9bc5b8
@ -33,6 +33,7 @@
|
|||||||
#include "llvm/ADT/DepthFirstIterator.h"
|
#include "llvm/ADT/DepthFirstIterator.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
|
#include "llvm/Support/Debug.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -546,6 +547,12 @@ void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the renaming set for this PHI node to our overall renaming information
|
// Add the renaming set for this PHI node to our overall renaming information
|
||||||
|
for (std::map<unsigned, MachineBasicBlock*>::iterator QI = PHIUnion.begin(),
|
||||||
|
QE = PHIUnion.end(); QI != QE; ++QI) {
|
||||||
|
DOUT << "Adding Renaming: " << QI->first << " -> "
|
||||||
|
<< P->getOperand(0).getReg() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
RenameSets.insert(std::make_pair(P->getOperand(0).getReg(), PHIUnion));
|
RenameSets.insert(std::make_pair(P->getOperand(0).getReg(), PHIUnion));
|
||||||
|
|
||||||
// Remember which registers are already renamed, so that we don't try to
|
// Remember which registers are already renamed, so that we don't try to
|
||||||
@ -762,10 +769,19 @@ void StrongPHIElimination::ScheduleCopies(MachineBasicBlock* MBB,
|
|||||||
std::set<unsigned> RegHandled;
|
std::set<unsigned> RegHandled;
|
||||||
for (SmallVector<std::pair<unsigned, MachineInstr*>, 4>::iterator I =
|
for (SmallVector<std::pair<unsigned, MachineInstr*>, 4>::iterator I =
|
||||||
InsertedPHIDests.begin(), E = InsertedPHIDests.end(); I != E; ++I) {
|
InsertedPHIDests.begin(), E = InsertedPHIDests.end(); I != E; ++I) {
|
||||||
if (RegHandled.insert(I->first).second &&
|
if (RegHandled.insert(I->first).second) {
|
||||||
!LI.getOrCreateInterval(I->first).liveAt(
|
LiveInterval& Int = LI.getOrCreateInterval(I->first);
|
||||||
LI.getMBBEndIdx(I->second->getParent())))
|
unsigned instrIdx = LI.getInstructionIndex(I->second);
|
||||||
LI.addLiveRangeToEndOfBlock(I->first, I->second);
|
if (Int.liveAt(LiveIntervals::getDefIndex(instrIdx)))
|
||||||
|
Int.removeRange(LiveIntervals::getDefIndex(instrIdx),
|
||||||
|
LI.getMBBEndIdx(I->second->getParent())+1,
|
||||||
|
true);
|
||||||
|
|
||||||
|
LiveRange R = LI.addLiveRangeToEndOfBlock(I->first, I->second);
|
||||||
|
R.valno->copy = I->second;
|
||||||
|
R.valno->def =
|
||||||
|
LiveIntervals::getDefIndex(LI.getInstructionIndex(I->second));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,20 +852,39 @@ void StrongPHIElimination::mergeLiveIntervals(unsigned primary,
|
|||||||
LiveInterval& RHS = LI.getOrCreateInterval(secondary);
|
LiveInterval& RHS = LI.getOrCreateInterval(secondary);
|
||||||
|
|
||||||
LI.computeNumbering();
|
LI.computeNumbering();
|
||||||
|
|
||||||
SmallVector<VNInfo*, 4> VNSet (RHS.vni_begin(), RHS.vni_end());
|
|
||||||
DenseMap<VNInfo*, VNInfo*> VNMap;
|
DenseMap<VNInfo*, VNInfo*> VNMap;
|
||||||
for (SmallVector<VNInfo*, 4>::iterator VI = VNSet.begin(),
|
for (LiveInterval::iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
|
||||||
VE = VNSet.end(); VI != VE; ++VI) {
|
LiveRange R = *I;
|
||||||
VNInfo* NewVN = LHS.getNextValue((*VI)->def,
|
|
||||||
(*VI)->copy,
|
unsigned Start = R.start;
|
||||||
LI.getVNInfoAllocator());
|
unsigned End = R.end;
|
||||||
LHS.MergeValueInAsValue(RHS, *VI, NewVN);
|
if (LHS.liveAt(Start))
|
||||||
RHS.removeValNo(*VI);
|
LHS.removeRange(Start, End, true);
|
||||||
|
|
||||||
|
if (const LiveRange* ER = LHS.getLiveRangeContaining(End))
|
||||||
|
End = ER->start;
|
||||||
|
|
||||||
|
LiveInterval::iterator RI = std::upper_bound(LHS.begin(), LHS.end(), R);
|
||||||
|
if (RI != LHS.end() && RI->start < End)
|
||||||
|
End = RI->start;
|
||||||
|
|
||||||
|
if (Start != End) {
|
||||||
|
VNInfo* OldVN = R.valno;
|
||||||
|
VNInfo*& NewVN = VNMap[OldVN];
|
||||||
|
if (!NewVN) {
|
||||||
|
NewVN = LHS.getNextValue(OldVN->def,
|
||||||
|
OldVN->copy,
|
||||||
|
LI.getVNInfoAllocator());
|
||||||
|
NewVN->kills = OldVN->kills;
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveRange LR (Start, End, NewVN);
|
||||||
|
LHS.addRange(LR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RHS.empty())
|
LI.removeInterval(RHS.reg);
|
||||||
LI.removeInterval(RHS.reg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
||||||
@ -881,6 +916,7 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
|||||||
unsigned reg = OI->first;
|
unsigned reg = OI->first;
|
||||||
++OI;
|
++OI;
|
||||||
I->second.erase(reg);
|
I->second.erase(reg);
|
||||||
|
DOUT << "Removing Renaming: " << reg << " -> " << I->first << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -897,6 +933,8 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
|
|||||||
while (I->second.size()) {
|
while (I->second.size()) {
|
||||||
std::map<unsigned, MachineBasicBlock*>::iterator SI = I->second.begin();
|
std::map<unsigned, MachineBasicBlock*>::iterator SI = I->second.begin();
|
||||||
|
|
||||||
|
DOUT << "Renaming: " << SI->first << " -> " << I->first << "\n";
|
||||||
|
|
||||||
if (SI->first != I->first) {
|
if (SI->first != I->first) {
|
||||||
mergeLiveIntervals(I->first, SI->first);
|
mergeLiveIntervals(I->first, SI->first);
|
||||||
Fn.getRegInfo().replaceRegWith(SI->first, I->first);
|
Fn.getRegInfo().replaceRegWith(SI->first, I->first);
|
||||||
|
Loading…
Reference in New Issue
Block a user