Allow LiveIntervalMap to be reused by resetting the current live interval.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113815 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen
2010-09-13 23:29:09 +00:00
parent 8466fa1842
commit 9ca2aeb2d2
2 changed files with 33 additions and 18 deletions

View File

@ -346,9 +346,15 @@ makeVV(const VNInfo *a, VNInfo *b) {
return std::make_pair(a, b); return std::make_pair(a, b);
} }
void LiveIntervalMap::reset(LiveInterval *li) {
li_ = li;
valueMap_.clear();
}
// defValue - Introduce a li_ def for ParentVNI that could be later than // defValue - Introduce a li_ def for ParentVNI that could be later than
// ParentVNI->def. // ParentVNI->def.
VNInfo *LiveIntervalMap::defValue(const VNInfo *ParentVNI, SlotIndex Idx) { VNInfo *LiveIntervalMap::defValue(const VNInfo *ParentVNI, SlotIndex Idx) {
assert(li_ && "call reset first");
assert(ParentVNI && "Mapping NULL value"); assert(ParentVNI && "Mapping NULL value");
assert(Idx.isValid() && "Invalid SlotIndex"); assert(Idx.isValid() && "Invalid SlotIndex");
assert(parentli_.getVNInfoAt(Idx) == ParentVNI && "Bad ParentVNI"); assert(parentli_.getVNInfoAt(Idx) == ParentVNI && "Bad ParentVNI");
@ -364,13 +370,14 @@ VNInfo *LiveIntervalMap::defValue(const VNInfo *ParentVNI, SlotIndex Idx) {
// Should we insert a minimal snippet of VNI LiveRange, or can we count on // Should we insert a minimal snippet of VNI LiveRange, or can we count on
// callers to do that? We need it for lookups of complex values. // callers to do that? We need it for lookups of complex values.
VNInfo *VNI = li_.getNextValue(Idx, 0, true, lis_.getVNInfoAllocator()); VNInfo *VNI = li_->getNextValue(Idx, 0, true, lis_.getVNInfoAllocator());
return VNI; return VNI;
} }
// mapValue - Find the mapped value for ParentVNI at Idx. // mapValue - Find the mapped value for ParentVNI at Idx.
// Potentially create phi-def values. // Potentially create phi-def values.
VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx) { VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx) {
assert(li_ && "call reset first");
assert(ParentVNI && "Mapping NULL value"); assert(ParentVNI && "Mapping NULL value");
assert(Idx.isValid() && "Invalid SlotIndex"); assert(Idx.isValid() && "Invalid SlotIndex");
assert(parentli_.getVNInfoAt(Idx) == ParentVNI && "Bad ParentVNI"); assert(parentli_.getVNInfoAt(Idx) == ParentVNI && "Bad ParentVNI");
@ -381,8 +388,8 @@ VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx) {
// This was an unknown value. Create a simple mapping. // This was an unknown value. Create a simple mapping.
if (InsP.second) if (InsP.second)
return InsP.first->second = li_.createValueCopy(ParentVNI, return InsP.first->second = li_->createValueCopy(ParentVNI,
lis_.getVNInfoAllocator()); lis_.getVNInfoAllocator());
// This was a simple mapped value. // This was a simple mapped value.
if (InsP.first->second) if (InsP.first->second)
return InsP.first->second; return InsP.first->second;
@ -449,7 +456,7 @@ VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx) {
// We have a collision between the old and new VNI at Succ. That means // We have a collision between the old and new VNI at Succ. That means
// neither dominates and we need a new phi-def. // neither dominates and we need a new phi-def.
VNI = li_.getNextValue(Start, 0, true, lis_.getVNInfoAllocator()); VNI = li_->getNextValue(Start, 0, true, lis_.getVNInfoAllocator());
VNI->setIsPHIDef(true); VNI->setIsPHIDef(true);
InsP.first->second = VNI; InsP.first->second = VNI;
@ -482,11 +489,11 @@ VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx) {
if (MBB == IdxMBB) { if (MBB == IdxMBB) {
// Don't add full liveness to IdxMBB, stop at Idx. // Don't add full liveness to IdxMBB, stop at Idx.
if (Start != Idx) if (Start != Idx)
li_.addRange(LiveRange(Start, Idx, VNI)); li_->addRange(LiveRange(Start, Idx, VNI));
// The caller had better add some liveness to IdxVNI, or it leaks. // The caller had better add some liveness to IdxVNI, or it leaks.
IdxVNI = VNI; IdxVNI = VNI;
} else } else
li_.addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI)); li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI));
} }
assert(IdxVNI && "Didn't find value for Idx"); assert(IdxVNI && "Didn't find value for Idx");
@ -497,8 +504,9 @@ VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx) {
// parentli_ is assumed to be live at Idx. Extend the live range to Idx. // parentli_ is assumed to be live at Idx. Extend the live range to Idx.
// Return the found VNInfo, or NULL. // Return the found VNInfo, or NULL.
VNInfo *LiveIntervalMap::extendTo(MachineBasicBlock *MBB, SlotIndex Idx) { VNInfo *LiveIntervalMap::extendTo(MachineBasicBlock *MBB, SlotIndex Idx) {
LiveInterval::iterator I = std::upper_bound(li_.begin(), li_.end(), Idx); assert(li_ && "call reset first");
if (I == li_.begin()) LiveInterval::iterator I = std::upper_bound(li_->begin(), li_->end(), Idx);
if (I == li_->begin())
return 0; return 0;
--I; --I;
if (I->start < lis_.getMBBStartIdx(MBB)) if (I->start < lis_.getMBBStartIdx(MBB))
@ -512,10 +520,11 @@ VNInfo *LiveIntervalMap::extendTo(MachineBasicBlock *MBB, SlotIndex Idx) {
// ParentVNI must be live in the [Start;End) interval. // ParentVNI must be live in the [Start;End) interval.
void LiveIntervalMap::addSimpleRange(SlotIndex Start, SlotIndex End, void LiveIntervalMap::addSimpleRange(SlotIndex Start, SlotIndex End,
const VNInfo *ParentVNI) { const VNInfo *ParentVNI) {
assert(li_ && "call reset first");
VNInfo *VNI = mapValue(ParentVNI, Start); VNInfo *VNI = mapValue(ParentVNI, Start);
// A simple mappoing is easy. // A simple mappoing is easy.
if (VNI->def == ParentVNI->def) { if (VNI->def == ParentVNI->def) {
li_.addRange(LiveRange(Start, End, VNI)); li_->addRange(LiveRange(Start, End, VNI));
return; return;
} }
@ -524,30 +533,31 @@ void LiveIntervalMap::addSimpleRange(SlotIndex Start, SlotIndex End,
MachineFunction::iterator MBBE = lis_.getMBBFromIndex(End); MachineFunction::iterator MBBE = lis_.getMBBFromIndex(End);
if (MBB == MBBE) { if (MBB == MBBE) {
li_.addRange(LiveRange(Start, End, VNI)); li_->addRange(LiveRange(Start, End, VNI));
return; return;
} }
// First block. // First block.
li_.addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI)); li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI));
// Run sequence of full blocks. // Run sequence of full blocks.
for (++MBB; MBB != MBBE; ++MBB) { for (++MBB; MBB != MBBE; ++MBB) {
Start = lis_.getMBBStartIdx(MBB); Start = lis_.getMBBStartIdx(MBB);
li_.addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB),
mapValue(ParentVNI, Start))); mapValue(ParentVNI, Start)));
} }
// Final block. // Final block.
Start = lis_.getMBBStartIdx(MBB); Start = lis_.getMBBStartIdx(MBB);
if (Start != End) if (Start != End)
li_.addRange(LiveRange(Start, End, mapValue(ParentVNI, Start))); li_->addRange(LiveRange(Start, End, mapValue(ParentVNI, Start)));
} }
/// addRange - Add live ranges to li_ where [Start;End) intersects parentli_. /// addRange - Add live ranges to li_ where [Start;End) intersects parentli_.
/// All needed values whose def is not inside [Start;End) must be defined /// All needed values whose def is not inside [Start;End) must be defined
/// beforehand so mapValue will work. /// beforehand so mapValue will work.
void LiveIntervalMap::addRange(SlotIndex Start, SlotIndex End) { void LiveIntervalMap::addRange(SlotIndex Start, SlotIndex End) {
assert(li_ && "call reset first");
LiveInterval::const_iterator B = parentli_.begin(), E = parentli_.end(); LiveInterval::const_iterator B = parentli_.begin(), E = parentli_.end();
LiveInterval::const_iterator I = std::lower_bound(B, E, Start); LiveInterval::const_iterator I = std::lower_bound(B, E, Start);

View File

@ -151,7 +151,7 @@ class LiveIntervalMap {
const LiveInterval &parentli_; const LiveInterval &parentli_;
// The child interval's values are fully contained inside parentli_ values. // The child interval's values are fully contained inside parentli_ values.
LiveInterval &li_; LiveInterval *li_;
typedef DenseMap<const VNInfo*, VNInfo*> ValueMap; typedef DenseMap<const VNInfo*, VNInfo*> ValueMap;
@ -172,9 +172,14 @@ class LiveIntervalMap {
public: public:
LiveIntervalMap(LiveIntervals &lis, LiveIntervalMap(LiveIntervals &lis,
const LiveInterval &parentli, const LiveInterval &parentli)
LiveInterval &li) : lis_(lis), parentli_(parentli), li_(0) {}
: lis_(lis), parentli_(parentli), li_(li) {}
/// reset - clear all data structures and start a new live interval.
void reset(LiveInterval *);
/// getLI - return the current live interval.
LiveInterval *getLI() const { return li_; }
/// defValue - define a value in li_ from the parentli_ value VNI and Idx. /// defValue - define a value in li_ from the parentli_ value VNI and Idx.
/// Idx does not have to be ParentVNI->def, but it must be contained within /// Idx does not have to be ParentVNI->def, but it must be contained within