mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-10 04:33:40 +00:00
Clean up a bunch of caching stuff in memdep. This reduces the time to run GVN
on 403.gcc from ~15s to ~10s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40884 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fee76bd9ba
commit
dbbe816757
@ -38,11 +38,12 @@ class MemoryDependenceAnalysis : public FunctionPass {
|
|||||||
|
|
||||||
depMapType depGraphLocal;
|
depMapType depGraphLocal;
|
||||||
|
|
||||||
typedef std::multimap<Instruction*, Instruction*> reverseDepMapType;
|
typedef DenseMap<Instruction*,
|
||||||
|
SmallPtrSet<Instruction*, 4> > reverseDepMapType;
|
||||||
reverseDepMapType reverseDep;
|
reverseDepMapType reverseDep;
|
||||||
|
|
||||||
Instruction* getCallSiteDependency(CallSite C, Instruction* start,
|
Instruction* getCallSiteDependency(CallSite C, Instruction* start,
|
||||||
bool local = true);
|
BasicBlock* block);
|
||||||
void nonLocalHelper(Instruction* query, BasicBlock* block,
|
void nonLocalHelper(Instruction* query, BasicBlock* block,
|
||||||
DenseMap<BasicBlock*, Value*>& resp);
|
DenseMap<BasicBlock*, Value*>& resp);
|
||||||
public:
|
public:
|
||||||
|
@ -26,8 +26,8 @@ using namespace llvm;
|
|||||||
|
|
||||||
char MemoryDependenceAnalysis::ID = 0;
|
char MemoryDependenceAnalysis::ID = 0;
|
||||||
|
|
||||||
Instruction* MemoryDependenceAnalysis::NonLocal = (Instruction*)-2;
|
Instruction* MemoryDependenceAnalysis::NonLocal = (Instruction*)-3;
|
||||||
Instruction* MemoryDependenceAnalysis::None = (Instruction*)-3;
|
Instruction* MemoryDependenceAnalysis::None = (Instruction*)-4;
|
||||||
|
|
||||||
// Register this pass...
|
// Register this pass...
|
||||||
static RegisterPass<MemoryDependenceAnalysis> X("memdep",
|
static RegisterPass<MemoryDependenceAnalysis> X("memdep",
|
||||||
@ -43,14 +43,21 @@ void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||||||
|
|
||||||
// Find the dependency of a CallSite
|
// Find the dependency of a CallSite
|
||||||
Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C, Instruction* start,
|
Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C, Instruction* start,
|
||||||
bool local) {
|
BasicBlock* block) {
|
||||||
assert(local && "Non-local memory dependence analysis not yet implemented");
|
|
||||||
|
|
||||||
AliasAnalysis& AA = getAnalysis<AliasAnalysis>();
|
AliasAnalysis& AA = getAnalysis<AliasAnalysis>();
|
||||||
TargetData& TD = getAnalysis<TargetData>();
|
TargetData& TD = getAnalysis<TargetData>();
|
||||||
BasicBlock::iterator blockBegin = C.getInstruction()->getParent()->begin();
|
BasicBlock::iterator blockBegin = C.getInstruction()->getParent()->begin();
|
||||||
BasicBlock::iterator QI = C.getInstruction();
|
BasicBlock::iterator QI = C.getInstruction();
|
||||||
|
|
||||||
|
if (start) {
|
||||||
|
QI = start;
|
||||||
|
blockBegin = start->getParent()->end();
|
||||||
|
} else if (!start && block) {
|
||||||
|
QI = block->end();
|
||||||
|
blockBegin = block->end();
|
||||||
|
}
|
||||||
|
|
||||||
while (QI != blockBegin) {
|
while (QI != blockBegin) {
|
||||||
--QI;
|
--QI;
|
||||||
|
|
||||||
@ -79,8 +86,11 @@ Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C, Instruc
|
|||||||
pointerSize = ~0UL;
|
pointerSize = ~0UL;
|
||||||
} else if (CallSite::get(QI).getInstruction() != 0) {
|
} else if (CallSite::get(QI).getInstruction() != 0) {
|
||||||
if (AA.getModRefInfo(C, CallSite::get(QI)) != AliasAnalysis::NoModRef) {
|
if (AA.getModRefInfo(C, CallSite::get(QI)) != AliasAnalysis::NoModRef) {
|
||||||
depGraphLocal.insert(std::make_pair(C.getInstruction(), std::make_pair(QI, true)));
|
if (!start && !block) {
|
||||||
reverseDep.insert(std::make_pair(QI, C.getInstruction()));
|
depGraphLocal.insert(std::make_pair(C.getInstruction(),
|
||||||
|
std::make_pair(QI, true)));
|
||||||
|
reverseDep[QI].insert(C.getInstruction());
|
||||||
|
}
|
||||||
return QI;
|
return QI;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
@ -89,15 +99,18 @@ Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C, Instruc
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (AA.getModRefInfo(C, pointer, pointerSize) != AliasAnalysis::NoModRef) {
|
if (AA.getModRefInfo(C, pointer, pointerSize) != AliasAnalysis::NoModRef) {
|
||||||
depGraphLocal.insert(std::make_pair(C.getInstruction(), std::make_pair(QI, true)));
|
if (!start && !block) {
|
||||||
reverseDep.insert(std::make_pair(QI, C.getInstruction()));
|
depGraphLocal.insert(std::make_pair(C.getInstruction(),
|
||||||
|
std::make_pair(QI, true)));
|
||||||
|
reverseDep[QI].insert(C.getInstruction());
|
||||||
|
}
|
||||||
return QI;
|
return QI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No dependence found
|
// No dependence found
|
||||||
depGraphLocal.insert(std::make_pair(C.getInstruction(), std::make_pair(NonLocal, true)));
|
depGraphLocal.insert(std::make_pair(C.getInstruction(), std::make_pair(NonLocal, true)));
|
||||||
reverseDep.insert(std::make_pair(NonLocal, C.getInstruction()));
|
reverseDep[NonLocal].insert(C.getInstruction());
|
||||||
return NonLocal;
|
return NonLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +231,7 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
// FreeInsts erase the entire structure, not just a field
|
// FreeInsts erase the entire structure, not just a field
|
||||||
dependeeSize = ~0UL;
|
dependeeSize = ~0UL;
|
||||||
} else if (CallSite::get(query).getInstruction() != 0)
|
} else if (CallSite::get(query).getInstruction() != 0)
|
||||||
return getCallSiteDependency(CallSite::get(query), start);
|
return getCallSiteDependency(CallSite::get(query), start, block);
|
||||||
else if (isa<AllocationInst>(query))
|
else if (isa<AllocationInst>(query))
|
||||||
return None;
|
return None;
|
||||||
else
|
else
|
||||||
@ -236,9 +249,9 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
if (StoreInst* S = dyn_cast<StoreInst>(QI)) {
|
if (StoreInst* S = dyn_cast<StoreInst>(QI)) {
|
||||||
// All volatile loads/stores depend on each other
|
// All volatile loads/stores depend on each other
|
||||||
if (queryIsVolatile && S->isVolatile()) {
|
if (queryIsVolatile && S->isVolatile()) {
|
||||||
if (!start || block) {
|
if (!start && !block) {
|
||||||
depGraphLocal.insert(std::make_pair(query, std::make_pair(S, true)));
|
depGraphLocal.insert(std::make_pair(query, std::make_pair(S, true)));
|
||||||
reverseDep.insert(std::make_pair(S, query));
|
reverseDep[S].insert(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return S;
|
return S;
|
||||||
@ -249,9 +262,9 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
} else if (LoadInst* L = dyn_cast<LoadInst>(QI)) {
|
} else if (LoadInst* L = dyn_cast<LoadInst>(QI)) {
|
||||||
// All volatile loads/stores depend on each other
|
// All volatile loads/stores depend on each other
|
||||||
if (queryIsVolatile && L->isVolatile()) {
|
if (queryIsVolatile && L->isVolatile()) {
|
||||||
if (!start || block) {
|
if (!start && !block) {
|
||||||
depGraphLocal.insert(std::make_pair(query, std::make_pair(L, true)));
|
depGraphLocal.insert(std::make_pair(query, std::make_pair(L, true)));
|
||||||
reverseDep.insert(std::make_pair(L, query));
|
reverseDep[L].insert(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return L;
|
return L;
|
||||||
@ -283,9 +296,9 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
if (isa<LoadInst>(query) && MR == AliasAnalysis::Ref)
|
if (isa<LoadInst>(query) && MR == AliasAnalysis::Ref)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!start || block) {
|
if (!start && !block) {
|
||||||
depGraphLocal.insert(std::make_pair(query, std::make_pair(QI, true)));
|
depGraphLocal.insert(std::make_pair(query, std::make_pair(QI, true)));
|
||||||
reverseDep.insert(std::make_pair(QI, query));
|
reverseDep[QI].insert(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QI;
|
return QI;
|
||||||
@ -305,9 +318,9 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
R == AliasAnalysis::MayAlias)
|
R == AliasAnalysis::MayAlias)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!start || block) {
|
if (!start && !block) {
|
||||||
depGraphLocal.insert(std::make_pair(query, std::make_pair(QI, true)));
|
depGraphLocal.insert(std::make_pair(query, std::make_pair(QI, true)));
|
||||||
reverseDep.insert(std::make_pair(QI, query));
|
reverseDep[QI].insert(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QI;
|
return QI;
|
||||||
@ -316,10 +329,10 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we found nothing, return the non-local flag
|
// If we found nothing, return the non-local flag
|
||||||
if (!start || block) {
|
if (!start && !block) {
|
||||||
depGraphLocal.insert(std::make_pair(query,
|
depGraphLocal.insert(std::make_pair(query,
|
||||||
std::make_pair(NonLocal, true)));
|
std::make_pair(NonLocal, true)));
|
||||||
reverseDep.insert(std::make_pair(NonLocal, query));
|
reverseDep[NonLocal].insert(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NonLocal;
|
return NonLocal;
|
||||||
@ -355,14 +368,14 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction* rem) {
|
|||||||
newDep = RI;
|
newDep = RI;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::multimap<Instruction*, Instruction*>::iterator I = reverseDep.find(rem);
|
SmallPtrSet<Instruction*, 4>& set = reverseDep[rem];
|
||||||
while (I != reverseDep.end() && I->first == rem) {
|
for (SmallPtrSet<Instruction*, 4>::iterator I = set.begin(), E = set.end();
|
||||||
|
I != E; ++I) {
|
||||||
// Insert the new dependencies
|
// Insert the new dependencies
|
||||||
// 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->second] = std::make_pair(newDep, !newDep);
|
depGraphLocal[*I] = std::make_pair(newDep, !newDep);
|
||||||
reverseDep.erase(I);
|
|
||||||
I = reverseDep.find(rem);
|
|
||||||
}
|
}
|
||||||
|
reverseDep.erase(rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
getAnalysis<AliasAnalysis>().deleteValue(rem);
|
getAnalysis<AliasAnalysis>().deleteValue(rem);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user