< prev index next >

src/share/vm/opto/ifg.cpp

Print this page




 422   }
 423   return cnt;
 424 }
 425 #endif
 426 
 427 /*
 428  * Adjust register pressure down by 1.  Capture last hi-to-low transition,
 429  */
 430 void PhaseChaitin::lower_pressure(Block* b, uint location, LRG& lrg, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure) {
 431   if (lrg.mask_is_nonempty_and_up()) {
 432     if (lrg.is_float_or_vector()) {
 433       float_pressure.lower(lrg, location);
 434     } else {
 435       // Do not count the SP and flag registers
 436       const RegMask& r = lrg.mask();
 437       if (r.overlap(*Matcher::idealreg2regmask[Op_RegI])) {
 438         int_pressure.lower(lrg, location);
 439       }
 440     }
 441   }

 442   assert(int_pressure.current_pressure() == count_int_pressure(liveout), "the int pressure is incorrect");
 443   assert(float_pressure.current_pressure() == count_float_pressure(liveout), "the float pressure is incorrect");

 444 }
 445 
 446 /* Go to the first non-phi index in a block */
 447 static uint first_nonphi_index(Block* b) {
 448   uint i;
 449   uint end_idx = b->end_idx();
 450   for (i = 1; i < end_idx; i++) {
 451     Node* n = b->get_node(i);
 452     if (!n->is_Phi()) {
 453       break;
 454     }
 455   }
 456   return i;
 457 }
 458 
 459 /*
 460  * Spills could be inserted before a CreateEx node which should be the first
 461  * instruction in a block after Phi nodes. If so, move the CreateEx node up.
 462  */
 463 static void move_exception_node_up(Block* b, uint first_inst, uint last_inst) {


 501  * and int/pointer registers.
 502  * Live ranges in the liveout are presumed live for the whole block.
 503  * We add the cost for the whole block to the area of the live ranges initially.
 504  * If a live range gets killed in the block, we'll subtract the unused part of
 505  * the block from the area.
 506  */
 507 void PhaseChaitin::compute_initial_block_pressure(Block* b, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure, double cost) {
 508   IndexSetIterator elements(liveout);
 509   uint lid = elements.next();
 510   while (lid != 0) {
 511     LRG& lrg = lrgs(lid);
 512     lrg._area += cost;
 513     raise_pressure(b, lrg, int_pressure, float_pressure);
 514     lid = elements.next();
 515   }
 516   assert(int_pressure.current_pressure() == count_int_pressure(liveout), "the int pressure is incorrect");
 517   assert(float_pressure.current_pressure() == count_float_pressure(liveout), "the float pressure is incorrect");
 518 }
 519 
 520 /*




















































 521  * Remove dead node if it's not used.
 522  * We only remove projection nodes if the node "defining" the projection is
 523  * dead, for example on x86, if we have a dead Add node we remove its
 524  * RFLAGS node.
 525  */
 526 bool PhaseChaitin::remove_node_if_not_used(Block* b, uint location, Node* n, uint lid, IndexSet* liveout) {
 527   Node* def = n->in(0);
 528   if (!n->is_Proj() ||
 529       (_lrg_map.live_range_id(def) && !liveout->member(_lrg_map.live_range_id(def)))) {
 530     if (n->is_MachProj()) {
 531       // Don't remove KILL projections if their "defining" nodes have
 532       // memory effects (have SCMemProj projection node) -
 533       // they are not dead even when their result is not used.
 534       // For example, compareAndSwapL (and other CAS) and EncodeISOArray nodes.
 535       // The method add_input_to_liveout() keeps such nodes alive (put them on liveout list)
 536       // when it sees SCMemProj node in a block. Unfortunately SCMemProj node could be placed
 537       // in block in such order that KILL MachProj nodes are processed first.
 538       if (def->has_out_with(Op_SCMemProj)) {
 539         return false;
 540       }


 718   // current pressure now means the pressure before the first instruction in the block
 719   // (since we have stepped through all instructions backwards)
 720   if (pressure.current_pressure() > pressure.high_pressure_limit()) {
 721     pressure.set_high_pressure_index_to_block_start();
 722   }
 723 }
 724 
 725 /*
 726  * Compute high pressure indice; avoid landing in the middle of projnodes
 727  * and set the high pressure index for the block
 728  */
 729 void PhaseChaitin::adjust_high_pressure_index(Block* b, uint& block_hrp_index, Pressure& pressure) {
 730   uint i = pressure.high_pressure_index();
 731   if (i < b->number_of_nodes() && i < b->end_idx() + 1) {
 732     Node* cur = b->get_node(i);
 733     while (cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch()) {
 734       cur = b->get_node(--i);
 735     }
 736   }
 737   block_hrp_index = i;










 738 }
 739 
 740 /* Build an interference graph:
 741  *   That is, if 2 live ranges are simultaneously alive but in their acceptable
 742  *   register sets do not overlap, then they do not interfere. The IFG is built
 743  *   by a single reverse pass over each basic block. Starting with the known
 744  *   live-out set, we remove things that get defined and add things that become
 745  *   live (essentially executing one pass of a standard LIVE analysis). Just
 746  *   before a Node defines a value (and removes it from the live-ness set) that
 747  *   value is certainly live. The defined value interferes with everything
 748  *   currently live. The value is then removed from the live-ness set and it's
 749  *   inputs are added to the live-ness set.
 750  * Compute register pressure for each block:
 751  *   We store the biggest register pressure for each block and also the first
 752  *   low to high register pressure transition within the block (if any).
 753  */
 754 uint PhaseChaitin::build_ifg_physical( ResourceArea *a ) {
 755   Compile::TracePhase tp("buildIFG", &timers[_t_buildIFGphysical]);
 756 
 757   uint must_spill = 0;




 422   }
 423   return cnt;
 424 }
 425 #endif
 426 
 427 /*
 428  * Adjust register pressure down by 1.  Capture last hi-to-low transition,
 429  */
 430 void PhaseChaitin::lower_pressure(Block* b, uint location, LRG& lrg, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure) {
 431   if (lrg.mask_is_nonempty_and_up()) {
 432     if (lrg.is_float_or_vector()) {
 433       float_pressure.lower(lrg, location);
 434     } else {
 435       // Do not count the SP and flag registers
 436       const RegMask& r = lrg.mask();
 437       if (r.overlap(*Matcher::idealreg2regmask[Op_RegI])) {
 438         int_pressure.lower(lrg, location);
 439       }
 440     }
 441   }
 442   if (_scheduling_info_generated == false) {
 443     assert(int_pressure.current_pressure() == count_int_pressure(liveout), "the int pressure is incorrect");
 444     assert(float_pressure.current_pressure() == count_float_pressure(liveout), "the float pressure is incorrect");
 445   }
 446 }
 447 
 448 /* Go to the first non-phi index in a block */
 449 static uint first_nonphi_index(Block* b) {
 450   uint i;
 451   uint end_idx = b->end_idx();
 452   for (i = 1; i < end_idx; i++) {
 453     Node* n = b->get_node(i);
 454     if (!n->is_Phi()) {
 455       break;
 456     }
 457   }
 458   return i;
 459 }
 460 
 461 /*
 462  * Spills could be inserted before a CreateEx node which should be the first
 463  * instruction in a block after Phi nodes. If so, move the CreateEx node up.
 464  */
 465 static void move_exception_node_up(Block* b, uint first_inst, uint last_inst) {


 503  * and int/pointer registers.
 504  * Live ranges in the liveout are presumed live for the whole block.
 505  * We add the cost for the whole block to the area of the live ranges initially.
 506  * If a live range gets killed in the block, we'll subtract the unused part of
 507  * the block from the area.
 508  */
 509 void PhaseChaitin::compute_initial_block_pressure(Block* b, IndexSet* liveout, Pressure& int_pressure, Pressure& float_pressure, double cost) {
 510   IndexSetIterator elements(liveout);
 511   uint lid = elements.next();
 512   while (lid != 0) {
 513     LRG& lrg = lrgs(lid);
 514     lrg._area += cost;
 515     raise_pressure(b, lrg, int_pressure, float_pressure);
 516     lid = elements.next();
 517   }
 518   assert(int_pressure.current_pressure() == count_int_pressure(liveout), "the int pressure is incorrect");
 519   assert(float_pressure.current_pressure() == count_float_pressure(liveout), "the float pressure is incorrect");
 520 }
 521 
 522 /*
 523 * Computes the entry register pressure of a block, looking at all live
 524 * ranges in the livein. The register pressure is computed for both float
 525 * and int/pointer registers.
 526 */
 527 void PhaseChaitin::compute_entry_block_pressure(Block* b) {
 528   IndexSet* livein = _live->livein(b);
 529   IndexSetIterator elements(livein);
 530   uint lid = elements.next();
 531   while (lid != 0) {
 532     LRG& lrg = lrgs(lid);
 533     raise_pressure(b, lrg, _sched_int_pressure, _sched_float_pressure);
 534     lid = elements.next();
 535   }
 536   // Now check phis for locally defined inputs
 537   for (uint j = 0; j < b->number_of_nodes(); j++) {
 538     Node* n = b->get_node(j);
 539     if (n->is_Phi()) {
 540       for (uint k = 1; k < n->req(); k++) {
 541         Node* phi_in = n->in(k);
 542         // Because we are talking about phis, raise register pressure once for each
 543         // instance of a phi to account for a single value
 544         if (_cfg.get_block_for_node(phi_in) == b) {
 545           LRG& lrg = lrgs(phi_in->_idx);
 546           raise_pressure(b, lrg, _sched_int_pressure, _sched_float_pressure);
 547           break;
 548         }
 549       }
 550     }
 551   }
 552   _sched_int_pressure.set_start_pressure(_sched_int_pressure.current_pressure());
 553   _sched_float_pressure.set_start_pressure(_sched_float_pressure.current_pressure());
 554 }
 555 
 556 /*
 557 * Computes the exit register pressure of a block, looking at all live
 558 * ranges in the liveout. The register pressure is computed for both float
 559 * and int/pointer registers.
 560 */
 561 void PhaseChaitin::compute_exit_block_pressure(Block* b) {
 562   IndexSet* livein = _live->live(b);
 563   IndexSetIterator elements(livein);
 564   _sched_int_pressure.set_current_pressure(0);
 565   _sched_float_pressure.set_current_pressure(0);
 566   uint lid = elements.next();
 567   while (lid != 0) {
 568     LRG& lrg = lrgs(lid);
 569     raise_pressure(b, lrg, _sched_int_pressure, _sched_float_pressure);
 570     lid = elements.next();
 571   }
 572 }
 573 
 574 /*
 575  * Remove dead node if it's not used.
 576  * We only remove projection nodes if the node "defining" the projection is
 577  * dead, for example on x86, if we have a dead Add node we remove its
 578  * RFLAGS node.
 579  */
 580 bool PhaseChaitin::remove_node_if_not_used(Block* b, uint location, Node* n, uint lid, IndexSet* liveout) {
 581   Node* def = n->in(0);
 582   if (!n->is_Proj() ||
 583       (_lrg_map.live_range_id(def) && !liveout->member(_lrg_map.live_range_id(def)))) {
 584     if (n->is_MachProj()) {
 585       // Don't remove KILL projections if their "defining" nodes have
 586       // memory effects (have SCMemProj projection node) -
 587       // they are not dead even when their result is not used.
 588       // For example, compareAndSwapL (and other CAS) and EncodeISOArray nodes.
 589       // The method add_input_to_liveout() keeps such nodes alive (put them on liveout list)
 590       // when it sees SCMemProj node in a block. Unfortunately SCMemProj node could be placed
 591       // in block in such order that KILL MachProj nodes are processed first.
 592       if (def->has_out_with(Op_SCMemProj)) {
 593         return false;
 594       }


 772   // current pressure now means the pressure before the first instruction in the block
 773   // (since we have stepped through all instructions backwards)
 774   if (pressure.current_pressure() > pressure.high_pressure_limit()) {
 775     pressure.set_high_pressure_index_to_block_start();
 776   }
 777 }
 778 
 779 /*
 780  * Compute high pressure indice; avoid landing in the middle of projnodes
 781  * and set the high pressure index for the block
 782  */
 783 void PhaseChaitin::adjust_high_pressure_index(Block* b, uint& block_hrp_index, Pressure& pressure) {
 784   uint i = pressure.high_pressure_index();
 785   if (i < b->number_of_nodes() && i < b->end_idx() + 1) {
 786     Node* cur = b->get_node(i);
 787     while (cur->is_Proj() || (cur->is_MachNullCheck()) || cur->is_Catch()) {
 788       cur = b->get_node(--i);
 789     }
 790   }
 791   block_hrp_index = i;
 792 }
 793 
 794 void PhaseChaitin::print_pressure_info(Pressure& pressure, const char *str) {
 795   if (str != NULL) {
 796     tty->print_cr("#  *** %s ***", str);
 797   }
 798   tty->print_cr("#     start pressure is = %d", pressure.start_pressure());
 799   tty->print_cr("#     max pressure is = %d", pressure.final_pressure());
 800   tty->print_cr("#     end pressure is = %d", pressure.current_pressure());
 801   tty->print_cr("#");
 802 }
 803 
 804 /* Build an interference graph:
 805  *   That is, if 2 live ranges are simultaneously alive but in their acceptable
 806  *   register sets do not overlap, then they do not interfere. The IFG is built
 807  *   by a single reverse pass over each basic block. Starting with the known
 808  *   live-out set, we remove things that get defined and add things that become
 809  *   live (essentially executing one pass of a standard LIVE analysis). Just
 810  *   before a Node defines a value (and removes it from the live-ness set) that
 811  *   value is certainly live. The defined value interferes with everything
 812  *   currently live. The value is then removed from the live-ness set and it's
 813  *   inputs are added to the live-ness set.
 814  * Compute register pressure for each block:
 815  *   We store the biggest register pressure for each block and also the first
 816  *   low to high register pressure transition within the block (if any).
 817  */
 818 uint PhaseChaitin::build_ifg_physical( ResourceArea *a ) {
 819   Compile::TracePhase tp("buildIFG", &timers[_t_buildIFGphysical]);
 820 
 821   uint must_spill = 0;


< prev index next >