[llvm-commits] [poolalloc] r159063 - in /poolalloc/trunk/lib/DSA: DSGraph.cpp StdLibPass.cpp

Will Dietz wdietz2 at illinois.edu
Fri Jun 22 19:56:57 PDT 2012


Author: wdietz2
Date: Fri Jun 22 21:56:57 2012
New Revision: 159063

URL: http://llvm.org/viewvc/llvm-project?rev=159063&view=rev
Log:
DSGraph::removeFunctionCalls: Actually remove all calls to the specified func.

Update StdLibPass to avoid invalidating iterators as a result of this.

Doesn't seem to have any significant impact AFAICT, but this is
the right thing regardless.

Modified:
    poolalloc/trunk/lib/DSA/DSGraph.cpp
    poolalloc/trunk/lib/DSA/StdLibPass.cpp

Modified: poolalloc/trunk/lib/DSA/DSGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DSGraph.cpp?rev=159063&r1=159062&r2=159063&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/DSGraph.cpp (original)
+++ poolalloc/trunk/lib/DSA/DSGraph.cpp Fri Jun 22 21:56:57 2012
@@ -133,19 +133,25 @@
 void DSGraph::dump() const { print(errs()); }
 
 void DSGraph::removeFunctionCalls(Function& F) {
-  for (std::list<DSCallSite>::iterator I = FunctionCalls.begin(),
-         E = FunctionCalls.end(); I != E; ++I)
-    if (I->isDirectCall() && I->getCalleeFunc() == &F) {
-      FunctionCalls.erase(I);
-      break;
-    }
+  std::list<DSCallSite>::iterator Erase = FunctionCalls.end();
+  for (std::list<DSCallSite>::iterator I = FunctionCalls.begin();
+       I != Erase; ) {
+    if (I->isDirectCall() && I->getCalleeFunc() == &F)
+      std::swap(*I, *--Erase);
+    else
+      ++I;
+  }
+  FunctionCalls.erase(Erase, FunctionCalls.end());
 
-  for (std::list<DSCallSite>::iterator I = AuxFunctionCalls.begin(),
-         E = AuxFunctionCalls.end(); I != E; ++I)
-    if (I->isDirectCall() && I->getCalleeFunc() == &F) {
-      AuxFunctionCalls.erase(I);
-      break;
-    }
+  Erase = AuxFunctionCalls.end();
+  for (std::list<DSCallSite>::iterator I = AuxFunctionCalls.begin();
+       I != Erase; ) {
+    if (I->isDirectCall() && I->getCalleeFunc() == &F)
+      std::swap(*I, *--Erase);
+    else
+      ++I;
+  }
+  AuxFunctionCalls.erase(Erase, AuxFunctionCalls.end());
 }
 
 /// addObjectToGraph - This method can be used to add global, stack, and heap

Modified: poolalloc/trunk/lib/DSA/StdLibPass.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/StdLibPass.cpp?rev=159063&r1=159062&r2=159063&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/StdLibPass.cpp (original)
+++ poolalloc/trunk/lib/DSA/StdLibPass.cpp Fri Jun 22 21:56:57 2012
@@ -446,23 +446,25 @@
 //
 void
 StdLibDataStructures::eraseCallsTo(Function* F) {
+  typedef std::pair<DSGraph*,Function*> RemovalPair;
+  DenseSet<RemovalPair> ToRemove;
   for (Value::use_iterator ii = F->use_begin(), ee = F->use_end();
        ii != ee; ++ii)
     if (CallInst* CI = dyn_cast<CallInst>(*ii)){
       if (CI->getCalledValue() == F) {
         DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
         //delete the call
-        DEBUG(errs() << "Removing " << F->getName().str() << " from " 
-	      << CI->getParent()->getParent()->getName().str() << "\n");
-        Graph->removeFunctionCalls(*F);
+        DEBUG(errs() << "Removing " << F->getName().str() << " from "
+              << CI->getParent()->getParent()->getName().str() << "\n");
+        ToRemove.insert(std::make_pair(Graph, F));
       }
     }else if (InvokeInst* CI = dyn_cast<InvokeInst>(*ii)){
       if (CI->getCalledValue() == F) {
         DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
         //delete the call
-        DEBUG(errs() << "Removing " << F->getName().str() << " from " 
-	      << CI->getParent()->getParent()->getName().str() << "\n");
-        Graph->removeFunctionCalls(*F);
+        DEBUG(errs() << "Removing " << F->getName().str() << " from "
+              << CI->getParent()->getParent()->getName().str() << "\n");
+        ToRemove.insert(std::make_pair(Graph, F));
       }
     } else if(ConstantExpr *CE = dyn_cast<ConstantExpr>(*ii)) {
       if(CE->isCast()) {
@@ -472,14 +474,18 @@
             if(CI->getCalledValue() == CE) {
               DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
               //delete the call
-              DEBUG(errs() << "Removing " << F->getName().str() << " from " 
-	        << CI->getParent()->getParent()->getName().str() << "\n");
-              Graph->removeFunctionCalls(*F);
+              DEBUG(errs() << "Removing " << F->getName().str() << " from "
+                    << CI->getParent()->getParent()->getName().str() << "\n");
+              ToRemove.insert(std::make_pair(Graph, F));
             }
           }
         }
       }
     }
+
+  for(DenseSet<RemovalPair>::iterator I = ToRemove.begin(), E = ToRemove.end();
+      I != E; ++I)
+    I->first->removeFunctionCalls(*I->second);
 }
 
 //





More information about the llvm-commits mailing list