src/share/vm/opto/matcher.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "memory/allocation.inline.hpp"
aoqi@0 27 #include "opto/addnode.hpp"
aoqi@0 28 #include "opto/callnode.hpp"
aoqi@0 29 #include "opto/connode.hpp"
aoqi@0 30 #include "opto/idealGraphPrinter.hpp"
aoqi@0 31 #include "opto/matcher.hpp"
aoqi@0 32 #include "opto/memnode.hpp"
aoqi@0 33 #include "opto/opcodes.hpp"
aoqi@0 34 #include "opto/regmask.hpp"
aoqi@0 35 #include "opto/rootnode.hpp"
aoqi@0 36 #include "opto/runtime.hpp"
aoqi@0 37 #include "opto/type.hpp"
aoqi@0 38 #include "opto/vectornode.hpp"
aoqi@0 39 #include "runtime/atomic.hpp"
aoqi@0 40 #include "runtime/os.hpp"
aoqi@0 41 #ifdef TARGET_ARCH_MODEL_x86_32
aoqi@0 42 # include "adfiles/ad_x86_32.hpp"
aoqi@0 43 #endif
aoqi@0 44 #ifdef TARGET_ARCH_MODEL_x86_64
aoqi@0 45 # include "adfiles/ad_x86_64.hpp"
aoqi@0 46 #endif
aoqi@0 47 #ifdef TARGET_ARCH_MODEL_sparc
aoqi@0 48 # include "adfiles/ad_sparc.hpp"
aoqi@0 49 #endif
aoqi@0 50 #ifdef TARGET_ARCH_MODEL_zero
aoqi@0 51 # include "adfiles/ad_zero.hpp"
aoqi@0 52 #endif
aoqi@0 53 #ifdef TARGET_ARCH_MODEL_arm
aoqi@0 54 # include "adfiles/ad_arm.hpp"
aoqi@0 55 #endif
aoqi@0 56 #ifdef TARGET_ARCH_MODEL_ppc_32
aoqi@0 57 # include "adfiles/ad_ppc_32.hpp"
aoqi@0 58 #endif
aoqi@0 59 #ifdef TARGET_ARCH_MODEL_ppc_64
aoqi@0 60 # include "adfiles/ad_ppc_64.hpp"
aoqi@0 61 #endif
aoqi@0 62
aoqi@0 63 OptoReg::Name OptoReg::c_frame_pointer;
aoqi@0 64
aoqi@0 65 const RegMask *Matcher::idealreg2regmask[_last_machine_leaf];
aoqi@0 66 RegMask Matcher::mreg2regmask[_last_Mach_Reg];
aoqi@0 67 RegMask Matcher::STACK_ONLY_mask;
aoqi@0 68 RegMask Matcher::c_frame_ptr_mask;
aoqi@0 69 const uint Matcher::_begin_rematerialize = _BEGIN_REMATERIALIZE;
aoqi@0 70 const uint Matcher::_end_rematerialize = _END_REMATERIALIZE;
aoqi@0 71
aoqi@0 72 //---------------------------Matcher-------------------------------------------
aoqi@0 73 Matcher::Matcher()
aoqi@0 74 : PhaseTransform( Phase::Ins_Select ),
aoqi@0 75 #ifdef ASSERT
aoqi@0 76 _old2new_map(C->comp_arena()),
aoqi@0 77 _new2old_map(C->comp_arena()),
aoqi@0 78 #endif
aoqi@0 79 _shared_nodes(C->comp_arena()),
aoqi@0 80 _reduceOp(reduceOp), _leftOp(leftOp), _rightOp(rightOp),
aoqi@0 81 _swallowed(swallowed),
aoqi@0 82 _begin_inst_chain_rule(_BEGIN_INST_CHAIN_RULE),
aoqi@0 83 _end_inst_chain_rule(_END_INST_CHAIN_RULE),
aoqi@0 84 _must_clone(must_clone),
aoqi@0 85 _register_save_policy(register_save_policy),
aoqi@0 86 _c_reg_save_policy(c_reg_save_policy),
aoqi@0 87 _register_save_type(register_save_type),
aoqi@0 88 _ruleName(ruleName),
aoqi@0 89 _allocation_started(false),
aoqi@0 90 _states_arena(Chunk::medium_size),
aoqi@0 91 _visited(&_states_arena),
aoqi@0 92 _shared(&_states_arena),
aoqi@0 93 _dontcare(&_states_arena) {
aoqi@0 94 C->set_matcher(this);
aoqi@0 95
aoqi@0 96 idealreg2spillmask [Op_RegI] = NULL;
aoqi@0 97 idealreg2spillmask [Op_RegN] = NULL;
aoqi@0 98 idealreg2spillmask [Op_RegL] = NULL;
aoqi@0 99 idealreg2spillmask [Op_RegF] = NULL;
aoqi@0 100 idealreg2spillmask [Op_RegD] = NULL;
aoqi@0 101 idealreg2spillmask [Op_RegP] = NULL;
aoqi@0 102 idealreg2spillmask [Op_VecS] = NULL;
aoqi@0 103 idealreg2spillmask [Op_VecD] = NULL;
aoqi@0 104 idealreg2spillmask [Op_VecX] = NULL;
aoqi@0 105 idealreg2spillmask [Op_VecY] = NULL;
aoqi@0 106
aoqi@0 107 idealreg2debugmask [Op_RegI] = NULL;
aoqi@0 108 idealreg2debugmask [Op_RegN] = NULL;
aoqi@0 109 idealreg2debugmask [Op_RegL] = NULL;
aoqi@0 110 idealreg2debugmask [Op_RegF] = NULL;
aoqi@0 111 idealreg2debugmask [Op_RegD] = NULL;
aoqi@0 112 idealreg2debugmask [Op_RegP] = NULL;
aoqi@0 113 idealreg2debugmask [Op_VecS] = NULL;
aoqi@0 114 idealreg2debugmask [Op_VecD] = NULL;
aoqi@0 115 idealreg2debugmask [Op_VecX] = NULL;
aoqi@0 116 idealreg2debugmask [Op_VecY] = NULL;
aoqi@0 117
aoqi@0 118 idealreg2mhdebugmask[Op_RegI] = NULL;
aoqi@0 119 idealreg2mhdebugmask[Op_RegN] = NULL;
aoqi@0 120 idealreg2mhdebugmask[Op_RegL] = NULL;
aoqi@0 121 idealreg2mhdebugmask[Op_RegF] = NULL;
aoqi@0 122 idealreg2mhdebugmask[Op_RegD] = NULL;
aoqi@0 123 idealreg2mhdebugmask[Op_RegP] = NULL;
aoqi@0 124 idealreg2mhdebugmask[Op_VecS] = NULL;
aoqi@0 125 idealreg2mhdebugmask[Op_VecD] = NULL;
aoqi@0 126 idealreg2mhdebugmask[Op_VecX] = NULL;
aoqi@0 127 idealreg2mhdebugmask[Op_VecY] = NULL;
aoqi@0 128
aoqi@0 129 debug_only(_mem_node = NULL;) // Ideal memory node consumed by mach node
aoqi@0 130 }
aoqi@0 131
aoqi@0 132 //------------------------------warp_incoming_stk_arg------------------------
aoqi@0 133 // This warps a VMReg into an OptoReg::Name
aoqi@0 134 OptoReg::Name Matcher::warp_incoming_stk_arg( VMReg reg ) {
aoqi@0 135 OptoReg::Name warped;
aoqi@0 136 if( reg->is_stack() ) { // Stack slot argument?
aoqi@0 137 warped = OptoReg::add(_old_SP, reg->reg2stack() );
aoqi@0 138 warped = OptoReg::add(warped, C->out_preserve_stack_slots());
aoqi@0 139 if( warped >= _in_arg_limit )
aoqi@0 140 _in_arg_limit = OptoReg::add(warped, 1); // Bump max stack slot seen
aoqi@0 141 if (!RegMask::can_represent_arg(warped)) {
aoqi@0 142 // the compiler cannot represent this method's calling sequence
aoqi@0 143 C->record_method_not_compilable_all_tiers("unsupported incoming calling sequence");
aoqi@0 144 return OptoReg::Bad;
aoqi@0 145 }
aoqi@0 146 return warped;
aoqi@0 147 }
aoqi@0 148 return OptoReg::as_OptoReg(reg);
aoqi@0 149 }
aoqi@0 150
aoqi@0 151 //---------------------------compute_old_SP------------------------------------
aoqi@0 152 OptoReg::Name Compile::compute_old_SP() {
aoqi@0 153 int fixed = fixed_slots();
aoqi@0 154 int preserve = in_preserve_stack_slots();
aoqi@0 155 return OptoReg::stack2reg(round_to(fixed + preserve, Matcher::stack_alignment_in_slots()));
aoqi@0 156 }
aoqi@0 157
aoqi@0 158
aoqi@0 159
aoqi@0 160 #ifdef ASSERT
aoqi@0 161 void Matcher::verify_new_nodes_only(Node* xroot) {
aoqi@0 162 // Make sure that the new graph only references new nodes
aoqi@0 163 ResourceMark rm;
aoqi@0 164 Unique_Node_List worklist;
aoqi@0 165 VectorSet visited(Thread::current()->resource_area());
aoqi@0 166 worklist.push(xroot);
aoqi@0 167 while (worklist.size() > 0) {
aoqi@0 168 Node* n = worklist.pop();
aoqi@0 169 visited <<= n->_idx;
aoqi@0 170 assert(C->node_arena()->contains(n), "dead node");
aoqi@0 171 for (uint j = 0; j < n->req(); j++) {
aoqi@0 172 Node* in = n->in(j);
aoqi@0 173 if (in != NULL) {
aoqi@0 174 assert(C->node_arena()->contains(in), "dead node");
aoqi@0 175 if (!visited.test(in->_idx)) {
aoqi@0 176 worklist.push(in);
aoqi@0 177 }
aoqi@0 178 }
aoqi@0 179 }
aoqi@0 180 }
aoqi@0 181 }
aoqi@0 182 #endif
aoqi@0 183
aoqi@0 184
aoqi@0 185 //---------------------------match---------------------------------------------
aoqi@0 186 void Matcher::match( ) {
aoqi@0 187 if( MaxLabelRootDepth < 100 ) { // Too small?
aoqi@0 188 assert(false, "invalid MaxLabelRootDepth, increase it to 100 minimum");
aoqi@0 189 MaxLabelRootDepth = 100;
aoqi@0 190 }
aoqi@0 191 // One-time initialization of some register masks.
aoqi@0 192 init_spill_mask( C->root()->in(1) );
aoqi@0 193 _return_addr_mask = return_addr();
aoqi@0 194 #ifdef _LP64
aoqi@0 195 // Pointers take 2 slots in 64-bit land
aoqi@0 196 _return_addr_mask.Insert(OptoReg::add(return_addr(),1));
aoqi@0 197 #endif
aoqi@0 198
aoqi@0 199 // Map a Java-signature return type into return register-value
aoqi@0 200 // machine registers for 0, 1 and 2 returned values.
aoqi@0 201 const TypeTuple *range = C->tf()->range();
aoqi@0 202 if( range->cnt() > TypeFunc::Parms ) { // If not a void function
aoqi@0 203 // Get ideal-register return type
aoqi@0 204 int ireg = range->field_at(TypeFunc::Parms)->ideal_reg();
aoqi@0 205 // Get machine return register
aoqi@0 206 uint sop = C->start()->Opcode();
aoqi@0 207 OptoRegPair regs = return_value(ireg, false);
aoqi@0 208
aoqi@0 209 // And mask for same
aoqi@0 210 _return_value_mask = RegMask(regs.first());
aoqi@0 211 if( OptoReg::is_valid(regs.second()) )
aoqi@0 212 _return_value_mask.Insert(regs.second());
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 // ---------------
aoqi@0 216 // Frame Layout
aoqi@0 217
aoqi@0 218 // Need the method signature to determine the incoming argument types,
aoqi@0 219 // because the types determine which registers the incoming arguments are
aoqi@0 220 // in, and this affects the matched code.
aoqi@0 221 const TypeTuple *domain = C->tf()->domain();
aoqi@0 222 uint argcnt = domain->cnt() - TypeFunc::Parms;
aoqi@0 223 BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, argcnt );
aoqi@0 224 VMRegPair *vm_parm_regs = NEW_RESOURCE_ARRAY( VMRegPair, argcnt );
aoqi@0 225 _parm_regs = NEW_RESOURCE_ARRAY( OptoRegPair, argcnt );
aoqi@0 226 _calling_convention_mask = NEW_RESOURCE_ARRAY( RegMask, argcnt );
aoqi@0 227 uint i;
aoqi@0 228 for( i = 0; i<argcnt; i++ ) {
aoqi@0 229 sig_bt[i] = domain->field_at(i+TypeFunc::Parms)->basic_type();
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 // Pass array of ideal registers and length to USER code (from the AD file)
aoqi@0 233 // that will convert this to an array of register numbers.
aoqi@0 234 const StartNode *start = C->start();
aoqi@0 235 start->calling_convention( sig_bt, vm_parm_regs, argcnt );
aoqi@0 236 #ifdef ASSERT
aoqi@0 237 // Sanity check users' calling convention. Real handy while trying to
aoqi@0 238 // get the initial port correct.
aoqi@0 239 { for (uint i = 0; i<argcnt; i++) {
aoqi@0 240 if( !vm_parm_regs[i].first()->is_valid() && !vm_parm_regs[i].second()->is_valid() ) {
aoqi@0 241 assert(domain->field_at(i+TypeFunc::Parms)==Type::HALF, "only allowed on halve" );
aoqi@0 242 _parm_regs[i].set_bad();
aoqi@0 243 continue;
aoqi@0 244 }
aoqi@0 245 VMReg parm_reg = vm_parm_regs[i].first();
aoqi@0 246 assert(parm_reg->is_valid(), "invalid arg?");
aoqi@0 247 if (parm_reg->is_reg()) {
aoqi@0 248 OptoReg::Name opto_parm_reg = OptoReg::as_OptoReg(parm_reg);
aoqi@0 249 assert(can_be_java_arg(opto_parm_reg) ||
aoqi@0 250 C->stub_function() == CAST_FROM_FN_PTR(address, OptoRuntime::rethrow_C) ||
aoqi@0 251 opto_parm_reg == inline_cache_reg(),
aoqi@0 252 "parameters in register must be preserved by runtime stubs");
aoqi@0 253 }
aoqi@0 254 for (uint j = 0; j < i; j++) {
aoqi@0 255 assert(parm_reg != vm_parm_regs[j].first(),
aoqi@0 256 "calling conv. must produce distinct regs");
aoqi@0 257 }
aoqi@0 258 }
aoqi@0 259 }
aoqi@0 260 #endif
aoqi@0 261
aoqi@0 262 // Do some initial frame layout.
aoqi@0 263
aoqi@0 264 // Compute the old incoming SP (may be called FP) as
aoqi@0 265 // OptoReg::stack0() + locks + in_preserve_stack_slots + pad2.
aoqi@0 266 _old_SP = C->compute_old_SP();
aoqi@0 267 assert( is_even(_old_SP), "must be even" );
aoqi@0 268
aoqi@0 269 // Compute highest incoming stack argument as
aoqi@0 270 // _old_SP + out_preserve_stack_slots + incoming argument size.
aoqi@0 271 _in_arg_limit = OptoReg::add(_old_SP, C->out_preserve_stack_slots());
aoqi@0 272 assert( is_even(_in_arg_limit), "out_preserve must be even" );
aoqi@0 273 for( i = 0; i < argcnt; i++ ) {
aoqi@0 274 // Permit args to have no register
aoqi@0 275 _calling_convention_mask[i].Clear();
aoqi@0 276 if( !vm_parm_regs[i].first()->is_valid() && !vm_parm_regs[i].second()->is_valid() ) {
aoqi@0 277 continue;
aoqi@0 278 }
aoqi@0 279 // calling_convention returns stack arguments as a count of
aoqi@0 280 // slots beyond OptoReg::stack0()/VMRegImpl::stack0. We need to convert this to
aoqi@0 281 // the allocators point of view, taking into account all the
aoqi@0 282 // preserve area, locks & pad2.
aoqi@0 283
aoqi@0 284 OptoReg::Name reg1 = warp_incoming_stk_arg(vm_parm_regs[i].first());
aoqi@0 285 if( OptoReg::is_valid(reg1))
aoqi@0 286 _calling_convention_mask[i].Insert(reg1);
aoqi@0 287
aoqi@0 288 OptoReg::Name reg2 = warp_incoming_stk_arg(vm_parm_regs[i].second());
aoqi@0 289 if( OptoReg::is_valid(reg2))
aoqi@0 290 _calling_convention_mask[i].Insert(reg2);
aoqi@0 291
aoqi@0 292 // Saved biased stack-slot register number
aoqi@0 293 _parm_regs[i].set_pair(reg2, reg1);
aoqi@0 294 }
aoqi@0 295
aoqi@0 296 // Finally, make sure the incoming arguments take up an even number of
aoqi@0 297 // words, in case the arguments or locals need to contain doubleword stack
aoqi@0 298 // slots. The rest of the system assumes that stack slot pairs (in
aoqi@0 299 // particular, in the spill area) which look aligned will in fact be
aoqi@0 300 // aligned relative to the stack pointer in the target machine. Double
aoqi@0 301 // stack slots will always be allocated aligned.
aoqi@0 302 _new_SP = OptoReg::Name(round_to(_in_arg_limit, RegMask::SlotsPerLong));
aoqi@0 303
aoqi@0 304 // Compute highest outgoing stack argument as
aoqi@0 305 // _new_SP + out_preserve_stack_slots + max(outgoing argument size).
aoqi@0 306 _out_arg_limit = OptoReg::add(_new_SP, C->out_preserve_stack_slots());
aoqi@0 307 assert( is_even(_out_arg_limit), "out_preserve must be even" );
aoqi@0 308
aoqi@0 309 if (!RegMask::can_represent_arg(OptoReg::add(_out_arg_limit,-1))) {
aoqi@0 310 // the compiler cannot represent this method's calling sequence
aoqi@0 311 C->record_method_not_compilable("must be able to represent all call arguments in reg mask");
aoqi@0 312 }
aoqi@0 313
aoqi@0 314 if (C->failing()) return; // bailed out on incoming arg failure
aoqi@0 315
aoqi@0 316 // ---------------
aoqi@0 317 // Collect roots of matcher trees. Every node for which
aoqi@0 318 // _shared[_idx] is cleared is guaranteed to not be shared, and thus
aoqi@0 319 // can be a valid interior of some tree.
aoqi@0 320 find_shared( C->root() );
aoqi@0 321 find_shared( C->top() );
aoqi@0 322
aoqi@0 323 C->print_method(PHASE_BEFORE_MATCHING);
aoqi@0 324
aoqi@0 325 // Create new ideal node ConP #NULL even if it does exist in old space
aoqi@0 326 // to avoid false sharing if the corresponding mach node is not used.
aoqi@0 327 // The corresponding mach node is only used in rare cases for derived
aoqi@0 328 // pointers.
aoqi@0 329 Node* new_ideal_null = ConNode::make(C, TypePtr::NULL_PTR);
aoqi@0 330
aoqi@0 331 // Swap out to old-space; emptying new-space
aoqi@0 332 Arena *old = C->node_arena()->move_contents(C->old_arena());
aoqi@0 333
aoqi@0 334 // Save debug and profile information for nodes in old space:
aoqi@0 335 _old_node_note_array = C->node_note_array();
aoqi@0 336 if (_old_node_note_array != NULL) {
aoqi@0 337 C->set_node_note_array(new(C->comp_arena()) GrowableArray<Node_Notes*>
aoqi@0 338 (C->comp_arena(), _old_node_note_array->length(),
aoqi@0 339 0, NULL));
aoqi@0 340 }
aoqi@0 341
aoqi@0 342 // Pre-size the new_node table to avoid the need for range checks.
aoqi@0 343 grow_new_node_array(C->unique());
aoqi@0 344
aoqi@0 345 // Reset node counter so MachNodes start with _idx at 0
aoqi@0 346 int nodes = C->unique(); // save value
aoqi@0 347 C->set_unique(0);
aoqi@0 348 C->reset_dead_node_list();
aoqi@0 349
aoqi@0 350 // Recursively match trees from old space into new space.
aoqi@0 351 // Correct leaves of new-space Nodes; they point to old-space.
aoqi@0 352 _visited.Clear(); // Clear visit bits for xform call
aoqi@0 353 C->set_cached_top_node(xform( C->top(), nodes ));
aoqi@0 354 if (!C->failing()) {
aoqi@0 355 Node* xroot = xform( C->root(), 1 );
aoqi@0 356 if (xroot == NULL) {
aoqi@0 357 Matcher::soft_match_failure(); // recursive matching process failed
aoqi@0 358 C->record_method_not_compilable("instruction match failed");
aoqi@0 359 } else {
aoqi@0 360 // During matching shared constants were attached to C->root()
aoqi@0 361 // because xroot wasn't available yet, so transfer the uses to
aoqi@0 362 // the xroot.
aoqi@0 363 for( DUIterator_Fast jmax, j = C->root()->fast_outs(jmax); j < jmax; j++ ) {
aoqi@0 364 Node* n = C->root()->fast_out(j);
aoqi@0 365 if (C->node_arena()->contains(n)) {
aoqi@0 366 assert(n->in(0) == C->root(), "should be control user");
aoqi@0 367 n->set_req(0, xroot);
aoqi@0 368 --j;
aoqi@0 369 --jmax;
aoqi@0 370 }
aoqi@0 371 }
aoqi@0 372
aoqi@0 373 // Generate new mach node for ConP #NULL
aoqi@0 374 assert(new_ideal_null != NULL, "sanity");
aoqi@0 375 _mach_null = match_tree(new_ideal_null);
aoqi@0 376 // Don't set control, it will confuse GCM since there are no uses.
aoqi@0 377 // The control will be set when this node is used first time
aoqi@0 378 // in find_base_for_derived().
aoqi@0 379 assert(_mach_null != NULL, "");
aoqi@0 380
aoqi@0 381 C->set_root(xroot->is_Root() ? xroot->as_Root() : NULL);
aoqi@0 382
aoqi@0 383 #ifdef ASSERT
aoqi@0 384 verify_new_nodes_only(xroot);
aoqi@0 385 #endif
aoqi@0 386 }
aoqi@0 387 }
aoqi@0 388 if (C->top() == NULL || C->root() == NULL) {
aoqi@0 389 C->record_method_not_compilable("graph lost"); // %%% cannot happen?
aoqi@0 390 }
aoqi@0 391 if (C->failing()) {
aoqi@0 392 // delete old;
aoqi@0 393 old->destruct_contents();
aoqi@0 394 return;
aoqi@0 395 }
aoqi@0 396 assert( C->top(), "" );
aoqi@0 397 assert( C->root(), "" );
aoqi@0 398 validate_null_checks();
aoqi@0 399
aoqi@0 400 // Now smoke old-space
aoqi@0 401 NOT_DEBUG( old->destruct_contents() );
aoqi@0 402
aoqi@0 403 // ------------------------
aoqi@0 404 // Set up save-on-entry registers
aoqi@0 405 Fixup_Save_On_Entry( );
aoqi@0 406 }
aoqi@0 407
aoqi@0 408
aoqi@0 409 //------------------------------Fixup_Save_On_Entry----------------------------
aoqi@0 410 // The stated purpose of this routine is to take care of save-on-entry
aoqi@0 411 // registers. However, the overall goal of the Match phase is to convert into
aoqi@0 412 // machine-specific instructions which have RegMasks to guide allocation.
aoqi@0 413 // So what this procedure really does is put a valid RegMask on each input
aoqi@0 414 // to the machine-specific variations of all Return, TailCall and Halt
aoqi@0 415 // instructions. It also adds edgs to define the save-on-entry values (and of
aoqi@0 416 // course gives them a mask).
aoqi@0 417
aoqi@0 418 static RegMask *init_input_masks( uint size, RegMask &ret_adr, RegMask &fp ) {
aoqi@0 419 RegMask *rms = NEW_RESOURCE_ARRAY( RegMask, size );
aoqi@0 420 // Do all the pre-defined register masks
aoqi@0 421 rms[TypeFunc::Control ] = RegMask::Empty;
aoqi@0 422 rms[TypeFunc::I_O ] = RegMask::Empty;
aoqi@0 423 rms[TypeFunc::Memory ] = RegMask::Empty;
aoqi@0 424 rms[TypeFunc::ReturnAdr] = ret_adr;
aoqi@0 425 rms[TypeFunc::FramePtr ] = fp;
aoqi@0 426 return rms;
aoqi@0 427 }
aoqi@0 428
aoqi@0 429 //---------------------------init_first_stack_mask-----------------------------
aoqi@0 430 // Create the initial stack mask used by values spilling to the stack.
aoqi@0 431 // Disallow any debug info in outgoing argument areas by setting the
aoqi@0 432 // initial mask accordingly.
aoqi@0 433 void Matcher::init_first_stack_mask() {
aoqi@0 434
aoqi@0 435 // Allocate storage for spill masks as masks for the appropriate load type.
aoqi@0 436 RegMask *rms = (RegMask*)C->comp_arena()->Amalloc_D(sizeof(RegMask) * (3*6+4));
aoqi@0 437
aoqi@0 438 idealreg2spillmask [Op_RegN] = &rms[0];
aoqi@0 439 idealreg2spillmask [Op_RegI] = &rms[1];
aoqi@0 440 idealreg2spillmask [Op_RegL] = &rms[2];
aoqi@0 441 idealreg2spillmask [Op_RegF] = &rms[3];
aoqi@0 442 idealreg2spillmask [Op_RegD] = &rms[4];
aoqi@0 443 idealreg2spillmask [Op_RegP] = &rms[5];
aoqi@0 444
aoqi@0 445 idealreg2debugmask [Op_RegN] = &rms[6];
aoqi@0 446 idealreg2debugmask [Op_RegI] = &rms[7];
aoqi@0 447 idealreg2debugmask [Op_RegL] = &rms[8];
aoqi@0 448 idealreg2debugmask [Op_RegF] = &rms[9];
aoqi@0 449 idealreg2debugmask [Op_RegD] = &rms[10];
aoqi@0 450 idealreg2debugmask [Op_RegP] = &rms[11];
aoqi@0 451
aoqi@0 452 idealreg2mhdebugmask[Op_RegN] = &rms[12];
aoqi@0 453 idealreg2mhdebugmask[Op_RegI] = &rms[13];
aoqi@0 454 idealreg2mhdebugmask[Op_RegL] = &rms[14];
aoqi@0 455 idealreg2mhdebugmask[Op_RegF] = &rms[15];
aoqi@0 456 idealreg2mhdebugmask[Op_RegD] = &rms[16];
aoqi@0 457 idealreg2mhdebugmask[Op_RegP] = &rms[17];
aoqi@0 458
aoqi@0 459 idealreg2spillmask [Op_VecS] = &rms[18];
aoqi@0 460 idealreg2spillmask [Op_VecD] = &rms[19];
aoqi@0 461 idealreg2spillmask [Op_VecX] = &rms[20];
aoqi@0 462 idealreg2spillmask [Op_VecY] = &rms[21];
aoqi@0 463
aoqi@0 464 OptoReg::Name i;
aoqi@0 465
aoqi@0 466 // At first, start with the empty mask
aoqi@0 467 C->FIRST_STACK_mask().Clear();
aoqi@0 468
aoqi@0 469 // Add in the incoming argument area
aoqi@0 470 OptoReg::Name init_in = OptoReg::add(_old_SP, C->out_preserve_stack_slots());
aoqi@0 471 for (i = init_in; i < _in_arg_limit; i = OptoReg::add(i,1)) {
aoqi@0 472 C->FIRST_STACK_mask().Insert(i);
aoqi@0 473 }
aoqi@0 474 // Add in all bits past the outgoing argument area
aoqi@0 475 guarantee(RegMask::can_represent_arg(OptoReg::add(_out_arg_limit,-1)),
aoqi@0 476 "must be able to represent all call arguments in reg mask");
aoqi@0 477 OptoReg::Name init = _out_arg_limit;
aoqi@0 478 for (i = init; RegMask::can_represent(i); i = OptoReg::add(i,1)) {
aoqi@0 479 C->FIRST_STACK_mask().Insert(i);
aoqi@0 480 }
aoqi@0 481 // Finally, set the "infinite stack" bit.
aoqi@0 482 C->FIRST_STACK_mask().set_AllStack();
aoqi@0 483
aoqi@0 484 // Make spill masks. Registers for their class, plus FIRST_STACK_mask.
aoqi@0 485 RegMask aligned_stack_mask = C->FIRST_STACK_mask();
aoqi@0 486 // Keep spill masks aligned.
aoqi@0 487 aligned_stack_mask.clear_to_pairs();
aoqi@0 488 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
aoqi@0 489
aoqi@0 490 *idealreg2spillmask[Op_RegP] = *idealreg2regmask[Op_RegP];
aoqi@0 491 #ifdef _LP64
aoqi@0 492 *idealreg2spillmask[Op_RegN] = *idealreg2regmask[Op_RegN];
aoqi@0 493 idealreg2spillmask[Op_RegN]->OR(C->FIRST_STACK_mask());
aoqi@0 494 idealreg2spillmask[Op_RegP]->OR(aligned_stack_mask);
aoqi@0 495 #else
aoqi@0 496 idealreg2spillmask[Op_RegP]->OR(C->FIRST_STACK_mask());
aoqi@0 497 #endif
aoqi@0 498 *idealreg2spillmask[Op_RegI] = *idealreg2regmask[Op_RegI];
aoqi@0 499 idealreg2spillmask[Op_RegI]->OR(C->FIRST_STACK_mask());
aoqi@0 500 *idealreg2spillmask[Op_RegL] = *idealreg2regmask[Op_RegL];
aoqi@0 501 idealreg2spillmask[Op_RegL]->OR(aligned_stack_mask);
aoqi@0 502 *idealreg2spillmask[Op_RegF] = *idealreg2regmask[Op_RegF];
aoqi@0 503 idealreg2spillmask[Op_RegF]->OR(C->FIRST_STACK_mask());
aoqi@0 504 *idealreg2spillmask[Op_RegD] = *idealreg2regmask[Op_RegD];
aoqi@0 505 idealreg2spillmask[Op_RegD]->OR(aligned_stack_mask);
aoqi@0 506
aoqi@0 507 if (Matcher::vector_size_supported(T_BYTE,4)) {
aoqi@0 508 *idealreg2spillmask[Op_VecS] = *idealreg2regmask[Op_VecS];
aoqi@0 509 idealreg2spillmask[Op_VecS]->OR(C->FIRST_STACK_mask());
aoqi@0 510 }
aoqi@0 511 if (Matcher::vector_size_supported(T_FLOAT,2)) {
aoqi@0 512 // For VecD we need dual alignment and 8 bytes (2 slots) for spills.
aoqi@0 513 // RA guarantees such alignment since it is needed for Double and Long values.
aoqi@0 514 *idealreg2spillmask[Op_VecD] = *idealreg2regmask[Op_VecD];
aoqi@0 515 idealreg2spillmask[Op_VecD]->OR(aligned_stack_mask);
aoqi@0 516 }
aoqi@0 517 if (Matcher::vector_size_supported(T_FLOAT,4)) {
aoqi@0 518 // For VecX we need quadro alignment and 16 bytes (4 slots) for spills.
aoqi@0 519 //
aoqi@0 520 // RA can use input arguments stack slots for spills but until RA
aoqi@0 521 // we don't know frame size and offset of input arg stack slots.
aoqi@0 522 //
aoqi@0 523 // Exclude last input arg stack slots to avoid spilling vectors there
aoqi@0 524 // otherwise vector spills could stomp over stack slots in caller frame.
aoqi@0 525 OptoReg::Name in = OptoReg::add(_in_arg_limit, -1);
aoqi@0 526 for (int k = 1; (in >= init_in) && (k < RegMask::SlotsPerVecX); k++) {
aoqi@0 527 aligned_stack_mask.Remove(in);
aoqi@0 528 in = OptoReg::add(in, -1);
aoqi@0 529 }
aoqi@0 530 aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecX);
aoqi@0 531 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
aoqi@0 532 *idealreg2spillmask[Op_VecX] = *idealreg2regmask[Op_VecX];
aoqi@0 533 idealreg2spillmask[Op_VecX]->OR(aligned_stack_mask);
aoqi@0 534 }
aoqi@0 535 if (Matcher::vector_size_supported(T_FLOAT,8)) {
aoqi@0 536 // For VecY we need octo alignment and 32 bytes (8 slots) for spills.
aoqi@0 537 OptoReg::Name in = OptoReg::add(_in_arg_limit, -1);
aoqi@0 538 for (int k = 1; (in >= init_in) && (k < RegMask::SlotsPerVecY); k++) {
aoqi@0 539 aligned_stack_mask.Remove(in);
aoqi@0 540 in = OptoReg::add(in, -1);
aoqi@0 541 }
aoqi@0 542 aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecY);
aoqi@0 543 assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
aoqi@0 544 *idealreg2spillmask[Op_VecY] = *idealreg2regmask[Op_VecY];
aoqi@0 545 idealreg2spillmask[Op_VecY]->OR(aligned_stack_mask);
aoqi@0 546 }
aoqi@0 547 if (UseFPUForSpilling) {
aoqi@0 548 // This mask logic assumes that the spill operations are
aoqi@0 549 // symmetric and that the registers involved are the same size.
aoqi@0 550 // On sparc for instance we may have to use 64 bit moves will
aoqi@0 551 // kill 2 registers when used with F0-F31.
aoqi@0 552 idealreg2spillmask[Op_RegI]->OR(*idealreg2regmask[Op_RegF]);
aoqi@0 553 idealreg2spillmask[Op_RegF]->OR(*idealreg2regmask[Op_RegI]);
aoqi@0 554 #ifdef _LP64
aoqi@0 555 idealreg2spillmask[Op_RegN]->OR(*idealreg2regmask[Op_RegF]);
aoqi@0 556 idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]);
aoqi@0 557 idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]);
aoqi@0 558 idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegD]);
aoqi@0 559 #else
aoqi@0 560 idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegF]);
aoqi@0 561 #ifdef ARM
aoqi@0 562 // ARM has support for moving 64bit values between a pair of
aoqi@0 563 // integer registers and a double register
aoqi@0 564 idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]);
aoqi@0 565 idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]);
aoqi@0 566 #endif
aoqi@0 567 #endif
aoqi@0 568 }
aoqi@0 569
aoqi@0 570 // Make up debug masks. Any spill slot plus callee-save registers.
aoqi@0 571 // Caller-save registers are assumed to be trashable by the various
aoqi@0 572 // inline-cache fixup routines.
aoqi@0 573 *idealreg2debugmask [Op_RegN]= *idealreg2spillmask[Op_RegN];
aoqi@0 574 *idealreg2debugmask [Op_RegI]= *idealreg2spillmask[Op_RegI];
aoqi@0 575 *idealreg2debugmask [Op_RegL]= *idealreg2spillmask[Op_RegL];
aoqi@0 576 *idealreg2debugmask [Op_RegF]= *idealreg2spillmask[Op_RegF];
aoqi@0 577 *idealreg2debugmask [Op_RegD]= *idealreg2spillmask[Op_RegD];
aoqi@0 578 *idealreg2debugmask [Op_RegP]= *idealreg2spillmask[Op_RegP];
aoqi@0 579
aoqi@0 580 *idealreg2mhdebugmask[Op_RegN]= *idealreg2spillmask[Op_RegN];
aoqi@0 581 *idealreg2mhdebugmask[Op_RegI]= *idealreg2spillmask[Op_RegI];
aoqi@0 582 *idealreg2mhdebugmask[Op_RegL]= *idealreg2spillmask[Op_RegL];
aoqi@0 583 *idealreg2mhdebugmask[Op_RegF]= *idealreg2spillmask[Op_RegF];
aoqi@0 584 *idealreg2mhdebugmask[Op_RegD]= *idealreg2spillmask[Op_RegD];
aoqi@0 585 *idealreg2mhdebugmask[Op_RegP]= *idealreg2spillmask[Op_RegP];
aoqi@0 586
aoqi@0 587 // Prevent stub compilations from attempting to reference
aoqi@0 588 // callee-saved registers from debug info
aoqi@0 589 bool exclude_soe = !Compile::current()->is_method_compilation();
aoqi@0 590
aoqi@0 591 for( i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
aoqi@0 592 // registers the caller has to save do not work
aoqi@0 593 if( _register_save_policy[i] == 'C' ||
aoqi@0 594 _register_save_policy[i] == 'A' ||
aoqi@0 595 (_register_save_policy[i] == 'E' && exclude_soe) ) {
aoqi@0 596 idealreg2debugmask [Op_RegN]->Remove(i);
aoqi@0 597 idealreg2debugmask [Op_RegI]->Remove(i); // Exclude save-on-call
aoqi@0 598 idealreg2debugmask [Op_RegL]->Remove(i); // registers from debug
aoqi@0 599 idealreg2debugmask [Op_RegF]->Remove(i); // masks
aoqi@0 600 idealreg2debugmask [Op_RegD]->Remove(i);
aoqi@0 601 idealreg2debugmask [Op_RegP]->Remove(i);
aoqi@0 602
aoqi@0 603 idealreg2mhdebugmask[Op_RegN]->Remove(i);
aoqi@0 604 idealreg2mhdebugmask[Op_RegI]->Remove(i);
aoqi@0 605 idealreg2mhdebugmask[Op_RegL]->Remove(i);
aoqi@0 606 idealreg2mhdebugmask[Op_RegF]->Remove(i);
aoqi@0 607 idealreg2mhdebugmask[Op_RegD]->Remove(i);
aoqi@0 608 idealreg2mhdebugmask[Op_RegP]->Remove(i);
aoqi@0 609 }
aoqi@0 610 }
aoqi@0 611
aoqi@0 612 // Subtract the register we use to save the SP for MethodHandle
aoqi@0 613 // invokes to from the debug mask.
aoqi@0 614 const RegMask save_mask = method_handle_invoke_SP_save_mask();
aoqi@0 615 idealreg2mhdebugmask[Op_RegN]->SUBTRACT(save_mask);
aoqi@0 616 idealreg2mhdebugmask[Op_RegI]->SUBTRACT(save_mask);
aoqi@0 617 idealreg2mhdebugmask[Op_RegL]->SUBTRACT(save_mask);
aoqi@0 618 idealreg2mhdebugmask[Op_RegF]->SUBTRACT(save_mask);
aoqi@0 619 idealreg2mhdebugmask[Op_RegD]->SUBTRACT(save_mask);
aoqi@0 620 idealreg2mhdebugmask[Op_RegP]->SUBTRACT(save_mask);
aoqi@0 621 }
aoqi@0 622
aoqi@0 623 //---------------------------is_save_on_entry----------------------------------
aoqi@0 624 bool Matcher::is_save_on_entry( int reg ) {
aoqi@0 625 return
aoqi@0 626 _register_save_policy[reg] == 'E' ||
aoqi@0 627 _register_save_policy[reg] == 'A' || // Save-on-entry register?
aoqi@0 628 // Also save argument registers in the trampolining stubs
aoqi@0 629 (C->save_argument_registers() && is_spillable_arg(reg));
aoqi@0 630 }
aoqi@0 631
aoqi@0 632 //---------------------------Fixup_Save_On_Entry-------------------------------
aoqi@0 633 void Matcher::Fixup_Save_On_Entry( ) {
aoqi@0 634 init_first_stack_mask();
aoqi@0 635
aoqi@0 636 Node *root = C->root(); // Short name for root
aoqi@0 637 // Count number of save-on-entry registers.
aoqi@0 638 uint soe_cnt = number_of_saved_registers();
aoqi@0 639 uint i;
aoqi@0 640
aoqi@0 641 // Find the procedure Start Node
aoqi@0 642 StartNode *start = C->start();
aoqi@0 643 assert( start, "Expect a start node" );
aoqi@0 644
aoqi@0 645 // Save argument registers in the trampolining stubs
aoqi@0 646 if( C->save_argument_registers() )
aoqi@0 647 for( i = 0; i < _last_Mach_Reg; i++ )
aoqi@0 648 if( is_spillable_arg(i) )
aoqi@0 649 soe_cnt++;
aoqi@0 650
aoqi@0 651 // Input RegMask array shared by all Returns.
aoqi@0 652 // The type for doubles and longs has a count of 2, but
aoqi@0 653 // there is only 1 returned value
aoqi@0 654 uint ret_edge_cnt = TypeFunc::Parms + ((C->tf()->range()->cnt() == TypeFunc::Parms) ? 0 : 1);
aoqi@0 655 RegMask *ret_rms = init_input_masks( ret_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
aoqi@0 656 // Returns have 0 or 1 returned values depending on call signature.
aoqi@0 657 // Return register is specified by return_value in the AD file.
aoqi@0 658 if (ret_edge_cnt > TypeFunc::Parms)
aoqi@0 659 ret_rms[TypeFunc::Parms+0] = _return_value_mask;
aoqi@0 660
aoqi@0 661 // Input RegMask array shared by all Rethrows.
aoqi@0 662 uint reth_edge_cnt = TypeFunc::Parms+1;
aoqi@0 663 RegMask *reth_rms = init_input_masks( reth_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
aoqi@0 664 // Rethrow takes exception oop only, but in the argument 0 slot.
aoqi@0 665 reth_rms[TypeFunc::Parms] = mreg2regmask[find_receiver(false)];
aoqi@0 666 #ifdef _LP64
aoqi@0 667 // Need two slots for ptrs in 64-bit land
aoqi@0 668 reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(find_receiver(false)),1));
aoqi@0 669 #endif
aoqi@0 670
aoqi@0 671 // Input RegMask array shared by all TailCalls
aoqi@0 672 uint tail_call_edge_cnt = TypeFunc::Parms+2;
aoqi@0 673 RegMask *tail_call_rms = init_input_masks( tail_call_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
aoqi@0 674
aoqi@0 675 // Input RegMask array shared by all TailJumps
aoqi@0 676 uint tail_jump_edge_cnt = TypeFunc::Parms+2;
aoqi@0 677 RegMask *tail_jump_rms = init_input_masks( tail_jump_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
aoqi@0 678
aoqi@0 679 // TailCalls have 2 returned values (target & moop), whose masks come
aoqi@0 680 // from the usual MachNode/MachOper mechanism. Find a sample
aoqi@0 681 // TailCall to extract these masks and put the correct masks into
aoqi@0 682 // the tail_call_rms array.
aoqi@0 683 for( i=1; i < root->req(); i++ ) {
aoqi@0 684 MachReturnNode *m = root->in(i)->as_MachReturn();
aoqi@0 685 if( m->ideal_Opcode() == Op_TailCall ) {
aoqi@0 686 tail_call_rms[TypeFunc::Parms+0] = m->MachNode::in_RegMask(TypeFunc::Parms+0);
aoqi@0 687 tail_call_rms[TypeFunc::Parms+1] = m->MachNode::in_RegMask(TypeFunc::Parms+1);
aoqi@0 688 break;
aoqi@0 689 }
aoqi@0 690 }
aoqi@0 691
aoqi@0 692 // TailJumps have 2 returned values (target & ex_oop), whose masks come
aoqi@0 693 // from the usual MachNode/MachOper mechanism. Find a sample
aoqi@0 694 // TailJump to extract these masks and put the correct masks into
aoqi@0 695 // the tail_jump_rms array.
aoqi@0 696 for( i=1; i < root->req(); i++ ) {
aoqi@0 697 MachReturnNode *m = root->in(i)->as_MachReturn();
aoqi@0 698 if( m->ideal_Opcode() == Op_TailJump ) {
aoqi@0 699 tail_jump_rms[TypeFunc::Parms+0] = m->MachNode::in_RegMask(TypeFunc::Parms+0);
aoqi@0 700 tail_jump_rms[TypeFunc::Parms+1] = m->MachNode::in_RegMask(TypeFunc::Parms+1);
aoqi@0 701 break;
aoqi@0 702 }
aoqi@0 703 }
aoqi@0 704
aoqi@0 705 // Input RegMask array shared by all Halts
aoqi@0 706 uint halt_edge_cnt = TypeFunc::Parms;
aoqi@0 707 RegMask *halt_rms = init_input_masks( halt_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
aoqi@0 708
aoqi@0 709 // Capture the return input masks into each exit flavor
aoqi@0 710 for( i=1; i < root->req(); i++ ) {
aoqi@0 711 MachReturnNode *exit = root->in(i)->as_MachReturn();
aoqi@0 712 switch( exit->ideal_Opcode() ) {
aoqi@0 713 case Op_Return : exit->_in_rms = ret_rms; break;
aoqi@0 714 case Op_Rethrow : exit->_in_rms = reth_rms; break;
aoqi@0 715 case Op_TailCall : exit->_in_rms = tail_call_rms; break;
aoqi@0 716 case Op_TailJump : exit->_in_rms = tail_jump_rms; break;
aoqi@0 717 case Op_Halt : exit->_in_rms = halt_rms; break;
aoqi@0 718 default : ShouldNotReachHere();
aoqi@0 719 }
aoqi@0 720 }
aoqi@0 721
aoqi@0 722 // Next unused projection number from Start.
aoqi@0 723 int proj_cnt = C->tf()->domain()->cnt();
aoqi@0 724
aoqi@0 725 // Do all the save-on-entry registers. Make projections from Start for
aoqi@0 726 // them, and give them a use at the exit points. To the allocator, they
aoqi@0 727 // look like incoming register arguments.
aoqi@0 728 for( i = 0; i < _last_Mach_Reg; i++ ) {
aoqi@0 729 if( is_save_on_entry(i) ) {
aoqi@0 730
aoqi@0 731 // Add the save-on-entry to the mask array
aoqi@0 732 ret_rms [ ret_edge_cnt] = mreg2regmask[i];
aoqi@0 733 reth_rms [ reth_edge_cnt] = mreg2regmask[i];
aoqi@0 734 tail_call_rms[tail_call_edge_cnt] = mreg2regmask[i];
aoqi@0 735 tail_jump_rms[tail_jump_edge_cnt] = mreg2regmask[i];
aoqi@0 736 // Halts need the SOE registers, but only in the stack as debug info.
aoqi@0 737 // A just-prior uncommon-trap or deoptimization will use the SOE regs.
aoqi@0 738 halt_rms [ halt_edge_cnt] = *idealreg2spillmask[_register_save_type[i]];
aoqi@0 739
aoqi@0 740 Node *mproj;
aoqi@0 741
aoqi@0 742 // Is this a RegF low half of a RegD? Double up 2 adjacent RegF's
aoqi@0 743 // into a single RegD.
aoqi@0 744 if( (i&1) == 0 &&
aoqi@0 745 _register_save_type[i ] == Op_RegF &&
aoqi@0 746 _register_save_type[i+1] == Op_RegF &&
aoqi@0 747 is_save_on_entry(i+1) ) {
aoqi@0 748 // Add other bit for double
aoqi@0 749 ret_rms [ ret_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 750 reth_rms [ reth_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 751 tail_call_rms[tail_call_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 752 tail_jump_rms[tail_jump_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 753 halt_rms [ halt_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 754 mproj = new (C) MachProjNode( start, proj_cnt, ret_rms[ret_edge_cnt], Op_RegD );
aoqi@0 755 proj_cnt += 2; // Skip 2 for doubles
aoqi@0 756 }
aoqi@0 757 else if( (i&1) == 1 && // Else check for high half of double
aoqi@0 758 _register_save_type[i-1] == Op_RegF &&
aoqi@0 759 _register_save_type[i ] == Op_RegF &&
aoqi@0 760 is_save_on_entry(i-1) ) {
aoqi@0 761 ret_rms [ ret_edge_cnt] = RegMask::Empty;
aoqi@0 762 reth_rms [ reth_edge_cnt] = RegMask::Empty;
aoqi@0 763 tail_call_rms[tail_call_edge_cnt] = RegMask::Empty;
aoqi@0 764 tail_jump_rms[tail_jump_edge_cnt] = RegMask::Empty;
aoqi@0 765 halt_rms [ halt_edge_cnt] = RegMask::Empty;
aoqi@0 766 mproj = C->top();
aoqi@0 767 }
aoqi@0 768 // Is this a RegI low half of a RegL? Double up 2 adjacent RegI's
aoqi@0 769 // into a single RegL.
aoqi@0 770 else if( (i&1) == 0 &&
aoqi@0 771 _register_save_type[i ] == Op_RegI &&
aoqi@0 772 _register_save_type[i+1] == Op_RegI &&
aoqi@0 773 is_save_on_entry(i+1) ) {
aoqi@0 774 // Add other bit for long
aoqi@0 775 ret_rms [ ret_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 776 reth_rms [ reth_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 777 tail_call_rms[tail_call_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 778 tail_jump_rms[tail_jump_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 779 halt_rms [ halt_edge_cnt].Insert(OptoReg::Name(i+1));
aoqi@0 780 mproj = new (C) MachProjNode( start, proj_cnt, ret_rms[ret_edge_cnt], Op_RegL );
aoqi@0 781 proj_cnt += 2; // Skip 2 for longs
aoqi@0 782 }
aoqi@0 783 else if( (i&1) == 1 && // Else check for high half of long
aoqi@0 784 _register_save_type[i-1] == Op_RegI &&
aoqi@0 785 _register_save_type[i ] == Op_RegI &&
aoqi@0 786 is_save_on_entry(i-1) ) {
aoqi@0 787 ret_rms [ ret_edge_cnt] = RegMask::Empty;
aoqi@0 788 reth_rms [ reth_edge_cnt] = RegMask::Empty;
aoqi@0 789 tail_call_rms[tail_call_edge_cnt] = RegMask::Empty;
aoqi@0 790 tail_jump_rms[tail_jump_edge_cnt] = RegMask::Empty;
aoqi@0 791 halt_rms [ halt_edge_cnt] = RegMask::Empty;
aoqi@0 792 mproj = C->top();
aoqi@0 793 } else {
aoqi@0 794 // Make a projection for it off the Start
aoqi@0 795 mproj = new (C) MachProjNode( start, proj_cnt++, ret_rms[ret_edge_cnt], _register_save_type[i] );
aoqi@0 796 }
aoqi@0 797
aoqi@0 798 ret_edge_cnt ++;
aoqi@0 799 reth_edge_cnt ++;
aoqi@0 800 tail_call_edge_cnt ++;
aoqi@0 801 tail_jump_edge_cnt ++;
aoqi@0 802 halt_edge_cnt ++;
aoqi@0 803
aoqi@0 804 // Add a use of the SOE register to all exit paths
aoqi@0 805 for( uint j=1; j < root->req(); j++ )
aoqi@0 806 root->in(j)->add_req(mproj);
aoqi@0 807 } // End of if a save-on-entry register
aoqi@0 808 } // End of for all machine registers
aoqi@0 809 }
aoqi@0 810
aoqi@0 811 //------------------------------init_spill_mask--------------------------------
aoqi@0 812 void Matcher::init_spill_mask( Node *ret ) {
aoqi@0 813 if( idealreg2regmask[Op_RegI] ) return; // One time only init
aoqi@0 814
aoqi@0 815 OptoReg::c_frame_pointer = c_frame_pointer();
aoqi@0 816 c_frame_ptr_mask = c_frame_pointer();
aoqi@0 817 #ifdef _LP64
aoqi@0 818 // pointers are twice as big
aoqi@0 819 c_frame_ptr_mask.Insert(OptoReg::add(c_frame_pointer(),1));
aoqi@0 820 #endif
aoqi@0 821
aoqi@0 822 // Start at OptoReg::stack0()
aoqi@0 823 STACK_ONLY_mask.Clear();
aoqi@0 824 OptoReg::Name init = OptoReg::stack2reg(0);
aoqi@0 825 // STACK_ONLY_mask is all stack bits
aoqi@0 826 OptoReg::Name i;
aoqi@0 827 for (i = init; RegMask::can_represent(i); i = OptoReg::add(i,1))
aoqi@0 828 STACK_ONLY_mask.Insert(i);
aoqi@0 829 // Also set the "infinite stack" bit.
aoqi@0 830 STACK_ONLY_mask.set_AllStack();
aoqi@0 831
aoqi@0 832 // Copy the register names over into the shared world
aoqi@0 833 for( i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
aoqi@0 834 // SharedInfo::regName[i] = regName[i];
aoqi@0 835 // Handy RegMasks per machine register
aoqi@0 836 mreg2regmask[i].Insert(i);
aoqi@0 837 }
aoqi@0 838
aoqi@0 839 // Grab the Frame Pointer
aoqi@0 840 Node *fp = ret->in(TypeFunc::FramePtr);
aoqi@0 841 Node *mem = ret->in(TypeFunc::Memory);
aoqi@0 842 const TypePtr* atp = TypePtr::BOTTOM;
aoqi@0 843 // Share frame pointer while making spill ops
aoqi@0 844 set_shared(fp);
aoqi@0 845
aoqi@0 846 // Compute generic short-offset Loads
aoqi@0 847 #ifdef _LP64
aoqi@0 848 MachNode *spillCP = match_tree(new (C) LoadNNode(NULL,mem,fp,atp,TypeInstPtr::BOTTOM,MemNode::unordered));
aoqi@0 849 #endif
aoqi@0 850 MachNode *spillI = match_tree(new (C) LoadINode(NULL,mem,fp,atp,TypeInt::INT,MemNode::unordered));
aoqi@0 851 MachNode *spillL = match_tree(new (C) LoadLNode(NULL,mem,fp,atp,TypeLong::LONG,MemNode::unordered,false));
aoqi@0 852 MachNode *spillF = match_tree(new (C) LoadFNode(NULL,mem,fp,atp,Type::FLOAT,MemNode::unordered));
aoqi@0 853 MachNode *spillD = match_tree(new (C) LoadDNode(NULL,mem,fp,atp,Type::DOUBLE,MemNode::unordered));
aoqi@0 854 MachNode *spillP = match_tree(new (C) LoadPNode(NULL,mem,fp,atp,TypeInstPtr::BOTTOM,MemNode::unordered));
aoqi@0 855 assert(spillI != NULL && spillL != NULL && spillF != NULL &&
aoqi@0 856 spillD != NULL && spillP != NULL, "");
aoqi@0 857 // Get the ADLC notion of the right regmask, for each basic type.
aoqi@0 858 #ifdef _LP64
aoqi@0 859 idealreg2regmask[Op_RegN] = &spillCP->out_RegMask();
aoqi@0 860 #endif
aoqi@0 861 idealreg2regmask[Op_RegI] = &spillI->out_RegMask();
aoqi@0 862 idealreg2regmask[Op_RegL] = &spillL->out_RegMask();
aoqi@0 863 idealreg2regmask[Op_RegF] = &spillF->out_RegMask();
aoqi@0 864 idealreg2regmask[Op_RegD] = &spillD->out_RegMask();
aoqi@0 865 idealreg2regmask[Op_RegP] = &spillP->out_RegMask();
aoqi@0 866
aoqi@0 867 // Vector regmasks.
aoqi@0 868 if (Matcher::vector_size_supported(T_BYTE,4)) {
aoqi@0 869 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
aoqi@0 870 MachNode *spillVectS = match_tree(new (C) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTS));
aoqi@0 871 idealreg2regmask[Op_VecS] = &spillVectS->out_RegMask();
aoqi@0 872 }
aoqi@0 873 if (Matcher::vector_size_supported(T_FLOAT,2)) {
aoqi@0 874 MachNode *spillVectD = match_tree(new (C) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTD));
aoqi@0 875 idealreg2regmask[Op_VecD] = &spillVectD->out_RegMask();
aoqi@0 876 }
aoqi@0 877 if (Matcher::vector_size_supported(T_FLOAT,4)) {
aoqi@0 878 MachNode *spillVectX = match_tree(new (C) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTX));
aoqi@0 879 idealreg2regmask[Op_VecX] = &spillVectX->out_RegMask();
aoqi@0 880 }
aoqi@0 881 if (Matcher::vector_size_supported(T_FLOAT,8)) {
aoqi@0 882 MachNode *spillVectY = match_tree(new (C) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTY));
aoqi@0 883 idealreg2regmask[Op_VecY] = &spillVectY->out_RegMask();
aoqi@0 884 }
aoqi@0 885 }
aoqi@0 886
aoqi@0 887 #ifdef ASSERT
aoqi@0 888 static void match_alias_type(Compile* C, Node* n, Node* m) {
aoqi@0 889 if (!VerifyAliases) return; // do not go looking for trouble by default
aoqi@0 890 const TypePtr* nat = n->adr_type();
aoqi@0 891 const TypePtr* mat = m->adr_type();
aoqi@0 892 int nidx = C->get_alias_index(nat);
aoqi@0 893 int midx = C->get_alias_index(mat);
aoqi@0 894 // Detune the assert for cases like (AndI 0xFF (LoadB p)).
aoqi@0 895 if (nidx == Compile::AliasIdxTop && midx >= Compile::AliasIdxRaw) {
aoqi@0 896 for (uint i = 1; i < n->req(); i++) {
aoqi@0 897 Node* n1 = n->in(i);
aoqi@0 898 const TypePtr* n1at = n1->adr_type();
aoqi@0 899 if (n1at != NULL) {
aoqi@0 900 nat = n1at;
aoqi@0 901 nidx = C->get_alias_index(n1at);
aoqi@0 902 }
aoqi@0 903 }
aoqi@0 904 }
aoqi@0 905 // %%% Kludgery. Instead, fix ideal adr_type methods for all these cases:
aoqi@0 906 if (nidx == Compile::AliasIdxTop && midx == Compile::AliasIdxRaw) {
aoqi@0 907 switch (n->Opcode()) {
aoqi@0 908 case Op_PrefetchRead:
aoqi@0 909 case Op_PrefetchWrite:
aoqi@0 910 case Op_PrefetchAllocation:
aoqi@0 911 nidx = Compile::AliasIdxRaw;
aoqi@0 912 nat = TypeRawPtr::BOTTOM;
aoqi@0 913 break;
aoqi@0 914 }
aoqi@0 915 }
aoqi@0 916 if (nidx == Compile::AliasIdxRaw && midx == Compile::AliasIdxTop) {
aoqi@0 917 switch (n->Opcode()) {
aoqi@0 918 case Op_ClearArray:
aoqi@0 919 midx = Compile::AliasIdxRaw;
aoqi@0 920 mat = TypeRawPtr::BOTTOM;
aoqi@0 921 break;
aoqi@0 922 }
aoqi@0 923 }
aoqi@0 924 if (nidx == Compile::AliasIdxTop && midx == Compile::AliasIdxBot) {
aoqi@0 925 switch (n->Opcode()) {
aoqi@0 926 case Op_Return:
aoqi@0 927 case Op_Rethrow:
aoqi@0 928 case Op_Halt:
aoqi@0 929 case Op_TailCall:
aoqi@0 930 case Op_TailJump:
aoqi@0 931 nidx = Compile::AliasIdxBot;
aoqi@0 932 nat = TypePtr::BOTTOM;
aoqi@0 933 break;
aoqi@0 934 }
aoqi@0 935 }
aoqi@0 936 if (nidx == Compile::AliasIdxBot && midx == Compile::AliasIdxTop) {
aoqi@0 937 switch (n->Opcode()) {
aoqi@0 938 case Op_StrComp:
aoqi@0 939 case Op_StrEquals:
aoqi@0 940 case Op_StrIndexOf:
aoqi@0 941 case Op_AryEq:
aoqi@0 942 case Op_MemBarVolatile:
aoqi@0 943 case Op_MemBarCPUOrder: // %%% these ideals should have narrower adr_type?
aoqi@0 944 case Op_EncodeISOArray:
aoqi@0 945 nidx = Compile::AliasIdxTop;
aoqi@0 946 nat = NULL;
aoqi@0 947 break;
aoqi@0 948 }
aoqi@0 949 }
aoqi@0 950 if (nidx != midx) {
aoqi@0 951 if (PrintOpto || (PrintMiscellaneous && (WizardMode || Verbose))) {
aoqi@0 952 tty->print_cr("==== Matcher alias shift %d => %d", nidx, midx);
aoqi@0 953 n->dump();
aoqi@0 954 m->dump();
aoqi@0 955 }
aoqi@0 956 assert(C->subsume_loads() && C->must_alias(nat, midx),
aoqi@0 957 "must not lose alias info when matching");
aoqi@0 958 }
aoqi@0 959 }
aoqi@0 960 #endif
aoqi@0 961
aoqi@0 962
aoqi@0 963 //------------------------------MStack-----------------------------------------
aoqi@0 964 // State and MStack class used in xform() and find_shared() iterative methods.
aoqi@0 965 enum Node_State { Pre_Visit, // node has to be pre-visited
aoqi@0 966 Visit, // visit node
aoqi@0 967 Post_Visit, // post-visit node
aoqi@0 968 Alt_Post_Visit // alternative post-visit path
aoqi@0 969 };
aoqi@0 970
aoqi@0 971 class MStack: public Node_Stack {
aoqi@0 972 public:
aoqi@0 973 MStack(int size) : Node_Stack(size) { }
aoqi@0 974
aoqi@0 975 void push(Node *n, Node_State ns) {
aoqi@0 976 Node_Stack::push(n, (uint)ns);
aoqi@0 977 }
aoqi@0 978 void push(Node *n, Node_State ns, Node *parent, int indx) {
aoqi@0 979 ++_inode_top;
aoqi@0 980 if ((_inode_top + 1) >= _inode_max) grow();
aoqi@0 981 _inode_top->node = parent;
aoqi@0 982 _inode_top->indx = (uint)indx;
aoqi@0 983 ++_inode_top;
aoqi@0 984 _inode_top->node = n;
aoqi@0 985 _inode_top->indx = (uint)ns;
aoqi@0 986 }
aoqi@0 987 Node *parent() {
aoqi@0 988 pop();
aoqi@0 989 return node();
aoqi@0 990 }
aoqi@0 991 Node_State state() const {
aoqi@0 992 return (Node_State)index();
aoqi@0 993 }
aoqi@0 994 void set_state(Node_State ns) {
aoqi@0 995 set_index((uint)ns);
aoqi@0 996 }
aoqi@0 997 };
aoqi@0 998
aoqi@0 999
aoqi@0 1000 //------------------------------xform------------------------------------------
aoqi@0 1001 // Given a Node in old-space, Match him (Label/Reduce) to produce a machine
aoqi@0 1002 // Node in new-space. Given a new-space Node, recursively walk his children.
aoqi@0 1003 Node *Matcher::transform( Node *n ) { ShouldNotCallThis(); return n; }
aoqi@0 1004 Node *Matcher::xform( Node *n, int max_stack ) {
aoqi@0 1005 // Use one stack to keep both: child's node/state and parent's node/index
aoqi@0 1006 MStack mstack(max_stack * 2 * 2); // C->unique() * 2 * 2
aoqi@0 1007 mstack.push(n, Visit, NULL, -1); // set NULL as parent to indicate root
aoqi@0 1008
aoqi@0 1009 while (mstack.is_nonempty()) {
aoqi@0 1010 C->check_node_count(NodeLimitFudgeFactor, "too many nodes matching instructions");
aoqi@0 1011 if (C->failing()) return NULL;
aoqi@0 1012 n = mstack.node(); // Leave node on stack
aoqi@0 1013 Node_State nstate = mstack.state();
aoqi@0 1014 if (nstate == Visit) {
aoqi@0 1015 mstack.set_state(Post_Visit);
aoqi@0 1016 Node *oldn = n;
aoqi@0 1017 // Old-space or new-space check
aoqi@0 1018 if (!C->node_arena()->contains(n)) {
aoqi@0 1019 // Old space!
aoqi@0 1020 Node* m;
aoqi@0 1021 if (has_new_node(n)) { // Not yet Label/Reduced
aoqi@0 1022 m = new_node(n);
aoqi@0 1023 } else {
aoqi@0 1024 if (!is_dontcare(n)) { // Matcher can match this guy
aoqi@0 1025 // Calls match special. They match alone with no children.
aoqi@0 1026 // Their children, the incoming arguments, match normally.
aoqi@0 1027 m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n);
aoqi@0 1028 if (C->failing()) return NULL;
aoqi@0 1029 if (m == NULL) { Matcher::soft_match_failure(); return NULL; }
aoqi@0 1030 } else { // Nothing the matcher cares about
aoqi@0 1031 if( n->is_Proj() && n->in(0)->is_Multi()) { // Projections?
aoqi@0 1032 // Convert to machine-dependent projection
aoqi@0 1033 m = n->in(0)->as_Multi()->match( n->as_Proj(), this );
aoqi@0 1034 #ifdef ASSERT
aoqi@0 1035 _new2old_map.map(m->_idx, n);
aoqi@0 1036 #endif
aoqi@0 1037 if (m->in(0) != NULL) // m might be top
aoqi@0 1038 collect_null_checks(m, n);
aoqi@0 1039 } else { // Else just a regular 'ol guy
aoqi@0 1040 m = n->clone(); // So just clone into new-space
aoqi@0 1041 #ifdef ASSERT
aoqi@0 1042 _new2old_map.map(m->_idx, n);
aoqi@0 1043 #endif
aoqi@0 1044 // Def-Use edges will be added incrementally as Uses
aoqi@0 1045 // of this node are matched.
aoqi@0 1046 assert(m->outcnt() == 0, "no Uses of this clone yet");
aoqi@0 1047 }
aoqi@0 1048 }
aoqi@0 1049
aoqi@0 1050 set_new_node(n, m); // Map old to new
aoqi@0 1051 if (_old_node_note_array != NULL) {
aoqi@0 1052 Node_Notes* nn = C->locate_node_notes(_old_node_note_array,
aoqi@0 1053 n->_idx);
aoqi@0 1054 C->set_node_notes_at(m->_idx, nn);
aoqi@0 1055 }
aoqi@0 1056 debug_only(match_alias_type(C, n, m));
aoqi@0 1057 }
aoqi@0 1058 n = m; // n is now a new-space node
aoqi@0 1059 mstack.set_node(n);
aoqi@0 1060 }
aoqi@0 1061
aoqi@0 1062 // New space!
aoqi@0 1063 if (_visited.test_set(n->_idx)) continue; // while(mstack.is_nonempty())
aoqi@0 1064
aoqi@0 1065 int i;
aoqi@0 1066 // Put precedence edges on stack first (match them last).
aoqi@0 1067 for (i = oldn->req(); (uint)i < oldn->len(); i++) {
aoqi@0 1068 Node *m = oldn->in(i);
aoqi@0 1069 if (m == NULL) break;
aoqi@0 1070 // set -1 to call add_prec() instead of set_req() during Step1
aoqi@0 1071 mstack.push(m, Visit, n, -1);
aoqi@0 1072 }
aoqi@0 1073
aoqi@0 1074 // For constant debug info, I'd rather have unmatched constants.
aoqi@0 1075 int cnt = n->req();
aoqi@0 1076 JVMState* jvms = n->jvms();
aoqi@0 1077 int debug_cnt = jvms ? jvms->debug_start() : cnt;
aoqi@0 1078
aoqi@0 1079 // Now do only debug info. Clone constants rather than matching.
aoqi@0 1080 // Constants are represented directly in the debug info without
aoqi@0 1081 // the need for executable machine instructions.
aoqi@0 1082 // Monitor boxes are also represented directly.
aoqi@0 1083 for (i = cnt - 1; i >= debug_cnt; --i) { // For all debug inputs do
aoqi@0 1084 Node *m = n->in(i); // Get input
aoqi@0 1085 int op = m->Opcode();
aoqi@0 1086 assert((op == Op_BoxLock) == jvms->is_monitor_use(i), "boxes only at monitor sites");
aoqi@0 1087 if( op == Op_ConI || op == Op_ConP || op == Op_ConN || op == Op_ConNKlass ||
aoqi@0 1088 op == Op_ConF || op == Op_ConD || op == Op_ConL
aoqi@0 1089 // || op == Op_BoxLock // %%%% enable this and remove (+++) in chaitin.cpp
aoqi@0 1090 ) {
aoqi@0 1091 m = m->clone();
aoqi@0 1092 #ifdef ASSERT
aoqi@0 1093 _new2old_map.map(m->_idx, n);
aoqi@0 1094 #endif
aoqi@0 1095 mstack.push(m, Post_Visit, n, i); // Don't need to visit
aoqi@0 1096 mstack.push(m->in(0), Visit, m, 0);
aoqi@0 1097 } else {
aoqi@0 1098 mstack.push(m, Visit, n, i);
aoqi@0 1099 }
aoqi@0 1100 }
aoqi@0 1101
aoqi@0 1102 // And now walk his children, and convert his inputs to new-space.
aoqi@0 1103 for( ; i >= 0; --i ) { // For all normal inputs do
aoqi@0 1104 Node *m = n->in(i); // Get input
aoqi@0 1105 if(m != NULL)
aoqi@0 1106 mstack.push(m, Visit, n, i);
aoqi@0 1107 }
aoqi@0 1108
aoqi@0 1109 }
aoqi@0 1110 else if (nstate == Post_Visit) {
aoqi@0 1111 // Set xformed input
aoqi@0 1112 Node *p = mstack.parent();
aoqi@0 1113 if (p != NULL) { // root doesn't have parent
aoqi@0 1114 int i = (int)mstack.index();
aoqi@0 1115 if (i >= 0)
aoqi@0 1116 p->set_req(i, n); // required input
aoqi@0 1117 else if (i == -1)
aoqi@0 1118 p->add_prec(n); // precedence input
aoqi@0 1119 else
aoqi@0 1120 ShouldNotReachHere();
aoqi@0 1121 }
aoqi@0 1122 mstack.pop(); // remove processed node from stack
aoqi@0 1123 }
aoqi@0 1124 else {
aoqi@0 1125 ShouldNotReachHere();
aoqi@0 1126 }
aoqi@0 1127 } // while (mstack.is_nonempty())
aoqi@0 1128 return n; // Return new-space Node
aoqi@0 1129 }
aoqi@0 1130
aoqi@0 1131 //------------------------------warp_outgoing_stk_arg------------------------
aoqi@0 1132 OptoReg::Name Matcher::warp_outgoing_stk_arg( VMReg reg, OptoReg::Name begin_out_arg_area, OptoReg::Name &out_arg_limit_per_call ) {
aoqi@0 1133 // Convert outgoing argument location to a pre-biased stack offset
aoqi@0 1134 if (reg->is_stack()) {
aoqi@0 1135 OptoReg::Name warped = reg->reg2stack();
aoqi@0 1136 // Adjust the stack slot offset to be the register number used
aoqi@0 1137 // by the allocator.
aoqi@0 1138 warped = OptoReg::add(begin_out_arg_area, warped);
aoqi@0 1139 // Keep track of the largest numbered stack slot used for an arg.
aoqi@0 1140 // Largest used slot per call-site indicates the amount of stack
aoqi@0 1141 // that is killed by the call.
aoqi@0 1142 if( warped >= out_arg_limit_per_call )
aoqi@0 1143 out_arg_limit_per_call = OptoReg::add(warped,1);
aoqi@0 1144 if (!RegMask::can_represent_arg(warped)) {
aoqi@0 1145 C->record_method_not_compilable_all_tiers("unsupported calling sequence");
aoqi@0 1146 return OptoReg::Bad;
aoqi@0 1147 }
aoqi@0 1148 return warped;
aoqi@0 1149 }
aoqi@0 1150 return OptoReg::as_OptoReg(reg);
aoqi@0 1151 }
aoqi@0 1152
aoqi@0 1153
aoqi@0 1154 //------------------------------match_sfpt-------------------------------------
aoqi@0 1155 // Helper function to match call instructions. Calls match special.
aoqi@0 1156 // They match alone with no children. Their children, the incoming
aoqi@0 1157 // arguments, match normally.
aoqi@0 1158 MachNode *Matcher::match_sfpt( SafePointNode *sfpt ) {
aoqi@0 1159 MachSafePointNode *msfpt = NULL;
aoqi@0 1160 MachCallNode *mcall = NULL;
aoqi@0 1161 uint cnt;
aoqi@0 1162 // Split out case for SafePoint vs Call
aoqi@0 1163 CallNode *call;
aoqi@0 1164 const TypeTuple *domain;
aoqi@0 1165 ciMethod* method = NULL;
aoqi@0 1166 bool is_method_handle_invoke = false; // for special kill effects
aoqi@0 1167 if( sfpt->is_Call() ) {
aoqi@0 1168 call = sfpt->as_Call();
aoqi@0 1169 domain = call->tf()->domain();
aoqi@0 1170 cnt = domain->cnt();
aoqi@0 1171
aoqi@0 1172 // Match just the call, nothing else
aoqi@0 1173 MachNode *m = match_tree(call);
aoqi@0 1174 if (C->failing()) return NULL;
aoqi@0 1175 if( m == NULL ) { Matcher::soft_match_failure(); return NULL; }
aoqi@0 1176
aoqi@0 1177 // Copy data from the Ideal SafePoint to the machine version
aoqi@0 1178 mcall = m->as_MachCall();
aoqi@0 1179
aoqi@0 1180 mcall->set_tf( call->tf());
aoqi@0 1181 mcall->set_entry_point(call->entry_point());
aoqi@0 1182 mcall->set_cnt( call->cnt());
aoqi@0 1183
aoqi@0 1184 if( mcall->is_MachCallJava() ) {
aoqi@0 1185 MachCallJavaNode *mcall_java = mcall->as_MachCallJava();
aoqi@0 1186 const CallJavaNode *call_java = call->as_CallJava();
aoqi@0 1187 method = call_java->method();
aoqi@0 1188 mcall_java->_method = method;
aoqi@0 1189 mcall_java->_bci = call_java->_bci;
aoqi@0 1190 mcall_java->_optimized_virtual = call_java->is_optimized_virtual();
aoqi@0 1191 is_method_handle_invoke = call_java->is_method_handle_invoke();
aoqi@0 1192 mcall_java->_method_handle_invoke = is_method_handle_invoke;
aoqi@0 1193 if (is_method_handle_invoke) {
aoqi@0 1194 C->set_has_method_handle_invokes(true);
aoqi@0 1195 }
aoqi@0 1196 if( mcall_java->is_MachCallStaticJava() )
aoqi@0 1197 mcall_java->as_MachCallStaticJava()->_name =
aoqi@0 1198 call_java->as_CallStaticJava()->_name;
aoqi@0 1199 if( mcall_java->is_MachCallDynamicJava() )
aoqi@0 1200 mcall_java->as_MachCallDynamicJava()->_vtable_index =
aoqi@0 1201 call_java->as_CallDynamicJava()->_vtable_index;
aoqi@0 1202 }
aoqi@0 1203 else if( mcall->is_MachCallRuntime() ) {
aoqi@0 1204 mcall->as_MachCallRuntime()->_name = call->as_CallRuntime()->_name;
aoqi@0 1205 }
aoqi@0 1206 msfpt = mcall;
aoqi@0 1207 }
aoqi@0 1208 // This is a non-call safepoint
aoqi@0 1209 else {
aoqi@0 1210 call = NULL;
aoqi@0 1211 domain = NULL;
aoqi@0 1212 MachNode *mn = match_tree(sfpt);
aoqi@0 1213 if (C->failing()) return NULL;
aoqi@0 1214 msfpt = mn->as_MachSafePoint();
aoqi@0 1215 cnt = TypeFunc::Parms;
aoqi@0 1216 }
aoqi@0 1217
aoqi@0 1218 // Advertise the correct memory effects (for anti-dependence computation).
aoqi@0 1219 msfpt->set_adr_type(sfpt->adr_type());
aoqi@0 1220
aoqi@0 1221 // Allocate a private array of RegMasks. These RegMasks are not shared.
aoqi@0 1222 msfpt->_in_rms = NEW_RESOURCE_ARRAY( RegMask, cnt );
aoqi@0 1223 // Empty them all.
aoqi@0 1224 memset( msfpt->_in_rms, 0, sizeof(RegMask)*cnt );
aoqi@0 1225
aoqi@0 1226 // Do all the pre-defined non-Empty register masks
aoqi@0 1227 msfpt->_in_rms[TypeFunc::ReturnAdr] = _return_addr_mask;
aoqi@0 1228 msfpt->_in_rms[TypeFunc::FramePtr ] = c_frame_ptr_mask;
aoqi@0 1229
aoqi@0 1230 // Place first outgoing argument can possibly be put.
aoqi@0 1231 OptoReg::Name begin_out_arg_area = OptoReg::add(_new_SP, C->out_preserve_stack_slots());
aoqi@0 1232 assert( is_even(begin_out_arg_area), "" );
aoqi@0 1233 // Compute max outgoing register number per call site.
aoqi@0 1234 OptoReg::Name out_arg_limit_per_call = begin_out_arg_area;
aoqi@0 1235 // Calls to C may hammer extra stack slots above and beyond any arguments.
aoqi@0 1236 // These are usually backing store for register arguments for varargs.
aoqi@0 1237 if( call != NULL && call->is_CallRuntime() )
aoqi@0 1238 out_arg_limit_per_call = OptoReg::add(out_arg_limit_per_call,C->varargs_C_out_slots_killed());
aoqi@0 1239
aoqi@0 1240
aoqi@0 1241 // Do the normal argument list (parameters) register masks
aoqi@0 1242 int argcnt = cnt - TypeFunc::Parms;
aoqi@0 1243 if( argcnt > 0 ) { // Skip it all if we have no args
aoqi@0 1244 BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, argcnt );
aoqi@0 1245 VMRegPair *parm_regs = NEW_RESOURCE_ARRAY( VMRegPair, argcnt );
aoqi@0 1246 int i;
aoqi@0 1247 for( i = 0; i < argcnt; i++ ) {
aoqi@0 1248 sig_bt[i] = domain->field_at(i+TypeFunc::Parms)->basic_type();
aoqi@0 1249 }
aoqi@0 1250 // V-call to pick proper calling convention
aoqi@0 1251 call->calling_convention( sig_bt, parm_regs, argcnt );
aoqi@0 1252
aoqi@0 1253 #ifdef ASSERT
aoqi@0 1254 // Sanity check users' calling convention. Really handy during
aoqi@0 1255 // the initial porting effort. Fairly expensive otherwise.
aoqi@0 1256 { for (int i = 0; i<argcnt; i++) {
aoqi@0 1257 if( !parm_regs[i].first()->is_valid() &&
aoqi@0 1258 !parm_regs[i].second()->is_valid() ) continue;
aoqi@0 1259 VMReg reg1 = parm_regs[i].first();
aoqi@0 1260 VMReg reg2 = parm_regs[i].second();
aoqi@0 1261 for (int j = 0; j < i; j++) {
aoqi@0 1262 if( !parm_regs[j].first()->is_valid() &&
aoqi@0 1263 !parm_regs[j].second()->is_valid() ) continue;
aoqi@0 1264 VMReg reg3 = parm_regs[j].first();
aoqi@0 1265 VMReg reg4 = parm_regs[j].second();
aoqi@0 1266 if( !reg1->is_valid() ) {
aoqi@0 1267 assert( !reg2->is_valid(), "valid halvsies" );
aoqi@0 1268 } else if( !reg3->is_valid() ) {
aoqi@0 1269 assert( !reg4->is_valid(), "valid halvsies" );
aoqi@0 1270 } else {
aoqi@0 1271 assert( reg1 != reg2, "calling conv. must produce distinct regs");
aoqi@0 1272 assert( reg1 != reg3, "calling conv. must produce distinct regs");
aoqi@0 1273 assert( reg1 != reg4, "calling conv. must produce distinct regs");
aoqi@0 1274 assert( reg2 != reg3, "calling conv. must produce distinct regs");
aoqi@0 1275 assert( reg2 != reg4 || !reg2->is_valid(), "calling conv. must produce distinct regs");
aoqi@0 1276 assert( reg3 != reg4, "calling conv. must produce distinct regs");
aoqi@0 1277 }
aoqi@0 1278 }
aoqi@0 1279 }
aoqi@0 1280 }
aoqi@0 1281 #endif
aoqi@0 1282
aoqi@0 1283 // Visit each argument. Compute its outgoing register mask.
aoqi@0 1284 // Return results now can have 2 bits returned.
aoqi@0 1285 // Compute max over all outgoing arguments both per call-site
aoqi@0 1286 // and over the entire method.
aoqi@0 1287 for( i = 0; i < argcnt; i++ ) {
aoqi@0 1288 // Address of incoming argument mask to fill in
aoqi@0 1289 RegMask *rm = &mcall->_in_rms[i+TypeFunc::Parms];
aoqi@0 1290 if( !parm_regs[i].first()->is_valid() &&
aoqi@0 1291 !parm_regs[i].second()->is_valid() ) {
aoqi@0 1292 continue; // Avoid Halves
aoqi@0 1293 }
aoqi@0 1294 // Grab first register, adjust stack slots and insert in mask.
aoqi@0 1295 OptoReg::Name reg1 = warp_outgoing_stk_arg(parm_regs[i].first(), begin_out_arg_area, out_arg_limit_per_call );
aoqi@0 1296 if (OptoReg::is_valid(reg1))
aoqi@0 1297 rm->Insert( reg1 );
aoqi@0 1298 // Grab second register (if any), adjust stack slots and insert in mask.
aoqi@0 1299 OptoReg::Name reg2 = warp_outgoing_stk_arg(parm_regs[i].second(), begin_out_arg_area, out_arg_limit_per_call );
aoqi@0 1300 if (OptoReg::is_valid(reg2))
aoqi@0 1301 rm->Insert( reg2 );
aoqi@0 1302 } // End of for all arguments
aoqi@0 1303
aoqi@0 1304 // Compute number of stack slots needed to restore stack in case of
aoqi@0 1305 // Pascal-style argument popping.
aoqi@0 1306 mcall->_argsize = out_arg_limit_per_call - begin_out_arg_area;
aoqi@0 1307 }
aoqi@0 1308
aoqi@0 1309 // Compute the max stack slot killed by any call. These will not be
aoqi@0 1310 // available for debug info, and will be used to adjust FIRST_STACK_mask
aoqi@0 1311 // after all call sites have been visited.
aoqi@0 1312 if( _out_arg_limit < out_arg_limit_per_call)
aoqi@0 1313 _out_arg_limit = out_arg_limit_per_call;
aoqi@0 1314
aoqi@0 1315 if (mcall) {
aoqi@0 1316 // Kill the outgoing argument area, including any non-argument holes and
aoqi@0 1317 // any legacy C-killed slots. Use Fat-Projections to do the killing.
aoqi@0 1318 // Since the max-per-method covers the max-per-call-site and debug info
aoqi@0 1319 // is excluded on the max-per-method basis, debug info cannot land in
aoqi@0 1320 // this killed area.
aoqi@0 1321 uint r_cnt = mcall->tf()->range()->cnt();
aoqi@0 1322 MachProjNode *proj = new (C) MachProjNode( mcall, r_cnt+10000, RegMask::Empty, MachProjNode::fat_proj );
aoqi@0 1323 if (!RegMask::can_represent_arg(OptoReg::Name(out_arg_limit_per_call-1))) {
aoqi@0 1324 C->record_method_not_compilable_all_tiers("unsupported outgoing calling sequence");
aoqi@0 1325 } else {
aoqi@0 1326 for (int i = begin_out_arg_area; i < out_arg_limit_per_call; i++)
aoqi@0 1327 proj->_rout.Insert(OptoReg::Name(i));
aoqi@0 1328 }
aoqi@0 1329 if (proj->_rout.is_NotEmpty()) {
aoqi@0 1330 push_projection(proj);
aoqi@0 1331 }
aoqi@0 1332 }
aoqi@0 1333 // Transfer the safepoint information from the call to the mcall
aoqi@0 1334 // Move the JVMState list
aoqi@0 1335 msfpt->set_jvms(sfpt->jvms());
aoqi@0 1336 for (JVMState* jvms = msfpt->jvms(); jvms; jvms = jvms->caller()) {
aoqi@0 1337 jvms->set_map(sfpt);
aoqi@0 1338 }
aoqi@0 1339
aoqi@0 1340 // Debug inputs begin just after the last incoming parameter
aoqi@0 1341 assert((mcall == NULL) || (mcall->jvms() == NULL) ||
aoqi@0 1342 (mcall->jvms()->debug_start() + mcall->_jvmadj == mcall->tf()->domain()->cnt()), "");
aoqi@0 1343
aoqi@0 1344 // Move the OopMap
aoqi@0 1345 msfpt->_oop_map = sfpt->_oop_map;
aoqi@0 1346
aoqi@0 1347 // Add additional edges.
aoqi@0 1348 if (msfpt->mach_constant_base_node_input() != (uint)-1 && !msfpt->is_MachCallLeaf()) {
aoqi@0 1349 // For these calls we can not add MachConstantBase in expand(), as the
aoqi@0 1350 // ins are not complete then.
aoqi@0 1351 msfpt->ins_req(msfpt->mach_constant_base_node_input(), C->mach_constant_base_node());
aoqi@0 1352 if (msfpt->jvms() &&
aoqi@0 1353 msfpt->mach_constant_base_node_input() <= msfpt->jvms()->debug_start() + msfpt->_jvmadj) {
aoqi@0 1354 // We added an edge before jvms, so we must adapt the position of the ins.
aoqi@0 1355 msfpt->jvms()->adapt_position(+1);
aoqi@0 1356 }
aoqi@0 1357 }
aoqi@0 1358
aoqi@0 1359 // Registers killed by the call are set in the local scheduling pass
aoqi@0 1360 // of Global Code Motion.
aoqi@0 1361 return msfpt;
aoqi@0 1362 }
aoqi@0 1363
aoqi@0 1364 //---------------------------match_tree----------------------------------------
aoqi@0 1365 // Match a Ideal Node DAG - turn it into a tree; Label & Reduce. Used as part
aoqi@0 1366 // of the whole-sale conversion from Ideal to Mach Nodes. Also used for
aoqi@0 1367 // making GotoNodes while building the CFG and in init_spill_mask() to identify
aoqi@0 1368 // a Load's result RegMask for memoization in idealreg2regmask[]
aoqi@0 1369 MachNode *Matcher::match_tree( const Node *n ) {
aoqi@0 1370 assert( n->Opcode() != Op_Phi, "cannot match" );
aoqi@0 1371 assert( !n->is_block_start(), "cannot match" );
aoqi@0 1372 // Set the mark for all locally allocated State objects.
aoqi@0 1373 // When this call returns, the _states_arena arena will be reset
aoqi@0 1374 // freeing all State objects.
aoqi@0 1375 ResourceMark rm( &_states_arena );
aoqi@0 1376
aoqi@0 1377 LabelRootDepth = 0;
aoqi@0 1378
aoqi@0 1379 // StoreNodes require their Memory input to match any LoadNodes
aoqi@0 1380 Node *mem = n->is_Store() ? n->in(MemNode::Memory) : (Node*)1 ;
aoqi@0 1381 #ifdef ASSERT
aoqi@0 1382 Node* save_mem_node = _mem_node;
aoqi@0 1383 _mem_node = n->is_Store() ? (Node*)n : NULL;
aoqi@0 1384 #endif
aoqi@0 1385 // State object for root node of match tree
aoqi@0 1386 // Allocate it on _states_arena - stack allocation can cause stack overflow.
aoqi@0 1387 State *s = new (&_states_arena) State;
aoqi@0 1388 s->_kids[0] = NULL;
aoqi@0 1389 s->_kids[1] = NULL;
aoqi@0 1390 s->_leaf = (Node*)n;
aoqi@0 1391 // Label the input tree, allocating labels from top-level arena
aoqi@0 1392 Label_Root( n, s, n->in(0), mem );
aoqi@0 1393 if (C->failing()) return NULL;
aoqi@0 1394
aoqi@0 1395 // The minimum cost match for the whole tree is found at the root State
aoqi@0 1396 uint mincost = max_juint;
aoqi@0 1397 uint cost = max_juint;
aoqi@0 1398 uint i;
aoqi@0 1399 for( i = 0; i < NUM_OPERANDS; i++ ) {
aoqi@0 1400 if( s->valid(i) && // valid entry and
aoqi@0 1401 s->_cost[i] < cost && // low cost and
aoqi@0 1402 s->_rule[i] >= NUM_OPERANDS ) // not an operand
aoqi@0 1403 cost = s->_cost[mincost=i];
aoqi@0 1404 }
aoqi@0 1405 if (mincost == max_juint) {
aoqi@0 1406 #ifndef PRODUCT
aoqi@0 1407 tty->print("No matching rule for:");
aoqi@0 1408 s->dump();
aoqi@0 1409 #endif
aoqi@0 1410 Matcher::soft_match_failure();
aoqi@0 1411 return NULL;
aoqi@0 1412 }
aoqi@0 1413 // Reduce input tree based upon the state labels to machine Nodes
aoqi@0 1414 MachNode *m = ReduceInst( s, s->_rule[mincost], mem );
aoqi@0 1415 #ifdef ASSERT
aoqi@0 1416 _old2new_map.map(n->_idx, m);
aoqi@0 1417 _new2old_map.map(m->_idx, (Node*)n);
aoqi@0 1418 #endif
aoqi@0 1419
aoqi@0 1420 // Add any Matcher-ignored edges
aoqi@0 1421 uint cnt = n->req();
aoqi@0 1422 uint start = 1;
aoqi@0 1423 if( mem != (Node*)1 ) start = MemNode::Memory+1;
aoqi@0 1424 if( n->is_AddP() ) {
aoqi@0 1425 assert( mem == (Node*)1, "" );
aoqi@0 1426 start = AddPNode::Base+1;
aoqi@0 1427 }
aoqi@0 1428 for( i = start; i < cnt; i++ ) {
aoqi@0 1429 if( !n->match_edge(i) ) {
aoqi@0 1430 if( i < m->req() )
aoqi@0 1431 m->ins_req( i, n->in(i) );
aoqi@0 1432 else
aoqi@0 1433 m->add_req( n->in(i) );
aoqi@0 1434 }
aoqi@0 1435 }
aoqi@0 1436
aoqi@0 1437 debug_only( _mem_node = save_mem_node; )
aoqi@0 1438 return m;
aoqi@0 1439 }
aoqi@0 1440
aoqi@0 1441
aoqi@0 1442 //------------------------------match_into_reg---------------------------------
aoqi@0 1443 // Choose to either match this Node in a register or part of the current
aoqi@0 1444 // match tree. Return true for requiring a register and false for matching
aoqi@0 1445 // as part of the current match tree.
aoqi@0 1446 static bool match_into_reg( const Node *n, Node *m, Node *control, int i, bool shared ) {
aoqi@0 1447
aoqi@0 1448 const Type *t = m->bottom_type();
aoqi@0 1449
aoqi@0 1450 if (t->singleton()) {
aoqi@0 1451 // Never force constants into registers. Allow them to match as
aoqi@0 1452 // constants or registers. Copies of the same value will share
aoqi@0 1453 // the same register. See find_shared_node.
aoqi@0 1454 return false;
aoqi@0 1455 } else { // Not a constant
aoqi@0 1456 // Stop recursion if they have different Controls.
aoqi@0 1457 Node* m_control = m->in(0);
aoqi@0 1458 // Control of load's memory can post-dominates load's control.
aoqi@0 1459 // So use it since load can't float above its memory.
aoqi@0 1460 Node* mem_control = (m->is_Load()) ? m->in(MemNode::Memory)->in(0) : NULL;
aoqi@0 1461 if (control && m_control && control != m_control && control != mem_control) {
aoqi@0 1462
aoqi@0 1463 // Actually, we can live with the most conservative control we
aoqi@0 1464 // find, if it post-dominates the others. This allows us to
aoqi@0 1465 // pick up load/op/store trees where the load can float a little
aoqi@0 1466 // above the store.
aoqi@0 1467 Node *x = control;
aoqi@0 1468 const uint max_scan = 6; // Arbitrary scan cutoff
aoqi@0 1469 uint j;
aoqi@0 1470 for (j=0; j<max_scan; j++) {
aoqi@0 1471 if (x->is_Region()) // Bail out at merge points
aoqi@0 1472 return true;
aoqi@0 1473 x = x->in(0);
aoqi@0 1474 if (x == m_control) // Does 'control' post-dominate
aoqi@0 1475 break; // m->in(0)? If so, we can use it
aoqi@0 1476 if (x == mem_control) // Does 'control' post-dominate
aoqi@0 1477 break; // mem_control? If so, we can use it
aoqi@0 1478 }
aoqi@0 1479 if (j == max_scan) // No post-domination before scan end?
aoqi@0 1480 return true; // Then break the match tree up
aoqi@0 1481 }
aoqi@0 1482 if ((m->is_DecodeN() && Matcher::narrow_oop_use_complex_address()) ||
aoqi@0 1483 (m->is_DecodeNKlass() && Matcher::narrow_klass_use_complex_address())) {
aoqi@0 1484 // These are commonly used in address expressions and can
aoqi@0 1485 // efficiently fold into them on X64 in some cases.
aoqi@0 1486 return false;
aoqi@0 1487 }
aoqi@0 1488 }
aoqi@0 1489
aoqi@0 1490 // Not forceable cloning. If shared, put it into a register.
aoqi@0 1491 return shared;
aoqi@0 1492 }
aoqi@0 1493
aoqi@0 1494
aoqi@0 1495 //------------------------------Instruction Selection--------------------------
aoqi@0 1496 // Label method walks a "tree" of nodes, using the ADLC generated DFA to match
aoqi@0 1497 // ideal nodes to machine instructions. Trees are delimited by shared Nodes,
aoqi@0 1498 // things the Matcher does not match (e.g., Memory), and things with different
aoqi@0 1499 // Controls (hence forced into different blocks). We pass in the Control
aoqi@0 1500 // selected for this entire State tree.
aoqi@0 1501
aoqi@0 1502 // The Matcher works on Trees, but an Intel add-to-memory requires a DAG: the
aoqi@0 1503 // Store and the Load must have identical Memories (as well as identical
aoqi@0 1504 // pointers). Since the Matcher does not have anything for Memory (and
aoqi@0 1505 // does not handle DAGs), I have to match the Memory input myself. If the
aoqi@0 1506 // Tree root is a Store, I require all Loads to have the identical memory.
aoqi@0 1507 Node *Matcher::Label_Root( const Node *n, State *svec, Node *control, const Node *mem){
aoqi@0 1508 // Since Label_Root is a recursive function, its possible that we might run
aoqi@0 1509 // out of stack space. See bugs 6272980 & 6227033 for more info.
aoqi@0 1510 LabelRootDepth++;
aoqi@0 1511 if (LabelRootDepth > MaxLabelRootDepth) {
aoqi@0 1512 C->record_method_not_compilable_all_tiers("Out of stack space, increase MaxLabelRootDepth");
aoqi@0 1513 return NULL;
aoqi@0 1514 }
aoqi@0 1515 uint care = 0; // Edges matcher cares about
aoqi@0 1516 uint cnt = n->req();
aoqi@0 1517 uint i = 0;
aoqi@0 1518
aoqi@0 1519 // Examine children for memory state
aoqi@0 1520 // Can only subsume a child into your match-tree if that child's memory state
aoqi@0 1521 // is not modified along the path to another input.
aoqi@0 1522 // It is unsafe even if the other inputs are separate roots.
aoqi@0 1523 Node *input_mem = NULL;
aoqi@0 1524 for( i = 1; i < cnt; i++ ) {
aoqi@0 1525 if( !n->match_edge(i) ) continue;
aoqi@0 1526 Node *m = n->in(i); // Get ith input
aoqi@0 1527 assert( m, "expect non-null children" );
aoqi@0 1528 if( m->is_Load() ) {
aoqi@0 1529 if( input_mem == NULL ) {
aoqi@0 1530 input_mem = m->in(MemNode::Memory);
aoqi@0 1531 } else if( input_mem != m->in(MemNode::Memory) ) {
aoqi@0 1532 input_mem = NodeSentinel;
aoqi@0 1533 }
aoqi@0 1534 }
aoqi@0 1535 }
aoqi@0 1536
aoqi@0 1537 for( i = 1; i < cnt; i++ ){// For my children
aoqi@0 1538 if( !n->match_edge(i) ) continue;
aoqi@0 1539 Node *m = n->in(i); // Get ith input
aoqi@0 1540 // Allocate states out of a private arena
aoqi@0 1541 State *s = new (&_states_arena) State;
aoqi@0 1542 svec->_kids[care++] = s;
aoqi@0 1543 assert( care <= 2, "binary only for now" );
aoqi@0 1544
aoqi@0 1545 // Recursively label the State tree.
aoqi@0 1546 s->_kids[0] = NULL;
aoqi@0 1547 s->_kids[1] = NULL;
aoqi@0 1548 s->_leaf = m;
aoqi@0 1549
aoqi@0 1550 // Check for leaves of the State Tree; things that cannot be a part of
aoqi@0 1551 // the current tree. If it finds any, that value is matched as a
aoqi@0 1552 // register operand. If not, then the normal matching is used.
aoqi@0 1553 if( match_into_reg(n, m, control, i, is_shared(m)) ||
aoqi@0 1554 //
aoqi@0 1555 // Stop recursion if this is LoadNode and the root of this tree is a
aoqi@0 1556 // StoreNode and the load & store have different memories.
aoqi@0 1557 ((mem!=(Node*)1) && m->is_Load() && m->in(MemNode::Memory) != mem) ||
aoqi@0 1558 // Can NOT include the match of a subtree when its memory state
aoqi@0 1559 // is used by any of the other subtrees
aoqi@0 1560 (input_mem == NodeSentinel) ) {
aoqi@0 1561 #ifndef PRODUCT
aoqi@0 1562 // Print when we exclude matching due to different memory states at input-loads
aoqi@0 1563 if( PrintOpto && (Verbose && WizardMode) && (input_mem == NodeSentinel)
aoqi@0 1564 && !((mem!=(Node*)1) && m->is_Load() && m->in(MemNode::Memory) != mem) ) {
aoqi@0 1565 tty->print_cr("invalid input_mem");
aoqi@0 1566 }
aoqi@0 1567 #endif
aoqi@0 1568 // Switch to a register-only opcode; this value must be in a register
aoqi@0 1569 // and cannot be subsumed as part of a larger instruction.
aoqi@0 1570 s->DFA( m->ideal_reg(), m );
aoqi@0 1571
aoqi@0 1572 } else {
aoqi@0 1573 // If match tree has no control and we do, adopt it for entire tree
aoqi@0 1574 if( control == NULL && m->in(0) != NULL && m->req() > 1 )
aoqi@0 1575 control = m->in(0); // Pick up control
aoqi@0 1576 // Else match as a normal part of the match tree.
aoqi@0 1577 control = Label_Root(m,s,control,mem);
aoqi@0 1578 if (C->failing()) return NULL;
aoqi@0 1579 }
aoqi@0 1580 }
aoqi@0 1581
aoqi@0 1582
aoqi@0 1583 // Call DFA to match this node, and return
aoqi@0 1584 svec->DFA( n->Opcode(), n );
aoqi@0 1585
aoqi@0 1586 #ifdef ASSERT
aoqi@0 1587 uint x;
aoqi@0 1588 for( x = 0; x < _LAST_MACH_OPER; x++ )
aoqi@0 1589 if( svec->valid(x) )
aoqi@0 1590 break;
aoqi@0 1591
aoqi@0 1592 if (x >= _LAST_MACH_OPER) {
aoqi@0 1593 n->dump();
aoqi@0 1594 svec->dump();
aoqi@0 1595 assert( false, "bad AD file" );
aoqi@0 1596 }
aoqi@0 1597 #endif
aoqi@0 1598 return control;
aoqi@0 1599 }
aoqi@0 1600
aoqi@0 1601
aoqi@0 1602 // Con nodes reduced using the same rule can share their MachNode
aoqi@0 1603 // which reduces the number of copies of a constant in the final
aoqi@0 1604 // program. The register allocator is free to split uses later to
aoqi@0 1605 // split live ranges.
aoqi@0 1606 MachNode* Matcher::find_shared_node(Node* leaf, uint rule) {
aoqi@0 1607 if (!leaf->is_Con() && !leaf->is_DecodeNarrowPtr()) return NULL;
aoqi@0 1608
aoqi@0 1609 // See if this Con has already been reduced using this rule.
aoqi@0 1610 if (_shared_nodes.Size() <= leaf->_idx) return NULL;
aoqi@0 1611 MachNode* last = (MachNode*)_shared_nodes.at(leaf->_idx);
aoqi@0 1612 if (last != NULL && rule == last->rule()) {
aoqi@0 1613 // Don't expect control change for DecodeN
aoqi@0 1614 if (leaf->is_DecodeNarrowPtr())
aoqi@0 1615 return last;
aoqi@0 1616 // Get the new space root.
aoqi@0 1617 Node* xroot = new_node(C->root());
aoqi@0 1618 if (xroot == NULL) {
aoqi@0 1619 // This shouldn't happen give the order of matching.
aoqi@0 1620 return NULL;
aoqi@0 1621 }
aoqi@0 1622
aoqi@0 1623 // Shared constants need to have their control be root so they
aoqi@0 1624 // can be scheduled properly.
aoqi@0 1625 Node* control = last->in(0);
aoqi@0 1626 if (control != xroot) {
aoqi@0 1627 if (control == NULL || control == C->root()) {
aoqi@0 1628 last->set_req(0, xroot);
aoqi@0 1629 } else {
aoqi@0 1630 assert(false, "unexpected control");
aoqi@0 1631 return NULL;
aoqi@0 1632 }
aoqi@0 1633 }
aoqi@0 1634 return last;
aoqi@0 1635 }
aoqi@0 1636 return NULL;
aoqi@0 1637 }
aoqi@0 1638
aoqi@0 1639
aoqi@0 1640 //------------------------------ReduceInst-------------------------------------
aoqi@0 1641 // Reduce a State tree (with given Control) into a tree of MachNodes.
aoqi@0 1642 // This routine (and it's cohort ReduceOper) convert Ideal Nodes into
aoqi@0 1643 // complicated machine Nodes. Each MachNode covers some tree of Ideal Nodes.
aoqi@0 1644 // Each MachNode has a number of complicated MachOper operands; each
aoqi@0 1645 // MachOper also covers a further tree of Ideal Nodes.
aoqi@0 1646
aoqi@0 1647 // The root of the Ideal match tree is always an instruction, so we enter
aoqi@0 1648 // the recursion here. After building the MachNode, we need to recurse
aoqi@0 1649 // the tree checking for these cases:
aoqi@0 1650 // (1) Child is an instruction -
aoqi@0 1651 // Build the instruction (recursively), add it as an edge.
aoqi@0 1652 // Build a simple operand (register) to hold the result of the instruction.
aoqi@0 1653 // (2) Child is an interior part of an instruction -
aoqi@0 1654 // Skip over it (do nothing)
aoqi@0 1655 // (3) Child is the start of a operand -
aoqi@0 1656 // Build the operand, place it inside the instruction
aoqi@0 1657 // Call ReduceOper.
aoqi@0 1658 MachNode *Matcher::ReduceInst( State *s, int rule, Node *&mem ) {
aoqi@0 1659 assert( rule >= NUM_OPERANDS, "called with operand rule" );
aoqi@0 1660
aoqi@0 1661 MachNode* shared_node = find_shared_node(s->_leaf, rule);
aoqi@0 1662 if (shared_node != NULL) {
aoqi@0 1663 return shared_node;
aoqi@0 1664 }
aoqi@0 1665
aoqi@0 1666 // Build the object to represent this state & prepare for recursive calls
aoqi@0 1667 MachNode *mach = s->MachNodeGenerator( rule, C );
aoqi@0 1668 mach->_opnds[0] = s->MachOperGenerator( _reduceOp[rule], C );
aoqi@0 1669 assert( mach->_opnds[0] != NULL, "Missing result operand" );
aoqi@0 1670 Node *leaf = s->_leaf;
aoqi@0 1671 // Check for instruction or instruction chain rule
aoqi@0 1672 if( rule >= _END_INST_CHAIN_RULE || rule < _BEGIN_INST_CHAIN_RULE ) {
aoqi@0 1673 assert(C->node_arena()->contains(s->_leaf) || !has_new_node(s->_leaf),
aoqi@0 1674 "duplicating node that's already been matched");
aoqi@0 1675 // Instruction
aoqi@0 1676 mach->add_req( leaf->in(0) ); // Set initial control
aoqi@0 1677 // Reduce interior of complex instruction
aoqi@0 1678 ReduceInst_Interior( s, rule, mem, mach, 1 );
aoqi@0 1679 } else {
aoqi@0 1680 // Instruction chain rules are data-dependent on their inputs
aoqi@0 1681 mach->add_req(0); // Set initial control to none
aoqi@0 1682 ReduceInst_Chain_Rule( s, rule, mem, mach );
aoqi@0 1683 }
aoqi@0 1684
aoqi@0 1685 // If a Memory was used, insert a Memory edge
aoqi@0 1686 if( mem != (Node*)1 ) {
aoqi@0 1687 mach->ins_req(MemNode::Memory,mem);
aoqi@0 1688 #ifdef ASSERT
aoqi@0 1689 // Verify adr type after matching memory operation
aoqi@0 1690 const MachOper* oper = mach->memory_operand();
aoqi@0 1691 if (oper != NULL && oper != (MachOper*)-1) {
aoqi@0 1692 // It has a unique memory operand. Find corresponding ideal mem node.
aoqi@0 1693 Node* m = NULL;
aoqi@0 1694 if (leaf->is_Mem()) {
aoqi@0 1695 m = leaf;
aoqi@0 1696 } else {
aoqi@0 1697 m = _mem_node;
aoqi@0 1698 assert(m != NULL && m->is_Mem(), "expecting memory node");
aoqi@0 1699 }
aoqi@0 1700 const Type* mach_at = mach->adr_type();
aoqi@0 1701 // DecodeN node consumed by an address may have different type
aoqi@0 1702 // then its input. Don't compare types for such case.
aoqi@0 1703 if (m->adr_type() != mach_at &&
aoqi@0 1704 (m->in(MemNode::Address)->is_DecodeNarrowPtr() ||
aoqi@0 1705 m->in(MemNode::Address)->is_AddP() &&
aoqi@0 1706 m->in(MemNode::Address)->in(AddPNode::Address)->is_DecodeNarrowPtr() ||
aoqi@0 1707 m->in(MemNode::Address)->is_AddP() &&
aoqi@0 1708 m->in(MemNode::Address)->in(AddPNode::Address)->is_AddP() &&
aoqi@0 1709 m->in(MemNode::Address)->in(AddPNode::Address)->in(AddPNode::Address)->is_DecodeNarrowPtr())) {
aoqi@0 1710 mach_at = m->adr_type();
aoqi@0 1711 }
aoqi@0 1712 if (m->adr_type() != mach_at) {
aoqi@0 1713 m->dump();
aoqi@0 1714 tty->print_cr("mach:");
aoqi@0 1715 mach->dump(1);
aoqi@0 1716 }
aoqi@0 1717 assert(m->adr_type() == mach_at, "matcher should not change adr type");
aoqi@0 1718 }
aoqi@0 1719 #endif
aoqi@0 1720 }
aoqi@0 1721
aoqi@0 1722 // If the _leaf is an AddP, insert the base edge
aoqi@0 1723 if (leaf->is_AddP()) {
aoqi@0 1724 mach->ins_req(AddPNode::Base,leaf->in(AddPNode::Base));
aoqi@0 1725 }
aoqi@0 1726
aoqi@0 1727 uint number_of_projections_prior = number_of_projections();
aoqi@0 1728
aoqi@0 1729 // Perform any 1-to-many expansions required
aoqi@0 1730 MachNode *ex = mach->Expand(s, _projection_list, mem);
aoqi@0 1731 if (ex != mach) {
aoqi@0 1732 assert(ex->ideal_reg() == mach->ideal_reg(), "ideal types should match");
aoqi@0 1733 if( ex->in(1)->is_Con() )
aoqi@0 1734 ex->in(1)->set_req(0, C->root());
aoqi@0 1735 // Remove old node from the graph
aoqi@0 1736 for( uint i=0; i<mach->req(); i++ ) {
aoqi@0 1737 mach->set_req(i,NULL);
aoqi@0 1738 }
aoqi@0 1739 #ifdef ASSERT
aoqi@0 1740 _new2old_map.map(ex->_idx, s->_leaf);
aoqi@0 1741 #endif
aoqi@0 1742 }
aoqi@0 1743
aoqi@0 1744 // PhaseChaitin::fixup_spills will sometimes generate spill code
aoqi@0 1745 // via the matcher. By the time, nodes have been wired into the CFG,
aoqi@0 1746 // and any further nodes generated by expand rules will be left hanging
aoqi@0 1747 // in space, and will not get emitted as output code. Catch this.
aoqi@0 1748 // Also, catch any new register allocation constraints ("projections")
aoqi@0 1749 // generated belatedly during spill code generation.
aoqi@0 1750 if (_allocation_started) {
aoqi@0 1751 guarantee(ex == mach, "no expand rules during spill generation");
aoqi@0 1752 guarantee(number_of_projections_prior == number_of_projections(), "no allocation during spill generation");
aoqi@0 1753 }
aoqi@0 1754
aoqi@0 1755 if (leaf->is_Con() || leaf->is_DecodeNarrowPtr()) {
aoqi@0 1756 // Record the con for sharing
aoqi@0 1757 _shared_nodes.map(leaf->_idx, ex);
aoqi@0 1758 }
aoqi@0 1759
aoqi@0 1760 return ex;
aoqi@0 1761 }
aoqi@0 1762
aoqi@0 1763 void Matcher::ReduceInst_Chain_Rule( State *s, int rule, Node *&mem, MachNode *mach ) {
aoqi@0 1764 // 'op' is what I am expecting to receive
aoqi@0 1765 int op = _leftOp[rule];
aoqi@0 1766 // Operand type to catch childs result
aoqi@0 1767 // This is what my child will give me.
aoqi@0 1768 int opnd_class_instance = s->_rule[op];
aoqi@0 1769 // Choose between operand class or not.
aoqi@0 1770 // This is what I will receive.
aoqi@0 1771 int catch_op = (FIRST_OPERAND_CLASS <= op && op < NUM_OPERANDS) ? opnd_class_instance : op;
aoqi@0 1772 // New rule for child. Chase operand classes to get the actual rule.
aoqi@0 1773 int newrule = s->_rule[catch_op];
aoqi@0 1774
aoqi@0 1775 if( newrule < NUM_OPERANDS ) {
aoqi@0 1776 // Chain from operand or operand class, may be output of shared node
aoqi@0 1777 assert( 0 <= opnd_class_instance && opnd_class_instance < NUM_OPERANDS,
aoqi@0 1778 "Bad AD file: Instruction chain rule must chain from operand");
aoqi@0 1779 // Insert operand into array of operands for this instruction
aoqi@0 1780 mach->_opnds[1] = s->MachOperGenerator( opnd_class_instance, C );
aoqi@0 1781
aoqi@0 1782 ReduceOper( s, newrule, mem, mach );
aoqi@0 1783 } else {
aoqi@0 1784 // Chain from the result of an instruction
aoqi@0 1785 assert( newrule >= _LAST_MACH_OPER, "Do NOT chain from internal operand");
aoqi@0 1786 mach->_opnds[1] = s->MachOperGenerator( _reduceOp[catch_op], C );
aoqi@0 1787 Node *mem1 = (Node*)1;
aoqi@0 1788 debug_only(Node *save_mem_node = _mem_node;)
aoqi@0 1789 mach->add_req( ReduceInst(s, newrule, mem1) );
aoqi@0 1790 debug_only(_mem_node = save_mem_node;)
aoqi@0 1791 }
aoqi@0 1792 return;
aoqi@0 1793 }
aoqi@0 1794
aoqi@0 1795
aoqi@0 1796 uint Matcher::ReduceInst_Interior( State *s, int rule, Node *&mem, MachNode *mach, uint num_opnds ) {
aoqi@0 1797 if( s->_leaf->is_Load() ) {
aoqi@0 1798 Node *mem2 = s->_leaf->in(MemNode::Memory);
aoqi@0 1799 assert( mem == (Node*)1 || mem == mem2, "multiple Memories being matched at once?" );
aoqi@0 1800 debug_only( if( mem == (Node*)1 ) _mem_node = s->_leaf;)
aoqi@0 1801 mem = mem2;
aoqi@0 1802 }
aoqi@0 1803 if( s->_leaf->in(0) != NULL && s->_leaf->req() > 1) {
aoqi@0 1804 if( mach->in(0) == NULL )
aoqi@0 1805 mach->set_req(0, s->_leaf->in(0));
aoqi@0 1806 }
aoqi@0 1807
aoqi@0 1808 // Now recursively walk the state tree & add operand list.
aoqi@0 1809 for( uint i=0; i<2; i++ ) { // binary tree
aoqi@0 1810 State *newstate = s->_kids[i];
aoqi@0 1811 if( newstate == NULL ) break; // Might only have 1 child
aoqi@0 1812 // 'op' is what I am expecting to receive
aoqi@0 1813 int op;
aoqi@0 1814 if( i == 0 ) {
aoqi@0 1815 op = _leftOp[rule];
aoqi@0 1816 } else {
aoqi@0 1817 op = _rightOp[rule];
aoqi@0 1818 }
aoqi@0 1819 // Operand type to catch childs result
aoqi@0 1820 // This is what my child will give me.
aoqi@0 1821 int opnd_class_instance = newstate->_rule[op];
aoqi@0 1822 // Choose between operand class or not.
aoqi@0 1823 // This is what I will receive.
aoqi@0 1824 int catch_op = (op >= FIRST_OPERAND_CLASS && op < NUM_OPERANDS) ? opnd_class_instance : op;
aoqi@0 1825 // New rule for child. Chase operand classes to get the actual rule.
aoqi@0 1826 int newrule = newstate->_rule[catch_op];
aoqi@0 1827
aoqi@0 1828 if( newrule < NUM_OPERANDS ) { // Operand/operandClass or internalOp/instruction?
aoqi@0 1829 // Operand/operandClass
aoqi@0 1830 // Insert operand into array of operands for this instruction
aoqi@0 1831 mach->_opnds[num_opnds++] = newstate->MachOperGenerator( opnd_class_instance, C );
aoqi@0 1832 ReduceOper( newstate, newrule, mem, mach );
aoqi@0 1833
aoqi@0 1834 } else { // Child is internal operand or new instruction
aoqi@0 1835 if( newrule < _LAST_MACH_OPER ) { // internal operand or instruction?
aoqi@0 1836 // internal operand --> call ReduceInst_Interior
aoqi@0 1837 // Interior of complex instruction. Do nothing but recurse.
aoqi@0 1838 num_opnds = ReduceInst_Interior( newstate, newrule, mem, mach, num_opnds );
aoqi@0 1839 } else {
aoqi@0 1840 // instruction --> call build operand( ) to catch result
aoqi@0 1841 // --> ReduceInst( newrule )
aoqi@0 1842 mach->_opnds[num_opnds++] = s->MachOperGenerator( _reduceOp[catch_op], C );
aoqi@0 1843 Node *mem1 = (Node*)1;
aoqi@0 1844 debug_only(Node *save_mem_node = _mem_node;)
aoqi@0 1845 mach->add_req( ReduceInst( newstate, newrule, mem1 ) );
aoqi@0 1846 debug_only(_mem_node = save_mem_node;)
aoqi@0 1847 }
aoqi@0 1848 }
aoqi@0 1849 assert( mach->_opnds[num_opnds-1], "" );
aoqi@0 1850 }
aoqi@0 1851 return num_opnds;
aoqi@0 1852 }
aoqi@0 1853
aoqi@0 1854 // This routine walks the interior of possible complex operands.
aoqi@0 1855 // At each point we check our children in the match tree:
aoqi@0 1856 // (1) No children -
aoqi@0 1857 // We are a leaf; add _leaf field as an input to the MachNode
aoqi@0 1858 // (2) Child is an internal operand -
aoqi@0 1859 // Skip over it ( do nothing )
aoqi@0 1860 // (3) Child is an instruction -
aoqi@0 1861 // Call ReduceInst recursively and
aoqi@0 1862 // and instruction as an input to the MachNode
aoqi@0 1863 void Matcher::ReduceOper( State *s, int rule, Node *&mem, MachNode *mach ) {
aoqi@0 1864 assert( rule < _LAST_MACH_OPER, "called with operand rule" );
aoqi@0 1865 State *kid = s->_kids[0];
aoqi@0 1866 assert( kid == NULL || s->_leaf->in(0) == NULL, "internal operands have no control" );
aoqi@0 1867
aoqi@0 1868 // Leaf? And not subsumed?
aoqi@0 1869 if( kid == NULL && !_swallowed[rule] ) {
aoqi@0 1870 mach->add_req( s->_leaf ); // Add leaf pointer
aoqi@0 1871 return; // Bail out
aoqi@0 1872 }
aoqi@0 1873
aoqi@0 1874 if( s->_leaf->is_Load() ) {
aoqi@0 1875 assert( mem == (Node*)1, "multiple Memories being matched at once?" );
aoqi@0 1876 mem = s->_leaf->in(MemNode::Memory);
aoqi@0 1877 debug_only(_mem_node = s->_leaf;)
aoqi@0 1878 }
aoqi@0 1879 if( s->_leaf->in(0) && s->_leaf->req() > 1) {
aoqi@0 1880 if( !mach->in(0) )
aoqi@0 1881 mach->set_req(0,s->_leaf->in(0));
aoqi@0 1882 else {
aoqi@0 1883 assert( s->_leaf->in(0) == mach->in(0), "same instruction, differing controls?" );
aoqi@0 1884 }
aoqi@0 1885 }
aoqi@0 1886
aoqi@0 1887 for( uint i=0; kid != NULL && i<2; kid = s->_kids[1], i++ ) { // binary tree
aoqi@0 1888 int newrule;
aoqi@0 1889 if( i == 0)
aoqi@0 1890 newrule = kid->_rule[_leftOp[rule]];
aoqi@0 1891 else
aoqi@0 1892 newrule = kid->_rule[_rightOp[rule]];
aoqi@0 1893
aoqi@0 1894 if( newrule < _LAST_MACH_OPER ) { // Operand or instruction?
aoqi@0 1895 // Internal operand; recurse but do nothing else
aoqi@0 1896 ReduceOper( kid, newrule, mem, mach );
aoqi@0 1897
aoqi@0 1898 } else { // Child is a new instruction
aoqi@0 1899 // Reduce the instruction, and add a direct pointer from this
aoqi@0 1900 // machine instruction to the newly reduced one.
aoqi@0 1901 Node *mem1 = (Node*)1;
aoqi@0 1902 debug_only(Node *save_mem_node = _mem_node;)
aoqi@0 1903 mach->add_req( ReduceInst( kid, newrule, mem1 ) );
aoqi@0 1904 debug_only(_mem_node = save_mem_node;)
aoqi@0 1905 }
aoqi@0 1906 }
aoqi@0 1907 }
aoqi@0 1908
aoqi@0 1909
aoqi@0 1910 // -------------------------------------------------------------------------
aoqi@0 1911 // Java-Java calling convention
aoqi@0 1912 // (what you use when Java calls Java)
aoqi@0 1913
aoqi@0 1914 //------------------------------find_receiver----------------------------------
aoqi@0 1915 // For a given signature, return the OptoReg for parameter 0.
aoqi@0 1916 OptoReg::Name Matcher::find_receiver( bool is_outgoing ) {
aoqi@0 1917 VMRegPair regs;
aoqi@0 1918 BasicType sig_bt = T_OBJECT;
aoqi@0 1919 calling_convention(&sig_bt, &regs, 1, is_outgoing);
aoqi@0 1920 // Return argument 0 register. In the LP64 build pointers
aoqi@0 1921 // take 2 registers, but the VM wants only the 'main' name.
aoqi@0 1922 return OptoReg::as_OptoReg(regs.first());
aoqi@0 1923 }
aoqi@0 1924
aoqi@0 1925 // This function identifies sub-graphs in which a 'load' node is
aoqi@0 1926 // input to two different nodes, and such that it can be matched
aoqi@0 1927 // with BMI instructions like blsi, blsr, etc.
aoqi@0 1928 // Example : for b = -a[i] & a[i] can be matched to blsi r32, m32.
aoqi@0 1929 // The graph is (AndL (SubL Con0 LoadL*) LoadL*), where LoadL*
aoqi@0 1930 // refers to the same node.
aoqi@0 1931 #ifdef X86
aoqi@0 1932 // Match the generic fused operations pattern (op1 (op2 Con{ConType} mop) mop)
aoqi@0 1933 // This is a temporary solution until we make DAGs expressible in ADL.
aoqi@0 1934 template<typename ConType>
aoqi@0 1935 class FusedPatternMatcher {
aoqi@0 1936 Node* _op1_node;
aoqi@0 1937 Node* _mop_node;
aoqi@0 1938 int _con_op;
aoqi@0 1939
aoqi@0 1940 static int match_next(Node* n, int next_op, int next_op_idx) {
aoqi@0 1941 if (n->in(1) == NULL || n->in(2) == NULL) {
aoqi@0 1942 return -1;
aoqi@0 1943 }
aoqi@0 1944
aoqi@0 1945 if (next_op_idx == -1) { // n is commutative, try rotations
aoqi@0 1946 if (n->in(1)->Opcode() == next_op) {
aoqi@0 1947 return 1;
aoqi@0 1948 } else if (n->in(2)->Opcode() == next_op) {
aoqi@0 1949 return 2;
aoqi@0 1950 }
aoqi@0 1951 } else {
aoqi@0 1952 assert(next_op_idx > 0 && next_op_idx <= 2, "Bad argument index");
aoqi@0 1953 if (n->in(next_op_idx)->Opcode() == next_op) {
aoqi@0 1954 return next_op_idx;
aoqi@0 1955 }
aoqi@0 1956 }
aoqi@0 1957 return -1;
aoqi@0 1958 }
aoqi@0 1959 public:
aoqi@0 1960 FusedPatternMatcher(Node* op1_node, Node *mop_node, int con_op) :
aoqi@0 1961 _op1_node(op1_node), _mop_node(mop_node), _con_op(con_op) { }
aoqi@0 1962
aoqi@0 1963 bool match(int op1, int op1_op2_idx, // op1 and the index of the op1->op2 edge, -1 if op1 is commutative
aoqi@0 1964 int op2, int op2_con_idx, // op2 and the index of the op2->con edge, -1 if op2 is commutative
aoqi@0 1965 typename ConType::NativeType con_value) {
aoqi@0 1966 if (_op1_node->Opcode() != op1) {
aoqi@0 1967 return false;
aoqi@0 1968 }
aoqi@0 1969 if (_mop_node->outcnt() > 2) {
aoqi@0 1970 return false;
aoqi@0 1971 }
aoqi@0 1972 op1_op2_idx = match_next(_op1_node, op2, op1_op2_idx);
aoqi@0 1973 if (op1_op2_idx == -1) {
aoqi@0 1974 return false;
aoqi@0 1975 }
aoqi@0 1976 // Memory operation must be the other edge
aoqi@0 1977 int op1_mop_idx = (op1_op2_idx & 1) + 1;
aoqi@0 1978
aoqi@0 1979 // Check that the mop node is really what we want
aoqi@0 1980 if (_op1_node->in(op1_mop_idx) == _mop_node) {
aoqi@0 1981 Node *op2_node = _op1_node->in(op1_op2_idx);
aoqi@0 1982 if (op2_node->outcnt() > 1) {
aoqi@0 1983 return false;
aoqi@0 1984 }
aoqi@0 1985 assert(op2_node->Opcode() == op2, "Should be");
aoqi@0 1986 op2_con_idx = match_next(op2_node, _con_op, op2_con_idx);
aoqi@0 1987 if (op2_con_idx == -1) {
aoqi@0 1988 return false;
aoqi@0 1989 }
aoqi@0 1990 // Memory operation must be the other edge
aoqi@0 1991 int op2_mop_idx = (op2_con_idx & 1) + 1;
aoqi@0 1992 // Check that the memory operation is the same node
aoqi@0 1993 if (op2_node->in(op2_mop_idx) == _mop_node) {
aoqi@0 1994 // Now check the constant
aoqi@0 1995 const Type* con_type = op2_node->in(op2_con_idx)->bottom_type();
aoqi@0 1996 if (con_type != Type::TOP && ConType::as_self(con_type)->get_con() == con_value) {
aoqi@0 1997 return true;
aoqi@0 1998 }
aoqi@0 1999 }
aoqi@0 2000 }
aoqi@0 2001 return false;
aoqi@0 2002 }
aoqi@0 2003 };
aoqi@0 2004
aoqi@0 2005
aoqi@0 2006 bool Matcher::is_bmi_pattern(Node *n, Node *m) {
aoqi@0 2007 if (n != NULL && m != NULL) {
aoqi@0 2008 if (m->Opcode() == Op_LoadI) {
aoqi@0 2009 FusedPatternMatcher<TypeInt> bmii(n, m, Op_ConI);
aoqi@0 2010 return bmii.match(Op_AndI, -1, Op_SubI, 1, 0) ||
aoqi@0 2011 bmii.match(Op_AndI, -1, Op_AddI, -1, -1) ||
aoqi@0 2012 bmii.match(Op_XorI, -1, Op_AddI, -1, -1);
aoqi@0 2013 } else if (m->Opcode() == Op_LoadL) {
aoqi@0 2014 FusedPatternMatcher<TypeLong> bmil(n, m, Op_ConL);
aoqi@0 2015 return bmil.match(Op_AndL, -1, Op_SubL, 1, 0) ||
aoqi@0 2016 bmil.match(Op_AndL, -1, Op_AddL, -1, -1) ||
aoqi@0 2017 bmil.match(Op_XorL, -1, Op_AddL, -1, -1);
aoqi@0 2018 }
aoqi@0 2019 }
aoqi@0 2020 return false;
aoqi@0 2021 }
aoqi@0 2022 #endif // X86
aoqi@0 2023
aoqi@0 2024 // A method-klass-holder may be passed in the inline_cache_reg
aoqi@0 2025 // and then expanded into the inline_cache_reg and a method_oop register
aoqi@0 2026 // defined in ad_<arch>.cpp
aoqi@0 2027
aoqi@0 2028
aoqi@0 2029 //------------------------------find_shared------------------------------------
aoqi@0 2030 // Set bits if Node is shared or otherwise a root
aoqi@0 2031 void Matcher::find_shared( Node *n ) {
aoqi@0 2032 // Allocate stack of size C->unique() * 2 to avoid frequent realloc
aoqi@0 2033 MStack mstack(C->unique() * 2);
aoqi@0 2034 // Mark nodes as address_visited if they are inputs to an address expression
aoqi@0 2035 VectorSet address_visited(Thread::current()->resource_area());
aoqi@0 2036 mstack.push(n, Visit); // Don't need to pre-visit root node
aoqi@0 2037 while (mstack.is_nonempty()) {
aoqi@0 2038 n = mstack.node(); // Leave node on stack
aoqi@0 2039 Node_State nstate = mstack.state();
aoqi@0 2040 uint nop = n->Opcode();
aoqi@0 2041 if (nstate == Pre_Visit) {
aoqi@0 2042 if (address_visited.test(n->_idx)) { // Visited in address already?
aoqi@0 2043 // Flag as visited and shared now.
aoqi@0 2044 set_visited(n);
aoqi@0 2045 }
aoqi@0 2046 if (is_visited(n)) { // Visited already?
aoqi@0 2047 // Node is shared and has no reason to clone. Flag it as shared.
aoqi@0 2048 // This causes it to match into a register for the sharing.
aoqi@0 2049 set_shared(n); // Flag as shared and
aoqi@0 2050 mstack.pop(); // remove node from stack
aoqi@0 2051 continue;
aoqi@0 2052 }
aoqi@0 2053 nstate = Visit; // Not already visited; so visit now
aoqi@0 2054 }
aoqi@0 2055 if (nstate == Visit) {
aoqi@0 2056 mstack.set_state(Post_Visit);
aoqi@0 2057 set_visited(n); // Flag as visited now
aoqi@0 2058 bool mem_op = false;
aoqi@0 2059
aoqi@0 2060 switch( nop ) { // Handle some opcodes special
aoqi@0 2061 case Op_Phi: // Treat Phis as shared roots
aoqi@0 2062 case Op_Parm:
aoqi@0 2063 case Op_Proj: // All handled specially during matching
aoqi@0 2064 case Op_SafePointScalarObject:
aoqi@0 2065 set_shared(n);
aoqi@0 2066 set_dontcare(n);
aoqi@0 2067 break;
aoqi@0 2068 case Op_If:
aoqi@0 2069 case Op_CountedLoopEnd:
aoqi@0 2070 mstack.set_state(Alt_Post_Visit); // Alternative way
aoqi@0 2071 // Convert (If (Bool (CmpX A B))) into (If (Bool) (CmpX A B)). Helps
aoqi@0 2072 // with matching cmp/branch in 1 instruction. The Matcher needs the
aoqi@0 2073 // Bool and CmpX side-by-side, because it can only get at constants
aoqi@0 2074 // that are at the leaves of Match trees, and the Bool's condition acts
aoqi@0 2075 // as a constant here.
aoqi@0 2076 mstack.push(n->in(1), Visit); // Clone the Bool
aoqi@0 2077 mstack.push(n->in(0), Pre_Visit); // Visit control input
aoqi@0 2078 continue; // while (mstack.is_nonempty())
aoqi@0 2079 case Op_ConvI2D: // These forms efficiently match with a prior
aoqi@0 2080 case Op_ConvI2F: // Load but not a following Store
aoqi@0 2081 if( n->in(1)->is_Load() && // Prior load
aoqi@0 2082 n->outcnt() == 1 && // Not already shared
aoqi@0 2083 n->unique_out()->is_Store() ) // Following store
aoqi@0 2084 set_shared(n); // Force it to be a root
aoqi@0 2085 break;
aoqi@0 2086 case Op_ReverseBytesI:
aoqi@0 2087 case Op_ReverseBytesL:
aoqi@0 2088 if( n->in(1)->is_Load() && // Prior load
aoqi@0 2089 n->outcnt() == 1 ) // Not already shared
aoqi@0 2090 set_shared(n); // Force it to be a root
aoqi@0 2091 break;
aoqi@0 2092 case Op_BoxLock: // Cant match until we get stack-regs in ADLC
aoqi@0 2093 case Op_IfFalse:
aoqi@0 2094 case Op_IfTrue:
aoqi@0 2095 case Op_MachProj:
aoqi@0 2096 case Op_MergeMem:
aoqi@0 2097 case Op_Catch:
aoqi@0 2098 case Op_CatchProj:
aoqi@0 2099 case Op_CProj:
aoqi@0 2100 case Op_JumpProj:
aoqi@0 2101 case Op_JProj:
aoqi@0 2102 case Op_NeverBranch:
aoqi@0 2103 set_dontcare(n);
aoqi@0 2104 break;
aoqi@0 2105 case Op_Jump:
aoqi@0 2106 mstack.push(n->in(1), Pre_Visit); // Switch Value (could be shared)
aoqi@0 2107 mstack.push(n->in(0), Pre_Visit); // Visit Control input
aoqi@0 2108 continue; // while (mstack.is_nonempty())
aoqi@0 2109 case Op_StrComp:
aoqi@0 2110 case Op_StrEquals:
aoqi@0 2111 case Op_StrIndexOf:
aoqi@0 2112 case Op_AryEq:
aoqi@0 2113 case Op_EncodeISOArray:
aoqi@0 2114 set_shared(n); // Force result into register (it will be anyways)
aoqi@0 2115 break;
aoqi@0 2116 case Op_ConP: { // Convert pointers above the centerline to NUL
aoqi@0 2117 TypeNode *tn = n->as_Type(); // Constants derive from type nodes
aoqi@0 2118 const TypePtr* tp = tn->type()->is_ptr();
aoqi@0 2119 if (tp->_ptr == TypePtr::AnyNull) {
aoqi@0 2120 tn->set_type(TypePtr::NULL_PTR);
aoqi@0 2121 }
aoqi@0 2122 break;
aoqi@0 2123 }
aoqi@0 2124 case Op_ConN: { // Convert narrow pointers above the centerline to NUL
aoqi@0 2125 TypeNode *tn = n->as_Type(); // Constants derive from type nodes
aoqi@0 2126 const TypePtr* tp = tn->type()->make_ptr();
aoqi@0 2127 if (tp && tp->_ptr == TypePtr::AnyNull) {
aoqi@0 2128 tn->set_type(TypeNarrowOop::NULL_PTR);
aoqi@0 2129 }
aoqi@0 2130 break;
aoqi@0 2131 }
aoqi@0 2132 case Op_Binary: // These are introduced in the Post_Visit state.
aoqi@0 2133 ShouldNotReachHere();
aoqi@0 2134 break;
aoqi@0 2135 case Op_ClearArray:
aoqi@0 2136 case Op_SafePoint:
aoqi@0 2137 mem_op = true;
aoqi@0 2138 break;
aoqi@0 2139 default:
aoqi@0 2140 if( n->is_Store() ) {
aoqi@0 2141 // Do match stores, despite no ideal reg
aoqi@0 2142 mem_op = true;
aoqi@0 2143 break;
aoqi@0 2144 }
aoqi@0 2145 if( n->is_Mem() ) { // Loads and LoadStores
aoqi@0 2146 mem_op = true;
aoqi@0 2147 // Loads must be root of match tree due to prior load conflict
aoqi@0 2148 if( C->subsume_loads() == false )
aoqi@0 2149 set_shared(n);
aoqi@0 2150 }
aoqi@0 2151 // Fall into default case
aoqi@0 2152 if( !n->ideal_reg() )
aoqi@0 2153 set_dontcare(n); // Unmatchable Nodes
aoqi@0 2154 } // end_switch
aoqi@0 2155
aoqi@0 2156 for(int i = n->req() - 1; i >= 0; --i) { // For my children
aoqi@0 2157 Node *m = n->in(i); // Get ith input
aoqi@0 2158 if (m == NULL) continue; // Ignore NULLs
aoqi@0 2159 uint mop = m->Opcode();
aoqi@0 2160
aoqi@0 2161 // Must clone all producers of flags, or we will not match correctly.
aoqi@0 2162 // Suppose a compare setting int-flags is shared (e.g., a switch-tree)
aoqi@0 2163 // then it will match into an ideal Op_RegFlags. Alas, the fp-flags
aoqi@0 2164 // are also there, so we may match a float-branch to int-flags and
aoqi@0 2165 // expect the allocator to haul the flags from the int-side to the
aoqi@0 2166 // fp-side. No can do.
aoqi@0 2167 if( _must_clone[mop] ) {
aoqi@0 2168 mstack.push(m, Visit);
aoqi@0 2169 continue; // for(int i = ...)
aoqi@0 2170 }
aoqi@0 2171
aoqi@0 2172 if( mop == Op_AddP && m->in(AddPNode::Base)->is_DecodeNarrowPtr()) {
aoqi@0 2173 // Bases used in addresses must be shared but since
aoqi@0 2174 // they are shared through a DecodeN they may appear
aoqi@0 2175 // to have a single use so force sharing here.
aoqi@0 2176 set_shared(m->in(AddPNode::Base)->in(1));
aoqi@0 2177 }
aoqi@0 2178
aoqi@0 2179 // if 'n' and 'm' are part of a graph for BMI instruction, clone this node.
aoqi@0 2180 #ifdef X86
aoqi@0 2181 if (UseBMI1Instructions && is_bmi_pattern(n, m)) {
aoqi@0 2182 mstack.push(m, Visit);
aoqi@0 2183 continue;
aoqi@0 2184 }
aoqi@0 2185 #endif
aoqi@0 2186
aoqi@0 2187 // Clone addressing expressions as they are "free" in memory access instructions
aoqi@0 2188 if( mem_op && i == MemNode::Address && mop == Op_AddP ) {
aoqi@0 2189 // Some inputs for address expression are not put on stack
aoqi@0 2190 // to avoid marking them as shared and forcing them into register
aoqi@0 2191 // if they are used only in address expressions.
aoqi@0 2192 // But they should be marked as shared if there are other uses
aoqi@0 2193 // besides address expressions.
aoqi@0 2194
aoqi@0 2195 Node *off = m->in(AddPNode::Offset);
aoqi@0 2196 if( off->is_Con() &&
aoqi@0 2197 // When there are other uses besides address expressions
aoqi@0 2198 // put it on stack and mark as shared.
aoqi@0 2199 !is_visited(m) ) {
aoqi@0 2200 address_visited.test_set(m->_idx); // Flag as address_visited
aoqi@0 2201 Node *adr = m->in(AddPNode::Address);
aoqi@0 2202
aoqi@0 2203 // Intel, ARM and friends can handle 2 adds in addressing mode
aoqi@0 2204 if( clone_shift_expressions && adr->is_AddP() &&
aoqi@0 2205 // AtomicAdd is not an addressing expression.
aoqi@0 2206 // Cheap to find it by looking for screwy base.
aoqi@0 2207 !adr->in(AddPNode::Base)->is_top() &&
aoqi@0 2208 // Are there other uses besides address expressions?
aoqi@0 2209 !is_visited(adr) ) {
aoqi@0 2210 address_visited.set(adr->_idx); // Flag as address_visited
aoqi@0 2211 Node *shift = adr->in(AddPNode::Offset);
aoqi@0 2212 // Check for shift by small constant as well
aoqi@0 2213 if( shift->Opcode() == Op_LShiftX && shift->in(2)->is_Con() &&
aoqi@0 2214 shift->in(2)->get_int() <= 3 &&
aoqi@0 2215 // Are there other uses besides address expressions?
aoqi@0 2216 !is_visited(shift) ) {
aoqi@0 2217 address_visited.set(shift->_idx); // Flag as address_visited
aoqi@0 2218 mstack.push(shift->in(2), Visit);
aoqi@0 2219 Node *conv = shift->in(1);
aoqi@0 2220 #ifdef _LP64
aoqi@0 2221 // Allow Matcher to match the rule which bypass
aoqi@0 2222 // ConvI2L operation for an array index on LP64
aoqi@0 2223 // if the index value is positive.
aoqi@0 2224 if( conv->Opcode() == Op_ConvI2L &&
aoqi@0 2225 conv->as_Type()->type()->is_long()->_lo >= 0 &&
aoqi@0 2226 // Are there other uses besides address expressions?
aoqi@0 2227 !is_visited(conv) ) {
aoqi@0 2228 address_visited.set(conv->_idx); // Flag as address_visited
aoqi@0 2229 mstack.push(conv->in(1), Pre_Visit);
aoqi@0 2230 } else
aoqi@0 2231 #endif
aoqi@0 2232 mstack.push(conv, Pre_Visit);
aoqi@0 2233 } else {
aoqi@0 2234 mstack.push(shift, Pre_Visit);
aoqi@0 2235 }
aoqi@0 2236 mstack.push(adr->in(AddPNode::Address), Pre_Visit);
aoqi@0 2237 mstack.push(adr->in(AddPNode::Base), Pre_Visit);
aoqi@0 2238 } else { // Sparc, Alpha, PPC and friends
aoqi@0 2239 mstack.push(adr, Pre_Visit);
aoqi@0 2240 }
aoqi@0 2241
aoqi@0 2242 // Clone X+offset as it also folds into most addressing expressions
aoqi@0 2243 mstack.push(off, Visit);
aoqi@0 2244 mstack.push(m->in(AddPNode::Base), Pre_Visit);
aoqi@0 2245 continue; // for(int i = ...)
aoqi@0 2246 } // if( off->is_Con() )
aoqi@0 2247 } // if( mem_op &&
aoqi@0 2248 mstack.push(m, Pre_Visit);
aoqi@0 2249 } // for(int i = ...)
aoqi@0 2250 }
aoqi@0 2251 else if (nstate == Alt_Post_Visit) {
aoqi@0 2252 mstack.pop(); // Remove node from stack
aoqi@0 2253 // We cannot remove the Cmp input from the Bool here, as the Bool may be
aoqi@0 2254 // shared and all users of the Bool need to move the Cmp in parallel.
aoqi@0 2255 // This leaves both the Bool and the If pointing at the Cmp. To
aoqi@0 2256 // prevent the Matcher from trying to Match the Cmp along both paths
aoqi@0 2257 // BoolNode::match_edge always returns a zero.
aoqi@0 2258
aoqi@0 2259 // We reorder the Op_If in a pre-order manner, so we can visit without
aoqi@0 2260 // accidentally sharing the Cmp (the Bool and the If make 2 users).
aoqi@0 2261 n->add_req( n->in(1)->in(1) ); // Add the Cmp next to the Bool
aoqi@0 2262 }
aoqi@0 2263 else if (nstate == Post_Visit) {
aoqi@0 2264 mstack.pop(); // Remove node from stack
aoqi@0 2265
aoqi@0 2266 // Now hack a few special opcodes
aoqi@0 2267 switch( n->Opcode() ) { // Handle some opcodes special
aoqi@0 2268 case Op_StorePConditional:
aoqi@0 2269 case Op_StoreIConditional:
aoqi@0 2270 case Op_StoreLConditional:
aoqi@0 2271 case Op_CompareAndSwapI:
aoqi@0 2272 case Op_CompareAndSwapL:
aoqi@0 2273 case Op_CompareAndSwapP:
aoqi@0 2274 case Op_CompareAndSwapN: { // Convert trinary to binary-tree
aoqi@0 2275 Node *newval = n->in(MemNode::ValueIn );
aoqi@0 2276 Node *oldval = n->in(LoadStoreConditionalNode::ExpectedIn);
aoqi@0 2277 Node *pair = new (C) BinaryNode( oldval, newval );
aoqi@0 2278 n->set_req(MemNode::ValueIn,pair);
aoqi@0 2279 n->del_req(LoadStoreConditionalNode::ExpectedIn);
aoqi@0 2280 break;
aoqi@0 2281 }
aoqi@0 2282 case Op_CMoveD: // Convert trinary to binary-tree
aoqi@0 2283 case Op_CMoveF:
aoqi@0 2284 case Op_CMoveI:
aoqi@0 2285 case Op_CMoveL:
aoqi@0 2286 case Op_CMoveN:
aoqi@0 2287 case Op_CMoveP: {
aoqi@0 2288 // Restructure into a binary tree for Matching. It's possible that
aoqi@0 2289 // we could move this code up next to the graph reshaping for IfNodes
aoqi@0 2290 // or vice-versa, but I do not want to debug this for Ladybird.
aoqi@0 2291 // 10/2/2000 CNC.
aoqi@0 2292 Node *pair1 = new (C) BinaryNode(n->in(1),n->in(1)->in(1));
aoqi@0 2293 n->set_req(1,pair1);
aoqi@0 2294 Node *pair2 = new (C) BinaryNode(n->in(2),n->in(3));
aoqi@0 2295 n->set_req(2,pair2);
aoqi@0 2296 n->del_req(3);
aoqi@0 2297 break;
aoqi@0 2298 }
aoqi@0 2299 case Op_LoopLimit: {
aoqi@0 2300 Node *pair1 = new (C) BinaryNode(n->in(1),n->in(2));
aoqi@0 2301 n->set_req(1,pair1);
aoqi@0 2302 n->set_req(2,n->in(3));
aoqi@0 2303 n->del_req(3);
aoqi@0 2304 break;
aoqi@0 2305 }
aoqi@0 2306 case Op_StrEquals: {
aoqi@0 2307 Node *pair1 = new (C) BinaryNode(n->in(2),n->in(3));
aoqi@0 2308 n->set_req(2,pair1);
aoqi@0 2309 n->set_req(3,n->in(4));
aoqi@0 2310 n->del_req(4);
aoqi@0 2311 break;
aoqi@0 2312 }
aoqi@0 2313 case Op_StrComp:
aoqi@0 2314 case Op_StrIndexOf: {
aoqi@0 2315 Node *pair1 = new (C) BinaryNode(n->in(2),n->in(3));
aoqi@0 2316 n->set_req(2,pair1);
aoqi@0 2317 Node *pair2 = new (C) BinaryNode(n->in(4),n->in(5));
aoqi@0 2318 n->set_req(3,pair2);
aoqi@0 2319 n->del_req(5);
aoqi@0 2320 n->del_req(4);
aoqi@0 2321 break;
aoqi@0 2322 }
aoqi@0 2323 case Op_EncodeISOArray: {
aoqi@0 2324 // Restructure into a binary tree for Matching.
aoqi@0 2325 Node* pair = new (C) BinaryNode(n->in(3), n->in(4));
aoqi@0 2326 n->set_req(3, pair);
aoqi@0 2327 n->del_req(4);
aoqi@0 2328 break;
aoqi@0 2329 }
aoqi@0 2330 default:
aoqi@0 2331 break;
aoqi@0 2332 }
aoqi@0 2333 }
aoqi@0 2334 else {
aoqi@0 2335 ShouldNotReachHere();
aoqi@0 2336 }
aoqi@0 2337 } // end of while (mstack.is_nonempty())
aoqi@0 2338 }
aoqi@0 2339
aoqi@0 2340 #ifdef ASSERT
aoqi@0 2341 // machine-independent root to machine-dependent root
aoqi@0 2342 void Matcher::dump_old2new_map() {
aoqi@0 2343 _old2new_map.dump();
aoqi@0 2344 }
aoqi@0 2345 #endif
aoqi@0 2346
aoqi@0 2347 //---------------------------collect_null_checks-------------------------------
aoqi@0 2348 // Find null checks in the ideal graph; write a machine-specific node for
aoqi@0 2349 // it. Used by later implicit-null-check handling. Actually collects
aoqi@0 2350 // either an IfTrue or IfFalse for the common NOT-null path, AND the ideal
aoqi@0 2351 // value being tested.
aoqi@0 2352 void Matcher::collect_null_checks( Node *proj, Node *orig_proj ) {
aoqi@0 2353 Node *iff = proj->in(0);
aoqi@0 2354 if( iff->Opcode() == Op_If ) {
aoqi@0 2355 // During matching If's have Bool & Cmp side-by-side
aoqi@0 2356 BoolNode *b = iff->in(1)->as_Bool();
aoqi@0 2357 Node *cmp = iff->in(2);
aoqi@0 2358 int opc = cmp->Opcode();
aoqi@0 2359 if (opc != Op_CmpP && opc != Op_CmpN) return;
aoqi@0 2360
aoqi@0 2361 const Type* ct = cmp->in(2)->bottom_type();
aoqi@0 2362 if (ct == TypePtr::NULL_PTR ||
aoqi@0 2363 (opc == Op_CmpN && ct == TypeNarrowOop::NULL_PTR)) {
aoqi@0 2364
aoqi@0 2365 bool push_it = false;
aoqi@0 2366 if( proj->Opcode() == Op_IfTrue ) {
aoqi@0 2367 extern int all_null_checks_found;
aoqi@0 2368 all_null_checks_found++;
aoqi@0 2369 if( b->_test._test == BoolTest::ne ) {
aoqi@0 2370 push_it = true;
aoqi@0 2371 }
aoqi@0 2372 } else {
aoqi@0 2373 assert( proj->Opcode() == Op_IfFalse, "" );
aoqi@0 2374 if( b->_test._test == BoolTest::eq ) {
aoqi@0 2375 push_it = true;
aoqi@0 2376 }
aoqi@0 2377 }
aoqi@0 2378 if( push_it ) {
aoqi@0 2379 _null_check_tests.push(proj);
aoqi@0 2380 Node* val = cmp->in(1);
aoqi@0 2381 #ifdef _LP64
aoqi@0 2382 if (val->bottom_type()->isa_narrowoop() &&
aoqi@0 2383 !Matcher::narrow_oop_use_complex_address()) {
aoqi@0 2384 //
aoqi@0 2385 // Look for DecodeN node which should be pinned to orig_proj.
aoqi@0 2386 // On platforms (Sparc) which can not handle 2 adds
aoqi@0 2387 // in addressing mode we have to keep a DecodeN node and
aoqi@0 2388 // use it to do implicit NULL check in address.
aoqi@0 2389 //
aoqi@0 2390 // DecodeN node was pinned to non-null path (orig_proj) during
aoqi@0 2391 // CastPP transformation in final_graph_reshaping_impl().
aoqi@0 2392 //
aoqi@0 2393 uint cnt = orig_proj->outcnt();
aoqi@0 2394 for (uint i = 0; i < orig_proj->outcnt(); i++) {
aoqi@0 2395 Node* d = orig_proj->raw_out(i);
aoqi@0 2396 if (d->is_DecodeN() && d->in(1) == val) {
aoqi@0 2397 val = d;
aoqi@0 2398 val->set_req(0, NULL); // Unpin now.
aoqi@0 2399 // Mark this as special case to distinguish from
aoqi@0 2400 // a regular case: CmpP(DecodeN, NULL).
aoqi@0 2401 val = (Node*)(((intptr_t)val) | 1);
aoqi@0 2402 break;
aoqi@0 2403 }
aoqi@0 2404 }
aoqi@0 2405 }
aoqi@0 2406 #endif
aoqi@0 2407 _null_check_tests.push(val);
aoqi@0 2408 }
aoqi@0 2409 }
aoqi@0 2410 }
aoqi@0 2411 }
aoqi@0 2412
aoqi@0 2413 //---------------------------validate_null_checks------------------------------
aoqi@0 2414 // Its possible that the value being NULL checked is not the root of a match
aoqi@0 2415 // tree. If so, I cannot use the value in an implicit null check.
aoqi@0 2416 void Matcher::validate_null_checks( ) {
aoqi@0 2417 uint cnt = _null_check_tests.size();
aoqi@0 2418 for( uint i=0; i < cnt; i+=2 ) {
aoqi@0 2419 Node *test = _null_check_tests[i];
aoqi@0 2420 Node *val = _null_check_tests[i+1];
aoqi@0 2421 bool is_decoden = ((intptr_t)val) & 1;
aoqi@0 2422 val = (Node*)(((intptr_t)val) & ~1);
aoqi@0 2423 if (has_new_node(val)) {
aoqi@0 2424 Node* new_val = new_node(val);
aoqi@0 2425 if (is_decoden) {
aoqi@0 2426 assert(val->is_DecodeNarrowPtr() && val->in(0) == NULL, "sanity");
aoqi@0 2427 // Note: new_val may have a control edge if
aoqi@0 2428 // the original ideal node DecodeN was matched before
aoqi@0 2429 // it was unpinned in Matcher::collect_null_checks().
aoqi@0 2430 // Unpin the mach node and mark it.
aoqi@0 2431 new_val->set_req(0, NULL);
aoqi@0 2432 new_val = (Node*)(((intptr_t)new_val) | 1);
aoqi@0 2433 }
aoqi@0 2434 // Is a match-tree root, so replace with the matched value
aoqi@0 2435 _null_check_tests.map(i+1, new_val);
aoqi@0 2436 } else {
aoqi@0 2437 // Yank from candidate list
aoqi@0 2438 _null_check_tests.map(i+1,_null_check_tests[--cnt]);
aoqi@0 2439 _null_check_tests.map(i,_null_check_tests[--cnt]);
aoqi@0 2440 _null_check_tests.pop();
aoqi@0 2441 _null_check_tests.pop();
aoqi@0 2442 i-=2;
aoqi@0 2443 }
aoqi@0 2444 }
aoqi@0 2445 }
aoqi@0 2446
aoqi@0 2447 // Used by the DFA in dfa_xxx.cpp. Check for a following barrier or
aoqi@0 2448 // atomic instruction acting as a store_load barrier without any
aoqi@0 2449 // intervening volatile load, and thus we don't need a barrier here.
aoqi@0 2450 // We retain the Node to act as a compiler ordering barrier.
aoqi@0 2451 bool Matcher::post_store_load_barrier(const Node* vmb) {
aoqi@0 2452 Compile* C = Compile::current();
aoqi@0 2453 assert(vmb->is_MemBar(), "");
aoqi@0 2454 assert(vmb->Opcode() != Op_MemBarAcquire && vmb->Opcode() != Op_LoadFence, "");
aoqi@0 2455 const MemBarNode* membar = vmb->as_MemBar();
aoqi@0 2456
aoqi@0 2457 // Get the Ideal Proj node, ctrl, that can be used to iterate forward
aoqi@0 2458 Node* ctrl = NULL;
aoqi@0 2459 for (DUIterator_Fast imax, i = membar->fast_outs(imax); i < imax; i++) {
aoqi@0 2460 Node* p = membar->fast_out(i);
aoqi@0 2461 assert(p->is_Proj(), "only projections here");
aoqi@0 2462 if ((p->as_Proj()->_con == TypeFunc::Control) &&
aoqi@0 2463 !C->node_arena()->contains(p)) { // Unmatched old-space only
aoqi@0 2464 ctrl = p;
aoqi@0 2465 break;
aoqi@0 2466 }
aoqi@0 2467 }
aoqi@0 2468 assert((ctrl != NULL), "missing control projection");
aoqi@0 2469
aoqi@0 2470 for (DUIterator_Fast jmax, j = ctrl->fast_outs(jmax); j < jmax; j++) {
aoqi@0 2471 Node *x = ctrl->fast_out(j);
aoqi@0 2472 int xop = x->Opcode();
aoqi@0 2473
aoqi@0 2474 // We don't need current barrier if we see another or a lock
aoqi@0 2475 // before seeing volatile load.
aoqi@0 2476 //
aoqi@0 2477 // Op_Fastunlock previously appeared in the Op_* list below.
aoqi@0 2478 // With the advent of 1-0 lock operations we're no longer guaranteed
aoqi@0 2479 // that a monitor exit operation contains a serializing instruction.
aoqi@0 2480
aoqi@0 2481 if (xop == Op_MemBarVolatile ||
aoqi@0 2482 xop == Op_CompareAndSwapL ||
aoqi@0 2483 xop == Op_CompareAndSwapP ||
aoqi@0 2484 xop == Op_CompareAndSwapN ||
aoqi@0 2485 xop == Op_CompareAndSwapI) {
aoqi@0 2486 return true;
aoqi@0 2487 }
aoqi@0 2488
aoqi@0 2489 // Op_FastLock previously appeared in the Op_* list above.
aoqi@0 2490 // With biased locking we're no longer guaranteed that a monitor
aoqi@0 2491 // enter operation contains a serializing instruction.
aoqi@0 2492 if ((xop == Op_FastLock) && !UseBiasedLocking) {
aoqi@0 2493 return true;
aoqi@0 2494 }
aoqi@0 2495
aoqi@0 2496 if (x->is_MemBar()) {
aoqi@0 2497 // We must retain this membar if there is an upcoming volatile
aoqi@0 2498 // load, which will be followed by acquire membar.
aoqi@0 2499 if (xop == Op_MemBarAcquire || xop == Op_LoadFence) {
aoqi@0 2500 return false;
aoqi@0 2501 } else {
aoqi@0 2502 // For other kinds of barriers, check by pretending we
aoqi@0 2503 // are them, and seeing if we can be removed.
aoqi@0 2504 return post_store_load_barrier(x->as_MemBar());
aoqi@0 2505 }
aoqi@0 2506 }
aoqi@0 2507
aoqi@0 2508 // probably not necessary to check for these
aoqi@0 2509 if (x->is_Call() || x->is_SafePoint() || x->is_block_proj()) {
aoqi@0 2510 return false;
aoqi@0 2511 }
aoqi@0 2512 }
aoqi@0 2513 return false;
aoqi@0 2514 }
aoqi@0 2515
aoqi@0 2516 // Check whether node n is a branch to an uncommon trap that we could
aoqi@0 2517 // optimize as test with very high branch costs in case of going to
aoqi@0 2518 // the uncommon trap. The code must be able to be recompiled to use
aoqi@0 2519 // a cheaper test.
aoqi@0 2520 bool Matcher::branches_to_uncommon_trap(const Node *n) {
aoqi@0 2521 // Don't do it for natives, adapters, or runtime stubs
aoqi@0 2522 Compile *C = Compile::current();
aoqi@0 2523 if (!C->is_method_compilation()) return false;
aoqi@0 2524
aoqi@0 2525 assert(n->is_If(), "You should only call this on if nodes.");
aoqi@0 2526 IfNode *ifn = n->as_If();
aoqi@0 2527
aoqi@0 2528 Node *ifFalse = NULL;
aoqi@0 2529 for (DUIterator_Fast imax, i = ifn->fast_outs(imax); i < imax; i++) {
aoqi@0 2530 if (ifn->fast_out(i)->is_IfFalse()) {
aoqi@0 2531 ifFalse = ifn->fast_out(i);
aoqi@0 2532 break;
aoqi@0 2533 }
aoqi@0 2534 }
aoqi@0 2535 assert(ifFalse, "An If should have an ifFalse. Graph is broken.");
aoqi@0 2536
aoqi@0 2537 Node *reg = ifFalse;
aoqi@0 2538 int cnt = 4; // We must protect against cycles. Limit to 4 iterations.
aoqi@0 2539 // Alternatively use visited set? Seems too expensive.
aoqi@0 2540 while (reg != NULL && cnt > 0) {
aoqi@0 2541 CallNode *call = NULL;
aoqi@0 2542 RegionNode *nxt_reg = NULL;
aoqi@0 2543 for (DUIterator_Fast imax, i = reg->fast_outs(imax); i < imax; i++) {
aoqi@0 2544 Node *o = reg->fast_out(i);
aoqi@0 2545 if (o->is_Call()) {
aoqi@0 2546 call = o->as_Call();
aoqi@0 2547 }
aoqi@0 2548 if (o->is_Region()) {
aoqi@0 2549 nxt_reg = o->as_Region();
aoqi@0 2550 }
aoqi@0 2551 }
aoqi@0 2552
aoqi@0 2553 if (call &&
aoqi@0 2554 call->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point()) {
aoqi@0 2555 const Type* trtype = call->in(TypeFunc::Parms)->bottom_type();
aoqi@0 2556 if (trtype->isa_int() && trtype->is_int()->is_con()) {
aoqi@0 2557 jint tr_con = trtype->is_int()->get_con();
aoqi@0 2558 Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(tr_con);
aoqi@0 2559 Deoptimization::DeoptAction action = Deoptimization::trap_request_action(tr_con);
aoqi@0 2560 assert((int)reason < (int)BitsPerInt, "recode bit map");
aoqi@0 2561
aoqi@0 2562 if (is_set_nth_bit(C->allowed_deopt_reasons(), (int)reason)
aoqi@0 2563 && action != Deoptimization::Action_none) {
aoqi@0 2564 // This uncommon trap is sure to recompile, eventually.
aoqi@0 2565 // When that happens, C->too_many_traps will prevent
aoqi@0 2566 // this transformation from happening again.
aoqi@0 2567 return true;
aoqi@0 2568 }
aoqi@0 2569 }
aoqi@0 2570 }
aoqi@0 2571
aoqi@0 2572 reg = nxt_reg;
aoqi@0 2573 cnt--;
aoqi@0 2574 }
aoqi@0 2575
aoqi@0 2576 return false;
aoqi@0 2577 }
aoqi@0 2578
aoqi@0 2579 //=============================================================================
aoqi@0 2580 //---------------------------State---------------------------------------------
aoqi@0 2581 State::State(void) {
aoqi@0 2582 #ifdef ASSERT
aoqi@0 2583 _id = 0;
aoqi@0 2584 _kids[0] = _kids[1] = (State*)(intptr_t) CONST64(0xcafebabecafebabe);
aoqi@0 2585 _leaf = (Node*)(intptr_t) CONST64(0xbaadf00dbaadf00d);
aoqi@0 2586 //memset(_cost, -1, sizeof(_cost));
aoqi@0 2587 //memset(_rule, -1, sizeof(_rule));
aoqi@0 2588 #endif
aoqi@0 2589 memset(_valid, 0, sizeof(_valid));
aoqi@0 2590 }
aoqi@0 2591
aoqi@0 2592 #ifdef ASSERT
aoqi@0 2593 State::~State() {
aoqi@0 2594 _id = 99;
aoqi@0 2595 _kids[0] = _kids[1] = (State*)(intptr_t) CONST64(0xcafebabecafebabe);
aoqi@0 2596 _leaf = (Node*)(intptr_t) CONST64(0xbaadf00dbaadf00d);
aoqi@0 2597 memset(_cost, -3, sizeof(_cost));
aoqi@0 2598 memset(_rule, -3, sizeof(_rule));
aoqi@0 2599 }
aoqi@0 2600 #endif
aoqi@0 2601
aoqi@0 2602 #ifndef PRODUCT
aoqi@0 2603 //---------------------------dump----------------------------------------------
aoqi@0 2604 void State::dump() {
aoqi@0 2605 tty->print("\n");
aoqi@0 2606 dump(0);
aoqi@0 2607 }
aoqi@0 2608
aoqi@0 2609 void State::dump(int depth) {
aoqi@0 2610 for( int j = 0; j < depth; j++ )
aoqi@0 2611 tty->print(" ");
aoqi@0 2612 tty->print("--N: ");
aoqi@0 2613 _leaf->dump();
aoqi@0 2614 uint i;
aoqi@0 2615 for( i = 0; i < _LAST_MACH_OPER; i++ )
aoqi@0 2616 // Check for valid entry
aoqi@0 2617 if( valid(i) ) {
aoqi@0 2618 for( int j = 0; j < depth; j++ )
aoqi@0 2619 tty->print(" ");
aoqi@0 2620 assert(_cost[i] != max_juint, "cost must be a valid value");
aoqi@0 2621 assert(_rule[i] < _last_Mach_Node, "rule[i] must be valid rule");
aoqi@0 2622 tty->print_cr("%s %d %s",
aoqi@0 2623 ruleName[i], _cost[i], ruleName[_rule[i]] );
aoqi@0 2624 }
aoqi@0 2625 tty->cr();
aoqi@0 2626
aoqi@0 2627 for( i=0; i<2; i++ )
aoqi@0 2628 if( _kids[i] )
aoqi@0 2629 _kids[i]->dump(depth+1);
aoqi@0 2630 }
aoqi@0 2631 #endif

mercurial