llvm.org GIT mirror llvm / a20f35d
Make many sets a much more reasonable size. This decreases the time to optimize Anton's testcase from 35.5s to 34.7s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37769 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
1 changed file(s) with 66 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
416416 ValueTable VN;
417417 std::vector createdExpressions;
418418
419 std::map > availableOut;
420 std::map32> > anticipatedIn;
419 std::map16> > availableOut;
420 std::map > anticipatedIn;
421421
422422 // This transformation requires dominator postdominator info
423423 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
427427
428428 // Helper fuctions
429429 // FIXME: eliminate or document these better
430 void dump(const SmallPtrSet& s) const;
431 void clean(SmallPtrSet& set, BitVector& presentInSet);
432 Value* find_leader(SmallPtrSet& vals,
430 void dump(const SmallPtrSet& s) const;
431 void clean(SmallPtrSet& set, BitVector& presentInSet);
432 Value* find_leader(SmallPtrSet& vals,
433433 uint32_t v);
434434 Value* phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ);
435 void phi_translate_set(SmallPtrSet& anticIn, BasicBlock* pred,
436 BasicBlock* succ, SmallPtrSet& out);
437
438 void topo_sort(SmallPtrSet& set,
435 void phi_translate_set(SmallPtrSet& anticIn, BasicBlock* pred,
436 BasicBlock* succ, SmallPtrSet& out);
437
438 void topo_sort(SmallPtrSet& set,
439439 std::vector& vec);
440440
441441 void cleanup();
442442 bool elimination();
443443
444 void val_insert(SmallPtrSet& s, Value* v);
445 void val_replace(SmallPtrSet>& s, Value* v);
444 void val_insert(SmallPtrSet>& s, Value* v);
445 void val_replace(SmallPtrSet& s, Value* v);
446446 bool dependsOnInvoke(Value* V);
447447 void buildsets_availout(BasicBlock::iterator I,
448 SmallPtrSet& currAvail,
449 SmallPtrSet& currPhis,
450 SmallPtrSet& currExps,
451 SmallPtrSet32>& currTemps,
448 SmallPtrSet16>& currAvail,
449 SmallPtrSet& currPhis,
450 SmallPtrSet& currExps,
451 SmallPtrSet& currTemps,
452452 BitVector& availNumbers,
453453 BitVector& expNumbers);
454454 bool buildsets_anticout(BasicBlock* BB,
455 SmallPtrSet32>& anticOut,
455 SmallPtrSet16>& anticOut,
456456 std::set& visited);
457457 unsigned buildsets_anticin(BasicBlock* BB,
458 SmallPtrSet& anticOut,
459 SmallPtrSet& currExps,
460 SmallPtrSet32>& currTemps,
458 SmallPtrSet16>& anticOut,
459 SmallPtrSet& currExps,
460 SmallPtrSet& currTemps,
461461 std::set& visited);
462462 void buildsets(Function& F);
463463
464464 void insertion_pre(Value* e, BasicBlock* BB,
465465 std::map& avail,
466 SmallPtrSet32>& new_set);
466 SmallPtrSet16>& new_set);
467467 unsigned insertion_mergepoint(std::vector& workList,
468468 df_iterator& D,
469 SmallPtrSet32>& new_set);
469 SmallPtrSet16>& new_set);
470470 bool insertion(Function& F);
471471
472472 };
489489 /// find_leader - Given a set and a value number, return the first
490490 /// element of the set with that value number, or 0 if no such element
491491 /// is present
492 Value* GVNPRE::find_leader(SmallPtrSet& vals, uint32_t v) {
493 for (SmallPtrSet::iterator I = vals.begin(), E = vals.end();
492 Value* GVNPRE::find_leader(SmallPtrSet& vals, uint32_t v) {
493 for (SmallPtrSet::iterator I = vals.begin(), E = vals.end();
494494 I != E; ++I)
495495 if (v == VN.lookup(*I))
496496 return *I;
500500
501501 /// val_insert - Insert a value into a set only if there is not a value
502502 /// with the same value number already in the set
503 void GVNPRE::val_insert(SmallPtrSet32>& s, Value* v) {
503 void GVNPRE::val_insert(SmallPtrSet16>& s, Value* v) {
504504 uint32_t num = VN.lookup(v);
505505 Value* leader = find_leader(s, num);
506506 if (leader == 0)
509509
510510 /// val_replace - Insert a value into a set, replacing any values already in
511511 /// the set that have the same value number
512 void GVNPRE::val_replace(SmallPtrSet32>& s, Value* v) {
512 void GVNPRE::val_replace(SmallPtrSet16>& s, Value* v) {
513513 uint32_t num = VN.lookup(v);
514514 Value* leader = find_leader(s, num);
515515 while (leader != 0) {
642642 }
643643
644644 /// phi_translate_set - Perform phi translation on every element of a set
645 void GVNPRE::phi_translate_set(SmallPtrSet32>& anticIn,
645 void GVNPRE::phi_translate_set(SmallPtrSet16>& anticIn,
646646 BasicBlock* pred, BasicBlock* succ,
647 SmallPtrSet& out) {
648 for (SmallPtrSet::iterator I = anticIn.begin(),
647 SmallPtrSet& out) {
648 for (SmallPtrSet::iterator I = anticIn.begin(),
649649 E = anticIn.end(); I != E; ++I) {
650650 Value* V = phi_translate(*I, pred, succ);
651651 if (V != 0)
670670 /// clean - Remove all non-opaque values from the set whose operands are not
671671 /// themselves in the set, as well as all values that depend on invokes (see
672672 /// above)
673 void GVNPRE::clean(SmallPtrSet32>& set, BitVector& presentInSet) {
673 void GVNPRE::clean(SmallPtrSet16>& set, BitVector& presentInSet) {
674674 std::vector worklist;
675675 worklist.reserve(set.size());
676676 topo_sort(set, worklist);
727727
728728 /// topo_sort - Given a set of values, sort them by topological
729729 /// order into the provided vector.
730 void GVNPRE::topo_sort(SmallPtrSet& set, std::vector& vec) {
731 SmallPtrSet visited;
730 void GVNPRE::topo_sort(SmallPtrSet& set, std::vector& vec) {
731 SmallPtrSet visited;
732732 std::vector stack;
733 for (SmallPtrSet32>::iterator I = set.begin(), E = set.end();
733 for (SmallPtrSet16>::iterator I = set.begin(), E = set.end();
734734 I != E; ++I) {
735735 if (visited.count(*I) == 0)
736736 stack.push_back(*I);
792792 }
793793
794794 /// dump - Dump a set of values to standard error
795 void GVNPRE::dump(const SmallPtrSet32>& s) const {
795 void GVNPRE::dump(const SmallPtrSet16>& s) const {
796796 DOUT << "{ ";
797 for (SmallPtrSet32>::iterator I = s.begin(), E = s.end();
797 for (SmallPtrSet16>::iterator I = s.begin(), E = s.end();
798798 I != E; ++I) {
799799 DEBUG((*I)->dump());
800800 }
869869 /// buildsets_availout - When calculating availability, handle an instruction
870870 /// by inserting it into the appropriate sets
871871 void GVNPRE::buildsets_availout(BasicBlock::iterator I,
872 SmallPtrSet& currAvail,
873 SmallPtrSet& currPhis,
874 SmallPtrSet& currExps,
875 SmallPtrSet32>& currTemps,
872 SmallPtrSet16>& currAvail,
873 SmallPtrSet& currPhis,
874 SmallPtrSet& currExps,
875 SmallPtrSet& currTemps,
876876 BitVector& availNumbers,
877877 BitVector& expNumbers) {
878878 // Handle PHI nodes
964964 /// buildsets_anticout - When walking the postdom tree, calculate the ANTIC_OUT
965965 /// set as a function of the ANTIC_IN set of the block's predecessors
966966 bool GVNPRE::buildsets_anticout(BasicBlock* BB,
967 SmallPtrSet32>& anticOut,
967 SmallPtrSet16>& anticOut,
968968 std::set& visited) {
969969 if (BB->getTerminator()->getNumSuccessors() == 1) {
970970 if (BB->getTerminator()->getSuccessor(0) != BB &&
982982
983983 for (unsigned i = 1; i < BB->getTerminator()->getNumSuccessors(); ++i) {
984984 BasicBlock* currSucc = BB->getTerminator()->getSuccessor(i);
985 SmallPtrSet32>& succAnticIn = anticipatedIn[currSucc];
985 SmallPtrSet16>& succAnticIn = anticipatedIn[currSucc];
986986
987987 std::vector temp;
988988
989 for (SmallPtrSet32>::iterator I = anticOut.begin(),
989 for (SmallPtrSet16>::iterator I = anticOut.begin(),
990990 E = anticOut.end(); I != E; ++I)
991991 if (succAnticIn.count(*I) == 0)
992992 temp.push_back(*I);
10041004 /// each block. ANTIC_IN is then a function of ANTIC_OUT and the GEN
10051005 /// sets populated in buildsets_availout
10061006 unsigned GVNPRE::buildsets_anticin(BasicBlock* BB,
1007 SmallPtrSet& anticOut,
1008 SmallPtrSet& currExps,
1009 SmallPtrSet32>& currTemps,
1007 SmallPtrSet16>& anticOut,
1008 SmallPtrSet& currExps,
1009 SmallPtrSet& currTemps,
10101010 std::set& visited) {
1011 SmallPtrSet32>& anticIn = anticipatedIn[BB];
1011 SmallPtrSet16>& anticIn = anticipatedIn[BB];
10121012 unsigned old = anticIn.size();
10131013
10141014 bool defer = buildsets_anticout(BB, anticOut, visited);
10181018 anticIn.clear();
10191019
10201020 BitVector numbers(VN.size());
1021 for (SmallPtrSet32>::iterator I = anticOut.begin(),
1021 for (SmallPtrSet16>::iterator I = anticOut.begin(),
10221022 E = anticOut.end(); I != E; ++I) {
10231023 unsigned num = VN.lookup_or_add(*I);
10241024 numbers.resize(VN.size());
10281028 numbers.set(num);
10291029 }
10301030 }
1031 for (SmallPtrSet32>::iterator I = currExps.begin(),
1031 for (SmallPtrSet16>::iterator I = currExps.begin(),
10321032 E = currExps.end(); I != E; ++I) {
10331033 if (!numbers.test(VN.lookup_or_add(*I))) {
10341034 anticIn.insert(*I);
10361036 }
10371037 }
10381038
1039 for (SmallPtrSet32>::iterator I = currTemps.begin(),
1039 for (SmallPtrSet16>::iterator I = currTemps.begin(),
10401040 E = currTemps.end(); I != E; ++I) {
10411041 anticIn.erase(*I);
10421042 numbers.flip(VN.lookup(*I));
10541054 /// buildsets - Phase 1 of the main algorithm. Construct the AVAIL_OUT
10551055 /// and the ANTIC_IN sets.
10561056 void GVNPRE::buildsets(Function& F) {
1057 std::map > generatedExpressions;
1058 std::map > generatedPhis;
1059 std::map32> > generatedTemporaries;
1057 std::map16> > generatedExpressions;
1058 std::map > generatedPhis;
1059 std::map > generatedTemporaries;
10601060
10611061 DominatorTree &DT = getAnalysis();
10621062
10671067 E = df_end(DT.getRootNode()); DI != E; ++DI) {
10681068
10691069 // Get the sets to update for this block
1070 SmallPtrSet& currExps = generatedExpressions[DI->getBlock()];
1071 SmallPtrSet& currPhis = generatedPhis[DI->getBlock()];
1072 SmallPtrSet& currTemps = generatedTemporaries[DI->getBlock()];
1073 SmallPtrSet32>& currAvail = availableOut[DI->getBlock()];
1070 SmallPtrSet16>& currExps = generatedExpressions[DI->getBlock()];
1071 SmallPtrSet& currPhis = generatedPhis[DI->getBlock()];
1072 SmallPtrSet& currTemps = generatedTemporaries[DI->getBlock()];
1073 SmallPtrSet& currAvail = availableOut[DI->getBlock()];
10741074
10751075 BasicBlock* BB = DI->getBlock();
10761076
10801080 availableOut[DI->getIDom()->getBlock()].end());
10811081
10821082 BitVector availNumbers(VN.size());
1083 for (SmallPtrSet32>::iterator I = currAvail.begin(),
1083 for (SmallPtrSet16>::iterator I = currAvail.begin(),
10841084 E = currAvail.end(); I != E; ++I)
10851085 availNumbers.set(VN.lookup(*I));
10861086
11041104
11051105 while (changed) {
11061106 changed = false;
1107 SmallPtrSet32> anticOut;
1107 SmallPtrSet16> anticOut;
11081108
11091109 // Postorder walk of the CFG
11101110 for (po_iterator BBI = po_begin(&F.getEntryBlock()),
11451145 /// the main block
11461146 void GVNPRE::insertion_pre(Value* e, BasicBlock* BB,
11471147 std::map& avail,
1148 SmallPtrSet32>& new_set) {
1148 SmallPtrSet16>& new_set) {
11491149 for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
11501150 Value* e2 = avail[*PI];
11511151 if (!find_leader(availableOut[*PI], VN.lookup(e2))) {
12051205
12061206 VN.add(newVal, VN.lookup(U));
12071207
1208 SmallPtrSet32>& predAvail = availableOut[*PI];
1208 SmallPtrSet16>& predAvail = availableOut[*PI];
12091209 val_replace(predAvail, newVal);
12101210
12111211 std::map::iterator av = avail.find(*PI);
12371237 /// block for the possibility of a partial redundancy. If present, eliminate it
12381238 unsigned GVNPRE::insertion_mergepoint(std::vector& workList,
12391239 df_iterator& D,
1240 SmallPtrSet32>& new_set) {
1240 SmallPtrSet16>& new_set) {
12411241 bool changed_function = false;
12421242 bool new_stuff = false;
12431243
13031303
13041304 DominatorTree &DT = getAnalysis();
13051305
1306 std::map32> > new_sets;
1306 std::map16> > new_sets;
13071307 bool new_stuff = true;
13081308 while (new_stuff) {
13091309 new_stuff = false;
13141314 if (BB == 0)
13151315 continue;
13161316
1317 SmallPtrSet& new_set = new_sets[BB];
1318 SmallPtrSet& availOut = availableOut[BB];
1319 SmallPtrSet32>& anticIn = anticipatedIn[BB];
1317 SmallPtrSet16>& new_set = new_sets[BB];
1318 SmallPtrSet& availOut = availableOut[BB];
1319 SmallPtrSet& anticIn = anticipatedIn[BB];
13201320
13211321 new_set.clear();
13221322
13231323 // Replace leaders with leaders inherited from dominator
13241324 if (DI->getIDom() != 0) {
1325 SmallPtrSet& dom_set = new_sets[DI->getIDom()->getBlock()];
1326 for (SmallPtrSet::iterator I = dom_set.begin(),
1325 SmallPtrSet& dom_set = new_sets[DI->getIDom()->getBlock()];
1326 for (SmallPtrSet::iterator I = dom_set.begin(),
13271327 E = dom_set.end(); I != E; ++I) {
13281328 new_set.insert(*I);
13291329 val_replace(availOut, *I);