src/share/vm/opto/postaloc.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File JDK-8022284 Sdiff src/share/vm/opto

src/share/vm/opto/postaloc.cpp

Print this page




  61     if( def->is_Copy() )        // Copies carry value through
  62       def = def->in(def->is_Copy());
  63     else if( def->is_Phi() )    // Phis can merge it from any direction
  64       def = def->in(1);
  65     else
  66       break;
  67     guarantee(def != NULL, "must not resurrect dead copy");
  68   }
  69   // If we reached the end and didn't find a callee save proj
  70   // then this may be a callee save proj so we return true
  71   // as the conservative answer. If we didn't reach then end
  72   // we must have discovered that it was not a callee save
  73   // else we would have returned.
  74   return i == limit;
  75 }
  76 
  77 //------------------------------yank-----------------------------------
  78 // Helper function for yank_if_dead
  79 int PhaseChaitin::yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) {
  80   int blk_adjust=0;
  81   Block *oldb = _cfg._bbs[old->_idx];
  82   oldb->find_remove(old);
  83   // Count 1 if deleting an instruction from the current block
  84   if( oldb == current_block ) blk_adjust++;
  85   _cfg._bbs.map(old->_idx,NULL);


  86   OptoReg::Name old_reg = lrgs(_lrg_map.live_range_id(old)).reg();
  87   if( regnd && (*regnd)[old_reg]==old ) { // Instruction is currently available?
  88     value->map(old_reg,NULL);  // Yank from value/regnd maps
  89     regnd->map(old_reg,NULL);  // This register's value is now unknown
  90   }
  91   return blk_adjust;
  92 }
  93 
  94 #ifdef ASSERT
  95 static bool expected_yanked_node(Node *old, Node *orig_old) {
  96   // This code is expected only next original nodes:
  97   // - load from constant table node which may have next data input nodes:
  98   //     MachConstantBase, Phi, MachTemp, MachSpillCopy
  99   // - load constant node which may have next data input nodes:
 100   //     MachTemp, MachSpillCopy
 101   // - MachSpillCopy
 102   // - MachProj and Copy dead nodes
 103   if (old->is_MachSpillCopy()) {
 104     return true;
 105   } else if (old->is_Con()) {


 416 
 417   // For all blocks
 418   for( uint i = 0; i < _cfg._num_blocks; i++ ) {
 419     uint j;
 420     Block *b = _cfg._blocks[i];
 421 
 422     // Count of Phis in block
 423     uint phi_dex;
 424     for( phi_dex = 1; phi_dex < b->_nodes.size(); phi_dex++ ) {
 425       Node *phi = b->_nodes[phi_dex];
 426       if( !phi->is_Phi() )
 427         break;
 428     }
 429 
 430     // If any predecessor has not been visited, we do not know the state
 431     // of registers at the start.  Check for this, while updating copies
 432     // along Phi input edges
 433     bool missing_some_inputs = false;
 434     Block *freed = NULL;
 435     for( j = 1; j < b->num_preds(); j++ ) {
 436       Block *pb = _cfg._bbs[b->pred(j)->_idx];
 437       // Remove copies along phi edges
 438       for( uint k=1; k<phi_dex; k++ )
 439         elide_copy( b->_nodes[k], j, b, *blk2value[pb->_pre_order], *blk2regnd[pb->_pre_order], false );
 440       if( blk2value[pb->_pre_order] ) { // Have a mapping on this edge?
 441         // See if this predecessor's mappings have been used by everybody
 442         // who wants them.  If so, free 'em.
 443         uint k;
 444         for( k=0; k<pb->_num_succs; k++ ) {
 445           Block *pbsucc = pb->_succs[k];
 446           if( !blk2value[pbsucc->_pre_order] && pbsucc != b )
 447             break;              // Found a future user
 448         }
 449         if( k >= pb->_num_succs ) { // No more uses, free!
 450           freed = pb;           // Record last block freed
 451           free_list.push(blk2value[pb->_pre_order]);
 452           free_list.push(blk2regnd[pb->_pre_order]);
 453         }
 454       } else {                  // This block has unvisited (loopback) inputs
 455         missing_some_inputs = true;
 456       }


 461     // 'freed's blocks off the list
 462     Node_List &regnd = *(free_list.is_empty() ? new Node_List() : free_list.pop());
 463     Node_List &value = *(free_list.is_empty() ? new Node_List() : free_list.pop());
 464     assert( !freed || blk2value[freed->_pre_order] == &value, "" );
 465     value.map(_max_reg,NULL);
 466     regnd.map(_max_reg,NULL);
 467     // Set mappings as OUR mappings
 468     blk2value[b->_pre_order] = &value;
 469     blk2regnd[b->_pre_order] = &regnd;
 470 
 471     // Initialize value & regnd for this block
 472     if( missing_some_inputs ) {
 473       // Some predecessor has not yet been visited; zap map to empty
 474       for( uint k = 0; k < (uint)_max_reg; k++ ) {
 475         value.map(k,NULL);
 476         regnd.map(k,NULL);
 477       }
 478     } else {
 479       if( !freed ) {            // Didn't get a freebie prior block
 480         // Must clone some data
 481         freed = _cfg._bbs[b->pred(1)->_idx];
 482         Node_List &f_value = *blk2value[freed->_pre_order];
 483         Node_List &f_regnd = *blk2regnd[freed->_pre_order];
 484         for( uint k = 0; k < (uint)_max_reg; k++ ) {
 485           value.map(k,f_value[k]);
 486           regnd.map(k,f_regnd[k]);
 487         }
 488       }
 489       // Merge all inputs together, setting to NULL any conflicts.
 490       for( j = 1; j < b->num_preds(); j++ ) {
 491         Block *pb = _cfg._bbs[b->pred(j)->_idx];
 492         if( pb == freed ) continue; // Did self already via freelist
 493         Node_List &p_regnd = *blk2regnd[pb->_pre_order];
 494         for( uint k = 0; k < (uint)_max_reg; k++ ) {
 495           if( regnd[k] != p_regnd[k] ) { // Conflict on reaching defs?
 496             value.map(k,NULL); // Then no value handy
 497             regnd.map(k,NULL);
 498           }
 499         }
 500       }
 501     }
 502 
 503     // For all Phi's
 504     for( j = 1; j < phi_dex; j++ ) {
 505       uint k;
 506       Node *phi = b->_nodes[j];
 507       uint pidx = _lrg_map.live_range_id(phi);
 508       OptoReg::Name preg = lrgs(_lrg_map.live_range_id(phi)).reg();
 509 
 510       // Remove copies remaining on edges.  Check for junk phi.
 511       Node *u = NULL;
 512       for (k = 1; k < phi->req(); k++) {
 513         Node *x = phi->in(k);
 514         if( phi != x && u != x ) // Found a different input
 515           u = u ? NodeSentinel : x; // Capture unique input, or NodeSentinel for 2nd input
 516       }
 517       if( u != NodeSentinel ) {    // Junk Phi.  Remove
 518         b->_nodes.remove(j--); phi_dex--;
 519         _cfg._bbs.map(phi->_idx,NULL);

 520         phi->replace_by(u);
 521         phi->disconnect_inputs(NULL, C);
 522         continue;
 523       }
 524       // Note that if value[pidx] exists, then we merged no new values here
 525       // and the phi is useless.  This can happen even with the above phi
 526       // removal for complex flows.  I cannot keep the better known value here
 527       // because locally the phi appears to define a new merged value.  If I
 528       // keep the better value then a copy of the phi, being unable to use the
 529       // global flow analysis, can't "peek through" the phi to the original
 530       // reaching value and so will act like it's defining a new value.  This
 531       // can lead to situations where some uses are from the old and some from
 532       // the new values.  Not illegal by itself but throws the over-strong
 533       // assert in scheduling.
 534       if( pidx ) {
 535         value.map(preg,phi);
 536         regnd.map(preg,phi);
 537         int n_regs = RegMask::num_registers(phi->ideal_reg());
 538         for (int l = 1; l < n_regs; l++) {
 539           OptoReg::Name preg_lo = OptoReg::add(preg,-l);




  61     if( def->is_Copy() )        // Copies carry value through
  62       def = def->in(def->is_Copy());
  63     else if( def->is_Phi() )    // Phis can merge it from any direction
  64       def = def->in(1);
  65     else
  66       break;
  67     guarantee(def != NULL, "must not resurrect dead copy");
  68   }
  69   // If we reached the end and didn't find a callee save proj
  70   // then this may be a callee save proj so we return true
  71   // as the conservative answer. If we didn't reach then end
  72   // we must have discovered that it was not a callee save
  73   // else we would have returned.
  74   return i == limit;
  75 }
  76 
  77 //------------------------------yank-----------------------------------
  78 // Helper function for yank_if_dead
  79 int PhaseChaitin::yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) {
  80   int blk_adjust=0;
  81   Block *oldb = _cfg.get_block_for_node(old);
  82   oldb->find_remove(old);
  83   // Count 1 if deleting an instruction from the current block
  84   if (oldb == current_block) {
  85     blk_adjust++;
  86   }
  87   _cfg.unmap_node_from_block(old);
  88   OptoReg::Name old_reg = lrgs(_lrg_map.live_range_id(old)).reg();
  89   if( regnd && (*regnd)[old_reg]==old ) { // Instruction is currently available?
  90     value->map(old_reg,NULL);  // Yank from value/regnd maps
  91     regnd->map(old_reg,NULL);  // This register's value is now unknown
  92   }
  93   return blk_adjust;
  94 }
  95 
  96 #ifdef ASSERT
  97 static bool expected_yanked_node(Node *old, Node *orig_old) {
  98   // This code is expected only next original nodes:
  99   // - load from constant table node which may have next data input nodes:
 100   //     MachConstantBase, Phi, MachTemp, MachSpillCopy
 101   // - load constant node which may have next data input nodes:
 102   //     MachTemp, MachSpillCopy
 103   // - MachSpillCopy
 104   // - MachProj and Copy dead nodes
 105   if (old->is_MachSpillCopy()) {
 106     return true;
 107   } else if (old->is_Con()) {


 418 
 419   // For all blocks
 420   for( uint i = 0; i < _cfg._num_blocks; i++ ) {
 421     uint j;
 422     Block *b = _cfg._blocks[i];
 423 
 424     // Count of Phis in block
 425     uint phi_dex;
 426     for( phi_dex = 1; phi_dex < b->_nodes.size(); phi_dex++ ) {
 427       Node *phi = b->_nodes[phi_dex];
 428       if( !phi->is_Phi() )
 429         break;
 430     }
 431 
 432     // If any predecessor has not been visited, we do not know the state
 433     // of registers at the start.  Check for this, while updating copies
 434     // along Phi input edges
 435     bool missing_some_inputs = false;
 436     Block *freed = NULL;
 437     for( j = 1; j < b->num_preds(); j++ ) {
 438       Block *pb = _cfg.get_block_for_node(b->pred(j));
 439       // Remove copies along phi edges
 440       for( uint k=1; k<phi_dex; k++ )
 441         elide_copy( b->_nodes[k], j, b, *blk2value[pb->_pre_order], *blk2regnd[pb->_pre_order], false );
 442       if( blk2value[pb->_pre_order] ) { // Have a mapping on this edge?
 443         // See if this predecessor's mappings have been used by everybody
 444         // who wants them.  If so, free 'em.
 445         uint k;
 446         for( k=0; k<pb->_num_succs; k++ ) {
 447           Block *pbsucc = pb->_succs[k];
 448           if( !blk2value[pbsucc->_pre_order] && pbsucc != b )
 449             break;              // Found a future user
 450         }
 451         if( k >= pb->_num_succs ) { // No more uses, free!
 452           freed = pb;           // Record last block freed
 453           free_list.push(blk2value[pb->_pre_order]);
 454           free_list.push(blk2regnd[pb->_pre_order]);
 455         }
 456       } else {                  // This block has unvisited (loopback) inputs
 457         missing_some_inputs = true;
 458       }


 463     // 'freed's blocks off the list
 464     Node_List &regnd = *(free_list.is_empty() ? new Node_List() : free_list.pop());
 465     Node_List &value = *(free_list.is_empty() ? new Node_List() : free_list.pop());
 466     assert( !freed || blk2value[freed->_pre_order] == &value, "" );
 467     value.map(_max_reg,NULL);
 468     regnd.map(_max_reg,NULL);
 469     // Set mappings as OUR mappings
 470     blk2value[b->_pre_order] = &value;
 471     blk2regnd[b->_pre_order] = &regnd;
 472 
 473     // Initialize value & regnd for this block
 474     if( missing_some_inputs ) {
 475       // Some predecessor has not yet been visited; zap map to empty
 476       for( uint k = 0; k < (uint)_max_reg; k++ ) {
 477         value.map(k,NULL);
 478         regnd.map(k,NULL);
 479       }
 480     } else {
 481       if( !freed ) {            // Didn't get a freebie prior block
 482         // Must clone some data
 483         freed = _cfg.get_block_for_node(b->pred(1));
 484         Node_List &f_value = *blk2value[freed->_pre_order];
 485         Node_List &f_regnd = *blk2regnd[freed->_pre_order];
 486         for( uint k = 0; k < (uint)_max_reg; k++ ) {
 487           value.map(k,f_value[k]);
 488           regnd.map(k,f_regnd[k]);
 489         }
 490       }
 491       // Merge all inputs together, setting to NULL any conflicts.
 492       for( j = 1; j < b->num_preds(); j++ ) {
 493         Block *pb = _cfg.get_block_for_node(b->pred(j));
 494         if( pb == freed ) continue; // Did self already via freelist
 495         Node_List &p_regnd = *blk2regnd[pb->_pre_order];
 496         for( uint k = 0; k < (uint)_max_reg; k++ ) {
 497           if( regnd[k] != p_regnd[k] ) { // Conflict on reaching defs?
 498             value.map(k,NULL); // Then no value handy
 499             regnd.map(k,NULL);
 500           }
 501         }
 502       }
 503     }
 504 
 505     // For all Phi's
 506     for( j = 1; j < phi_dex; j++ ) {
 507       uint k;
 508       Node *phi = b->_nodes[j];
 509       uint pidx = _lrg_map.live_range_id(phi);
 510       OptoReg::Name preg = lrgs(_lrg_map.live_range_id(phi)).reg();
 511 
 512       // Remove copies remaining on edges.  Check for junk phi.
 513       Node *u = NULL;
 514       for (k = 1; k < phi->req(); k++) {
 515         Node *x = phi->in(k);
 516         if( phi != x && u != x ) // Found a different input
 517           u = u ? NodeSentinel : x; // Capture unique input, or NodeSentinel for 2nd input
 518       }
 519       if( u != NodeSentinel ) {    // Junk Phi.  Remove
 520         b->_nodes.remove(j--);
 521         phi_dex--;
 522         _cfg.unmap_node_from_block(phi);
 523         phi->replace_by(u);
 524         phi->disconnect_inputs(NULL, C);
 525         continue;
 526       }
 527       // Note that if value[pidx] exists, then we merged no new values here
 528       // and the phi is useless.  This can happen even with the above phi
 529       // removal for complex flows.  I cannot keep the better known value here
 530       // because locally the phi appears to define a new merged value.  If I
 531       // keep the better value then a copy of the phi, being unable to use the
 532       // global flow analysis, can't "peek through" the phi to the original
 533       // reaching value and so will act like it's defining a new value.  This
 534       // can lead to situations where some uses are from the old and some from
 535       // the new values.  Not illegal by itself but throws the over-strong
 536       // assert in scheduling.
 537       if( pidx ) {
 538         value.map(preg,phi);
 539         regnd.map(preg,phi);
 540         int n_regs = RegMask::num_registers(phi->ideal_reg());
 541         for (int l = 1; l < n_regs; l++) {
 542           OptoReg::Name preg_lo = OptoReg::add(preg,-l);


src/share/vm/opto/postaloc.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File