src/share/vm/opto/matcher.cpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added MIPS 64-bit port.

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

mercurial