mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-02 04:24:22 +00:00
Refactor some code; check if commuteInstruction is able to commute the instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47208 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -192,6 +192,31 @@ bool SimpleRegisterCoalescing::AdjustCopiesBackFrom(LiveInterval &IntA,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// HasOtherReachingDefs - Return true if there are definitions of IntB
|
||||||
|
/// other than BValNo val# that can reach uses of AValno val# of IntA.
|
||||||
|
bool SimpleRegisterCoalescing::HasOtherReachingDefs(LiveInterval &IntA,
|
||||||
|
LiveInterval &IntB,
|
||||||
|
VNInfo *AValNo,
|
||||||
|
VNInfo *BValNo) {
|
||||||
|
for (LiveInterval::iterator AI = IntA.begin(), AE = IntA.end();
|
||||||
|
AI != AE; ++AI) {
|
||||||
|
if (AI->valno != AValNo) continue;
|
||||||
|
LiveInterval::Ranges::iterator BI =
|
||||||
|
std::upper_bound(IntB.ranges.begin(), IntB.ranges.end(), AI->start);
|
||||||
|
if (BI != IntB.ranges.begin())
|
||||||
|
--BI;
|
||||||
|
for (; BI != IntB.ranges.end() && AI->end >= BI->start; ++BI) {
|
||||||
|
if (BI->valno == BValNo)
|
||||||
|
continue;
|
||||||
|
if (BI->start <= AI->start && BI->end > AI->start)
|
||||||
|
return true;
|
||||||
|
if (BI->start > AI->start && BI->start < AI->end)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// RemoveCopyByCommutingDef - We found a non-trivially-coalescable copy with IntA
|
/// RemoveCopyByCommutingDef - We found a non-trivially-coalescable copy with IntA
|
||||||
/// being the source and IntB being the dest, thus this defines a value number
|
/// being the source and IntB being the dest, thus this defines a value number
|
||||||
/// in IntB. If the source value number (in IntA) is defined by a commutable
|
/// in IntB. If the source value number (in IntA) is defined by a commutable
|
||||||
@ -254,27 +279,15 @@ bool SimpleRegisterCoalescing::RemoveCopyByCommutingDef(LiveInterval &IntA,
|
|||||||
|
|
||||||
// Make sure there are no other definitions of IntB that would reach the
|
// Make sure there are no other definitions of IntB that would reach the
|
||||||
// uses which the new definition can reach.
|
// uses which the new definition can reach.
|
||||||
for (LiveInterval::iterator AI = IntA.begin(), AE = IntA.end();
|
if (HasOtherReachingDefs(IntA, IntB, AValNo, BValNo))
|
||||||
AI != AE; ++AI) {
|
return false;
|
||||||
if (AI->valno != AValNo) continue;
|
|
||||||
LiveInterval::Ranges::iterator BI =
|
|
||||||
std::upper_bound(IntB.ranges.begin(), IntB.ranges.end(), AI->start);
|
|
||||||
if (BI != IntB.ranges.begin())
|
|
||||||
--BI;
|
|
||||||
for (; BI != IntB.ranges.end() && AI->end >= BI->start; ++BI) {
|
|
||||||
if (BI->valno == BLR->valno)
|
|
||||||
continue;
|
|
||||||
if (BI->start <= AI->start && BI->end > AI->start)
|
|
||||||
return false;
|
|
||||||
if (BI->start > AI->start && BI->start < AI->end)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// At this point we have decided that it is legal to do this
|
// At this point we have decided that it is legal to do this
|
||||||
// transformation. Start by commuting the instruction.
|
// transformation. Start by commuting the instruction.
|
||||||
MachineBasicBlock *MBB = DefMI->getParent();
|
MachineBasicBlock *MBB = DefMI->getParent();
|
||||||
MachineInstr *NewMI = tii_->commuteInstruction(DefMI);
|
MachineInstr *NewMI = tii_->commuteInstruction(DefMI);
|
||||||
|
if (!NewMI)
|
||||||
|
return false;
|
||||||
if (NewMI != DefMI) {
|
if (NewMI != DefMI) {
|
||||||
li_->ReplaceMachineInstrInMaps(DefMI, NewMI);
|
li_->ReplaceMachineInstrInMaps(DefMI, NewMI);
|
||||||
MBB->insert(DefMI, NewMI);
|
MBB->insert(DefMI, NewMI);
|
||||||
@ -682,7 +695,6 @@ bool SimpleRegisterCoalescing::JoinCopy(CopyRec &TheCopy, bool &Again) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Otherwise, we are unable to join the intervals.
|
// Otherwise, we are unable to join the intervals.
|
||||||
DOUT << "Interference!\n";
|
DOUT << "Interference!\n";
|
||||||
Again = true; // May be possible to coalesce later.
|
Again = true; // May be possible to coalesce later.
|
||||||
|
@ -178,6 +178,11 @@ namespace llvm {
|
|||||||
bool AdjustCopiesBackFrom(LiveInterval &IntA, LiveInterval &IntB,
|
bool AdjustCopiesBackFrom(LiveInterval &IntA, LiveInterval &IntB,
|
||||||
MachineInstr *CopyMI);
|
MachineInstr *CopyMI);
|
||||||
|
|
||||||
|
/// HasOtherReachingDefs - Return true if there are definitions of IntB
|
||||||
|
/// other than BValNo val# that can reach uses of AValno val# of IntA.
|
||||||
|
bool HasOtherReachingDefs(LiveInterval &IntA, LiveInterval &IntB,
|
||||||
|
VNInfo *AValNo, VNInfo *BValNo);
|
||||||
|
|
||||||
/// RemoveCopyByCommutingDef - We found a non-trivially-coalescable copy.
|
/// RemoveCopyByCommutingDef - We found a non-trivially-coalescable copy.
|
||||||
/// If the source value number is defined by a commutable instruction and
|
/// If the source value number is defined by a commutable instruction and
|
||||||
/// its other operand is coalesced to the copy dest register, see if we
|
/// its other operand is coalesced to the copy dest register, see if we
|
||||||
|
Reference in New Issue
Block a user