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

John Criswell criswell at uiuc.edu
Fri Jul 23 13:25:32 PDT 2010


Author: criswell
Date: Fri Jul 23 15:25:31 2010
New Revision: 109260

URL: http://llvm.org/viewvc/llvm-project?rev=109260&view=rev
Log:
Use a worklist to record which operands of a constant need to be replaced
when replacing an original function with its clone.
This is intended to prevent potential iterator invalidation errors.

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=109260&r1=109259&r2=109260&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Fri Jul 23 15:25:31 2010
@@ -248,13 +248,26 @@
       // constant because they are uniqued.
       if (Constant *C = dyn_cast<Constant>(user)) {
         if (!isa<GlobalValue>(C)) {
+
+          //
+          // Scan through all operands in the constant.  If they are the
+          // function that we want to replace, then add them to a worklist (we
+          // use a worklist to avoid iterator invalidation errors).
+          //
+          std::vector<Use *> ReplaceWorklist;
           for (User::op_iterator use = user->op_begin();
                use != user->op_end();
                ++use) {
             if (use->get() == F) {
-              C->replaceUsesOfWithOnConstant(F, CEnew, use);
+              ReplaceWorklist.push_back (use);
             }
           }
+
+          //
+          // Do replacements in the worklist.
+          //
+          for (unsigned index = 0; index < ReplaceWorklist.size(); ++index)
+            C->replaceUsesOfWithOnConstant(F, CEnew, ReplaceWorklist[index]);
           continue;
         }
       }





More information about the llvm-commits mailing list