File: | jdk/src/hotspot/share/opto/loopPredicate.cpp |
Warning: | line 892, column 7 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | ||||||||
2 | * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. | ||||||||
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||||||||
4 | * | ||||||||
5 | * This code is free software; you can redistribute it and/or modify it | ||||||||
6 | * under the terms of the GNU General Public License version 2 only, as | ||||||||
7 | * published by the Free Software Foundation. | ||||||||
8 | * | ||||||||
9 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||||||||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||||||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||
12 | * version 2 for more details (a copy is included in the LICENSE file that | ||||||||
13 | * accompanied this code). | ||||||||
14 | * | ||||||||
15 | * You should have received a copy of the GNU General Public License version | ||||||||
16 | * 2 along with this work; if not, write to the Free Software Foundation, | ||||||||
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||||
18 | * | ||||||||
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||||||||
20 | * or visit www.oracle.com if you need additional information or have any | ||||||||
21 | * questions. | ||||||||
22 | * | ||||||||
23 | */ | ||||||||
24 | |||||||||
25 | #include "precompiled.hpp" | ||||||||
26 | #include "opto/loopnode.hpp" | ||||||||
27 | #include "opto/addnode.hpp" | ||||||||
28 | #include "opto/callnode.hpp" | ||||||||
29 | #include "opto/connode.hpp" | ||||||||
30 | #include "opto/convertnode.hpp" | ||||||||
31 | #include "opto/loopnode.hpp" | ||||||||
32 | #include "opto/matcher.hpp" | ||||||||
33 | #include "opto/mulnode.hpp" | ||||||||
34 | #include "opto/opaquenode.hpp" | ||||||||
35 | #include "opto/rootnode.hpp" | ||||||||
36 | #include "opto/subnode.hpp" | ||||||||
37 | #include <fenv.h> | ||||||||
38 | #include <math.h> | ||||||||
39 | |||||||||
40 | /* | ||||||||
41 | * The general idea of Loop Predication is to insert a predicate on the entry | ||||||||
42 | * path to a loop, and raise a uncommon trap if the check of the condition fails. | ||||||||
43 | * The condition checks are promoted from inside the loop body, and thus | ||||||||
44 | * the checks inside the loop could be eliminated. Currently, loop predication | ||||||||
45 | * optimization has been applied to remove array range check and loop invariant | ||||||||
46 | * checks (such as null checks). | ||||||||
47 | * | ||||||||
48 | * There are at least 3 kinds of predicates: a place holder inserted | ||||||||
49 | * at parse time, the tests added by predication above the place | ||||||||
50 | * holder (referred to as concrete predicates), skeleton predicates | ||||||||
51 | * that are added between main loop and pre loop to protect C2 from | ||||||||
52 | * inconsistencies in some rare cases of over unrolling. Skeleton | ||||||||
53 | * predicates themselves are expanded and updated as unrolling | ||||||||
54 | * proceeds. They don't compile to any code. | ||||||||
55 | * | ||||||||
56 | */ | ||||||||
57 | |||||||||
58 | //-------------------------------register_control------------------------- | ||||||||
59 | void PhaseIdealLoop::register_control(Node* n, IdealLoopTree *loop, Node* pred, bool update_body) { | ||||||||
60 | assert(n->is_CFG(), "msust be control node")do { if (!(n->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 60, "assert(" "n->is_CFG()" ") failed", "msust be control node" ); ::breakpoint(); } } while (0); | ||||||||
61 | _igvn.register_new_node_with_optimizer(n); | ||||||||
62 | if (update_body) { | ||||||||
63 | loop->_body.push(n); | ||||||||
64 | } | ||||||||
65 | set_loop(n, loop); | ||||||||
66 | // When called from beautify_loops() idom is not constructed yet. | ||||||||
67 | if (_idom != NULL__null) { | ||||||||
68 | set_idom(n, pred, dom_depth(pred)); | ||||||||
69 | } | ||||||||
70 | } | ||||||||
71 | |||||||||
72 | //------------------------------create_new_if_for_predicate------------------------ | ||||||||
73 | // create a new if above the uct_if_pattern for the predicate to be promoted. | ||||||||
74 | // | ||||||||
75 | // before after | ||||||||
76 | // ---------- ---------- | ||||||||
77 | // ctrl ctrl | ||||||||
78 | // | | | ||||||||
79 | // | | | ||||||||
80 | // v v | ||||||||
81 | // iff new_iff | ||||||||
82 | // / \ / \ | ||||||||
83 | // / \ / \ | ||||||||
84 | // v v v v | ||||||||
85 | // uncommon_proj cont_proj if_uct if_cont | ||||||||
86 | // \ | | | | | ||||||||
87 | // \ | | | | | ||||||||
88 | // v v v | v | ||||||||
89 | // rgn loop | iff | ||||||||
90 | // | | / \ | ||||||||
91 | // | | / \ | ||||||||
92 | // v | v v | ||||||||
93 | // uncommon_trap | uncommon_proj cont_proj | ||||||||
94 | // \ \ | | | ||||||||
95 | // \ \ | | | ||||||||
96 | // v v v v | ||||||||
97 | // rgn loop | ||||||||
98 | // | | ||||||||
99 | // | | ||||||||
100 | // v | ||||||||
101 | // uncommon_trap | ||||||||
102 | // | ||||||||
103 | // | ||||||||
104 | // We will create a region to guard the uct call if there is no one there. | ||||||||
105 | // The continuation projection (if_cont) of the new_iff is returned which | ||||||||
106 | // is by default a true projection if 'if_cont_is_true_proj' is true. | ||||||||
107 | // Otherwise, the continuation projection is set up to be the false | ||||||||
108 | // projection. This code is also used to clone predicates to cloned loops. | ||||||||
109 | ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry, | ||||||||
110 | Deoptimization::DeoptReason reason, int opcode, | ||||||||
111 | bool if_cont_is_true_proj, Node_List* old_new, | ||||||||
112 | UnswitchingAction unswitching_action) { | ||||||||
113 | assert(cont_proj->is_uncommon_trap_if_pattern(reason), "must be a uct if pattern!")do { if (!(cont_proj->is_uncommon_trap_if_pattern(reason)) ) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 113, "assert(" "cont_proj->is_uncommon_trap_if_pattern(reason)" ") failed", "must be a uct if pattern!"); ::breakpoint(); } } while (0); | ||||||||
114 | IfNode* iff = cont_proj->in(0)->as_If(); | ||||||||
115 | |||||||||
116 | ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con); | ||||||||
117 | Node *rgn = uncommon_proj->unique_ctrl_out(); | ||||||||
118 | assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct")do { if (!(rgn->is_Region() || rgn->is_Call())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 118, "assert(" "rgn->is_Region() || rgn->is_Call()" ") failed" , "must be a region or call uct"); ::breakpoint(); } } while ( 0); | ||||||||
119 | |||||||||
120 | uint proj_index = 1; // region's edge corresponding to uncommon_proj | ||||||||
121 | if (!rgn->is_Region()) { // create a region to guard the call | ||||||||
122 | assert(rgn->is_Call(), "must be call uct")do { if (!(rgn->is_Call())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 122, "assert(" "rgn->is_Call()" ") failed", "must be call uct" ); ::breakpoint(); } } while (0); | ||||||||
123 | CallNode* call = rgn->as_Call(); | ||||||||
124 | IdealLoopTree* loop = get_loop(call); | ||||||||
125 | rgn = new RegionNode(1); | ||||||||
126 | Node* uncommon_proj_orig = uncommon_proj; | ||||||||
127 | uncommon_proj = uncommon_proj->clone()->as_Proj(); | ||||||||
128 | register_control(uncommon_proj, loop, iff); | ||||||||
129 | rgn->add_req(uncommon_proj); | ||||||||
130 | register_control(rgn, loop, uncommon_proj); | ||||||||
131 | _igvn.replace_input_of(call, 0, rgn); | ||||||||
132 | // When called from beautify_loops() idom is not constructed yet. | ||||||||
133 | if (_idom != NULL__null) { | ||||||||
134 | set_idom(call, rgn, dom_depth(rgn)); | ||||||||
135 | } | ||||||||
136 | // Move nodes pinned on the projection or whose control is set to | ||||||||
137 | // the projection to the region. | ||||||||
138 | lazy_replace(uncommon_proj_orig, rgn); | ||||||||
139 | } else { | ||||||||
140 | // Find region's edge corresponding to uncommon_proj | ||||||||
141 | for (; proj_index < rgn->req(); proj_index++) | ||||||||
142 | if (rgn->in(proj_index) == uncommon_proj) break; | ||||||||
143 | assert(proj_index < rgn->req(), "sanity")do { if (!(proj_index < rgn->req())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 143, "assert(" "proj_index < rgn->req()" ") failed", "sanity" ); ::breakpoint(); } } while (0); | ||||||||
144 | } | ||||||||
145 | |||||||||
146 | Node* entry = iff->in(0); | ||||||||
147 | if (new_entry != NULL__null) { | ||||||||
148 | // Clonning the predicate to new location. | ||||||||
149 | entry = new_entry; | ||||||||
150 | } | ||||||||
151 | // Create new_iff | ||||||||
152 | IdealLoopTree* lp = get_loop(entry); | ||||||||
153 | IfNode* new_iff = NULL__null; | ||||||||
154 | if (opcode == Op_If) { | ||||||||
155 | new_iff = new IfNode(entry, iff->in(1), iff->_prob, iff->_fcnt); | ||||||||
156 | } else { | ||||||||
157 | assert(opcode == Op_RangeCheck, "no other if variant here")do { if (!(opcode == Op_RangeCheck)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 157, "assert(" "opcode == Op_RangeCheck" ") failed", "no other if variant here" ); ::breakpoint(); } } while (0); | ||||||||
158 | new_iff = new RangeCheckNode(entry, iff->in(1), iff->_prob, iff->_fcnt); | ||||||||
159 | } | ||||||||
160 | register_control(new_iff, lp, entry); | ||||||||
161 | Node* if_cont; | ||||||||
162 | Node* if_uct; | ||||||||
163 | if (if_cont_is_true_proj) { | ||||||||
164 | if_cont = new IfTrueNode(new_iff); | ||||||||
165 | if_uct = new IfFalseNode(new_iff); | ||||||||
166 | } else { | ||||||||
167 | if_uct = new IfTrueNode(new_iff); | ||||||||
168 | if_cont = new IfFalseNode(new_iff); | ||||||||
169 | } | ||||||||
170 | |||||||||
171 | if (cont_proj->is_IfFalse()) { | ||||||||
172 | // Swap | ||||||||
173 | Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp; | ||||||||
174 | } | ||||||||
175 | register_control(if_cont, lp, new_iff); | ||||||||
176 | register_control(if_uct, get_loop(rgn), new_iff); | ||||||||
177 | |||||||||
178 | // if_uct to rgn | ||||||||
179 | _igvn.hash_delete(rgn); | ||||||||
180 | rgn->add_req(if_uct); | ||||||||
181 | // When called from beautify_loops() idom is not constructed yet. | ||||||||
182 | if (_idom != NULL__null) { | ||||||||
183 | Node* ridom = idom(rgn); | ||||||||
184 | Node* nrdom = dom_lca_internal(ridom, new_iff); | ||||||||
185 | set_idom(rgn, nrdom, dom_depth(rgn)); | ||||||||
186 | } | ||||||||
187 | |||||||||
188 | // If rgn has phis add new edges which has the same | ||||||||
189 | // value as on original uncommon_proj pass. | ||||||||
190 | assert(rgn->in(rgn->req() -1) == if_uct, "new edge should be last")do { if (!(rgn->in(rgn->req() -1) == if_uct)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 190, "assert(" "rgn->in(rgn->req() -1) == if_uct" ") failed" , "new edge should be last"); ::breakpoint(); } } while (0); | ||||||||
191 | bool has_phi = false; | ||||||||
192 | for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) { | ||||||||
193 | Node* use = rgn->fast_out(i); | ||||||||
194 | if (use->is_Phi() && use->outcnt() > 0) { | ||||||||
195 | assert(use->in(0) == rgn, "")do { if (!(use->in(0) == rgn)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 195, "assert(" "use->in(0) == rgn" ") failed", ""); ::breakpoint (); } } while (0); | ||||||||
196 | _igvn.rehash_node_delayed(use); | ||||||||
197 | Node* phi_input = use->in(proj_index); | ||||||||
198 | if (unswitching_action == UnswitchingAction::FastLoopCloning | ||||||||
199 | && !phi_input->is_CFG() && !phi_input->is_Phi() && get_ctrl(phi_input) == uncommon_proj) { | ||||||||
200 | // There are some control dependent nodes on the uncommon projection and we are currently copying predicates | ||||||||
201 | // to the fast loop in loop unswitching (first step, slow loop is processed afterwards). For the fast loop, | ||||||||
202 | // we need to clone all the data nodes in the chain from the phi ('use') up until the node whose control input | ||||||||
203 | // is the uncommon_proj. The slow loop can reuse the old data nodes and thus only needs to update the control | ||||||||
204 | // input to the uncommon_proj (done on the next invocation of this method when 'unswitch_is_slow_loop' is true. | ||||||||
205 | assert(LoopUnswitching, "sanity check")do { if (!(LoopUnswitching)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 205, "assert(" "LoopUnswitching" ") failed", "sanity check" ); ::breakpoint(); } } while (0); | ||||||||
206 | phi_input = clone_data_nodes_for_fast_loop(phi_input, uncommon_proj, if_uct, old_new); | ||||||||
207 | } else if (unswitching_action == UnswitchingAction::SlowLoopRewiring) { | ||||||||
208 | // Replace phi input for the old predicate path with TOP as the predicate is dying anyways. This avoids the need | ||||||||
209 | // to clone the data nodes again for the slow loop. | ||||||||
210 | assert(LoopUnswitching, "sanity check")do { if (!(LoopUnswitching)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 210, "assert(" "LoopUnswitching" ") failed", "sanity check" ); ::breakpoint(); } } while (0); | ||||||||
211 | _igvn.replace_input_of(use, proj_index, C->top()); | ||||||||
212 | } | ||||||||
213 | use->add_req(phi_input); | ||||||||
214 | has_phi = true; | ||||||||
215 | } | ||||||||
216 | } | ||||||||
217 | assert(!has_phi || rgn->req() > 3, "no phis when region is created")do { if (!(!has_phi || rgn->req() > 3)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 217, "assert(" "!has_phi || rgn->req() > 3" ") failed" , "no phis when region is created"); ::breakpoint(); } } while (0); | ||||||||
218 | if (unswitching_action == UnswitchingAction::SlowLoopRewiring) { | ||||||||
219 | // Rewire the control dependent data nodes for the slow loop from the old to the new uncommon projection. | ||||||||
220 | assert(uncommon_proj->outcnt() > 1 && old_new == NULL, "sanity")do { if (!(uncommon_proj->outcnt() > 1 && old_new == __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 220, "assert(" "uncommon_proj->outcnt() > 1 && old_new == __null" ") failed", "sanity"); ::breakpoint(); } } while (0); | ||||||||
221 | for (DUIterator_Fast jmax, j = uncommon_proj->fast_outs(jmax); j < jmax; j++) { | ||||||||
222 | Node* data = uncommon_proj->fast_out(j); | ||||||||
223 | if (!data->is_CFG()) { | ||||||||
224 | _igvn.replace_input_of(data, 0, if_uct); | ||||||||
225 | set_ctrl(data, if_uct); | ||||||||
226 | --j; | ||||||||
227 | --jmax; | ||||||||
228 | } | ||||||||
229 | } | ||||||||
230 | } | ||||||||
231 | |||||||||
232 | if (new_entry == NULL__null) { | ||||||||
233 | // Attach if_cont to iff | ||||||||
234 | _igvn.replace_input_of(iff, 0, if_cont); | ||||||||
235 | if (_idom != NULL__null) { | ||||||||
236 | set_idom(iff, if_cont, dom_depth(iff)); | ||||||||
237 | } | ||||||||
238 | } | ||||||||
239 | return if_cont->as_Proj(); | ||||||||
240 | } | ||||||||
241 | |||||||||
242 | // Clone data nodes for the fast loop while creating a new If with create_new_if_for_predicate. Returns the node which is | ||||||||
243 | // used for the uncommon trap phi input. | ||||||||
244 | Node* PhaseIdealLoop::clone_data_nodes_for_fast_loop(Node* phi_input, ProjNode* uncommon_proj, Node* if_uct, Node_List* old_new) { | ||||||||
245 | // Step 1: Clone all nodes on the data chain but do not rewire anything, yet. Keep track of the cloned nodes | ||||||||
246 | // by using the old_new mapping. This mapping is then used in step 2 to rewire the cloned nodes accordingly. | ||||||||
247 | DEBUG_ONLY(uint last_idx = C->unique();)uint last_idx = C->unique(); | ||||||||
248 | Unique_Node_List list; | ||||||||
249 | list.push(phi_input); | ||||||||
250 | for (uint j = 0; j < list.size(); j++) { | ||||||||
251 | Node* next = list.at(j); | ||||||||
252 | Node* clone = next->clone(); | ||||||||
253 | _igvn.register_new_node_with_optimizer(clone); | ||||||||
254 | old_new->map(next->_idx, clone); | ||||||||
255 | for (uint k = 1; k < next->req(); k++) { | ||||||||
256 | Node* in = next->in(k); | ||||||||
257 | if (!in->is_Phi() && get_ctrl(in) == uncommon_proj) { | ||||||||
258 | list.push(in); | ||||||||
259 | } | ||||||||
260 | } | ||||||||
261 | } | ||||||||
262 | |||||||||
263 | // Step 2: All nodes are cloned. Rewire them by using the old_new mapping. | ||||||||
264 | for (uint j = 0; j < list.size(); j++) { | ||||||||
265 | Node* next = list.at(j); | ||||||||
266 | Node* clone = old_new->at(next->_idx); | ||||||||
267 | assert(clone != NULL && clone->_idx >= last_idx, "must exist and be a proper clone")do { if (!(clone != __null && clone->_idx >= last_idx )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 267, "assert(" "clone != __null && clone->_idx >= last_idx" ") failed", "must exist and be a proper clone"); ::breakpoint (); } } while (0); | ||||||||
268 | if (next->in(0) == uncommon_proj) { | ||||||||
269 | // All data nodes with a control input to the uncommon projection in the chain need to be rewired to the new uncommon | ||||||||
270 | // projection (could not only be the last data node in the chain but also, for example, a DivNode within the chain). | ||||||||
271 | _igvn.replace_input_of(clone, 0, if_uct); | ||||||||
272 | set_ctrl(clone, if_uct); | ||||||||
273 | } | ||||||||
274 | |||||||||
275 | // Rewire the inputs of the cloned nodes to the old nodes to the new clones. | ||||||||
276 | for (uint k = 1; k < next->req(); k++) { | ||||||||
277 | Node* in = next->in(k); | ||||||||
278 | if (!in->is_Phi()) { | ||||||||
279 | assert(!in->is_CFG(), "must be data node")do { if (!(!in->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 279, "assert(" "!in->is_CFG()" ") failed", "must be data node" ); ::breakpoint(); } } while (0); | ||||||||
280 | Node* in_clone = old_new->at(in->_idx); | ||||||||
281 | if (in_clone != NULL__null) { | ||||||||
282 | assert(in_clone->_idx >= last_idx, "must be a valid clone")do { if (!(in_clone->_idx >= last_idx)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 282, "assert(" "in_clone->_idx >= last_idx" ") failed" , "must be a valid clone"); ::breakpoint(); } } while (0); | ||||||||
283 | _igvn.replace_input_of(clone, k, in_clone); | ||||||||
284 | set_ctrl(clone, if_uct); | ||||||||
285 | } | ||||||||
286 | } | ||||||||
287 | } | ||||||||
288 | } | ||||||||
289 | Node* clone_phi_input = old_new->at(phi_input->_idx); | ||||||||
290 | assert(clone_phi_input != NULL && clone_phi_input->_idx >= last_idx, "must exist and be a proper clone")do { if (!(clone_phi_input != __null && clone_phi_input ->_idx >= last_idx)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 290, "assert(" "clone_phi_input != __null && clone_phi_input->_idx >= last_idx" ") failed", "must exist and be a proper clone"); ::breakpoint (); } } while (0); | ||||||||
291 | return clone_phi_input; | ||||||||
292 | } | ||||||||
293 | //--------------------------clone_predicate----------------------- | ||||||||
294 | ProjNode* PhaseIdealLoop::clone_predicate_to_unswitched_loop(ProjNode* predicate_proj, Node* new_entry, | ||||||||
295 | Deoptimization::DeoptReason reason, Node_List* old_new) { | ||||||||
296 | UnswitchingAction unswitching_action; | ||||||||
297 | if (predicate_proj->other_if_proj()->outcnt() > 1) { | ||||||||
298 | // There are some data dependencies that need to be taken care of when cloning a predicate. | ||||||||
299 | unswitching_action = old_new == NULL__null ? UnswitchingAction::SlowLoopRewiring : UnswitchingAction::FastLoopCloning; | ||||||||
300 | } else { | ||||||||
301 | unswitching_action = UnswitchingAction::None; | ||||||||
302 | } | ||||||||
303 | |||||||||
304 | ProjNode* new_predicate_proj = create_new_if_for_predicate(predicate_proj, new_entry, reason, Op_If, | ||||||||
305 | true, old_new, unswitching_action); | ||||||||
306 | IfNode* iff = new_predicate_proj->in(0)->as_If(); | ||||||||
307 | Node* ctrl = iff->in(0); | ||||||||
308 | |||||||||
309 | // Match original condition since predicate's projections could be swapped. | ||||||||
310 | assert(predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be")do { if (!(predicate_proj->in(0)->in(1)->in(1)->Opcode ()==Op_Opaque1)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 310, "assert(" "predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1" ") failed", "must be"); ::breakpoint(); } } while (0); | ||||||||
311 | Node* opq = new Opaque1Node(C, predicate_proj->in(0)->in(1)->in(1)->in(1)); | ||||||||
312 | C->add_predicate_opaq(opq); | ||||||||
313 | Node* bol = new Conv2BNode(opq); | ||||||||
314 | register_new_node(opq, ctrl); | ||||||||
315 | register_new_node(bol, ctrl); | ||||||||
316 | _igvn.hash_delete(iff); | ||||||||
317 | iff->set_req(1, bol); | ||||||||
318 | return new_predicate_proj; | ||||||||
319 | } | ||||||||
320 | |||||||||
321 | // Clones skeleton predicates starting at 'old_predicate_proj' by following its control inputs and rewires the control edges of in the loop from | ||||||||
322 | // the old predicates to the new cloned predicates. | ||||||||
323 | void PhaseIdealLoop::clone_skeleton_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, Deoptimization::DeoptReason reason, | ||||||||
324 | ProjNode* old_predicate_proj, ProjNode* iffast_pred, ProjNode* ifslow_pred) { | ||||||||
325 | assert(iffast_pred->in(0)->is_If() && ifslow_pred->in(0)->is_If(), "sanity check")do { if (!(iffast_pred->in(0)->is_If() && ifslow_pred ->in(0)->is_If())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 325, "assert(" "iffast_pred->in(0)->is_If() && ifslow_pred->in(0)->is_If()" ") failed", "sanity check"); ::breakpoint(); } } while (0); | ||||||||
326 | // Only need to clone range check predicates as those can be changed and duplicated by inserting pre/main/post loops | ||||||||
327 | // and doing loop unrolling. Push the original predicates on a list to later process them in reverse order to keep the | ||||||||
328 | // original predicate order. | ||||||||
329 | Unique_Node_List list; | ||||||||
330 | get_skeleton_predicates(old_predicate_proj, list); | ||||||||
331 | |||||||||
332 | Node_List to_process; | ||||||||
333 | IfNode* iff = old_predicate_proj->in(0)->as_If(); | ||||||||
334 | ProjNode* uncommon_proj = iff->proj_out(1 - old_predicate_proj->as_Proj()->_con); | ||||||||
335 | // Process in reverse order such that 'create_new_if_for_predicate' can be used in 'clone_skeleton_predicate_for_unswitched_loops' | ||||||||
336 | // and the original order is maintained. | ||||||||
337 | for (int i = list.size() - 1; i >= 0; i--) { | ||||||||
338 | Node* predicate = list.at(i); | ||||||||
339 | assert(predicate->in(0)->is_If(), "must be If node")do { if (!(predicate->in(0)->is_If())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 339, "assert(" "predicate->in(0)->is_If()" ") failed" , "must be If node"); ::breakpoint(); } } while (0); | ||||||||
340 | iff = predicate->in(0)->as_If(); | ||||||||
341 | assert(predicate->is_Proj() && predicate->as_Proj()->is_IfProj(), "predicate must be a projection of an if node")do { if (!(predicate->is_Proj() && predicate->as_Proj ()->is_IfProj())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 341, "assert(" "predicate->is_Proj() && predicate->as_Proj()->is_IfProj()" ") failed", "predicate must be a projection of an if node"); ::breakpoint(); } } while (0); | ||||||||
342 | IfProjNode* predicate_proj = predicate->as_IfProj(); | ||||||||
343 | |||||||||
344 | ProjNode* fast_proj = clone_skeleton_predicate_for_unswitched_loops(iff, predicate_proj, reason, iffast_pred); | ||||||||
345 | assert(skeleton_predicate_has_opaque(fast_proj->in(0)->as_If()), "must find skeleton predicate for fast loop")do { if (!(skeleton_predicate_has_opaque(fast_proj->in(0)-> as_If()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 345, "assert(" "skeleton_predicate_has_opaque(fast_proj->in(0)->as_If())" ") failed", "must find skeleton predicate for fast loop"); :: breakpoint(); } } while (0); | ||||||||
346 | ProjNode* slow_proj = clone_skeleton_predicate_for_unswitched_loops(iff, predicate_proj, reason, ifslow_pred); | ||||||||
347 | assert(skeleton_predicate_has_opaque(slow_proj->in(0)->as_If()), "must find skeleton predicate for slow loop")do { if (!(skeleton_predicate_has_opaque(slow_proj->in(0)-> as_If()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 347, "assert(" "skeleton_predicate_has_opaque(slow_proj->in(0)->as_If())" ") failed", "must find skeleton predicate for slow loop"); :: breakpoint(); } } while (0); | ||||||||
348 | |||||||||
349 | // Update control dependent data nodes. | ||||||||
350 | for (DUIterator j = predicate->outs(); predicate->has_out(j); j++) { | ||||||||
351 | Node* fast_node = predicate->out(j); | ||||||||
352 | if (loop->is_member(get_loop(ctrl_or_self(fast_node)))) { | ||||||||
353 | assert(fast_node->in(0) == predicate, "only control edge")do { if (!(fast_node->in(0) == predicate)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 353, "assert(" "fast_node->in(0) == predicate" ") failed" , "only control edge"); ::breakpoint(); } } while (0); | ||||||||
354 | Node* slow_node = old_new[fast_node->_idx]; | ||||||||
355 | assert(slow_node->in(0) == predicate, "only control edge")do { if (!(slow_node->in(0) == predicate)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 355, "assert(" "slow_node->in(0) == predicate" ") failed" , "only control edge"); ::breakpoint(); } } while (0); | ||||||||
356 | _igvn.replace_input_of(fast_node, 0, fast_proj); | ||||||||
357 | to_process.push(slow_node); | ||||||||
358 | --j; | ||||||||
359 | } | ||||||||
360 | } | ||||||||
361 | // Have to delay updates to the slow loop so uses of predicate are not modified while we iterate on them. | ||||||||
362 | while (to_process.size() > 0) { | ||||||||
363 | Node* slow_node = to_process.pop(); | ||||||||
364 | _igvn.replace_input_of(slow_node, 0, slow_proj); | ||||||||
365 | } | ||||||||
366 | } | ||||||||
367 | } | ||||||||
368 | |||||||||
369 | // Put all skeleton predicate projections on a list, starting at 'predicate' and going up in the tree. If 'get_opaque' | ||||||||
370 | // is set, then the Opaque4 nodes of the skeleton predicates are put on the list instead of the projections. | ||||||||
371 | void PhaseIdealLoop::get_skeleton_predicates(Node* predicate, Unique_Node_List& list, bool get_opaque) { | ||||||||
372 | IfNode* iff = predicate->in(0)->as_If(); | ||||||||
373 | ProjNode* uncommon_proj = iff->proj_out(1 - predicate->as_Proj()->_con); | ||||||||
374 | Node* rgn = uncommon_proj->unique_ctrl_out(); | ||||||||
375 | assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct")do { if (!(rgn->is_Region() || rgn->is_Call())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 375, "assert(" "rgn->is_Region() || rgn->is_Call()" ") failed" , "must be a region or call uct"); ::breakpoint(); } } while ( 0); | ||||||||
376 | assert(iff->in(1)->in(1)->Opcode() == Op_Opaque1, "unexpected predicate shape")do { if (!(iff->in(1)->in(1)->Opcode() == Op_Opaque1 )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 376, "assert(" "iff->in(1)->in(1)->Opcode() == Op_Opaque1" ") failed", "unexpected predicate shape"); ::breakpoint(); } } while (0); | ||||||||
377 | predicate = iff->in(0); | ||||||||
378 | while (predicate != NULL__null && predicate->is_Proj() && predicate->in(0)->is_If()) { | ||||||||
379 | iff = predicate->in(0)->as_If(); | ||||||||
380 | uncommon_proj = iff->proj_out(1 - predicate->as_Proj()->_con); | ||||||||
381 | if (uncommon_proj->unique_ctrl_out() != rgn) { | ||||||||
382 | break; | ||||||||
383 | } | ||||||||
384 | if (iff->in(1)->Opcode() == Op_Opaque4 && skeleton_predicate_has_opaque(iff)) { | ||||||||
385 | if (get_opaque) { | ||||||||
386 | // Collect the predicate Opaque4 node. | ||||||||
387 | list.push(iff->in(1)); | ||||||||
388 | } else { | ||||||||
389 | // Collect the predicate projection. | ||||||||
390 | list.push(predicate); | ||||||||
391 | } | ||||||||
392 | } | ||||||||
393 | predicate = predicate->in(0)->in(0); | ||||||||
394 | } | ||||||||
395 | } | ||||||||
396 | |||||||||
397 | // Clone a skeleton predicate for an unswitched loop. OpaqueLoopInit and OpaqueLoopStride nodes are cloned and uncommon | ||||||||
398 | // traps are kept for the predicate (a Halt node is used later when creating pre/main/post loops and copying this cloned | ||||||||
399 | // predicate again). | ||||||||
400 | ProjNode* PhaseIdealLoop::clone_skeleton_predicate_for_unswitched_loops(Node* iff, ProjNode* predicate, | ||||||||
401 | Deoptimization::DeoptReason reason, | ||||||||
402 | ProjNode* output_proj) { | ||||||||
403 | Node* bol = clone_skeleton_predicate_bool(iff, NULL__null, NULL__null, output_proj); | ||||||||
404 | ProjNode* proj = create_new_if_for_predicate(output_proj, NULL__null, reason, iff->Opcode(), predicate->is_IfTrue()); | ||||||||
405 | _igvn.replace_input_of(proj->in(0), 1, bol); | ||||||||
406 | _igvn.replace_input_of(output_proj->in(0), 0, proj); | ||||||||
407 | set_idom(output_proj->in(0), proj, dom_depth(proj)); | ||||||||
408 | return proj; | ||||||||
409 | } | ||||||||
410 | |||||||||
411 | //--------------------------clone_loop_predicates----------------------- | ||||||||
412 | // Clone loop predicates to cloned loops when unswitching a loop. | ||||||||
413 | void PhaseIdealLoop::clone_predicates_to_unswitched_loop(IdealLoopTree* loop, Node_List& old_new, ProjNode*& iffast_pred, ProjNode*& ifslow_pred) { | ||||||||
414 | LoopNode* head = loop->_head->as_Loop(); | ||||||||
415 | bool clone_limit_check = !head->is_CountedLoop(); | ||||||||
416 | Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl); | ||||||||
417 | |||||||||
418 | // Search original predicates | ||||||||
419 | ProjNode* limit_check_proj = NULL__null; | ||||||||
420 | limit_check_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check); | ||||||||
421 | if (limit_check_proj != NULL__null) { | ||||||||
422 | entry = skip_loop_predicates(entry); | ||||||||
423 | } | ||||||||
424 | ProjNode* profile_predicate_proj = NULL__null; | ||||||||
425 | ProjNode* predicate_proj = NULL__null; | ||||||||
426 | if (UseProfiledLoopPredicate) { | ||||||||
427 | profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate); | ||||||||
428 | if (profile_predicate_proj != NULL__null) { | ||||||||
429 | entry = skip_loop_predicates(entry); | ||||||||
430 | } | ||||||||
431 | } | ||||||||
432 | if (UseLoopPredicate) { | ||||||||
433 | predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); | ||||||||
434 | } | ||||||||
435 | if (predicate_proj != NULL__null) { // right pattern that can be used by loop predication | ||||||||
436 | // clone predicate | ||||||||
437 | iffast_pred = clone_predicate_to_unswitched_loop(predicate_proj, iffast_pred, Deoptimization::Reason_predicate, &old_new); | ||||||||
438 | ifslow_pred = clone_predicate_to_unswitched_loop(predicate_proj, ifslow_pred, Deoptimization::Reason_predicate); | ||||||||
439 | clone_skeleton_predicates_to_unswitched_loop(loop, old_new, Deoptimization::Reason_predicate, predicate_proj, iffast_pred, ifslow_pred); | ||||||||
440 | |||||||||
441 | check_created_predicate_for_unswitching(iffast_pred); | ||||||||
442 | check_created_predicate_for_unswitching(ifslow_pred); | ||||||||
443 | } | ||||||||
444 | if (profile_predicate_proj != NULL__null) { // right pattern that can be used by loop predication | ||||||||
445 | // clone predicate | ||||||||
446 | iffast_pred = clone_predicate_to_unswitched_loop(profile_predicate_proj, iffast_pred, Deoptimization::Reason_profile_predicate, &old_new); | ||||||||
447 | ifslow_pred = clone_predicate_to_unswitched_loop(profile_predicate_proj, ifslow_pred, Deoptimization::Reason_profile_predicate); | ||||||||
448 | clone_skeleton_predicates_to_unswitched_loop(loop, old_new, Deoptimization::Reason_profile_predicate, profile_predicate_proj, iffast_pred, ifslow_pred); | ||||||||
449 | |||||||||
450 | check_created_predicate_for_unswitching(iffast_pred); | ||||||||
451 | check_created_predicate_for_unswitching(ifslow_pred); | ||||||||
452 | } | ||||||||
453 | if (limit_check_proj != NULL__null && clone_limit_check) { | ||||||||
454 | // Clone loop limit check last to insert it before loop. | ||||||||
455 | // Don't clone a limit check which was already finalized | ||||||||
456 | // for this counted loop (only one limit check is needed). | ||||||||
457 | iffast_pred = clone_predicate_to_unswitched_loop(limit_check_proj, iffast_pred, Deoptimization::Reason_loop_limit_check, &old_new); | ||||||||
458 | ifslow_pred = clone_predicate_to_unswitched_loop(limit_check_proj, ifslow_pred, Deoptimization::Reason_loop_limit_check); | ||||||||
459 | |||||||||
460 | check_created_predicate_for_unswitching(iffast_pred); | ||||||||
461 | check_created_predicate_for_unswitching(ifslow_pred); | ||||||||
462 | } | ||||||||
463 | } | ||||||||
464 | |||||||||
465 | #ifndef PRODUCT | ||||||||
466 | void PhaseIdealLoop::check_created_predicate_for_unswitching(const Node* new_entry) { | ||||||||
467 | assert(new_entry != NULL, "IfTrue or IfFalse after clone predicate")do { if (!(new_entry != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 467, "assert(" "new_entry != __null" ") failed", "IfTrue or IfFalse after clone predicate" ); ::breakpoint(); } } while (0); | ||||||||
468 | if (TraceLoopPredicate) { | ||||||||
469 | tty->print("Loop Predicate cloned: "); | ||||||||
470 | debug_only(new_entry->in(0)->dump();)new_entry->in(0)->dump();; | ||||||||
471 | } | ||||||||
472 | } | ||||||||
473 | #endif | ||||||||
474 | |||||||||
475 | |||||||||
476 | //--------------------------skip_loop_predicates------------------------------ | ||||||||
477 | // Skip related predicates. | ||||||||
478 | Node* PhaseIdealLoop::skip_loop_predicates(Node* entry) { | ||||||||
479 | IfNode* iff = entry->in(0)->as_If(); | ||||||||
480 | ProjNode* uncommon_proj = iff->proj_out(1 - entry->as_Proj()->_con); | ||||||||
481 | Node* rgn = uncommon_proj->unique_ctrl_out(); | ||||||||
482 | assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct")do { if (!(rgn->is_Region() || rgn->is_Call())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 482, "assert(" "rgn->is_Region() || rgn->is_Call()" ") failed" , "must be a region or call uct"); ::breakpoint(); } } while ( 0); | ||||||||
483 | entry = entry->in(0)->in(0); | ||||||||
484 | while (entry != NULL__null && entry->is_Proj() && entry->in(0)->is_If()) { | ||||||||
485 | uncommon_proj = entry->in(0)->as_If()->proj_out(1 - entry->as_Proj()->_con); | ||||||||
486 | if (uncommon_proj->unique_ctrl_out() != rgn) | ||||||||
487 | break; | ||||||||
488 | entry = entry->in(0)->in(0); | ||||||||
489 | } | ||||||||
490 | return entry; | ||||||||
491 | } | ||||||||
492 | |||||||||
493 | Node* PhaseIdealLoop::skip_all_loop_predicates(Node* entry) { | ||||||||
494 | Node* predicate = NULL__null; | ||||||||
495 | predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check); | ||||||||
496 | if (predicate != NULL__null) { | ||||||||
497 | entry = skip_loop_predicates(entry); | ||||||||
498 | } | ||||||||
499 | if (UseProfiledLoopPredicate) { | ||||||||
500 | predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate); | ||||||||
501 | if (predicate != NULL__null) { // right pattern that can be used by loop predication | ||||||||
502 | entry = skip_loop_predicates(entry); | ||||||||
503 | } | ||||||||
504 | } | ||||||||
505 | if (UseLoopPredicate) { | ||||||||
506 | predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); | ||||||||
507 | if (predicate != NULL__null) { // right pattern that can be used by loop predication | ||||||||
508 | entry = skip_loop_predicates(entry); | ||||||||
509 | } | ||||||||
510 | } | ||||||||
511 | return entry; | ||||||||
512 | } | ||||||||
513 | |||||||||
514 | //--------------------------find_predicate_insertion_point------------------- | ||||||||
515 | // Find a good location to insert a predicate | ||||||||
516 | ProjNode* PhaseIdealLoop::find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason) { | ||||||||
517 | if (start_c == NULL__null || !start_c->is_Proj()) | ||||||||
518 | return NULL__null; | ||||||||
519 | if (start_c->as_Proj()->is_uncommon_trap_if_pattern(reason)) { | ||||||||
520 | return start_c->as_Proj(); | ||||||||
521 | } | ||||||||
522 | return NULL__null; | ||||||||
523 | } | ||||||||
524 | |||||||||
525 | //--------------------------find_predicate------------------------------------ | ||||||||
526 | // Find a predicate | ||||||||
527 | Node* PhaseIdealLoop::find_predicate(Node* entry) { | ||||||||
528 | Node* predicate = NULL__null; | ||||||||
529 | predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check); | ||||||||
530 | if (predicate != NULL__null) { // right pattern that can be used by loop predication | ||||||||
531 | return entry; | ||||||||
532 | } | ||||||||
533 | if (UseLoopPredicate) { | ||||||||
534 | predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); | ||||||||
535 | if (predicate != NULL__null) { // right pattern that can be used by loop predication | ||||||||
536 | return entry; | ||||||||
537 | } | ||||||||
538 | } | ||||||||
539 | if (UseProfiledLoopPredicate) { | ||||||||
540 | predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate); | ||||||||
541 | if (predicate != NULL__null) { // right pattern that can be used by loop predication | ||||||||
542 | return entry; | ||||||||
543 | } | ||||||||
544 | } | ||||||||
545 | return NULL__null; | ||||||||
546 | } | ||||||||
547 | |||||||||
548 | //------------------------------Invariance----------------------------------- | ||||||||
549 | // Helper class for loop_predication_impl to compute invariance on the fly and | ||||||||
550 | // clone invariants. | ||||||||
551 | class Invariance : public StackObj { | ||||||||
552 | VectorSet _visited, _invariant; | ||||||||
553 | Node_Stack _stack; | ||||||||
554 | VectorSet _clone_visited; | ||||||||
555 | Node_List _old_new; // map of old to new (clone) | ||||||||
556 | IdealLoopTree* _lpt; | ||||||||
557 | PhaseIdealLoop* _phase; | ||||||||
558 | Node* _data_dependency_on; // The projection into the loop on which data nodes are dependent or NULL otherwise | ||||||||
559 | |||||||||
560 | // Helper function to set up the invariance for invariance computation | ||||||||
561 | // If n is a known invariant, set up directly. Otherwise, look up the | ||||||||
562 | // the possibility to push n onto the stack for further processing. | ||||||||
563 | void visit(Node* use, Node* n) { | ||||||||
564 | if (_lpt->is_invariant(n)) { // known invariant | ||||||||
565 | _invariant.set(n->_idx); | ||||||||
566 | } else if (!n->is_CFG()) { | ||||||||
567 | Node *n_ctrl = _phase->ctrl_or_self(n); | ||||||||
568 | Node *u_ctrl = _phase->ctrl_or_self(use); // self if use is a CFG | ||||||||
569 | if (_phase->is_dominator(n_ctrl, u_ctrl)) { | ||||||||
570 | _stack.push(n, n->in(0) == NULL__null ? 1 : 0); | ||||||||
571 | } | ||||||||
572 | } | ||||||||
573 | } | ||||||||
574 | |||||||||
575 | // Compute invariance for "the_node" and (possibly) all its inputs recursively | ||||||||
576 | // on the fly | ||||||||
577 | void compute_invariance(Node* n) { | ||||||||
578 | assert(_visited.test(n->_idx), "must be")do { if (!(_visited.test(n->_idx))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 578, "assert(" "_visited.test(n->_idx)" ") failed", "must be" ); ::breakpoint(); } } while (0); | ||||||||
579 | visit(n, n); | ||||||||
580 | while (_stack.is_nonempty()) { | ||||||||
581 | Node* n = _stack.node(); | ||||||||
582 | uint idx = _stack.index(); | ||||||||
583 | if (idx == n->req()) { // all inputs are processed | ||||||||
584 | _stack.pop(); | ||||||||
585 | // n is invariant if it's inputs are all invariant | ||||||||
586 | bool all_inputs_invariant = true; | ||||||||
587 | for (uint i = 0; i < n->req(); i++) { | ||||||||
588 | Node* in = n->in(i); | ||||||||
589 | if (in == NULL__null) continue; | ||||||||
590 | assert(_visited.test(in->_idx), "must have visited input")do { if (!(_visited.test(in->_idx))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 590, "assert(" "_visited.test(in->_idx)" ") failed", "must have visited input" ); ::breakpoint(); } } while (0); | ||||||||
591 | if (!_invariant.test(in->_idx)) { // bad guy | ||||||||
592 | all_inputs_invariant = false; | ||||||||
593 | break; | ||||||||
594 | } | ||||||||
595 | } | ||||||||
596 | if (all_inputs_invariant) { | ||||||||
597 | // If n's control is a predicate that was moved out of the | ||||||||
598 | // loop, it was marked invariant but n is only invariant if | ||||||||
599 | // it depends only on that test. Otherwise, unless that test | ||||||||
600 | // is out of the loop, it's not invariant. | ||||||||
601 | if (n->is_CFG() || n->depends_only_on_test() || n->in(0) == NULL__null || !_phase->is_member(_lpt, n->in(0))) { | ||||||||
602 | _invariant.set(n->_idx); // I am a invariant too | ||||||||
603 | } | ||||||||
604 | } | ||||||||
605 | } else { // process next input | ||||||||
606 | _stack.set_index(idx + 1); | ||||||||
607 | Node* m = n->in(idx); | ||||||||
608 | if (m != NULL__null && !_visited.test_set(m->_idx)) { | ||||||||
609 | visit(n, m); | ||||||||
610 | } | ||||||||
611 | } | ||||||||
612 | } | ||||||||
613 | } | ||||||||
614 | |||||||||
615 | // Helper function to set up _old_new map for clone_nodes. | ||||||||
616 | // If n is a known invariant, set up directly ("clone" of n == n). | ||||||||
617 | // Otherwise, push n onto the stack for real cloning. | ||||||||
618 | void clone_visit(Node* n) { | ||||||||
619 | assert(_invariant.test(n->_idx), "must be invariant")do { if (!(_invariant.test(n->_idx))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 619, "assert(" "_invariant.test(n->_idx)" ") failed", "must be invariant" ); ::breakpoint(); } } while (0); | ||||||||
620 | if (_lpt->is_invariant(n)) { // known invariant | ||||||||
621 | _old_new.map(n->_idx, n); | ||||||||
622 | } else { // to be cloned | ||||||||
623 | assert(!n->is_CFG(), "should not see CFG here")do { if (!(!n->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 623, "assert(" "!n->is_CFG()" ") failed", "should not see CFG here" ); ::breakpoint(); } } while (0); | ||||||||
624 | _stack.push(n, n->in(0) == NULL__null ? 1 : 0); | ||||||||
625 | } | ||||||||
626 | } | ||||||||
627 | |||||||||
628 | // Clone "n" and (possibly) all its inputs recursively | ||||||||
629 | void clone_nodes(Node* n, Node* ctrl) { | ||||||||
630 | clone_visit(n); | ||||||||
631 | while (_stack.is_nonempty()) { | ||||||||
632 | Node* n = _stack.node(); | ||||||||
633 | uint idx = _stack.index(); | ||||||||
634 | if (idx == n->req()) { // all inputs processed, clone n! | ||||||||
635 | _stack.pop(); | ||||||||
636 | // clone invariant node | ||||||||
637 | Node* n_cl = n->clone(); | ||||||||
638 | _old_new.map(n->_idx, n_cl); | ||||||||
639 | _phase->register_new_node(n_cl, ctrl); | ||||||||
640 | for (uint i = 0; i < n->req(); i++) { | ||||||||
641 | Node* in = n_cl->in(i); | ||||||||
642 | if (in == NULL__null) continue; | ||||||||
643 | n_cl->set_req(i, _old_new[in->_idx]); | ||||||||
644 | } | ||||||||
645 | } else { // process next input | ||||||||
646 | _stack.set_index(idx + 1); | ||||||||
647 | Node* m = n->in(idx); | ||||||||
648 | if (m != NULL__null && !_clone_visited.test_set(m->_idx)) { | ||||||||
649 | clone_visit(m); // visit the input | ||||||||
650 | } | ||||||||
651 | } | ||||||||
652 | } | ||||||||
653 | } | ||||||||
654 | |||||||||
655 | public: | ||||||||
656 | Invariance(Arena* area, IdealLoopTree* lpt) : | ||||||||
657 | _visited(area), _invariant(area), | ||||||||
658 | _stack(area, 10 /* guess */), | ||||||||
659 | _clone_visited(area), _old_new(area), | ||||||||
660 | _lpt(lpt), _phase(lpt->_phase), | ||||||||
661 | _data_dependency_on(NULL__null) | ||||||||
662 | { | ||||||||
663 | LoopNode* head = _lpt->_head->as_Loop(); | ||||||||
664 | Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl); | ||||||||
665 | if (entry->outcnt() != 1) { | ||||||||
666 | // If a node is pinned between the predicates and the loop | ||||||||
667 | // entry, we won't be able to move any node in the loop that | ||||||||
668 | // depends on it above it in a predicate. Mark all those nodes | ||||||||
669 | // as non-loop-invariant. | ||||||||
670 | // Loop predication could create new nodes for which the below | ||||||||
671 | // invariant information is missing. Mark the 'entry' node to | ||||||||
672 | // later check again if a node needs to be treated as non-loop- | ||||||||
673 | // invariant as well. | ||||||||
674 | _data_dependency_on = entry; | ||||||||
675 | Unique_Node_List wq; | ||||||||
676 | wq.push(entry); | ||||||||
677 | for (uint next = 0; next < wq.size(); ++next) { | ||||||||
678 | Node *n = wq.at(next); | ||||||||
679 | for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { | ||||||||
680 | Node* u = n->fast_out(i); | ||||||||
681 | if (!u->is_CFG()) { | ||||||||
682 | Node* c = _phase->get_ctrl(u); | ||||||||
683 | if (_lpt->is_member(_phase->get_loop(c)) || _phase->is_dominator(c, head)) { | ||||||||
684 | _visited.set(u->_idx); | ||||||||
685 | wq.push(u); | ||||||||
686 | } | ||||||||
687 | } | ||||||||
688 | } | ||||||||
689 | } | ||||||||
690 | } | ||||||||
691 | } | ||||||||
692 | |||||||||
693 | // Did we explicitly mark some nodes non-loop-invariant? If so, return the entry node on which some data nodes | ||||||||
694 | // are dependent that prevent loop predication. Otherwise, return NULL. | ||||||||
695 | Node* data_dependency_on() { | ||||||||
696 | return _data_dependency_on; | ||||||||
697 | } | ||||||||
698 | |||||||||
699 | // Map old to n for invariance computation and clone | ||||||||
700 | void map_ctrl(Node* old, Node* n) { | ||||||||
701 | assert(old->is_CFG() && n->is_CFG(), "must be")do { if (!(old->is_CFG() && n->is_CFG())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 701, "assert(" "old->is_CFG() && n->is_CFG()" ") failed", "must be"); ::breakpoint(); } } while (0); | ||||||||
702 | _old_new.map(old->_idx, n); // "clone" of old is n | ||||||||
703 | _invariant.set(old->_idx); // old is invariant | ||||||||
704 | _clone_visited.set(old->_idx); | ||||||||
705 | } | ||||||||
706 | |||||||||
707 | // Driver function to compute invariance | ||||||||
708 | bool is_invariant(Node* n) { | ||||||||
709 | if (!_visited.test_set(n->_idx)) | ||||||||
710 | compute_invariance(n); | ||||||||
711 | return (_invariant.test(n->_idx) != 0); | ||||||||
712 | } | ||||||||
713 | |||||||||
714 | // Driver function to clone invariant | ||||||||
715 | Node* clone(Node* n, Node* ctrl) { | ||||||||
716 | assert(ctrl->is_CFG(), "must be")do { if (!(ctrl->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 716, "assert(" "ctrl->is_CFG()" ") failed", "must be"); :: breakpoint(); } } while (0); | ||||||||
717 | assert(_invariant.test(n->_idx), "must be an invariant")do { if (!(_invariant.test(n->_idx))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 717, "assert(" "_invariant.test(n->_idx)" ") failed", "must be an invariant" ); ::breakpoint(); } } while (0); | ||||||||
718 | if (!_clone_visited.test(n->_idx)) | ||||||||
719 | clone_nodes(n, ctrl); | ||||||||
720 | return _old_new[n->_idx]; | ||||||||
721 | } | ||||||||
722 | }; | ||||||||
723 | |||||||||
724 | //------------------------------is_range_check_if ----------------------------------- | ||||||||
725 | // Returns true if the predicate of iff is in "scale*iv + offset u< load_range(ptr)" format | ||||||||
726 | // Note: this function is particularly designed for loop predication. We require load_range | ||||||||
727 | // and offset to be loop invariant computed on the fly by "invar" | ||||||||
728 | bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, BasicType bt, Node *iv, Node *&range, | ||||||||
729 | Node *&offset, jlong &scale) const { | ||||||||
730 | if (!is_loop_exit(iff)) { | ||||||||
731 | return false; | ||||||||
732 | } | ||||||||
733 | if (!iff->in(1)->is_Bool()) { | ||||||||
734 | return false; | ||||||||
735 | } | ||||||||
736 | const BoolNode *bol = iff->in(1)->as_Bool(); | ||||||||
737 | if (bol->_test._test != BoolTest::lt) { | ||||||||
738 | return false; | ||||||||
739 | } | ||||||||
740 | if (!bol->in(1)->is_Cmp()) { | ||||||||
741 | return false; | ||||||||
742 | } | ||||||||
743 | const CmpNode *cmp = bol->in(1)->as_Cmp(); | ||||||||
744 | if (cmp->Opcode() != Op_Cmp_unsigned(bt)) { | ||||||||
745 | return false; | ||||||||
746 | } | ||||||||
747 | range = cmp->in(2); | ||||||||
748 | if (range->Opcode() != Op_LoadRange) { | ||||||||
749 | const TypeInteger* tinteger = phase->_igvn.type(range)->isa_integer(bt); | ||||||||
750 | if (tinteger == NULL__null || tinteger->empty() || tinteger->lo_as_long() < 0) { | ||||||||
751 | // Allow predication on positive values that aren't LoadRanges. | ||||||||
752 | // This allows optimization of loops where the length of the | ||||||||
753 | // array is a known value and doesn't need to be loaded back | ||||||||
754 | // from the array. | ||||||||
755 | return false; | ||||||||
756 | } | ||||||||
757 | } else { | ||||||||
758 | assert(bt == T_INT, "no LoadRange for longs")do { if (!(bt == T_INT)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 758, "assert(" "bt == T_INT" ") failed", "no LoadRange for longs" ); ::breakpoint(); } } while (0); | ||||||||
759 | } | ||||||||
760 | scale = 0; | ||||||||
761 | offset = NULL__null; | ||||||||
762 | if (!phase->is_scaled_iv_plus_offset(cmp->in(1), iv, &scale, &offset, bt)) { | ||||||||
763 | return false; | ||||||||
764 | } | ||||||||
765 | return true; | ||||||||
766 | } | ||||||||
767 | |||||||||
768 | bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar DEBUG_ONLY(COMMA ProjNode *predicate_proj), ProjNode *predicate_proj) const { | ||||||||
769 | Node* range = NULL__null; | ||||||||
770 | Node* offset = NULL__null; | ||||||||
771 | jlong scale = 0; | ||||||||
772 | Node* iv = _head->as_BaseCountedLoop()->phi(); | ||||||||
773 | Compile* C = Compile::current(); | ||||||||
774 | const uint old_unique_idx = C->unique(); | ||||||||
775 | if (!is_range_check_if(iff, phase, T_INT, iv, range, offset, scale)) { | ||||||||
776 | return false; | ||||||||
777 | } | ||||||||
778 | if (!invar.is_invariant(range)) { | ||||||||
779 | return false; | ||||||||
780 | } | ||||||||
781 | if (offset != NULL__null) { | ||||||||
782 | if (!invar.is_invariant(offset)) { // offset must be invariant | ||||||||
783 | return false; | ||||||||
784 | } | ||||||||
785 | Node* data_dependency_on = invar.data_dependency_on(); | ||||||||
786 | if (data_dependency_on != NULL__null && old_unique_idx < C->unique()) { | ||||||||
787 | // 'offset' node was newly created in is_range_check_if(). Check that it does not depend on the entry projection | ||||||||
788 | // into the loop. If it does, we cannot perform loop predication (see Invariant::Invariant()). | ||||||||
789 | assert(!offset->is_CFG(), "offset must be a data node")do { if (!(!offset->is_CFG())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 789, "assert(" "!offset->is_CFG()" ") failed", "offset must be a data node" ); ::breakpoint(); } } while (0); | ||||||||
790 | if (_phase->get_ctrl(offset) == data_dependency_on) { | ||||||||
791 | return false; | ||||||||
792 | } | ||||||||
793 | } | ||||||||
794 | } | ||||||||
795 | #ifdef ASSERT1 | ||||||||
796 | if (offset && phase->has_ctrl(offset)) { | ||||||||
797 | Node* offset_ctrl = phase->get_ctrl(offset); | ||||||||
798 | if (phase->get_loop(predicate_proj) == phase->get_loop(offset_ctrl) && | ||||||||
799 | phase->is_dominator(predicate_proj, offset_ctrl)) { | ||||||||
800 | // If the control of offset is loop predication promoted by previous pass, | ||||||||
801 | // then it will lead to cyclic dependency. | ||||||||
802 | // Previously promoted loop predication is in the same loop of predication | ||||||||
803 | // point. | ||||||||
804 | // This situation can occur when pinning nodes too conservatively - can we do better? | ||||||||
805 | assert(false, "cyclic dependency prevents range check elimination, idx: offset %d, offset_ctrl %d, predicate_proj %d",do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 806, "assert(" "false" ") failed", "cyclic dependency prevents range check elimination, idx: offset %d, offset_ctrl %d, predicate_proj %d" , offset->_idx, offset_ctrl->_idx, predicate_proj->_idx ); ::breakpoint(); } } while (0) | ||||||||
806 | offset->_idx, offset_ctrl->_idx, predicate_proj->_idx)do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 806, "assert(" "false" ") failed", "cyclic dependency prevents range check elimination, idx: offset %d, offset_ctrl %d, predicate_proj %d" , offset->_idx, offset_ctrl->_idx, predicate_proj->_idx ); ::breakpoint(); } } while (0); | ||||||||
807 | } | ||||||||
808 | } | ||||||||
809 | #endif | ||||||||
810 | return true; | ||||||||
811 | } | ||||||||
812 | |||||||||
813 | //------------------------------rc_predicate----------------------------------- | ||||||||
814 | // Create a range check predicate | ||||||||
815 | // | ||||||||
816 | // for (i = init; i < limit; i += stride) { | ||||||||
817 | // a[scale*i+offset] | ||||||||
818 | // } | ||||||||
819 | // | ||||||||
820 | // Compute max(scale*i + offset) for init <= i < limit and build the predicate | ||||||||
821 | // as "max(scale*i + offset) u< a.length". | ||||||||
822 | // | ||||||||
823 | // There are two cases for max(scale*i + offset): | ||||||||
824 | // (1) stride*scale > 0 | ||||||||
825 | // max(scale*i + offset) = scale*(limit-stride) + offset | ||||||||
826 | // (2) stride*scale < 0 | ||||||||
827 | // max(scale*i + offset) = scale*init + offset | ||||||||
828 | BoolNode* PhaseIdealLoop::rc_predicate(IdealLoopTree *loop, Node* ctrl, | ||||||||
829 | int scale, Node* offset, | ||||||||
830 | Node* init, Node* limit, jint stride, | ||||||||
831 | Node* range, bool upper, bool &overflow, bool negate) { | ||||||||
832 | jint con_limit = (limit != NULL__null && limit->is_Con()) ? limit->get_int() : 0; | ||||||||
833 | jint con_init = init->is_Con() ? init->get_int() : 0; | ||||||||
834 | jint con_offset = offset->is_Con() ? offset->get_int() : 0; | ||||||||
835 | |||||||||
836 | stringStream* predString = NULL__null; | ||||||||
837 | if (TraceLoopPredicate) { | ||||||||
838 | predString = new stringStream(); | ||||||||
839 | predString->print("rc_predicate "); | ||||||||
840 | } | ||||||||
841 | |||||||||
842 | overflow = false; | ||||||||
843 | Node* max_idx_expr = NULL__null; | ||||||||
844 | const TypeInt* idx_type = TypeInt::INT; | ||||||||
845 | if ((stride
| ||||||||
846 | guarantee(limit != NULL, "sanity")do { if (!(limit != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 846, "guarantee(" "limit != NULL" ") failed", "sanity"); :: breakpoint(); } } while (0); | ||||||||
847 | if (TraceLoopPredicate) { | ||||||||
848 | if (limit->is_Con()) { | ||||||||
849 | predString->print("(%d ", con_limit); | ||||||||
850 | } else { | ||||||||
851 | predString->print("(limit "); | ||||||||
852 | } | ||||||||
853 | predString->print("- %d) ", stride); | ||||||||
854 | } | ||||||||
855 | // Check if (limit - stride) may overflow | ||||||||
856 | const TypeInt* limit_type = _igvn.type(limit)->isa_int(); | ||||||||
857 | jint limit_lo = limit_type->_lo; | ||||||||
858 | jint limit_hi = limit_type->_hi; | ||||||||
859 | if ((stride > 0 && (java_subtract(limit_lo, stride) < limit_lo)) || | ||||||||
860 | (stride < 0 && (java_subtract(limit_hi, stride) > limit_hi))) { | ||||||||
861 | // No overflow possible | ||||||||
862 | ConINode* con_stride = _igvn.intcon(stride); | ||||||||
863 | set_ctrl(con_stride, C->root()); | ||||||||
864 | max_idx_expr = new SubINode(limit, con_stride); | ||||||||
865 | idx_type = TypeInt::make(limit_lo - stride, limit_hi - stride, limit_type->_widen); | ||||||||
866 | } else { | ||||||||
867 | // May overflow | ||||||||
868 | overflow = true; | ||||||||
869 | limit = new ConvI2LNode(limit); | ||||||||
870 | register_new_node(limit, ctrl); | ||||||||
871 | ConLNode* con_stride = _igvn.longcon(stride); | ||||||||
872 | set_ctrl(con_stride, C->root()); | ||||||||
873 | max_idx_expr = new SubLNode(limit, con_stride); | ||||||||
874 | } | ||||||||
875 | register_new_node(max_idx_expr, ctrl); | ||||||||
876 | } else { | ||||||||
877 | if (TraceLoopPredicate
| ||||||||
878 | if (init->is_Con()) { | ||||||||
879 | predString->print("%d ", con_init); | ||||||||
880 | } else { | ||||||||
881 | predString->print("init "); | ||||||||
882 | } | ||||||||
883 | } | ||||||||
884 | idx_type = _igvn.type(init)->isa_int(); | ||||||||
885 | max_idx_expr = init; | ||||||||
886 | } | ||||||||
887 | |||||||||
888 | if (scale
| ||||||||
889 | ConNode* con_scale = _igvn.intcon(scale); | ||||||||
890 | set_ctrl(con_scale, C->root()); | ||||||||
891 | if (TraceLoopPredicate) { | ||||||||
892 | predString->print("* %d ", scale); | ||||||||
| |||||||||
893 | } | ||||||||
894 | // Check if (scale * max_idx_expr) may overflow | ||||||||
895 | const TypeInt* scale_type = TypeInt::make(scale); | ||||||||
896 | MulINode* mul = new MulINode(max_idx_expr, con_scale); | ||||||||
897 | idx_type = (TypeInt*)mul->mul_ring(idx_type, scale_type); | ||||||||
898 | if (overflow || TypeInt::INT->higher_equal(idx_type)) { | ||||||||
899 | // May overflow | ||||||||
900 | mul->destruct(&_igvn); | ||||||||
901 | if (!overflow) { | ||||||||
902 | max_idx_expr = new ConvI2LNode(max_idx_expr); | ||||||||
903 | register_new_node(max_idx_expr, ctrl); | ||||||||
904 | } | ||||||||
905 | overflow = true; | ||||||||
906 | con_scale = _igvn.longcon(scale); | ||||||||
907 | set_ctrl(con_scale, C->root()); | ||||||||
908 | max_idx_expr = new MulLNode(max_idx_expr, con_scale); | ||||||||
909 | } else { | ||||||||
910 | // No overflow possible | ||||||||
911 | max_idx_expr = mul; | ||||||||
912 | } | ||||||||
913 | register_new_node(max_idx_expr, ctrl); | ||||||||
914 | } | ||||||||
915 | |||||||||
916 | if (offset && (!offset->is_Con() || con_offset != 0)){ | ||||||||
917 | if (TraceLoopPredicate) { | ||||||||
918 | if (offset->is_Con()) { | ||||||||
919 | predString->print("+ %d ", con_offset); | ||||||||
920 | } else { | ||||||||
921 | predString->print("+ offset"); | ||||||||
922 | } | ||||||||
923 | } | ||||||||
924 | // Check if (max_idx_expr + offset) may overflow | ||||||||
925 | const TypeInt* offset_type = _igvn.type(offset)->isa_int(); | ||||||||
926 | jint lo = java_add(idx_type->_lo, offset_type->_lo); | ||||||||
927 | jint hi = java_add(idx_type->_hi, offset_type->_hi); | ||||||||
928 | if (overflow || (lo > hi) || | ||||||||
929 | ((idx_type->_lo & offset_type->_lo) < 0 && lo >= 0) || | ||||||||
930 | ((~(idx_type->_hi | offset_type->_hi)) < 0 && hi < 0)) { | ||||||||
931 | // May overflow | ||||||||
932 | if (!overflow) { | ||||||||
933 | max_idx_expr = new ConvI2LNode(max_idx_expr); | ||||||||
934 | register_new_node(max_idx_expr, ctrl); | ||||||||
935 | } | ||||||||
936 | overflow = true; | ||||||||
937 | offset = new ConvI2LNode(offset); | ||||||||
938 | register_new_node(offset, ctrl); | ||||||||
939 | max_idx_expr = new AddLNode(max_idx_expr, offset); | ||||||||
940 | } else { | ||||||||
941 | // No overflow possible | ||||||||
942 | max_idx_expr = new AddINode(max_idx_expr, offset); | ||||||||
943 | } | ||||||||
944 | register_new_node(max_idx_expr, ctrl); | ||||||||
945 | } | ||||||||
946 | |||||||||
947 | CmpNode* cmp = NULL__null; | ||||||||
948 | if (overflow) { | ||||||||
949 | // Integer expressions may overflow, do long comparison | ||||||||
950 | range = new ConvI2LNode(range); | ||||||||
951 | register_new_node(range, ctrl); | ||||||||
952 | cmp = new CmpULNode(max_idx_expr, range); | ||||||||
953 | } else { | ||||||||
954 | cmp = new CmpUNode(max_idx_expr, range); | ||||||||
955 | } | ||||||||
956 | register_new_node(cmp, ctrl); | ||||||||
957 | BoolNode* bol = new BoolNode(cmp, negate ? BoolTest::ge : BoolTest::lt); | ||||||||
958 | register_new_node(bol, ctrl); | ||||||||
959 | |||||||||
960 | if (TraceLoopPredicate) { | ||||||||
961 | predString->print_cr("<u range"); | ||||||||
962 | tty->print("%s", predString->base()); | ||||||||
963 | predString->~stringStream(); | ||||||||
964 | } | ||||||||
965 | return bol; | ||||||||
966 | } | ||||||||
967 | |||||||||
968 | // Should loop predication look not only in the path from tail to head | ||||||||
969 | // but also in branches of the loop body? | ||||||||
970 | bool PhaseIdealLoop::loop_predication_should_follow_branches(IdealLoopTree *loop, ProjNode *predicate_proj, float& loop_trip_cnt) { | ||||||||
971 | if (!UseProfiledLoopPredicate) { | ||||||||
972 | return false; | ||||||||
973 | } | ||||||||
974 | |||||||||
975 | if (predicate_proj == NULL__null) { | ||||||||
976 | return false; | ||||||||
977 | } | ||||||||
978 | |||||||||
979 | LoopNode* head = loop->_head->as_Loop(); | ||||||||
980 | bool follow_branches = true; | ||||||||
981 | IdealLoopTree* l = loop->_child; | ||||||||
982 | // For leaf loops and loops with a single inner loop | ||||||||
983 | while (l != NULL__null && follow_branches) { | ||||||||
984 | IdealLoopTree* child = l; | ||||||||
985 | if (child->_child != NULL__null && | ||||||||
986 | child->_head->is_OuterStripMinedLoop()) { | ||||||||
987 | assert(child->_child->_next == NULL, "only one inner loop for strip mined loop")do { if (!(child->_child->_next == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 987, "assert(" "child->_child->_next == __null" ") failed" , "only one inner loop for strip mined loop"); ::breakpoint() ; } } while (0); | ||||||||
988 | assert(child->_child->_head->is_CountedLoop() && child->_child->_head->as_CountedLoop()->is_strip_mined(), "inner loop should be strip mined")do { if (!(child->_child->_head->is_CountedLoop() && child->_child->_head->as_CountedLoop()->is_strip_mined ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 988, "assert(" "child->_child->_head->is_CountedLoop() && child->_child->_head->as_CountedLoop()->is_strip_mined()" ") failed", "inner loop should be strip mined"); ::breakpoint (); } } while (0); | ||||||||
989 | child = child->_child; | ||||||||
990 | } | ||||||||
991 | if (child->_child != NULL__null || child->_irreducible) { | ||||||||
992 | follow_branches = false; | ||||||||
993 | } | ||||||||
994 | l = l->_next; | ||||||||
995 | } | ||||||||
996 | if (follow_branches) { | ||||||||
997 | loop->compute_profile_trip_cnt(this); | ||||||||
998 | if (head->is_profile_trip_failed()) { | ||||||||
999 | follow_branches = false; | ||||||||
1000 | } else { | ||||||||
1001 | loop_trip_cnt = head->profile_trip_cnt(); | ||||||||
1002 | if (head->is_CountedLoop()) { | ||||||||
1003 | CountedLoopNode* cl = head->as_CountedLoop(); | ||||||||
1004 | if (cl->phi() != NULL__null) { | ||||||||
1005 | const TypeInt* t = _igvn.type(cl->phi())->is_int(); | ||||||||
1006 | float worst_case_trip_cnt = ((float)t->_hi - t->_lo) / ABS(cl->stride_con()); | ||||||||
1007 | if (worst_case_trip_cnt < loop_trip_cnt) { | ||||||||
1008 | loop_trip_cnt = worst_case_trip_cnt; | ||||||||
1009 | } | ||||||||
1010 | } | ||||||||
1011 | } | ||||||||
1012 | } | ||||||||
1013 | } | ||||||||
1014 | return follow_branches; | ||||||||
1015 | } | ||||||||
1016 | |||||||||
1017 | // Compute probability of reaching some CFG node from a fixed | ||||||||
1018 | // dominating CFG node | ||||||||
1019 | class PathFrequency { | ||||||||
1020 | private: | ||||||||
1021 | Node* _dom; // frequencies are computed relative to this node | ||||||||
1022 | Node_Stack _stack; | ||||||||
1023 | GrowableArray<float> _freqs_stack; // keep track of intermediate result at regions | ||||||||
1024 | GrowableArray<float> _freqs; // cache frequencies | ||||||||
1025 | PhaseIdealLoop* _phase; | ||||||||
1026 | |||||||||
1027 | void set_rounding(int mode) { | ||||||||
1028 | // fesetround is broken on windows | ||||||||
1029 | NOT_WINDOWS(fesetround(mode);)fesetround(mode); | ||||||||
1030 | } | ||||||||
1031 | |||||||||
1032 | void check_frequency(float f) { | ||||||||
1033 | NOT_WINDOWS(assert(f <= 1 && f >= 0, "Incorrect frequency");)do { if (!(f <= 1 && f >= 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1033, "assert(" "f <= 1 && f >= 0" ") failed" , "Incorrect frequency"); ::breakpoint(); } } while (0); | ||||||||
1034 | } | ||||||||
1035 | |||||||||
1036 | public: | ||||||||
1037 | PathFrequency(Node* dom, PhaseIdealLoop* phase) | ||||||||
1038 | : _dom(dom), _stack(0), _phase(phase) { | ||||||||
1039 | } | ||||||||
1040 | |||||||||
1041 | float to(Node* n) { | ||||||||
1042 | // post order walk on the CFG graph from n to _dom | ||||||||
1043 | set_rounding(FE_TOWARDZERO0xc00); // make sure rounding doesn't push frequency above 1 | ||||||||
1044 | IdealLoopTree* loop = _phase->get_loop(_dom); | ||||||||
1045 | Node* c = n; | ||||||||
1046 | for (;;) { | ||||||||
1047 | assert(_phase->get_loop(c) == loop, "have to be in the same loop")do { if (!(_phase->get_loop(c) == loop)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1047, "assert(" "_phase->get_loop(c) == loop" ") failed" , "have to be in the same loop"); ::breakpoint(); } } while ( 0); | ||||||||
1048 | if (c == _dom || _freqs.at_grow(c->_idx, -1) >= 0) { | ||||||||
1049 | float f = c == _dom ? 1 : _freqs.at(c->_idx); | ||||||||
1050 | Node* prev = c; | ||||||||
1051 | while (_stack.size() > 0 && prev == c) { | ||||||||
1052 | Node* n = _stack.node(); | ||||||||
1053 | if (!n->is_Region()) { | ||||||||
1054 | if (_phase->get_loop(n) != _phase->get_loop(n->in(0))) { | ||||||||
1055 | // Found an inner loop: compute frequency of reaching this | ||||||||
1056 | // exit from the loop head by looking at the number of | ||||||||
1057 | // times each loop exit was taken | ||||||||
1058 | IdealLoopTree* inner_loop = _phase->get_loop(n->in(0)); | ||||||||
1059 | LoopNode* inner_head = inner_loop->_head->as_Loop(); | ||||||||
1060 | assert(_phase->get_loop(n) == loop, "only 1 inner loop")do { if (!(_phase->get_loop(n) == loop)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1060, "assert(" "_phase->get_loop(n) == loop" ") failed" , "only 1 inner loop"); ::breakpoint(); } } while (0); | ||||||||
1061 | if (inner_head->is_OuterStripMinedLoop()) { | ||||||||
1062 | inner_head->verify_strip_mined(1); | ||||||||
1063 | if (n->in(0) == inner_head->in(LoopNode::LoopBackControl)->in(0)) { | ||||||||
1064 | n = n->in(0)->in(0)->in(0); | ||||||||
1065 | } | ||||||||
1066 | inner_loop = inner_loop->_child; | ||||||||
1067 | inner_head = inner_loop->_head->as_Loop(); | ||||||||
1068 | inner_head->verify_strip_mined(1); | ||||||||
1069 | } | ||||||||
1070 | set_rounding(FE_UPWARD0x800); // make sure rounding doesn't push frequency above 1 | ||||||||
1071 | float loop_exit_cnt = 0.0f; | ||||||||
1072 | for (uint i = 0; i < inner_loop->_body.size(); i++) { | ||||||||
1073 | Node *n = inner_loop->_body[i]; | ||||||||
1074 | float c = inner_loop->compute_profile_trip_cnt_helper(n); | ||||||||
1075 | loop_exit_cnt += c; | ||||||||
1076 | } | ||||||||
1077 | set_rounding(FE_TOWARDZERO0xc00); | ||||||||
1078 | float cnt = -1; | ||||||||
1079 | if (n->in(0)->is_If()) { | ||||||||
1080 | IfNode* iff = n->in(0)->as_If(); | ||||||||
1081 | float p = n->in(0)->as_If()->_prob; | ||||||||
1082 | if (n->Opcode() == Op_IfFalse) { | ||||||||
1083 | p = 1 - p; | ||||||||
1084 | } | ||||||||
1085 | if (p > PROB_MIN(1e-6f)) { | ||||||||
1086 | cnt = p * iff->_fcnt; | ||||||||
1087 | } else { | ||||||||
1088 | cnt = 0; | ||||||||
1089 | } | ||||||||
1090 | } else { | ||||||||
1091 | assert(n->in(0)->is_Jump(), "unsupported node kind")do { if (!(n->in(0)->is_Jump())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1091, "assert(" "n->in(0)->is_Jump()" ") failed", "unsupported node kind" ); ::breakpoint(); } } while (0); | ||||||||
1092 | JumpNode* jmp = n->in(0)->as_Jump(); | ||||||||
1093 | float p = n->in(0)->as_Jump()->_probs[n->as_JumpProj()->_con]; | ||||||||
1094 | cnt = p * jmp->_fcnt; | ||||||||
1095 | } | ||||||||
1096 | float this_exit_f = cnt > 0 ? cnt / loop_exit_cnt : 0; | ||||||||
1097 | check_frequency(this_exit_f); | ||||||||
1098 | f = f * this_exit_f; | ||||||||
1099 | check_frequency(f); | ||||||||
1100 | } else { | ||||||||
1101 | float p = -1; | ||||||||
1102 | if (n->in(0)->is_If()) { | ||||||||
1103 | p = n->in(0)->as_If()->_prob; | ||||||||
1104 | if (n->Opcode() == Op_IfFalse) { | ||||||||
1105 | p = 1 - p; | ||||||||
1106 | } | ||||||||
1107 | } else { | ||||||||
1108 | assert(n->in(0)->is_Jump(), "unsupported node kind")do { if (!(n->in(0)->is_Jump())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1108, "assert(" "n->in(0)->is_Jump()" ") failed", "unsupported node kind" ); ::breakpoint(); } } while (0); | ||||||||
1109 | p = n->in(0)->as_Jump()->_probs[n->as_JumpProj()->_con]; | ||||||||
1110 | } | ||||||||
1111 | f = f * p; | ||||||||
1112 | check_frequency(f); | ||||||||
1113 | } | ||||||||
1114 | _freqs.at_put_grow(n->_idx, (float)f, -1); | ||||||||
1115 | _stack.pop(); | ||||||||
1116 | } else { | ||||||||
1117 | float prev_f = _freqs_stack.pop(); | ||||||||
1118 | float new_f = f; | ||||||||
1119 | f = new_f + prev_f; | ||||||||
1120 | check_frequency(f); | ||||||||
1121 | uint i = _stack.index(); | ||||||||
1122 | if (i < n->req()) { | ||||||||
1123 | c = n->in(i); | ||||||||
1124 | _stack.set_index(i+1); | ||||||||
1125 | _freqs_stack.push(f); | ||||||||
1126 | } else { | ||||||||
1127 | _freqs.at_put_grow(n->_idx, f, -1); | ||||||||
1128 | _stack.pop(); | ||||||||
1129 | } | ||||||||
1130 | } | ||||||||
1131 | } | ||||||||
1132 | if (_stack.size() == 0) { | ||||||||
1133 | set_rounding(FE_TONEAREST0); | ||||||||
1134 | check_frequency(f); | ||||||||
1135 | return f; | ||||||||
1136 | } | ||||||||
1137 | } else if (c->is_Loop()) { | ||||||||
1138 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1138); ::breakpoint(); } while (0); | ||||||||
1139 | c = c->in(LoopNode::EntryControl); | ||||||||
1140 | } else if (c->is_Region()) { | ||||||||
1141 | _freqs_stack.push(0); | ||||||||
1142 | _stack.push(c, 2); | ||||||||
1143 | c = c->in(1); | ||||||||
1144 | } else { | ||||||||
1145 | if (c->is_IfProj()) { | ||||||||
1146 | IfNode* iff = c->in(0)->as_If(); | ||||||||
1147 | if (iff->_prob == PROB_UNKNOWN(-1.0f)) { | ||||||||
1148 | // assume never taken | ||||||||
1149 | _freqs.at_put_grow(c->_idx, 0, -1); | ||||||||
1150 | } else if (_phase->get_loop(c) != _phase->get_loop(iff)) { | ||||||||
1151 | if (iff->_fcnt == COUNT_UNKNOWN(-1.0f)) { | ||||||||
1152 | // assume never taken | ||||||||
1153 | _freqs.at_put_grow(c->_idx, 0, -1); | ||||||||
1154 | } else { | ||||||||
1155 | // skip over loop | ||||||||
1156 | _stack.push(c, 1); | ||||||||
1157 | c = _phase->get_loop(c->in(0))->_head->as_Loop()->skip_strip_mined()->in(LoopNode::EntryControl); | ||||||||
1158 | } | ||||||||
1159 | } else { | ||||||||
1160 | _stack.push(c, 1); | ||||||||
1161 | c = iff; | ||||||||
1162 | } | ||||||||
1163 | } else if (c->is_JumpProj()) { | ||||||||
1164 | JumpNode* jmp = c->in(0)->as_Jump(); | ||||||||
1165 | if (_phase->get_loop(c) != _phase->get_loop(jmp)) { | ||||||||
1166 | if (jmp->_fcnt == COUNT_UNKNOWN(-1.0f)) { | ||||||||
1167 | // assume never taken | ||||||||
1168 | _freqs.at_put_grow(c->_idx, 0, -1); | ||||||||
1169 | } else { | ||||||||
1170 | // skip over loop | ||||||||
1171 | _stack.push(c, 1); | ||||||||
1172 | c = _phase->get_loop(c->in(0))->_head->as_Loop()->skip_strip_mined()->in(LoopNode::EntryControl); | ||||||||
1173 | } | ||||||||
1174 | } else { | ||||||||
1175 | _stack.push(c, 1); | ||||||||
1176 | c = jmp; | ||||||||
1177 | } | ||||||||
1178 | } else if (c->Opcode() == Op_CatchProj && | ||||||||
1179 | c->in(0)->Opcode() == Op_Catch && | ||||||||
1180 | c->in(0)->in(0)->is_Proj() && | ||||||||
1181 | c->in(0)->in(0)->in(0)->is_Call()) { | ||||||||
1182 | // assume exceptions are never thrown | ||||||||
1183 | uint con = c->as_Proj()->_con; | ||||||||
1184 | if (con == CatchProjNode::fall_through_index) { | ||||||||
1185 | Node* call = c->in(0)->in(0)->in(0)->in(0); | ||||||||
1186 | if (_phase->get_loop(call) != _phase->get_loop(c)) { | ||||||||
1187 | _freqs.at_put_grow(c->_idx, 0, -1); | ||||||||
1188 | } else { | ||||||||
1189 | c = call; | ||||||||
1190 | } | ||||||||
1191 | } else { | ||||||||
1192 | assert(con >= CatchProjNode::catch_all_index, "what else?")do { if (!(con >= CatchProjNode::catch_all_index)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1192, "assert(" "con >= CatchProjNode::catch_all_index" ") failed" , "what else?"); ::breakpoint(); } } while (0); | ||||||||
1193 | _freqs.at_put_grow(c->_idx, 0, -1); | ||||||||
1194 | } | ||||||||
1195 | } else if (c->unique_ctrl_out() == NULL__null && !c->is_If() && !c->is_Jump()) { | ||||||||
1196 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1196); ::breakpoint(); } while (0); | ||||||||
1197 | } else { | ||||||||
1198 | c = c->in(0); | ||||||||
1199 | } | ||||||||
1200 | } | ||||||||
1201 | } | ||||||||
1202 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1202); ::breakpoint(); } while (0); | ||||||||
1203 | return -1; | ||||||||
1204 | } | ||||||||
1205 | }; | ||||||||
1206 | |||||||||
1207 | void PhaseIdealLoop::loop_predication_follow_branches(Node *n, IdealLoopTree *loop, float loop_trip_cnt, | ||||||||
1208 | PathFrequency& pf, Node_Stack& stack, VectorSet& seen, | ||||||||
1209 | Node_List& if_proj_list) { | ||||||||
1210 | assert(n->is_Region(), "start from a region")do { if (!(n->is_Region())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1210, "assert(" "n->is_Region()" ") failed", "start from a region" ); ::breakpoint(); } } while (0); | ||||||||
1211 | Node* tail = loop->tail(); | ||||||||
1212 | stack.push(n, 1); | ||||||||
1213 | do { | ||||||||
1214 | Node* c = stack.node(); | ||||||||
1215 | assert(c->is_Region() || c->is_IfProj(), "only region here")do { if (!(c->is_Region() || c->is_IfProj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1215, "assert(" "c->is_Region() || c->is_IfProj()" ") failed" , "only region here"); ::breakpoint(); } } while (0); | ||||||||
1216 | uint i = stack.index(); | ||||||||
1217 | |||||||||
1218 | if (i < c->req()) { | ||||||||
1219 | stack.set_index(i+1); | ||||||||
1220 | Node* in = c->in(i); | ||||||||
1221 | while (!is_dominator(in, tail) && !seen.test_set(in->_idx)) { | ||||||||
1222 | IdealLoopTree* in_loop = get_loop(in); | ||||||||
1223 | if (in_loop != loop) { | ||||||||
1224 | in = in_loop->_head->in(LoopNode::EntryControl); | ||||||||
1225 | } else if (in->is_Region()) { | ||||||||
1226 | stack.push(in, 1); | ||||||||
1227 | break; | ||||||||
1228 | } else if (in->is_IfProj() && | ||||||||
1229 | in->as_Proj()->is_uncommon_trap_if_pattern(Deoptimization::Reason_none) && | ||||||||
1230 | (in->in(0)->Opcode() == Op_If || | ||||||||
1231 | in->in(0)->Opcode() == Op_RangeCheck)) { | ||||||||
1232 | if (pf.to(in) * loop_trip_cnt >= 1) { | ||||||||
1233 | stack.push(in, 1); | ||||||||
1234 | } | ||||||||
1235 | in = in->in(0); | ||||||||
1236 | } else { | ||||||||
1237 | in = in->in(0); | ||||||||
1238 | } | ||||||||
1239 | } | ||||||||
1240 | } else { | ||||||||
1241 | if (c->is_IfProj()) { | ||||||||
1242 | if_proj_list.push(c); | ||||||||
1243 | } | ||||||||
1244 | stack.pop(); | ||||||||
1245 | } | ||||||||
1246 | |||||||||
1247 | } while (stack.size() > 0); | ||||||||
1248 | } | ||||||||
1249 | |||||||||
1250 | |||||||||
1251 | bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree *loop, ProjNode* proj, ProjNode *predicate_proj, | ||||||||
1252 | CountedLoopNode *cl, ConNode* zero, Invariance& invar, | ||||||||
1253 | Deoptimization::DeoptReason reason) { | ||||||||
1254 | // Following are changed to nonnull when a predicate can be hoisted | ||||||||
1255 | ProjNode* new_predicate_proj = NULL__null; | ||||||||
1256 | IfNode* iff = proj->in(0)->as_If(); | ||||||||
1257 | Node* test = iff->in(1); | ||||||||
1258 | if (!test->is_Bool()){ //Conv2B, ... | ||||||||
1259 | return false; | ||||||||
1260 | } | ||||||||
1261 | BoolNode* bol = test->as_Bool(); | ||||||||
1262 | if (invar.is_invariant(bol)) { | ||||||||
1263 | // Invariant test | ||||||||
1264 | new_predicate_proj = create_new_if_for_predicate(predicate_proj, NULL__null, | ||||||||
1265 | reason, | ||||||||
1266 | iff->Opcode()); | ||||||||
1267 | Node* ctrl = new_predicate_proj->in(0)->as_If()->in(0); | ||||||||
1268 | BoolNode* new_predicate_bol = invar.clone(bol, ctrl)->as_Bool(); | ||||||||
1269 | |||||||||
1270 | // Negate test if necessary | ||||||||
1271 | bool negated = false; | ||||||||
1272 | if (proj->_con != predicate_proj->_con) { | ||||||||
1273 | new_predicate_bol = new BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate()); | ||||||||
1274 | register_new_node(new_predicate_bol, ctrl); | ||||||||
1275 | negated = true; | ||||||||
1276 | } | ||||||||
1277 | IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If(); | ||||||||
1278 | _igvn.hash_delete(new_predicate_iff); | ||||||||
1279 | new_predicate_iff->set_req(1, new_predicate_bol); | ||||||||
1280 | #ifndef PRODUCT | ||||||||
1281 | if (TraceLoopPredicate) { | ||||||||
1282 | tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx); | ||||||||
1283 | loop->dump_head(); | ||||||||
1284 | } else if (TraceLoopOpts) { | ||||||||
1285 | tty->print("Predicate IC "); | ||||||||
1286 | loop->dump_head(); | ||||||||
1287 | } | ||||||||
1288 | #endif | ||||||||
1289 | } else if (cl != NULL__null && loop->is_range_check_if(iff, this, invar DEBUG_ONLY(COMMA predicate_proj), predicate_proj)) { | ||||||||
1290 | // Range check for counted loops | ||||||||
1291 | const Node* cmp = bol->in(1)->as_Cmp(); | ||||||||
1292 | Node* idx = cmp->in(1); | ||||||||
1293 | assert(!invar.is_invariant(idx), "index is variant")do { if (!(!invar.is_invariant(idx))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1293, "assert(" "!invar.is_invariant(idx)" ") failed", "index is variant" ); ::breakpoint(); } } while (0); | ||||||||
1294 | Node* rng = cmp->in(2); | ||||||||
1295 | assert(rng->Opcode() == Op_LoadRange || iff->is_RangeCheck() || _igvn.type(rng)->is_int()->_lo >= 0, "must be")do { if (!(rng->Opcode() == Op_LoadRange || iff->is_RangeCheck () || _igvn.type(rng)->is_int()->_lo >= 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1295, "assert(" "rng->Opcode() == Op_LoadRange || iff->is_RangeCheck() || _igvn.type(rng)->is_int()->_lo >= 0" ") failed", "must be"); ::breakpoint(); } } while (0); | ||||||||
1296 | assert(invar.is_invariant(rng), "range must be invariant")do { if (!(invar.is_invariant(rng))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1296, "assert(" "invar.is_invariant(rng)" ") failed", "range must be invariant" ); ::breakpoint(); } } while (0); | ||||||||
1297 | int scale = 1; | ||||||||
1298 | Node* offset = zero; | ||||||||
1299 | bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset); | ||||||||
1300 | assert(ok, "must be index expression")do { if (!(ok)) { (*g_assert_poison) = 'X';; report_vm_error( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1300, "assert(" "ok" ") failed", "must be index expression" ); ::breakpoint(); } } while (0); | ||||||||
1301 | |||||||||
1302 | Node* init = cl->init_trip(); | ||||||||
1303 | // Limit is not exact. | ||||||||
1304 | // Calculate exact limit here. | ||||||||
1305 | // Note, counted loop's test is '<' or '>'. | ||||||||
1306 | loop->compute_trip_count(this); | ||||||||
1307 | Node* limit = exact_limit(loop); | ||||||||
1308 | int stride = cl->stride()->get_int(); | ||||||||
1309 | |||||||||
1310 | // Build if's for the upper and lower bound tests. The | ||||||||
1311 | // lower_bound test will dominate the upper bound test and all | ||||||||
1312 | // cloned or created nodes will use the lower bound test as | ||||||||
1313 | // their declared control. | ||||||||
1314 | |||||||||
1315 | // Perform cloning to keep Invariance state correct since the | ||||||||
1316 | // late schedule will place invariant things in the loop. | ||||||||
1317 | Node *ctrl = predicate_proj->in(0)->as_If()->in(0); | ||||||||
1318 | rng = invar.clone(rng, ctrl); | ||||||||
1319 | if (offset && offset != zero) { | ||||||||
1320 | assert(invar.is_invariant(offset), "offset must be loop invariant")do { if (!(invar.is_invariant(offset))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1320, "assert(" "invar.is_invariant(offset)" ") failed", "offset must be loop invariant" ); ::breakpoint(); } } while (0); | ||||||||
1321 | offset = invar.clone(offset, ctrl); | ||||||||
1322 | } | ||||||||
1323 | // If predicate expressions may overflow in the integer range, longs are used. | ||||||||
1324 | bool overflow = false; | ||||||||
1325 | bool negate = (proj->_con != predicate_proj->_con); | ||||||||
1326 | |||||||||
1327 | // Test the lower bound | ||||||||
1328 | BoolNode* lower_bound_bol = rc_predicate(loop, ctrl, scale, offset, init, limit, stride, rng, false, overflow, negate); | ||||||||
1329 | |||||||||
1330 | ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL__null, reason, overflow ? Op_If : iff->Opcode()); | ||||||||
1331 | IfNode* lower_bound_iff = lower_bound_proj->in(0)->as_If(); | ||||||||
1332 | _igvn.hash_delete(lower_bound_iff); | ||||||||
1333 | lower_bound_iff->set_req(1, lower_bound_bol); | ||||||||
1334 | if (TraceLoopPredicate) tty->print_cr("lower bound check if: %s %d ", negate ? " negated" : "", lower_bound_iff->_idx); | ||||||||
1335 | |||||||||
1336 | // Test the upper bound | ||||||||
1337 | BoolNode* upper_bound_bol = rc_predicate(loop, lower_bound_proj, scale, offset, init, limit, stride, rng, true, overflow, negate); | ||||||||
1338 | |||||||||
1339 | ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL__null, reason, overflow ? Op_If : iff->Opcode()); | ||||||||
1340 | assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate")do { if (!(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1340, "assert(" "upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj" ") failed", "should dominate"); ::breakpoint(); } } while (0 ); | ||||||||
1341 | IfNode* upper_bound_iff = upper_bound_proj->in(0)->as_If(); | ||||||||
1342 | _igvn.hash_delete(upper_bound_iff); | ||||||||
1343 | upper_bound_iff->set_req(1, upper_bound_bol); | ||||||||
1344 | if (TraceLoopPredicate) tty->print_cr("upper bound check if: %s %d ", negate ? " negated" : "", lower_bound_iff->_idx); | ||||||||
1345 | |||||||||
1346 | // Fall through into rest of the clean up code which will move | ||||||||
1347 | // any dependent nodes onto the upper bound test. | ||||||||
1348 | new_predicate_proj = upper_bound_proj; | ||||||||
1349 | |||||||||
1350 | if (iff->is_RangeCheck()) { | ||||||||
1351 | new_predicate_proj = insert_initial_skeleton_predicate(iff, loop, proj, predicate_proj, upper_bound_proj, scale, offset, init, limit, stride, rng, overflow, reason); | ||||||||
1352 | } | ||||||||
1353 | |||||||||
1354 | #ifndef PRODUCT | ||||||||
1355 | if (TraceLoopOpts && !TraceLoopPredicate) { | ||||||||
1356 | tty->print("Predicate RC "); | ||||||||
1357 | loop->dump_head(); | ||||||||
1358 | } | ||||||||
1359 | #endif | ||||||||
1360 | } else { | ||||||||
1361 | // Loop variant check (for example, range check in non-counted loop) | ||||||||
1362 | // with uncommon trap. | ||||||||
1363 | return false; | ||||||||
1364 | } | ||||||||
1365 | assert(new_predicate_proj != NULL, "sanity")do { if (!(new_predicate_proj != __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1365, "assert(" "new_predicate_proj != __null" ") failed", "sanity" ); ::breakpoint(); } } while (0); | ||||||||
1366 | // Success - attach condition (new_predicate_bol) to predicate if | ||||||||
1367 | invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate | ||||||||
1368 | |||||||||
1369 | // Eliminate the old If in the loop body | ||||||||
1370 | dominated_by( new_predicate_proj, iff, proj->_con != new_predicate_proj->_con ); | ||||||||
1371 | |||||||||
1372 | C->set_major_progress(); | ||||||||
1373 | return true; | ||||||||
1374 | } | ||||||||
1375 | |||||||||
1376 | |||||||||
1377 | // After pre/main/post loops are created, we'll put a copy of some | ||||||||
1378 | // range checks between the pre and main loop to validate the value | ||||||||
1379 | // of the main loop induction variable. Make a copy of the predicates | ||||||||
1380 | // here with an opaque node as a place holder for the value (will be | ||||||||
1381 | // updated by PhaseIdealLoop::clone_skeleton_predicate()). | ||||||||
1382 | ProjNode* PhaseIdealLoop::insert_initial_skeleton_predicate(IfNode* iff, IdealLoopTree *loop, | ||||||||
1383 | ProjNode* proj, ProjNode *predicate_proj, | ||||||||
1384 | ProjNode* upper_bound_proj, | ||||||||
1385 | int scale, Node* offset, | ||||||||
1386 | Node* init, Node* limit, jint stride, | ||||||||
1387 | Node* rng, bool &overflow, | ||||||||
1388 | Deoptimization::DeoptReason reason) { | ||||||||
1389 | // First predicate for the initial value on first loop iteration | ||||||||
1390 | Node* opaque_init = new OpaqueLoopInitNode(C, init); | ||||||||
1391 | register_new_node(opaque_init, upper_bound_proj); | ||||||||
1392 | bool negate = (proj->_con != predicate_proj->_con); | ||||||||
| |||||||||
1393 | BoolNode* bol = rc_predicate(loop, upper_bound_proj, scale, offset, opaque_init, limit, stride, rng, (stride > 0) != (scale > 0), overflow, negate); | ||||||||
1394 | Node* opaque_bol = new Opaque4Node(C, bol, _igvn.intcon(1)); // This will go away once loop opts are over | ||||||||
1395 | C->add_skeleton_predicate_opaq(opaque_bol); | ||||||||
1396 | register_new_node(opaque_bol, upper_bound_proj); | ||||||||
1397 | ProjNode* new_proj = create_new_if_for_predicate(predicate_proj, NULL__null, reason, overflow ? Op_If : iff->Opcode()); | ||||||||
1398 | _igvn.replace_input_of(new_proj->in(0), 1, opaque_bol); | ||||||||
1399 | assert(opaque_init->outcnt() > 0, "should be used")do { if (!(opaque_init->outcnt() > 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1399, "assert(" "opaque_init->outcnt() > 0" ") failed" , "should be used"); ::breakpoint(); } } while (0); | ||||||||
1400 | |||||||||
1401 | // Second predicate for init + (current stride - initial stride) | ||||||||
1402 | // This is identical to the previous predicate initially but as | ||||||||
1403 | // unrolling proceeds current stride is updated. | ||||||||
1404 | Node* init_stride = loop->_head->as_CountedLoop()->stride(); | ||||||||
1405 | Node* opaque_stride = new OpaqueLoopStrideNode(C, init_stride); | ||||||||
1406 | register_new_node(opaque_stride, new_proj); | ||||||||
1407 | Node* max_value = new SubINode(opaque_stride, init_stride); | ||||||||
1408 | register_new_node(max_value, new_proj); | ||||||||
1409 | max_value = new AddINode(opaque_init, max_value); | ||||||||
1410 | register_new_node(max_value, new_proj); | ||||||||
1411 | bol = rc_predicate(loop, new_proj, scale, offset, max_value, limit, stride, rng, (stride > 0) != (scale > 0), overflow, negate); | ||||||||
1412 | opaque_bol = new Opaque4Node(C, bol, _igvn.intcon(1)); | ||||||||
1413 | C->add_skeleton_predicate_opaq(opaque_bol); | ||||||||
1414 | register_new_node(opaque_bol, new_proj); | ||||||||
1415 | new_proj = create_new_if_for_predicate(predicate_proj, NULL__null, reason, overflow ? Op_If : iff->Opcode()); | ||||||||
1416 | _igvn.replace_input_of(new_proj->in(0), 1, opaque_bol); | ||||||||
1417 | assert(max_value->outcnt() > 0, "should be used")do { if (!(max_value->outcnt() > 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1417, "assert(" "max_value->outcnt() > 0" ") failed", "should be used"); ::breakpoint(); } } while (0); | ||||||||
1418 | |||||||||
1419 | return new_proj; | ||||||||
1420 | } | ||||||||
1421 | |||||||||
1422 | //------------------------------ loop_predication_impl-------------------------- | ||||||||
1423 | // Insert loop predicates for null checks and range checks | ||||||||
1424 | bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree *loop) { | ||||||||
1425 | if (!UseLoopPredicate) return false; | ||||||||
1426 | |||||||||
1427 | if (!loop->_head->is_Loop()) { | ||||||||
1428 | // Could be a simple region when irreducible loops are present. | ||||||||
1429 | return false; | ||||||||
1430 | } | ||||||||
1431 | LoopNode* head = loop->_head->as_Loop(); | ||||||||
1432 | |||||||||
1433 | if (head->unique_ctrl_out()->Opcode() == Op_NeverBranch) { | ||||||||
1434 | // do nothing for infinite loops | ||||||||
1435 | return false; | ||||||||
1436 | } | ||||||||
1437 | |||||||||
1438 | if (head->is_OuterStripMinedLoop()) { | ||||||||
1439 | return false; | ||||||||
1440 | } | ||||||||
1441 | |||||||||
1442 | CountedLoopNode *cl = NULL__null; | ||||||||
1443 | if (head->is_valid_counted_loop(T_INT)) { | ||||||||
1444 | cl = head->as_CountedLoop(); | ||||||||
1445 | // do nothing for iteration-splitted loops | ||||||||
1446 | if (!cl->is_normal_loop()) return false; | ||||||||
1447 | // Avoid RCE if Counted loop's test is '!='. | ||||||||
1448 | BoolTest::mask bt = cl->loopexit()->test_trip(); | ||||||||
1449 | if (bt != BoolTest::lt && bt != BoolTest::gt) | ||||||||
1450 | cl = NULL__null; | ||||||||
1451 | } | ||||||||
1452 | |||||||||
1453 | Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl); | ||||||||
1454 | ProjNode *loop_limit_proj = NULL__null; | ||||||||
1455 | ProjNode *predicate_proj = NULL__null; | ||||||||
1456 | ProjNode *profile_predicate_proj = NULL__null; | ||||||||
1457 | // Loop limit check predicate should be near the loop. | ||||||||
1458 | loop_limit_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check); | ||||||||
1459 | if (loop_limit_proj != NULL__null) { | ||||||||
1460 | entry = skip_loop_predicates(loop_limit_proj); | ||||||||
1461 | } | ||||||||
1462 | bool has_profile_predicates = false; | ||||||||
1463 | profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate); | ||||||||
1464 | if (profile_predicate_proj != NULL__null) { | ||||||||
1465 | Node* n = skip_loop_predicates(entry); | ||||||||
1466 | // Check if predicates were already added to the profile predicate | ||||||||
1467 | // block | ||||||||
1468 | if (n != entry->in(0)->in(0) || n->outcnt() != 1) { | ||||||||
1469 | has_profile_predicates = true; | ||||||||
1470 | } | ||||||||
1471 | entry = n; | ||||||||
1472 | } | ||||||||
1473 | predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); | ||||||||
1474 | |||||||||
1475 | float loop_trip_cnt = -1; | ||||||||
1476 | bool follow_branches = loop_predication_should_follow_branches(loop, profile_predicate_proj, loop_trip_cnt); | ||||||||
1477 | assert(!follow_branches || loop_trip_cnt >= 0, "negative trip count?")do { if (!(!follow_branches || loop_trip_cnt >= 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopPredicate.cpp" , 1477, "assert(" "!follow_branches || loop_trip_cnt >= 0" ") failed", "negative trip count?"); ::breakpoint(); } } while (0); | ||||||||
1478 | |||||||||
1479 | if (predicate_proj == NULL__null && !follow_branches) { | ||||||||
1480 | #ifndef PRODUCT | ||||||||
1481 | if (TraceLoopPredicate) { | ||||||||
1482 | tty->print("missing predicate:"); | ||||||||
1483 | loop->dump_head(); | ||||||||
1484 | head->dump(1); | ||||||||
1485 | } | ||||||||
1486 | #endif | ||||||||
1487 | return false; | ||||||||
1488 | } | ||||||||
1489 | ConNode* zero = _igvn.intcon(0); | ||||||||
1490 | set_ctrl(zero, C->root()); | ||||||||
1491 | |||||||||
1492 | ResourceArea* area = Thread::current()->resource_area(); | ||||||||
1493 | Invariance invar(area, loop); | ||||||||
1494 | |||||||||
1495 | // Create list of if-projs such that a newer proj dominates all older | ||||||||
1496 | // projs in the list, and they all dominate loop->tail() | ||||||||
1497 | Node_List if_proj_list; | ||||||||
1498 | Node_List regions; | ||||||||
1499 | Node* current_proj = loop->tail(); // start from tail | ||||||||
1500 | |||||||||
1501 | |||||||||
1502 | Node_List controls; | ||||||||
1503 | while (current_proj != head) { | ||||||||
1504 | if (loop == get_loop(current_proj) && // still in the loop ? | ||||||||
1505 | current_proj->is_Proj() && // is a projection ? | ||||||||
1506 | (current_proj->in(0)->Opcode() == Op_If || | ||||||||
1507 | current_proj->in(0)->Opcode() == Op_RangeCheck)) { // is a if projection ? | ||||||||
1508 | if_proj_list.push(current_proj); | ||||||||
1509 | } | ||||||||
1510 | if (follow_branches && | ||||||||
1511 | current_proj->Opcode() == Op_Region && | ||||||||
1512 | loop == get_loop(current_proj)) { | ||||||||
1513 | regions.push(current_proj); | ||||||||
1514 | } | ||||||||
1515 | current_proj = idom(current_proj); | ||||||||
1516 | } | ||||||||
1517 | |||||||||
1518 | bool hoisted = false; // true if at least one proj is promoted | ||||||||
1519 | |||||||||
1520 | if (!has_profile_predicates) { | ||||||||
1521 | while (if_proj_list.size() > 0) { | ||||||||
1522 | Node* n = if_proj_list.pop(); | ||||||||
1523 | |||||||||
1524 | ProjNode* proj = n->as_Proj(); | ||||||||
1525 | IfNode* iff = proj->in(0)->as_If(); | ||||||||
1526 | |||||||||
1527 | CallStaticJavaNode* call = proj->is_uncommon_trap_if_pattern(Deoptimization::Reason_none); | ||||||||
1528 | if (call == NULL__null) { | ||||||||
1529 | if (loop->is_loop_exit(iff)) { | ||||||||
1530 | // stop processing the remaining projs in the list because the execution of them | ||||||||
1531 | // depends on the condition of "iff" (iff->in(1)). | ||||||||
1532 | break; | ||||||||
1533 | } else { | ||||||||
1534 | // Both arms are inside the loop. There are two cases: | ||||||||
1535 | // (1) there is one backward branch. In this case, any remaining proj | ||||||||
1536 | // in the if_proj list post-dominates "iff". So, the condition of "iff" | ||||||||
1537 | // does not determine the execution the remining projs directly, and we | ||||||||
1538 | // can safely continue. | ||||||||
1539 | // (2) both arms are forwarded, i.e. a diamond shape. In this case, "proj" | ||||||||
1540 | // does not dominate loop->tail(), so it can not be in the if_proj list. | ||||||||
1541 | continue; | ||||||||
1542 | } | ||||||||
1543 | } | ||||||||
1544 | Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(call->uncommon_trap_request()); | ||||||||
1545 | if (reason == Deoptimization::Reason_predicate) { | ||||||||
1546 | break; | ||||||||
1547 | } | ||||||||
1548 | |||||||||
1549 | if (predicate_proj != NULL__null) { | ||||||||
1550 | hoisted = loop_predication_impl_helper(loop, proj, predicate_proj, cl, zero, invar, Deoptimization::Reason_predicate) | hoisted; | ||||||||
1551 | } | ||||||||
1552 | } // end while | ||||||||
1553 | } | ||||||||
1554 | |||||||||
1555 | if (follow_branches) { | ||||||||
1556 | PathFrequency pf(loop->_head, this); | ||||||||
1557 | |||||||||
1558 | // Some projections were skipped by regular predicates because of | ||||||||
1559 | // an early loop exit. Try them with profile data. | ||||||||
1560 | while (if_proj_list.size() > 0) { | ||||||||
1561 | Node* proj = if_proj_list.pop(); | ||||||||
1562 | float f = pf.to(proj); | ||||||||
1563 | if (proj->as_Proj()->is_uncommon_trap_if_pattern(Deoptimization::Reason_none) && | ||||||||
1564 | f * loop_trip_cnt >= 1) { | ||||||||
1565 | hoisted = loop_predication_impl_helper(loop, proj->as_Proj(), profile_predicate_proj, cl, zero, invar, Deoptimization::Reason_profile_predicate) | hoisted; | ||||||||
1566 | } | ||||||||
1567 | } | ||||||||
1568 | |||||||||
1569 | // And look into all branches | ||||||||
1570 | Node_Stack stack(0); | ||||||||
1571 | VectorSet seen; | ||||||||
1572 | Node_List if_proj_list_freq(area); | ||||||||
1573 | while (regions.size() > 0) { | ||||||||
1574 | Node* c = regions.pop(); | ||||||||
1575 | loop_predication_follow_branches(c, loop, loop_trip_cnt, pf, stack, seen, if_proj_list_freq); | ||||||||
1576 | } | ||||||||
1577 | |||||||||
1578 | for (uint i = 0; i < if_proj_list_freq.size(); i++) { | ||||||||
1579 | ProjNode* proj = if_proj_list_freq.at(i)->as_Proj(); | ||||||||
1580 | hoisted = loop_predication_impl_helper(loop, proj, profile_predicate_proj, cl, zero, invar, Deoptimization::Reason_profile_predicate) | hoisted; | ||||||||
1581 | } | ||||||||
1582 | } | ||||||||
1583 | |||||||||
1584 | #ifndef PRODUCT | ||||||||
1585 | // report that the loop predication has been actually performed | ||||||||
1586 | // for this loop | ||||||||
1587 | if (TraceLoopPredicate && hoisted) { | ||||||||
1588 | tty->print("Loop Predication Performed:"); | ||||||||
1589 | loop->dump_head(); | ||||||||
1590 | } | ||||||||
1591 | #endif | ||||||||
1592 | |||||||||
1593 | head->verify_strip_mined(1); | ||||||||
1594 | |||||||||
1595 | return hoisted; | ||||||||
1596 | } | ||||||||
1597 | |||||||||
1598 | //------------------------------loop_predication-------------------------------- | ||||||||
1599 | // driver routine for loop predication optimization | ||||||||
1600 | bool IdealLoopTree::loop_predication( PhaseIdealLoop *phase) { | ||||||||
1601 | bool hoisted = false; | ||||||||
1602 | // Recursively promote predicates | ||||||||
1603 | if (_child) { | ||||||||
1604 | hoisted = _child->loop_predication( phase); | ||||||||
1605 | } | ||||||||
1606 | |||||||||
1607 | // self | ||||||||
1608 | if (!_irreducible && !tail()->is_top()) { | ||||||||
1609 | hoisted |= phase->loop_predication_impl(this); | ||||||||
1610 | } | ||||||||
1611 | |||||||||
1612 | if (_next) { //sibling | ||||||||
1613 | hoisted |= _next->loop_predication( phase); | ||||||||
1614 | } | ||||||||
1615 | |||||||||
1616 | return hoisted; | ||||||||
1617 | } |
1 | /* | ||||
2 | * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. | ||||
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||||
4 | * | ||||
5 | * This code is free software; you can redistribute it and/or modify it | ||||
6 | * under the terms of the GNU General Public License version 2 only, as | ||||
7 | * published by the Free Software Foundation. | ||||
8 | * | ||||
9 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||
12 | * version 2 for more details (a copy is included in the LICENSE file that | ||||
13 | * accompanied this code). | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU General Public License version | ||||
16 | * 2 along with this work; if not, write to the Free Software Foundation, | ||||
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
18 | * | ||||
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||||
20 | * or visit www.oracle.com if you need additional information or have any | ||||
21 | * questions. | ||||
22 | * | ||||
23 | */ | ||||
24 | |||||
25 | #ifndef SHARE_OPTO_LOOPNODE_HPP | ||||
26 | #define SHARE_OPTO_LOOPNODE_HPP | ||||
27 | |||||
28 | #include "opto/cfgnode.hpp" | ||||
29 | #include "opto/multnode.hpp" | ||||
30 | #include "opto/phaseX.hpp" | ||||
31 | #include "opto/subnode.hpp" | ||||
32 | #include "opto/type.hpp" | ||||
33 | |||||
34 | class CmpNode; | ||||
35 | class BaseCountedLoopEndNode; | ||||
36 | class CountedLoopNode; | ||||
37 | class IdealLoopTree; | ||||
38 | class LoopNode; | ||||
39 | class Node; | ||||
40 | class OuterStripMinedLoopEndNode; | ||||
41 | class PathFrequency; | ||||
42 | class PhaseIdealLoop; | ||||
43 | class CountedLoopReserveKit; | ||||
44 | class VectorSet; | ||||
45 | class Invariance; | ||||
46 | struct small_cache; | ||||
47 | |||||
48 | // | ||||
49 | // I D E A L I Z E D L O O P S | ||||
50 | // | ||||
51 | // Idealized loops are the set of loops I perform more interesting | ||||
52 | // transformations on, beyond simple hoisting. | ||||
53 | |||||
54 | //------------------------------LoopNode--------------------------------------- | ||||
55 | // Simple loop header. Fall in path on left, loop-back path on right. | ||||
56 | class LoopNode : public RegionNode { | ||||
57 | // Size is bigger to hold the flags. However, the flags do not change | ||||
58 | // the semantics so it does not appear in the hash & cmp functions. | ||||
59 | virtual uint size_of() const { return sizeof(*this); } | ||||
60 | protected: | ||||
61 | uint _loop_flags; | ||||
62 | // Names for flag bitfields | ||||
63 | enum { Normal=0, Pre=1, Main=2, Post=3, PreMainPostFlagsMask=3, | ||||
64 | MainHasNoPreLoop = 1<<2, | ||||
65 | HasExactTripCount = 1<<3, | ||||
66 | InnerLoop = 1<<4, | ||||
67 | PartialPeelLoop = 1<<5, | ||||
68 | PartialPeelFailed = 1<<6, | ||||
69 | HasReductions = 1<<7, | ||||
70 | WasSlpAnalyzed = 1<<8, | ||||
71 | PassedSlpAnalysis = 1<<9, | ||||
72 | DoUnrollOnly = 1<<10, | ||||
73 | VectorizedLoop = 1<<11, | ||||
74 | HasAtomicPostLoop = 1<<12, | ||||
75 | HasRangeChecks = 1<<13, | ||||
76 | IsMultiversioned = 1<<14, | ||||
77 | StripMined = 1<<15, | ||||
78 | SubwordLoop = 1<<16, | ||||
79 | ProfileTripFailed = 1<<17, | ||||
80 | LoopNestInnerLoop = 1 << 18, | ||||
81 | LoopNestLongOuterLoop = 1 << 19}; | ||||
82 | char _unswitch_count; | ||||
83 | enum { _unswitch_max=3 }; | ||||
84 | char _postloop_flags; | ||||
85 | enum { LoopNotRCEChecked = 0, LoopRCEChecked = 1, RCEPostLoop = 2 }; | ||||
86 | |||||
87 | // Expected trip count from profile data | ||||
88 | float _profile_trip_cnt; | ||||
89 | |||||
90 | public: | ||||
91 | // Names for edge indices | ||||
92 | enum { Self=0, EntryControl, LoopBackControl }; | ||||
93 | |||||
94 | bool is_inner_loop() const { return _loop_flags & InnerLoop; } | ||||
95 | void set_inner_loop() { _loop_flags |= InnerLoop; } | ||||
96 | |||||
97 | bool range_checks_present() const { return _loop_flags & HasRangeChecks; } | ||||
98 | bool is_multiversioned() const { return _loop_flags & IsMultiversioned; } | ||||
99 | bool is_vectorized_loop() const { return _loop_flags & VectorizedLoop; } | ||||
100 | bool is_partial_peel_loop() const { return _loop_flags & PartialPeelLoop; } | ||||
101 | void set_partial_peel_loop() { _loop_flags |= PartialPeelLoop; } | ||||
102 | bool partial_peel_has_failed() const { return _loop_flags & PartialPeelFailed; } | ||||
103 | bool is_strip_mined() const { return _loop_flags & StripMined; } | ||||
104 | bool is_profile_trip_failed() const { return _loop_flags & ProfileTripFailed; } | ||||
105 | bool is_subword_loop() const { return _loop_flags & SubwordLoop; } | ||||
106 | bool is_loop_nest_inner_loop() const { return _loop_flags & LoopNestInnerLoop; } | ||||
107 | bool is_loop_nest_outer_loop() const { return _loop_flags & LoopNestLongOuterLoop; } | ||||
108 | |||||
109 | void mark_partial_peel_failed() { _loop_flags |= PartialPeelFailed; } | ||||
110 | void mark_has_reductions() { _loop_flags |= HasReductions; } | ||||
111 | void mark_was_slp() { _loop_flags |= WasSlpAnalyzed; } | ||||
112 | void mark_passed_slp() { _loop_flags |= PassedSlpAnalysis; } | ||||
113 | void mark_do_unroll_only() { _loop_flags |= DoUnrollOnly; } | ||||
114 | void mark_loop_vectorized() { _loop_flags |= VectorizedLoop; } | ||||
115 | void mark_has_atomic_post_loop() { _loop_flags |= HasAtomicPostLoop; } | ||||
116 | void mark_has_range_checks() { _loop_flags |= HasRangeChecks; } | ||||
117 | void mark_is_multiversioned() { _loop_flags |= IsMultiversioned; } | ||||
118 | void mark_strip_mined() { _loop_flags |= StripMined; } | ||||
119 | void clear_strip_mined() { _loop_flags &= ~StripMined; } | ||||
120 | void mark_profile_trip_failed() { _loop_flags |= ProfileTripFailed; } | ||||
121 | void mark_subword_loop() { _loop_flags |= SubwordLoop; } | ||||
122 | void mark_loop_nest_inner_loop() { _loop_flags |= LoopNestInnerLoop; } | ||||
123 | void mark_loop_nest_outer_loop() { _loop_flags |= LoopNestLongOuterLoop; } | ||||
124 | |||||
125 | int unswitch_max() { return _unswitch_max; } | ||||
126 | int unswitch_count() { return _unswitch_count; } | ||||
127 | |||||
128 | int has_been_range_checked() const { return _postloop_flags & LoopRCEChecked; } | ||||
129 | void set_has_been_range_checked() { _postloop_flags |= LoopRCEChecked; } | ||||
130 | int is_rce_post_loop() const { return _postloop_flags & RCEPostLoop; } | ||||
131 | void set_is_rce_post_loop() { _postloop_flags |= RCEPostLoop; } | ||||
132 | |||||
133 | void set_unswitch_count(int val) { | ||||
134 | assert (val <= unswitch_max(), "too many unswitches")do { if (!(val <= unswitch_max())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 134, "assert(" "val <= unswitch_max()" ") failed", "too many unswitches" ); ::breakpoint(); } } while (0); | ||||
135 | _unswitch_count = val; | ||||
136 | } | ||||
137 | |||||
138 | void set_profile_trip_cnt(float ptc) { _profile_trip_cnt = ptc; } | ||||
139 | float profile_trip_cnt() { return _profile_trip_cnt; } | ||||
140 | |||||
141 | LoopNode(Node *entry, Node *backedge) | ||||
142 | : RegionNode(3), _loop_flags(0), _unswitch_count(0), | ||||
143 | _postloop_flags(0), _profile_trip_cnt(COUNT_UNKNOWN(-1.0f)) { | ||||
144 | init_class_id(Class_Loop); | ||||
145 | init_req(EntryControl, entry); | ||||
146 | init_req(LoopBackControl, backedge); | ||||
147 | } | ||||
148 | |||||
149 | virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | ||||
150 | virtual int Opcode() const; | ||||
151 | bool can_be_counted_loop(PhaseTransform* phase) const { | ||||
152 | return req() == 3 && in(0) != NULL__null && | ||||
153 | in(1) != NULL__null && phase->type(in(1)) != Type::TOP && | ||||
154 | in(2) != NULL__null && phase->type(in(2)) != Type::TOP; | ||||
155 | } | ||||
156 | bool is_valid_counted_loop(BasicType bt) const; | ||||
157 | #ifndef PRODUCT | ||||
158 | virtual void dump_spec(outputStream *st) const; | ||||
159 | #endif | ||||
160 | |||||
161 | void verify_strip_mined(int expect_skeleton) const NOT_DEBUG_RETURN; | ||||
162 | virtual LoopNode* skip_strip_mined(int expect_skeleton = 1) { return this; } | ||||
163 | virtual IfTrueNode* outer_loop_tail() const { ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 163); ::breakpoint(); } while (0); return NULL__null; } | ||||
164 | virtual OuterStripMinedLoopEndNode* outer_loop_end() const { ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 164); ::breakpoint(); } while (0); return NULL__null; } | ||||
165 | virtual IfFalseNode* outer_loop_exit() const { ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 165); ::breakpoint(); } while (0); return NULL__null; } | ||||
166 | virtual SafePointNode* outer_safepoint() const { ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 166); ::breakpoint(); } while (0); return NULL__null; } | ||||
167 | }; | ||||
168 | |||||
169 | //------------------------------Counted Loops---------------------------------- | ||||
170 | // Counted loops are all trip-counted loops, with exactly 1 trip-counter exit | ||||
171 | // path (and maybe some other exit paths). The trip-counter exit is always | ||||
172 | // last in the loop. The trip-counter have to stride by a constant; | ||||
173 | // the exit value is also loop invariant. | ||||
174 | |||||
175 | // CountedLoopNodes and CountedLoopEndNodes come in matched pairs. The | ||||
176 | // CountedLoopNode has the incoming loop control and the loop-back-control | ||||
177 | // which is always the IfTrue before the matching CountedLoopEndNode. The | ||||
178 | // CountedLoopEndNode has an incoming control (possibly not the | ||||
179 | // CountedLoopNode if there is control flow in the loop), the post-increment | ||||
180 | // trip-counter value, and the limit. The trip-counter value is always of | ||||
181 | // the form (Op old-trip-counter stride). The old-trip-counter is produced | ||||
182 | // by a Phi connected to the CountedLoopNode. The stride is constant. | ||||
183 | // The Op is any commutable opcode, including Add, Mul, Xor. The | ||||
184 | // CountedLoopEndNode also takes in the loop-invariant limit value. | ||||
185 | |||||
186 | // From a CountedLoopNode I can reach the matching CountedLoopEndNode via the | ||||
187 | // loop-back control. From CountedLoopEndNodes I can reach CountedLoopNodes | ||||
188 | // via the old-trip-counter from the Op node. | ||||
189 | |||||
190 | //------------------------------CountedLoopNode-------------------------------- | ||||
191 | // CountedLoopNodes head simple counted loops. CountedLoopNodes have as | ||||
192 | // inputs the incoming loop-start control and the loop-back control, so they | ||||
193 | // act like RegionNodes. They also take in the initial trip counter, the | ||||
194 | // loop-invariant stride and the loop-invariant limit value. CountedLoopNodes | ||||
195 | // produce a loop-body control and the trip counter value. Since | ||||
196 | // CountedLoopNodes behave like RegionNodes I still have a standard CFG model. | ||||
197 | |||||
198 | class BaseCountedLoopNode : public LoopNode { | ||||
199 | public: | ||||
200 | BaseCountedLoopNode(Node *entry, Node *backedge) | ||||
201 | : LoopNode(entry, backedge) { | ||||
202 | } | ||||
203 | |||||
204 | Node *init_control() const { return in(EntryControl); } | ||||
205 | Node *back_control() const { return in(LoopBackControl); } | ||||
206 | |||||
207 | Node* init_trip() const; | ||||
208 | Node* stride() const; | ||||
209 | bool stride_is_con() const; | ||||
210 | Node* limit() const; | ||||
211 | Node* incr() const; | ||||
212 | Node* phi() const; | ||||
213 | |||||
214 | BaseCountedLoopEndNode* loopexit_or_null() const; | ||||
215 | BaseCountedLoopEndNode* loopexit() const; | ||||
216 | |||||
217 | virtual BasicType bt() const = 0; | ||||
218 | |||||
219 | jlong stride_con() const; | ||||
220 | |||||
221 | static BaseCountedLoopNode* make(Node* entry, Node* backedge, BasicType bt); | ||||
222 | }; | ||||
223 | |||||
224 | |||||
225 | class CountedLoopNode : public BaseCountedLoopNode { | ||||
226 | // Size is bigger to hold _main_idx. However, _main_idx does not change | ||||
227 | // the semantics so it does not appear in the hash & cmp functions. | ||||
228 | virtual uint size_of() const { return sizeof(*this); } | ||||
229 | |||||
230 | // For Pre- and Post-loops during debugging ONLY, this holds the index of | ||||
231 | // the Main CountedLoop. Used to assert that we understand the graph shape. | ||||
232 | node_idx_t _main_idx; | ||||
233 | |||||
234 | // Known trip count calculated by compute_exact_trip_count() | ||||
235 | uint _trip_count; | ||||
236 | |||||
237 | // Log2 of original loop bodies in unrolled loop | ||||
238 | int _unrolled_count_log2; | ||||
239 | |||||
240 | // Node count prior to last unrolling - used to decide if | ||||
241 | // unroll,optimize,unroll,optimize,... is making progress | ||||
242 | int _node_count_before_unroll; | ||||
243 | |||||
244 | // If slp analysis is performed we record the maximum | ||||
245 | // vector mapped unroll factor here | ||||
246 | int _slp_maximum_unroll_factor; | ||||
247 | |||||
248 | public: | ||||
249 | CountedLoopNode(Node *entry, Node *backedge) | ||||
250 | : BaseCountedLoopNode(entry, backedge), _main_idx(0), _trip_count(max_juint), | ||||
251 | _unrolled_count_log2(0), _node_count_before_unroll(0), | ||||
252 | _slp_maximum_unroll_factor(0) { | ||||
253 | init_class_id(Class_CountedLoop); | ||||
254 | // Initialize _trip_count to the largest possible value. | ||||
255 | // Will be reset (lower) if the loop's trip count is known. | ||||
256 | } | ||||
257 | |||||
258 | virtual int Opcode() const; | ||||
259 | virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | ||||
260 | |||||
261 | CountedLoopEndNode* loopexit_or_null() const { return (CountedLoopEndNode*) BaseCountedLoopNode::loopexit_or_null(); } | ||||
262 | CountedLoopEndNode* loopexit() const { return (CountedLoopEndNode*) BaseCountedLoopNode::loopexit(); } | ||||
263 | int stride_con() const; | ||||
264 | |||||
265 | // Match increment with optional truncation | ||||
266 | static Node* | ||||
267 | match_incr_with_optional_truncation(Node* expr, Node** trunc1, Node** trunc2, const TypeInteger** trunc_type, | ||||
268 | BasicType bt); | ||||
269 | |||||
270 | // A 'main' loop has a pre-loop and a post-loop. The 'main' loop | ||||
271 | // can run short a few iterations and may start a few iterations in. | ||||
272 | // It will be RCE'd and unrolled and aligned. | ||||
273 | |||||
274 | // A following 'post' loop will run any remaining iterations. Used | ||||
275 | // during Range Check Elimination, the 'post' loop will do any final | ||||
276 | // iterations with full checks. Also used by Loop Unrolling, where | ||||
277 | // the 'post' loop will do any epilog iterations needed. Basically, | ||||
278 | // a 'post' loop can not profitably be further unrolled or RCE'd. | ||||
279 | |||||
280 | // A preceding 'pre' loop will run at least 1 iteration (to do peeling), | ||||
281 | // it may do under-flow checks for RCE and may do alignment iterations | ||||
282 | // so the following main loop 'knows' that it is striding down cache | ||||
283 | // lines. | ||||
284 | |||||
285 | // A 'main' loop that is ONLY unrolled or peeled, never RCE'd or | ||||
286 | // Aligned, may be missing it's pre-loop. | ||||
287 | bool is_normal_loop () const { return (_loop_flags&PreMainPostFlagsMask) == Normal; } | ||||
288 | bool is_pre_loop () const { return (_loop_flags&PreMainPostFlagsMask) == Pre; } | ||||
289 | bool is_main_loop () const { return (_loop_flags&PreMainPostFlagsMask) == Main; } | ||||
290 | bool is_post_loop () const { return (_loop_flags&PreMainPostFlagsMask) == Post; } | ||||
291 | bool is_reduction_loop() const { return (_loop_flags&HasReductions) == HasReductions; } | ||||
292 | bool was_slp_analyzed () const { return (_loop_flags&WasSlpAnalyzed) == WasSlpAnalyzed; } | ||||
293 | bool has_passed_slp () const { return (_loop_flags&PassedSlpAnalysis) == PassedSlpAnalysis; } | ||||
294 | bool is_unroll_only () const { return (_loop_flags&DoUnrollOnly) == DoUnrollOnly; } | ||||
295 | bool is_main_no_pre_loop() const { return _loop_flags & MainHasNoPreLoop; } | ||||
296 | bool has_atomic_post_loop () const { return (_loop_flags & HasAtomicPostLoop) == HasAtomicPostLoop; } | ||||
297 | void set_main_no_pre_loop() { _loop_flags |= MainHasNoPreLoop; } | ||||
298 | |||||
299 | int main_idx() const { return _main_idx; } | ||||
300 | |||||
301 | |||||
302 | void set_pre_loop (CountedLoopNode *main) { assert(is_normal_loop(),"")do { if (!(is_normal_loop())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 302, "assert(" "is_normal_loop()" ") failed", ""); ::breakpoint (); } } while (0); _loop_flags |= Pre ; _main_idx = main->_idx; } | ||||
303 | void set_main_loop ( ) { assert(is_normal_loop(),"")do { if (!(is_normal_loop())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 303, "assert(" "is_normal_loop()" ") failed", ""); ::breakpoint (); } } while (0); _loop_flags |= Main; } | ||||
304 | void set_post_loop (CountedLoopNode *main) { assert(is_normal_loop(),"")do { if (!(is_normal_loop())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 304, "assert(" "is_normal_loop()" ") failed", ""); ::breakpoint (); } } while (0); _loop_flags |= Post; _main_idx = main->_idx; } | ||||
305 | void set_normal_loop( ) { _loop_flags &= ~PreMainPostFlagsMask; } | ||||
306 | |||||
307 | void set_trip_count(uint tc) { _trip_count = tc; } | ||||
308 | uint trip_count() { return _trip_count; } | ||||
309 | |||||
310 | bool has_exact_trip_count() const { return (_loop_flags & HasExactTripCount) != 0; } | ||||
311 | void set_exact_trip_count(uint tc) { | ||||
312 | _trip_count = tc; | ||||
313 | _loop_flags |= HasExactTripCount; | ||||
314 | } | ||||
315 | void set_nonexact_trip_count() { | ||||
316 | _loop_flags &= ~HasExactTripCount; | ||||
317 | } | ||||
318 | void set_notpassed_slp() { | ||||
319 | _loop_flags &= ~PassedSlpAnalysis; | ||||
320 | } | ||||
321 | |||||
322 | void double_unrolled_count() { _unrolled_count_log2++; } | ||||
323 | int unrolled_count() { return 1 << MIN2(_unrolled_count_log2, BitsPerInt-3); } | ||||
324 | |||||
325 | void set_node_count_before_unroll(int ct) { _node_count_before_unroll = ct; } | ||||
326 | int node_count_before_unroll() { return _node_count_before_unroll; } | ||||
327 | void set_slp_max_unroll(int unroll_factor) { _slp_maximum_unroll_factor = unroll_factor; } | ||||
328 | int slp_max_unroll() const { return _slp_maximum_unroll_factor; } | ||||
329 | |||||
330 | virtual LoopNode* skip_strip_mined(int expect_skeleton = 1); | ||||
331 | OuterStripMinedLoopNode* outer_loop() const; | ||||
332 | virtual IfTrueNode* outer_loop_tail() const; | ||||
333 | virtual OuterStripMinedLoopEndNode* outer_loop_end() const; | ||||
334 | virtual IfFalseNode* outer_loop_exit() const; | ||||
335 | virtual SafePointNode* outer_safepoint() const; | ||||
336 | |||||
337 | // If this is a main loop in a pre/main/post loop nest, walk over | ||||
338 | // the predicates that were inserted by | ||||
339 | // duplicate_predicates()/add_range_check_predicate() | ||||
340 | static Node* skip_predicates_from_entry(Node* ctrl); | ||||
341 | Node* skip_predicates(); | ||||
342 | |||||
343 | virtual BasicType bt() const { | ||||
344 | return T_INT; | ||||
345 | } | ||||
346 | |||||
347 | Node* is_canonical_loop_entry(); | ||||
348 | |||||
349 | #ifndef PRODUCT | ||||
350 | virtual void dump_spec(outputStream *st) const; | ||||
351 | #endif | ||||
352 | }; | ||||
353 | |||||
354 | class LongCountedLoopNode : public BaseCountedLoopNode { | ||||
355 | public: | ||||
356 | LongCountedLoopNode(Node *entry, Node *backedge) | ||||
357 | : BaseCountedLoopNode(entry, backedge) { | ||||
358 | init_class_id(Class_LongCountedLoop); | ||||
359 | } | ||||
360 | |||||
361 | virtual int Opcode() const; | ||||
362 | |||||
363 | virtual BasicType bt() const { | ||||
364 | return T_LONG; | ||||
365 | } | ||||
366 | |||||
367 | LongCountedLoopEndNode* loopexit_or_null() const { return (LongCountedLoopEndNode*) BaseCountedLoopNode::loopexit_or_null(); } | ||||
368 | LongCountedLoopEndNode* loopexit() const { return (LongCountedLoopEndNode*) BaseCountedLoopNode::loopexit(); } | ||||
369 | }; | ||||
370 | |||||
371 | |||||
372 | //------------------------------CountedLoopEndNode----------------------------- | ||||
373 | // CountedLoopEndNodes end simple trip counted loops. They act much like | ||||
374 | // IfNodes. | ||||
375 | |||||
376 | class BaseCountedLoopEndNode : public IfNode { | ||||
377 | public: | ||||
378 | enum { TestControl, TestValue }; | ||||
379 | BaseCountedLoopEndNode(Node *control, Node *test, float prob, float cnt) | ||||
380 | : IfNode(control, test, prob, cnt) { | ||||
381 | init_class_id(Class_BaseCountedLoopEnd); | ||||
382 | } | ||||
383 | |||||
384 | Node *cmp_node() const { return (in(TestValue)->req() >=2) ? in(TestValue)->in(1) : NULL__null; } | ||||
385 | Node* incr() const { Node* tmp = cmp_node(); return (tmp && tmp->req() == 3) ? tmp->in(1) : NULL__null; } | ||||
386 | Node* limit() const { Node* tmp = cmp_node(); return (tmp && tmp->req() == 3) ? tmp->in(2) : NULL__null; } | ||||
387 | Node* stride() const { Node* tmp = incr(); return (tmp && tmp->req() == 3) ? tmp->in(2) : NULL__null; } | ||||
388 | Node* init_trip() const { Node* tmp = phi(); return (tmp && tmp->req() == 3) ? tmp->in(1) : NULL__null; } | ||||
389 | bool stride_is_con() const { Node *tmp = stride(); return (tmp != NULL__null && tmp->is_Con()); } | ||||
390 | |||||
391 | PhiNode* phi() const { | ||||
392 | Node* tmp = incr(); | ||||
393 | if (tmp && tmp->req() == 3) { | ||||
394 | Node* phi = tmp->in(1); | ||||
395 | if (phi->is_Phi()) { | ||||
396 | return phi->as_Phi(); | ||||
397 | } | ||||
398 | } | ||||
399 | return NULL__null; | ||||
400 | } | ||||
401 | |||||
402 | BaseCountedLoopNode* loopnode() const { | ||||
403 | // The CountedLoopNode that goes with this CountedLoopEndNode may | ||||
404 | // have been optimized out by the IGVN so be cautious with the | ||||
405 | // pattern matching on the graph | ||||
406 | PhiNode* iv_phi = phi(); | ||||
407 | if (iv_phi == NULL__null) { | ||||
408 | return NULL__null; | ||||
409 | } | ||||
410 | Node* ln = iv_phi->in(0); | ||||
411 | if (!ln->is_BaseCountedLoop() || ln->as_BaseCountedLoop()->loopexit_or_null() != this) { | ||||
412 | return NULL__null; | ||||
413 | } | ||||
414 | if (ln->as_BaseCountedLoop()->bt() != bt()) { | ||||
415 | return NULL__null; | ||||
416 | } | ||||
417 | return ln->as_BaseCountedLoop(); | ||||
418 | } | ||||
419 | |||||
420 | BoolTest::mask test_trip() const { return in(TestValue)->as_Bool()->_test._test; } | ||||
421 | |||||
422 | jlong stride_con() const; | ||||
423 | virtual BasicType bt() const = 0; | ||||
424 | |||||
425 | static BaseCountedLoopEndNode* make(Node* control, Node* test, float prob, float cnt, BasicType bt); | ||||
426 | }; | ||||
427 | |||||
428 | class CountedLoopEndNode : public BaseCountedLoopEndNode { | ||||
429 | public: | ||||
430 | |||||
431 | CountedLoopEndNode(Node *control, Node *test, float prob, float cnt) | ||||
432 | : BaseCountedLoopEndNode(control, test, prob, cnt) { | ||||
433 | init_class_id(Class_CountedLoopEnd); | ||||
434 | } | ||||
435 | virtual int Opcode() const; | ||||
436 | |||||
437 | CountedLoopNode* loopnode() const { | ||||
438 | return (CountedLoopNode*) BaseCountedLoopEndNode::loopnode(); | ||||
439 | } | ||||
440 | |||||
441 | virtual BasicType bt() const { | ||||
442 | return T_INT; | ||||
443 | } | ||||
444 | |||||
445 | #ifndef PRODUCT | ||||
446 | virtual void dump_spec(outputStream *st) const; | ||||
447 | #endif | ||||
448 | }; | ||||
449 | |||||
450 | class LongCountedLoopEndNode : public BaseCountedLoopEndNode { | ||||
451 | public: | ||||
452 | LongCountedLoopEndNode(Node *control, Node *test, float prob, float cnt) | ||||
453 | : BaseCountedLoopEndNode(control, test, prob, cnt) { | ||||
454 | init_class_id(Class_LongCountedLoopEnd); | ||||
455 | } | ||||
456 | |||||
457 | LongCountedLoopNode* loopnode() const { | ||||
458 | return (LongCountedLoopNode*) BaseCountedLoopEndNode::loopnode(); | ||||
459 | } | ||||
460 | |||||
461 | virtual int Opcode() const; | ||||
462 | |||||
463 | virtual BasicType bt() const { | ||||
464 | return T_LONG; | ||||
465 | } | ||||
466 | }; | ||||
467 | |||||
468 | |||||
469 | inline BaseCountedLoopEndNode* BaseCountedLoopNode::loopexit_or_null() const { | ||||
470 | Node* bctrl = back_control(); | ||||
471 | if (bctrl == NULL__null) return NULL__null; | ||||
472 | |||||
473 | Node* lexit = bctrl->in(0); | ||||
474 | if (!lexit->is_BaseCountedLoopEnd()) { | ||||
475 | return NULL__null; | ||||
476 | } | ||||
477 | BaseCountedLoopEndNode* result = lexit->as_BaseCountedLoopEnd(); | ||||
478 | if (result->bt() != bt()) { | ||||
479 | return NULL__null; | ||||
480 | } | ||||
481 | return result; | ||||
482 | } | ||||
483 | |||||
484 | inline BaseCountedLoopEndNode* BaseCountedLoopNode::loopexit() const { | ||||
485 | BaseCountedLoopEndNode* cle = loopexit_or_null(); | ||||
486 | assert(cle != NULL, "loopexit is NULL")do { if (!(cle != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 486, "assert(" "cle != __null" ") failed", "loopexit is NULL" ); ::breakpoint(); } } while (0); | ||||
487 | return cle; | ||||
488 | } | ||||
489 | |||||
490 | inline Node* BaseCountedLoopNode::init_trip() const { | ||||
491 | BaseCountedLoopEndNode* cle = loopexit_or_null(); | ||||
492 | return cle != NULL__null ? cle->init_trip() : NULL__null; | ||||
493 | } | ||||
494 | inline Node* BaseCountedLoopNode::stride() const { | ||||
495 | BaseCountedLoopEndNode* cle = loopexit_or_null(); | ||||
496 | return cle != NULL__null ? cle->stride() : NULL__null; | ||||
497 | } | ||||
498 | |||||
499 | inline bool BaseCountedLoopNode::stride_is_con() const { | ||||
500 | BaseCountedLoopEndNode* cle = loopexit_or_null(); | ||||
501 | return cle != NULL__null && cle->stride_is_con(); | ||||
502 | } | ||||
503 | inline Node* BaseCountedLoopNode::limit() const { | ||||
504 | BaseCountedLoopEndNode* cle = loopexit_or_null(); | ||||
505 | return cle != NULL__null ? cle->limit() : NULL__null; | ||||
506 | } | ||||
507 | inline Node* BaseCountedLoopNode::incr() const { | ||||
508 | BaseCountedLoopEndNode* cle = loopexit_or_null(); | ||||
509 | return cle != NULL__null ? cle->incr() : NULL__null; | ||||
510 | } | ||||
511 | inline Node* BaseCountedLoopNode::phi() const { | ||||
512 | BaseCountedLoopEndNode* cle = loopexit_or_null(); | ||||
513 | return cle != NULL__null ? cle->phi() : NULL__null; | ||||
514 | } | ||||
515 | |||||
516 | inline jlong BaseCountedLoopNode::stride_con() const { | ||||
517 | BaseCountedLoopEndNode* cle = loopexit_or_null(); | ||||
518 | return cle != NULL__null ? cle->stride_con() : 0; | ||||
519 | } | ||||
520 | |||||
521 | |||||
522 | //------------------------------LoopLimitNode----------------------------- | ||||
523 | // Counted Loop limit node which represents exact final iterator value: | ||||
524 | // trip_count = (limit - init_trip + stride - 1)/stride | ||||
525 | // final_value= trip_count * stride + init_trip. | ||||
526 | // Use HW instructions to calculate it when it can overflow in integer. | ||||
527 | // Note, final_value should fit into integer since counted loop has | ||||
528 | // limit check: limit <= max_int-stride. | ||||
529 | class LoopLimitNode : public Node { | ||||
530 | enum { Init=1, Limit=2, Stride=3 }; | ||||
531 | public: | ||||
532 | LoopLimitNode( Compile* C, Node *init, Node *limit, Node *stride ) : Node(0,init,limit,stride) { | ||||
533 | // Put it on the Macro nodes list to optimize during macro nodes expansion. | ||||
534 | init_flags(Flag_is_macro); | ||||
535 | C->add_macro_node(this); | ||||
536 | } | ||||
537 | virtual int Opcode() const; | ||||
538 | virtual const Type *bottom_type() const { return TypeInt::INT; } | ||||
539 | virtual uint ideal_reg() const { return Op_RegI; } | ||||
540 | virtual const Type* Value(PhaseGVN* phase) const; | ||||
541 | virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | ||||
542 | virtual Node* Identity(PhaseGVN* phase); | ||||
543 | }; | ||||
544 | |||||
545 | // Support for strip mining | ||||
546 | class OuterStripMinedLoopNode : public LoopNode { | ||||
547 | private: | ||||
548 | CountedLoopNode* inner_loop() const; | ||||
549 | public: | ||||
550 | OuterStripMinedLoopNode(Compile* C, Node *entry, Node *backedge) | ||||
551 | : LoopNode(entry, backedge) { | ||||
552 | init_class_id(Class_OuterStripMinedLoop); | ||||
553 | init_flags(Flag_is_macro); | ||||
554 | C->add_macro_node(this); | ||||
555 | } | ||||
556 | |||||
557 | virtual int Opcode() const; | ||||
558 | |||||
559 | virtual IfTrueNode* outer_loop_tail() const; | ||||
560 | virtual OuterStripMinedLoopEndNode* outer_loop_end() const; | ||||
561 | virtual IfFalseNode* outer_loop_exit() const; | ||||
562 | virtual SafePointNode* outer_safepoint() const; | ||||
563 | void adjust_strip_mined_loop(PhaseIterGVN* igvn); | ||||
564 | }; | ||||
565 | |||||
566 | class OuterStripMinedLoopEndNode : public IfNode { | ||||
567 | public: | ||||
568 | OuterStripMinedLoopEndNode(Node *control, Node *test, float prob, float cnt) | ||||
569 | : IfNode(control, test, prob, cnt) { | ||||
570 | init_class_id(Class_OuterStripMinedLoopEnd); | ||||
571 | } | ||||
572 | |||||
573 | virtual int Opcode() const; | ||||
574 | |||||
575 | virtual const Type* Value(PhaseGVN* phase) const; | ||||
576 | virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | ||||
577 | |||||
578 | bool is_expanded(PhaseGVN *phase) const; | ||||
579 | }; | ||||
580 | |||||
581 | // -----------------------------IdealLoopTree---------------------------------- | ||||
582 | class IdealLoopTree : public ResourceObj { | ||||
583 | public: | ||||
584 | IdealLoopTree *_parent; // Parent in loop tree | ||||
585 | IdealLoopTree *_next; // Next sibling in loop tree | ||||
586 | IdealLoopTree *_child; // First child in loop tree | ||||
587 | |||||
588 | // The head-tail backedge defines the loop. | ||||
589 | // If a loop has multiple backedges, this is addressed during cleanup where | ||||
590 | // we peel off the multiple backedges, merging all edges at the bottom and | ||||
591 | // ensuring that one proper backedge flow into the loop. | ||||
592 | Node *_head; // Head of loop | ||||
593 | Node *_tail; // Tail of loop | ||||
594 | inline Node *tail(); // Handle lazy update of _tail field | ||||
595 | inline Node *head(); // Handle lazy update of _head field | ||||
596 | PhaseIdealLoop* _phase; | ||||
597 | int _local_loop_unroll_limit; | ||||
598 | int _local_loop_unroll_factor; | ||||
599 | |||||
600 | Node_List _body; // Loop body for inner loops | ||||
601 | |||||
602 | uint16_t _nest; // Nesting depth | ||||
603 | uint8_t _irreducible:1, // True if irreducible | ||||
604 | _has_call:1, // True if has call safepoint | ||||
605 | _has_sfpt:1, // True if has non-call safepoint | ||||
606 | _rce_candidate:1; // True if candidate for range check elimination | ||||
607 | |||||
608 | Node_List* _safepts; // List of safepoints in this loop | ||||
609 | Node_List* _required_safept; // A inner loop cannot delete these safepts; | ||||
610 | bool _allow_optimizations; // Allow loop optimizations | ||||
611 | |||||
612 | IdealLoopTree( PhaseIdealLoop* phase, Node *head, Node *tail ) | ||||
613 | : _parent(0), _next(0), _child(0), | ||||
614 | _head(head), _tail(tail), | ||||
615 | _phase(phase), | ||||
616 | _local_loop_unroll_limit(0), _local_loop_unroll_factor(0), | ||||
617 | _nest(0), _irreducible(0), _has_call(0), _has_sfpt(0), _rce_candidate(0), | ||||
618 | _safepts(NULL__null), | ||||
619 | _required_safept(NULL__null), | ||||
620 | _allow_optimizations(true) | ||||
621 | { | ||||
622 | precond(_head != NULL)do { if (!(_head != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 622, "assert(" "_head != __null" ") failed", "precond"); :: breakpoint(); } } while (0); | ||||
623 | precond(_tail != NULL)do { if (!(_tail != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 623, "assert(" "_tail != __null" ") failed", "precond"); :: breakpoint(); } } while (0); | ||||
624 | } | ||||
625 | |||||
626 | // Is 'l' a member of 'this'? | ||||
627 | bool is_member(const IdealLoopTree *l) const; // Test for nested membership | ||||
628 | |||||
629 | // Set loop nesting depth. Accumulate has_call bits. | ||||
630 | int set_nest( uint depth ); | ||||
631 | |||||
632 | // Split out multiple fall-in edges from the loop header. Move them to a | ||||
633 | // private RegionNode before the loop. This becomes the loop landing pad. | ||||
634 | void split_fall_in( PhaseIdealLoop *phase, int fall_in_cnt ); | ||||
635 | |||||
636 | // Split out the outermost loop from this shared header. | ||||
637 | void split_outer_loop( PhaseIdealLoop *phase ); | ||||
638 | |||||
639 | // Merge all the backedges from the shared header into a private Region. | ||||
640 | // Feed that region as the one backedge to this loop. | ||||
641 | void merge_many_backedges( PhaseIdealLoop *phase ); | ||||
642 | |||||
643 | // Split shared headers and insert loop landing pads. | ||||
644 | // Insert a LoopNode to replace the RegionNode. | ||||
645 | // Returns TRUE if loop tree is structurally changed. | ||||
646 | bool beautify_loops( PhaseIdealLoop *phase ); | ||||
647 | |||||
648 | // Perform optimization to use the loop predicates for null checks and range checks. | ||||
649 | // Applies to any loop level (not just the innermost one) | ||||
650 | bool loop_predication( PhaseIdealLoop *phase); | ||||
651 | |||||
652 | // Perform iteration-splitting on inner loops. Split iterations to | ||||
653 | // avoid range checks or one-shot null checks. Returns false if the | ||||
654 | // current round of loop opts should stop. | ||||
655 | bool iteration_split( PhaseIdealLoop *phase, Node_List &old_new ); | ||||
656 | |||||
657 | // Driver for various flavors of iteration splitting. Returns false | ||||
658 | // if the current round of loop opts should stop. | ||||
659 | bool iteration_split_impl( PhaseIdealLoop *phase, Node_List &old_new ); | ||||
660 | |||||
661 | // Given dominators, try to find loops with calls that must always be | ||||
662 | // executed (call dominates loop tail). These loops do not need non-call | ||||
663 | // safepoints (ncsfpt). | ||||
664 | void check_safepts(VectorSet &visited, Node_List &stack); | ||||
665 | |||||
666 | // Allpaths backwards scan from loop tail, terminating each path at first safepoint | ||||
667 | // encountered. | ||||
668 | void allpaths_check_safepts(VectorSet &visited, Node_List &stack); | ||||
669 | |||||
670 | // Remove safepoints from loop. Optionally keeping one. | ||||
671 | void remove_safepoints(PhaseIdealLoop* phase, bool keep_one); | ||||
672 | |||||
673 | // Convert to counted loops where possible | ||||
674 | void counted_loop( PhaseIdealLoop *phase ); | ||||
675 | |||||
676 | // Check for Node being a loop-breaking test | ||||
677 | Node *is_loop_exit(Node *iff) const; | ||||
678 | |||||
679 | // Remove simplistic dead code from loop body | ||||
680 | void DCE_loop_body(); | ||||
681 | |||||
682 | // Look for loop-exit tests with my 50/50 guesses from the Parsing stage. | ||||
683 | // Replace with a 1-in-10 exit guess. | ||||
684 | void adjust_loop_exit_prob( PhaseIdealLoop *phase ); | ||||
685 | |||||
686 | // Return TRUE or FALSE if the loop should never be RCE'd or aligned. | ||||
687 | // Useful for unrolling loops with NO array accesses. | ||||
688 | bool policy_peel_only( PhaseIdealLoop *phase ) const; | ||||
689 | |||||
690 | // Return TRUE or FALSE if the loop should be unswitched -- clone | ||||
691 | // loop with an invariant test | ||||
692 | bool policy_unswitching( PhaseIdealLoop *phase ) const; | ||||
693 | |||||
694 | // Micro-benchmark spamming. Remove empty loops. | ||||
695 | bool do_remove_empty_loop( PhaseIdealLoop *phase ); | ||||
696 | |||||
697 | // Convert one iteration loop into normal code. | ||||
698 | bool do_one_iteration_loop( PhaseIdealLoop *phase ); | ||||
699 | |||||
700 | // Return TRUE or FALSE if the loop should be peeled or not. Peel if we can | ||||
701 | // move some loop-invariant test (usually a null-check) before the loop. | ||||
702 | bool policy_peeling(PhaseIdealLoop *phase); | ||||
703 | |||||
704 | uint estimate_peeling(PhaseIdealLoop *phase); | ||||
705 | |||||
706 | // Return TRUE or FALSE if the loop should be maximally unrolled. Stash any | ||||
707 | // known trip count in the counted loop node. | ||||
708 | bool policy_maximally_unroll(PhaseIdealLoop *phase) const; | ||||
709 | |||||
710 | // Return TRUE or FALSE if the loop should be unrolled or not. Apply unroll | ||||
711 | // if the loop is a counted loop and the loop body is small enough. | ||||
712 | bool policy_unroll(PhaseIdealLoop *phase); | ||||
713 | |||||
714 | // Loop analyses to map to a maximal superword unrolling for vectorization. | ||||
715 | void policy_unroll_slp_analysis(CountedLoopNode *cl, PhaseIdealLoop *phase, int future_unroll_ct); | ||||
716 | |||||
717 | // Return TRUE or FALSE if the loop should be range-check-eliminated. | ||||
718 | // Gather a list of IF tests that are dominated by iteration splitting; | ||||
719 | // also gather the end of the first split and the start of the 2nd split. | ||||
720 | bool policy_range_check(PhaseIdealLoop* phase, bool provisional, BasicType bt) const; | ||||
721 | |||||
722 | // Return TRUE if "iff" is a range check. | ||||
723 | bool is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar DEBUG_ONLY(COMMA ProjNode *predicate_proj), ProjNode *predicate_proj) const; | ||||
724 | bool is_range_check_if(IfNode* iff, PhaseIdealLoop* phase, BasicType bt, Node* iv, Node*& range, Node*& offset, | ||||
725 | jlong& scale) const; | ||||
726 | |||||
727 | // Estimate the number of nodes required when cloning a loop (body). | ||||
728 | uint est_loop_clone_sz(uint factor) const; | ||||
729 | // Estimate the number of nodes required when unrolling a loop (body). | ||||
730 | uint est_loop_unroll_sz(uint factor) const; | ||||
731 | |||||
732 | // Compute loop trip count if possible | ||||
733 | void compute_trip_count(PhaseIdealLoop* phase); | ||||
734 | |||||
735 | // Compute loop trip count from profile data | ||||
736 | float compute_profile_trip_cnt_helper(Node* n); | ||||
737 | void compute_profile_trip_cnt( PhaseIdealLoop *phase ); | ||||
738 | |||||
739 | // Reassociate invariant expressions. | ||||
740 | void reassociate_invariants(PhaseIdealLoop *phase); | ||||
741 | // Reassociate invariant binary expressions. | ||||
742 | Node* reassociate(Node* n1, PhaseIdealLoop *phase); | ||||
743 | // Reassociate invariant add and subtract expressions. | ||||
744 | Node* reassociate_add_sub(Node* n1, int inv1_idx, int inv2_idx, PhaseIdealLoop *phase); | ||||
745 | // Return nonzero index of invariant operand if invariant and variant | ||||
746 | // are combined with an associative binary. Helper for reassociate_invariants. | ||||
747 | int find_invariant(Node* n, PhaseIdealLoop *phase); | ||||
748 | // Return TRUE if "n" is associative. | ||||
749 | bool is_associative(Node* n, Node* base=NULL__null); | ||||
750 | |||||
751 | // Return true if n is invariant | ||||
752 | bool is_invariant(Node* n) const; | ||||
753 | |||||
754 | // Put loop body on igvn work list | ||||
755 | void record_for_igvn(); | ||||
756 | |||||
757 | bool is_root() { return _parent == NULL__null; } | ||||
758 | // A proper/reducible loop w/o any (occasional) dead back-edge. | ||||
759 | bool is_loop() { return !_irreducible && !tail()->is_top(); } | ||||
760 | bool is_counted() { return is_loop() && _head->is_CountedLoop(); } | ||||
761 | bool is_innermost() { return is_loop() && _child == NULL__null; } | ||||
762 | |||||
763 | void remove_main_post_loops(CountedLoopNode *cl, PhaseIdealLoop *phase); | ||||
764 | |||||
765 | #ifndef PRODUCT | ||||
766 | void dump_head() const; // Dump loop head only | ||||
767 | void dump() const; // Dump this loop recursively | ||||
768 | void verify_tree(IdealLoopTree *loop, const IdealLoopTree *parent) const; | ||||
769 | #endif | ||||
770 | |||||
771 | private: | ||||
772 | enum { EMPTY_LOOP_SIZE = 7 }; // Number of nodes in an empty loop. | ||||
773 | |||||
774 | // Estimate the number of nodes resulting from control and data flow merge. | ||||
775 | uint est_loop_flow_merge_sz() const; | ||||
776 | }; | ||||
777 | |||||
778 | // -----------------------------PhaseIdealLoop--------------------------------- | ||||
779 | // Computes the mapping from Nodes to IdealLoopTrees. Organizes IdealLoopTrees | ||||
780 | // into a loop tree. Drives the loop-based transformations on the ideal graph. | ||||
781 | class PhaseIdealLoop : public PhaseTransform { | ||||
782 | friend class IdealLoopTree; | ||||
783 | friend class SuperWord; | ||||
784 | friend class CountedLoopReserveKit; | ||||
785 | friend class ShenandoahBarrierC2Support; | ||||
786 | friend class AutoNodeBudget; | ||||
787 | |||||
788 | // Pre-computed def-use info | ||||
789 | PhaseIterGVN &_igvn; | ||||
790 | |||||
791 | // Head of loop tree | ||||
792 | IdealLoopTree* _ltree_root; | ||||
793 | |||||
794 | // Array of pre-order numbers, plus post-visited bit. | ||||
795 | // ZERO for not pre-visited. EVEN for pre-visited but not post-visited. | ||||
796 | // ODD for post-visited. Other bits are the pre-order number. | ||||
797 | uint *_preorders; | ||||
798 | uint _max_preorder; | ||||
799 | |||||
800 | const PhaseIdealLoop* _verify_me; | ||||
801 | bool _verify_only; | ||||
802 | |||||
803 | // Allocate _preorders[] array | ||||
804 | void allocate_preorders() { | ||||
805 | _max_preorder = C->unique()+8; | ||||
806 | _preorders = NEW_RESOURCE_ARRAY(uint, _max_preorder)(uint*) resource_allocate_bytes((_max_preorder) * sizeof(uint )); | ||||
807 | memset(_preorders, 0, sizeof(uint) * _max_preorder); | ||||
808 | } | ||||
809 | |||||
810 | // Allocate _preorders[] array | ||||
811 | void reallocate_preorders() { | ||||
812 | if ( _max_preorder < C->unique() ) { | ||||
813 | _preorders = REALLOC_RESOURCE_ARRAY(uint, _preorders, _max_preorder, C->unique())(uint*) resource_reallocate_bytes((char*)(_preorders), (_max_preorder ) * sizeof(uint), (C->unique()) * sizeof(uint)); | ||||
814 | _max_preorder = C->unique(); | ||||
815 | } | ||||
816 | memset(_preorders, 0, sizeof(uint) * _max_preorder); | ||||
817 | } | ||||
818 | |||||
819 | // Check to grow _preorders[] array for the case when build_loop_tree_impl() | ||||
820 | // adds new nodes. | ||||
821 | void check_grow_preorders( ) { | ||||
822 | if ( _max_preorder < C->unique() ) { | ||||
823 | uint newsize = _max_preorder<<1; // double size of array | ||||
824 | _preorders = REALLOC_RESOURCE_ARRAY(uint, _preorders, _max_preorder, newsize)(uint*) resource_reallocate_bytes((char*)(_preorders), (_max_preorder ) * sizeof(uint), (newsize) * sizeof(uint)); | ||||
825 | memset(&_preorders[_max_preorder],0,sizeof(uint)*(newsize-_max_preorder)); | ||||
826 | _max_preorder = newsize; | ||||
827 | } | ||||
828 | } | ||||
829 | // Check for pre-visited. Zero for NOT visited; non-zero for visited. | ||||
830 | int is_visited( Node *n ) const { return _preorders[n->_idx]; } | ||||
831 | // Pre-order numbers are written to the Nodes array as low-bit-set values. | ||||
832 | void set_preorder_visited( Node *n, int pre_order ) { | ||||
833 | assert( !is_visited( n ), "already set" )do { if (!(!is_visited( n ))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 833, "assert(" "!is_visited( n )" ") failed", "already set" ); ::breakpoint(); } } while (0); | ||||
834 | _preorders[n->_idx] = (pre_order<<1); | ||||
835 | }; | ||||
836 | // Return pre-order number. | ||||
837 | int get_preorder( Node *n ) const { assert( is_visited(n), "" )do { if (!(is_visited(n))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 837, "assert(" "is_visited(n)" ") failed", ""); ::breakpoint (); } } while (0); return _preorders[n->_idx]>>1; } | ||||
838 | |||||
839 | // Check for being post-visited. | ||||
840 | // Should be previsited already (checked with assert(is_visited(n))). | ||||
841 | int is_postvisited( Node *n ) const { assert( is_visited(n), "" )do { if (!(is_visited(n))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 841, "assert(" "is_visited(n)" ") failed", ""); ::breakpoint (); } } while (0); return _preorders[n->_idx]&1; } | ||||
842 | |||||
843 | // Mark as post visited | ||||
844 | void set_postvisited( Node *n ) { assert( !is_postvisited( n ), "" )do { if (!(!is_postvisited( n ))) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 844, "assert(" "!is_postvisited( n )" ") failed", ""); ::breakpoint (); } } while (0); _preorders[n->_idx] |= 1; } | ||||
845 | |||||
846 | public: | ||||
847 | // Set/get control node out. Set lower bit to distinguish from IdealLoopTree | ||||
848 | // Returns true if "n" is a data node, false if it's a control node. | ||||
849 | bool has_ctrl( Node *n ) const { return ((intptr_t)_nodes[n->_idx]) & 1; } | ||||
850 | |||||
851 | private: | ||||
852 | // clear out dead code after build_loop_late | ||||
853 | Node_List _deadlist; | ||||
854 | |||||
855 | // Support for faster execution of get_late_ctrl()/dom_lca() | ||||
856 | // when a node has many uses and dominator depth is deep. | ||||
857 | GrowableArray<jlong> _dom_lca_tags; | ||||
858 | uint _dom_lca_tags_round; | ||||
859 | void init_dom_lca_tags(); | ||||
860 | |||||
861 | // Helper for debugging bad dominance relationships | ||||
862 | bool verify_dominance(Node* n, Node* use, Node* LCA, Node* early); | ||||
863 | |||||
864 | Node* compute_lca_of_uses(Node* n, Node* early, bool verify = false); | ||||
865 | |||||
866 | // Inline wrapper for frequent cases: | ||||
867 | // 1) only one use | ||||
868 | // 2) a use is the same as the current LCA passed as 'n1' | ||||
869 | Node *dom_lca_for_get_late_ctrl( Node *lca, Node *n, Node *tag ) { | ||||
870 | assert( n->is_CFG(), "" )do { if (!(n->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 870, "assert(" "n->is_CFG()" ") failed", ""); ::breakpoint (); } } while (0); | ||||
871 | // Fast-path NULL lca | ||||
872 | if( lca != NULL__null && lca != n ) { | ||||
873 | assert( lca->is_CFG(), "" )do { if (!(lca->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 873, "assert(" "lca->is_CFG()" ") failed", ""); ::breakpoint (); } } while (0); | ||||
874 | // find LCA of all uses | ||||
875 | n = dom_lca_for_get_late_ctrl_internal( lca, n, tag ); | ||||
876 | } | ||||
877 | return find_non_split_ctrl(n); | ||||
878 | } | ||||
879 | Node *dom_lca_for_get_late_ctrl_internal( Node *lca, Node *n, Node *tag ); | ||||
880 | |||||
881 | // Helper function for directing control inputs away from CFG split points. | ||||
882 | Node *find_non_split_ctrl( Node *ctrl ) const { | ||||
883 | if (ctrl
| ||||
884 | if (ctrl->is_MultiBranch()) { | ||||
885 | ctrl = ctrl->in(0); | ||||
886 | } | ||||
887 | assert(ctrl->is_CFG(), "CFG")do { if (!(ctrl->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 887, "assert(" "ctrl->is_CFG()" ") failed", "CFG"); ::breakpoint (); } } while (0); | ||||
888 | } | ||||
889 | return ctrl; | ||||
890 | } | ||||
891 | |||||
892 | Node* cast_incr_before_loop(Node* incr, Node* ctrl, Node* loop); | ||||
893 | |||||
894 | #ifdef ASSERT1 | ||||
895 | void ensure_zero_trip_guard_proj(Node* node, bool is_main_loop); | ||||
896 | #endif | ||||
897 | void copy_skeleton_predicates_to_main_loop_helper(Node* predicate, Node* init, Node* stride, IdealLoopTree* outer_loop, LoopNode* outer_main_head, | ||||
898 | uint dd_main_head, const uint idx_before_pre_post, const uint idx_after_post_before_pre, | ||||
899 | Node* zero_trip_guard_proj_main, Node* zero_trip_guard_proj_post, const Node_List &old_new); | ||||
900 | void copy_skeleton_predicates_to_main_loop(CountedLoopNode* pre_head, Node* init, Node* stride, IdealLoopTree* outer_loop, LoopNode* outer_main_head, | ||||
901 | uint dd_main_head, const uint idx_before_pre_post, const uint idx_after_post_before_pre, | ||||
902 | Node* zero_trip_guard_proj_main, Node* zero_trip_guard_proj_post, const Node_List &old_new); | ||||
903 | Node* clone_skeleton_predicate_for_main_or_post_loop(Node* iff, Node* new_init, Node* new_stride, Node* predicate, Node* uncommon_proj, Node* control, | ||||
904 | IdealLoopTree* outer_loop, Node* input_proj); | ||||
905 | Node* clone_skeleton_predicate_bool(Node* iff, Node* new_init, Node* new_stride, Node* control); | ||||
906 | static bool skeleton_predicate_has_opaque(IfNode* iff); | ||||
907 | static void get_skeleton_predicates(Node* predicate, Unique_Node_List& list, bool get_opaque = false); | ||||
908 | void update_main_loop_skeleton_predicates(Node* ctrl, CountedLoopNode* loop_head, Node* init, int stride_con); | ||||
909 | void copy_skeleton_predicates_to_post_loop(LoopNode* main_loop_head, CountedLoopNode* post_loop_head, Node* init, Node* stride); | ||||
910 | void insert_loop_limit_check(ProjNode* limit_check_proj, Node* cmp_limit, Node* bol); | ||||
911 | #ifdef ASSERT1 | ||||
912 | bool only_has_infinite_loops(); | ||||
913 | #endif | ||||
914 | |||||
915 | void log_loop_tree(); | ||||
916 | |||||
917 | public: | ||||
918 | |||||
919 | PhaseIterGVN &igvn() const { return _igvn; } | ||||
920 | |||||
921 | bool has_node( Node* n ) const { | ||||
922 | guarantee(n != NULL, "No Node.")do { if (!(n != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 922, "guarantee(" "n != NULL" ") failed", "No Node."); ::breakpoint (); } } while (0); | ||||
923 | return _nodes[n->_idx] != NULL__null; | ||||
924 | } | ||||
925 | // check if transform created new nodes that need _ctrl recorded | ||||
926 | Node *get_late_ctrl( Node *n, Node *early ); | ||||
927 | Node *get_early_ctrl( Node *n ); | ||||
928 | Node *get_early_ctrl_for_expensive(Node *n, Node* earliest); | ||||
929 | void set_early_ctrl(Node* n, bool update_body); | ||||
930 | void set_subtree_ctrl(Node* n, bool update_body); | ||||
931 | void set_ctrl( Node *n, Node *ctrl ) { | ||||
932 | assert( !has_node(n) || has_ctrl(n), "" )do { if (!(!has_node(n) || has_ctrl(n))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 932, "assert(" "!has_node(n) || has_ctrl(n)" ") failed", "" ); ::breakpoint(); } } while (0); | ||||
933 | assert( ctrl->in(0), "cannot set dead control node" )do { if (!(ctrl->in(0))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 933, "assert(" "ctrl->in(0)" ") failed", "cannot set dead control node" ); ::breakpoint(); } } while (0); | ||||
934 | assert( ctrl == find_non_split_ctrl(ctrl), "must set legal crtl" )do { if (!(ctrl == find_non_split_ctrl(ctrl))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 934, "assert(" "ctrl == find_non_split_ctrl(ctrl)" ") failed" , "must set legal crtl"); ::breakpoint(); } } while (0); | ||||
935 | _nodes.map( n->_idx, (Node*)((intptr_t)ctrl + 1) ); | ||||
936 | } | ||||
937 | // Set control and update loop membership | ||||
938 | void set_ctrl_and_loop(Node* n, Node* ctrl) { | ||||
939 | IdealLoopTree* old_loop = get_loop(get_ctrl(n)); | ||||
940 | IdealLoopTree* new_loop = get_loop(ctrl); | ||||
941 | if (old_loop != new_loop) { | ||||
942 | if (old_loop->_child == NULL__null) old_loop->_body.yank(n); | ||||
943 | if (new_loop->_child == NULL__null) new_loop->_body.push(n); | ||||
944 | } | ||||
945 | set_ctrl(n, ctrl); | ||||
946 | } | ||||
947 | // Control nodes can be replaced or subsumed. During this pass they | ||||
948 | // get their replacement Node in slot 1. Instead of updating the block | ||||
949 | // location of all Nodes in the subsumed block, we lazily do it. As we | ||||
950 | // pull such a subsumed block out of the array, we write back the final | ||||
951 | // correct block. | ||||
952 | Node *get_ctrl( Node *i ) { | ||||
953 | |||||
954 | assert(has_node(i), "")do { if (!(has_node(i))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 954, "assert(" "has_node(i)" ") failed", ""); ::breakpoint( ); } } while (0); | ||||
955 | Node *n = get_ctrl_no_update(i); | ||||
956 | _nodes.map( i->_idx, (Node*)((intptr_t)n + 1) ); | ||||
957 | assert(has_node(i) && has_ctrl(i), "")do { if (!(has_node(i) && has_ctrl(i))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 957, "assert(" "has_node(i) && has_ctrl(i)" ") failed" , ""); ::breakpoint(); } } while (0); | ||||
958 | assert(n == find_non_split_ctrl(n), "must return legal ctrl" )do { if (!(n == find_non_split_ctrl(n))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 958, "assert(" "n == find_non_split_ctrl(n)" ") failed", "must return legal ctrl" ); ::breakpoint(); } } while (0); | ||||
959 | return n; | ||||
960 | } | ||||
961 | // true if CFG node d dominates CFG node n | ||||
962 | bool is_dominator(Node *d, Node *n); | ||||
963 | // return get_ctrl for a data node and self(n) for a CFG node | ||||
964 | Node* ctrl_or_self(Node* n) { | ||||
965 | if (has_ctrl(n)) | ||||
966 | return get_ctrl(n); | ||||
967 | else { | ||||
968 | assert (n->is_CFG(), "must be a CFG node")do { if (!(n->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 968, "assert(" "n->is_CFG()" ") failed", "must be a CFG node" ); ::breakpoint(); } } while (0); | ||||
969 | return n; | ||||
970 | } | ||||
971 | } | ||||
972 | |||||
973 | Node *get_ctrl_no_update_helper(Node *i) const { | ||||
974 | assert(has_ctrl(i), "should be control, not loop")do { if (!(has_ctrl(i))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 974, "assert(" "has_ctrl(i)" ") failed", "should be control, not loop" ); ::breakpoint(); } } while (0); | ||||
975 | return (Node*)(((intptr_t)_nodes[i->_idx]) & ~1); | ||||
976 | } | ||||
977 | |||||
978 | Node *get_ctrl_no_update(Node *i) const { | ||||
979 | assert( has_ctrl(i), "" )do { if (!(has_ctrl(i))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 979, "assert(" "has_ctrl(i)" ") failed", ""); ::breakpoint( ); } } while (0); | ||||
980 | Node *n = get_ctrl_no_update_helper(i); | ||||
981 | if (!n->in(0)) { | ||||
982 | // Skip dead CFG nodes | ||||
983 | do { | ||||
984 | n = get_ctrl_no_update_helper(n); | ||||
985 | } while (!n->in(0)); | ||||
986 | n = find_non_split_ctrl(n); | ||||
987 | } | ||||
988 | return n; | ||||
989 | } | ||||
990 | |||||
991 | // Check for loop being set | ||||
992 | // "n" must be a control node. Returns true if "n" is known to be in a loop. | ||||
993 | bool has_loop( Node *n ) const { | ||||
994 | assert(!has_node(n) || !has_ctrl(n), "")do { if (!(!has_node(n) || !has_ctrl(n))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 994, "assert(" "!has_node(n) || !has_ctrl(n)" ") failed", "" ); ::breakpoint(); } } while (0); | ||||
995 | return has_node(n); | ||||
996 | } | ||||
997 | // Set loop | ||||
998 | void set_loop( Node *n, IdealLoopTree *loop ) { | ||||
999 | _nodes.map(n->_idx, (Node*)loop); | ||||
1000 | } | ||||
1001 | // Lazy-dazy update of 'get_ctrl' and 'idom_at' mechanisms. Replace | ||||
1002 | // the 'old_node' with 'new_node'. Kill old-node. Add a reference | ||||
1003 | // from old_node to new_node to support the lazy update. Reference | ||||
1004 | // replaces loop reference, since that is not needed for dead node. | ||||
1005 | void lazy_update(Node *old_node, Node *new_node) { | ||||
1006 | assert(old_node != new_node, "no cycles please")do { if (!(old_node != new_node)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1006, "assert(" "old_node != new_node" ") failed", "no cycles please" ); ::breakpoint(); } } while (0); | ||||
1007 | // Re-use the side array slot for this node to provide the | ||||
1008 | // forwarding pointer. | ||||
1009 | _nodes.map(old_node->_idx, (Node*)((intptr_t)new_node + 1)); | ||||
1010 | } | ||||
1011 | void lazy_replace(Node *old_node, Node *new_node) { | ||||
1012 | _igvn.replace_node(old_node, new_node); | ||||
1013 | lazy_update(old_node, new_node); | ||||
1014 | } | ||||
1015 | |||||
1016 | private: | ||||
1017 | |||||
1018 | // Place 'n' in some loop nest, where 'n' is a CFG node | ||||
1019 | void build_loop_tree(); | ||||
1020 | int build_loop_tree_impl( Node *n, int pre_order ); | ||||
1021 | // Insert loop into the existing loop tree. 'innermost' is a leaf of the | ||||
1022 | // loop tree, not the root. | ||||
1023 | IdealLoopTree *sort( IdealLoopTree *loop, IdealLoopTree *innermost ); | ||||
1024 | |||||
1025 | // Place Data nodes in some loop nest | ||||
1026 | void build_loop_early( VectorSet &visited, Node_List &worklist, Node_Stack &nstack ); | ||||
1027 | void build_loop_late ( VectorSet &visited, Node_List &worklist, Node_Stack &nstack ); | ||||
1028 | void build_loop_late_post_work(Node* n, bool pinned); | ||||
1029 | void build_loop_late_post(Node* n); | ||||
1030 | void verify_strip_mined_scheduling(Node *n, Node* least); | ||||
1031 | |||||
1032 | // Array of immediate dominance info for each CFG node indexed by node idx | ||||
1033 | private: | ||||
1034 | uint _idom_size; | ||||
1035 | Node **_idom; // Array of immediate dominators | ||||
1036 | uint *_dom_depth; // Used for fast LCA test | ||||
1037 | GrowableArray<uint>* _dom_stk; // For recomputation of dom depth | ||||
1038 | |||||
1039 | // build the loop tree and perform any requested optimizations | ||||
1040 | void build_and_optimize(LoopOptsMode mode); | ||||
1041 | |||||
1042 | // Dominators for the sea of nodes | ||||
1043 | void Dominators(); | ||||
1044 | |||||
1045 | // Compute the Ideal Node to Loop mapping | ||||
1046 | PhaseIdealLoop(PhaseIterGVN& igvn, LoopOptsMode mode) : | ||||
1047 | PhaseTransform(Ideal_Loop), | ||||
1048 | _igvn(igvn), | ||||
1049 | _verify_me(nullptr), | ||||
1050 | _verify_only(false), | ||||
1051 | _nodes_required(UINT_MAX(2147483647 *2U +1U)) { | ||||
1052 | assert(mode != LoopOptsVerify, "wrong constructor to verify IdealLoop")do { if (!(mode != LoopOptsVerify)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1052, "assert(" "mode != LoopOptsVerify" ") failed", "wrong constructor to verify IdealLoop" ); ::breakpoint(); } } while (0); | ||||
1053 | build_and_optimize(mode); | ||||
1054 | } | ||||
1055 | |||||
1056 | #ifndef PRODUCT | ||||
1057 | // Verify that verify_me made the same decisions as a fresh run | ||||
1058 | // or only verify that the graph is valid if verify_me is null. | ||||
1059 | PhaseIdealLoop(PhaseIterGVN& igvn, const PhaseIdealLoop* verify_me = nullptr) : | ||||
1060 | PhaseTransform(Ideal_Loop), | ||||
1061 | _igvn(igvn), | ||||
1062 | _verify_me(verify_me), | ||||
1063 | _verify_only(verify_me == nullptr), | ||||
1064 | _nodes_required(UINT_MAX(2147483647 *2U +1U)) { | ||||
1065 | build_and_optimize(LoopOptsVerify); | ||||
1066 | } | ||||
1067 | #endif | ||||
1068 | |||||
1069 | public: | ||||
1070 | Node* idom_no_update(Node* d) const { | ||||
1071 | return idom_no_update(d->_idx); | ||||
1072 | } | ||||
1073 | |||||
1074 | Node* idom_no_update(uint didx) const { | ||||
1075 | assert(didx < _idom_size, "oob")do { if (!(didx < _idom_size)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1075, "assert(" "didx < _idom_size" ") failed", "oob"); :: breakpoint(); } } while (0); | ||||
1076 | Node* n = _idom[didx]; | ||||
1077 | assert(n != NULL,"Bad immediate dominator info.")do { if (!(n != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1077, "assert(" "n != __null" ") failed", "Bad immediate dominator info." ); ::breakpoint(); } } while (0); | ||||
1078 | while (n->in(0) == NULL__null) { // Skip dead CFG nodes | ||||
1079 | n = (Node*)(((intptr_t)_nodes[n->_idx]) & ~1); | ||||
1080 | assert(n != NULL,"Bad immediate dominator info.")do { if (!(n != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1080, "assert(" "n != __null" ") failed", "Bad immediate dominator info." ); ::breakpoint(); } } while (0); | ||||
1081 | } | ||||
1082 | return n; | ||||
1083 | } | ||||
1084 | |||||
1085 | Node *idom(Node* d) const { | ||||
1086 | return idom(d->_idx); | ||||
1087 | } | ||||
1088 | |||||
1089 | Node *idom(uint didx) const { | ||||
1090 | Node *n = idom_no_update(didx); | ||||
1091 | _idom[didx] = n; // Lazily remove dead CFG nodes from table. | ||||
1092 | return n; | ||||
1093 | } | ||||
1094 | |||||
1095 | uint dom_depth(Node* d) const { | ||||
1096 | guarantee(d != NULL, "Null dominator info.")do { if (!(d != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1096, "guarantee(" "d != NULL" ") failed", "Null dominator info." ); ::breakpoint(); } } while (0); | ||||
1097 | guarantee(d->_idx < _idom_size, "")do { if (!(d->_idx < _idom_size)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1097, "guarantee(" "d->_idx < _idom_size" ") failed", ""); ::breakpoint(); } } while (0); | ||||
1098 | return _dom_depth[d->_idx]; | ||||
1099 | } | ||||
1100 | void set_idom(Node* d, Node* n, uint dom_depth); | ||||
1101 | // Locally compute IDOM using dom_lca call | ||||
1102 | Node *compute_idom( Node *region ) const; | ||||
1103 | // Recompute dom_depth | ||||
1104 | void recompute_dom_depth(); | ||||
1105 | |||||
1106 | // Is safept not required by an outer loop? | ||||
1107 | bool is_deleteable_safept(Node* sfpt); | ||||
1108 | |||||
1109 | // Replace parallel induction variable (parallel to trip counter) | ||||
1110 | void replace_parallel_iv(IdealLoopTree *loop); | ||||
1111 | |||||
1112 | Node *dom_lca( Node *n1, Node *n2 ) const { | ||||
1113 | return find_non_split_ctrl(dom_lca_internal(n1, n2)); | ||||
1114 | } | ||||
1115 | Node *dom_lca_internal( Node *n1, Node *n2 ) const; | ||||
1116 | |||||
1117 | // Build and verify the loop tree without modifying the graph. This | ||||
1118 | // is useful to verify that all inputs properly dominate their uses. | ||||
1119 | static void verify(PhaseIterGVN& igvn) { | ||||
1120 | #ifdef ASSERT1 | ||||
1121 | ResourceMark rm; | ||||
1122 | Compile::TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]); | ||||
1123 | PhaseIdealLoop v(igvn); | ||||
1124 | #endif | ||||
1125 | } | ||||
1126 | |||||
1127 | // Recommended way to use PhaseIdealLoop. | ||||
1128 | // Run PhaseIdealLoop in some mode and allocates a local scope for memory allocations. | ||||
1129 | static void optimize(PhaseIterGVN &igvn, LoopOptsMode mode) { | ||||
1130 | ResourceMark rm; | ||||
1131 | PhaseIdealLoop v(igvn, mode); | ||||
1132 | |||||
1133 | Compile* C = Compile::current(); | ||||
1134 | if (!C->failing()) { | ||||
1135 | // Cleanup any modified bits | ||||
1136 | igvn.optimize(); | ||||
1137 | |||||
1138 | v.log_loop_tree(); | ||||
1139 | } | ||||
1140 | } | ||||
1141 | |||||
1142 | // True if the method has at least 1 irreducible loop | ||||
1143 | bool _has_irreducible_loops; | ||||
1144 | |||||
1145 | // Per-Node transform | ||||
1146 | virtual Node* transform(Node* n) { return NULL__null; } | ||||
1147 | |||||
1148 | Node* loop_exit_control(Node* x, IdealLoopTree* loop); | ||||
1149 | Node* loop_exit_test(Node* back_control, IdealLoopTree* loop, Node*& incr, Node*& limit, BoolTest::mask& bt, float& cl_prob); | ||||
1150 | Node* loop_iv_incr(Node* incr, Node* x, IdealLoopTree* loop, Node*& phi_incr); | ||||
1151 | Node* loop_iv_stride(Node* incr, IdealLoopTree* loop, Node*& xphi); | ||||
1152 | PhiNode* loop_iv_phi(Node* xphi, Node* phi_incr, Node* x, IdealLoopTree* loop); | ||||
1153 | |||||
1154 | bool is_counted_loop(Node* x, IdealLoopTree*&loop, BasicType iv_bt); | ||||
1155 | |||||
1156 | Node* loop_nest_replace_iv(Node* iv_to_replace, Node* inner_iv, Node* outer_phi, Node* inner_head, BasicType bt); | ||||
1157 | bool create_loop_nest(IdealLoopTree* loop, Node_List &old_new); | ||||
1158 | #ifdef ASSERT1 | ||||
1159 | bool convert_to_long_loop(Node* cmp, Node* phi, IdealLoopTree* loop); | ||||
1160 | #endif | ||||
1161 | void add_empty_predicate(Deoptimization::DeoptReason reason, Node* inner_head, IdealLoopTree* loop, SafePointNode* sfpt); | ||||
1162 | SafePointNode* find_safepoint(Node* back_control, Node* x, IdealLoopTree* loop); | ||||
1163 | IdealLoopTree* insert_outer_loop(IdealLoopTree* loop, LoopNode* outer_l, Node* outer_ift); | ||||
1164 | IdealLoopTree* create_outer_strip_mined_loop(BoolNode *test, Node *cmp, Node *init_control, | ||||
1165 | IdealLoopTree* loop, float cl_prob, float le_fcnt, | ||||
1166 | Node*& entry_control, Node*& iffalse); | ||||
1167 | |||||
1168 | Node* exact_limit( IdealLoopTree *loop ); | ||||
1169 | |||||
1170 | // Return a post-walked LoopNode | ||||
1171 | IdealLoopTree *get_loop( Node *n ) const { | ||||
1172 | // Dead nodes have no loop, so return the top level loop instead | ||||
1173 | if (!has_node(n)) return _ltree_root; | ||||
1174 | assert(!has_ctrl(n), "")do { if (!(!has_ctrl(n))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1174, "assert(" "!has_ctrl(n)" ") failed", ""); ::breakpoint (); } } while (0); | ||||
1175 | return (IdealLoopTree*)_nodes[n->_idx]; | ||||
1176 | } | ||||
1177 | |||||
1178 | IdealLoopTree* ltree_root() const { return _ltree_root; } | ||||
1179 | |||||
1180 | // Is 'n' a (nested) member of 'loop'? | ||||
1181 | int is_member( const IdealLoopTree *loop, Node *n ) const { | ||||
1182 | return loop->is_member(get_loop(n)); } | ||||
1183 | |||||
1184 | // This is the basic building block of the loop optimizations. It clones an | ||||
1185 | // entire loop body. It makes an old_new loop body mapping; with this | ||||
1186 | // mapping you can find the new-loop equivalent to an old-loop node. All | ||||
1187 | // new-loop nodes are exactly equal to their old-loop counterparts, all | ||||
1188 | // edges are the same. All exits from the old-loop now have a RegionNode | ||||
1189 | // that merges the equivalent new-loop path. This is true even for the | ||||
1190 | // normal "loop-exit" condition. All uses of loop-invariant old-loop values | ||||
1191 | // now come from (one or more) Phis that merge their new-loop equivalents. | ||||
1192 | // Parameter side_by_side_idom: | ||||
1193 | // When side_by_size_idom is NULL, the dominator tree is constructed for | ||||
1194 | // the clone loop to dominate the original. Used in construction of | ||||
1195 | // pre-main-post loop sequence. | ||||
1196 | // When nonnull, the clone and original are side-by-side, both are | ||||
1197 | // dominated by the passed in side_by_side_idom node. Used in | ||||
1198 | // construction of unswitched loops. | ||||
1199 | enum CloneLoopMode { | ||||
1200 | IgnoreStripMined = 0, // Only clone inner strip mined loop | ||||
1201 | CloneIncludesStripMined = 1, // clone both inner and outer strip mined loops | ||||
1202 | ControlAroundStripMined = 2 // Only clone inner strip mined loop, | ||||
1203 | // result control flow branches | ||||
1204 | // either to inner clone or outer | ||||
1205 | // strip mined loop. | ||||
1206 | }; | ||||
1207 | void clone_loop( IdealLoopTree *loop, Node_List &old_new, int dom_depth, | ||||
1208 | CloneLoopMode mode, Node* side_by_side_idom = NULL__null); | ||||
1209 | void clone_loop_handle_data_uses(Node* old, Node_List &old_new, | ||||
1210 | IdealLoopTree* loop, IdealLoopTree* companion_loop, | ||||
1211 | Node_List*& split_if_set, Node_List*& split_bool_set, | ||||
1212 | Node_List*& split_cex_set, Node_List& worklist, | ||||
1213 | uint new_counter, CloneLoopMode mode); | ||||
1214 | void clone_outer_loop(LoopNode* head, CloneLoopMode mode, IdealLoopTree *loop, | ||||
1215 | IdealLoopTree* outer_loop, int dd, Node_List &old_new, | ||||
1216 | Node_List& extra_data_nodes); | ||||
1217 | |||||
1218 | // If we got the effect of peeling, either by actually peeling or by | ||||
1219 | // making a pre-loop which must execute at least once, we can remove | ||||
1220 | // all loop-invariant dominated tests in the main body. | ||||
1221 | void peeled_dom_test_elim( IdealLoopTree *loop, Node_List &old_new ); | ||||
1222 | |||||
1223 | // Generate code to do a loop peel for the given loop (and body). | ||||
1224 | // old_new is a temp array. | ||||
1225 | void do_peeling( IdealLoopTree *loop, Node_List &old_new ); | ||||
1226 | |||||
1227 | // Add pre and post loops around the given loop. These loops are used | ||||
1228 | // during RCE, unrolling and aligning loops. | ||||
1229 | void insert_pre_post_loops( IdealLoopTree *loop, Node_List &old_new, bool peel_only ); | ||||
1230 | |||||
1231 | // Add post loop after the given loop. | ||||
1232 | Node *insert_post_loop(IdealLoopTree* loop, Node_List& old_new, | ||||
1233 | CountedLoopNode* main_head, CountedLoopEndNode* main_end, | ||||
1234 | Node*& incr, Node* limit, CountedLoopNode*& post_head); | ||||
1235 | |||||
1236 | // Add an RCE'd post loop which we will multi-version adapt for run time test path usage | ||||
1237 | void insert_scalar_rced_post_loop( IdealLoopTree *loop, Node_List &old_new ); | ||||
1238 | |||||
1239 | // Add a vector post loop between a vector main loop and the current post loop | ||||
1240 | void insert_vector_post_loop(IdealLoopTree *loop, Node_List &old_new); | ||||
1241 | // If Node n lives in the back_ctrl block, we clone a private version of n | ||||
1242 | // in preheader_ctrl block and return that, otherwise return n. | ||||
1243 | Node *clone_up_backedge_goo( Node *back_ctrl, Node *preheader_ctrl, Node *n, VectorSet &visited, Node_Stack &clones ); | ||||
1244 | |||||
1245 | // Take steps to maximally unroll the loop. Peel any odd iterations, then | ||||
1246 | // unroll to do double iterations. The next round of major loop transforms | ||||
1247 | // will repeat till the doubled loop body does all remaining iterations in 1 | ||||
1248 | // pass. | ||||
1249 | void do_maximally_unroll( IdealLoopTree *loop, Node_List &old_new ); | ||||
1250 | |||||
1251 | // Unroll the loop body one step - make each trip do 2 iterations. | ||||
1252 | void do_unroll( IdealLoopTree *loop, Node_List &old_new, bool adjust_min_trip ); | ||||
1253 | |||||
1254 | // Mark vector reduction candidates before loop unrolling | ||||
1255 | void mark_reductions( IdealLoopTree *loop ); | ||||
1256 | |||||
1257 | // Return true if exp is a constant times an induction var | ||||
1258 | bool is_scaled_iv(Node* exp, Node* iv, jlong* p_scale, BasicType bt, bool* converted); | ||||
1259 | |||||
1260 | bool is_iv(Node* exp, Node* iv, BasicType bt); | ||||
1261 | |||||
1262 | // Return true if exp is a scaled induction var plus (or minus) constant | ||||
1263 | bool is_scaled_iv_plus_offset(Node* exp, Node* iv, jlong* p_scale, Node** p_offset, BasicType bt, bool* converted = NULL__null, int depth = 0); | ||||
1264 | bool is_scaled_iv_plus_offset(Node* exp, Node* iv, int* p_scale, Node** p_offset) { | ||||
1265 | jlong long_scale; | ||||
1266 | if (is_scaled_iv_plus_offset(exp, iv, &long_scale, p_offset, T_INT)) { | ||||
1267 | int int_scale = checked_cast<int>(long_scale); | ||||
1268 | if (p_scale != NULL__null) { | ||||
1269 | *p_scale = int_scale; | ||||
1270 | } | ||||
1271 | return true; | ||||
1272 | } | ||||
1273 | return false; | ||||
1274 | } | ||||
1275 | |||||
1276 | // Enum to determine the action to be performed in create_new_if_for_predicate() when processing phis of UCT regions. | ||||
1277 | enum class UnswitchingAction { | ||||
1278 | None, // No special action. | ||||
1279 | FastLoopCloning, // Need to clone nodes for the fast loop. | ||||
1280 | SlowLoopRewiring // Need to rewire nodes for the slow loop. | ||||
1281 | }; | ||||
1282 | |||||
1283 | // Create a new if above the uncommon_trap_if_pattern for the predicate to be promoted | ||||
1284 | ProjNode* create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry, Deoptimization::DeoptReason reason, | ||||
1285 | int opcode, bool if_cont_is_true_proj = true, Node_List* old_new = NULL__null, | ||||
1286 | UnswitchingAction unswitching_action = UnswitchingAction::None); | ||||
1287 | |||||
1288 | // Clone data nodes for the fast loop while creating a new If with create_new_if_for_predicate. | ||||
1289 | Node* clone_data_nodes_for_fast_loop(Node* phi_input, ProjNode* uncommon_proj, Node* if_uct, Node_List* old_new); | ||||
1290 | |||||
1291 | void register_control(Node* n, IdealLoopTree *loop, Node* pred, bool update_body = true); | ||||
1292 | |||||
1293 | static Node* skip_all_loop_predicates(Node* entry); | ||||
1294 | static Node* skip_loop_predicates(Node* entry); | ||||
1295 | |||||
1296 | // Find a good location to insert a predicate | ||||
1297 | static ProjNode* find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason); | ||||
1298 | // Find a predicate | ||||
1299 | static Node* find_predicate(Node* entry); | ||||
1300 | // Construct a range check for a predicate if | ||||
1301 | BoolNode* rc_predicate(IdealLoopTree *loop, Node* ctrl, | ||||
1302 | int scale, Node* offset, | ||||
1303 | Node* init, Node* limit, jint stride, | ||||
1304 | Node* range, bool upper, bool &overflow, | ||||
1305 | bool negate); | ||||
1306 | |||||
1307 | // Implementation of the loop predication to promote checks outside the loop | ||||
1308 | bool loop_predication_impl(IdealLoopTree *loop); | ||||
1309 | bool loop_predication_impl_helper(IdealLoopTree *loop, ProjNode* proj, ProjNode *predicate_proj, | ||||
1310 | CountedLoopNode *cl, ConNode* zero, Invariance& invar, | ||||
1311 | Deoptimization::DeoptReason reason); | ||||
1312 | bool loop_predication_should_follow_branches(IdealLoopTree *loop, ProjNode *predicate_proj, float& loop_trip_cnt); | ||||
1313 | void loop_predication_follow_branches(Node *c, IdealLoopTree *loop, float loop_trip_cnt, | ||||
1314 | PathFrequency& pf, Node_Stack& stack, VectorSet& seen, | ||||
1315 | Node_List& if_proj_list); | ||||
1316 | ProjNode* insert_initial_skeleton_predicate(IfNode* iff, IdealLoopTree *loop, | ||||
1317 | ProjNode* proj, ProjNode *predicate_proj, | ||||
1318 | ProjNode* upper_bound_proj, | ||||
1319 | int scale, Node* offset, | ||||
1320 | Node* init, Node* limit, jint stride, | ||||
1321 | Node* rng, bool& overflow, | ||||
1322 | Deoptimization::DeoptReason reason); | ||||
1323 | Node* add_range_check_predicate(IdealLoopTree* loop, CountedLoopNode* cl, | ||||
1324 | Node* predicate_proj, int scale_con, Node* offset, | ||||
1325 | Node* limit, jint stride_con, Node* value); | ||||
1326 | |||||
1327 | // Helper function to collect predicate for eliminating the useless ones | ||||
1328 | void collect_potentially_useful_predicates(IdealLoopTree *loop, Unique_Node_List &predicate_opaque1); | ||||
1329 | void eliminate_useless_predicates(); | ||||
1330 | |||||
1331 | // Change the control input of expensive nodes to allow commoning by | ||||
1332 | // IGVN when it is guaranteed to not result in a more frequent | ||||
1333 | // execution of the expensive node. Return true if progress. | ||||
1334 | bool process_expensive_nodes(); | ||||
1335 | |||||
1336 | // Check whether node has become unreachable | ||||
1337 | bool is_node_unreachable(Node *n) const { | ||||
1338 | return !has_node(n) || n->is_unreachable(_igvn); | ||||
1339 | } | ||||
1340 | |||||
1341 | // Eliminate range-checks and other trip-counter vs loop-invariant tests. | ||||
1342 | int do_range_check( IdealLoopTree *loop, Node_List &old_new ); | ||||
1343 | |||||
1344 | // Check to see if do_range_check(...) cleaned the main loop of range-checks | ||||
1345 | void has_range_checks(IdealLoopTree *loop); | ||||
1346 | |||||
1347 | // Process post loops which have range checks and try to build a multi-version | ||||
1348 | // guard to safely determine if we can execute the post loop which was RCE'd. | ||||
1349 | bool multi_version_post_loops(IdealLoopTree *rce_loop, IdealLoopTree *legacy_loop); | ||||
1350 | |||||
1351 | // Cause the rce'd post loop to optimized away, this happens if we cannot complete multiverioning | ||||
1352 | void poison_rce_post_loop(IdealLoopTree *rce_loop); | ||||
1353 | |||||
1354 | // Create a slow version of the loop by cloning the loop | ||||
1355 | // and inserting an if to select fast-slow versions. | ||||
1356 | // Return the inserted if. | ||||
1357 | IfNode* create_slow_version_of_loop(IdealLoopTree *loop, | ||||
1358 | Node_List &old_new, | ||||
1359 | IfNode* unswitch_iff, | ||||
1360 | CloneLoopMode mode); | ||||
1361 | |||||
1362 | // Clone a loop and return the clone head (clone_loop_head). | ||||
1363 | // Added nodes include int(1), int(0) - disconnected, If, IfTrue, IfFalse, | ||||
1364 | // This routine was created for usage in CountedLoopReserveKit. | ||||
1365 | // | ||||
1366 | // int(1) -> If -> IfTrue -> original_loop_head | ||||
1367 | // | | ||||
1368 | // V | ||||
1369 | // IfFalse -> clone_loop_head (returned by function pointer) | ||||
1370 | // | ||||
1371 | LoopNode* create_reserve_version_of_loop(IdealLoopTree *loop, CountedLoopReserveKit* lk); | ||||
1372 | // Clone loop with an invariant test (that does not exit) and | ||||
1373 | // insert a clone of the test that selects which version to | ||||
1374 | // execute. | ||||
1375 | void do_unswitching (IdealLoopTree *loop, Node_List &old_new); | ||||
1376 | |||||
1377 | // Find candidate "if" for unswitching | ||||
1378 | IfNode* find_unswitching_candidate(const IdealLoopTree *loop) const; | ||||
1379 | |||||
1380 | // Range Check Elimination uses this function! | ||||
1381 | // Constrain the main loop iterations so the affine function: | ||||
1382 | // low_limit <= scale_con * I + offset < upper_limit | ||||
1383 | // always holds true. That is, either increase the number of iterations in | ||||
1384 | // the pre-loop or the post-loop until the condition holds true in the main | ||||
1385 | // loop. Scale_con, offset and limit are all loop invariant. | ||||
1386 | void add_constraint(jlong stride_con, jlong scale_con, Node* offset, Node* low_limit, Node* upper_limit, Node* pre_ctrl, Node** pre_limit, Node** main_limit); | ||||
1387 | // Helper function for add_constraint(). | ||||
1388 | Node* adjust_limit(bool reduce, Node* scale, Node* offset, Node* rc_limit, Node* old_limit, Node* pre_ctrl, bool round); | ||||
1389 | |||||
1390 | // Partially peel loop up through last_peel node. | ||||
1391 | bool partial_peel( IdealLoopTree *loop, Node_List &old_new ); | ||||
1392 | |||||
1393 | // Create a scheduled list of nodes control dependent on ctrl set. | ||||
1394 | void scheduled_nodelist( IdealLoopTree *loop, VectorSet& ctrl, Node_List &sched ); | ||||
1395 | // Has a use in the vector set | ||||
1396 | bool has_use_in_set( Node* n, VectorSet& vset ); | ||||
1397 | // Has use internal to the vector set (ie. not in a phi at the loop head) | ||||
1398 | bool has_use_internal_to_set( Node* n, VectorSet& vset, IdealLoopTree *loop ); | ||||
1399 | // clone "n" for uses that are outside of loop | ||||
1400 | int clone_for_use_outside_loop( IdealLoopTree *loop, Node* n, Node_List& worklist ); | ||||
1401 | // clone "n" for special uses that are in the not_peeled region | ||||
1402 | void clone_for_special_use_inside_loop( IdealLoopTree *loop, Node* n, | ||||
1403 | VectorSet& not_peel, Node_List& sink_list, Node_List& worklist ); | ||||
1404 | // Insert phi(lp_entry_val, back_edge_val) at use->in(idx) for loop lp if phi does not already exist | ||||
1405 | void insert_phi_for_loop( Node* use, uint idx, Node* lp_entry_val, Node* back_edge_val, LoopNode* lp ); | ||||
1406 | #ifdef ASSERT1 | ||||
1407 | // Validate the loop partition sets: peel and not_peel | ||||
1408 | bool is_valid_loop_partition( IdealLoopTree *loop, VectorSet& peel, Node_List& peel_list, VectorSet& not_peel ); | ||||
1409 | // Ensure that uses outside of loop are of the right form | ||||
1410 | bool is_valid_clone_loop_form( IdealLoopTree *loop, Node_List& peel_list, | ||||
1411 | uint orig_exit_idx, uint clone_exit_idx); | ||||
1412 | bool is_valid_clone_loop_exit_use( IdealLoopTree *loop, Node* use, uint exit_idx); | ||||
1413 | #endif | ||||
1414 | |||||
1415 | // Returns nonzero constant stride if-node is a possible iv test (otherwise returns zero.) | ||||
1416 | int stride_of_possible_iv( Node* iff ); | ||||
1417 | bool is_possible_iv_test( Node* iff ) { return stride_of_possible_iv(iff) != 0; } | ||||
1418 | // Return the (unique) control output node that's in the loop (if it exists.) | ||||
1419 | Node* stay_in_loop( Node* n, IdealLoopTree *loop); | ||||
1420 | // Insert a signed compare loop exit cloned from an unsigned compare. | ||||
1421 | IfNode* insert_cmpi_loop_exit(IfNode* if_cmpu, IdealLoopTree *loop); | ||||
1422 | void remove_cmpi_loop_exit(IfNode* if_cmp, IdealLoopTree *loop); | ||||
1423 | // Utility to register node "n" with PhaseIdealLoop | ||||
1424 | void register_node(Node* n, IdealLoopTree *loop, Node* pred, int ddepth); | ||||
1425 | // Utility to create an if-projection | ||||
1426 | ProjNode* proj_clone(ProjNode* p, IfNode* iff); | ||||
1427 | // Force the iff control output to be the live_proj | ||||
1428 | Node* short_circuit_if(IfNode* iff, ProjNode* live_proj); | ||||
1429 | // Insert a region before an if projection | ||||
1430 | RegionNode* insert_region_before_proj(ProjNode* proj); | ||||
1431 | // Insert a new if before an if projection | ||||
1432 | ProjNode* insert_if_before_proj(Node* left, bool Signed, BoolTest::mask relop, Node* right, ProjNode* proj); | ||||
1433 | |||||
1434 | // Passed in a Phi merging (recursively) some nearly equivalent Bool/Cmps. | ||||
1435 | // "Nearly" because all Nodes have been cloned from the original in the loop, | ||||
1436 | // but the fall-in edges to the Cmp are different. Clone bool/Cmp pairs | ||||
1437 | // through the Phi recursively, and return a Bool. | ||||
1438 | Node *clone_iff( PhiNode *phi, IdealLoopTree *loop ); | ||||
1439 | CmpNode *clone_bool( PhiNode *phi, IdealLoopTree *loop ); | ||||
1440 | |||||
1441 | |||||
1442 | // Rework addressing expressions to get the most loop-invariant stuff | ||||
1443 | // moved out. We'd like to do all associative operators, but it's especially | ||||
1444 | // important (common) to do address expressions. | ||||
1445 | Node *remix_address_expressions( Node *n ); | ||||
1446 | |||||
1447 | // Convert add to muladd to generate MuladdS2I under certain criteria | ||||
1448 | Node * convert_add_to_muladd(Node * n); | ||||
1449 | |||||
1450 | // Attempt to use a conditional move instead of a phi/branch | ||||
1451 | Node *conditional_move( Node *n ); | ||||
1452 | |||||
1453 | // Reorganize offset computations to lower register pressure. | ||||
1454 | // Mostly prevent loop-fallout uses of the pre-incremented trip counter | ||||
1455 | // (which are then alive with the post-incremented trip counter | ||||
1456 | // forcing an extra register move) | ||||
1457 | void reorg_offsets( IdealLoopTree *loop ); | ||||
1458 | |||||
1459 | // Check for aggressive application of 'split-if' optimization, | ||||
1460 | // using basic block level info. | ||||
1461 | void split_if_with_blocks ( VectorSet &visited, Node_Stack &nstack); | ||||
1462 | Node *split_if_with_blocks_pre ( Node *n ); | ||||
1463 | void split_if_with_blocks_post( Node *n ); | ||||
1464 | Node *has_local_phi_input( Node *n ); | ||||
1465 | // Mark an IfNode as being dominated by a prior test, | ||||
1466 | // without actually altering the CFG (and hence IDOM info). | ||||
1467 | void dominated_by( Node *prevdom, Node *iff, bool flip = false, bool exclude_loop_predicate = false ); | ||||
1468 | |||||
1469 | // Split Node 'n' through merge point | ||||
1470 | Node *split_thru_region( Node *n, Node *region ); | ||||
1471 | // Split Node 'n' through merge point if there is enough win. | ||||
1472 | Node *split_thru_phi( Node *n, Node *region, int policy ); | ||||
1473 | // Found an If getting its condition-code input from a Phi in the | ||||
1474 | // same block. Split thru the Region. | ||||
1475 | void do_split_if( Node *iff ); | ||||
1476 | |||||
1477 | // Conversion of fill/copy patterns into intrinsic versions | ||||
1478 | bool do_intrinsify_fill(); | ||||
1479 | bool intrinsify_fill(IdealLoopTree* lpt); | ||||
1480 | bool match_fill_loop(IdealLoopTree* lpt, Node*& store, Node*& store_value, | ||||
1481 | Node*& shift, Node*& offset); | ||||
1482 | |||||
1483 | private: | ||||
1484 | // Return a type based on condition control flow | ||||
1485 | const TypeInt* filtered_type( Node *n, Node* n_ctrl); | ||||
1486 | const TypeInt* filtered_type( Node *n ) { return filtered_type(n, NULL__null); } | ||||
1487 | // Helpers for filtered type | ||||
1488 | const TypeInt* filtered_type_from_dominators( Node* val, Node *val_ctrl); | ||||
1489 | |||||
1490 | // Helper functions | ||||
1491 | Node *spinup( Node *iff, Node *new_false, Node *new_true, Node *region, Node *phi, small_cache *cache ); | ||||
1492 | Node *find_use_block( Node *use, Node *def, Node *old_false, Node *new_false, Node *old_true, Node *new_true ); | ||||
1493 | void handle_use( Node *use, Node *def, small_cache *cache, Node *region_dom, Node *new_false, Node *new_true, Node *old_false, Node *old_true ); | ||||
1494 | bool split_up( Node *n, Node *blk1, Node *blk2 ); | ||||
1495 | void sink_use( Node *use, Node *post_loop ); | ||||
1496 | Node* place_outside_loop(Node* useblock, IdealLoopTree* loop) const; | ||||
1497 | Node* try_move_store_before_loop(Node* n, Node *n_ctrl); | ||||
1498 | void try_move_store_after_loop(Node* n); | ||||
1499 | bool identical_backtoback_ifs(Node *n); | ||||
1500 | bool can_split_if(Node *n_ctrl); | ||||
1501 | |||||
1502 | // Determine if a method is too big for a/another round of split-if, based on | ||||
1503 | // a magic (approximate) ratio derived from the equally magic constant 35000, | ||||
1504 | // previously used for this purpose (but without relating to the node limit). | ||||
1505 | bool must_throttle_split_if() { | ||||
1506 | uint threshold = C->max_node_limit() * 2 / 5; | ||||
1507 | return C->live_nodes() > threshold; | ||||
1508 | } | ||||
1509 | |||||
1510 | // A simplistic node request tracking mechanism, where | ||||
1511 | // = UINT_MAX Request not valid or made final. | ||||
1512 | // < UINT_MAX Nodes currently requested (estimate). | ||||
1513 | uint _nodes_required; | ||||
1514 | |||||
1515 | enum { REQUIRE_MIN = 70 }; | ||||
1516 | |||||
1517 | uint nodes_required() const { return _nodes_required; } | ||||
1518 | |||||
1519 | // Given the _currently_ available number of nodes, check whether there is | ||||
1520 | // "room" for an additional request or not, considering the already required | ||||
1521 | // number of nodes. Return TRUE if the new request is exceeding the node | ||||
1522 | // budget limit, otherwise return FALSE. Note that this interpretation will | ||||
1523 | // act pessimistic on additional requests when new nodes have already been | ||||
1524 | // generated since the 'begin'. This behaviour fits with the intention that | ||||
1525 | // node estimates/requests should be made upfront. | ||||
1526 | bool exceeding_node_budget(uint required = 0) { | ||||
1527 | assert(C->live_nodes() < C->max_node_limit(), "sanity")do { if (!(C->live_nodes() < C->max_node_limit())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1527, "assert(" "C->live_nodes() < C->max_node_limit()" ") failed", "sanity"); ::breakpoint(); } } while (0); | ||||
1528 | uint available = C->max_node_limit() - C->live_nodes(); | ||||
1529 | return available < required + _nodes_required + REQUIRE_MIN; | ||||
1530 | } | ||||
1531 | |||||
1532 | uint require_nodes(uint require, uint minreq = REQUIRE_MIN) { | ||||
1533 | precond(require > 0)do { if (!(require > 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1533, "assert(" "require > 0" ") failed", "precond"); :: breakpoint(); } } while (0); | ||||
1534 | _nodes_required += MAX2(require, minreq); | ||||
1535 | return _nodes_required; | ||||
1536 | } | ||||
1537 | |||||
1538 | bool may_require_nodes(uint require, uint minreq = REQUIRE_MIN) { | ||||
1539 | return !exceeding_node_budget(require) && require_nodes(require, minreq) > 0; | ||||
1540 | } | ||||
1541 | |||||
1542 | uint require_nodes_begin() { | ||||
1543 | assert(_nodes_required == UINT_MAX, "Bad state (begin).")do { if (!(_nodes_required == (2147483647 *2U +1U))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1543, "assert(" "_nodes_required == (2147483647 *2U +1U)" ") failed" , "Bad state (begin)."); ::breakpoint(); } } while (0); | ||||
1544 | _nodes_required = 0; | ||||
1545 | return C->live_nodes(); | ||||
1546 | } | ||||
1547 | |||||
1548 | // When a node request is final, optionally check that the requested number | ||||
1549 | // of nodes was reasonably correct with respect to the number of new nodes | ||||
1550 | // introduced since the last 'begin'. Always check that we have not exceeded | ||||
1551 | // the maximum node limit. | ||||
1552 | void require_nodes_final(uint live_at_begin, bool check_estimate) { | ||||
1553 | assert(_nodes_required < UINT_MAX, "Bad state (final).")do { if (!(_nodes_required < (2147483647 *2U +1U))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1553, "assert(" "_nodes_required < (2147483647 *2U +1U)" ") failed", "Bad state (final)."); ::breakpoint(); } } while (0); | ||||
1554 | |||||
1555 | #ifdef ASSERT1 | ||||
1556 | if (check_estimate) { | ||||
1557 | // Check that the node budget request was not off by too much (x2). | ||||
1558 | // Should this be the case we _surely_ need to improve the estimates | ||||
1559 | // used in our budget calculations. | ||||
1560 | if (C->live_nodes() - live_at_begin > 2 * _nodes_required) { | ||||
1561 | log_info(compilation)(!(LogImpl<(LogTag::_compilation), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_compilation), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>("Bad node estimate: actual = %d >> request = %d", | ||||
1562 | C->live_nodes() - live_at_begin, _nodes_required); | ||||
1563 | } | ||||
1564 | } | ||||
1565 | #endif | ||||
1566 | // Assert that we have stayed within the node budget limit. | ||||
1567 | assert(C->live_nodes() < C->max_node_limit(),do { if (!(C->live_nodes() < C->max_node_limit())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1570, "assert(" "C->live_nodes() < C->max_node_limit()" ") failed", "Exceeding node budget limit: %d + %d > %d (request = %d)" , C->live_nodes() - live_at_begin, live_at_begin, C->max_node_limit (), _nodes_required); ::breakpoint(); } } while (0) | ||||
1568 | "Exceeding node budget limit: %d + %d > %d (request = %d)",do { if (!(C->live_nodes() < C->max_node_limit())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1570, "assert(" "C->live_nodes() < C->max_node_limit()" ") failed", "Exceeding node budget limit: %d + %d > %d (request = %d)" , C->live_nodes() - live_at_begin, live_at_begin, C->max_node_limit (), _nodes_required); ::breakpoint(); } } while (0) | ||||
1569 | C->live_nodes() - live_at_begin, live_at_begin,do { if (!(C->live_nodes() < C->max_node_limit())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1570, "assert(" "C->live_nodes() < C->max_node_limit()" ") failed", "Exceeding node budget limit: %d + %d > %d (request = %d)" , C->live_nodes() - live_at_begin, live_at_begin, C->max_node_limit (), _nodes_required); ::breakpoint(); } } while (0) | ||||
1570 | C->max_node_limit(), _nodes_required)do { if (!(C->live_nodes() < C->max_node_limit())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1570, "assert(" "C->live_nodes() < C->max_node_limit()" ") failed", "Exceeding node budget limit: %d + %d > %d (request = %d)" , C->live_nodes() - live_at_begin, live_at_begin, C->max_node_limit (), _nodes_required); ::breakpoint(); } } while (0); | ||||
1571 | |||||
1572 | _nodes_required = UINT_MAX(2147483647 *2U +1U); | ||||
1573 | } | ||||
1574 | |||||
1575 | // Clone loop predicates to slow and fast loop when unswitching a loop | ||||
1576 | void clone_predicates_to_unswitched_loop(IdealLoopTree* loop, Node_List& old_new, ProjNode*& iffast_pred, ProjNode*& ifslow_pred); | ||||
1577 | ProjNode* clone_predicate_to_unswitched_loop(ProjNode* predicate_proj, Node* new_entry, Deoptimization::DeoptReason reason, | ||||
1578 | Node_List* old_new = NULL__null); | ||||
1579 | void clone_skeleton_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, Deoptimization::DeoptReason reason, | ||||
1580 | ProjNode* old_predicate_proj, ProjNode* iffast_pred, ProjNode* ifslow_pred); | ||||
1581 | ProjNode* clone_skeleton_predicate_for_unswitched_loops(Node* iff, ProjNode* predicate, | ||||
1582 | Deoptimization::DeoptReason reason, | ||||
1583 | ProjNode* output_proj); | ||||
1584 | static void check_created_predicate_for_unswitching(const Node* new_entry) PRODUCT_RETURN; | ||||
1585 | |||||
1586 | bool _created_loop_node; | ||||
1587 | #ifdef ASSERT1 | ||||
1588 | void dump_real_LCA(Node* early, Node* wrong_lca); | ||||
1589 | bool check_idom_chains_intersection(const Node* n, uint& idom_idx_new, uint& idom_idx_other, const Node_List* nodes_seen) const; | ||||
1590 | #endif | ||||
1591 | |||||
1592 | public: | ||||
1593 | void set_created_loop_node() { _created_loop_node = true; } | ||||
1594 | bool created_loop_node() { return _created_loop_node; } | ||||
1595 | void register_new_node(Node* n, Node* blk); | ||||
1596 | |||||
1597 | #ifdef ASSERT1 | ||||
1598 | void dump_bad_graph(const char* msg, Node* n, Node* early, Node* LCA); | ||||
1599 | #endif | ||||
1600 | |||||
1601 | #ifndef PRODUCT | ||||
1602 | void dump() const; | ||||
1603 | void dump_idom(Node* n) const; | ||||
1604 | void dump(IdealLoopTree* loop, uint rpo_idx, Node_List &rpo_list) const; | ||||
1605 | void verify() const; // Major slow :-) | ||||
1606 | void verify_compare(Node* n, const PhaseIdealLoop* loop_verify, VectorSet &visited) const; | ||||
1607 | IdealLoopTree* get_loop_idx(Node* n) const { | ||||
1608 | // Dead nodes have no loop, so return the top level loop instead | ||||
1609 | return _nodes[n->_idx] ? (IdealLoopTree*)_nodes[n->_idx] : _ltree_root; | ||||
1610 | } | ||||
1611 | // Print some stats | ||||
1612 | static void print_statistics(); | ||||
1613 | static int _loop_invokes; // Count of PhaseIdealLoop invokes | ||||
1614 | static int _loop_work; // Sum of PhaseIdealLoop x _unique | ||||
1615 | static volatile int _long_loop_candidates; | ||||
1616 | static volatile int _long_loop_nests; | ||||
1617 | static volatile int _long_loop_counted_loops; | ||||
1618 | #endif | ||||
1619 | |||||
1620 | void rpo(Node* start, Node_Stack &stk, VectorSet &visited, Node_List &rpo_list) const; | ||||
1621 | |||||
1622 | void check_counted_loop_shape(IdealLoopTree* loop, Node* x, BasicType bt) NOT_DEBUG_RETURN; | ||||
1623 | |||||
1624 | LoopNode* create_inner_head(IdealLoopTree* loop, BaseCountedLoopNode* head, IfNode* exit_test); | ||||
1625 | |||||
1626 | |||||
1627 | int extract_long_range_checks(const IdealLoopTree* loop, jlong stride_con, int iters_limit, PhiNode* phi, | ||||
1628 | Node_List &range_checks); | ||||
1629 | |||||
1630 | void transform_long_range_checks(int stride_con, const Node_List &range_checks, Node* outer_phi, | ||||
1631 | Node* inner_iters_actual_int, Node* inner_phi, | ||||
1632 | Node* iv_add, LoopNode* inner_head); | ||||
1633 | |||||
1634 | Node* get_late_ctrl_with_anti_dep(LoadNode* n, Node* early, Node* LCA); | ||||
1635 | |||||
1636 | bool ctrl_of_use_out_of_loop(const Node* n, Node* n_ctrl, IdealLoopTree* n_loop, Node* ctrl); | ||||
1637 | |||||
1638 | bool ctrl_of_all_uses_out_of_loop(const Node* n, Node* n_ctrl, IdealLoopTree* n_loop); | ||||
1639 | |||||
1640 | Node* compute_early_ctrl(Node* n, Node* n_ctrl); | ||||
1641 | |||||
1642 | void try_sink_out_of_loop(Node* n); | ||||
1643 | |||||
1644 | Node* clamp(Node* R, Node* L, Node* H); | ||||
1645 | |||||
1646 | bool safe_for_if_replacement(const Node* dom) const; | ||||
1647 | |||||
1648 | void strip_mined_nest_back_to_counted_loop(IdealLoopTree* loop, const BaseCountedLoopNode* head, Node* back_control, | ||||
1649 | IfNode*&exit_test, SafePointNode*&safepoint); | ||||
1650 | }; | ||||
1651 | |||||
1652 | |||||
1653 | class AutoNodeBudget : public StackObj | ||||
1654 | { | ||||
1655 | public: | ||||
1656 | enum budget_check_t { BUDGET_CHECK, NO_BUDGET_CHECK }; | ||||
1657 | |||||
1658 | AutoNodeBudget(PhaseIdealLoop* phase, budget_check_t chk = BUDGET_CHECK) | ||||
1659 | : _phase(phase), | ||||
1660 | _check_at_final(chk == BUDGET_CHECK), | ||||
1661 | _nodes_at_begin(0) | ||||
1662 | { | ||||
1663 | precond(_phase != NULL)do { if (!(_phase != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/loopnode.hpp" , 1663, "assert(" "_phase != __null" ") failed", "precond"); :: breakpoint(); } } while (0); | ||||
1664 | |||||
1665 | _nodes_at_begin = _phase->require_nodes_begin(); | ||||
1666 | } | ||||
1667 | |||||
1668 | ~AutoNodeBudget() { | ||||
1669 | #ifndef PRODUCT | ||||
1670 | if (TraceLoopOpts) { | ||||
1671 | uint request = _phase->nodes_required(); | ||||
1672 | uint delta = _phase->C->live_nodes() - _nodes_at_begin; | ||||
1673 | |||||
1674 | if (request < delta) { | ||||
1675 | tty->print_cr("Exceeding node budget: %d < %d", request, delta); | ||||
1676 | } else { | ||||
1677 | uint const REQUIRE_MIN = PhaseIdealLoop::REQUIRE_MIN; | ||||
1678 | // Identify the worst estimates as "poor" ones. | ||||
1679 | if (request > REQUIRE_MIN && delta > 0) { | ||||
1680 | if ((delta > REQUIRE_MIN && request > 3 * delta) || | ||||
1681 | (delta <= REQUIRE_MIN && request > 10 * delta)) { | ||||
1682 | tty->print_cr("Poor node estimate: %d >> %d", request, delta); | ||||
1683 | } | ||||
1684 | } | ||||
1685 | } | ||||
1686 | } | ||||
1687 | #endif // PRODUCT | ||||
1688 | _phase->require_nodes_final(_nodes_at_begin, _check_at_final); | ||||
1689 | } | ||||
1690 | |||||
1691 | private: | ||||
1692 | PhaseIdealLoop* _phase; | ||||
1693 | bool _check_at_final; | ||||
1694 | uint _nodes_at_begin; | ||||
1695 | }; | ||||
1696 | |||||
1697 | |||||
1698 | // This kit may be used for making of a reserved copy of a loop before this loop | ||||
1699 | // goes under non-reversible changes. | ||||
1700 | // | ||||
1701 | // Function create_reserve() creates a reserved copy (clone) of the loop. | ||||
1702 | // The reserved copy is created by calling | ||||
1703 | // PhaseIdealLoop::create_reserve_version_of_loop - see there how | ||||
1704 | // the original and reserved loops are connected in the outer graph. | ||||
1705 | // If create_reserve succeeded, it returns 'true' and _has_reserved is set to 'true'. | ||||
1706 | // | ||||
1707 | // By default the reserved copy (clone) of the loop is created as dead code - it is | ||||
1708 | // dominated in the outer loop by this node chain: | ||||
1709 | // intcon(1)->If->IfFalse->reserved_copy. | ||||
1710 | // The original loop is dominated by the the same node chain but IfTrue projection: | ||||
1711 | // intcon(0)->If->IfTrue->original_loop. | ||||
1712 | // | ||||
1713 | // In this implementation of CountedLoopReserveKit the ctor includes create_reserve() | ||||
1714 | // and the dtor, checks _use_new value. | ||||
1715 | // If _use_new == false, it "switches" control to reserved copy of the loop | ||||
1716 | // by simple replacing of node intcon(1) with node intcon(0). | ||||
1717 | // | ||||
1718 | // Here is a proposed example of usage (see also SuperWord::output in superword.cpp). | ||||
1719 | // | ||||
1720 | // void CountedLoopReserveKit_example() | ||||
1721 | // { | ||||
1722 | // CountedLoopReserveKit lrk((phase, lpt, DoReserveCopy = true); // create local object | ||||
1723 | // if (DoReserveCopy && !lrk.has_reserved()) { | ||||
1724 | // return; //failed to create reserved loop copy | ||||
1725 | // } | ||||
1726 | // ... | ||||
1727 | // //something is wrong, switch to original loop | ||||
1728 | /// if(something_is_wrong) return; // ~CountedLoopReserveKit makes the switch | ||||
1729 | // ... | ||||
1730 | // //everything worked ok, return with the newly modified loop | ||||
1731 | // lrk.use_new(); | ||||
1732 | // return; // ~CountedLoopReserveKit does nothing once use_new() was called | ||||
1733 | // } | ||||
1734 | // | ||||
1735 | // Keep in mind, that by default if create_reserve() is not followed by use_new() | ||||
1736 | // the dtor will "switch to the original" loop. | ||||
1737 | // NOTE. You you modify outside of the original loop this class is no help. | ||||
1738 | // | ||||
1739 | class CountedLoopReserveKit { | ||||
1740 | private: | ||||
1741 | PhaseIdealLoop* _phase; | ||||
1742 | IdealLoopTree* _lpt; | ||||
1743 | LoopNode* _lp; | ||||
1744 | IfNode* _iff; | ||||
1745 | LoopNode* _lp_reserved; | ||||
1746 | bool _has_reserved; | ||||
1747 | bool _use_new; | ||||
1748 | const bool _active; //may be set to false in ctor, then the object is dummy | ||||
1749 | |||||
1750 | public: | ||||
1751 | CountedLoopReserveKit(PhaseIdealLoop* phase, IdealLoopTree *loop, bool active); | ||||
1752 | ~CountedLoopReserveKit(); | ||||
1753 | void use_new() {_use_new = true;} | ||||
1754 | void set_iff(IfNode* x) {_iff = x;} | ||||
1755 | bool has_reserved() const { return _active && _has_reserved;} | ||||
1756 | private: | ||||
1757 | bool create_reserve(); | ||||
1758 | };// class CountedLoopReserveKit | ||||
1759 | |||||
1760 | inline Node* IdealLoopTree::tail() { | ||||
1761 | // Handle lazy update of _tail field. | ||||
1762 | if (_tail->in(0) == NULL__null) { | ||||
1763 | _tail = _phase->get_ctrl(_tail); | ||||
1764 | } | ||||
1765 | return _tail; | ||||
1766 | } | ||||
1767 | |||||
1768 | inline Node* IdealLoopTree::head() { | ||||
1769 | // Handle lazy update of _head field. | ||||
1770 | if (_head->in(0) == NULL__null) { | ||||
1771 | _head = _phase->get_ctrl(_head); | ||||
1772 | } | ||||
1773 | return _head; | ||||
1774 | } | ||||
1775 | |||||
1776 | // Iterate over the loop tree using a preorder, left-to-right traversal. | ||||
1777 | // | ||||
1778 | // Example that visits all counted loops from within PhaseIdealLoop | ||||
1779 | // | ||||
1780 | // for (LoopTreeIterator iter(_ltree_root); !iter.done(); iter.next()) { | ||||
1781 | // IdealLoopTree* lpt = iter.current(); | ||||
1782 | // if (!lpt->is_counted()) continue; | ||||
1783 | // ... | ||||
1784 | class LoopTreeIterator : public StackObj { | ||||
1785 | private: | ||||
1786 | IdealLoopTree* _root; | ||||
1787 | IdealLoopTree* _curnt; | ||||
1788 | |||||
1789 | public: | ||||
1790 | LoopTreeIterator(IdealLoopTree* root) : _root(root), _curnt(root) {} | ||||
1791 | |||||
1792 | bool done() { return _curnt == NULL__null; } // Finished iterating? | ||||
1793 | |||||
1794 | void next(); // Advance to next loop tree | ||||
1795 | |||||
1796 | IdealLoopTree* current() { return _curnt; } // Return current value of iterator. | ||||
1797 | }; | ||||
1798 | |||||
1799 | #endif // SHARE_OPTO_LOOPNODE_HPP |