260 const Node* base = mach->get_base_and_disp(offset, adr_type);
261 if (base == nullptr || base == NodeSentinel) {
262 // Narrow oop address doesn't have base, only index.
263 // Give up if offset is beyond page size or if heap base is not protected.
264 if (val->bottom_type()->isa_narrowoop() &&
265 (MacroAssembler::needs_explicit_null_check(offset) ||
266 !CompressedOops::use_implicit_null_checks()))
267 continue;
268 // cannot reason about it; is probably not implicit null exception
269 } else {
270 const TypePtr* tptr;
271 if ((UseCompressedOops || UseCompressedClassPointers) &&
272 (CompressedOops::shift() == 0 || CompressedKlassPointers::shift() == 0)) {
273 // 32-bits narrow oop can be the base of address expressions
274 tptr = base->get_ptr_type();
275 } else {
276 // only regular oops are expected here
277 tptr = base->bottom_type()->is_ptr();
278 }
279 // Give up if offset is not a compile-time constant.
280 if (offset == Type::OffsetBot || tptr->_offset == Type::OffsetBot)
281 continue;
282 offset += tptr->_offset; // correct if base is offsetted
283 // Give up if reference is beyond page size.
284 if (MacroAssembler::needs_explicit_null_check(offset))
285 continue;
286 // Give up if base is a decode node and the heap base is not protected.
287 if (base->is_Mach() && base->as_Mach()->ideal_Opcode() == Op_DecodeN &&
288 !CompressedOops::use_implicit_null_checks())
289 continue;
290 }
291 }
292
293 // Check ctrl input to see if the null-check dominates the memory op
294 Block *cb = get_block_for_node(mach);
295 cb = cb->_idom; // Always hoist at least 1 block
296 if( !was_store ) { // Stores can be hoisted only one block
297 while( cb->_dom_depth > (block->_dom_depth + 1))
298 cb = cb->_idom; // Hoist loads as far as we want
299 // The non-null-block should dominate the memory op, too. Live
300 // range spilling will insert a spill in the non-null-block if it is
301 // needs to spill the memory op for an implicit null check.
302 if (cb->_dom_depth == (block->_dom_depth + 1)) {
303 if (cb != not_null_block) continue;
304 cb = cb->_idom;
305 }
306 }
307 if( cb != block ) continue;
308
309 // Found a memory user; see if it can be hoisted to check-block
310 uint vidx = 0; // Capture index of value into memop
311 uint j;
312 for( j = mach->req()-1; j > 0; j-- ) {
313 if( mach->in(j) == val ) {
314 vidx = j;
315 // Ignore DecodeN val which could be hoisted to where needed.
316 if( is_decoden ) continue;
317 }
318 // Block of memory-op input
319 Block *inb = get_block_for_node(mach->in(j));
320 Block *b = block; // Start from nul check
321 while( b != inb && b->_dom_depth > inb->_dom_depth )
322 b = b->_idom; // search upwards for input
323 // See if input dominates null check
324 if( b != inb )
325 break;
326 }
327 if( j > 0 )
328 continue;
329 Block *mb = get_block_for_node(mach);
330 // Hoisting stores requires more checks for the anti-dependence case.
331 // Give up hoisting if we have to move the store past any load.
332 if (was_store) {
333 // Make sure control does not do a merge (would have to check allpaths)
334 if (mb->num_preds() != 2) {
335 continue;
336 }
337 // mach is a store, hence block is the immediate dominator of mb.
338 // Due to the null-check shape of block (where its successors cannot re-join),
339 // block must be the direct predecessor of mb.
392 tempb->find_remove(temp);
393 block->add_inst(temp);
394 map_node_to_block(temp, block);
395 }
396 }
397 valb->find_remove(val);
398 block->add_inst(val);
399 map_node_to_block(val, block);
400 // DecodeN on x86 may kill flags. Check for flag-killing projections
401 // that also need to be hoisted.
402 for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
403 Node* n = val->fast_out(j);
404 if( n->is_MachProj() ) {
405 get_block_for_node(n)->find_remove(n);
406 block->add_inst(n);
407 map_node_to_block(n, block);
408 }
409 }
410 }
411 }
412 // Hoist the memory candidate up to the end of the test block.
413 Block *old_block = get_block_for_node(best);
414 old_block->find_remove(best);
415 block->add_inst(best);
416 map_node_to_block(best, block);
417
418 // Move the control dependence if it is pinned to not-null block.
419 // Don't change it in other cases: null or dominating control.
420 Node* ctrl = best->in(0);
421 if (ctrl != nullptr && get_block_for_node(ctrl) == not_null_block) {
422 // Set it to control edge of null check.
423 best->set_req(0, proj->in(0)->in(0));
424 }
425
426 // Check for flag-killing projections that also need to be hoisted
427 // Should be DU safe because no edge updates.
428 for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
429 Node* n = best->fast_out(j);
430 if( n->is_MachProj() ) {
431 get_block_for_node(n)->find_remove(n);
863 // Children of projections are now all ready
864 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
865 Node* m = n->fast_out(j); // Get user
866 if(get_block_for_node(m) != block) {
867 continue;
868 }
869 if( m->is_Phi() ) continue;
870 int m_cnt = ready_cnt.at(m->_idx) - 1;
871 ready_cnt.at_put(m->_idx, m_cnt);
872 if( m_cnt == 0 )
873 worklist.push(m);
874 }
875
876 }
877
878 // Act as if the call defines the Frame Pointer.
879 // Certainly the FP is alive and well after the call.
880 regs.Insert(_matcher.c_frame_pointer());
881
882 // Set all registers killed and not already defined by the call.
883 uint r_cnt = mcall->tf()->range()->cnt();
884 int op = mcall->ideal_Opcode();
885 MachProjNode *proj = new MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
886 map_node_to_block(proj, block);
887 block->insert_node(proj, node_cnt++);
888
889 // Select the right register save policy.
890 const char *save_policy = nullptr;
891 switch (op) {
892 case Op_CallRuntime:
893 case Op_CallLeaf:
894 case Op_CallLeafNoFP:
895 case Op_CallLeafVector:
896 // Calling C code so use C calling convention
897 save_policy = _matcher._c_reg_save_policy;
898 break;
899
900 case Op_CallStaticJava:
901 case Op_CallDynamicJava:
902 // Calling Java code so use Java calling convention
903 save_policy = _matcher._register_save_policy;
|
260 const Node* base = mach->get_base_and_disp(offset, adr_type);
261 if (base == nullptr || base == NodeSentinel) {
262 // Narrow oop address doesn't have base, only index.
263 // Give up if offset is beyond page size or if heap base is not protected.
264 if (val->bottom_type()->isa_narrowoop() &&
265 (MacroAssembler::needs_explicit_null_check(offset) ||
266 !CompressedOops::use_implicit_null_checks()))
267 continue;
268 // cannot reason about it; is probably not implicit null exception
269 } else {
270 const TypePtr* tptr;
271 if ((UseCompressedOops || UseCompressedClassPointers) &&
272 (CompressedOops::shift() == 0 || CompressedKlassPointers::shift() == 0)) {
273 // 32-bits narrow oop can be the base of address expressions
274 tptr = base->get_ptr_type();
275 } else {
276 // only regular oops are expected here
277 tptr = base->bottom_type()->is_ptr();
278 }
279 // Give up if offset is not a compile-time constant.
280 if (offset == Type::OffsetBot || tptr->offset() == Type::OffsetBot)
281 continue;
282 offset += tptr->offset(); // correct if base is offsetted
283 // Give up if reference is beyond page size.
284 if (MacroAssembler::needs_explicit_null_check(offset))
285 continue;
286 // Give up if base is a decode node and the heap base is not protected.
287 if (base->is_Mach() && base->as_Mach()->ideal_Opcode() == Op_DecodeN &&
288 !CompressedOops::use_implicit_null_checks())
289 continue;
290 }
291 }
292
293 // Check ctrl input to see if the null-check dominates the memory op
294 Block *cb = get_block_for_node(mach);
295 cb = cb->_idom; // Always hoist at least 1 block
296 if( !was_store ) { // Stores can be hoisted only one block
297 while( cb->_dom_depth > (block->_dom_depth + 1))
298 cb = cb->_idom; // Hoist loads as far as we want
299 // The non-null-block should dominate the memory op, too. Live
300 // range spilling will insert a spill in the non-null-block if it is
301 // needs to spill the memory op for an implicit null check.
302 if (cb->_dom_depth == (block->_dom_depth + 1)) {
303 if (cb != not_null_block) continue;
304 cb = cb->_idom;
305 }
306 }
307 if( cb != block ) continue;
308
309 // Found a memory user; see if it can be hoisted to check-block
310 uint vidx = 0; // Capture index of value into memop
311 uint j;
312 for( j = mach->req()-1; j > 0; j-- ) {
313 if( mach->in(j) == val ) {
314 vidx = j;
315 // Ignore DecodeN val which could be hoisted to where needed.
316 if( is_decoden ) continue;
317 }
318 // Block of memory-op input
319 Block* inb = get_block_for_node(mach->in(j));
320 if (mach->in(j)->is_Con() && mach->in(j)->req() == 1 && inb == get_block_for_node(mach)) {
321 // Ignore constant loads scheduled in the same block (we can simply hoist them as well)
322 continue;
323 }
324 Block *b = block; // Start from nul check
325 while( b != inb && b->_dom_depth > inb->_dom_depth )
326 b = b->_idom; // search upwards for input
327 // See if input dominates null check
328 if( b != inb )
329 break;
330 }
331 if( j > 0 )
332 continue;
333 Block *mb = get_block_for_node(mach);
334 // Hoisting stores requires more checks for the anti-dependence case.
335 // Give up hoisting if we have to move the store past any load.
336 if (was_store) {
337 // Make sure control does not do a merge (would have to check allpaths)
338 if (mb->num_preds() != 2) {
339 continue;
340 }
341 // mach is a store, hence block is the immediate dominator of mb.
342 // Due to the null-check shape of block (where its successors cannot re-join),
343 // block must be the direct predecessor of mb.
396 tempb->find_remove(temp);
397 block->add_inst(temp);
398 map_node_to_block(temp, block);
399 }
400 }
401 valb->find_remove(val);
402 block->add_inst(val);
403 map_node_to_block(val, block);
404 // DecodeN on x86 may kill flags. Check for flag-killing projections
405 // that also need to be hoisted.
406 for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
407 Node* n = val->fast_out(j);
408 if( n->is_MachProj() ) {
409 get_block_for_node(n)->find_remove(n);
410 block->add_inst(n);
411 map_node_to_block(n, block);
412 }
413 }
414 }
415 }
416
417 // Hoist constant load inputs as well.
418 for (uint i = 1; i < best->req(); ++i) {
419 Node* n = best->in(i);
420 if (n->is_Con() && get_block_for_node(n) == get_block_for_node(best)) {
421 get_block_for_node(n)->find_remove(n);
422 block->add_inst(n);
423 map_node_to_block(n, block);
424 // Constant loads may kill flags (for example, when XORing a register).
425 // Check for flag-killing projections that also need to be hoisted.
426 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
427 Node* proj = n->fast_out(j);
428 if (proj->is_MachProj()) {
429 get_block_for_node(proj)->find_remove(proj);
430 block->add_inst(proj);
431 map_node_to_block(proj, block);
432 }
433 }
434 }
435 }
436
437 // Hoist the memory candidate up to the end of the test block.
438 Block *old_block = get_block_for_node(best);
439 old_block->find_remove(best);
440 block->add_inst(best);
441 map_node_to_block(best, block);
442
443 // Move the control dependence if it is pinned to not-null block.
444 // Don't change it in other cases: null or dominating control.
445 Node* ctrl = best->in(0);
446 if (ctrl != nullptr && get_block_for_node(ctrl) == not_null_block) {
447 // Set it to control edge of null check.
448 best->set_req(0, proj->in(0)->in(0));
449 }
450
451 // Check for flag-killing projections that also need to be hoisted
452 // Should be DU safe because no edge updates.
453 for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
454 Node* n = best->fast_out(j);
455 if( n->is_MachProj() ) {
456 get_block_for_node(n)->find_remove(n);
888 // Children of projections are now all ready
889 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
890 Node* m = n->fast_out(j); // Get user
891 if(get_block_for_node(m) != block) {
892 continue;
893 }
894 if( m->is_Phi() ) continue;
895 int m_cnt = ready_cnt.at(m->_idx) - 1;
896 ready_cnt.at_put(m->_idx, m_cnt);
897 if( m_cnt == 0 )
898 worklist.push(m);
899 }
900
901 }
902
903 // Act as if the call defines the Frame Pointer.
904 // Certainly the FP is alive and well after the call.
905 regs.Insert(_matcher.c_frame_pointer());
906
907 // Set all registers killed and not already defined by the call.
908 uint r_cnt = mcall->tf()->range_cc()->cnt();
909 int op = mcall->ideal_Opcode();
910 MachProjNode *proj = new MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
911 map_node_to_block(proj, block);
912 block->insert_node(proj, node_cnt++);
913
914 // Select the right register save policy.
915 const char *save_policy = nullptr;
916 switch (op) {
917 case Op_CallRuntime:
918 case Op_CallLeaf:
919 case Op_CallLeafNoFP:
920 case Op_CallLeafVector:
921 // Calling C code so use C calling convention
922 save_policy = _matcher._c_reg_save_policy;
923 break;
924
925 case Op_CallStaticJava:
926 case Op_CallDynamicJava:
927 // Calling Java code so use Java calling convention
928 save_policy = _matcher._register_save_policy;
|