Mercurial > hg > graal-jvmci-8
comparison src/share/vm/opto/coalesce.cpp @ 12023:d1034bd8cefc
8022284: Hide internal data structure in PhaseCFG
Summary: Hide private node to block mapping using public interface
Reviewed-by: kvn, roland
author | adlertz |
---|---|
date | Wed, 07 Aug 2013 17:56:19 +0200 |
parents | 693e4d04fd09 |
children | adb9a7d94cb5 |
comparison
equal
deleted
inserted
replaced
12004:71526a36ebb4 | 12023:d1034bd8cefc |
---|---|
50 uint j; | 50 uint j; |
51 Block *b = _phc._cfg._blocks[i]; | 51 Block *b = _phc._cfg._blocks[i]; |
52 // Print a nice block header | 52 // Print a nice block header |
53 tty->print("B%d: ",b->_pre_order); | 53 tty->print("B%d: ",b->_pre_order); |
54 for( j=1; j<b->num_preds(); j++ ) | 54 for( j=1; j<b->num_preds(); j++ ) |
55 tty->print("B%d ", _phc._cfg._bbs[b->pred(j)->_idx]->_pre_order); | 55 tty->print("B%d ", _phc._cfg.get_block_for_node(b->pred(j))->_pre_order); |
56 tty->print("-> "); | 56 tty->print("-> "); |
57 for( j=0; j<b->_num_succs; j++ ) | 57 for( j=0; j<b->_num_succs; j++ ) |
58 tty->print("B%d ",b->_succs[j]->_pre_order); | 58 tty->print("B%d ",b->_succs[j]->_pre_order); |
59 tty->print(" IDom: B%d/#%d\n", b->_idom ? b->_idom->_pre_order : 0, b->_dom_depth); | 59 tty->print(" IDom: B%d/#%d\n", b->_idom ? b->_idom->_pre_order : 0, b->_dom_depth); |
60 uint cnt = b->_nodes.size(); | 60 uint cnt = b->_nodes.size(); |
206 // Insert new temp between copy and source | 206 // Insert new temp between copy and source |
207 tmp ->set_req(idx,copy->in(idx)); | 207 tmp ->set_req(idx,copy->in(idx)); |
208 copy->set_req(idx,tmp); | 208 copy->set_req(idx,tmp); |
209 // Save source in temp early, before source is killed | 209 // Save source in temp early, before source is killed |
210 b->_nodes.insert(kill_src_idx,tmp); | 210 b->_nodes.insert(kill_src_idx,tmp); |
211 _phc._cfg._bbs.map( tmp->_idx, b ); | 211 _phc._cfg.map_node_to_block(tmp, b); |
212 last_use_idx++; | 212 last_use_idx++; |
213 } | 213 } |
214 | 214 |
215 // Insert just after last use | 215 // Insert just after last use |
216 b->_nodes.insert(last_use_idx+1,copy); | 216 b->_nodes.insert(last_use_idx+1,copy); |
284 // Check for mismatch inputs to Phi | 284 // Check for mismatch inputs to Phi |
285 for (uint j = 1; j < cnt; j++) { | 285 for (uint j = 1; j < cnt; j++) { |
286 Node *m = n->in(j); | 286 Node *m = n->in(j); |
287 uint src_name = _phc._lrg_map.find(m); | 287 uint src_name = _phc._lrg_map.find(m); |
288 if (src_name != phi_name) { | 288 if (src_name != phi_name) { |
289 Block *pred = _phc._cfg._bbs[b->pred(j)->_idx]; | 289 Block *pred = _phc._cfg.get_block_for_node(b->pred(j)); |
290 Node *copy; | 290 Node *copy; |
291 assert(!m->is_Con() || m->is_Mach(), "all Con must be Mach"); | 291 assert(!m->is_Con() || m->is_Mach(), "all Con must be Mach"); |
292 // Rematerialize constants instead of copying them | 292 // Rematerialize constants instead of copying them |
293 if( m->is_Mach() && m->as_Mach()->is_Con() && | 293 if( m->is_Mach() && m->as_Mach()->is_Con() && |
294 m->as_Mach()->rematerialize() ) { | 294 m->as_Mach()->rematerialize() ) { |
303 // Find a good place to insert. Kinda tricky, use a subroutine | 303 // Find a good place to insert. Kinda tricky, use a subroutine |
304 insert_copy_with_overlap(pred,copy,phi_name,src_name); | 304 insert_copy_with_overlap(pred,copy,phi_name,src_name); |
305 } | 305 } |
306 // Insert the copy in the use-def chain | 306 // Insert the copy in the use-def chain |
307 n->set_req(j, copy); | 307 n->set_req(j, copy); |
308 _phc._cfg._bbs.map( copy->_idx, pred ); | 308 _phc._cfg.map_node_to_block(copy, pred); |
309 // Extend ("register allocate") the names array for the copy. | 309 // Extend ("register allocate") the names array for the copy. |
310 _phc._lrg_map.extend(copy->_idx, phi_name); | 310 _phc._lrg_map.extend(copy->_idx, phi_name); |
311 } // End of if Phi names do not match | 311 } // End of if Phi names do not match |
312 } // End of for all inputs to Phi | 312 } // End of for all inputs to Phi |
313 } else { // End of if Phi | 313 } else { // End of if Phi |
341 } | 341 } |
342 // Insert the copy in the use-def chain | 342 // Insert the copy in the use-def chain |
343 n->set_req(idx, copy); | 343 n->set_req(idx, copy); |
344 // Extend ("register allocate") the names array for the copy. | 344 // Extend ("register allocate") the names array for the copy. |
345 _phc._lrg_map.extend(copy->_idx, name); | 345 _phc._lrg_map.extend(copy->_idx, name); |
346 _phc._cfg._bbs.map( copy->_idx, b ); | 346 _phc._cfg.map_node_to_block(copy, b); |
347 } | 347 } |
348 | 348 |
349 } // End of is two-adr | 349 } // End of is two-adr |
350 | 350 |
351 // Insert a copy at a debug use for a lrg which has high frequency | 351 // Insert a copy at a debug use for a lrg which has high frequency |
352 if (b->_freq < OPTO_DEBUG_SPLIT_FREQ || b->is_uncommon(_phc._cfg._bbs)) { | 352 if (b->_freq < OPTO_DEBUG_SPLIT_FREQ || b->is_uncommon(&_phc._cfg)) { |
353 // Walk the debug inputs to the node and check for lrg freq | 353 // Walk the debug inputs to the node and check for lrg freq |
354 JVMState* jvms = n->jvms(); | 354 JVMState* jvms = n->jvms(); |
355 uint debug_start = jvms ? jvms->debug_start() : 999999; | 355 uint debug_start = jvms ? jvms->debug_start() : 999999; |
356 uint debug_end = jvms ? jvms->debug_end() : 999999; | 356 uint debug_end = jvms ? jvms->debug_end() : 999999; |
357 for(uint inpidx = debug_start; inpidx < debug_end; inpidx++) { | 357 for(uint inpidx = debug_start; inpidx < debug_end; inpidx++) { |
389 b->_nodes.insert( l++, copy ); | 389 b->_nodes.insert( l++, copy ); |
390 // Extend ("register allocate") the names array for the copy. | 390 // Extend ("register allocate") the names array for the copy. |
391 uint max_lrg_id = _phc._lrg_map.max_lrg_id(); | 391 uint max_lrg_id = _phc._lrg_map.max_lrg_id(); |
392 _phc.new_lrg(copy, max_lrg_id); | 392 _phc.new_lrg(copy, max_lrg_id); |
393 _phc._lrg_map.set_max_lrg_id(max_lrg_id + 1); | 393 _phc._lrg_map.set_max_lrg_id(max_lrg_id + 1); |
394 _phc._cfg._bbs.map(copy->_idx, b); | 394 _phc._cfg.map_node_to_block(copy, b); |
395 //tty->print_cr("Split a debug use in Aggressive Coalesce"); | 395 //tty->print_cr("Split a debug use in Aggressive Coalesce"); |
396 } // End of if high frequency use/def | 396 } // End of if high frequency use/def |
397 } // End of for all debug inputs | 397 } // End of for all debug inputs |
398 } // End of if low frequency safepoint | 398 } // End of if low frequency safepoint |
399 | 399 |
435 uint i; | 435 uint i; |
436 for( i=0; i<b->_num_succs; i++ ) { | 436 for( i=0; i<b->_num_succs; i++ ) { |
437 Block *bs = b->_succs[i]; | 437 Block *bs = b->_succs[i]; |
438 // Find index of 'b' in 'bs' predecessors | 438 // Find index of 'b' in 'bs' predecessors |
439 uint j=1; | 439 uint j=1; |
440 while( _phc._cfg._bbs[bs->pred(j)->_idx] != b ) j++; | 440 while (_phc._cfg.get_block_for_node(bs->pred(j)) != b) { |
441 j++; | |
442 } | |
443 | |
441 // Visit all the Phis in successor block | 444 // Visit all the Phis in successor block |
442 for( uint k = 1; k<bs->_nodes.size(); k++ ) { | 445 for( uint k = 1; k<bs->_nodes.size(); k++ ) { |
443 Node *n = bs->_nodes[k]; | 446 Node *n = bs->_nodes[k]; |
444 if( !n->is_Phi() ) break; | 447 if( !n->is_Phi() ) break; |
445 combine_these_two( n, n->in(j) ); | 448 combine_these_two( n, n->in(j) ); |
508 b->_nodes.remove(bindex); | 511 b->_nodes.remove(bindex); |
509 if( bindex < b->_ihrp_index ) b->_ihrp_index--; | 512 if( bindex < b->_ihrp_index ) b->_ihrp_index--; |
510 if( bindex < b->_fhrp_index ) b->_fhrp_index--; | 513 if( bindex < b->_fhrp_index ) b->_fhrp_index--; |
511 | 514 |
512 // Stretched lr1; add it to liveness of intermediate blocks | 515 // Stretched lr1; add it to liveness of intermediate blocks |
513 Block *b2 = _phc._cfg._bbs[src_copy->_idx]; | 516 Block *b2 = _phc._cfg.get_block_for_node(src_copy); |
514 while( b != b2 ) { | 517 while( b != b2 ) { |
515 b = _phc._cfg._bbs[b->pred(1)->_idx]; | 518 b = _phc._cfg.get_block_for_node(b->pred(1)); |
516 _phc._live->live(b)->insert(lr1); | 519 _phc._live->live(b)->insert(lr1); |
517 } | 520 } |
518 } | 521 } |
519 | 522 |
520 //------------------------------compute_separating_interferences--------------- | 523 //------------------------------compute_separating_interferences--------------- |
530 while( 1 ) { | 533 while( 1 ) { |
531 // Find previous instruction | 534 // Find previous instruction |
532 bindex2--; // Chain backwards 1 instruction | 535 bindex2--; // Chain backwards 1 instruction |
533 while( bindex2 == 0 ) { // At block start, find prior block | 536 while( bindex2 == 0 ) { // At block start, find prior block |
534 assert( b2->num_preds() == 2, "cannot double coalesce across c-flow" ); | 537 assert( b2->num_preds() == 2, "cannot double coalesce across c-flow" ); |
535 b2 = _phc._cfg._bbs[b2->pred(1)->_idx]; | 538 b2 = _phc._cfg.get_block_for_node(b2->pred(1)); |
536 bindex2 = b2->end_idx()-1; | 539 bindex2 = b2->end_idx()-1; |
537 } | 540 } |
538 // Get prior instruction | 541 // Get prior instruction |
539 assert(bindex2 < b2->_nodes.size(), "index out of bounds"); | 542 assert(bindex2 < b2->_nodes.size(), "index out of bounds"); |
540 Node *x = b2->_nodes[bindex2]; | 543 Node *x = b2->_nodes[bindex2]; |
674 // Number of bits free | 677 // Number of bits free |
675 uint rm_size = rm.Size(); | 678 uint rm_size = rm.Size(); |
676 | 679 |
677 if (UseFPUForSpilling && rm.is_AllStack() ) { | 680 if (UseFPUForSpilling && rm.is_AllStack() ) { |
678 // Don't coalesce when frequency difference is large | 681 // Don't coalesce when frequency difference is large |
679 Block *dst_b = _phc._cfg._bbs[dst_copy->_idx]; | 682 Block *dst_b = _phc._cfg.get_block_for_node(dst_copy); |
680 Block *src_def_b = _phc._cfg._bbs[src_def->_idx]; | 683 Block *src_def_b = _phc._cfg.get_block_for_node(src_def); |
681 if (src_def_b->_freq > 10*dst_b->_freq ) | 684 if (src_def_b->_freq > 10*dst_b->_freq ) |
682 return false; | 685 return false; |
683 } | 686 } |
684 | 687 |
685 // If we can use any stack slot, then effective size is infinite | 688 // If we can use any stack slot, then effective size is infinite |
688 if( rm_size == 0 ) return false; | 691 if( rm_size == 0 ) return false; |
689 | 692 |
690 // Another early bail-out test is when we are double-coalescing and the | 693 // Another early bail-out test is when we are double-coalescing and the |
691 // 2 copies are separated by some control flow. | 694 // 2 copies are separated by some control flow. |
692 if( dst_copy != src_copy ) { | 695 if( dst_copy != src_copy ) { |
693 Block *src_b = _phc._cfg._bbs[src_copy->_idx]; | 696 Block *src_b = _phc._cfg.get_block_for_node(src_copy); |
694 Block *b2 = b; | 697 Block *b2 = b; |
695 while( b2 != src_b ) { | 698 while( b2 != src_b ) { |
696 if( b2->num_preds() > 2 ){// Found merge-point | 699 if( b2->num_preds() > 2 ){// Found merge-point |
697 _phc._lost_opp_cflow_coalesce++; | 700 _phc._lost_opp_cflow_coalesce++; |
698 // extra record_bias commented out because Chris believes it is not | 701 // extra record_bias commented out because Chris believes it is not |
699 // productive. Since we can record only 1 bias, we want to choose one | 702 // productive. Since we can record only 1 bias, we want to choose one |
700 // that stands a chance of working and this one probably does not. | 703 // that stands a chance of working and this one probably does not. |
701 //record_bias( _phc._lrgs, lr1, lr2 ); | 704 //record_bias( _phc._lrgs, lr1, lr2 ); |
702 return false; // To hard to find all interferences | 705 return false; // To hard to find all interferences |
703 } | 706 } |
704 b2 = _phc._cfg._bbs[b2->pred(1)->_idx]; | 707 b2 = _phc._cfg.get_block_for_node(b2->pred(1)); |
705 } | 708 } |
706 } | 709 } |
707 | 710 |
708 // Union the two interference sets together into '_ulr' | 711 // Union the two interference sets together into '_ulr' |
709 uint reg_degree = _ulr.lrg_union( lr1, lr2, rm_size, _phc._ifg, rm ); | 712 uint reg_degree = _ulr.lrg_union( lr1, lr2, rm_size, _phc._ifg, rm ); |
784 | 787 |
785 //------------------------------coalesce--------------------------------------- | 788 //------------------------------coalesce--------------------------------------- |
786 // Conservative (but pessimistic) copy coalescing of a single block | 789 // Conservative (but pessimistic) copy coalescing of a single block |
787 void PhaseConservativeCoalesce::coalesce( Block *b ) { | 790 void PhaseConservativeCoalesce::coalesce( Block *b ) { |
788 // Bail out on infrequent blocks | 791 // Bail out on infrequent blocks |
789 if( b->is_uncommon(_phc._cfg._bbs) ) | 792 if (b->is_uncommon(&_phc._cfg)) { |
790 return; | 793 return; |
794 } | |
791 // Check this block for copies. | 795 // Check this block for copies. |
792 for( uint i = 1; i<b->end_idx(); i++ ) { | 796 for( uint i = 1; i<b->end_idx(); i++ ) { |
793 // Check for actual copies on inputs. Coalesce a copy into its | 797 // Check for actual copies on inputs. Coalesce a copy into its |
794 // input if use and copy's input are compatible. | 798 // input if use and copy's input are compatible. |
795 Node *copy1 = b->_nodes[i]; | 799 Node *copy1 = b->_nodes[i]; |