mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237070 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -598,7 +598,10 @@ simplifyRelocatesOffABase(IntrinsicInst *RelocatedBase,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Create a Builder and replace the target callsite with a gep
|
// 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());
|
Builder.SetCurrentDebugLocation(ToReplace->getDebugLoc());
|
||||||
|
|
||||||
// If gc_relocate does not match the actual type, cast it to the right type.
|
// If gc_relocate does not match the actual type, cast it to the right type.
|
||||||
@ -626,14 +629,10 @@ simplifyRelocatesOffABase(IntrinsicInst *RelocatedBase,
|
|||||||
if (RelocatedBase->getType() != Base->getType()) {
|
if (RelocatedBase->getType() != Base->getType()) {
|
||||||
ActualRelocatedBase =
|
ActualRelocatedBase =
|
||||||
cast<Instruction>(Builder.CreateBitCast(RelocatedBase, Base->getType()));
|
cast<Instruction>(Builder.CreateBitCast(RelocatedBase, Base->getType()));
|
||||||
ActualRelocatedBase->removeFromParent();
|
|
||||||
ActualRelocatedBase->insertAfter(cast<Instruction>(RelocatedBase));
|
|
||||||
}
|
}
|
||||||
Value *Replacement = Builder.CreateGEP(
|
Value *Replacement = Builder.CreateGEP(
|
||||||
Derived->getSourceElementType(), ActualRelocatedBase, makeArrayRef(OffsetV));
|
Derived->getSourceElementType(), ActualRelocatedBase, makeArrayRef(OffsetV));
|
||||||
Instruction *ReplacementInst = cast<Instruction>(Replacement);
|
Instruction *ReplacementInst = cast<Instruction>(Replacement);
|
||||||
ReplacementInst->removeFromParent();
|
|
||||||
ReplacementInst->insertAfter(ActualRelocatedBase);
|
|
||||||
Replacement->takeName(ToReplace);
|
Replacement->takeName(ToReplace);
|
||||||
// If the newly generated derived pointer's type does not match the original derived
|
// 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.
|
// pointer's type, cast the new derived pointer to match it. Same reasoning as above.
|
||||||
@ -641,8 +640,6 @@ simplifyRelocatesOffABase(IntrinsicInst *RelocatedBase,
|
|||||||
if (ReplacementInst->getType() != ToReplace->getType()) {
|
if (ReplacementInst->getType() != ToReplace->getType()) {
|
||||||
ActualReplacement =
|
ActualReplacement =
|
||||||
cast<Instruction>(Builder.CreateBitCast(ReplacementInst, ToReplace->getType()));
|
cast<Instruction>(Builder.CreateBitCast(ReplacementInst, ToReplace->getType()));
|
||||||
ActualReplacement->removeFromParent();
|
|
||||||
ActualReplacement->insertAfter(ReplacementInst);
|
|
||||||
}
|
}
|
||||||
ToReplace->replaceAllUsesWith(ActualReplacement);
|
ToReplace->replaceAllUsesWith(ActualReplacement);
|
||||||
ToReplace->eraseFromParent();
|
ToReplace->eraseFromParent();
|
||||||
|
Reference in New Issue
Block a user