From 396a4a55e535728e2023aa331401c1a2b782cb9a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 29 Nov 2008 21:33:22 +0000 Subject: [PATCH] Change MemDep::getNonLocalDependency to return its results as a smallvector instead of a DenseMap. This speeds up GVN by 5% on 403.gcc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60255 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/MemoryDependenceAnalysis.h | 3 ++- lib/Analysis/MemoryDependenceAnalysis.cpp | 13 ++++++------- lib/Transforms/Scalar/GVN.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/llvm/Analysis/MemoryDependenceAnalysis.h b/include/llvm/Analysis/MemoryDependenceAnalysis.h index faffe375563..10aeb290c84 100644 --- a/include/llvm/Analysis/MemoryDependenceAnalysis.h +++ b/include/llvm/Analysis/MemoryDependenceAnalysis.h @@ -175,7 +175,8 @@ namespace llvm { /// This method assumes the instruction returns a "nonlocal" dependency /// within its own block. void getNonLocalDependency(Instruction *QueryInst, - DenseMap &Result); + SmallVectorImpl > &Result); /// removeInstruction - Remove an instruction from the dependence analysis, /// updating the dependence of instructions that previously depended on it. diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index f59be5ec03b..099d43492cd 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -104,8 +104,10 @@ getCallSiteDependency(CallSite C, BasicBlock::iterator ScanIt, /// This method assumes the instruction returns a "nonlocal" dependency /// within its own block. /// -void MemoryDependenceAnalysis::getNonLocalDependency(Instruction *QueryInst, - DenseMap &Result) { +void MemoryDependenceAnalysis:: +getNonLocalDependency(Instruction *QueryInst, + SmallVectorImpl > &Result) { assert(getDependency(QueryInst).isNonLocal() && "getNonLocalDependency should only be used on insts with non-local deps!"); DenseMap &Cache = NonLocalDeps[QueryInst]; @@ -128,10 +130,7 @@ void MemoryDependenceAnalysis::getNonLocalDependency(Instruction *QueryInst, } else { // Seed DirtyBlocks with each of the preds of QueryInst's block. BasicBlock *QueryBB = QueryInst->getParent(); - // FIXME: use range insertion/append. - for (pred_iterator PI = pred_begin(QueryBB), E = pred_end(QueryBB); - PI != E; ++PI) - DirtyBlocks.push_back(*PI); + DirtyBlocks.append(pred_begin(QueryBB), pred_end(QueryBB)); NumUncacheNonlocal++; } @@ -173,7 +172,7 @@ void MemoryDependenceAnalysis::getNonLocalDependency(Instruction *QueryInst, // Copy the result into the output set. for (DenseMap::iterator I = Cache.begin(), E = Cache.end(); I != E; ++I) - Result[I->first] = ConvToResult(I->second); + Result.push_back(std::make_pair(I->first, ConvToResult(I->second))); } /// getDependency - Return the instruction on which a memory operation diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index a6cc9931efa..1522dbab47d 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -495,11 +495,11 @@ uint32_t ValueTable::lookup_or_add(Value* V) { } - DenseMap deps; + SmallVector, 32> deps; MD->getNonLocalDependency(C, deps); CallInst* cdep = 0; - for (DenseMap + for (SmallVector, 32> ::iterator I = deps.begin(), E = deps.end(); I != E; ++I) { if (I->second.isNone()) { valueNumbering.insert(std::make_pair(V, nextValueNumber)); @@ -871,7 +871,7 @@ bool GVN::processNonLocalLoad(LoadInst* L, MemoryDependenceAnalysis& MD = getAnalysis(); // Find the non-local dependencies of the load - DenseMap deps; + SmallVector, 32> deps; MD.getNonLocalDependency(L, deps); // If we had to process more than one hundred blocks to find the @@ -885,8 +885,8 @@ bool GVN::processNonLocalLoad(LoadInst* L, DenseMap repl; // Filter out useless results (non-locals, etc) - for (DenseMap::iterator I = deps.begin(), - E = deps.end(); I != E; ++I) { + for (SmallVector, 32>::iterator + I = deps.begin(), E = deps.end(); I != E; ++I) { if (I->second.isNone()) { repl[I->first] = UndefValue::get(L->getType()); continue;