< prev index next >

src/hotspot/share/opto/loopnode.cpp

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciMethodData.hpp"
  27 #include "compiler/compileLog.hpp"


  28 #include "libadt/vectset.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "opto/addnode.hpp"
  32 #include "opto/callnode.hpp"
  33 #include "opto/connode.hpp"
  34 #include "opto/convertnode.hpp"
  35 #include "opto/divnode.hpp"
  36 #include "opto/idealGraphPrinter.hpp"
  37 #include "opto/loopnode.hpp"
  38 #include "opto/mulnode.hpp"
  39 #include "opto/rootnode.hpp"
  40 #include "opto/superword.hpp"
  41 
  42 //=============================================================================
  43 //------------------------------is_loop_iv-------------------------------------
  44 // Determine if a node is Counted loop induction variable.
  45 // The method is declared in node.hpp.
  46 const Node* Node::is_loop_iv() const {
  47   if (this->is_Phi() && !this->as_Phi()->is_copy() &&


 196         next = parent_ctl->in(0)->in(0)->in(0);
 197       } else {
 198         // Check if parent control has a single projection (this
 199         // control is the only possible successor of the parent
 200         // control). If so, we can try to move the node above the
 201         // parent control.
 202         int nb_ctl_proj = 0;
 203         for (DUIterator_Fast imax, i = parent_ctl->fast_outs(imax); i < imax; i++) {
 204           Node *p = parent_ctl->fast_out(i);
 205           if (p->is_Proj() && p->is_CFG()) {
 206             nb_ctl_proj++;
 207             if (nb_ctl_proj > 1) {
 208               break;
 209             }
 210           }
 211         }
 212 
 213         if (nb_ctl_proj > 1) {
 214           break;
 215         }
 216         assert(parent_ctl->is_Start() || parent_ctl->is_MemBar() || parent_ctl->is_Call(), "unexpected node");

 217         assert(idom(ctl) == parent_ctl, "strange");
 218         next = idom(parent_ctl);
 219       }
 220     } else {
 221       next = idom(ctl);
 222     }
 223     if (next->is_Root() || next->is_Start() || dom_depth(next) < min_dom_depth) {
 224       break;
 225     }
 226     ctl = next;
 227   }
 228 
 229   if (ctl != n->in(0)) {
 230     _igvn.replace_input_of(n, 0, ctl);
 231     _igvn.hash_insert(n);
 232   }
 233 
 234   return ctl;
 235 }
 236 


2618         }
2619         if (n2->in(0) != c2) {
2620           _igvn.hash_delete(n2);
2621           n2->set_req(0, c2);
2622           _igvn.hash_insert(n2);
2623           _igvn._worklist.push(n2);
2624           progress = true;
2625         }
2626       }
2627     }
2628   }
2629 
2630   return progress;
2631 }
2632 
2633 
2634 //=============================================================================
2635 //----------------------------build_and_optimize-------------------------------
2636 // Create a PhaseLoop.  Build the ideal Loop tree.  Map each Ideal Node to
2637 // its corresponding LoopNode.  If 'optimize' is true, do some loop cleanups.
2638 void PhaseIdealLoop::build_and_optimize(bool do_split_ifs, bool skip_loop_opts) {
2639   ResourceMark rm;
2640 
2641   int old_progress = C->major_progress();
2642   uint orig_worklist_size = _igvn._worklist.size();
2643 
2644   // Reset major-progress flag for the driver's heuristics
2645   C->clear_major_progress();
2646 
2647 #ifndef PRODUCT
2648   // Capture for later assert
2649   uint unique = C->unique();
2650   _loop_invokes++;
2651   _loop_work += unique;
2652 #endif
2653 
2654   // True if the method has at least 1 irreducible loop
2655   _has_irreducible_loops = false;
2656 
2657   _created_loop_node = false;
2658 


2860       // check for vectorized loops, any reassociation of invariants was already done
2861       if (is_counted && lpt->_head->as_CountedLoop()->do_unroll_only()) continue;
2862 
2863       lpt->reassociate_invariants(this);
2864 
2865       // Because RCE opportunities can be masked by split_thru_phi,
2866       // look for RCE candidates and inhibit split_thru_phi
2867       // on just their loop-phi's for this pass of loop opts
2868       if (SplitIfBlocks && do_split_ifs) {
2869         if (lpt->policy_range_check(this)) {
2870           lpt->_rce_candidate = 1; // = true
2871         }
2872       }
2873     }
2874   }
2875 
2876   // Check for aggressive application of split-if and other transforms
2877   // that require basic-block info (like cloning through Phi's)
2878   if( SplitIfBlocks && do_split_ifs ) {
2879     visited.Clear();
2880     split_if_with_blocks( visited, nstack );
2881     NOT_PRODUCT( if( VerifyLoopOptimizations ) verify(); );



2882   }
2883 
2884   if (!C->major_progress() && do_expensive_nodes && process_expensive_nodes()) {
2885     C->set_major_progress();
2886   }
2887 
2888   // Perform loop predication before iteration splitting
2889   if (C->has_loops() && !C->major_progress() && (C->predicate_count() > 0)) {
2890     _ltree_root->_child->loop_predication(this);
2891   }
2892 
2893   if (OptimizeFill && UseLoopPredicate && C->has_loops() && !C->major_progress()) {
2894     if (do_intrinsify_fill()) {
2895       C->set_major_progress();
2896     }
2897   }
2898 
2899   // Perform iteration-splitting on inner loops.  Split iterations to avoid
2900   // range checks or one-shot null checks.
2901 


4114     // state), Mods/Loads can float around.  So free them up.
4115     bool pinned = true;
4116     switch( n->Opcode() ) {
4117     case Op_DivI:
4118     case Op_DivF:
4119     case Op_DivD:
4120     case Op_ModI:
4121     case Op_ModF:
4122     case Op_ModD:
4123     case Op_LoadB:              // Same with Loads; they can sink
4124     case Op_LoadUB:             // during loop optimizations.
4125     case Op_LoadUS:
4126     case Op_LoadD:
4127     case Op_LoadF:
4128     case Op_LoadI:
4129     case Op_LoadKlass:
4130     case Op_LoadNKlass:
4131     case Op_LoadL:
4132     case Op_LoadS:
4133     case Op_LoadP:


4134     case Op_LoadN:
4135     case Op_LoadRange:
4136     case Op_LoadD_unaligned:
4137     case Op_LoadL_unaligned:
4138     case Op_StrComp:            // Does a bunch of load-like effects
4139     case Op_StrEquals:
4140     case Op_StrIndexOf:
4141     case Op_StrIndexOfChar:
4142     case Op_AryEq:
4143     case Op_HasNegatives:
4144       pinned = false;
4145     }
4146     if( pinned ) {
4147       IdealLoopTree *chosen_loop = get_loop(n->is_CFG() ? n : get_ctrl(n));
4148       if( !chosen_loop->_child )       // Inner loop?
4149         chosen_loop->_body.push(n); // Collect inner loops
4150       return;
4151     }
4152   } else {                      // No slot zero
4153     if( n->is_CFG() ) {         // CFG with no slot 0 is dead




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciMethodData.hpp"
  27 #include "compiler/compileLog.hpp"
  28 #include "gc/shared/barrierSet.hpp"
  29 #include "gc/shared/c2/barrierSetC2.hpp"
  30 #include "libadt/vectset.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "opto/addnode.hpp"
  34 #include "opto/callnode.hpp"
  35 #include "opto/connode.hpp"
  36 #include "opto/convertnode.hpp"
  37 #include "opto/divnode.hpp"
  38 #include "opto/idealGraphPrinter.hpp"
  39 #include "opto/loopnode.hpp"
  40 #include "opto/mulnode.hpp"
  41 #include "opto/rootnode.hpp"
  42 #include "opto/superword.hpp"
  43 
  44 //=============================================================================
  45 //------------------------------is_loop_iv-------------------------------------
  46 // Determine if a node is Counted loop induction variable.
  47 // The method is declared in node.hpp.
  48 const Node* Node::is_loop_iv() const {
  49   if (this->is_Phi() && !this->as_Phi()->is_copy() &&


 198         next = parent_ctl->in(0)->in(0)->in(0);
 199       } else {
 200         // Check if parent control has a single projection (this
 201         // control is the only possible successor of the parent
 202         // control). If so, we can try to move the node above the
 203         // parent control.
 204         int nb_ctl_proj = 0;
 205         for (DUIterator_Fast imax, i = parent_ctl->fast_outs(imax); i < imax; i++) {
 206           Node *p = parent_ctl->fast_out(i);
 207           if (p->is_Proj() && p->is_CFG()) {
 208             nb_ctl_proj++;
 209             if (nb_ctl_proj > 1) {
 210               break;
 211             }
 212           }
 213         }
 214 
 215         if (nb_ctl_proj > 1) {
 216           break;
 217         }
 218         assert(parent_ctl->is_Start() || parent_ctl->is_MemBar() || parent_ctl->is_Call() ||
 219                BarrierSet::barrier_set()->barrier_set_c2()->is_gc_barrier_node(parent_ctl), "unexpected node");
 220         assert(idom(ctl) == parent_ctl, "strange");
 221         next = idom(parent_ctl);
 222       }
 223     } else {
 224       next = idom(ctl);
 225     }
 226     if (next->is_Root() || next->is_Start() || dom_depth(next) < min_dom_depth) {
 227       break;
 228     }
 229     ctl = next;
 230   }
 231 
 232   if (ctl != n->in(0)) {
 233     _igvn.replace_input_of(n, 0, ctl);
 234     _igvn.hash_insert(n);
 235   }
 236 
 237   return ctl;
 238 }
 239 


2621         }
2622         if (n2->in(0) != c2) {
2623           _igvn.hash_delete(n2);
2624           n2->set_req(0, c2);
2625           _igvn.hash_insert(n2);
2626           _igvn._worklist.push(n2);
2627           progress = true;
2628         }
2629       }
2630     }
2631   }
2632 
2633   return progress;
2634 }
2635 
2636 
2637 //=============================================================================
2638 //----------------------------build_and_optimize-------------------------------
2639 // Create a PhaseLoop.  Build the ideal Loop tree.  Map each Ideal Node to
2640 // its corresponding LoopNode.  If 'optimize' is true, do some loop cleanups.
2641 void PhaseIdealLoop::build_and_optimize(bool do_split_ifs, bool skip_loop_opts, bool last_round) {
2642   ResourceMark rm;
2643 
2644   int old_progress = C->major_progress();
2645   uint orig_worklist_size = _igvn._worklist.size();
2646 
2647   // Reset major-progress flag for the driver's heuristics
2648   C->clear_major_progress();
2649 
2650 #ifndef PRODUCT
2651   // Capture for later assert
2652   uint unique = C->unique();
2653   _loop_invokes++;
2654   _loop_work += unique;
2655 #endif
2656 
2657   // True if the method has at least 1 irreducible loop
2658   _has_irreducible_loops = false;
2659 
2660   _created_loop_node = false;
2661 


2863       // check for vectorized loops, any reassociation of invariants was already done
2864       if (is_counted && lpt->_head->as_CountedLoop()->do_unroll_only()) continue;
2865 
2866       lpt->reassociate_invariants(this);
2867 
2868       // Because RCE opportunities can be masked by split_thru_phi,
2869       // look for RCE candidates and inhibit split_thru_phi
2870       // on just their loop-phi's for this pass of loop opts
2871       if (SplitIfBlocks && do_split_ifs) {
2872         if (lpt->policy_range_check(this)) {
2873           lpt->_rce_candidate = 1; // = true
2874         }
2875       }
2876     }
2877   }
2878 
2879   // Check for aggressive application of split-if and other transforms
2880   // that require basic-block info (like cloning through Phi's)
2881   if( SplitIfBlocks && do_split_ifs ) {
2882     visited.Clear();
2883     split_if_with_blocks( visited, nstack, last_round );
2884     NOT_PRODUCT( if( VerifyLoopOptimizations ) verify(); );
2885     if (last_round) {
2886       C->set_major_progress();
2887     }
2888   }
2889 
2890   if (!C->major_progress() && do_expensive_nodes && process_expensive_nodes()) {
2891     C->set_major_progress();
2892   }
2893 
2894   // Perform loop predication before iteration splitting
2895   if (C->has_loops() && !C->major_progress() && (C->predicate_count() > 0)) {
2896     _ltree_root->_child->loop_predication(this);
2897   }
2898 
2899   if (OptimizeFill && UseLoopPredicate && C->has_loops() && !C->major_progress()) {
2900     if (do_intrinsify_fill()) {
2901       C->set_major_progress();
2902     }
2903   }
2904 
2905   // Perform iteration-splitting on inner loops.  Split iterations to avoid
2906   // range checks or one-shot null checks.
2907 


4120     // state), Mods/Loads can float around.  So free them up.
4121     bool pinned = true;
4122     switch( n->Opcode() ) {
4123     case Op_DivI:
4124     case Op_DivF:
4125     case Op_DivD:
4126     case Op_ModI:
4127     case Op_ModF:
4128     case Op_ModD:
4129     case Op_LoadB:              // Same with Loads; they can sink
4130     case Op_LoadUB:             // during loop optimizations.
4131     case Op_LoadUS:
4132     case Op_LoadD:
4133     case Op_LoadF:
4134     case Op_LoadI:
4135     case Op_LoadKlass:
4136     case Op_LoadNKlass:
4137     case Op_LoadL:
4138     case Op_LoadS:
4139     case Op_LoadP:
4140     case Op_LoadBarrierSlowReg:
4141     case Op_LoadBarrierWeakSlowReg:
4142     case Op_LoadN:
4143     case Op_LoadRange:
4144     case Op_LoadD_unaligned:
4145     case Op_LoadL_unaligned:
4146     case Op_StrComp:            // Does a bunch of load-like effects
4147     case Op_StrEquals:
4148     case Op_StrIndexOf:
4149     case Op_StrIndexOfChar:
4150     case Op_AryEq:
4151     case Op_HasNegatives:
4152       pinned = false;
4153     }
4154     if( pinned ) {
4155       IdealLoopTree *chosen_loop = get_loop(n->is_CFG() ? n : get_ctrl(n));
4156       if( !chosen_loop->_child )       // Inner loop?
4157         chosen_loop->_body.push(n); // Collect inner loops
4158       return;
4159     }
4160   } else {                      // No slot zero
4161     if( n->is_CFG() ) {         // CFG with no slot 0 is dead


< prev index next >