1105
1106 // Create Debug Information Recorder to record scopes, oopmaps, etc.
1107 env()->set_oop_recorder(new OopRecorder(env()->arena()));
1108 env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
1109 env()->set_dependencies(new Dependencies(env()));
1110
1111 _fixed_slots = 0;
1112 set_has_split_ifs(false);
1113 set_has_loops(has_method() && method()->has_loops()); // first approximation
1114 set_has_stringbuilder(false);
1115 set_has_boxed_value(false);
1116 _trap_can_recompile = false; // no traps emitted yet
1117 _major_progress = true; // start out assuming good things will happen
1118 set_has_unsafe_access(false);
1119 set_max_vector_size(0);
1120 set_clear_upper_avx(false); //false as default for clear upper bits of ymm registers
1121 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1122 set_decompile_count(0);
1123
1124 set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1125 set_num_loop_opts(LoopOptsCount);
1126 set_do_inlining(Inline);
1127 set_max_inline_size(MaxInlineSize);
1128 set_freq_inline_size(FreqInlineSize);
1129 set_do_scheduling(OptoScheduling);
1130 set_do_count_invocations(false);
1131 set_do_method_data_update(false);
1132
1133 set_do_vector_loop(false);
1134
1135 if (AllowVectorizeOnDemand) {
1136 if (has_method() && (_directive->VectorizeOption || _directive->VectorizeDebugOption)) {
1137 set_do_vector_loop(true);
1138 NOT_PRODUCT(if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n", method()->name()->as_quoted_ascii());})
1139 } else if (has_method() && method()->name() != 0 &&
1140 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1141 set_do_vector_loop(true);
1142 }
1143 }
1144 set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1145 NOT_PRODUCT(if (use_cmove() && Verbose && has_method()) {tty->print("Compile::Init: use CMove without profitability tests for method %s\n", method()->name()->as_quoted_ascii());})
2152
2153 if (failing()) return;
2154
2155 {
2156 TracePhase tp("incrementalInline_pru", &timers[_t_incrInline_pru]);
2157 ResourceMark rm;
2158 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
2159 }
2160
2161 {
2162 TracePhase tp("incrementalInline_igvn", &timers[_t_incrInline_igvn]);
2163 igvn = PhaseIterGVN(gvn);
2164 igvn.optimize();
2165 }
2166 }
2167
2168 set_inlining_incrementally(false);
2169 }
2170
2171
2172 bool Compile::optimize_loops(int& loop_opts_cnt, PhaseIterGVN& igvn, LoopOptsMode mode) {
2173 if(loop_opts_cnt > 0) {
2174 debug_only( int cnt = 0; );
2175 while(major_progress() && (loop_opts_cnt > 0)) {
2176 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2177 assert( cnt++ < 40, "infinite cycle in loop optimization" );
2178 PhaseIdealLoop ideal_loop(igvn, mode);
2179 loop_opts_cnt--;
2180 if (failing()) return false;
2181 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2182 }
2183 }
2184 return true;
2185 }
2186
2187 //------------------------------Optimize---------------------------------------
2188 // Given a graph, optimize it.
2189 void Compile::Optimize() {
2190 TracePhase tp("optimizer", &timers[_t_optimizer]);
2191
2192 #ifndef PRODUCT
2193 if (_directive->BreakAtCompileOption) {
2194 BREAKPOINT;
2195 }
2196
2197 #endif
2198
2199 #ifdef ASSERT
2200 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2201 bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
2202 #endif
2203
2204 ResourceMark rm;
2205 int loop_opts_cnt;
2206
2207 print_inlining_reinit();
2208
2209 NOT_PRODUCT( verify_graph_edges(); )
2210
2211 print_method(PHASE_AFTER_PARSING);
2212
2213 {
2214 // Iterative Global Value Numbering, including ideal transforms
2215 // Initialize IterGVN with types and values from parse-time GVN
2216 PhaseIterGVN igvn(initial_gvn());
2217 #ifdef ASSERT
2218 _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
2219 #endif
2220 {
2221 TracePhase tp("iterGVN", &timers[_t_iterGVN]);
2222 igvn.optimize();
2223 }
2224
2225 if (failing()) return;
2288
2289 if (failing()) return;
2290
2291 if (congraph() != NULL && macro_count() > 0) {
2292 TracePhase tp("macroEliminate", &timers[_t_macroEliminate]);
2293 PhaseMacroExpand mexp(igvn);
2294 mexp.eliminate_macro_nodes();
2295 igvn.set_delay_transform(false);
2296
2297 igvn.optimize();
2298 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2299
2300 if (failing()) return;
2301 }
2302 }
2303
2304 // Loop transforms on the ideal graph. Range Check Elimination,
2305 // peeling, unrolling, etc.
2306
2307 // Set loop opts counter
2308 loop_opts_cnt = num_loop_opts();
2309 if((loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
2310 {
2311 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2312 PhaseIdealLoop ideal_loop(igvn, LoopOptsDefault);
2313 loop_opts_cnt--;
2314 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
2315 if (failing()) return;
2316 }
2317 // Loop opts pass if partial peeling occurred in previous pass
2318 if(PartialPeelLoop && major_progress() && (loop_opts_cnt > 0)) {
2319 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2320 PhaseIdealLoop ideal_loop(igvn, LoopOptsSkipSplitIf);
2321 loop_opts_cnt--;
2322 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
2323 if (failing()) return;
2324 }
2325 // Loop opts pass for loop-unrolling before CCP
2326 if(major_progress() && (loop_opts_cnt > 0)) {
2327 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2328 PhaseIdealLoop ideal_loop(igvn, LoopOptsSkipSplitIf);
2329 loop_opts_cnt--;
2330 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP3, 2);
2331 }
2332 if (!failing()) {
2333 // Verify that last round of loop opts produced a valid graph
2334 TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]);
2335 PhaseIdealLoop::verify(igvn);
2336 }
2337 }
2338 if (failing()) return;
2339
2340 // Conditional Constant Propagation;
2341 PhaseCCP ccp( &igvn );
2342 assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
2343 {
2344 TracePhase tp("ccp", &timers[_t_ccp]);
2345 ccp.do_transform();
2346 }
2347 print_method(PHASE_CPP1, 2);
2348
2349 assert( true, "Break here to ccp.dump_old2new_map()");
2350
2351 // Iterative Global Value Numbering, including ideal transforms
2352 {
2353 TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
2354 igvn = ccp;
2355 igvn.optimize();
2356 }
2357
2358 print_method(PHASE_ITER_GVN2, 2);
2359
2360 if (failing()) return;
2361
2362 // Loop transforms on the ideal graph. Range Check Elimination,
2363 // peeling, unrolling, etc.
2364 if (!optimize_loops(loop_opts_cnt, igvn, LoopOptsDefault)) {
2365 return;
2366 }
2367
2368 #if INCLUDE_ZGC
2369 if (UseZGC) {
2370 ZBarrierSetC2::find_dominating_barriers(igvn);
2371 }
2372 #endif
2373
2374 if (failing()) return;
2375
2376 // Ensure that major progress is now clear
2377 C->clear_major_progress();
2378
2379 {
2380 // Verify that all previous optimizations produced a valid graph
2381 // at least to this point, even if no loop optimizations were done.
2382 TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]);
2383 PhaseIdealLoop::verify(igvn);
2384 }
2387 // No more loop optimizations. Remove all range check dependent CastIINodes.
2388 C->remove_range_check_casts(igvn);
2389 igvn.optimize();
2390 }
2391
2392 #ifdef ASSERT
2393 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2394 bs->verify_gc_barriers(this, BarrierSetC2::BeforeExpand);
2395 #endif
2396
2397 {
2398 TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2399 PhaseMacroExpand mex(igvn);
2400 print_method(PHASE_BEFORE_MACRO_EXPANSION, 2);
2401 if (mex.expand_macro_nodes()) {
2402 assert(failing(), "must bail out w/ explicit message");
2403 return;
2404 }
2405 }
2406
2407 if (opaque4_count() > 0) {
2408 C->remove_opaque4_nodes(igvn);
2409 igvn.optimize();
2410 }
2411
2412 DEBUG_ONLY( _modified_nodes = NULL; )
2413 } // (End scope of igvn; run destructor if necessary for asserts.)
2414
2415 process_print_inlining();
2416 // A method with only infinite loops has no edges entering loops from root
2417 {
2418 TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2419 if (final_graph_reshaping()) {
2420 assert(failing(), "must bail out w/ explicit message");
2421 return;
2422 }
2423 }
2424
2425 print_method(PHASE_OPTIMIZE_FINISHED, 2);
2426 }
|
1105
1106 // Create Debug Information Recorder to record scopes, oopmaps, etc.
1107 env()->set_oop_recorder(new OopRecorder(env()->arena()));
1108 env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
1109 env()->set_dependencies(new Dependencies(env()));
1110
1111 _fixed_slots = 0;
1112 set_has_split_ifs(false);
1113 set_has_loops(has_method() && method()->has_loops()); // first approximation
1114 set_has_stringbuilder(false);
1115 set_has_boxed_value(false);
1116 _trap_can_recompile = false; // no traps emitted yet
1117 _major_progress = true; // start out assuming good things will happen
1118 set_has_unsafe_access(false);
1119 set_max_vector_size(0);
1120 set_clear_upper_avx(false); //false as default for clear upper bits of ymm registers
1121 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1122 set_decompile_count(0);
1123
1124 set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1125 _loop_opts_cnt = LoopOptsCount;
1126 set_do_inlining(Inline);
1127 set_max_inline_size(MaxInlineSize);
1128 set_freq_inline_size(FreqInlineSize);
1129 set_do_scheduling(OptoScheduling);
1130 set_do_count_invocations(false);
1131 set_do_method_data_update(false);
1132
1133 set_do_vector_loop(false);
1134
1135 if (AllowVectorizeOnDemand) {
1136 if (has_method() && (_directive->VectorizeOption || _directive->VectorizeDebugOption)) {
1137 set_do_vector_loop(true);
1138 NOT_PRODUCT(if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n", method()->name()->as_quoted_ascii());})
1139 } else if (has_method() && method()->name() != 0 &&
1140 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1141 set_do_vector_loop(true);
1142 }
1143 }
1144 set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1145 NOT_PRODUCT(if (use_cmove() && Verbose && has_method()) {tty->print("Compile::Init: use CMove without profitability tests for method %s\n", method()->name()->as_quoted_ascii());})
2152
2153 if (failing()) return;
2154
2155 {
2156 TracePhase tp("incrementalInline_pru", &timers[_t_incrInline_pru]);
2157 ResourceMark rm;
2158 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
2159 }
2160
2161 {
2162 TracePhase tp("incrementalInline_igvn", &timers[_t_incrInline_igvn]);
2163 igvn = PhaseIterGVN(gvn);
2164 igvn.optimize();
2165 }
2166 }
2167
2168 set_inlining_incrementally(false);
2169 }
2170
2171
2172 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2173 if(_loop_opts_cnt > 0) {
2174 debug_only( int cnt = 0; );
2175 while(major_progress() && (_loop_opts_cnt > 0)) {
2176 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2177 assert( cnt++ < 40, "infinite cycle in loop optimization" );
2178 PhaseIdealLoop ideal_loop(igvn, mode);
2179 _loop_opts_cnt--;
2180 if (failing()) return false;
2181 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2182 }
2183 }
2184 return true;
2185 }
2186
2187 //------------------------------Optimize---------------------------------------
2188 // Given a graph, optimize it.
2189 void Compile::Optimize() {
2190 TracePhase tp("optimizer", &timers[_t_optimizer]);
2191
2192 #ifndef PRODUCT
2193 if (_directive->BreakAtCompileOption) {
2194 BREAKPOINT;
2195 }
2196
2197 #endif
2198
2199 #ifdef ASSERT
2200 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2201 bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
2202 #endif
2203
2204 ResourceMark rm;
2205
2206 print_inlining_reinit();
2207
2208 NOT_PRODUCT( verify_graph_edges(); )
2209
2210 print_method(PHASE_AFTER_PARSING);
2211
2212 {
2213 // Iterative Global Value Numbering, including ideal transforms
2214 // Initialize IterGVN with types and values from parse-time GVN
2215 PhaseIterGVN igvn(initial_gvn());
2216 #ifdef ASSERT
2217 _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
2218 #endif
2219 {
2220 TracePhase tp("iterGVN", &timers[_t_iterGVN]);
2221 igvn.optimize();
2222 }
2223
2224 if (failing()) return;
2287
2288 if (failing()) return;
2289
2290 if (congraph() != NULL && macro_count() > 0) {
2291 TracePhase tp("macroEliminate", &timers[_t_macroEliminate]);
2292 PhaseMacroExpand mexp(igvn);
2293 mexp.eliminate_macro_nodes();
2294 igvn.set_delay_transform(false);
2295
2296 igvn.optimize();
2297 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2298
2299 if (failing()) return;
2300 }
2301 }
2302
2303 // Loop transforms on the ideal graph. Range Check Elimination,
2304 // peeling, unrolling, etc.
2305
2306 // Set loop opts counter
2307 if((_loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
2308 {
2309 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2310 PhaseIdealLoop ideal_loop(igvn, LoopOptsDefault);
2311 _loop_opts_cnt--;
2312 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
2313 if (failing()) return;
2314 }
2315 // Loop opts pass if partial peeling occurred in previous pass
2316 if(PartialPeelLoop && major_progress() && (_loop_opts_cnt > 0)) {
2317 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2318 PhaseIdealLoop ideal_loop(igvn, LoopOptsSkipSplitIf);
2319 _loop_opts_cnt--;
2320 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
2321 if (failing()) return;
2322 }
2323 // Loop opts pass for loop-unrolling before CCP
2324 if(major_progress() && (_loop_opts_cnt > 0)) {
2325 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2326 PhaseIdealLoop ideal_loop(igvn, LoopOptsSkipSplitIf);
2327 _loop_opts_cnt--;
2328 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP3, 2);
2329 }
2330 if (!failing()) {
2331 // Verify that last round of loop opts produced a valid graph
2332 TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]);
2333 PhaseIdealLoop::verify(igvn);
2334 }
2335 }
2336 if (failing()) return;
2337
2338 // Conditional Constant Propagation;
2339 PhaseCCP ccp( &igvn );
2340 assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
2341 {
2342 TracePhase tp("ccp", &timers[_t_ccp]);
2343 ccp.do_transform();
2344 }
2345 print_method(PHASE_CPP1, 2);
2346
2347 assert( true, "Break here to ccp.dump_old2new_map()");
2348
2349 // Iterative Global Value Numbering, including ideal transforms
2350 {
2351 TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
2352 igvn = ccp;
2353 igvn.optimize();
2354 }
2355
2356 print_method(PHASE_ITER_GVN2, 2);
2357
2358 if (failing()) return;
2359
2360 // Loop transforms on the ideal graph. Range Check Elimination,
2361 // peeling, unrolling, etc.
2362 if (!optimize_loops(igvn, LoopOptsDefault)) {
2363 return;
2364 }
2365
2366 #if INCLUDE_ZGC
2367 if (UseZGC) {
2368 ZBarrierSetC2::find_dominating_barriers(igvn);
2369 }
2370 #endif
2371
2372 if (failing()) return;
2373
2374 // Ensure that major progress is now clear
2375 C->clear_major_progress();
2376
2377 {
2378 // Verify that all previous optimizations produced a valid graph
2379 // at least to this point, even if no loop optimizations were done.
2380 TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]);
2381 PhaseIdealLoop::verify(igvn);
2382 }
2385 // No more loop optimizations. Remove all range check dependent CastIINodes.
2386 C->remove_range_check_casts(igvn);
2387 igvn.optimize();
2388 }
2389
2390 #ifdef ASSERT
2391 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2392 bs->verify_gc_barriers(this, BarrierSetC2::BeforeExpand);
2393 #endif
2394
2395 {
2396 TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2397 PhaseMacroExpand mex(igvn);
2398 print_method(PHASE_BEFORE_MACRO_EXPANSION, 2);
2399 if (mex.expand_macro_nodes()) {
2400 assert(failing(), "must bail out w/ explicit message");
2401 return;
2402 }
2403 }
2404
2405 {
2406 TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
2407 print_method(PHASE_BEFORE_BARRIER_EXPAND, 2);
2408 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2409 if (bs->expand_barriers(this, igvn)) {
2410 assert(failing(), "must bail out w/ explicit message");
2411 return;
2412 }
2413 }
2414
2415 if (opaque4_count() > 0) {
2416 C->remove_opaque4_nodes(igvn);
2417 igvn.optimize();
2418 }
2419
2420 DEBUG_ONLY( _modified_nodes = NULL; )
2421 } // (End scope of igvn; run destructor if necessary for asserts.)
2422
2423 process_print_inlining();
2424 // A method with only infinite loops has no edges entering loops from root
2425 {
2426 TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2427 if (final_graph_reshaping()) {
2428 assert(failing(), "must bail out w/ explicit message");
2429 return;
2430 }
2431 }
2432
2433 print_method(PHASE_OPTIMIZE_FINISHED, 2);
2434 }
|