From 01352aa1875ee08ae847cce398322042830d92ed Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 16 Nov 2006 02:41:50 +0000 Subject: [PATCH] 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 --- include/llvm/CodeGen/LiveIntervalAnalysis.h | 5 +++ lib/CodeGen/LiveIntervalAnalysis.cpp | 49 +++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/llvm/CodeGen/LiveIntervalAnalysis.h b/include/llvm/CodeGen/LiveIntervalAnalysis.h index 717063ecff4..11f836b99ac 100644 --- a/include/llvm/CodeGen/LiveIntervalAnalysis.h +++ b/include/llvm/CodeGen/LiveIntervalAnalysis.h @@ -148,6 +148,11 @@ namespace llvm { VirtRegMap& vrm, int slot); + /// CreateNewLiveInterval - Create a new live interval with the given live + /// ranges. The new live interval will have an infinite spill weight. + LiveInterval &CreateNewLiveInterval(const LiveInterval *LI, + const std::vector &LRs); + virtual void getAnalysisUsage(AnalysisUsage &AU) const; virtual void releaseMemory(); diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 03f38602aee..a57e8aa6d30 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 &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::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::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 LiveIntervals:: addIntervalsForSpills(const LiveInterval &li, VirtRegMap &vrm, int slot) { // since this is called after the analysis is done we don't know if