[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/DataStructure.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Oct 29 22:41:36 PDT 2004



Changes in directory llvm/lib/Analysis/DataStructure:

DataStructure.cpp updated: 1.181 -> 1.182
---
Log message:

Fix three bugs:
 1. Calls to external global VARIABLES should not be treated as a call to an
    external function
 2. Efficiently deleting an element from a vector by using std::swap with
    the back, then pop_back is NOT a good way to keep the vector sorted.
 3. Our hope of having stuff get deleted by making them redundant just won't
    work.  In particular, if we have three calls in sequence that should be
    merged: A, B, C   first we unify B into A.  To be sure that they appeared
    identical (so B would be erased) we set B = A.  On the next step, we 
    unified C into A and set C = A.  Unfortunately, this is no guarantee that
    C = B, so we would fail to delete the dead call.  Switch to a more 
    explicit scheme.



---
Diffs of the changes:  (+12 -9)

Index: llvm/lib/Analysis/DataStructure/DataStructure.cpp
diff -u llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.181 llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.182
--- llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.181	Fri Oct 29 23:05:01 2004
+++ llvm/lib/Analysis/DataStructure/DataStructure.cpp	Sat Oct 30 00:41:23 2004
@@ -1491,7 +1491,7 @@
 static inline bool nodeContainsExternalFunction(const DSNode *N) {
   const std::vector<GlobalValue*> &Globals = N->getGlobals();
   for (unsigned i = 0, e = Globals.size(); i != e; ++i)
-    if (Globals[i]->isExternal())
+    if (Globals[i]->isExternal() && isa<Function>(Globals[i]))
       return true;
   return false;
 }
@@ -1507,6 +1507,9 @@
   Function *LastCalleeFunc = 0;
   unsigned NumDuplicateCalls = 0;
   bool LastCalleeContainsExternalFunction = false;
+
+  std::vector<unsigned> CallsToDelete;
+
   for (unsigned i = 0; i != Calls.size(); ++i) {
     DSCallSite &CS = Calls[i];
 
@@ -1518,9 +1521,7 @@
 #ifndef NDEBUG
       std::cerr << "WARNING: Useless call site found.\n";
 #endif
-      CS.swap(Calls.back());
-      Calls.pop_back();
-      --i;
+      CallsToDelete.push_back(i);
     } else {
       // If the return value or any arguments point to a void node with no
       // information at all in it, and the call node is the only node to point
@@ -1563,11 +1564,8 @@
           DSCallSite &OCS = Calls[i-1];
           OCS.mergeWith(CS);
           
-          // The node will now be eliminated as a duplicate!
-          if (CS.getNumPtrArgs() < OCS.getNumPtrArgs())
-            CS = OCS;
-          else if (CS.getNumPtrArgs() > OCS.getNumPtrArgs())
-            OCS = CS;
+          // No need to keep this call anymore.
+          CallsToDelete.push_back(i);
         }
 #endif
       } else {
@@ -1583,6 +1581,11 @@
     }
   }
 #endif
+
+  unsigned NumDeleted = 0;
+  for (unsigned i = 0, e = CallsToDelete.size(); i != e; ++i)
+    Calls.erase(Calls.begin()+CallsToDelete[i]-NumDeleted++);
+
   Calls.erase(std::unique(Calls.begin(), Calls.end()), Calls.end());
 
   // Track the number of call nodes merged away...






More information about the llvm-commits mailing list