mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-17 15:38:40 +00:00
Extract method ProcessUses from LocalRewriter::RewriteMBB. Both parent and child
are still way too long, but it's a start. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116116 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
657985eb8b
commit
a32181a57d
@ -1110,6 +1110,12 @@ private:
|
||||
|
||||
bool InsertSpills(MachineInstr *MI);
|
||||
|
||||
void ProcessUses(MachineInstr &MI, AvailableSpills &Spills,
|
||||
std::vector<MachineInstr*> &MaybeDeadStores,
|
||||
BitVector &RegKills,
|
||||
ReuseInfo &ReusedOperands,
|
||||
std::vector<MachineOperand*> &KillOps);
|
||||
|
||||
void RewriteMBB(LiveIntervals *LIs,
|
||||
AvailableSpills &Spills, BitVector &RegKills,
|
||||
std::vector<MachineOperand*> &KillOps);
|
||||
@ -1828,7 +1834,7 @@ bool LocalRewriter::InsertRestores(MachineInstr *MI,
|
||||
return true;
|
||||
}
|
||||
|
||||
/// InsertEmergencySpills - Insert spills after MI if requested by VRM. Return
|
||||
/// InsertSpills - Insert spills after MI if requested by VRM. Return
|
||||
/// true if spills were inserted.
|
||||
bool LocalRewriter::InsertSpills(MachineInstr *MI) {
|
||||
if (!VRM->isSpillPt(MI))
|
||||
@ -1856,68 +1862,15 @@ bool LocalRewriter::InsertSpills(MachineInstr *MI) {
|
||||
}
|
||||
|
||||
|
||||
/// rewriteMBB - Keep track of which spills are available even after the
|
||||
/// register allocator is done with them. If possible, avoid reloading vregs.
|
||||
void
|
||||
LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||
AvailableSpills &Spills, BitVector &RegKills,
|
||||
/// ProcessUses - Process all of MI's spilled operands and all available
|
||||
/// operands.
|
||||
void LocalRewriter::ProcessUses(MachineInstr &MI, AvailableSpills &Spills,
|
||||
std::vector<MachineInstr*> &MaybeDeadStores,
|
||||
BitVector &RegKills,
|
||||
ReuseInfo &ReusedOperands,
|
||||
std::vector<MachineOperand*> &KillOps) {
|
||||
|
||||
DEBUG(dbgs() << "\n**** Local spiller rewriting MBB '"
|
||||
<< MBB->getName() << "':\n");
|
||||
|
||||
MachineFunction &MF = *MBB->getParent();
|
||||
|
||||
// MaybeDeadStores - When we need to write a value back into a stack slot,
|
||||
// keep track of the inserted store. If the stack slot value is never read
|
||||
// (because the value was used from some available register, for example), and
|
||||
// subsequently stored to, the original store is dead. This map keeps track
|
||||
// of inserted stores that are not used. If we see a subsequent store to the
|
||||
// same stack slot, the original store is deleted.
|
||||
std::vector<MachineInstr*> MaybeDeadStores;
|
||||
MaybeDeadStores.resize(MF.getFrameInfo()->getObjectIndexEnd(), NULL);
|
||||
|
||||
// ReMatDefs - These are rematerializable def MIs which are not deleted.
|
||||
SmallSet<MachineInstr*, 4> ReMatDefs;
|
||||
|
||||
// Clear kill info.
|
||||
SmallSet<unsigned, 2> KilledMIRegs;
|
||||
|
||||
// Keep track of the registers we have already spilled in case there are
|
||||
// multiple defs of the same register in MI.
|
||||
SmallSet<unsigned, 8> SpilledMIRegs;
|
||||
|
||||
RegKills.reset();
|
||||
KillOps.clear();
|
||||
KillOps.resize(TRI->getNumRegs(), NULL);
|
||||
|
||||
DistanceMap.clear();
|
||||
for (MachineBasicBlock::iterator MII = MBB->begin(), E = MBB->end();
|
||||
MII != E; ) {
|
||||
MachineBasicBlock::iterator NextMII = llvm::next(MII);
|
||||
|
||||
if (OptimizeByUnfold(MII, MaybeDeadStores, Spills, RegKills, KillOps))
|
||||
NextMII = llvm::next(MII);
|
||||
|
||||
if (InsertEmergencySpills(MII))
|
||||
NextMII = llvm::next(MII);
|
||||
|
||||
InsertRestores(MII, Spills, RegKills, KillOps);
|
||||
|
||||
if (InsertSpills(MII))
|
||||
NextMII = llvm::next(MII);
|
||||
|
||||
bool Erased = false;
|
||||
bool BackTracked = false;
|
||||
MachineInstr &MI = *MII;
|
||||
|
||||
// Remember DbgValue's which reference stack slots.
|
||||
if (MI.isDebugValue() && MI.getOperand(0).isFI())
|
||||
Slot2DbgValues[MI.getOperand(0).getIndex()].push_back(&MI);
|
||||
|
||||
/// ReusedOperands - Keep track of operand reuse in case we need to undo
|
||||
/// reuse.
|
||||
ReuseInfo ReusedOperands(MI, TRI);
|
||||
SmallVector<unsigned, 4> VirtUseOps;
|
||||
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
|
||||
MachineOperand &MO = MI.getOperand(i);
|
||||
@ -2144,7 +2097,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||
// Back-schedule reloads and remats.
|
||||
MachineBasicBlock::iterator InsertLoc =
|
||||
ComputeReloadLoc(&MI, MBB->begin(), PhysReg, TRI, DoReMat,
|
||||
SSorRMId, TII, MF);
|
||||
SSorRMId, TII, *MBB->getParent());
|
||||
MachineInstr *CopyMI = BuildMI(*MBB, InsertLoc, MI.getDebugLoc(),
|
||||
TII->get(TargetOpcode::COPY),
|
||||
DesignatedReg).addReg(PhysReg);
|
||||
@ -2159,7 +2112,7 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||
SubIdx ? TRI->getSubReg(DesignatedReg, SubIdx) : DesignatedReg;
|
||||
MI.getOperand(i).setReg(RReg);
|
||||
MI.getOperand(i).setSubReg(0);
|
||||
DEBUG(dbgs() << '\t' << *prior(MII));
|
||||
DEBUG(dbgs() << '\t' << *prior(InsertLoc));
|
||||
++NumReused;
|
||||
continue;
|
||||
} // if (PhysReg)
|
||||
@ -2183,8 +2136,8 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||
else {
|
||||
// Back-schedule reloads and remats.
|
||||
MachineBasicBlock::iterator InsertLoc =
|
||||
ComputeReloadLoc(MII, MBB->begin(), PhysReg, TRI, DoReMat,
|
||||
SSorRMId, TII, MF);
|
||||
ComputeReloadLoc(MI, MBB->begin(), PhysReg, TRI, DoReMat,
|
||||
SSorRMId, TII, *MBB->getParent());
|
||||
|
||||
if (DoReMat) {
|
||||
ReMaterialize(*MBB, InsertLoc, PhysReg, VirtReg, TII, TRI, *VRM);
|
||||
@ -2235,6 +2188,69 @@ LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// rewriteMBB - Keep track of which spills are available even after the
|
||||
/// register allocator is done with them. If possible, avoid reloading vregs.
|
||||
void
|
||||
LocalRewriter::RewriteMBB(LiveIntervals *LIs,
|
||||
AvailableSpills &Spills, BitVector &RegKills,
|
||||
std::vector<MachineOperand*> &KillOps) {
|
||||
|
||||
DEBUG(dbgs() << "\n**** Local spiller rewriting MBB '"
|
||||
<< MBB->getName() << "':\n");
|
||||
|
||||
MachineFunction &MF = *MBB->getParent();
|
||||
|
||||
// MaybeDeadStores - When we need to write a value back into a stack slot,
|
||||
// keep track of the inserted store. If the stack slot value is never read
|
||||
// (because the value was used from some available register, for example), and
|
||||
// subsequently stored to, the original store is dead. This map keeps track
|
||||
// of inserted stores that are not used. If we see a subsequent store to the
|
||||
// same stack slot, the original store is deleted.
|
||||
std::vector<MachineInstr*> MaybeDeadStores;
|
||||
MaybeDeadStores.resize(MF.getFrameInfo()->getObjectIndexEnd(), NULL);
|
||||
|
||||
// ReMatDefs - These are rematerializable def MIs which are not deleted.
|
||||
SmallSet<MachineInstr*, 4> ReMatDefs;
|
||||
|
||||
// Keep track of the registers we have already spilled in case there are
|
||||
// multiple defs of the same register in MI.
|
||||
SmallSet<unsigned, 8> SpilledMIRegs;
|
||||
|
||||
RegKills.reset();
|
||||
KillOps.clear();
|
||||
KillOps.resize(TRI->getNumRegs(), NULL);
|
||||
|
||||
DistanceMap.clear();
|
||||
for (MachineBasicBlock::iterator MII = MBB->begin(), E = MBB->end();
|
||||
MII != E; ) {
|
||||
MachineBasicBlock::iterator NextMII = llvm::next(MII);
|
||||
|
||||
if (OptimizeByUnfold(MII, MaybeDeadStores, Spills, RegKills, KillOps))
|
||||
NextMII = llvm::next(MII);
|
||||
|
||||
if (InsertEmergencySpills(MII))
|
||||
NextMII = llvm::next(MII);
|
||||
|
||||
InsertRestores(MII, Spills, RegKills, KillOps);
|
||||
|
||||
if (InsertSpills(MII))
|
||||
NextMII = llvm::next(MII);
|
||||
|
||||
bool Erased = false;
|
||||
bool BackTracked = false;
|
||||
MachineInstr &MI = *MII;
|
||||
|
||||
// Remember DbgValue's which reference stack slots.
|
||||
if (MI.isDebugValue() && MI.getOperand(0).isFI())
|
||||
Slot2DbgValues[MI.getOperand(0).getIndex()].push_back(&MI);
|
||||
|
||||
/// ReusedOperands - Keep track of operand reuse in case we need to undo
|
||||
/// reuse.
|
||||
ReuseInfo ReusedOperands(MI, TRI);
|
||||
|
||||
ProcessUses(MI, Spills, MaybeDeadStores, RegKills, ReusedOperands, KillOps);
|
||||
|
||||
DEBUG(dbgs() << '\t' << MI);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user