src/share/vm/opto/phaseX.cpp

changeset 8193
70649f10b88c
parent 8068
c1091733abe6
child 8285
535618ab1c04
child 8478
c42cb5db3601
equal deleted inserted replaced
8191:c1679cc87ba0 8193:70649f10b88c
396 396
397 397
398 //============================================================================= 398 //=============================================================================
399 //------------------------------PhaseRemoveUseless----------------------------- 399 //------------------------------PhaseRemoveUseless-----------------------------
400 // 1) Use a breadthfirst walk to collect useful nodes reachable from root. 400 // 1) Use a breadthfirst walk to collect useful nodes reachable from root.
401 PhaseRemoveUseless::PhaseRemoveUseless( PhaseGVN *gvn, Unique_Node_List *worklist ) : Phase(Remove_Useless), 401 PhaseRemoveUseless::PhaseRemoveUseless(PhaseGVN *gvn, Unique_Node_List *worklist, PhaseNumber phase_num) : Phase(phase_num),
402 _useful(Thread::current()->resource_area()) { 402 _useful(Thread::current()->resource_area()) {
403 403
404 // Implementation requires 'UseLoopSafepoints == true' and an edge from root 404 // Implementation requires 'UseLoopSafepoints == true' and an edge from root
405 // to each SafePointNode at a backward branch. Inserted in add_safepoint(). 405 // to each SafePointNode at a backward branch. Inserted in add_safepoint().
406 if( !UseLoopSafepoints || !OptoRemoveUseless ) return; 406 if( !UseLoopSafepoints || !OptoRemoveUseless ) return;
431 root->rm_prec(i); 431 root->rm_prec(i);
432 --i; 432 --i;
433 } 433 }
434 } 434 }
435 } 435 }
436 }
437
438 //=============================================================================
439 //------------------------------PhaseRenumberLive------------------------------
440 // First, remove useless nodes (equivalent to identifying live nodes).
441 // Then, renumber live nodes.
442 //
443 // The set of live nodes is returned by PhaseRemoveUseless in the _useful structure.
444 // If the number of live nodes is 'x' (where 'x' == _useful.size()), then the
445 // PhaseRenumberLive updates the node ID of each node (the _idx field) with a unique
446 // value in the range [0, x).
447 //
448 // At the end of the PhaseRenumberLive phase, the compiler's count of unique nodes is
449 // updated to 'x' and the list of dead nodes is reset (as there are no dead nodes).
450 //
451 // The PhaseRenumberLive phase updates two data structures with the new node IDs.
452 // (1) The worklist is used by the PhaseIterGVN phase to identify nodes that must be
453 // processed. A new worklist (with the updated node IDs) is returned in 'new_worklist'.
454 // (2) Type information (the field PhaseGVN::_types) maps type information to each
455 // node ID. The mapping is updated to use the new node IDs as well. Updated type
456 // information is returned in PhaseGVN::_types.
457 //
458 // The PhaseRenumberLive phase does not preserve the order of elements in the worklist.
459 //
460 // Other data structures used by the compiler are not updated. The hash table for value
461 // numbering (the field PhaseGVN::_table) is not updated because computing the hash
462 // values is not based on node IDs. The field PhaseGVN::_nodes is not updated either
463 // because it is empty wherever PhaseRenumberLive is used.
464 PhaseRenumberLive::PhaseRenumberLive(PhaseGVN* gvn,
465 Unique_Node_List* worklist, Unique_Node_List* new_worklist,
466 PhaseNumber phase_num) :
467 PhaseRemoveUseless(gvn, worklist, Remove_Useless_And_Renumber_Live) {
468
469 assert(RenumberLiveNodes, "RenumberLiveNodes must be set to true for node renumbering to take place");
470 assert(C->live_nodes() == _useful.size(), "the number of live nodes must match the number of useful nodes");
471 assert(gvn->nodes_size() == 0, "GVN must not contain any nodes at this point");
472
473 uint old_unique_count = C->unique();
474 uint live_node_count = C->live_nodes();
475 uint worklist_size = worklist->size();
476
477 // Storage for the updated type information.
478 Type_Array new_type_array(C->comp_arena());
479
480 // Iterate over the set of live nodes.
481 uint current_idx = 0; // The current new node ID. Incremented after every assignment.
482 for (uint i = 0; i < _useful.size(); i++) {
483 Node* n = _useful.at(i);
484 const Type* type = gvn->type_or_null(n);
485 new_type_array.map(current_idx, type);
486
487 bool in_worklist = false;
488 if (worklist->member(n)) {
489 in_worklist = true;
490 }
491
492 n->set_idx(current_idx); // Update node ID.
493
494 if (in_worklist) {
495 new_worklist->push(n);
496 }
497
498 current_idx++;
499 }
500
501 assert(worklist_size == new_worklist->size(), "the new worklist must have the same size as the original worklist");
502 assert(live_node_count == current_idx, "all live nodes must be processed");
503
504 // Replace the compiler's type information with the updated type information.
505 gvn->replace_types(new_type_array);
506
507 // Update the unique node count of the compilation to the number of currently live nodes.
508 C->set_unique(live_node_count);
509
510 // Set the dead node count to 0 and reset dead node list.
511 C->reset_dead_node_list();
436 } 512 }
437 513
438 514
439 //============================================================================= 515 //=============================================================================
440 //------------------------------PhaseTransform--------------------------------- 516 //------------------------------PhaseTransform---------------------------------

mercurial