From 70ac81f489912af29c2eee3335e4e8e72d0b54c5 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Thu, 16 Aug 2007 22:02:55 +0000 Subject: [PATCH] Add some more comments to GVN. llvm-svn: 41129 --- lib/Transforms/Scalar/GVN.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index d1a15c10816..0b0825544d7 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -756,6 +756,7 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig, PN->addIncoming(val, *PI); } + // Attempt to collapse PHI nodes that are trivially redundant Value* v = PN->hasConstantValue(); if (v) { if (Instruction* inst = dyn_cast(v)) { @@ -804,19 +805,24 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig, } } + // 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& toErase) { MemoryDependenceAnalysis& MD = getAnalysis(); + // Find the non-local dependencies of the load DenseMap deps; MD.getNonLocalDependency(L, deps); DenseMap repl; + // Filter out useless results (non-locals, etc) for (DenseMap::iterator I = deps.begin(), E = deps.end(); I != E; ++I) if (I->second == MemoryDependenceAnalysis::None) { @@ -837,6 +843,7 @@ bool GVN::processNonLocalLoad(LoadInst* L, return false; } + // Use cached PHI construction information from previous runs SmallPtrSet& p = phiMap[L->getPointerOperand()]; for (SmallPtrSet::iterator I = p.begin(), E = p.end(); I != E; ++I) { @@ -852,6 +859,7 @@ bool GVN::processNonLocalLoad(LoadInst* L, } } + // Perform PHI construction SmallPtrSet visited; Value* v = GetValueForBlock(L->getParent(), L, repl, true); @@ -863,6 +871,8 @@ bool GVN::processNonLocalLoad(LoadInst* L, 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& lastLoad, SmallVector& toErase) { @@ -891,6 +901,8 @@ bool GVN::processLoad(LoadInst* L, 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(dep) || isa(dep))) { @@ -946,6 +958,7 @@ bool GVN::processInstruction(Instruction* I, unsigned num = VN.lookup_or_add(I); + // Collapse PHI nodes if (PHINode* p = dyn_cast(I)) { Value* constVal = p->hasConstantValue(); @@ -966,6 +979,7 @@ bool GVN::processInstruction(Instruction* I, toErase.push_back(p); } } + // Perform value-number based elimination } else if (currAvail.test(num)) { Value* repl = find_leader(currAvail, num);