diff options
| author | Wei Mi <wmi@google.com> | 2016-04-15 23:16:44 +0000 |
|---|---|---|
| committer | Wei Mi <wmi@google.com> | 2016-04-15 23:16:44 +0000 |
| commit | 963f2df4d2aaa5e76aa6c0bc52f3de66af7be8c4 (patch) | |
| tree | 6acd7dacd2443a1ff01f9c257c82bed1c9d83ebe /llvm/lib/CodeGen | |
| parent | 6d09f993c266398d9bcfee6d71a03132167a01cd (diff) | |
| download | bcm5719-llvm-963f2df4d2aaa5e76aa6c0bc52f3de66af7be8c4.tar.gz bcm5719-llvm-963f2df4d2aaa5e76aa6c0bc52f3de66af7be8c4.zip | |
Don't skip splitSeparateComponents in eliminateDeadDefs for HoistSpillHelper::hoistAllSpills.
Because HoistSpillHelper::hoistAllSpills is called in postOptimization, before the
patch we didn't want LiveRangeEdit::eliminateDeadDefs to call splitSeparateComponents
and generate unassigned new vregs. However, skipping splitSeparateComponents will make
verify-machineinstrs unhappy, so I remove the early return, and use
HoistSpillHelper::LRE_DidCloneVirtReg to assign physreg/stackslot for those new vregs.
In addition, some code reorganization to make class HoistSpillHelper privately inheriting
from LiveRangeEdit::Delegate possible. This is to be consistent with class RAGreedy and
class RegisterCoalescer.
Differential Revision: http://reviews.llvm.org/D19142
llvm-svn: 266489
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/InlineSpiller.cpp | 34 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/LiveRangeEdit.cpp | 6 |
2 files changed, 23 insertions, 17 deletions
diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp index 5cdc3979fab..60a99f6b399 100644 --- a/llvm/lib/CodeGen/InlineSpiller.cpp +++ b/llvm/lib/CodeGen/InlineSpiller.cpp @@ -55,7 +55,8 @@ static cl::opt<bool> DisableHoisting("disable-spill-hoist", cl::Hidden, cl::desc("Disable inline spill hoisting")); namespace { -class HoistSpillHelper { +class HoistSpillHelper : private LiveRangeEdit::Delegate { + MachineFunction &MF; LiveIntervals &LIS; LiveStacks &LSS; AliasAnalysis *AA; @@ -105,7 +106,7 @@ class HoistSpillHelper { public: HoistSpillHelper(MachineFunctionPass &pass, MachineFunction &mf, VirtRegMap &vrm) - : LIS(pass.getAnalysis<LiveIntervals>()), + : MF(mf), LIS(pass.getAnalysis<LiveIntervals>()), LSS(pass.getAnalysis<LiveStacks>()), AA(&pass.getAnalysis<AAResultsWrapperPass>().getAAResults()), MDT(pass.getAnalysis<MachineDominatorTree>()), @@ -118,7 +119,8 @@ public: void addToMergeableSpills(MachineInstr *Spill, int StackSlot, unsigned Original); bool rmFromMergeableSpills(MachineInstr *Spill, int StackSlot); - void hoistAllSpills(LiveRangeEdit &Edit); + void hoistAllSpills(); + void LRE_DidCloneVirtReg(unsigned, unsigned) override; }; class InlineSpiller : public Spiller { @@ -1040,13 +1042,7 @@ void InlineSpiller::spill(LiveRangeEdit &edit) { /// Optimizations after all the reg selections and spills are done. /// -void InlineSpiller::postOptimization() { - SmallVector<unsigned, 4> NewVRegs; - LiveRangeEdit LRE(nullptr, NewVRegs, MF, LIS, &VRM, nullptr); - HSpiller.hoistAllSpills(LRE); - assert(NewVRegs.size() == 0 && - "No new vregs should be generated in hoistAllSpills"); -} +void InlineSpiller::postOptimization() { HSpiller.hoistAllSpills(); } /// When a spill is inserted, add the spill to MergeableSpills map. /// @@ -1360,7 +1356,10 @@ void HoistSpillHelper::runHoistSpills( /// its subtree to that node. In this way, we can get benefit locally even if /// hoisting all the equal spills to one cold place is impossible. /// -void HoistSpillHelper::hoistAllSpills(LiveRangeEdit &Edit) { +void HoistSpillHelper::hoistAllSpills() { + SmallVector<unsigned, 4> NewVRegs; + LiveRangeEdit Edit(nullptr, NewVRegs, MF, LIS, &VRM, this); + // Save the mapping between stackslot and its original reg. DenseMap<int, unsigned> SlotToOrigReg; for (unsigned i = 0, e = MRI.getNumVirtRegs(); i != e; ++i) { @@ -1436,6 +1435,17 @@ void HoistSpillHelper::hoistAllSpills(LiveRangeEdit &Edit) { RMEnt->RemoveOperand(i - 1); } } - Edit.eliminateDeadDefs(SpillsToRm, None, true); + Edit.eliminateDeadDefs(SpillsToRm, None); } } + +/// For VirtReg clone, the \p New register should have the same physreg or +/// stackslot as the \p old register. +void HoistSpillHelper::LRE_DidCloneVirtReg(unsigned New, unsigned Old) { + if (VRM.hasPhys(Old)) + VRM.assignVirt2Phys(New, VRM.getPhys(Old)); + else if (VRM.getStackSlot(Old) != VirtRegMap::NO_STACK_SLOT) + VRM.assignVirt2StackSlot(New, VRM.getStackSlot(Old)); + else + llvm_unreachable("VReg should be assigned either physreg or stackslot"); +} diff --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp index 987c2891544..3ed02f46c0e 100644 --- a/llvm/lib/CodeGen/LiveRangeEdit.cpp +++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp @@ -356,8 +356,7 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) { } void LiveRangeEdit::eliminateDeadDefs(SmallVectorImpl<MachineInstr *> &Dead, - ArrayRef<unsigned> RegsBeingSpilled, - bool NoSplit) { + ArrayRef<unsigned> RegsBeingSpilled) { ToShrinkSet ToShrink; for (;;) { @@ -379,9 +378,6 @@ void LiveRangeEdit::eliminateDeadDefs(SmallVectorImpl<MachineInstr *> &Dead, if (!LIS.shrinkToUses(LI, &Dead)) continue; - if (NoSplit) - continue; - // Don't create new intervals for a register being spilled. // The new intervals would have to be spilled anyway so its not worth it. // Also they currently aren't spilled so creating them and not spilling |

