hotspot/src/share/vm/opto/lcm.cpp
changeset 22828 17ecb098bc1e
parent 22807 1cf02ef734e2
parent 19330 49d6711171e6
child 22838 82c7497fbad4
equal deleted inserted replaced
22827:07d991d45a51 22828:17ecb098bc1e
   238           continue;             // Give up is reference is beyond 4K page size
   238           continue;             // Give up is reference is beyond 4K page size
   239       }
   239       }
   240     }
   240     }
   241 
   241 
   242     // Check ctrl input to see if the null-check dominates the memory op
   242     // Check ctrl input to see if the null-check dominates the memory op
   243     Block *cb = cfg->_bbs[mach->_idx];
   243     Block *cb = cfg->get_block_for_node(mach);
   244     cb = cb->_idom;             // Always hoist at least 1 block
   244     cb = cb->_idom;             // Always hoist at least 1 block
   245     if( !was_store ) {          // Stores can be hoisted only one block
   245     if( !was_store ) {          // Stores can be hoisted only one block
   246       while( cb->_dom_depth > (_dom_depth + 1))
   246       while( cb->_dom_depth > (_dom_depth + 1))
   247         cb = cb->_idom;         // Hoist loads as far as we want
   247         cb = cb->_idom;         // Hoist loads as far as we want
   248       // The non-null-block should dominate the memory op, too. Live
   248       // The non-null-block should dominate the memory op, too. Live
   263         vidx = j;
   263         vidx = j;
   264         // Ignore DecodeN val which could be hoisted to where needed.
   264         // Ignore DecodeN val which could be hoisted to where needed.
   265         if( is_decoden ) continue;
   265         if( is_decoden ) continue;
   266       }
   266       }
   267       // Block of memory-op input
   267       // Block of memory-op input
   268       Block *inb = cfg->_bbs[mach->in(j)->_idx];
   268       Block *inb = cfg->get_block_for_node(mach->in(j));
   269       Block *b = this;          // Start from nul check
   269       Block *b = this;          // Start from nul check
   270       while( b != inb && b->_dom_depth > inb->_dom_depth )
   270       while( b != inb && b->_dom_depth > inb->_dom_depth )
   271         b = b->_idom;           // search upwards for input
   271         b = b->_idom;           // search upwards for input
   272       // See if input dominates null check
   272       // See if input dominates null check
   273       if( b != inb )
   273       if( b != inb )
   274         break;
   274         break;
   275     }
   275     }
   276     if( j > 0 )
   276     if( j > 0 )
   277       continue;
   277       continue;
   278     Block *mb = cfg->_bbs[mach->_idx];
   278     Block *mb = cfg->get_block_for_node(mach);
   279     // Hoisting stores requires more checks for the anti-dependence case.
   279     // Hoisting stores requires more checks for the anti-dependence case.
   280     // Give up hoisting if we have to move the store past any load.
   280     // Give up hoisting if we have to move the store past any load.
   281     if( was_store ) {
   281     if( was_store ) {
   282       Block *b = mb;            // Start searching here for a local load
   282       Block *b = mb;            // Start searching here for a local load
   283       // mach use (faulting) trying to hoist
   283       // mach use (faulting) trying to hoist
   292         }
   292         }
   293         if( k < b->_nodes.size() )
   293         if( k < b->_nodes.size() )
   294           break;                // Found anti-dependent load
   294           break;                // Found anti-dependent load
   295         // Make sure control does not do a merge (would have to check allpaths)
   295         // Make sure control does not do a merge (would have to check allpaths)
   296         if( b->num_preds() != 2 ) break;
   296         if( b->num_preds() != 2 ) break;
   297         b = cfg->_bbs[b->pred(1)->_idx]; // Move up to predecessor block
   297         b = cfg->get_block_for_node(b->pred(1)); // Move up to predecessor block
   298       }
   298       }
   299       if( b != this ) continue;
   299       if( b != this ) continue;
   300     }
   300     }
   301 
   301 
   302     // Make sure this memory op is not already being used for a NullCheck
   302     // Make sure this memory op is not already being used for a NullCheck
   304     if( e->is_MachNullCheck() && e->in(1) == mach )
   304     if( e->is_MachNullCheck() && e->in(1) == mach )
   305       continue;                 // Already being used as a NULL check
   305       continue;                 // Already being used as a NULL check
   306 
   306 
   307     // Found a candidate!  Pick one with least dom depth - the highest
   307     // Found a candidate!  Pick one with least dom depth - the highest
   308     // in the dom tree should be closest to the null check.
   308     // in the dom tree should be closest to the null check.
   309     if( !best ||
   309     if (best == NULL || cfg->get_block_for_node(mach)->_dom_depth < cfg->get_block_for_node(best)->_dom_depth) {
   310         cfg->_bbs[mach->_idx]->_dom_depth < cfg->_bbs[best->_idx]->_dom_depth ) {
       
   311       best = mach;
   310       best = mach;
   312       bidx = vidx;
   311       bidx = vidx;
   313 
       
   314     }
   312     }
   315   }
   313   }
   316   // No candidate!
   314   // No candidate!
   317   if( !best ) return;
   315   if (best == NULL) {
       
   316     return;
       
   317   }
   318 
   318 
   319   // ---- Found an implicit null check
   319   // ---- Found an implicit null check
   320   extern int implicit_null_checks;
   320   extern int implicit_null_checks;
   321   implicit_null_checks++;
   321   implicit_null_checks++;
   322 
   322 
   323   if( is_decoden ) {
   323   if( is_decoden ) {
   324     // Check if we need to hoist decodeHeapOop_not_null first.
   324     // Check if we need to hoist decodeHeapOop_not_null first.
   325     Block *valb = cfg->_bbs[val->_idx];
   325     Block *valb = cfg->get_block_for_node(val);
   326     if( this != valb && this->_dom_depth < valb->_dom_depth ) {
   326     if( this != valb && this->_dom_depth < valb->_dom_depth ) {
   327       // Hoist it up to the end of the test block.
   327       // Hoist it up to the end of the test block.
   328       valb->find_remove(val);
   328       valb->find_remove(val);
   329       this->add_inst(val);
   329       this->add_inst(val);
   330       cfg->_bbs.map(val->_idx,this);
   330       cfg->map_node_to_block(val, this);
   331       // DecodeN on x86 may kill flags. Check for flag-killing projections
   331       // DecodeN on x86 may kill flags. Check for flag-killing projections
   332       // that also need to be hoisted.
   332       // that also need to be hoisted.
   333       for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
   333       for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
   334         Node* n = val->fast_out(j);
   334         Node* n = val->fast_out(j);
   335         if( n->is_MachProj() ) {
   335         if( n->is_MachProj() ) {
   336           cfg->_bbs[n->_idx]->find_remove(n);
   336           cfg->get_block_for_node(n)->find_remove(n);
   337           this->add_inst(n);
   337           this->add_inst(n);
   338           cfg->_bbs.map(n->_idx,this);
   338           cfg->map_node_to_block(n, this);
   339         }
   339         }
   340       }
   340       }
   341     }
   341     }
   342   }
   342   }
   343   // Hoist the memory candidate up to the end of the test block.
   343   // Hoist the memory candidate up to the end of the test block.
   344   Block *old_block = cfg->_bbs[best->_idx];
   344   Block *old_block = cfg->get_block_for_node(best);
   345   old_block->find_remove(best);
   345   old_block->find_remove(best);
   346   add_inst(best);
   346   add_inst(best);
   347   cfg->_bbs.map(best->_idx,this);
   347   cfg->map_node_to_block(best, this);
   348 
   348 
   349   // Move the control dependence
   349   // Move the control dependence
   350   if (best->in(0) && best->in(0) == old_block->_nodes[0])
   350   if (best->in(0) && best->in(0) == old_block->_nodes[0])
   351     best->set_req(0, _nodes[0]);
   351     best->set_req(0, _nodes[0]);
   352 
   352 
   353   // Check for flag-killing projections that also need to be hoisted
   353   // Check for flag-killing projections that also need to be hoisted
   354   // Should be DU safe because no edge updates.
   354   // Should be DU safe because no edge updates.
   355   for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
   355   for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
   356     Node* n = best->fast_out(j);
   356     Node* n = best->fast_out(j);
   357     if( n->is_MachProj() ) {
   357     if( n->is_MachProj() ) {
   358       cfg->_bbs[n->_idx]->find_remove(n);
   358       cfg->get_block_for_node(n)->find_remove(n);
   359       add_inst(n);
   359       add_inst(n);
   360       cfg->_bbs.map(n->_idx,this);
   360       cfg->map_node_to_block(n, this);
   361     }
   361     }
   362   }
   362   }
   363 
   363 
   364   Compile *C = cfg->C;
   364   Compile *C = cfg->C;
   365   // proj==Op_True --> ne test; proj==Op_False --> eq test.
   365   // proj==Op_True --> ne test; proj==Op_False --> eq test.
   386   // Since schedule-local needs precise def-use info, we need to correct
   386   // Since schedule-local needs precise def-use info, we need to correct
   387   // it as well.
   387   // it as well.
   388   Node *old_tst = proj->in(0);
   388   Node *old_tst = proj->in(0);
   389   MachNode *nul_chk = new (C) MachNullCheckNode(old_tst->in(0),best,bidx);
   389   MachNode *nul_chk = new (C) MachNullCheckNode(old_tst->in(0),best,bidx);
   390   _nodes.map(end_idx(),nul_chk);
   390   _nodes.map(end_idx(),nul_chk);
   391   cfg->_bbs.map(nul_chk->_idx,this);
   391   cfg->map_node_to_block(nul_chk, this);
   392   // Redirect users of old_test to nul_chk
   392   // Redirect users of old_test to nul_chk
   393   for (DUIterator_Last i2min, i2 = old_tst->last_outs(i2min); i2 >= i2min; --i2)
   393   for (DUIterator_Last i2min, i2 = old_tst->last_outs(i2min); i2 >= i2min; --i2)
   394     old_tst->last_out(i2)->set_req(0, nul_chk);
   394     old_tst->last_out(i2)->set_req(0, nul_chk);
   395   // Clean-up any dead code
   395   // Clean-up any dead code
   396   for (uint i3 = 0; i3 < old_tst->req(); i3++)
   396   for (uint i3 = 0; i3 < old_tst->req(); i3++)
   469 
   469 
   470       for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
   470       for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
   471         Node* use = n->fast_out(j);
   471         Node* use = n->fast_out(j);
   472 
   472 
   473         // The use is a conditional branch, make them adjacent
   473         // The use is a conditional branch, make them adjacent
   474         if (use->is_MachIf() && cfg->_bbs[use->_idx]==this ) {
   474         if (use->is_MachIf() && cfg->get_block_for_node(use) == this) {
   475           found_machif = true;
   475           found_machif = true;
   476           break;
   476           break;
   477         }
   477         }
   478 
   478 
   479         // More than this instruction pending for successor to be ready,
   479         // More than this instruction pending for successor to be ready,
   502     // MachTemps should be scheduled last so they are near their uses
   502     // MachTemps should be scheduled last so they are near their uses
   503     if (n->is_MachTemp()) {
   503     if (n->is_MachTemp()) {
   504       n_choice = 1;
   504       n_choice = 1;
   505     }
   505     }
   506 
   506 
   507     uint n_latency = cfg->_node_latency->at_grow(n->_idx);
   507     uint n_latency = cfg->get_latency_for_node(n);
   508     uint n_score   = n->req();   // Many inputs get high score to break ties
   508     uint n_score   = n->req();   // Many inputs get high score to break ties
   509 
   509 
   510     // Keep best latency found
   510     // Keep best latency found
   511     cand_cnt++;
   511     cand_cnt++;
   512     if (choice < n_choice ||
   512     if (choice < n_choice ||
   530   return n;
   530   return n;
   531 }
   531 }
   532 
   532 
   533 
   533 
   534 //------------------------------set_next_call----------------------------------
   534 //------------------------------set_next_call----------------------------------
   535 void Block::set_next_call( Node *n, VectorSet &next_call, Block_Array &bbs ) {
   535 void Block::set_next_call( Node *n, VectorSet &next_call, PhaseCFG* cfg) {
   536   if( next_call.test_set(n->_idx) ) return;
   536   if( next_call.test_set(n->_idx) ) return;
   537   for( uint i=0; i<n->len(); i++ ) {
   537   for( uint i=0; i<n->len(); i++ ) {
   538     Node *m = n->in(i);
   538     Node *m = n->in(i);
   539     if( !m ) continue;  // must see all nodes in block that precede call
   539     if( !m ) continue;  // must see all nodes in block that precede call
   540     if( bbs[m->_idx] == this )
   540     if (cfg->get_block_for_node(m) == this) {
   541       set_next_call( m, next_call, bbs );
   541       set_next_call(m, next_call, cfg);
       
   542     }
   542   }
   543   }
   543 }
   544 }
   544 
   545 
   545 //------------------------------needed_for_next_call---------------------------
   546 //------------------------------needed_for_next_call---------------------------
   546 // Set the flag 'next_call' for each Node that is needed for the next call to
   547 // Set the flag 'next_call' for each Node that is needed for the next call to
   547 // be scheduled.  This flag lets me bias scheduling so Nodes needed for the
   548 // be scheduled.  This flag lets me bias scheduling so Nodes needed for the
   548 // next subroutine call get priority - basically it moves things NOT needed
   549 // next subroutine call get priority - basically it moves things NOT needed
   549 // for the next call till after the call.  This prevents me from trying to
   550 // for the next call till after the call.  This prevents me from trying to
   550 // carry lots of stuff live across a call.
   551 // carry lots of stuff live across a call.
   551 void Block::needed_for_next_call(Node *this_call, VectorSet &next_call, Block_Array &bbs) {
   552 void Block::needed_for_next_call(Node *this_call, VectorSet &next_call, PhaseCFG* cfg) {
   552   // Find the next control-defining Node in this block
   553   // Find the next control-defining Node in this block
   553   Node* call = NULL;
   554   Node* call = NULL;
   554   for (DUIterator_Fast imax, i = this_call->fast_outs(imax); i < imax; i++) {
   555   for (DUIterator_Fast imax, i = this_call->fast_outs(imax); i < imax; i++) {
   555     Node* m = this_call->fast_out(i);
   556     Node* m = this_call->fast_out(i);
   556     if( bbs[m->_idx] == this && // Local-block user
   557     if(cfg->get_block_for_node(m) == this && // Local-block user
   557         m != this_call &&       // Not self-start node
   558         m != this_call &&       // Not self-start node
   558         m->is_MachCall() )
   559         m->is_MachCall() )
   559       call = m;
   560       call = m;
   560       break;
   561       break;
   561   }
   562   }
   562   if (call == NULL)  return;    // No next call (e.g., block end is near)
   563   if (call == NULL)  return;    // No next call (e.g., block end is near)
   563   // Set next-call for all inputs to this call
   564   // Set next-call for all inputs to this call
   564   set_next_call(call, next_call, bbs);
   565   set_next_call(call, next_call, cfg);
   565 }
   566 }
   566 
   567 
   567 //------------------------------add_call_kills-------------------------------------
   568 //------------------------------add_call_kills-------------------------------------
   568 void Block::add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe) {
   569 void Block::add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe) {
   569   // Fill in the kill mask for the call
   570   // Fill in the kill mask for the call
   579   }
   580   }
   580 }
   581 }
   581 
   582 
   582 
   583 
   583 //------------------------------sched_call-------------------------------------
   584 //------------------------------sched_call-------------------------------------
   584 uint Block::sched_call( Matcher &matcher, Block_Array &bbs, uint node_cnt, Node_List &worklist, GrowableArray<int> &ready_cnt, MachCallNode *mcall, VectorSet &next_call ) {
   585 uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_List &worklist, GrowableArray<int> &ready_cnt, MachCallNode *mcall, VectorSet &next_call ) {
   585   RegMask regs;
   586   RegMask regs;
   586 
   587 
   587   // Schedule all the users of the call right now.  All the users are
   588   // Schedule all the users of the call right now.  All the users are
   588   // projection Nodes, so they must be scheduled next to the call.
   589   // projection Nodes, so they must be scheduled next to the call.
   589   // Collect all the defined registers.
   590   // Collect all the defined registers.
   598     // Collect defined registers
   599     // Collect defined registers
   599     regs.OR(n->out_RegMask());
   600     regs.OR(n->out_RegMask());
   600     // Check for scheduling the next control-definer
   601     // Check for scheduling the next control-definer
   601     if( n->bottom_type() == Type::CONTROL )
   602     if( n->bottom_type() == Type::CONTROL )
   602       // Warm up next pile of heuristic bits
   603       // Warm up next pile of heuristic bits
   603       needed_for_next_call(n, next_call, bbs);
   604       needed_for_next_call(n, next_call, cfg);
   604 
   605 
   605     // Children of projections are now all ready
   606     // Children of projections are now all ready
   606     for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
   607     for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
   607       Node* m = n->fast_out(j); // Get user
   608       Node* m = n->fast_out(j); // Get user
   608       if( bbs[m->_idx] != this ) continue;
   609       if(cfg->get_block_for_node(m) != this) {
       
   610         continue;
       
   611       }
   609       if( m->is_Phi() ) continue;
   612       if( m->is_Phi() ) continue;
   610       int m_cnt = ready_cnt.at(m->_idx)-1;
   613       int m_cnt = ready_cnt.at(m->_idx)-1;
   611       ready_cnt.at_put(m->_idx, m_cnt);
   614       ready_cnt.at_put(m->_idx, m_cnt);
   612       if( m_cnt == 0 )
   615       if( m_cnt == 0 )
   613         worklist.push(m);
   616         worklist.push(m);
   621 
   624 
   622   // Set all registers killed and not already defined by the call.
   625   // Set all registers killed and not already defined by the call.
   623   uint r_cnt = mcall->tf()->range()->cnt();
   626   uint r_cnt = mcall->tf()->range()->cnt();
   624   int op = mcall->ideal_Opcode();
   627   int op = mcall->ideal_Opcode();
   625   MachProjNode *proj = new (matcher.C) MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
   628   MachProjNode *proj = new (matcher.C) MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
   626   bbs.map(proj->_idx,this);
   629   cfg->map_node_to_block(proj, this);
   627   _nodes.insert(node_cnt++, proj);
   630   _nodes.insert(node_cnt++, proj);
   628 
   631 
   629   // Select the right register save policy.
   632   // Select the right register save policy.
   630   const char * save_policy;
   633   const char * save_policy;
   631   switch (op) {
   634   switch (op) {
   709       // Count block-local inputs to 'n'
   712       // Count block-local inputs to 'n'
   710       uint cnt = n->len();      // Input count
   713       uint cnt = n->len();      // Input count
   711       uint local = 0;
   714       uint local = 0;
   712       for( uint j=0; j<cnt; j++ ) {
   715       for( uint j=0; j<cnt; j++ ) {
   713         Node *m = n->in(j);
   716         Node *m = n->in(j);
   714         if( m && cfg->_bbs[m->_idx] == this && !m->is_top() )
   717         if( m && cfg->get_block_for_node(m) == this && !m->is_top() )
   715           local++;              // One more block-local input
   718           local++;              // One more block-local input
   716       }
   719       }
   717       ready_cnt.at_put(n->_idx, local); // Count em up
   720       ready_cnt.at_put(n->_idx, local); // Count em up
   718 
   721 
   719 #ifdef ASSERT
   722 #ifdef ASSERT
   721         if( n->is_Mach() && n->as_Mach()->ideal_Opcode() == Op_StoreCM ) {
   724         if( n->is_Mach() && n->as_Mach()->ideal_Opcode() == Op_StoreCM ) {
   722           // Check the precedence edges
   725           // Check the precedence edges
   723           for (uint prec = n->req(); prec < n->len(); prec++) {
   726           for (uint prec = n->req(); prec < n->len(); prec++) {
   724             Node* oop_store = n->in(prec);
   727             Node* oop_store = n->in(prec);
   725             if (oop_store != NULL) {
   728             if (oop_store != NULL) {
   726               assert(cfg->_bbs[oop_store->_idx]->_dom_depth <= this->_dom_depth, "oop_store must dominate card-mark");
   729               assert(cfg->get_block_for_node(oop_store)->_dom_depth <= this->_dom_depth, "oop_store must dominate card-mark");
   727             }
   730             }
   728           }
   731           }
   729         }
   732         }
   730       }
   733       }
   731 #endif
   734 #endif
   754   uint i3;
   757   uint i3;
   755   for(i3 = 0; i3<phi_cnt; i3++ ) {  // For all pre-scheduled
   758   for(i3 = 0; i3<phi_cnt; i3++ ) {  // For all pre-scheduled
   756     Node *n = _nodes[i3];       // Get pre-scheduled
   759     Node *n = _nodes[i3];       // Get pre-scheduled
   757     for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
   760     for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
   758       Node* m = n->fast_out(j);
   761       Node* m = n->fast_out(j);
   759       if( cfg->_bbs[m->_idx] ==this ) { // Local-block user
   762       if (cfg->get_block_for_node(m) == this) { // Local-block user
   760         int m_cnt = ready_cnt.at(m->_idx)-1;
   763         int m_cnt = ready_cnt.at(m->_idx)-1;
   761         ready_cnt.at_put(m->_idx, m_cnt);   // Fix ready count
   764         ready_cnt.at_put(m->_idx, m_cnt);   // Fix ready count
   762       }
   765       }
   763     }
   766     }
   764   }
   767   }
   787     Node* d = delay.pop();
   790     Node* d = delay.pop();
   788     worklist.push(d);
   791     worklist.push(d);
   789   }
   792   }
   790 
   793 
   791   // Warm up the 'next_call' heuristic bits
   794   // Warm up the 'next_call' heuristic bits
   792   needed_for_next_call(_nodes[0], next_call, cfg->_bbs);
   795   needed_for_next_call(_nodes[0], next_call, cfg);
   793 
   796 
   794 #ifndef PRODUCT
   797 #ifndef PRODUCT
   795     if (cfg->trace_opto_pipelining()) {
   798     if (cfg->trace_opto_pipelining()) {
   796       for (uint j=0; j<_nodes.size(); j++) {
   799       for (uint j=0; j<_nodes.size(); j++) {
   797         Node     *n = _nodes[j];
   800         Node     *n = _nodes[j];
   798         int     idx = n->_idx;
   801         int     idx = n->_idx;
   799         tty->print("#   ready cnt:%3d  ", ready_cnt.at(idx));
   802         tty->print("#   ready cnt:%3d  ", ready_cnt.at(idx));
   800         tty->print("latency:%3d  ", cfg->_node_latency->at_grow(idx));
   803         tty->print("latency:%3d  ", cfg->get_latency_for_node(n));
   801         tty->print("%4d: %s\n", idx, n->Name());
   804         tty->print("%4d: %s\n", idx, n->Name());
   802       }
   805       }
   803     }
   806     }
   804 #endif
   807 #endif
   805 
   808 
   823     _nodes.map(phi_cnt++,n);    // Schedule him next
   826     _nodes.map(phi_cnt++,n);    // Schedule him next
   824 
   827 
   825 #ifndef PRODUCT
   828 #ifndef PRODUCT
   826     if (cfg->trace_opto_pipelining()) {
   829     if (cfg->trace_opto_pipelining()) {
   827       tty->print("#    select %d: %s", n->_idx, n->Name());
   830       tty->print("#    select %d: %s", n->_idx, n->Name());
   828       tty->print(", latency:%d", cfg->_node_latency->at_grow(n->_idx));
   831       tty->print(", latency:%d", cfg->get_latency_for_node(n));
   829       n->dump();
   832       n->dump();
   830       if (Verbose) {
   833       if (Verbose) {
   831         tty->print("#   ready list:");
   834         tty->print("#   ready list:");
   832         for( uint i=0; i<worklist.size(); i++ ) { // Inspect entire worklist
   835         for( uint i=0; i<worklist.size(); i++ ) { // Inspect entire worklist
   833           Node *n = worklist[i];      // Get Node on worklist
   836           Node *n = worklist[i];      // Get Node on worklist
   838     }
   841     }
   839 
   842 
   840 #endif
   843 #endif
   841     if( n->is_MachCall() ) {
   844     if( n->is_MachCall() ) {
   842       MachCallNode *mcall = n->as_MachCall();
   845       MachCallNode *mcall = n->as_MachCall();
   843       phi_cnt = sched_call(matcher, cfg->_bbs, phi_cnt, worklist, ready_cnt, mcall, next_call);
   846       phi_cnt = sched_call(matcher, cfg, phi_cnt, worklist, ready_cnt, mcall, next_call);
   844       continue;
   847       continue;
   845     }
   848     }
   846 
   849 
   847     if (n->is_Mach() && n->as_Mach()->has_call()) {
   850     if (n->is_Mach() && n->as_Mach()->has_call()) {
   848       RegMask regs;
   851       RegMask regs;
   849       regs.Insert(matcher.c_frame_pointer());
   852       regs.Insert(matcher.c_frame_pointer());
   850       regs.OR(n->out_RegMask());
   853       regs.OR(n->out_RegMask());
   851 
   854 
   852       MachProjNode *proj = new (matcher.C) MachProjNode( n, 1, RegMask::Empty, MachProjNode::fat_proj );
   855       MachProjNode *proj = new (matcher.C) MachProjNode( n, 1, RegMask::Empty, MachProjNode::fat_proj );
   853       cfg->_bbs.map(proj->_idx,this);
   856       cfg->map_node_to_block(proj, this);
   854       _nodes.insert(phi_cnt++, proj);
   857       _nodes.insert(phi_cnt++, proj);
   855 
   858 
   856       add_call_kills(proj, regs, matcher._c_reg_save_policy, false);
   859       add_call_kills(proj, regs, matcher._c_reg_save_policy, false);
   857     }
   860     }
   858 
   861 
   859     // Children are now all ready
   862     // Children are now all ready
   860     for (DUIterator_Fast i5max, i5 = n->fast_outs(i5max); i5 < i5max; i5++) {
   863     for (DUIterator_Fast i5max, i5 = n->fast_outs(i5max); i5 < i5max; i5++) {
   861       Node* m = n->fast_out(i5); // Get user
   864       Node* m = n->fast_out(i5); // Get user
   862       if( cfg->_bbs[m->_idx] != this ) continue;
   865       if (cfg->get_block_for_node(m) != this) {
       
   866         continue;
       
   867       }
   863       if( m->is_Phi() ) continue;
   868       if( m->is_Phi() ) continue;
   864       if (m->_idx >= max_idx) { // new node, skip it
   869       if (m->_idx >= max_idx) { // new node, skip it
   865         assert(m->is_MachProj() && n->is_Mach() && n->as_Mach()->has_call(), "unexpected node types");
   870         assert(m->is_MachProj() && n->is_Mach() && n->as_Mach()->has_call(), "unexpected node types");
   866         continue;
   871         continue;
   867       }
   872       }
   915     }
   920     }
   916   }
   921   }
   917 }
   922 }
   918 
   923 
   919 //------------------------------catch_cleanup_find_cloned_def------------------
   924 //------------------------------catch_cleanup_find_cloned_def------------------
   920 static Node *catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def_blk, Block_Array &bbs, int n_clone_idx) {
   925 static Node *catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def_blk, PhaseCFG* cfg, int n_clone_idx) {
   921   assert( use_blk != def_blk, "Inter-block cleanup only");
   926   assert( use_blk != def_blk, "Inter-block cleanup only");
   922 
   927 
   923   // The use is some block below the Catch.  Find and return the clone of the def
   928   // The use is some block below the Catch.  Find and return the clone of the def
   924   // that dominates the use. If there is no clone in a dominating block, then
   929   // that dominates the use. If there is no clone in a dominating block, then
   925   // create a phi for the def in a dominating block.
   930   // create a phi for the def in a dominating block.
   941   if( j == def_blk->_num_succs ) {
   946   if( j == def_blk->_num_succs ) {
   942     // Block at same level in dom-tree is not a successor.  It needs a
   947     // Block at same level in dom-tree is not a successor.  It needs a
   943     // PhiNode, the PhiNode uses from the def and IT's uses need fixup.
   948     // PhiNode, the PhiNode uses from the def and IT's uses need fixup.
   944     Node_Array inputs = new Node_List(Thread::current()->resource_area());
   949     Node_Array inputs = new Node_List(Thread::current()->resource_area());
   945     for(uint k = 1; k < use_blk->num_preds(); k++) {
   950     for(uint k = 1; k < use_blk->num_preds(); k++) {
   946       inputs.map(k, catch_cleanup_find_cloned_def(bbs[use_blk->pred(k)->_idx], def, def_blk, bbs, n_clone_idx));
   951       Block* block = cfg->get_block_for_node(use_blk->pred(k));
       
   952       inputs.map(k, catch_cleanup_find_cloned_def(block, def, def_blk, cfg, n_clone_idx));
   947     }
   953     }
   948 
   954 
   949     // Check to see if the use_blk already has an identical phi inserted.
   955     // Check to see if the use_blk already has an identical phi inserted.
   950     // If it exists, it will be at the first position since all uses of a
   956     // If it exists, it will be at the first position since all uses of a
   951     // def are processed together.
   957     // def are processed together.
   963 
   969 
   964     // If an existing PhiNode was not found, make a new one.
   970     // If an existing PhiNode was not found, make a new one.
   965     if (fixup == NULL) {
   971     if (fixup == NULL) {
   966       Node *new_phi = PhiNode::make(use_blk->head(), def);
   972       Node *new_phi = PhiNode::make(use_blk->head(), def);
   967       use_blk->_nodes.insert(1, new_phi);
   973       use_blk->_nodes.insert(1, new_phi);
   968       bbs.map(new_phi->_idx, use_blk);
   974       cfg->map_node_to_block(new_phi, use_blk);
   969       for (uint k = 1; k < use_blk->num_preds(); k++) {
   975       for (uint k = 1; k < use_blk->num_preds(); k++) {
   970         new_phi->set_req(k, inputs[k]);
   976         new_phi->set_req(k, inputs[k]);
   971       }
   977       }
   972       fixup = new_phi;
   978       fixup = new_phi;
   973     }
   979     }
  1003 }
  1009 }
  1004 
  1010 
  1005 //------------------------------catch_cleanup_inter_block---------------------
  1011 //------------------------------catch_cleanup_inter_block---------------------
  1006 // Fix all input edges in use that reference "def".  The use is in a different
  1012 // Fix all input edges in use that reference "def".  The use is in a different
  1007 // block than the def.
  1013 // block than the def.
  1008 static void catch_cleanup_inter_block(Node *use, Block *use_blk, Node *def, Block *def_blk, Block_Array &bbs, int n_clone_idx) {
  1014 static void catch_cleanup_inter_block(Node *use, Block *use_blk, Node *def, Block *def_blk, PhaseCFG* cfg, int n_clone_idx) {
  1009   if( !use_blk ) return;        // Can happen if the use is a precedence edge
  1015   if( !use_blk ) return;        // Can happen if the use is a precedence edge
  1010 
  1016 
  1011   Node *new_def = catch_cleanup_find_cloned_def(use_blk, def, def_blk, bbs, n_clone_idx);
  1017   Node *new_def = catch_cleanup_find_cloned_def(use_blk, def, def_blk, cfg, n_clone_idx);
  1012   catch_cleanup_fix_all_inputs(use, def, new_def);
  1018   catch_cleanup_fix_all_inputs(use, def, new_def);
  1013 }
  1019 }
  1014 
  1020 
  1015 //------------------------------call_catch_cleanup-----------------------------
  1021 //------------------------------call_catch_cleanup-----------------------------
  1016 // If we inserted any instructions between a Call and his CatchNode,
  1022 // If we inserted any instructions between a Call and his CatchNode,
  1017 // clone the instructions on all paths below the Catch.
  1023 // clone the instructions on all paths below the Catch.
  1018 void Block::call_catch_cleanup(Block_Array &bbs, Compile* C) {
  1024 void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) {
  1019 
  1025 
  1020   // End of region to clone
  1026   // End of region to clone
  1021   uint end = end_idx();
  1027   uint end = end_idx();
  1022   if( !_nodes[end]->is_Catch() ) return;
  1028   if( !_nodes[end]->is_Catch() ) return;
  1023   // Start of region to clone
  1029   // Start of region to clone
  1038     for( uint j = end; j > beg; j-- ) {
  1044     for( uint j = end; j > beg; j-- ) {
  1039       // It is safe here to clone a node with anti_dependence
  1045       // It is safe here to clone a node with anti_dependence
  1040       // since clones dominate on each path.
  1046       // since clones dominate on each path.
  1041       Node *clone = _nodes[j-1]->clone();
  1047       Node *clone = _nodes[j-1]->clone();
  1042       sb->_nodes.insert( 1, clone );
  1048       sb->_nodes.insert( 1, clone );
  1043       bbs.map(clone->_idx,sb);
  1049       cfg->map_node_to_block(clone, sb);
  1044     }
  1050     }
  1045   }
  1051   }
  1046 
  1052 
  1047 
  1053 
  1048   // Fixup edges.  Check the def-use info per cloned Node
  1054   // Fixup edges.  Check the def-use info per cloned Node
  1055       out->push(n->fast_out(j1));
  1061       out->push(n->fast_out(j1));
  1056     }
  1062     }
  1057     uint max = out->size();
  1063     uint max = out->size();
  1058     for (uint j = 0; j < max; j++) {// For all users
  1064     for (uint j = 0; j < max; j++) {// For all users
  1059       Node *use = out->pop();
  1065       Node *use = out->pop();
  1060       Block *buse = bbs[use->_idx];
  1066       Block *buse = cfg->get_block_for_node(use);
  1061       if( use->is_Phi() ) {
  1067       if( use->is_Phi() ) {
  1062         for( uint k = 1; k < use->req(); k++ )
  1068         for( uint k = 1; k < use->req(); k++ )
  1063           if( use->in(k) == n ) {
  1069           if( use->in(k) == n ) {
  1064             Node *fixup = catch_cleanup_find_cloned_def(bbs[buse->pred(k)->_idx], n, this, bbs, n_clone_idx);
  1070             Block* block = cfg->get_block_for_node(buse->pred(k));
       
  1071             Node *fixup = catch_cleanup_find_cloned_def(block, n, this, cfg, n_clone_idx);
  1065             use->set_req(k, fixup);
  1072             use->set_req(k, fixup);
  1066           }
  1073           }
  1067       } else {
  1074       } else {
  1068         if (this == buse) {
  1075         if (this == buse) {
  1069           catch_cleanup_intra_block(use, n, this, beg, n_clone_idx);
  1076           catch_cleanup_intra_block(use, n, this, beg, n_clone_idx);
  1070         } else {
  1077         } else {
  1071           catch_cleanup_inter_block(use, buse, n, this, bbs, n_clone_idx);
  1078           catch_cleanup_inter_block(use, buse, n, this, cfg, n_clone_idx);
  1072         }
  1079         }
  1073       }
  1080       }
  1074     } // End for all users
  1081     } // End for all users
  1075 
  1082 
  1076   } // End of for all Nodes in cloned area
  1083   } // End of for all Nodes in cloned area