return false;
}
+/// RemoveFromReverseMap - This is a helper function that removes Val from
+/// 'Inst's set in ReverseMap. If the set becomes empty, remove Inst's entry.
+template <typename KeyTy>
+static void RemoveFromReverseMap(DenseMap<Instruction*,
+ SmallPtrSet<KeyTy*, 4> > &ReverseMap,
+ Instruction *Inst, KeyTy *Val) {
+ typename DenseMap<Instruction*, SmallPtrSet<KeyTy*, 4> >::iterator
+ InstIt = ReverseMap.find(Inst);
+ assert(InstIt != ReverseMap.end() && "Reverse map out of sync?");
+ bool Found = InstIt->second.erase(Val);
+ assert(Found && "Invalid reverse map!"); Found=Found;
+ if (InstIt->second.empty())
+ ReverseMap.erase(InstIt);
+}
+
/// getCallSiteDependencyFrom - Private helper for finding the local
/// dependencies of a call site.
if (Instruction *Inst = LocalCache.getInst()) {
ScanPos = Inst;
- SmallPtrSet<Instruction*, 4> &InstMap = ReverseLocalDeps[Inst];
- bool Found = InstMap.erase(QueryInst);
- assert(Found && "Invalid reverse map!"); Found=Found;
- if (InstMap.empty())
- // FIXME: use an iterator to avoid looking up inst again.
- ReverseLocalDeps.erase(Inst);
+ RemoveFromReverseMap(ReverseLocalDeps, Inst, QueryInst);
}
BasicBlock *QueryParent = QueryInst->getParent();
if (ExistingResult) {
if (Instruction *Inst = ExistingResult->getInst()) {
ScanPos = Inst;
-
// We're removing QueryInst's use of Inst.
- SmallPtrSet<Instruction*, 4> &InstMap = ReverseNonLocalDeps[Inst];
- bool Found = InstMap.erase(QueryInst);
- assert(Found && "Invalid reverse map!"); Found=Found;
- // FIXME: Use an iterator to avoid looking up inst again.
- if (InstMap.empty()) ReverseNonLocalDeps.erase(Inst);
+ RemoveFromReverseMap(ReverseNonLocalDeps, Inst, QueryInst);
}
}
ScanPos = ExistingResult->getInst();
// Eliminating the dirty entry from 'Cache', so update the reverse info.
- SmallPtrSet<void *, 4> &InstMap = ReverseNonLocalPtrDeps[ScanPos];
- bool Contained = InstMap.erase(CacheKey.getOpaqueValue());
- assert(Contained && "Invalid cache entry"); Contained=Contained;
- // FIXME: Use an iterator to avoid a repeated lookup in ".erase".
- if (InstMap.empty()) ReverseNonLocalPtrDeps.erase(ScanPos);
+ RemoveFromReverseMap(ReverseNonLocalPtrDeps, ScanPos,
+ CacheKey.getOpaqueValue());
} else {
++NumUncacheNonLocalPtr;
}
assert(Target->getParent() == PInfo[i].first && Target != P.getPointer());
// Eliminating the dirty entry from 'Cache', so update the reverse info.
- SmallPtrSet<void *, 4> &InstMap = ReverseNonLocalPtrDeps[Target];
- bool Contained = InstMap.erase(P.getOpaqueValue());
- assert(Contained && "Invalid cache entry"); Contained=Contained;
-
- // FIXME: Use an iterator to avoid a repeated lookup in ".erase".
- if (InstMap.empty()) ReverseNonLocalPtrDeps.erase(Target);
+ RemoveFromReverseMap(ReverseNonLocalPtrDeps, Target, P.getOpaqueValue());
}
// Remove P from NonLocalPointerDeps (which deletes NonLocalDepInfo).
for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end();
DI != DE; ++DI)
if (Instruction *Inst = DI->second.getInst())
- ReverseNonLocalDeps[Inst].erase(RemInst);
+ RemoveFromReverseMap(ReverseNonLocalDeps, Inst, RemInst);
NonLocalDeps.erase(NLDI);
}
LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst);
if (LocalDepEntry != LocalDeps.end()) {
// Remove us from DepInst's reverse set now that the local dep info is gone.
- if (Instruction *Inst = LocalDepEntry->second.getInst()) {
- SmallPtrSet<Instruction*, 4> &RLD = ReverseLocalDeps[Inst];
- bool Found = RLD.erase(RemInst);
- assert(Found && "Invalid reverse map!"); Found=Found;
- // FIXME: Use an iterator to avoid looking up Inst again.
- if (RLD.empty())
- ReverseLocalDeps.erase(Inst);
- }
+ if (Instruction *Inst = LocalDepEntry->second.getInst())
+ RemoveFromReverseMap(ReverseLocalDeps, Inst, RemInst);
// Remove this local dependency info.
LocalDeps.erase(LocalDepEntry);
// Loop over all of the things that depend on the instruction we're removing.
//
SmallVector<std::pair<Instruction*, Instruction*>, 8> ReverseDepsToAdd;
+
+ // If we find RemInst as a clobber or Def in any of the maps for other values,
+ // we need to replace its entry with a dirty version of the instruction after
+ // it. If RemInst is a terminator, we use a null dirty value.
+ //
+ // Using a dirty version of the instruction after RemInst saves having to scan
+ // the entire block to get to this point.
+ MemDepResult NewDirtyVal;
+ if (!RemInst->isTerminator())
+ NewDirtyVal = MemDepResult::getDirty(++BasicBlock::iterator(RemInst));
ReverseDepMapType::iterator ReverseDepIt = ReverseLocalDeps.find(RemInst);
if (ReverseDepIt != ReverseLocalDeps.end()) {
assert(!ReverseDeps.empty() && !isa<TerminatorInst>(RemInst) &&
"Nothing can locally depend on a terminator");
- // Anything that was locally dependent on RemInst is now going to be
- // dependent on the instruction after RemInst. It will have the dirty flag
- // set so it will rescan. This saves having to scan the entire block to get
- // to this point.
- Instruction *NewDepInst = ++BasicBlock::iterator(RemInst);
-
for (SmallPtrSet<Instruction*, 4>::iterator I = ReverseDeps.begin(),
E = ReverseDeps.end(); I != E; ++I) {
Instruction *InstDependingOnRemInst = *I;
assert(InstDependingOnRemInst != RemInst &&
"Already removed our local dep info");
- LocalDeps[InstDependingOnRemInst] = MemDepResult::getDirty(NewDepInst);
+ LocalDeps[InstDependingOnRemInst] = NewDirtyVal;
// Make sure to remember that new things depend on NewDepInst.
- ReverseDepsToAdd.push_back(std::make_pair(NewDepInst,
+ assert(NewDirtyVal.getInst() && "There is no way something else can have "
+ "a local dep on this if it is a terminator!");
+ ReverseDepsToAdd.push_back(std::make_pair(NewDirtyVal.getInst(),
InstDependingOnRemInst));
}
if (DI->second.getInst() != RemInst) continue;
// Convert to a dirty entry for the subsequent instruction.
- Instruction *NextI = 0;
- if (!RemInst->isTerminator()) {
- NextI = ++BasicBlock::iterator(RemInst);
+ DI->second = NewDirtyVal;
+
+ if (Instruction *NextI = NewDirtyVal.getInst())
ReverseDepsToAdd.push_back(std::make_pair(NextI, *I));
- }
- DI->second = MemDepResult::getDirty(NextI);
}
}
NonLocalDepInfo &NLPDI = NonLocalPointerDeps[P];
- MemDepResult NewDirtyVal;
- if (!RemInst->isTerminator())
- NewDirtyVal = MemDepResult::getDirty(++BasicBlock::iterator(RemInst));
-
// Update any entries for RemInst to use the instruction after it.
for (NonLocalDepInfo::iterator DI = NLPDI.begin(), DE = NLPDI.end();
DI != DE; ++DI) {