[llvm-commits] [llvm] r41129 - /llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Owen Anderson
resistor at mac.com
Thu Aug 16 15:02:55 PDT 2007
Author: resistor
Date: Thu Aug 16 17:02:55 2007
New Revision: 41129
URL: http://llvm.org/viewvc/llvm-project?rev=41129&view=rev
Log:
Add some more comments to GVN.
Modified:
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=41129&r1=41128&r2=41129&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Thu Aug 16 17:02:55 2007
@@ -756,6 +756,7 @@
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)) {
@@ -804,19 +805,24 @@
}
}
+ // 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) {
@@ -837,6 +843,7 @@
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) {
@@ -852,6 +859,7 @@
}
}
+ // Perform PHI construction
SmallPtrSet<BasicBlock*, 4> visited;
Value* v = GetValueForBlock(L->getParent(), L, repl, true);
@@ -863,6 +871,8 @@
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) {
@@ -891,6 +901,8 @@
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))) {
@@ -946,6 +958,7 @@
unsigned num = VN.lookup_or_add(I);
+ // Collapse PHI nodes
if (PHINode* p = dyn_cast<PHINode>(I)) {
Value* constVal = p->hasConstantValue();
@@ -966,6 +979,7 @@
toErase.push_back(p);
}
}
+ // Perform value-number based elimination
} else if (currAvail.test(num)) {
Value* repl = find_leader(currAvail, num);
More information about the llvm-commits
mailing list