diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-06-04 09:18:41 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-06-04 09:18:41 +0000 |
commit | 14f8a50ce74830eb97811e52914ddca26ffedaa4 (patch) | |
tree | 6d1861bf53b6feb65e0dd92460b033125aa731f0 /lib/CodeGen/RegAllocLinearScan.cpp | |
parent | 375cac23b0efe93bdd869790aee9a5c2e0a6968c (diff) | |
download | external_llvm-14f8a50ce74830eb97811e52914ddca26ffedaa4.zip external_llvm-14f8a50ce74830eb97811e52914ddca26ffedaa4.tar.gz external_llvm-14f8a50ce74830eb97811e52914ddca26ffedaa4.tar.bz2 |
Add a stack slot coloring pass. Not yet enabled.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51934 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/RegAllocLinearScan.cpp')
-rw-r--r-- | lib/CodeGen/RegAllocLinearScan.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/CodeGen/RegAllocLinearScan.cpp b/lib/CodeGen/RegAllocLinearScan.cpp index 456ee63..8bfa868 100644 --- a/lib/CodeGen/RegAllocLinearScan.cpp +++ b/lib/CodeGen/RegAllocLinearScan.cpp @@ -12,10 +12,11 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "regalloc" -#include "llvm/CodeGen/LiveIntervalAnalysis.h" #include "PhysRegTracker.h" #include "VirtRegMap.h" #include "llvm/Function.h" +#include "llvm/CodeGen/LiveIntervalAnalysis.h" +#include "llvm/CodeGen/LiveStackAnalysis.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineLoopInfo.h" @@ -67,6 +68,7 @@ namespace { MachineRegisterInfo *reginfo_; BitVector allocatableRegs_; LiveIntervals* li_; + LiveStacks* ls_; const MachineLoopInfo *loopInfo; /// handled_ - Intervals are added to the handled_ set in the order of their @@ -103,6 +105,8 @@ namespace { // Make sure PassManager knows which analyses to make available // to coalescing and which analyses coalescing invalidates. AU.addRequiredTransitive<RegisterCoalescer>(); + AU.addRequired<LiveStacks>(); + AU.addPreserved<LiveStacks>(); AU.addRequired<MachineLoopInfo>(); AU.addPreserved<MachineLoopInfo>(); AU.addPreservedID(MachineDominatorsID); @@ -171,6 +175,9 @@ namespace { char RALinScan::ID = 0; } +static RegisterPass<RALinScan> +X("linearscan-regalloc", "Linear Scan Register Allocator"); + void RALinScan::ComputeRelatedRegClasses() { const TargetRegisterInfo &TRI = *tri_; @@ -258,6 +265,7 @@ bool RALinScan::runOnMachineFunction(MachineFunction &fn) { reginfo_ = &mf_->getRegInfo(); allocatableRegs_ = tri_->getAllocatableSet(fn); li_ = &getAnalysis<LiveIntervals>(); + ls_ = &getAnalysis<LiveStacks>(); loopInfo = &getAnalysis<MachineLoopInfo>(); // We don't run the coalescer here because we have no reason to @@ -504,6 +512,26 @@ static void RevertVectorIteratorsTo(RALinScan::IntervalPtrs &V, unsigned Point){ } } +/// addStackInterval - Create a LiveInterval for stack if the specified live +/// interval has been spilled. +static void addStackInterval(LiveInterval *cur, LiveStacks *ls_, + LiveIntervals *li_, VirtRegMap &vrm_) { + int SS = vrm_.getStackSlot(cur->reg); + if (SS == VirtRegMap::NO_STACK_SLOT) + return; + LiveInterval &SI = ls_->getOrCreateInterval(SS); + VNInfo *VNI; + if (SI.getNumValNums()) + VNI = SI.getValNumInfo(0); + else + VNI = SI.getNextValue(~0U, 0, ls_->getVNInfoAllocator()); + + LiveInterval &RI = li_->getInterval(cur->reg); + // FIXME: This may be overly conservative. + SI.MergeRangesInAsValue(RI, VNI); + SI.weight += RI.weight; +} + /// assignRegOrStackSlotAtInterval - assign a register if one is available, or /// spill. void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur) @@ -717,6 +745,7 @@ void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur) DOUT << "\t\t\tspilling(c): " << *cur << '\n'; std::vector<LiveInterval*> added = li_->addIntervalsForSpills(*cur, loopInfo, *vrm_); + addStackInterval(cur, ls_, li_, *vrm_); if (added.empty()) return; // Early exit if all spills were folded. @@ -769,6 +798,7 @@ void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur) earliestStart = std::min(earliestStart, i->first->beginNumber()); std::vector<LiveInterval*> newIs = li_->addIntervalsForSpills(*i->first, loopInfo, *vrm_); + addStackInterval(i->first, ls_, li_, *vrm_); std::copy(newIs.begin(), newIs.end(), std::back_inserter(added)); spilled.insert(reg); } @@ -782,6 +812,7 @@ void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur) earliestStart = std::min(earliestStart, i->first->beginNumber()); std::vector<LiveInterval*> newIs = li_->addIntervalsForSpills(*i->first, loopInfo, *vrm_); + addStackInterval(i->first, ls_, li_, *vrm_); std::copy(newIs.begin(), newIs.end(), std::back_inserter(added)); spilled.insert(reg); } |