[PATCH] D54011: [NFC][LICM] Factor out instruction erasing logic
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 1 16:54:00 PDT 2018
mkazantsev created this revision.
mkazantsev added a reviewer: apilipenko.
This patch factors out a function that makes all required updates
whenever an instruction gets erased.
https://reviews.llvm.org/D54011
Files:
lib/Transforms/Scalar/LICM.cpp
Index: lib/Transforms/Scalar/LICM.cpp
===================================================================
--- lib/Transforms/Scalar/LICM.cpp
+++ lib/Transforms/Scalar/LICM.cpp
@@ -123,6 +123,8 @@
const LoopInfo *LI,
const LoopSafetyInfo *SafetyInfo);
+void eraseInstruction(Instruction &I, AliasSetTracker *AST);
+
namespace {
struct LoopInvariantCodeMotion {
using ASTrackerMapTy = DenseMap<Loop *, std::unique_ptr<AliasSetTracker>>;
@@ -404,8 +406,7 @@
LLVM_DEBUG(dbgs() << "LICM deleting dead inst: " << I << '\n');
salvageDebugInfo(I);
++II;
- CurAST->deleteValue(&I);
- I.eraseFromParent();
+ eraseInstruction(I, CurAST);
Changed = true;
continue;
}
@@ -422,8 +423,7 @@
if (sink(I, LI, DT, CurLoop, SafetyInfo, ORE, FreeInLoop)) {
if (!FreeInLoop) {
++II;
- CurAST->deleteValue(&I);
- I.eraseFromParent();
+ eraseInstruction(I, CurAST);
}
Changed = true;
}
@@ -481,8 +481,7 @@
CurAST->copyValue(&I, C);
I.replaceAllUsesWith(C);
if (isInstructionTriviallyDead(&I, TLI)) {
- CurAST->deleteValue(&I);
- I.eraseFromParent();
+ eraseInstruction(I, CurAST);
}
Changed = true;
continue;
@@ -519,7 +518,7 @@
Product->setFastMathFlags(I.getFastMathFlags());
Product->insertAfter(&I);
I.replaceAllUsesWith(Product);
- I.eraseFromParent();
+ eraseInstruction(I, CurAST);
hoist(*ReciprocalDivisor, DT, CurLoop, SafetyInfo, ORE);
Changed = true;
@@ -888,6 +887,12 @@
return New;
}
+void eraseInstruction(Instruction &I, AliasSetTracker *AST) {
+ if (AST)
+ AST->deleteValue(&I);
+ I.eraseFromParent();
+}
+
static Instruction *sinkThroughTriviallyReplaceablePHI(
PHINode *TPN, Instruction *I, LoopInfo *LI,
SmallDenseMap<BasicBlock *, Instruction *, 32> &SunkCopies,
@@ -1086,7 +1091,7 @@
Instruction *New = sinkThroughTriviallyReplaceablePHI(PN, &I, LI, SunkCopies,
SafetyInfo, CurLoop);
PN->replaceAllUsesWith(New);
- PN->eraseFromParent();
+ eraseInstruction(*PN, nullptr);
Changed = true;
}
return Changed;
@@ -1516,7 +1521,7 @@
// If the SSAUpdater didn't use the load in the preheader, just zap it now.
if (PreheaderLoad->use_empty())
- PreheaderLoad->eraseFromParent();
+ eraseInstruction(*PreheaderLoad, CurAST);
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54011.172270.patch
Type: text/x-patch
Size: 2633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181101/f0f6eee7/attachment.bin>
More information about the llvm-commits
mailing list