src/share/vm/opto/loopnode.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8148754-cr Sdiff src/share/vm/opto

src/share/vm/opto/loopnode.cpp

Print this page




 849     julong trip_cnt = cl->trip_count();
 850     jlong final_con = init_con + trip_cnt*stride_con;
 851     int final_int = (int)final_con;
 852     // The final value should be in integer range since the loop
 853     // is counted and the limit was checked for overflow.
 854     assert(final_con == (jlong)final_int, "final value should be integer");
 855     limit = _igvn.intcon(final_int);
 856   } else {
 857     // Create new LoopLimit node to get exact limit (final iv value).
 858     limit = new LoopLimitNode(C, cl->init_trip(), cl->limit(), cl->stride());
 859     register_new_node(limit, cl->in(LoopNode::EntryControl));
 860   }
 861   assert(limit != NULL, "sanity");
 862   return limit;
 863 }
 864 
 865 //------------------------------Ideal------------------------------------------
 866 // Return a node which is more "ideal" than the current node.
 867 // Attempt to convert into a counted-loop.
 868 Node *LoopNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 869   if (!can_be_counted_loop(phase)) {
 870     phase->C->set_major_progress();
 871   }
 872   return RegionNode::Ideal(phase, can_reshape);
 873 }
 874 
 875 
 876 //=============================================================================
 877 //------------------------------Ideal------------------------------------------
 878 // Return a node which is more "ideal" than the current node.
 879 // Attempt to convert into a counted-loop.
 880 Node *CountedLoopNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 881   return RegionNode::Ideal(phase, can_reshape);
 882 }
 883 
 884 //------------------------------dump_spec--------------------------------------
 885 // Dump special per-node info
 886 #ifndef PRODUCT
 887 void CountedLoopNode::dump_spec(outputStream *st) const {
 888   LoopNode::dump_spec(st);
 889   if (stride_is_con()) {
 890     st->print("stride: %d ",stride_con());
 891   }


2119           progress = true;
2120         }
2121         if (n2->in(0) != c2) {
2122           _igvn.hash_delete(n2);
2123           n2->set_req(0, c2);
2124           _igvn.hash_insert(n2);
2125           _igvn._worklist.push(n2);
2126           progress = true;
2127         }
2128       }
2129     }
2130   }
2131 
2132   return progress;
2133 }
2134 
2135 
2136 //=============================================================================
2137 //----------------------------build_and_optimize-------------------------------
2138 // Create a PhaseLoop.  Build the ideal Loop tree.  Map each Ideal Node to
2139 // its corresponding LoopNode.  If 'optimize' is true, do some loop cleanups.
2140 void PhaseIdealLoop::build_and_optimize(bool do_split_ifs, bool skip_loop_opts) {
2141   ResourceMark rm;
2142 
2143   int old_progress = C->major_progress();
2144   uint orig_worklist_size = _igvn._worklist.size();
2145 
2146   // Reset major-progress flag for the driver's heuristics
2147   C->clear_major_progress();
2148 
2149 #ifndef PRODUCT
2150   // Capture for later assert
2151   uint unique = C->unique();
2152   _loop_invokes++;
2153   _loop_work += unique;
2154 #endif
2155 
2156   // True if the method has at least 1 irreducible loop
2157   _has_irreducible_loops = false;
2158 
2159   _created_loop_node = false;
2160 
2161   Arena *a = Thread::current()->resource_area();
2162   VectorSet visited(a);
2163   // Pre-grow the mapping from Nodes to IdealLoopTrees.


2276   // it will be processed among C->top() inputs
2277   worklist.push( C->top() );
2278   visited.set( C->top()->_idx ); // Set C->top() as visited now
2279   build_loop_early( visited, worklist, nstack );
2280 
2281   // Given early legal placement, try finding counted loops.  This placement
2282   // is good enough to discover most loop invariants.
2283   if( !_verify_me && !_verify_only )
2284     _ltree_root->counted_loop( this );
2285 
2286   // Find latest loop placement.  Find ideal loop placement.
2287   visited.Clear();
2288   init_dom_lca_tags();
2289   // Need C->root() on worklist when processing outs
2290   worklist.push( C->root() );
2291   NOT_PRODUCT( C->verify_graph_edges(); )
2292   worklist.push( C->top() );
2293   build_loop_late( visited, worklist, nstack );
2294 
2295   if (_verify_only) {
2296     // restore major progress flag
2297     for (int i = 0; i < old_progress; i++)
2298       C->set_major_progress();

2299     assert(C->unique() == unique, "verification mode made Nodes? ? ?");
2300     assert(_igvn._worklist.size() == orig_worklist_size, "shouldn't push anything");
2301     return;
2302   }
2303 
2304   // clear out the dead code after build_loop_late
2305   while (_deadlist.size()) {
2306     _igvn.remove_globally_dead_node(_deadlist.pop());
2307   }
2308 
2309   if (stop_early) {
2310     assert(do_expensive_nodes, "why are we here?");
2311     if (process_expensive_nodes()) {
2312       // If we made some progress when processing expensive nodes then
2313       // the IGVN may modify the graph in a way that will allow us to
2314       // make some more progress: we need to try processing expensive
2315       // nodes again.
2316       C->set_major_progress();
2317     }
2318     _igvn.optimize();


2324   // For example, peeling. Eliminate them before next loop optimizations.
2325   if (UseLoopPredicate || LoopLimitCheck) {
2326     eliminate_useless_predicates();
2327   }
2328 
2329 #ifndef PRODUCT
2330   C->verify_graph_edges();
2331   if (_verify_me) {             // Nested verify pass?
2332     // Check to see if the verify mode is broken
2333     assert(C->unique() == unique, "non-optimize mode made Nodes? ? ?");
2334     return;
2335   }
2336   if(VerifyLoopOptimizations) verify();
2337   if(TraceLoopOpts && C->has_loops()) {
2338     _ltree_root->dump();
2339   }
2340 #endif
2341 
2342   if (skip_loop_opts) {
2343     // restore major progress flag
2344     for (int i = 0; i < old_progress; i++) {
2345       C->set_major_progress();
2346     }
2347 
2348     // Cleanup any modified bits
2349     _igvn.optimize();
2350 
2351     if (C->log() != NULL) {
2352       log_loop_tree(_ltree_root, _ltree_root, C->log());
2353     }
2354     return;
2355   }
2356 
2357   if (ReassociateInvariants) {
2358     // Reassociate invariants and prep for split_thru_phi
2359     for (LoopTreeIterator iter(_ltree_root); !iter.done(); iter.next()) {
2360       IdealLoopTree* lpt = iter.current();
2361       bool is_counted = lpt->is_counted();
2362       if (!is_counted || !lpt->is_inner()) continue;
2363 
2364       // check for vectorized loops, any reassociation of invariants was already done


2475 void PhaseIdealLoop::print_statistics() {
2476   tty->print_cr("PhaseIdealLoop=%d, sum _unique=%d", _loop_invokes, _loop_work);
2477 }
2478 
2479 //------------------------------verify-----------------------------------------
2480 // Build a verify-only PhaseIdealLoop, and see that it agrees with me.
2481 static int fail;                // debug only, so its multi-thread dont care
2482 void PhaseIdealLoop::verify() const {
2483   int old_progress = C->major_progress();
2484   ResourceMark rm;
2485   PhaseIdealLoop loop_verify( _igvn, this );
2486   VectorSet visited(Thread::current()->resource_area());
2487 
2488   fail = 0;
2489   verify_compare( C->root(), &loop_verify, visited );
2490   assert( fail == 0, "verify loops failed" );
2491   // Verify loop structure is the same
2492   _ltree_root->verify_tree(loop_verify._ltree_root, NULL);
2493   // Reset major-progress.  It was cleared by creating a verify version of
2494   // PhaseIdealLoop.
2495   for( int i=0; i<old_progress; i++ )
2496     C->set_major_progress();

2497 }
2498 
2499 //------------------------------verify_compare---------------------------------
2500 // Make sure me and the given PhaseIdealLoop agree on key data structures
2501 void PhaseIdealLoop::verify_compare( Node *n, const PhaseIdealLoop *loop_verify, VectorSet &visited ) const {
2502   if( !n ) return;
2503   if( visited.test_set( n->_idx ) ) return;
2504   if( !_nodes[n->_idx] ) {      // Unreachable
2505     assert( !loop_verify->_nodes[n->_idx], "both should be unreachable" );
2506     return;
2507   }
2508 
2509   uint i;
2510   for( i = 0; i < n->req(); i++ )
2511     verify_compare( n->in(i), loop_verify, visited );
2512 
2513   // Check the '_nodes' block/loop structure
2514   i = n->_idx;
2515   if( has_ctrl(n) ) {           // We have control; verify has loop or ctrl
2516     if( _nodes[i] != loop_verify->_nodes[i] &&




 849     julong trip_cnt = cl->trip_count();
 850     jlong final_con = init_con + trip_cnt*stride_con;
 851     int final_int = (int)final_con;
 852     // The final value should be in integer range since the loop
 853     // is counted and the limit was checked for overflow.
 854     assert(final_con == (jlong)final_int, "final value should be integer");
 855     limit = _igvn.intcon(final_int);
 856   } else {
 857     // Create new LoopLimit node to get exact limit (final iv value).
 858     limit = new LoopLimitNode(C, cl->init_trip(), cl->limit(), cl->stride());
 859     register_new_node(limit, cl->in(LoopNode::EntryControl));
 860   }
 861   assert(limit != NULL, "sanity");
 862   return limit;
 863 }
 864 
 865 //------------------------------Ideal------------------------------------------
 866 // Return a node which is more "ideal" than the current node.
 867 // Attempt to convert into a counted-loop.
 868 Node *LoopNode::Ideal(PhaseGVN *phase, bool can_reshape) {



 869   return RegionNode::Ideal(phase, can_reshape);
 870 }
 871 
 872 
 873 //=============================================================================
 874 //------------------------------Ideal------------------------------------------
 875 // Return a node which is more "ideal" than the current node.
 876 // Attempt to convert into a counted-loop.
 877 Node *CountedLoopNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 878   return RegionNode::Ideal(phase, can_reshape);
 879 }
 880 
 881 //------------------------------dump_spec--------------------------------------
 882 // Dump special per-node info
 883 #ifndef PRODUCT
 884 void CountedLoopNode::dump_spec(outputStream *st) const {
 885   LoopNode::dump_spec(st);
 886   if (stride_is_con()) {
 887     st->print("stride: %d ",stride_con());
 888   }


2116           progress = true;
2117         }
2118         if (n2->in(0) != c2) {
2119           _igvn.hash_delete(n2);
2120           n2->set_req(0, c2);
2121           _igvn.hash_insert(n2);
2122           _igvn._worklist.push(n2);
2123           progress = true;
2124         }
2125       }
2126     }
2127   }
2128 
2129   return progress;
2130 }
2131 
2132 
2133 //=============================================================================
2134 //----------------------------build_and_optimize-------------------------------
2135 // Create a PhaseLoop.  Build the ideal Loop tree.  Map each Ideal Node to
2136 // its corresponding LoopNode.
2137 void PhaseIdealLoop::build_and_optimize(bool do_split_ifs, bool skip_loop_opts) {
2138   ResourceMark rm;
2139 
2140   bool old_progress = C->major_progress();
2141   uint orig_worklist_size = _igvn._worklist.size();
2142 
2143   // Reset major-progress flag for the driver's heuristics
2144   C->clear_major_progress();
2145 
2146 #ifndef PRODUCT
2147   // Capture for later assert
2148   uint unique = C->unique();
2149   _loop_invokes++;
2150   _loop_work += unique;
2151 #endif
2152 
2153   // True if the method has at least 1 irreducible loop
2154   _has_irreducible_loops = false;
2155 
2156   _created_loop_node = false;
2157 
2158   Arena *a = Thread::current()->resource_area();
2159   VectorSet visited(a);
2160   // Pre-grow the mapping from Nodes to IdealLoopTrees.


2273   // it will be processed among C->top() inputs
2274   worklist.push( C->top() );
2275   visited.set( C->top()->_idx ); // Set C->top() as visited now
2276   build_loop_early( visited, worklist, nstack );
2277 
2278   // Given early legal placement, try finding counted loops.  This placement
2279   // is good enough to discover most loop invariants.
2280   if( !_verify_me && !_verify_only )
2281     _ltree_root->counted_loop( this );
2282 
2283   // Find latest loop placement.  Find ideal loop placement.
2284   visited.Clear();
2285   init_dom_lca_tags();
2286   // Need C->root() on worklist when processing outs
2287   worklist.push( C->root() );
2288   NOT_PRODUCT( C->verify_graph_edges(); )
2289   worklist.push( C->top() );
2290   build_loop_late( visited, worklist, nstack );
2291 
2292   if (_verify_only) {
2293     if (old_progress) {

2294       C->set_major_progress();
2295     }
2296     assert(C->unique() == unique, "verification mode made Nodes? ? ?");
2297     assert(_igvn._worklist.size() == orig_worklist_size, "shouldn't push anything");
2298     return;
2299   }
2300 
2301   // clear out the dead code after build_loop_late
2302   while (_deadlist.size()) {
2303     _igvn.remove_globally_dead_node(_deadlist.pop());
2304   }
2305 
2306   if (stop_early) {
2307     assert(do_expensive_nodes, "why are we here?");
2308     if (process_expensive_nodes()) {
2309       // If we made some progress when processing expensive nodes then
2310       // the IGVN may modify the graph in a way that will allow us to
2311       // make some more progress: we need to try processing expensive
2312       // nodes again.
2313       C->set_major_progress();
2314     }
2315     _igvn.optimize();


2321   // For example, peeling. Eliminate them before next loop optimizations.
2322   if (UseLoopPredicate || LoopLimitCheck) {
2323     eliminate_useless_predicates();
2324   }
2325 
2326 #ifndef PRODUCT
2327   C->verify_graph_edges();
2328   if (_verify_me) {             // Nested verify pass?
2329     // Check to see if the verify mode is broken
2330     assert(C->unique() == unique, "non-optimize mode made Nodes? ? ?");
2331     return;
2332   }
2333   if(VerifyLoopOptimizations) verify();
2334   if(TraceLoopOpts && C->has_loops()) {
2335     _ltree_root->dump();
2336   }
2337 #endif
2338 
2339   if (skip_loop_opts) {
2340     // restore major progress flag
2341     if (old_progress) {
2342       C->set_major_progress();
2343     }
2344 
2345     // Cleanup any modified bits
2346     _igvn.optimize();
2347 
2348     if (C->log() != NULL) {
2349       log_loop_tree(_ltree_root, _ltree_root, C->log());
2350     }
2351     return;
2352   }
2353 
2354   if (ReassociateInvariants) {
2355     // Reassociate invariants and prep for split_thru_phi
2356     for (LoopTreeIterator iter(_ltree_root); !iter.done(); iter.next()) {
2357       IdealLoopTree* lpt = iter.current();
2358       bool is_counted = lpt->is_counted();
2359       if (!is_counted || !lpt->is_inner()) continue;
2360 
2361       // check for vectorized loops, any reassociation of invariants was already done


2472 void PhaseIdealLoop::print_statistics() {
2473   tty->print_cr("PhaseIdealLoop=%d, sum _unique=%d", _loop_invokes, _loop_work);
2474 }
2475 
2476 //------------------------------verify-----------------------------------------
2477 // Build a verify-only PhaseIdealLoop, and see that it agrees with me.
2478 static int fail;                // debug only, so its multi-thread dont care
2479 void PhaseIdealLoop::verify() const {
2480   int old_progress = C->major_progress();
2481   ResourceMark rm;
2482   PhaseIdealLoop loop_verify( _igvn, this );
2483   VectorSet visited(Thread::current()->resource_area());
2484 
2485   fail = 0;
2486   verify_compare( C->root(), &loop_verify, visited );
2487   assert( fail == 0, "verify loops failed" );
2488   // Verify loop structure is the same
2489   _ltree_root->verify_tree(loop_verify._ltree_root, NULL);
2490   // Reset major-progress.  It was cleared by creating a verify version of
2491   // PhaseIdealLoop.
2492   if (old_progress) {
2493     C->set_major_progress();
2494   }
2495 }
2496 
2497 //------------------------------verify_compare---------------------------------
2498 // Make sure me and the given PhaseIdealLoop agree on key data structures
2499 void PhaseIdealLoop::verify_compare( Node *n, const PhaseIdealLoop *loop_verify, VectorSet &visited ) const {
2500   if( !n ) return;
2501   if( visited.test_set( n->_idx ) ) return;
2502   if( !_nodes[n->_idx] ) {      // Unreachable
2503     assert( !loop_verify->_nodes[n->_idx], "both should be unreachable" );
2504     return;
2505   }
2506 
2507   uint i;
2508   for( i = 0; i < n->req(); i++ )
2509     verify_compare( n->in(i), loop_verify, visited );
2510 
2511   // Check the '_nodes' block/loop structure
2512   i = n->_idx;
2513   if( has_ctrl(n) ) {           // We have control; verify has loop or ctrl
2514     if( _nodes[i] != loop_verify->_nodes[i] &&


src/share/vm/opto/loopnode.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File