[PATCH] Refactoring gc_relocate related code in CodeGenPrepare.cpp

Chen Li meloli87 at gmail.com
Mon May 11 16:36:17 PDT 2015


Hi sanjoy, reames, AndyAyers,

The original code insert new instructions by following a Create->Remove->ReInsert flow. This patch removes the unnecessary Remove->ReInsert part by setting up the InsertPoint correctly at the very beginning. This change does not introduce any functionality change.

http://reviews.llvm.org/D9687

Files:
  lib/CodeGen/CodeGenPrepare.cpp

Index: lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- lib/CodeGen/CodeGenPrepare.cpp
+++ lib/CodeGen/CodeGenPrepare.cpp
@@ -598,7 +598,10 @@
       continue;
 
     // Create a Builder and replace the target callsite with a gep
-    IRBuilder<> Builder(ToReplace);
+    assert(RelocatedBase->getNextNode() && "Should always have one since it's not a terminator");
+
+    // Insert after RelocatedBase
+    IRBuilder<> Builder(RelocatedBase->getNextNode());
     Builder.SetCurrentDebugLocation(ToReplace->getDebugLoc());
 
     // If gc_relocate does not match the actual type, cast it to the right type.
@@ -626,23 +629,17 @@
     if (RelocatedBase->getType() != Base->getType()) {
       ActualRelocatedBase =
           cast<Instruction>(Builder.CreateBitCast(RelocatedBase, Base->getType()));
-      ActualRelocatedBase->removeFromParent();
-      ActualRelocatedBase->insertAfter(cast<Instruction>(RelocatedBase));
     }
     Value *Replacement = Builder.CreateGEP(
         Derived->getSourceElementType(), ActualRelocatedBase, makeArrayRef(OffsetV));
     Instruction *ReplacementInst = cast<Instruction>(Replacement);
-    ReplacementInst->removeFromParent();
-    ReplacementInst->insertAfter(ActualRelocatedBase);
     Replacement->takeName(ToReplace);
     // If the newly generated derived pointer's type does not match the original derived
     // pointer's type, cast the new derived pointer to match it. Same reasoning as above.
     Instruction *ActualReplacement = ReplacementInst;
     if (ReplacementInst->getType() != ToReplace->getType()) {
       ActualReplacement =
           cast<Instruction>(Builder.CreateBitCast(ReplacementInst, ToReplace->getType()));
-      ActualReplacement->removeFromParent();
-      ActualReplacement->insertAfter(ReplacementInst);
     }
     ToReplace->replaceAllUsesWith(ActualReplacement);
     ToReplace->eraseFromParent();

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9687.25526.patch
Type: text/x-patch
Size: 1937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150511/94f11d90/attachment.bin>


More information about the llvm-commits mailing list