summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2007-07-31 20:01:27 +0000
committerDavid Greene <greened@obbligato.org>2007-07-31 20:01:27 +0000
commitdf464195fe049d5ea921e2e37f4f833c2ea4e3ec (patch)
treefaa1871198effb724f6ab5c37c29510c627e6323
parent054ab94bff7827b8004465b75dfe0d539568621a (diff)
downloadllvm-df464195fe049d5ea921e2e37f4f833c2ea4e3ec.tar.gz
llvm-df464195fe049d5ea921e2e37f4f833c2ea4e3ec.tar.bz2
llvm-df464195fe049d5ea921e2e37f4f833c2ea4e3ec.tar.xz
Fix GLIBCXX_DEBUG error owing to dereference of end iterator. There's
no guarantee that an instruction returned by getDependency exists in the maps. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40647 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Analysis/MemoryDependenceAnalysis.h11
-rw-r--r--lib/Analysis/MemoryDependenceAnalysis.cpp59
2 files changed, 41 insertions, 29 deletions
diff --git a/include/llvm/Analysis/MemoryDependenceAnalysis.h b/include/llvm/Analysis/MemoryDependenceAnalysis.h
index 8679cd9dd8..7546eda862 100644
--- a/include/llvm/Analysis/MemoryDependenceAnalysis.h
+++ b/include/llvm/Analysis/MemoryDependenceAnalysis.h
@@ -32,9 +32,14 @@ class Instruction;
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);
diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp
index 02b0af6f0f..5a8cb7bfaa 100644
--- a/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -308,33 +308,40 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
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);
}