File: | jdk/src/hotspot/share/opto/loopPredicate.cpp |
Warning: | line 921, column 9 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
| ||||||||
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
| ||||||||
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) 1997, 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_NODE_HPP |
26 | #define SHARE_OPTO_NODE_HPP |
27 | |
28 | #include "libadt/vectset.hpp" |
29 | #include "opto/compile.hpp" |
30 | #include "opto/type.hpp" |
31 | #include "utilities/copy.hpp" |
32 | |
33 | // Portions of code courtesy of Clifford Click |
34 | |
35 | // Optimization - Graph Style |
36 | |
37 | |
38 | class AbstractLockNode; |
39 | class AddNode; |
40 | class AddPNode; |
41 | class AliasInfo; |
42 | class AllocateArrayNode; |
43 | class AllocateNode; |
44 | class ArrayCopyNode; |
45 | class BaseCountedLoopNode; |
46 | class BaseCountedLoopEndNode; |
47 | class BlackholeNode; |
48 | class Block; |
49 | class BoolNode; |
50 | class BoxLockNode; |
51 | class CMoveNode; |
52 | class CallDynamicJavaNode; |
53 | class CallJavaNode; |
54 | class CallLeafNode; |
55 | class CallLeafNoFPNode; |
56 | class CallNode; |
57 | class CallRuntimeNode; |
58 | class CallNativeNode; |
59 | class CallStaticJavaNode; |
60 | class CastFFNode; |
61 | class CastDDNode; |
62 | class CastVVNode; |
63 | class CastIINode; |
64 | class CastLLNode; |
65 | class CatchNode; |
66 | class CatchProjNode; |
67 | class CheckCastPPNode; |
68 | class ClearArrayNode; |
69 | class CmpNode; |
70 | class CodeBuffer; |
71 | class ConstraintCastNode; |
72 | class ConNode; |
73 | class CompareAndSwapNode; |
74 | class CompareAndExchangeNode; |
75 | class CountedLoopNode; |
76 | class CountedLoopEndNode; |
77 | class DecodeNarrowPtrNode; |
78 | class DecodeNNode; |
79 | class DecodeNKlassNode; |
80 | class EncodeNarrowPtrNode; |
81 | class EncodePNode; |
82 | class EncodePKlassNode; |
83 | class FastLockNode; |
84 | class FastUnlockNode; |
85 | class HaltNode; |
86 | class IfNode; |
87 | class IfProjNode; |
88 | class IfFalseNode; |
89 | class IfTrueNode; |
90 | class InitializeNode; |
91 | class JVMState; |
92 | class JumpNode; |
93 | class JumpProjNode; |
94 | class LoadNode; |
95 | class LoadStoreNode; |
96 | class LoadStoreConditionalNode; |
97 | class LockNode; |
98 | class LongCountedLoopNode; |
99 | class LongCountedLoopEndNode; |
100 | class LoopNode; |
101 | class LShiftNode; |
102 | class MachBranchNode; |
103 | class MachCallDynamicJavaNode; |
104 | class MachCallJavaNode; |
105 | class MachCallLeafNode; |
106 | class MachCallNode; |
107 | class MachCallNativeNode; |
108 | class MachCallRuntimeNode; |
109 | class MachCallStaticJavaNode; |
110 | class MachConstantBaseNode; |
111 | class MachConstantNode; |
112 | class MachGotoNode; |
113 | class MachIfNode; |
114 | class MachJumpNode; |
115 | class MachNode; |
116 | class MachNullCheckNode; |
117 | class MachProjNode; |
118 | class MachReturnNode; |
119 | class MachSafePointNode; |
120 | class MachSpillCopyNode; |
121 | class MachTempNode; |
122 | class MachMergeNode; |
123 | class MachMemBarNode; |
124 | class Matcher; |
125 | class MemBarNode; |
126 | class MemBarStoreStoreNode; |
127 | class MemNode; |
128 | class MergeMemNode; |
129 | class MoveNode; |
130 | class MulNode; |
131 | class MultiNode; |
132 | class MultiBranchNode; |
133 | class NeverBranchNode; |
134 | class Opaque1Node; |
135 | class OuterStripMinedLoopNode; |
136 | class OuterStripMinedLoopEndNode; |
137 | class Node; |
138 | class Node_Array; |
139 | class Node_List; |
140 | class Node_Stack; |
141 | class OopMap; |
142 | class ParmNode; |
143 | class PCTableNode; |
144 | class PhaseCCP; |
145 | class PhaseGVN; |
146 | class PhaseIterGVN; |
147 | class PhaseRegAlloc; |
148 | class PhaseTransform; |
149 | class PhaseValues; |
150 | class PhiNode; |
151 | class Pipeline; |
152 | class ProjNode; |
153 | class RangeCheckNode; |
154 | class RegMask; |
155 | class RegionNode; |
156 | class RootNode; |
157 | class SafePointNode; |
158 | class SafePointScalarObjectNode; |
159 | class StartNode; |
160 | class State; |
161 | class StoreNode; |
162 | class SubNode; |
163 | class SubTypeCheckNode; |
164 | class Type; |
165 | class TypeNode; |
166 | class UnlockNode; |
167 | class VectorNode; |
168 | class LoadVectorNode; |
169 | class LoadVectorMaskedNode; |
170 | class StoreVectorMaskedNode; |
171 | class LoadVectorGatherNode; |
172 | class StoreVectorNode; |
173 | class StoreVectorScatterNode; |
174 | class VectorMaskCmpNode; |
175 | class VectorUnboxNode; |
176 | class VectorSet; |
177 | class VectorReinterpretNode; |
178 | class ShiftVNode; |
179 | |
180 | // The type of all node counts and indexes. |
181 | // It must hold at least 16 bits, but must also be fast to load and store. |
182 | // This type, if less than 32 bits, could limit the number of possible nodes. |
183 | // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.) |
184 | typedef unsigned int node_idx_t; |
185 | |
186 | |
187 | #ifndef OPTO_DU_ITERATOR_ASSERT1 |
188 | #ifdef ASSERT1 |
189 | #define OPTO_DU_ITERATOR_ASSERT1 1 |
190 | #else |
191 | #define OPTO_DU_ITERATOR_ASSERT1 0 |
192 | #endif |
193 | #endif //OPTO_DU_ITERATOR_ASSERT |
194 | |
195 | #if OPTO_DU_ITERATOR_ASSERT1 |
196 | class DUIterator; |
197 | class DUIterator_Fast; |
198 | class DUIterator_Last; |
199 | #else |
200 | typedef uint DUIterator; |
201 | typedef Node** DUIterator_Fast; |
202 | typedef Node** DUIterator_Last; |
203 | #endif |
204 | |
205 | // Node Sentinel |
206 | #define NodeSentinel(Node*)-1 (Node*)-1 |
207 | |
208 | // Unknown count frequency |
209 | #define COUNT_UNKNOWN(-1.0f) (-1.0f) |
210 | |
211 | //------------------------------Node------------------------------------------- |
212 | // Nodes define actions in the program. They create values, which have types. |
213 | // They are both vertices in a directed graph and program primitives. Nodes |
214 | // are labeled; the label is the "opcode", the primitive function in the lambda |
215 | // calculus sense that gives meaning to the Node. Node inputs are ordered (so |
216 | // that "a-b" is different from "b-a"). The inputs to a Node are the inputs to |
217 | // the Node's function. These inputs also define a Type equation for the Node. |
218 | // Solving these Type equations amounts to doing dataflow analysis. |
219 | // Control and data are uniformly represented in the graph. Finally, Nodes |
220 | // have a unique dense integer index which is used to index into side arrays |
221 | // whenever I have phase-specific information. |
222 | |
223 | class Node { |
224 | friend class VMStructs; |
225 | |
226 | // Lots of restrictions on cloning Nodes |
227 | NONCOPYABLE(Node)Node(Node const&) = delete; Node& operator=(Node const &) = delete; |
228 | |
229 | public: |
230 | friend class Compile; |
231 | #if OPTO_DU_ITERATOR_ASSERT1 |
232 | friend class DUIterator_Common; |
233 | friend class DUIterator; |
234 | friend class DUIterator_Fast; |
235 | friend class DUIterator_Last; |
236 | #endif |
237 | |
238 | // Because Nodes come and go, I define an Arena of Node structures to pull |
239 | // from. This should allow fast access to node creation & deletion. This |
240 | // field is a local cache of a value defined in some "program fragment" for |
241 | // which these Nodes are just a part of. |
242 | |
243 | inline void* operator new(size_t x) throw() { |
244 | Compile* C = Compile::current(); |
245 | Node* n = (Node*)C->node_arena()->AmallocWords(x); |
246 | return (void*)n; |
247 | } |
248 | |
249 | // Delete is a NOP |
250 | void operator delete( void *ptr ) {} |
251 | // Fancy destructor; eagerly attempt to reclaim Node numberings and storage |
252 | void destruct(PhaseValues* phase); |
253 | |
254 | // Create a new Node. Required is the number is of inputs required for |
255 | // semantic correctness. |
256 | Node( uint required ); |
257 | |
258 | // Create a new Node with given input edges. |
259 | // This version requires use of the "edge-count" new. |
260 | // E.g. new (C,3) FooNode( C, NULL, left, right ); |
261 | Node( Node *n0 ); |
262 | Node( Node *n0, Node *n1 ); |
263 | Node( Node *n0, Node *n1, Node *n2 ); |
264 | Node( Node *n0, Node *n1, Node *n2, Node *n3 ); |
265 | Node( Node *n0, Node *n1, Node *n2, Node *n3, Node *n4 ); |
266 | Node( Node *n0, Node *n1, Node *n2, Node *n3, Node *n4, Node *n5 ); |
267 | Node( Node *n0, Node *n1, Node *n2, Node *n3, |
268 | Node *n4, Node *n5, Node *n6 ); |
269 | |
270 | // Clone an inherited Node given only the base Node type. |
271 | Node* clone() const; |
272 | |
273 | // Clone a Node, immediately supplying one or two new edges. |
274 | // The first and second arguments, if non-null, replace in(1) and in(2), |
275 | // respectively. |
276 | Node* clone_with_data_edge(Node* in1, Node* in2 = NULL__null) const { |
277 | Node* nn = clone(); |
278 | if (in1 != NULL__null) nn->set_req(1, in1); |
279 | if (in2 != NULL__null) nn->set_req(2, in2); |
280 | return nn; |
281 | } |
282 | |
283 | private: |
284 | // Shared setup for the above constructors. |
285 | // Handles all interactions with Compile::current. |
286 | // Puts initial values in all Node fields except _idx. |
287 | // Returns the initial value for _idx, which cannot |
288 | // be initialized by assignment. |
289 | inline int Init(int req); |
290 | |
291 | //----------------- input edge handling |
292 | protected: |
293 | friend class PhaseCFG; // Access to address of _in array elements |
294 | Node **_in; // Array of use-def references to Nodes |
295 | Node **_out; // Array of def-use references to Nodes |
296 | |
297 | // Input edges are split into two categories. Required edges are required |
298 | // for semantic correctness; order is important and NULLs are allowed. |
299 | // Precedence edges are used to help determine execution order and are |
300 | // added, e.g., for scheduling purposes. They are unordered and not |
301 | // duplicated; they have no embedded NULLs. Edges from 0 to _cnt-1 |
302 | // are required, from _cnt to _max-1 are precedence edges. |
303 | node_idx_t _cnt; // Total number of required Node inputs. |
304 | |
305 | node_idx_t _max; // Actual length of input array. |
306 | |
307 | // Output edges are an unordered list of def-use edges which exactly |
308 | // correspond to required input edges which point from other nodes |
309 | // to this one. Thus the count of the output edges is the number of |
310 | // users of this node. |
311 | node_idx_t _outcnt; // Total number of Node outputs. |
312 | |
313 | node_idx_t _outmax; // Actual length of output array. |
314 | |
315 | // Grow the actual input array to the next larger power-of-2 bigger than len. |
316 | void grow( uint len ); |
317 | // Grow the output array to the next larger power-of-2 bigger than len. |
318 | void out_grow( uint len ); |
319 | |
320 | public: |
321 | // Each Node is assigned a unique small/dense number. This number is used |
322 | // to index into auxiliary arrays of data and bit vectors. |
323 | // The field _idx is declared constant to defend against inadvertent assignments, |
324 | // since it is used by clients as a naked field. However, the field's value can be |
325 | // changed using the set_idx() method. |
326 | // |
327 | // The PhaseRenumberLive phase renumbers nodes based on liveness information. |
328 | // Therefore, it updates the value of the _idx field. The parse-time _idx is |
329 | // preserved in _parse_idx. |
330 | const node_idx_t _idx; |
331 | DEBUG_ONLY(const node_idx_t _parse_idx;)const node_idx_t _parse_idx; |
332 | // IGV node identifier. Two nodes, possibly in different compilation phases, |
333 | // have the same IGV identifier if (and only if) they are the very same node |
334 | // (same memory address) or one is "derived" from the other (by e.g. |
335 | // renumbering or matching). This identifier makes it possible to follow the |
336 | // entire lifetime of a node in IGV even if its C2 identifier (_idx) changes. |
337 | NOT_PRODUCT(node_idx_t _igv_idx;)node_idx_t _igv_idx; |
338 | |
339 | // Get the (read-only) number of input edges |
340 | uint req() const { return _cnt; } |
341 | uint len() const { return _max; } |
342 | // Get the (read-only) number of output edges |
343 | uint outcnt() const { return _outcnt; } |
344 | |
345 | #if OPTO_DU_ITERATOR_ASSERT1 |
346 | // Iterate over the out-edges of this node. Deletions are illegal. |
347 | inline DUIterator outs() const; |
348 | // Use this when the out array might have changed to suppress asserts. |
349 | inline DUIterator& refresh_out_pos(DUIterator& i) const; |
350 | // Does the node have an out at this position? (Used for iteration.) |
351 | inline bool has_out(DUIterator& i) const; |
352 | inline Node* out(DUIterator& i) const; |
353 | // Iterate over the out-edges of this node. All changes are illegal. |
354 | inline DUIterator_Fast fast_outs(DUIterator_Fast& max) const; |
355 | inline Node* fast_out(DUIterator_Fast& i) const; |
356 | // Iterate over the out-edges of this node, deleting one at a time. |
357 | inline DUIterator_Last last_outs(DUIterator_Last& min) const; |
358 | inline Node* last_out(DUIterator_Last& i) const; |
359 | // The inline bodies of all these methods are after the iterator definitions. |
360 | #else |
361 | // Iterate over the out-edges of this node. Deletions are illegal. |
362 | // This iteration uses integral indexes, to decouple from array reallocations. |
363 | DUIterator outs() const { return 0; } |
364 | // Use this when the out array might have changed to suppress asserts. |
365 | DUIterator refresh_out_pos(DUIterator i) const { return i; } |
366 | |
367 | // Reference to the i'th output Node. Error if out of bounds. |
368 | Node* out(DUIterator i) const { assert(i < _outcnt, "oob")do { if (!(i < _outcnt)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 368, "assert(" "i < _outcnt" ") failed", "oob"); ::breakpoint (); } } while (0); return _out[i]; } |
369 | // Does the node have an out at this position? (Used for iteration.) |
370 | bool has_out(DUIterator i) const { return i < _outcnt; } |
371 | |
372 | // Iterate over the out-edges of this node. All changes are illegal. |
373 | // This iteration uses a pointer internal to the out array. |
374 | DUIterator_Fast fast_outs(DUIterator_Fast& max) const { |
375 | Node** out = _out; |
376 | // Assign a limit pointer to the reference argument: |
377 | max = out + (ptrdiff_t)_outcnt; |
378 | // Return the base pointer: |
379 | return out; |
380 | } |
381 | Node* fast_out(DUIterator_Fast i) const { return *i; } |
382 | // Iterate over the out-edges of this node, deleting one at a time. |
383 | // This iteration uses a pointer internal to the out array. |
384 | DUIterator_Last last_outs(DUIterator_Last& min) const { |
385 | Node** out = _out; |
386 | // Assign a limit pointer to the reference argument: |
387 | min = out; |
388 | // Return the pointer to the start of the iteration: |
389 | return out + (ptrdiff_t)_outcnt - 1; |
390 | } |
391 | Node* last_out(DUIterator_Last i) const { return *i; } |
392 | #endif |
393 | |
394 | // Reference to the i'th input Node. Error if out of bounds. |
395 | Node* in(uint i) const { assert(i < _max, "oob: i=%d, _max=%d", i, _max)do { if (!(i < _max)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 395, "assert(" "i < _max" ") failed", "oob: i=%d, _max=%d" , i, _max); ::breakpoint(); } } while (0); return _in[i]; } |
396 | // Reference to the i'th input Node. NULL if out of bounds. |
397 | Node* lookup(uint i) const { return ((i < _max) ? _in[i] : NULL__null); } |
398 | // Reference to the i'th output Node. Error if out of bounds. |
399 | // Use this accessor sparingly. We are going trying to use iterators instead. |
400 | Node* raw_out(uint i) const { assert(i < _outcnt,"oob")do { if (!(i < _outcnt)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 400, "assert(" "i < _outcnt" ") failed", "oob"); ::breakpoint (); } } while (0); return _out[i]; } |
401 | // Return the unique out edge. |
402 | Node* unique_out() const { assert(_outcnt==1,"not unique")do { if (!(_outcnt==1)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 402, "assert(" "_outcnt==1" ") failed", "not unique"); ::breakpoint (); } } while (0); return _out[0]; } |
403 | // Delete out edge at position 'i' by moving last out edge to position 'i' |
404 | void raw_del_out(uint i) { |
405 | assert(i < _outcnt,"oob")do { if (!(i < _outcnt)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 405, "assert(" "i < _outcnt" ") failed", "oob"); ::breakpoint (); } } while (0); |
406 | assert(_outcnt > 0,"oob")do { if (!(_outcnt > 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 406, "assert(" "_outcnt > 0" ") failed", "oob"); ::breakpoint (); } } while (0); |
407 | #if OPTO_DU_ITERATOR_ASSERT1 |
408 | // Record that a change happened here. |
409 | debug_only(_last_del = _out[i]; ++_del_tick)_last_del = _out[i]; ++_del_tick; |
410 | #endif |
411 | _out[i] = _out[--_outcnt]; |
412 | // Smash the old edge so it can't be used accidentally. |
413 | debug_only(_out[_outcnt] = (Node *)(uintptr_t)0xdeadbeef)_out[_outcnt] = (Node *)(uintptr_t)0xdeadbeef; |
414 | } |
415 | |
416 | #ifdef ASSERT1 |
417 | bool is_dead() const; |
418 | #define is_not_dead(n)((n) == __null || !VerifyIterativeGVN || !((n)->is_dead()) ) ((n) == NULL__null || !VerifyIterativeGVN || !((n)->is_dead())) |
419 | bool is_reachable_from_root() const; |
420 | #endif |
421 | // Check whether node has become unreachable |
422 | bool is_unreachable(PhaseIterGVN &igvn) const; |
423 | |
424 | // Set a required input edge, also updates corresponding output edge |
425 | void add_req( Node *n ); // Append a NEW required input |
426 | void add_req( Node *n0, Node *n1 ) { |
427 | add_req(n0); add_req(n1); } |
428 | void add_req( Node *n0, Node *n1, Node *n2 ) { |
429 | add_req(n0); add_req(n1); add_req(n2); } |
430 | void add_req_batch( Node* n, uint m ); // Append m NEW required inputs (all n). |
431 | void del_req( uint idx ); // Delete required edge & compact |
432 | void del_req_ordered( uint idx ); // Delete required edge & compact with preserved order |
433 | void ins_req( uint i, Node *n ); // Insert a NEW required input |
434 | void set_req( uint i, Node *n ) { |
435 | assert( is_not_dead(n), "can not use dead node")do { if (!(((n) == __null || !VerifyIterativeGVN || !((n)-> is_dead())))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 435, "assert(" "((n) == __null || !VerifyIterativeGVN || !((n)->is_dead()))" ") failed", "can not use dead node"); ::breakpoint(); } } while (0); |
436 | assert( i < _cnt, "oob: i=%d, _cnt=%d", i, _cnt)do { if (!(i < _cnt)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 436, "assert(" "i < _cnt" ") failed", "oob: i=%d, _cnt=%d" , i, _cnt); ::breakpoint(); } } while (0); |
437 | assert( !VerifyHashTableKeys || _hash_lock == 0,do { if (!(!VerifyHashTableKeys || _hash_lock == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 438, "assert(" "!VerifyHashTableKeys || _hash_lock == 0" ") failed" , "remove node from hash table before modifying it"); ::breakpoint (); } } while (0) |
438 | "remove node from hash table before modifying it")do { if (!(!VerifyHashTableKeys || _hash_lock == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 438, "assert(" "!VerifyHashTableKeys || _hash_lock == 0" ") failed" , "remove node from hash table before modifying it"); ::breakpoint (); } } while (0); |
439 | Node** p = &_in[i]; // cache this._in, across the del_out call |
440 | if (*p != NULL__null) (*p)->del_out((Node *)this); |
441 | (*p) = n; |
442 | if (n != NULL__null) n->add_out((Node *)this); |
443 | Compile::current()->record_modified_node(this); |
444 | } |
445 | // Light version of set_req() to init inputs after node creation. |
446 | void init_req( uint i, Node *n ) { |
447 | assert( i == 0 && this == n ||do { if (!(i == 0 && this == n || ((n) == __null || ! VerifyIterativeGVN || !((n)->is_dead())))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 448, "assert(" "i == 0 && this == n || ((n) == __null || !VerifyIterativeGVN || !((n)->is_dead()))" ") failed", "can not use dead node"); ::breakpoint(); } } while (0) |
448 | is_not_dead(n), "can not use dead node")do { if (!(i == 0 && this == n || ((n) == __null || ! VerifyIterativeGVN || !((n)->is_dead())))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 448, "assert(" "i == 0 && this == n || ((n) == __null || !VerifyIterativeGVN || !((n)->is_dead()))" ") failed", "can not use dead node"); ::breakpoint(); } } while (0); |
449 | assert( i < _cnt, "oob")do { if (!(i < _cnt)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 449, "assert(" "i < _cnt" ") failed", "oob"); ::breakpoint (); } } while (0); |
450 | assert( !VerifyHashTableKeys || _hash_lock == 0,do { if (!(!VerifyHashTableKeys || _hash_lock == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 451, "assert(" "!VerifyHashTableKeys || _hash_lock == 0" ") failed" , "remove node from hash table before modifying it"); ::breakpoint (); } } while (0) |
451 | "remove node from hash table before modifying it")do { if (!(!VerifyHashTableKeys || _hash_lock == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 451, "assert(" "!VerifyHashTableKeys || _hash_lock == 0" ") failed" , "remove node from hash table before modifying it"); ::breakpoint (); } } while (0); |
452 | assert( _in[i] == NULL, "sanity")do { if (!(_in[i] == __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 452, "assert(" "_in[i] == __null" ") failed", "sanity"); :: breakpoint(); } } while (0); |
453 | _in[i] = n; |
454 | if (n != NULL__null) n->add_out((Node *)this); |
455 | Compile::current()->record_modified_node(this); |
456 | } |
457 | // Find first occurrence of n among my edges: |
458 | int find_edge(Node* n); |
459 | int find_prec_edge(Node* n) { |
460 | for (uint i = req(); i < len(); i++) { |
461 | if (_in[i] == n) return i; |
462 | if (_in[i] == NULL__null) { |
463 | DEBUG_ONLY( while ((++i) < len()) assert(_in[i] == NULL, "Gap in prec edges!"); )while ((++i) < len()) do { if (!(_in[i] == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 463, "assert(" "_in[i] == __null" ") failed", "Gap in prec edges!" ); ::breakpoint(); } } while (0); |
464 | break; |
465 | } |
466 | } |
467 | return -1; |
468 | } |
469 | int replace_edge(Node* old, Node* neww, PhaseGVN* gvn = NULL__null); |
470 | int replace_edges_in_range(Node* old, Node* neww, int start, int end, PhaseGVN* gvn); |
471 | // NULL out all inputs to eliminate incoming Def-Use edges. |
472 | void disconnect_inputs(Compile* C); |
473 | |
474 | // Quickly, return true if and only if I am Compile::current()->top(). |
475 | bool is_top() const { |
476 | assert((this == (Node*) Compile::current()->top()) == (_out == NULL), "")do { if (!((this == (Node*) Compile::current()->top()) == ( _out == __null))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 476, "assert(" "(this == (Node*) Compile::current()->top()) == (_out == __null)" ") failed", ""); ::breakpoint(); } } while (0); |
477 | return (_out == NULL__null); |
478 | } |
479 | // Reaffirm invariants for is_top. (Only from Compile::set_cached_top_node.) |
480 | void setup_is_top(); |
481 | |
482 | // Strip away casting. (It is depth-limited.) |
483 | Node* uncast(bool keep_deps = false) const; |
484 | // Return whether two Nodes are equivalent, after stripping casting. |
485 | bool eqv_uncast(const Node* n, bool keep_deps = false) const { |
486 | return (this->uncast(keep_deps) == n->uncast(keep_deps)); |
487 | } |
488 | |
489 | // Find out of current node that matches opcode. |
490 | Node* find_out_with(int opcode); |
491 | // Return true if the current node has an out that matches opcode. |
492 | bool has_out_with(int opcode); |
493 | // Return true if the current node has an out that matches any of the opcodes. |
494 | bool has_out_with(int opcode1, int opcode2, int opcode3, int opcode4); |
495 | |
496 | private: |
497 | static Node* uncast_helper(const Node* n, bool keep_deps); |
498 | |
499 | // Add an output edge to the end of the list |
500 | void add_out( Node *n ) { |
501 | if (is_top()) return; |
502 | if( _outcnt == _outmax ) out_grow(_outcnt); |
503 | _out[_outcnt++] = n; |
504 | } |
505 | // Delete an output edge |
506 | void del_out( Node *n ) { |
507 | if (is_top()) return; |
508 | Node** outp = &_out[_outcnt]; |
509 | // Find and remove n |
510 | do { |
511 | assert(outp > _out, "Missing Def-Use edge")do { if (!(outp > _out)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 511, "assert(" "outp > _out" ") failed", "Missing Def-Use edge" ); ::breakpoint(); } } while (0); |
512 | } while (*--outp != n); |
513 | *outp = _out[--_outcnt]; |
514 | // Smash the old edge so it can't be used accidentally. |
515 | debug_only(_out[_outcnt] = (Node *)(uintptr_t)0xdeadbeef)_out[_outcnt] = (Node *)(uintptr_t)0xdeadbeef; |
516 | // Record that a change happened here. |
517 | #if OPTO_DU_ITERATOR_ASSERT1 |
518 | debug_only(_last_del = n; ++_del_tick)_last_del = n; ++_del_tick; |
519 | #endif |
520 | } |
521 | // Close gap after removing edge. |
522 | void close_prec_gap_at(uint gap) { |
523 | assert(_cnt <= gap && gap < _max, "no valid prec edge")do { if (!(_cnt <= gap && gap < _max)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 523, "assert(" "_cnt <= gap && gap < _max" ") failed" , "no valid prec edge"); ::breakpoint(); } } while (0); |
524 | uint i = gap; |
525 | Node *last = NULL__null; |
526 | for (; i < _max-1; ++i) { |
527 | Node *next = _in[i+1]; |
528 | if (next == NULL__null) break; |
529 | last = next; |
530 | } |
531 | _in[gap] = last; // Move last slot to empty one. |
532 | _in[i] = NULL__null; // NULL out last slot. |
533 | } |
534 | |
535 | public: |
536 | // Globally replace this node by a given new node, updating all uses. |
537 | void replace_by(Node* new_node); |
538 | // Globally replace this node by a given new node, updating all uses |
539 | // and cutting input edges of old node. |
540 | void subsume_by(Node* new_node, Compile* c) { |
541 | replace_by(new_node); |
542 | disconnect_inputs(c); |
543 | } |
544 | void set_req_X(uint i, Node *n, PhaseIterGVN *igvn); |
545 | void set_req_X(uint i, Node *n, PhaseGVN *gvn); |
546 | // Find the one non-null required input. RegionNode only |
547 | Node *nonnull_req() const; |
548 | // Add or remove precedence edges |
549 | void add_prec( Node *n ); |
550 | void rm_prec( uint i ); |
551 | |
552 | // Note: prec(i) will not necessarily point to n if edge already exists. |
553 | void set_prec( uint i, Node *n ) { |
554 | assert(i < _max, "oob: i=%d, _max=%d", i, _max)do { if (!(i < _max)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 554, "assert(" "i < _max" ") failed", "oob: i=%d, _max=%d" , i, _max); ::breakpoint(); } } while (0); |
555 | assert(is_not_dead(n), "can not use dead node")do { if (!(((n) == __null || !VerifyIterativeGVN || !((n)-> is_dead())))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 555, "assert(" "((n) == __null || !VerifyIterativeGVN || !((n)->is_dead()))" ") failed", "can not use dead node"); ::breakpoint(); } } while (0); |
556 | assert(i >= _cnt, "not a precedence edge")do { if (!(i >= _cnt)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 556, "assert(" "i >= _cnt" ") failed", "not a precedence edge" ); ::breakpoint(); } } while (0); |
557 | // Avoid spec violation: duplicated prec edge. |
558 | if (_in[i] == n) return; |
559 | if (n == NULL__null || find_prec_edge(n) != -1) { |
560 | rm_prec(i); |
561 | return; |
562 | } |
563 | if (_in[i] != NULL__null) _in[i]->del_out((Node *)this); |
564 | _in[i] = n; |
565 | n->add_out((Node *)this); |
566 | } |
567 | |
568 | // Set this node's index, used by cisc_version to replace current node |
569 | void set_idx(uint new_idx) { |
570 | const node_idx_t* ref = &_idx; |
571 | *(node_idx_t*)ref = new_idx; |
572 | } |
573 | // Swap input edge order. (Edge indexes i1 and i2 are usually 1 and 2.) |
574 | void swap_edges(uint i1, uint i2) { |
575 | debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH)uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH; |
576 | // Def-Use info is unchanged |
577 | Node* n1 = in(i1); |
578 | Node* n2 = in(i2); |
579 | _in[i1] = n2; |
580 | _in[i2] = n1; |
581 | // If this node is in the hash table, make sure it doesn't need a rehash. |
582 | assert(check_hash == NO_HASH || check_hash == hash(), "edge swap must preserve hash code")do { if (!(check_hash == NO_HASH || check_hash == hash())) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 582, "assert(" "check_hash == NO_HASH || check_hash == hash()" ") failed", "edge swap must preserve hash code"); ::breakpoint (); } } while (0); |
583 | } |
584 | |
585 | // Iterators over input Nodes for a Node X are written as: |
586 | // for( i = 0; i < X.req(); i++ ) ... X[i] ... |
587 | // NOTE: Required edges can contain embedded NULL pointers. |
588 | |
589 | //----------------- Other Node Properties |
590 | |
591 | // Generate class IDs for (some) ideal nodes so that it is possible to determine |
592 | // the type of a node using a non-virtual method call (the method is_<Node>() below). |
593 | // |
594 | // A class ID of an ideal node is a set of bits. In a class ID, a single bit determines |
595 | // the type of the node the ID represents; another subset of an ID's bits are reserved |
596 | // for the superclasses of the node represented by the ID. |
597 | // |
598 | // By design, if A is a supertype of B, A.is_B() returns true and B.is_A() |
599 | // returns false. A.is_A() returns true. |
600 | // |
601 | // If two classes, A and B, have the same superclass, a different bit of A's class id |
602 | // is reserved for A's type than for B's type. That bit is specified by the third |
603 | // parameter in the macro DEFINE_CLASS_ID. |
604 | // |
605 | // By convention, classes with deeper hierarchy are declared first. Moreover, |
606 | // classes with the same hierarchy depth are sorted by usage frequency. |
607 | // |
608 | // The query method masks the bits to cut off bits of subclasses and then compares |
609 | // the result with the class id (see the macro DEFINE_CLASS_QUERY below). |
610 | // |
611 | // Class_MachCall=30, ClassMask_MachCall=31 |
612 | // 12 8 4 0 |
613 | // 0 0 0 0 0 0 0 0 1 1 1 1 0 |
614 | // | | | | |
615 | // | | | Bit_Mach=2 |
616 | // | | Bit_MachReturn=4 |
617 | // | Bit_MachSafePoint=8 |
618 | // Bit_MachCall=16 |
619 | // |
620 | // Class_CountedLoop=56, ClassMask_CountedLoop=63 |
621 | // 12 8 4 0 |
622 | // 0 0 0 0 0 0 0 1 1 1 0 0 0 |
623 | // | | | |
624 | // | | Bit_Region=8 |
625 | // | Bit_Loop=16 |
626 | // Bit_CountedLoop=32 |
627 | |
628 | #define DEFINE_CLASS_ID(cl, supcl, subn) \ |
629 | Bit_##cl = (Class_##supcl == 0) ? 1 << subn : (Bit_##supcl) << (1 + subn) , \ |
630 | Class_##cl = Class_##supcl + Bit_##cl , \ |
631 | ClassMask_##cl = ((Bit_##cl << 1) - 1) , |
632 | |
633 | // This enum is used only for C2 ideal and mach nodes with is_<node>() methods |
634 | // so that its values fit into 32 bits. |
635 | enum NodeClasses { |
636 | Bit_Node = 0x00000000, |
637 | Class_Node = 0x00000000, |
638 | ClassMask_Node = 0xFFFFFFFF, |
639 | |
640 | DEFINE_CLASS_ID(Multi, Node, 0) |
641 | DEFINE_CLASS_ID(SafePoint, Multi, 0) |
642 | DEFINE_CLASS_ID(Call, SafePoint, 0) |
643 | DEFINE_CLASS_ID(CallJava, Call, 0) |
644 | DEFINE_CLASS_ID(CallStaticJava, CallJava, 0) |
645 | DEFINE_CLASS_ID(CallDynamicJava, CallJava, 1) |
646 | DEFINE_CLASS_ID(CallRuntime, Call, 1) |
647 | DEFINE_CLASS_ID(CallLeaf, CallRuntime, 0) |
648 | DEFINE_CLASS_ID(CallLeafNoFP, CallLeaf, 0) |
649 | DEFINE_CLASS_ID(Allocate, Call, 2) |
650 | DEFINE_CLASS_ID(AllocateArray, Allocate, 0) |
651 | DEFINE_CLASS_ID(AbstractLock, Call, 3) |
652 | DEFINE_CLASS_ID(Lock, AbstractLock, 0) |
653 | DEFINE_CLASS_ID(Unlock, AbstractLock, 1) |
654 | DEFINE_CLASS_ID(ArrayCopy, Call, 4) |
655 | DEFINE_CLASS_ID(CallNative, Call, 5) |
656 | DEFINE_CLASS_ID(MultiBranch, Multi, 1) |
657 | DEFINE_CLASS_ID(PCTable, MultiBranch, 0) |
658 | DEFINE_CLASS_ID(Catch, PCTable, 0) |
659 | DEFINE_CLASS_ID(Jump, PCTable, 1) |
660 | DEFINE_CLASS_ID(If, MultiBranch, 1) |
661 | DEFINE_CLASS_ID(BaseCountedLoopEnd, If, 0) |
662 | DEFINE_CLASS_ID(CountedLoopEnd, BaseCountedLoopEnd, 0) |
663 | DEFINE_CLASS_ID(LongCountedLoopEnd, BaseCountedLoopEnd, 1) |
664 | DEFINE_CLASS_ID(RangeCheck, If, 1) |
665 | DEFINE_CLASS_ID(OuterStripMinedLoopEnd, If, 2) |
666 | DEFINE_CLASS_ID(NeverBranch, MultiBranch, 2) |
667 | DEFINE_CLASS_ID(Start, Multi, 2) |
668 | DEFINE_CLASS_ID(MemBar, Multi, 3) |
669 | DEFINE_CLASS_ID(Initialize, MemBar, 0) |
670 | DEFINE_CLASS_ID(MemBarStoreStore, MemBar, 1) |
671 | |
672 | DEFINE_CLASS_ID(Mach, Node, 1) |
673 | DEFINE_CLASS_ID(MachReturn, Mach, 0) |
674 | DEFINE_CLASS_ID(MachSafePoint, MachReturn, 0) |
675 | DEFINE_CLASS_ID(MachCall, MachSafePoint, 0) |
676 | DEFINE_CLASS_ID(MachCallJava, MachCall, 0) |
677 | DEFINE_CLASS_ID(MachCallStaticJava, MachCallJava, 0) |
678 | DEFINE_CLASS_ID(MachCallDynamicJava, MachCallJava, 1) |
679 | DEFINE_CLASS_ID(MachCallRuntime, MachCall, 1) |
680 | DEFINE_CLASS_ID(MachCallLeaf, MachCallRuntime, 0) |
681 | DEFINE_CLASS_ID(MachCallNative, MachCall, 2) |
682 | DEFINE_CLASS_ID(MachBranch, Mach, 1) |
683 | DEFINE_CLASS_ID(MachIf, MachBranch, 0) |
684 | DEFINE_CLASS_ID(MachGoto, MachBranch, 1) |
685 | DEFINE_CLASS_ID(MachNullCheck, MachBranch, 2) |
686 | DEFINE_CLASS_ID(MachSpillCopy, Mach, 2) |
687 | DEFINE_CLASS_ID(MachTemp, Mach, 3) |
688 | DEFINE_CLASS_ID(MachConstantBase, Mach, 4) |
689 | DEFINE_CLASS_ID(MachConstant, Mach, 5) |
690 | DEFINE_CLASS_ID(MachJump, MachConstant, 0) |
691 | DEFINE_CLASS_ID(MachMerge, Mach, 6) |
692 | DEFINE_CLASS_ID(MachMemBar, Mach, 7) |
693 | |
694 | DEFINE_CLASS_ID(Type, Node, 2) |
695 | DEFINE_CLASS_ID(Phi, Type, 0) |
696 | DEFINE_CLASS_ID(ConstraintCast, Type, 1) |
697 | DEFINE_CLASS_ID(CastII, ConstraintCast, 0) |
698 | DEFINE_CLASS_ID(CheckCastPP, ConstraintCast, 1) |
699 | DEFINE_CLASS_ID(CastLL, ConstraintCast, 2) |
700 | DEFINE_CLASS_ID(CastFF, ConstraintCast, 3) |
701 | DEFINE_CLASS_ID(CastDD, ConstraintCast, 4) |
702 | DEFINE_CLASS_ID(CastVV, ConstraintCast, 5) |
703 | DEFINE_CLASS_ID(CMove, Type, 3) |
704 | DEFINE_CLASS_ID(SafePointScalarObject, Type, 4) |
705 | DEFINE_CLASS_ID(DecodeNarrowPtr, Type, 5) |
706 | DEFINE_CLASS_ID(DecodeN, DecodeNarrowPtr, 0) |
707 | DEFINE_CLASS_ID(DecodeNKlass, DecodeNarrowPtr, 1) |
708 | DEFINE_CLASS_ID(EncodeNarrowPtr, Type, 6) |
709 | DEFINE_CLASS_ID(EncodeP, EncodeNarrowPtr, 0) |
710 | DEFINE_CLASS_ID(EncodePKlass, EncodeNarrowPtr, 1) |
711 | DEFINE_CLASS_ID(Vector, Type, 7) |
712 | DEFINE_CLASS_ID(VectorMaskCmp, Vector, 0) |
713 | DEFINE_CLASS_ID(VectorUnbox, Vector, 1) |
714 | DEFINE_CLASS_ID(VectorReinterpret, Vector, 2) |
715 | DEFINE_CLASS_ID(ShiftV, Vector, 3) |
716 | |
717 | DEFINE_CLASS_ID(Proj, Node, 3) |
718 | DEFINE_CLASS_ID(CatchProj, Proj, 0) |
719 | DEFINE_CLASS_ID(JumpProj, Proj, 1) |
720 | DEFINE_CLASS_ID(IfProj, Proj, 2) |
721 | DEFINE_CLASS_ID(IfTrue, IfProj, 0) |
722 | DEFINE_CLASS_ID(IfFalse, IfProj, 1) |
723 | DEFINE_CLASS_ID(Parm, Proj, 4) |
724 | DEFINE_CLASS_ID(MachProj, Proj, 5) |
725 | |
726 | DEFINE_CLASS_ID(Mem, Node, 4) |
727 | DEFINE_CLASS_ID(Load, Mem, 0) |
728 | DEFINE_CLASS_ID(LoadVector, Load, 0) |
729 | DEFINE_CLASS_ID(LoadVectorGather, LoadVector, 0) |
730 | DEFINE_CLASS_ID(LoadVectorMasked, LoadVector, 1) |
731 | DEFINE_CLASS_ID(Store, Mem, 1) |
732 | DEFINE_CLASS_ID(StoreVector, Store, 0) |
733 | DEFINE_CLASS_ID(StoreVectorScatter, StoreVector, 0) |
734 | DEFINE_CLASS_ID(StoreVectorMasked, StoreVector, 1) |
735 | DEFINE_CLASS_ID(LoadStore, Mem, 2) |
736 | DEFINE_CLASS_ID(LoadStoreConditional, LoadStore, 0) |
737 | DEFINE_CLASS_ID(CompareAndSwap, LoadStoreConditional, 0) |
738 | DEFINE_CLASS_ID(CompareAndExchangeNode, LoadStore, 1) |
739 | |
740 | DEFINE_CLASS_ID(Region, Node, 5) |
741 | DEFINE_CLASS_ID(Loop, Region, 0) |
742 | DEFINE_CLASS_ID(Root, Loop, 0) |
743 | DEFINE_CLASS_ID(BaseCountedLoop, Loop, 1) |
744 | DEFINE_CLASS_ID(CountedLoop, BaseCountedLoop, 0) |
745 | DEFINE_CLASS_ID(LongCountedLoop, BaseCountedLoop, 1) |
746 | DEFINE_CLASS_ID(OuterStripMinedLoop, Loop, 2) |
747 | |
748 | DEFINE_CLASS_ID(Sub, Node, 6) |
749 | DEFINE_CLASS_ID(Cmp, Sub, 0) |
750 | DEFINE_CLASS_ID(FastLock, Cmp, 0) |
751 | DEFINE_CLASS_ID(FastUnlock, Cmp, 1) |
752 | DEFINE_CLASS_ID(SubTypeCheck,Cmp, 2) |
753 | |
754 | DEFINE_CLASS_ID(MergeMem, Node, 7) |
755 | DEFINE_CLASS_ID(Bool, Node, 8) |
756 | DEFINE_CLASS_ID(AddP, Node, 9) |
757 | DEFINE_CLASS_ID(BoxLock, Node, 10) |
758 | DEFINE_CLASS_ID(Add, Node, 11) |
759 | DEFINE_CLASS_ID(Mul, Node, 12) |
760 | DEFINE_CLASS_ID(ClearArray, Node, 14) |
761 | DEFINE_CLASS_ID(Halt, Node, 15) |
762 | DEFINE_CLASS_ID(Opaque1, Node, 16) |
763 | DEFINE_CLASS_ID(Move, Node, 17) |
764 | DEFINE_CLASS_ID(LShift, Node, 18) |
765 | |
766 | _max_classes = ClassMask_Move |
767 | }; |
768 | #undef DEFINE_CLASS_ID |
769 | |
770 | // Flags are sorted by usage frequency. |
771 | enum NodeFlags { |
772 | Flag_is_Copy = 1 << 0, // should be first bit to avoid shift |
773 | Flag_rematerialize = 1 << 1, |
774 | Flag_needs_anti_dependence_check = 1 << 2, |
775 | Flag_is_macro = 1 << 3, |
776 | Flag_is_Con = 1 << 4, |
777 | Flag_is_cisc_alternate = 1 << 5, |
778 | Flag_is_dead_loop_safe = 1 << 6, |
779 | Flag_may_be_short_branch = 1 << 7, |
780 | Flag_avoid_back_to_back_before = 1 << 8, |
781 | Flag_avoid_back_to_back_after = 1 << 9, |
782 | Flag_has_call = 1 << 10, |
783 | Flag_is_reduction = 1 << 11, |
784 | Flag_is_scheduled = 1 << 12, |
785 | Flag_has_vector_mask_set = 1 << 13, |
786 | Flag_is_expensive = 1 << 14, |
787 | Flag_is_predicated_vector = 1 << 15, |
788 | Flag_for_post_loop_opts_igvn = 1 << 16, |
789 | _last_flag = Flag_for_post_loop_opts_igvn |
790 | }; |
791 | |
792 | class PD; |
793 | |
794 | private: |
795 | juint _class_id; |
796 | juint _flags; |
797 | |
798 | static juint max_flags(); |
799 | |
800 | protected: |
801 | // These methods should be called from constructors only. |
802 | void init_class_id(juint c) { |
803 | _class_id = c; // cast out const |
804 | } |
805 | void init_flags(uint fl) { |
806 | assert(fl <= max_flags(), "invalid node flag")do { if (!(fl <= max_flags())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 806, "assert(" "fl <= max_flags()" ") failed", "invalid node flag" ); ::breakpoint(); } } while (0); |
807 | _flags |= fl; |
808 | } |
809 | void clear_flag(uint fl) { |
810 | assert(fl <= max_flags(), "invalid node flag")do { if (!(fl <= max_flags())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 810, "assert(" "fl <= max_flags()" ") failed", "invalid node flag" ); ::breakpoint(); } } while (0); |
811 | _flags &= ~fl; |
812 | } |
813 | |
814 | public: |
815 | const juint class_id() const { return _class_id; } |
816 | |
817 | const juint flags() const { return _flags; } |
818 | |
819 | void add_flag(juint fl) { init_flags(fl); } |
820 | |
821 | void remove_flag(juint fl) { clear_flag(fl); } |
822 | |
823 | // Return a dense integer opcode number |
824 | virtual int Opcode() const; |
825 | |
826 | // Virtual inherited Node size |
827 | virtual uint size_of() const; |
828 | |
829 | // Other interesting Node properties |
830 | #define DEFINE_CLASS_QUERY(type) \ |
831 | bool is_##type() const { \ |
832 | return ((_class_id & ClassMask_##type) == Class_##type); \ |
833 | } \ |
834 | type##Node *as_##type() const { \ |
835 | assert(is_##type(), "invalid node class: %s", Name())do { if (!(is_##type())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 835, "assert(" "is_##type()" ") failed", "invalid node class: %s" , Name()); ::breakpoint(); } } while (0); \ |
836 | return (type##Node*)this; \ |
837 | } \ |
838 | type##Node* isa_##type() const { \ |
839 | return (is_##type()) ? as_##type() : NULL__null; \ |
840 | } |
841 | |
842 | DEFINE_CLASS_QUERY(AbstractLock) |
843 | DEFINE_CLASS_QUERY(Add) |
844 | DEFINE_CLASS_QUERY(AddP) |
845 | DEFINE_CLASS_QUERY(Allocate) |
846 | DEFINE_CLASS_QUERY(AllocateArray) |
847 | DEFINE_CLASS_QUERY(ArrayCopy) |
848 | DEFINE_CLASS_QUERY(BaseCountedLoop) |
849 | DEFINE_CLASS_QUERY(BaseCountedLoopEnd) |
850 | DEFINE_CLASS_QUERY(Bool) |
851 | DEFINE_CLASS_QUERY(BoxLock) |
852 | DEFINE_CLASS_QUERY(Call) |
853 | DEFINE_CLASS_QUERY(CallNative) |
854 | DEFINE_CLASS_QUERY(CallDynamicJava) |
855 | DEFINE_CLASS_QUERY(CallJava) |
856 | DEFINE_CLASS_QUERY(CallLeaf) |
857 | DEFINE_CLASS_QUERY(CallLeafNoFP) |
858 | DEFINE_CLASS_QUERY(CallRuntime) |
859 | DEFINE_CLASS_QUERY(CallStaticJava) |
860 | DEFINE_CLASS_QUERY(Catch) |
861 | DEFINE_CLASS_QUERY(CatchProj) |
862 | DEFINE_CLASS_QUERY(CheckCastPP) |
863 | DEFINE_CLASS_QUERY(CastII) |
864 | DEFINE_CLASS_QUERY(CastLL) |
865 | DEFINE_CLASS_QUERY(ConstraintCast) |
866 | DEFINE_CLASS_QUERY(ClearArray) |
867 | DEFINE_CLASS_QUERY(CMove) |
868 | DEFINE_CLASS_QUERY(Cmp) |
869 | DEFINE_CLASS_QUERY(CountedLoop) |
870 | DEFINE_CLASS_QUERY(CountedLoopEnd) |
871 | DEFINE_CLASS_QUERY(DecodeNarrowPtr) |
872 | DEFINE_CLASS_QUERY(DecodeN) |
873 | DEFINE_CLASS_QUERY(DecodeNKlass) |
874 | DEFINE_CLASS_QUERY(EncodeNarrowPtr) |
875 | DEFINE_CLASS_QUERY(EncodeP) |
876 | DEFINE_CLASS_QUERY(EncodePKlass) |
877 | DEFINE_CLASS_QUERY(FastLock) |
878 | DEFINE_CLASS_QUERY(FastUnlock) |
879 | DEFINE_CLASS_QUERY(Halt) |
880 | DEFINE_CLASS_QUERY(If) |
881 | DEFINE_CLASS_QUERY(RangeCheck) |
882 | DEFINE_CLASS_QUERY(IfProj) |
883 | DEFINE_CLASS_QUERY(IfFalse) |
884 | DEFINE_CLASS_QUERY(IfTrue) |
885 | DEFINE_CLASS_QUERY(Initialize) |
886 | DEFINE_CLASS_QUERY(Jump) |
887 | DEFINE_CLASS_QUERY(JumpProj) |
888 | DEFINE_CLASS_QUERY(LongCountedLoop) |
889 | DEFINE_CLASS_QUERY(LongCountedLoopEnd) |
890 | DEFINE_CLASS_QUERY(Load) |
891 | DEFINE_CLASS_QUERY(LoadStore) |
892 | DEFINE_CLASS_QUERY(LoadStoreConditional) |
893 | DEFINE_CLASS_QUERY(Lock) |
894 | DEFINE_CLASS_QUERY(Loop) |
895 | DEFINE_CLASS_QUERY(LShift) |
896 | DEFINE_CLASS_QUERY(Mach) |
897 | DEFINE_CLASS_QUERY(MachBranch) |
898 | DEFINE_CLASS_QUERY(MachCall) |
899 | DEFINE_CLASS_QUERY(MachCallNative) |
900 | DEFINE_CLASS_QUERY(MachCallDynamicJava) |
901 | DEFINE_CLASS_QUERY(MachCallJava) |
902 | DEFINE_CLASS_QUERY(MachCallLeaf) |
903 | DEFINE_CLASS_QUERY(MachCallRuntime) |
904 | DEFINE_CLASS_QUERY(MachCallStaticJava) |
905 | DEFINE_CLASS_QUERY(MachConstantBase) |
906 | DEFINE_CLASS_QUERY(MachConstant) |
907 | DEFINE_CLASS_QUERY(MachGoto) |
908 | DEFINE_CLASS_QUERY(MachIf) |
909 | DEFINE_CLASS_QUERY(MachJump) |
910 | DEFINE_CLASS_QUERY(MachNullCheck) |
911 | DEFINE_CLASS_QUERY(MachProj) |
912 | DEFINE_CLASS_QUERY(MachReturn) |
913 | DEFINE_CLASS_QUERY(MachSafePoint) |
914 | DEFINE_CLASS_QUERY(MachSpillCopy) |
915 | DEFINE_CLASS_QUERY(MachTemp) |
916 | DEFINE_CLASS_QUERY(MachMemBar) |
917 | DEFINE_CLASS_QUERY(MachMerge) |
918 | DEFINE_CLASS_QUERY(Mem) |
919 | DEFINE_CLASS_QUERY(MemBar) |
920 | DEFINE_CLASS_QUERY(MemBarStoreStore) |
921 | DEFINE_CLASS_QUERY(MergeMem) |
922 | DEFINE_CLASS_QUERY(Move) |
923 | DEFINE_CLASS_QUERY(Mul) |
924 | DEFINE_CLASS_QUERY(Multi) |
925 | DEFINE_CLASS_QUERY(MultiBranch) |
926 | DEFINE_CLASS_QUERY(Opaque1) |
927 | DEFINE_CLASS_QUERY(OuterStripMinedLoop) |
928 | DEFINE_CLASS_QUERY(OuterStripMinedLoopEnd) |
929 | DEFINE_CLASS_QUERY(Parm) |
930 | DEFINE_CLASS_QUERY(PCTable) |
931 | DEFINE_CLASS_QUERY(Phi) |
932 | DEFINE_CLASS_QUERY(Proj) |
933 | DEFINE_CLASS_QUERY(Region) |
934 | DEFINE_CLASS_QUERY(Root) |
935 | DEFINE_CLASS_QUERY(SafePoint) |
936 | DEFINE_CLASS_QUERY(SafePointScalarObject) |
937 | DEFINE_CLASS_QUERY(Start) |
938 | DEFINE_CLASS_QUERY(Store) |
939 | DEFINE_CLASS_QUERY(Sub) |
940 | DEFINE_CLASS_QUERY(SubTypeCheck) |
941 | DEFINE_CLASS_QUERY(Type) |
942 | DEFINE_CLASS_QUERY(Vector) |
943 | DEFINE_CLASS_QUERY(VectorMaskCmp) |
944 | DEFINE_CLASS_QUERY(VectorUnbox) |
945 | DEFINE_CLASS_QUERY(VectorReinterpret); |
946 | DEFINE_CLASS_QUERY(LoadVector) |
947 | DEFINE_CLASS_QUERY(LoadVectorGather) |
948 | DEFINE_CLASS_QUERY(StoreVector) |
949 | DEFINE_CLASS_QUERY(StoreVectorScatter) |
950 | DEFINE_CLASS_QUERY(ShiftV) |
951 | DEFINE_CLASS_QUERY(Unlock) |
952 | |
953 | #undef DEFINE_CLASS_QUERY |
954 | |
955 | // duplicate of is_MachSpillCopy() |
956 | bool is_SpillCopy () const { |
957 | return ((_class_id & ClassMask_MachSpillCopy) == Class_MachSpillCopy); |
958 | } |
959 | |
960 | bool is_Con () const { return (_flags & Flag_is_Con) != 0; } |
961 | // The data node which is safe to leave in dead loop during IGVN optimization. |
962 | bool is_dead_loop_safe() const; |
963 | |
964 | // is_Copy() returns copied edge index (0 or 1) |
965 | uint is_Copy() const { return (_flags & Flag_is_Copy); } |
966 | |
967 | virtual bool is_CFG() const { return false; } |
968 | |
969 | // If this node is control-dependent on a test, can it be |
970 | // rerouted to a dominating equivalent test? This is usually |
971 | // true of non-CFG nodes, but can be false for operations which |
972 | // depend for their correct sequencing on more than one test. |
973 | // (In that case, hoisting to a dominating test may silently |
974 | // skip some other important test.) |
975 | virtual bool depends_only_on_test() const { assert(!is_CFG(), "")do { if (!(!is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 975, "assert(" "!is_CFG()" ") failed", ""); ::breakpoint(); } } while (0); return true; }; |
976 | |
977 | // When building basic blocks, I need to have a notion of block beginning |
978 | // Nodes, next block selector Nodes (block enders), and next block |
979 | // projections. These calls need to work on their machine equivalents. The |
980 | // Ideal beginning Nodes are RootNode, RegionNode and StartNode. |
981 | bool is_block_start() const { |
982 | if ( is_Region() ) |
983 | return this == (const Node*)in(0); |
984 | else |
985 | return is_Start(); |
986 | } |
987 | |
988 | // The Ideal control projection Nodes are IfTrue/IfFalse, JumpProjNode, Root, |
989 | // Goto and Return. This call also returns the block ending Node. |
990 | virtual const Node *is_block_proj() const; |
991 | |
992 | // The node is a "macro" node which needs to be expanded before matching |
993 | bool is_macro() const { return (_flags & Flag_is_macro) != 0; } |
994 | // The node is expensive: the best control is set during loop opts |
995 | bool is_expensive() const { return (_flags & Flag_is_expensive) != 0 && in(0) != NULL__null; } |
996 | |
997 | // An arithmetic node which accumulates a data in a loop. |
998 | // It must have the loop's phi as input and provide a def to the phi. |
999 | bool is_reduction() const { return (_flags & Flag_is_reduction) != 0; } |
1000 | |
1001 | bool is_predicated_vector() const { return (_flags & Flag_is_predicated_vector) != 0; } |
1002 | |
1003 | // The node is a CountedLoopEnd with a mask annotation so as to emit a restore context |
1004 | bool has_vector_mask_set() const { return (_flags & Flag_has_vector_mask_set) != 0; } |
1005 | |
1006 | // Used in lcm to mark nodes that have scheduled |
1007 | bool is_scheduled() const { return (_flags & Flag_is_scheduled) != 0; } |
1008 | |
1009 | bool for_post_loop_opts_igvn() const { return (_flags & Flag_for_post_loop_opts_igvn) != 0; } |
1010 | |
1011 | //----------------- Optimization |
1012 | |
1013 | // Get the worst-case Type output for this Node. |
1014 | virtual const class Type *bottom_type() const; |
1015 | |
1016 | // If we find a better type for a node, try to record it permanently. |
1017 | // Return true if this node actually changed. |
1018 | // Be sure to do the hash_delete game in the "rehash" variant. |
1019 | void raise_bottom_type(const Type* new_type); |
1020 | |
1021 | // Get the address type with which this node uses and/or defs memory, |
1022 | // or NULL if none. The address type is conservatively wide. |
1023 | // Returns non-null for calls, membars, loads, stores, etc. |
1024 | // Returns TypePtr::BOTTOM if the node touches memory "broadly". |
1025 | virtual const class TypePtr *adr_type() const { return NULL__null; } |
1026 | |
1027 | // Return an existing node which computes the same function as this node. |
1028 | // The optimistic combined algorithm requires this to return a Node which |
1029 | // is a small number of steps away (e.g., one of my inputs). |
1030 | virtual Node* Identity(PhaseGVN* phase); |
1031 | |
1032 | // Return the set of values this Node can take on at runtime. |
1033 | virtual const Type* Value(PhaseGVN* phase) const; |
1034 | |
1035 | // Return a node which is more "ideal" than the current node. |
1036 | // The invariants on this call are subtle. If in doubt, read the |
1037 | // treatise in node.cpp above the default implemention AND TEST WITH |
1038 | // +VerifyIterativeGVN! |
1039 | virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); |
1040 | |
1041 | // Some nodes have specific Ideal subgraph transformations only if they are |
1042 | // unique users of specific nodes. Such nodes should be put on IGVN worklist |
1043 | // for the transformations to happen. |
1044 | bool has_special_unique_user() const; |
1045 | |
1046 | // Skip Proj and CatchProj nodes chains. Check for Null and Top. |
1047 | Node* find_exact_control(Node* ctrl); |
1048 | |
1049 | // Check if 'this' node dominates or equal to 'sub'. |
1050 | bool dominates(Node* sub, Node_List &nlist); |
1051 | |
1052 | protected: |
1053 | bool remove_dead_region(PhaseGVN *phase, bool can_reshape); |
1054 | public: |
1055 | |
1056 | // See if there is valid pipeline info |
1057 | static const Pipeline *pipeline_class(); |
1058 | virtual const Pipeline *pipeline() const; |
1059 | |
1060 | // Compute the latency from the def to this instruction of the ith input node |
1061 | uint latency(uint i); |
1062 | |
1063 | // Hash & compare functions, for pessimistic value numbering |
1064 | |
1065 | // If the hash function returns the special sentinel value NO_HASH, |
1066 | // the node is guaranteed never to compare equal to any other node. |
1067 | // If we accidentally generate a hash with value NO_HASH the node |
1068 | // won't go into the table and we'll lose a little optimization. |
1069 | static const uint NO_HASH = 0; |
1070 | virtual uint hash() const; |
1071 | virtual bool cmp( const Node &n ) const; |
1072 | |
1073 | // Operation appears to be iteratively computed (such as an induction variable) |
1074 | // It is possible for this operation to return false for a loop-varying |
1075 | // value, if it appears (by local graph inspection) to be computed by a simple conditional. |
1076 | bool is_iteratively_computed(); |
1077 | |
1078 | // Determine if a node is a counted loop induction variable. |
1079 | // NOTE: The method is defined in "loopnode.cpp". |
1080 | bool is_cloop_ind_var() const; |
1081 | |
1082 | // Return a node with opcode "opc" and same inputs as "this" if one can |
1083 | // be found; Otherwise return NULL; |
1084 | Node* find_similar(int opc); |
1085 | |
1086 | // Return the unique control out if only one. Null if none or more than one. |
1087 | Node* unique_ctrl_out() const; |
1088 | |
1089 | // Set control or add control as precedence edge |
1090 | void ensure_control_or_add_prec(Node* c); |
1091 | |
1092 | //----------------- Code Generation |
1093 | |
1094 | // Ideal register class for Matching. Zero means unmatched instruction |
1095 | // (these are cloned instead of converted to machine nodes). |
1096 | virtual uint ideal_reg() const; |
1097 | |
1098 | static const uint NotAMachineReg; // must be > max. machine register |
1099 | |
1100 | // Do we Match on this edge index or not? Generally false for Control |
1101 | // and true for everything else. Weird for calls & returns. |
1102 | virtual uint match_edge(uint idx) const; |
1103 | |
1104 | // Register class output is returned in |
1105 | virtual const RegMask &out_RegMask() const; |
1106 | // Register class input is expected in |
1107 | virtual const RegMask &in_RegMask(uint) const; |
1108 | // Should we clone rather than spill this instruction? |
1109 | bool rematerialize() const; |
1110 | |
1111 | // Return JVM State Object if this Node carries debug info, or NULL otherwise |
1112 | virtual JVMState* jvms() const; |
1113 | |
1114 | // Print as assembly |
1115 | virtual void format( PhaseRegAlloc *, outputStream* st = tty ) const; |
1116 | // Emit bytes starting at parameter 'ptr' |
1117 | // Bump 'ptr' by the number of output bytes |
1118 | virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; |
1119 | // Size of instruction in bytes |
1120 | virtual uint size(PhaseRegAlloc *ra_) const; |
1121 | |
1122 | // Convenience function to extract an integer constant from a node. |
1123 | // If it is not an integer constant (either Con, CastII, or Mach), |
1124 | // return value_if_unknown. |
1125 | jint find_int_con(jint value_if_unknown) const { |
1126 | const TypeInt* t = find_int_type(); |
1127 | return (t != NULL__null && t->is_con()) ? t->get_con() : value_if_unknown; |
1128 | } |
1129 | // Return the constant, knowing it is an integer constant already |
1130 | jint get_int() const { |
1131 | const TypeInt* t = find_int_type(); |
1132 | guarantee(t != NULL, "must be con")do { if (!(t != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1132, "guarantee(" "t != NULL" ") failed", "must be con"); :: breakpoint(); } } while (0); |
1133 | return t->get_con(); |
1134 | } |
1135 | // Here's where the work is done. Can produce non-constant int types too. |
1136 | const TypeInt* find_int_type() const; |
1137 | const TypeInteger* find_integer_type(BasicType bt) const; |
1138 | |
1139 | // Same thing for long (and intptr_t, via type.hpp): |
1140 | jlong get_long() const { |
1141 | const TypeLong* t = find_long_type(); |
1142 | guarantee(t != NULL, "must be con")do { if (!(t != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1142, "guarantee(" "t != NULL" ") failed", "must be con"); :: breakpoint(); } } while (0); |
1143 | return t->get_con(); |
1144 | } |
1145 | jlong find_long_con(jint value_if_unknown) const { |
1146 | const TypeLong* t = find_long_type(); |
1147 | return (t != NULL__null && t->is_con()) ? t->get_con() : value_if_unknown; |
1148 | } |
1149 | const TypeLong* find_long_type() const; |
1150 | |
1151 | jlong get_integer_as_long(BasicType bt) const { |
1152 | const TypeInteger* t = find_integer_type(bt); |
1153 | guarantee(t != NULL, "must be con")do { if (!(t != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1153, "guarantee(" "t != NULL" ") failed", "must be con"); :: breakpoint(); } } while (0); |
1154 | return t->get_con_as_long(bt); |
1155 | } |
1156 | const TypePtr* get_ptr_type() const; |
1157 | |
1158 | // These guys are called by code generated by ADLC: |
1159 | intptr_t get_ptr() const; |
1160 | intptr_t get_narrowcon() const; |
1161 | jdouble getd() const; |
1162 | jfloat getf() const; |
1163 | |
1164 | // Nodes which are pinned into basic blocks |
1165 | virtual bool pinned() const { return false; } |
1166 | |
1167 | // Nodes which use memory without consuming it, hence need antidependences |
1168 | // More specifically, needs_anti_dependence_check returns true iff the node |
1169 | // (a) does a load, and (b) does not perform a store (except perhaps to a |
1170 | // stack slot or some other unaliased location). |
1171 | bool needs_anti_dependence_check() const; |
1172 | |
1173 | // Return which operand this instruction may cisc-spill. In other words, |
1174 | // return operand position that can convert from reg to memory access |
1175 | virtual int cisc_operand() const { return AdlcVMDeps::Not_cisc_spillable; } |
1176 | bool is_cisc_alternate() const { return (_flags & Flag_is_cisc_alternate) != 0; } |
1177 | |
1178 | // Whether this is a memory-writing machine node. |
1179 | bool is_memory_writer() const { return is_Mach() && bottom_type()->has_memory(); } |
1180 | |
1181 | //----------------- Printing, etc |
1182 | #ifndef PRODUCT |
1183 | private: |
1184 | int _indent; |
1185 | |
1186 | public: |
1187 | void set_indent(int indent) { _indent = indent; } |
1188 | |
1189 | private: |
1190 | static bool add_to_worklist(Node* n, Node_List* worklist, Arena* old_arena, VectorSet* old_space, VectorSet* new_space); |
1191 | public: |
1192 | Node* find(int idx, bool only_ctrl = false); // Search the graph for the given idx. |
1193 | Node* find_ctrl(int idx); // Search control ancestors for the given idx. |
1194 | void dump() const { dump("\n"); } // Print this node. |
1195 | void dump(const char* suffix, bool mark = false, outputStream *st = tty) const; // Print this node. |
1196 | void dump(int depth) const; // Print this node, recursively to depth d |
1197 | void dump_ctrl(int depth) const; // Print control nodes, to depth d |
1198 | void dump_comp() const; // Print this node in compact representation. |
1199 | // Print this node in compact representation. |
1200 | void dump_comp(const char* suffix, outputStream *st = tty) const; |
1201 | virtual void dump_req(outputStream *st = tty) const; // Print required-edge info |
1202 | virtual void dump_prec(outputStream *st = tty) const; // Print precedence-edge info |
1203 | virtual void dump_out(outputStream *st = tty) const; // Print the output edge info |
1204 | virtual void dump_spec(outputStream *st) const {}; // Print per-node info |
1205 | // Print compact per-node info |
1206 | virtual void dump_compact_spec(outputStream *st) const { dump_spec(st); } |
1207 | void dump_related() const; // Print related nodes (depends on node at hand). |
1208 | // Print related nodes up to given depths for input and output nodes. |
1209 | void dump_related(uint d_in, uint d_out) const; |
1210 | void dump_related_compact() const; // Print related nodes in compact representation. |
1211 | // Collect related nodes. |
1212 | virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const; |
1213 | // Collect nodes starting from this node, explicitly including/excluding control and data links. |
1214 | void collect_nodes(GrowableArray<Node*> *ns, int d, bool ctrl, bool data) const; |
1215 | |
1216 | // Node collectors, to be used in implementations of Node::rel(). |
1217 | // Collect the entire data input graph. Include control inputs if requested. |
1218 | void collect_nodes_in_all_data(GrowableArray<Node*> *ns, bool ctrl) const; |
1219 | // Collect the entire control input graph. Include data inputs if requested. |
1220 | void collect_nodes_in_all_ctrl(GrowableArray<Node*> *ns, bool data) const; |
1221 | // Collect the entire output graph until hitting and including control nodes. |
1222 | void collect_nodes_out_all_ctrl_boundary(GrowableArray<Node*> *ns) const; |
1223 | |
1224 | void verify_edges(Unique_Node_List &visited); // Verify bi-directional edges |
1225 | static void verify(int verify_depth, VectorSet& visited, Node_List& worklist); |
1226 | |
1227 | // This call defines a class-unique string used to identify class instances |
1228 | virtual const char *Name() const; |
1229 | |
1230 | void dump_format(PhaseRegAlloc *ra) const; // debug access to MachNode::format(...) |
1231 | // RegMask Print Functions |
1232 | void dump_in_regmask(int idx) { in_RegMask(idx).dump(); } |
1233 | void dump_out_regmask() { out_RegMask().dump(); } |
1234 | static bool in_dump() { return Compile::current()->_in_dump_cnt > 0; } |
1235 | void fast_dump() const { |
1236 | tty->print("%4d: %-17s", _idx, Name()); |
1237 | for (uint i = 0; i < len(); i++) |
1238 | if (in(i)) |
1239 | tty->print(" %4d", in(i)->_idx); |
1240 | else |
1241 | tty->print(" NULL"); |
1242 | tty->print("\n"); |
1243 | } |
1244 | #endif |
1245 | #ifdef ASSERT1 |
1246 | void verify_construction(); |
1247 | bool verify_jvms(const JVMState* jvms) const; |
1248 | int _debug_idx; // Unique value assigned to every node. |
1249 | int debug_idx() const { return _debug_idx; } |
1250 | void set_debug_idx( int debug_idx ) { _debug_idx = debug_idx; } |
1251 | |
1252 | Node* _debug_orig; // Original version of this, if any. |
1253 | Node* debug_orig() const { return _debug_orig; } |
1254 | void set_debug_orig(Node* orig); // _debug_orig = orig |
1255 | void dump_orig(outputStream *st, bool print_key = true) const; |
1256 | |
1257 | int _hash_lock; // Barrier to modifications of nodes in the hash table |
1258 | void enter_hash_lock() { ++_hash_lock; assert(_hash_lock < 99, "in too many hash tables?")do { if (!(_hash_lock < 99)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1258, "assert(" "_hash_lock < 99" ") failed", "in too many hash tables?" ); ::breakpoint(); } } while (0); } |
1259 | void exit_hash_lock() { --_hash_lock; assert(_hash_lock >= 0, "mispaired hash locks")do { if (!(_hash_lock >= 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1259, "assert(" "_hash_lock >= 0" ") failed", "mispaired hash locks" ); ::breakpoint(); } } while (0); } |
1260 | |
1261 | static void init_NodeProperty(); |
1262 | |
1263 | #if OPTO_DU_ITERATOR_ASSERT1 |
1264 | const Node* _last_del; // The last deleted node. |
1265 | uint _del_tick; // Bumped when a deletion happens.. |
1266 | #endif |
1267 | #endif |
1268 | }; |
1269 | |
1270 | inline bool not_a_node(const Node* n) { |
1271 | if (n == NULL__null) return true; |
1272 | if (((intptr_t)n & 1) != 0) return true; // uninitialized, etc. |
1273 | if (*(address*)n == badAddress((address)::badAddressVal)) return true; // kill by Node::destruct |
1274 | return false; |
1275 | } |
1276 | |
1277 | //----------------------------------------------------------------------------- |
1278 | // Iterators over DU info, and associated Node functions. |
1279 | |
1280 | #if OPTO_DU_ITERATOR_ASSERT1 |
1281 | |
1282 | // Common code for assertion checking on DU iterators. |
1283 | class DUIterator_Common { |
1284 | #ifdef ASSERT1 |
1285 | protected: |
1286 | bool _vdui; // cached value of VerifyDUIterators |
1287 | const Node* _node; // the node containing the _out array |
1288 | uint _outcnt; // cached node->_outcnt |
1289 | uint _del_tick; // cached node->_del_tick |
1290 | Node* _last; // last value produced by the iterator |
1291 | |
1292 | void sample(const Node* node); // used by c'tor to set up for verifies |
1293 | void verify(const Node* node, bool at_end_ok = false); |
1294 | void verify_resync(); |
1295 | void reset(const DUIterator_Common& that); |
1296 | |
1297 | // The VDUI_ONLY macro protects code conditionalized on VerifyDUIterators |
1298 | #define I_VDUI_ONLY(i,x) { if ((i)._vdui) { x; } } |
1299 | #else |
1300 | #define I_VDUI_ONLY(i,x) { } |
1301 | #endif //ASSERT |
1302 | }; |
1303 | |
1304 | #define VDUI_ONLY(x) I_VDUI_ONLY(*this, x) |
1305 | |
1306 | // Default DU iterator. Allows appends onto the out array. |
1307 | // Allows deletion from the out array only at the current point. |
1308 | // Usage: |
1309 | // for (DUIterator i = x->outs(); x->has_out(i); i++) { |
1310 | // Node* y = x->out(i); |
1311 | // ... |
1312 | // } |
1313 | // Compiles in product mode to a unsigned integer index, which indexes |
1314 | // onto a repeatedly reloaded base pointer of x->_out. The loop predicate |
1315 | // also reloads x->_outcnt. If you delete, you must perform "--i" just |
1316 | // before continuing the loop. You must delete only the last-produced |
1317 | // edge. You must delete only a single copy of the last-produced edge, |
1318 | // or else you must delete all copies at once (the first time the edge |
1319 | // is produced by the iterator). |
1320 | class DUIterator : public DUIterator_Common { |
1321 | friend class Node; |
1322 | |
1323 | // This is the index which provides the product-mode behavior. |
1324 | // Whatever the product-mode version of the system does to the |
1325 | // DUI index is done to this index. All other fields in |
1326 | // this class are used only for assertion checking. |
1327 | uint _idx; |
1328 | |
1329 | #ifdef ASSERT1 |
1330 | uint _refresh_tick; // Records the refresh activity. |
1331 | |
1332 | void sample(const Node* node); // Initialize _refresh_tick etc. |
1333 | void verify(const Node* node, bool at_end_ok = false); |
1334 | void verify_increment(); // Verify an increment operation. |
1335 | void verify_resync(); // Verify that we can back up over a deletion. |
1336 | void verify_finish(); // Verify that the loop terminated properly. |
1337 | void refresh(); // Resample verification info. |
1338 | void reset(const DUIterator& that); // Resample after assignment. |
1339 | #endif |
1340 | |
1341 | DUIterator(const Node* node, int dummy_to_avoid_conversion) |
1342 | { _idx = 0; debug_only(sample(node))sample(node); } |
1343 | |
1344 | public: |
1345 | // initialize to garbage; clear _vdui to disable asserts |
1346 | DUIterator() |
1347 | { /*initialize to garbage*/ debug_only(_vdui = false)_vdui = false; } |
1348 | |
1349 | DUIterator(const DUIterator& that) |
1350 | { _idx = that._idx; debug_only(_vdui = false; reset(that))_vdui = false; reset(that); } |
1351 | |
1352 | void operator++(int dummy_to_specify_postfix_op) |
1353 | { _idx++; VDUI_ONLY(verify_increment()); } |
1354 | |
1355 | void operator--() |
1356 | { VDUI_ONLY(verify_resync()); --_idx; } |
1357 | |
1358 | ~DUIterator() |
1359 | { VDUI_ONLY(verify_finish()); } |
1360 | |
1361 | void operator=(const DUIterator& that) |
1362 | { _idx = that._idx; debug_only(reset(that))reset(that); } |
1363 | }; |
1364 | |
1365 | DUIterator Node::outs() const |
1366 | { return DUIterator(this, 0); } |
1367 | DUIterator& Node::refresh_out_pos(DUIterator& i) const |
1368 | { I_VDUI_ONLY(i, i.refresh()); return i; } |
1369 | bool Node::has_out(DUIterator& i) const |
1370 | { I_VDUI_ONLY(i, i.verify(this,true));return i._idx < _outcnt; } |
1371 | Node* Node::out(DUIterator& i) const |
1372 | { I_VDUI_ONLY(i, i.verify(this)); return debug_only(i._last=)i._last= _out[i._idx]; } |
1373 | |
1374 | |
1375 | // Faster DU iterator. Disallows insertions into the out array. |
1376 | // Allows deletion from the out array only at the current point. |
1377 | // Usage: |
1378 | // for (DUIterator_Fast imax, i = x->fast_outs(imax); i < imax; i++) { |
1379 | // Node* y = x->fast_out(i); |
1380 | // ... |
1381 | // } |
1382 | // Compiles in product mode to raw Node** pointer arithmetic, with |
1383 | // no reloading of pointers from the original node x. If you delete, |
1384 | // you must perform "--i; --imax" just before continuing the loop. |
1385 | // If you delete multiple copies of the same edge, you must decrement |
1386 | // imax, but not i, multiple times: "--i, imax -= num_edges". |
1387 | class DUIterator_Fast : public DUIterator_Common { |
1388 | friend class Node; |
1389 | friend class DUIterator_Last; |
1390 | |
1391 | // This is the pointer which provides the product-mode behavior. |
1392 | // Whatever the product-mode version of the system does to the |
1393 | // DUI pointer is done to this pointer. All other fields in |
1394 | // this class are used only for assertion checking. |
1395 | Node** _outp; |
1396 | |
1397 | #ifdef ASSERT1 |
1398 | void verify(const Node* node, bool at_end_ok = false); |
1399 | void verify_limit(); |
1400 | void verify_resync(); |
1401 | void verify_relimit(uint n); |
1402 | void reset(const DUIterator_Fast& that); |
1403 | #endif |
1404 | |
1405 | // Note: offset must be signed, since -1 is sometimes passed |
1406 | DUIterator_Fast(const Node* node, ptrdiff_t offset) |
1407 | { _outp = node->_out + offset; debug_only(sample(node))sample(node); } |
1408 | |
1409 | public: |
1410 | // initialize to garbage; clear _vdui to disable asserts |
1411 | DUIterator_Fast() |
1412 | { /*initialize to garbage*/ debug_only(_vdui = false)_vdui = false; } |
1413 | |
1414 | DUIterator_Fast(const DUIterator_Fast& that) |
1415 | { _outp = that._outp; debug_only(_vdui = false; reset(that))_vdui = false; reset(that); } |
1416 | |
1417 | void operator++(int dummy_to_specify_postfix_op) |
1418 | { _outp++; VDUI_ONLY(verify(_node, true)); } |
1419 | |
1420 | void operator--() |
1421 | { VDUI_ONLY(verify_resync()); --_outp; } |
1422 | |
1423 | void operator-=(uint n) // applied to the limit only |
1424 | { _outp -= n; VDUI_ONLY(verify_relimit(n)); } |
1425 | |
1426 | bool operator<(DUIterator_Fast& limit) { |
1427 | I_VDUI_ONLY(*this, this->verify(_node, true)); |
1428 | I_VDUI_ONLY(limit, limit.verify_limit()); |
1429 | return _outp < limit._outp; |
1430 | } |
1431 | |
1432 | void operator=(const DUIterator_Fast& that) |
1433 | { _outp = that._outp; debug_only(reset(that))reset(that); } |
1434 | }; |
1435 | |
1436 | DUIterator_Fast Node::fast_outs(DUIterator_Fast& imax) const { |
1437 | // Assign a limit pointer to the reference argument: |
1438 | imax = DUIterator_Fast(this, (ptrdiff_t)_outcnt); |
1439 | // Return the base pointer: |
1440 | return DUIterator_Fast(this, 0); |
1441 | } |
1442 | Node* Node::fast_out(DUIterator_Fast& i) const { |
1443 | I_VDUI_ONLY(i, i.verify(this)); |
1444 | return debug_only(i._last=)i._last= *i._outp; |
1445 | } |
1446 | |
1447 | |
1448 | // Faster DU iterator. Requires each successive edge to be removed. |
1449 | // Does not allow insertion of any edges. |
1450 | // Usage: |
1451 | // for (DUIterator_Last imin, i = x->last_outs(imin); i >= imin; i -= num_edges) { |
1452 | // Node* y = x->last_out(i); |
1453 | // ... |
1454 | // } |
1455 | // Compiles in product mode to raw Node** pointer arithmetic, with |
1456 | // no reloading of pointers from the original node x. |
1457 | class DUIterator_Last : private DUIterator_Fast { |
1458 | friend class Node; |
1459 | |
1460 | #ifdef ASSERT1 |
1461 | void verify(const Node* node, bool at_end_ok = false); |
1462 | void verify_limit(); |
1463 | void verify_step(uint num_edges); |
1464 | #endif |
1465 | |
1466 | // Note: offset must be signed, since -1 is sometimes passed |
1467 | DUIterator_Last(const Node* node, ptrdiff_t offset) |
1468 | : DUIterator_Fast(node, offset) { } |
1469 | |
1470 | void operator++(int dummy_to_specify_postfix_op) {} // do not use |
1471 | void operator<(int) {} // do not use |
1472 | |
1473 | public: |
1474 | DUIterator_Last() { } |
1475 | // initialize to garbage |
1476 | |
1477 | DUIterator_Last(const DUIterator_Last& that) = default; |
1478 | |
1479 | void operator--() |
1480 | { _outp--; VDUI_ONLY(verify_step(1)); } |
1481 | |
1482 | void operator-=(uint n) |
1483 | { _outp -= n; VDUI_ONLY(verify_step(n)); } |
1484 | |
1485 | bool operator>=(DUIterator_Last& limit) { |
1486 | I_VDUI_ONLY(*this, this->verify(_node, true)); |
1487 | I_VDUI_ONLY(limit, limit.verify_limit()); |
1488 | return _outp >= limit._outp; |
1489 | } |
1490 | |
1491 | DUIterator_Last& operator=(const DUIterator_Last& that) = default; |
1492 | }; |
1493 | |
1494 | DUIterator_Last Node::last_outs(DUIterator_Last& imin) const { |
1495 | // Assign a limit pointer to the reference argument: |
1496 | imin = DUIterator_Last(this, 0); |
1497 | // Return the initial pointer: |
1498 | return DUIterator_Last(this, (ptrdiff_t)_outcnt - 1); |
1499 | } |
1500 | Node* Node::last_out(DUIterator_Last& i) const { |
1501 | I_VDUI_ONLY(i, i.verify(this)); |
1502 | return debug_only(i._last=)i._last= *i._outp; |
1503 | } |
1504 | |
1505 | #endif //OPTO_DU_ITERATOR_ASSERT |
1506 | |
1507 | #undef I_VDUI_ONLY |
1508 | #undef VDUI_ONLY |
1509 | |
1510 | // An Iterator that truly follows the iterator pattern. Doesn't |
1511 | // support deletion but could be made to. |
1512 | // |
1513 | // for (SimpleDUIterator i(n); i.has_next(); i.next()) { |
1514 | // Node* m = i.get(); |
1515 | // |
1516 | class SimpleDUIterator : public StackObj { |
1517 | private: |
1518 | Node* node; |
1519 | DUIterator_Fast i; |
1520 | DUIterator_Fast imax; |
1521 | public: |
1522 | SimpleDUIterator(Node* n): node(n), i(n->fast_outs(imax)) {} |
1523 | bool has_next() { return i < imax; } |
1524 | void next() { i++; } |
1525 | Node* get() { return node->fast_out(i); } |
1526 | }; |
1527 | |
1528 | |
1529 | //----------------------------------------------------------------------------- |
1530 | // Map dense integer indices to Nodes. Uses classic doubling-array trick. |
1531 | // Abstractly provides an infinite array of Node*'s, initialized to NULL. |
1532 | // Note that the constructor just zeros things, and since I use Arena |
1533 | // allocation I do not need a destructor to reclaim storage. |
1534 | class Node_Array : public ResourceObj { |
1535 | friend class VMStructs; |
1536 | protected: |
1537 | Arena* _a; // Arena to allocate in |
1538 | uint _max; |
1539 | Node** _nodes; |
1540 | void grow( uint i ); // Grow array node to fit |
1541 | public: |
1542 | Node_Array(Arena* a, uint max = OptoNodeListSize) : _a(a), _max(max) { |
1543 | _nodes = NEW_ARENA_ARRAY(a, Node*, max)(Node**) (a)->Amalloc((max) * sizeof(Node*)); |
1544 | clear(); |
1545 | } |
1546 | |
1547 | Node_Array(Node_Array* na) : _a(na->_a), _max(na->_max), _nodes(na->_nodes) {} |
1548 | Node *operator[] ( uint i ) const // Lookup, or NULL for not mapped |
1549 | { return (i<_max) ? _nodes[i] : (Node*)NULL__null; } |
1550 | Node* at(uint i) const { assert(i<_max,"oob")do { if (!(i<_max)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1550, "assert(" "i<_max" ") failed", "oob"); ::breakpoint (); } } while (0); return _nodes[i]; } |
1551 | Node** adr() { return _nodes; } |
1552 | // Extend the mapping: index i maps to Node *n. |
1553 | void map( uint i, Node *n ) { if( i>=_max ) grow(i); _nodes[i] = n; } |
1554 | void insert( uint i, Node *n ); |
1555 | void remove( uint i ); // Remove, preserving order |
1556 | // Clear all entries in _nodes to NULL but keep storage |
1557 | void clear() { |
1558 | Copy::zero_to_bytes(_nodes, _max * sizeof(Node*)); |
1559 | } |
1560 | |
1561 | uint Size() const { return _max; } |
1562 | void dump() const; |
1563 | }; |
1564 | |
1565 | class Node_List : public Node_Array { |
1566 | friend class VMStructs; |
1567 | uint _cnt; |
1568 | public: |
1569 | Node_List(uint max = OptoNodeListSize) : Node_Array(Thread::current()->resource_area(), max), _cnt(0) {} |
1570 | Node_List(Arena *a, uint max = OptoNodeListSize) : Node_Array(a, max), _cnt(0) {} |
1571 | bool contains(const Node* n) const { |
1572 | for (uint e = 0; e < size(); e++) { |
1573 | if (at(e) == n) return true; |
1574 | } |
1575 | return false; |
1576 | } |
1577 | void insert( uint i, Node *n ) { Node_Array::insert(i,n); _cnt++; } |
1578 | void remove( uint i ) { Node_Array::remove(i); _cnt--; } |
1579 | void push( Node *b ) { map(_cnt++,b); } |
1580 | void yank( Node *n ); // Find and remove |
1581 | Node *pop() { return _nodes[--_cnt]; } |
1582 | void clear() { _cnt = 0; Node_Array::clear(); } // retain storage |
1583 | void copy(const Node_List& from) { |
1584 | if (from._max > _max) { |
1585 | grow(from._max); |
1586 | } |
1587 | _cnt = from._cnt; |
1588 | Copy::conjoint_words_to_higher((HeapWord*)&from._nodes[0], (HeapWord*)&_nodes[0], from._max * sizeof(Node*)); |
1589 | } |
1590 | |
1591 | uint size() const { return _cnt; } |
1592 | void dump() const; |
1593 | void dump_simple() const; |
1594 | }; |
1595 | |
1596 | //------------------------------Unique_Node_List------------------------------- |
1597 | class Unique_Node_List : public Node_List { |
1598 | friend class VMStructs; |
1599 | VectorSet _in_worklist; |
1600 | uint _clock_index; // Index in list where to pop from next |
1601 | public: |
1602 | Unique_Node_List() : Node_List(), _clock_index(0) {} |
1603 | Unique_Node_List(Arena *a) : Node_List(a), _in_worklist(a), _clock_index(0) {} |
1604 | |
1605 | void remove( Node *n ); |
1606 | bool member( Node *n ) { return _in_worklist.test(n->_idx) != 0; } |
1607 | VectorSet& member_set(){ return _in_worklist; } |
1608 | |
1609 | void push(Node* b) { |
1610 | if( !_in_worklist.test_set(b->_idx) ) |
1611 | Node_List::push(b); |
1612 | } |
1613 | Node *pop() { |
1614 | if( _clock_index >= size() ) _clock_index = 0; |
1615 | Node *b = at(_clock_index); |
1616 | map( _clock_index, Node_List::pop()); |
1617 | if (size() != 0) _clock_index++; // Always start from 0 |
1618 | _in_worklist.remove(b->_idx); |
1619 | return b; |
1620 | } |
1621 | Node *remove(uint i) { |
1622 | Node *b = Node_List::at(i); |
1623 | _in_worklist.remove(b->_idx); |
1624 | map(i,Node_List::pop()); |
1625 | return b; |
1626 | } |
1627 | void yank(Node *n) { |
1628 | _in_worklist.remove(n->_idx); |
1629 | Node_List::yank(n); |
1630 | } |
1631 | void clear() { |
1632 | _in_worklist.clear(); // Discards storage but grows automatically |
1633 | Node_List::clear(); |
1634 | _clock_index = 0; |
1635 | } |
1636 | |
1637 | // Used after parsing to remove useless nodes before Iterative GVN |
1638 | void remove_useless_nodes(VectorSet& useful); |
1639 | |
1640 | bool contains(const Node* n) const { |
1641 | fatal("use faster member() instead")do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1641, "use faster member() instead"); ::breakpoint(); } while (0); |
1642 | return false; |
1643 | } |
1644 | |
1645 | #ifndef PRODUCT |
1646 | void print_set() const { _in_worklist.print(); } |
1647 | #endif |
1648 | }; |
1649 | |
1650 | // Inline definition of Compile::record_for_igvn must be deferred to this point. |
1651 | inline void Compile::record_for_igvn(Node* n) { |
1652 | _for_igvn->push(n); |
1653 | } |
1654 | |
1655 | //------------------------------Node_Stack------------------------------------- |
1656 | class Node_Stack { |
1657 | friend class VMStructs; |
1658 | protected: |
1659 | struct INode { |
1660 | Node *node; // Processed node |
1661 | uint indx; // Index of next node's child |
1662 | }; |
1663 | INode *_inode_top; // tos, stack grows up |
1664 | INode *_inode_max; // End of _inodes == _inodes + _max |
1665 | INode *_inodes; // Array storage for the stack |
1666 | Arena *_a; // Arena to allocate in |
1667 | void grow(); |
1668 | public: |
1669 | Node_Stack(int size) { |
1670 | size_t max = (size > OptoNodeListSize) ? size : OptoNodeListSize; |
1671 | _a = Thread::current()->resource_area(); |
1672 | _inodes = NEW_ARENA_ARRAY( _a, INode, max )(INode*) (_a)->Amalloc((max) * sizeof(INode)); |
1673 | _inode_max = _inodes + max; |
1674 | _inode_top = _inodes - 1; // stack is empty |
1675 | } |
1676 | |
1677 | Node_Stack(Arena *a, int size) : _a(a) { |
1678 | size_t max = (size > OptoNodeListSize) ? size : OptoNodeListSize; |
1679 | _inodes = NEW_ARENA_ARRAY( _a, INode, max )(INode*) (_a)->Amalloc((max) * sizeof(INode)); |
1680 | _inode_max = _inodes + max; |
1681 | _inode_top = _inodes - 1; // stack is empty |
1682 | } |
1683 | |
1684 | void pop() { |
1685 | assert(_inode_top >= _inodes, "node stack underflow")do { if (!(_inode_top >= _inodes)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1685, "assert(" "_inode_top >= _inodes" ") failed", "node stack underflow" ); ::breakpoint(); } } while (0); |
1686 | --_inode_top; |
1687 | } |
1688 | void push(Node *n, uint i) { |
1689 | ++_inode_top; |
1690 | if (_inode_top >= _inode_max) grow(); |
1691 | INode *top = _inode_top; // optimization |
1692 | top->node = n; |
1693 | top->indx = i; |
1694 | } |
1695 | Node *node() const { |
1696 | return _inode_top->node; |
1697 | } |
1698 | Node* node_at(uint i) const { |
1699 | assert(_inodes + i <= _inode_top, "in range")do { if (!(_inodes + i <= _inode_top)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1699, "assert(" "_inodes + i <= _inode_top" ") failed", "in range" ); ::breakpoint(); } } while (0); |
1700 | return _inodes[i].node; |
1701 | } |
1702 | uint index() const { |
1703 | return _inode_top->indx; |
1704 | } |
1705 | uint index_at(uint i) const { |
1706 | assert(_inodes + i <= _inode_top, "in range")do { if (!(_inodes + i <= _inode_top)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1706, "assert(" "_inodes + i <= _inode_top" ") failed", "in range" ); ::breakpoint(); } } while (0); |
1707 | return _inodes[i].indx; |
1708 | } |
1709 | void set_node(Node *n) { |
1710 | _inode_top->node = n; |
1711 | } |
1712 | void set_index(uint i) { |
1713 | _inode_top->indx = i; |
1714 | } |
1715 | uint size_max() const { return (uint)pointer_delta(_inode_max, _inodes, sizeof(INode)); } // Max size |
1716 | uint size() const { return (uint)pointer_delta((_inode_top+1), _inodes, sizeof(INode)); } // Current size |
1717 | bool is_nonempty() const { return (_inode_top >= _inodes); } |
1718 | bool is_empty() const { return (_inode_top < _inodes); } |
1719 | void clear() { _inode_top = _inodes - 1; } // retain storage |
1720 | |
1721 | // Node_Stack is used to map nodes. |
1722 | Node* find(uint idx) const; |
1723 | }; |
1724 | |
1725 | |
1726 | //-----------------------------Node_Notes-------------------------------------- |
1727 | // Debugging or profiling annotations loosely and sparsely associated |
1728 | // with some nodes. See Compile::node_notes_at for the accessor. |
1729 | class Node_Notes { |
1730 | friend class VMStructs; |
1731 | JVMState* _jvms; |
1732 | |
1733 | public: |
1734 | Node_Notes(JVMState* jvms = NULL__null) { |
1735 | _jvms = jvms; |
1736 | } |
1737 | |
1738 | JVMState* jvms() { return _jvms; } |
1739 | void set_jvms(JVMState* x) { _jvms = x; } |
1740 | |
1741 | // True if there is nothing here. |
1742 | bool is_clear() { |
1743 | return (_jvms == NULL__null); |
1744 | } |
1745 | |
1746 | // Make there be nothing here. |
1747 | void clear() { |
1748 | _jvms = NULL__null; |
1749 | } |
1750 | |
1751 | // Make a new, clean node notes. |
1752 | static Node_Notes* make(Compile* C) { |
1753 | Node_Notes* nn = NEW_ARENA_ARRAY(C->comp_arena(), Node_Notes, 1)(Node_Notes*) (C->comp_arena())->Amalloc((1) * sizeof(Node_Notes )); |
1754 | nn->clear(); |
1755 | return nn; |
1756 | } |
1757 | |
1758 | Node_Notes* clone(Compile* C) { |
1759 | Node_Notes* nn = NEW_ARENA_ARRAY(C->comp_arena(), Node_Notes, 1)(Node_Notes*) (C->comp_arena())->Amalloc((1) * sizeof(Node_Notes )); |
1760 | (*nn) = (*this); |
1761 | return nn; |
1762 | } |
1763 | |
1764 | // Absorb any information from source. |
1765 | bool update_from(Node_Notes* source) { |
1766 | bool changed = false; |
1767 | if (source != NULL__null) { |
1768 | if (source->jvms() != NULL__null) { |
1769 | set_jvms(source->jvms()); |
1770 | changed = true; |
1771 | } |
1772 | } |
1773 | return changed; |
1774 | } |
1775 | }; |
1776 | |
1777 | // Inlined accessors for Compile::node_nodes that require the preceding class: |
1778 | inline Node_Notes* |
1779 | Compile::locate_node_notes(GrowableArray<Node_Notes*>* arr, |
1780 | int idx, bool can_grow) { |
1781 | assert(idx >= 0, "oob")do { if (!(idx >= 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1781, "assert(" "idx >= 0" ") failed", "oob"); ::breakpoint (); } } while (0); |
1782 | int block_idx = (idx >> _log2_node_notes_block_size); |
1783 | int grow_by = (block_idx - (arr == NULL__null? 0: arr->length())); |
1784 | if (grow_by >= 0) { |
1785 | if (!can_grow) return NULL__null; |
1786 | grow_node_notes(arr, grow_by + 1); |
1787 | } |
1788 | if (arr == NULL__null) return NULL__null; |
1789 | // (Every element of arr is a sub-array of length _node_notes_block_size.) |
1790 | return arr->at(block_idx) + (idx & (_node_notes_block_size-1)); |
1791 | } |
1792 | |
1793 | inline bool |
1794 | Compile::set_node_notes_at(int idx, Node_Notes* value) { |
1795 | if (value == NULL__null || value->is_clear()) |
1796 | return false; // nothing to write => write nothing |
1797 | Node_Notes* loc = locate_node_notes(_node_note_array, idx, true); |
1798 | assert(loc != NULL, "")do { if (!(loc != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1798, "assert(" "loc != __null" ") failed", ""); ::breakpoint (); } } while (0); |
1799 | return loc->update_from(value); |
1800 | } |
1801 | |
1802 | |
1803 | //------------------------------TypeNode--------------------------------------- |
1804 | // Node with a Type constant. |
1805 | class TypeNode : public Node { |
1806 | protected: |
1807 | virtual uint hash() const; // Check the type |
1808 | virtual bool cmp( const Node &n ) const; |
1809 | virtual uint size_of() const; // Size is bigger |
1810 | const Type* const _type; |
1811 | public: |
1812 | void set_type(const Type* t) { |
1813 | assert(t != NULL, "sanity")do { if (!(t != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1813, "assert(" "t != __null" ") failed", "sanity"); ::breakpoint (); } } while (0); |
1814 | debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH)uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH; |
1815 | *(const Type**)&_type = t; // cast away const-ness |
1816 | // If this node is in the hash table, make sure it doesn't need a rehash. |
1817 | assert(check_hash == NO_HASH || check_hash == hash(), "type change must preserve hash code")do { if (!(check_hash == NO_HASH || check_hash == hash())) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1817, "assert(" "check_hash == NO_HASH || check_hash == hash()" ") failed", "type change must preserve hash code"); ::breakpoint (); } } while (0); |
1818 | } |
1819 | const Type* type() const { assert(_type != NULL, "sanity")do { if (!(_type != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1819, "assert(" "_type != __null" ") failed", "sanity"); :: breakpoint(); } } while (0); return _type; }; |
1820 | TypeNode( const Type *t, uint required ) : Node(required), _type(t) { |
1821 | init_class_id(Class_Type); |
1822 | } |
1823 | virtual const Type* Value(PhaseGVN* phase) const; |
1824 | virtual const Type *bottom_type() const; |
1825 | virtual uint ideal_reg() const; |
1826 | #ifndef PRODUCT |
1827 | virtual void dump_spec(outputStream *st) const; |
1828 | virtual void dump_compact_spec(outputStream *st) const; |
1829 | #endif |
1830 | }; |
1831 | |
1832 | #include "opto/opcodes.hpp" |
1833 | |
1834 | #define Op_IL(op)inline int Op_op(BasicType bt) { do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1834, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); if (bt == T_INT) { return Op_opI ; } return Op_opL; } \ |
1835 | inline int Op_ ## op(BasicType bt) { \ |
1836 | assert(bt == T_INT || bt == T_LONG, "only for int or longs")do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1836, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); \ |
1837 | if (bt == T_INT) { \ |
1838 | return Op_## op ## I; \ |
1839 | } \ |
1840 | return Op_## op ## L; \ |
1841 | } |
1842 | |
1843 | Op_IL(Add)inline int Op_Add(BasicType bt) { do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1843, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); if (bt == T_INT) { return Op_AddI ; } return Op_AddL; } |
1844 | Op_IL(Sub)inline int Op_Sub(BasicType bt) { do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1844, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); if (bt == T_INT) { return Op_SubI ; } return Op_SubL; } |
1845 | Op_IL(Mul)inline int Op_Mul(BasicType bt) { do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1845, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); if (bt == T_INT) { return Op_MulI ; } return Op_MulL; } |
1846 | Op_IL(URShift)inline int Op_URShift(BasicType bt) { do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1846, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); if (bt == T_INT) { return Op_URShiftI ; } return Op_URShiftL; } |
1847 | Op_IL(LShift)inline int Op_LShift(BasicType bt) { do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1847, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); if (bt == T_INT) { return Op_LShiftI ; } return Op_LShiftL; } |
1848 | Op_IL(Xor)inline int Op_Xor(BasicType bt) { do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1848, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); if (bt == T_INT) { return Op_XorI ; } return Op_XorL; } |
1849 | Op_IL(Cmp)inline int Op_Cmp(BasicType bt) { do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1849, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); if (bt == T_INT) { return Op_CmpI ; } return Op_CmpL; } |
1850 | |
1851 | inline int Op_Cmp_unsigned(BasicType bt) { |
1852 | assert(bt == T_INT || bt == T_LONG, "only for int or longs")do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1852, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); |
1853 | if (bt == T_INT) { |
1854 | return Op_CmpU; |
1855 | } |
1856 | return Op_CmpUL; |
1857 | } |
1858 | |
1859 | inline int Op_Cast(BasicType bt) { |
1860 | assert(bt == T_INT || bt == T_LONG, "only for int or longs")do { if (!(bt == T_INT || bt == T_LONG)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp" , 1860, "assert(" "bt == T_INT || bt == T_LONG" ") failed", "only for int or longs" ); ::breakpoint(); } } while (0); |
1861 | if (bt == T_INT) { |
1862 | return Op_CastII; |
1863 | } |
1864 | return Op_CastLL; |
1865 | } |
1866 | |
1867 | #endif // SHARE_OPTO_NODE_HPP |