[llvm-commits] [poolalloc] r58614 - /poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp

John Criswell criswell at uiuc.edu
Mon Nov 3 08:03:12 PST 2008


Author: criswell
Date: Mon Nov  3 10:03:12 2008
New Revision: 58614

URL: http://llvm.org/viewvc/llvm-project?rev=58614&view=rev
Log:
When replacing references to an original function with a reference to a cloned
function, do not do replacements for call or invoke instructions in original
functions.  All cases where such replacement can properly pass pool descriptors
has already been done; any further replacement incorrect replaces a call to an
original function with an incorrect call to a cloned function.

Modified:
    poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp

Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=58614&r1=58613&r2=58614&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Mon Nov  3 10:03:12 2008
@@ -129,6 +129,7 @@
     if (!I->isDeclaration() && Graphs->hasDSGraph(*I))
       FindFunctionPoolArgs(*I);
 
+  // Map that maps an original function to its clone
   std::map<Function*, Function*> FuncMap;
 
   // Now clone a function using the pool arg list obtained in the previous
@@ -156,11 +157,41 @@
       ProcessFunctionBody(*I, FI != FuncMap.end() ? *FI->second : *I);
     }
 }
-  // Replace all uses of original functions with the transformed function.
+
+  //
+  // Replace any remaining uses of original functions with the transformed
+  // function i.e., the cloned function.
+  //
   for (std::map<Function *, Function *>::iterator I = FuncMap.begin(),
-         E = FuncMap.end(); I != E; ++I) {
+                                                  E = FuncMap.end();
+                                                  I != E; ++I) {
     Function *F = I->first;
-    F->replaceAllUsesWith(ConstantExpr::getPointerCast(I->second, F->getType()));
+
+    //
+    // Scan through all uses of the original function.  Replace it as long as
+    // the use is not a Call or Invoke instruction that
+    //  o) is within an original function (all such call instructions should
+    //     have been transformed already), and
+    //  o) the called function is the function that we're replacing
+    //
+    for (Function::use_iterator User = F->use_begin();
+                                User != F->use_end();
+                                ++User) {
+      if (CallInst * CI = dyn_cast<CallInst>(User)) {
+        if (CI->getCalledFunction() == F)
+          if ((FuncMap.find(CI->getParent()->getParent())) != FuncMap.end())
+            continue;
+      }
+
+      if (InvokeInst * CI = dyn_cast<InvokeInst>(User)) {
+        if (CI->getCalledFunction() == F)
+          if ((FuncMap.find(CI->getParent()->getParent())) != FuncMap.end())
+            continue;
+      }
+
+      User->replaceUsesOfWith (F, ConstantExpr::getPointerCast(I->second,
+                                                               F->getType()));
+    }
   }
 
   if (CurHeuristic->IsRealHeuristic())





More information about the llvm-commits mailing list