annotate src/share/vm/opto/split_if.cpp @ 4710:41406797186b

7113012: G1: rename not-fully-young GCs as "mixed" Summary: Renamed partially-young GCs as mixed and fully-young GCs as young. Change all external output that includes those terms (GC log and GC ergo log) as well as any comments, fields, methods, etc. The changeset also includes very minor code tidying up (added some curly brackets). Reviewed-by: johnc, brutisso
author tonyp
date Fri, 16 Dec 2011 02:14:27 -0500
parents 8805f8c1e23e
children 5e990493719e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1273
diff changeset
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1273
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1273
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1273
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
26 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
27 #include "opto/callnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
28 #include "opto/connode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
29 #include "opto/loopnode.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 //------------------------------split_thru_region------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // Split Node 'n' through merge point.
a61af66fc99e Initial load
duke
parents:
diff changeset
34 Node *PhaseIdealLoop::split_thru_region( Node *n, Node *region ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 uint wins = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 assert( n->is_CFG(), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
37 assert( region->is_Region(), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
38 Node *r = new (C, region->req()) RegionNode( region->req() );
a61af66fc99e Initial load
duke
parents:
diff changeset
39 IdealLoopTree *loop = get_loop( n );
a61af66fc99e Initial load
duke
parents:
diff changeset
40 for( uint i = 1; i < region->req(); i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 Node *x = n->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 Node *in0 = n->in(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 if( in0->in(0) == region ) x->set_req( 0, in0->in(i) );
a61af66fc99e Initial load
duke
parents:
diff changeset
44 for( uint j = 1; j < n->req(); j++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 Node *in = n->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 if( get_ctrl(in) == region )
a61af66fc99e Initial load
duke
parents:
diff changeset
47 x->set_req( j, in->in(i) );
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49 _igvn.register_new_node_with_optimizer(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 set_loop(x, loop);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 set_idom(x, x->in(0), dom_depth(x->in(0))+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 r->init_req(i, x);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Record region
a61af66fc99e Initial load
duke
parents:
diff changeset
56 r->set_req(0,region); // Not a TRUE RegionNode
a61af66fc99e Initial load
duke
parents:
diff changeset
57 _igvn.register_new_node_with_optimizer(r);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 set_loop(r, loop);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if( !loop->_child )
a61af66fc99e Initial load
duke
parents:
diff changeset
60 loop->_body.push(r);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return r;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 //------------------------------split_up---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Split block-local op up through the phis to empty the current block
a61af66fc99e Initial load
duke
parents:
diff changeset
66 bool PhaseIdealLoop::split_up( Node *n, Node *blk1, Node *blk2 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if( n->is_CFG() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 assert( n->in(0) != blk1, "Lousy candidate for split-if" );
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 if( get_ctrl(n) != blk1 && get_ctrl(n) != blk2 )
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return false; // Not block local
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if( n->is_Phi() ) return false; // Local PHIs are expected
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Recursively split-up inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
76 for (uint i = 1; i < n->req(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if( split_up( n->in(i), blk1, blk2 ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Got split recursively and self went dead?
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (n->outcnt() == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _igvn.remove_dead_node(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // Check for needing to clone-up a compare. Can't do that, it forces
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // another (nested) split-if transform. Instead, clone it "down".
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if( n->is_Cmp() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 assert(get_ctrl(n) == blk2 || get_ctrl(n) == blk1, "must be in block with IF");
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Check for simple Cmp/Bool/CMove which we can clone-up. Cmp/Bool/CMove
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // sequence can have no other users and it must all reside in the split-if
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // block. Non-simple Cmp/Bool/CMove sequences are 'cloned-down' below -
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // private, per-use versions of the Cmp and Bool are made. These sink to
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // the CMove block. If the CMove is in the split-if block, then in the
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // next iteration this will become a simple Cmp/Bool/CMove set to clone-up.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 Node *bol, *cmov;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if( !(n->outcnt() == 1 && n->unique_out()->is_Bool() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
97 (bol = n->unique_out()->as_Bool()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
98 (get_ctrl(bol) == blk1 ||
a61af66fc99e Initial load
duke
parents:
diff changeset
99 get_ctrl(bol) == blk2) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
100 bol->outcnt() == 1 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
101 bol->unique_out()->is_CMove() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
102 (cmov = bol->unique_out()->as_CMove()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
103 (get_ctrl(cmov) == blk1 ||
a61af66fc99e Initial load
duke
parents:
diff changeset
104 get_ctrl(cmov) == blk2) ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // Must clone down
a61af66fc99e Initial load
duke
parents:
diff changeset
107 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if( PrintOpto && VerifyLoopOptimizations ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 tty->print("Cloning down: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 n->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Clone down any block-local BoolNode uses of this CmpNode
a61af66fc99e Initial load
duke
parents:
diff changeset
114 for (DUIterator i = n->outs(); n->has_out(i); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 Node* bol = n->out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 assert( bol->is_Bool(), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (bol->outcnt() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 Node* use = bol->unique_out();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 Node *use_c = use->is_If() ? use->in(0) : get_ctrl(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (use_c == blk1 || use_c == blk2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (get_ctrl(bol) == blk1 || get_ctrl(bol) == blk2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Recursively sink any BoolNode
a61af66fc99e Initial load
duke
parents:
diff changeset
126 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if( PrintOpto && VerifyLoopOptimizations ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 tty->print("Cloning down: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 bol->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
132 for (DUIterator_Last jmin, j = bol->last_outs(jmin); j >= jmin; --j) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Uses are either IfNodes or CMoves
a61af66fc99e Initial load
duke
parents:
diff changeset
134 Node* iff = bol->last_out(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 assert( iff->in(1) == bol, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Get control block of either the CMove or the If input
a61af66fc99e Initial load
duke
parents:
diff changeset
137 Node *iff_ctrl = iff->is_If() ? iff->in(0) : get_ctrl(iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Node *x = bol->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 register_new_node(x, iff_ctrl);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 _igvn.hash_delete(iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 iff->set_req(1, x);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 _igvn._worklist.push(iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _igvn.remove_dead_node( bol );
a61af66fc99e Initial load
duke
parents:
diff changeset
145 --i;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Clone down this CmpNode
a61af66fc99e Initial load
duke
parents:
diff changeset
149 for (DUIterator_Last jmin, j = n->last_outs(jmin); j >= jmin; --j) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 Node* bol = n->last_out(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 assert( bol->in(1) == n, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
152 Node *x = n->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 register_new_node(x, get_ctrl(bol));
a61af66fc99e Initial load
duke
parents:
diff changeset
154 _igvn.hash_delete(bol);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 bol->set_req(1, x);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 _igvn._worklist.push(bol);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 _igvn.remove_dead_node( n );
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // See if splitting-up a Store. Any anti-dep loads must go up as
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // well. An anti-dep load might be in the wrong block, because in
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // this particular layout/schedule we ignored anti-deps and allow
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // memory to be alive twice. This only works if we do the same
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // operations on anti-dep loads as we do their killing stores.
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if( n->is_Store() && n->in(MemNode::Memory)->in(0) == n->in(0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Get store's memory slice
a61af66fc99e Initial load
duke
parents:
diff changeset
171 int alias_idx = C->get_alias_index(_igvn.type(n->in(MemNode::Address))->is_ptr());
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Get memory-phi anti-dep loads will be using
a61af66fc99e Initial load
duke
parents:
diff changeset
174 Node *memphi = n->in(MemNode::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 assert( memphi->is_Phi(), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // Hoist any anti-dep load to the splitting block;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // it will then "split-up".
a61af66fc99e Initial load
duke
parents:
diff changeset
178 for (DUIterator_Fast imax,i = memphi->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 Node *load = memphi->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 if( load->is_Load() && alias_idx == C->get_alias_index(_igvn.type(load->in(MemNode::Address))->is_ptr()) )
a61af66fc99e Initial load
duke
parents:
diff changeset
181 set_ctrl(load,blk1);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // Found some other Node; must clone it up
a61af66fc99e Initial load
duke
parents:
diff changeset
186 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
187 if( PrintOpto && VerifyLoopOptimizations ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 tty->print("Cloning up: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
189 n->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
192
1273
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
193 // ConvI2L may have type information on it which becomes invalid if
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
194 // it moves up in the graph so change any clones so widen the type
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
195 // to TypeLong::INT when pushing it up.
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
196 const Type* rtype = NULL;
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
197 if (n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::INT) {
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
198 rtype = TypeLong::INT;
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
199 }
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
200
0
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // Now actually split-up this guy. One copy per control path merging.
a61af66fc99e Initial load
duke
parents:
diff changeset
202 Node *phi = PhiNode::make_blank(blk1, n);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 for( uint j = 1; j < blk1->req(); j++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 Node *x = n->clone();
1273
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
205 // Widen the type of the ConvI2L when pushing up.
877a14af58e1 6663854: assert(n != __null,"Bad immediate dominator info.") in C2 with -Xcomp
never
parents: 1172
diff changeset
206 if (rtype != NULL) x->as_Type()->set_type(rtype);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if( n->in(0) && n->in(0) == blk1 )
a61af66fc99e Initial load
duke
parents:
diff changeset
208 x->set_req( 0, blk1->in(j) );
a61af66fc99e Initial load
duke
parents:
diff changeset
209 for( uint i = 1; i < n->req(); i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 Node *m = n->in(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if( get_ctrl(m) == blk1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 assert( m->in(0) == blk1, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
213 x->set_req( i, m->in(j) );
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 register_new_node( x, blk1->in(j) );
a61af66fc99e Initial load
duke
parents:
diff changeset
217 phi->init_req( j, x );
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // Announce phi to optimizer
a61af66fc99e Initial load
duke
parents:
diff changeset
220 register_new_node(phi, blk1);
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // Remove cloned-up value from optimizer; use phi instead
1621
6027dddc26c6 6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents: 1552
diff changeset
223 _igvn.replace_node( n, phi );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // (There used to be a self-recursive call to split_up() here,
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // but it is not needed. All necessary forward walking is done
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // by do_split_if() below.)
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 //------------------------------register_new_node------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
233 void PhaseIdealLoop::register_new_node( Node *n, Node *blk ) {
1172
b2b6a9bf6238 6894779: Loop Predication for Loop Optimizer in C2
cfang
parents: 605
diff changeset
234 assert(!n->is_CFG(), "must be data node");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
235 _igvn.register_new_node_with_optimizer(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 set_ctrl(n, blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 IdealLoopTree *loop = get_loop(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if( !loop->_child )
a61af66fc99e Initial load
duke
parents:
diff changeset
239 loop->_body.push(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 //------------------------------small_cache------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
243 struct small_cache : public Dict {
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 small_cache() : Dict( cmpkey, hashptr ) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
246 Node *probe( Node *use_blk ) { return (Node*)((*this)[use_blk]); }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 void lru_insert( Node *use_blk, Node *new_def ) { Insert(use_blk,new_def); }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 };
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 //------------------------------spinup-----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // "Spin up" the dominator tree, starting at the use site and stopping when we
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // find the post-dominating point.
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // We must be at the merge point which post-dominates 'new_false' and
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // 'new_true'. Figure out which edges into the RegionNode eventually lead up
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // to false and which to true. Put in a PhiNode to merge values; plug in
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // the appropriate false-arm or true-arm values. If some path leads to the
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // original IF, then insert a Phi recursively.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 Node *PhaseIdealLoop::spinup( Node *iff_dom, Node *new_false, Node *new_true, Node *use_blk, Node *def, small_cache *cache ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (use_blk->is_top()) // Handle dead uses
a61af66fc99e Initial load
duke
parents:
diff changeset
261 return use_blk;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 Node *prior_n = (Node*)0xdeadbeef;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 Node *n = use_blk; // Get path input
a61af66fc99e Initial load
duke
parents:
diff changeset
264 assert( use_blk != iff_dom, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // Here's the "spinup" the dominator tree loop. Do a cache-check
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // along the way, in case we've come this way before.
a61af66fc99e Initial load
duke
parents:
diff changeset
267 while( n != iff_dom ) { // Found post-dominating point?
a61af66fc99e Initial load
duke
parents:
diff changeset
268 prior_n = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 n = idom(n); // Search higher
a61af66fc99e Initial load
duke
parents:
diff changeset
270 Node *s = cache->probe( prior_n ); // Check cache
a61af66fc99e Initial load
duke
parents:
diff changeset
271 if( s ) return s; // Cache hit!
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 Node *phi_post;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if( prior_n == new_false || prior_n == new_true ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 phi_post = def->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
277 phi_post->set_req(0, prior_n );
a61af66fc99e Initial load
duke
parents:
diff changeset
278 register_new_node(phi_post, prior_n);
a61af66fc99e Initial load
duke
parents:
diff changeset
279 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // This method handles both control uses (looking for Regions) or data
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // uses (looking for Phis). If looking for a control use, then we need
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // to insert a Region instead of a Phi; however Regions always exist
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // previously (the hash_find_insert below would always hit) so we can
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // return the existing Region.
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if( def->is_CFG() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 phi_post = prior_n; // If looking for CFG, return prior
a61af66fc99e Initial load
duke
parents:
diff changeset
287 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 assert( def->is_Phi(), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
289 assert( prior_n->is_Region(), "must be a post-dominating merge point" );
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // Need a Phi here
a61af66fc99e Initial load
duke
parents:
diff changeset
292 phi_post = PhiNode::make_blank(prior_n, def);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Search for both true and false on all paths till find one.
a61af66fc99e Initial load
duke
parents:
diff changeset
294 for( uint i = 1; i < phi_post->req(); i++ ) // For all paths
a61af66fc99e Initial load
duke
parents:
diff changeset
295 phi_post->init_req( i, spinup( iff_dom, new_false, new_true, prior_n->in(i), def, cache ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
296 Node *t = _igvn.hash_find_insert(phi_post);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 if( t ) { // See if we already have this one
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // phi_post will not be used, so kill it
a61af66fc99e Initial load
duke
parents:
diff changeset
299 _igvn.remove_dead_node(phi_post);
a61af66fc99e Initial load
duke
parents:
diff changeset
300 phi_post->destruct();
a61af66fc99e Initial load
duke
parents:
diff changeset
301 phi_post = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 register_new_node( phi_post, prior_n );
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // Update cache everywhere
a61af66fc99e Initial load
duke
parents:
diff changeset
309 prior_n = (Node*)0xdeadbeef; // Reset IDOM walk
a61af66fc99e Initial load
duke
parents:
diff changeset
310 n = use_blk; // Get path input
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // Spin-up the idom tree again, basically doing path-compression.
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // Insert cache entries along the way, so that if we ever hit this
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // point in the IDOM tree again we'll stop immediately on a cache hit.
a61af66fc99e Initial load
duke
parents:
diff changeset
314 while( n != iff_dom ) { // Found post-dominating point?
a61af66fc99e Initial load
duke
parents:
diff changeset
315 prior_n = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 n = idom(n); // Search higher
a61af66fc99e Initial load
duke
parents:
diff changeset
317 cache->lru_insert( prior_n, phi_post ); // Fill cache
a61af66fc99e Initial load
duke
parents:
diff changeset
318 } // End of while not gone high enough
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 return phi_post;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 //------------------------------find_use_block---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // Find the block a USE is in. Normally USE's are in the same block as the
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // using instruction. For Phi-USE's, the USE is in the predecessor block
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // along the corresponding path.
a61af66fc99e Initial load
duke
parents:
diff changeset
327 Node *PhaseIdealLoop::find_use_block( Node *use, Node *def, Node *old_false, Node *new_false, Node *old_true, Node *new_true ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // CFG uses are their own block
a61af66fc99e Initial load
duke
parents:
diff changeset
329 if( use->is_CFG() )
a61af66fc99e Initial load
duke
parents:
diff changeset
330 return use;
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 if( use->is_Phi() ) { // Phi uses in prior block
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Grab the first Phi use; there may be many.
605
98cb887364d3 6810672: Comment typos
twisti
parents: 0
diff changeset
334 // Each will be handled as a separate iteration of
0
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // the "while( phi->outcnt() )" loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
336 uint j;
a61af66fc99e Initial load
duke
parents:
diff changeset
337 for( j = 1; j < use->req(); j++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
338 if( use->in(j) == def )
a61af66fc99e Initial load
duke
parents:
diff changeset
339 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 assert( j < use->req(), "def should be among use's inputs" );
a61af66fc99e Initial load
duke
parents:
diff changeset
341 return use->in(0)->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // Normal (non-phi) use
a61af66fc99e Initial load
duke
parents:
diff changeset
344 Node *use_blk = get_ctrl(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // Some uses are directly attached to the old (and going away)
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // false and true branches.
a61af66fc99e Initial load
duke
parents:
diff changeset
347 if( use_blk == old_false ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 use_blk = new_false;
a61af66fc99e Initial load
duke
parents:
diff changeset
349 set_ctrl(use, new_false);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if( use_blk == old_true ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 use_blk = new_true;
a61af66fc99e Initial load
duke
parents:
diff changeset
353 set_ctrl(use, new_true);
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (use_blk == NULL) { // He's dead, Jim
1621
6027dddc26c6 6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents: 1552
diff changeset
357 _igvn.replace_node(use, C->top());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 return use_blk;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 //------------------------------handle_use-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
364 // Handle uses of the merge point. Basically, split-if makes the merge point
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // go away so all uses of the merge point must go away as well. Most block
a61af66fc99e Initial load
duke
parents:
diff changeset
366 // local uses have already been split-up, through the merge point. Uses from
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // far below the merge point can't always be split up (e.g., phi-uses are
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // pinned) and it makes too much stuff live. Instead we use a path-based
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // solution to move uses down.
a61af66fc99e Initial load
duke
parents:
diff changeset
370 //
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // If the use is along the pre-split-CFG true branch, then the new use will
a61af66fc99e Initial load
duke
parents:
diff changeset
372 // be from the post-split-CFG true merge point. Vice-versa for the false
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // path. Some uses will be along both paths; then we sink the use to the
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // post-dominating location; we may need to insert a Phi there.
a61af66fc99e Initial load
duke
parents:
diff changeset
375 void PhaseIdealLoop::handle_use( Node *use, Node *def, small_cache *cache, Node *region_dom, Node *new_false, Node *new_true, Node *old_false, Node *old_true ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376
a61af66fc99e Initial load
duke
parents:
diff changeset
377 Node *use_blk = find_use_block(use,def,old_false,new_false,old_true,new_true);
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if( !use_blk ) return; // He's dead, Jim
a61af66fc99e Initial load
duke
parents:
diff changeset
379
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // Walk up the dominator tree until I hit either the old IfFalse, the old
a61af66fc99e Initial load
duke
parents:
diff changeset
381 // IfTrue or the old If. Insert Phis where needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
382 Node *new_def = spinup( region_dom, new_false, new_true, use_blk, def, cache );
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // Found where this USE goes. Re-point him.
a61af66fc99e Initial load
duke
parents:
diff changeset
385 uint i;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 for( i = 0; i < use->req(); i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
387 if( use->in(i) == def )
a61af66fc99e Initial load
duke
parents:
diff changeset
388 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
389 assert( i < use->req(), "def should be among use's inputs" );
a61af66fc99e Initial load
duke
parents:
diff changeset
390 _igvn.hash_delete(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 use->set_req(i, new_def);
a61af66fc99e Initial load
duke
parents:
diff changeset
392 _igvn._worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 //------------------------------do_split_if------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // Found an If getting its condition-code input from a Phi in the same block.
a61af66fc99e Initial load
duke
parents:
diff changeset
397 // Split thru the Region.
a61af66fc99e Initial load
duke
parents:
diff changeset
398 void PhaseIdealLoop::do_split_if( Node *iff ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
400 if( PrintOpto && VerifyLoopOptimizations )
a61af66fc99e Initial load
duke
parents:
diff changeset
401 tty->print_cr("Split-if");
2445
08eb13460b3a 7004535: Clone loop predicate during loop unswitch
kvn
parents: 1972
diff changeset
402 if (TraceLoopOpts) {
08eb13460b3a 7004535: Clone loop predicate during loop unswitch
kvn
parents: 1972
diff changeset
403 tty->print_cr("SplitIf");
08eb13460b3a 7004535: Clone loop predicate during loop unswitch
kvn
parents: 1972
diff changeset
404 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
405 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
406 C->set_major_progress();
a61af66fc99e Initial load
duke
parents:
diff changeset
407 Node *region = iff->in(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
408 Node *region_dom = idom(region);
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // We are going to clone this test (and the control flow with it) up through
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // the incoming merge point. We need to empty the current basic block.
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // Clone any instructions which must be in this block up through the merge
a61af66fc99e Initial load
duke
parents:
diff changeset
413 // point.
a61af66fc99e Initial load
duke
parents:
diff changeset
414 DUIterator i, j;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 bool progress = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 while (progress) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 progress = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
418 for (i = region->outs(); region->has_out(i); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 Node* n = region->out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
420 if( n == region ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 // The IF to be split is OK.
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if( n == iff ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 if( !n->is_Phi() ) { // Found pinned memory op or such
a61af66fc99e Initial load
duke
parents:
diff changeset
424 if (split_up(n, region, iff)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 i = region->refresh_out_pos(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 progress = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430 assert( n->in(0) == region, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 // Recursively split up all users of a Phi
a61af66fc99e Initial load
duke
parents:
diff changeset
433 for (j = n->outs(); n->has_out(j); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 Node* m = n->out(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // If m is dead, throw it away, and declare progress
a61af66fc99e Initial load
duke
parents:
diff changeset
436 if (_nodes[m->_idx] == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 _igvn.remove_dead_node(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
438 // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440 else if (m != iff && split_up(m, region, iff)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
442 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // Something unpredictable changed.
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // Tell the iterators to refresh themselves, and rerun the loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
447 i = region->refresh_out_pos(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 j = region->refresh_out_pos(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
449 progress = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 // Now we have no instructions in the block containing the IF.
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // Split the IF.
a61af66fc99e Initial load
duke
parents:
diff changeset
456 Node *new_iff = split_thru_region( iff, region );
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 // Replace both uses of 'new_iff' with Regions merging True/False
a61af66fc99e Initial load
duke
parents:
diff changeset
459 // paths. This makes 'new_iff' go dead.
a61af66fc99e Initial load
duke
parents:
diff changeset
460 Node *old_false, *old_true;
a61af66fc99e Initial load
duke
parents:
diff changeset
461 Node *new_false, *new_true;
a61af66fc99e Initial load
duke
parents:
diff changeset
462 for (DUIterator_Last j2min, j2 = iff->last_outs(j2min); j2 >= j2min; --j2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 Node *ifp = iff->last_out(j2);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 assert( ifp->Opcode() == Op_IfFalse || ifp->Opcode() == Op_IfTrue, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
465 ifp->set_req(0, new_iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
466 Node *ifpx = split_thru_region( ifp, region );
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // Replace 'If' projection of a Region with a Region of
a61af66fc99e Initial load
duke
parents:
diff changeset
469 // 'If' projections.
a61af66fc99e Initial load
duke
parents:
diff changeset
470 ifpx->set_req(0, ifpx); // A TRUE RegionNode
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // Setup dominator info
a61af66fc99e Initial load
duke
parents:
diff changeset
473 set_idom(ifpx, region_dom, dom_depth(region_dom) + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
474
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // Check for splitting loop tails
a61af66fc99e Initial load
duke
parents:
diff changeset
476 if( get_loop(iff)->tail() == ifp )
a61af66fc99e Initial load
duke
parents:
diff changeset
477 get_loop(iff)->_tail = ifpx;
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // Replace in the graph with lazy-update mechanism
a61af66fc99e Initial load
duke
parents:
diff changeset
480 new_iff->set_req(0, new_iff); // hook self so it does not go dead
a61af66fc99e Initial load
duke
parents:
diff changeset
481 lazy_replace_proj( ifp, ifpx );
a61af66fc99e Initial load
duke
parents:
diff changeset
482 new_iff->set_req(0, region);
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // Record bits for later xforms
a61af66fc99e Initial load
duke
parents:
diff changeset
485 if( ifp->Opcode() == Op_IfFalse ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 old_false = ifp;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 new_false = ifpx;
a61af66fc99e Initial load
duke
parents:
diff changeset
488 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
489 old_true = ifp;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 new_true = ifpx;
a61af66fc99e Initial load
duke
parents:
diff changeset
491 }
a61af66fc99e Initial load
duke
parents:
diff changeset
492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
493 _igvn.remove_dead_node(new_iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // Lazy replace IDOM info with the region's dominator
a61af66fc99e Initial load
duke
parents:
diff changeset
495 lazy_replace( iff, region_dom );
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // Now make the original merge point go dead, by handling all its uses.
a61af66fc99e Initial load
duke
parents:
diff changeset
498 small_cache region_cache;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // Preload some control flow in region-cache
a61af66fc99e Initial load
duke
parents:
diff changeset
500 region_cache.lru_insert( new_false, new_false );
a61af66fc99e Initial load
duke
parents:
diff changeset
501 region_cache.lru_insert( new_true , new_true );
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // Now handle all uses of the splitting block
3893
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
503 for (DUIterator k = region->outs(); region->has_out(k); k++) {
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
504 Node* phi = region->out(k);
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
505 if (!phi->in(0)) { // Dead phi? Remove it
0
a61af66fc99e Initial load
duke
parents:
diff changeset
506 _igvn.remove_dead_node(phi);
3893
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
507 } else if (phi == region) { // Found the self-reference
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
508 continue; // No roll-back of DUIterator
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
509 } else if (phi->is_Phi()) { // Expected common case: Phi hanging off of Region
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
510 assert(phi->in(0) == region, "Inconsistent graph");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // Need a per-def cache. Phi represents a def, so make a cache
a61af66fc99e Initial load
duke
parents:
diff changeset
512 small_cache phi_cache;
a61af66fc99e Initial load
duke
parents:
diff changeset
513
a61af66fc99e Initial load
duke
parents:
diff changeset
514 // Inspect all Phi uses to make the Phi go dead
a61af66fc99e Initial load
duke
parents:
diff changeset
515 for (DUIterator_Last lmin, l = phi->last_outs(lmin); l >= lmin; --l) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 Node* use = phi->last_out(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
517 // Compute the new DEF for this USE. New DEF depends on the path
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // taken from the original DEF to the USE. The new DEF may be some
a61af66fc99e Initial load
duke
parents:
diff changeset
519 // collection of PHI's merging values from different paths. The Phis
a61af66fc99e Initial load
duke
parents:
diff changeset
520 // inserted depend only on the location of the USE. We use a
a61af66fc99e Initial load
duke
parents:
diff changeset
521 // 2-element cache to handle multiple uses from the same block.
3893
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
522 handle_use(use, phi, &phi_cache, region_dom, new_false, new_true, old_false, old_true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
523 } // End of while phi has uses
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // Remove the dead Phi
a61af66fc99e Initial load
duke
parents:
diff changeset
525 _igvn.remove_dead_node( phi );
a61af66fc99e Initial load
duke
parents:
diff changeset
526 } else {
3893
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
527 assert(phi->in(0) == region, "Inconsistent graph");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
528 // Random memory op guarded by Region. Compute new DEF for USE.
3893
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
529 handle_use(phi, region, &region_cache, region_dom, new_false, new_true, old_false, old_true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
3893
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
531 // Every path above deletes a use of the region, except for the region
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
532 // self-cycle (which is needed by handle_use calling find_use_block
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
533 // calling get_ctrl calling get_ctrl_no_update looking for dead
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
534 // regions). So roll back the DUIterator innards.
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
535 --k;
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
536 } // End of while merge point has phis
0
a61af66fc99e Initial load
duke
parents:
diff changeset
537
3893
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
538 assert(region->outcnt() == 1, "Only self reference should remain"); // Just Self on the Region
8805f8c1e23e 6591247: C2 cleans up the merge point too early during SplitIf
iveresov
parents: 2445
diff changeset
539 region->set_req(0, NULL); // Break the self-cycle
0
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // Any leftover bits in the splitting block must not have depended on local
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // Phi inputs (these have already been split-up). Hence it's safe to hoist
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // these guys to the dominating point.
a61af66fc99e Initial load
duke
parents:
diff changeset
544 lazy_replace( region, region_dom );
a61af66fc99e Initial load
duke
parents:
diff changeset
545 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
546 if( VerifyLoopOptimizations ) verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
547 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
548 }