Adjust to the changed StructType interface. In particular, getElementTypes() is...
[oota-llvm.git] / lib / Analysis / DataStructure / DataStructure.cpp
index 57651d78e1ee5677641df083e3d2f1afad1699f7..f67d0d613f1d89e41b76eb15594336bb04d7e451 100644 (file)
@@ -30,6 +30,8 @@ namespace {
   Statistic<> NumCallNodesMerged("dsa", "Number of call nodes merged");
   Statistic<> NumNodeAllocated  ("dsa", "Number of nodes allocated");
   Statistic<> NumDNE            ("dsa", "Number of nodes removed by reachability");
+  Statistic<> NumTrivialDNE     ("dsa", "Number of nodes trivially removed");
+  Statistic<> NumTrivialGlobalDNE("dsa", "Number of globals trivially removed");
 
   cl::opt<bool>
   EnableDSNodeGlobalRootsHack("enable-dsa-globalrootshack", cl::Hidden,
@@ -46,7 +48,7 @@ namespace {
 using namespace DS;
 
 DSNode *DSNodeHandle::HandleForwarding() const {
-  assert(!N->ForwardNH.isNull() && "Can only be invoked if forwarding!");
+  assert(N->isForwarding() && "Can only be invoked if forwarding!");
 
   // Handle node forwarding here!
   DSNode *Next = N->ForwardNH.getNode();  // Cause recursive shrinkage
@@ -124,6 +126,10 @@ void DSNode::forwardNode(DSNode *To, unsigned Offset) {
   NodeType = DEAD;
   Size = 0;
   Ty = Type::VoidTy;
+
+  // Remove this node from the parent graph's Nodes list.
+  ParentGraph->unlinkNode(this);  
+  ParentGraph = 0;
 }
 
 // addGlobal - Add an entry for a global value to the Globals list.  This also
@@ -235,7 +241,7 @@ namespace {
         StackState &SS = Stack.back();
         if (const StructType *ST = dyn_cast<StructType>(SS.Ty)) {
           ++SS.Idx;
-          if (SS.Idx != ST->getElementTypes().size()) {
+          if (SS.Idx != ST->getNumElements()) {
             const StructLayout *SL = TD.getStructLayout(ST);
             SS.Offset += SL->MemberOffsets[SS.Idx]-SL->MemberOffsets[SS.Idx-1];
             return;
@@ -260,14 +266,14 @@ namespace {
       while (!Stack.empty() && !Stack.back().Ty->isFirstClassType()) {
         StackState &SS = Stack.back();
         if (const StructType *ST = dyn_cast<StructType>(SS.Ty)) {
-          if (ST->getElementTypes().empty()) {
+          if (ST->getNumElements() == 0) {
             assert(SS.Idx == 0);
             PopStackAndAdvance();
           } else {
             // Step into the structure...
-            assert(SS.Idx < ST->getElementTypes().size());
+            assert(SS.Idx < ST->getNumElements());
             const StructLayout *SL = TD.getStructLayout(ST);
-            Stack.push_back(StackState(ST->getElementTypes()[SS.Idx],
+            Stack.push_back(StackState(ST->getElementType(SS.Idx),
                                        SS.Offset+SL->MemberOffsets[SS.Idx]));
           }
         } else {
@@ -437,7 +443,7 @@ bool DSNode::mergeTypeInfo(const Type *NewTy, unsigned Offset,
         /* empty */;
 
       // The offset we are looking for must be in the i'th element...
-      SubType = STy->getElementTypes()[i];
+      SubType = STy->getElementType(i);
       O += SL.MemberOffsets[i];
       break;
     }
@@ -490,7 +496,7 @@ bool DSNode::mergeTypeInfo(const Type *NewTy, unsigned Offset,
         NextPadSize = SL.MemberOffsets[1];
       else
         NextPadSize = SubTypeSize;
-      NextSubType = STy->getElementTypes()[0];
+      NextSubType = STy->getElementType(0);
       NextSubTypeSize = TD.getTypeSize(NextSubType);
       break;
     }
@@ -1466,8 +1472,6 @@ static void removeIdenticalCalls(std::vector<DSCallSite> &Calls) {
 //
 void DSGraph::removeTriviallyDeadNodes() {
   TIME_REGION(X, "removeTriviallyDeadNodes");
-  removeIdenticalCalls(FunctionCalls);
-  removeIdenticalCalls(AuxFunctionCalls);
 
   // Loop over all of the nodes in the graph, calling getNode on each field.
   // This will cause all nodes to update their forwarding edges, causing
@@ -1527,6 +1531,7 @@ void DSGraph::removeTriviallyDeadNodes() {
           for (unsigned j = 0, e = Globals.size(); j != e; ++j)
             ScalarMap.erase(Globals[j]);
           Node.makeNodeDead();
+          ++NumTrivialGlobalDNE;
         }
       }
     }
@@ -1534,10 +1539,14 @@ void DSGraph::removeTriviallyDeadNodes() {
     if (Node.getNodeFlags() == 0 && Node.hasNoReferrers()) {
       // This node is dead!
       NI = Nodes.erase(NI);    // Erase & remove from node list.
+      ++NumTrivialDNE;
     } else {
       ++NI;
     }
   }
+
+  removeIdenticalCalls(FunctionCalls);
+  removeIdenticalCalls(AuxFunctionCalls);
 }
 
 
@@ -1751,12 +1760,8 @@ void DSGraph::removeDeadNodes(unsigned Flags) {
   AuxFunctionCalls.erase(AuxFunctionCalls.begin()+CurIdx,
                          AuxFunctionCalls.end());
 
-  // We are finally done with the GGCloner so we can clear it and then get rid
-  // of unused nodes in the GlobalsGraph produced by merging.
-  if (GGCloner.clonedNode()) {
-    GGCloner.destroy();
-    GlobalsGraph->removeTriviallyDeadNodes();
-  }
+  // We are finally done with the GGCloner so we can destroy it.
+  GGCloner.destroy();
 
   // At this point, any nodes which are visited, but not alive, are nodes
   // which can be removed.  Loop over all nodes, eliminating completely