mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
Cache non-local memory dependence analysis. This is a significant compile
time performance win in most cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41126 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fe8e14a6c9
commit
4d13de4e3b
@ -37,12 +37,20 @@ class MemoryDependenceAnalysis : public FunctionPass {
|
|||||||
depMapType;
|
depMapType;
|
||||||
depMapType depGraphLocal;
|
depMapType depGraphLocal;
|
||||||
|
|
||||||
|
// A map from instructions to their non-local dependencies.
|
||||||
|
typedef DenseMap<Instruction*, DenseMap<BasicBlock*, Value*> >
|
||||||
|
nonLocalDepMapType;
|
||||||
|
nonLocalDepMapType depGraphNonLocal;
|
||||||
|
|
||||||
// A reverse mapping form dependencies to the dependees. This is
|
// A reverse mapping form dependencies to the dependees. This is
|
||||||
// used when removing instructions to keep the cache coherent.
|
// used when removing instructions to keep the cache coherent.
|
||||||
typedef DenseMap<Instruction*, SmallPtrSet<Instruction*, 4> >
|
typedef DenseMap<Value*, SmallPtrSet<Instruction*, 4> >
|
||||||
reverseDepMapType;
|
reverseDepMapType;
|
||||||
reverseDepMapType reverseDep;
|
reverseDepMapType reverseDep;
|
||||||
|
|
||||||
|
// A reverse mapping form dependencies to the non-local dependees.
|
||||||
|
reverseDepMapType reverseDepNonLocal;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Special marker indicating that the query has no dependency
|
// Special marker indicating that the query has no dependency
|
||||||
// in the specified block.
|
// in the specified block.
|
||||||
@ -61,7 +69,9 @@ class MemoryDependenceAnalysis : public FunctionPass {
|
|||||||
/// Clean up memory in between runs
|
/// Clean up memory in between runs
|
||||||
void releaseMemory() {
|
void releaseMemory() {
|
||||||
depGraphLocal.clear();
|
depGraphLocal.clear();
|
||||||
|
depGraphNonLocal.clear();
|
||||||
reverseDep.clear();
|
reverseDep.clear();
|
||||||
|
reverseDepNonLocal.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getAnalysisUsage - Does not modify anything. It uses Value Numbering
|
/// getAnalysisUsage - Does not modify anything. It uses Value Numbering
|
||||||
|
@ -203,6 +203,11 @@ void MemoryDependenceAnalysis::nonLocalHelper(Instruction* query,
|
|||||||
/// blocks between the query and its dependencies.
|
/// blocks between the query and its dependencies.
|
||||||
void MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query,
|
void MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query,
|
||||||
DenseMap<BasicBlock*, Value*>& resp) {
|
DenseMap<BasicBlock*, Value*>& resp) {
|
||||||
|
if (depGraphNonLocal.count(query)) {
|
||||||
|
resp = depGraphNonLocal[query];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// First check that we don't actually have a local dependency.
|
// First check that we don't actually have a local dependency.
|
||||||
Instruction* localDep = getDependency(query);
|
Instruction* localDep = getDependency(query);
|
||||||
if (localDep != NonLocal) {
|
if (localDep != NonLocal) {
|
||||||
@ -212,6 +217,13 @@ void MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query,
|
|||||||
|
|
||||||
// If not, go ahead and search for non-local ones.
|
// If not, go ahead and search for non-local ones.
|
||||||
nonLocalHelper(query, query->getParent(), resp);
|
nonLocalHelper(query, query->getParent(), resp);
|
||||||
|
|
||||||
|
// Update the non-local dependency cache
|
||||||
|
for (DenseMap<BasicBlock*, Value*>::iterator I = resp.begin(), E = resp.end();
|
||||||
|
I != E; ++I) {
|
||||||
|
depGraphNonLocal[query].insert(*I);
|
||||||
|
reverseDepNonLocal[I->second].insert(query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getDependency - Return the instruction on which a memory operation
|
/// getDependency - Return the instruction on which a memory operation
|
||||||
@ -380,8 +392,6 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction* rem) {
|
|||||||
Instruction* newDep = NonLocal;
|
Instruction* newDep = NonLocal;
|
||||||
|
|
||||||
depMapType::iterator depGraphEntry = depGraphLocal.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 != depGraphLocal.end()) {
|
||||||
if (depGraphEntry->second.first != NonLocal &&
|
if (depGraphEntry->second.first != NonLocal &&
|
||||||
@ -410,8 +420,18 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction* rem) {
|
|||||||
// Mark it as unconfirmed as long as it is not the non-local flag
|
// Mark it as unconfirmed as long as it is not the non-local flag
|
||||||
depGraphLocal[*I] = std::make_pair(newDep, !newDep);
|
depGraphLocal[*I] = std::make_pair(newDep, !newDep);
|
||||||
}
|
}
|
||||||
|
|
||||||
reverseDep.erase(rem);
|
reverseDep.erase(rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (depGraphNonLocal.count(rem)) {
|
||||||
|
SmallPtrSet<Instruction*, 4>& set = reverseDepNonLocal[rem];
|
||||||
|
for (SmallPtrSet<Instruction*, 4>::iterator I = set.begin(), E = set.end();
|
||||||
|
I != E; ++I)
|
||||||
|
depGraphNonLocal.erase(*I);
|
||||||
|
|
||||||
|
reverseDepNonLocal.erase(rem);
|
||||||
|
}
|
||||||
|
|
||||||
getAnalysis<AliasAnalysis>().deleteValue(rem);
|
getAnalysis<AliasAnalysis>().deleteValue(rem);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user