From 6aa17f1def4f597b55f5c72d2926997547fe9311 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Thu, 19 Jul 2007 06:37:56 +0000 Subject: [PATCH] Use SmallVector and DenseMap in even more places. With this, the time to optimize 403.gcc is down to 15.1s. llvm-svn: 40042 --- llvm/lib/Transforms/Scalar/GVNPRE.cpp | 53 +++++++++++++-------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/GVNPRE.cpp b/llvm/lib/Transforms/Scalar/GVNPRE.cpp index e1e92f8561f1..69e5f733f731 100644 --- a/llvm/lib/Transforms/Scalar/GVNPRE.cpp +++ b/llvm/lib/Transforms/Scalar/GVNPRE.cpp @@ -39,7 +39,6 @@ #include #include #include -#include using namespace llvm; //===----------------------------------------------------------------------===// @@ -659,7 +658,7 @@ namespace { private: ValueTable VN; - std::vector createdExpressions; + SmallVector createdExpressions; DenseMap availableOut; DenseMap anticipatedIn; @@ -683,7 +682,7 @@ namespace { BasicBlock* succ, ValueNumberedSet& out) ; void topo_sort(ValueNumberedSet& set, - std::vector& vec) ; + SmallVector& vec) ; void cleanup() ; bool elimination() ; @@ -695,23 +694,23 @@ namespace { ValueNumberedSet& currAvail, ValueNumberedSet& currPhis, ValueNumberedSet& currExps, - SmallPtrSet& currTemps) ; + SmallPtrSet& currTemps); bool buildsets_anticout(BasicBlock* BB, ValueNumberedSet& anticOut, - SmallPtrSet& visited) ; + SmallPtrSet& visited); unsigned buildsets_anticin(BasicBlock* BB, ValueNumberedSet& anticOut, ValueNumberedSet& currExps, SmallPtrSet& currTemps, - SmallPtrSet& visited) ; + SmallPtrSet& visited); void buildsets(Function& F) ; void insertion_pre(Value* e, BasicBlock* BB, - std::map& avail, - std::map& new_set) ; - unsigned insertion_mergepoint(std::vector& workList, + DenseMap& avail, + std::map& new_set); + unsigned insertion_mergepoint(SmallVector& workList, df_iterator& D, - std::map& new_set) ; + std::map& new_set); bool insertion(Function& F) ; }; @@ -925,7 +924,7 @@ Value* GVNPRE::phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) { return 0; bool changed_idx = false; - std::vector newIdx; + SmallVector newIdx; for (GetElementPtrInst::op_iterator I = U->idx_begin(), E = U->idx_end(); I != E; ++I) if (isa(*I)) { @@ -996,7 +995,7 @@ bool GVNPRE::dependsOnInvoke(Value* V) { /// themselves in the set, as well as all values that depend on invokes (see /// above) void GVNPRE::clean(ValueNumberedSet& set) { - std::vector worklist; + SmallVector worklist; worklist.reserve(set.size()); topo_sort(set, worklist); @@ -1085,9 +1084,9 @@ void GVNPRE::clean(ValueNumberedSet& set) { /// topo_sort - Given a set of values, sort them by topological /// order into the provided vector. -void GVNPRE::topo_sort(ValueNumberedSet& set, std::vector& vec) { +void GVNPRE::topo_sort(ValueNumberedSet& set, SmallVector& vec) { SmallPtrSet visited; - std::vector stack; + SmallVector stack; for (ValueNumberedSet::iterator I = set.begin(), E = set.end(); I != E; ++I) { if (visited.count(*I) == 0) @@ -1205,8 +1204,8 @@ void GVNPRE::dump(ValueNumberedSet& s) const { bool GVNPRE::elimination() { bool changed_function = false; - std::vector > replace; - std::vector erase; + SmallVector, 8> replace; + SmallVector erase; DominatorTree& DT = getAnalysis(); @@ -1242,7 +1241,7 @@ bool GVNPRE::elimination() { changed_function = true; } - for (std::vector::iterator I = erase.begin(), E = erase.end(); + for (SmallVector::iterator I = erase.begin(), E = erase.end(); I != E; ++I) (*I)->eraseFromParent(); @@ -1416,14 +1415,14 @@ bool GVNPRE::buildsets_anticout(BasicBlock* BB, BasicBlock* currSucc = BB->getTerminator()->getSuccessor(i); ValueNumberedSet& succAnticIn = anticipatedIn[currSucc]; - std::vector temp; + SmallVector temp; for (ValueNumberedSet::iterator I = anticOut.begin(), E = anticOut.end(); I != E; ++I) if (!succAnticIn.test(VN.lookup(*I))) temp.push_back(*I); - for (std::vector::iterator I = temp.begin(), E = temp.end(); + for (SmallVector::iterator I = temp.begin(), E = temp.end(); I != E; ++I) { anticOut.erase(*I); anticOut.reset(VN.lookup(*I)); @@ -1562,7 +1561,7 @@ void GVNPRE::buildsets(Function& F) { /// by inserting appropriate values into the predecessors and a phi node in /// the main block void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, - std::map& avail, + DenseMap& avail, std::map& new_sets) { for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) { Value* e2 = avail[*PI]; @@ -1622,7 +1621,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, } // Vararg operators - std::vector sVarargs; + SmallVector sVarargs; if (GetElementPtrInst* G = dyn_cast(U)) { for (GetElementPtrInst::op_iterator OI = G->idx_begin(), OE = G->idx_end(); OI != OE; ++OI) { @@ -1680,7 +1679,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, val_replace(new_sets[*PI], newVal); predAvail.set(VN.lookup(newVal)); - std::map::iterator av = avail.find(*PI); + DenseMap::iterator av = avail.find(*PI); if (av != avail.end()) avail.erase(av); avail.insert(std::make_pair(*PI, newVal)); @@ -1711,7 +1710,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, /// insertion_mergepoint - When walking the dom tree, check at each merge /// block for the possibility of a partial redundancy. If present, eliminate it -unsigned GVNPRE::insertion_mergepoint(std::vector& workList, +unsigned GVNPRE::insertion_mergepoint(SmallVector& workList, df_iterator& D, std::map& new_sets) { bool changed_function = false; @@ -1728,7 +1727,7 @@ unsigned GVNPRE::insertion_mergepoint(std::vector& workList, if (availableOut[D->getIDom()->getBlock()].test(VN.lookup(e))) continue; - std::map avail; + DenseMap avail; bool by_some = false; bool all_same = true; Value * first_s = 0; @@ -1739,13 +1738,13 @@ unsigned GVNPRE::insertion_mergepoint(std::vector& workList, Value *e3 = find_leader(availableOut[*PI], VN.lookup(e2)); if (e3 == 0) { - std::map::iterator av = avail.find(*PI); + DenseMap::iterator av = avail.find(*PI); if (av != avail.end()) avail.erase(av); avail.insert(std::make_pair(*PI, e2)); all_same = false; } else { - std::map::iterator av = avail.find(*PI); + DenseMap::iterator av = avail.find(*PI); if (av != avail.end()) avail.erase(av); avail.insert(std::make_pair(*PI, e3)); @@ -1811,7 +1810,7 @@ bool GVNPRE::insertion(Function& F) { // If there is more than one predecessor... if (pred_begin(BB) != pred_end(BB) && ++pred_begin(BB) != pred_end(BB)) { - std::vector workList; + SmallVector workList; workList.reserve(anticIn.size()); topo_sort(anticIn, workList);