From ccb33335a3eae11ebb1cd17b5c5d5630b34fae0d Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Fri, 20 Sep 2002 00:45:47 +0000 Subject: [PATCH] Allow copy coalescing in more cases: if sum of node degrees is more than than #available regs, compute the sum excluding duplicates and if that is less than #regs, go ahead and coalesce. Add method IGNode::getCombinedDegree to count excluding duplicates. llvm-svn: 3842 --- lib/CodeGen/RegAlloc/IGNode.cpp | 16 ++++++++++++++++ lib/CodeGen/RegAlloc/LiveRangeInfo.cpp | 11 ++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/RegAlloc/IGNode.cpp b/lib/CodeGen/RegAlloc/IGNode.cpp index c8fca7a23b6..caee2961664 100644 --- a/lib/CodeGen/RegAlloc/IGNode.cpp +++ b/lib/CodeGen/RegAlloc/IGNode.cpp @@ -36,3 +36,19 @@ void IGNode::delAdjIGNode(const IGNode *Node) { assert( It != AdjList.end() ); // the node must be there AdjList.erase(It); } + +//----------------------------------------------------------------------------- +// Get the number of unique neighbors if these two nodes are merged +//----------------------------------------------------------------------------- + +unsigned +IGNode::getCombinedDegree(const IGNode* otherNode) const +{ + std::vector nbrs(AdjList); + nbrs.insert(nbrs.end(), otherNode->AdjList.begin(), otherNode->AdjList.end()); + sort(nbrs.begin(), nbrs.end()); + std::vector::iterator new_end = unique(nbrs.begin(), nbrs.end()); + return new_end - nbrs.begin(); +} + + diff --git a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp index 7ad70186663..2037d815682 100644 --- a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp +++ b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp @@ -318,6 +318,12 @@ void LiveRangeInfo::coalesceLRs() LROfDef->getUserIGNode()->getNumOfNeighbors() + LROfUse->getUserIGNode()->getNumOfNeighbors(); + if (CombinedDegree > RCOfDef->getNumOfAvailRegs()) { + // get more precise estimate of combined degree + CombinedDegree = LROfDef->getUserIGNode()-> + getCombinedDegree(LROfUse->getUserIGNode()); + } + if (CombinedDegree <= RCOfDef->getNumOfAvailRegs()) { // if both LRs do not have suggested colors if (!(LROfDef->hasSuggestedColor() && @@ -353,7 +359,10 @@ void LiveRangeInfo::printLiveRanges() { for( ; HMI != LiveRangeMap.end(); ++HMI) { if (HMI->first && HMI->second) { cerr << " Value* " << RAV(HMI->first) << "\t: "; - cerr << "LR# " << HMI->second->getUserIGNode()->getIndex(); + if (IGNode* igNode = HMI->second->getUserIGNode()) + cerr << "LR# " << igNode->getIndex(); + else + cerr << "LR# " << ""; cerr << "\t:Values = "; printSet(*HMI->second); cerr << "\n"; } }