Mercurial > hg > truffle
comparison src/share/vm/opto/compile.cpp @ 7196:2aff40cb4703
7092905: C2: Keep track of the number of dead nodes
Summary: keep an (almost) accurate running count of the reachable (live) flow graph nodes.
Reviewed-by: kvn, twisti, jrose, vlivanov
author | bharadwaj |
---|---|
date | Tue, 27 Nov 2012 17:24:15 -0800 |
parents | cfe522e6461c |
children | cd3d6a6b95d9 |
comparison
equal
deleted
inserted
replaced
7195:2cd5e15048e6 | 7196:2aff40cb4703 |
---|---|
314 i -= uses_found; // we deleted 1 or more copies of this edge | 314 i -= uses_found; // we deleted 1 or more copies of this edge |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 | 318 |
319 | 319 static inline bool not_a_node(const Node* n) { |
320 if (n == NULL) return true; | |
321 if (((intptr_t)n & 1) != 0) return true; // uninitialized, etc. | |
322 if (*(address*)n == badAddress) return true; // kill by Node::destruct | |
323 return false; | |
324 } | |
320 | 325 |
321 // Identify all nodes that are reachable from below, useful. | 326 // Identify all nodes that are reachable from below, useful. |
322 // Use breadth-first pass that records state in a Unique_Node_List, | 327 // Use breadth-first pass that records state in a Unique_Node_List, |
323 // recursive traversal is slower. | 328 // recursive traversal is slower. |
324 void Compile::identify_useful_nodes(Unique_Node_List &useful) { | 329 void Compile::identify_useful_nodes(Unique_Node_List &useful) { |
335 assert( next < unique(), "Unique useful nodes < total nodes"); | 340 assert( next < unique(), "Unique useful nodes < total nodes"); |
336 Node *n = useful.at(next); | 341 Node *n = useful.at(next); |
337 uint max = n->len(); | 342 uint max = n->len(); |
338 for( uint i = 0; i < max; ++i ) { | 343 for( uint i = 0; i < max; ++i ) { |
339 Node *m = n->in(i); | 344 Node *m = n->in(i); |
340 if( m == NULL ) continue; | 345 if (not_a_node(m)) continue; |
341 useful.push(m); | 346 useful.push(m); |
347 } | |
348 } | |
349 } | |
350 | |
351 // Update dead_node_list with any missing dead nodes using useful | |
352 // list. Consider all non-useful nodes to be useless i.e., dead nodes. | |
353 void Compile::update_dead_node_list(Unique_Node_List &useful) { | |
354 uint max_idx = unique(); | |
355 VectorSet& useful_node_set = useful.member_set(); | |
356 | |
357 for (uint node_idx = 0; node_idx < max_idx; node_idx++) { | |
358 // If node with index node_idx is not in useful set, | |
359 // mark it as dead in dead node list. | |
360 if (! useful_node_set.test(node_idx) ) { | |
361 record_dead_node(node_idx); | |
342 } | 362 } |
343 } | 363 } |
344 } | 364 } |
345 | 365 |
346 // Disconnect all useless nodes by disconnecting those at the boundary. | 366 // Disconnect all useless nodes by disconnecting those at the boundary. |
580 _node_bundling_base(NULL), | 600 _node_bundling_base(NULL), |
581 _java_calls(0), | 601 _java_calls(0), |
582 _inner_loops(0), | 602 _inner_loops(0), |
583 _scratch_const_size(-1), | 603 _scratch_const_size(-1), |
584 _in_scratch_emit_size(false), | 604 _in_scratch_emit_size(false), |
605 _dead_node_list(comp_arena()), | |
606 _dead_node_count(0), | |
585 #ifndef PRODUCT | 607 #ifndef PRODUCT |
586 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")), | 608 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")), |
587 _printer(IdealGraphPrinter::printer()), | 609 _printer(IdealGraphPrinter::printer()), |
588 #endif | 610 #endif |
589 _congraph(NULL) { | 611 _congraph(NULL) { |
871 _inner_loops(0), | 893 _inner_loops(0), |
872 #ifndef PRODUCT | 894 #ifndef PRODUCT |
873 _trace_opto_output(TraceOptoOutput), | 895 _trace_opto_output(TraceOptoOutput), |
874 _printer(NULL), | 896 _printer(NULL), |
875 #endif | 897 #endif |
898 _dead_node_list(comp_arena()), | |
899 _dead_node_count(0), | |
876 _congraph(NULL) { | 900 _congraph(NULL) { |
877 C = this; | 901 C = this; |
878 | 902 |
879 #ifndef PRODUCT | 903 #ifndef PRODUCT |
880 TraceTime t1(NULL, &_t_totalCompilation, TimeCompiler, false); | 904 TraceTime t1(NULL, &_t_totalCompilation, TimeCompiler, false); |
1066 // their _out arrays. | 1090 // their _out arrays. |
1067 if (_top != NULL) _top->setup_is_top(); | 1091 if (_top != NULL) _top->setup_is_top(); |
1068 if (old_top != NULL) old_top->setup_is_top(); | 1092 if (old_top != NULL) old_top->setup_is_top(); |
1069 assert(_top == NULL || top()->is_top(), ""); | 1093 assert(_top == NULL || top()->is_top(), ""); |
1070 } | 1094 } |
1095 | |
1096 #ifdef ASSERT | |
1097 uint Compile::count_live_nodes_by_graph_walk() { | |
1098 Unique_Node_List useful(comp_arena()); | |
1099 // Get useful node list by walking the graph. | |
1100 identify_useful_nodes(useful); | |
1101 return useful.size(); | |
1102 } | |
1103 | |
1104 void Compile::print_missing_nodes() { | |
1105 | |
1106 // Return if CompileLog is NULL and PrintIdealNodeCount is false. | |
1107 if ((_log == NULL) && (! PrintIdealNodeCount)) { | |
1108 return; | |
1109 } | |
1110 | |
1111 // This is an expensive function. It is executed only when the user | |
1112 // specifies VerifyIdealNodeCount option or otherwise knows the | |
1113 // additional work that needs to be done to identify reachable nodes | |
1114 // by walking the flow graph and find the missing ones using | |
1115 // _dead_node_list. | |
1116 | |
1117 Unique_Node_List useful(comp_arena()); | |
1118 // Get useful node list by walking the graph. | |
1119 identify_useful_nodes(useful); | |
1120 | |
1121 uint l_nodes = C->live_nodes(); | |
1122 uint l_nodes_by_walk = useful.size(); | |
1123 | |
1124 if (l_nodes != l_nodes_by_walk) { | |
1125 if (_log != NULL) { | |
1126 _log->begin_head("mismatched_nodes count='%d'", abs((int) (l_nodes - l_nodes_by_walk))); | |
1127 _log->stamp(); | |
1128 _log->end_head(); | |
1129 } | |
1130 VectorSet& useful_member_set = useful.member_set(); | |
1131 int last_idx = l_nodes_by_walk; | |
1132 for (int i = 0; i < last_idx; i++) { | |
1133 if (useful_member_set.test(i)) { | |
1134 if (_dead_node_list.test(i)) { | |
1135 if (_log != NULL) { | |
1136 _log->elem("mismatched_node_info node_idx='%d' type='both live and dead'", i); | |
1137 } | |
1138 if (PrintIdealNodeCount) { | |
1139 // Print the log message to tty | |
1140 tty->print_cr("mismatched_node idx='%d' both live and dead'", i); | |
1141 useful.at(i)->dump(); | |
1142 } | |
1143 } | |
1144 } | |
1145 else if (! _dead_node_list.test(i)) { | |
1146 if (_log != NULL) { | |
1147 _log->elem("mismatched_node_info node_idx='%d' type='neither live nor dead'", i); | |
1148 } | |
1149 if (PrintIdealNodeCount) { | |
1150 // Print the log message to tty | |
1151 tty->print_cr("mismatched_node idx='%d' type='neither live nor dead'", i); | |
1152 } | |
1153 } | |
1154 } | |
1155 if (_log != NULL) { | |
1156 _log->tail("mismatched_nodes"); | |
1157 } | |
1158 } | |
1159 } | |
1160 #endif | |
1071 | 1161 |
1072 #ifndef PRODUCT | 1162 #ifndef PRODUCT |
1073 void Compile::verify_top(Node* tn) const { | 1163 void Compile::verify_top(Node* tn) const { |
1074 if (tn != NULL) { | 1164 if (tn != NULL) { |
1075 assert(tn->is_Con(), "top node must be a constant"); | 1165 assert(tn->is_Con(), "top node must be a constant"); |
2085 // Note that OffsetBot and OffsetTop are very negative. | 2175 // Note that OffsetBot and OffsetTop are very negative. |
2086 } | 2176 } |
2087 | 2177 |
2088 // Eliminate trivially redundant StoreCMs and accumulate their | 2178 // Eliminate trivially redundant StoreCMs and accumulate their |
2089 // precedence edges. | 2179 // precedence edges. |
2090 static void eliminate_redundant_card_marks(Node* n) { | 2180 void Compile::eliminate_redundant_card_marks(Node* n) { |
2091 assert(n->Opcode() == Op_StoreCM, "expected StoreCM"); | 2181 assert(n->Opcode() == Op_StoreCM, "expected StoreCM"); |
2092 if (n->in(MemNode::Address)->outcnt() > 1) { | 2182 if (n->in(MemNode::Address)->outcnt() > 1) { |
2093 // There are multiple users of the same address so it might be | 2183 // There are multiple users of the same address so it might be |
2094 // possible to eliminate some of the StoreCMs | 2184 // possible to eliminate some of the StoreCMs |
2095 Node* mem = n->in(MemNode::Memory); | 2185 Node* mem = n->in(MemNode::Memory); |
2120 done = true; | 2210 done = true; |
2121 } | 2211 } |
2122 // Eliminate the previous StoreCM | 2212 // Eliminate the previous StoreCM |
2123 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory)); | 2213 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory)); |
2124 assert(mem->outcnt() == 0, "should be dead"); | 2214 assert(mem->outcnt() == 0, "should be dead"); |
2125 mem->disconnect_inputs(NULL); | 2215 mem->disconnect_inputs(NULL, this); |
2126 } else { | 2216 } else { |
2127 prev = mem; | 2217 prev = mem; |
2128 } | 2218 } |
2129 mem = prev->in(MemNode::Memory); | 2219 mem = prev->in(MemNode::Memory); |
2130 } | 2220 } |
2131 } | 2221 } |
2132 } | 2222 } |
2133 | 2223 |
2134 //------------------------------final_graph_reshaping_impl---------------------- | 2224 //------------------------------final_graph_reshaping_impl---------------------- |
2135 // Implement items 1-5 from final_graph_reshaping below. | 2225 // Implement items 1-5 from final_graph_reshaping below. |
2136 static void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc ) { | 2226 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) { |
2137 | 2227 |
2138 if ( n->outcnt() == 0 ) return; // dead node | 2228 if ( n->outcnt() == 0 ) return; // dead node |
2139 uint nop = n->Opcode(); | 2229 uint nop = n->Opcode(); |
2140 | 2230 |
2141 // Check for 2-input instruction with "last use" on right input. | 2231 // Check for 2-input instruction with "last use" on right input. |
2161 } | 2251 } |
2162 } | 2252 } |
2163 | 2253 |
2164 #ifdef ASSERT | 2254 #ifdef ASSERT |
2165 if( n->is_Mem() ) { | 2255 if( n->is_Mem() ) { |
2166 Compile* C = Compile::current(); | 2256 int alias_idx = get_alias_index(n->as_Mem()->adr_type()); |
2167 int alias_idx = C->get_alias_index(n->as_Mem()->adr_type()); | |
2168 assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw || | 2257 assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw || |
2169 // oop will be recorded in oop map if load crosses safepoint | 2258 // oop will be recorded in oop map if load crosses safepoint |
2170 n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() || | 2259 n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() || |
2171 LoadNode::is_immutable_value(n->in(MemNode::Address))), | 2260 LoadNode::is_immutable_value(n->in(MemNode::Address))), |
2172 "raw memory operations should have control edge"); | 2261 "raw memory operations should have control edge"); |
2211 case Op_CmpD3: | 2300 case Op_CmpD3: |
2212 frc.inc_double_count(); | 2301 frc.inc_double_count(); |
2213 break; | 2302 break; |
2214 case Op_Opaque1: // Remove Opaque Nodes before matching | 2303 case Op_Opaque1: // Remove Opaque Nodes before matching |
2215 case Op_Opaque2: // Remove Opaque Nodes before matching | 2304 case Op_Opaque2: // Remove Opaque Nodes before matching |
2216 n->subsume_by(n->in(1)); | 2305 n->subsume_by(n->in(1), this); |
2217 break; | 2306 break; |
2218 case Op_CallStaticJava: | 2307 case Op_CallStaticJava: |
2219 case Op_CallJava: | 2308 case Op_CallJava: |
2220 case Op_CallDynamicJava: | 2309 case Op_CallDynamicJava: |
2221 frc.inc_java_call_count(); // Count java call site; | 2310 frc.inc_java_call_count(); // Count java call site; |
2335 Node* nn = NULL; | 2424 Node* nn = NULL; |
2336 | 2425 |
2337 int op = t->isa_oopptr() ? Op_ConN : Op_ConNKlass; | 2426 int op = t->isa_oopptr() ? Op_ConN : Op_ConNKlass; |
2338 | 2427 |
2339 // Look for existing ConN node of the same exact type. | 2428 // Look for existing ConN node of the same exact type. |
2340 Compile* C = Compile::current(); | 2429 Node* r = root(); |
2341 Node* r = C->root(); | |
2342 uint cnt = r->outcnt(); | 2430 uint cnt = r->outcnt(); |
2343 for (uint i = 0; i < cnt; i++) { | 2431 for (uint i = 0; i < cnt; i++) { |
2344 Node* m = r->raw_out(i); | 2432 Node* m = r->raw_out(i); |
2345 if (m!= NULL && m->Opcode() == op && | 2433 if (m!= NULL && m->Opcode() == op && |
2346 m->bottom_type()->make_ptr() == t) { | 2434 m->bottom_type()->make_ptr() == t) { |
2350 } | 2438 } |
2351 if (nn != NULL) { | 2439 if (nn != NULL) { |
2352 // Decode a narrow oop to match address | 2440 // Decode a narrow oop to match address |
2353 // [R12 + narrow_oop_reg<<3 + offset] | 2441 // [R12 + narrow_oop_reg<<3 + offset] |
2354 if (t->isa_oopptr()) { | 2442 if (t->isa_oopptr()) { |
2355 nn = new (C) DecodeNNode(nn, t); | 2443 nn = new (this) DecodeNNode(nn, t); |
2356 } else { | 2444 } else { |
2357 nn = new (C) DecodeNKlassNode(nn, t); | 2445 nn = new (this) DecodeNKlassNode(nn, t); |
2358 } | 2446 } |
2359 n->set_req(AddPNode::Base, nn); | 2447 n->set_req(AddPNode::Base, nn); |
2360 n->set_req(AddPNode::Address, nn); | 2448 n->set_req(AddPNode::Address, nn); |
2361 if (addp->outcnt() == 0) { | 2449 if (addp->outcnt() == 0) { |
2362 addp->disconnect_inputs(NULL); | 2450 addp->disconnect_inputs(NULL, this); |
2363 } | 2451 } |
2364 } | 2452 } |
2365 } | 2453 } |
2366 } | 2454 } |
2367 #endif | 2455 #endif |
2369 } | 2457 } |
2370 | 2458 |
2371 #ifdef _LP64 | 2459 #ifdef _LP64 |
2372 case Op_CastPP: | 2460 case Op_CastPP: |
2373 if (n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) { | 2461 if (n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) { |
2374 Compile* C = Compile::current(); | |
2375 Node* in1 = n->in(1); | 2462 Node* in1 = n->in(1); |
2376 const Type* t = n->bottom_type(); | 2463 const Type* t = n->bottom_type(); |
2377 Node* new_in1 = in1->clone(); | 2464 Node* new_in1 = in1->clone(); |
2378 new_in1->as_DecodeN()->set_type(t); | 2465 new_in1->as_DecodeN()->set_type(t); |
2379 | 2466 |
2398 // corresponds to use it as value in implicit_null_check(). | 2485 // corresponds to use it as value in implicit_null_check(). |
2399 // | 2486 // |
2400 new_in1->set_req(0, n->in(0)); | 2487 new_in1->set_req(0, n->in(0)); |
2401 } | 2488 } |
2402 | 2489 |
2403 n->subsume_by(new_in1); | 2490 n->subsume_by(new_in1, this); |
2404 if (in1->outcnt() == 0) { | 2491 if (in1->outcnt() == 0) { |
2405 in1->disconnect_inputs(NULL); | 2492 in1->disconnect_inputs(NULL, this); |
2406 } | 2493 } |
2407 } | 2494 } |
2408 break; | 2495 break; |
2409 | 2496 |
2410 case Op_CmpP: | 2497 case Op_CmpP: |
2417 in2 = in1; | 2504 in2 = in1; |
2418 in1 = n->in(2); | 2505 in1 = n->in(2); |
2419 } | 2506 } |
2420 assert(in1->is_DecodeNarrowPtr(), "sanity"); | 2507 assert(in1->is_DecodeNarrowPtr(), "sanity"); |
2421 | 2508 |
2422 Compile* C = Compile::current(); | |
2423 Node* new_in2 = NULL; | 2509 Node* new_in2 = NULL; |
2424 if (in2->is_DecodeNarrowPtr()) { | 2510 if (in2->is_DecodeNarrowPtr()) { |
2425 assert(in2->Opcode() == in1->Opcode(), "must be same node type"); | 2511 assert(in2->Opcode() == in1->Opcode(), "must be same node type"); |
2426 new_in2 = in2->in(1); | 2512 new_in2 = in2->in(1); |
2427 } else if (in2->Opcode() == Op_ConP) { | 2513 } else if (in2->Opcode() == Op_ConP) { |
2430 assert(in1->is_DecodeN(), "compare klass to null?"); | 2516 assert(in1->is_DecodeN(), "compare klass to null?"); |
2431 // Don't convert CmpP null check into CmpN if compressed | 2517 // Don't convert CmpP null check into CmpN if compressed |
2432 // oops implicit null check is not generated. | 2518 // oops implicit null check is not generated. |
2433 // This will allow to generate normal oop implicit null check. | 2519 // This will allow to generate normal oop implicit null check. |
2434 if (Matcher::gen_narrow_oop_implicit_null_checks()) | 2520 if (Matcher::gen_narrow_oop_implicit_null_checks()) |
2435 new_in2 = ConNode::make(C, TypeNarrowOop::NULL_PTR); | 2521 new_in2 = ConNode::make(this, TypeNarrowOop::NULL_PTR); |
2436 // | 2522 // |
2437 // This transformation together with CastPP transformation above | 2523 // This transformation together with CastPP transformation above |
2438 // will generated code for implicit NULL checks for compressed oops. | 2524 // will generated code for implicit NULL checks for compressed oops. |
2439 // | 2525 // |
2440 // The original code after Optimize() | 2526 // The original code after Optimize() |
2469 // decode_not_null narrow_oop_reg, base_reg | 2555 // decode_not_null narrow_oop_reg, base_reg |
2470 // Load [base_reg + offset], val_reg | 2556 // Load [base_reg + offset], val_reg |
2471 // NullCheck base_reg | 2557 // NullCheck base_reg |
2472 // | 2558 // |
2473 } else if (t->isa_oopptr()) { | 2559 } else if (t->isa_oopptr()) { |
2474 new_in2 = ConNode::make(C, t->make_narrowoop()); | 2560 new_in2 = ConNode::make(this, t->make_narrowoop()); |
2475 } else if (t->isa_klassptr()) { | 2561 } else if (t->isa_klassptr()) { |
2476 new_in2 = ConNode::make(C, t->make_narrowklass()); | 2562 new_in2 = ConNode::make(this, t->make_narrowklass()); |
2477 } | 2563 } |
2478 } | 2564 } |
2479 if (new_in2 != NULL) { | 2565 if (new_in2 != NULL) { |
2480 Node* cmpN = new (C) CmpNNode(in1->in(1), new_in2); | 2566 Node* cmpN = new (this) CmpNNode(in1->in(1), new_in2); |
2481 n->subsume_by( cmpN ); | 2567 n->subsume_by(cmpN, this); |
2482 if (in1->outcnt() == 0) { | 2568 if (in1->outcnt() == 0) { |
2483 in1->disconnect_inputs(NULL); | 2569 in1->disconnect_inputs(NULL, this); |
2484 } | 2570 } |
2485 if (in2->outcnt() == 0) { | 2571 if (in2->outcnt() == 0) { |
2486 in2->disconnect_inputs(NULL); | 2572 in2->disconnect_inputs(NULL, this); |
2487 } | 2573 } |
2488 } | 2574 } |
2489 } | 2575 } |
2490 break; | 2576 break; |
2491 | 2577 |
2499 | 2585 |
2500 case Op_EncodeP: | 2586 case Op_EncodeP: |
2501 case Op_EncodePKlass: { | 2587 case Op_EncodePKlass: { |
2502 Node* in1 = n->in(1); | 2588 Node* in1 = n->in(1); |
2503 if (in1->is_DecodeNarrowPtr()) { | 2589 if (in1->is_DecodeNarrowPtr()) { |
2504 n->subsume_by(in1->in(1)); | 2590 n->subsume_by(in1->in(1), this); |
2505 } else if (in1->Opcode() == Op_ConP) { | 2591 } else if (in1->Opcode() == Op_ConP) { |
2506 Compile* C = Compile::current(); | |
2507 const Type* t = in1->bottom_type(); | 2592 const Type* t = in1->bottom_type(); |
2508 if (t == TypePtr::NULL_PTR) { | 2593 if (t == TypePtr::NULL_PTR) { |
2509 assert(t->isa_oopptr(), "null klass?"); | 2594 assert(t->isa_oopptr(), "null klass?"); |
2510 n->subsume_by(ConNode::make(C, TypeNarrowOop::NULL_PTR)); | 2595 n->subsume_by(ConNode::make(this, TypeNarrowOop::NULL_PTR), this); |
2511 } else if (t->isa_oopptr()) { | 2596 } else if (t->isa_oopptr()) { |
2512 n->subsume_by(ConNode::make(C, t->make_narrowoop())); | 2597 n->subsume_by(ConNode::make(this, t->make_narrowoop()), this); |
2513 } else if (t->isa_klassptr()) { | 2598 } else if (t->isa_klassptr()) { |
2514 n->subsume_by(ConNode::make(C, t->make_narrowklass())); | 2599 n->subsume_by(ConNode::make(this, t->make_narrowklass()), this); |
2515 } | 2600 } |
2516 } | 2601 } |
2517 if (in1->outcnt() == 0) { | 2602 if (in1->outcnt() == 0) { |
2518 in1->disconnect_inputs(NULL); | 2603 in1->disconnect_inputs(NULL, this); |
2519 } | 2604 } |
2520 break; | 2605 break; |
2521 } | 2606 } |
2522 | 2607 |
2523 case Op_Proj: { | 2608 case Op_Proj: { |
2536 proj = use; | 2621 proj = use; |
2537 break; | 2622 break; |
2538 } | 2623 } |
2539 } | 2624 } |
2540 assert(proj != NULL, "must be found"); | 2625 assert(proj != NULL, "must be found"); |
2541 p->subsume_by(proj); | 2626 p->subsume_by(proj, this); |
2542 } | 2627 } |
2543 } | 2628 } |
2544 break; | 2629 break; |
2545 } | 2630 } |
2546 | 2631 |
2556 assert(m != NULL, ""); | 2641 assert(m != NULL, ""); |
2557 if (unique_in != m) | 2642 if (unique_in != m) |
2558 unique_in = NULL; | 2643 unique_in = NULL; |
2559 } | 2644 } |
2560 if (unique_in != NULL) { | 2645 if (unique_in != NULL) { |
2561 n->subsume_by(unique_in); | 2646 n->subsume_by(unique_in, this); |
2562 } | 2647 } |
2563 } | 2648 } |
2564 break; | 2649 break; |
2565 | 2650 |
2566 #endif | 2651 #endif |
2569 if (UseDivMod) { | 2654 if (UseDivMod) { |
2570 // Check if a%b and a/b both exist | 2655 // Check if a%b and a/b both exist |
2571 Node* d = n->find_similar(Op_DivI); | 2656 Node* d = n->find_similar(Op_DivI); |
2572 if (d) { | 2657 if (d) { |
2573 // Replace them with a fused divmod if supported | 2658 // Replace them with a fused divmod if supported |
2574 Compile* C = Compile::current(); | |
2575 if (Matcher::has_match_rule(Op_DivModI)) { | 2659 if (Matcher::has_match_rule(Op_DivModI)) { |
2576 DivModINode* divmod = DivModINode::make(C, n); | 2660 DivModINode* divmod = DivModINode::make(this, n); |
2577 d->subsume_by(divmod->div_proj()); | 2661 d->subsume_by(divmod->div_proj(), this); |
2578 n->subsume_by(divmod->mod_proj()); | 2662 n->subsume_by(divmod->mod_proj(), this); |
2579 } else { | 2663 } else { |
2580 // replace a%b with a-((a/b)*b) | 2664 // replace a%b with a-((a/b)*b) |
2581 Node* mult = new (C) MulINode(d, d->in(2)); | 2665 Node* mult = new (this) MulINode(d, d->in(2)); |
2582 Node* sub = new (C) SubINode(d->in(1), mult); | 2666 Node* sub = new (this) SubINode(d->in(1), mult); |
2583 n->subsume_by( sub ); | 2667 n->subsume_by(sub, this); |
2584 } | 2668 } |
2585 } | 2669 } |
2586 } | 2670 } |
2587 break; | 2671 break; |
2588 | 2672 |
2590 if (UseDivMod) { | 2674 if (UseDivMod) { |
2591 // Check if a%b and a/b both exist | 2675 // Check if a%b and a/b both exist |
2592 Node* d = n->find_similar(Op_DivL); | 2676 Node* d = n->find_similar(Op_DivL); |
2593 if (d) { | 2677 if (d) { |
2594 // Replace them with a fused divmod if supported | 2678 // Replace them with a fused divmod if supported |
2595 Compile* C = Compile::current(); | |
2596 if (Matcher::has_match_rule(Op_DivModL)) { | 2679 if (Matcher::has_match_rule(Op_DivModL)) { |
2597 DivModLNode* divmod = DivModLNode::make(C, n); | 2680 DivModLNode* divmod = DivModLNode::make(this, n); |
2598 d->subsume_by(divmod->div_proj()); | 2681 d->subsume_by(divmod->div_proj(), this); |
2599 n->subsume_by(divmod->mod_proj()); | 2682 n->subsume_by(divmod->mod_proj(), this); |
2600 } else { | 2683 } else { |
2601 // replace a%b with a-((a/b)*b) | 2684 // replace a%b with a-((a/b)*b) |
2602 Node* mult = new (C) MulLNode(d, d->in(2)); | 2685 Node* mult = new (this) MulLNode(d, d->in(2)); |
2603 Node* sub = new (C) SubLNode(d->in(1), mult); | 2686 Node* sub = new (this) SubLNode(d->in(1), mult); |
2604 n->subsume_by( sub ); | 2687 n->subsume_by(sub, this); |
2605 } | 2688 } |
2606 } | 2689 } |
2607 } | 2690 } |
2608 break; | 2691 break; |
2609 | 2692 |
2618 case Op_PackL: | 2701 case Op_PackL: |
2619 case Op_PackD: | 2702 case Op_PackD: |
2620 if (n->req()-1 > 2) { | 2703 if (n->req()-1 > 2) { |
2621 // Replace many operand PackNodes with a binary tree for matching | 2704 // Replace many operand PackNodes with a binary tree for matching |
2622 PackNode* p = (PackNode*) n; | 2705 PackNode* p = (PackNode*) n; |
2623 Node* btp = p->binary_tree_pack(Compile::current(), 1, n->req()); | 2706 Node* btp = p->binary_tree_pack(this, 1, n->req()); |
2624 n->subsume_by(btp); | 2707 n->subsume_by(btp, this); |
2625 } | 2708 } |
2626 break; | 2709 break; |
2627 case Op_Loop: | 2710 case Op_Loop: |
2628 case Op_CountedLoop: | 2711 case Op_CountedLoop: |
2629 if (n->as_Loop()->is_inner_loop()) { | 2712 if (n->as_Loop()->is_inner_loop()) { |
2643 juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1); | 2726 juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1); |
2644 const TypeInt* t = in2->find_int_type(); | 2727 const TypeInt* t = in2->find_int_type(); |
2645 if (t != NULL && t->is_con()) { | 2728 if (t != NULL && t->is_con()) { |
2646 juint shift = t->get_con(); | 2729 juint shift = t->get_con(); |
2647 if (shift > mask) { // Unsigned cmp | 2730 if (shift > mask) { // Unsigned cmp |
2648 Compile* C = Compile::current(); | 2731 n->set_req(2, ConNode::make(this, TypeInt::make(shift & mask))); |
2649 n->set_req(2, ConNode::make(C, TypeInt::make(shift & mask))); | |
2650 } | 2732 } |
2651 } else { | 2733 } else { |
2652 if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) { | 2734 if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) { |
2653 Compile* C = Compile::current(); | 2735 Node* shift = new (this) AndINode(in2, ConNode::make(this, TypeInt::make(mask))); |
2654 Node* shift = new (C) AndINode(in2, ConNode::make(C, TypeInt::make(mask))); | |
2655 n->set_req(2, shift); | 2736 n->set_req(2, shift); |
2656 } | 2737 } |
2657 } | 2738 } |
2658 if (in2->outcnt() == 0) { // Remove dead node | 2739 if (in2->outcnt() == 0) { // Remove dead node |
2659 in2->disconnect_inputs(NULL); | 2740 in2->disconnect_inputs(NULL, this); |
2660 } | 2741 } |
2661 } | 2742 } |
2662 break; | 2743 break; |
2663 default: | 2744 default: |
2664 assert( !n->is_Call(), "" ); | 2745 assert( !n->is_Call(), "" ); |
2672 } | 2753 } |
2673 | 2754 |
2674 //------------------------------final_graph_reshaping_walk--------------------- | 2755 //------------------------------final_graph_reshaping_walk--------------------- |
2675 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(), | 2756 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(), |
2676 // requires that the walk visits a node's inputs before visiting the node. | 2757 // requires that the walk visits a node's inputs before visiting the node. |
2677 static void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) { | 2758 void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) { |
2678 ResourceArea *area = Thread::current()->resource_area(); | 2759 ResourceArea *area = Thread::current()->resource_area(); |
2679 Unique_Node_List sfpt(area); | 2760 Unique_Node_List sfpt(area); |
2680 | 2761 |
2681 frc._visited.set(root->_idx); // first, mark node as visited | 2762 frc._visited.set(root->_idx); // first, mark node as visited |
2682 uint cnt = root->req(); | 2763 uint cnt = root->req(); |
2739 } | 2820 } |
2740 if (safe_to_skip) { | 2821 if (safe_to_skip) { |
2741 n->set_req(j, in->in(1)); | 2822 n->set_req(j, in->in(1)); |
2742 } | 2823 } |
2743 if (in->outcnt() == 0) { | 2824 if (in->outcnt() == 0) { |
2744 in->disconnect_inputs(NULL); | 2825 in->disconnect_inputs(NULL, this); |
2745 } | 2826 } |
2746 } | 2827 } |
2747 } | 2828 } |
2748 } | 2829 } |
2749 } | 2830 } |
3012 } | 3093 } |
3013 _root = NULL; // flush the graph, too | 3094 _root = NULL; // flush the graph, too |
3014 } | 3095 } |
3015 | 3096 |
3016 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog) | 3097 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog) |
3017 : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false) | 3098 : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false), |
3099 _phase_name(name), _dolog(dolog) | |
3018 { | 3100 { |
3019 if (dolog) { | 3101 if (dolog) { |
3020 C = Compile::current(); | 3102 C = Compile::current(); |
3021 _log = C->log(); | 3103 _log = C->log(); |
3022 } else { | 3104 } else { |
3023 C = NULL; | 3105 C = NULL; |
3024 _log = NULL; | 3106 _log = NULL; |
3025 } | 3107 } |
3026 if (_log != NULL) { | 3108 if (_log != NULL) { |
3027 _log->begin_head("phase name='%s' nodes='%d'", name, C->unique()); | 3109 _log->begin_head("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes()); |
3028 _log->stamp(); | 3110 _log->stamp(); |
3029 _log->end_head(); | 3111 _log->end_head(); |
3030 } | 3112 } |
3031 } | 3113 } |
3032 | 3114 |
3033 Compile::TracePhase::~TracePhase() { | 3115 Compile::TracePhase::~TracePhase() { |
3116 | |
3117 C = Compile::current(); | |
3118 if (_dolog) { | |
3119 _log = C->log(); | |
3120 } else { | |
3121 _log = NULL; | |
3122 } | |
3123 | |
3124 #ifdef ASSERT | |
3125 if (PrintIdealNodeCount) { | |
3126 tty->print_cr("phase name='%s' nodes='%d' live='%d' live_graph_walk='%d'", | |
3127 _phase_name, C->unique(), C->live_nodes(), C->count_live_nodes_by_graph_walk()); | |
3128 } | |
3129 | |
3130 if (VerifyIdealNodeCount) { | |
3131 Compile::current()->print_missing_nodes(); | |
3132 } | |
3133 #endif | |
3134 | |
3034 if (_log != NULL) { | 3135 if (_log != NULL) { |
3035 _log->done("phase nodes='%d'", C->unique()); | 3136 _log->done("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes()); |
3036 } | 3137 } |
3037 } | 3138 } |
3038 | 3139 |
3039 //============================================================================= | 3140 //============================================================================= |
3040 // Two Constant's are equal when the type and the value are equal. | 3141 // Two Constant's are equal when the type and the value are equal. |