mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-21 02:24:22 +00:00
- Merge UsedBlocks info after two virtual registers are coalesced.
- Use distance to closest use to determine whether to abort coalescing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35141 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -940,49 +940,51 @@ bool LiveIntervals::JoinCopy(MachineInstr *CopyMI,
|
|||||||
if (ReduceJoinPhys && !isDead &&
|
if (ReduceJoinPhys && !isDead &&
|
||||||
MRegisterInfo::isPhysicalRegister(repSrcReg)) {
|
MRegisterInfo::isPhysicalRegister(repSrcReg)) {
|
||||||
// Small function. No need to worry!
|
// Small function. No need to worry!
|
||||||
if (r2iMap_.size() <= allocatableRegs_.size() * 2)
|
unsigned Threshold = allocatableRegs_.count() * 2;
|
||||||
|
if (r2iMap_.size() <= Threshold)
|
||||||
goto TryJoin;
|
goto TryJoin;
|
||||||
|
|
||||||
LiveVariables::VarInfo& dvi = lv_->getVarInfo(repDstReg);
|
LiveVariables::VarInfo& dvi = lv_->getVarInfo(repDstReg);
|
||||||
// Is the value used in the current BB or any immediate successroe BB?
|
// Is the value used in the current BB or any immediate successroe BB?
|
||||||
MachineBasicBlock *SrcBB = CopyMI->getParent();
|
MachineBasicBlock *CopyBB = CopyMI->getParent();
|
||||||
if (!dvi.UsedBlocks[SrcBB->getNumber()]) {
|
if (dvi.UsedBlocks[CopyBB->getNumber()])
|
||||||
for (MachineBasicBlock::succ_iterator SI = SrcBB->succ_begin(),
|
goto TryJoin;
|
||||||
SE = SrcBB->succ_end(); SI != SE; ++SI) {
|
for (MachineBasicBlock::succ_iterator SI = CopyBB->succ_begin(),
|
||||||
|
SE = CopyBB->succ_end(); SI != SE; ++SI) {
|
||||||
MachineBasicBlock *SuccMBB = *SI;
|
MachineBasicBlock *SuccMBB = *SI;
|
||||||
if (dvi.UsedBlocks[SuccMBB->getNumber()])
|
if (dvi.UsedBlocks[SuccMBB->getNumber()])
|
||||||
goto TryJoin;
|
goto TryJoin;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Ok, no use in this BB and no use in immediate successor BB's. Be really
|
// Ok, no use in this BB and no use in immediate successor BB's. Be really
|
||||||
// careful now!
|
// careful now!
|
||||||
// It's only used in one BB, forget about it!
|
// It's only used in one BB, forget about it!
|
||||||
if (dvi.UsedBlocks.count() <= 1) {
|
if (dvi.UsedBlocks.count() < 2) {
|
||||||
++numAborts;
|
++numAborts;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Examine all the blocks where the value is used. If any is in the same
|
// Determine whether to allow coalescing based on how far the closest
|
||||||
// loop, then it's ok. Or if the current BB is a preheader of any of the
|
// use is.
|
||||||
// loop that uses this value, that's ok as well.
|
unsigned CopyIdx = getInstructionIndex(CopyMI);
|
||||||
const LoopInfo &LI = getAnalysis<LoopInfo>();
|
unsigned MinDist = i2miMap_.size() * InstrSlots::NUM;
|
||||||
const Loop *L = LI.getLoopFor(SrcBB->getBasicBlock());
|
|
||||||
int UseBBNum = dvi.UsedBlocks.find_first();
|
int UseBBNum = dvi.UsedBlocks.find_first();
|
||||||
while (UseBBNum != -1) {
|
while (UseBBNum != -1) {
|
||||||
MachineBasicBlock *UseBB = mf_->getBlockNumbered(UseBBNum);
|
MachineBasicBlock *UseBB = mf_->getBlockNumbered(UseBBNum);
|
||||||
const Loop *UL = LI.getLoopFor(UseBB->getBasicBlock());
|
unsigned UseIdx = getMBBStartIdx(UseBB);
|
||||||
if ((UL && UL == L) || // A use in the same loop
|
if (UseIdx > CopyIdx) {
|
||||||
(UL && L && // A use in a loop and this BB is the preheader
|
MinDist = std::min(MinDist, UseIdx - CopyIdx);
|
||||||
UL->getLoopPreheader() == SrcBB->getBasicBlock()))
|
if (MinDist <= Threshold)
|
||||||
goto TryJoin;
|
break;
|
||||||
|
}
|
||||||
UseBBNum = dvi.UsedBlocks.find_next(UseBBNum);
|
UseBBNum = dvi.UsedBlocks.find_next(UseBBNum);
|
||||||
}
|
}
|
||||||
|
if (MinDist > Threshold) {
|
||||||
// Don't do it!
|
// Don't do it!
|
||||||
++numAborts;
|
++numAborts;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TryJoin:
|
TryJoin:
|
||||||
// Okay, attempt to join these two intervals. On failure, this returns false.
|
// Okay, attempt to join these two intervals. On failure, this returns false.
|
||||||
@ -1038,6 +1040,11 @@ TryJoin:
|
|||||||
if (MRegisterInfo::isPhysicalRegister(repDstReg)) {
|
if (MRegisterInfo::isPhysicalRegister(repDstReg)) {
|
||||||
for (const unsigned *AS = mri_->getAliasSet(repDstReg); *AS; ++AS)
|
for (const unsigned *AS = mri_->getAliasSet(repDstReg); *AS; ++AS)
|
||||||
getInterval(*AS).MergeInClobberRanges(SrcInt);
|
getInterval(*AS).MergeInClobberRanges(SrcInt);
|
||||||
|
} else {
|
||||||
|
// Merge UsedBlocks info if the destination is a virtual register.
|
||||||
|
LiveVariables::VarInfo& dVI = lv_->getVarInfo(repDstReg);
|
||||||
|
LiveVariables::VarInfo& sVI = lv_->getVarInfo(repSrcReg);
|
||||||
|
dVI.UsedBlocks |= sVI.UsedBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
DOUT << "\n\t\tJoined. Result = "; DestInt.print(DOUT, mri_);
|
DOUT << "\n\t\tJoined. Result = "; DestInt.print(DOUT, mri_);
|
||||||
|
Reference in New Issue
Block a user