[llvm] r237070 - Refactoring gc_relocate related code in CodeGenPrepare.cpp

Sanjoy Das sanjoy at playingwithpointers.com
Mon May 11 16:47:30 PDT 2015


Author: sanjoy
Date: Mon May 11 18:47:30 2015
New Revision: 237070

URL: http://llvm.org/viewvc/llvm-project?rev=237070&view=rev
Log:
Refactoring gc_relocate related code in CodeGenPrepare.cpp

Summary:
The original code inserted 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.

Patch by Chen Li!

Reviewers: reames, AndyAyers, sanjoy

Reviewed By: sanjoy

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9687

Modified:
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=237070&r1=237069&r2=237070&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Mon May 11 18:47:30 2015
@@ -598,7 +598,10 @@ simplifyRelocatesOffABase(IntrinsicInst
       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,14 +629,10 @@ simplifyRelocatesOffABase(IntrinsicInst
     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.
@@ -641,8 +640,6 @@ simplifyRelocatesOffABase(IntrinsicInst
     if (ReplacementInst->getType() != ToReplace->getType()) {
       ActualReplacement =
           cast<Instruction>(Builder.CreateBitCast(ReplacementInst, ToReplace->getType()));
-      ActualReplacement->removeFromParent();
-      ActualReplacement->insertAfter(ReplacementInst);
     }
     ToReplace->replaceAllUsesWith(ActualReplacement);
     ToReplace->eraseFromParent();





More information about the llvm-commits mailing list