aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-05-03 05:46:20 +0000
committerDan Gohman <gohman@apple.com>2009-05-03 05:46:20 +0000
commitf9a77b77c2324b2ca5c644909ebda387daf82fe3 (patch)
tree480474eeed43ad0aace0877991230a0ac7d26a1e /lib/Transforms
parent0e670dfa277279463d7c8d8bba093c2b2160d9ff (diff)
downloadexternal_llvm-f9a77b77c2324b2ca5c644909ebda387daf82fe3.tar.gz
external_llvm-f9a77b77c2324b2ca5c644909ebda387daf82fe3.tar.bz2
external_llvm-f9a77b77c2324b2ca5c644909ebda387daf82fe3.zip
Revert r70645 for now; it's causing a variety of regressions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70661 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp2
-rw-r--r--lib/Transforms/Scalar/LoopDeletion.cpp7
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp23
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp7
-rw-r--r--lib/Transforms/Utils/Local.cpp21
5 files changed, 51 insertions, 9 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index 3d9017d17e..be94c45793 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -124,6 +124,7 @@ DeleteTriviallyDeadInstructions(SmallPtrSet<Instruction*, 16> &Insts) {
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (Instruction *U = dyn_cast<Instruction>(I->getOperand(i)))
Insts.insert(U);
+ SE->deleteValueFromRecords(I);
DOUT << "INDVARS: Deleting: " << *I;
I->eraseFromParent();
Changed = true;
@@ -307,6 +308,7 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L,
// the PHI entirely. This is safe, because the NewVal won't be variant
// in the loop, so we don't need an LCSSA phi node anymore.
if (NumPreds == 1) {
+ SE->deleteValueFromRecords(PN);
PN->replaceAllUsesWith(ExitVal);
PN->eraseFromParent();
break;
diff --git a/lib/Transforms/Scalar/LoopDeletion.cpp b/lib/Transforms/Scalar/LoopDeletion.cpp
index 96b7a5288a..83c25619bf 100644
--- a/lib/Transforms/Scalar/LoopDeletion.cpp
+++ b/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -246,6 +246,13 @@ bool LoopDeletion::runOnLoop(Loop* L, LPPassManager& LPM) {
DT.eraseNode(*LI);
if (DF) DF->removeBlock(*LI);
+ // Remove instructions that we're deleting from ScalarEvolution.
+ for (BasicBlock::iterator BI = (*LI)->begin(), BE = (*LI)->end();
+ BI != BE; ++BI)
+ SE.deleteValueFromRecords(BI);
+
+ SE.deleteValueFromRecords(*LI);
+
// Remove the block from the reference counting scheme, so that we can
// delete it freely later.
(*LI)->dropAllReferences();
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 7d69dc8333..b940665152 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -253,6 +253,8 @@ void LoopStrengthReduce::DeleteTriviallyDeadInstructions() {
if (I == 0 || !isInstructionTriviallyDead(I))
continue;
+ SE->deleteValueFromRecords(I);
+
for (User::op_iterator OI = I->op_begin(), E = I->op_end(); OI != E; ++OI) {
if (Instruction *U = dyn_cast<Instruction>(*OI)) {
*OI = 0;
@@ -2128,6 +2130,7 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
// Remove the old compare instruction. The old indvar is probably dead too.
DeadInsts.push_back(cast<Instruction>(CondUse->OperandValToReplace));
+ SE->deleteValueFromRecords(OldCond);
OldCond->replaceAllUsesWith(Cond);
OldCond->eraseFromParent();
@@ -2248,12 +2251,16 @@ ICmpInst *LoopStrengthReduce::OptimizeSMax(Loop *L, ICmpInst *Cond,
Cond->getOperand(0), NewRHS, "scmp", Cond);
// Delete the max calculation instructions.
+ SE->deleteValueFromRecords(Cond);
Cond->replaceAllUsesWith(NewCond);
Cond->eraseFromParent();
Instruction *Cmp = cast<Instruction>(Sel->getOperand(0));
+ SE->deleteValueFromRecords(Sel);
Sel->eraseFromParent();
- if (Cmp->use_empty())
+ if (Cmp->use_empty()) {
+ SE->deleteValueFromRecords(Cmp);
Cmp->eraseFromParent();
+ }
CondUse->User = NewCond;
return NewCond;
}
@@ -2360,6 +2367,7 @@ void LoopStrengthReduce::OptimizeShadowIV(Loop *L) {
NewPH->addIncoming(NewIncr, PH->getIncomingBlock(Latch));
/* Remove cast operation */
+ SE->deleteValueFromRecords(ShadowUse);
ShadowUse->replaceAllUsesWith(NewPH);
ShadowUse->eraseFromParent();
SI->second.Users.erase(CandidateUI);
@@ -2499,8 +2507,17 @@ bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager &LPM) {
DeleteTriviallyDeadInstructions();
// At this point, it is worth checking to see if any recurrence PHIs are also
- // dead, so that we can remove them as well.
- DeleteDeadPHIs(L->getHeader());
+ // dead, so that we can remove them as well. To keep ScalarEvolution
+ // current, use a ValueDeletionListener class.
+ struct LSRListener : public ValueDeletionListener {
+ ScalarEvolution &SE;
+ explicit LSRListener(ScalarEvolution &se) : SE(se) {}
+
+ virtual void ValueWillBeDeleted(Value *V) {
+ SE.deleteValueFromRecords(V);
+ }
+ } VDL(*SE);
+ DeleteDeadPHIs(L->getHeader(), &VDL);
return Changed;
}
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 93764b6d1a..076f89e337 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -78,8 +78,9 @@ void llvm::FoldSingleEntryPHINodes(BasicBlock *BB) {
/// DeleteDeadPHIs - Examine each PHI in the given block and delete it if it
/// is dead. Also recursively delete any operands that become dead as
/// a result. This includes tracing the def-use list from the PHI to see if
-/// it is ultimately unused or if it reaches an unused cycle.
-void llvm::DeleteDeadPHIs(BasicBlock *BB) {
+/// it is ultimately unused or if it reaches an unused cycle. If a
+/// ValueDeletionListener is specified, it is notified of the deletions.
+void llvm::DeleteDeadPHIs(BasicBlock *BB, ValueDeletionListener *VDL) {
// Recursively deleting a PHI may cause multiple PHIs to be deleted
// or RAUW'd undef, so use an array of WeakVH for the PHIs to delete.
SmallVector<WeakVH, 8> PHIs;
@@ -89,7 +90,7 @@ void llvm::DeleteDeadPHIs(BasicBlock *BB) {
for (unsigned i = 0, e = PHIs.size(); i != e; ++i)
if (PHINode *PN = dyn_cast_or_null<PHINode>(PHIs[i].operator Value*()))
- RecursivelyDeleteDeadPHINode(PN);
+ RecursivelyDeleteDeadPHINode(PN, VDL);
}
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index fea739cb46..3b36362bb3 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -178,10 +178,18 @@ bool llvm::isInstructionTriviallyDead(Instruction *I) {
return false;
}
+/// ~ValueDeletionListener - A trivial dtor, defined out of line to give the
+/// class a home.
+llvm::ValueDeletionListener::~ValueDeletionListener() {}
+
/// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
/// trivially dead instruction, delete it. If that makes any of its operands
/// trivially dead, delete them too, recursively.
-void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) {
+///
+/// If a ValueDeletionListener is specified, it is notified of instructions that
+/// are actually deleted (before they are actually deleted).
+void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V,
+ ValueDeletionListener *VDL) {
Instruction *I = dyn_cast<Instruction>(V);
if (!I || !I->use_empty() || !isInstructionTriviallyDead(I))
return;
@@ -193,6 +201,10 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) {
I = DeadInsts.back();
DeadInsts.pop_back();
+ // If the client wanted to know, tell it about deleted instructions.
+ if (VDL)
+ VDL->ValueWillBeDeleted(I);
+
// Null out all of the instruction's operands to see if any operand becomes
// dead as we go.
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
@@ -218,8 +230,11 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) {
/// either forms a cycle or is terminated by a trivially dead instruction,
/// delete it. If that makes any of its operands trivially dead, delete them
/// too, recursively.
+///
+/// If a ValueDeletionListener is specified, it is notified of instructions that
+/// are actually deleted (before they are actually deleted).
void
-llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
+llvm::RecursivelyDeleteDeadPHINode(PHINode *PN, ValueDeletionListener *VDL) {
// We can remove a PHI if it is on a cycle in the def-use graph
// where each node in the cycle has degree one, i.e. only one use,
@@ -238,7 +253,7 @@ llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
if (!PHIs.insert(cast<PHINode>(JP))) {
// Break the cycle and delete the PHI and its operands.
JP->replaceAllUsesWith(UndefValue::get(JP->getType()));
- RecursivelyDeleteTriviallyDeadInstructions(JP);
+ RecursivelyDeleteTriviallyDeadInstructions(JP, VDL);
break;
}
}