PN->addIncoming(val, *PI);
}
+ // Attempt to collapse PHI nodes that are trivially redundant
Value* v = PN->hasConstantValue();
if (v) {
if (Instruction* inst = dyn_cast<Instruction>(v)) {
}
}
+ // Cache our phi construction results
phiMap[orig->getPointerOperand()].insert(PN);
return PN;
}
+/// processNonLocalLoad - Attempt to eliminate a load whose dependencies are
+/// non-local by performing PHI construction.
bool GVN::processNonLocalLoad(LoadInst* L,
SmallVector<Instruction*, 4>& toErase) {
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
+ // Find the non-local dependencies of the load
DenseMap<BasicBlock*, Value*> deps;
MD.getNonLocalDependency(L, deps);
DenseMap<BasicBlock*, Value*> repl;
+ // Filter out useless results (non-locals, etc)
for (DenseMap<BasicBlock*, Value*>::iterator I = deps.begin(), E = deps.end();
I != E; ++I)
if (I->second == MemoryDependenceAnalysis::None) {
return false;
}
+ // Use cached PHI construction information from previous runs
SmallPtrSet<Instruction*, 4>& p = phiMap[L->getPointerOperand()];
for (SmallPtrSet<Instruction*, 4>::iterator I = p.begin(), E = p.end();
I != E; ++I) {
}
}
+ // Perform PHI construction
SmallPtrSet<BasicBlock*, 4> visited;
Value* v = GetValueForBlock(L->getParent(), L, repl, true);
return true;
}
+/// processLoad - Attempt to eliminate a load, first by eliminating it
+/// locally, and then attempting non-local elimination if that fails.
bool GVN::processLoad(LoadInst* L,
DenseMap<Value*, LoadInst*>& lastLoad,
SmallVector<Instruction*, 4>& toErase) {
bool deletedLoad = false;
+ // Walk up the dependency chain until we either find
+ // a dependency we can use, or we can't walk any further
while (dep != MemoryDependenceAnalysis::None &&
dep != MemoryDependenceAnalysis::NonLocal &&
(isa<LoadInst>(dep) || isa<StoreInst>(dep))) {
unsigned num = VN.lookup_or_add(I);
+ // Collapse PHI nodes
if (PHINode* p = dyn_cast<PHINode>(I)) {
Value* constVal = p->hasConstantValue();
toErase.push_back(p);
}
}
+ // Perform value-number based elimination
} else if (currAvail.test(num)) {
Value* repl = find_leader(currAvail, num);