mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Enable loop splitting in RegAllocGreedy.
The heuristics split around the largest loop where the current register may be allocated without interference. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122106 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9a3dc55202
commit
f428eb6c1b
@ -49,6 +49,9 @@ private:
|
|||||||
MachineLoopRange(const MachineLoop*, Allocator&, SlotIndexes&);
|
MachineLoopRange(const MachineLoop*, Allocator&, SlotIndexes&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// getLoop - Return the mapped machine loop.
|
||||||
|
const MachineLoop *getLoop() const { return Loop; }
|
||||||
|
|
||||||
/// overlaps - Return true if this loop overlaps the given range of machine
|
/// overlaps - Return true if this loop overlaps the given range of machine
|
||||||
/// inteructions.
|
/// inteructions.
|
||||||
bool overlaps(SlotIndex Start, SlotIndex Stop);
|
bool overlaps(SlotIndex Start, SlotIndex Stop);
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#define DEBUG_TYPE "regalloc"
|
#define DEBUG_TYPE "regalloc"
|
||||||
#include "AllocationOrder.h"
|
#include "AllocationOrder.h"
|
||||||
#include "LiveIntervalUnion.h"
|
#include "LiveIntervalUnion.h"
|
||||||
|
#include "LiveRangeEdit.h"
|
||||||
#include "RegAllocBase.h"
|
#include "RegAllocBase.h"
|
||||||
#include "Spiller.h"
|
#include "Spiller.h"
|
||||||
#include "SplitKit.h"
|
#include "SplitKit.h"
|
||||||
@ -26,6 +27,7 @@
|
|||||||
#include "llvm/CodeGen/CalcSpillWeights.h"
|
#include "llvm/CodeGen/CalcSpillWeights.h"
|
||||||
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
||||||
#include "llvm/CodeGen/LiveStackAnalysis.h"
|
#include "llvm/CodeGen/LiveStackAnalysis.h"
|
||||||
|
#include "llvm/CodeGen/MachineDominators.h"
|
||||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||||
#include "llvm/CodeGen/MachineLoopInfo.h"
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
||||||
#include "llvm/CodeGen/MachineLoopRanges.h"
|
#include "llvm/CodeGen/MachineLoopRanges.h"
|
||||||
@ -52,8 +54,10 @@ class RAGreedy : public MachineFunctionPass, public RegAllocBase {
|
|||||||
|
|
||||||
// analyses
|
// analyses
|
||||||
LiveStacks *LS;
|
LiveStacks *LS;
|
||||||
|
MachineDominatorTree *DomTree;
|
||||||
MachineLoopInfo *Loops;
|
MachineLoopInfo *Loops;
|
||||||
MachineLoopRanges *LoopRanges;
|
MachineLoopRanges *LoopRanges;
|
||||||
|
|
||||||
// state
|
// state
|
||||||
std::auto_ptr<Spiller> SpillerInstance;
|
std::auto_ptr<Spiller> SpillerInstance;
|
||||||
std::auto_ptr<SplitAnalysis> SA;
|
std::auto_ptr<SplitAnalysis> SA;
|
||||||
@ -88,6 +92,8 @@ private:
|
|||||||
LiveInterval *getSingleInterference(LiveInterval&, unsigned);
|
LiveInterval *getSingleInterference(LiveInterval&, unsigned);
|
||||||
bool reassignVReg(LiveInterval &InterferingVReg, unsigned OldPhysReg);
|
bool reassignVReg(LiveInterval &InterferingVReg, unsigned OldPhysReg);
|
||||||
bool reassignInterferences(LiveInterval &VirtReg, unsigned PhysReg);
|
bool reassignInterferences(LiveInterval &VirtReg, unsigned PhysReg);
|
||||||
|
unsigned findInterferenceFreeReg(MachineLoopRange*,
|
||||||
|
LiveInterval&, AllocationOrder&);
|
||||||
|
|
||||||
unsigned tryReassign(LiveInterval&, AllocationOrder&);
|
unsigned tryReassign(LiveInterval&, AllocationOrder&);
|
||||||
unsigned trySplit(LiveInterval&, AllocationOrder&,
|
unsigned trySplit(LiveInterval&, AllocationOrder&,
|
||||||
@ -126,8 +132,8 @@ void RAGreedy::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||||||
AU.addRequired<CalculateSpillWeights>();
|
AU.addRequired<CalculateSpillWeights>();
|
||||||
AU.addRequired<LiveStacks>();
|
AU.addRequired<LiveStacks>();
|
||||||
AU.addPreserved<LiveStacks>();
|
AU.addPreserved<LiveStacks>();
|
||||||
AU.addRequiredID(MachineDominatorsID);
|
AU.addRequired<MachineDominatorTree>();
|
||||||
AU.addPreservedID(MachineDominatorsID);
|
AU.addPreserved<MachineDominatorTree>();
|
||||||
AU.addRequired<MachineLoopInfo>();
|
AU.addRequired<MachineLoopInfo>();
|
||||||
AU.addPreserved<MachineLoopInfo>();
|
AU.addPreserved<MachineLoopInfo>();
|
||||||
AU.addRequired<MachineLoopRanges>();
|
AU.addRequired<MachineLoopRanges>();
|
||||||
@ -257,6 +263,27 @@ unsigned RAGreedy::tryReassign(LiveInterval &VirtReg, AllocationOrder &Order) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// findInterferenceFreeReg - Find a physical register in Order where Loop has
|
||||||
|
/// no interferences with VirtReg.
|
||||||
|
unsigned RAGreedy::findInterferenceFreeReg(MachineLoopRange *Loop,
|
||||||
|
LiveInterval &VirtReg,
|
||||||
|
AllocationOrder &Order) {
|
||||||
|
Order.rewind();
|
||||||
|
while (unsigned PhysReg = Order.next()) {
|
||||||
|
bool interference = false;
|
||||||
|
for (const unsigned *AI = TRI->getOverlaps(PhysReg); *AI; ++AI) {
|
||||||
|
if (query(VirtReg, *AI).checkLoopInterference(Loop)) {
|
||||||
|
interference = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!interference)
|
||||||
|
return PhysReg;
|
||||||
|
}
|
||||||
|
// No physreg found.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// trySplit - Try to split VirtReg or one of its interferences, making it
|
/// trySplit - Try to split VirtReg or one of its interferences, making it
|
||||||
/// assignable.
|
/// assignable.
|
||||||
/// @return Physreg when VirtReg may be assigned and/or new SplitVRegs.
|
/// @return Physreg when VirtReg may be assigned and/or new SplitVRegs.
|
||||||
@ -266,29 +293,42 @@ unsigned RAGreedy::trySplit(LiveInterval &VirtReg, AllocationOrder &Order,
|
|||||||
SA->analyze(&VirtReg);
|
SA->analyze(&VirtReg);
|
||||||
|
|
||||||
// Get the set of loops that have VirtReg uses and are splittable.
|
// Get the set of loops that have VirtReg uses and are splittable.
|
||||||
SplitAnalysis::LoopPtrSet SplitLoops;
|
SplitAnalysis::LoopPtrSet SplitLoopSet;
|
||||||
SA->getSplitLoops(SplitLoops);
|
SA->getSplitLoops(SplitLoopSet);
|
||||||
|
|
||||||
Order.rewind();
|
// Order loops by descending area.
|
||||||
while (unsigned PhysReg = Order.next()) {
|
SmallVector<MachineLoopRange*, 8> SplitLoops;
|
||||||
for (const unsigned *AI = TRI->getOverlaps(PhysReg); *AI; ++AI) {
|
for (SplitAnalysis::LoopPtrSet::const_iterator I = SplitLoopSet.begin(),
|
||||||
LiveIntervalUnion::Query &Q = query(VirtReg, *AI);
|
E = SplitLoopSet.end(); I != E; ++I)
|
||||||
if (!Q.checkInterference())
|
SplitLoops.push_back(LoopRanges->getLoopRange(*I));
|
||||||
continue;
|
array_pod_sort(SplitLoops.begin(), SplitLoops.end(),
|
||||||
LiveIntervalUnion::InterferenceResult IR = Q.firstInterference();
|
MachineLoopRange::byAreaDesc);
|
||||||
do {
|
|
||||||
DEBUG({dbgs() << " "; IR.print(dbgs(), TRI);});
|
// Find the first loop that is interference-free for some register in the
|
||||||
for (SplitAnalysis::LoopPtrSet::iterator I = SplitLoops.begin(),
|
// allocation order.
|
||||||
E = SplitLoops.end(); I != E; ++I) {
|
MachineLoopRange *Loop = 0;
|
||||||
MachineLoopRange *Range = LoopRanges->getLoopRange(*I);
|
for (unsigned i = 0, e = SplitLoops.size(); i != e; ++i) {
|
||||||
if (!Range->overlaps(IR.start(), IR.stop()))
|
if (unsigned PhysReg = findInterferenceFreeReg(SplitLoops[i],
|
||||||
continue;
|
VirtReg, Order)) {
|
||||||
DEBUG(dbgs() << ", overlaps " << *Range);
|
Loop = SplitLoops[i];
|
||||||
}
|
DEBUG(dbgs() << " " << TRI->getName(PhysReg)
|
||||||
DEBUG(dbgs() << '\n');
|
<< " has no interferences in " << *Loop << '\n');
|
||||||
} while (Q.nextInterference(IR));
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Loop) {
|
||||||
|
DEBUG(dbgs() << " All candidate loops have interference.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the split around Loop.
|
||||||
|
SmallVector<LiveInterval*, 4> SpillRegs;
|
||||||
|
LiveRangeEdit LREdit(VirtReg, SplitVRegs, SpillRegs);
|
||||||
|
SplitEditor(*SA, *LIS, *VRM, *DomTree, LREdit)
|
||||||
|
.splitAroundLoop(Loop->getLoop());
|
||||||
|
|
||||||
|
// We have new split regs, don't assign anything.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,6 +401,7 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
|
|||||||
|
|
||||||
MF = &mf;
|
MF = &mf;
|
||||||
RegAllocBase::init(getAnalysis<VirtRegMap>(), getAnalysis<LiveIntervals>());
|
RegAllocBase::init(getAnalysis<VirtRegMap>(), getAnalysis<LiveIntervals>());
|
||||||
|
DomTree = &getAnalysis<MachineDominatorTree>();
|
||||||
ReservedRegs = TRI->getReservedRegs(*MF);
|
ReservedRegs = TRI->getReservedRegs(*MF);
|
||||||
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
|
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
|
||||||
Loops = &getAnalysis<MachineLoopInfo>();
|
Loops = &getAnalysis<MachineLoopInfo>();
|
||||||
|
Loading…
Reference in New Issue
Block a user