Mercurial > hg > truffle
comparison src/share/vm/opto/block.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 | 650868c062a9 |
comparison
equal
deleted
inserted
replaced
12070:afbe18ae0905 | 12071:adb9a7d94cb5 |
---|---|
33 #include "opto/matcher.hpp" | 33 #include "opto/matcher.hpp" |
34 #include "opto/opcodes.hpp" | 34 #include "opto/opcodes.hpp" |
35 #include "opto/rootnode.hpp" | 35 #include "opto/rootnode.hpp" |
36 #include "utilities/copy.hpp" | 36 #include "utilities/copy.hpp" |
37 | 37 |
38 // Optimization - Graph Style | |
39 | |
40 | |
41 //----------------------------------------------------------------------------- | |
42 void Block_Array::grow( uint i ) { | 38 void Block_Array::grow( uint i ) { |
43 assert(i >= Max(), "must be an overflow"); | 39 assert(i >= Max(), "must be an overflow"); |
44 debug_only(_limit = i+1); | 40 debug_only(_limit = i+1); |
45 if( i < _size ) return; | 41 if( i < _size ) return; |
46 if( !_size ) { | 42 if( !_size ) { |
52 while( i >= _size ) _size <<= 1; // Double to fit | 48 while( i >= _size ) _size <<= 1; // Double to fit |
53 _blocks = (Block**)_arena->Arealloc( _blocks, old*sizeof(Block*),_size*sizeof(Block*)); | 49 _blocks = (Block**)_arena->Arealloc( _blocks, old*sizeof(Block*),_size*sizeof(Block*)); |
54 Copy::zero_to_bytes( &_blocks[old], (_size-old)*sizeof(Block*) ); | 50 Copy::zero_to_bytes( &_blocks[old], (_size-old)*sizeof(Block*) ); |
55 } | 51 } |
56 | 52 |
57 //============================================================================= | |
58 void Block_List::remove(uint i) { | 53 void Block_List::remove(uint i) { |
59 assert(i < _cnt, "index out of bounds"); | 54 assert(i < _cnt, "index out of bounds"); |
60 Copy::conjoint_words_to_lower((HeapWord*)&_blocks[i+1], (HeapWord*)&_blocks[i], ((_cnt-i-1)*sizeof(Block*))); | 55 Copy::conjoint_words_to_lower((HeapWord*)&_blocks[i+1], (HeapWord*)&_blocks[i], ((_cnt-i-1)*sizeof(Block*))); |
61 pop(); // shrink list by one block | 56 pop(); // shrink list by one block |
62 } | 57 } |
73 tty->print("B%d ", _blocks[i]->_pre_order); | 68 tty->print("B%d ", _blocks[i]->_pre_order); |
74 } | 69 } |
75 tty->print("size = %d\n", size()); | 70 tty->print("size = %d\n", size()); |
76 } | 71 } |
77 #endif | 72 #endif |
78 | |
79 //============================================================================= | |
80 | 73 |
81 uint Block::code_alignment() { | 74 uint Block::code_alignment() { |
82 // Check for Root block | 75 // Check for Root block |
83 if (_pre_order == 0) return CodeEntryAlignment; | 76 if (_pre_order == 0) return CodeEntryAlignment; |
84 // Check for Start block | 77 // Check for Start block |
111 } | 104 } |
112 | 105 |
113 return unit_sz; // no particular alignment | 106 return unit_sz; // no particular alignment |
114 } | 107 } |
115 | 108 |
116 //----------------------------------------------------------------------------- | |
117 // Compute the size of first 'inst_cnt' instructions in this block. | 109 // Compute the size of first 'inst_cnt' instructions in this block. |
118 // Return the number of instructions left to compute if the block has | 110 // Return the number of instructions left to compute if the block has |
119 // less then 'inst_cnt' instructions. Stop, and return 0 if sum_size | 111 // less then 'inst_cnt' instructions. Stop, and return 0 if sum_size |
120 // exceeds OptoLoopAlignment. | 112 // exceeds OptoLoopAlignment. |
121 uint Block::compute_first_inst_size(uint& sum_size, uint inst_cnt, | 113 uint Block::compute_first_inst_size(uint& sum_size, uint inst_cnt, |
136 } | 128 } |
137 } | 129 } |
138 return inst_cnt; | 130 return inst_cnt; |
139 } | 131 } |
140 | 132 |
141 //----------------------------------------------------------------------------- | |
142 uint Block::find_node( const Node *n ) const { | 133 uint Block::find_node( const Node *n ) const { |
143 for( uint i = 0; i < _nodes.size(); i++ ) { | 134 for( uint i = 0; i < _nodes.size(); i++ ) { |
144 if( _nodes[i] == n ) | 135 if( _nodes[i] == n ) |
145 return i; | 136 return i; |
146 } | 137 } |
151 // Find and remove n from block list | 142 // Find and remove n from block list |
152 void Block::find_remove( const Node *n ) { | 143 void Block::find_remove( const Node *n ) { |
153 _nodes.remove(find_node(n)); | 144 _nodes.remove(find_node(n)); |
154 } | 145 } |
155 | 146 |
156 //------------------------------is_Empty--------------------------------------- | |
157 // Return empty status of a block. Empty blocks contain only the head, other | 147 // Return empty status of a block. Empty blocks contain only the head, other |
158 // ideal nodes, and an optional trailing goto. | 148 // ideal nodes, and an optional trailing goto. |
159 int Block::is_Empty() const { | 149 int Block::is_Empty() const { |
160 | 150 |
161 // Root or start block is not considered empty | 151 // Root or start block is not considered empty |
190 } | 180 } |
191 | 181 |
192 return not_empty; | 182 return not_empty; |
193 } | 183 } |
194 | 184 |
195 //------------------------------has_uncommon_code------------------------------ | |
196 // Return true if the block's code implies that it is likely to be | 185 // Return true if the block's code implies that it is likely to be |
197 // executed infrequently. Check to see if the block ends in a Halt or | 186 // executed infrequently. Check to see if the block ends in a Halt or |
198 // a low probability call. | 187 // a low probability call. |
199 bool Block::has_uncommon_code() const { | 188 bool Block::has_uncommon_code() const { |
200 Node* en = end(); | 189 Node* en = end(); |
216 | 205 |
217 int op = en->is_Mach() ? en->as_Mach()->ideal_Opcode() : en->Opcode(); | 206 int op = en->is_Mach() ? en->as_Mach()->ideal_Opcode() : en->Opcode(); |
218 return op == Op_Halt; | 207 return op == Op_Halt; |
219 } | 208 } |
220 | 209 |
221 //------------------------------is_uncommon------------------------------------ | |
222 // True if block is low enough frequency or guarded by a test which | 210 // True if block is low enough frequency or guarded by a test which |
223 // mostly does not go here. | 211 // mostly does not go here. |
224 bool Block::is_uncommon(PhaseCFG* cfg) const { | 212 bool Block::is_uncommon(PhaseCFG* cfg) const { |
225 // Initial blocks must never be moved, so are never uncommon. | 213 // Initial blocks must never be moved, so are never uncommon. |
226 if (head()->is_Root() || head()->is_Start()) return false; | 214 if (head()->is_Root() || head()->is_Start()) return false; |
269 return true; | 257 return true; |
270 } | 258 } |
271 return false; | 259 return false; |
272 } | 260 } |
273 | 261 |
274 //------------------------------dump------------------------------------------- | |
275 #ifndef PRODUCT | 262 #ifndef PRODUCT |
276 void Block::dump_bidx(const Block* orig, outputStream* st) const { | 263 void Block::dump_bidx(const Block* orig, outputStream* st) const { |
277 if (_pre_order) st->print("B%d",_pre_order); | 264 if (_pre_order) st->print("B%d",_pre_order); |
278 else st->print("N%d", head()->_idx); | 265 else st->print("N%d", head()->_idx); |
279 | 266 |
362 } | 349 } |
363 tty->print("\n"); | 350 tty->print("\n"); |
364 } | 351 } |
365 #endif | 352 #endif |
366 | 353 |
367 //============================================================================= | |
368 //------------------------------PhaseCFG--------------------------------------- | |
369 PhaseCFG::PhaseCFG(Arena* arena, RootNode* root, Matcher& matcher) | 354 PhaseCFG::PhaseCFG(Arena* arena, RootNode* root, Matcher& matcher) |
370 : Phase(CFG) | 355 : Phase(CFG) |
371 , _block_arena(arena) | 356 , _block_arena(arena) |
357 , _root(root) | |
358 , _matcher(matcher) | |
372 , _node_to_block_mapping(arena) | 359 , _node_to_block_mapping(arena) |
373 , _root(root) | |
374 , _node_latency(NULL) | 360 , _node_latency(NULL) |
375 #ifndef PRODUCT | 361 #ifndef PRODUCT |
376 , _trace_opto_pipelining(TraceOptoPipelining || C->method_has_option("TraceOptoPipelining")) | 362 , _trace_opto_pipelining(TraceOptoPipelining || C->method_has_option("TraceOptoPipelining")) |
377 #endif | 363 #endif |
378 #ifdef ASSERT | 364 #ifdef ASSERT |
388 _goto = matcher.match_tree(x); | 374 _goto = matcher.match_tree(x); |
389 assert(_goto != NULL, ""); | 375 assert(_goto != NULL, ""); |
390 _goto->set_req(0,_goto); | 376 _goto->set_req(0,_goto); |
391 | 377 |
392 // Build the CFG in Reverse Post Order | 378 // Build the CFG in Reverse Post Order |
393 _num_blocks = build_cfg(); | 379 _number_of_blocks = build_cfg(); |
394 _broot = get_block_for_node(_root); | 380 _root_block = get_block_for_node(_root); |
395 } | 381 } |
396 | 382 |
397 //------------------------------build_cfg-------------------------------------- | |
398 // Build a proper looking CFG. Make every block begin with either a StartNode | 383 // Build a proper looking CFG. Make every block begin with either a StartNode |
399 // or a RegionNode. Make every block end with either a Goto, If or Return. | 384 // or a RegionNode. Make every block end with either a Goto, If or Return. |
400 // The RootNode both starts and ends it's own block. Do this with a recursive | 385 // The RootNode both starts and ends it's own block. Do this with a recursive |
401 // backwards walk over the control edges. | 386 // backwards walk over the control edges. |
402 uint PhaseCFG::build_cfg() { | 387 uint PhaseCFG::build_cfg() { |
494 } | 479 } |
495 // Return number of basic blocks for all children and self | 480 // Return number of basic blocks for all children and self |
496 return sum; | 481 return sum; |
497 } | 482 } |
498 | 483 |
499 //------------------------------insert_goto_at--------------------------------- | |
500 // Inserts a goto & corresponding basic block between | 484 // Inserts a goto & corresponding basic block between |
501 // block[block_no] and its succ_no'th successor block | 485 // block[block_no] and its succ_no'th successor block |
502 void PhaseCFG::insert_goto_at(uint block_no, uint succ_no) { | 486 void PhaseCFG::insert_goto_at(uint block_no, uint succ_no) { |
503 // get block with block_no | 487 // get block with block_no |
504 assert(block_no < _num_blocks, "illegal block number"); | 488 assert(block_no < number_of_blocks(), "illegal block number"); |
505 Block* in = _blocks[block_no]; | 489 Block* in = get_block(block_no); |
506 // get successor block succ_no | 490 // get successor block succ_no |
507 assert(succ_no < in->_num_succs, "illegal successor number"); | 491 assert(succ_no < in->_num_succs, "illegal successor number"); |
508 Block* out = in->_succs[succ_no]; | 492 Block* out = in->_succs[succ_no]; |
509 // Compute frequency of the new block. Do this before inserting | 493 // Compute frequency of the new block. Do this before inserting |
510 // new block in case succ_prob() needs to infer the probability from | 494 // new block in case succ_prob() needs to infer the probability from |
535 // remap predecessor's successor to new block | 519 // remap predecessor's successor to new block |
536 in->_succs.map(succ_no, block); | 520 in->_succs.map(succ_no, block); |
537 // Set the frequency of the new block | 521 // Set the frequency of the new block |
538 block->_freq = freq; | 522 block->_freq = freq; |
539 // add new basic block to basic block list | 523 // add new basic block to basic block list |
540 _blocks.insert(block_no + 1, block); | 524 add_block_at(block_no + 1, block); |
541 _num_blocks++; | 525 } |
542 } | 526 |
543 | |
544 //------------------------------no_flip_branch--------------------------------- | |
545 // Does this block end in a multiway branch that cannot have the default case | 527 // Does this block end in a multiway branch that cannot have the default case |
546 // flipped for another case? | 528 // flipped for another case? |
547 static bool no_flip_branch( Block *b ) { | 529 static bool no_flip_branch( Block *b ) { |
548 int branch_idx = b->_nodes.size() - b->_num_succs-1; | 530 int branch_idx = b->_nodes.size() - b->_num_succs-1; |
549 if( branch_idx < 1 ) return false; | 531 if( branch_idx < 1 ) return false; |
558 return true; | 540 return true; |
559 } | 541 } |
560 return false; | 542 return false; |
561 } | 543 } |
562 | 544 |
563 //------------------------------convert_NeverBranch_to_Goto-------------------- | |
564 // Check for NeverBranch at block end. This needs to become a GOTO to the | 545 // Check for NeverBranch at block end. This needs to become a GOTO to the |
565 // true target. NeverBranch are treated as a conditional branch that always | 546 // true target. NeverBranch are treated as a conditional branch that always |
566 // goes the same direction for most of the optimizer and are used to give a | 547 // goes the same direction for most of the optimizer and are used to give a |
567 // fake exit path to infinite loops. At this late stage they need to turn | 548 // fake exit path to infinite loops. At this late stage they need to turn |
568 // into Goto's so that when you enter the infinite loop you indeed hang. | 549 // into Goto's so that when you enter the infinite loop you indeed hang. |
596 dead->head()->del_req(j); | 577 dead->head()->del_req(j); |
597 for( int k = 1; dead->_nodes[k]->is_Phi(); k++ ) | 578 for( int k = 1; dead->_nodes[k]->is_Phi(); k++ ) |
598 dead->_nodes[k]->del_req(j); | 579 dead->_nodes[k]->del_req(j); |
599 } | 580 } |
600 | 581 |
601 //------------------------------move_to_next----------------------------------- | |
602 // Helper function to move block bx to the slot following b_index. Return | 582 // Helper function to move block bx to the slot following b_index. Return |
603 // true if the move is successful, otherwise false | 583 // true if the move is successful, otherwise false |
604 bool PhaseCFG::move_to_next(Block* bx, uint b_index) { | 584 bool PhaseCFG::move_to_next(Block* bx, uint b_index) { |
605 if (bx == NULL) return false; | 585 if (bx == NULL) return false; |
606 | 586 |
607 // Return false if bx is already scheduled. | 587 // Return false if bx is already scheduled. |
608 uint bx_index = bx->_pre_order; | 588 uint bx_index = bx->_pre_order; |
609 if ((bx_index <= b_index) && (_blocks[bx_index] == bx)) { | 589 if ((bx_index <= b_index) && (get_block(bx_index) == bx)) { |
610 return false; | 590 return false; |
611 } | 591 } |
612 | 592 |
613 // Find the current index of block bx on the block list | 593 // Find the current index of block bx on the block list |
614 bx_index = b_index + 1; | 594 bx_index = b_index + 1; |
615 while( bx_index < _num_blocks && _blocks[bx_index] != bx ) bx_index++; | 595 while (bx_index < number_of_blocks() && get_block(bx_index) != bx) { |
616 assert(_blocks[bx_index] == bx, "block not found"); | 596 bx_index++; |
597 } | |
598 assert(get_block(bx_index) == bx, "block not found"); | |
617 | 599 |
618 // If the previous block conditionally falls into bx, return false, | 600 // If the previous block conditionally falls into bx, return false, |
619 // because moving bx will create an extra jump. | 601 // because moving bx will create an extra jump. |
620 for(uint k = 1; k < bx->num_preds(); k++ ) { | 602 for(uint k = 1; k < bx->num_preds(); k++ ) { |
621 Block* pred = get_block_for_node(bx->pred(k)); | 603 Block* pred = get_block_for_node(bx->pred(k)); |
622 if (pred == _blocks[bx_index-1]) { | 604 if (pred == get_block(bx_index - 1)) { |
623 if (pred->_num_succs != 1) { | 605 if (pred->_num_succs != 1) { |
624 return false; | 606 return false; |
625 } | 607 } |
626 } | 608 } |
627 } | 609 } |
630 _blocks.remove(bx_index); | 612 _blocks.remove(bx_index); |
631 _blocks.insert(b_index + 1, bx); | 613 _blocks.insert(b_index + 1, bx); |
632 return true; | 614 return true; |
633 } | 615 } |
634 | 616 |
635 //------------------------------move_to_end------------------------------------ | |
636 // Move empty and uncommon blocks to the end. | 617 // Move empty and uncommon blocks to the end. |
637 void PhaseCFG::move_to_end(Block *b, uint i) { | 618 void PhaseCFG::move_to_end(Block *b, uint i) { |
638 int e = b->is_Empty(); | 619 int e = b->is_Empty(); |
639 if (e != Block::not_empty) { | 620 if (e != Block::not_empty) { |
640 if (e == Block::empty_with_goto) { | 621 if (e == Block::empty_with_goto) { |
648 // Move the empty block to the end, and don't recheck. | 629 // Move the empty block to the end, and don't recheck. |
649 _blocks.remove(i); | 630 _blocks.remove(i); |
650 _blocks.push(b); | 631 _blocks.push(b); |
651 } | 632 } |
652 | 633 |
653 //---------------------------set_loop_alignment-------------------------------- | |
654 // Set loop alignment for every block | 634 // Set loop alignment for every block |
655 void PhaseCFG::set_loop_alignment() { | 635 void PhaseCFG::set_loop_alignment() { |
656 uint last = _num_blocks; | 636 uint last = number_of_blocks(); |
657 assert( _blocks[0] == _broot, "" ); | 637 assert(get_block(0) == get_root_block(), ""); |
658 | 638 |
659 for (uint i = 1; i < last; i++ ) { | 639 for (uint i = 1; i < last; i++) { |
660 Block *b = _blocks[i]; | 640 Block* block = get_block(i); |
661 if (b->head()->is_Loop()) { | 641 if (block->head()->is_Loop()) { |
662 b->set_loop_alignment(b); | 642 block->set_loop_alignment(block); |
663 } | 643 } |
664 } | 644 } |
665 } | 645 } |
666 | 646 |
667 //-----------------------------remove_empty------------------------------------ | |
668 // Make empty basic blocks to be "connector" blocks, Move uncommon blocks | 647 // Make empty basic blocks to be "connector" blocks, Move uncommon blocks |
669 // to the end. | 648 // to the end. |
670 void PhaseCFG::remove_empty() { | 649 void PhaseCFG::remove_empty_blocks() { |
671 // Move uncommon blocks to the end | 650 // Move uncommon blocks to the end |
672 uint last = _num_blocks; | 651 uint last = number_of_blocks(); |
673 assert( _blocks[0] == _broot, "" ); | 652 assert(get_block(0) == get_root_block(), ""); |
674 | 653 |
675 for (uint i = 1; i < last; i++) { | 654 for (uint i = 1; i < last; i++) { |
676 Block *b = _blocks[i]; | 655 Block* block = get_block(i); |
677 if (b->is_connector()) break; | 656 if (block->is_connector()) { |
657 break; | |
658 } | |
678 | 659 |
679 // Check for NeverBranch at block end. This needs to become a GOTO to the | 660 // Check for NeverBranch at block end. This needs to become a GOTO to the |
680 // true target. NeverBranch are treated as a conditional branch that | 661 // true target. NeverBranch are treated as a conditional branch that |
681 // always goes the same direction for most of the optimizer and are used | 662 // always goes the same direction for most of the optimizer and are used |
682 // to give a fake exit path to infinite loops. At this late stage they | 663 // to give a fake exit path to infinite loops. At this late stage they |
683 // need to turn into Goto's so that when you enter the infinite loop you | 664 // need to turn into Goto's so that when you enter the infinite loop you |
684 // indeed hang. | 665 // indeed hang. |
685 if( b->_nodes[b->end_idx()]->Opcode() == Op_NeverBranch ) | 666 if (block->_nodes[block->end_idx()]->Opcode() == Op_NeverBranch) { |
686 convert_NeverBranch_to_Goto(b); | 667 convert_NeverBranch_to_Goto(block); |
668 } | |
687 | 669 |
688 // Look for uncommon blocks and move to end. | 670 // Look for uncommon blocks and move to end. |
689 if (!C->do_freq_based_layout()) { | 671 if (!C->do_freq_based_layout()) { |
690 if (b->is_uncommon(this)) { | 672 if (block->is_uncommon(this)) { |
691 move_to_end(b, i); | 673 move_to_end(block, i); |
692 last--; // No longer check for being uncommon! | 674 last--; // No longer check for being uncommon! |
693 if( no_flip_branch(b) ) { // Fall-thru case must follow? | 675 if (no_flip_branch(block)) { // Fall-thru case must follow? |
694 b = _blocks[i]; // Find the fall-thru block | 676 // Find the fall-thru block |
695 move_to_end(b, i); | 677 block = get_block(i); |
678 move_to_end(block, i); | |
696 last--; | 679 last--; |
697 } | 680 } |
698 i--; // backup block counter post-increment | 681 // backup block counter post-increment |
682 i--; | |
699 } | 683 } |
700 } | 684 } |
701 } | 685 } |
702 | 686 |
703 // Move empty blocks to the end | 687 // Move empty blocks to the end |
704 last = _num_blocks; | 688 last = number_of_blocks(); |
705 for (uint i = 1; i < last; i++) { | 689 for (uint i = 1; i < last; i++) { |
706 Block *b = _blocks[i]; | 690 Block* block = get_block(i); |
707 if (b->is_Empty() != Block::not_empty) { | 691 if (block->is_Empty() != Block::not_empty) { |
708 move_to_end(b, i); | 692 move_to_end(block, i); |
709 last--; | 693 last--; |
710 i--; | 694 i--; |
711 } | 695 } |
712 } // End of for all blocks | 696 } // End of for all blocks |
713 } | 697 } |
714 | 698 |
715 //-----------------------------fixup_flow-------------------------------------- | |
716 // Fix up the final control flow for basic blocks. | 699 // Fix up the final control flow for basic blocks. |
717 void PhaseCFG::fixup_flow() { | 700 void PhaseCFG::fixup_flow() { |
718 // Fixup final control flow for the blocks. Remove jump-to-next | 701 // Fixup final control flow for the blocks. Remove jump-to-next |
719 // block. If neither arm of a IF follows the conditional branch, we | 702 // block. If neither arm of a IF follows the conditional branch, we |
720 // have to add a second jump after the conditional. We place the | 703 // have to add a second jump after the conditional. We place the |
721 // TRUE branch target in succs[0] for both GOTOs and IFs. | 704 // TRUE branch target in succs[0] for both GOTOs and IFs. |
722 for (uint i=0; i < _num_blocks; i++) { | 705 for (uint i = 0; i < number_of_blocks(); i++) { |
723 Block *b = _blocks[i]; | 706 Block* block = get_block(i); |
724 b->_pre_order = i; // turn pre-order into block-index | 707 block->_pre_order = i; // turn pre-order into block-index |
725 | 708 |
726 // Connector blocks need no further processing. | 709 // Connector blocks need no further processing. |
727 if (b->is_connector()) { | 710 if (block->is_connector()) { |
728 assert((i+1) == _num_blocks || _blocks[i+1]->is_connector(), | 711 assert((i+1) == number_of_blocks() || get_block(i + 1)->is_connector(), "All connector blocks should sink to the end"); |
729 "All connector blocks should sink to the end"); | |
730 continue; | 712 continue; |
731 } | 713 } |
732 assert(b->is_Empty() != Block::completely_empty, | 714 assert(block->is_Empty() != Block::completely_empty, "Empty blocks should be connectors"); |
733 "Empty blocks should be connectors"); | 715 |
734 | 716 Block* bnext = (i < number_of_blocks() - 1) ? get_block(i + 1) : NULL; |
735 Block *bnext = (i < _num_blocks-1) ? _blocks[i+1] : NULL; | 717 Block* bs0 = block->non_connector_successor(0); |
736 Block *bs0 = b->non_connector_successor(0); | |
737 | 718 |
738 // Check for multi-way branches where I cannot negate the test to | 719 // Check for multi-way branches where I cannot negate the test to |
739 // exchange the true and false targets. | 720 // exchange the true and false targets. |
740 if( no_flip_branch( b ) ) { | 721 if (no_flip_branch(block)) { |
741 // Find fall through case - if must fall into its target | 722 // Find fall through case - if must fall into its target |
742 int branch_idx = b->_nodes.size() - b->_num_succs; | 723 int branch_idx = block->_nodes.size() - block->_num_succs; |
743 for (uint j2 = 0; j2 < b->_num_succs; j2++) { | 724 for (uint j2 = 0; j2 < block->_num_succs; j2++) { |
744 const ProjNode* p = b->_nodes[branch_idx + j2]->as_Proj(); | 725 const ProjNode* p = block->_nodes[branch_idx + j2]->as_Proj(); |
745 if (p->_con == 0) { | 726 if (p->_con == 0) { |
746 // successor j2 is fall through case | 727 // successor j2 is fall through case |
747 if (b->non_connector_successor(j2) != bnext) { | 728 if (block->non_connector_successor(j2) != bnext) { |
748 // but it is not the next block => insert a goto | 729 // but it is not the next block => insert a goto |
749 insert_goto_at(i, j2); | 730 insert_goto_at(i, j2); |
750 } | 731 } |
751 // Put taken branch in slot 0 | 732 // Put taken branch in slot 0 |
752 if( j2 == 0 && b->_num_succs == 2) { | 733 if (j2 == 0 && block->_num_succs == 2) { |
753 // Flip targets in succs map | 734 // Flip targets in succs map |
754 Block *tbs0 = b->_succs[0]; | 735 Block *tbs0 = block->_succs[0]; |
755 Block *tbs1 = b->_succs[1]; | 736 Block *tbs1 = block->_succs[1]; |
756 b->_succs.map( 0, tbs1 ); | 737 block->_succs.map(0, tbs1); |
757 b->_succs.map( 1, tbs0 ); | 738 block->_succs.map(1, tbs0); |
758 } | 739 } |
759 break; | 740 break; |
760 } | 741 } |
761 } | 742 } |
743 | |
762 // Remove all CatchProjs | 744 // Remove all CatchProjs |
763 for (uint j1 = 0; j1 < b->_num_succs; j1++) b->_nodes.pop(); | 745 for (uint j = 0; j < block->_num_succs; j++) { |
764 | 746 block->_nodes.pop(); |
765 } else if (b->_num_succs == 1) { | 747 } |
748 | |
749 } else if (block->_num_succs == 1) { | |
766 // Block ends in a Goto? | 750 // Block ends in a Goto? |
767 if (bnext == bs0) { | 751 if (bnext == bs0) { |
768 // We fall into next block; remove the Goto | 752 // We fall into next block; remove the Goto |
769 b->_nodes.pop(); | 753 block->_nodes.pop(); |
770 } | 754 } |
771 | 755 |
772 } else if( b->_num_succs == 2 ) { // Block ends in a If? | 756 } else if(block->_num_succs == 2) { // Block ends in a If? |
773 // Get opcode of 1st projection (matches _succs[0]) | 757 // Get opcode of 1st projection (matches _succs[0]) |
774 // Note: Since this basic block has 2 exits, the last 2 nodes must | 758 // Note: Since this basic block has 2 exits, the last 2 nodes must |
775 // be projections (in any order), the 3rd last node must be | 759 // be projections (in any order), the 3rd last node must be |
776 // the IfNode (we have excluded other 2-way exits such as | 760 // the IfNode (we have excluded other 2-way exits such as |
777 // CatchNodes already). | 761 // CatchNodes already). |
778 MachNode *iff = b->_nodes[b->_nodes.size()-3]->as_Mach(); | 762 MachNode* iff = block->_nodes[block->_nodes.size() - 3]->as_Mach(); |
779 ProjNode *proj0 = b->_nodes[b->_nodes.size()-2]->as_Proj(); | 763 ProjNode* proj0 = block->_nodes[block->_nodes.size() - 2]->as_Proj(); |
780 ProjNode *proj1 = b->_nodes[b->_nodes.size()-1]->as_Proj(); | 764 ProjNode* proj1 = block->_nodes[block->_nodes.size() - 1]->as_Proj(); |
781 | 765 |
782 // Assert that proj0 and succs[0] match up. Similarly for proj1 and succs[1]. | 766 // Assert that proj0 and succs[0] match up. Similarly for proj1 and succs[1]. |
783 assert(proj0->raw_out(0) == b->_succs[0]->head(), "Mismatch successor 0"); | 767 assert(proj0->raw_out(0) == block->_succs[0]->head(), "Mismatch successor 0"); |
784 assert(proj1->raw_out(0) == b->_succs[1]->head(), "Mismatch successor 1"); | 768 assert(proj1->raw_out(0) == block->_succs[1]->head(), "Mismatch successor 1"); |
785 | 769 |
786 Block *bs1 = b->non_connector_successor(1); | 770 Block* bs1 = block->non_connector_successor(1); |
787 | 771 |
788 // Check for neither successor block following the current | 772 // Check for neither successor block following the current |
789 // block ending in a conditional. If so, move one of the | 773 // block ending in a conditional. If so, move one of the |
790 // successors after the current one, provided that the | 774 // successors after the current one, provided that the |
791 // successor was previously unscheduled, but moveable | 775 // successor was previously unscheduled, but moveable |
792 // (i.e., all paths to it involve a branch). | 776 // (i.e., all paths to it involve a branch). |
793 if( !C->do_freq_based_layout() && bnext != bs0 && bnext != bs1 ) { | 777 if (!C->do_freq_based_layout() && bnext != bs0 && bnext != bs1) { |
794 // Choose the more common successor based on the probability | 778 // Choose the more common successor based on the probability |
795 // of the conditional branch. | 779 // of the conditional branch. |
796 Block *bx = bs0; | 780 Block* bx = bs0; |
797 Block *by = bs1; | 781 Block* by = bs1; |
798 | 782 |
799 // _prob is the probability of taking the true path. Make | 783 // _prob is the probability of taking the true path. Make |
800 // p the probability of taking successor #1. | 784 // p the probability of taking successor #1. |
801 float p = iff->as_MachIf()->_prob; | 785 float p = iff->as_MachIf()->_prob; |
802 if( proj0->Opcode() == Op_IfTrue ) { | 786 if (proj0->Opcode() == Op_IfTrue) { |
803 p = 1.0 - p; | 787 p = 1.0 - p; |
804 } | 788 } |
805 | 789 |
806 // Prefer successor #1 if p > 0.5 | 790 // Prefer successor #1 if p > 0.5 |
807 if (p > PROB_FAIR) { | 791 if (p > PROB_FAIR) { |
824 // Check for the next block being in succs[0]. We are going to branch | 808 // Check for the next block being in succs[0]. We are going to branch |
825 // to succs[0], so we want the fall-thru case as the next block in | 809 // to succs[0], so we want the fall-thru case as the next block in |
826 // succs[1]. | 810 // succs[1]. |
827 if (bnext == bs0) { | 811 if (bnext == bs0) { |
828 // Fall-thru case in succs[0], so flip targets in succs map | 812 // Fall-thru case in succs[0], so flip targets in succs map |
829 Block *tbs0 = b->_succs[0]; | 813 Block* tbs0 = block->_succs[0]; |
830 Block *tbs1 = b->_succs[1]; | 814 Block* tbs1 = block->_succs[1]; |
831 b->_succs.map( 0, tbs1 ); | 815 block->_succs.map(0, tbs1); |
832 b->_succs.map( 1, tbs0 ); | 816 block->_succs.map(1, tbs0); |
833 // Flip projection for each target | 817 // Flip projection for each target |
834 { ProjNode *tmp = proj0; proj0 = proj1; proj1 = tmp; } | 818 ProjNode* tmp = proj0; |
835 | 819 proj0 = proj1; |
836 } else if( bnext != bs1 ) { | 820 proj1 = tmp; |
821 | |
822 } else if(bnext != bs1) { | |
837 // Need a double-branch | 823 // Need a double-branch |
838 // The existing conditional branch need not change. | 824 // The existing conditional branch need not change. |
839 // Add a unconditional branch to the false target. | 825 // Add a unconditional branch to the false target. |
840 // Alas, it must appear in its own block and adding a | 826 // Alas, it must appear in its own block and adding a |
841 // block this late in the game is complicated. Sigh. | 827 // block this late in the game is complicated. Sigh. |
842 insert_goto_at(i, 1); | 828 insert_goto_at(i, 1); |
843 } | 829 } |
844 | 830 |
845 // Make sure we TRUE branch to the target | 831 // Make sure we TRUE branch to the target |
846 if( proj0->Opcode() == Op_IfFalse ) { | 832 if (proj0->Opcode() == Op_IfFalse) { |
847 iff->as_MachIf()->negate(); | 833 iff->as_MachIf()->negate(); |
848 } | 834 } |
849 | 835 |
850 b->_nodes.pop(); // Remove IfFalse & IfTrue projections | 836 block->_nodes.pop(); // Remove IfFalse & IfTrue projections |
851 b->_nodes.pop(); | 837 block->_nodes.pop(); |
852 | 838 |
853 } else { | 839 } else { |
854 // Multi-exit block, e.g. a switch statement | 840 // Multi-exit block, e.g. a switch statement |
855 // But we don't need to do anything here | 841 // But we don't need to do anything here |
856 } | 842 } |
857 } // End of for all blocks | 843 } // End of for all blocks |
858 } | 844 } |
859 | 845 |
860 | 846 |
861 //------------------------------dump------------------------------------------- | |
862 #ifndef PRODUCT | 847 #ifndef PRODUCT |
863 void PhaseCFG::_dump_cfg( const Node *end, VectorSet &visited ) const { | 848 void PhaseCFG::_dump_cfg( const Node *end, VectorSet &visited ) const { |
864 const Node *x = end->is_block_proj(); | 849 const Node *x = end->is_block_proj(); |
865 assert( x, "not a CFG" ); | 850 assert( x, "not a CFG" ); |
866 | 851 |
882 // Dump the block | 867 // Dump the block |
883 get_block_for_node(p)->dump(this); | 868 get_block_for_node(p)->dump(this); |
884 } | 869 } |
885 | 870 |
886 void PhaseCFG::dump( ) const { | 871 void PhaseCFG::dump( ) const { |
887 tty->print("\n--- CFG --- %d BBs\n",_num_blocks); | 872 tty->print("\n--- CFG --- %d BBs\n", number_of_blocks()); |
888 if (_blocks.size()) { // Did we do basic-block layout? | 873 if (_blocks.size()) { // Did we do basic-block layout? |
889 for (uint i = 0; i < _num_blocks; i++) { | 874 for (uint i = 0; i < number_of_blocks(); i++) { |
890 _blocks[i]->dump(this); | 875 const Block* block = get_block(i); |
876 block->dump(this); | |
891 } | 877 } |
892 } else { // Else do it with a DFS | 878 } else { // Else do it with a DFS |
893 VectorSet visited(_block_arena); | 879 VectorSet visited(_block_arena); |
894 _dump_cfg(_root,visited); | 880 _dump_cfg(_root,visited); |
895 } | 881 } |
896 } | 882 } |
897 | 883 |
898 void PhaseCFG::dump_headers() { | 884 void PhaseCFG::dump_headers() { |
899 for( uint i = 0; i < _num_blocks; i++ ) { | 885 for (uint i = 0; i < number_of_blocks(); i++) { |
900 if (_blocks[i]) { | 886 Block* block = get_block(i); |
901 _blocks[i]->dump_head(this); | 887 if (block != NULL) { |
902 } | 888 block->dump_head(this); |
903 } | 889 } |
904 } | 890 } |
905 | 891 } |
906 void PhaseCFG::verify( ) const { | 892 |
893 void PhaseCFG::verify() const { | |
907 #ifdef ASSERT | 894 #ifdef ASSERT |
908 // Verify sane CFG | 895 // Verify sane CFG |
909 for (uint i = 0; i < _num_blocks; i++) { | 896 for (uint i = 0; i < number_of_blocks(); i++) { |
910 Block *b = _blocks[i]; | 897 Block* block = get_block(i); |
911 uint cnt = b->_nodes.size(); | 898 uint cnt = block->_nodes.size(); |
912 uint j; | 899 uint j; |
913 for (j = 0; j < cnt; j++) { | 900 for (j = 0; j < cnt; j++) { |
914 Node *n = b->_nodes[j]; | 901 Node *n = block->_nodes[j]; |
915 assert(get_block_for_node(n) == b, ""); | 902 assert(get_block_for_node(n) == block, ""); |
916 if (j >= 1 && n->is_Mach() && | 903 if (j >= 1 && n->is_Mach() && n->as_Mach()->ideal_Opcode() == Op_CreateEx) { |
917 n->as_Mach()->ideal_Opcode() == Op_CreateEx) { | 904 assert(j == 1 || block->_nodes[j-1]->is_Phi(), "CreateEx must be first instruction in block"); |
918 assert(j == 1 || b->_nodes[j-1]->is_Phi(), | |
919 "CreateEx must be first instruction in block"); | |
920 } | 905 } |
921 for (uint k = 0; k < n->req(); k++) { | 906 for (uint k = 0; k < n->req(); k++) { |
922 Node *def = n->in(k); | 907 Node *def = n->in(k); |
923 if (def && def != n) { | 908 if (def && def != n) { |
924 assert(get_block_for_node(def) || def->is_Con(), "must have block; constants for debug info ok"); | 909 assert(get_block_for_node(def) || def->is_Con(), "must have block; constants for debug info ok"); |
925 // Verify that instructions in the block is in correct order. | 910 // Verify that instructions in the block is in correct order. |
926 // Uses must follow their definition if they are at the same block. | 911 // Uses must follow their definition if they are at the same block. |
927 // Mostly done to check that MachSpillCopy nodes are placed correctly | 912 // Mostly done to check that MachSpillCopy nodes are placed correctly |
928 // when CreateEx node is moved in build_ifg_physical(). | 913 // when CreateEx node is moved in build_ifg_physical(). |
929 if (get_block_for_node(def) == b && | 914 if (get_block_for_node(def) == block && !(block->head()->is_Loop() && n->is_Phi()) && |
930 !(b->head()->is_Loop() && n->is_Phi()) && | |
931 // See (+++) comment in reg_split.cpp | 915 // See (+++) comment in reg_split.cpp |
932 !(n->jvms() != NULL && n->jvms()->is_monitor_use(k))) { | 916 !(n->jvms() != NULL && n->jvms()->is_monitor_use(k))) { |
933 bool is_loop = false; | 917 bool is_loop = false; |
934 if (n->is_Phi()) { | 918 if (n->is_Phi()) { |
935 for (uint l = 1; l < def->req(); l++) { | 919 for (uint l = 1; l < def->req(); l++) { |
937 is_loop = true; | 921 is_loop = true; |
938 break; // Some kind of loop | 922 break; // Some kind of loop |
939 } | 923 } |
940 } | 924 } |
941 } | 925 } |
942 assert(is_loop || b->find_node(def) < j, "uses must follow definitions"); | 926 assert(is_loop || block->find_node(def) < j, "uses must follow definitions"); |
943 } | 927 } |
944 } | 928 } |
945 } | 929 } |
946 } | 930 } |
947 | 931 |
948 j = b->end_idx(); | 932 j = block->end_idx(); |
949 Node *bp = (Node*)b->_nodes[b->_nodes.size()-1]->is_block_proj(); | 933 Node* bp = (Node*)block->_nodes[block->_nodes.size() - 1]->is_block_proj(); |
950 assert( bp, "last instruction must be a block proj" ); | 934 assert(bp, "last instruction must be a block proj"); |
951 assert( bp == b->_nodes[j], "wrong number of successors for this block" ); | 935 assert(bp == block->_nodes[j], "wrong number of successors for this block"); |
952 if (bp->is_Catch()) { | 936 if (bp->is_Catch()) { |
953 while (b->_nodes[--j]->is_MachProj()) ; | 937 while (block->_nodes[--j]->is_MachProj()) { |
954 assert(b->_nodes[j]->is_MachCall(), "CatchProj must follow call"); | 938 ; |
939 } | |
940 assert(block->_nodes[j]->is_MachCall(), "CatchProj must follow call"); | |
955 } else if (bp->is_Mach() && bp->as_Mach()->ideal_Opcode() == Op_If) { | 941 } else if (bp->is_Mach() && bp->as_Mach()->ideal_Opcode() == Op_If) { |
956 assert(b->_num_succs == 2, "Conditional branch must have two targets"); | 942 assert(block->_num_succs == 2, "Conditional branch must have two targets"); |
957 } | 943 } |
958 } | 944 } |
959 #endif | 945 #endif |
960 } | 946 } |
961 #endif | 947 #endif |
962 | 948 |
963 //============================================================================= | |
964 //------------------------------UnionFind-------------------------------------- | |
965 UnionFind::UnionFind( uint max ) : _cnt(max), _max(max), _indices(NEW_RESOURCE_ARRAY(uint,max)) { | 949 UnionFind::UnionFind( uint max ) : _cnt(max), _max(max), _indices(NEW_RESOURCE_ARRAY(uint,max)) { |
966 Copy::zero_to_bytes( _indices, sizeof(uint)*max ); | 950 Copy::zero_to_bytes( _indices, sizeof(uint)*max ); |
967 } | 951 } |
968 | 952 |
969 void UnionFind::extend( uint from_idx, uint to_idx ) { | 953 void UnionFind::extend( uint from_idx, uint to_idx ) { |
984 extend(max,0); | 968 extend(max,0); |
985 // Initialize to be the ID mapping. | 969 // Initialize to be the ID mapping. |
986 for( uint i=0; i<max; i++ ) map(i,i); | 970 for( uint i=0; i<max; i++ ) map(i,i); |
987 } | 971 } |
988 | 972 |
989 //------------------------------Find_compress---------------------------------- | |
990 // Straight out of Tarjan's union-find algorithm | 973 // Straight out of Tarjan's union-find algorithm |
991 uint UnionFind::Find_compress( uint idx ) { | 974 uint UnionFind::Find_compress( uint idx ) { |
992 uint cur = idx; | 975 uint cur = idx; |
993 uint next = lookup(cur); | 976 uint next = lookup(cur); |
994 while( next != cur ) { // Scan chain of equivalences | 977 while( next != cur ) { // Scan chain of equivalences |
1004 idx = tmp; | 987 idx = tmp; |
1005 } | 988 } |
1006 return idx; | 989 return idx; |
1007 } | 990 } |
1008 | 991 |
1009 //------------------------------Find_const------------------------------------- | |
1010 // Like Find above, but no path compress, so bad asymptotic behavior | 992 // Like Find above, but no path compress, so bad asymptotic behavior |
1011 uint UnionFind::Find_const( uint idx ) const { | 993 uint UnionFind::Find_const( uint idx ) const { |
1012 if( idx == 0 ) return idx; // Ignore the zero idx | 994 if( idx == 0 ) return idx; // Ignore the zero idx |
1013 // Off the end? This can happen during debugging dumps | 995 // Off the end? This can happen during debugging dumps |
1014 // when data structures have not finished being updated. | 996 // when data structures have not finished being updated. |
1019 next = lookup(idx); | 1001 next = lookup(idx); |
1020 } | 1002 } |
1021 return next; | 1003 return next; |
1022 } | 1004 } |
1023 | 1005 |
1024 //------------------------------Union------------------------------------------ | |
1025 // union 2 sets together. | 1006 // union 2 sets together. |
1026 void UnionFind::Union( uint idx1, uint idx2 ) { | 1007 void UnionFind::Union( uint idx1, uint idx2 ) { |
1027 uint src = Find(idx1); | 1008 uint src = Find(idx1); |
1028 uint dst = Find(idx2); | 1009 uint dst = Find(idx2); |
1029 assert( src, "" ); | 1010 assert( src, "" ); |
1068 } | 1049 } |
1069 tty->cr(); | 1050 tty->cr(); |
1070 } | 1051 } |
1071 #endif | 1052 #endif |
1072 | 1053 |
1073 //============================================================================= | |
1074 | |
1075 //------------------------------edge_order------------------------------------- | |
1076 // Comparison function for edges | 1054 // Comparison function for edges |
1077 static int edge_order(CFGEdge **e0, CFGEdge **e1) { | 1055 static int edge_order(CFGEdge **e0, CFGEdge **e1) { |
1078 float freq0 = (*e0)->freq(); | 1056 float freq0 = (*e0)->freq(); |
1079 float freq1 = (*e1)->freq(); | 1057 float freq1 = (*e1)->freq(); |
1080 if (freq0 != freq1) { | 1058 if (freq0 != freq1) { |
1085 int dist1 = (*e1)->to()->_rpo - (*e1)->from()->_rpo; | 1063 int dist1 = (*e1)->to()->_rpo - (*e1)->from()->_rpo; |
1086 | 1064 |
1087 return dist1 - dist0; | 1065 return dist1 - dist0; |
1088 } | 1066 } |
1089 | 1067 |
1090 //------------------------------trace_frequency_order-------------------------- | |
1091 // Comparison function for edges | 1068 // Comparison function for edges |
1092 extern "C" int trace_frequency_order(const void *p0, const void *p1) { | 1069 extern "C" int trace_frequency_order(const void *p0, const void *p1) { |
1093 Trace *tr0 = *(Trace **) p0; | 1070 Trace *tr0 = *(Trace **) p0; |
1094 Trace *tr1 = *(Trace **) p1; | 1071 Trace *tr1 = *(Trace **) p1; |
1095 Block *b0 = tr0->first_block(); | 1072 Block *b0 = tr0->first_block(); |
1111 int diff = tr0->first_block()->_rpo - tr1->first_block()->_rpo; | 1088 int diff = tr0->first_block()->_rpo - tr1->first_block()->_rpo; |
1112 | 1089 |
1113 return diff; | 1090 return diff; |
1114 } | 1091 } |
1115 | 1092 |
1116 //------------------------------find_edges------------------------------------- | |
1117 // Find edges of interest, i.e, those which can fall through. Presumes that | 1093 // Find edges of interest, i.e, those which can fall through. Presumes that |
1118 // edges which don't fall through are of low frequency and can be generally | 1094 // edges which don't fall through are of low frequency and can be generally |
1119 // ignored. Initialize the list of traces. | 1095 // ignored. Initialize the list of traces. |
1120 void PhaseBlockLayout::find_edges() | 1096 void PhaseBlockLayout::find_edges() { |
1121 { | |
1122 // Walk the blocks, creating edges and Traces | 1097 // Walk the blocks, creating edges and Traces |
1123 uint i; | 1098 uint i; |
1124 Trace *tr = NULL; | 1099 Trace *tr = NULL; |
1125 for (i = 0; i < _cfg._num_blocks; i++) { | 1100 for (i = 0; i < _cfg.number_of_blocks(); i++) { |
1126 Block *b = _cfg._blocks[i]; | 1101 Block* b = _cfg.get_block(i); |
1127 tr = new Trace(b, next, prev); | 1102 tr = new Trace(b, next, prev); |
1128 traces[tr->id()] = tr; | 1103 traces[tr->id()] = tr; |
1129 | 1104 |
1130 // All connector blocks should be at the end of the list | 1105 // All connector blocks should be at the end of the list |
1131 if (b->is_connector()) break; | 1106 if (b->is_connector()) break; |
1145 | 1120 |
1146 // We see a merge point, so stop search for the next block | 1121 // We see a merge point, so stop search for the next block |
1147 if (n->num_preds() != 1) break; | 1122 if (n->num_preds() != 1) break; |
1148 | 1123 |
1149 i++; | 1124 i++; |
1150 assert(n = _cfg._blocks[i], "expecting next block"); | 1125 assert(n = _cfg.get_block(i), "expecting next block"); |
1151 tr->append(n); | 1126 tr->append(n); |
1152 uf->map(n->_pre_order, tr->id()); | 1127 uf->map(n->_pre_order, tr->id()); |
1153 traces[n->_pre_order] = NULL; | 1128 traces[n->_pre_order] = NULL; |
1154 nfallthru = b->num_fall_throughs(); | 1129 nfallthru = b->num_fall_throughs(); |
1155 b = n; | 1130 b = n; |
1169 } | 1144 } |
1170 } | 1145 } |
1171 } | 1146 } |
1172 | 1147 |
1173 // Group connector blocks into one trace | 1148 // Group connector blocks into one trace |
1174 for (i++; i < _cfg._num_blocks; i++) { | 1149 for (i++; i < _cfg.number_of_blocks(); i++) { |
1175 Block *b = _cfg._blocks[i]; | 1150 Block *b = _cfg.get_block(i); |
1176 assert(b->is_connector(), "connector blocks at the end"); | 1151 assert(b->is_connector(), "connector blocks at the end"); |
1177 tr->append(b); | 1152 tr->append(b); |
1178 uf->map(b->_pre_order, tr->id()); | 1153 uf->map(b->_pre_order, tr->id()); |
1179 traces[b->_pre_order] = NULL; | 1154 traces[b->_pre_order] = NULL; |
1180 } | 1155 } |
1181 } | 1156 } |
1182 | 1157 |
1183 //------------------------------union_traces---------------------------------- | |
1184 // Union two traces together in uf, and null out the trace in the list | 1158 // Union two traces together in uf, and null out the trace in the list |
1185 void PhaseBlockLayout::union_traces(Trace* updated_trace, Trace* old_trace) | 1159 void PhaseBlockLayout::union_traces(Trace* updated_trace, Trace* old_trace) { |
1186 { | |
1187 uint old_id = old_trace->id(); | 1160 uint old_id = old_trace->id(); |
1188 uint updated_id = updated_trace->id(); | 1161 uint updated_id = updated_trace->id(); |
1189 | 1162 |
1190 uint lo_id = updated_id; | 1163 uint lo_id = updated_id; |
1191 uint hi_id = old_id; | 1164 uint hi_id = old_id; |
1205 // to the higher. | 1178 // to the higher. |
1206 uf->Union(lo_id, hi_id); | 1179 uf->Union(lo_id, hi_id); |
1207 traces[hi_id] = NULL; | 1180 traces[hi_id] = NULL; |
1208 } | 1181 } |
1209 | 1182 |
1210 //------------------------------grow_traces------------------------------------- | |
1211 // Append traces together via the most frequently executed edges | 1183 // Append traces together via the most frequently executed edges |
1212 void PhaseBlockLayout::grow_traces() | 1184 void PhaseBlockLayout::grow_traces() { |
1213 { | |
1214 // Order the edges, and drive the growth of Traces via the most | 1185 // Order the edges, and drive the growth of Traces via the most |
1215 // frequently executed edges. | 1186 // frequently executed edges. |
1216 edges->sort(edge_order); | 1187 edges->sort(edge_order); |
1217 for (int i = 0; i < edges->length(); i++) { | 1188 for (int i = 0; i < edges->length(); i++) { |
1218 CFGEdge *e = edges->at(i); | 1189 CFGEdge *e = edges->at(i); |
1250 } | 1221 } |
1251 } | 1222 } |
1252 } | 1223 } |
1253 } | 1224 } |
1254 | 1225 |
1255 //------------------------------merge_traces----------------------------------- | |
1256 // Embed one trace into another, if the fork or join points are sufficiently | 1226 // Embed one trace into another, if the fork or join points are sufficiently |
1257 // balanced. | 1227 // balanced. |
1258 void PhaseBlockLayout::merge_traces(bool fall_thru_only) | 1228 void PhaseBlockLayout::merge_traces(bool fall_thru_only) { |
1259 { | |
1260 // Walk the edge list a another time, looking at unprocessed edges. | 1229 // Walk the edge list a another time, looking at unprocessed edges. |
1261 // Fold in diamonds | 1230 // Fold in diamonds |
1262 for (int i = 0; i < edges->length(); i++) { | 1231 for (int i = 0; i < edges->length(); i++) { |
1263 CFGEdge *e = edges->at(i); | 1232 CFGEdge *e = edges->at(i); |
1264 | 1233 |
1308 assert(src_block->num_fall_throughs() == 2, "unexpected diamond"); | 1277 assert(src_block->num_fall_throughs() == 2, "unexpected diamond"); |
1309 e->set_state(CFGEdge::connected); | 1278 e->set_state(CFGEdge::connected); |
1310 src_trace->insert_after(src_block, targ_trace); | 1279 src_trace->insert_after(src_block, targ_trace); |
1311 union_traces(src_trace, targ_trace); | 1280 union_traces(src_trace, targ_trace); |
1312 } else if (src_at_tail) { | 1281 } else if (src_at_tail) { |
1313 if (src_trace != trace(_cfg._broot)) { | 1282 if (src_trace != trace(_cfg.get_root_block())) { |
1314 e->set_state(CFGEdge::connected); | 1283 e->set_state(CFGEdge::connected); |
1315 targ_trace->insert_before(targ_block, src_trace); | 1284 targ_trace->insert_before(targ_block, src_trace); |
1316 union_traces(targ_trace, src_trace); | 1285 union_traces(targ_trace, src_trace); |
1317 } | 1286 } |
1318 } | 1287 } |
1319 } else if (e->state() == CFGEdge::open) { | 1288 } else if (e->state() == CFGEdge::open) { |
1320 // Append traces, even without a fall-thru connection. | 1289 // Append traces, even without a fall-thru connection. |
1321 // But leave root entry at the beginning of the block list. | 1290 // But leave root entry at the beginning of the block list. |
1322 if (targ_trace != trace(_cfg._broot)) { | 1291 if (targ_trace != trace(_cfg.get_root_block())) { |
1323 e->set_state(CFGEdge::connected); | 1292 e->set_state(CFGEdge::connected); |
1324 src_trace->append(targ_trace); | 1293 src_trace->append(targ_trace); |
1325 union_traces(src_trace, targ_trace); | 1294 union_traces(src_trace, targ_trace); |
1326 } | 1295 } |
1327 } | 1296 } |
1328 } | 1297 } |
1329 } | 1298 } |
1330 | 1299 |
1331 //----------------------------reorder_traces----------------------------------- | |
1332 // Order the sequence of the traces in some desirable way, and fixup the | 1300 // Order the sequence of the traces in some desirable way, and fixup the |
1333 // jumps at the end of each block. | 1301 // jumps at the end of each block. |
1334 void PhaseBlockLayout::reorder_traces(int count) | 1302 void PhaseBlockLayout::reorder_traces(int count) { |
1335 { | |
1336 ResourceArea *area = Thread::current()->resource_area(); | 1303 ResourceArea *area = Thread::current()->resource_area(); |
1337 Trace ** new_traces = NEW_ARENA_ARRAY(area, Trace *, count); | 1304 Trace ** new_traces = NEW_ARENA_ARRAY(area, Trace *, count); |
1338 Block_List worklist; | 1305 Block_List worklist; |
1339 int new_count = 0; | 1306 int new_count = 0; |
1340 | 1307 |
1345 new_traces[new_count++] = tr; | 1312 new_traces[new_count++] = tr; |
1346 } | 1313 } |
1347 } | 1314 } |
1348 | 1315 |
1349 // The entry block should be first on the new trace list. | 1316 // The entry block should be first on the new trace list. |
1350 Trace *tr = trace(_cfg._broot); | 1317 Trace *tr = trace(_cfg.get_root_block()); |
1351 assert(tr == new_traces[0], "entry trace misplaced"); | 1318 assert(tr == new_traces[0], "entry trace misplaced"); |
1352 | 1319 |
1353 // Sort the new trace list by frequency | 1320 // Sort the new trace list by frequency |
1354 qsort(new_traces + 1, new_count - 1, sizeof(new_traces[0]), trace_frequency_order); | 1321 qsort(new_traces + 1, new_count - 1, sizeof(new_traces[0]), trace_frequency_order); |
1355 | 1322 |
1356 // Patch up the successor blocks | 1323 // Patch up the successor blocks |
1357 _cfg._blocks.reset(); | 1324 _cfg.clear_blocks(); |
1358 _cfg._num_blocks = 0; | |
1359 for (int i = 0; i < new_count; i++) { | 1325 for (int i = 0; i < new_count; i++) { |
1360 Trace *tr = new_traces[i]; | 1326 Trace *tr = new_traces[i]; |
1361 if (tr != NULL) { | 1327 if (tr != NULL) { |
1362 tr->fixup_blocks(_cfg); | 1328 tr->fixup_blocks(_cfg); |
1363 } | 1329 } |
1364 } | 1330 } |
1365 } | 1331 } |
1366 | 1332 |
1367 //------------------------------PhaseBlockLayout------------------------------- | |
1368 // Order basic blocks based on frequency | 1333 // Order basic blocks based on frequency |
1369 PhaseBlockLayout::PhaseBlockLayout(PhaseCFG &cfg) : | 1334 PhaseBlockLayout::PhaseBlockLayout(PhaseCFG &cfg) |
1370 Phase(BlockLayout), | 1335 : Phase(BlockLayout) |
1371 _cfg(cfg) | 1336 , _cfg(cfg) { |
1372 { | |
1373 ResourceMark rm; | 1337 ResourceMark rm; |
1374 ResourceArea *area = Thread::current()->resource_area(); | 1338 ResourceArea *area = Thread::current()->resource_area(); |
1375 | 1339 |
1376 // List of traces | 1340 // List of traces |
1377 int size = _cfg._num_blocks + 1; | 1341 int size = _cfg.number_of_blocks() + 1; |
1378 traces = NEW_ARENA_ARRAY(area, Trace *, size); | 1342 traces = NEW_ARENA_ARRAY(area, Trace *, size); |
1379 memset(traces, 0, size*sizeof(Trace*)); | 1343 memset(traces, 0, size*sizeof(Trace*)); |
1380 next = NEW_ARENA_ARRAY(area, Block *, size); | 1344 next = NEW_ARENA_ARRAY(area, Block *, size); |
1381 memset(next, 0, size*sizeof(Block *)); | 1345 memset(next, 0, size*sizeof(Block *)); |
1382 prev = NEW_ARENA_ARRAY(area, Block *, size); | 1346 prev = NEW_ARENA_ARRAY(area, Block *, size); |
1405 merge_traces(false); | 1369 merge_traces(false); |
1406 | 1370 |
1407 // Re-order all the remaining traces by frequency | 1371 // Re-order all the remaining traces by frequency |
1408 reorder_traces(size); | 1372 reorder_traces(size); |
1409 | 1373 |
1410 assert(_cfg._num_blocks >= (uint) (size - 1), "number of blocks can not shrink"); | 1374 assert(_cfg.number_of_blocks() >= (uint) (size - 1), "number of blocks can not shrink"); |
1411 } | 1375 } |
1412 | 1376 |
1413 | 1377 |
1414 //------------------------------backedge--------------------------------------- | |
1415 // Edge e completes a loop in a trace. If the target block is head of the | 1378 // Edge e completes a loop in a trace. If the target block is head of the |
1416 // loop, rotate the loop block so that the loop ends in a conditional branch. | 1379 // loop, rotate the loop block so that the loop ends in a conditional branch. |
1417 bool Trace::backedge(CFGEdge *e) { | 1380 bool Trace::backedge(CFGEdge *e) { |
1418 bool loop_rotated = false; | 1381 bool loop_rotated = false; |
1419 Block *src_block = e->from(); | 1382 Block *src_block = e->from(); |
1461 } | 1424 } |
1462 | 1425 |
1463 return loop_rotated; | 1426 return loop_rotated; |
1464 } | 1427 } |
1465 | 1428 |
1466 //------------------------------fixup_blocks----------------------------------- | |
1467 // push blocks onto the CFG list | 1429 // push blocks onto the CFG list |
1468 // ensure that blocks have the correct two-way branch sense | 1430 // ensure that blocks have the correct two-way branch sense |
1469 void Trace::fixup_blocks(PhaseCFG &cfg) { | 1431 void Trace::fixup_blocks(PhaseCFG &cfg) { |
1470 Block *last = last_block(); | 1432 Block *last = last_block(); |
1471 for (Block *b = first_block(); b != NULL; b = next(b)) { | 1433 for (Block *b = first_block(); b != NULL; b = next(b)) { |
1472 cfg._blocks.push(b); | 1434 cfg.add_block(b); |
1473 cfg._num_blocks++; | |
1474 if (!b->is_connector()) { | 1435 if (!b->is_connector()) { |
1475 int nfallthru = b->num_fall_throughs(); | 1436 int nfallthru = b->num_fall_throughs(); |
1476 if (b != last) { | 1437 if (b != last) { |
1477 if (nfallthru == 2) { | 1438 if (nfallthru == 2) { |
1478 // Ensure that the sense of the branch is correct | 1439 // Ensure that the sense of the branch is correct |