diff options
author | Bill Wendling <isanbard@gmail.com> | 2006-11-16 02:41:50 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2006-11-16 02:41:50 +0000 |
commit | 01352aa1875ee08ae847cce398322042830d92ed (patch) | |
tree | 2f94c497f8b5af3ceab73fb573f19a8879c4eecd /lib/CodeGen/LiveIntervalAnalysis.cpp | |
parent | 027f388ab8aa509e5614168d451150def8765b3c (diff) | |
download | llvm-01352aa1875ee08ae847cce398322042830d92ed.tar.gz llvm-01352aa1875ee08ae847cce398322042830d92ed.tar.bz2 llvm-01352aa1875ee08ae847cce398322042830d92ed.tar.xz |
Added a new method "CreateNewLiveInterval" which, given a list of
LiveRanges, creates a new LiveInterval from them. The LiveRanges should
have existed already in another LiveInterval, but removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31780 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/LiveIntervalAnalysis.cpp')
-rw-r--r-- | lib/CodeGen/LiveIntervalAnalysis.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 03f38602ae..a57e8aa6d3 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -251,6 +251,55 @@ void LiveIntervals::print(std::ostream &O, const Module* ) const { } } +/// CreateNewLiveInterval - Create a new live interval with the given live +/// ranges. The new live interval will have an infinite spill weight. +LiveInterval& +LiveIntervals::CreateNewLiveInterval(const LiveInterval *LI, + const std::vector<LiveRange> &LRs) { + const TargetRegisterClass *RC = mf_->getSSARegMap()->getRegClass(LI->reg); + + // Create a new virtual register for the spill interval. + unsigned NewVReg = mf_->getSSARegMap()->createVirtualRegister(RC); + + // Replace the old virtual registers in the machine operands with the shiny + // new one. + for (std::vector<LiveRange>::const_iterator + I = LRs.begin(), E = LRs.end(); I != E; ++I) { + unsigned Index = getBaseIndex(I->start); + unsigned End = getBaseIndex(I->end - 1) + InstrSlots::NUM; + + for (; Index != End; Index += InstrSlots::NUM) { + // Skip deleted instructions + while (Index != End && !getInstructionFromIndex(Index)) + Index += InstrSlots::NUM; + + if (Index == End) break; + + MachineInstr *MI = getInstructionFromIndex(Index); + + for (unsigned J = 0; J != MI->getNumOperands(); ++J) { + MachineOperand &MOp = MI->getOperand(J); + if (MOp.isRegister() && rep(MOp.getReg()) == LI->reg) + MOp.setReg(NewVReg); + } + } + } + + LiveInterval &NewLI = getOrCreateInterval(NewVReg); + + // The spill weight is now infinity as it cannot be spilled again + NewLI.weight = float(HUGE_VAL); + + for (std::vector<LiveRange>::const_iterator + I = LRs.begin(), E = LRs.end(); I != E; ++I) { + DEBUG(std::cerr << " Adding live range " << *I << " to new interval\n"); + NewLI.addRange(*I); + } + + DEBUG(std::cerr << "Created new live interval " << NewLI << "\n"); + return NewLI; +} + std::vector<LiveInterval*> LiveIntervals:: addIntervalsForSpills(const LiveInterval &li, VirtRegMap &vrm, int slot) { // since this is called after the analysis is done we don't know if |