1 /* 2 * Copyright (c) 1997, 2025, 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 "gc/shared/barrierSet.hpp" 26 #include "gc/shared/c2/barrierSetC2.hpp" 27 #include "memory/allocation.inline.hpp" 28 #include "memory/resourceArea.hpp" 29 #include "oops/compressedOops.hpp" 30 #include "opto/ad.hpp" 31 #include "opto/addnode.hpp" 32 #include "opto/callnode.hpp" 33 #include "opto/idealGraphPrinter.hpp" 34 #include "opto/matcher.hpp" 35 #include "opto/memnode.hpp" 36 #include "opto/movenode.hpp" 37 #include "opto/opcodes.hpp" 38 #include "opto/regmask.hpp" 39 #include "opto/rootnode.hpp" 40 #include "opto/runtime.hpp" 41 #include "opto/type.hpp" 42 #include "opto/vectornode.hpp" 43 #include "runtime/os.inline.hpp" 44 #include "runtime/sharedRuntime.hpp" 45 #include "utilities/align.hpp" 46 47 OptoReg::Name OptoReg::c_frame_pointer; 48 49 const RegMask *Matcher::idealreg2regmask[_last_machine_leaf]; 50 RegMask Matcher::mreg2regmask[_last_Mach_Reg]; 51 RegMask Matcher::caller_save_regmask; 52 RegMask Matcher::caller_save_regmask_exclude_soe; 53 RegMask Matcher::mh_caller_save_regmask; 54 RegMask Matcher::mh_caller_save_regmask_exclude_soe; 55 RegMask Matcher::STACK_ONLY_mask; 56 RegMask Matcher::c_frame_ptr_mask; 57 const uint Matcher::_begin_rematerialize = _BEGIN_REMATERIALIZE; 58 const uint Matcher::_end_rematerialize = _END_REMATERIALIZE; 59 60 //---------------------------Matcher------------------------------------------- 61 Matcher::Matcher() 62 : PhaseTransform( Phase::Ins_Select ), 63 _states_arena(Chunk::medium_size, mtCompiler), 64 _new_nodes(C->comp_arena()), 65 _visited(&_states_arena), 66 _shared(&_states_arena), 67 _dontcare(&_states_arena), 68 _reduceOp(reduceOp), _leftOp(leftOp), _rightOp(rightOp), 69 _swallowed(swallowed), 70 _begin_inst_chain_rule(_BEGIN_INST_CHAIN_RULE), 71 _end_inst_chain_rule(_END_INST_CHAIN_RULE), 72 _must_clone(must_clone), 73 _shared_nodes(C->comp_arena()), 74 #ifndef PRODUCT 75 _old2new_map(C->comp_arena()), 76 _new2old_map(C->comp_arena()), 77 _reused(C->comp_arena()), 78 #endif // !PRODUCT 79 _allocation_started(false), 80 _ruleName(ruleName), 81 _register_save_policy(register_save_policy), 82 _c_reg_save_policy(c_reg_save_policy), 83 _register_save_type(register_save_type) { 84 C->set_matcher(this); 85 86 idealreg2spillmask [Op_RegI] = nullptr; 87 idealreg2spillmask [Op_RegN] = nullptr; 88 idealreg2spillmask [Op_RegL] = nullptr; 89 idealreg2spillmask [Op_RegF] = nullptr; 90 idealreg2spillmask [Op_RegD] = nullptr; 91 idealreg2spillmask [Op_RegP] = nullptr; 92 idealreg2spillmask [Op_VecA] = nullptr; 93 idealreg2spillmask [Op_VecS] = nullptr; 94 idealreg2spillmask [Op_VecD] = nullptr; 95 idealreg2spillmask [Op_VecX] = nullptr; 96 idealreg2spillmask [Op_VecY] = nullptr; 97 idealreg2spillmask [Op_VecZ] = nullptr; 98 idealreg2spillmask [Op_RegFlags] = nullptr; 99 idealreg2spillmask [Op_RegVectMask] = nullptr; 100 101 idealreg2debugmask [Op_RegI] = nullptr; 102 idealreg2debugmask [Op_RegN] = nullptr; 103 idealreg2debugmask [Op_RegL] = nullptr; 104 idealreg2debugmask [Op_RegF] = nullptr; 105 idealreg2debugmask [Op_RegD] = nullptr; 106 idealreg2debugmask [Op_RegP] = nullptr; 107 idealreg2debugmask [Op_VecA] = nullptr; 108 idealreg2debugmask [Op_VecS] = nullptr; 109 idealreg2debugmask [Op_VecD] = nullptr; 110 idealreg2debugmask [Op_VecX] = nullptr; 111 idealreg2debugmask [Op_VecY] = nullptr; 112 idealreg2debugmask [Op_VecZ] = nullptr; 113 idealreg2debugmask [Op_RegFlags] = nullptr; 114 idealreg2debugmask [Op_RegVectMask] = nullptr; 115 116 idealreg2mhdebugmask[Op_RegI] = nullptr; 117 idealreg2mhdebugmask[Op_RegN] = nullptr; 118 idealreg2mhdebugmask[Op_RegL] = nullptr; 119 idealreg2mhdebugmask[Op_RegF] = nullptr; 120 idealreg2mhdebugmask[Op_RegD] = nullptr; 121 idealreg2mhdebugmask[Op_RegP] = nullptr; 122 idealreg2mhdebugmask[Op_VecA] = nullptr; 123 idealreg2mhdebugmask[Op_VecS] = nullptr; 124 idealreg2mhdebugmask[Op_VecD] = nullptr; 125 idealreg2mhdebugmask[Op_VecX] = nullptr; 126 idealreg2mhdebugmask[Op_VecY] = nullptr; 127 idealreg2mhdebugmask[Op_VecZ] = nullptr; 128 idealreg2mhdebugmask[Op_RegFlags] = nullptr; 129 idealreg2mhdebugmask[Op_RegVectMask] = nullptr; 130 131 debug_only(_mem_node = nullptr;) // Ideal memory node consumed by mach node 132 } 133 134 //------------------------------warp_incoming_stk_arg------------------------ 135 // This warps a VMReg into an OptoReg::Name 136 OptoReg::Name Matcher::warp_incoming_stk_arg( VMReg reg ) { 137 OptoReg::Name warped; 138 if( reg->is_stack() ) { // Stack slot argument? 139 warped = OptoReg::add(_old_SP, reg->reg2stack() ); 140 warped = OptoReg::add(warped, C->out_preserve_stack_slots()); 141 if( warped >= _in_arg_limit ) 142 _in_arg_limit = OptoReg::add(warped, 1); // Bump max stack slot seen 143 if (!RegMask::can_represent_arg(warped)) { 144 // the compiler cannot represent this method's calling sequence 145 // Bailout. We do not have space to represent all arguments. 146 C->record_method_not_compilable("unsupported incoming calling sequence"); 147 return OptoReg::Bad; 148 } 149 return warped; 150 } 151 return OptoReg::as_OptoReg(reg); 152 } 153 154 //---------------------------compute_old_SP------------------------------------ 155 OptoReg::Name Compile::compute_old_SP() { 156 int fixed = fixed_slots(); 157 int preserve = in_preserve_stack_slots(); 158 return OptoReg::stack2reg(align_up(fixed + preserve, (int)Matcher::stack_alignment_in_slots())); 159 } 160 161 162 163 #ifdef ASSERT 164 void Matcher::verify_new_nodes_only(Node* xroot) { 165 // Make sure that the new graph only references new nodes 166 ResourceMark rm; 167 Unique_Node_List worklist; 168 VectorSet visited; 169 worklist.push(xroot); 170 while (worklist.size() > 0) { 171 Node* n = worklist.pop(); 172 if (visited.test_set(n->_idx)) { 173 continue; 174 } 175 assert(C->node_arena()->contains(n), "dead node"); 176 for (uint j = 0; j < n->req(); j++) { 177 Node* in = n->in(j); 178 if (in != nullptr) { 179 worklist.push(in); 180 } 181 } 182 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) { 183 worklist.push(n->fast_out(j)); 184 } 185 } 186 } 187 #endif 188 189 // Array of RegMask, one per returned values (inline type instances can 190 // be returned as multiple return values, one per field) 191 RegMask* Matcher::return_values_mask(const TypeFunc* tf) { 192 const TypeTuple* range = tf->range_cc(); 193 uint cnt = range->cnt() - TypeFunc::Parms; 194 if (cnt == 0) { 195 return nullptr; 196 } 197 RegMask* mask = NEW_RESOURCE_ARRAY(RegMask, cnt); 198 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, cnt); 199 VMRegPair* vm_parm_regs = NEW_RESOURCE_ARRAY(VMRegPair, cnt); 200 for (uint i = 0; i < cnt; i++) { 201 sig_bt[i] = range->field_at(i+TypeFunc::Parms)->basic_type(); 202 } 203 204 int regs = SharedRuntime::java_return_convention(sig_bt, vm_parm_regs, cnt); 205 if (regs <= 0) { 206 // We ran out of registers to store the IsInit information for a nullable inline type return. 207 // Since it is only set in the 'call_epilog', we can simply put it on the stack. 208 assert(tf->returns_inline_type_as_fields(), "should have been tested during graph construction"); 209 // TODO 8284443 Can we teach the register allocator to reserve a stack slot instead? 210 // mask[--cnt] = STACK_ONLY_mask does not work (test with -XX:+StressGCM) 211 int slot = C->fixed_slots() - 2; 212 if (C->needs_stack_repair()) { 213 slot -= 2; // Account for stack increment value 214 } 215 mask[--cnt].Clear(); 216 mask[cnt].Insert(OptoReg::stack2reg(slot)); 217 } 218 for (uint i = 0; i < cnt; i++) { 219 mask[i].Clear(); 220 221 OptoReg::Name reg1 = OptoReg::as_OptoReg(vm_parm_regs[i].first()); 222 if (OptoReg::is_valid(reg1)) { 223 mask[i].Insert(reg1); 224 } 225 OptoReg::Name reg2 = OptoReg::as_OptoReg(vm_parm_regs[i].second()); 226 if (OptoReg::is_valid(reg2)) { 227 mask[i].Insert(reg2); 228 } 229 } 230 231 return mask; 232 } 233 234 //---------------------------match--------------------------------------------- 235 void Matcher::match( ) { 236 if( MaxLabelRootDepth < 100 ) { // Too small? 237 assert(false, "invalid MaxLabelRootDepth, increase it to 100 minimum"); 238 MaxLabelRootDepth = 100; 239 } 240 // One-time initialization of some register masks. 241 init_spill_mask( C->root()->in(1) ); 242 if (C->failing()) { 243 return; 244 } 245 _return_addr_mask = return_addr(); 246 #ifdef _LP64 247 // Pointers take 2 slots in 64-bit land 248 _return_addr_mask.Insert(OptoReg::add(return_addr(),1)); 249 #endif 250 251 // Map Java-signature return types into return register-value 252 // machine registers. 253 _return_values_mask = return_values_mask(C->tf()); 254 255 // --------------- 256 // Frame Layout 257 258 // Need the method signature to determine the incoming argument types, 259 // because the types determine which registers the incoming arguments are 260 // in, and this affects the matched code. 261 const TypeTuple *domain = C->tf()->domain_cc(); 262 uint argcnt = domain->cnt() - TypeFunc::Parms; 263 BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, argcnt ); 264 VMRegPair *vm_parm_regs = NEW_RESOURCE_ARRAY( VMRegPair, argcnt ); 265 _parm_regs = NEW_RESOURCE_ARRAY( OptoRegPair, argcnt ); 266 _calling_convention_mask = NEW_RESOURCE_ARRAY( RegMask, argcnt ); 267 uint i; 268 for( i = 0; i<argcnt; i++ ) { 269 sig_bt[i] = domain->field_at(i+TypeFunc::Parms)->basic_type(); 270 } 271 272 // Pass array of ideal registers and length to USER code (from the AD file) 273 // that will convert this to an array of register numbers. 274 const StartNode *start = C->start(); 275 start->calling_convention( sig_bt, vm_parm_regs, argcnt ); 276 #ifdef ASSERT 277 // Sanity check users' calling convention. Real handy while trying to 278 // get the initial port correct. 279 { for (uint i = 0; i<argcnt; i++) { 280 if( !vm_parm_regs[i].first()->is_valid() && !vm_parm_regs[i].second()->is_valid() ) { 281 assert(domain->field_at(i+TypeFunc::Parms)==Type::HALF, "only allowed on halve" ); 282 _parm_regs[i].set_bad(); 283 continue; 284 } 285 VMReg parm_reg = vm_parm_regs[i].first(); 286 assert(parm_reg->is_valid(), "invalid arg?"); 287 if (parm_reg->is_reg()) { 288 OptoReg::Name opto_parm_reg = OptoReg::as_OptoReg(parm_reg); 289 assert(can_be_java_arg(opto_parm_reg) || 290 C->stub_function() == CAST_FROM_FN_PTR(address, OptoRuntime::rethrow_C) || 291 opto_parm_reg == inline_cache_reg(), 292 "parameters in register must be preserved by runtime stubs"); 293 } 294 for (uint j = 0; j < i; j++) { 295 assert(parm_reg != vm_parm_regs[j].first(), 296 "calling conv. must produce distinct regs"); 297 } 298 } 299 } 300 #endif 301 302 // Do some initial frame layout. 303 304 // Compute the old incoming SP (may be called FP) as 305 // OptoReg::stack0() + locks + in_preserve_stack_slots + pad2. 306 _old_SP = C->compute_old_SP(); 307 assert( is_even(_old_SP), "must be even" ); 308 309 // Compute highest incoming stack argument as 310 // _old_SP + out_preserve_stack_slots + incoming argument size. 311 _in_arg_limit = OptoReg::add(_old_SP, C->out_preserve_stack_slots()); 312 assert( is_even(_in_arg_limit), "out_preserve must be even" ); 313 for( i = 0; i < argcnt; i++ ) { 314 // Permit args to have no register 315 _calling_convention_mask[i].Clear(); 316 if( !vm_parm_regs[i].first()->is_valid() && !vm_parm_regs[i].second()->is_valid() ) { 317 _parm_regs[i].set_bad(); 318 continue; 319 } 320 // calling_convention returns stack arguments as a count of 321 // slots beyond OptoReg::stack0()/VMRegImpl::stack0. We need to convert this to 322 // the allocators point of view, taking into account all the 323 // preserve area, locks & pad2. 324 325 OptoReg::Name reg1 = warp_incoming_stk_arg(vm_parm_regs[i].first()); 326 if (C->failing()) { 327 return; 328 } 329 if( OptoReg::is_valid(reg1)) 330 _calling_convention_mask[i].Insert(reg1); 331 332 OptoReg::Name reg2 = warp_incoming_stk_arg(vm_parm_regs[i].second()); 333 if (C->failing()) { 334 return; 335 } 336 if( OptoReg::is_valid(reg2)) 337 _calling_convention_mask[i].Insert(reg2); 338 339 // Saved biased stack-slot register number 340 _parm_regs[i].set_pair(reg2, reg1); 341 } 342 343 // Finally, make sure the incoming arguments take up an even number of 344 // words, in case the arguments or locals need to contain doubleword stack 345 // slots. The rest of the system assumes that stack slot pairs (in 346 // particular, in the spill area) which look aligned will in fact be 347 // aligned relative to the stack pointer in the target machine. Double 348 // stack slots will always be allocated aligned. 349 _new_SP = OptoReg::Name(align_up(_in_arg_limit, (int)RegMask::SlotsPerLong)); 350 351 // Compute highest outgoing stack argument as 352 // _new_SP + out_preserve_stack_slots + max(outgoing argument size). 353 _out_arg_limit = OptoReg::add(_new_SP, C->out_preserve_stack_slots()); 354 assert( is_even(_out_arg_limit), "out_preserve must be even" ); 355 356 if (!RegMask::can_represent_arg(OptoReg::add(_out_arg_limit,-1))) { 357 // the compiler cannot represent this method's calling sequence 358 // Bailout. We do not have space to represent all arguments. 359 C->record_method_not_compilable("must be able to represent all call arguments in reg mask"); 360 } 361 362 if (C->failing()) return; // bailed out on incoming arg failure 363 364 // --------------- 365 // Collect roots of matcher trees. Every node for which 366 // _shared[_idx] is cleared is guaranteed to not be shared, and thus 367 // can be a valid interior of some tree. 368 find_shared( C->root() ); 369 find_shared( C->top() ); 370 371 C->print_method(PHASE_BEFORE_MATCHING, 1); 372 373 // Create new ideal node ConP #null even if it does exist in old space 374 // to avoid false sharing if the corresponding mach node is not used. 375 // The corresponding mach node is only used in rare cases for derived 376 // pointers. 377 Node* new_ideal_null = ConNode::make(TypePtr::NULL_PTR); 378 379 // Swap out to old-space; emptying new-space 380 Arena* old = C->swap_old_and_new(); 381 382 // Save debug and profile information for nodes in old space: 383 _old_node_note_array = C->node_note_array(); 384 if (_old_node_note_array != nullptr) { 385 C->set_node_note_array(new(C->comp_arena()) GrowableArray<Node_Notes*> 386 (C->comp_arena(), _old_node_note_array->length(), 387 0, nullptr)); 388 } 389 390 // Pre-size the new_node table to avoid the need for range checks. 391 grow_new_node_array(C->unique()); 392 393 // Reset node counter so MachNodes start with _idx at 0 394 int live_nodes = C->live_nodes(); 395 C->set_unique(0); 396 C->reset_dead_node_list(); 397 398 // Recursively match trees from old space into new space. 399 // Correct leaves of new-space Nodes; they point to old-space. 400 _visited.clear(); 401 Node* const n = xform(C->top(), live_nodes); 402 if (C->failing()) return; 403 C->set_cached_top_node(n); 404 if (!C->failing()) { 405 Node* xroot = xform( C->root(), 1 ); 406 if (C->failing()) return; 407 if (xroot == nullptr) { 408 Matcher::soft_match_failure(); // recursive matching process failed 409 assert(false, "instruction match failed"); 410 C->record_method_not_compilable("instruction match failed"); 411 } else { 412 // During matching shared constants were attached to C->root() 413 // because xroot wasn't available yet, so transfer the uses to 414 // the xroot. 415 for( DUIterator_Fast jmax, j = C->root()->fast_outs(jmax); j < jmax; j++ ) { 416 Node* n = C->root()->fast_out(j); 417 if (C->node_arena()->contains(n)) { 418 assert(n->in(0) == C->root(), "should be control user"); 419 n->set_req(0, xroot); 420 --j; 421 --jmax; 422 } 423 } 424 425 // Generate new mach node for ConP #null 426 assert(new_ideal_null != nullptr, "sanity"); 427 _mach_null = match_tree(new_ideal_null); 428 // Don't set control, it will confuse GCM since there are no uses. 429 // The control will be set when this node is used first time 430 // in find_base_for_derived(). 431 assert(_mach_null != nullptr || C->failure_is_artificial(), ""); // bailouts are handled below. 432 433 C->set_root(xroot->is_Root() ? xroot->as_Root() : nullptr); 434 435 #ifdef ASSERT 436 verify_new_nodes_only(xroot); 437 #endif 438 } 439 } 440 if (C->top() == nullptr || C->root() == nullptr) { 441 // New graph lost. This is due to a compilation failure we encountered earlier. 442 stringStream ss; 443 if (C->failure_reason() != nullptr) { 444 ss.print("graph lost: %s", C->failure_reason()); 445 } else { 446 assert(C->failure_reason() != nullptr, "graph lost: reason unknown"); 447 ss.print("graph lost: reason unknown"); 448 } 449 C->record_method_not_compilable(ss.as_string() DEBUG_ONLY(COMMA true)); 450 } 451 if (C->failing()) { 452 // delete old; 453 old->destruct_contents(); 454 return; 455 } 456 assert( C->top(), "" ); 457 assert( C->root(), "" ); 458 validate_null_checks(); 459 460 // Now smoke old-space 461 NOT_DEBUG( old->destruct_contents() ); 462 463 // ------------------------ 464 // Set up save-on-entry registers. 465 Fixup_Save_On_Entry( ); 466 467 { // Cleanup mach IR after selection phase is over. 468 Compile::TracePhase tp(_t_postselect_cleanup); 469 do_postselect_cleanup(); 470 if (C->failing()) return; 471 assert(verify_after_postselect_cleanup(), ""); 472 } 473 } 474 475 //------------------------------Fixup_Save_On_Entry---------------------------- 476 // The stated purpose of this routine is to take care of save-on-entry 477 // registers. However, the overall goal of the Match phase is to convert into 478 // machine-specific instructions which have RegMasks to guide allocation. 479 // So what this procedure really does is put a valid RegMask on each input 480 // to the machine-specific variations of all Return, TailCall and Halt 481 // instructions. It also adds edgs to define the save-on-entry values (and of 482 // course gives them a mask). 483 484 static RegMask *init_input_masks( uint size, RegMask &ret_adr, RegMask &fp ) { 485 RegMask *rms = NEW_RESOURCE_ARRAY( RegMask, size ); 486 // Do all the pre-defined register masks 487 rms[TypeFunc::Control ] = RegMask::Empty; 488 rms[TypeFunc::I_O ] = RegMask::Empty; 489 rms[TypeFunc::Memory ] = RegMask::Empty; 490 rms[TypeFunc::ReturnAdr] = ret_adr; 491 rms[TypeFunc::FramePtr ] = fp; 492 return rms; 493 } 494 495 int Matcher::scalable_predicate_reg_slots() { 496 assert(Matcher::has_predicated_vectors() && Matcher::supports_scalable_vector(), 497 "scalable predicate vector should be supported"); 498 int vector_reg_bit_size = Matcher::scalable_vector_reg_size(T_BYTE) << LogBitsPerByte; 499 // We assume each predicate register is one-eighth of the size of 500 // scalable vector register, one mask bit per vector byte. 501 int predicate_reg_bit_size = vector_reg_bit_size >> 3; 502 // Compute number of slots which is required when scalable predicate 503 // register is spilled. E.g. if scalable vector register is 640 bits, 504 // predicate register is 80 bits, which is 2.5 * slots. 505 // We will round up the slot number to power of 2, which is required 506 // by find_first_set(). 507 int slots = predicate_reg_bit_size & (BitsPerInt - 1) 508 ? (predicate_reg_bit_size >> LogBitsPerInt) + 1 509 : predicate_reg_bit_size >> LogBitsPerInt; 510 return round_up_power_of_2(slots); 511 } 512 513 #define NOF_STACK_MASKS (3*13) 514 515 // Create the initial stack mask used by values spilling to the stack. 516 // Disallow any debug info in outgoing argument areas by setting the 517 // initial mask accordingly. 518 void Matcher::init_first_stack_mask() { 519 520 // Allocate storage for spill masks as masks for the appropriate load type. 521 RegMask *rms = (RegMask*)C->comp_arena()->AmallocWords(sizeof(RegMask) * NOF_STACK_MASKS); 522 523 // Initialize empty placeholder masks into the newly allocated arena 524 for (int i = 0; i < NOF_STACK_MASKS; i++) { 525 new (rms + i) RegMask(); 526 } 527 528 idealreg2spillmask [Op_RegN] = &rms[0]; 529 idealreg2spillmask [Op_RegI] = &rms[1]; 530 idealreg2spillmask [Op_RegL] = &rms[2]; 531 idealreg2spillmask [Op_RegF] = &rms[3]; 532 idealreg2spillmask [Op_RegD] = &rms[4]; 533 idealreg2spillmask [Op_RegP] = &rms[5]; 534 535 idealreg2debugmask [Op_RegN] = &rms[6]; 536 idealreg2debugmask [Op_RegI] = &rms[7]; 537 idealreg2debugmask [Op_RegL] = &rms[8]; 538 idealreg2debugmask [Op_RegF] = &rms[9]; 539 idealreg2debugmask [Op_RegD] = &rms[10]; 540 idealreg2debugmask [Op_RegP] = &rms[11]; 541 542 idealreg2mhdebugmask[Op_RegN] = &rms[12]; 543 idealreg2mhdebugmask[Op_RegI] = &rms[13]; 544 idealreg2mhdebugmask[Op_RegL] = &rms[14]; 545 idealreg2mhdebugmask[Op_RegF] = &rms[15]; 546 idealreg2mhdebugmask[Op_RegD] = &rms[16]; 547 idealreg2mhdebugmask[Op_RegP] = &rms[17]; 548 549 idealreg2spillmask [Op_VecA] = &rms[18]; 550 idealreg2spillmask [Op_VecS] = &rms[19]; 551 idealreg2spillmask [Op_VecD] = &rms[20]; 552 idealreg2spillmask [Op_VecX] = &rms[21]; 553 idealreg2spillmask [Op_VecY] = &rms[22]; 554 idealreg2spillmask [Op_VecZ] = &rms[23]; 555 556 idealreg2debugmask [Op_VecA] = &rms[24]; 557 idealreg2debugmask [Op_VecS] = &rms[25]; 558 idealreg2debugmask [Op_VecD] = &rms[26]; 559 idealreg2debugmask [Op_VecX] = &rms[27]; 560 idealreg2debugmask [Op_VecY] = &rms[28]; 561 idealreg2debugmask [Op_VecZ] = &rms[29]; 562 563 idealreg2mhdebugmask[Op_VecA] = &rms[30]; 564 idealreg2mhdebugmask[Op_VecS] = &rms[31]; 565 idealreg2mhdebugmask[Op_VecD] = &rms[32]; 566 idealreg2mhdebugmask[Op_VecX] = &rms[33]; 567 idealreg2mhdebugmask[Op_VecY] = &rms[34]; 568 idealreg2mhdebugmask[Op_VecZ] = &rms[35]; 569 570 idealreg2spillmask [Op_RegVectMask] = &rms[36]; 571 idealreg2debugmask [Op_RegVectMask] = &rms[37]; 572 idealreg2mhdebugmask[Op_RegVectMask] = &rms[38]; 573 574 OptoReg::Name i; 575 576 // At first, start with the empty mask 577 C->FIRST_STACK_mask().Clear(); 578 579 // Add in the incoming argument area 580 OptoReg::Name init_in = OptoReg::add(_old_SP, C->out_preserve_stack_slots()); 581 for (i = init_in; i < _in_arg_limit; i = OptoReg::add(i,1)) { 582 C->FIRST_STACK_mask().Insert(i); 583 } 584 585 // Add in all bits past the outgoing argument area 586 guarantee(RegMask::can_represent_arg(OptoReg::add(_out_arg_limit,-1)), 587 "must be able to represent all call arguments in reg mask"); 588 OptoReg::Name init = _out_arg_limit; 589 for (i = init; RegMask::can_represent(i); i = OptoReg::add(i,1)) { 590 C->FIRST_STACK_mask().Insert(i); 591 } 592 // Finally, set the "infinite stack" bit. 593 C->FIRST_STACK_mask().set_AllStack(); 594 595 // Make spill masks. Registers for their class, plus FIRST_STACK_mask. 596 RegMask aligned_stack_mask = C->FIRST_STACK_mask(); 597 // Keep spill masks aligned. 598 aligned_stack_mask.clear_to_pairs(); 599 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack"); 600 RegMask scalable_stack_mask = aligned_stack_mask; 601 602 *idealreg2spillmask[Op_RegP] = *idealreg2regmask[Op_RegP]; 603 #ifdef _LP64 604 *idealreg2spillmask[Op_RegN] = *idealreg2regmask[Op_RegN]; 605 idealreg2spillmask[Op_RegN]->OR(C->FIRST_STACK_mask()); 606 idealreg2spillmask[Op_RegP]->OR(aligned_stack_mask); 607 #else 608 idealreg2spillmask[Op_RegP]->OR(C->FIRST_STACK_mask()); 609 #endif 610 *idealreg2spillmask[Op_RegI] = *idealreg2regmask[Op_RegI]; 611 idealreg2spillmask[Op_RegI]->OR(C->FIRST_STACK_mask()); 612 *idealreg2spillmask[Op_RegL] = *idealreg2regmask[Op_RegL]; 613 idealreg2spillmask[Op_RegL]->OR(aligned_stack_mask); 614 *idealreg2spillmask[Op_RegF] = *idealreg2regmask[Op_RegF]; 615 idealreg2spillmask[Op_RegF]->OR(C->FIRST_STACK_mask()); 616 *idealreg2spillmask[Op_RegD] = *idealreg2regmask[Op_RegD]; 617 idealreg2spillmask[Op_RegD]->OR(aligned_stack_mask); 618 619 if (Matcher::has_predicated_vectors()) { 620 *idealreg2spillmask[Op_RegVectMask] = *idealreg2regmask[Op_RegVectMask]; 621 idealreg2spillmask[Op_RegVectMask]->OR(aligned_stack_mask); 622 } else { 623 *idealreg2spillmask[Op_RegVectMask] = RegMask::Empty; 624 } 625 626 if (Matcher::vector_size_supported(T_BYTE,4)) { 627 *idealreg2spillmask[Op_VecS] = *idealreg2regmask[Op_VecS]; 628 idealreg2spillmask[Op_VecS]->OR(C->FIRST_STACK_mask()); 629 } else { 630 *idealreg2spillmask[Op_VecS] = RegMask::Empty; 631 } 632 633 if (Matcher::vector_size_supported(T_FLOAT,2)) { 634 // For VecD we need dual alignment and 8 bytes (2 slots) for spills. 635 // RA guarantees such alignment since it is needed for Double and Long values. 636 *idealreg2spillmask[Op_VecD] = *idealreg2regmask[Op_VecD]; 637 idealreg2spillmask[Op_VecD]->OR(aligned_stack_mask); 638 } else { 639 *idealreg2spillmask[Op_VecD] = RegMask::Empty; 640 } 641 642 if (Matcher::vector_size_supported(T_FLOAT,4)) { 643 // For VecX we need quadro alignment and 16 bytes (4 slots) for spills. 644 // 645 // RA can use input arguments stack slots for spills but until RA 646 // we don't know frame size and offset of input arg stack slots. 647 // 648 // Exclude last input arg stack slots to avoid spilling vectors there 649 // otherwise vector spills could stomp over stack slots in caller frame. 650 OptoReg::Name in = OptoReg::add(_in_arg_limit, -1); 651 for (int k = 1; (in >= init_in) && (k < RegMask::SlotsPerVecX); k++) { 652 aligned_stack_mask.Remove(in); 653 in = OptoReg::add(in, -1); 654 } 655 aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecX); 656 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack"); 657 *idealreg2spillmask[Op_VecX] = *idealreg2regmask[Op_VecX]; 658 idealreg2spillmask[Op_VecX]->OR(aligned_stack_mask); 659 } else { 660 *idealreg2spillmask[Op_VecX] = RegMask::Empty; 661 } 662 663 if (Matcher::vector_size_supported(T_FLOAT,8)) { 664 // For VecY we need octo alignment and 32 bytes (8 slots) for spills. 665 OptoReg::Name in = OptoReg::add(_in_arg_limit, -1); 666 for (int k = 1; (in >= init_in) && (k < RegMask::SlotsPerVecY); k++) { 667 aligned_stack_mask.Remove(in); 668 in = OptoReg::add(in, -1); 669 } 670 aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecY); 671 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack"); 672 *idealreg2spillmask[Op_VecY] = *idealreg2regmask[Op_VecY]; 673 idealreg2spillmask[Op_VecY]->OR(aligned_stack_mask); 674 } else { 675 *idealreg2spillmask[Op_VecY] = RegMask::Empty; 676 } 677 678 if (Matcher::vector_size_supported(T_FLOAT,16)) { 679 // For VecZ we need enough alignment and 64 bytes (16 slots) for spills. 680 OptoReg::Name in = OptoReg::add(_in_arg_limit, -1); 681 for (int k = 1; (in >= init_in) && (k < RegMask::SlotsPerVecZ); k++) { 682 aligned_stack_mask.Remove(in); 683 in = OptoReg::add(in, -1); 684 } 685 aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecZ); 686 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack"); 687 *idealreg2spillmask[Op_VecZ] = *idealreg2regmask[Op_VecZ]; 688 idealreg2spillmask[Op_VecZ]->OR(aligned_stack_mask); 689 } else { 690 *idealreg2spillmask[Op_VecZ] = RegMask::Empty; 691 } 692 693 if (Matcher::supports_scalable_vector()) { 694 int k = 1; 695 OptoReg::Name in = OptoReg::add(_in_arg_limit, -1); 696 if (Matcher::has_predicated_vectors()) { 697 // Exclude last input arg stack slots to avoid spilling vector register there, 698 // otherwise RegVectMask spills could stomp over stack slots in caller frame. 699 for (; (in >= init_in) && (k < scalable_predicate_reg_slots()); k++) { 700 scalable_stack_mask.Remove(in); 701 in = OptoReg::add(in, -1); 702 } 703 704 // For RegVectMask 705 scalable_stack_mask.clear_to_sets(scalable_predicate_reg_slots()); 706 assert(scalable_stack_mask.is_AllStack(), "should be infinite stack"); 707 *idealreg2spillmask[Op_RegVectMask] = *idealreg2regmask[Op_RegVectMask]; 708 idealreg2spillmask[Op_RegVectMask]->OR(scalable_stack_mask); 709 } 710 711 // Exclude last input arg stack slots to avoid spilling vector register there, 712 // otherwise vector spills could stomp over stack slots in caller frame. 713 for (; (in >= init_in) && (k < scalable_vector_reg_size(T_FLOAT)); k++) { 714 scalable_stack_mask.Remove(in); 715 in = OptoReg::add(in, -1); 716 } 717 718 // For VecA 719 scalable_stack_mask.clear_to_sets(RegMask::SlotsPerVecA); 720 assert(scalable_stack_mask.is_AllStack(), "should be infinite stack"); 721 *idealreg2spillmask[Op_VecA] = *idealreg2regmask[Op_VecA]; 722 idealreg2spillmask[Op_VecA]->OR(scalable_stack_mask); 723 } else { 724 *idealreg2spillmask[Op_VecA] = RegMask::Empty; 725 } 726 727 if (UseFPUForSpilling) { 728 // This mask logic assumes that the spill operations are 729 // symmetric and that the registers involved are the same size. 730 // On sparc for instance we may have to use 64 bit moves will 731 // kill 2 registers when used with F0-F31. 732 idealreg2spillmask[Op_RegI]->OR(*idealreg2regmask[Op_RegF]); 733 idealreg2spillmask[Op_RegF]->OR(*idealreg2regmask[Op_RegI]); 734 #ifdef _LP64 735 idealreg2spillmask[Op_RegN]->OR(*idealreg2regmask[Op_RegF]); 736 idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]); 737 idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]); 738 idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegD]); 739 #else 740 idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegF]); 741 #ifdef ARM 742 // ARM has support for moving 64bit values between a pair of 743 // integer registers and a double register 744 idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]); 745 idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]); 746 #endif 747 #endif 748 } 749 750 // Make up debug masks. Any spill slot plus callee-save (SOE) registers. 751 // Caller-save (SOC, AS) registers are assumed to be trashable by the various 752 // inline-cache fixup routines. 753 *idealreg2debugmask [Op_RegN] = *idealreg2spillmask[Op_RegN]; 754 *idealreg2debugmask [Op_RegI] = *idealreg2spillmask[Op_RegI]; 755 *idealreg2debugmask [Op_RegL] = *idealreg2spillmask[Op_RegL]; 756 *idealreg2debugmask [Op_RegF] = *idealreg2spillmask[Op_RegF]; 757 *idealreg2debugmask [Op_RegD] = *idealreg2spillmask[Op_RegD]; 758 *idealreg2debugmask [Op_RegP] = *idealreg2spillmask[Op_RegP]; 759 *idealreg2debugmask [Op_RegVectMask] = *idealreg2spillmask[Op_RegVectMask]; 760 761 *idealreg2debugmask [Op_VecA] = *idealreg2spillmask[Op_VecA]; 762 *idealreg2debugmask [Op_VecS] = *idealreg2spillmask[Op_VecS]; 763 *idealreg2debugmask [Op_VecD] = *idealreg2spillmask[Op_VecD]; 764 *idealreg2debugmask [Op_VecX] = *idealreg2spillmask[Op_VecX]; 765 *idealreg2debugmask [Op_VecY] = *idealreg2spillmask[Op_VecY]; 766 *idealreg2debugmask [Op_VecZ] = *idealreg2spillmask[Op_VecZ]; 767 768 *idealreg2mhdebugmask[Op_RegN] = *idealreg2spillmask[Op_RegN]; 769 *idealreg2mhdebugmask[Op_RegI] = *idealreg2spillmask[Op_RegI]; 770 *idealreg2mhdebugmask[Op_RegL] = *idealreg2spillmask[Op_RegL]; 771 *idealreg2mhdebugmask[Op_RegF] = *idealreg2spillmask[Op_RegF]; 772 *idealreg2mhdebugmask[Op_RegD] = *idealreg2spillmask[Op_RegD]; 773 *idealreg2mhdebugmask[Op_RegP] = *idealreg2spillmask[Op_RegP]; 774 *idealreg2mhdebugmask[Op_RegVectMask] = *idealreg2spillmask[Op_RegVectMask]; 775 776 *idealreg2mhdebugmask[Op_VecA] = *idealreg2spillmask[Op_VecA]; 777 *idealreg2mhdebugmask[Op_VecS] = *idealreg2spillmask[Op_VecS]; 778 *idealreg2mhdebugmask[Op_VecD] = *idealreg2spillmask[Op_VecD]; 779 *idealreg2mhdebugmask[Op_VecX] = *idealreg2spillmask[Op_VecX]; 780 *idealreg2mhdebugmask[Op_VecY] = *idealreg2spillmask[Op_VecY]; 781 *idealreg2mhdebugmask[Op_VecZ] = *idealreg2spillmask[Op_VecZ]; 782 783 // Prevent stub compilations from attempting to reference 784 // callee-saved (SOE) registers from debug info 785 bool exclude_soe = !Compile::current()->is_method_compilation(); 786 RegMask* caller_save_mask = exclude_soe ? &caller_save_regmask_exclude_soe : &caller_save_regmask; 787 RegMask* mh_caller_save_mask = exclude_soe ? &mh_caller_save_regmask_exclude_soe : &mh_caller_save_regmask; 788 789 idealreg2debugmask[Op_RegN]->SUBTRACT(*caller_save_mask); 790 idealreg2debugmask[Op_RegI]->SUBTRACT(*caller_save_mask); 791 idealreg2debugmask[Op_RegL]->SUBTRACT(*caller_save_mask); 792 idealreg2debugmask[Op_RegF]->SUBTRACT(*caller_save_mask); 793 idealreg2debugmask[Op_RegD]->SUBTRACT(*caller_save_mask); 794 idealreg2debugmask[Op_RegP]->SUBTRACT(*caller_save_mask); 795 idealreg2debugmask[Op_RegVectMask]->SUBTRACT(*caller_save_mask); 796 797 idealreg2debugmask[Op_VecA]->SUBTRACT(*caller_save_mask); 798 idealreg2debugmask[Op_VecS]->SUBTRACT(*caller_save_mask); 799 idealreg2debugmask[Op_VecD]->SUBTRACT(*caller_save_mask); 800 idealreg2debugmask[Op_VecX]->SUBTRACT(*caller_save_mask); 801 idealreg2debugmask[Op_VecY]->SUBTRACT(*caller_save_mask); 802 idealreg2debugmask[Op_VecZ]->SUBTRACT(*caller_save_mask); 803 804 idealreg2mhdebugmask[Op_RegN]->SUBTRACT(*mh_caller_save_mask); 805 idealreg2mhdebugmask[Op_RegI]->SUBTRACT(*mh_caller_save_mask); 806 idealreg2mhdebugmask[Op_RegL]->SUBTRACT(*mh_caller_save_mask); 807 idealreg2mhdebugmask[Op_RegF]->SUBTRACT(*mh_caller_save_mask); 808 idealreg2mhdebugmask[Op_RegD]->SUBTRACT(*mh_caller_save_mask); 809 idealreg2mhdebugmask[Op_RegP]->SUBTRACT(*mh_caller_save_mask); 810 idealreg2mhdebugmask[Op_RegVectMask]->SUBTRACT(*mh_caller_save_mask); 811 812 idealreg2mhdebugmask[Op_VecA]->SUBTRACT(*mh_caller_save_mask); 813 idealreg2mhdebugmask[Op_VecS]->SUBTRACT(*mh_caller_save_mask); 814 idealreg2mhdebugmask[Op_VecD]->SUBTRACT(*mh_caller_save_mask); 815 idealreg2mhdebugmask[Op_VecX]->SUBTRACT(*mh_caller_save_mask); 816 idealreg2mhdebugmask[Op_VecY]->SUBTRACT(*mh_caller_save_mask); 817 idealreg2mhdebugmask[Op_VecZ]->SUBTRACT(*mh_caller_save_mask); 818 } 819 820 //---------------------------is_save_on_entry---------------------------------- 821 bool Matcher::is_save_on_entry(int reg) { 822 return 823 _register_save_policy[reg] == 'E' || 824 _register_save_policy[reg] == 'A'; // Save-on-entry register? 825 } 826 827 //---------------------------Fixup_Save_On_Entry------------------------------- 828 void Matcher::Fixup_Save_On_Entry( ) { 829 init_first_stack_mask(); 830 831 Node *root = C->root(); // Short name for root 832 // Count number of save-on-entry registers. 833 uint soe_cnt = number_of_saved_registers(); 834 uint i; 835 836 // Find the procedure Start Node 837 StartNode *start = C->start(); 838 assert( start, "Expect a start node" ); 839 840 // Input RegMask array shared by all Returns. 841 // The type for doubles and longs has a count of 2, but 842 // there is only 1 returned value 843 uint ret_edge_cnt = C->tf()->range_cc()->cnt(); 844 RegMask *ret_rms = init_input_masks( ret_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask ); 845 for (i = TypeFunc::Parms; i < ret_edge_cnt; i++) { 846 ret_rms[i] = _return_values_mask[i-TypeFunc::Parms]; 847 } 848 849 // Input RegMask array shared by all ForwardExceptions 850 uint forw_exc_edge_cnt = TypeFunc::Parms; 851 RegMask* forw_exc_rms = init_input_masks( forw_exc_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask ); 852 853 // Input RegMask array shared by all Rethrows. 854 uint reth_edge_cnt = TypeFunc::Parms+1; 855 RegMask *reth_rms = init_input_masks( reth_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask ); 856 // Rethrow takes exception oop only, but in the argument 0 slot. 857 OptoReg::Name reg = find_receiver(); 858 if (reg >= 0) { 859 reth_rms[TypeFunc::Parms] = mreg2regmask[reg]; 860 #ifdef _LP64 861 // Need two slots for ptrs in 64-bit land 862 reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(reg), 1)); 863 #endif 864 } 865 866 // Input RegMask array shared by all TailCalls 867 uint tail_call_edge_cnt = TypeFunc::Parms+2; 868 RegMask *tail_call_rms = init_input_masks( tail_call_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask ); 869 870 // Input RegMask array shared by all TailJumps 871 uint tail_jump_edge_cnt = TypeFunc::Parms+2; 872 RegMask *tail_jump_rms = init_input_masks( tail_jump_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask ); 873 874 // TailCalls have 2 returned values (target & moop), whose masks come 875 // from the usual MachNode/MachOper mechanism. Find a sample 876 // TailCall to extract these masks and put the correct masks into 877 // the tail_call_rms array. 878 for( i=1; i < root->req(); i++ ) { 879 MachReturnNode *m = root->in(i)->as_MachReturn(); 880 if( m->ideal_Opcode() == Op_TailCall ) { 881 tail_call_rms[TypeFunc::Parms+0] = m->MachNode::in_RegMask(TypeFunc::Parms+0); 882 tail_call_rms[TypeFunc::Parms+1] = m->MachNode::in_RegMask(TypeFunc::Parms+1); 883 break; 884 } 885 } 886 887 // TailJumps have 2 returned values (target & ex_oop), whose masks come 888 // from the usual MachNode/MachOper mechanism. Find a sample 889 // TailJump to extract these masks and put the correct masks into 890 // the tail_jump_rms array. 891 for( i=1; i < root->req(); i++ ) { 892 MachReturnNode *m = root->in(i)->as_MachReturn(); 893 if( m->ideal_Opcode() == Op_TailJump ) { 894 tail_jump_rms[TypeFunc::Parms+0] = m->MachNode::in_RegMask(TypeFunc::Parms+0); 895 tail_jump_rms[TypeFunc::Parms+1] = m->MachNode::in_RegMask(TypeFunc::Parms+1); 896 break; 897 } 898 } 899 900 // Input RegMask array shared by all Halts 901 uint halt_edge_cnt = TypeFunc::Parms; 902 RegMask *halt_rms = init_input_masks( halt_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask ); 903 904 // Capture the return input masks into each exit flavor 905 for( i=1; i < root->req(); i++ ) { 906 MachReturnNode *exit = root->in(i)->as_MachReturn(); 907 switch( exit->ideal_Opcode() ) { 908 case Op_Return : exit->_in_rms = ret_rms; break; 909 case Op_Rethrow : exit->_in_rms = reth_rms; break; 910 case Op_TailCall : exit->_in_rms = tail_call_rms; break; 911 case Op_TailJump : exit->_in_rms = tail_jump_rms; break; 912 case Op_ForwardException: exit->_in_rms = forw_exc_rms; break; 913 case Op_Halt : exit->_in_rms = halt_rms; break; 914 default : ShouldNotReachHere(); 915 } 916 } 917 918 // Next unused projection number from Start. 919 int proj_cnt = C->tf()->domain_cc()->cnt(); 920 921 // Do all the save-on-entry registers. Make projections from Start for 922 // them, and give them a use at the exit points. To the allocator, they 923 // look like incoming register arguments. 924 for( i = 0; i < _last_Mach_Reg; i++ ) { 925 if( is_save_on_entry(i) ) { 926 927 // Add the save-on-entry to the mask array 928 ret_rms [ ret_edge_cnt] = mreg2regmask[i]; 929 reth_rms [ reth_edge_cnt] = mreg2regmask[i]; 930 tail_call_rms[tail_call_edge_cnt] = mreg2regmask[i]; 931 tail_jump_rms[tail_jump_edge_cnt] = mreg2regmask[i]; 932 forw_exc_rms [ forw_exc_edge_cnt] = mreg2regmask[i]; 933 // Halts need the SOE registers, but only in the stack as debug info. 934 // A just-prior uncommon-trap or deoptimization will use the SOE regs. 935 halt_rms [ halt_edge_cnt] = *idealreg2spillmask[_register_save_type[i]]; 936 937 Node *mproj; 938 939 // Is this a RegF low half of a RegD? Double up 2 adjacent RegF's 940 // into a single RegD. 941 if( (i&1) == 0 && 942 _register_save_type[i ] == Op_RegF && 943 _register_save_type[i+1] == Op_RegF && 944 is_save_on_entry(i+1) ) { 945 // Add other bit for double 946 ret_rms [ ret_edge_cnt].Insert(OptoReg::Name(i+1)); 947 reth_rms [ reth_edge_cnt].Insert(OptoReg::Name(i+1)); 948 tail_call_rms[tail_call_edge_cnt].Insert(OptoReg::Name(i+1)); 949 tail_jump_rms[tail_jump_edge_cnt].Insert(OptoReg::Name(i+1)); 950 forw_exc_rms [ forw_exc_edge_cnt].Insert(OptoReg::Name(i+1)); 951 halt_rms [ halt_edge_cnt].Insert(OptoReg::Name(i+1)); 952 mproj = new MachProjNode( start, proj_cnt, ret_rms[ret_edge_cnt], Op_RegD ); 953 proj_cnt += 2; // Skip 2 for doubles 954 } 955 else if( (i&1) == 1 && // Else check for high half of double 956 _register_save_type[i-1] == Op_RegF && 957 _register_save_type[i ] == Op_RegF && 958 is_save_on_entry(i-1) ) { 959 ret_rms [ ret_edge_cnt] = RegMask::Empty; 960 reth_rms [ reth_edge_cnt] = RegMask::Empty; 961 tail_call_rms[tail_call_edge_cnt] = RegMask::Empty; 962 tail_jump_rms[tail_jump_edge_cnt] = RegMask::Empty; 963 forw_exc_rms [ forw_exc_edge_cnt] = RegMask::Empty; 964 halt_rms [ halt_edge_cnt] = RegMask::Empty; 965 mproj = C->top(); 966 } 967 // Is this a RegI low half of a RegL? Double up 2 adjacent RegI's 968 // into a single RegL. 969 else if( (i&1) == 0 && 970 _register_save_type[i ] == Op_RegI && 971 _register_save_type[i+1] == Op_RegI && 972 is_save_on_entry(i+1) ) { 973 // Add other bit for long 974 ret_rms [ ret_edge_cnt].Insert(OptoReg::Name(i+1)); 975 reth_rms [ reth_edge_cnt].Insert(OptoReg::Name(i+1)); 976 tail_call_rms[tail_call_edge_cnt].Insert(OptoReg::Name(i+1)); 977 tail_jump_rms[tail_jump_edge_cnt].Insert(OptoReg::Name(i+1)); 978 forw_exc_rms [ forw_exc_edge_cnt].Insert(OptoReg::Name(i+1)); 979 halt_rms [ halt_edge_cnt].Insert(OptoReg::Name(i+1)); 980 mproj = new MachProjNode( start, proj_cnt, ret_rms[ret_edge_cnt], Op_RegL ); 981 proj_cnt += 2; // Skip 2 for longs 982 } 983 else if( (i&1) == 1 && // Else check for high half of long 984 _register_save_type[i-1] == Op_RegI && 985 _register_save_type[i ] == Op_RegI && 986 is_save_on_entry(i-1) ) { 987 ret_rms [ ret_edge_cnt] = RegMask::Empty; 988 reth_rms [ reth_edge_cnt] = RegMask::Empty; 989 tail_call_rms[tail_call_edge_cnt] = RegMask::Empty; 990 tail_jump_rms[tail_jump_edge_cnt] = RegMask::Empty; 991 forw_exc_rms [ forw_exc_edge_cnt] = RegMask::Empty; 992 halt_rms [ halt_edge_cnt] = RegMask::Empty; 993 mproj = C->top(); 994 } else { 995 // Make a projection for it off the Start 996 mproj = new MachProjNode( start, proj_cnt++, ret_rms[ret_edge_cnt], _register_save_type[i] ); 997 } 998 999 ret_edge_cnt ++; 1000 reth_edge_cnt ++; 1001 tail_call_edge_cnt ++; 1002 tail_jump_edge_cnt ++; 1003 forw_exc_edge_cnt++; 1004 halt_edge_cnt ++; 1005 1006 // Add a use of the SOE register to all exit paths 1007 for (uint j=1; j < root->req(); j++) { 1008 root->in(j)->add_req(mproj); 1009 } 1010 } // End of if a save-on-entry register 1011 } // End of for all machine registers 1012 } 1013 1014 //------------------------------init_spill_mask-------------------------------- 1015 void Matcher::init_spill_mask( Node *ret ) { 1016 if( idealreg2regmask[Op_RegI] ) return; // One time only init 1017 1018 OptoReg::c_frame_pointer = c_frame_pointer(); 1019 c_frame_ptr_mask = c_frame_pointer(); 1020 #ifdef _LP64 1021 // pointers are twice as big 1022 c_frame_ptr_mask.Insert(OptoReg::add(c_frame_pointer(),1)); 1023 #endif 1024 1025 // Start at OptoReg::stack0() 1026 STACK_ONLY_mask.Clear(); 1027 OptoReg::Name init = OptoReg::stack2reg(0); 1028 // STACK_ONLY_mask is all stack bits 1029 OptoReg::Name i; 1030 for (i = init; RegMask::can_represent(i); i = OptoReg::add(i,1)) 1031 STACK_ONLY_mask.Insert(i); 1032 // Also set the "infinite stack" bit. 1033 STACK_ONLY_mask.set_AllStack(); 1034 1035 for (i = OptoReg::Name(0); i < OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i, 1)) { 1036 // Copy the register names over into the shared world. 1037 // SharedInfo::regName[i] = regName[i]; 1038 // Handy RegMasks per machine register 1039 mreg2regmask[i].Insert(i); 1040 1041 // Set up regmasks used to exclude save-on-call (and always-save) registers from debug masks. 1042 if (_register_save_policy[i] == 'C' || 1043 _register_save_policy[i] == 'A') { 1044 caller_save_regmask.Insert(i); 1045 mh_caller_save_regmask.Insert(i); 1046 } 1047 // Exclude save-on-entry registers from debug masks for stub compilations. 1048 if (_register_save_policy[i] == 'C' || 1049 _register_save_policy[i] == 'A' || 1050 _register_save_policy[i] == 'E') { 1051 caller_save_regmask_exclude_soe.Insert(i); 1052 mh_caller_save_regmask_exclude_soe.Insert(i); 1053 } 1054 } 1055 1056 // Also exclude the register we use to save the SP for MethodHandle 1057 // invokes to from the corresponding MH debug masks 1058 const RegMask sp_save_mask = method_handle_invoke_SP_save_mask(); 1059 mh_caller_save_regmask.OR(sp_save_mask); 1060 mh_caller_save_regmask_exclude_soe.OR(sp_save_mask); 1061 1062 // Grab the Frame Pointer 1063 Node *fp = ret->in(TypeFunc::FramePtr); 1064 // Share frame pointer while making spill ops 1065 set_shared(fp); 1066 1067 // Get the ADLC notion of the right regmask, for each basic type. 1068 #ifdef _LP64 1069 idealreg2regmask[Op_RegN] = regmask_for_ideal_register(Op_RegN, ret); 1070 #endif 1071 idealreg2regmask[Op_RegI] = regmask_for_ideal_register(Op_RegI, ret); 1072 idealreg2regmask[Op_RegP] = regmask_for_ideal_register(Op_RegP, ret); 1073 idealreg2regmask[Op_RegF] = regmask_for_ideal_register(Op_RegF, ret); 1074 idealreg2regmask[Op_RegD] = regmask_for_ideal_register(Op_RegD, ret); 1075 idealreg2regmask[Op_RegL] = regmask_for_ideal_register(Op_RegL, ret); 1076 idealreg2regmask[Op_VecA] = regmask_for_ideal_register(Op_VecA, ret); 1077 idealreg2regmask[Op_VecS] = regmask_for_ideal_register(Op_VecS, ret); 1078 idealreg2regmask[Op_VecD] = regmask_for_ideal_register(Op_VecD, ret); 1079 idealreg2regmask[Op_VecX] = regmask_for_ideal_register(Op_VecX, ret); 1080 idealreg2regmask[Op_VecY] = regmask_for_ideal_register(Op_VecY, ret); 1081 idealreg2regmask[Op_VecZ] = regmask_for_ideal_register(Op_VecZ, ret); 1082 idealreg2regmask[Op_RegVectMask] = regmask_for_ideal_register(Op_RegVectMask, ret); 1083 } 1084 1085 #ifdef ASSERT 1086 static void match_alias_type(Compile* C, Node* n, Node* m) { 1087 if (!VerifyAliases) return; // do not go looking for trouble by default 1088 const TypePtr* nat = n->adr_type(); 1089 const TypePtr* mat = m->adr_type(); 1090 int nidx = C->get_alias_index(nat); 1091 int midx = C->get_alias_index(mat); 1092 // Detune the assert for cases like (AndI 0xFF (LoadB p)). 1093 if (nidx == Compile::AliasIdxTop && midx >= Compile::AliasIdxRaw) { 1094 for (uint i = 1; i < n->req(); i++) { 1095 Node* n1 = n->in(i); 1096 const TypePtr* n1at = n1->adr_type(); 1097 if (n1at != nullptr) { 1098 nat = n1at; 1099 nidx = C->get_alias_index(n1at); 1100 } 1101 } 1102 } 1103 // %%% Kludgery. Instead, fix ideal adr_type methods for all these cases: 1104 if (nidx == Compile::AliasIdxTop && midx == Compile::AliasIdxRaw) { 1105 switch (n->Opcode()) { 1106 case Op_PrefetchAllocation: 1107 nidx = Compile::AliasIdxRaw; 1108 nat = TypeRawPtr::BOTTOM; 1109 break; 1110 } 1111 } 1112 if (nidx == Compile::AliasIdxRaw && midx == Compile::AliasIdxTop) { 1113 switch (n->Opcode()) { 1114 case Op_ClearArray: 1115 midx = Compile::AliasIdxRaw; 1116 mat = TypeRawPtr::BOTTOM; 1117 break; 1118 } 1119 } 1120 if (nidx == Compile::AliasIdxTop && midx == Compile::AliasIdxBot) { 1121 switch (n->Opcode()) { 1122 case Op_Return: 1123 case Op_Rethrow: 1124 case Op_Halt: 1125 case Op_TailCall: 1126 case Op_TailJump: 1127 case Op_ForwardException: 1128 nidx = Compile::AliasIdxBot; 1129 nat = TypePtr::BOTTOM; 1130 break; 1131 } 1132 } 1133 if (nidx == Compile::AliasIdxBot && midx == Compile::AliasIdxTop) { 1134 switch (n->Opcode()) { 1135 case Op_StrComp: 1136 case Op_StrEquals: 1137 case Op_StrIndexOf: 1138 case Op_StrIndexOfChar: 1139 case Op_AryEq: 1140 case Op_VectorizedHashCode: 1141 case Op_CountPositives: 1142 case Op_MemBarVolatile: 1143 case Op_MemBarCPUOrder: // %%% these ideals should have narrower adr_type? 1144 case Op_StrInflatedCopy: 1145 case Op_StrCompressedCopy: 1146 case Op_OnSpinWait: 1147 case Op_EncodeISOArray: 1148 nidx = Compile::AliasIdxTop; 1149 nat = nullptr; 1150 break; 1151 } 1152 } 1153 if (nidx != midx) { 1154 if (PrintOpto || (PrintMiscellaneous && (WizardMode || Verbose))) { 1155 tty->print_cr("==== Matcher alias shift %d => %d", nidx, midx); 1156 n->dump(); 1157 m->dump(); 1158 } 1159 assert(C->subsume_loads() && C->must_alias(nat, midx), 1160 "must not lose alias info when matching"); 1161 } 1162 } 1163 #endif 1164 1165 //------------------------------xform------------------------------------------ 1166 // Given a Node in old-space, Match him (Label/Reduce) to produce a machine 1167 // Node in new-space. Given a new-space Node, recursively walk his children. 1168 Node *Matcher::transform( Node *n ) { ShouldNotCallThis(); return n; } 1169 Node *Matcher::xform( Node *n, int max_stack ) { 1170 // Use one stack to keep both: child's node/state and parent's node/index 1171 MStack mstack(max_stack * 2 * 2); // usually: C->live_nodes() * 2 * 2 1172 mstack.push(n, Visit, nullptr, -1); // set null as parent to indicate root 1173 while (mstack.is_nonempty()) { 1174 C->check_node_count(NodeLimitFudgeFactor, "too many nodes matching instructions"); 1175 if (C->failing()) return nullptr; 1176 n = mstack.node(); // Leave node on stack 1177 Node_State nstate = mstack.state(); 1178 if (nstate == Visit) { 1179 mstack.set_state(Post_Visit); 1180 Node *oldn = n; 1181 // Old-space or new-space check 1182 if (!C->node_arena()->contains(n)) { 1183 // Old space! 1184 Node* m; 1185 if (has_new_node(n)) { // Not yet Label/Reduced 1186 m = new_node(n); 1187 } else { 1188 if (!is_dontcare(n)) { // Matcher can match this guy 1189 // Calls match special. They match alone with no children. 1190 // Their children, the incoming arguments, match normally. 1191 m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n); 1192 if (C->failing()) return nullptr; 1193 if (m == nullptr) { Matcher::soft_match_failure(); return nullptr; } 1194 if (n->is_MemBar()) { 1195 m->as_MachMemBar()->set_adr_type(n->adr_type()); 1196 } 1197 } else { // Nothing the matcher cares about 1198 if (n->is_Proj() && n->in(0) != nullptr && n->in(0)->is_Multi()) { // Projections? 1199 // Convert to machine-dependent projection 1200 RegMask* mask = nullptr; 1201 if (n->in(0)->is_Call() && n->in(0)->as_Call()->tf()->returns_inline_type_as_fields()) { 1202 mask = return_values_mask(n->in(0)->as_Call()->tf()); 1203 } 1204 m = n->in(0)->as_Multi()->match(n->as_Proj(), this, mask); 1205 NOT_PRODUCT(record_new2old(m, n);) 1206 if (m->in(0) != nullptr) // m might be top 1207 collect_null_checks(m, n); 1208 } else { // Else just a regular 'ol guy 1209 m = n->clone(); // So just clone into new-space 1210 NOT_PRODUCT(record_new2old(m, n);) 1211 // Def-Use edges will be added incrementally as Uses 1212 // of this node are matched. 1213 assert(m->outcnt() == 0, "no Uses of this clone yet"); 1214 } 1215 } 1216 1217 set_new_node(n, m); // Map old to new 1218 if (_old_node_note_array != nullptr) { 1219 Node_Notes* nn = C->locate_node_notes(_old_node_note_array, 1220 n->_idx); 1221 C->set_node_notes_at(m->_idx, nn); 1222 } 1223 debug_only(match_alias_type(C, n, m)); 1224 } 1225 n = m; // n is now a new-space node 1226 mstack.set_node(n); 1227 } 1228 1229 // New space! 1230 if (_visited.test_set(n->_idx)) continue; // while(mstack.is_nonempty()) 1231 1232 int i; 1233 // Put precedence edges on stack first (match them last). 1234 for (i = oldn->req(); (uint)i < oldn->len(); i++) { 1235 Node *m = oldn->in(i); 1236 if (m == nullptr) break; 1237 // set -1 to call add_prec() instead of set_req() during Step1 1238 mstack.push(m, Visit, n, -1); 1239 } 1240 1241 // Handle precedence edges for interior nodes 1242 for (i = n->len()-1; (uint)i >= n->req(); i--) { 1243 Node *m = n->in(i); 1244 if (m == nullptr || C->node_arena()->contains(m)) continue; 1245 n->rm_prec(i); 1246 // set -1 to call add_prec() instead of set_req() during Step1 1247 mstack.push(m, Visit, n, -1); 1248 } 1249 1250 // For constant debug info, I'd rather have unmatched constants. 1251 int cnt = n->req(); 1252 JVMState* jvms = n->jvms(); 1253 int debug_cnt = jvms ? jvms->debug_start() : cnt; 1254 1255 // Now do only debug info. Clone constants rather than matching. 1256 // Constants are represented directly in the debug info without 1257 // the need for executable machine instructions. 1258 // Monitor boxes are also represented directly. 1259 for (i = cnt - 1; i >= debug_cnt; --i) { // For all debug inputs do 1260 Node *m = n->in(i); // Get input 1261 int op = m->Opcode(); 1262 assert((op == Op_BoxLock) == jvms->is_monitor_use(i), "boxes only at monitor sites"); 1263 if( op == Op_ConI || op == Op_ConP || op == Op_ConN || op == Op_ConNKlass || 1264 op == Op_ConF || op == Op_ConD || op == Op_ConL 1265 // || op == Op_BoxLock // %%%% enable this and remove (+++) in chaitin.cpp 1266 ) { 1267 m = m->clone(); 1268 NOT_PRODUCT(record_new2old(m, n)); 1269 mstack.push(m, Post_Visit, n, i); // Don't need to visit 1270 mstack.push(m->in(0), Visit, m, 0); 1271 } else { 1272 mstack.push(m, Visit, n, i); 1273 } 1274 } 1275 1276 // And now walk his children, and convert his inputs to new-space. 1277 for( ; i >= 0; --i ) { // For all normal inputs do 1278 Node *m = n->in(i); // Get input 1279 if(m != nullptr) 1280 mstack.push(m, Visit, n, i); 1281 } 1282 1283 } 1284 else if (nstate == Post_Visit) { 1285 // Set xformed input 1286 Node *p = mstack.parent(); 1287 if (p != nullptr) { // root doesn't have parent 1288 int i = (int)mstack.index(); 1289 if (i >= 0) 1290 p->set_req(i, n); // required input 1291 else if (i == -1) 1292 p->add_prec(n); // precedence input 1293 else 1294 ShouldNotReachHere(); 1295 } 1296 mstack.pop(); // remove processed node from stack 1297 } 1298 else { 1299 ShouldNotReachHere(); 1300 } 1301 } // while (mstack.is_nonempty()) 1302 return n; // Return new-space Node 1303 } 1304 1305 //------------------------------warp_outgoing_stk_arg------------------------ 1306 OptoReg::Name Matcher::warp_outgoing_stk_arg( VMReg reg, OptoReg::Name begin_out_arg_area, OptoReg::Name &out_arg_limit_per_call ) { 1307 // Convert outgoing argument location to a pre-biased stack offset 1308 if (reg->is_stack()) { 1309 OptoReg::Name warped = reg->reg2stack(); 1310 // Adjust the stack slot offset to be the register number used 1311 // by the allocator. 1312 warped = OptoReg::add(begin_out_arg_area, warped); 1313 // Keep track of the largest numbered stack slot used for an arg. 1314 // Largest used slot per call-site indicates the amount of stack 1315 // that is killed by the call. 1316 if( warped >= out_arg_limit_per_call ) 1317 out_arg_limit_per_call = OptoReg::add(warped,1); 1318 if (!RegMask::can_represent_arg(warped)) { 1319 // Bailout. For example not enough space on stack for all arguments. Happens for methods with too many arguments. 1320 C->record_method_not_compilable("unsupported calling sequence"); 1321 return OptoReg::Bad; 1322 } 1323 return warped; 1324 } 1325 return OptoReg::as_OptoReg(reg); 1326 } 1327 1328 1329 //------------------------------match_sfpt------------------------------------- 1330 // Helper function to match call instructions. Calls match special. 1331 // They match alone with no children. Their children, the incoming 1332 // arguments, match normally. 1333 MachNode *Matcher::match_sfpt( SafePointNode *sfpt ) { 1334 MachSafePointNode *msfpt = nullptr; 1335 MachCallNode *mcall = nullptr; 1336 uint cnt; 1337 // Split out case for SafePoint vs Call 1338 CallNode *call; 1339 const TypeTuple *domain; 1340 ciMethod* method = nullptr; 1341 bool is_method_handle_invoke = false; // for special kill effects 1342 if( sfpt->is_Call() ) { 1343 call = sfpt->as_Call(); 1344 domain = call->tf()->domain_cc(); 1345 cnt = domain->cnt(); 1346 1347 // Match just the call, nothing else 1348 MachNode *m = match_tree(call); 1349 if (C->failing()) return nullptr; 1350 if( m == nullptr ) { Matcher::soft_match_failure(); return nullptr; } 1351 1352 // Copy data from the Ideal SafePoint to the machine version 1353 mcall = m->as_MachCall(); 1354 1355 mcall->set_tf( call->tf()); 1356 mcall->set_entry_point( call->entry_point()); 1357 mcall->set_cnt( call->cnt()); 1358 mcall->set_guaranteed_safepoint(call->guaranteed_safepoint()); 1359 1360 if( mcall->is_MachCallJava() ) { 1361 MachCallJavaNode *mcall_java = mcall->as_MachCallJava(); 1362 const CallJavaNode *call_java = call->as_CallJava(); 1363 assert(call_java->validate_symbolic_info(), "inconsistent info"); 1364 method = call_java->method(); 1365 mcall_java->_method = method; 1366 mcall_java->_optimized_virtual = call_java->is_optimized_virtual(); 1367 is_method_handle_invoke = call_java->is_method_handle_invoke(); 1368 mcall_java->_method_handle_invoke = is_method_handle_invoke; 1369 mcall_java->_override_symbolic_info = call_java->override_symbolic_info(); 1370 mcall_java->_arg_escape = call_java->arg_escape(); 1371 if (is_method_handle_invoke) { 1372 C->set_has_method_handle_invokes(true); 1373 } 1374 if( mcall_java->is_MachCallStaticJava() ) 1375 mcall_java->as_MachCallStaticJava()->_name = 1376 call_java->as_CallStaticJava()->_name; 1377 if( mcall_java->is_MachCallDynamicJava() ) 1378 mcall_java->as_MachCallDynamicJava()->_vtable_index = 1379 call_java->as_CallDynamicJava()->_vtable_index; 1380 } 1381 else if( mcall->is_MachCallRuntime() ) { 1382 MachCallRuntimeNode* mach_call_rt = mcall->as_MachCallRuntime(); 1383 mach_call_rt->_name = call->as_CallRuntime()->_name; 1384 mach_call_rt->_leaf_no_fp = call->is_CallLeafNoFP(); 1385 } 1386 msfpt = mcall; 1387 } 1388 // This is a non-call safepoint 1389 else { 1390 call = nullptr; 1391 domain = nullptr; 1392 MachNode *mn = match_tree(sfpt); 1393 if (C->failing()) return nullptr; 1394 msfpt = mn->as_MachSafePoint(); 1395 cnt = TypeFunc::Parms; 1396 } 1397 msfpt->_has_ea_local_in_scope = sfpt->has_ea_local_in_scope(); 1398 1399 // Advertise the correct memory effects (for anti-dependence computation). 1400 msfpt->set_adr_type(sfpt->adr_type()); 1401 1402 // Allocate a private array of RegMasks. These RegMasks are not shared. 1403 msfpt->_in_rms = NEW_RESOURCE_ARRAY( RegMask, cnt ); 1404 // Empty them all. 1405 for (uint i = 0; i < cnt; i++) ::new (&(msfpt->_in_rms[i])) RegMask(); 1406 1407 // Do all the pre-defined non-Empty register masks 1408 msfpt->_in_rms[TypeFunc::ReturnAdr] = _return_addr_mask; 1409 msfpt->_in_rms[TypeFunc::FramePtr ] = c_frame_ptr_mask; 1410 1411 // Place first outgoing argument can possibly be put. 1412 OptoReg::Name begin_out_arg_area = OptoReg::add(_new_SP, C->out_preserve_stack_slots()); 1413 assert( is_even(begin_out_arg_area), "" ); 1414 // Compute max outgoing register number per call site. 1415 OptoReg::Name out_arg_limit_per_call = begin_out_arg_area; 1416 // Calls to C may hammer extra stack slots above and beyond any arguments. 1417 // These are usually backing store for register arguments for varargs. 1418 if( call != nullptr && call->is_CallRuntime() ) 1419 out_arg_limit_per_call = OptoReg::add(out_arg_limit_per_call,C->varargs_C_out_slots_killed()); 1420 1421 1422 // Do the normal argument list (parameters) register masks 1423 // Null entry point is a special cast where the target of the call 1424 // is in a register. 1425 int adj = (call != nullptr && call->entry_point() == nullptr) ? 1 : 0; 1426 int argcnt = cnt - TypeFunc::Parms - adj; 1427 if( argcnt > 0 ) { // Skip it all if we have no args 1428 BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, argcnt ); 1429 VMRegPair *parm_regs = NEW_RESOURCE_ARRAY( VMRegPair, argcnt ); 1430 int i; 1431 for( i = 0; i < argcnt; i++ ) { 1432 sig_bt[i] = domain->field_at(i+TypeFunc::Parms+adj)->basic_type(); 1433 } 1434 // V-call to pick proper calling convention 1435 call->calling_convention( sig_bt, parm_regs, argcnt ); 1436 1437 #ifdef ASSERT 1438 // Sanity check users' calling convention. Really handy during 1439 // the initial porting effort. Fairly expensive otherwise. 1440 { for (int i = 0; i<argcnt; i++) { 1441 if( !parm_regs[i].first()->is_valid() && 1442 !parm_regs[i].second()->is_valid() ) continue; 1443 VMReg reg1 = parm_regs[i].first(); 1444 VMReg reg2 = parm_regs[i].second(); 1445 for (int j = 0; j < i; j++) { 1446 if( !parm_regs[j].first()->is_valid() && 1447 !parm_regs[j].second()->is_valid() ) continue; 1448 VMReg reg3 = parm_regs[j].first(); 1449 VMReg reg4 = parm_regs[j].second(); 1450 if( !reg1->is_valid() ) { 1451 assert( !reg2->is_valid(), "valid halvsies" ); 1452 } else if( !reg3->is_valid() ) { 1453 assert( !reg4->is_valid(), "valid halvsies" ); 1454 } else { 1455 assert( reg1 != reg2, "calling conv. must produce distinct regs"); 1456 assert( reg1 != reg3, "calling conv. must produce distinct regs"); 1457 assert( reg1 != reg4, "calling conv. must produce distinct regs"); 1458 assert( reg2 != reg3, "calling conv. must produce distinct regs"); 1459 assert( reg2 != reg4 || !reg2->is_valid(), "calling conv. must produce distinct regs"); 1460 assert( reg3 != reg4, "calling conv. must produce distinct regs"); 1461 } 1462 } 1463 } 1464 } 1465 #endif 1466 1467 // Visit each argument. Compute its outgoing register mask. 1468 // Return results now can have 2 bits returned. 1469 // Compute max over all outgoing arguments both per call-site 1470 // and over the entire method. 1471 for( i = 0; i < argcnt; i++ ) { 1472 // Address of incoming argument mask to fill in 1473 RegMask *rm = &mcall->_in_rms[i+TypeFunc::Parms+adj]; 1474 VMReg first = parm_regs[i].first(); 1475 VMReg second = parm_regs[i].second(); 1476 if(!first->is_valid() && 1477 !second->is_valid()) { 1478 continue; // Avoid Halves 1479 } 1480 // Handle case where arguments are in vector registers. 1481 if(call->in(TypeFunc::Parms + i)->bottom_type()->isa_vect()) { 1482 OptoReg::Name reg_fst = OptoReg::as_OptoReg(first); 1483 OptoReg::Name reg_snd = OptoReg::as_OptoReg(second); 1484 assert (reg_fst <= reg_snd, "fst=%d snd=%d", reg_fst, reg_snd); 1485 for (OptoReg::Name r = reg_fst; r <= reg_snd; r++) { 1486 rm->Insert(r); 1487 } 1488 } 1489 // Grab first register, adjust stack slots and insert in mask. 1490 OptoReg::Name reg1 = warp_outgoing_stk_arg(first, begin_out_arg_area, out_arg_limit_per_call ); 1491 if (C->failing()) { 1492 return nullptr; 1493 } 1494 if (OptoReg::is_valid(reg1)) { 1495 rm->Insert( reg1 ); 1496 } 1497 // Grab second register (if any), adjust stack slots and insert in mask. 1498 OptoReg::Name reg2 = warp_outgoing_stk_arg(second, begin_out_arg_area, out_arg_limit_per_call ); 1499 if (C->failing()) { 1500 return nullptr; 1501 } 1502 if (OptoReg::is_valid(reg2)) { 1503 rm->Insert( reg2 ); 1504 } 1505 } // End of for all arguments 1506 } 1507 1508 // Compute the max stack slot killed by any call. These will not be 1509 // available for debug info, and will be used to adjust FIRST_STACK_mask 1510 // after all call sites have been visited. 1511 if( _out_arg_limit < out_arg_limit_per_call) 1512 _out_arg_limit = out_arg_limit_per_call; 1513 1514 if (mcall) { 1515 // Kill the outgoing argument area, including any non-argument holes and 1516 // any legacy C-killed slots. Use Fat-Projections to do the killing. 1517 // Since the max-per-method covers the max-per-call-site and debug info 1518 // is excluded on the max-per-method basis, debug info cannot land in 1519 // this killed area. 1520 uint r_cnt = mcall->tf()->range_sig()->cnt(); 1521 MachProjNode *proj = new MachProjNode( mcall, r_cnt+10000, RegMask::Empty, MachProjNode::fat_proj ); 1522 if (!RegMask::can_represent_arg(OptoReg::Name(out_arg_limit_per_call-1))) { 1523 // Bailout. We do not have space to represent all arguments. 1524 C->record_method_not_compilable("unsupported outgoing calling sequence"); 1525 } else { 1526 for (int i = begin_out_arg_area; i < out_arg_limit_per_call; i++) 1527 proj->_rout.Insert(OptoReg::Name(i)); 1528 } 1529 if (proj->_rout.is_NotEmpty()) { 1530 push_projection(proj); 1531 } 1532 } 1533 // Transfer the safepoint information from the call to the mcall 1534 // Move the JVMState list 1535 msfpt->set_jvms(sfpt->jvms()); 1536 for (JVMState* jvms = msfpt->jvms(); jvms; jvms = jvms->caller()) { 1537 jvms->set_map(sfpt); 1538 } 1539 1540 // Debug inputs begin just after the last incoming parameter 1541 assert((mcall == nullptr) || (mcall->jvms() == nullptr) || 1542 (mcall->jvms()->debug_start() + mcall->_jvmadj == mcall->tf()->domain_cc()->cnt()), ""); 1543 1544 // Add additional edges. 1545 if (msfpt->mach_constant_base_node_input() != (uint)-1 && !msfpt->is_MachCallLeaf()) { 1546 // For these calls we can not add MachConstantBase in expand(), as the 1547 // ins are not complete then. 1548 msfpt->ins_req(msfpt->mach_constant_base_node_input(), C->mach_constant_base_node()); 1549 if (msfpt->jvms() && 1550 msfpt->mach_constant_base_node_input() <= msfpt->jvms()->debug_start() + msfpt->_jvmadj) { 1551 // We added an edge before jvms, so we must adapt the position of the ins. 1552 msfpt->jvms()->adapt_position(+1); 1553 } 1554 } 1555 1556 // Registers killed by the call are set in the local scheduling pass 1557 // of Global Code Motion. 1558 return msfpt; 1559 } 1560 1561 //---------------------------match_tree---------------------------------------- 1562 // Match a Ideal Node DAG - turn it into a tree; Label & Reduce. Used as part 1563 // of the whole-sale conversion from Ideal to Mach Nodes. Also used for 1564 // making GotoNodes while building the CFG and in init_spill_mask() to identify 1565 // a Load's result RegMask for memoization in idealreg2regmask[] 1566 MachNode *Matcher::match_tree( const Node *n ) { 1567 assert( n->Opcode() != Op_Phi, "cannot match" ); 1568 assert( !n->is_block_start(), "cannot match" ); 1569 // Set the mark for all locally allocated State objects. 1570 // When this call returns, the _states_arena arena will be reset 1571 // freeing all State objects. 1572 ResourceMark rm( &_states_arena ); 1573 1574 LabelRootDepth = 0; 1575 1576 // StoreNodes require their Memory input to match any LoadNodes 1577 Node *mem = n->is_Store() ? n->in(MemNode::Memory) : (Node*)1 ; 1578 #ifdef ASSERT 1579 Node* save_mem_node = _mem_node; 1580 _mem_node = n->is_Store() ? (Node*)n : nullptr; 1581 #endif 1582 // State object for root node of match tree 1583 // Allocate it on _states_arena - stack allocation can cause stack overflow. 1584 State *s = new (&_states_arena) State; 1585 s->_kids[0] = nullptr; 1586 s->_kids[1] = nullptr; 1587 s->_leaf = (Node*)n; 1588 // Label the input tree, allocating labels from top-level arena 1589 Node* root_mem = mem; 1590 Label_Root(n, s, n->in(0), root_mem); 1591 if (C->failing()) return nullptr; 1592 1593 // The minimum cost match for the whole tree is found at the root State 1594 uint mincost = max_juint; 1595 uint cost = max_juint; 1596 uint i; 1597 for (i = 0; i < NUM_OPERANDS; i++) { 1598 if (s->valid(i) && // valid entry and 1599 s->cost(i) < cost && // low cost and 1600 s->rule(i) >= NUM_OPERANDS) {// not an operand 1601 mincost = i; 1602 cost = s->cost(i); 1603 } 1604 } 1605 if (mincost == max_juint) { 1606 #ifndef PRODUCT 1607 tty->print("No matching rule for:"); 1608 s->dump(); 1609 #endif 1610 Matcher::soft_match_failure(); 1611 return nullptr; 1612 } 1613 // Reduce input tree based upon the state labels to machine Nodes 1614 MachNode *m = ReduceInst(s, s->rule(mincost), mem); 1615 // New-to-old mapping is done in ReduceInst, to cover complex instructions. 1616 NOT_PRODUCT(_old2new_map.map(n->_idx, m);) 1617 1618 // Add any Matcher-ignored edges 1619 uint cnt = n->req(); 1620 uint start = 1; 1621 if( mem != (Node*)1 ) start = MemNode::Memory+1; 1622 if( n->is_AddP() ) { 1623 assert( mem == (Node*)1, "" ); 1624 start = AddPNode::Base+1; 1625 } 1626 for( i = start; i < cnt; i++ ) { 1627 if( !n->match_edge(i) ) { 1628 if( i < m->req() ) 1629 m->ins_req( i, n->in(i) ); 1630 else 1631 m->add_req( n->in(i) ); 1632 } 1633 } 1634 1635 debug_only( _mem_node = save_mem_node; ) 1636 return m; 1637 } 1638 1639 1640 //------------------------------match_into_reg--------------------------------- 1641 // Choose to either match this Node in a register or part of the current 1642 // match tree. Return true for requiring a register and false for matching 1643 // as part of the current match tree. 1644 static bool match_into_reg( const Node *n, Node *m, Node *control, int i, bool shared ) { 1645 1646 const Type *t = m->bottom_type(); 1647 1648 if (t->singleton()) { 1649 // Never force constants into registers. Allow them to match as 1650 // constants or registers. Copies of the same value will share 1651 // the same register. See find_shared_node. 1652 return false; 1653 } else { // Not a constant 1654 if (!shared && Matcher::is_encode_and_store_pattern(n, m)) { 1655 // Make it possible to match "encode and store" patterns with non-shared 1656 // encode operations that are pinned to a control node (e.g. by CastPP 1657 // node removal in final graph reshaping). The matched instruction cannot 1658 // float above the encode's control node because it is pinned to the 1659 // store's control node. 1660 return false; 1661 } 1662 // Stop recursion if they have different Controls. 1663 Node* m_control = m->in(0); 1664 // Control of load's memory can post-dominates load's control. 1665 // So use it since load can't float above its memory. 1666 Node* mem_control = (m->is_Load()) ? m->in(MemNode::Memory)->in(0) : nullptr; 1667 if (control && m_control && control != m_control && control != mem_control) { 1668 1669 // Actually, we can live with the most conservative control we 1670 // find, if it post-dominates the others. This allows us to 1671 // pick up load/op/store trees where the load can float a little 1672 // above the store. 1673 Node *x = control; 1674 const uint max_scan = 6; // Arbitrary scan cutoff 1675 uint j; 1676 for (j=0; j<max_scan; j++) { 1677 if (x->is_Region()) // Bail out at merge points 1678 return true; 1679 x = x->in(0); 1680 if (x == m_control) // Does 'control' post-dominate 1681 break; // m->in(0)? If so, we can use it 1682 if (x == mem_control) // Does 'control' post-dominate 1683 break; // mem_control? If so, we can use it 1684 } 1685 if (j == max_scan) // No post-domination before scan end? 1686 return true; // Then break the match tree up 1687 } 1688 if ((m->is_DecodeN() && Matcher::narrow_oop_use_complex_address()) || 1689 (m->is_DecodeNKlass() && Matcher::narrow_klass_use_complex_address())) { 1690 // These are commonly used in address expressions and can 1691 // efficiently fold into them on X64 in some cases. 1692 return false; 1693 } 1694 } 1695 1696 // Not forceable cloning. If shared, put it into a register. 1697 return shared; 1698 } 1699 1700 1701 //------------------------------Instruction Selection-------------------------- 1702 // Label method walks a "tree" of nodes, using the ADLC generated DFA to match 1703 // ideal nodes to machine instructions. Trees are delimited by shared Nodes, 1704 // things the Matcher does not match (e.g., Memory), and things with different 1705 // Controls (hence forced into different blocks). We pass in the Control 1706 // selected for this entire State tree. 1707 1708 // The Matcher works on Trees, but an Intel add-to-memory requires a DAG: the 1709 // Store and the Load must have identical Memories (as well as identical 1710 // pointers). Since the Matcher does not have anything for Memory (and 1711 // does not handle DAGs), I have to match the Memory input myself. If the 1712 // Tree root is a Store or if there are multiple Loads in the tree, I require 1713 // all Loads to have the identical memory. 1714 Node* Matcher::Label_Root(const Node* n, State* svec, Node* control, Node*& mem) { 1715 // Since Label_Root is a recursive function, its possible that we might run 1716 // out of stack space. See bugs 6272980 & 6227033 for more info. 1717 LabelRootDepth++; 1718 if (LabelRootDepth > MaxLabelRootDepth) { 1719 // Bailout. Can for example be hit with a deep chain of operations. 1720 C->record_method_not_compilable("Out of stack space, increase MaxLabelRootDepth"); 1721 return nullptr; 1722 } 1723 uint care = 0; // Edges matcher cares about 1724 uint cnt = n->req(); 1725 uint i = 0; 1726 1727 // Examine children for memory state 1728 // Can only subsume a child into your match-tree if that child's memory state 1729 // is not modified along the path to another input. 1730 // It is unsafe even if the other inputs are separate roots. 1731 Node *input_mem = nullptr; 1732 for( i = 1; i < cnt; i++ ) { 1733 if( !n->match_edge(i) ) continue; 1734 Node *m = n->in(i); // Get ith input 1735 assert( m, "expect non-null children" ); 1736 if( m->is_Load() ) { 1737 if( input_mem == nullptr ) { 1738 input_mem = m->in(MemNode::Memory); 1739 if (mem == (Node*)1) { 1740 // Save this memory to bail out if there's another memory access 1741 // to a different memory location in the same tree. 1742 mem = input_mem; 1743 } 1744 } else if( input_mem != m->in(MemNode::Memory) ) { 1745 input_mem = NodeSentinel; 1746 } 1747 } 1748 } 1749 1750 for( i = 1; i < cnt; i++ ){// For my children 1751 if( !n->match_edge(i) ) continue; 1752 Node *m = n->in(i); // Get ith input 1753 // Allocate states out of a private arena 1754 State *s = new (&_states_arena) State; 1755 svec->_kids[care++] = s; 1756 assert( care <= 2, "binary only for now" ); 1757 1758 // Recursively label the State tree. 1759 s->_kids[0] = nullptr; 1760 s->_kids[1] = nullptr; 1761 s->_leaf = m; 1762 1763 // Check for leaves of the State Tree; things that cannot be a part of 1764 // the current tree. If it finds any, that value is matched as a 1765 // register operand. If not, then the normal matching is used. 1766 if( match_into_reg(n, m, control, i, is_shared(m)) || 1767 // Stop recursion if this is a LoadNode and there is another memory access 1768 // to a different memory location in the same tree (for example, a StoreNode 1769 // at the root of this tree or another LoadNode in one of the children). 1770 ((mem!=(Node*)1) && m->is_Load() && m->in(MemNode::Memory) != mem) || 1771 // Can NOT include the match of a subtree when its memory state 1772 // is used by any of the other subtrees 1773 (input_mem == NodeSentinel) ) { 1774 // Print when we exclude matching due to different memory states at input-loads 1775 if (PrintOpto && (Verbose && WizardMode) && (input_mem == NodeSentinel) 1776 && !((mem!=(Node*)1) && m->is_Load() && m->in(MemNode::Memory) != mem)) { 1777 tty->print_cr("invalid input_mem"); 1778 } 1779 // Switch to a register-only opcode; this value must be in a register 1780 // and cannot be subsumed as part of a larger instruction. 1781 s->DFA( m->ideal_reg(), m ); 1782 1783 } else { 1784 // If match tree has no control and we do, adopt it for entire tree 1785 if( control == nullptr && m->in(0) != nullptr && m->req() > 1 ) 1786 control = m->in(0); // Pick up control 1787 // Else match as a normal part of the match tree. 1788 control = Label_Root(m, s, control, mem); 1789 if (C->failing()) return nullptr; 1790 } 1791 } 1792 1793 // Call DFA to match this node, and return 1794 svec->DFA( n->Opcode(), n ); 1795 1796 uint x; 1797 for( x = 0; x < _LAST_MACH_OPER; x++ ) 1798 if( svec->valid(x) ) 1799 break; 1800 1801 if (x >= _LAST_MACH_OPER) { 1802 #ifdef ASSERT 1803 n->dump(); 1804 svec->dump(); 1805 #endif 1806 assert( false, "bad AD file" ); 1807 C->record_failure("bad AD file"); 1808 } 1809 return control; 1810 } 1811 1812 1813 // Con nodes reduced using the same rule can share their MachNode 1814 // which reduces the number of copies of a constant in the final 1815 // program. The register allocator is free to split uses later to 1816 // split live ranges. 1817 MachNode* Matcher::find_shared_node(Node* leaf, uint rule) { 1818 if (!leaf->is_Con() && !leaf->is_DecodeNarrowPtr()) return nullptr; 1819 1820 // See if this Con has already been reduced using this rule. 1821 if (_shared_nodes.max() <= leaf->_idx) return nullptr; 1822 MachNode* last = (MachNode*)_shared_nodes.at(leaf->_idx); 1823 if (last != nullptr && rule == last->rule()) { 1824 // Don't expect control change for DecodeN 1825 if (leaf->is_DecodeNarrowPtr()) 1826 return last; 1827 // Get the new space root. 1828 Node* xroot = new_node(C->root()); 1829 if (xroot == nullptr) { 1830 // This shouldn't happen give the order of matching. 1831 return nullptr; 1832 } 1833 1834 // Shared constants need to have their control be root so they 1835 // can be scheduled properly. 1836 Node* control = last->in(0); 1837 if (control != xroot) { 1838 if (control == nullptr || control == C->root()) { 1839 last->set_req(0, xroot); 1840 } else { 1841 assert(false, "unexpected control"); 1842 return nullptr; 1843 } 1844 } 1845 return last; 1846 } 1847 return nullptr; 1848 } 1849 1850 1851 //------------------------------ReduceInst------------------------------------- 1852 // Reduce a State tree (with given Control) into a tree of MachNodes. 1853 // This routine (and it's cohort ReduceOper) convert Ideal Nodes into 1854 // complicated machine Nodes. Each MachNode covers some tree of Ideal Nodes. 1855 // Each MachNode has a number of complicated MachOper operands; each 1856 // MachOper also covers a further tree of Ideal Nodes. 1857 1858 // The root of the Ideal match tree is always an instruction, so we enter 1859 // the recursion here. After building the MachNode, we need to recurse 1860 // the tree checking for these cases: 1861 // (1) Child is an instruction - 1862 // Build the instruction (recursively), add it as an edge. 1863 // Build a simple operand (register) to hold the result of the instruction. 1864 // (2) Child is an interior part of an instruction - 1865 // Skip over it (do nothing) 1866 // (3) Child is the start of a operand - 1867 // Build the operand, place it inside the instruction 1868 // Call ReduceOper. 1869 MachNode *Matcher::ReduceInst( State *s, int rule, Node *&mem ) { 1870 assert( rule >= NUM_OPERANDS, "called with operand rule" ); 1871 1872 MachNode* shared_node = find_shared_node(s->_leaf, rule); 1873 if (shared_node != nullptr) { 1874 return shared_node; 1875 } 1876 1877 // Build the object to represent this state & prepare for recursive calls 1878 MachNode *mach = s->MachNodeGenerator(rule); 1879 guarantee(mach != nullptr, "Missing MachNode"); 1880 mach->_opnds[0] = s->MachOperGenerator(_reduceOp[rule]); 1881 assert( mach->_opnds[0] != nullptr, "Missing result operand" ); 1882 Node *leaf = s->_leaf; 1883 NOT_PRODUCT(record_new2old(mach, leaf);) 1884 // Check for instruction or instruction chain rule 1885 if( rule >= _END_INST_CHAIN_RULE || rule < _BEGIN_INST_CHAIN_RULE ) { 1886 assert(C->node_arena()->contains(s->_leaf) || !has_new_node(s->_leaf), 1887 "duplicating node that's already been matched"); 1888 // Instruction 1889 mach->add_req( leaf->in(0) ); // Set initial control 1890 // Reduce interior of complex instruction 1891 ReduceInst_Interior( s, rule, mem, mach, 1 ); 1892 } else { 1893 // Instruction chain rules are data-dependent on their inputs 1894 mach->add_req(nullptr); // Set initial control to none 1895 ReduceInst_Chain_Rule( s, rule, mem, mach ); 1896 } 1897 1898 // If a Memory was used, insert a Memory edge 1899 if( mem != (Node*)1 ) { 1900 mach->ins_req(MemNode::Memory,mem); 1901 #ifdef ASSERT 1902 // Verify adr type after matching memory operation 1903 const MachOper* oper = mach->memory_operand(); 1904 if (oper != nullptr && oper != (MachOper*)-1) { 1905 // It has a unique memory operand. Find corresponding ideal mem node. 1906 Node* m = nullptr; 1907 if (leaf->is_Mem()) { 1908 m = leaf; 1909 } else { 1910 m = _mem_node; 1911 assert(m != nullptr && m->is_Mem(), "expecting memory node"); 1912 } 1913 const Type* mach_at = mach->adr_type(); 1914 // DecodeN node consumed by an address may have different type 1915 // than its input. Don't compare types for such case. 1916 if (m->adr_type() != mach_at && 1917 (m->in(MemNode::Address)->is_DecodeNarrowPtr() || 1918 (m->in(MemNode::Address)->is_AddP() && 1919 m->in(MemNode::Address)->in(AddPNode::Address)->is_DecodeNarrowPtr()) || 1920 (m->in(MemNode::Address)->is_AddP() && 1921 m->in(MemNode::Address)->in(AddPNode::Address)->is_AddP() && 1922 m->in(MemNode::Address)->in(AddPNode::Address)->in(AddPNode::Address)->is_DecodeNarrowPtr()))) { 1923 mach_at = m->adr_type(); 1924 } 1925 if (m->adr_type() != mach_at) { 1926 m->dump(); 1927 tty->print_cr("mach:"); 1928 mach->dump(1); 1929 } 1930 assert(m->adr_type() == mach_at, "matcher should not change adr type"); 1931 } 1932 #endif 1933 } 1934 1935 // If the _leaf is an AddP, insert the base edge 1936 if (leaf->is_AddP()) { 1937 mach->ins_req(AddPNode::Base,leaf->in(AddPNode::Base)); 1938 } 1939 1940 uint number_of_projections_prior = number_of_projections(); 1941 1942 // Perform any 1-to-many expansions required 1943 MachNode *ex = mach->Expand(s, _projection_list, mem); 1944 if (ex != mach) { 1945 assert(ex->ideal_reg() == mach->ideal_reg(), "ideal types should match"); 1946 if( ex->in(1)->is_Con() ) 1947 ex->in(1)->set_req(0, C->root()); 1948 // Remove old node from the graph 1949 for( uint i=0; i<mach->req(); i++ ) { 1950 mach->set_req(i,nullptr); 1951 } 1952 NOT_PRODUCT(record_new2old(ex, s->_leaf);) 1953 } 1954 1955 // PhaseChaitin::fixup_spills will sometimes generate spill code 1956 // via the matcher. By the time, nodes have been wired into the CFG, 1957 // and any further nodes generated by expand rules will be left hanging 1958 // in space, and will not get emitted as output code. Catch this. 1959 // Also, catch any new register allocation constraints ("projections") 1960 // generated belatedly during spill code generation. 1961 if (_allocation_started) { 1962 guarantee(ex == mach, "no expand rules during spill generation"); 1963 guarantee(number_of_projections_prior == number_of_projections(), "no allocation during spill generation"); 1964 } 1965 1966 if (leaf->is_Con() || leaf->is_DecodeNarrowPtr()) { 1967 // Record the con for sharing 1968 _shared_nodes.map(leaf->_idx, ex); 1969 } 1970 1971 // Have mach nodes inherit GC barrier data 1972 mach->set_barrier_data(MemNode::barrier_data(leaf)); 1973 1974 return ex; 1975 } 1976 1977 void Matcher::handle_precedence_edges(Node* n, MachNode *mach) { 1978 for (uint i = n->req(); i < n->len(); i++) { 1979 if (n->in(i) != nullptr) { 1980 mach->add_prec(n->in(i)); 1981 } 1982 } 1983 } 1984 1985 void Matcher::ReduceInst_Chain_Rule(State* s, int rule, Node* &mem, MachNode* mach) { 1986 // 'op' is what I am expecting to receive 1987 int op = _leftOp[rule]; 1988 // Operand type to catch childs result 1989 // This is what my child will give me. 1990 unsigned int opnd_class_instance = s->rule(op); 1991 // Choose between operand class or not. 1992 // This is what I will receive. 1993 int catch_op = (FIRST_OPERAND_CLASS <= op && op < NUM_OPERANDS) ? opnd_class_instance : op; 1994 // New rule for child. Chase operand classes to get the actual rule. 1995 unsigned int newrule = s->rule(catch_op); 1996 1997 if (newrule < NUM_OPERANDS) { 1998 // Chain from operand or operand class, may be output of shared node 1999 assert(opnd_class_instance < NUM_OPERANDS, "Bad AD file: Instruction chain rule must chain from operand"); 2000 // Insert operand into array of operands for this instruction 2001 mach->_opnds[1] = s->MachOperGenerator(opnd_class_instance); 2002 2003 ReduceOper(s, newrule, mem, mach); 2004 } else { 2005 // Chain from the result of an instruction 2006 assert(newrule >= _LAST_MACH_OPER, "Do NOT chain from internal operand"); 2007 mach->_opnds[1] = s->MachOperGenerator(_reduceOp[catch_op]); 2008 Node *mem1 = (Node*)1; 2009 debug_only(Node *save_mem_node = _mem_node;) 2010 mach->add_req( ReduceInst(s, newrule, mem1) ); 2011 debug_only(_mem_node = save_mem_node;) 2012 } 2013 return; 2014 } 2015 2016 2017 uint Matcher::ReduceInst_Interior( State *s, int rule, Node *&mem, MachNode *mach, uint num_opnds ) { 2018 handle_precedence_edges(s->_leaf, mach); 2019 2020 if( s->_leaf->is_Load() ) { 2021 Node *mem2 = s->_leaf->in(MemNode::Memory); 2022 assert( mem == (Node*)1 || mem == mem2, "multiple Memories being matched at once?" ); 2023 debug_only( if( mem == (Node*)1 ) _mem_node = s->_leaf;) 2024 mem = mem2; 2025 } 2026 if( s->_leaf->in(0) != nullptr && s->_leaf->req() > 1) { 2027 if( mach->in(0) == nullptr ) 2028 mach->set_req(0, s->_leaf->in(0)); 2029 } 2030 2031 // Now recursively walk the state tree & add operand list. 2032 for( uint i=0; i<2; i++ ) { // binary tree 2033 State *newstate = s->_kids[i]; 2034 if( newstate == nullptr ) break; // Might only have 1 child 2035 // 'op' is what I am expecting to receive 2036 int op; 2037 if( i == 0 ) { 2038 op = _leftOp[rule]; 2039 } else { 2040 op = _rightOp[rule]; 2041 } 2042 // Operand type to catch childs result 2043 // This is what my child will give me. 2044 int opnd_class_instance = newstate->rule(op); 2045 // Choose between operand class or not. 2046 // This is what I will receive. 2047 int catch_op = (op >= FIRST_OPERAND_CLASS && op < NUM_OPERANDS) ? opnd_class_instance : op; 2048 // New rule for child. Chase operand classes to get the actual rule. 2049 int newrule = newstate->rule(catch_op); 2050 2051 if (newrule < NUM_OPERANDS) { // Operand/operandClass or internalOp/instruction? 2052 // Operand/operandClass 2053 // Insert operand into array of operands for this instruction 2054 mach->_opnds[num_opnds++] = newstate->MachOperGenerator(opnd_class_instance); 2055 ReduceOper(newstate, newrule, mem, mach); 2056 2057 } else { // Child is internal operand or new instruction 2058 if (newrule < _LAST_MACH_OPER) { // internal operand or instruction? 2059 // internal operand --> call ReduceInst_Interior 2060 // Interior of complex instruction. Do nothing but recurse. 2061 num_opnds = ReduceInst_Interior(newstate, newrule, mem, mach, num_opnds); 2062 } else { 2063 // instruction --> call build operand( ) to catch result 2064 // --> ReduceInst( newrule ) 2065 mach->_opnds[num_opnds++] = s->MachOperGenerator(_reduceOp[catch_op]); 2066 Node *mem1 = (Node*)1; 2067 debug_only(Node *save_mem_node = _mem_node;) 2068 mach->add_req( ReduceInst( newstate, newrule, mem1 ) ); 2069 debug_only(_mem_node = save_mem_node;) 2070 } 2071 } 2072 assert( mach->_opnds[num_opnds-1], "" ); 2073 } 2074 return num_opnds; 2075 } 2076 2077 // This routine walks the interior of possible complex operands. 2078 // At each point we check our children in the match tree: 2079 // (1) No children - 2080 // We are a leaf; add _leaf field as an input to the MachNode 2081 // (2) Child is an internal operand - 2082 // Skip over it ( do nothing ) 2083 // (3) Child is an instruction - 2084 // Call ReduceInst recursively and 2085 // and instruction as an input to the MachNode 2086 void Matcher::ReduceOper( State *s, int rule, Node *&mem, MachNode *mach ) { 2087 assert( rule < _LAST_MACH_OPER, "called with operand rule" ); 2088 State *kid = s->_kids[0]; 2089 assert( kid == nullptr || s->_leaf->in(0) == nullptr, "internal operands have no control" ); 2090 2091 // Leaf? And not subsumed? 2092 if( kid == nullptr && !_swallowed[rule] ) { 2093 mach->add_req( s->_leaf ); // Add leaf pointer 2094 return; // Bail out 2095 } 2096 2097 if( s->_leaf->is_Load() ) { 2098 assert( mem == (Node*)1, "multiple Memories being matched at once?" ); 2099 mem = s->_leaf->in(MemNode::Memory); 2100 debug_only(_mem_node = s->_leaf;) 2101 } 2102 2103 handle_precedence_edges(s->_leaf, mach); 2104 2105 if( s->_leaf->in(0) && s->_leaf->req() > 1) { 2106 if( !mach->in(0) ) 2107 mach->set_req(0,s->_leaf->in(0)); 2108 else { 2109 assert( s->_leaf->in(0) == mach->in(0), "same instruction, differing controls?" ); 2110 } 2111 } 2112 2113 for (uint i = 0; kid != nullptr && i < 2; kid = s->_kids[1], i++) { // binary tree 2114 int newrule; 2115 if( i == 0) { 2116 newrule = kid->rule(_leftOp[rule]); 2117 } else { 2118 newrule = kid->rule(_rightOp[rule]); 2119 } 2120 2121 if (newrule < _LAST_MACH_OPER) { // Operand or instruction? 2122 // Internal operand; recurse but do nothing else 2123 ReduceOper(kid, newrule, mem, mach); 2124 2125 } else { // Child is a new instruction 2126 // Reduce the instruction, and add a direct pointer from this 2127 // machine instruction to the newly reduced one. 2128 Node *mem1 = (Node*)1; 2129 debug_only(Node *save_mem_node = _mem_node;) 2130 mach->add_req( ReduceInst( kid, newrule, mem1 ) ); 2131 debug_only(_mem_node = save_mem_node;) 2132 } 2133 } 2134 } 2135 2136 2137 // ------------------------------------------------------------------------- 2138 // Java-Java calling convention 2139 // (what you use when Java calls Java) 2140 2141 //------------------------------find_receiver---------------------------------- 2142 // For a given signature, return the OptoReg for parameter 0. 2143 OptoReg::Name Matcher::find_receiver() { 2144 VMRegPair regs; 2145 BasicType sig_bt = T_OBJECT; 2146 SharedRuntime::java_calling_convention(&sig_bt, ®s, 1); 2147 // Return argument 0 register. In the LP64 build pointers 2148 // take 2 registers, but the VM wants only the 'main' name. 2149 return OptoReg::as_OptoReg(regs.first()); 2150 } 2151 2152 bool Matcher::is_vshift_con_pattern(Node* n, Node* m) { 2153 if (n != nullptr && m != nullptr) { 2154 return VectorNode::is_vector_shift(n) && 2155 VectorNode::is_vector_shift_count(m) && m->in(1)->is_Con(); 2156 } 2157 return false; 2158 } 2159 2160 bool Matcher::clone_node(Node* n, Node* m, Matcher::MStack& mstack) { 2161 // Must clone all producers of flags, or we will not match correctly. 2162 // Suppose a compare setting int-flags is shared (e.g., a switch-tree) 2163 // then it will match into an ideal Op_RegFlags. Alas, the fp-flags 2164 // are also there, so we may match a float-branch to int-flags and 2165 // expect the allocator to haul the flags from the int-side to the 2166 // fp-side. No can do. 2167 if (_must_clone[m->Opcode()]) { 2168 mstack.push(m, Visit); 2169 return true; 2170 } 2171 return pd_clone_node(n, m, mstack); 2172 } 2173 2174 bool Matcher::clone_base_plus_offset_address(AddPNode* m, Matcher::MStack& mstack, VectorSet& address_visited) { 2175 Node *off = m->in(AddPNode::Offset); 2176 if (off->is_Con()) { 2177 address_visited.test_set(m->_idx); // Flag as address_visited 2178 mstack.push(m->in(AddPNode::Address), Pre_Visit); 2179 // Clone X+offset as it also folds into most addressing expressions 2180 mstack.push(off, Visit); 2181 mstack.push(m->in(AddPNode::Base), Pre_Visit); 2182 return true; 2183 } 2184 return false; 2185 } 2186 2187 // A method-klass-holder may be passed in the inline_cache_reg 2188 // and then expanded into the inline_cache_reg and a method_ptr register 2189 // defined in ad_<arch>.cpp 2190 2191 //------------------------------find_shared------------------------------------ 2192 // Set bits if Node is shared or otherwise a root 2193 void Matcher::find_shared(Node* n) { 2194 // Allocate stack of size C->live_nodes() * 2 to avoid frequent realloc 2195 MStack mstack(C->live_nodes() * 2); 2196 // Mark nodes as address_visited if they are inputs to an address expression 2197 VectorSet address_visited; 2198 mstack.push(n, Visit); // Don't need to pre-visit root node 2199 while (mstack.is_nonempty()) { 2200 n = mstack.node(); // Leave node on stack 2201 Node_State nstate = mstack.state(); 2202 uint nop = n->Opcode(); 2203 if (nstate == Pre_Visit) { 2204 if (address_visited.test(n->_idx)) { // Visited in address already? 2205 // Flag as visited and shared now. 2206 set_visited(n); 2207 } 2208 if (is_visited(n)) { // Visited already? 2209 // Node is shared and has no reason to clone. Flag it as shared. 2210 // This causes it to match into a register for the sharing. 2211 set_shared(n); // Flag as shared and 2212 if (n->is_DecodeNarrowPtr()) { 2213 // Oop field/array element loads must be shared but since 2214 // they are shared through a DecodeN they may appear to have 2215 // a single use so force sharing here. 2216 set_shared(n->in(1)); 2217 } 2218 mstack.pop(); // remove node from stack 2219 continue; 2220 } 2221 nstate = Visit; // Not already visited; so visit now 2222 } 2223 if (nstate == Visit) { 2224 mstack.set_state(Post_Visit); 2225 set_visited(n); // Flag as visited now 2226 bool mem_op = false; 2227 int mem_addr_idx = MemNode::Address; 2228 if (find_shared_visit(mstack, n, nop, mem_op, mem_addr_idx)) { 2229 continue; 2230 } 2231 for (int i = n->len() - 1; i >= 0; --i) { // For my children 2232 Node* m = n->in(i); // Get ith input 2233 if (m == nullptr) { 2234 continue; // Ignore nulls 2235 } 2236 if (clone_node(n, m, mstack)) { 2237 continue; 2238 } 2239 2240 // Clone addressing expressions as they are "free" in memory access instructions 2241 if (mem_op && i == mem_addr_idx && m->is_AddP() && 2242 // When there are other uses besides address expressions 2243 // put it on stack and mark as shared. 2244 !is_visited(m)) { 2245 // Some inputs for address expression are not put on stack 2246 // to avoid marking them as shared and forcing them into register 2247 // if they are used only in address expressions. 2248 // But they should be marked as shared if there are other uses 2249 // besides address expressions. 2250 2251 if (pd_clone_address_expressions(m->as_AddP(), mstack, address_visited)) { 2252 continue; 2253 } 2254 } // if( mem_op && 2255 mstack.push(m, Pre_Visit); 2256 } // for(int i = ...) 2257 } 2258 else if (nstate == Alt_Post_Visit) { 2259 mstack.pop(); // Remove node from stack 2260 // We cannot remove the Cmp input from the Bool here, as the Bool may be 2261 // shared and all users of the Bool need to move the Cmp in parallel. 2262 // This leaves both the Bool and the If pointing at the Cmp. To 2263 // prevent the Matcher from trying to Match the Cmp along both paths 2264 // BoolNode::match_edge always returns a zero. 2265 2266 // We reorder the Op_If in a pre-order manner, so we can visit without 2267 // accidentally sharing the Cmp (the Bool and the If make 2 users). 2268 n->add_req( n->in(1)->in(1) ); // Add the Cmp next to the Bool 2269 } 2270 else if (nstate == Post_Visit) { 2271 mstack.pop(); // Remove node from stack 2272 2273 // Now hack a few special opcodes 2274 uint opcode = n->Opcode(); 2275 bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->matcher_find_shared_post_visit(this, n, opcode); 2276 if (!gc_handled) { 2277 find_shared_post_visit(n, opcode); 2278 } 2279 } 2280 else { 2281 ShouldNotReachHere(); 2282 } 2283 } // end of while (mstack.is_nonempty()) 2284 } 2285 2286 bool Matcher::find_shared_visit(MStack& mstack, Node* n, uint opcode, bool& mem_op, int& mem_addr_idx) { 2287 switch(opcode) { // Handle some opcodes special 2288 case Op_Phi: // Treat Phis as shared roots 2289 case Op_Parm: 2290 case Op_Proj: // All handled specially during matching 2291 case Op_SafePointScalarObject: 2292 set_shared(n); 2293 set_dontcare(n); 2294 break; 2295 case Op_If: 2296 case Op_CountedLoopEnd: 2297 mstack.set_state(Alt_Post_Visit); // Alternative way 2298 // Convert (If (Bool (CmpX A B))) into (If (Bool) (CmpX A B)). Helps 2299 // with matching cmp/branch in 1 instruction. The Matcher needs the 2300 // Bool and CmpX side-by-side, because it can only get at constants 2301 // that are at the leaves of Match trees, and the Bool's condition acts 2302 // as a constant here. 2303 mstack.push(n->in(1), Visit); // Clone the Bool 2304 mstack.push(n->in(0), Pre_Visit); // Visit control input 2305 return true; // while (mstack.is_nonempty()) 2306 case Op_ConvI2D: // These forms efficiently match with a prior 2307 case Op_ConvI2F: // Load but not a following Store 2308 if( n->in(1)->is_Load() && // Prior load 2309 n->outcnt() == 1 && // Not already shared 2310 n->unique_out()->is_Store() ) // Following store 2311 set_shared(n); // Force it to be a root 2312 break; 2313 case Op_ReverseBytesI: 2314 case Op_ReverseBytesL: 2315 if( n->in(1)->is_Load() && // Prior load 2316 n->outcnt() == 1 ) // Not already shared 2317 set_shared(n); // Force it to be a root 2318 break; 2319 case Op_BoxLock: // Can't match until we get stack-regs in ADLC 2320 case Op_IfFalse: 2321 case Op_IfTrue: 2322 case Op_MachProj: 2323 case Op_MergeMem: 2324 case Op_Catch: 2325 case Op_CatchProj: 2326 case Op_CProj: 2327 case Op_JumpProj: 2328 case Op_JProj: 2329 case Op_NeverBranch: 2330 set_dontcare(n); 2331 break; 2332 case Op_Jump: 2333 mstack.push(n->in(1), Pre_Visit); // Switch Value (could be shared) 2334 mstack.push(n->in(0), Pre_Visit); // Visit Control input 2335 return true; // while (mstack.is_nonempty()) 2336 case Op_StrComp: 2337 case Op_StrEquals: 2338 case Op_StrIndexOf: 2339 case Op_StrIndexOfChar: 2340 case Op_AryEq: 2341 case Op_VectorizedHashCode: 2342 case Op_CountPositives: 2343 case Op_StrInflatedCopy: 2344 case Op_StrCompressedCopy: 2345 case Op_EncodeISOArray: 2346 case Op_FmaD: 2347 case Op_FmaF: 2348 case Op_FmaVD: 2349 case Op_FmaVF: 2350 case Op_MacroLogicV: 2351 case Op_VectorCmpMasked: 2352 case Op_CompressV: 2353 case Op_CompressM: 2354 case Op_ExpandV: 2355 case Op_VectorLoadMask: 2356 set_shared(n); // Force result into register (it will be anyways) 2357 break; 2358 case Op_ConP: { // Convert pointers above the centerline to NUL 2359 TypeNode *tn = n->as_Type(); // Constants derive from type nodes 2360 const TypePtr* tp = tn->type()->is_ptr(); 2361 if (tp->_ptr == TypePtr::AnyNull) { 2362 tn->set_type(TypePtr::NULL_PTR); 2363 } 2364 break; 2365 } 2366 case Op_ConN: { // Convert narrow pointers above the centerline to NUL 2367 TypeNode *tn = n->as_Type(); // Constants derive from type nodes 2368 const TypePtr* tp = tn->type()->make_ptr(); 2369 if (tp && tp->_ptr == TypePtr::AnyNull) { 2370 tn->set_type(TypeNarrowOop::NULL_PTR); 2371 } 2372 break; 2373 } 2374 case Op_Binary: // These are introduced in the Post_Visit state. 2375 ShouldNotReachHere(); 2376 break; 2377 case Op_ClearArray: 2378 case Op_SafePoint: 2379 mem_op = true; 2380 break; 2381 default: 2382 if( n->is_Store() ) { 2383 // Do match stores, despite no ideal reg 2384 mem_op = true; 2385 break; 2386 } 2387 if( n->is_Mem() ) { // Loads and LoadStores 2388 mem_op = true; 2389 // Loads must be root of match tree due to prior load conflict 2390 if( C->subsume_loads() == false ) 2391 set_shared(n); 2392 } 2393 // Fall into default case 2394 if( !n->ideal_reg() ) 2395 set_dontcare(n); // Unmatchable Nodes 2396 } // end_switch 2397 return false; 2398 } 2399 2400 void Matcher::find_shared_post_visit(Node* n, uint opcode) { 2401 if (n->is_predicated_vector()) { 2402 // Restructure into binary trees for Matching. 2403 if (n->req() == 4) { 2404 n->set_req(1, new BinaryNode(n->in(1), n->in(2))); 2405 n->set_req(2, n->in(3)); 2406 n->del_req(3); 2407 } else if (n->req() == 5) { 2408 n->set_req(1, new BinaryNode(n->in(1), n->in(2))); 2409 n->set_req(2, new BinaryNode(n->in(3), n->in(4))); 2410 n->del_req(4); 2411 n->del_req(3); 2412 } else if (n->req() == 6) { 2413 Node* b3 = new BinaryNode(n->in(4), n->in(5)); 2414 Node* b2 = new BinaryNode(n->in(3), b3); 2415 Node* b1 = new BinaryNode(n->in(2), b2); 2416 n->set_req(2, b1); 2417 n->del_req(5); 2418 n->del_req(4); 2419 n->del_req(3); 2420 } 2421 return; 2422 } 2423 2424 switch(opcode) { // Handle some opcodes special 2425 case Op_CompareAndExchangeB: 2426 case Op_CompareAndExchangeS: 2427 case Op_CompareAndExchangeI: 2428 case Op_CompareAndExchangeL: 2429 case Op_CompareAndExchangeP: 2430 case Op_CompareAndExchangeN: 2431 case Op_WeakCompareAndSwapB: 2432 case Op_WeakCompareAndSwapS: 2433 case Op_WeakCompareAndSwapI: 2434 case Op_WeakCompareAndSwapL: 2435 case Op_WeakCompareAndSwapP: 2436 case Op_WeakCompareAndSwapN: 2437 case Op_CompareAndSwapB: 2438 case Op_CompareAndSwapS: 2439 case Op_CompareAndSwapI: 2440 case Op_CompareAndSwapL: 2441 case Op_CompareAndSwapP: 2442 case Op_CompareAndSwapN: { // Convert trinary to binary-tree 2443 Node* newval = n->in(MemNode::ValueIn); 2444 Node* oldval = n->in(LoadStoreConditionalNode::ExpectedIn); 2445 Node* pair = new BinaryNode(oldval, newval); 2446 n->set_req(MemNode::ValueIn, pair); 2447 n->del_req(LoadStoreConditionalNode::ExpectedIn); 2448 break; 2449 } 2450 case Op_CMoveD: // Convert trinary to binary-tree 2451 case Op_CMoveF: 2452 case Op_CMoveI: 2453 case Op_CMoveL: 2454 case Op_CMoveN: 2455 case Op_CMoveP: { 2456 // Restructure into a binary tree for Matching. It's possible that 2457 // we could move this code up next to the graph reshaping for IfNodes 2458 // or vice-versa, but I do not want to debug this for Ladybird. 2459 // 10/2/2000 CNC. 2460 Node* pair1 = new BinaryNode(n->in(1), n->in(1)->in(1)); 2461 n->set_req(1, pair1); 2462 Node* pair2 = new BinaryNode(n->in(2), n->in(3)); 2463 n->set_req(2, pair2); 2464 n->del_req(3); 2465 break; 2466 } 2467 case Op_MacroLogicV: { 2468 Node* pair1 = new BinaryNode(n->in(1), n->in(2)); 2469 Node* pair2 = new BinaryNode(n->in(3), n->in(4)); 2470 n->set_req(1, pair1); 2471 n->set_req(2, pair2); 2472 n->del_req(4); 2473 n->del_req(3); 2474 break; 2475 } 2476 case Op_StoreVectorMasked: { 2477 Node* pair = new BinaryNode(n->in(3), n->in(4)); 2478 n->set_req(3, pair); 2479 n->del_req(4); 2480 break; 2481 } 2482 case Op_SelectFromTwoVector: 2483 case Op_LoopLimit: { 2484 Node* pair1 = new BinaryNode(n->in(1), n->in(2)); 2485 n->set_req(1, pair1); 2486 n->set_req(2, n->in(3)); 2487 n->del_req(3); 2488 break; 2489 } 2490 case Op_StrEquals: 2491 case Op_StrIndexOfChar: { 2492 Node* pair1 = new BinaryNode(n->in(2), n->in(3)); 2493 n->set_req(2, pair1); 2494 n->set_req(3, n->in(4)); 2495 n->del_req(4); 2496 break; 2497 } 2498 case Op_StrComp: 2499 case Op_StrIndexOf: 2500 case Op_VectorizedHashCode: { 2501 Node* pair1 = new BinaryNode(n->in(2), n->in(3)); 2502 n->set_req(2, pair1); 2503 Node* pair2 = new BinaryNode(n->in(4),n->in(5)); 2504 n->set_req(3, pair2); 2505 n->del_req(5); 2506 n->del_req(4); 2507 break; 2508 } 2509 case Op_EncodeISOArray: 2510 case Op_StrCompressedCopy: 2511 case Op_StrInflatedCopy: { 2512 // Restructure into a binary tree for Matching. 2513 Node* pair = new BinaryNode(n->in(3), n->in(4)); 2514 n->set_req(3, pair); 2515 n->del_req(4); 2516 break; 2517 } 2518 case Op_FmaD: 2519 case Op_FmaF: 2520 case Op_FmaVD: 2521 case Op_FmaVF: { 2522 // Restructure into a binary tree for Matching. 2523 Node* pair = new BinaryNode(n->in(1), n->in(2)); 2524 n->set_req(2, pair); 2525 n->set_req(1, n->in(3)); 2526 n->del_req(3); 2527 break; 2528 } 2529 case Op_MulAddS2I: { 2530 Node* pair1 = new BinaryNode(n->in(1), n->in(2)); 2531 Node* pair2 = new BinaryNode(n->in(3), n->in(4)); 2532 n->set_req(1, pair1); 2533 n->set_req(2, pair2); 2534 n->del_req(4); 2535 n->del_req(3); 2536 break; 2537 } 2538 case Op_ClearArray: { 2539 Node* pair = new BinaryNode(n->in(2), n->in(3)); 2540 n->set_req(2, pair); 2541 n->set_req(3, n->in(4)); 2542 n->del_req(4); 2543 break; 2544 } 2545 case Op_VectorCmpMasked: 2546 case Op_CopySignD: 2547 case Op_SignumVF: 2548 case Op_SignumVD: 2549 case Op_SignumF: 2550 case Op_SignumD: { 2551 Node* pair = new BinaryNode(n->in(2), n->in(3)); 2552 n->set_req(2, pair); 2553 n->del_req(3); 2554 break; 2555 } 2556 case Op_VectorBlend: 2557 case Op_VectorInsert: { 2558 Node* pair = new BinaryNode(n->in(1), n->in(2)); 2559 n->set_req(1, pair); 2560 n->set_req(2, n->in(3)); 2561 n->del_req(3); 2562 break; 2563 } 2564 case Op_LoadVectorGather: 2565 if (is_subword_type(n->bottom_type()->is_vect()->element_basic_type())) { 2566 Node* pair = new BinaryNode(n->in(MemNode::ValueIn), n->in(MemNode::ValueIn+1)); 2567 n->set_req(MemNode::ValueIn, pair); 2568 n->del_req(MemNode::ValueIn+1); 2569 } 2570 break; 2571 case Op_LoadVectorGatherMasked: 2572 if (is_subword_type(n->bottom_type()->is_vect()->element_basic_type())) { 2573 Node* pair2 = new BinaryNode(n->in(MemNode::ValueIn + 1), n->in(MemNode::ValueIn + 2)); 2574 Node* pair1 = new BinaryNode(n->in(MemNode::ValueIn), pair2); 2575 n->set_req(MemNode::ValueIn, pair1); 2576 n->del_req(MemNode::ValueIn+2); 2577 n->del_req(MemNode::ValueIn+1); 2578 break; 2579 } // fall-through 2580 case Op_StoreVectorScatter: { 2581 Node* pair = new BinaryNode(n->in(MemNode::ValueIn), n->in(MemNode::ValueIn+1)); 2582 n->set_req(MemNode::ValueIn, pair); 2583 n->del_req(MemNode::ValueIn+1); 2584 break; 2585 } 2586 case Op_StoreVectorScatterMasked: { 2587 Node* pair = new BinaryNode(n->in(MemNode::ValueIn+1), n->in(MemNode::ValueIn+2)); 2588 n->set_req(MemNode::ValueIn+1, pair); 2589 n->del_req(MemNode::ValueIn+2); 2590 pair = new BinaryNode(n->in(MemNode::ValueIn), n->in(MemNode::ValueIn+1)); 2591 n->set_req(MemNode::ValueIn, pair); 2592 n->del_req(MemNode::ValueIn+1); 2593 break; 2594 } 2595 case Op_VectorMaskCmp: { 2596 n->set_req(1, new BinaryNode(n->in(1), n->in(2))); 2597 n->set_req(2, n->in(3)); 2598 n->del_req(3); 2599 break; 2600 } 2601 case Op_PartialSubtypeCheck: { 2602 if (UseSecondarySupersTable && n->in(2)->is_Con()) { 2603 // PartialSubtypeCheck uses both constant and register operands for superclass input. 2604 n->set_req(2, new BinaryNode(n->in(2), n->in(2))); 2605 break; 2606 } 2607 break; 2608 } 2609 case Op_StoreLSpecial: { 2610 if (n->req() > (MemNode::ValueIn + 1) && n->in(MemNode::ValueIn + 1) != nullptr) { 2611 Node* pair = new BinaryNode(n->in(MemNode::ValueIn), n->in(MemNode::ValueIn + 1)); 2612 n->set_req(MemNode::ValueIn, pair); 2613 n->del_req(MemNode::ValueIn + 1); 2614 } 2615 break; 2616 } 2617 default: 2618 break; 2619 } 2620 } 2621 2622 #ifndef PRODUCT 2623 void Matcher::record_new2old(Node* newn, Node* old) { 2624 _new2old_map.map(newn->_idx, old); 2625 if (!_reused.test_set(old->_igv_idx)) { 2626 // Reuse the Ideal-level IGV identifier so that the node can be tracked 2627 // across matching. If there are multiple machine nodes expanded from the 2628 // same Ideal node, only one will reuse its IGV identifier. 2629 newn->_igv_idx = old->_igv_idx; 2630 } 2631 } 2632 2633 // machine-independent root to machine-dependent root 2634 void Matcher::dump_old2new_map() { 2635 _old2new_map.dump(); 2636 } 2637 #endif // !PRODUCT 2638 2639 //---------------------------collect_null_checks------------------------------- 2640 // Find null checks in the ideal graph; write a machine-specific node for 2641 // it. Used by later implicit-null-check handling. Actually collects 2642 // either an IfTrue or IfFalse for the common NOT-null path, AND the ideal 2643 // value being tested. 2644 void Matcher::collect_null_checks( Node *proj, Node *orig_proj ) { 2645 Node *iff = proj->in(0); 2646 if( iff->Opcode() == Op_If ) { 2647 // During matching If's have Bool & Cmp side-by-side 2648 BoolNode *b = iff->in(1)->as_Bool(); 2649 Node *cmp = iff->in(2); 2650 int opc = cmp->Opcode(); 2651 if (opc != Op_CmpP && opc != Op_CmpN) return; 2652 2653 const Type* ct = cmp->in(2)->bottom_type(); 2654 if (ct == TypePtr::NULL_PTR || 2655 (opc == Op_CmpN && ct == TypeNarrowOop::NULL_PTR)) { 2656 2657 bool push_it = false; 2658 if( proj->Opcode() == Op_IfTrue ) { 2659 #ifndef PRODUCT 2660 extern uint all_null_checks_found; 2661 all_null_checks_found++; 2662 #endif 2663 if( b->_test._test == BoolTest::ne ) { 2664 push_it = true; 2665 } 2666 } else { 2667 assert( proj->Opcode() == Op_IfFalse, "" ); 2668 if( b->_test._test == BoolTest::eq ) { 2669 push_it = true; 2670 } 2671 } 2672 if( push_it ) { 2673 _null_check_tests.push(proj); 2674 Node* val = cmp->in(1); 2675 #ifdef _LP64 2676 if (val->bottom_type()->isa_narrowoop() && 2677 !Matcher::narrow_oop_use_complex_address()) { 2678 // 2679 // Look for DecodeN node which should be pinned to orig_proj. 2680 // On platforms (Sparc) which can not handle 2 adds 2681 // in addressing mode we have to keep a DecodeN node and 2682 // use it to do implicit null check in address. 2683 // 2684 // DecodeN node was pinned to non-null path (orig_proj) during 2685 // CastPP transformation in final_graph_reshaping_impl(). 2686 // 2687 uint cnt = orig_proj->outcnt(); 2688 for (uint i = 0; i < orig_proj->outcnt(); i++) { 2689 Node* d = orig_proj->raw_out(i); 2690 if (d->is_DecodeN() && d->in(1) == val) { 2691 val = d; 2692 val->set_req(0, nullptr); // Unpin now. 2693 // Mark this as special case to distinguish from 2694 // a regular case: CmpP(DecodeN, null). 2695 val = (Node*)(((intptr_t)val) | 1); 2696 break; 2697 } 2698 } 2699 } 2700 #endif 2701 _null_check_tests.push(val); 2702 } 2703 } 2704 } 2705 } 2706 2707 //---------------------------validate_null_checks------------------------------ 2708 // Its possible that the value being null checked is not the root of a match 2709 // tree. If so, I cannot use the value in an implicit null check. 2710 void Matcher::validate_null_checks( ) { 2711 uint cnt = _null_check_tests.size(); 2712 for( uint i=0; i < cnt; i+=2 ) { 2713 Node *test = _null_check_tests[i]; 2714 Node *val = _null_check_tests[i+1]; 2715 bool is_decoden = ((intptr_t)val) & 1; 2716 val = (Node*)(((intptr_t)val) & ~1); 2717 if (has_new_node(val)) { 2718 Node* new_val = new_node(val); 2719 if (is_decoden) { 2720 assert(val->is_DecodeNarrowPtr() && val->in(0) == nullptr, "sanity"); 2721 // Note: new_val may have a control edge if 2722 // the original ideal node DecodeN was matched before 2723 // it was unpinned in Matcher::collect_null_checks(). 2724 // Unpin the mach node and mark it. 2725 new_val->set_req(0, nullptr); 2726 new_val = (Node*)(((intptr_t)new_val) | 1); 2727 } 2728 // Is a match-tree root, so replace with the matched value 2729 _null_check_tests.map(i+1, new_val); 2730 } else { 2731 // Yank from candidate list 2732 _null_check_tests.map(i+1,_null_check_tests[--cnt]); 2733 _null_check_tests.map(i,_null_check_tests[--cnt]); 2734 _null_check_tests.pop(); 2735 _null_check_tests.pop(); 2736 i-=2; 2737 } 2738 } 2739 } 2740 2741 bool Matcher::gen_narrow_oop_implicit_null_checks() { 2742 // Advice matcher to perform null checks on the narrow oop side. 2743 // Implicit checks are not possible on the uncompressed oop side anyway 2744 // (at least not for read accesses). 2745 // Performs significantly better (especially on Power 6). 2746 if (!os::zero_page_read_protected()) { 2747 return true; 2748 } 2749 return CompressedOops::use_implicit_null_checks() && 2750 (narrow_oop_use_complex_address() || 2751 CompressedOops::base() != nullptr); 2752 } 2753 2754 // Compute RegMask for an ideal register. 2755 const RegMask* Matcher::regmask_for_ideal_register(uint ideal_reg, Node* ret) { 2756 assert(!C->failing_internal() || C->failure_is_artificial(), "already failing."); 2757 if (C->failing()) { 2758 return nullptr; 2759 } 2760 const Type* t = Type::mreg2type[ideal_reg]; 2761 if (t == nullptr) { 2762 assert(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ, "not a vector: %d", ideal_reg); 2763 return nullptr; // not supported 2764 } 2765 Node* fp = ret->in(TypeFunc::FramePtr); 2766 Node* mem = ret->in(TypeFunc::Memory); 2767 const TypePtr* atp = TypePtr::BOTTOM; 2768 MemNode::MemOrd mo = MemNode::unordered; 2769 2770 Node* spill; 2771 switch (ideal_reg) { 2772 case Op_RegN: spill = new LoadNNode(nullptr, mem, fp, atp, t->is_narrowoop(), mo); break; 2773 case Op_RegI: spill = new LoadINode(nullptr, mem, fp, atp, t->is_int(), mo); break; 2774 case Op_RegP: spill = new LoadPNode(nullptr, mem, fp, atp, t->is_ptr(), mo); break; 2775 case Op_RegF: spill = new LoadFNode(nullptr, mem, fp, atp, t, mo); break; 2776 case Op_RegD: spill = new LoadDNode(nullptr, mem, fp, atp, t, mo); break; 2777 case Op_RegL: spill = new LoadLNode(nullptr, mem, fp, atp, t->is_long(), mo); break; 2778 2779 case Op_VecA: // fall-through 2780 case Op_VecS: // fall-through 2781 case Op_VecD: // fall-through 2782 case Op_VecX: // fall-through 2783 case Op_VecY: // fall-through 2784 case Op_VecZ: spill = new LoadVectorNode(nullptr, mem, fp, atp, t->is_vect()); break; 2785 case Op_RegVectMask: return Matcher::predicate_reg_mask(); 2786 2787 default: ShouldNotReachHere(); 2788 } 2789 MachNode* mspill = match_tree(spill); 2790 assert(mspill != nullptr || C->failure_is_artificial(), "matching failed: %d", ideal_reg); 2791 if (C->failing()) { 2792 return nullptr; 2793 } 2794 // Handle generic vector operand case 2795 if (Matcher::supports_generic_vector_operands && t->isa_vect()) { 2796 specialize_mach_node(mspill); 2797 } 2798 return &mspill->out_RegMask(); 2799 } 2800 2801 // Process Mach IR right after selection phase is over. 2802 void Matcher::do_postselect_cleanup() { 2803 if (supports_generic_vector_operands) { 2804 specialize_generic_vector_operands(); 2805 if (C->failing()) return; 2806 } 2807 } 2808 2809 //---------------------------------------------------------------------- 2810 // Generic machine operands elision. 2811 //---------------------------------------------------------------------- 2812 2813 // Compute concrete vector operand for a generic TEMP vector mach node based on its user info. 2814 void Matcher::specialize_temp_node(MachTempNode* tmp, MachNode* use, uint idx) { 2815 assert(use->in(idx) == tmp, "not a user"); 2816 assert(!Matcher::is_generic_vector(use->_opnds[0]), "use not processed yet"); 2817 2818 if ((uint)idx == use->two_adr()) { // DEF_TEMP case 2819 tmp->_opnds[0] = use->_opnds[0]->clone(); 2820 } else { 2821 uint ideal_vreg = vector_ideal_reg(C->max_vector_size()); 2822 tmp->_opnds[0] = Matcher::pd_specialize_generic_vector_operand(tmp->_opnds[0], ideal_vreg, true /*is_temp*/); 2823 } 2824 } 2825 2826 // Compute concrete vector operand for a generic DEF/USE vector operand (of mach node m at index idx). 2827 MachOper* Matcher::specialize_vector_operand(MachNode* m, uint opnd_idx) { 2828 assert(Matcher::is_generic_vector(m->_opnds[opnd_idx]), "repeated updates"); 2829 Node* def = nullptr; 2830 if (opnd_idx == 0) { // DEF 2831 def = m; // use mach node itself to compute vector operand type 2832 } else { 2833 int base_idx = m->operand_index(opnd_idx); 2834 def = m->in(base_idx); 2835 if (def->is_Mach()) { 2836 if (def->is_MachTemp() && Matcher::is_generic_vector(def->as_Mach()->_opnds[0])) { 2837 specialize_temp_node(def->as_MachTemp(), m, base_idx); // MachTemp node use site 2838 } else if (is_reg2reg_move(def->as_Mach())) { 2839 def = def->in(1); // skip over generic reg-to-reg moves 2840 } 2841 } 2842 } 2843 assert(def->bottom_type()->isa_vect(), "not a vector"); 2844 uint ideal_vreg = def->bottom_type()->ideal_reg(); 2845 return Matcher::pd_specialize_generic_vector_operand(m->_opnds[opnd_idx], ideal_vreg, false /*is_temp*/); 2846 } 2847 2848 void Matcher::specialize_mach_node(MachNode* m) { 2849 assert(!m->is_MachTemp(), "processed along with its user"); 2850 // For generic use operands pull specific register class operands from 2851 // its def instruction's output operand (def operand). 2852 for (uint i = 0; i < m->num_opnds(); i++) { 2853 if (Matcher::is_generic_vector(m->_opnds[i])) { 2854 m->_opnds[i] = specialize_vector_operand(m, i); 2855 } 2856 } 2857 } 2858 2859 // Replace generic vector operands with concrete vector operands and eliminate generic reg-to-reg moves from the graph. 2860 void Matcher::specialize_generic_vector_operands() { 2861 assert(supports_generic_vector_operands, "sanity"); 2862 ResourceMark rm; 2863 2864 // Replace generic vector operands (vec/legVec) with concrete ones (vec[SDXYZ]/legVec[SDXYZ]) 2865 // and remove reg-to-reg vector moves (MoveVec2Leg and MoveLeg2Vec). 2866 Unique_Node_List live_nodes; 2867 C->identify_useful_nodes(live_nodes); 2868 2869 while (live_nodes.size() > 0) { 2870 MachNode* m = live_nodes.pop()->isa_Mach(); 2871 if (m != nullptr) { 2872 if (Matcher::is_reg2reg_move(m)) { 2873 // Register allocator properly handles vec <=> leg moves using register masks. 2874 int opnd_idx = m->operand_index(1); 2875 Node* def = m->in(opnd_idx); 2876 m->subsume_by(def, C); 2877 } else if (m->is_MachTemp()) { 2878 // process MachTemp nodes at use site (see Matcher::specialize_vector_operand) 2879 } else { 2880 specialize_mach_node(m); 2881 } 2882 } 2883 } 2884 } 2885 2886 uint Matcher::vector_length(const Node* n) { 2887 const TypeVect* vt = n->bottom_type()->is_vect(); 2888 return vt->length(); 2889 } 2890 2891 uint Matcher::vector_length(const MachNode* use, const MachOper* opnd) { 2892 int def_idx = use->operand_index(opnd); 2893 Node* def = use->in(def_idx); 2894 return def->bottom_type()->is_vect()->length(); 2895 } 2896 2897 uint Matcher::vector_length_in_bytes(const Node* n) { 2898 const TypeVect* vt = n->bottom_type()->is_vect(); 2899 return vt->length_in_bytes(); 2900 } 2901 2902 uint Matcher::vector_length_in_bytes(const MachNode* use, const MachOper* opnd) { 2903 uint def_idx = use->operand_index(opnd); 2904 Node* def = use->in(def_idx); 2905 return def->bottom_type()->is_vect()->length_in_bytes(); 2906 } 2907 2908 BasicType Matcher::vector_element_basic_type(const Node* n) { 2909 const TypeVect* vt = n->bottom_type()->is_vect(); 2910 return vt->element_basic_type(); 2911 } 2912 2913 BasicType Matcher::vector_element_basic_type(const MachNode* use, const MachOper* opnd) { 2914 int def_idx = use->operand_index(opnd); 2915 Node* def = use->in(def_idx); 2916 return def->bottom_type()->is_vect()->element_basic_type(); 2917 } 2918 2919 bool Matcher::is_non_long_integral_vector(const Node* n) { 2920 BasicType bt = vector_element_basic_type(n); 2921 assert(bt != T_CHAR, "char is not allowed in vector"); 2922 return is_subword_type(bt) || bt == T_INT; 2923 } 2924 2925 bool Matcher::is_encode_and_store_pattern(const Node* n, const Node* m) { 2926 if (n == nullptr || 2927 m == nullptr || 2928 n->Opcode() != Op_StoreN || 2929 !m->is_EncodeP() || 2930 n->as_Store()->barrier_data() == 0) { 2931 return false; 2932 } 2933 assert(m == n->in(MemNode::ValueIn), "m should be input to n"); 2934 return true; 2935 } 2936 2937 #ifdef ASSERT 2938 bool Matcher::verify_after_postselect_cleanup() { 2939 assert(!C->failing_internal() || C->failure_is_artificial(), "sanity"); 2940 if (supports_generic_vector_operands) { 2941 Unique_Node_List useful; 2942 C->identify_useful_nodes(useful); 2943 for (uint i = 0; i < useful.size(); i++) { 2944 MachNode* m = useful.at(i)->isa_Mach(); 2945 if (m != nullptr) { 2946 assert(!Matcher::is_reg2reg_move(m), "no MoveVec nodes allowed"); 2947 for (uint j = 0; j < m->num_opnds(); j++) { 2948 assert(!Matcher::is_generic_vector(m->_opnds[j]), "no generic vector operands allowed"); 2949 } 2950 } 2951 } 2952 } 2953 return true; 2954 } 2955 #endif // ASSERT 2956 2957 // Used by the DFA in dfa_xxx.cpp. Check for a following barrier or 2958 // atomic instruction acting as a store_load barrier without any 2959 // intervening volatile load, and thus we don't need a barrier here. 2960 // We retain the Node to act as a compiler ordering barrier. 2961 bool Matcher::post_store_load_barrier(const Node* vmb) { 2962 Compile* C = Compile::current(); 2963 assert(vmb->is_MemBar(), ""); 2964 assert(vmb->Opcode() != Op_MemBarAcquire && vmb->Opcode() != Op_LoadFence, ""); 2965 const MemBarNode* membar = vmb->as_MemBar(); 2966 2967 // Get the Ideal Proj node, ctrl, that can be used to iterate forward 2968 Node* ctrl = nullptr; 2969 for (DUIterator_Fast imax, i = membar->fast_outs(imax); i < imax; i++) { 2970 Node* p = membar->fast_out(i); 2971 assert(p->is_Proj(), "only projections here"); 2972 if ((p->as_Proj()->_con == TypeFunc::Control) && 2973 !C->node_arena()->contains(p)) { // Unmatched old-space only 2974 ctrl = p; 2975 break; 2976 } 2977 } 2978 assert((ctrl != nullptr), "missing control projection"); 2979 2980 for (DUIterator_Fast jmax, j = ctrl->fast_outs(jmax); j < jmax; j++) { 2981 Node *x = ctrl->fast_out(j); 2982 int xop = x->Opcode(); 2983 2984 // We don't need current barrier if we see another or a lock 2985 // before seeing volatile load. 2986 // 2987 // Op_Fastunlock previously appeared in the Op_* list below. 2988 // With the advent of 1-0 lock operations we're no longer guaranteed 2989 // that a monitor exit operation contains a serializing instruction. 2990 2991 if (xop == Op_MemBarVolatile || 2992 xop == Op_CompareAndExchangeB || 2993 xop == Op_CompareAndExchangeS || 2994 xop == Op_CompareAndExchangeI || 2995 xop == Op_CompareAndExchangeL || 2996 xop == Op_CompareAndExchangeP || 2997 xop == Op_CompareAndExchangeN || 2998 xop == Op_WeakCompareAndSwapB || 2999 xop == Op_WeakCompareAndSwapS || 3000 xop == Op_WeakCompareAndSwapL || 3001 xop == Op_WeakCompareAndSwapP || 3002 xop == Op_WeakCompareAndSwapN || 3003 xop == Op_WeakCompareAndSwapI || 3004 xop == Op_CompareAndSwapB || 3005 xop == Op_CompareAndSwapS || 3006 xop == Op_CompareAndSwapL || 3007 xop == Op_CompareAndSwapP || 3008 xop == Op_CompareAndSwapN || 3009 xop == Op_CompareAndSwapI || 3010 BarrierSet::barrier_set()->barrier_set_c2()->matcher_is_store_load_barrier(x, xop)) { 3011 return true; 3012 } 3013 3014 // Op_FastLock previously appeared in the Op_* list above. 3015 if (xop == Op_FastLock) { 3016 return true; 3017 } 3018 3019 if (x->is_MemBar()) { 3020 // We must retain this membar if there is an upcoming volatile 3021 // load, which will be followed by acquire membar. 3022 if (xop == Op_MemBarAcquire || xop == Op_LoadFence) { 3023 return false; 3024 } else { 3025 // For other kinds of barriers, check by pretending we 3026 // are them, and seeing if we can be removed. 3027 return post_store_load_barrier(x->as_MemBar()); 3028 } 3029 } 3030 3031 // probably not necessary to check for these 3032 if (x->is_Call() || x->is_SafePoint() || x->is_block_proj()) { 3033 return false; 3034 } 3035 } 3036 return false; 3037 } 3038 3039 // Check whether node n is a branch to an uncommon trap that we could 3040 // optimize as test with very high branch costs in case of going to 3041 // the uncommon trap. The code must be able to be recompiled to use 3042 // a cheaper test. 3043 bool Matcher::branches_to_uncommon_trap(const Node *n) { 3044 // Don't do it for natives, adapters, or runtime stubs 3045 Compile *C = Compile::current(); 3046 if (!C->is_method_compilation()) return false; 3047 3048 assert(n->is_If(), "You should only call this on if nodes."); 3049 IfNode *ifn = n->as_If(); 3050 3051 Node *ifFalse = nullptr; 3052 for (DUIterator_Fast imax, i = ifn->fast_outs(imax); i < imax; i++) { 3053 if (ifn->fast_out(i)->is_IfFalse()) { 3054 ifFalse = ifn->fast_out(i); 3055 break; 3056 } 3057 } 3058 assert(ifFalse, "An If should have an ifFalse. Graph is broken."); 3059 3060 Node *reg = ifFalse; 3061 int cnt = 4; // We must protect against cycles. Limit to 4 iterations. 3062 // Alternatively use visited set? Seems too expensive. 3063 while (reg != nullptr && cnt > 0) { 3064 CallNode *call = nullptr; 3065 RegionNode *nxt_reg = nullptr; 3066 for (DUIterator_Fast imax, i = reg->fast_outs(imax); i < imax; i++) { 3067 Node *o = reg->fast_out(i); 3068 if (o->is_Call()) { 3069 call = o->as_Call(); 3070 } 3071 if (o->is_Region()) { 3072 nxt_reg = o->as_Region(); 3073 } 3074 } 3075 3076 if (call && 3077 call->entry_point() == OptoRuntime::uncommon_trap_blob()->entry_point()) { 3078 const Type* trtype = call->in(TypeFunc::Parms)->bottom_type(); 3079 if (trtype->isa_int() && trtype->is_int()->is_con()) { 3080 jint tr_con = trtype->is_int()->get_con(); 3081 Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(tr_con); 3082 Deoptimization::DeoptAction action = Deoptimization::trap_request_action(tr_con); 3083 assert((int)reason < (int)BitsPerInt, "recode bit map"); 3084 3085 if (is_set_nth_bit(C->allowed_deopt_reasons(), (int)reason) 3086 && action != Deoptimization::Action_none) { 3087 // This uncommon trap is sure to recompile, eventually. 3088 // When that happens, C->too_many_traps will prevent 3089 // this transformation from happening again. 3090 return true; 3091 } 3092 } 3093 } 3094 3095 reg = nxt_reg; 3096 cnt--; 3097 } 3098 3099 return false; 3100 } 3101 3102 //============================================================================= 3103 //---------------------------State--------------------------------------------- 3104 State::State(void) : _rule() { 3105 #ifdef ASSERT 3106 _id = 0; 3107 _kids[0] = _kids[1] = (State*)(intptr_t) CONST64(0xcafebabecafebabe); 3108 _leaf = (Node*)(intptr_t) CONST64(0xbaadf00dbaadf00d); 3109 #endif 3110 } 3111 3112 #ifdef ASSERT 3113 State::~State() { 3114 _id = 99; 3115 _kids[0] = _kids[1] = (State*)(intptr_t) CONST64(0xcafebabecafebabe); 3116 _leaf = (Node*)(intptr_t) CONST64(0xbaadf00dbaadf00d); 3117 memset(_cost, -3, sizeof(_cost)); 3118 memset(_rule, -3, sizeof(_rule)); 3119 } 3120 #endif 3121 3122 #ifndef PRODUCT 3123 //---------------------------dump---------------------------------------------- 3124 void State::dump() { 3125 tty->print("\n"); 3126 dump(0); 3127 } 3128 3129 void State::dump(int depth) { 3130 for (int j = 0; j < depth; j++) { 3131 tty->print(" "); 3132 } 3133 tty->print("--N: "); 3134 _leaf->dump(); 3135 uint i; 3136 for (i = 0; i < _LAST_MACH_OPER; i++) { 3137 // Check for valid entry 3138 if (valid(i)) { 3139 for (int j = 0; j < depth; j++) { 3140 tty->print(" "); 3141 } 3142 assert(cost(i) != max_juint, "cost must be a valid value"); 3143 assert(rule(i) < _last_Mach_Node, "rule[i] must be valid rule"); 3144 tty->print_cr("%s %d %s", 3145 ruleName[i], cost(i), ruleName[rule(i)] ); 3146 } 3147 } 3148 tty->cr(); 3149 3150 for (i = 0; i < 2; i++) { 3151 if (_kids[i]) { 3152 _kids[i]->dump(depth + 1); 3153 } 3154 } 3155 } 3156 #endif