< prev index next >

src/hotspot/share/opto/compile.cpp

Print this page




2194           igvn.remove_dead_node(n);
2195         }
2196         --i;
2197       }
2198     }
2199   }
2200 }
2201 
2202 //------------------------------Optimize---------------------------------------
2203 // Given a graph, optimize it.
2204 void Compile::Optimize() {
2205   TracePhase tp("optimizer", &timers[_t_optimizer]);
2206 
2207 #ifndef PRODUCT
2208   if (_directive->BreakAtCompileOption) {
2209     BREAKPOINT;
2210   }
2211 
2212 #endif
2213 
2214   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2215 #ifdef ASSERT

2216   bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
2217 #endif
2218 
2219   ResourceMark rm;
2220 
2221   print_inlining_reinit();
2222 
2223   NOT_PRODUCT( verify_graph_edges(); )
2224 
2225   print_method(PHASE_AFTER_PARSING);
2226 
2227  {
2228   // Iterative Global Value Numbering, including ideal transforms
2229   // Initialize IterGVN with types and values from parse-time GVN
2230   PhaseIterGVN igvn(initial_gvn());
2231 #ifdef ASSERT
2232   _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
2233 #endif
2234   {
2235     TracePhase tp("iterGVN", &timers[_t_iterGVN]);


2354   }
2355   if (failing())  return;
2356 
2357   // Conditional Constant Propagation;
2358   PhaseCCP ccp( &igvn );
2359   assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
2360   {
2361     TracePhase tp("ccp", &timers[_t_ccp]);
2362     ccp.do_transform();
2363   }
2364   print_method(PHASE_CPP1, 2);
2365 
2366   assert( true, "Break here to ccp.dump_old2new_map()");
2367 
2368   // Iterative Global Value Numbering, including ideal transforms
2369   {
2370     TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
2371     igvn = ccp;
2372     igvn.optimize();
2373   }

2374   print_method(PHASE_ITER_GVN2, 2);
2375 
2376   if (failing())  return;
2377 
2378   // Loop transforms on the ideal graph.  Range Check Elimination,
2379   // peeling, unrolling, etc.
2380   if (!optimize_loops(igvn, LoopOptsDefault)) {
2381     return;
2382   }
2383 






2384   if (failing())  return;
2385 
2386   // Ensure that major progress is now clear
2387   C->clear_major_progress();
2388 
2389   {
2390     // Verify that all previous optimizations produced a valid graph
2391     // at least to this point, even if no loop optimizations were done.
2392     TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]);
2393     PhaseIdealLoop::verify(igvn);
2394   }
2395 
2396   if (range_check_cast_count() > 0) {
2397     // No more loop optimizations. Remove all range check dependent CastIINodes.
2398     C->remove_range_check_casts(igvn);
2399     igvn.optimize();
2400   }
2401 
2402 #ifdef ASSERT
2403   bs->verify_gc_barriers(this, BarrierSetC2::BeforeLateInsertion);
2404 #endif
2405 
2406   bs->barrier_insertion_phase(C, igvn);
2407   if (failing())  return;
2408 
2409 #ifdef ASSERT
2410   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2411 #endif
2412 
2413   {
2414     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2415     PhaseMacroExpand  mex(igvn);

2416     if (mex.expand_macro_nodes()) {
2417       assert(failing(), "must bail out w/ explicit message");
2418       return;
2419     }
2420     print_method(PHASE_MACRO_EXPANSION, 2);
2421   }
2422 
2423   {
2424     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);


2425     if (bs->expand_barriers(this, igvn)) {
2426       assert(failing(), "must bail out w/ explicit message");
2427       return;
2428     }
2429     print_method(PHASE_BARRIER_EXPANSION, 2);
2430   }
2431 
2432   if (opaque4_count() > 0) {
2433     C->remove_opaque4_nodes(igvn);
2434     igvn.optimize();
2435   }
2436 
2437   DEBUG_ONLY( _modified_nodes = NULL; )
2438  } // (End scope of igvn; run destructor if necessary for asserts.)
2439 
2440  process_print_inlining();
2441  // A method with only infinite loops has no edges entering loops from root
2442  {
2443    TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2444    if (final_graph_reshaping()) {
2445      assert(failing(), "must bail out w/ explicit message");
2446      return;
2447    }
2448  }
2449 


2805       break;
2806     }
2807     default:
2808       break;
2809     }
2810   }
2811 
2812 #ifdef ASSERT
2813   if( n->is_Mem() ) {
2814     int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2815     assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
2816             // oop will be recorded in oop map if load crosses safepoint
2817             n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
2818                              LoadNode::is_immutable_value(n->in(MemNode::Address))),
2819             "raw memory operations should have control edge");
2820   }
2821   if (n->is_MemBar()) {
2822     MemBarNode* mb = n->as_MemBar();
2823     if (mb->trailing_store() || mb->trailing_load_store()) {
2824       assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair");
2825       Node* mem = BarrierSet::barrier_set()->barrier_set_c2()->step_over_gc_barrier(mb->in(MemBarNode::Precedent));
2826       assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||
2827              (mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op");
2828     } else if (mb->leading()) {
2829       assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair");
2830     }
2831   }
2832 #endif
2833   // Count FPU ops and common calls, implements item (3)
2834   bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->final_graph_reshaping(this, n, nop);
2835   if (!gc_handled) {
2836     final_graph_reshaping_main_switch(n, frc, nop);
2837   }
2838 
2839   // Collect CFG split points
2840   if (n->is_MultiBranch() && !n->is_RangeCheck()) {
2841     frc._tests.push(n);
2842   }
2843 }
2844 
2845 void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop) {




2194           igvn.remove_dead_node(n);
2195         }
2196         --i;
2197       }
2198     }
2199   }
2200 }
2201 
2202 //------------------------------Optimize---------------------------------------
2203 // Given a graph, optimize it.
2204 void Compile::Optimize() {
2205   TracePhase tp("optimizer", &timers[_t_optimizer]);
2206 
2207 #ifndef PRODUCT
2208   if (_directive->BreakAtCompileOption) {
2209     BREAKPOINT;
2210   }
2211 
2212 #endif
2213 

2214 #ifdef ASSERT
2215   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2216   bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
2217 #endif
2218 
2219   ResourceMark rm;
2220 
2221   print_inlining_reinit();
2222 
2223   NOT_PRODUCT( verify_graph_edges(); )
2224 
2225   print_method(PHASE_AFTER_PARSING);
2226 
2227  {
2228   // Iterative Global Value Numbering, including ideal transforms
2229   // Initialize IterGVN with types and values from parse-time GVN
2230   PhaseIterGVN igvn(initial_gvn());
2231 #ifdef ASSERT
2232   _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
2233 #endif
2234   {
2235     TracePhase tp("iterGVN", &timers[_t_iterGVN]);


2354   }
2355   if (failing())  return;
2356 
2357   // Conditional Constant Propagation;
2358   PhaseCCP ccp( &igvn );
2359   assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
2360   {
2361     TracePhase tp("ccp", &timers[_t_ccp]);
2362     ccp.do_transform();
2363   }
2364   print_method(PHASE_CPP1, 2);
2365 
2366   assert( true, "Break here to ccp.dump_old2new_map()");
2367 
2368   // Iterative Global Value Numbering, including ideal transforms
2369   {
2370     TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
2371     igvn = ccp;
2372     igvn.optimize();
2373   }
2374 
2375   print_method(PHASE_ITER_GVN2, 2);
2376 
2377   if (failing())  return;
2378 
2379   // Loop transforms on the ideal graph.  Range Check Elimination,
2380   // peeling, unrolling, etc.
2381   if (!optimize_loops(igvn, LoopOptsDefault)) {
2382     return;
2383   }
2384 
2385 #if INCLUDE_ZGC
2386   if (UseZGC) {
2387     ZBarrierSetC2::find_dominating_barriers(igvn);
2388   }
2389 #endif
2390 
2391   if (failing())  return;
2392 
2393   // Ensure that major progress is now clear
2394   C->clear_major_progress();
2395 
2396   {
2397     // Verify that all previous optimizations produced a valid graph
2398     // at least to this point, even if no loop optimizations were done.
2399     TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]);
2400     PhaseIdealLoop::verify(igvn);
2401   }
2402 
2403   if (range_check_cast_count() > 0) {
2404     // No more loop optimizations. Remove all range check dependent CastIINodes.
2405     C->remove_range_check_casts(igvn);
2406     igvn.optimize();
2407   }
2408 
2409 #ifdef ASSERT
2410   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2411   bs->verify_gc_barriers(this, BarrierSetC2::BeforeExpand);






2412 #endif
2413 
2414   {
2415     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2416     PhaseMacroExpand  mex(igvn);
2417     print_method(PHASE_BEFORE_MACRO_EXPANSION, 2);
2418     if (mex.expand_macro_nodes()) {
2419       assert(failing(), "must bail out w/ explicit message");
2420       return;
2421     }

2422   }
2423 
2424   {
2425     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
2426     print_method(PHASE_BEFORE_BARRIER_EXPAND, 2);
2427     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2428     if (bs->expand_barriers(this, igvn)) {
2429       assert(failing(), "must bail out w/ explicit message");
2430       return;
2431     }

2432   }
2433 
2434   if (opaque4_count() > 0) {
2435     C->remove_opaque4_nodes(igvn);
2436     igvn.optimize();
2437   }
2438 
2439   DEBUG_ONLY( _modified_nodes = NULL; )
2440  } // (End scope of igvn; run destructor if necessary for asserts.)
2441 
2442  process_print_inlining();
2443  // A method with only infinite loops has no edges entering loops from root
2444  {
2445    TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2446    if (final_graph_reshaping()) {
2447      assert(failing(), "must bail out w/ explicit message");
2448      return;
2449    }
2450  }
2451 


2807       break;
2808     }
2809     default:
2810       break;
2811     }
2812   }
2813 
2814 #ifdef ASSERT
2815   if( n->is_Mem() ) {
2816     int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2817     assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
2818             // oop will be recorded in oop map if load crosses safepoint
2819             n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
2820                              LoadNode::is_immutable_value(n->in(MemNode::Address))),
2821             "raw memory operations should have control edge");
2822   }
2823   if (n->is_MemBar()) {
2824     MemBarNode* mb = n->as_MemBar();
2825     if (mb->trailing_store() || mb->trailing_load_store()) {
2826       assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair");
2827       Node* mem = mb->in(MemBarNode::Precedent);
2828       assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||
2829              (mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op");
2830     } else if (mb->leading()) {
2831       assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair");
2832     }
2833   }
2834 #endif
2835   // Count FPU ops and common calls, implements item (3)
2836   bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->final_graph_reshaping(this, n, nop);
2837   if (!gc_handled) {
2838     final_graph_reshaping_main_switch(n, frc, nop);
2839   }
2840 
2841   // Collect CFG split points
2842   if (n->is_MultiBranch() && !n->is_RangeCheck()) {
2843     frc._tests.push(n);
2844   }
2845 }
2846 
2847 void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop) {


< prev index next >