mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
- Check if a register is livein before removing it. It may have already been removed.
- Do not iterate over SmallPtrSet, the order of iteration is not deterministic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50209 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1734055999
commit
a971dbdde2
@ -176,6 +176,10 @@ public:
|
||||
///
|
||||
void removeLiveIn(unsigned Reg);
|
||||
|
||||
/// isLiveIn - Return true if the specified register is in the live in set.
|
||||
///
|
||||
bool isLiveIn(unsigned Reg) const;
|
||||
|
||||
// Iteration support for live in sets. These sets are kept in sorted
|
||||
// order by their register number.
|
||||
typedef std::vector<unsigned>::iterator livein_iterator;
|
||||
|
@ -205,6 +205,11 @@ void MachineBasicBlock::removeLiveIn(unsigned Reg) {
|
||||
LiveIns.erase(I);
|
||||
}
|
||||
|
||||
bool MachineBasicBlock::isLiveIn(unsigned Reg) const {
|
||||
const_livein_iterator I = std::find(livein_begin(), livein_end(), Reg);
|
||||
return I != livein_end();
|
||||
}
|
||||
|
||||
void MachineBasicBlock::moveBefore(MachineBasicBlock *NewAfter) {
|
||||
MachineFunction::BasicBlockListType &BBList =getParent()->getBasicBlockList();
|
||||
getParent()->getBasicBlockList().splice(NewAfter, BBList, this);
|
||||
|
@ -639,7 +639,8 @@ SimpleRegisterCoalescing::ShortenDeadCopySrcLiveRange(LiveInterval &li,
|
||||
// first instruction index starts at > 0 value.
|
||||
assert(TargetRegisterInfo::isPhysicalRegister(li.reg));
|
||||
// Live-in to the function but dead. Remove it from entry live-in set.
|
||||
mf_->begin()->removeLiveIn(li.reg);
|
||||
if (mf_->begin()->isLiveIn(li.reg))
|
||||
mf_->begin()->removeLiveIn(li.reg);
|
||||
const LiveRange *LR = li.getLiveRangeContaining(CopyIdx);
|
||||
removeRange(li, LR->start, LR->end, li_, tri_);
|
||||
return removeIntervalIfEmpty(li, li_, tri_);
|
||||
@ -2002,27 +2003,6 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) {
|
||||
I->second.print(DOUT, tri_);
|
||||
DOUT << "\n";
|
||||
}
|
||||
|
||||
// Delete all coalesced copies.
|
||||
for (SmallPtrSet<MachineInstr*,32>::iterator I = JoinedCopies.begin(),
|
||||
E = JoinedCopies.end(); I != E; ++I) {
|
||||
MachineInstr *CopyMI = *I;
|
||||
unsigned SrcReg, DstReg;
|
||||
if (!tii_->isMoveInstr(*CopyMI, SrcReg, DstReg)) {
|
||||
assert((CopyMI->getOpcode() == TargetInstrInfo::EXTRACT_SUBREG ||
|
||||
CopyMI->getOpcode() == TargetInstrInfo::INSERT_SUBREG) &&
|
||||
"Unrecognized copy instruction");
|
||||
DstReg = CopyMI->getOperand(0).getReg();
|
||||
}
|
||||
if (CopyMI->registerDefIsDead(DstReg)) {
|
||||
LiveInterval &li = li_->getInterval(DstReg);
|
||||
if (!ShortenDeadCopySrcLiveRange(li, CopyMI))
|
||||
ShortenDeadCopyLiveRange(li, CopyMI);
|
||||
}
|
||||
li_->RemoveMachineInstrFromMaps(*I);
|
||||
(*I)->eraseFromParent();
|
||||
++numPeep;
|
||||
}
|
||||
}
|
||||
|
||||
// Perform a final pass over the instructions and compute spill weights
|
||||
@ -2034,15 +2014,35 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) {
|
||||
|
||||
for (MachineBasicBlock::iterator mii = mbb->begin(), mie = mbb->end();
|
||||
mii != mie; ) {
|
||||
// if the move will be an identity move delete it
|
||||
unsigned srcReg, dstReg;
|
||||
bool isMove = tii_->isMoveInstr(*mii, srcReg, dstReg);
|
||||
if (isMove && srcReg == dstReg) {
|
||||
if (li_->hasInterval(srcReg)) {
|
||||
LiveInterval &RegInt = li_->getInterval(srcReg);
|
||||
MachineInstr *MI = mii;
|
||||
unsigned SrcReg, DstReg;
|
||||
if (JoinedCopies.count(MI)) {
|
||||
// Delete all coalesced copies.
|
||||
if (!tii_->isMoveInstr(*MI, SrcReg, DstReg)) {
|
||||
assert((MI->getOpcode() == TargetInstrInfo::EXTRACT_SUBREG ||
|
||||
MI->getOpcode() == TargetInstrInfo::INSERT_SUBREG) &&
|
||||
"Unrecognized copy instruction");
|
||||
DstReg = MI->getOperand(0).getReg();
|
||||
}
|
||||
if (MI->registerDefIsDead(DstReg)) {
|
||||
LiveInterval &li = li_->getInterval(DstReg);
|
||||
if (!ShortenDeadCopySrcLiveRange(li, MI))
|
||||
ShortenDeadCopyLiveRange(li, MI);
|
||||
}
|
||||
li_->RemoveMachineInstrFromMaps(MI);
|
||||
mii = mbbi->erase(mii);
|
||||
++numPeep;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the move will be an identity move delete it
|
||||
bool isMove = tii_->isMoveInstr(*mii, SrcReg, DstReg);
|
||||
if (isMove && SrcReg == DstReg) {
|
||||
if (li_->hasInterval(SrcReg)) {
|
||||
LiveInterval &RegInt = li_->getInterval(SrcReg);
|
||||
// If def of this move instruction is dead, remove its live range
|
||||
// from the dstination register's live interval.
|
||||
if (mii->registerDefIsDead(dstReg)) {
|
||||
if (mii->registerDefIsDead(DstReg)) {
|
||||
if (!ShortenDeadCopySrcLiveRange(RegInt, mii))
|
||||
ShortenDeadCopyLiveRange(RegInt, mii);
|
||||
}
|
||||
@ -2050,7 +2050,7 @@ bool SimpleRegisterCoalescing::runOnMachineFunction(MachineFunction &fn) {
|
||||
li_->RemoveMachineInstrFromMaps(mii);
|
||||
mii = mbbi->erase(mii);
|
||||
++numPeep;
|
||||
} else if (!isMove || !TurnCopyIntoImpDef(mii, mbb, dstReg, srcReg)) {
|
||||
} else if (!isMove || !TurnCopyIntoImpDef(mii, mbb, DstReg, SrcReg)) {
|
||||
SmallSet<unsigned, 4> UniqueUses;
|
||||
for (unsigned i = 0, e = mii->getNumOperands(); i != e; ++i) {
|
||||
const MachineOperand &mop = mii->getOperand(i);
|
||||
|
Loading…
Reference in New Issue
Block a user