mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-29 13:32:33 +00:00
factor some code, fixing some fixme's.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60672 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e91a4881e1
commit
d44745d241
@ -57,6 +57,21 @@ bool MemoryDependenceAnalysis::runOnFunction(Function &) {
|
|||||||
return false;
|
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
|
/// getCallSiteDependencyFrom - Private helper for finding the local
|
||||||
/// dependencies of a call site.
|
/// dependencies of a call site.
|
||||||
@ -207,12 +222,7 @@ MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) {
|
|||||||
if (Instruction *Inst = LocalCache.getInst()) {
|
if (Instruction *Inst = LocalCache.getInst()) {
|
||||||
ScanPos = Inst;
|
ScanPos = Inst;
|
||||||
|
|
||||||
SmallPtrSet<Instruction*, 4> &InstMap = ReverseLocalDeps[Inst];
|
RemoveFromReverseMap(ReverseLocalDeps, Inst, QueryInst);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicBlock *QueryParent = QueryInst->getParent();
|
BasicBlock *QueryParent = QueryInst->getParent();
|
||||||
@ -363,13 +373,8 @@ MemoryDependenceAnalysis::getNonLocalDependency(Instruction *QueryInst) {
|
|||||||
if (ExistingResult) {
|
if (ExistingResult) {
|
||||||
if (Instruction *Inst = ExistingResult->getInst()) {
|
if (Instruction *Inst = ExistingResult->getInst()) {
|
||||||
ScanPos = Inst;
|
ScanPos = Inst;
|
||||||
|
|
||||||
// We're removing QueryInst's use of Inst.
|
// We're removing QueryInst's use of Inst.
|
||||||
SmallPtrSet<Instruction*, 4> &InstMap = ReverseNonLocalDeps[Inst];
|
RemoveFromReverseMap(ReverseNonLocalDeps, Inst, QueryInst);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,11 +532,8 @@ getNonLocalPointerDepInternal(Value *Pointer, uint64_t PointeeSize,
|
|||||||
ScanPos = ExistingResult->getInst();
|
ScanPos = ExistingResult->getInst();
|
||||||
|
|
||||||
// Eliminating the dirty entry from 'Cache', so update the reverse info.
|
// Eliminating the dirty entry from 'Cache', so update the reverse info.
|
||||||
SmallPtrSet<void *, 4> &InstMap = ReverseNonLocalPtrDeps[ScanPos];
|
RemoveFromReverseMap(ReverseNonLocalPtrDeps, ScanPos,
|
||||||
bool Contained = InstMap.erase(CacheKey.getOpaqueValue());
|
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);
|
|
||||||
} else {
|
} else {
|
||||||
++NumUncacheNonLocalPtr;
|
++NumUncacheNonLocalPtr;
|
||||||
}
|
}
|
||||||
@ -595,12 +597,7 @@ RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair P) {
|
|||||||
assert(Target->getParent() == PInfo[i].first && Target != P.getPointer());
|
assert(Target->getParent() == PInfo[i].first && Target != P.getPointer());
|
||||||
|
|
||||||
// Eliminating the dirty entry from 'Cache', so update the reverse info.
|
// Eliminating the dirty entry from 'Cache', so update the reverse info.
|
||||||
SmallPtrSet<void *, 4> &InstMap = ReverseNonLocalPtrDeps[Target];
|
RemoveFromReverseMap(ReverseNonLocalPtrDeps, Target, P.getOpaqueValue());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove P from NonLocalPointerDeps (which deletes NonLocalDepInfo).
|
// Remove P from NonLocalPointerDeps (which deletes NonLocalDepInfo).
|
||||||
@ -620,7 +617,7 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction *RemInst) {
|
|||||||
for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end();
|
for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end();
|
||||||
DI != DE; ++DI)
|
DI != DE; ++DI)
|
||||||
if (Instruction *Inst = DI->second.getInst())
|
if (Instruction *Inst = DI->second.getInst())
|
||||||
ReverseNonLocalDeps[Inst].erase(RemInst);
|
RemoveFromReverseMap(ReverseNonLocalDeps, Inst, RemInst);
|
||||||
NonLocalDeps.erase(NLDI);
|
NonLocalDeps.erase(NLDI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,14 +626,8 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction *RemInst) {
|
|||||||
LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst);
|
LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst);
|
||||||
if (LocalDepEntry != LocalDeps.end()) {
|
if (LocalDepEntry != LocalDeps.end()) {
|
||||||
// Remove us from DepInst's reverse set now that the local dep info is gone.
|
// Remove us from DepInst's reverse set now that the local dep info is gone.
|
||||||
if (Instruction *Inst = LocalDepEntry->second.getInst()) {
|
if (Instruction *Inst = LocalDepEntry->second.getInst())
|
||||||
SmallPtrSet<Instruction*, 4> &RLD = ReverseLocalDeps[Inst];
|
RemoveFromReverseMap(ReverseLocalDeps, Inst, RemInst);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove this local dependency info.
|
// Remove this local dependency info.
|
||||||
LocalDeps.erase(LocalDepEntry);
|
LocalDeps.erase(LocalDepEntry);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user