2390
2391 // Keep loop predicates and perform optimizations with them
2392 // until no more loop optimizations could be done.
2393 // After that switch predicates off and do more loop optimizations.
2394 if (!C->major_progress() && (C->predicate_count() > 0)) {
2395 C->cleanup_loop_predicates(_igvn);
2396 #ifndef PRODUCT
2397 if (TraceLoopOpts) {
2398 tty->print_cr("PredicatesOff");
2399 }
2400 #endif
2401 C->set_major_progress();
2402 }
2403
2404 // Convert scalar to superword operations at the end of all loop opts.
2405 if (UseSuperWord && C->has_loops() && !C->major_progress()) {
2406 // SuperWord transform
2407 SuperWord sw(this);
2408 for (LoopTreeIterator iter(_ltree_root); !iter.done(); iter.next()) {
2409 IdealLoopTree* lpt = iter.current();
2410 if (lpt->is_counted()) {
2411 sw.transform_loop(lpt);
2412 }
2413 }
2414 }
2415
2416 // Cleanup any modified bits
2417 _igvn.optimize();
2418
2419 // disable assert until issue with split_flow_path is resolved (6742111)
2420 // assert(!_has_irreducible_loops || C->parsed_irreducible_loop() || C->is_osr_compilation(),
2421 // "shouldn't introduce irreducible loops");
2422
2423 if (C->log() != NULL) {
2424 log_loop_tree(_ltree_root, _ltree_root, C->log());
2425 }
2426 }
2427
2428 #ifndef PRODUCT
2429 //------------------------------print_statistics-------------------------------
3661 }
3662 tty->cr();
3663 }
3664 #endif
3665
3666 #ifndef PRODUCT
3667 //------------------------------dump-------------------------------------------
3668 void PhaseIdealLoop::dump( ) const {
3669 ResourceMark rm;
3670 Arena* arena = Thread::current()->resource_area();
3671 Node_Stack stack(arena, C->unique() >> 2);
3672 Node_List rpo_list;
3673 VectorSet visited(arena);
3674 visited.set(C->top()->_idx);
3675 rpo( C->root(), stack, visited, rpo_list );
3676 // Dump root loop indexed by last element in PO order
3677 dump( _ltree_root, rpo_list.size(), rpo_list );
3678 }
3679
3680 void PhaseIdealLoop::dump( IdealLoopTree *loop, uint idx, Node_List &rpo_list ) const {
3681 CloneMap& cm = C->clone_map();
3682 loop->dump_head();
3683
3684 // Now scan for CFG nodes in the same loop
3685 for( uint j=idx; j > 0; j-- ) {
3686 Node *n = rpo_list[j-1];
3687 if( !_nodes[n->_idx] ) // Skip dead nodes
3688 continue;
3689 if( get_loop(n) != loop ) { // Wrong loop nest
3690 if( get_loop(n)->_head == n && // Found nested loop?
3691 get_loop(n)->_parent == loop )
3692 dump(get_loop(n),rpo_list.size(),rpo_list); // Print it nested-ly
3693 continue;
3694 }
3695
3696 // Dump controlling node
3697 for( uint x = 0; x < loop->_nest; x++ )
3698 tty->print(" ");
3699 tty->print("C");
3700 if( n == C->root() ) {
3701 n->dump();
3702 } else {
3703 Node* cached_idom = idom_no_update(n);
3704 Node *computed_idom = n->in(0);
3705 if( n->is_Region() ) {
3706 computed_idom = compute_idom(n);
3707 // computed_idom() will return n->in(0) when idom(n) is an IfNode (or
3708 // any MultiBranch ctrl node), so apply a similar transform to
3709 // the cached idom returned from idom_no_update.
3710 cached_idom = find_non_split_ctrl(cached_idom);
3711 }
3712 tty->print(" ID:%d",computed_idom->_idx);
3713 cm.dump(n->_idx);
3714 n->dump();
3715 if( cached_idom != computed_idom ) {
3716 tty->print_cr("*** BROKEN IDOM! Computed as: %d, cached as: %d",
3717 computed_idom->_idx, cached_idom->_idx);
3718 }
3719 }
3720 // Dump nodes it controls
3721 for( uint k = 0; k < _nodes.Size(); k++ ) {
3722 // (k < C->unique() && get_ctrl(find(k)) == n)
3723 if (k < C->unique() && _nodes[k] == (Node*)((intptr_t)n + 1)) {
3724 Node *m = C->root()->find(k);
3725 if( m && m->outcnt() > 0 ) {
3726 if (!(has_ctrl(m) && get_ctrl_no_update(m) == n)) {
3727 tty->print_cr("*** BROKEN CTRL ACCESSOR! _nodes[k] is %p, ctrl is %p",
3728 _nodes[k], has_ctrl(m) ? get_ctrl_no_update(m) : NULL);
3729 }
3730 for( uint j = 0; j < loop->_nest; j++ )
3731 tty->print(" ");
3732 tty->print(" ");
3733 cm.dump(m->_idx);
3734 m->dump();
3735 }
3736 }
3737 }
3738 }
3739 }
3740
3741 // Collect a R-P-O for the whole CFG.
3742 // Result list is in post-order (scan backwards for RPO)
3743 void PhaseIdealLoop::rpo( Node *start, Node_Stack &stk, VectorSet &visited, Node_List &rpo_list ) const {
3744 stk.push(start, 0);
3745 visited.set(start->_idx);
3746
3747 while (stk.is_nonempty()) {
3748 Node* m = stk.node();
3749 uint idx = stk.index();
3750 if (idx < m->outcnt()) {
3751 stk.set_index(idx + 1);
3752 Node* n = m->raw_out(idx);
3753 if (n->is_CFG() && !visited.test_set(n->_idx)) {
|
2390
2391 // Keep loop predicates and perform optimizations with them
2392 // until no more loop optimizations could be done.
2393 // After that switch predicates off and do more loop optimizations.
2394 if (!C->major_progress() && (C->predicate_count() > 0)) {
2395 C->cleanup_loop_predicates(_igvn);
2396 #ifndef PRODUCT
2397 if (TraceLoopOpts) {
2398 tty->print_cr("PredicatesOff");
2399 }
2400 #endif
2401 C->set_major_progress();
2402 }
2403
2404 // Convert scalar to superword operations at the end of all loop opts.
2405 if (UseSuperWord && C->has_loops() && !C->major_progress()) {
2406 // SuperWord transform
2407 SuperWord sw(this);
2408 for (LoopTreeIterator iter(_ltree_root); !iter.done(); iter.next()) {
2409 IdealLoopTree* lpt = iter.current();
2410 #ifndef PRODUCT
2411 if (TraceLoopOpts) {
2412 tty->print_cr("Testing for SuperWord loop %d", lpt->_head->_idx);
2413 lpt->dump_head();
2414 lpt->dump();
2415 }
2416 #endif
2417 if (lpt->is_counted()) {
2418 sw.transform_loop(lpt);
2419 }
2420 }
2421 }
2422
2423 // Cleanup any modified bits
2424 _igvn.optimize();
2425
2426 // disable assert until issue with split_flow_path is resolved (6742111)
2427 // assert(!_has_irreducible_loops || C->parsed_irreducible_loop() || C->is_osr_compilation(),
2428 // "shouldn't introduce irreducible loops");
2429
2430 if (C->log() != NULL) {
2431 log_loop_tree(_ltree_root, _ltree_root, C->log());
2432 }
2433 }
2434
2435 #ifndef PRODUCT
2436 //------------------------------print_statistics-------------------------------
3668 }
3669 tty->cr();
3670 }
3671 #endif
3672
3673 #ifndef PRODUCT
3674 //------------------------------dump-------------------------------------------
3675 void PhaseIdealLoop::dump( ) const {
3676 ResourceMark rm;
3677 Arena* arena = Thread::current()->resource_area();
3678 Node_Stack stack(arena, C->unique() >> 2);
3679 Node_List rpo_list;
3680 VectorSet visited(arena);
3681 visited.set(C->top()->_idx);
3682 rpo( C->root(), stack, visited, rpo_list );
3683 // Dump root loop indexed by last element in PO order
3684 dump( _ltree_root, rpo_list.size(), rpo_list );
3685 }
3686
3687 void PhaseIdealLoop::dump( IdealLoopTree *loop, uint idx, Node_List &rpo_list ) const {
3688 loop->dump_head();
3689
3690 // Now scan for CFG nodes in the same loop
3691 for( uint j=idx; j > 0; j-- ) {
3692 Node *n = rpo_list[j-1];
3693 if( !_nodes[n->_idx] ) // Skip dead nodes
3694 continue;
3695 if( get_loop(n) != loop ) { // Wrong loop nest
3696 if( get_loop(n)->_head == n && // Found nested loop?
3697 get_loop(n)->_parent == loop )
3698 dump(get_loop(n),rpo_list.size(),rpo_list); // Print it nested-ly
3699 continue;
3700 }
3701
3702 // Dump controlling node
3703 for( uint x = 0; x < loop->_nest; x++ )
3704 tty->print(" ");
3705 tty->print("C");
3706 if( n == C->root() ) {
3707 n->dump();
3708 } else {
3709 Node* cached_idom = idom_no_update(n);
3710 Node *computed_idom = n->in(0);
3711 if( n->is_Region() ) {
3712 computed_idom = compute_idom(n);
3713 // computed_idom() will return n->in(0) when idom(n) is an IfNode (or
3714 // any MultiBranch ctrl node), so apply a similar transform to
3715 // the cached idom returned from idom_no_update.
3716 cached_idom = find_non_split_ctrl(cached_idom);
3717 }
3718 tty->print(" ID:%d",computed_idom->_idx);
3719 n->dump();
3720 if( cached_idom != computed_idom ) {
3721 tty->print_cr("*** BROKEN IDOM! Computed as: %d, cached as: %d",
3722 computed_idom->_idx, cached_idom->_idx);
3723 }
3724 }
3725 // Dump nodes it controls
3726 for( uint k = 0; k < _nodes.Size(); k++ ) {
3727 // (k < C->unique() && get_ctrl(find(k)) == n)
3728 if (k < C->unique() && _nodes[k] == (Node*)((intptr_t)n + 1)) {
3729 Node *m = C->root()->find(k);
3730 if( m && m->outcnt() > 0 ) {
3731 if (!(has_ctrl(m) && get_ctrl_no_update(m) == n)) {
3732 tty->print_cr("*** BROKEN CTRL ACCESSOR! _nodes[k] is %p, ctrl is %p",
3733 _nodes[k], has_ctrl(m) ? get_ctrl_no_update(m) : NULL);
3734 }
3735 for( uint j = 0; j < loop->_nest; j++ )
3736 tty->print(" ");
3737 tty->print(" ");
3738 m->dump();
3739 }
3740 }
3741 }
3742 }
3743 }
3744
3745 // Collect a R-P-O for the whole CFG.
3746 // Result list is in post-order (scan backwards for RPO)
3747 void PhaseIdealLoop::rpo( Node *start, Node_Stack &stk, VectorSet &visited, Node_List &rpo_list ) const {
3748 stk.push(start, 0);
3749 visited.set(start->_idx);
3750
3751 while (stk.is_nonempty()) {
3752 Node* m = stk.node();
3753 uint idx = stk.index();
3754 if (idx < m->outcnt()) {
3755 stk.set_index(idx + 1);
3756 Node* n = m->raw_out(idx);
3757 if (n->is_CFG() && !visited.test_set(n->_idx)) {
|