[llvm-commits] [llvm] r60304 - in /llvm/trunk: include/llvm/Analysis/MemoryDependenceAnalysis.h lib/Analysis/MemoryDependenceAnalysis.cpp
Chris Lattner
sabre at nondot.org
Sun Nov 30 11:24:31 PST 2008
Author: lattner
Date: Sun Nov 30 13:24:31 2008
New Revision: 60304
URL: http://llvm.org/viewvc/llvm-project?rev=60304&view=rev
Log:
Cache TargetData/AliasAnalysis in the pass instead of calling
getAnalysis<>. getAnalysis<> is apparently extremely expensive.
Doing this speeds up GVN on 403.gcc by 16%!
Modified:
llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h?rev=60304&r1=60303&r2=60304&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Sun Nov 30 13:24:31 2008
@@ -25,6 +25,8 @@
class FunctionPass;
class Instruction;
class CallSite;
+ class AliasAnalysis;
+ class TargetData;
/// MemDepResult - A memory dependence query can return one of three different
/// answers:
@@ -148,13 +150,15 @@
// A reverse mapping form dependencies to the non-local dependees.
ReverseDepMapType ReverseNonLocalDeps;
+ /// Current AA implementation, just a cache.
+ AliasAnalysis *AA;
+ TargetData *TD;
public:
MemoryDependenceAnalysis() : FunctionPass(&ID) {}
static char ID;
- /// Pass Implementation stuff. This doesn't do any analysis.
- ///
- bool runOnFunction(Function &) {return false; }
+ /// Pass Implementation stuff. This doesn't do any analysis eagerly.
+ bool runOnFunction(Function &);
/// Clean up memory in between runs
void releaseMemory() {
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=60304&r1=60303&r2=60304&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Sun Nov 30 13:24:31 2008
@@ -45,14 +45,17 @@
AU.addRequiredTransitive<TargetData>();
}
+bool MemoryDependenceAnalysis::runOnFunction(Function &) {
+ AA = &getAnalysis<AliasAnalysis>();
+ TD = &getAnalysis<TargetData>();
+ return false;
+}
+
/// getCallSiteDependency - Private helper for finding the local dependencies
/// of a call site.
MemoryDependenceAnalysis::DepResultTy MemoryDependenceAnalysis::
getCallSiteDependency(CallSite C, BasicBlock::iterator ScanIt,
BasicBlock *BB) {
- AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
- TargetData &TD = getAnalysis<TargetData>();
-
// Walk backwards through the block, looking for dependencies
while (ScanIt != BB->begin()) {
Instruction *Inst = --ScanIt;
@@ -62,17 +65,17 @@
uint64_t PointerSize = 0;
if (StoreInst *S = dyn_cast<StoreInst>(Inst)) {
Pointer = S->getPointerOperand();
- PointerSize = TD.getTypeStoreSize(S->getOperand(0)->getType());
+ PointerSize = TD->getTypeStoreSize(S->getOperand(0)->getType());
} else if (VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
Pointer = V->getOperand(0);
- PointerSize = TD.getTypeStoreSize(V->getType());
+ PointerSize = TD->getTypeStoreSize(V->getType());
} else if (FreeInst *F = dyn_cast<FreeInst>(Inst)) {
Pointer = F->getPointerOperand();
// FreeInsts erase the entire structure
PointerSize = ~0UL;
} else if (isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) {
- if (AA.getModRefBehavior(CallSite::get(Inst)) ==
+ if (AA->getModRefBehavior(CallSite::get(Inst)) ==
AliasAnalysis::DoesNotAccessMemory)
continue;
return DepResultTy(Inst, Normal);
@@ -81,7 +84,7 @@
continue;
}
- if (AA.getModRefInfo(C, Pointer, PointerSize) != AliasAnalysis::NoModRef)
+ if (AA->getModRefInfo(C, Pointer, PointerSize) != AliasAnalysis::NoModRef)
return DepResultTy(Inst, Normal);
}
@@ -95,9 +98,6 @@
MemoryDependenceAnalysis::DepResultTy MemoryDependenceAnalysis::
getDependencyFromInternal(Instruction *QueryInst, BasicBlock::iterator ScanIt,
BasicBlock *BB) {
- AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
- TargetData &TD = getAnalysis<TargetData>();
-
// Get the pointer value for which dependence will be determined
Value *MemPtr = 0;
uint64_t MemSize = 0;
@@ -105,15 +105,15 @@
if (StoreInst* S = dyn_cast<StoreInst>(QueryInst)) {
MemPtr = S->getPointerOperand();
- MemSize = TD.getTypeStoreSize(S->getOperand(0)->getType());
+ MemSize = TD->getTypeStoreSize(S->getOperand(0)->getType());
MemVolatile = S->isVolatile();
} else if (LoadInst* L = dyn_cast<LoadInst>(QueryInst)) {
MemPtr = L->getPointerOperand();
- MemSize = TD.getTypeStoreSize(L->getType());
+ MemSize = TD->getTypeStoreSize(L->getType());
MemVolatile = L->isVolatile();
} else if (VAArgInst* V = dyn_cast<VAArgInst>(QueryInst)) {
MemPtr = V->getOperand(0);
- MemSize = TD.getTypeStoreSize(V->getType());
+ MemSize = TD->getTypeStoreSize(V->getType());
} else if (FreeInst* F = dyn_cast<FreeInst>(QueryInst)) {
MemPtr = F->getPointerOperand();
// FreeInsts erase the entire structure, not just a field.
@@ -138,11 +138,11 @@
// a load depends on another must aliased load from the same value.
if (LoadInst *L = dyn_cast<LoadInst>(Inst)) {
Value *Pointer = L->getPointerOperand();
- uint64_t PointerSize = TD.getTypeStoreSize(L->getType());
+ uint64_t PointerSize = TD->getTypeStoreSize(L->getType());
// If we found a pointer, check if it could be the same as our pointer
AliasAnalysis::AliasResult R =
- AA.alias(Pointer, PointerSize, MemPtr, MemSize);
+ AA->alias(Pointer, PointerSize, MemPtr, MemSize);
if (R == AliasAnalysis::NoAlias)
continue;
@@ -161,13 +161,13 @@
Value *AccessPtr = MemPtr->getUnderlyingObject();
if (AccessPtr == AI ||
- AA.alias(AI, 1, AccessPtr, 1) == AliasAnalysis::MustAlias)
+ AA->alias(AI, 1, AccessPtr, 1) == AliasAnalysis::MustAlias)
return DepResultTy(0, None);
continue;
}
// See if this instruction mod/ref's the pointer.
- AliasAnalysis::ModRefResult MRR = AA.getModRefInfo(Inst, MemPtr, MemSize);
+ AliasAnalysis::ModRefResult MRR = AA->getModRefInfo(Inst, MemPtr, MemSize);
if (MRR == AliasAnalysis::NoModRef)
continue;
@@ -426,7 +426,7 @@
}
assert(!NonLocalDeps.count(RemInst) && "RemInst got reinserted?");
- getAnalysis<AliasAnalysis>().deleteValue(RemInst);
+ AA->deleteValue(RemInst);
DEBUG(verifyRemoved(RemInst));
}
More information about the llvm-commits
mailing list