hotspot/src/share/vm/opto/loopUnswitch.cpp

Print this page
rev 611 : Merge
   1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)loopUnswitch.cpp     1.6 07/06/29 14:41:32 JVM"
   3 #endif
   4 /*
   5  * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  


  37 //    if (invariant-test) then       stmt2
  38 //      stmt2                        stmt4
  39 //    else                         endloop
  40 //      stmt3                    else
  41 //    endif                        loop [clone]
  42 //    stmt4                          stmt1 [clone]
  43 //  endloop                          stmt3
  44 //                                   stmt4 [clone]
  45 //                                 endloop
  46 //                               endif
  47 //
  48 // Note: the "else" clause may be empty
  49 
  50 //------------------------------policy_unswitching-----------------------------
  51 // Return TRUE or FALSE if the loop should be unswitched
  52 // (ie. clone loop with an invariant test that does not exit the loop)
  53 bool IdealLoopTree::policy_unswitching( PhaseIdealLoop *phase ) const {
  54   if( !LoopUnswitching ) {
  55     return false;
  56   }



  57   uint nodes_left = MaxNodeLimit - phase->C->unique();
  58   if (2 * _body.size() > nodes_left) {
  59     return false; // Too speculative if running low on nodes.
  60   }
  61   LoopNode* head = _head->as_Loop();
  62   if (head->unswitch_count() + 1 > head->unswitch_max()) {
  63     return false;
  64   }
  65   return phase->find_unswitching_candidate(this) != NULL;
  66 }
  67 
  68 //------------------------------find_unswitching_candidate-----------------------------
  69 // Find candidate "if" for unswitching
  70 IfNode* PhaseIdealLoop::find_unswitching_candidate(const IdealLoopTree *loop) const {
  71 
  72   // Find first invariant test that doesn't exit the loop
  73   LoopNode *head = loop->_head->as_Loop();
  74   IfNode* unswitch_iff = NULL;
  75   Node* n = head->in(LoopNode::LoopBackControl);
  76   while (n != head) {


 188   }
 189 #endif
 190 
 191   C->set_major_progress();
 192 }
 193 
 194 //-------------------------create_slow_version_of_loop------------------------
 195 // Create a slow version of the loop by cloning the loop
 196 // and inserting an if to select fast-slow versions.
 197 // Return control projection of the entry to the fast version.
 198 ProjNode* PhaseIdealLoop::create_slow_version_of_loop(IdealLoopTree *loop,
 199                                                       Node_List &old_new) {
 200   LoopNode* head  = loop->_head->as_Loop();
 201   Node*     entry = head->in(LoopNode::EntryControl);
 202   _igvn.hash_delete(entry);
 203   _igvn._worklist.push(entry);
 204   IdealLoopTree* outer_loop = loop->_parent;
 205 
 206   Node *cont      = _igvn.intcon(1);
 207   set_ctrl(cont, C->root());
 208   Node* opq       = new (C, 2) Opaque1Node(cont);
 209   register_node(opq, outer_loop, entry, dom_depth(entry));
 210   Node *bol       = new (C, 2) Conv2BNode(opq);
 211   register_node(bol, outer_loop, entry, dom_depth(entry));
 212   IfNode* iff = new (C, 2) IfNode(entry, bol, PROB_MAX, COUNT_UNKNOWN);
 213   register_node(iff, outer_loop, entry, dom_depth(entry));
 214   ProjNode* iffast = new (C, 1) IfTrueNode(iff);
 215   register_node(iffast, outer_loop, iff, dom_depth(iff));
 216   ProjNode* ifslow = new (C, 1) IfFalseNode(iff);
 217   register_node(ifslow, outer_loop, iff, dom_depth(iff));
 218 
 219   // Clone the loop body.  The clone becomes the fast loop.  The
 220   // original pre-header will (illegally) have 2 control users (old & new loops).
 221   clone_loop(loop, old_new, dom_depth(head), iff);
 222   assert(old_new[head->_idx]->is_Loop(), "" );
 223 
 224   // Fast (true) control
 225   _igvn.hash_delete(head);
 226   head->set_req(LoopNode::EntryControl, iffast);
 227   set_idom(head, iffast, dom_depth(head));
 228   _igvn._worklist.push(head);
   1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)loopUnswitch.cpp     1.6 07/06/29 14:41:32 JVM"
   3 #endif
   4 /*
   5  * Copyright 2006-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  


  37 //    if (invariant-test) then       stmt2
  38 //      stmt2                        stmt4
  39 //    else                         endloop
  40 //      stmt3                    else
  41 //    endif                        loop [clone]
  42 //    stmt4                          stmt1 [clone]
  43 //  endloop                          stmt3
  44 //                                   stmt4 [clone]
  45 //                                 endloop
  46 //                               endif
  47 //
  48 // Note: the "else" clause may be empty
  49 
  50 //------------------------------policy_unswitching-----------------------------
  51 // Return TRUE or FALSE if the loop should be unswitched
  52 // (ie. clone loop with an invariant test that does not exit the loop)
  53 bool IdealLoopTree::policy_unswitching( PhaseIdealLoop *phase ) const {
  54   if( !LoopUnswitching ) {
  55     return false;
  56   }
  57   if (!_head->is_Loop()) {
  58     return false;
  59   }
  60   uint nodes_left = MaxNodeLimit - phase->C->unique();
  61   if (2 * _body.size() > nodes_left) {
  62     return false; // Too speculative if running low on nodes.
  63   }
  64   LoopNode* head = _head->as_Loop();
  65   if (head->unswitch_count() + 1 > head->unswitch_max()) {
  66     return false;
  67   }
  68   return phase->find_unswitching_candidate(this) != NULL;
  69 }
  70 
  71 //------------------------------find_unswitching_candidate-----------------------------
  72 // Find candidate "if" for unswitching
  73 IfNode* PhaseIdealLoop::find_unswitching_candidate(const IdealLoopTree *loop) const {
  74 
  75   // Find first invariant test that doesn't exit the loop
  76   LoopNode *head = loop->_head->as_Loop();
  77   IfNode* unswitch_iff = NULL;
  78   Node* n = head->in(LoopNode::LoopBackControl);
  79   while (n != head) {


 191   }
 192 #endif
 193 
 194   C->set_major_progress();
 195 }
 196 
 197 //-------------------------create_slow_version_of_loop------------------------
 198 // Create a slow version of the loop by cloning the loop
 199 // and inserting an if to select fast-slow versions.
 200 // Return control projection of the entry to the fast version.
 201 ProjNode* PhaseIdealLoop::create_slow_version_of_loop(IdealLoopTree *loop,
 202                                                       Node_List &old_new) {
 203   LoopNode* head  = loop->_head->as_Loop();
 204   Node*     entry = head->in(LoopNode::EntryControl);
 205   _igvn.hash_delete(entry);
 206   _igvn._worklist.push(entry);
 207   IdealLoopTree* outer_loop = loop->_parent;
 208 
 209   Node *cont      = _igvn.intcon(1);
 210   set_ctrl(cont, C->root());
 211   Node* opq       = new (C, 2) Opaque1Node(C, cont);
 212   register_node(opq, outer_loop, entry, dom_depth(entry));
 213   Node *bol       = new (C, 2) Conv2BNode(opq);
 214   register_node(bol, outer_loop, entry, dom_depth(entry));
 215   IfNode* iff = new (C, 2) IfNode(entry, bol, PROB_MAX, COUNT_UNKNOWN);
 216   register_node(iff, outer_loop, entry, dom_depth(entry));
 217   ProjNode* iffast = new (C, 1) IfTrueNode(iff);
 218   register_node(iffast, outer_loop, iff, dom_depth(iff));
 219   ProjNode* ifslow = new (C, 1) IfFalseNode(iff);
 220   register_node(ifslow, outer_loop, iff, dom_depth(iff));
 221 
 222   // Clone the loop body.  The clone becomes the fast loop.  The
 223   // original pre-header will (illegally) have 2 control users (old & new loops).
 224   clone_loop(loop, old_new, dom_depth(head), iff);
 225   assert(old_new[head->_idx]->is_Loop(), "" );
 226 
 227   // Fast (true) control
 228   _igvn.hash_delete(head);
 229   head->set_req(LoopNode::EntryControl, iffast);
 230   set_idom(head, iffast, dom_depth(head));
 231   _igvn._worklist.push(head);