diff --git a/include/llvm/Analysis/MemoryDependenceAnalysis.h b/include/llvm/Analysis/MemoryDependenceAnalysis.h index f46a2862bff..da82d7aa286 100644 --- a/include/llvm/Analysis/MemoryDependenceAnalysis.h +++ b/include/llvm/Analysis/MemoryDependenceAnalysis.h @@ -18,6 +18,7 @@ #include "llvm/Pass.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/PointerIntPair.h" namespace llvm { @@ -28,6 +29,7 @@ namespace llvm { class AliasAnalysis; class TargetData; class MemoryDependenceAnalysis; + class PredIteratorCache; /// MemDepResult - A memory dependence query can return one of three different /// answers, described below. @@ -193,23 +195,18 @@ namespace llvm { /// Current AA implementation, just a cache. AliasAnalysis *AA; TargetData *TD; + OwningPtr PredCache; public: - MemoryDependenceAnalysis() : FunctionPass(&ID) {} + MemoryDependenceAnalysis(); + ~MemoryDependenceAnalysis(); static char ID; /// Pass Implementation stuff. This doesn't do any analysis eagerly. bool runOnFunction(Function &); /// Clean up memory in between runs - void releaseMemory() { - LocalDeps.clear(); - NonLocalDeps.clear(); - NonLocalPointerDeps.clear(); - ReverseLocalDeps.clear(); - ReverseNonLocalDeps.clear(); - ReverseNonLocalPtrDeps.clear(); - } - + void releaseMemory(); + /// getAnalysisUsage - Does not modify anything. It uses Value Numbering /// and Alias Analysis. /// diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index c42633bac1d..94395027f21 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -21,7 +21,7 @@ #include "llvm/Function.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/ADT/Statistic.h" -#include "llvm/Support/CFG.h" +#include "llvm/Support/PredIteratorCache.h" #include "llvm/Support/Debug.h" #include "llvm/Target/TargetData.h" using namespace llvm; @@ -45,6 +45,25 @@ char MemoryDependenceAnalysis::ID = 0; static RegisterPass X("memdep", "Memory Dependence Analysis", false, true); +MemoryDependenceAnalysis::MemoryDependenceAnalysis() +: FunctionPass(&ID), PredCache(0) { +} +MemoryDependenceAnalysis::~MemoryDependenceAnalysis() { +} + +/// Clean up memory in between runs +void MemoryDependenceAnalysis::releaseMemory() { + LocalDeps.clear(); + NonLocalDeps.clear(); + NonLocalPointerDeps.clear(); + ReverseLocalDeps.clear(); + ReverseNonLocalDeps.clear(); + ReverseNonLocalPtrDeps.clear(); + PredCache->clear(); +} + + + /// getAnalysisUsage - Does not modify anything. It uses Alias Analysis. /// void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { @@ -56,6 +75,8 @@ void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { bool MemoryDependenceAnalysis::runOnFunction(Function &) { AA = &getAnalysis(); TD = &getAnalysis(); + if (PredCache == 0) + PredCache.reset(new PredIteratorCache()); return false; } @@ -468,8 +489,7 @@ getNonLocalPointerDependency(Value *Pointer, bool isLoad, BasicBlock *FromBB, // While we have blocks to analyze, get their values. SmallPtrSet Visited; - for (pred_iterator PI = pred_begin(FromBB), E = pred_end(FromBB); PI != E; - ++PI) { + for (BasicBlock **PI = PredCache->GetPreds(FromBB); *PI; ++PI) { // TODO: PHI TRANSLATE. getNonLocalPointerDepInternal(Pointer, PointeeSize, isLoad, *PI, Result, Visited); @@ -592,7 +612,7 @@ getNonLocalPointerDepInternal(Value *Pointer, uint64_t PointeeSize, // Otherwise, we have to process all the predecessors of this block to scan // them as well. - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) { // TODO: PHI TRANSLATE. Worklist.push_back(*PI); }