diff options
author | Dan Gohman <gohman@apple.com> | 2009-05-03 05:46:20 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-05-03 05:46:20 +0000 |
commit | f9a77b77c2324b2ca5c644909ebda387daf82fe3 (patch) | |
tree | 480474eeed43ad0aace0877991230a0ac7d26a1e /lib/Analysis/ScalarEvolution.cpp | |
parent | 0e670dfa277279463d7c8d8bba093c2b2160d9ff (diff) |
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/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | lib/Analysis/ScalarEvolution.cpp | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 48a2f52612..a6d39541aa 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -1466,6 +1466,34 @@ SCEVHandle ScalarEvolution::getUnknown(Value *V) { // Basic SCEV Analysis and PHI Idiom Recognition Code // +/// deleteValueFromRecords - This method should be called by the +/// client before it removes an instruction from the program, to make sure +/// that no dangling references are left around. +void ScalarEvolution::deleteValueFromRecords(Value *V) { + SmallVector<Value *, 16> Worklist; + + if (Scalars.erase(V)) { + if (PHINode *PN = dyn_cast<PHINode>(V)) + ConstantEvolutionLoopExitValue.erase(PN); + Worklist.push_back(V); + } + + while (!Worklist.empty()) { + Value *VV = Worklist.back(); + Worklist.pop_back(); + + for (Instruction::use_iterator UI = VV->use_begin(), UE = VV->use_end(); + UI != UE; ++UI) { + Instruction *Inst = cast<Instruction>(*UI); + if (Scalars.erase(Inst)) { + if (PHINode *PN = dyn_cast<PHINode>(VV)) + ConstantEvolutionLoopExitValue.erase(PN); + Worklist.push_back(Inst); + } + } + } +} + /// isSCEVable - Test if values of the given type are analyzable within /// the SCEV framework. This primarily includes integer types, and it /// can optionally include pointer types if the ScalarEvolution class @@ -1527,10 +1555,10 @@ bool ScalarEvolution::hasSCEV(Value *V) const { SCEVHandle ScalarEvolution::getSCEV(Value *V) { assert(isSCEVable(V->getType()) && "Value is not SCEVable!"); - std::map<SCEVCallbackVH, SCEVHandle>::iterator I = Scalars.find(V); + std::map<Value*, SCEVHandle>::iterator I = Scalars.find(V); if (I != Scalars.end()) return I->second; SCEVHandle S = createSCEV(V); - Scalars.insert(std::make_pair(SCEVCallbackVH(V, this), S)); + Scalars.insert(std::make_pair(V, S)); return S; } @@ -1619,8 +1647,7 @@ ScalarEvolution::getTruncateOrSignExtend(const SCEVHandle &V, void ScalarEvolution:: ReplaceSymbolicValueWithConcrete(Instruction *I, const SCEVHandle &SymName, const SCEVHandle &NewVal) { - std::map<SCEVCallbackVH, SCEVHandle>::iterator SI = - Scalars.find(SCEVCallbackVH(I, this)); + std::map<Value*, SCEVHandle>::iterator SI = Scalars.find(I); if (SI == Scalars.end()) return; SCEVHandle NV = @@ -1652,7 +1679,7 @@ SCEVHandle ScalarEvolution::createNodeForPHI(PHINode *PN) { SCEVHandle SymbolicName = getUnknown(PN); assert(Scalars.find(PN) == Scalars.end() && "PHI node already processed?"); - Scalars.insert(std::make_pair(SCEVCallbackVH(PN, this), SymbolicName)); + Scalars.insert(std::make_pair(PN, SymbolicName)); // Using this symbolic name for the PHI, analyze the value coming around // the back-edge. @@ -2104,7 +2131,7 @@ void ScalarEvolution::forgetLoopBackedgeTakenCount(const Loop *L) { void ScalarEvolution::forgetLoopPHIs(const Loop *L) { for (BasicBlock::iterator I = L->getHeader()->begin(); PHINode *PN = dyn_cast<PHINode>(I); ++I) - Scalars.erase(PN); + deleteValueFromRecords(PN); } /// ComputeBackedgeTakenCount - Compute the number of times the backedge @@ -3317,25 +3344,6 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, //===----------------------------------------------------------------------===// -// SCEVCallbackVH Class Implementation -//===----------------------------------------------------------------------===// - -void SCEVCallbackVH::deleted() { - assert(SE && "SCEVCallbackVH called with a non-null ScalarEvolution!"); - SE->Scalars.erase(getValPtr()); - // this now dangles! -} - -void SCEVCallbackVH::allUsesReplacedWith(Value *V) { - assert(SE && "SCEVCallbackVH called with a non-null ScalarEvolution!"); - SE->Scalars.erase(getValPtr()); - // this now dangles! -} - -SCEVCallbackVH::SCEVCallbackVH(Value *V, ScalarEvolution *se) - : CallbackVH(V), SE(se) {} - -//===----------------------------------------------------------------------===// // ScalarEvolution Class Implementation //===----------------------------------------------------------------------===// |