< prev index next >

src/hotspot/share/opto/compile.cpp

Print this page




  51 #include "opto/divnode.hpp"
  52 #include "opto/escape.hpp"
  53 #include "opto/idealGraphPrinter.hpp"
  54 #include "opto/loopnode.hpp"
  55 #include "opto/machnode.hpp"
  56 #include "opto/macro.hpp"
  57 #include "opto/matcher.hpp"
  58 #include "opto/mathexactnode.hpp"
  59 #include "opto/memnode.hpp"
  60 #include "opto/mulnode.hpp"
  61 #include "opto/narrowptrnode.hpp"
  62 #include "opto/node.hpp"
  63 #include "opto/opcodes.hpp"
  64 #include "opto/output.hpp"
  65 #include "opto/parse.hpp"
  66 #include "opto/phaseX.hpp"
  67 #include "opto/rootnode.hpp"
  68 #include "opto/runtime.hpp"
  69 #include "opto/stringopts.hpp"
  70 #include "opto/type.hpp"

  71 #include "opto/vectornode.hpp"
  72 #include "runtime/arguments.hpp"
  73 #include "runtime/sharedRuntime.hpp"
  74 #include "runtime/signature.hpp"
  75 #include "runtime/stubRoutines.hpp"
  76 #include "runtime/timer.hpp"
  77 #include "utilities/align.hpp"
  78 #include "utilities/copy.hpp"
  79 #include "utilities/macros.hpp"
  80 #include "utilities/resourceHash.hpp"
  81 
  82 
  83 // -------------------- Compile::mach_constant_base_node -----------------------
  84 // Constant table base node singleton.
  85 MachConstantBaseNode* Compile::mach_constant_base_node() {
  86   if (_mach_constant_base_node == NULL) {
  87     _mach_constant_base_node = new MachConstantBaseNode();
  88     _mach_constant_base_node->add_req(C->root());
  89   }
  90   return _mach_constant_base_node;


 394   // Remove useless expensive nodes
 395   for (int i = C->expensive_count()-1; i >= 0; i--) {
 396     Node* n = C->expensive_node(i);
 397     if (!useful.member(n)) {
 398       remove_expensive_node(n);
 399     }
 400   }
 401   // Remove useless Opaque4 nodes
 402   for (int i = opaque4_count() - 1; i >= 0; i--) {
 403     Node* opaq = opaque4_node(i);
 404     if (!useful.member(opaq)) {
 405       remove_opaque4_node(opaq);
 406     }
 407   }
 408   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 409   bs->eliminate_useless_gc_barriers(useful, this);
 410   // clean up the late inline lists
 411   remove_useless_late_inlines(&_string_late_inlines, useful);
 412   remove_useless_late_inlines(&_boxing_late_inlines, useful);
 413   remove_useless_late_inlines(&_late_inlines, useful);

 414   debug_only(verify_graph_edges(true/*check for no_dead_code*/);)
 415 }
 416 
 417 // ============================================================================
 418 //------------------------------CompileWrapper---------------------------------
 419 class CompileWrapper : public StackObj {
 420   Compile *const _compile;
 421  public:
 422   CompileWrapper(Compile* compile);
 423 
 424   ~CompileWrapper();
 425 };
 426 
 427 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
 428   // the Compile* pointer is stored in the current ciEnv:
 429   ciEnv* env = compile->env();
 430   assert(env == ciEnv::current(), "must already be a ciEnv active");
 431   assert(env->compiler_data() == NULL, "compile already active?");
 432   env->set_compiler_data(compile);
 433   assert(compile == Compile::current(), "sanity");


 526                   _comp_arena(mtCompiler),
 527                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 528                   _env(ci_env),
 529                   _directive(directive),
 530                   _log(ci_env->log()),
 531                   _failure_reason(NULL),
 532                   _congraph(NULL),
 533                   NOT_PRODUCT(_printer(NULL) COMMA)
 534                   _dead_node_list(comp_arena()),
 535                   _dead_node_count(0),
 536                   _node_arena(mtCompiler),
 537                   _old_arena(mtCompiler),
 538                   _mach_constant_base_node(NULL),
 539                   _Compile_types(mtCompiler),
 540                   _initial_gvn(NULL),
 541                   _for_igvn(NULL),
 542                   _warm_calls(NULL),
 543                   _late_inlines(comp_arena(), 2, 0, NULL),
 544                   _string_late_inlines(comp_arena(), 2, 0, NULL),
 545                   _boxing_late_inlines(comp_arena(), 2, 0, NULL),

 546                   _late_inlines_pos(0),
 547                   _number_of_mh_late_inlines(0),
 548                   _print_inlining_stream(NULL),
 549                   _print_inlining_list(NULL),
 550                   _print_inlining_idx(0),
 551                   _print_inlining_output(NULL),
 552                   _replay_inline_data(NULL),
 553                   _java_calls(0),
 554                   _inner_loops(0),
 555                   _interpreter_frame_size(0)
 556 #ifndef PRODUCT
 557                   , _in_dump_cnt(0)
 558 #endif
 559 {
 560   C = this;
 561   CompileWrapper cw(this);
 562 
 563   if (CITimeVerbose) {
 564     tty->print(" ");
 565     target->holder()->name()->print();


1929         low_live_nodes = live_nodes();
1930         _major_progress = true;
1931       }
1932 
1933       if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {
1934         break; // finish
1935       }
1936     }
1937 
1938     for_igvn()->clear();
1939     initial_gvn()->replace_with(&igvn);
1940 
1941     while (inline_incrementally_one()) {
1942       assert(!failing(), "inconsistent");
1943     }
1944 
1945     if (failing())  return;
1946 
1947     inline_incrementally_cleanup(igvn);
1948 


1949     if (failing())  return;
1950   }
1951   assert( igvn._worklist.size() == 0, "should be done with igvn" );
1952 
1953   if (_string_late_inlines.length() > 0) {
1954     assert(has_stringbuilder(), "inconsistent");
1955     for_igvn()->clear();
1956     initial_gvn()->replace_with(&igvn);
1957 
1958     inline_string_calls(false);
1959 
1960     if (failing())  return;
1961 
1962     inline_incrementally_cleanup(igvn);
1963   }
1964 
1965   set_inlining_incrementally(false);
1966 }
1967 
1968 


2063 
2064     print_method(PHASE_INCREMENTAL_BOXING_INLINE, 2);
2065 
2066     if (failing())  return;
2067   }
2068 
2069   // Now that all inlining is over, cut edge from root to loop
2070   // safepoints
2071   remove_root_to_sfpts_edges(igvn);
2072 
2073   // Remove the speculative part of types and clean up the graph from
2074   // the extra CastPP nodes whose only purpose is to carry them. Do
2075   // that early so that optimizations are not disrupted by the extra
2076   // CastPP nodes.
2077   remove_speculative_types(igvn);
2078 
2079   // No more new expensive nodes will be added to the list from here
2080   // so keep only the actual candidates for optimizations.
2081   cleanup_expensive_nodes(igvn);
2082 










2083   if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2084     Compile::TracePhase tp("", &timers[_t_renumberLive]);
2085     initial_gvn()->replace_with(&igvn);
2086     for_igvn()->clear();
2087     Unique_Node_List new_worklist(C->comp_arena());
2088     {
2089       ResourceMark rm;
2090       PhaseRenumberLive prl = PhaseRenumberLive(initial_gvn(), for_igvn(), &new_worklist);
2091     }
2092     set_for_igvn(&new_worklist);
2093     igvn = PhaseIterGVN(initial_gvn());
2094     igvn.optimize();
2095   }
2096 
2097   // Perform escape analysis
2098   if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) {
2099     if (has_loops()) {
2100       // Cleanup graph (remove dead nodes).
2101       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2102       PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);


2517       in2_unique_inputs_cnt = collect_unique_inputs(in2, not_used, not_used);
2518     }
2519     // Pick the node with minimum number of inputs.
2520     if (in1_unique_inputs_cnt >= 3 && in2_unique_inputs_cnt >= 3) {
2521       return false; // still too many inputs
2522     }
2523     // Recompute partition & inputs.
2524     Node* child       = (in1_unique_inputs_cnt < in2_unique_inputs_cnt ? in1 : in2);
2525     collect_unique_inputs(child, partition, inputs);
2526 
2527     Node* other_input = (in1_unique_inputs_cnt < in2_unique_inputs_cnt ? in2 : in1);
2528     inputs.push(other_input);
2529 
2530     partition.push(n);
2531   }
2532 
2533   return (partition.size() == 2 || partition.size() == 3) &&
2534          (inputs.size()    == 2 || inputs.size()    == 3);
2535 }
2536 




























2537 
2538 void Compile::process_logic_cone_root(PhaseIterGVN &igvn, Node *n, VectorSet &visited) {
2539   assert(is_vector_bitwise_op(n), "not a root");
2540 
2541   visited.set(n->_idx);
2542 
2543   // 1) Do a DFS walk over the logic cone.
2544   for (uint i = 1; i < n->req(); i++) {
2545     Node* in = n->in(i);
2546     if (!visited.test(in->_idx) && is_vector_bitwise_op(in)) {
2547       process_logic_cone_root(igvn, in, visited);
2548     }
2549   }
2550 
2551   // 2) Bottom up traversal: Merge node[s] with
2552   // the parent to form macro logic node.
2553   Unique_Node_List partition;
2554   Unique_Node_List inputs;
2555   if (compute_logic_cone(n, partition, inputs)) {
2556     const TypeVect* vt = n->bottom_type()->is_vect();


2585   }
2586 
2587   // Perform instruction selection.  You might think we could reclaim Matcher
2588   // memory PDQ, but actually the Matcher is used in generating spill code.
2589   // Internals of the Matcher (including some VectorSets) must remain live
2590   // for awhile - thus I cannot reclaim Matcher memory lest a VectorSet usage
2591   // set a bit in reclaimed memory.
2592 
2593   // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
2594   // nodes.  Mapping is only valid at the root of each matched subtree.
2595   NOT_PRODUCT( verify_graph_edges(); )
2596 
2597   Matcher matcher;
2598   _matcher = &matcher;
2599   {
2600     TracePhase tp("matcher", &timers[_t_matcher]);
2601     matcher.match();
2602     if (failing()) {
2603       return;
2604     }

2605   }
2606 
2607   // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
2608   // nodes.  Mapping is only valid at the root of each matched subtree.
2609   NOT_PRODUCT( verify_graph_edges(); )
2610 
2611   // If you have too many nodes, or if matching has failed, bail out
2612   check_node_count(0, "out of nodes matching instructions");
2613   if (failing()) {
2614     return;
2615   }
2616 
2617   print_method(PHASE_MATCHING, 2);
2618 
2619   // Build a proper-looking CFG
2620   PhaseCFG cfg(node_arena(), root(), matcher);
2621   _cfg = &cfg;
2622   {
2623     TracePhase tp("scheduler", &timers[_t_scheduler]);
2624     bool success = cfg.do_global_code_motion();
2625     if (!success) {
2626       return;


2774   }
2775 }
2776 
2777 //------------------------------final_graph_reshaping_impl----------------------
2778 // Implement items 1-5 from final_graph_reshaping below.
2779 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
2780 
2781   if ( n->outcnt() == 0 ) return; // dead node
2782   uint nop = n->Opcode();
2783 
2784   // Check for 2-input instruction with "last use" on right input.
2785   // Swap to left input.  Implements item (2).
2786   if( n->req() == 3 &&          // two-input instruction
2787       n->in(1)->outcnt() > 1 && // left use is NOT a last use
2788       (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
2789       n->in(2)->outcnt() == 1 &&// right use IS a last use
2790       !n->in(2)->is_Con() ) {   // right use is not a constant
2791     // Check for commutative opcode
2792     switch( nop ) {
2793     case Op_AddI:  case Op_AddF:  case Op_AddD:  case Op_AddL:
2794     case Op_MaxI:  case Op_MinI:

2795     case Op_MulI:  case Op_MulF:  case Op_MulD:  case Op_MulL:
2796     case Op_AndL:  case Op_XorL:  case Op_OrL:
2797     case Op_AndI:  case Op_XorI:  case Op_OrI: {
2798       // Move "last use" input to left by swapping inputs
2799       n->swap_edges(1, 2);
2800       break;
2801     }
2802     default:
2803       break;
2804     }
2805   }
2806 
2807 #ifdef ASSERT
2808   if( n->is_Mem() ) {
2809     int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2810     assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
2811             // oop will be recorded in oop map if load crosses safepoint
2812             n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
2813                              LoadNode::is_immutable_value(n->in(MemNode::Address))),
2814             "raw memory operations should have control edge");


3339       // Check if a%b and a/b both exist
3340       Node* d = n->find_similar(Op_DivL);
3341       if (d) {
3342         // Replace them with a fused divmod if supported
3343         if (Matcher::has_match_rule(Op_DivModL)) {
3344           DivModLNode* divmod = DivModLNode::make(n);
3345           d->subsume_by(divmod->div_proj(), this);
3346           n->subsume_by(divmod->mod_proj(), this);
3347         } else {
3348           // replace a%b with a-((a/b)*b)
3349           Node* mult = new MulLNode(d, d->in(2));
3350           Node* sub  = new SubLNode(d->in(1), mult);
3351           n->subsume_by(sub, this);
3352         }
3353       }
3354     }
3355     break;
3356 
3357   case Op_LoadVector:
3358   case Op_StoreVector:


3359     break;
3360 
3361   case Op_AddReductionVI:
3362   case Op_AddReductionVL:
3363   case Op_AddReductionVF:
3364   case Op_AddReductionVD:
3365   case Op_MulReductionVI:
3366   case Op_MulReductionVL:
3367   case Op_MulReductionVF:
3368   case Op_MulReductionVD:
3369   case Op_MinReductionV:
3370   case Op_MaxReductionV:
3371   case Op_AndReductionV:
3372   case Op_OrReductionV:
3373   case Op_XorReductionV:
3374     break;
3375 
3376   case Op_PackB:
3377   case Op_PackS:
3378   case Op_PackI:


4554   }
4555 }
4556 
4557 // Move Allocate nodes to the start of the list
4558 void Compile::sort_macro_nodes() {
4559   int count = macro_count();
4560   int allocates = 0;
4561   for (int i = 0; i < count; i++) {
4562     Node* n = macro_node(i);
4563     if (n->is_Allocate()) {
4564       if (i != allocates) {
4565         Node* tmp = macro_node(allocates);
4566         _macro_nodes->at_put(allocates, n);
4567         _macro_nodes->at_put(i, tmp);
4568       }
4569       allocates++;
4570     }
4571   }
4572 }
4573 
4574 void Compile::print_method(CompilerPhaseType cpt, int level, int idx) {
4575   EventCompilerPhase event;
4576   if (event.should_commit()) {
4577     CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, cpt, C->_compile_id, level);
4578   }
4579 
4580 #ifndef PRODUCT
4581   if (should_print(level)) {







4582     char output[1024];

4583     if (idx != 0) {
4584       jio_snprintf(output, sizeof(output), "%s:%d", CompilerPhaseTypeHelper::to_string(cpt), idx);
4585     } else {
4586       jio_snprintf(output, sizeof(output), "%s", CompilerPhaseTypeHelper::to_string(cpt));
4587     }
4588     _printer->print_method(output, level);
4589   }
4590 #endif
4591   C->_latest_stage_start_counter.stamp();












4592 }
4593 
4594 void Compile::end_method(int level) {
4595   EventCompilerPhase event;
4596   if (event.should_commit()) {
4597     CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, PHASE_END, C->_compile_id, level);
4598   }
4599 
4600 #ifndef PRODUCT
4601   if (_method != NULL && should_print(level)) {
4602     _printer->end_method();
4603   }
4604 #endif
4605 }
4606 
4607 
4608 #ifndef PRODUCT
4609 IdealGraphPrinter* Compile::_debug_file_printer = NULL;
4610 IdealGraphPrinter* Compile::_debug_network_printer = NULL;
4611 




  51 #include "opto/divnode.hpp"
  52 #include "opto/escape.hpp"
  53 #include "opto/idealGraphPrinter.hpp"
  54 #include "opto/loopnode.hpp"
  55 #include "opto/machnode.hpp"
  56 #include "opto/macro.hpp"
  57 #include "opto/matcher.hpp"
  58 #include "opto/mathexactnode.hpp"
  59 #include "opto/memnode.hpp"
  60 #include "opto/mulnode.hpp"
  61 #include "opto/narrowptrnode.hpp"
  62 #include "opto/node.hpp"
  63 #include "opto/opcodes.hpp"
  64 #include "opto/output.hpp"
  65 #include "opto/parse.hpp"
  66 #include "opto/phaseX.hpp"
  67 #include "opto/rootnode.hpp"
  68 #include "opto/runtime.hpp"
  69 #include "opto/stringopts.hpp"
  70 #include "opto/type.hpp"
  71 #include "opto/vector.hpp"
  72 #include "opto/vectornode.hpp"
  73 #include "runtime/arguments.hpp"
  74 #include "runtime/sharedRuntime.hpp"
  75 #include "runtime/signature.hpp"
  76 #include "runtime/stubRoutines.hpp"
  77 #include "runtime/timer.hpp"
  78 #include "utilities/align.hpp"
  79 #include "utilities/copy.hpp"
  80 #include "utilities/macros.hpp"
  81 #include "utilities/resourceHash.hpp"
  82 
  83 
  84 // -------------------- Compile::mach_constant_base_node -----------------------
  85 // Constant table base node singleton.
  86 MachConstantBaseNode* Compile::mach_constant_base_node() {
  87   if (_mach_constant_base_node == NULL) {
  88     _mach_constant_base_node = new MachConstantBaseNode();
  89     _mach_constant_base_node->add_req(C->root());
  90   }
  91   return _mach_constant_base_node;


 395   // Remove useless expensive nodes
 396   for (int i = C->expensive_count()-1; i >= 0; i--) {
 397     Node* n = C->expensive_node(i);
 398     if (!useful.member(n)) {
 399       remove_expensive_node(n);
 400     }
 401   }
 402   // Remove useless Opaque4 nodes
 403   for (int i = opaque4_count() - 1; i >= 0; i--) {
 404     Node* opaq = opaque4_node(i);
 405     if (!useful.member(opaq)) {
 406       remove_opaque4_node(opaq);
 407     }
 408   }
 409   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 410   bs->eliminate_useless_gc_barriers(useful, this);
 411   // clean up the late inline lists
 412   remove_useless_late_inlines(&_string_late_inlines, useful);
 413   remove_useless_late_inlines(&_boxing_late_inlines, useful);
 414   remove_useless_late_inlines(&_late_inlines, useful);
 415   remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
 416   debug_only(verify_graph_edges(true/*check for no_dead_code*/);)
 417 }
 418 
 419 // ============================================================================
 420 //------------------------------CompileWrapper---------------------------------
 421 class CompileWrapper : public StackObj {
 422   Compile *const _compile;
 423  public:
 424   CompileWrapper(Compile* compile);
 425 
 426   ~CompileWrapper();
 427 };
 428 
 429 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
 430   // the Compile* pointer is stored in the current ciEnv:
 431   ciEnv* env = compile->env();
 432   assert(env == ciEnv::current(), "must already be a ciEnv active");
 433   assert(env->compiler_data() == NULL, "compile already active?");
 434   env->set_compiler_data(compile);
 435   assert(compile == Compile::current(), "sanity");


 528                   _comp_arena(mtCompiler),
 529                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 530                   _env(ci_env),
 531                   _directive(directive),
 532                   _log(ci_env->log()),
 533                   _failure_reason(NULL),
 534                   _congraph(NULL),
 535                   NOT_PRODUCT(_printer(NULL) COMMA)
 536                   _dead_node_list(comp_arena()),
 537                   _dead_node_count(0),
 538                   _node_arena(mtCompiler),
 539                   _old_arena(mtCompiler),
 540                   _mach_constant_base_node(NULL),
 541                   _Compile_types(mtCompiler),
 542                   _initial_gvn(NULL),
 543                   _for_igvn(NULL),
 544                   _warm_calls(NULL),
 545                   _late_inlines(comp_arena(), 2, 0, NULL),
 546                   _string_late_inlines(comp_arena(), 2, 0, NULL),
 547                   _boxing_late_inlines(comp_arena(), 2, 0, NULL),
 548                   _vector_reboxing_late_inlines(comp_arena(), 2, 0, NULL),
 549                   _late_inlines_pos(0),
 550                   _number_of_mh_late_inlines(0),
 551                   _print_inlining_stream(NULL),
 552                   _print_inlining_list(NULL),
 553                   _print_inlining_idx(0),
 554                   _print_inlining_output(NULL),
 555                   _replay_inline_data(NULL),
 556                   _java_calls(0),
 557                   _inner_loops(0),
 558                   _interpreter_frame_size(0)
 559 #ifndef PRODUCT
 560                   , _in_dump_cnt(0)
 561 #endif
 562 {
 563   C = this;
 564   CompileWrapper cw(this);
 565 
 566   if (CITimeVerbose) {
 567     tty->print(" ");
 568     target->holder()->name()->print();


1932         low_live_nodes = live_nodes();
1933         _major_progress = true;
1934       }
1935 
1936       if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {
1937         break; // finish
1938       }
1939     }
1940 
1941     for_igvn()->clear();
1942     initial_gvn()->replace_with(&igvn);
1943 
1944     while (inline_incrementally_one()) {
1945       assert(!failing(), "inconsistent");
1946     }
1947 
1948     if (failing())  return;
1949 
1950     inline_incrementally_cleanup(igvn);
1951 
1952     print_method(PHASE_INCREMENTAL_INLINE_STEP, 3);
1953 
1954     if (failing())  return;
1955   }
1956   assert( igvn._worklist.size() == 0, "should be done with igvn" );
1957 
1958   if (_string_late_inlines.length() > 0) {
1959     assert(has_stringbuilder(), "inconsistent");
1960     for_igvn()->clear();
1961     initial_gvn()->replace_with(&igvn);
1962 
1963     inline_string_calls(false);
1964 
1965     if (failing())  return;
1966 
1967     inline_incrementally_cleanup(igvn);
1968   }
1969 
1970   set_inlining_incrementally(false);
1971 }
1972 
1973 


2068 
2069     print_method(PHASE_INCREMENTAL_BOXING_INLINE, 2);
2070 
2071     if (failing())  return;
2072   }
2073 
2074   // Now that all inlining is over, cut edge from root to loop
2075   // safepoints
2076   remove_root_to_sfpts_edges(igvn);
2077 
2078   // Remove the speculative part of types and clean up the graph from
2079   // the extra CastPP nodes whose only purpose is to carry them. Do
2080   // that early so that optimizations are not disrupted by the extra
2081   // CastPP nodes.
2082   remove_speculative_types(igvn);
2083 
2084   // No more new expensive nodes will be added to the list from here
2085   // so keep only the actual candidates for optimizations.
2086   cleanup_expensive_nodes(igvn);
2087 
2088   assert(EnableVectorSupport || !has_vbox_nodes(), "sanity");
2089   if (EnableVectorSupport && has_vbox_nodes()) {
2090     TracePhase tp("", &timers[_t_vector]);
2091     PhaseVector pv(igvn);
2092     pv.optimize_vector_boxes();
2093 
2094     print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
2095   }
2096   assert(!has_vbox_nodes(), "sanity");
2097 
2098   if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2099     Compile::TracePhase tp("", &timers[_t_renumberLive]);
2100     initial_gvn()->replace_with(&igvn);
2101     for_igvn()->clear();
2102     Unique_Node_List new_worklist(C->comp_arena());
2103     {
2104       ResourceMark rm;
2105       PhaseRenumberLive prl = PhaseRenumberLive(initial_gvn(), for_igvn(), &new_worklist);
2106     }
2107     set_for_igvn(&new_worklist);
2108     igvn = PhaseIterGVN(initial_gvn());
2109     igvn.optimize();
2110   }
2111 
2112   // Perform escape analysis
2113   if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) {
2114     if (has_loops()) {
2115       // Cleanup graph (remove dead nodes).
2116       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2117       PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);


2532       in2_unique_inputs_cnt = collect_unique_inputs(in2, not_used, not_used);
2533     }
2534     // Pick the node with minimum number of inputs.
2535     if (in1_unique_inputs_cnt >= 3 && in2_unique_inputs_cnt >= 3) {
2536       return false; // still too many inputs
2537     }
2538     // Recompute partition & inputs.
2539     Node* child       = (in1_unique_inputs_cnt < in2_unique_inputs_cnt ? in1 : in2);
2540     collect_unique_inputs(child, partition, inputs);
2541 
2542     Node* other_input = (in1_unique_inputs_cnt < in2_unique_inputs_cnt ? in2 : in1);
2543     inputs.push(other_input);
2544 
2545     partition.push(n);
2546   }
2547 
2548   return (partition.size() == 2 || partition.size() == 3) &&
2549          (inputs.size()    == 2 || inputs.size()    == 3);
2550 }
2551 
2552 void Compile::inline_vector_reboxing_calls() {
2553   if (C->_vector_reboxing_late_inlines.length() > 0) {
2554     PhaseGVN* gvn = C->initial_gvn();
2555 
2556     _late_inlines_pos = C->_late_inlines.length();
2557     while (_vector_reboxing_late_inlines.length() > 0) {
2558       CallGenerator* cg = _vector_reboxing_late_inlines.pop();
2559       cg->do_late_inline();
2560       if (failing())  return;
2561       print_method(PHASE_INLINE_VECTOR_REBOX, cg->call_node());
2562     }
2563     _vector_reboxing_late_inlines.trunc_to(0);
2564   }
2565 }
2566 
2567 bool Compile::has_vbox_nodes() {
2568   if (C->_vector_reboxing_late_inlines.length() > 0) {
2569     return true;
2570   }
2571   for (int macro_idx = C->macro_count() - 1; macro_idx >= 0; macro_idx--) {
2572     Node * n = C->macro_node(macro_idx);
2573     assert(n->is_macro(), "only macro nodes expected here");
2574     if (n->Opcode() == Op_VectorUnbox || n->Opcode() == Op_VectorBox || n->Opcode() == Op_VectorBoxAllocate) {
2575       return true;
2576     }
2577   }
2578   return false;
2579 }
2580 
2581 void Compile::process_logic_cone_root(PhaseIterGVN &igvn, Node *n, VectorSet &visited) {
2582   assert(is_vector_bitwise_op(n), "not a root");
2583 
2584   visited.set(n->_idx);
2585 
2586   // 1) Do a DFS walk over the logic cone.
2587   for (uint i = 1; i < n->req(); i++) {
2588     Node* in = n->in(i);
2589     if (!visited.test(in->_idx) && is_vector_bitwise_op(in)) {
2590       process_logic_cone_root(igvn, in, visited);
2591     }
2592   }
2593 
2594   // 2) Bottom up traversal: Merge node[s] with
2595   // the parent to form macro logic node.
2596   Unique_Node_List partition;
2597   Unique_Node_List inputs;
2598   if (compute_logic_cone(n, partition, inputs)) {
2599     const TypeVect* vt = n->bottom_type()->is_vect();


2628   }
2629 
2630   // Perform instruction selection.  You might think we could reclaim Matcher
2631   // memory PDQ, but actually the Matcher is used in generating spill code.
2632   // Internals of the Matcher (including some VectorSets) must remain live
2633   // for awhile - thus I cannot reclaim Matcher memory lest a VectorSet usage
2634   // set a bit in reclaimed memory.
2635 
2636   // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
2637   // nodes.  Mapping is only valid at the root of each matched subtree.
2638   NOT_PRODUCT( verify_graph_edges(); )
2639 
2640   Matcher matcher;
2641   _matcher = &matcher;
2642   {
2643     TracePhase tp("matcher", &timers[_t_matcher]);
2644     matcher.match();
2645     if (failing()) {
2646       return;
2647     }
2648     print_method(PHASE_AFTER_MATCHING, 3);
2649   }

2650   // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
2651   // nodes.  Mapping is only valid at the root of each matched subtree.
2652   NOT_PRODUCT( verify_graph_edges(); )
2653 
2654   // If you have too many nodes, or if matching has failed, bail out
2655   check_node_count(0, "out of nodes matching instructions");
2656   if (failing()) {
2657     return;
2658   }
2659 
2660   print_method(PHASE_MATCHING, 2);
2661 
2662   // Build a proper-looking CFG
2663   PhaseCFG cfg(node_arena(), root(), matcher);
2664   _cfg = &cfg;
2665   {
2666     TracePhase tp("scheduler", &timers[_t_scheduler]);
2667     bool success = cfg.do_global_code_motion();
2668     if (!success) {
2669       return;


2817   }
2818 }
2819 
2820 //------------------------------final_graph_reshaping_impl----------------------
2821 // Implement items 1-5 from final_graph_reshaping below.
2822 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
2823 
2824   if ( n->outcnt() == 0 ) return; // dead node
2825   uint nop = n->Opcode();
2826 
2827   // Check for 2-input instruction with "last use" on right input.
2828   // Swap to left input.  Implements item (2).
2829   if( n->req() == 3 &&          // two-input instruction
2830       n->in(1)->outcnt() > 1 && // left use is NOT a last use
2831       (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
2832       n->in(2)->outcnt() == 1 &&// right use IS a last use
2833       !n->in(2)->is_Con() ) {   // right use is not a constant
2834     // Check for commutative opcode
2835     switch( nop ) {
2836     case Op_AddI:  case Op_AddF:  case Op_AddD:  case Op_AddL:
2837     case Op_MaxI:  case Op_MaxL:  case Op_MaxF:  case Op_MaxD:
2838     case Op_MinI:  case Op_MinL:  case Op_MinF:  case Op_MinD:
2839     case Op_MulI:  case Op_MulF:  case Op_MulD:  case Op_MulL:
2840     case Op_AndL:  case Op_XorL:  case Op_OrL:
2841     case Op_AndI:  case Op_XorI:  case Op_OrI: {
2842       // Move "last use" input to left by swapping inputs
2843       n->swap_edges(1, 2);
2844       break;
2845     }
2846     default:
2847       break;
2848     }
2849   }
2850 
2851 #ifdef ASSERT
2852   if( n->is_Mem() ) {
2853     int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2854     assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
2855             // oop will be recorded in oop map if load crosses safepoint
2856             n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
2857                              LoadNode::is_immutable_value(n->in(MemNode::Address))),
2858             "raw memory operations should have control edge");


3383       // Check if a%b and a/b both exist
3384       Node* d = n->find_similar(Op_DivL);
3385       if (d) {
3386         // Replace them with a fused divmod if supported
3387         if (Matcher::has_match_rule(Op_DivModL)) {
3388           DivModLNode* divmod = DivModLNode::make(n);
3389           d->subsume_by(divmod->div_proj(), this);
3390           n->subsume_by(divmod->mod_proj(), this);
3391         } else {
3392           // replace a%b with a-((a/b)*b)
3393           Node* mult = new MulLNode(d, d->in(2));
3394           Node* sub  = new SubLNode(d->in(1), mult);
3395           n->subsume_by(sub, this);
3396         }
3397       }
3398     }
3399     break;
3400 
3401   case Op_LoadVector:
3402   case Op_StoreVector:
3403   case Op_LoadVectorGather:
3404   case Op_StoreVectorScatter:
3405     break;
3406 
3407   case Op_AddReductionVI:
3408   case Op_AddReductionVL:
3409   case Op_AddReductionVF:
3410   case Op_AddReductionVD:
3411   case Op_MulReductionVI:
3412   case Op_MulReductionVL:
3413   case Op_MulReductionVF:
3414   case Op_MulReductionVD:
3415   case Op_MinReductionV:
3416   case Op_MaxReductionV:
3417   case Op_AndReductionV:
3418   case Op_OrReductionV:
3419   case Op_XorReductionV:
3420     break;
3421 
3422   case Op_PackB:
3423   case Op_PackS:
3424   case Op_PackI:


4600   }
4601 }
4602 
4603 // Move Allocate nodes to the start of the list
4604 void Compile::sort_macro_nodes() {
4605   int count = macro_count();
4606   int allocates = 0;
4607   for (int i = 0; i < count; i++) {
4608     Node* n = macro_node(i);
4609     if (n->is_Allocate()) {
4610       if (i != allocates) {
4611         Node* tmp = macro_node(allocates);
4612         _macro_nodes->at_put(allocates, n);
4613         _macro_nodes->at_put(i, tmp);
4614       }
4615       allocates++;
4616     }
4617   }
4618 }
4619 
4620 void Compile::print_method(CompilerPhaseType cpt, const char *name, int level, int idx) {
4621   EventCompilerPhase event;
4622   if (event.should_commit()) {
4623     CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, cpt, C->_compile_id, level);
4624   }

4625 #ifndef PRODUCT
4626   if (should_print(level)) {
4627     _printer->print_method(name, level);
4628   }
4629 #endif
4630   C->_latest_stage_start_counter.stamp();
4631 }
4632 
4633 void Compile::print_method(CompilerPhaseType cpt, int level, int idx) {
4634   char output[1024];
4635 #ifndef PRODUCT
4636   if (idx != 0) {
4637     jio_snprintf(output, sizeof(output), "%s:%d", CompilerPhaseTypeHelper::to_string(cpt), idx);
4638   } else {
4639     jio_snprintf(output, sizeof(output), "%s", CompilerPhaseTypeHelper::to_string(cpt));
4640   }


4641 #endif
4642   print_method(cpt, output, level, idx);
4643 }
4644 
4645 void Compile::print_method(CompilerPhaseType cpt, Node* n, int level) {
4646   ResourceMark rm;
4647   stringStream ss;
4648   ss.print_raw(CompilerPhaseTypeHelper::to_string(cpt));
4649   if (n != NULL) {
4650     ss.print(": %d %s ", n->_idx, NodeClassNames[n->Opcode()]);
4651   } else {
4652     ss.print_raw(": NULL");
4653   }
4654   C->print_method(cpt, ss.as_string(), level);
4655 }
4656 
4657 void Compile::end_method(int level) {
4658   EventCompilerPhase event;
4659   if (event.should_commit()) {
4660     CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, PHASE_END, C->_compile_id, level);
4661   }
4662 
4663 #ifndef PRODUCT
4664   if (_method != NULL && should_print(level)) {
4665     _printer->end_method();
4666   }
4667 #endif
4668 }
4669 
4670 
4671 #ifndef PRODUCT
4672 IdealGraphPrinter* Compile::_debug_file_printer = NULL;
4673 IdealGraphPrinter* Compile::_debug_network_printer = NULL;
4674 


< prev index next >