Bug Summary

File:jdk/src/hotspot/share/opto/lcm.cpp
Warning:line 810, column 12
Array access (from variable 'save_policy') results in a null pointer dereference

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name lcm.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/libjvm/objs/precompiled -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D _GNU_SOURCE -D _REENTRANT -D LIBC=gnu -D LINUX -D VM_LITTLE_ENDIAN -D _LP64=1 -D ASSERT -D CHECK_UNHANDLED_OOPS -D TARGET_ARCH_x86 -D INCLUDE_SUFFIX_OS=_linux -D INCLUDE_SUFFIX_CPU=_x86 -D INCLUDE_SUFFIX_COMPILER=_gcc -D TARGET_COMPILER_gcc -D AMD64 -D HOTSPOT_LIB_ARCH="amd64" -D COMPILER1 -D COMPILER2 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -I /home/daniel/Projects/java/jdk/src/hotspot/share/precompiled -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjimage -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -D _FORTIFY_SOURCE=2 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-format-zero-length -Wno-unused-parameter -Wno-unused -Wno-parentheses -Wno-comment -Wno-unknown-pragmas -Wno-address -Wno-delete-non-virtual-dtor -Wno-char-subscripts -Wno-array-bounds -Wno-int-in-bool-context -Wno-ignored-qualifiers -Wno-missing-field-initializers -Wno-implicit-fallthrough -Wno-empty-body -Wno-strict-overflow -Wno-sequence-point -Wno-maybe-uninitialized -Wno-misleading-indentation -Wno-cast-function-type -Wno-shift-negative-value -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make/hotspot -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fno-rtti -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c++ /home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp

/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp

1/*
2 * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#include "precompiled.hpp"
26#include "asm/macroAssembler.inline.hpp"
27#include "gc/shared/gc_globals.hpp"
28#include "memory/allocation.inline.hpp"
29#include "oops/compressedOops.hpp"
30#include "opto/ad.hpp"
31#include "opto/block.hpp"
32#include "opto/c2compiler.hpp"
33#include "opto/callnode.hpp"
34#include "opto/cfgnode.hpp"
35#include "opto/machnode.hpp"
36#include "opto/runtime.hpp"
37#include "opto/chaitin.hpp"
38#include "runtime/sharedRuntime.hpp"
39
40// Optimization - Graph Style
41
42// Check whether val is not-null-decoded compressed oop,
43// i.e. will grab into the base of the heap if it represents NULL.
44static bool accesses_heap_base_zone(Node *val) {
45 if (CompressedOops::base() != NULL__null) { // Implies UseCompressedOops.
46 if (val && val->is_Mach()) {
47 if (val->as_Mach()->ideal_Opcode() == Op_DecodeN) {
48 // This assumes all Decodes with TypePtr::NotNull are matched to nodes that
49 // decode NULL to point to the heap base (Decode_NN).
50 if (val->bottom_type()->is_oopptr()->ptr() == TypePtr::NotNull) {
51 return true;
52 }
53 }
54 // Must recognize load operation with Decode matched in memory operand.
55 // We should not reach here exept for PPC/AIX, as os::zero_page_read_protected()
56 // returns true everywhere else. On PPC, no such memory operands
57 // exist, therefore we did not yet implement a check for such operands.
58 NOT_AIX(Unimplemented())do { (*g_assert_poison) = 'X';; report_unimplemented("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 58); ::breakpoint(); } while (0)
;
59 }
60 }
61 return false;
62}
63
64static bool needs_explicit_null_check_for_read(Node *val) {
65 // On some OSes (AIX) the page at address 0 is only write protected.
66 // If so, only Store operations will trap.
67 if (os::zero_page_read_protected()) {
68 return false; // Implicit null check will work.
69 }
70 // Also a read accessing the base of a heap-based compressed heap will trap.
71 if (accesses_heap_base_zone(val) && // Hits the base zone page.
72 CompressedOops::use_implicit_null_checks()) { // Base zone page is protected.
73 return false;
74 }
75
76 return true;
77}
78
79//------------------------------implicit_null_check----------------------------
80// Detect implicit-null-check opportunities. Basically, find NULL checks
81// with suitable memory ops nearby. Use the memory op to do the NULL check.
82// I can generate a memory op if there is not one nearby.
83// The proj is the control projection for the not-null case.
84// The val is the pointer being checked for nullness or
85// decodeHeapOop_not_null node if it did not fold into address.
86void PhaseCFG::implicit_null_check(Block* block, Node *proj, Node *val, int allowed_reasons) {
87 // Assume if null check need for 0 offset then always needed
88 // Intel solaris doesn't support any null checks yet and no
89 // mechanism exists (yet) to set the switches at an os_cpu level
90 if( !ImplicitNullChecks || MacroAssembler::needs_explicit_null_check(0)) return;
91
92 // Make sure the ptr-is-null path appears to be uncommon!
93 float f = block->end()->as_MachIf()->_prob;
94 if( proj->Opcode() == Op_IfTrue ) f = 1.0f - f;
95 if( f > PROB_UNLIKELY_MAG(4)(1e-4f) ) return;
96
97 uint bidx = 0; // Capture index of value into memop
98 bool was_store; // Memory op is a store op
99
100 // Get the successor block for if the test ptr is non-null
101 Block* not_null_block; // this one goes with the proj
102 Block* null_block;
103 if (block->get_node(block->number_of_nodes()-1) == proj) {
104 null_block = block->_succs[0];
105 not_null_block = block->_succs[1];
106 } else {
107 assert(block->get_node(block->number_of_nodes()-2) == proj, "proj is one or the other")do { if (!(block->get_node(block->number_of_nodes()-2) ==
proj)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 107, "assert(" "block->get_node(block->number_of_nodes()-2) == proj"
") failed", "proj is one or the other"); ::breakpoint(); } }
while (0)
;
108 not_null_block = block->_succs[0];
109 null_block = block->_succs[1];
110 }
111 while (null_block->is_Empty() == Block::empty_with_goto) {
112 null_block = null_block->_succs[0];
113 }
114
115 // Search the exception block for an uncommon trap.
116 // (See Parse::do_if and Parse::do_ifnull for the reason
117 // we need an uncommon trap. Briefly, we need a way to
118 // detect failure of this optimization, as in 6366351.)
119 {
120 bool found_trap = false;
121 for (uint i1 = 0; i1 < null_block->number_of_nodes(); i1++) {
122 Node* nn = null_block->get_node(i1);
123 if (nn->is_MachCall() &&
124 nn->as_MachCall()->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point()) {
125 const Type* trtype = nn->in(TypeFunc::Parms)->bottom_type();
126 if (trtype->isa_int() && trtype->is_int()->is_con()) {
127 jint tr_con = trtype->is_int()->get_con();
128 Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(tr_con);
129 Deoptimization::DeoptAction action = Deoptimization::trap_request_action(tr_con);
130 assert((int)reason < (int)BitsPerInt, "recode bit map")do { if (!((int)reason < (int)BitsPerInt)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 130, "assert(" "(int)reason < (int)BitsPerInt" ") failed"
, "recode bit map"); ::breakpoint(); } } while (0)
;
131 if (is_set_nth_bit(allowed_reasons, (int) reason)
132 && action != Deoptimization::Action_none) {
133 // This uncommon trap is sure to recompile, eventually.
134 // When that happens, C->too_many_traps will prevent
135 // this transformation from happening again.
136 found_trap = true;
137 }
138 }
139 break;
140 }
141 }
142 if (!found_trap) {
143 // We did not find an uncommon trap.
144 return;
145 }
146 }
147
148 // Check for decodeHeapOop_not_null node which did not fold into address
149 bool is_decoden = ((intptr_t)val) & 1;
150 val = (Node*)(((intptr_t)val) & ~1);
151
152 assert(!is_decoden || (val->in(0) == NULL) && val->is_Mach() &&do { if (!(!is_decoden || (val->in(0) == __null) &&
val->is_Mach() && (val->as_Mach()->ideal_Opcode
() == Op_DecodeN))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 153, "assert(" "!is_decoden || (val->in(0) == __null) && val->is_Mach() && (val->as_Mach()->ideal_Opcode() == Op_DecodeN)"
") failed", "sanity"); ::breakpoint(); } } while (0)
153 (val->as_Mach()->ideal_Opcode() == Op_DecodeN), "sanity")do { if (!(!is_decoden || (val->in(0) == __null) &&
val->is_Mach() && (val->as_Mach()->ideal_Opcode
() == Op_DecodeN))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 153, "assert(" "!is_decoden || (val->in(0) == __null) && val->is_Mach() && (val->as_Mach()->ideal_Opcode() == Op_DecodeN)"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
154
155 // Search the successor block for a load or store who's base value is also
156 // the tested value. There may be several.
157 MachNode *best = NULL__null; // Best found so far
158 for (DUIterator i = val->outs(); val->has_out(i); i++) {
159 Node *m = val->out(i);
160 if( !m->is_Mach() ) continue;
161 MachNode *mach = m->as_Mach();
162 was_store = false;
163 int iop = mach->ideal_Opcode();
164 switch( iop ) {
165 case Op_LoadB:
166 case Op_LoadUB:
167 case Op_LoadUS:
168 case Op_LoadD:
169 case Op_LoadF:
170 case Op_LoadI:
171 case Op_LoadL:
172 case Op_LoadP:
173 case Op_LoadN:
174 case Op_LoadS:
175 case Op_LoadKlass:
176 case Op_LoadNKlass:
177 case Op_LoadRange:
178 case Op_LoadD_unaligned:
179 case Op_LoadL_unaligned:
180 assert(mach->in(2) == val, "should be address")do { if (!(mach->in(2) == val)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 180, "assert(" "mach->in(2) == val" ") failed", "should be address"
); ::breakpoint(); } } while (0)
;
181 break;
182 case Op_StoreB:
183 case Op_StoreC:
184 case Op_StoreCM:
185 case Op_StoreD:
186 case Op_StoreF:
187 case Op_StoreI:
188 case Op_StoreL:
189 case Op_StoreP:
190 case Op_StoreN:
191 case Op_StoreNKlass:
192 was_store = true; // Memory op is a store op
193 // Stores will have their address in slot 2 (memory in slot 1).
194 // If the value being nul-checked is in another slot, it means we
195 // are storing the checked value, which does NOT check the value!
196 if( mach->in(2) != val ) continue;
197 break; // Found a memory op?
198 case Op_StrComp:
199 case Op_StrEquals:
200 case Op_StrIndexOf:
201 case Op_StrIndexOfChar:
202 case Op_AryEq:
203 case Op_StrInflatedCopy:
204 case Op_StrCompressedCopy:
205 case Op_EncodeISOArray:
206 case Op_HasNegatives:
207 // Not a legit memory op for implicit null check regardless of
208 // embedded loads
209 continue;
210 default: // Also check for embedded loads
211 if( !mach->needs_anti_dependence_check() )
212 continue; // Not an memory op; skip it
213 if( must_clone[iop] ) {
214 // Do not move nodes which produce flags because
215 // RA will try to clone it to place near branch and
216 // it will cause recompilation, see clone_node().
217 continue;
218 }
219 {
220 // Check that value is used in memory address in
221 // instructions with embedded load (CmpP val1,(val2+off)).
222 Node* base;
223 Node* index;
224 const MachOper* oper = mach->memory_inputs(base, index);
225 if (oper == NULL__null || oper == (MachOper*)-1) {
226 continue; // Not an memory op; skip it
227 }
228 if (val == base ||
229 (val == index && val->bottom_type()->isa_narrowoop())) {
230 break; // Found it
231 } else {
232 continue; // Skip it
233 }
234 }
235 break;
236 }
237
238 // On some OSes (AIX) the page at address 0 is only write protected.
239 // If so, only Store operations will trap.
240 // But a read accessing the base of a heap-based compressed heap will trap.
241 if (!was_store && needs_explicit_null_check_for_read(val)) {
242 continue;
243 }
244
245 // Check that node's control edge is not-null block's head or dominates it,
246 // otherwise we can't hoist it because there are other control dependencies.
247 Node* ctrl = mach->in(0);
248 if (ctrl != NULL__null && !(ctrl == not_null_block->head() ||
249 get_block_for_node(ctrl)->dominates(not_null_block))) {
250 continue;
251 }
252
253 // check if the offset is not too high for implicit exception
254 {
255 intptr_t offset = 0;
256 const TypePtr *adr_type = NULL__null; // Do not need this return value here
257 const Node* base = mach->get_base_and_disp(offset, adr_type);
258 if (base == NULL__null || base == NodeSentinel(Node*)-1) {
259 // Narrow oop address doesn't have base, only index.
260 // Give up if offset is beyond page size or if heap base is not protected.
261 if (val->bottom_type()->isa_narrowoop() &&
262 (MacroAssembler::needs_explicit_null_check(offset) ||
263 !CompressedOops::use_implicit_null_checks()))
264 continue;
265 // cannot reason about it; is probably not implicit null exception
266 } else {
267 const TypePtr* tptr;
268 if ((UseCompressedOops || UseCompressedClassPointers) &&
269 (CompressedOops::shift() == 0 || CompressedKlassPointers::shift() == 0)) {
270 // 32-bits narrow oop can be the base of address expressions
271 tptr = base->get_ptr_type();
272 } else {
273 // only regular oops are expected here
274 tptr = base->bottom_type()->is_ptr();
275 }
276 // Give up if offset is not a compile-time constant.
277 if (offset == Type::OffsetBot || tptr->_offset == Type::OffsetBot)
278 continue;
279 offset += tptr->_offset; // correct if base is offseted
280 // Give up if reference is beyond page size.
281 if (MacroAssembler::needs_explicit_null_check(offset))
282 continue;
283 // Give up if base is a decode node and the heap base is not protected.
284 if (base->is_Mach() && base->as_Mach()->ideal_Opcode() == Op_DecodeN &&
285 !CompressedOops::use_implicit_null_checks())
286 continue;
287 }
288 }
289
290 // Check ctrl input to see if the null-check dominates the memory op
291 Block *cb = get_block_for_node(mach);
292 cb = cb->_idom; // Always hoist at least 1 block
293 if( !was_store ) { // Stores can be hoisted only one block
294 while( cb->_dom_depth > (block->_dom_depth + 1))
295 cb = cb->_idom; // Hoist loads as far as we want
296 // The non-null-block should dominate the memory op, too. Live
297 // range spilling will insert a spill in the non-null-block if it is
298 // needs to spill the memory op for an implicit null check.
299 if (cb->_dom_depth == (block->_dom_depth + 1)) {
300 if (cb != not_null_block) continue;
301 cb = cb->_idom;
302 }
303 }
304 if( cb != block ) continue;
305
306 // Found a memory user; see if it can be hoisted to check-block
307 uint vidx = 0; // Capture index of value into memop
308 uint j;
309 for( j = mach->req()-1; j > 0; j-- ) {
310 if( mach->in(j) == val ) {
311 vidx = j;
312 // Ignore DecodeN val which could be hoisted to where needed.
313 if( is_decoden ) continue;
314 }
315 // Block of memory-op input
316 Block *inb = get_block_for_node(mach->in(j));
317 Block *b = block; // Start from nul check
318 while( b != inb && b->_dom_depth > inb->_dom_depth )
319 b = b->_idom; // search upwards for input
320 // See if input dominates null check
321 if( b != inb )
322 break;
323 }
324 if( j > 0 )
325 continue;
326 Block *mb = get_block_for_node(mach);
327 // Hoisting stores requires more checks for the anti-dependence case.
328 // Give up hoisting if we have to move the store past any load.
329 if( was_store ) {
330 Block *b = mb; // Start searching here for a local load
331 // mach use (faulting) trying to hoist
332 // n might be blocker to hoisting
333 while( b != block ) {
334 uint k;
335 for( k = 1; k < b->number_of_nodes(); k++ ) {
336 Node *n = b->get_node(k);
337 if( n->needs_anti_dependence_check() &&
338 n->in(LoadNode::Memory) == mach->in(StoreNode::Memory) )
339 break; // Found anti-dependent load
340 }
341 if( k < b->number_of_nodes() )
342 break; // Found anti-dependent load
343 // Make sure control does not do a merge (would have to check allpaths)
344 if( b->num_preds() != 2 ) break;
345 b = get_block_for_node(b->pred(1)); // Move up to predecessor block
346 }
347 if( b != block ) continue;
348 }
349
350 // Make sure this memory op is not already being used for a NullCheck
351 Node *e = mb->end();
352 if( e->is_MachNullCheck() && e->in(1) == mach )
353 continue; // Already being used as a NULL check
354
355 // Found a candidate! Pick one with least dom depth - the highest
356 // in the dom tree should be closest to the null check.
357 if (best == NULL__null || get_block_for_node(mach)->_dom_depth < get_block_for_node(best)->_dom_depth) {
358 best = mach;
359 bidx = vidx;
360 }
361 }
362 // No candidate!
363 if (best == NULL__null) {
364 return;
365 }
366
367 // ---- Found an implicit null check
368#ifndef PRODUCT
369 extern int implicit_null_checks;
370 implicit_null_checks++;
371#endif
372
373 if( is_decoden ) {
374 // Check if we need to hoist decodeHeapOop_not_null first.
375 Block *valb = get_block_for_node(val);
376 if( block != valb && block->_dom_depth < valb->_dom_depth ) {
377 // Hoist it up to the end of the test block together with its inputs if they exist.
378 for (uint i = 2; i < val->req(); i++) {
379 // DecodeN has 2 regular inputs + optional MachTemp or load Base inputs.
380 Node *temp = val->in(i);
381 Block *tempb = get_block_for_node(temp);
382 if (!tempb->dominates(block)) {
383 assert(block->dominates(tempb), "sanity check: temp node placement")do { if (!(block->dominates(tempb))) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 383, "assert(" "block->dominates(tempb)" ") failed", "sanity check: temp node placement"
); ::breakpoint(); } } while (0)
;
384 // We only expect nodes without further inputs, like MachTemp or load Base.
385 assert(temp->req() == 0 || (temp->req() == 1 && temp->in(0) == (Node*)C->root()),do { if (!(temp->req() == 0 || (temp->req() == 1 &&
temp->in(0) == (Node*)C->root()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 386, "assert(" "temp->req() == 0 || (temp->req() == 1 && temp->in(0) == (Node*)C->root())"
") failed", "need for recursive hoisting not expected"); ::breakpoint
(); } } while (0)
386 "need for recursive hoisting not expected")do { if (!(temp->req() == 0 || (temp->req() == 1 &&
temp->in(0) == (Node*)C->root()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 386, "assert(" "temp->req() == 0 || (temp->req() == 1 && temp->in(0) == (Node*)C->root())"
") failed", "need for recursive hoisting not expected"); ::breakpoint
(); } } while (0)
;
387 tempb->find_remove(temp);
388 block->add_inst(temp);
389 map_node_to_block(temp, block);
390 }
391 }
392 valb->find_remove(val);
393 block->add_inst(val);
394 map_node_to_block(val, block);
395 // DecodeN on x86 may kill flags. Check for flag-killing projections
396 // that also need to be hoisted.
397 for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
398 Node* n = val->fast_out(j);
399 if( n->is_MachProj() ) {
400 get_block_for_node(n)->find_remove(n);
401 block->add_inst(n);
402 map_node_to_block(n, block);
403 }
404 }
405 }
406 }
407 // Hoist the memory candidate up to the end of the test block.
408 Block *old_block = get_block_for_node(best);
409 old_block->find_remove(best);
410 block->add_inst(best);
411 map_node_to_block(best, block);
412
413 // Move the control dependence if it is pinned to not-null block.
414 // Don't change it in other cases: NULL or dominating control.
415 Node* ctrl = best->in(0);
416 if (ctrl != NULL__null && get_block_for_node(ctrl) == not_null_block) {
417 // Set it to control edge of null check.
418 best->set_req(0, proj->in(0)->in(0));
419 }
420
421 // Check for flag-killing projections that also need to be hoisted
422 // Should be DU safe because no edge updates.
423 for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
424 Node* n = best->fast_out(j);
425 if( n->is_MachProj() ) {
426 get_block_for_node(n)->find_remove(n);
427 block->add_inst(n);
428 map_node_to_block(n, block);
429 }
430 }
431
432 // proj==Op_True --> ne test; proj==Op_False --> eq test.
433 // One of two graph shapes got matched:
434 // (IfTrue (If (Bool NE (CmpP ptr NULL))))
435 // (IfFalse (If (Bool EQ (CmpP ptr NULL))))
436 // NULL checks are always branch-if-eq. If we see a IfTrue projection
437 // then we are replacing a 'ne' test with a 'eq' NULL check test.
438 // We need to flip the projections to keep the same semantics.
439 if( proj->Opcode() == Op_IfTrue ) {
440 // Swap order of projections in basic block to swap branch targets
441 Node *tmp1 = block->get_node(block->end_idx()+1);
442 Node *tmp2 = block->get_node(block->end_idx()+2);
443 block->map_node(tmp2, block->end_idx()+1);
444 block->map_node(tmp1, block->end_idx()+2);
445 Node *tmp = new Node(C->top()); // Use not NULL input
446 tmp1->replace_by(tmp);
447 tmp2->replace_by(tmp1);
448 tmp->replace_by(tmp2);
449 tmp->destruct(NULL__null);
450 }
451
452 // Remove the existing null check; use a new implicit null check instead.
453 // Since schedule-local needs precise def-use info, we need to correct
454 // it as well.
455 Node *old_tst = proj->in(0);
456 MachNode *nul_chk = new MachNullCheckNode(old_tst->in(0),best,bidx);
457 block->map_node(nul_chk, block->end_idx());
458 map_node_to_block(nul_chk, block);
459 // Redirect users of old_test to nul_chk
460 for (DUIterator_Last i2min, i2 = old_tst->last_outs(i2min); i2 >= i2min; --i2)
461 old_tst->last_out(i2)->set_req(0, nul_chk);
462 // Clean-up any dead code
463 for (uint i3 = 0; i3 < old_tst->req(); i3++) {
464 Node* in = old_tst->in(i3);
465 old_tst->set_req(i3, NULL__null);
466 if (in->outcnt() == 0) {
467 // Remove dead input node
468 in->disconnect_inputs(C);
469 block->find_remove(in);
470 }
471 }
472
473 latency_from_uses(nul_chk);
474 latency_from_uses(best);
475
476 // insert anti-dependences to defs in this block
477 if (! best->needs_anti_dependence_check()) {
478 for (uint k = 1; k < block->number_of_nodes(); k++) {
479 Node *n = block->get_node(k);
480 if (n->needs_anti_dependence_check() &&
481 n->in(LoadNode::Memory) == best->in(StoreNode::Memory)) {
482 // Found anti-dependent load
483 insert_anti_dependences(block, n);
484 }
485 }
486 }
487}
488
489
490//------------------------------select-----------------------------------------
491// Select a nice fellow from the worklist to schedule next. If there is only
492// one choice, then use it. Projections take top priority for correctness
493// reasons - if I see a projection, then it is next. There are a number of
494// other special cases, for instructions that consume condition codes, et al.
495// These are chosen immediately. Some instructions are required to immediately
496// precede the last instruction in the block, and these are taken last. Of the
497// remaining cases (most), choose the instruction with the greatest latency
498// (that is, the most number of pseudo-cycles required to the end of the
499// routine). If there is a tie, choose the instruction with the most inputs.
500Node* PhaseCFG::select(
501 Block* block,
502 Node_List &worklist,
503 GrowableArray<int> &ready_cnt,
504 VectorSet &next_call,
505 uint sched_slot,
506 intptr_t* recalc_pressure_nodes) {
507
508 // If only a single entry on the stack, use it
509 uint cnt = worklist.size();
510 if (cnt == 1) {
511 Node *n = worklist[0];
512 worklist.map(0,worklist.pop());
513 return n;
514 }
515
516 uint choice = 0; // Bigger is most important
517 uint latency = 0; // Bigger is scheduled first
518 uint score = 0; // Bigger is better
519 int idx = -1; // Index in worklist
520 int cand_cnt = 0; // Candidate count
521 bool block_size_threshold_ok = (recalc_pressure_nodes != NULL__null) && (block->number_of_nodes() > 10);
522
523 for( uint i=0; i<cnt; i++ ) { // Inspect entire worklist
524 // Order in worklist is used to break ties.
525 // See caller for how this is used to delay scheduling
526 // of induction variable increments to after the other
527 // uses of the phi are scheduled.
528 Node *n = worklist[i]; // Get Node on worklist
529
530 int iop = n->is_Mach() ? n->as_Mach()->ideal_Opcode() : 0;
531 if( n->is_Proj() || // Projections always win
532 n->Opcode()== Op_Con || // So does constant 'Top'
533 iop == Op_CreateEx || // Create-exception must start block
534 iop == Op_CheckCastPP
535 ) {
536 worklist.map(i,worklist.pop());
537 return n;
538 }
539
540 // Final call in a block must be adjacent to 'catch'
541 Node *e = block->end();
542 if( e->is_Catch() && e->in(0)->in(0) == n )
543 continue;
544
545 // Memory op for an implicit null check has to be at the end of the block
546 if( e->is_MachNullCheck() && e->in(1) == n )
547 continue;
548
549 // Schedule IV increment last.
550 if (e->is_Mach() && e->as_Mach()->ideal_Opcode() == Op_CountedLoopEnd) {
551 // Cmp might be matched into CountedLoopEnd node.
552 Node *cmp = (e->in(1)->ideal_reg() == Op_RegFlags) ? e->in(1) : e;
553 if (cmp->req() > 1 && cmp->in(1) == n && n->is_iteratively_computed()) {
554 continue;
555 }
556 }
557
558 uint n_choice = 2;
559
560 // See if this instruction is consumed by a branch. If so, then (as the
561 // branch is the last instruction in the basic block) force it to the
562 // end of the basic block
563 if ( must_clone[iop] ) {
564 // See if any use is a branch
565 bool found_machif = false;
566
567 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
568 Node* use = n->fast_out(j);
569
570 // The use is a conditional branch, make them adjacent
571 if (use->is_MachIf() && get_block_for_node(use) == block) {
572 found_machif = true;
573 break;
574 }
575
576 // More than this instruction pending for successor to be ready,
577 // don't choose this if other opportunities are ready
578 if (ready_cnt.at(use->_idx) > 1)
579 n_choice = 1;
580 }
581
582 // loop terminated, prefer not to use this instruction
583 if (found_machif)
584 continue;
585 }
586
587 // See if this has a predecessor that is "must_clone", i.e. sets the
588 // condition code. If so, choose this first
589 for (uint j = 0; j < n->req() ; j++) {
590 Node *inn = n->in(j);
591 if (inn) {
592 if (inn->is_Mach() && must_clone[inn->as_Mach()->ideal_Opcode()] ) {
593 n_choice = 3;
594 break;
595 }
596 }
597 }
598
599 // MachTemps should be scheduled last so they are near their uses
600 if (n->is_MachTemp()) {
601 n_choice = 1;
602 }
603
604 uint n_latency = get_latency_for_node(n);
605 uint n_score = n->req(); // Many inputs get high score to break ties
606
607 if (OptoRegScheduling && block_size_threshold_ok) {
608 if (recalc_pressure_nodes[n->_idx] == 0x7fff7fff) {
609 _regalloc->_scratch_int_pressure.init(_regalloc->_sched_int_pressure.high_pressure_limit());
610 _regalloc->_scratch_float_pressure.init(_regalloc->_sched_float_pressure.high_pressure_limit());
611 // simulate the notion that we just picked this node to schedule
612 n->add_flag(Node::Flag_is_scheduled);
613 // now caculate its effect upon the graph if we did
614 adjust_register_pressure(n, block, recalc_pressure_nodes, false);
615 // return its state for finalize in case somebody else wins
616 n->remove_flag(Node::Flag_is_scheduled);
617 // now save the two final pressure components of register pressure, limiting pressure calcs to short size
618 short int_pressure = (short)_regalloc->_scratch_int_pressure.current_pressure();
619 short float_pressure = (short)_regalloc->_scratch_float_pressure.current_pressure();
620 recalc_pressure_nodes[n->_idx] = int_pressure;
621 recalc_pressure_nodes[n->_idx] |= (float_pressure << 16);
622 }
623
624 if (_scheduling_for_pressure) {
625 latency = n_latency;
626 if (n_choice != 3) {
627 // Now evaluate each register pressure component based on threshold in the score.
628 // In general the defining register type will dominate the score, ergo we will not see register pressure grow on both banks
629 // on a single instruction, but we might see it shrink on both banks.
630 // For each use of register that has a register class that is over the high pressure limit, we build n_score up for
631 // live ranges that terminate on this instruction.
632 if (_regalloc->_sched_int_pressure.current_pressure() > _regalloc->_sched_int_pressure.high_pressure_limit()) {
633 short int_pressure = (short)recalc_pressure_nodes[n->_idx];
634 n_score = (int_pressure < 0) ? ((score + n_score) - int_pressure) : (int_pressure > 0) ? 1 : n_score;
635 }
636 if (_regalloc->_sched_float_pressure.current_pressure() > _regalloc->_sched_float_pressure.high_pressure_limit()) {
637 short float_pressure = (short)(recalc_pressure_nodes[n->_idx] >> 16);
638 n_score = (float_pressure < 0) ? ((score + n_score) - float_pressure) : (float_pressure > 0) ? 1 : n_score;
639 }
640 } else {
641 // make sure we choose these candidates
642 score = 0;
643 }
644 }
645 }
646
647 // Keep best latency found
648 cand_cnt++;
649 if (choice < n_choice ||
650 (choice == n_choice &&
651 ((StressLCM && C->randomized_select(cand_cnt)) ||
652 (!StressLCM &&
653 (latency < n_latency ||
654 (latency == n_latency &&
655 (score < n_score))))))) {
656 choice = n_choice;
657 latency = n_latency;
658 score = n_score;
659 idx = i; // Also keep index in worklist
660 }
661 } // End of for all ready nodes in worklist
662
663 guarantee(idx >= 0, "index should be set")do { if (!(idx >= 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 663, "guarantee(" "idx >= 0" ") failed", "index should be set"
); ::breakpoint(); } } while (0)
;
664 Node *n = worklist[(uint)idx]; // Get the winner
665
666 worklist.map((uint)idx, worklist.pop()); // Compress worklist
667 return n;
668}
669
670//-------------------------adjust_register_pressure----------------------------
671void PhaseCFG::adjust_register_pressure(Node* n, Block* block, intptr_t* recalc_pressure_nodes, bool finalize_mode) {
672 PhaseLive* liveinfo = _regalloc->get_live();
673 IndexSet* liveout = liveinfo->live(block);
674 // first adjust the register pressure for the sources
675 for (uint i = 1; i < n->req(); i++) {
676 bool lrg_ends = false;
677 Node *src_n = n->in(i);
678 if (src_n == NULL__null) continue;
679 if (!src_n->is_Mach()) continue;
680 uint src = _regalloc->_lrg_map.find(src_n);
681 if (src == 0) continue;
682 LRG& lrg_src = _regalloc->lrgs(src);
683 // detect if the live range ends or not
684 if (liveout->member(src) == false) {
685 lrg_ends = true;
686 for (DUIterator_Fast jmax, j = src_n->fast_outs(jmax); j < jmax; j++) {
687 Node* m = src_n->fast_out(j); // Get user
688 if (m == n) continue;
689 if (!m->is_Mach()) continue;
690 MachNode *mach = m->as_Mach();
691 bool src_matches = false;
692 int iop = mach->ideal_Opcode();
693
694 switch (iop) {
695 case Op_StoreB:
696 case Op_StoreC:
697 case Op_StoreCM:
698 case Op_StoreD:
699 case Op_StoreF:
700 case Op_StoreI:
701 case Op_StoreL:
702 case Op_StoreP:
703 case Op_StoreN:
704 case Op_StoreVector:
705 case Op_StoreVectorMasked:
706 case Op_StoreVectorScatter:
707 case Op_StoreVectorScatterMasked:
708 case Op_StoreNKlass:
709 for (uint k = 1; k < m->req(); k++) {
710 Node *in = m->in(k);
711 if (in == src_n) {
712 src_matches = true;
713 break;
714 }
715 }
716 break;
717
718 default:
719 src_matches = true;
720 break;
721 }
722
723 // If we have a store as our use, ignore the non source operands
724 if (src_matches == false) continue;
725
726 // Mark every unscheduled use which is not n with a recalculation
727 if ((get_block_for_node(m) == block) && (!m->is_scheduled())) {
728 if (finalize_mode && !m->is_Phi()) {
729 recalc_pressure_nodes[m->_idx] = 0x7fff7fff;
730 }
731 lrg_ends = false;
732 }
733 }
734 }
735 // if none, this live range ends and we can adjust register pressure
736 if (lrg_ends) {
737 if (finalize_mode) {
738 _regalloc->lower_pressure(block, 0, lrg_src, NULL__null, _regalloc->_sched_int_pressure, _regalloc->_sched_float_pressure);
739 } else {
740 _regalloc->lower_pressure(block, 0, lrg_src, NULL__null, _regalloc->_scratch_int_pressure, _regalloc->_scratch_float_pressure);
741 }
742 }
743 }
744
745 // now add the register pressure from the dest and evaluate which heuristic we should use:
746 // 1.) The default, latency scheduling
747 // 2.) Register pressure scheduling based on the high pressure limit threshold for int or float register stacks
748 uint dst = _regalloc->_lrg_map.find(n);
749 if (dst != 0) {
750 LRG& lrg_dst = _regalloc->lrgs(dst);
751 if (finalize_mode) {
752 _regalloc->raise_pressure(block, lrg_dst, _regalloc->_sched_int_pressure, _regalloc->_sched_float_pressure);
753 // check to see if we fall over the register pressure cliff here
754 if (_regalloc->_sched_int_pressure.current_pressure() > _regalloc->_sched_int_pressure.high_pressure_limit()) {
755 _scheduling_for_pressure = true;
756 } else if (_regalloc->_sched_float_pressure.current_pressure() > _regalloc->_sched_float_pressure.high_pressure_limit()) {
757 _scheduling_for_pressure = true;
758 } else {
759 // restore latency scheduling mode
760 _scheduling_for_pressure = false;
761 }
762 } else {
763 _regalloc->raise_pressure(block, lrg_dst, _regalloc->_scratch_int_pressure, _regalloc->_scratch_float_pressure);
764 }
765 }
766}
767
768//------------------------------set_next_call----------------------------------
769void PhaseCFG::set_next_call(Block* block, Node* n, VectorSet& next_call) {
770 if( next_call.test_set(n->_idx) ) return;
771 for( uint i=0; i<n->len(); i++ ) {
772 Node *m = n->in(i);
773 if( !m ) continue; // must see all nodes in block that precede call
774 if (get_block_for_node(m) == block) {
775 set_next_call(block, m, next_call);
776 }
777 }
778}
779
780//------------------------------needed_for_next_call---------------------------
781// Set the flag 'next_call' for each Node that is needed for the next call to
782// be scheduled. This flag lets me bias scheduling so Nodes needed for the
783// next subroutine call get priority - basically it moves things NOT needed
784// for the next call till after the call. This prevents me from trying to
785// carry lots of stuff live across a call.
786void PhaseCFG::needed_for_next_call(Block* block, Node* this_call, VectorSet& next_call) {
787 // Find the next control-defining Node in this block
788 Node* call = NULL__null;
789 for (DUIterator_Fast imax, i = this_call->fast_outs(imax); i < imax; i++) {
790 Node* m = this_call->fast_out(i);
791 if (get_block_for_node(m) == block && // Local-block user
792 m != this_call && // Not self-start node
793 m->is_MachCall()) {
794 call = m;
795 break;
796 }
797 }
798 if (call == NULL__null) return; // No next call (e.g., block end is near)
799 // Set next-call for all inputs to this call
800 set_next_call(block, call, next_call);
801}
802
803//------------------------------add_call_kills-------------------------------------
804// helper function that adds caller save registers to MachProjNode
805static void add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe) {
806 // Fill in the kill mask for the call
807 for( OptoReg::Name r = OptoReg::Name(0); r < _last_Mach_Reg; r=OptoReg::add(r,1) ) {
16
Loop condition is true. Entering loop body
808 if( !regs.Member(r) ) { // Not already defined by the call
17
Calling 'RegMask::Member'
21
Returning from 'RegMask::Member'
22
Assuming the condition is true
23
Taking true branch
809 // Save-on-call register?
810 if ((save_policy[r] == 'C') ||
24
Array access (from variable 'save_policy') results in a null pointer dereference
811 (save_policy[r] == 'A') ||
812 ((save_policy[r] == 'E') && exclude_soe)) {
813 proj->_rout.Insert(r);
814 }
815 }
816 }
817}
818
819
820//------------------------------sched_call-------------------------------------
821uint PhaseCFG::sched_call(Block* block, uint node_cnt, Node_List& worklist, GrowableArray<int>& ready_cnt, MachCallNode* mcall, VectorSet& next_call) {
822 RegMask regs;
823
824 // Schedule all the users of the call right now. All the users are
825 // projection Nodes, so they must be scheduled next to the call.
826 // Collect all the defined registers.
827 for (DUIterator_Fast imax, i = mcall->fast_outs(imax); i < imax; i++) {
1
Calling 'DUIterator_Fast::operator<'
8
Returning from 'DUIterator_Fast::operator<'
9
Loop condition is false. Execution continues on line 859
828 Node* n = mcall->fast_out(i);
829 assert( n->is_MachProj(), "" )do { if (!(n->is_MachProj())) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 829, "assert(" "n->is_MachProj()" ") failed", ""); ::breakpoint
(); } } while (0)
;
830 int n_cnt = ready_cnt.at(n->_idx)-1;
831 ready_cnt.at_put(n->_idx, n_cnt);
832 assert( n_cnt == 0, "" )do { if (!(n_cnt == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 832, "assert(" "n_cnt == 0" ") failed", ""); ::breakpoint()
; } } while (0)
;
833 // Schedule next to call
834 block->map_node(n, node_cnt++);
835 // Collect defined registers
836 regs.OR(n->out_RegMask());
837 // Check for scheduling the next control-definer
838 if( n->bottom_type() == Type::CONTROL )
839 // Warm up next pile of heuristic bits
840 needed_for_next_call(block, n, next_call);
841
842 // Children of projections are now all ready
843 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
844 Node* m = n->fast_out(j); // Get user
845 if(get_block_for_node(m) != block) {
846 continue;
847 }
848 if( m->is_Phi() ) continue;
849 int m_cnt = ready_cnt.at(m->_idx) - 1;
850 ready_cnt.at_put(m->_idx, m_cnt);
851 if( m_cnt == 0 )
852 worklist.push(m);
853 }
854
855 }
856
857 // Act as if the call defines the Frame Pointer.
858 // Certainly the FP is alive and well after the call.
859 regs.Insert(_matcher.c_frame_pointer());
860
861 // Set all registers killed and not already defined by the call.
862 uint r_cnt = mcall->tf()->range()->cnt();
863 int op = mcall->ideal_Opcode();
864 MachProjNode *proj = new MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
865 map_node_to_block(proj, block);
866 block->insert_node(proj, node_cnt++);
867
868 // Select the right register save policy.
869 const char *save_policy = NULL__null;
10
'save_policy' initialized to a null pointer value
870 switch (op) {
11
Control jumps to the 'default' case at line 891
871 case Op_CallRuntime:
872 case Op_CallLeaf:
873 case Op_CallLeafNoFP:
874 case Op_CallLeafVector:
875 // Calling C code so use C calling convention
876 save_policy = _matcher._c_reg_save_policy;
877 break;
878
879 case Op_CallStaticJava:
880 case Op_CallDynamicJava:
881 // Calling Java code so use Java calling convention
882 save_policy = _matcher._register_save_policy;
883 break;
884 case Op_CallNative:
885 // We use the c reg save policy here since Foreign Linker
886 // only supports the C ABI currently.
887 // TODO compute actual save policy based on nep->abi
888 save_policy = _matcher._c_reg_save_policy;
889 break;
890
891 default:
892 ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 892); ::breakpoint(); } while (0)
;
12
Loop condition is false. Exiting loop
893 }
894
895 // When using CallRuntime mark SOE registers as killed by the call
896 // so values that could show up in the RegisterMap aren't live in a
897 // callee saved register since the register wouldn't know where to
898 // find them. CallLeaf and CallLeafNoFP are ok because they can't
899 // have debug info on them. Strictly speaking this only needs to be
900 // done for oops since idealreg2debugmask takes care of debug info
901 // references but there no way to handle oops differently than other
902 // pointers as far as the kill mask goes.
903 //
904 // Also, native callees can not save oops, so we kill the SOE registers
905 // here in case a native call has a safepoint. This doesn't work for
906 // RBP though, which seems to be special-cased elsewhere to always be
907 // treated as alive, so we instead manually save the location of RBP
908 // before doing the native call (see NativeInvokerGenerator::generate).
909 bool exclude_soe = op
12.1
'op' is not equal to Op_CallRuntime
12.1
'op' is not equal to Op_CallRuntime
12.1
'op' is not equal to Op_CallRuntime
== Op_CallRuntime
910 || (op
12.2
'op' is not equal to Op_CallNative
12.2
'op' is not equal to Op_CallNative
12.2
'op' is not equal to Op_CallNative
== Op_CallNative && mcall->guaranteed_safepoint());
911
912 // If the call is a MethodHandle invoke, we need to exclude the
913 // register which is used to save the SP value over MH invokes from
914 // the mask. Otherwise this register could be used for
915 // deoptimization information.
916 if (op
12.3
'op' is not equal to Op_CallStaticJava
12.3
'op' is not equal to Op_CallStaticJava
12.3
'op' is not equal to Op_CallStaticJava
== Op_CallStaticJava) {
13
Taking false branch
917 MachCallStaticJavaNode* mcallstaticjava = (MachCallStaticJavaNode*) mcall;
918 if (mcallstaticjava->_method_handle_invoke)
919 proj->_rout.OR(Matcher::method_handle_invoke_SP_save_mask());
920 }
921
922 add_call_kills(proj, regs, save_policy, exclude_soe);
14
Passing null pointer value via 3rd parameter 'save_policy'
15
Calling 'add_call_kills'
923
924 return node_cnt;
925}
926
927
928//------------------------------schedule_local---------------------------------
929// Topological sort within a block. Someday become a real scheduler.
930bool PhaseCFG::schedule_local(Block* block, GrowableArray<int>& ready_cnt, VectorSet& next_call, intptr_t *recalc_pressure_nodes) {
931 // Already "sorted" are the block start Node (as the first entry), and
932 // the block-ending Node and any trailing control projections. We leave
933 // these alone. PhiNodes and ParmNodes are made to follow the block start
934 // Node. Everything else gets topo-sorted.
935
936#ifndef PRODUCT
937 if (trace_opto_pipelining()) {
938 tty->print_cr("# --- schedule_local B%d, before: ---", block->_pre_order);
939 for (uint i = 0;i < block->number_of_nodes(); i++) {
940 tty->print("# ");
941 block->get_node(i)->fast_dump();
942 }
943 tty->print_cr("#");
944 }
945#endif
946
947 // RootNode is already sorted
948 if (block->number_of_nodes() == 1) {
949 return true;
950 }
951
952 bool block_size_threshold_ok = (recalc_pressure_nodes != NULL__null) && (block->number_of_nodes() > 10);
953
954 // We track the uses of local definitions as input dependences so that
955 // we know when a given instruction is avialable to be scheduled.
956 uint i;
957 if (OptoRegScheduling && block_size_threshold_ok) {
958 for (i = 1; i < block->number_of_nodes(); i++) { // setup nodes for pressure calc
959 Node *n = block->get_node(i);
960 n->remove_flag(Node::Flag_is_scheduled);
961 if (!n->is_Phi()) {
962 recalc_pressure_nodes[n->_idx] = 0x7fff7fff;
963 }
964 }
965 }
966
967 // Move PhiNodes and ParmNodes from 1 to cnt up to the start
968 uint node_cnt = block->end_idx();
969 uint phi_cnt = 1;
970 for( i = 1; i<node_cnt; i++ ) { // Scan for Phi
971 Node *n = block->get_node(i);
972 if( n->is_Phi() || // Found a PhiNode or ParmNode
973 (n->is_Proj() && n->in(0) == block->head()) ) {
974 // Move guy at 'phi_cnt' to the end; makes a hole at phi_cnt
975 block->map_node(block->get_node(phi_cnt), i);
976 block->map_node(n, phi_cnt++); // swap Phi/Parm up front
977 if (OptoRegScheduling && block_size_threshold_ok) {
978 // mark n as scheduled
979 n->add_flag(Node::Flag_is_scheduled);
980 }
981 } else { // All others
982 // Count block-local inputs to 'n'
983 uint cnt = n->len(); // Input count
984 uint local = 0;
985 for( uint j=0; j<cnt; j++ ) {
986 Node *m = n->in(j);
987 if( m && get_block_for_node(m) == block && !m->is_top() )
988 local++; // One more block-local input
989 }
990 ready_cnt.at_put(n->_idx, local); // Count em up
991
992#ifdef ASSERT1
993 if (UseG1GC) {
994 if( n->is_Mach() && n->as_Mach()->ideal_Opcode() == Op_StoreCM ) {
995 // Check the precedence edges
996 for (uint prec = n->req(); prec < n->len(); prec++) {
997 Node* oop_store = n->in(prec);
998 if (oop_store != NULL__null) {
999 assert(get_block_for_node(oop_store)->_dom_depth <= block->_dom_depth, "oop_store must dominate card-mark")do { if (!(get_block_for_node(oop_store)->_dom_depth <=
block->_dom_depth)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 999, "assert(" "get_block_for_node(oop_store)->_dom_depth <= block->_dom_depth"
") failed", "oop_store must dominate card-mark"); ::breakpoint
(); } } while (0)
;
1000 }
1001 }
1002 }
1003 }
1004#endif
1005
1006 // A few node types require changing a required edge to a precedence edge
1007 // before allocation.
1008 if( n->is_Mach() && n->req() > TypeFunc::Parms &&
1009 (n->as_Mach()->ideal_Opcode() == Op_MemBarAcquire ||
1010 n->as_Mach()->ideal_Opcode() == Op_MemBarVolatile) ) {
1011 // MemBarAcquire could be created without Precedent edge.
1012 // del_req() replaces the specified edge with the last input edge
1013 // and then removes the last edge. If the specified edge > number of
1014 // edges the last edge will be moved outside of the input edges array
1015 // and the edge will be lost. This is why this code should be
1016 // executed only when Precedent (== TypeFunc::Parms) edge is present.
1017 Node *x = n->in(TypeFunc::Parms);
1018 if (x != NULL__null && get_block_for_node(x) == block && n->find_prec_edge(x) != -1) {
1019 // Old edge to node within same block will get removed, but no precedence
1020 // edge will get added because it already exists. Update ready count.
1021 int cnt = ready_cnt.at(n->_idx);
1022 assert(cnt > 1, "MemBar node %d must not get ready here", n->_idx)do { if (!(cnt > 1)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 1022, "assert(" "cnt > 1" ") failed", "MemBar node %d must not get ready here"
, n->_idx); ::breakpoint(); } } while (0)
;
1023 ready_cnt.at_put(n->_idx, cnt-1);
1024 }
1025 n->del_req(TypeFunc::Parms);
1026 n->add_prec(x);
1027 }
1028 }
1029 }
1030 for(uint i2=i; i2< block->number_of_nodes(); i2++ ) // Trailing guys get zapped count
1031 ready_cnt.at_put(block->get_node(i2)->_idx, 0);
1032
1033 // All the prescheduled guys do not hold back internal nodes
1034 uint i3;
1035 for (i3 = 0; i3 < phi_cnt; i3++) { // For all pre-scheduled
1036 Node *n = block->get_node(i3); // Get pre-scheduled
1037 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
1038 Node* m = n->fast_out(j);
1039 if (get_block_for_node(m) == block) { // Local-block user
1040 int m_cnt = ready_cnt.at(m->_idx)-1;
1041 if (OptoRegScheduling && block_size_threshold_ok) {
1042 // mark m as scheduled
1043 if (m_cnt < 0) {
1044 m->add_flag(Node::Flag_is_scheduled);
1045 }
1046 }
1047 ready_cnt.at_put(m->_idx, m_cnt); // Fix ready count
1048 }
1049 }
1050 }
1051
1052 Node_List delay;
1053 // Make a worklist
1054 Node_List worklist;
1055 for(uint i4=i3; i4<node_cnt; i4++ ) { // Put ready guys on worklist
1056 Node *m = block->get_node(i4);
1057 if( !ready_cnt.at(m->_idx) ) { // Zero ready count?
1058 if (m->is_iteratively_computed()) {
1059 // Push induction variable increments last to allow other uses
1060 // of the phi to be scheduled first. The select() method breaks
1061 // ties in scheduling by worklist order.
1062 delay.push(m);
1063 } else if (m->is_Mach() && m->as_Mach()->ideal_Opcode() == Op_CreateEx) {
1064 // Force the CreateEx to the top of the list so it's processed
1065 // first and ends up at the start of the block.
1066 worklist.insert(0, m);
1067 } else {
1068 worklist.push(m); // Then on to worklist!
1069 }
1070 }
1071 }
1072 while (delay.size()) {
1073 Node* d = delay.pop();
1074 worklist.push(d);
1075 }
1076
1077 if (OptoRegScheduling && block_size_threshold_ok) {
1078 // To stage register pressure calculations we need to examine the live set variables
1079 // breaking them up by register class to compartmentalize the calculations.
1080 _regalloc->_sched_int_pressure.init(Matcher::int_pressure_limit());
1081 _regalloc->_sched_float_pressure.init(Matcher::float_pressure_limit());
1082 _regalloc->_scratch_int_pressure.init(Matcher::int_pressure_limit());
1083 _regalloc->_scratch_float_pressure.init(Matcher::float_pressure_limit());
1084
1085 _regalloc->compute_entry_block_pressure(block);
1086 }
1087
1088 // Warm up the 'next_call' heuristic bits
1089 needed_for_next_call(block, block->head(), next_call);
1090
1091#ifndef PRODUCT
1092 if (trace_opto_pipelining()) {
1093 for (uint j=0; j< block->number_of_nodes(); j++) {
1094 Node *n = block->get_node(j);
1095 int idx = n->_idx;
1096 tty->print("# ready cnt:%3d ", ready_cnt.at(idx));
1097 tty->print("latency:%3d ", get_latency_for_node(n));
1098 tty->print("%4d: %s\n", idx, n->Name());
1099 }
1100 }
1101#endif
1102
1103 uint max_idx = (uint)ready_cnt.length();
1104 // Pull from worklist and schedule
1105 while( worklist.size() ) { // Worklist is not ready
1106
1107#ifndef PRODUCT
1108 if (trace_opto_pipelining()) {
1109 tty->print("# ready list:");
1110 for( uint i=0; i<worklist.size(); i++ ) { // Inspect entire worklist
1111 Node *n = worklist[i]; // Get Node on worklist
1112 tty->print(" %d", n->_idx);
1113 }
1114 tty->cr();
1115 }
1116#endif
1117
1118 // Select and pop a ready guy from worklist
1119 Node* n = select(block, worklist, ready_cnt, next_call, phi_cnt, recalc_pressure_nodes);
1120 block->map_node(n, phi_cnt++); // Schedule him next
1121
1122 if (OptoRegScheduling && block_size_threshold_ok) {
1123 n->add_flag(Node::Flag_is_scheduled);
1124
1125 // Now adjust the resister pressure with the node we selected
1126 if (!n->is_Phi()) {
1127 adjust_register_pressure(n, block, recalc_pressure_nodes, true);
1128 }
1129 }
1130
1131#ifndef PRODUCT
1132 if (trace_opto_pipelining()) {
1133 tty->print("# select %d: %s", n->_idx, n->Name());
1134 tty->print(", latency:%d", get_latency_for_node(n));
1135 n->dump();
1136 if (Verbose) {
1137 tty->print("# ready list:");
1138 for( uint i=0; i<worklist.size(); i++ ) { // Inspect entire worklist
1139 Node *n = worklist[i]; // Get Node on worklist
1140 tty->print(" %d", n->_idx);
1141 }
1142 tty->cr();
1143 }
1144 }
1145
1146#endif
1147 if( n->is_MachCall() ) {
1148 MachCallNode *mcall = n->as_MachCall();
1149 phi_cnt = sched_call(block, phi_cnt, worklist, ready_cnt, mcall, next_call);
1150 continue;
1151 }
1152
1153 if (n->is_Mach() && n->as_Mach()->has_call()) {
1154 RegMask regs;
1155 regs.Insert(_matcher.c_frame_pointer());
1156 regs.OR(n->out_RegMask());
1157
1158 MachProjNode *proj = new MachProjNode( n, 1, RegMask::Empty, MachProjNode::fat_proj );
1159 map_node_to_block(proj, block);
1160 block->insert_node(proj, phi_cnt++);
1161
1162 add_call_kills(proj, regs, _matcher._c_reg_save_policy, false);
1163 }
1164
1165 // Children are now all ready
1166 for (DUIterator_Fast i5max, i5 = n->fast_outs(i5max); i5 < i5max; i5++) {
1167 Node* m = n->fast_out(i5); // Get user
1168 if (get_block_for_node(m) != block) {
1169 continue;
1170 }
1171 if( m->is_Phi() ) continue;
1172 if (m->_idx >= max_idx) { // new node, skip it
1173 assert(m->is_MachProj() && n->is_Mach() && n->as_Mach()->has_call(), "unexpected node types")do { if (!(m->is_MachProj() && n->is_Mach() &&
n->as_Mach()->has_call())) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 1173, "assert(" "m->is_MachProj() && n->is_Mach() && n->as_Mach()->has_call()"
") failed", "unexpected node types"); ::breakpoint(); } } while
(0)
;
1174 continue;
1175 }
1176 int m_cnt = ready_cnt.at(m->_idx) - 1;
1177 ready_cnt.at_put(m->_idx, m_cnt);
1178 if( m_cnt == 0 )
1179 worklist.push(m);
1180 }
1181 }
1182
1183 if( phi_cnt != block->end_idx() ) {
1184 // did not schedule all. Retry, Bailout, or Die
1185 if (C->subsume_loads() == true && !C->failing()) {
1186 // Retry with subsume_loads == false
1187 // If this is the first failure, the sentinel string will "stick"
1188 // to the Compile object, and the C2Compiler will see it and retry.
1189 C->record_failure(C2Compiler::retry_no_subsuming_loads());
1190 } else {
1191 assert(false, "graph should be schedulable")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 1191, "assert(" "false" ") failed", "graph should be schedulable"
); ::breakpoint(); } } while (0)
;
1192 }
1193 // assert( phi_cnt == end_idx(), "did not schedule all" );
1194 return false;
1195 }
1196
1197 if (OptoRegScheduling && block_size_threshold_ok) {
1198 _regalloc->compute_exit_block_pressure(block);
1199 block->_reg_pressure = _regalloc->_sched_int_pressure.final_pressure();
1200 block->_freg_pressure = _regalloc->_sched_float_pressure.final_pressure();
1201 }
1202
1203#ifndef PRODUCT
1204 if (trace_opto_pipelining()) {
1205 tty->print_cr("#");
1206 tty->print_cr("# after schedule_local");
1207 for (uint i = 0;i < block->number_of_nodes();i++) {
1208 tty->print("# ");
1209 block->get_node(i)->fast_dump();
1210 }
1211 tty->print_cr("# ");
1212
1213 if (OptoRegScheduling && block_size_threshold_ok) {
1214 tty->print_cr("# pressure info : %d", block->_pre_order);
1215 _regalloc->print_pressure_info(_regalloc->_sched_int_pressure, "int register info");
1216 _regalloc->print_pressure_info(_regalloc->_sched_float_pressure, "float register info");
1217 }
1218 tty->cr();
1219 }
1220#endif
1221
1222 return true;
1223}
1224
1225//--------------------------catch_cleanup_fix_all_inputs-----------------------
1226static void catch_cleanup_fix_all_inputs(Node *use, Node *old_def, Node *new_def) {
1227 for (uint l = 0; l < use->len(); l++) {
1228 if (use->in(l) == old_def) {
1229 if (l < use->req()) {
1230 use->set_req(l, new_def);
1231 } else {
1232 use->rm_prec(l);
1233 use->add_prec(new_def);
1234 l--;
1235 }
1236 }
1237 }
1238}
1239
1240//------------------------------catch_cleanup_find_cloned_def------------------
1241Node* PhaseCFG::catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def_blk, int n_clone_idx) {
1242 assert( use_blk != def_blk, "Inter-block cleanup only")do { if (!(use_blk != def_blk)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 1242, "assert(" "use_blk != def_blk" ") failed", "Inter-block cleanup only"
); ::breakpoint(); } } while (0)
;
1243
1244 // The use is some block below the Catch. Find and return the clone of the def
1245 // that dominates the use. If there is no clone in a dominating block, then
1246 // create a phi for the def in a dominating block.
1247
1248 // Find which successor block dominates this use. The successor
1249 // blocks must all be single-entry (from the Catch only; I will have
1250 // split blocks to make this so), hence they all dominate.
1251 while( use_blk->_dom_depth > def_blk->_dom_depth+1 )
1252 use_blk = use_blk->_idom;
1253
1254 // Find the successor
1255 Node *fixup = NULL__null;
1256
1257 uint j;
1258 for( j = 0; j < def_blk->_num_succs; j++ )
1259 if( use_blk == def_blk->_succs[j] )
1260 break;
1261
1262 if( j == def_blk->_num_succs ) {
1263 // Block at same level in dom-tree is not a successor. It needs a
1264 // PhiNode, the PhiNode uses from the def and IT's uses need fixup.
1265 Node_Array inputs = new Node_List();
1266 for(uint k = 1; k < use_blk->num_preds(); k++) {
1267 Block* block = get_block_for_node(use_blk->pred(k));
1268 inputs.map(k, catch_cleanup_find_cloned_def(block, def, def_blk, n_clone_idx));
1269 }
1270
1271 // Check to see if the use_blk already has an identical phi inserted.
1272 // If it exists, it will be at the first position since all uses of a
1273 // def are processed together.
1274 Node *phi = use_blk->get_node(1);
1275 if( phi->is_Phi() ) {
1276 fixup = phi;
1277 for (uint k = 1; k < use_blk->num_preds(); k++) {
1278 if (phi->in(k) != inputs[k]) {
1279 // Not a match
1280 fixup = NULL__null;
1281 break;
1282 }
1283 }
1284 }
1285
1286 // If an existing PhiNode was not found, make a new one.
1287 if (fixup == NULL__null) {
1288 Node *new_phi = PhiNode::make(use_blk->head(), def);
1289 use_blk->insert_node(new_phi, 1);
1290 map_node_to_block(new_phi, use_blk);
1291 for (uint k = 1; k < use_blk->num_preds(); k++) {
1292 new_phi->set_req(k, inputs[k]);
1293 }
1294 fixup = new_phi;
1295 }
1296
1297 } else {
1298 // Found the use just below the Catch. Make it use the clone.
1299 fixup = use_blk->get_node(n_clone_idx);
1300 }
1301
1302 return fixup;
1303}
1304
1305//--------------------------catch_cleanup_intra_block--------------------------
1306// Fix all input edges in use that reference "def". The use is in the same
1307// block as the def and both have been cloned in each successor block.
1308static void catch_cleanup_intra_block(Node *use, Node *def, Block *blk, int beg, int n_clone_idx) {
1309
1310 // Both the use and def have been cloned. For each successor block,
1311 // get the clone of the use, and make its input the clone of the def
1312 // found in that block.
1313
1314 uint use_idx = blk->find_node(use);
1315 uint offset_idx = use_idx - beg;
1316 for( uint k = 0; k < blk->_num_succs; k++ ) {
1317 // Get clone in each successor block
1318 Block *sb = blk->_succs[k];
1319 Node *clone = sb->get_node(offset_idx+1);
1320 assert( clone->Opcode() == use->Opcode(), "" )do { if (!(clone->Opcode() == use->Opcode())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 1320, "assert(" "clone->Opcode() == use->Opcode()" ") failed"
, ""); ::breakpoint(); } } while (0)
;
1321
1322 // Make use-clone reference the def-clone
1323 catch_cleanup_fix_all_inputs(clone, def, sb->get_node(n_clone_idx));
1324 }
1325}
1326
1327//------------------------------catch_cleanup_inter_block---------------------
1328// Fix all input edges in use that reference "def". The use is in a different
1329// block than the def.
1330void PhaseCFG::catch_cleanup_inter_block(Node *use, Block *use_blk, Node *def, Block *def_blk, int n_clone_idx) {
1331 if( !use_blk ) return; // Can happen if the use is a precedence edge
1332
1333 Node *new_def = catch_cleanup_find_cloned_def(use_blk, def, def_blk, n_clone_idx);
1334 catch_cleanup_fix_all_inputs(use, def, new_def);
1335}
1336
1337//------------------------------call_catch_cleanup-----------------------------
1338// If we inserted any instructions between a Call and his CatchNode,
1339// clone the instructions on all paths below the Catch.
1340void PhaseCFG::call_catch_cleanup(Block* block) {
1341
1342 // End of region to clone
1343 uint end = block->end_idx();
1344 if( !block->get_node(end)->is_Catch() ) return;
1345 // Start of region to clone
1346 uint beg = end;
1347 while(!block->get_node(beg-1)->is_MachProj() ||
1348 !block->get_node(beg-1)->in(0)->is_MachCall() ) {
1349 beg--;
1350 assert(beg > 0,"Catch cleanup walking beyond block boundary")do { if (!(beg > 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 1350, "assert(" "beg > 0" ") failed", "Catch cleanup walking beyond block boundary"
); ::breakpoint(); } } while (0)
;
1351 }
1352 // Range of inserted instructions is [beg, end)
1353 if( beg == end ) return;
1354
1355 // Clone along all Catch output paths. Clone area between the 'beg' and
1356 // 'end' indices.
1357 for( uint i = 0; i < block->_num_succs; i++ ) {
1358 Block *sb = block->_succs[i];
1359 // Clone the entire area; ignoring the edge fixup for now.
1360 for( uint j = end; j > beg; j-- ) {
1361 Node *clone = block->get_node(j-1)->clone();
1362 sb->insert_node(clone, 1);
1363 map_node_to_block(clone, sb);
1364 if (clone->needs_anti_dependence_check()) {
1365 insert_anti_dependences(sb, clone);
1366 }
1367 }
1368 }
1369
1370
1371 // Fixup edges. Check the def-use info per cloned Node
1372 for(uint i2 = beg; i2 < end; i2++ ) {
1373 uint n_clone_idx = i2-beg+1; // Index of clone of n in each successor block
1374 Node *n = block->get_node(i2); // Node that got cloned
1375 // Need DU safe iterator because of edge manipulation in calls.
1376 Unique_Node_List* out = new Unique_Node_List();
1377 for (DUIterator_Fast j1max, j1 = n->fast_outs(j1max); j1 < j1max; j1++) {
1378 out->push(n->fast_out(j1));
1379 }
1380 uint max = out->size();
1381 for (uint j = 0; j < max; j++) {// For all users
1382 Node *use = out->pop();
1383 Block *buse = get_block_for_node(use);
1384 if( use->is_Phi() ) {
1385 for( uint k = 1; k < use->req(); k++ )
1386 if( use->in(k) == n ) {
1387 Block* b = get_block_for_node(buse->pred(k));
1388 Node *fixup = catch_cleanup_find_cloned_def(b, n, block, n_clone_idx);
1389 use->set_req(k, fixup);
1390 }
1391 } else {
1392 if (block == buse) {
1393 catch_cleanup_intra_block(use, n, block, beg, n_clone_idx);
1394 } else {
1395 catch_cleanup_inter_block(use, buse, n, block, n_clone_idx);
1396 }
1397 }
1398 } // End for all users
1399
1400 } // End of for all Nodes in cloned area
1401
1402 // Remove the now-dead cloned ops
1403 for(uint i3 = beg; i3 < end; i3++ ) {
1404 block->get_node(beg)->disconnect_inputs(C);
1405 block->remove_node(beg);
1406 }
1407
1408 // If the successor blocks have a CreateEx node, move it back to the top
1409 for (uint i4 = 0; i4 < block->_num_succs; i4++) {
1410 Block *sb = block->_succs[i4];
1411 uint new_cnt = end - beg;
1412 // Remove any newly created, but dead, nodes by traversing their schedule
1413 // backwards. Here, a dead node is a node whose only outputs (if any) are
1414 // unused projections.
1415 for (uint j = new_cnt; j > 0; j--) {
1416 Node *n = sb->get_node(j);
1417 // Individual projections are examined together with all siblings when
1418 // their parent is visited.
1419 if (n->is_Proj()) {
1420 continue;
1421 }
1422 bool dead = true;
1423 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1424 Node* out = n->fast_out(i);
1425 // n is live if it has a non-projection output or a used projection.
1426 if (!out->is_Proj() || out->outcnt() > 0) {
1427 dead = false;
1428 break;
1429 }
1430 }
1431 if (dead) {
1432 // n's only outputs (if any) are unused projections scheduled next to n
1433 // (see PhaseCFG::select()). Remove these projections backwards.
1434 for (uint k = j + n->outcnt(); k > j; k--) {
1435 Node* proj = sb->get_node(k);
1436 assert(proj->is_Proj() && proj->in(0) == n,do { if (!(proj->is_Proj() && proj->in(0) == n)
) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 1437, "assert(" "proj->is_Proj() && proj->in(0) == n"
") failed", "projection should correspond to dead node"); ::
breakpoint(); } } while (0)
1437 "projection should correspond to dead node")do { if (!(proj->is_Proj() && proj->in(0) == n)
) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/lcm.cpp"
, 1437, "assert(" "proj->is_Proj() && proj->in(0) == n"
") failed", "projection should correspond to dead node"); ::
breakpoint(); } } while (0)
;
1438 proj->disconnect_inputs(C);
1439 sb->remove_node(k);
1440 new_cnt--;
1441 }
1442 // Now remove the node itself.
1443 n->disconnect_inputs(C);
1444 sb->remove_node(j);
1445 new_cnt--;
1446 }
1447 }
1448 // If any newly created nodes remain, move the CreateEx node to the top
1449 if (new_cnt > 0) {
1450 Node *cex = sb->get_node(1+new_cnt);
1451 if( cex->is_Mach() && cex->as_Mach()->ideal_Opcode() == Op_CreateEx ) {
1452 sb->remove_node(1+new_cnt);
1453 sb->insert_node(cex, 1);
1454 }
1455 }
1456 }
1457}

/home/daniel/Projects/java/jdk/src/hotspot/share/opto/node.hpp

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
38class AbstractLockNode;
39class AddNode;
40class AddPNode;
41class AliasInfo;
42class AllocateArrayNode;
43class AllocateNode;
44class ArrayCopyNode;
45class BaseCountedLoopNode;
46class BaseCountedLoopEndNode;
47class BlackholeNode;
48class Block;
49class BoolNode;
50class BoxLockNode;
51class CMoveNode;
52class CallDynamicJavaNode;
53class CallJavaNode;
54class CallLeafNode;
55class CallLeafNoFPNode;
56class CallNode;
57class CallRuntimeNode;
58class CallNativeNode;
59class CallStaticJavaNode;
60class CastFFNode;
61class CastDDNode;
62class CastVVNode;
63class CastIINode;
64class CastLLNode;
65class CatchNode;
66class CatchProjNode;
67class CheckCastPPNode;
68class ClearArrayNode;
69class CmpNode;
70class CodeBuffer;
71class ConstraintCastNode;
72class ConNode;
73class CompareAndSwapNode;
74class CompareAndExchangeNode;
75class CountedLoopNode;
76class CountedLoopEndNode;
77class DecodeNarrowPtrNode;
78class DecodeNNode;
79class DecodeNKlassNode;
80class EncodeNarrowPtrNode;
81class EncodePNode;
82class EncodePKlassNode;
83class FastLockNode;
84class FastUnlockNode;
85class HaltNode;
86class IfNode;
87class IfProjNode;
88class IfFalseNode;
89class IfTrueNode;
90class InitializeNode;
91class JVMState;
92class JumpNode;
93class JumpProjNode;
94class LoadNode;
95class LoadStoreNode;
96class LoadStoreConditionalNode;
97class LockNode;
98class LongCountedLoopNode;
99class LongCountedLoopEndNode;
100class LoopNode;
101class LShiftNode;
102class MachBranchNode;
103class MachCallDynamicJavaNode;
104class MachCallJavaNode;
105class MachCallLeafNode;
106class MachCallNode;
107class MachCallNativeNode;
108class MachCallRuntimeNode;
109class MachCallStaticJavaNode;
110class MachConstantBaseNode;
111class MachConstantNode;
112class MachGotoNode;
113class MachIfNode;
114class MachJumpNode;
115class MachNode;
116class MachNullCheckNode;
117class MachProjNode;
118class MachReturnNode;
119class MachSafePointNode;
120class MachSpillCopyNode;
121class MachTempNode;
122class MachMergeNode;
123class MachMemBarNode;
124class Matcher;
125class MemBarNode;
126class MemBarStoreStoreNode;
127class MemNode;
128class MergeMemNode;
129class MoveNode;
130class MulNode;
131class MultiNode;
132class MultiBranchNode;
133class NeverBranchNode;
134class Opaque1Node;
135class OuterStripMinedLoopNode;
136class OuterStripMinedLoopEndNode;
137class Node;
138class Node_Array;
139class Node_List;
140class Node_Stack;
141class OopMap;
142class ParmNode;
143class PCTableNode;
144class PhaseCCP;
145class PhaseGVN;
146class PhaseIterGVN;
147class PhaseRegAlloc;
148class PhaseTransform;
149class PhaseValues;
150class PhiNode;
151class Pipeline;
152class ProjNode;
153class RangeCheckNode;
154class RegMask;
155class RegionNode;
156class RootNode;
157class SafePointNode;
158class SafePointScalarObjectNode;
159class StartNode;
160class State;
161class StoreNode;
162class SubNode;
163class SubTypeCheckNode;
164class Type;
165class TypeNode;
166class UnlockNode;
167class VectorNode;
168class LoadVectorNode;
169class LoadVectorMaskedNode;
170class StoreVectorMaskedNode;
171class LoadVectorGatherNode;
172class StoreVectorNode;
173class StoreVectorScatterNode;
174class VectorMaskCmpNode;
175class VectorUnboxNode;
176class VectorSet;
177class VectorReinterpretNode;
178class 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.)
184typedef 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
196class DUIterator;
197class DUIterator_Fast;
198class DUIterator_Last;
199#else
200typedef uint DUIterator;
201typedef Node** DUIterator_Fast;
202typedef 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
223class 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
229public:
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
283private:
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
292protected:
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
496private:
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
535public:
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
794private:
795 juint _class_id;
796 juint _flags;
797
798 static juint max_flags();
799
800protected:
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
814public:
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
1052protected:
1053 bool remove_dead_region(PhaseGVN *phase, bool can_reshape);
1054public:
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);
1191public:
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
1270inline 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.
1283class 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).
1320class 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
1365DUIterator Node::outs() const
1366 { return DUIterator(this, 0); }
1367DUIterator& Node::refresh_out_pos(DUIterator& i) const
1368 { I_VDUI_ONLY(i, i.refresh()); return i; }
1369bool Node::has_out(DUIterator& i) const
1370 { I_VDUI_ONLY(i, i.verify(this,true));return i._idx < _outcnt; }
1371Node* 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".
1387class 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));
2
Assuming field '_vdui' is false
3
Taking false branch
1428 I_VDUI_ONLY(limit, limit.verify_limit());
4
Assuming field '_vdui' is false
5
Taking false branch
1429 return _outp < limit._outp;
6
Assuming '_outp' is >= 'limit._outp'
7
Returning zero, which participates in a condition later
1430 }
1431
1432 void operator=(const DUIterator_Fast& that)
1433 { _outp = that._outp; debug_only(reset(that))reset(that); }
1434};
1435
1436DUIterator_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}
1442Node* 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.
1457class 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
1494DUIterator_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}
1500Node* 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//
1516class 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.
1534class Node_Array : public ResourceObj {
1535 friend class VMStructs;
1536protected:
1537 Arena* _a; // Arena to allocate in
1538 uint _max;
1539 Node** _nodes;
1540 void grow( uint i ); // Grow array node to fit
1541public:
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
1565class Node_List : public Node_Array {
1566 friend class VMStructs;
1567 uint _cnt;
1568public:
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-------------------------------
1597class 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
1601public:
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.
1651inline void Compile::record_for_igvn(Node* n) {
1652 _for_igvn->push(n);
1653}
1654
1655//------------------------------Node_Stack-------------------------------------
1656class Node_Stack {
1657 friend class VMStructs;
1658protected:
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();
1668public:
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.
1729class Node_Notes {
1730 friend class VMStructs;
1731 JVMState* _jvms;
1732
1733public:
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:
1778inline Node_Notes*
1779Compile::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
1793inline bool
1794Compile::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.
1805class TypeNode : public Node {
1806protected:
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;
1811public:
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
1843Op_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; }
1844Op_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; }
1845Op_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; }
1846Op_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; }
1847Op_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; }
1848Op_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; }
1849Op_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
1851inline 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
1859inline 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

/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp

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_REGMASK_HPP
26#define SHARE_OPTO_REGMASK_HPP
27
28#include "code/vmreg.hpp"
29#include "opto/optoreg.hpp"
30#include "utilities/count_leading_zeros.hpp"
31#include "utilities/count_trailing_zeros.hpp"
32
33class LRG;
34
35//-------------Non-zero bit search methods used by RegMask---------------------
36// Find lowest 1, undefined if empty/0
37static unsigned int find_lowest_bit(uintptr_t mask) {
38 return count_trailing_zeros(mask);
39}
40// Find highest 1, undefined if empty/0
41static unsigned int find_highest_bit(uintptr_t mask) {
42 return count_leading_zeros(mask) ^ (BitsPerWord - 1U);
43}
44
45//------------------------------RegMask----------------------------------------
46// The ADL file describes how to print the machine-specific registers, as well
47// as any notion of register classes. We provide a register mask, which is
48// just a collection of Register numbers.
49
50// The ADLC defines 2 macros, RM_SIZE and FORALL_BODY.
51// RM_SIZE is the size of a register mask in 32-bit words.
52// FORALL_BODY replicates a BODY macro once per word in the register mask.
53// The usage is somewhat clumsy and limited to the regmask.[h,c]pp files.
54// However, it means the ADLC can redefine the unroll macro and all loops
55// over register masks will be unrolled by the correct amount.
56
57class RegMask {
58
59 friend class RegMaskIterator;
60
61 // The RM_SIZE is aligned to 64-bit - assert that this holds
62 LP64_ONLY(STATIC_ASSERT(is_aligned(RM_SIZE, 2)))static_assert((is_aligned(RM_SIZE, 2)), "is_aligned(RM_SIZE, 2)"
)
;
63
64 static const unsigned int _WordBitMask = BitsPerWord - 1U;
65 static const unsigned int _LogWordBits = LogBitsPerWord;
66 static const unsigned int _RM_SIZE = LP64_ONLY(RM_SIZE >> 1)RM_SIZE >> 1 NOT_LP64(RM_SIZE);
67 static const unsigned int _RM_MAX = _RM_SIZE - 1U;
68
69 union {
70 // Array of Register Mask bits. This array is large enough to cover
71 // all the machine registers and all parameters that need to be passed
72 // on the stack (stack registers) up to some interesting limit. Methods
73 // that need more parameters will NOT be compiled. On Intel, the limit
74 // is something like 90+ parameters.
75 int _RM_I[RM_SIZE];
76 uintptr_t _RM_UP[_RM_SIZE];
77 };
78
79 // The low and high water marks represents the lowest and highest word
80 // that might contain set register mask bits, respectively. We guarantee
81 // that there are no bits in words outside this range, but any word at
82 // and between the two marks can still be 0.
83 unsigned int _lwm;
84 unsigned int _hwm;
85
86 public:
87 enum { CHUNK_SIZE = _RM_SIZE * BitsPerWord };
88
89 // SlotsPerLong is 2, since slots are 32 bits and longs are 64 bits.
90 // Also, consider the maximum alignment size for a normally allocated
91 // value. Since we allocate register pairs but not register quads (at
92 // present), this alignment is SlotsPerLong (== 2). A normally
93 // aligned allocated register is either a single register, or a pair
94 // of adjacent registers, the lower-numbered being even.
95 // See also is_aligned_Pairs() below, and the padding added before
96 // Matcher::_new_SP to keep allocated pairs aligned properly.
97 // If we ever go to quad-word allocations, SlotsPerQuad will become
98 // the controlling alignment constraint. Note that this alignment
99 // requirement is internal to the allocator, and independent of any
100 // particular platform.
101 enum { SlotsPerLong = 2,
102 SlotsPerVecA = 8,
103 SlotsPerVecS = 1,
104 SlotsPerVecD = 2,
105 SlotsPerVecX = 4,
106 SlotsPerVecY = 8,
107 SlotsPerVecZ = 16,
108 SlotsPerRegVectMask = X86_ONLY(2)2 NOT_X86(1)
109 };
110
111 // A constructor only used by the ADLC output. All mask fields are filled
112 // in directly. Calls to this look something like RM(1,2,3,4);
113 RegMask(
114# define BODY(I) int a##I,
115 FORALL_BODYBODY(0) BODY(1) BODY(2) BODY(3) BODY(4) BODY(5) BODY(6) BODY(
7) BODY(8) BODY(9) BODY(10) BODY(11) BODY(12) BODY(13) BODY(14
) BODY(15) BODY(16) BODY(17) BODY(18) BODY(19) BODY(20) BODY(
21)
116# undef BODY
117 int dummy = 0) {
118#if defined(VM_LITTLE_ENDIAN1) || !defined(_LP641)
119# define BODY(I) _RM_I[I] = a##I;
120#else
121 // We need to swap ints.
122# define BODY(I) _RM_I[I ^ 1] = a##I;
123#endif
124 FORALL_BODYBODY(0) BODY(1) BODY(2) BODY(3) BODY(4) BODY(5) BODY(6) BODY(
7) BODY(8) BODY(9) BODY(10) BODY(11) BODY(12) BODY(13) BODY(14
) BODY(15) BODY(16) BODY(17) BODY(18) BODY(19) BODY(20) BODY(
21)
125# undef BODY
126 _lwm = 0;
127 _hwm = _RM_MAX;
128 while (_hwm > 0 && _RM_UP[_hwm] == 0) _hwm--;
129 while ((_lwm < _hwm) && _RM_UP[_lwm] == 0) _lwm++;
130 assert(valid_watermarks(), "post-condition")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 130, "assert(" "valid_watermarks()" ") failed", "post-condition"
); ::breakpoint(); } } while (0)
;
131 }
132
133 // Handy copying constructor
134 RegMask(RegMask *rm) {
135 _hwm = rm->_hwm;
136 _lwm = rm->_lwm;
137 for (unsigned i = 0; i < _RM_SIZE; i++) {
138 _RM_UP[i] = rm->_RM_UP[i];
139 }
140 assert(valid_watermarks(), "post-condition")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 140, "assert(" "valid_watermarks()" ") failed", "post-condition"
); ::breakpoint(); } } while (0)
;
141 }
142
143 // Construct an empty mask
144 RegMask() : _RM_UP(), _lwm(_RM_MAX), _hwm(0) {
145 assert(valid_watermarks(), "post-condition")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 145, "assert(" "valid_watermarks()" ") failed", "post-condition"
); ::breakpoint(); } } while (0)
;
146 }
147
148 // Construct a mask with a single bit
149 RegMask(OptoReg::Name reg) : RegMask() {
150 Insert(reg);
151 }
152
153 // Check for register being in mask
154 bool Member(OptoReg::Name reg) const {
155 assert(reg < CHUNK_SIZE, "")do { if (!(reg < CHUNK_SIZE)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 155, "assert(" "reg < CHUNK_SIZE" ") failed", ""); ::breakpoint
(); } } while (0)
;
18
Taking false branch
19
Loop condition is false. Exiting loop
156
157 unsigned r = (unsigned)reg;
158 return _RM_UP[r >> _LogWordBits] & (uintptr_t(1) << (r & _WordBitMask));
20
Returning value, which participates in a condition later
159 }
160
161 // The last bit in the register mask indicates that the mask should repeat
162 // indefinitely with ONE bits. Returns TRUE if mask is infinite or
163 // unbounded in size. Returns FALSE if mask is finite size.
164 bool is_AllStack() const {
165 return (_RM_UP[_RM_MAX] & (uintptr_t(1) << _WordBitMask)) != 0;
166 }
167
168 void set_AllStack() {
169 _RM_UP[_RM_MAX] |= (uintptr_t(1) << _WordBitMask);
170 }
171
172 // Test for being a not-empty mask.
173 bool is_NotEmpty() const {
174 assert(valid_watermarks(), "sanity")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 174, "assert(" "valid_watermarks()" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
175 uintptr_t tmp = 0;
176 for (unsigned i = _lwm; i <= _hwm; i++) {
177 tmp |= _RM_UP[i];
178 }
179 return tmp;
180 }
181
182 // Find lowest-numbered register from mask, or BAD if mask is empty.
183 OptoReg::Name find_first_elem() const {
184 assert(valid_watermarks(), "sanity")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 184, "assert(" "valid_watermarks()" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
185 for (unsigned i = _lwm; i <= _hwm; i++) {
186 uintptr_t bits = _RM_UP[i];
187 if (bits) {
188 return OptoReg::Name((i << _LogWordBits) + find_lowest_bit(bits));
189 }
190 }
191 return OptoReg::Name(OptoReg::Bad);
192 }
193
194 // Get highest-numbered register from mask, or BAD if mask is empty.
195 OptoReg::Name find_last_elem() const {
196 assert(valid_watermarks(), "sanity")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 196, "assert(" "valid_watermarks()" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
197 // Careful not to overflow if _lwm == 0
198 unsigned i = _hwm + 1;
199 while (i > _lwm) {
200 uintptr_t bits = _RM_UP[--i];
201 if (bits) {
202 return OptoReg::Name((i << _LogWordBits) + find_highest_bit(bits));
203 }
204 }
205 return OptoReg::Name(OptoReg::Bad);
206 }
207
208 // Clear out partial bits; leave only aligned adjacent bit pairs.
209 void clear_to_pairs();
210
211#ifdef ASSERT1
212 // Verify watermarks are sane, i.e., within bounds and that no
213 // register words below or above the watermarks have bits set.
214 bool valid_watermarks() const {
215 assert(_hwm < _RM_SIZE, "_hwm out of range: %d", _hwm)do { if (!(_hwm < _RM_SIZE)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 215, "assert(" "_hwm < _RM_SIZE" ") failed", "_hwm out of range: %d"
, _hwm); ::breakpoint(); } } while (0)
;
216 assert(_lwm < _RM_SIZE, "_lwm out of range: %d", _lwm)do { if (!(_lwm < _RM_SIZE)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 216, "assert(" "_lwm < _RM_SIZE" ") failed", "_lwm out of range: %d"
, _lwm); ::breakpoint(); } } while (0)
;
217 for (unsigned i = 0; i < _lwm; i++) {
218 assert(_RM_UP[i] == 0, "_lwm too high: %d regs at: %d", _lwm, i)do { if (!(_RM_UP[i] == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 218, "assert(" "_RM_UP[i] == 0" ") failed", "_lwm too high: %d regs at: %d"
, _lwm, i); ::breakpoint(); } } while (0)
;
219 }
220 for (unsigned i = _hwm + 1; i < _RM_SIZE; i++) {
221 assert(_RM_UP[i] == 0, "_hwm too low: %d regs at: %d", _hwm, i)do { if (!(_RM_UP[i] == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 221, "assert(" "_RM_UP[i] == 0" ") failed", "_hwm too low: %d regs at: %d"
, _hwm, i); ::breakpoint(); } } while (0)
;
222 }
223 return true;
224 }
225#endif // !ASSERT
226
227 // Test that the mask contains only aligned adjacent bit pairs
228 bool is_aligned_pairs() const;
229
230 // mask is a pair of misaligned registers
231 bool is_misaligned_pair() const;
232 // Test for single register
233 bool is_bound1() const;
234 // Test for a single adjacent pair
235 bool is_bound_pair() const;
236 // Test for a single adjacent set of ideal register's size.
237 bool is_bound(uint ireg) const;
238
239 // Check that whether given reg number with size is valid
240 // for current regmask, where reg is the highest number.
241 bool is_valid_reg(OptoReg::Name reg, const int size) const;
242
243 // Find the lowest-numbered register set in the mask. Return the
244 // HIGHEST register number in the set, or BAD if no sets.
245 // Assert that the mask contains only bit sets.
246 OptoReg::Name find_first_set(LRG &lrg, const int size) const;
247
248 // Clear out partial bits; leave only aligned adjacent bit sets of size.
249 void clear_to_sets(const unsigned int size);
250 // Smear out partial bits to aligned adjacent bit sets.
251 void smear_to_sets(const unsigned int size);
252 // Test that the mask contains only aligned adjacent bit sets
253 bool is_aligned_sets(const unsigned int size) const;
254
255 // Test for a single adjacent set
256 bool is_bound_set(const unsigned int size) const;
257
258 static bool is_vector(uint ireg);
259 static int num_registers(uint ireg);
260 static int num_registers(uint ireg, LRG &lrg);
261
262 // Fast overlap test. Non-zero if any registers in common.
263 bool overlap(const RegMask &rm) const {
264 assert(valid_watermarks() && rm.valid_watermarks(), "sanity")do { if (!(valid_watermarks() && rm.valid_watermarks(
))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 264, "assert(" "valid_watermarks() && rm.valid_watermarks()"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
265 unsigned hwm = MIN2(_hwm, rm._hwm);
266 unsigned lwm = MAX2(_lwm, rm._lwm);
267 uintptr_t result = 0;
268 for (unsigned i = lwm; i <= hwm; i++) {
269 result |= _RM_UP[i] & rm._RM_UP[i];
270 }
271 return result;
272 }
273
274 // Special test for register pressure based splitting
275 // UP means register only, Register plus stack, or stack only is DOWN
276 bool is_UP() const;
277
278 // Clear a register mask
279 void Clear() {
280 _lwm = _RM_MAX;
281 _hwm = 0;
282 memset(_RM_UP, 0, sizeof(uintptr_t) * _RM_SIZE);
283 assert(valid_watermarks(), "sanity")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 283, "assert(" "valid_watermarks()" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
284 }
285
286 // Fill a register mask with 1's
287 void Set_All() {
288 _lwm = 0;
289 _hwm = _RM_MAX;
290 memset(_RM_UP, 0xFF, sizeof(uintptr_t) * _RM_SIZE);
291 assert(valid_watermarks(), "sanity")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 291, "assert(" "valid_watermarks()" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
292 }
293
294 // Insert register into mask
295 void Insert(OptoReg::Name reg) {
296 assert(reg != OptoReg::Bad, "sanity")do { if (!(reg != OptoReg::Bad)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 296, "assert(" "reg != OptoReg::Bad" ") failed", "sanity");
::breakpoint(); } } while (0)
;
297 assert(reg != OptoReg::Special, "sanity")do { if (!(reg != OptoReg::Special)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 297, "assert(" "reg != OptoReg::Special" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
298 assert(reg < CHUNK_SIZE, "sanity")do { if (!(reg < CHUNK_SIZE)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 298, "assert(" "reg < CHUNK_SIZE" ") failed", "sanity");
::breakpoint(); } } while (0)
;
299 assert(valid_watermarks(), "pre-condition")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 299, "assert(" "valid_watermarks()" ") failed", "pre-condition"
); ::breakpoint(); } } while (0)
;
300 unsigned r = (unsigned)reg;
301 unsigned index = r >> _LogWordBits;
302 if (index > _hwm) _hwm = index;
303 if (index < _lwm) _lwm = index;
304 _RM_UP[index] |= (uintptr_t(1) << (r & _WordBitMask));
305 assert(valid_watermarks(), "post-condition")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 305, "assert(" "valid_watermarks()" ") failed", "post-condition"
); ::breakpoint(); } } while (0)
;
306 }
307
308 // Remove register from mask
309 void Remove(OptoReg::Name reg) {
310 assert(reg < CHUNK_SIZE, "")do { if (!(reg < CHUNK_SIZE)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 310, "assert(" "reg < CHUNK_SIZE" ") failed", ""); ::breakpoint
(); } } while (0)
;
311 unsigned r = (unsigned)reg;
312 _RM_UP[r >> _LogWordBits] &= ~(uintptr_t(1) << (r & _WordBitMask));
313 }
314
315 // OR 'rm' into 'this'
316 void OR(const RegMask &rm) {
317 assert(valid_watermarks() && rm.valid_watermarks(), "sanity")do { if (!(valid_watermarks() && rm.valid_watermarks(
))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 317, "assert(" "valid_watermarks() && rm.valid_watermarks()"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
318 // OR widens the live range
319 if (_lwm > rm._lwm) _lwm = rm._lwm;
320 if (_hwm < rm._hwm) _hwm = rm._hwm;
321 for (unsigned i = _lwm; i <= _hwm; i++) {
322 _RM_UP[i] |= rm._RM_UP[i];
323 }
324 assert(valid_watermarks(), "sanity")do { if (!(valid_watermarks())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 324, "assert(" "valid_watermarks()" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
325 }
326
327 // AND 'rm' into 'this'
328 void AND(const RegMask &rm) {
329 assert(valid_watermarks() && rm.valid_watermarks(), "sanity")do { if (!(valid_watermarks() && rm.valid_watermarks(
))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 329, "assert(" "valid_watermarks() && rm.valid_watermarks()"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
330 // Do not evaluate words outside the current watermark range, as they are
331 // already zero and an &= would not change that
332 for (unsigned i = _lwm; i <= _hwm; i++) {
333 _RM_UP[i] &= rm._RM_UP[i];
334 }
335 // Narrow the watermarks if &rm spans a narrower range.
336 // Update after to ensure non-overlapping words are zeroed out.
337 if (_lwm < rm._lwm) _lwm = rm._lwm;
338 if (_hwm > rm._hwm) _hwm = rm._hwm;
339 }
340
341 // Subtract 'rm' from 'this'
342 void SUBTRACT(const RegMask &rm) {
343 assert(valid_watermarks() && rm.valid_watermarks(), "sanity")do { if (!(valid_watermarks() && rm.valid_watermarks(
))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 343, "assert(" "valid_watermarks() && rm.valid_watermarks()"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
344 unsigned hwm = MIN2(_hwm, rm._hwm);
345 unsigned lwm = MAX2(_lwm, rm._lwm);
346 for (unsigned i = lwm; i <= hwm; i++) {
347 _RM_UP[i] &= ~rm._RM_UP[i];
348 }
349 }
350
351 // Compute size of register mask: number of bits
352 uint Size() const;
353
354#ifndef PRODUCT
355 void print() const { dump(); }
356 void dump(outputStream *st = tty) const; // Print a mask
357#endif
358
359 static const RegMask Empty; // Common empty mask
360 static const RegMask All; // Common all mask
361
362 static bool can_represent(OptoReg::Name reg) {
363 // NOTE: -1 in computation reflects the usage of the last
364 // bit of the regmask as an infinite stack flag and
365 // -7 is to keep mask aligned for largest value (VecZ).
366 return (int)reg < (int)(CHUNK_SIZE - 1);
367 }
368 static bool can_represent_arg(OptoReg::Name reg) {
369 // NOTE: -SlotsPerVecZ in computation reflects the need
370 // to keep mask aligned for largest value (VecZ).
371 return (int)reg < (int)(CHUNK_SIZE - SlotsPerVecZ);
372 }
373};
374
375class RegMaskIterator {
376 private:
377 uintptr_t _current_bits;
378 unsigned int _next_index;
379 OptoReg::Name _reg;
380 const RegMask& _rm;
381 public:
382 RegMaskIterator(const RegMask& rm) : _current_bits(0), _next_index(rm._lwm), _reg(OptoReg::Bad), _rm(rm) {
383 // Calculate the first element
384 next();
385 }
386
387 bool has_next() {
388 return _reg != OptoReg::Bad;
389 }
390
391 // Get the current element and calculate the next
392 OptoReg::Name next() {
393 OptoReg::Name r = _reg;
394
395 // This bit shift scheme, borrowed from IndexSetIterator,
396 // shifts the _current_bits down by the number of trailing
397 // zeros - which leaves the "current" bit on position zero,
398 // then subtracts by 1 to clear it. This quirk avoids the
399 // undefined behavior that could arise if trying to shift
400 // away the bit with a single >> (next_bit + 1) shift when
401 // next_bit is 31/63. It also keeps number of shifts and
402 // arithmetic ops to a minimum.
403
404 // We have previously found bits at _next_index - 1, and
405 // still have some left at the same index.
406 if (_current_bits != 0) {
407 unsigned int next_bit = find_lowest_bit(_current_bits);
408 assert(_reg != OptoReg::Bad, "can't be in a bad state")do { if (!(_reg != OptoReg::Bad)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 408, "assert(" "_reg != OptoReg::Bad" ") failed", "can't be in a bad state"
); ::breakpoint(); } } while (0)
;
409 assert(next_bit > 0, "must be")do { if (!(next_bit > 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 409, "assert(" "next_bit > 0" ") failed", "must be"); ::
breakpoint(); } } while (0)
;
410 assert(((_current_bits >> next_bit) & 0x1) == 1, "lowest bit must be set after shift")do { if (!(((_current_bits >> next_bit) & 0x1) == 1
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 410, "assert(" "((_current_bits >> next_bit) & 0x1) == 1"
") failed", "lowest bit must be set after shift"); ::breakpoint
(); } } while (0)
;
411 _current_bits = (_current_bits >> next_bit) - 1;
412 _reg = OptoReg::add(_reg, next_bit);
413 return r;
414 }
415
416 // Find the next word with bits
417 while (_next_index <= _rm._hwm) {
418 _current_bits = _rm._RM_UP[_next_index++];
419 if (_current_bits != 0) {
420 // Found a word. Calculate the first register element and
421 // prepare _current_bits by shifting it down and clearing
422 // the lowest bit
423 unsigned int next_bit = find_lowest_bit(_current_bits);
424 assert(((_current_bits >> next_bit) & 0x1) == 1, "lowest bit must be set after shift")do { if (!(((_current_bits >> next_bit) & 0x1) == 1
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/regmask.hpp"
, 424, "assert(" "((_current_bits >> next_bit) & 0x1) == 1"
") failed", "lowest bit must be set after shift"); ::breakpoint
(); } } while (0)
;
425 _current_bits = (_current_bits >> next_bit) - 1;
426 _reg = OptoReg::Name(((_next_index - 1) << RegMask::_LogWordBits) + next_bit);
427 return r;
428 }
429 }
430
431 // No more bits
432 _reg = OptoReg::Name(OptoReg::Bad);
433 return r;
434 }
435};
436
437// Do not use this constant directly in client code!
438#undef RM_SIZE
439
440#endif // SHARE_OPTO_REGMASK_HPP