Mercurial > hg > graal-compiler
comparison src/share/vm/opto/coalesce.cpp @ 12071:adb9a7d94cb5
8023003: Cleanup the public interface to PhaseCFG
Summary: public methods that don't need to be public should be private.
Reviewed-by: kvn, twisti
author | adlertz |
---|---|
date | Fri, 16 Aug 2013 10:23:55 +0200 |
parents | d1034bd8cefc |
children | 4b2838704fd5 |
comparison
equal
deleted
inserted
replaced
12070:afbe18ae0905 | 12071:adb9a7d94cb5 |
---|---|
32 #include "opto/indexSet.hpp" | 32 #include "opto/indexSet.hpp" |
33 #include "opto/machnode.hpp" | 33 #include "opto/machnode.hpp" |
34 #include "opto/matcher.hpp" | 34 #include "opto/matcher.hpp" |
35 #include "opto/regmask.hpp" | 35 #include "opto/regmask.hpp" |
36 | 36 |
37 //============================================================================= | |
38 //------------------------------Dump------------------------------------------- | |
39 #ifndef PRODUCT | 37 #ifndef PRODUCT |
40 void PhaseCoalesce::dump(Node *n) const { | 38 void PhaseCoalesce::dump(Node *n) const { |
41 // Being a const function means I cannot use 'Find' | 39 // Being a const function means I cannot use 'Find' |
42 uint r = _phc._lrg_map.find(n); | 40 uint r = _phc._lrg_map.find(n); |
43 tty->print("L%d/N%d ",r,n->_idx); | 41 tty->print("L%d/N%d ",r,n->_idx); |
44 } | 42 } |
45 | 43 |
46 //------------------------------dump------------------------------------------- | |
47 void PhaseCoalesce::dump() const { | 44 void PhaseCoalesce::dump() const { |
48 // I know I have a block layout now, so I can print blocks in a loop | 45 // I know I have a block layout now, so I can print blocks in a loop |
49 for( uint i=0; i<_phc._cfg._num_blocks; i++ ) { | 46 for( uint i=0; i<_phc._cfg.number_of_blocks(); i++ ) { |
50 uint j; | 47 uint j; |
51 Block *b = _phc._cfg._blocks[i]; | 48 Block* b = _phc._cfg.get_block(i); |
52 // Print a nice block header | 49 // Print a nice block header |
53 tty->print("B%d: ",b->_pre_order); | 50 tty->print("B%d: ",b->_pre_order); |
54 for( j=1; j<b->num_preds(); j++ ) | 51 for( j=1; j<b->num_preds(); j++ ) |
55 tty->print("B%d ", _phc._cfg.get_block_for_node(b->pred(j))->_pre_order); | 52 tty->print("B%d ", _phc._cfg.get_block_for_node(b->pred(j))->_pre_order); |
56 tty->print("-> "); | 53 tty->print("-> "); |
83 tty->print("\n"); | 80 tty->print("\n"); |
84 } | 81 } |
85 } | 82 } |
86 #endif | 83 #endif |
87 | 84 |
88 //------------------------------combine_these_two------------------------------ | |
89 // Combine the live ranges def'd by these 2 Nodes. N2 is an input to N1. | 85 // Combine the live ranges def'd by these 2 Nodes. N2 is an input to N1. |
90 void PhaseCoalesce::combine_these_two(Node *n1, Node *n2) { | 86 void PhaseCoalesce::combine_these_two(Node *n1, Node *n2) { |
91 uint lr1 = _phc._lrg_map.find(n1); | 87 uint lr1 = _phc._lrg_map.find(n1); |
92 uint lr2 = _phc._lrg_map.find(n2); | 88 uint lr2 = _phc._lrg_map.find(n2); |
93 if( lr1 != lr2 && // Different live ranges already AND | 89 if( lr1 != lr2 && // Different live ranges already AND |
125 lrg1->AND(lrg2->mask()); | 121 lrg1->AND(lrg2->mask()); |
126 } | 122 } |
127 } | 123 } |
128 } | 124 } |
129 | 125 |
130 //------------------------------coalesce_driver-------------------------------- | |
131 // Copy coalescing | 126 // Copy coalescing |
132 void PhaseCoalesce::coalesce_driver( ) { | 127 void PhaseCoalesce::coalesce_driver() { |
133 | |
134 verify(); | 128 verify(); |
135 // Coalesce from high frequency to low | 129 // Coalesce from high frequency to low |
136 for( uint i=0; i<_phc._cfg._num_blocks; i++ ) | 130 for (uint i = 0; i < _phc._cfg.number_of_blocks(); i++) { |
137 coalesce( _phc._blks[i] ); | 131 coalesce(_phc._blks[i]); |
138 | 132 } |
139 } | 133 } |
140 | 134 |
141 //------------------------------insert_copy_with_overlap----------------------- | |
142 // I am inserting copies to come out of SSA form. In the general case, I am | 135 // I am inserting copies to come out of SSA form. In the general case, I am |
143 // doing a parallel renaming. I'm in the Named world now, so I can't do a | 136 // doing a parallel renaming. I'm in the Named world now, so I can't do a |
144 // general parallel renaming. All the copies now use "names" (live-ranges) | 137 // general parallel renaming. All the copies now use "names" (live-ranges) |
145 // to carry values instead of the explicit use-def chains. Suppose I need to | 138 // to carry values instead of the explicit use-def chains. Suppose I need to |
146 // insert 2 copies into the same block. They copy L161->L128 and L128->L132. | 139 // insert 2 copies into the same block. They copy L161->L128 and L128->L132. |
214 | 207 |
215 // Insert just after last use | 208 // Insert just after last use |
216 b->_nodes.insert(last_use_idx+1,copy); | 209 b->_nodes.insert(last_use_idx+1,copy); |
217 } | 210 } |
218 | 211 |
219 //------------------------------insert_copies---------------------------------- | |
220 void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) { | 212 void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) { |
221 // We do LRGs compressing and fix a liveout data only here since the other | 213 // We do LRGs compressing and fix a liveout data only here since the other |
222 // place in Split() is guarded by the assert which we never hit. | 214 // place in Split() is guarded by the assert which we never hit. |
223 _phc._lrg_map.compress_uf_map_for_nodes(); | 215 _phc._lrg_map.compress_uf_map_for_nodes(); |
224 // Fix block's liveout data for compressed live ranges. | 216 // Fix block's liveout data for compressed live ranges. |
225 for (uint lrg = 1; lrg < _phc._lrg_map.max_lrg_id(); lrg++) { | 217 for (uint lrg = 1; lrg < _phc._lrg_map.max_lrg_id(); lrg++) { |
226 uint compressed_lrg = _phc._lrg_map.find(lrg); | 218 uint compressed_lrg = _phc._lrg_map.find(lrg); |
227 if (lrg != compressed_lrg) { | 219 if (lrg != compressed_lrg) { |
228 for (uint bidx = 0; bidx < _phc._cfg._num_blocks; bidx++) { | 220 for (uint bidx = 0; bidx < _phc._cfg.number_of_blocks(); bidx++) { |
229 IndexSet *liveout = _phc._live->live(_phc._cfg._blocks[bidx]); | 221 IndexSet *liveout = _phc._live->live(_phc._cfg.get_block(bidx)); |
230 if (liveout->member(lrg)) { | 222 if (liveout->member(lrg)) { |
231 liveout->remove(lrg); | 223 liveout->remove(lrg); |
232 liveout->insert(compressed_lrg); | 224 liveout->insert(compressed_lrg); |
233 } | 225 } |
234 } | 226 } |
237 | 229 |
238 // All new nodes added are actual copies to replace virtual copies. | 230 // All new nodes added are actual copies to replace virtual copies. |
239 // Nodes with index less than '_unique' are original, non-virtual Nodes. | 231 // Nodes with index less than '_unique' are original, non-virtual Nodes. |
240 _unique = C->unique(); | 232 _unique = C->unique(); |
241 | 233 |
242 for( uint i=0; i<_phc._cfg._num_blocks; i++ ) { | 234 for (uint i = 0; i < _phc._cfg.number_of_blocks(); i++) { |
243 C->check_node_count(NodeLimitFudgeFactor, "out of nodes in coalesce"); | 235 C->check_node_count(NodeLimitFudgeFactor, "out of nodes in coalesce"); |
244 if (C->failing()) return; | 236 if (C->failing()) return; |
245 Block *b = _phc._cfg._blocks[i]; | 237 Block *b = _phc._cfg.get_block(i); |
246 uint cnt = b->num_preds(); // Number of inputs to the Phi | 238 uint cnt = b->num_preds(); // Number of inputs to the Phi |
247 | 239 |
248 for( uint l = 1; l<b->_nodes.size(); l++ ) { | 240 for( uint l = 1; l<b->_nodes.size(); l++ ) { |
249 Node *n = b->_nodes[l]; | 241 Node *n = b->_nodes[l]; |
250 | 242 |
401 | 393 |
402 } // End of for all instructions | 394 } // End of for all instructions |
403 } // End of for all blocks | 395 } // End of for all blocks |
404 } | 396 } |
405 | 397 |
406 //============================================================================= | 398 |
407 //------------------------------coalesce--------------------------------------- | |
408 // Aggressive (but pessimistic) copy coalescing of a single block | 399 // Aggressive (but pessimistic) copy coalescing of a single block |
409 | 400 |
410 // The following coalesce pass represents a single round of aggressive | 401 // The following coalesce pass represents a single round of aggressive |
411 // pessimistic coalesce. "Aggressive" means no attempt to preserve | 402 // pessimistic coalesce. "Aggressive" means no attempt to preserve |
412 // colorability when coalescing. This occasionally means more spills, but | 403 // colorability when coalescing. This occasionally means more spills, but |
462 combine_these_two(mach, mach->in(idx)); | 453 combine_these_two(mach, mach->in(idx)); |
463 } | 454 } |
464 } // End of for all instructions in block | 455 } // End of for all instructions in block |
465 } | 456 } |
466 | 457 |
467 //============================================================================= | |
468 //------------------------------PhaseConservativeCoalesce---------------------- | |
469 PhaseConservativeCoalesce::PhaseConservativeCoalesce(PhaseChaitin &chaitin) : PhaseCoalesce(chaitin) { | 458 PhaseConservativeCoalesce::PhaseConservativeCoalesce(PhaseChaitin &chaitin) : PhaseCoalesce(chaitin) { |
470 _ulr.initialize(_phc._lrg_map.max_lrg_id()); | 459 _ulr.initialize(_phc._lrg_map.max_lrg_id()); |
471 } | 460 } |
472 | 461 |
473 //------------------------------verify----------------------------------------- | |
474 void PhaseConservativeCoalesce::verify() { | 462 void PhaseConservativeCoalesce::verify() { |
475 #ifdef ASSERT | 463 #ifdef ASSERT |
476 _phc.set_was_low(); | 464 _phc.set_was_low(); |
477 #endif | 465 #endif |
478 } | 466 } |
479 | 467 |
480 //------------------------------union_helper----------------------------------- | |
481 void PhaseConservativeCoalesce::union_helper( Node *lr1_node, Node *lr2_node, uint lr1, uint lr2, Node *src_def, Node *dst_copy, Node *src_copy, Block *b, uint bindex ) { | 468 void PhaseConservativeCoalesce::union_helper( Node *lr1_node, Node *lr2_node, uint lr1, uint lr2, Node *src_def, Node *dst_copy, Node *src_copy, Block *b, uint bindex ) { |
482 // Join live ranges. Merge larger into smaller. Union lr2 into lr1 in the | 469 // Join live ranges. Merge larger into smaller. Union lr2 into lr1 in the |
483 // union-find tree | 470 // union-find tree |
484 _phc.Union( lr1_node, lr2_node ); | 471 _phc.Union( lr1_node, lr2_node ); |
485 | 472 |
518 b = _phc._cfg.get_block_for_node(b->pred(1)); | 505 b = _phc._cfg.get_block_for_node(b->pred(1)); |
519 _phc._live->live(b)->insert(lr1); | 506 _phc._live->live(b)->insert(lr1); |
520 } | 507 } |
521 } | 508 } |
522 | 509 |
523 //------------------------------compute_separating_interferences--------------- | |
524 // Factored code from copy_copy that computes extra interferences from | 510 // Factored code from copy_copy that computes extra interferences from |
525 // lengthening a live range by double-coalescing. | 511 // lengthening a live range by double-coalescing. |
526 uint PhaseConservativeCoalesce::compute_separating_interferences(Node *dst_copy, Node *src_copy, Block *b, uint bindex, RegMask &rm, uint reg_degree, uint rm_size, uint lr1, uint lr2 ) { | 512 uint PhaseConservativeCoalesce::compute_separating_interferences(Node *dst_copy, Node *src_copy, Block *b, uint bindex, RegMask &rm, uint reg_degree, uint rm_size, uint lr1, uint lr2 ) { |
527 | 513 |
528 assert(!lrgs(lr1)._fat_proj, "cannot coalesce fat_proj"); | 514 assert(!lrgs(lr1)._fat_proj, "cannot coalesce fat_proj"); |
584 } // End of else collect interferences for 1 node | 570 } // End of else collect interferences for 1 node |
585 } // End of while forever, scan back for interferences | 571 } // End of while forever, scan back for interferences |
586 return reg_degree; | 572 return reg_degree; |
587 } | 573 } |
588 | 574 |
589 //------------------------------update_ifg------------------------------------- | |
590 void PhaseConservativeCoalesce::update_ifg(uint lr1, uint lr2, IndexSet *n_lr1, IndexSet *n_lr2) { | 575 void PhaseConservativeCoalesce::update_ifg(uint lr1, uint lr2, IndexSet *n_lr1, IndexSet *n_lr2) { |
591 // Some original neighbors of lr1 might have gone away | 576 // Some original neighbors of lr1 might have gone away |
592 // because the constrained register mask prevented them. | 577 // because the constrained register mask prevented them. |
593 // Remove lr1 from such neighbors. | 578 // Remove lr1 from such neighbors. |
594 IndexSetIterator one(n_lr1); | 579 IndexSetIterator one(n_lr1); |
614 while ((neighbor = three.next()) != 0) | 599 while ((neighbor = three.next()) != 0) |
615 if( _phc._ifg->neighbors(neighbor)->insert(lr1) ) | 600 if( _phc._ifg->neighbors(neighbor)->insert(lr1) ) |
616 lrgs(neighbor).inc_degree( lrg1.compute_degree(lrgs(neighbor)) ); | 601 lrgs(neighbor).inc_degree( lrg1.compute_degree(lrgs(neighbor)) ); |
617 } | 602 } |
618 | 603 |
619 //------------------------------record_bias------------------------------------ | |
620 static void record_bias( const PhaseIFG *ifg, int lr1, int lr2 ) { | 604 static void record_bias( const PhaseIFG *ifg, int lr1, int lr2 ) { |
621 // Tag copy bias here | 605 // Tag copy bias here |
622 if( !ifg->lrgs(lr1)._copy_bias ) | 606 if( !ifg->lrgs(lr1)._copy_bias ) |
623 ifg->lrgs(lr1)._copy_bias = lr2; | 607 ifg->lrgs(lr1)._copy_bias = lr2; |
624 if( !ifg->lrgs(lr2)._copy_bias ) | 608 if( !ifg->lrgs(lr2)._copy_bias ) |
625 ifg->lrgs(lr2)._copy_bias = lr1; | 609 ifg->lrgs(lr2)._copy_bias = lr1; |
626 } | 610 } |
627 | 611 |
628 //------------------------------copy_copy-------------------------------------- | |
629 // See if I can coalesce a series of multiple copies together. I need the | 612 // See if I can coalesce a series of multiple copies together. I need the |
630 // final dest copy and the original src copy. They can be the same Node. | 613 // final dest copy and the original src copy. They can be the same Node. |
631 // Compute the compatible register masks. | 614 // Compute the compatible register masks. |
632 bool PhaseConservativeCoalesce::copy_copy(Node *dst_copy, Node *src_copy, Block *b, uint bindex) { | 615 bool PhaseConservativeCoalesce::copy_copy(Node *dst_copy, Node *src_copy, Block *b, uint bindex) { |
633 | 616 |
783 //tty->print_cr("warning: slow verify happening"); | 766 //tty->print_cr("warning: slow verify happening"); |
784 //_phc._ifg->verify( &_phc ); | 767 //_phc._ifg->verify( &_phc ); |
785 return true; | 768 return true; |
786 } | 769 } |
787 | 770 |
788 //------------------------------coalesce--------------------------------------- | |
789 // Conservative (but pessimistic) copy coalescing of a single block | 771 // Conservative (but pessimistic) copy coalescing of a single block |
790 void PhaseConservativeCoalesce::coalesce( Block *b ) { | 772 void PhaseConservativeCoalesce::coalesce( Block *b ) { |
791 // Bail out on infrequent blocks | 773 // Bail out on infrequent blocks |
792 if (b->is_uncommon(&_phc._cfg)) { | 774 if (b->is_uncommon(&_phc._cfg)) { |
793 return; | 775 return; |