Author: greened Date: Tue Jul 31 15:01:27 2007 New Revision: 40647 URL: http://llvm.org/viewvc/llvm-project?rev=40647&view=rev Log:
Fix GLIBCXX_DEBUG error owing to dereference of end iterator. There's no guarantee that an instruction returned by getDependency exists in the maps. Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h?rev=40647&r1=40646&r2=40647&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original) +++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Tue Jul 31 15:01:27 2007 @@ -32,9 +32,14 @@ class MemoryDependenceAnalysis : public FunctionPass { private: - - DenseMap<Instruction*, std::pair<Instruction*, bool> > depGraphLocal; - std::multimap<Instruction*, Instruction*> reverseDep; + + typedef DenseMap<Instruction*, std::pair<Instruction*, bool> > + depMapType; + + depMapType depGraphLocal; + + typedef std::multimap<Instruction*, Instruction*> reverseDepMapType; + reverseDepMapType reverseDep; Instruction* getCallSiteDependency(CallSite C, Instruction* start, bool local = true); Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=40647&r1=40646&r2=40647&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original) +++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Tue Jul 31 15:01:27 2007 @@ -308,33 +308,40 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction* rem) { // Figure out the new dep for things that currently depend on rem Instruction* newDep = NonLocal; - if (depGraphLocal[rem].first != NonLocal && - depGraphLocal[rem].second) { - // If we have dep info for rem, set them to it - BasicBlock::iterator RI = depGraphLocal[rem].first; - RI++; - newDep = RI; - } else if (depGraphLocal[rem].first == NonLocal && - depGraphLocal[rem].second ) { - // If we have a confirmed non-local flag, use it - newDep = NonLocal; - } else { - // Otherwise, use the immediate successor of rem - // NOTE: This is because, when getDependence is called, it will first check - // the immediate predecessor of what is in the cache. - BasicBlock::iterator RI = rem; - RI++; - newDep = RI; - } - std::multimap<Instruction*, Instruction*>::iterator I = reverseDep.find(rem); - while (I->first == rem) { - // Insert the new dependencies - // Mark it as unconfirmed as long as it is not the non-local flag - depGraphLocal[I->second] = std::make_pair(newDep, !newDep); - reverseDep.erase(I); - I = reverseDep.find(rem); + depMapType::iterator depGraphEntry = depGraphLocal.find(rem); + // We assume here that it's not in the reverse map if it's not in + // the dep map. Checking it could be expensive, so don't do it. + + if (depGraphEntry != depGraphLocal.end()) { + if (depGraphEntry->second.first != NonLocal && + depGraphEntry->second.second) { + // If we have dep info for rem, set them to it + BasicBlock::iterator RI = depGraphEntry->second.first; + RI++; + newDep = RI; + } else if (depGraphEntry->second.first == NonLocal && + depGraphEntry->second.second ) { + // If we have a confirmed non-local flag, use it + newDep = NonLocal; + } else { + // Otherwise, use the immediate successor of rem + // NOTE: This is because, when getDependence is called, it will first check + // the immediate predecessor of what is in the cache. + BasicBlock::iterator RI = rem; + RI++; + newDep = RI; + } + + std::multimap<Instruction*, Instruction*>::iterator I = reverseDep.find(rem); + while (I != reverseDep.end() && I->first == rem) { + // Insert the new dependencies + // Mark it as unconfirmed as long as it is not the non-local flag + depGraphLocal[I->second] = std::make_pair(newDep, !newDep); + reverseDep.erase(I); + I = reverseDep.find(rem); + } } - + getAnalysis<AliasAnalysis>().deleteValue(rem); } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits