From 5190ce83744ceadeb0167330bbf83ff99de066ee Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 12 Nov 2002 07:20:45 +0000 Subject: [PATCH] Fix two bugs: * The globals vector was getting broken and unsorted, this caused vortex to get badly pessimized * Node offset handling was being handled really poorly, and in particular we were not merging types with offsets right. This causes several graphs to be non-merged. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4699 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/DataStructure/DataStructure.cpp | 54 ++++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp index f88b9997dd8..432dbb0d5c9 100644 --- a/lib/Analysis/DataStructure/DataStructure.cpp +++ b/lib/Analysis/DataStructure/DataStructure.cpp @@ -341,9 +341,9 @@ void MergeSortedVectors(vector &Dest, const vector &Src) { T Tmp = Dest[0]; // Save value in temporary... Dest = Src; // Copy over list... typename vector::iterator I = - std::lower_bound(Dest.begin(), Dest.end(),Tmp); - if (I == Dest.end() || *I != Src[0]) // If not already contained... - Dest.insert(I, Src[0]); + std::lower_bound(Dest.begin(), Dest.end(), Tmp); + if (I == Dest.end() || *I != Tmp) // If not already contained... + Dest.insert(I, Tmp); } else { // Make a copy to the side of Dest... @@ -387,9 +387,28 @@ void DSNode::mergeWith(const DSNodeHandle &NH, unsigned Offset) { return; } + // If both nodes are not at offset 0, make sure that we are merging the node + // at an later offset into the node with the zero offset. + // + if (Offset < NH.getOffset()) { + N->mergeWith(DSNodeHandle(this, Offset), NH.getOffset()); + return; + } else if (Offset == NH.getOffset() && getSize() < N->getSize()) { + // If the offsets are the same, merge the smaller node into the bigger node + N->mergeWith(DSNodeHandle(this, Offset), NH.getOffset()); + return; + } + + // Now we know that Offset >= NH.Offset, so convert it so our "Offset" (with + // respect to NH.Offset) is now zero. NOffset is the distance from the base + // of our object that N starts from. + // + unsigned NOffset = Offset-NH.getOffset(); + unsigned NSize = N->getSize(); + // Merge the type entries of the two nodes together... if (N->Ty.Ty != Type::VoidTy) { - mergeTypeInfo(N->Ty.Ty, Offset); + mergeTypeInfo(N->Ty.Ty, NOffset); // mergeTypeInfo can cause collapsing, which can cause this node to become // dead. @@ -404,30 +423,19 @@ void DSNode::mergeWith(const DSNodeHandle &NH, unsigned Offset) { if (!N->isNodeCompletelyFolded()) { N->foldNodeCompletely(); if (hasNoReferrers()) return; + NSize = N->getSize(); } } else if (N->isNodeCompletelyFolded()) { foldNodeCompletely(); - Offset = 0; if (hasNoReferrers()) return; + Offset = 0; + NOffset = NH.getOffset(); + NSize = N->getSize(); } N = NH.getNode(); - assert((NodeType & DSNode::DEAD) == 0); - if (this == N || N == 0) return; assert((NodeType & DSNode::DEAD) == 0); - // If both nodes are not at offset 0, make sure that we are merging the node - // at an later offset into the node with the zero offset. - // - if (Offset > NH.getOffset()) { - N->mergeWith(DSNodeHandle(this, Offset), NH.getOffset()); - return; - } else if (Offset == NH.getOffset() && getSize() < N->getSize()) { - // If the offsets are the same, merge the smaller node into the bigger node - N->mergeWith(DSNodeHandle(this, Offset), NH.getOffset()); - return; - } - #if 0 std::cerr << "\n\nMerging:\n"; N->print(std::cerr, 0); @@ -435,14 +443,6 @@ void DSNode::mergeWith(const DSNodeHandle &NH, unsigned Offset) { print(std::cerr, 0); #endif - // Now we know that Offset <= NH.Offset, so convert it so our "Offset" (with - // respect to NH.Offset) is now zero. - // - unsigned NOffset = NH.getOffset()-Offset; - unsigned NSize = N->getSize(); - - assert((NodeType & DSNode::DEAD) == 0); - // Remove all edges pointing at N, causing them to point to 'this' instead. // Make sure to adjust their offset, not just the node pointer. //