1906 //----------------------------Finish_Warm--------------------------------------
1907 void Compile::Finish_Warm() {
1908 if (!InlineWarmCalls) return;
1909 if (failing()) return;
1910 if (warm_calls() == NULL) return;
1911
1912 // Clean up loose ends, if we are out of space for inlining.
1913 WarmCallInfo* call;
1914 while ((call = pop_warm_call()) != NULL) {
1915 call->make_cold();
1916 }
1917 }
1918
1919 //---------------------cleanup_loop_predicates-----------------------
1920 // Remove the opaque nodes that protect the predicates so that all unused
1921 // checks and uncommon_traps will be eliminated from the ideal graph
1922 void Compile::cleanup_loop_predicates(PhaseIterGVN &igvn) {
1923 if (predicate_count()==0) return;
1924 for (int i = predicate_count(); i > 0; i--) {
1925 Node * n = predicate_opaque1_node(i-1);
1926 assert(n->Opcode() == Op_Opaque1, "must be");
1927 igvn.replace_node(n, n->in(1));
1928 }
1929 assert(predicate_count()==0, "should be clean!");
1930 }
1931
1932 void Compile::add_range_check_cast(Node* n) {
1933 assert(n->isa_CastII()->has_range_check(), "CastII should have range check dependency");
1934 assert(!_range_check_casts->contains(n), "duplicate entry in range check casts");
1935 _range_check_casts->append(n);
1936 }
1937
1938 // Remove all range check dependent CastIINodes.
1939 void Compile::remove_range_check_casts(PhaseIterGVN &igvn) {
1940 for (int i = range_check_cast_count(); i > 0; i--) {
1941 Node* cast = range_check_cast_node(i-1);
1942 assert(cast->isa_CastII()->has_range_check(), "CastII should have range check dependency");
1943 igvn.replace_node(cast, cast->in(1));
1944 }
1945 assert(range_check_cast_count() == 0, "should be empty");
1946 }
2589
2590 int get_call_count () const { return _call_count ; }
2591 int get_float_count () const { return _float_count ; }
2592 int get_double_count() const { return _double_count; }
2593 int get_java_call_count() const { return _java_call_count; }
2594 int get_inner_loop_count() const { return _inner_loop_count; }
2595 };
2596
2597 #ifdef ASSERT
2598 static bool oop_offset_is_sane(const TypeInstPtr* tp) {
2599 ciInstanceKlass *k = tp->klass()->as_instance_klass();
2600 // Make sure the offset goes inside the instance layout.
2601 return k->contains_field_offset(tp->offset());
2602 // Note that OffsetBot and OffsetTop are very negative.
2603 }
2604 #endif
2605
2606 // Eliminate trivially redundant StoreCMs and accumulate their
2607 // precedence edges.
2608 void Compile::eliminate_redundant_card_marks(Node* n) {
2609 assert(n->Opcode() == Op_StoreCM, "expected StoreCM");
2610 if (n->in(MemNode::Address)->outcnt() > 1) {
2611 // There are multiple users of the same address so it might be
2612 // possible to eliminate some of the StoreCMs
2613 Node* mem = n->in(MemNode::Memory);
2614 Node* adr = n->in(MemNode::Address);
2615 Node* val = n->in(MemNode::ValueIn);
2616 Node* prev = n;
2617 bool done = false;
2618 // Walk the chain of StoreCMs eliminating ones that match. As
2619 // long as it's a chain of single users then the optimization is
2620 // safe. Eliminating partially redundant StoreCMs would require
2621 // cloning copies down the other paths.
2622 while (mem->Opcode() == Op_StoreCM && mem->outcnt() == 1 && !done) {
2623 if (adr == mem->in(MemNode::Address) &&
2624 val == mem->in(MemNode::ValueIn)) {
2625 // redundant StoreCM
2626 if (mem->req() > MemNode::OopStore) {
2627 // Hasn't been processed by this code yet.
2628 n->add_prec(mem->in(MemNode::OopStore));
2629 } else {
2630 // Already converted to precedence edge
2631 for (uint i = mem->req(); i < mem->len(); i++) {
2632 // Accumulate any precedence edges
2633 if (mem->in(i) != NULL) {
2634 n->add_prec(mem->in(i));
2635 }
2636 }
2637 // Everything above this point has been processed.
2638 done = true;
2639 }
2640 // Eliminate the previous StoreCM
2641 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
2642 assert(mem->outcnt() == 0, "should be dead");
2643 mem->disconnect_inputs(NULL, this);
2644 } else {
2645 prev = mem;
2646 }
2647 mem = prev->in(MemNode::Memory);
2648 }
2649 }
2650 }
2651
2652 //------------------------------final_graph_reshaping_impl----------------------
2653 // Implement items 1-5 from final_graph_reshaping below.
2654 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
2655
2656 if ( n->outcnt() == 0 ) return; // dead node
2657 uint nop = n->Opcode();
2658
2659 // Check for 2-input instruction with "last use" on right input.
2660 // Swap to left input. Implements item (2).
2661 if( n->req() == 3 && // two-input instruction
2662 n->in(1)->outcnt() > 1 && // left use is NOT a last use
2663 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
2664 n->in(2)->outcnt() == 1 &&// right use IS a last use
2665 !n->in(2)->is_Con() ) { // right use is not a constant
2666 // Check for commutative opcode
2667 switch( nop ) {
2668 case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL:
2669 case Op_MaxI: case Op_MinI:
2670 case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL:
2671 case Op_AndL: case Op_XorL: case Op_OrL:
2672 case Op_AndI: case Op_XorI: case Op_OrI: {
2673 // Move "last use" input to left by swapping inputs
2674 n->swap_edges(1, 2);
2675 break;
2676 }
2677 default:
2678 break;
2679 }
2680 }
2681
2682 #ifdef ASSERT
2683 if( n->is_Mem() ) {
2684 int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2685 assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
2686 // oop will be recorded in oop map if load crosses safepoint
2687 n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
2688 LoadNode::is_immutable_value(n->in(MemNode::Address))),
2689 "raw memory operations should have control edge");
2690 }
2691 #endif
2692 // Count FPU ops and common calls, implements item (3)
2693 switch( nop ) {
2694 // Count all float operations that may use FPU
2695 case Op_AddF:
2696 case Op_SubF:
2697 case Op_MulF:
2698 case Op_DivF:
2699 case Op_NegF:
2700 case Op_ModF:
2701 case Op_ConvI2F:
2702 case Op_ConF:
2703 case Op_CmpF:
2704 case Op_CmpF3:
2705 // case Op_ConvL2F: // longs are split into 32-bit halves
2706 frc.inc_float_count();
2707 break;
2708
2709 case Op_ConvF2D:
2710 case Op_ConvD2F:
2711 frc.inc_float_count();
2712 frc.inc_double_count();
2713 break;
2714
2715 // Count all double operations that may use FPU
2716 case Op_AddD:
2717 case Op_SubD:
2718 case Op_MulD:
2719 case Op_DivD:
2720 case Op_NegD:
2721 case Op_ModD:
2722 case Op_ConvI2D:
2723 case Op_ConvD2I:
2724 // case Op_ConvL2D: // handled by leaf call
2725 // case Op_ConvD2L: // handled by leaf call
2726 case Op_ConD:
2727 case Op_CmpD:
2728 case Op_CmpD3:
2729 frc.inc_double_count();
2730 break;
2731 case Op_Opaque1: // Remove Opaque Nodes before matching
2732 case Op_Opaque2: // Remove Opaque Nodes before matching
2733 case Op_Opaque3:
2734 n->subsume_by(n->in(1), this);
2735 break;
2736 case Op_CallStaticJava:
2737 case Op_CallJava:
2738 case Op_CallDynamicJava:
2739 frc.inc_java_call_count(); // Count java call site;
2740 case Op_CallRuntime:
2741 case Op_CallLeaf:
2742 case Op_CallLeafNoFP: {
2743 assert( n->is_Call(), "" );
2744 CallNode *call = n->as_Call();
2745 // Count call sites where the FP mode bit would have to be flipped.
2746 // Do not count uncommon runtime calls:
2747 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
2748 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
2749 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) {
2750 frc.inc_call_count(); // Count the call site
2751 } else { // See if uncommon argument is shared
2752 Node *n = call->in(TypeFunc::Parms);
2753 int nop = n->Opcode();
2754 // Clone shared simple arguments to uncommon calls, item (1).
2755 if( n->outcnt() > 1 &&
2756 !n->is_Proj() &&
2757 nop != Op_CreateEx &&
2758 nop != Op_CheckCastPP &&
2759 nop != Op_DecodeN &&
2760 nop != Op_DecodeNKlass &&
2761 !n->is_Mem() ) {
2762 Node *x = n->clone();
2763 call->set_req( TypeFunc::Parms, x );
2764 }
2765 }
2766 break;
2767 }
2768
2769 case Op_StoreD:
2770 case Op_LoadD:
2771 case Op_LoadD_unaligned:
2772 frc.inc_double_count();
2773 goto handle_mem;
2774 case Op_StoreF:
2775 case Op_LoadF:
2776 frc.inc_float_count();
2777 goto handle_mem;
2778
2779 case Op_StoreCM:
2780 {
2781 // Convert OopStore dependence into precedence edge
2782 Node* prec = n->in(MemNode::OopStore);
2783 n->del_req(MemNode::OopStore);
2784 n->add_prec(prec);
2785 eliminate_redundant_card_marks(n);
2786 }
2787
2788 // fall through
2789
2790 case Op_StoreB:
2791 case Op_StoreC:
2792 case Op_StorePConditional:
2793 case Op_StoreI:
2794 case Op_StoreL:
2795 case Op_StoreIConditional:
2796 case Op_StoreLConditional:
2797 case Op_CompareAndSwapB:
2798 case Op_CompareAndSwapS:
2799 case Op_CompareAndSwapI:
2800 case Op_CompareAndSwapL:
2801 case Op_CompareAndSwapP:
2802 case Op_CompareAndSwapN:
2803 case Op_WeakCompareAndSwapB:
2804 case Op_WeakCompareAndSwapS:
2805 case Op_WeakCompareAndSwapI:
2806 case Op_WeakCompareAndSwapL:
2807 case Op_WeakCompareAndSwapP:
2808 case Op_WeakCompareAndSwapN:
2809 case Op_CompareAndExchangeB:
2810 case Op_CompareAndExchangeS:
2811 case Op_CompareAndExchangeI:
2812 case Op_CompareAndExchangeL:
2813 case Op_CompareAndExchangeP:
2814 case Op_CompareAndExchangeN:
2815 case Op_GetAndAddS:
2816 case Op_GetAndAddB:
2817 case Op_GetAndAddI:
2818 case Op_GetAndAddL:
2819 case Op_GetAndSetS:
2820 case Op_GetAndSetB:
2821 case Op_GetAndSetI:
2822 case Op_GetAndSetL:
2823 case Op_GetAndSetP:
2824 case Op_GetAndSetN:
2825 case Op_StoreP:
2826 case Op_StoreN:
2827 case Op_StoreNKlass:
2828 case Op_LoadB:
2829 case Op_LoadUB:
2830 case Op_LoadUS:
2831 case Op_LoadI:
2832 case Op_LoadKlass:
2833 case Op_LoadNKlass:
2834 case Op_LoadL:
2835 case Op_LoadL_unaligned:
2836 case Op_LoadPLocked:
2837 case Op_LoadP:
2838 case Op_LoadN:
2839 case Op_LoadRange:
2840 case Op_LoadS: {
2841 handle_mem:
2842 #ifdef ASSERT
2843 if( VerifyOptoOopOffsets ) {
2844 assert( n->is_Mem(), "" );
2845 MemNode *mem = (MemNode*)n;
2846 // Check to see if address types have grounded out somehow.
2847 const TypeInstPtr *tp = mem->in(MemNode::Address)->bottom_type()->isa_instptr();
2848 assert( !tp || oop_offset_is_sane(tp), "" );
2849 }
2850 #endif
2851 break;
2852 }
2853
2854 case Op_AddP: { // Assert sane base pointers
2855 Node *addp = n->in(AddPNode::Address);
2856 assert( !addp->is_AddP() ||
2857 addp->in(AddPNode::Base)->is_top() || // Top OK for allocation
2858 addp->in(AddPNode::Base) == n->in(AddPNode::Base),
2859 "Base pointers must match (addp %u)", addp->_idx );
2860 #ifdef _LP64
2861 if ((UseCompressedOops || UseCompressedClassPointers) &&
2862 addp->Opcode() == Op_ConP &&
2863 addp == n->in(AddPNode::Base) &&
2864 n->in(AddPNode::Offset)->is_Con()) {
2865 // Use addressing with narrow klass to load with offset on x86.
2866 // On sparc loading 32-bits constant and decoding it have less
2867 // instructions (4) then load 64-bits constant (7).
2868 // Do this transformation here since IGVN will convert ConN back to ConP.
2869 const Type* t = addp->bottom_type();
2870 if (t->isa_oopptr() || t->isa_klassptr()) {
2871 Node* nn = NULL;
2872
2873 int op = t->isa_oopptr() ? Op_ConN : Op_ConNKlass;
2874
2875 // Look for existing ConN node of the same exact type.
2876 Node* r = root();
2877 uint cnt = r->outcnt();
2878 for (uint i = 0; i < cnt; i++) {
2879 Node* m = r->raw_out(i);
2880 if (m!= NULL && m->Opcode() == op &&
2881 m->bottom_type()->make_ptr() == t) {
2882 nn = m;
2883 break;
2884 }
2885 }
2886 if (nn != NULL) {
2887 // Decode a narrow oop to match address
2888 // [R12 + narrow_oop_reg<<3 + offset]
2889 if (t->isa_oopptr()) {
2890 nn = new DecodeNNode(nn, t);
2891 } else {
2892 nn = new DecodeNKlassNode(nn, t);
2893 }
2903 assert(out_j == NULL || !out_j->is_AddP() || out_j->in(AddPNode::Base) != addp,
2904 "more than 2 AddP nodes in a chain (out_j %u)", out_j->_idx);
2905 }
2906 #endif
2907 }
2908 }
2909 n->set_req(AddPNode::Base, nn);
2910 n->set_req(AddPNode::Address, nn);
2911 if (addp->outcnt() == 0) {
2912 addp->disconnect_inputs(NULL, this);
2913 }
2914 }
2915 }
2916 }
2917 #endif
2918 // platform dependent reshaping of the address expression
2919 reshape_address(n->as_AddP());
2920 break;
2921 }
2922
2923 case Op_CastPP: {
2924 // Remove CastPP nodes to gain more freedom during scheduling but
2925 // keep the dependency they encode as control or precedence edges
2926 // (if control is set already) on memory operations. Some CastPP
2927 // nodes don't have a control (don't carry a dependency): skip
2928 // those.
2929 if (n->in(0) != NULL) {
2930 ResourceMark rm;
2931 Unique_Node_List wq;
2932 wq.push(n);
2933 for (uint next = 0; next < wq.size(); ++next) {
2934 Node *m = wq.at(next);
2935 for (DUIterator_Fast imax, i = m->fast_outs(imax); i < imax; i++) {
2936 Node* use = m->fast_out(i);
2937 if (use->is_Mem() || use->is_EncodeNarrowPtr()) {
2938 use->ensure_control_or_add_prec(n->in(0));
2939 } else {
2940 switch(use->Opcode()) {
2941 case Op_AddP:
2942 case Op_DecodeN:
2943 case Op_DecodeNKlass:
2944 case Op_CheckCastPP:
2945 case Op_CastPP:
2946 wq.push(use);
2947 break;
2948 }
2949 }
2950 }
2951 }
2952 }
2953 const bool is_LP64 = LP64_ONLY(true) NOT_LP64(false);
2954 if (is_LP64 && n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) {
2955 Node* in1 = n->in(1);
2956 const Type* t = n->bottom_type();
2957 Node* new_in1 = in1->clone();
2958 new_in1->as_DecodeN()->set_type(t);
2959
2960 if (!Matcher::narrow_oop_use_complex_address()) {
2961 //
2962 // x86, ARM and friends can handle 2 adds in addressing mode
2963 // and Matcher can fold a DecodeN node into address by using
2964 // a narrow oop directly and do implicit NULL check in address:
2965 //
2976 // Pin the new DecodeN node to non-null path on these platform (Sparc)
2977 // to keep the information to which NULL check the new DecodeN node
2978 // corresponds to use it as value in implicit_null_check().
2979 //
2980 new_in1->set_req(0, n->in(0));
2981 }
2982
2983 n->subsume_by(new_in1, this);
2984 if (in1->outcnt() == 0) {
2985 in1->disconnect_inputs(NULL, this);
2986 }
2987 } else {
2988 n->subsume_by(n->in(1), this);
2989 if (n->outcnt() == 0) {
2990 n->disconnect_inputs(NULL, this);
2991 }
2992 }
2993 break;
2994 }
2995 #ifdef _LP64
2996 case Op_CmpP:
2997 // Do this transformation here to preserve CmpPNode::sub() and
2998 // other TypePtr related Ideal optimizations (for example, ptr nullness).
2999 if (n->in(1)->is_DecodeNarrowPtr() || n->in(2)->is_DecodeNarrowPtr()) {
3000 Node* in1 = n->in(1);
3001 Node* in2 = n->in(2);
3002 if (!in1->is_DecodeNarrowPtr()) {
3003 in2 = in1;
3004 in1 = n->in(2);
3005 }
3006 assert(in1->is_DecodeNarrowPtr(), "sanity");
3007
3008 Node* new_in2 = NULL;
3009 if (in2->is_DecodeNarrowPtr()) {
3010 assert(in2->Opcode() == in1->Opcode(), "must be same node type");
3011 new_in2 = in2->in(1);
3012 } else if (in2->Opcode() == Op_ConP) {
3013 const Type* t = in2->bottom_type();
3014 if (t == TypePtr::NULL_PTR) {
3015 assert(in1->is_DecodeN(), "compare klass to null?");
3016 // Don't convert CmpP null check into CmpN if compressed
3017 // oops implicit null check is not generated.
3018 // This will allow to generate normal oop implicit null check.
3019 if (Matcher::gen_narrow_oop_implicit_null_checks())
3020 new_in2 = ConNode::make(TypeNarrowOop::NULL_PTR);
3021 //
3022 // This transformation together with CastPP transformation above
3023 // will generated code for implicit NULL checks for compressed oops.
3024 //
3025 // The original code after Optimize()
3026 //
3027 // LoadN memory, narrow_oop_reg
3028 // decode narrow_oop_reg, base_reg
3029 // CmpP base_reg, NULL
3030 // CastPP base_reg // NotNull
3031 // Load [base_reg + offset], val_reg
3032 //
3057 //
3058 } else if (t->isa_oopptr()) {
3059 new_in2 = ConNode::make(t->make_narrowoop());
3060 } else if (t->isa_klassptr()) {
3061 new_in2 = ConNode::make(t->make_narrowklass());
3062 }
3063 }
3064 if (new_in2 != NULL) {
3065 Node* cmpN = new CmpNNode(in1->in(1), new_in2);
3066 n->subsume_by(cmpN, this);
3067 if (in1->outcnt() == 0) {
3068 in1->disconnect_inputs(NULL, this);
3069 }
3070 if (in2->outcnt() == 0) {
3071 in2->disconnect_inputs(NULL, this);
3072 }
3073 }
3074 }
3075 break;
3076
3077 case Op_DecodeN:
3078 case Op_DecodeNKlass:
3079 assert(!n->in(1)->is_EncodeNarrowPtr(), "should be optimized out");
3080 // DecodeN could be pinned when it can't be fold into
3081 // an address expression, see the code for Op_CastPP above.
3082 assert(n->in(0) == NULL || (UseCompressedOops && !Matcher::narrow_oop_use_complex_address()), "no control");
3083 break;
3084
3085 case Op_EncodeP:
3086 case Op_EncodePKlass: {
3087 Node* in1 = n->in(1);
3088 if (in1->is_DecodeNarrowPtr()) {
3089 n->subsume_by(in1->in(1), this);
3090 } else if (in1->Opcode() == Op_ConP) {
3091 const Type* t = in1->bottom_type();
3092 if (t == TypePtr::NULL_PTR) {
3093 assert(t->isa_oopptr(), "null klass?");
3094 n->subsume_by(ConNode::make(TypeNarrowOop::NULL_PTR), this);
3095 } else if (t->isa_oopptr()) {
3096 n->subsume_by(ConNode::make(t->make_narrowoop()), this);
3097 } else if (t->isa_klassptr()) {
3098 n->subsume_by(ConNode::make(t->make_narrowklass()), this);
3099 }
3100 }
3101 if (in1->outcnt() == 0) {
3102 in1->disconnect_inputs(NULL, this);
3103 }
3104 break;
3105 }
3106
3107 case Op_Proj: {
3108 if (OptimizeStringConcat) {
3109 ProjNode* p = n->as_Proj();
3110 if (p->_is_io_use) {
3111 // Separate projections were used for the exception path which
3112 // are normally removed by a late inline. If it wasn't inlined
3113 // then they will hang around and should just be replaced with
3114 // the original one.
3115 Node* proj = NULL;
3116 // Replace with just one
3117 for (SimpleDUIterator i(p->in(0)); i.has_next(); i.next()) {
3118 Node *use = i.get();
3119 if (use->is_Proj() && p != use && use->as_Proj()->_con == p->_con) {
3120 proj = use;
3121 break;
3122 }
3123 }
3124 assert(proj != NULL, "must be found");
3125 p->subsume_by(proj, this);
3126 }
3127 }
3128 break;
3129 }
3130
3131 case Op_Phi:
3132 if (n->as_Phi()->bottom_type()->isa_narrowoop() || n->as_Phi()->bottom_type()->isa_narrowklass()) {
3133 // The EncodeP optimization may create Phi with the same edges
3134 // for all paths. It is not handled well by Register Allocator.
3135 Node* unique_in = n->in(1);
3136 assert(unique_in != NULL, "");
3137 uint cnt = n->req();
3138 for (uint i = 2; i < cnt; i++) {
3139 Node* m = n->in(i);
3140 assert(m != NULL, "");
3141 if (unique_in != m)
3142 unique_in = NULL;
3143 }
3144 if (unique_in != NULL) {
3145 n->subsume_by(unique_in, this);
3146 }
3147 }
3148 break;
3149
3150 #endif
3151
3152 #ifdef ASSERT
3153 case Op_CastII:
3154 // Verify that all range check dependent CastII nodes were removed.
3155 if (n->isa_CastII()->has_range_check()) {
3156 n->dump(3);
3157 assert(false, "Range check dependent CastII node was not removed");
3158 }
3159 break;
3160 #endif
3161
3162 case Op_ModI:
3163 if (UseDivMod) {
3164 // Check if a%b and a/b both exist
3165 Node* d = n->find_similar(Op_DivI);
3166 if (d) {
3167 // Replace them with a fused divmod if supported
3168 if (Matcher::has_match_rule(Op_DivModI)) {
3169 DivModINode* divmod = DivModINode::make(n);
3170 d->subsume_by(divmod->div_proj(), this);
3171 n->subsume_by(divmod->mod_proj(), this);
3172 } else {
3173 // replace a%b with a-((a/b)*b)
3174 Node* mult = new MulINode(d, d->in(2));
3175 Node* sub = new SubINode(d->in(1), mult);
3176 n->subsume_by(sub, this);
3177 }
3178 }
3179 }
3180 break;
3181
3182 case Op_ModL:
3183 if (UseDivMod) {
3184 // Check if a%b and a/b both exist
3185 Node* d = n->find_similar(Op_DivL);
3186 if (d) {
3187 // Replace them with a fused divmod if supported
3188 if (Matcher::has_match_rule(Op_DivModL)) {
3189 DivModLNode* divmod = DivModLNode::make(n);
3190 d->subsume_by(divmod->div_proj(), this);
3191 n->subsume_by(divmod->mod_proj(), this);
3192 } else {
3193 // replace a%b with a-((a/b)*b)
3194 Node* mult = new MulLNode(d, d->in(2));
3195 Node* sub = new SubLNode(d->in(1), mult);
3196 n->subsume_by(sub, this);
3197 }
3198 }
3199 }
3200 break;
3201
3202 case Op_LoadVector:
3203 case Op_StoreVector:
3204 break;
3205
3206 case Op_AddReductionVI:
3207 case Op_AddReductionVL:
3208 case Op_AddReductionVF:
3209 case Op_AddReductionVD:
3210 case Op_MulReductionVI:
3211 case Op_MulReductionVL:
3212 case Op_MulReductionVF:
3213 case Op_MulReductionVD:
3214 break;
3215
3216 case Op_PackB:
3217 case Op_PackS:
3218 case Op_PackI:
3219 case Op_PackF:
3220 case Op_PackL:
3221 case Op_PackD:
3222 if (n->req()-1 > 2) {
3223 // Replace many operand PackNodes with a binary tree for matching
3224 PackNode* p = (PackNode*) n;
3225 Node* btp = p->binary_tree_pack(1, n->req());
3226 n->subsume_by(btp, this);
3227 }
3228 break;
3229 case Op_Loop:
3230 case Op_CountedLoop:
3231 if (n->as_Loop()->is_inner_loop()) {
3232 frc.inc_inner_loop_count();
3233 }
3234 break;
3235 case Op_LShiftI:
3236 case Op_RShiftI:
3237 case Op_URShiftI:
3238 case Op_LShiftL:
3239 case Op_RShiftL:
3240 case Op_URShiftL:
3241 if (Matcher::need_masked_shift_count) {
3242 // The cpu's shift instructions don't restrict the count to the
3243 // lower 5/6 bits. We need to do the masking ourselves.
3244 Node* in2 = n->in(2);
3245 juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1);
3246 const TypeInt* t = in2->find_int_type();
3247 if (t != NULL && t->is_con()) {
3248 juint shift = t->get_con();
3249 if (shift > mask) { // Unsigned cmp
3250 n->set_req(2, ConNode::make(TypeInt::make(shift & mask)));
3251 }
3252 } else {
3253 if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) {
3254 Node* shift = new AndINode(in2, ConNode::make(TypeInt::make(mask)));
3255 n->set_req(2, shift);
3256 }
3257 }
3258 if (in2->outcnt() == 0) { // Remove dead node
3259 in2->disconnect_inputs(NULL, this);
3260 }
3261 }
3262 break;
3263 case Op_MemBarStoreStore:
3264 case Op_MemBarRelease:
3265 // Break the link with AllocateNode: it is no longer useful and
3266 // confuses register allocation.
3267 if (n->req() > MemBarNode::Precedent) {
3268 n->set_req(MemBarNode::Precedent, top());
3269 }
3270 break;
3271 case Op_RangeCheck: {
3272 RangeCheckNode* rc = n->as_RangeCheck();
3273 Node* iff = new IfNode(rc->in(0), rc->in(1), rc->_prob, rc->_fcnt);
3274 n->subsume_by(iff, this);
3275 frc._tests.push(iff);
3276 break;
3277 }
3278 case Op_ConvI2L: {
3279 if (!Matcher::convi2l_type_required) {
3280 // Code generation on some platforms doesn't need accurate
3281 // ConvI2L types. Widening the type can help remove redundant
3282 // address computations.
3283 n->as_Type()->set_type(TypeLong::INT);
3284 ResourceMark rm;
3285 Node_List wq;
3286 wq.push(n);
3287 for (uint next = 0; next < wq.size(); next++) {
3288 Node *m = wq.at(next);
3289
3290 for(;;) {
3291 // Loop over all nodes with identical inputs edges as m
3292 Node* k = m->find_similar(m->Opcode());
3293 if (k == NULL) {
3294 break;
3295 }
3296 // Push their uses so we get a chance to remove node made
3297 // redundant
3298 for (DUIterator_Fast imax, i = k->fast_outs(imax); i < imax; i++) {
3299 Node* u = k->fast_out(i);
3300 assert(!wq.contains(u), "shouldn't process one node several times");
3301 if (u->Opcode() == Op_LShiftL ||
3302 u->Opcode() == Op_AddL ||
3303 u->Opcode() == Op_SubL ||
3304 u->Opcode() == Op_AddP) {
3305 wq.push(u);
3306 }
3307 }
3308 // Replace all nodes with identical edges as m with m
3309 k->subsume_by(m, this);
3310 }
3311 }
3312 }
3313 break;
3314 }
3315 default:
3316 assert( !n->is_Call(), "" );
3317 assert( !n->is_Mem(), "" );
3318 assert( nop != Op_ProfileBoolean, "should be eliminated during IGVN");
3319 break;
3320 }
3321
3322 // Collect CFG split points
3323 if (n->is_MultiBranch() && !n->is_RangeCheck()) {
3324 frc._tests.push(n);
3325 }
3326 }
3327
3328 //------------------------------final_graph_reshaping_walk---------------------
3329 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
3330 // requires that the walk visits a node's inputs before visiting the node.
3331 void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {
3332 ResourceArea *area = Thread::current()->resource_area();
3333 Unique_Node_List sfpt(area);
3334
3335 frc._visited.set(root->_idx); // first, mark node as visited
3336 uint cnt = root->req();
3337 Node *n = root;
3338 uint i = 0;
3696 } else {
3697 visited.push(x);
3698 }
3699
3700 if (x->is_Region()) {
3701 for (uint i = 1; i < x->req(); i++) {
3702 worklist.push(x->in(i));
3703 }
3704 } else {
3705 worklist.push(x->in(0));
3706 // We are looking for the pattern:
3707 // /->ThreadLocal
3708 // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset)
3709 // \->ConI(0)
3710 // We want to verify that the If and the LoadB have the same control
3711 // See GraphKit::g1_write_barrier_pre()
3712 if (x->is_If()) {
3713 IfNode *iff = x->as_If();
3714 if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) {
3715 CmpNode *cmp = iff->in(1)->in(1)->as_Cmp();
3716 if (cmp->Opcode() == Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0
3717 && cmp->in(1)->is_Load()) {
3718 LoadNode* load = cmp->in(1)->as_Load();
3719 if (load->Opcode() == Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Op_ThreadLocal
3720 && load->in(2)->in(3)->is_Con()
3721 && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == marking_offset) {
3722
3723 Node* if_ctrl = iff->in(0);
3724 Node* load_ctrl = load->in(0);
3725
3726 if (if_ctrl != load_ctrl) {
3727 // Skip possible CProj->NeverBranch in infinite loops
3728 if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Op_CProj)
3729 && (if_ctrl->in(0)->is_MultiBranch() && if_ctrl->in(0)->Opcode() == Op_NeverBranch)) {
3730 if_ctrl = if_ctrl->in(0)->in(0);
3731 }
3732 }
3733 assert(load_ctrl != NULL && if_ctrl == load_ctrl, "controls must match");
3734 }
3735 }
3736 }
3737 }
3738 }
3739 }
3740 }
3741 }
3742
3743 #endif
3744
3745 // The Compile object keeps track of failure reasons separately from the ciEnv.
3746 // This is required because there is not quite a 1-1 relation between the
3747 // ciEnv and its compilation task and the Compile object. Note that one
3748 // ciEnv might use two Compile objects, if C2Compiler::compile_method decides
3749 // to backtrack and retry without subsuming loads. Other than this backtracking
4275 if (C->log() != NULL) {
4276 C->log()->inline_fail(msg);
4277 }
4278 }
4279
4280
4281 // Dump inlining replay data to the stream.
4282 // Don't change thread state and acquire any locks.
4283 void Compile::dump_inline_data(outputStream* out) {
4284 InlineTree* inl_tree = ilt();
4285 if (inl_tree != NULL) {
4286 out->print(" inline %d", inl_tree->count());
4287 inl_tree->dump_replay_data(out);
4288 }
4289 }
4290
4291 int Compile::cmp_expensive_nodes(Node* n1, Node* n2) {
4292 if (n1->Opcode() < n2->Opcode()) return -1;
4293 else if (n1->Opcode() > n2->Opcode()) return 1;
4294
4295 assert(n1->req() == n2->req(), "can't compare %s nodes: n1->req() = %d, n2->req() = %d", NodeClassNames[n1->Opcode()], n1->req(), n2->req());
4296 for (uint i = 1; i < n1->req(); i++) {
4297 if (n1->in(i) < n2->in(i)) return -1;
4298 else if (n1->in(i) > n2->in(i)) return 1;
4299 }
4300
4301 return 0;
4302 }
4303
4304 int Compile::cmp_expensive_nodes(Node** n1p, Node** n2p) {
4305 Node* n1 = *n1p;
4306 Node* n2 = *n2p;
4307
4308 return cmp_expensive_nodes(n1, n2);
4309 }
4310
4311 void Compile::sort_expensive_nodes() {
4312 if (!expensive_nodes_sorted()) {
4313 _expensive_nodes->sort(cmp_expensive_nodes);
4314 }
4315 }
|
1906 //----------------------------Finish_Warm--------------------------------------
1907 void Compile::Finish_Warm() {
1908 if (!InlineWarmCalls) return;
1909 if (failing()) return;
1910 if (warm_calls() == NULL) return;
1911
1912 // Clean up loose ends, if we are out of space for inlining.
1913 WarmCallInfo* call;
1914 while ((call = pop_warm_call()) != NULL) {
1915 call->make_cold();
1916 }
1917 }
1918
1919 //---------------------cleanup_loop_predicates-----------------------
1920 // Remove the opaque nodes that protect the predicates so that all unused
1921 // checks and uncommon_traps will be eliminated from the ideal graph
1922 void Compile::cleanup_loop_predicates(PhaseIterGVN &igvn) {
1923 if (predicate_count()==0) return;
1924 for (int i = predicate_count(); i > 0; i--) {
1925 Node * n = predicate_opaque1_node(i-1);
1926 assert(n->Opcode() == Opcodes::Op_Opaque1, "must be");
1927 igvn.replace_node(n, n->in(1));
1928 }
1929 assert(predicate_count()==0, "should be clean!");
1930 }
1931
1932 void Compile::add_range_check_cast(Node* n) {
1933 assert(n->isa_CastII()->has_range_check(), "CastII should have range check dependency");
1934 assert(!_range_check_casts->contains(n), "duplicate entry in range check casts");
1935 _range_check_casts->append(n);
1936 }
1937
1938 // Remove all range check dependent CastIINodes.
1939 void Compile::remove_range_check_casts(PhaseIterGVN &igvn) {
1940 for (int i = range_check_cast_count(); i > 0; i--) {
1941 Node* cast = range_check_cast_node(i-1);
1942 assert(cast->isa_CastII()->has_range_check(), "CastII should have range check dependency");
1943 igvn.replace_node(cast, cast->in(1));
1944 }
1945 assert(range_check_cast_count() == 0, "should be empty");
1946 }
2589
2590 int get_call_count () const { return _call_count ; }
2591 int get_float_count () const { return _float_count ; }
2592 int get_double_count() const { return _double_count; }
2593 int get_java_call_count() const { return _java_call_count; }
2594 int get_inner_loop_count() const { return _inner_loop_count; }
2595 };
2596
2597 #ifdef ASSERT
2598 static bool oop_offset_is_sane(const TypeInstPtr* tp) {
2599 ciInstanceKlass *k = tp->klass()->as_instance_klass();
2600 // Make sure the offset goes inside the instance layout.
2601 return k->contains_field_offset(tp->offset());
2602 // Note that OffsetBot and OffsetTop are very negative.
2603 }
2604 #endif
2605
2606 // Eliminate trivially redundant StoreCMs and accumulate their
2607 // precedence edges.
2608 void Compile::eliminate_redundant_card_marks(Node* n) {
2609 assert(n->Opcode() == Opcodes::Op_StoreCM, "expected StoreCM");
2610 if (n->in(MemNode::Address)->outcnt() > 1) {
2611 // There are multiple users of the same address so it might be
2612 // possible to eliminate some of the StoreCMs
2613 Node* mem = n->in(MemNode::Memory);
2614 Node* adr = n->in(MemNode::Address);
2615 Node* val = n->in(MemNode::ValueIn);
2616 Node* prev = n;
2617 bool done = false;
2618 // Walk the chain of StoreCMs eliminating ones that match. As
2619 // long as it's a chain of single users then the optimization is
2620 // safe. Eliminating partially redundant StoreCMs would require
2621 // cloning copies down the other paths.
2622 while (mem->Opcode() == Opcodes::Op_StoreCM && mem->outcnt() == 1 && !done) {
2623 if (adr == mem->in(MemNode::Address) &&
2624 val == mem->in(MemNode::ValueIn)) {
2625 // redundant StoreCM
2626 if (mem->req() > MemNode::OopStore) {
2627 // Hasn't been processed by this code yet.
2628 n->add_prec(mem->in(MemNode::OopStore));
2629 } else {
2630 // Already converted to precedence edge
2631 for (uint i = mem->req(); i < mem->len(); i++) {
2632 // Accumulate any precedence edges
2633 if (mem->in(i) != NULL) {
2634 n->add_prec(mem->in(i));
2635 }
2636 }
2637 // Everything above this point has been processed.
2638 done = true;
2639 }
2640 // Eliminate the previous StoreCM
2641 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
2642 assert(mem->outcnt() == 0, "should be dead");
2643 mem->disconnect_inputs(NULL, this);
2644 } else {
2645 prev = mem;
2646 }
2647 mem = prev->in(MemNode::Memory);
2648 }
2649 }
2650 }
2651
2652 //------------------------------final_graph_reshaping_impl----------------------
2653 // Implement items 1-5 from final_graph_reshaping below.
2654 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
2655
2656 if ( n->outcnt() == 0 ) return; // dead node
2657 Opcodes nop = n->Opcode();
2658
2659 // Check for 2-input instruction with "last use" on right input.
2660 // Swap to left input. Implements item (2).
2661 if( n->req() == 3 && // two-input instruction
2662 n->in(1)->outcnt() > 1 && // left use is NOT a last use
2663 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
2664 n->in(2)->outcnt() == 1 &&// right use IS a last use
2665 !n->in(2)->is_Con() ) { // right use is not a constant
2666 // Check for commutative opcode
2667 switch( nop ) {
2668 case Opcodes::Op_AddI: case Opcodes::Op_AddF: case Opcodes::Op_AddD: case Opcodes::Op_AddL:
2669 case Opcodes::Op_MaxI: case Opcodes::Op_MinI:
2670 case Opcodes::Op_MulI: case Opcodes::Op_MulF: case Opcodes::Op_MulD: case Opcodes::Op_MulL:
2671 case Opcodes::Op_AndL: case Opcodes::Op_XorL: case Opcodes::Op_OrL:
2672 case Opcodes::Op_AndI: case Opcodes::Op_XorI: case Opcodes::Op_OrI: {
2673 // Move "last use" input to left by swapping inputs
2674 n->swap_edges(1, 2);
2675 break;
2676 }
2677 default:
2678 break;
2679 }
2680 }
2681
2682 #ifdef ASSERT
2683 if( n->is_Mem() ) {
2684 int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2685 assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
2686 // oop will be recorded in oop map if load crosses safepoint
2687 n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
2688 LoadNode::is_immutable_value(n->in(MemNode::Address))),
2689 "raw memory operations should have control edge");
2690 }
2691 #endif
2692 // Count FPU ops and common calls, implements item (3)
2693 switch( nop ) {
2694 // Count all float operations that may use FPU
2695 case Opcodes::Op_AddF:
2696 case Opcodes::Op_SubF:
2697 case Opcodes::Op_MulF:
2698 case Opcodes::Op_DivF:
2699 case Opcodes::Op_NegF:
2700 case Opcodes::Op_ModF:
2701 case Opcodes::Op_ConvI2F:
2702 case Opcodes::Op_ConF:
2703 case Opcodes::Op_CmpF:
2704 case Opcodes::Op_CmpF3:
2705 // case Op_ConvL2F: // longs are split into 32-bit halves
2706 frc.inc_float_count();
2707 break;
2708
2709 case Opcodes::Op_ConvF2D:
2710 case Opcodes::Op_ConvD2F:
2711 frc.inc_float_count();
2712 frc.inc_double_count();
2713 break;
2714
2715 // Count all double operations that may use FPU
2716 case Opcodes::Op_AddD:
2717 case Opcodes::Op_SubD:
2718 case Opcodes::Op_MulD:
2719 case Opcodes::Op_DivD:
2720 case Opcodes::Op_NegD:
2721 case Opcodes::Op_ModD:
2722 case Opcodes::Op_ConvI2D:
2723 case Opcodes::Op_ConvD2I:
2724 // case Op_ConvL2D: // handled by leaf call
2725 // case Op_ConvD2L: // handled by leaf call
2726 case Opcodes::Op_ConD:
2727 case Opcodes::Op_CmpD:
2728 case Opcodes::Op_CmpD3:
2729 frc.inc_double_count();
2730 break;
2731 case Opcodes::Op_Opaque1: // Remove Opaque Nodes before matching
2732 case Opcodes::Op_Opaque2: // Remove Opaque Nodes before matching
2733 case Opcodes::Op_Opaque3:
2734 n->subsume_by(n->in(1), this);
2735 break;
2736 case Opcodes::Op_CallStaticJava:
2737 case Opcodes::Op_CallJava:
2738 case Opcodes::Op_CallDynamicJava:
2739 frc.inc_java_call_count(); // Count java call site;
2740 case Opcodes::Op_CallRuntime:
2741 case Opcodes::Op_CallLeaf:
2742 case Opcodes::Op_CallLeafNoFP: {
2743 assert( n->is_Call(), "" );
2744 CallNode *call = n->as_Call();
2745 // Count call sites where the FP mode bit would have to be flipped.
2746 // Do not count uncommon runtime calls:
2747 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
2748 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
2749 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) {
2750 frc.inc_call_count(); // Count the call site
2751 } else { // See if uncommon argument is shared
2752 Node *n = call->in(TypeFunc::Parms);
2753 Opcodes nop = n->Opcode();
2754 // Clone shared simple arguments to uncommon calls, item (1).
2755 if( n->outcnt() > 1 &&
2756 !n->is_Proj() &&
2757 nop != Opcodes::Op_CreateEx &&
2758 nop != Opcodes::Op_CheckCastPP &&
2759 nop != Opcodes::Op_DecodeN &&
2760 nop != Opcodes::Op_DecodeNKlass &&
2761 !n->is_Mem() ) {
2762 Node *x = n->clone();
2763 call->set_req( TypeFunc::Parms, x );
2764 }
2765 }
2766 break;
2767 }
2768
2769 case Opcodes::Op_StoreD:
2770 case Opcodes::Op_LoadD:
2771 case Opcodes::Op_LoadD_unaligned:
2772 frc.inc_double_count();
2773 goto handle_mem;
2774 case Opcodes::Op_StoreF:
2775 case Opcodes::Op_LoadF:
2776 frc.inc_float_count();
2777 goto handle_mem;
2778
2779 case Opcodes::Op_StoreCM:
2780 {
2781 // Convert OopStore dependence into precedence edge
2782 Node* prec = n->in(MemNode::OopStore);
2783 n->del_req(MemNode::OopStore);
2784 n->add_prec(prec);
2785 eliminate_redundant_card_marks(n);
2786 }
2787
2788 // fall through
2789
2790 case Opcodes::Op_StoreB:
2791 case Opcodes::Op_StoreC:
2792 case Opcodes::Op_StorePConditional:
2793 case Opcodes::Op_StoreI:
2794 case Opcodes::Op_StoreL:
2795 case Opcodes::Op_StoreIConditional:
2796 case Opcodes::Op_StoreLConditional:
2797 case Opcodes::Op_CompareAndSwapB:
2798 case Opcodes::Op_CompareAndSwapS:
2799 case Opcodes::Op_CompareAndSwapI:
2800 case Opcodes::Op_CompareAndSwapL:
2801 case Opcodes::Op_CompareAndSwapP:
2802 case Opcodes::Op_CompareAndSwapN:
2803 case Opcodes::Op_WeakCompareAndSwapB:
2804 case Opcodes::Op_WeakCompareAndSwapS:
2805 case Opcodes::Op_WeakCompareAndSwapI:
2806 case Opcodes::Op_WeakCompareAndSwapL:
2807 case Opcodes::Op_WeakCompareAndSwapP:
2808 case Opcodes::Op_WeakCompareAndSwapN:
2809 case Opcodes::Op_CompareAndExchangeB:
2810 case Opcodes::Op_CompareAndExchangeS:
2811 case Opcodes::Op_CompareAndExchangeI:
2812 case Opcodes::Op_CompareAndExchangeL:
2813 case Opcodes::Op_CompareAndExchangeP:
2814 case Opcodes::Op_CompareAndExchangeN:
2815 case Opcodes::Op_GetAndAddS:
2816 case Opcodes::Op_GetAndAddB:
2817 case Opcodes::Op_GetAndAddI:
2818 case Opcodes::Op_GetAndAddL:
2819 case Opcodes::Op_GetAndSetS:
2820 case Opcodes::Op_GetAndSetB:
2821 case Opcodes::Op_GetAndSetI:
2822 case Opcodes::Op_GetAndSetL:
2823 case Opcodes::Op_GetAndSetP:
2824 case Opcodes::Op_GetAndSetN:
2825 case Opcodes::Op_StoreP:
2826 case Opcodes::Op_StoreN:
2827 case Opcodes::Op_StoreNKlass:
2828 case Opcodes::Op_LoadB:
2829 case Opcodes::Op_LoadUB:
2830 case Opcodes::Op_LoadUS:
2831 case Opcodes::Op_LoadI:
2832 case Opcodes::Op_LoadKlass:
2833 case Opcodes::Op_LoadNKlass:
2834 case Opcodes::Op_LoadL:
2835 case Opcodes::Op_LoadL_unaligned:
2836 case Opcodes::Op_LoadPLocked:
2837 case Opcodes::Op_LoadP:
2838 case Opcodes::Op_LoadN:
2839 case Opcodes::Op_LoadRange:
2840 case Opcodes::Op_LoadS: {
2841 handle_mem:
2842 #ifdef ASSERT
2843 if( VerifyOptoOopOffsets ) {
2844 assert( n->is_Mem(), "" );
2845 MemNode *mem = (MemNode*)n;
2846 // Check to see if address types have grounded out somehow.
2847 const TypeInstPtr *tp = mem->in(MemNode::Address)->bottom_type()->isa_instptr();
2848 assert( !tp || oop_offset_is_sane(tp), "" );
2849 }
2850 #endif
2851 break;
2852 }
2853
2854 case Opcodes::Op_AddP: { // Assert sane base pointers
2855 Node *addp = n->in(AddPNode::Address);
2856 assert( !addp->is_AddP() ||
2857 addp->in(AddPNode::Base)->is_top() || // Top OK for allocation
2858 addp->in(AddPNode::Base) == n->in(AddPNode::Base),
2859 "Base pointers must match (addp %u)", addp->_idx );
2860 #ifdef _LP64
2861 if ((UseCompressedOops || UseCompressedClassPointers) &&
2862 addp->Opcode() == Opcodes::Op_ConP &&
2863 addp == n->in(AddPNode::Base) &&
2864 n->in(AddPNode::Offset)->is_Con()) {
2865 // Use addressing with narrow klass to load with offset on x86.
2866 // On sparc loading 32-bits constant and decoding it have less
2867 // instructions (4) then load 64-bits constant (7).
2868 // Do this transformation here since IGVN will convert ConN back to ConP.
2869 const Type* t = addp->bottom_type();
2870 if (t->isa_oopptr() || t->isa_klassptr()) {
2871 Node* nn = NULL;
2872
2873 Opcodes op = t->isa_oopptr() ? Opcodes::Op_ConN : Opcodes::Op_ConNKlass;
2874
2875 // Look for existing ConN node of the same exact type.
2876 Node* r = root();
2877 uint cnt = r->outcnt();
2878 for (uint i = 0; i < cnt; i++) {
2879 Node* m = r->raw_out(i);
2880 if (m!= NULL && m->Opcode() == op &&
2881 m->bottom_type()->make_ptr() == t) {
2882 nn = m;
2883 break;
2884 }
2885 }
2886 if (nn != NULL) {
2887 // Decode a narrow oop to match address
2888 // [R12 + narrow_oop_reg<<3 + offset]
2889 if (t->isa_oopptr()) {
2890 nn = new DecodeNNode(nn, t);
2891 } else {
2892 nn = new DecodeNKlassNode(nn, t);
2893 }
2903 assert(out_j == NULL || !out_j->is_AddP() || out_j->in(AddPNode::Base) != addp,
2904 "more than 2 AddP nodes in a chain (out_j %u)", out_j->_idx);
2905 }
2906 #endif
2907 }
2908 }
2909 n->set_req(AddPNode::Base, nn);
2910 n->set_req(AddPNode::Address, nn);
2911 if (addp->outcnt() == 0) {
2912 addp->disconnect_inputs(NULL, this);
2913 }
2914 }
2915 }
2916 }
2917 #endif
2918 // platform dependent reshaping of the address expression
2919 reshape_address(n->as_AddP());
2920 break;
2921 }
2922
2923 case Opcodes::Op_CastPP: {
2924 // Remove CastPP nodes to gain more freedom during scheduling but
2925 // keep the dependency they encode as control or precedence edges
2926 // (if control is set already) on memory operations. Some CastPP
2927 // nodes don't have a control (don't carry a dependency): skip
2928 // those.
2929 if (n->in(0) != NULL) {
2930 ResourceMark rm;
2931 Unique_Node_List wq;
2932 wq.push(n);
2933 for (uint next = 0; next < wq.size(); ++next) {
2934 Node *m = wq.at(next);
2935 for (DUIterator_Fast imax, i = m->fast_outs(imax); i < imax; i++) {
2936 Node* use = m->fast_out(i);
2937 if (use->is_Mem() || use->is_EncodeNarrowPtr()) {
2938 use->ensure_control_or_add_prec(n->in(0));
2939 } else {
2940 switch(use->Opcode()) {
2941 case Opcodes::Op_AddP:
2942 case Opcodes::Op_DecodeN:
2943 case Opcodes::Op_DecodeNKlass:
2944 case Opcodes::Op_CheckCastPP:
2945 case Opcodes::Op_CastPP:
2946 wq.push(use);
2947 break;
2948 }
2949 }
2950 }
2951 }
2952 }
2953 const bool is_LP64 = LP64_ONLY(true) NOT_LP64(false);
2954 if (is_LP64 && n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) {
2955 Node* in1 = n->in(1);
2956 const Type* t = n->bottom_type();
2957 Node* new_in1 = in1->clone();
2958 new_in1->as_DecodeN()->set_type(t);
2959
2960 if (!Matcher::narrow_oop_use_complex_address()) {
2961 //
2962 // x86, ARM and friends can handle 2 adds in addressing mode
2963 // and Matcher can fold a DecodeN node into address by using
2964 // a narrow oop directly and do implicit NULL check in address:
2965 //
2976 // Pin the new DecodeN node to non-null path on these platform (Sparc)
2977 // to keep the information to which NULL check the new DecodeN node
2978 // corresponds to use it as value in implicit_null_check().
2979 //
2980 new_in1->set_req(0, n->in(0));
2981 }
2982
2983 n->subsume_by(new_in1, this);
2984 if (in1->outcnt() == 0) {
2985 in1->disconnect_inputs(NULL, this);
2986 }
2987 } else {
2988 n->subsume_by(n->in(1), this);
2989 if (n->outcnt() == 0) {
2990 n->disconnect_inputs(NULL, this);
2991 }
2992 }
2993 break;
2994 }
2995 #ifdef _LP64
2996 case Opcodes::Op_CmpP:
2997 // Do this transformation here to preserve CmpPNode::sub() and
2998 // other TypePtr related Ideal optimizations (for example, ptr nullness).
2999 if (n->in(1)->is_DecodeNarrowPtr() || n->in(2)->is_DecodeNarrowPtr()) {
3000 Node* in1 = n->in(1);
3001 Node* in2 = n->in(2);
3002 if (!in1->is_DecodeNarrowPtr()) {
3003 in2 = in1;
3004 in1 = n->in(2);
3005 }
3006 assert(in1->is_DecodeNarrowPtr(), "sanity");
3007
3008 Node* new_in2 = NULL;
3009 if (in2->is_DecodeNarrowPtr()) {
3010 assert(in2->Opcode() == in1->Opcode(), "must be same node type");
3011 new_in2 = in2->in(1);
3012 } else if (in2->Opcode() == Opcodes::Op_ConP) {
3013 const Type* t = in2->bottom_type();
3014 if (t == TypePtr::NULL_PTR) {
3015 assert(in1->is_DecodeN(), "compare klass to null?");
3016 // Don't convert CmpP null check into CmpN if compressed
3017 // oops implicit null check is not generated.
3018 // This will allow to generate normal oop implicit null check.
3019 if (Matcher::gen_narrow_oop_implicit_null_checks())
3020 new_in2 = ConNode::make(TypeNarrowOop::NULL_PTR);
3021 //
3022 // This transformation together with CastPP transformation above
3023 // will generated code for implicit NULL checks for compressed oops.
3024 //
3025 // The original code after Optimize()
3026 //
3027 // LoadN memory, narrow_oop_reg
3028 // decode narrow_oop_reg, base_reg
3029 // CmpP base_reg, NULL
3030 // CastPP base_reg // NotNull
3031 // Load [base_reg + offset], val_reg
3032 //
3057 //
3058 } else if (t->isa_oopptr()) {
3059 new_in2 = ConNode::make(t->make_narrowoop());
3060 } else if (t->isa_klassptr()) {
3061 new_in2 = ConNode::make(t->make_narrowklass());
3062 }
3063 }
3064 if (new_in2 != NULL) {
3065 Node* cmpN = new CmpNNode(in1->in(1), new_in2);
3066 n->subsume_by(cmpN, this);
3067 if (in1->outcnt() == 0) {
3068 in1->disconnect_inputs(NULL, this);
3069 }
3070 if (in2->outcnt() == 0) {
3071 in2->disconnect_inputs(NULL, this);
3072 }
3073 }
3074 }
3075 break;
3076
3077 case Opcodes::Op_DecodeN:
3078 case Opcodes::Op_DecodeNKlass:
3079 assert(!n->in(1)->is_EncodeNarrowPtr(), "should be optimized out");
3080 // DecodeN could be pinned when it can't be fold into
3081 // an address expression, see the code for Op_CastPP above.
3082 assert(n->in(0) == NULL || (UseCompressedOops && !Matcher::narrow_oop_use_complex_address()), "no control");
3083 break;
3084
3085 case Opcodes::Op_EncodeP:
3086 case Opcodes::Op_EncodePKlass: {
3087 Node* in1 = n->in(1);
3088 if (in1->is_DecodeNarrowPtr()) {
3089 n->subsume_by(in1->in(1), this);
3090 } else if (in1->Opcode() == Opcodes::Op_ConP) {
3091 const Type* t = in1->bottom_type();
3092 if (t == TypePtr::NULL_PTR) {
3093 assert(t->isa_oopptr(), "null klass?");
3094 n->subsume_by(ConNode::make(TypeNarrowOop::NULL_PTR), this);
3095 } else if (t->isa_oopptr()) {
3096 n->subsume_by(ConNode::make(t->make_narrowoop()), this);
3097 } else if (t->isa_klassptr()) {
3098 n->subsume_by(ConNode::make(t->make_narrowklass()), this);
3099 }
3100 }
3101 if (in1->outcnt() == 0) {
3102 in1->disconnect_inputs(NULL, this);
3103 }
3104 break;
3105 }
3106
3107 case Opcodes::Op_Proj: {
3108 if (OptimizeStringConcat) {
3109 ProjNode* p = n->as_Proj();
3110 if (p->_is_io_use) {
3111 // Separate projections were used for the exception path which
3112 // are normally removed by a late inline. If it wasn't inlined
3113 // then they will hang around and should just be replaced with
3114 // the original one.
3115 Node* proj = NULL;
3116 // Replace with just one
3117 for (SimpleDUIterator i(p->in(0)); i.has_next(); i.next()) {
3118 Node *use = i.get();
3119 if (use->is_Proj() && p != use && use->as_Proj()->_con == p->_con) {
3120 proj = use;
3121 break;
3122 }
3123 }
3124 assert(proj != NULL, "must be found");
3125 p->subsume_by(proj, this);
3126 }
3127 }
3128 break;
3129 }
3130
3131 case Opcodes::Op_Phi:
3132 if (n->as_Phi()->bottom_type()->isa_narrowoop() || n->as_Phi()->bottom_type()->isa_narrowklass()) {
3133 // The EncodeP optimization may create Phi with the same edges
3134 // for all paths. It is not handled well by Register Allocator.
3135 Node* unique_in = n->in(1);
3136 assert(unique_in != NULL, "");
3137 uint cnt = n->req();
3138 for (uint i = 2; i < cnt; i++) {
3139 Node* m = n->in(i);
3140 assert(m != NULL, "");
3141 if (unique_in != m)
3142 unique_in = NULL;
3143 }
3144 if (unique_in != NULL) {
3145 n->subsume_by(unique_in, this);
3146 }
3147 }
3148 break;
3149
3150 #endif
3151
3152 #ifdef ASSERT
3153 case Opcodes::Op_CastII:
3154 // Verify that all range check dependent CastII nodes were removed.
3155 if (n->isa_CastII()->has_range_check()) {
3156 n->dump(3);
3157 assert(false, "Range check dependent CastII node was not removed");
3158 }
3159 break;
3160 #endif
3161
3162 case Opcodes::Op_ModI:
3163 if (UseDivMod) {
3164 // Check if a%b and a/b both exist
3165 Node* d = n->find_similar(Opcodes::Op_DivI);
3166 if (d) {
3167 // Replace them with a fused divmod if supported
3168 if (Matcher::has_match_rule(Opcodes::Op_DivModI)) {
3169 DivModINode* divmod = DivModINode::make(n);
3170 d->subsume_by(divmod->div_proj(), this);
3171 n->subsume_by(divmod->mod_proj(), this);
3172 } else {
3173 // replace a%b with a-((a/b)*b)
3174 Node* mult = new MulINode(d, d->in(2));
3175 Node* sub = new SubINode(d->in(1), mult);
3176 n->subsume_by(sub, this);
3177 }
3178 }
3179 }
3180 break;
3181
3182 case Opcodes::Op_ModL:
3183 if (UseDivMod) {
3184 // Check if a%b and a/b both exist
3185 Node* d = n->find_similar(Opcodes::Op_DivL);
3186 if (d) {
3187 // Replace them with a fused divmod if supported
3188 if (Matcher::has_match_rule(Opcodes::Op_DivModL)) {
3189 DivModLNode* divmod = DivModLNode::make(n);
3190 d->subsume_by(divmod->div_proj(), this);
3191 n->subsume_by(divmod->mod_proj(), this);
3192 } else {
3193 // replace a%b with a-((a/b)*b)
3194 Node* mult = new MulLNode(d, d->in(2));
3195 Node* sub = new SubLNode(d->in(1), mult);
3196 n->subsume_by(sub, this);
3197 }
3198 }
3199 }
3200 break;
3201
3202 case Opcodes::Op_LoadVector:
3203 case Opcodes::Op_StoreVector:
3204 break;
3205
3206 case Opcodes::Op_AddReductionVI:
3207 case Opcodes::Op_AddReductionVL:
3208 case Opcodes::Op_AddReductionVF:
3209 case Opcodes::Op_AddReductionVD:
3210 case Opcodes::Op_MulReductionVI:
3211 case Opcodes::Op_MulReductionVL:
3212 case Opcodes::Op_MulReductionVF:
3213 case Opcodes::Op_MulReductionVD:
3214 break;
3215
3216 case Opcodes::Op_PackB:
3217 case Opcodes::Op_PackS:
3218 case Opcodes::Op_PackI:
3219 case Opcodes::Op_PackF:
3220 case Opcodes::Op_PackL:
3221 case Opcodes::Op_PackD:
3222 if (n->req()-1 > 2) {
3223 // Replace many operand PackNodes with a binary tree for matching
3224 PackNode* p = (PackNode*) n;
3225 Node* btp = p->binary_tree_pack(1, n->req());
3226 n->subsume_by(btp, this);
3227 }
3228 break;
3229 case Opcodes::Op_Loop:
3230 case Opcodes::Op_CountedLoop:
3231 if (n->as_Loop()->is_inner_loop()) {
3232 frc.inc_inner_loop_count();
3233 }
3234 break;
3235 case Opcodes::Op_LShiftI:
3236 case Opcodes::Op_RShiftI:
3237 case Opcodes::Op_URShiftI:
3238 case Opcodes::Op_LShiftL:
3239 case Opcodes::Op_RShiftL:
3240 case Opcodes::Op_URShiftL:
3241 if (Matcher::need_masked_shift_count) {
3242 // The cpu's shift instructions don't restrict the count to the
3243 // lower 5/6 bits. We need to do the masking ourselves.
3244 Node* in2 = n->in(2);
3245 juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1);
3246 const TypeInt* t = in2->find_int_type();
3247 if (t != NULL && t->is_con()) {
3248 juint shift = t->get_con();
3249 if (shift > mask) { // Unsigned cmp
3250 n->set_req(2, ConNode::make(TypeInt::make(shift & mask)));
3251 }
3252 } else {
3253 if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) {
3254 Node* shift = new AndINode(in2, ConNode::make(TypeInt::make(mask)));
3255 n->set_req(2, shift);
3256 }
3257 }
3258 if (in2->outcnt() == 0) { // Remove dead node
3259 in2->disconnect_inputs(NULL, this);
3260 }
3261 }
3262 break;
3263 case Opcodes::Op_MemBarStoreStore:
3264 case Opcodes::Op_MemBarRelease:
3265 // Break the link with AllocateNode: it is no longer useful and
3266 // confuses register allocation.
3267 if (n->req() > MemBarNode::Precedent) {
3268 n->set_req(MemBarNode::Precedent, top());
3269 }
3270 break;
3271 case Opcodes::Op_RangeCheck: {
3272 RangeCheckNode* rc = n->as_RangeCheck();
3273 Node* iff = new IfNode(rc->in(0), rc->in(1), rc->_prob, rc->_fcnt);
3274 n->subsume_by(iff, this);
3275 frc._tests.push(iff);
3276 break;
3277 }
3278 case Opcodes::Op_ConvI2L: {
3279 if (!Matcher::convi2l_type_required) {
3280 // Code generation on some platforms doesn't need accurate
3281 // ConvI2L types. Widening the type can help remove redundant
3282 // address computations.
3283 n->as_Type()->set_type(TypeLong::INT);
3284 ResourceMark rm;
3285 Node_List wq;
3286 wq.push(n);
3287 for (uint next = 0; next < wq.size(); next++) {
3288 Node *m = wq.at(next);
3289
3290 for(;;) {
3291 // Loop over all nodes with identical inputs edges as m
3292 Node* k = m->find_similar(m->Opcode());
3293 if (k == NULL) {
3294 break;
3295 }
3296 // Push their uses so we get a chance to remove node made
3297 // redundant
3298 for (DUIterator_Fast imax, i = k->fast_outs(imax); i < imax; i++) {
3299 Node* u = k->fast_out(i);
3300 assert(!wq.contains(u), "shouldn't process one node several times");
3301 if (u->Opcode() == Opcodes::Op_LShiftL ||
3302 u->Opcode() == Opcodes::Op_AddL ||
3303 u->Opcode() == Opcodes::Op_SubL ||
3304 u->Opcode() == Opcodes::Op_AddP) {
3305 wq.push(u);
3306 }
3307 }
3308 // Replace all nodes with identical edges as m with m
3309 k->subsume_by(m, this);
3310 }
3311 }
3312 }
3313 break;
3314 }
3315 default:
3316 assert( !n->is_Call(), "" );
3317 assert( !n->is_Mem(), "" );
3318 assert( nop != Opcodes::Op_ProfileBoolean, "should be eliminated during IGVN");
3319 break;
3320 }
3321
3322 // Collect CFG split points
3323 if (n->is_MultiBranch() && !n->is_RangeCheck()) {
3324 frc._tests.push(n);
3325 }
3326 }
3327
3328 //------------------------------final_graph_reshaping_walk---------------------
3329 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
3330 // requires that the walk visits a node's inputs before visiting the node.
3331 void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {
3332 ResourceArea *area = Thread::current()->resource_area();
3333 Unique_Node_List sfpt(area);
3334
3335 frc._visited.set(root->_idx); // first, mark node as visited
3336 uint cnt = root->req();
3337 Node *n = root;
3338 uint i = 0;
3696 } else {
3697 visited.push(x);
3698 }
3699
3700 if (x->is_Region()) {
3701 for (uint i = 1; i < x->req(); i++) {
3702 worklist.push(x->in(i));
3703 }
3704 } else {
3705 worklist.push(x->in(0));
3706 // We are looking for the pattern:
3707 // /->ThreadLocal
3708 // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset)
3709 // \->ConI(0)
3710 // We want to verify that the If and the LoadB have the same control
3711 // See GraphKit::g1_write_barrier_pre()
3712 if (x->is_If()) {
3713 IfNode *iff = x->as_If();
3714 if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) {
3715 CmpNode *cmp = iff->in(1)->in(1)->as_Cmp();
3716 if (cmp->Opcode() == Opcodes::Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0
3717 && cmp->in(1)->is_Load()) {
3718 LoadNode* load = cmp->in(1)->as_Load();
3719 if (load->Opcode() == Opcodes::Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Opcodes::Op_ThreadLocal
3720 && load->in(2)->in(3)->is_Con()
3721 && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == marking_offset) {
3722
3723 Node* if_ctrl = iff->in(0);
3724 Node* load_ctrl = load->in(0);
3725
3726 if (if_ctrl != load_ctrl) {
3727 // Skip possible CProj->NeverBranch in infinite loops
3728 if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Opcodes::Op_CProj)
3729 && (if_ctrl->in(0)->is_MultiBranch() && if_ctrl->in(0)->Opcode() == Opcodes::Op_NeverBranch)) {
3730 if_ctrl = if_ctrl->in(0)->in(0);
3731 }
3732 }
3733 assert(load_ctrl != NULL && if_ctrl == load_ctrl, "controls must match");
3734 }
3735 }
3736 }
3737 }
3738 }
3739 }
3740 }
3741 }
3742
3743 #endif
3744
3745 // The Compile object keeps track of failure reasons separately from the ciEnv.
3746 // This is required because there is not quite a 1-1 relation between the
3747 // ciEnv and its compilation task and the Compile object. Note that one
3748 // ciEnv might use two Compile objects, if C2Compiler::compile_method decides
3749 // to backtrack and retry without subsuming loads. Other than this backtracking
4275 if (C->log() != NULL) {
4276 C->log()->inline_fail(msg);
4277 }
4278 }
4279
4280
4281 // Dump inlining replay data to the stream.
4282 // Don't change thread state and acquire any locks.
4283 void Compile::dump_inline_data(outputStream* out) {
4284 InlineTree* inl_tree = ilt();
4285 if (inl_tree != NULL) {
4286 out->print(" inline %d", inl_tree->count());
4287 inl_tree->dump_replay_data(out);
4288 }
4289 }
4290
4291 int Compile::cmp_expensive_nodes(Node* n1, Node* n2) {
4292 if (n1->Opcode() < n2->Opcode()) return -1;
4293 else if (n1->Opcode() > n2->Opcode()) return 1;
4294
4295 assert(n1->req() == n2->req(), "can't compare %s nodes: n1->req() = %d, n2->req() = %d", NodeClassNames[static_cast<uint>(n1->Opcode())], n1->req(), n2->req());
4296 for (uint i = 1; i < n1->req(); i++) {
4297 if (n1->in(i) < n2->in(i)) return -1;
4298 else if (n1->in(i) > n2->in(i)) return 1;
4299 }
4300
4301 return 0;
4302 }
4303
4304 int Compile::cmp_expensive_nodes(Node** n1p, Node** n2p) {
4305 Node* n1 = *n1p;
4306 Node* n2 = *n2p;
4307
4308 return cmp_expensive_nodes(n1, n2);
4309 }
4310
4311 void Compile::sort_expensive_nodes() {
4312 if (!expensive_nodes_sorted()) {
4313 _expensive_nodes->sort(cmp_expensive_nodes);
4314 }
4315 }
|