Mercurial > hg > truffle
comparison src/share/vm/opto/reg_split.cpp @ 10408:836a62f43af9
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 19 Jun 2013 10:45:56 +0200 |
parents | b274ac1dbe11 |
children | d1034bd8cefc |
comparison
equal
deleted
inserted
replaced
10086:e0fb8a213650 | 10408:836a62f43af9 |
---|---|
48 // | 48 // |
49 // As a side effect, unlink from (hence make dead) coalesced copies. | 49 // As a side effect, unlink from (hence make dead) coalesced copies. |
50 // | 50 // |
51 | 51 |
52 static const char out_of_nodes[] = "out of nodes during split"; | 52 static const char out_of_nodes[] = "out of nodes during split"; |
53 | |
54 static bool contains_no_live_range_input(const Node* def) { | |
55 for (uint i = 1; i < def->req(); ++i) { | |
56 if (def->in(i) != NULL && def->in_RegMask(i).is_NotEmpty()) { | |
57 return false; | |
58 } | |
59 } | |
60 return true; | |
61 } | |
53 | 62 |
54 //------------------------------get_spillcopy_wide----------------------------- | 63 //------------------------------get_spillcopy_wide----------------------------- |
55 // Get a SpillCopy node with wide-enough masks. Use the 'wide-mask', the | 64 // Get a SpillCopy node with wide-enough masks. Use the 'wide-mask', the |
56 // wide ideal-register spill-mask if possible. If the 'wide-mask' does | 65 // wide ideal-register spill-mask if possible. If the 'wide-mask' does |
57 // not cover the input (or output), use the input (or output) mask instead. | 66 // not cover the input (or output), use the input (or output) mask instead. |
316 // the inputs. | 325 // the inputs. |
317 if( def->req() > 1 ) { | 326 if( def->req() > 1 ) { |
318 for( uint i = 1; i < def->req(); i++ ) { | 327 for( uint i = 1; i < def->req(); i++ ) { |
319 Node *in = def->in(i); | 328 Node *in = def->in(i); |
320 // Check for single-def (LRG cannot redefined) | 329 // Check for single-def (LRG cannot redefined) |
321 uint lidx = n2lidx(in); | 330 uint lidx = _lrg_map.live_range_id(in); |
322 if( lidx >= _maxlrg ) continue; // Value is a recent spill-copy | 331 if (lidx >= _lrg_map.max_lrg_id()) { |
323 if (lrgs(lidx).is_singledef()) continue; | 332 continue; // Value is a recent spill-copy |
333 } | |
334 if (lrgs(lidx).is_singledef()) { | |
335 continue; | |
336 } | |
324 | 337 |
325 Block *b_def = _cfg._bbs[def->_idx]; | 338 Block *b_def = _cfg._bbs[def->_idx]; |
326 int idx_def = b_def->find_node(def); | 339 int idx_def = b_def->find_node(def); |
327 Node *in_spill = get_spillcopy_wide( in, def, i ); | 340 Node *in_spill = get_spillcopy_wide( in, def, i ); |
328 if( !in_spill ) return 0; // Bailed out | 341 if( !in_spill ) return 0; // Bailed out |
342 // See if any inputs are currently being spilled, and take the | 355 // See if any inputs are currently being spilled, and take the |
343 // latest copy of spilled inputs. | 356 // latest copy of spilled inputs. |
344 if( spill->req() > 1 ) { | 357 if( spill->req() > 1 ) { |
345 for( uint i = 1; i < spill->req(); i++ ) { | 358 for( uint i = 1; i < spill->req(); i++ ) { |
346 Node *in = spill->in(i); | 359 Node *in = spill->in(i); |
347 uint lidx = Find_id(in); | 360 uint lidx = _lrg_map.find_id(in); |
348 | 361 |
349 // Walk backwards thru spill copy node intermediates | 362 // Walk backwards thru spill copy node intermediates |
350 if (walkThru) { | 363 if (walkThru) { |
351 while ( in->is_SpillCopy() && lidx >= _maxlrg ) { | 364 while (in->is_SpillCopy() && lidx >= _lrg_map.max_lrg_id()) { |
352 in = in->in(1); | 365 in = in->in(1); |
353 lidx = Find_id(in); | 366 lidx = _lrg_map.find_id(in); |
354 } | 367 } |
355 | 368 |
356 if (lidx < _maxlrg && lrgs(lidx).is_multidef()) { | 369 if (lidx < _lrg_map.max_lrg_id() && lrgs(lidx).is_multidef()) { |
357 // walkThru found a multidef LRG, which is unsafe to use, so | 370 // walkThru found a multidef LRG, which is unsafe to use, so |
358 // just keep the original def used in the clone. | 371 // just keep the original def used in the clone. |
359 in = spill->in(i); | 372 in = spill->in(i); |
360 lidx = Find_id(in); | 373 lidx = _lrg_map.find_id(in); |
361 } | 374 } |
362 } | 375 } |
363 | 376 |
364 if( lidx < _maxlrg && lrgs(lidx).reg() >= LRG::SPILL_REG ) { | 377 if (lidx < _lrg_map.max_lrg_id() && lrgs(lidx).reg() >= LRG::SPILL_REG) { |
365 Node *rdef = Reachblock[lrg2reach[lidx]]; | 378 Node *rdef = Reachblock[lrg2reach[lidx]]; |
366 if( rdef ) spill->set_req(i,rdef); | 379 if (rdef) { |
380 spill->set_req(i, rdef); | |
381 } | |
367 } | 382 } |
368 } | 383 } |
369 } | 384 } |
370 | 385 |
371 | 386 |
380 // Increment the counter for this lrg | 395 // Increment the counter for this lrg |
381 splits.at_put(slidx, splits.at(slidx)+1); | 396 splits.at_put(slidx, splits.at(slidx)+1); |
382 #endif | 397 #endif |
383 // See if the cloned def kills any flags, and copy those kills as well | 398 // See if the cloned def kills any flags, and copy those kills as well |
384 uint i = insidx+1; | 399 uint i = insidx+1; |
385 if( clone_projs( b, i, def, spill, maxlrg ) ) { | 400 if( clone_projs( b, i, def, spill, maxlrg) ) { |
386 // Adjust the point where we go hi-pressure | 401 // Adjust the point where we go hi-pressure |
387 if( i <= b->_ihrp_index ) b->_ihrp_index++; | 402 if( i <= b->_ihrp_index ) b->_ihrp_index++; |
388 if( i <= b->_fhrp_index ) b->_fhrp_index++; | 403 if( i <= b->_fhrp_index ) b->_fhrp_index++; |
389 } | 404 } |
390 | 405 |
422 | 437 |
423 | 438 |
424 //------------------------------prompt_use--------------------------------- | 439 //------------------------------prompt_use--------------------------------- |
425 // True if lidx is used before any real register is def'd in the block | 440 // True if lidx is used before any real register is def'd in the block |
426 bool PhaseChaitin::prompt_use( Block *b, uint lidx ) { | 441 bool PhaseChaitin::prompt_use( Block *b, uint lidx ) { |
427 if( lrgs(lidx)._was_spilled2 ) return false; | 442 if (lrgs(lidx)._was_spilled2) { |
443 return false; | |
444 } | |
428 | 445 |
429 // Scan block for 1st use. | 446 // Scan block for 1st use. |
430 for( uint i = 1; i <= b->end_idx(); i++ ) { | 447 for( uint i = 1; i <= b->end_idx(); i++ ) { |
431 Node *n = b->_nodes[i]; | 448 Node *n = b->_nodes[i]; |
432 // Ignore PHI use, these can be up or down | 449 // Ignore PHI use, these can be up or down |
433 if( n->is_Phi() ) continue; | 450 if (n->is_Phi()) { |
434 for( uint j = 1; j < n->req(); j++ ) | 451 continue; |
435 if( Find_id(n->in(j)) == lidx ) | 452 } |
453 for (uint j = 1; j < n->req(); j++) { | |
454 if (_lrg_map.find_id(n->in(j)) == lidx) { | |
436 return true; // Found 1st use! | 455 return true; // Found 1st use! |
437 if( n->out_RegMask().is_NotEmpty() ) return false; | 456 } |
457 } | |
458 if (n->out_RegMask().is_NotEmpty()) { | |
459 return false; | |
460 } | |
438 } | 461 } |
439 return false; | 462 return false; |
440 } | 463 } |
441 | 464 |
442 //------------------------------Split-------------------------------------- | 465 //------------------------------Split-------------------------------------- |
462 Node_List *defs,*phis; | 485 Node_List *defs,*phis; |
463 bool *UPblock; | 486 bool *UPblock; |
464 bool u1, u2, u3; | 487 bool u1, u2, u3; |
465 Block *b, *pred; | 488 Block *b, *pred; |
466 PhiNode *phi; | 489 PhiNode *phi; |
467 GrowableArray<uint> lidxs(split_arena, _maxlrg, 0, 0); | 490 GrowableArray<uint> lidxs(split_arena, maxlrg, 0, 0); |
468 | 491 |
469 // Array of counters to count splits per live range | 492 // Array of counters to count splits per live range |
470 GrowableArray<uint> splits(split_arena, _maxlrg, 0, 0); | 493 GrowableArray<uint> splits(split_arena, maxlrg, 0, 0); |
471 | 494 |
472 #define NEW_SPLIT_ARRAY(type, size)\ | 495 #define NEW_SPLIT_ARRAY(type, size)\ |
473 (type*) split_arena->allocate_bytes((size) * sizeof(type)) | 496 (type*) split_arena->allocate_bytes((size) * sizeof(type)) |
474 | 497 |
475 //----------Setup Code---------- | 498 //----------Setup Code---------- |
476 // Create a convenient mapping from lrg numbers to reaches/leaves indices | 499 // Create a convenient mapping from lrg numbers to reaches/leaves indices |
477 uint *lrg2reach = NEW_SPLIT_ARRAY( uint, _maxlrg ); | 500 uint *lrg2reach = NEW_SPLIT_ARRAY(uint, maxlrg); |
478 // Keep track of DEFS & Phis for later passes | 501 // Keep track of DEFS & Phis for later passes |
479 defs = new Node_List(); | 502 defs = new Node_List(); |
480 phis = new Node_List(); | 503 phis = new Node_List(); |
481 // Gather info on which LRG's are spilling, and build maps | 504 // Gather info on which LRG's are spilling, and build maps |
482 for( bidx = 1; bidx < _maxlrg; bidx++ ) { | 505 for (bidx = 1; bidx < maxlrg; bidx++) { |
483 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) { | 506 if (lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG) { |
484 assert(!lrgs(bidx).mask().is_AllStack(),"AllStack should color"); | 507 assert(!lrgs(bidx).mask().is_AllStack(),"AllStack should color"); |
485 lrg2reach[bidx] = spill_cnt; | 508 lrg2reach[bidx] = spill_cnt; |
486 spill_cnt++; | 509 spill_cnt++; |
487 lidxs.append(bidx); | 510 lidxs.append(bidx); |
488 #ifdef ASSERT | 511 #ifdef ASSERT |
627 non_phi = insidx; | 650 non_phi = insidx; |
628 // break out of the for loop as we have handled all phi nodes | 651 // break out of the for loop as we have handled all phi nodes |
629 break; | 652 break; |
630 } | 653 } |
631 // must be looking at a phi | 654 // must be looking at a phi |
632 if( Find_id(n1) == lidxs.at(slidx) ) { | 655 if (_lrg_map.find_id(n1) == lidxs.at(slidx)) { |
633 // found the necessary phi | 656 // found the necessary phi |
634 needs_phi = false; | 657 needs_phi = false; |
635 has_phi = true; | 658 has_phi = true; |
636 // initialize the Reaches entry for this LRG | 659 // initialize the Reaches entry for this LRG |
637 Reachblock[slidx] = phi; | 660 Reachblock[slidx] = phi; |
649 phi = new (C) PhiNode(b->head(), n3->bottom_type()); | 672 phi = new (C) PhiNode(b->head(), n3->bottom_type()); |
650 // initialize the Reaches entry for this LRG | 673 // initialize the Reaches entry for this LRG |
651 Reachblock[slidx] = phi; | 674 Reachblock[slidx] = phi; |
652 | 675 |
653 // add node to block & node_to_block mapping | 676 // add node to block & node_to_block mapping |
654 insert_proj( b, insidx++, phi, maxlrg++ ); | 677 insert_proj(b, insidx++, phi, maxlrg++); |
655 non_phi++; | 678 non_phi++; |
656 // Reset new phi's mapping to be the spilling live range | 679 // Reset new phi's mapping to be the spilling live range |
657 _names.map(phi->_idx, lidx); | 680 _lrg_map.map(phi->_idx, lidx); |
658 assert(Find_id(phi) == lidx,"Bad update on Union-Find mapping"); | 681 assert(_lrg_map.find_id(phi) == lidx, "Bad update on Union-Find mapping"); |
659 } // end if not found correct phi | 682 } // end if not found correct phi |
660 // Here you have either found or created the Phi, so record it | 683 // Here you have either found or created the Phi, so record it |
661 assert(phi != NULL,"Must have a Phi Node here"); | 684 assert(phi != NULL,"Must have a Phi Node here"); |
662 phis->push(phi); | 685 phis->push(phi); |
663 // PhiNodes should either force the LRG UP or DOWN depending | 686 // PhiNodes should either force the LRG UP or DOWN depending |
719 //----------Walk Instructions in the Block and Split---------- | 742 //----------Walk Instructions in the Block and Split---------- |
720 // For all non-phi instructions in the block | 743 // For all non-phi instructions in the block |
721 for( insidx = 1; insidx <= b->end_idx(); insidx++ ) { | 744 for( insidx = 1; insidx <= b->end_idx(); insidx++ ) { |
722 Node *n = b->_nodes[insidx]; | 745 Node *n = b->_nodes[insidx]; |
723 // Find the defining Node's live range index | 746 // Find the defining Node's live range index |
724 uint defidx = Find_id(n); | 747 uint defidx = _lrg_map.find_id(n); |
725 uint cnt = n->req(); | 748 uint cnt = n->req(); |
726 | 749 |
727 if( n->is_Phi() ) { | 750 if (n->is_Phi()) { |
728 // Skip phi nodes after removing dead copies. | 751 // Skip phi nodes after removing dead copies. |
729 if( defidx < _maxlrg ) { | 752 if (defidx < _lrg_map.max_lrg_id()) { |
730 // Check for useless Phis. These appear if we spill, then | 753 // Check for useless Phis. These appear if we spill, then |
731 // coalesce away copies. Dont touch Phis in spilling live | 754 // coalesce away copies. Dont touch Phis in spilling live |
732 // ranges; they are busy getting modifed in this pass. | 755 // ranges; they are busy getting modifed in this pass. |
733 if( lrgs(defidx).reg() < LRG::SPILL_REG ) { | 756 if( lrgs(defidx).reg() < LRG::SPILL_REG ) { |
734 uint i; | 757 uint i; |
742 break; | 765 break; |
743 u = n->in(i); // Else record it | 766 u = n->in(i); // Else record it |
744 } | 767 } |
745 } | 768 } |
746 assert( u, "at least 1 valid input expected" ); | 769 assert( u, "at least 1 valid input expected" ); |
747 if( i >= cnt ) { // Found one unique input | 770 if (i >= cnt) { // Found one unique input |
748 assert(Find_id(n) == Find_id(u), "should be the same lrg"); | 771 assert(_lrg_map.find_id(n) == _lrg_map.find_id(u), "should be the same lrg"); |
749 n->replace_by(u); // Then replace with unique input | 772 n->replace_by(u); // Then replace with unique input |
750 n->disconnect_inputs(NULL, C); | 773 n->disconnect_inputs(NULL, C); |
751 b->_nodes.remove(insidx); | 774 b->_nodes.remove(insidx); |
752 insidx--; | 775 insidx--; |
753 b->_ihrp_index--; | 776 b->_ihrp_index--; |
791 // Insert point is just past last use or def in the block | 814 // Insert point is just past last use or def in the block |
792 int insert_point = insidx-1; | 815 int insert_point = insidx-1; |
793 while( insert_point > 0 ) { | 816 while( insert_point > 0 ) { |
794 Node *n = b->_nodes[insert_point]; | 817 Node *n = b->_nodes[insert_point]; |
795 // Hit top of block? Quit going backwards | 818 // Hit top of block? Quit going backwards |
796 if( n->is_Phi() ) break; | 819 if (n->is_Phi()) { |
820 break; | |
821 } | |
797 // Found a def? Better split after it. | 822 // Found a def? Better split after it. |
798 if( n2lidx(n) == lidx ) break; | 823 if (_lrg_map.live_range_id(n) == lidx) { |
824 break; | |
825 } | |
799 // Look for a use | 826 // Look for a use |
800 uint i; | 827 uint i; |
801 for( i = 1; i < n->req(); i++ ) | 828 for( i = 1; i < n->req(); i++ ) { |
802 if( n2lidx(n->in(i)) == lidx ) | 829 if (_lrg_map.live_range_id(n->in(i)) == lidx) { |
803 break; | 830 break; |
831 } | |
832 } | |
804 // Found a use? Better split after it. | 833 // Found a use? Better split after it. |
805 if( i < n->req() ) break; | 834 if (i < n->req()) { |
835 break; | |
836 } | |
806 insert_point--; | 837 insert_point--; |
807 } | 838 } |
808 uint orig_eidx = b->end_idx(); | 839 uint orig_eidx = b->end_idx(); |
809 maxlrg = split_DEF( n1, b, insert_point, maxlrg, Reachblock, debug_defs, splits, slidx); | 840 maxlrg = split_DEF( n1, b, insert_point, maxlrg, Reachblock, debug_defs, splits, slidx); |
810 // If it wasn't split bail | 841 // If it wasn't split bail |
811 if (!maxlrg) { | 842 if (!maxlrg) { |
812 return 0; | 843 return 0; |
813 } | 844 } |
814 // Spill of NULL check mem op goes into the following block. | 845 // Spill of NULL check mem op goes into the following block. |
815 if (b->end_idx() > orig_eidx) | 846 if (b->end_idx() > orig_eidx) { |
816 insidx++; | 847 insidx++; |
848 } | |
817 } | 849 } |
818 // This is a new DEF, so update UP | 850 // This is a new DEF, so update UP |
819 UPblock[slidx] = false; | 851 UPblock[slidx] = false; |
820 #ifndef PRODUCT | 852 #ifndef PRODUCT |
821 // DEBUG | 853 // DEBUG |
830 } // end for all spilling live ranges | 862 } // end for all spilling live ranges |
831 assert( b->_nodes[insidx] == n, "got insidx set incorrectly" ); | 863 assert( b->_nodes[insidx] == n, "got insidx set incorrectly" ); |
832 } // end if crossing HRP Boundry | 864 } // end if crossing HRP Boundry |
833 | 865 |
834 // If the LRG index is oob, then this is a new spillcopy, skip it. | 866 // If the LRG index is oob, then this is a new spillcopy, skip it. |
835 if( defidx >= _maxlrg ) { | 867 if (defidx >= _lrg_map.max_lrg_id()) { |
836 continue; | 868 continue; |
837 } | 869 } |
838 LRG &deflrg = lrgs(defidx); | 870 LRG &deflrg = lrgs(defidx); |
839 uint copyidx = n->is_Copy(); | 871 uint copyidx = n->is_Copy(); |
840 // Remove coalesced copy from CFG | 872 // Remove coalesced copy from CFG |
841 if( copyidx && defidx == n2lidx(n->in(copyidx)) ) { | 873 if (copyidx && defidx == _lrg_map.live_range_id(n->in(copyidx))) { |
842 n->replace_by( n->in(copyidx) ); | 874 n->replace_by( n->in(copyidx) ); |
843 n->set_req( copyidx, NULL ); | 875 n->set_req( copyidx, NULL ); |
844 b->_nodes.remove(insidx--); | 876 b->_nodes.remove(insidx--); |
845 b->_ihrp_index--; // Adjust the point where we go hi-pressure | 877 b->_ihrp_index--; // Adjust the point where we go hi-pressure |
846 b->_fhrp_index--; | 878 b->_fhrp_index--; |
862 for( inpidx = 1; inpidx < cnt; inpidx++ ) { | 894 for( inpidx = 1; inpidx < cnt; inpidx++ ) { |
863 // Derived/base pairs may be added to our inputs during this loop. | 895 // Derived/base pairs may be added to our inputs during this loop. |
864 // If inpidx > old_last, then one of these new inputs is being | 896 // If inpidx > old_last, then one of these new inputs is being |
865 // handled. Skip the derived part of the pair, but process | 897 // handled. Skip the derived part of the pair, but process |
866 // the base like any other input. | 898 // the base like any other input. |
867 if( inpidx > old_last && ((inpidx - oopoff) & 1) == DERIVED ) { | 899 if (inpidx > old_last && ((inpidx - oopoff) & 1) == DERIVED) { |
868 continue; // skip derived_debug added below | 900 continue; // skip derived_debug added below |
869 } | 901 } |
870 // Get lidx of input | 902 // Get lidx of input |
871 uint useidx = Find_id(n->in(inpidx)); | 903 uint useidx = _lrg_map.find_id(n->in(inpidx)); |
872 // Not a brand-new split, and it is a spill use | 904 // Not a brand-new split, and it is a spill use |
873 if( useidx < _maxlrg && lrgs(useidx).reg() >= LRG::SPILL_REG ) { | 905 if (useidx < _lrg_map.max_lrg_id() && lrgs(useidx).reg() >= LRG::SPILL_REG) { |
874 // Check for valid reaching DEF | 906 // Check for valid reaching DEF |
875 slidx = lrg2reach[useidx]; | 907 slidx = lrg2reach[useidx]; |
876 Node *def = Reachblock[slidx]; | 908 Node *def = Reachblock[slidx]; |
877 assert( def != NULL, "Using Undefined Value in Split()\n"); | 909 assert( def != NULL, "Using Undefined Value in Split()\n"); |
878 | 910 |
884 // does not attempt to assign it a register. | 916 // does not attempt to assign it a register. |
885 def = clone_node(def, b, C); | 917 def = clone_node(def, b, C); |
886 if (def == NULL || C->check_node_count(NodeLimitFudgeFactor, out_of_nodes)) { | 918 if (def == NULL || C->check_node_count(NodeLimitFudgeFactor, out_of_nodes)) { |
887 return 0; | 919 return 0; |
888 } | 920 } |
889 _names.extend(def->_idx,0); | 921 _lrg_map.extend(def->_idx, 0); |
890 _cfg._bbs.map(def->_idx,b); | 922 _cfg._bbs.map(def->_idx,b); |
891 n->set_req(inpidx, def); | 923 n->set_req(inpidx, def); |
892 continue; | 924 continue; |
893 } | 925 } |
894 | 926 |
1184 } // End if spill def | 1216 } // End if spill def |
1185 | 1217 |
1186 // ********** Split Left Over Mem-Mem Moves ********** | 1218 // ********** Split Left Over Mem-Mem Moves ********** |
1187 // Check for mem-mem copies and split them now. Do not do this | 1219 // Check for mem-mem copies and split them now. Do not do this |
1188 // to copies about to be spilled; they will be Split shortly. | 1220 // to copies about to be spilled; they will be Split shortly. |
1189 if( copyidx ) { | 1221 if (copyidx) { |
1190 Node *use = n->in(copyidx); | 1222 Node *use = n->in(copyidx); |
1191 uint useidx = Find_id(use); | 1223 uint useidx = _lrg_map.find_id(use); |
1192 if( useidx < _maxlrg && // This is not a new split | 1224 if (useidx < _lrg_map.max_lrg_id() && // This is not a new split |
1193 OptoReg::is_stack(deflrg.reg()) && | 1225 OptoReg::is_stack(deflrg.reg()) && |
1194 deflrg.reg() < LRG::SPILL_REG ) { // And DEF is from stack | 1226 deflrg.reg() < LRG::SPILL_REG ) { // And DEF is from stack |
1195 LRG &uselrg = lrgs(useidx); | 1227 LRG &uselrg = lrgs(useidx); |
1196 if( OptoReg::is_stack(uselrg.reg()) && | 1228 if( OptoReg::is_stack(uselrg.reg()) && |
1197 uselrg.reg() < LRG::SPILL_REG && // USE is from stack | 1229 uselrg.reg() < LRG::SPILL_REG && // USE is from stack |
1226 // instance may be a case to add liveout adjustment in compress_uf_map(). | 1258 // instance may be a case to add liveout adjustment in compress_uf_map(). |
1227 // See 5063219. | 1259 // See 5063219. |
1228 uint member; | 1260 uint member; |
1229 IndexSetIterator isi(liveout); | 1261 IndexSetIterator isi(liveout); |
1230 while ((member = isi.next()) != 0) { | 1262 while ((member = isi.next()) != 0) { |
1231 assert(defidx != Find_const(member), "Live out member has not been compressed"); | 1263 assert(defidx != _lrg_map.find_const(member), "Live out member has not been compressed"); |
1232 } | 1264 } |
1233 #endif | 1265 #endif |
1234 Reachblock[slidx] = NULL; | 1266 Reachblock[slidx] = NULL; |
1235 } else { | 1267 } else { |
1236 assert(Reachblock[slidx] != NULL,"No reaching definition for liveout value"); | 1268 assert(Reachblock[slidx] != NULL,"No reaching definition for liveout value"); |
1259 for( insidx = 0; insidx < phis->size(); insidx++ ) { | 1291 for( insidx = 0; insidx < phis->size(); insidx++ ) { |
1260 Node *phi = phis->at(insidx); | 1292 Node *phi = phis->at(insidx); |
1261 assert(phi->is_Phi(),"This list must only contain Phi Nodes"); | 1293 assert(phi->is_Phi(),"This list must only contain Phi Nodes"); |
1262 Block *b = _cfg._bbs[phi->_idx]; | 1294 Block *b = _cfg._bbs[phi->_idx]; |
1263 // Grab the live range number | 1295 // Grab the live range number |
1264 uint lidx = Find_id(phi); | 1296 uint lidx = _lrg_map.find_id(phi); |
1265 uint slidx = lrg2reach[lidx]; | 1297 uint slidx = lrg2reach[lidx]; |
1266 // Update node to lidx map | 1298 // Update node to lidx map |
1267 new_lrg(phi, maxlrg++); | 1299 new_lrg(phi, maxlrg++); |
1268 // Get PASS1's up/down decision for the block. | 1300 // Get PASS1's up/down decision for the block. |
1269 int phi_up = !!UP_entry[slidx]->test(b->_pre_order); | 1301 int phi_up = !!UP_entry[slidx]->test(b->_pre_order); |
1287 pidx = pred->_pre_order; | 1319 pidx = pred->_pre_order; |
1288 // Grab reaching def | 1320 // Grab reaching def |
1289 Node *def = Reaches[pidx][slidx]; | 1321 Node *def = Reaches[pidx][slidx]; |
1290 assert( def, "must have reaching def" ); | 1322 assert( def, "must have reaching def" ); |
1291 // If input up/down sense and reg-pressure DISagree | 1323 // If input up/down sense and reg-pressure DISagree |
1292 if( def->rematerialize() ) { | 1324 if (def->rematerialize() && contains_no_live_range_input(def)) { |
1293 // Place the rematerialized node above any MSCs created during | 1325 // Place the rematerialized node above any MSCs created during |
1294 // phi node splitting. end_idx points at the insertion point | 1326 // phi node splitting. end_idx points at the insertion point |
1295 // so look at the node before it. | 1327 // so look at the node before it. |
1296 int insert = pred->end_idx(); | 1328 int insert = pred->end_idx(); |
1297 while (insert >= 1 && | 1329 while (insert >= 1 && |
1298 pred->_nodes[insert - 1]->is_SpillCopy() && | 1330 pred->_nodes[insert - 1]->is_SpillCopy() && |
1299 Find(pred->_nodes[insert - 1]) >= lrgs_before_phi_split) { | 1331 _lrg_map.find(pred->_nodes[insert - 1]) >= lrgs_before_phi_split) { |
1300 insert--; | 1332 insert--; |
1301 } | 1333 } |
1302 def = split_Rematerialize( def, pred, insert, maxlrg, splits, slidx, lrg2reach, Reachblock, false ); | 1334 def = split_Rematerialize(def, pred, insert, maxlrg, splits, slidx, lrg2reach, Reachblock, false); |
1303 if( !def ) return 0; // Bail out | 1335 if (!def) { |
1336 return 0; // Bail out | |
1337 } | |
1304 } | 1338 } |
1305 // Update the Phi's input edge array | 1339 // Update the Phi's input edge array |
1306 phi->set_req(i,def); | 1340 phi->set_req(i,def); |
1307 // Grab the UP/DOWN sense for the input | 1341 // Grab the UP/DOWN sense for the input |
1308 u1 = UP[pidx][slidx]; | 1342 u1 = UP[pidx][slidx]; |
1314 } | 1348 } |
1315 } | 1349 } |
1316 } // End for all inputs to the Phi | 1350 } // End for all inputs to the Phi |
1317 } // End for all Phi Nodes | 1351 } // End for all Phi Nodes |
1318 // Update _maxlrg to save Union asserts | 1352 // Update _maxlrg to save Union asserts |
1319 _maxlrg = maxlrg; | 1353 _lrg_map.set_max_lrg_id(maxlrg); |
1320 | 1354 |
1321 | 1355 |
1322 //----------PASS 3---------- | 1356 //----------PASS 3---------- |
1323 // Pass over all Phi's to union the live ranges | 1357 // Pass over all Phi's to union the live ranges |
1324 for( insidx = 0; insidx < phis->size(); insidx++ ) { | 1358 for( insidx = 0; insidx < phis->size(); insidx++ ) { |
1326 assert(phi->is_Phi(),"This list must only contain Phi Nodes"); | 1360 assert(phi->is_Phi(),"This list must only contain Phi Nodes"); |
1327 // Walk all inputs to Phi and Union input live range with Phi live range | 1361 // Walk all inputs to Phi and Union input live range with Phi live range |
1328 for( uint i = 1; i < phi->req(); i++ ) { | 1362 for( uint i = 1; i < phi->req(); i++ ) { |
1329 // Grab the input node | 1363 // Grab the input node |
1330 Node *n = phi->in(i); | 1364 Node *n = phi->in(i); |
1331 assert( n, "" ); | 1365 assert(n, "node should exist"); |
1332 uint lidx = Find(n); | 1366 uint lidx = _lrg_map.find(n); |
1333 uint pidx = Find(phi); | 1367 uint pidx = _lrg_map.find(phi); |
1334 if( lidx < pidx ) | 1368 if (lidx < pidx) { |
1335 Union(n, phi); | 1369 Union(n, phi); |
1336 else if( lidx > pidx ) | 1370 } |
1371 else if(lidx > pidx) { | |
1337 Union(phi, n); | 1372 Union(phi, n); |
1373 } | |
1338 } // End for all inputs to the Phi Node | 1374 } // End for all inputs to the Phi Node |
1339 } // End for all Phi Nodes | 1375 } // End for all Phi Nodes |
1340 // Now union all two address instructions | 1376 // Now union all two address instructions |
1341 for( insidx = 0; insidx < defs->size(); insidx++ ) { | 1377 for (insidx = 0; insidx < defs->size(); insidx++) { |
1342 // Grab the def | 1378 // Grab the def |
1343 n1 = defs->at(insidx); | 1379 n1 = defs->at(insidx); |
1344 // Set new lidx for DEF & handle 2-addr instructions | 1380 // Set new lidx for DEF & handle 2-addr instructions |
1345 if( n1->is_Mach() && ((twoidx = n1->as_Mach()->two_adr()) != 0) ) { | 1381 if (n1->is_Mach() && ((twoidx = n1->as_Mach()->two_adr()) != 0)) { |
1346 assert( Find(n1->in(twoidx)) < maxlrg,"Assigning bad live range index"); | 1382 assert(_lrg_map.find(n1->in(twoidx)) < maxlrg,"Assigning bad live range index"); |
1347 // Union the input and output live ranges | 1383 // Union the input and output live ranges |
1348 uint lr1 = Find(n1); | 1384 uint lr1 = _lrg_map.find(n1); |
1349 uint lr2 = Find(n1->in(twoidx)); | 1385 uint lr2 = _lrg_map.find(n1->in(twoidx)); |
1350 if( lr1 < lr2 ) | 1386 if (lr1 < lr2) { |
1351 Union(n1, n1->in(twoidx)); | 1387 Union(n1, n1->in(twoidx)); |
1352 else if( lr1 > lr2 ) | 1388 } |
1389 else if (lr1 > lr2) { | |
1353 Union(n1->in(twoidx), n1); | 1390 Union(n1->in(twoidx), n1); |
1391 } | |
1354 } // End if two address | 1392 } // End if two address |
1355 } // End for all defs | 1393 } // End for all defs |
1356 // DEBUG | 1394 // DEBUG |
1357 #ifdef ASSERT | 1395 #ifdef ASSERT |
1358 // Validate all live range index assignments | 1396 // Validate all live range index assignments |
1359 for( bidx = 0; bidx < _cfg._num_blocks; bidx++ ) { | 1397 for (bidx = 0; bidx < _cfg._num_blocks; bidx++) { |
1360 b = _cfg._blocks[bidx]; | 1398 b = _cfg._blocks[bidx]; |
1361 for( insidx = 0; insidx <= b->end_idx(); insidx++ ) { | 1399 for (insidx = 0; insidx <= b->end_idx(); insidx++) { |
1362 Node *n = b->_nodes[insidx]; | 1400 Node *n = b->_nodes[insidx]; |
1363 uint defidx = Find(n); | 1401 uint defidx = _lrg_map.find(n); |
1364 assert(defidx < _maxlrg,"Bad live range index in Split"); | 1402 assert(defidx < _lrg_map.max_lrg_id(), "Bad live range index in Split"); |
1365 assert(defidx < maxlrg,"Bad live range index in Split"); | 1403 assert(defidx < maxlrg,"Bad live range index in Split"); |
1366 } | 1404 } |
1367 } | 1405 } |
1368 // Issue a warning if splitting made no progress | 1406 // Issue a warning if splitting made no progress |
1369 int noprogress = 0; | 1407 int noprogress = 0; |
1370 for( slidx = 0; slidx < spill_cnt; slidx++ ) { | 1408 for (slidx = 0; slidx < spill_cnt; slidx++) { |
1371 if( PrintOpto && WizardMode && splits.at(slidx) == 0 ) { | 1409 if (PrintOpto && WizardMode && splits.at(slidx) == 0) { |
1372 tty->print_cr("Failed to split live range %d", lidxs.at(slidx)); | 1410 tty->print_cr("Failed to split live range %d", lidxs.at(slidx)); |
1373 //BREAKPOINT; | 1411 //BREAKPOINT; |
1374 } | 1412 } |
1375 else { | 1413 else { |
1376 noprogress++; | 1414 noprogress++; |