0N/A/*
3845N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "opto/addnode.hpp"
1879N/A#include "opto/callnode.hpp"
1879N/A#include "opto/connode.hpp"
1879N/A#include "opto/idealGraphPrinter.hpp"
1879N/A#include "opto/matcher.hpp"
1879N/A#include "opto/memnode.hpp"
1879N/A#include "opto/opcodes.hpp"
1879N/A#include "opto/regmask.hpp"
1879N/A#include "opto/rootnode.hpp"
1879N/A#include "opto/runtime.hpp"
1879N/A#include "opto/type.hpp"
3845N/A#include "opto/vectornode.hpp"
1879N/A#include "runtime/atomic.hpp"
1879N/A#include "runtime/os.hpp"
1879N/A#ifdef TARGET_ARCH_MODEL_x86_32
1879N/A# include "adfiles/ad_x86_32.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_x86_64
1879N/A# include "adfiles/ad_x86_64.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_sparc
1879N/A# include "adfiles/ad_sparc.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_zero
1879N/A# include "adfiles/ad_zero.hpp"
1879N/A#endif
2248N/A#ifdef TARGET_ARCH_MODEL_arm
2248N/A# include "adfiles/ad_arm.hpp"
2248N/A#endif
2621N/A#ifdef TARGET_ARCH_MODEL_ppc
2621N/A# include "adfiles/ad_ppc.hpp"
2621N/A#endif
0N/A
0N/AOptoReg::Name OptoReg::c_frame_pointer;
0N/A
0N/Aconst RegMask *Matcher::idealreg2regmask[_last_machine_leaf];
0N/ARegMask Matcher::mreg2regmask[_last_Mach_Reg];
0N/ARegMask Matcher::STACK_ONLY_mask;
0N/ARegMask Matcher::c_frame_ptr_mask;
0N/Aconst uint Matcher::_begin_rematerialize = _BEGIN_REMATERIALIZE;
0N/Aconst uint Matcher::_end_rematerialize = _END_REMATERIALIZE;
0N/A
0N/A//---------------------------Matcher-------------------------------------------
0N/AMatcher::Matcher( Node_List &proj_list ) :
0N/A PhaseTransform( Phase::Ins_Select ),
0N/A#ifdef ASSERT
0N/A _old2new_map(C->comp_arena()),
222N/A _new2old_map(C->comp_arena()),
0N/A#endif
168N/A _shared_nodes(C->comp_arena()),
0N/A _reduceOp(reduceOp), _leftOp(leftOp), _rightOp(rightOp),
0N/A _swallowed(swallowed),
0N/A _begin_inst_chain_rule(_BEGIN_INST_CHAIN_RULE),
0N/A _end_inst_chain_rule(_END_INST_CHAIN_RULE),
0N/A _must_clone(must_clone), _proj_list(proj_list),
0N/A _register_save_policy(register_save_policy),
0N/A _c_reg_save_policy(c_reg_save_policy),
0N/A _register_save_type(register_save_type),
0N/A _ruleName(ruleName),
0N/A _allocation_started(false),
0N/A _states_arena(Chunk::medium_size),
0N/A _visited(&_states_arena),
0N/A _shared(&_states_arena),
0N/A _dontcare(&_states_arena) {
0N/A C->set_matcher(this);
0N/A
1137N/A idealreg2spillmask [Op_RegI] = NULL;
1137N/A idealreg2spillmask [Op_RegN] = NULL;
1137N/A idealreg2spillmask [Op_RegL] = NULL;
1137N/A idealreg2spillmask [Op_RegF] = NULL;
1137N/A idealreg2spillmask [Op_RegD] = NULL;
1137N/A idealreg2spillmask [Op_RegP] = NULL;
3845N/A idealreg2spillmask [Op_VecS] = NULL;
3845N/A idealreg2spillmask [Op_VecD] = NULL;
3845N/A idealreg2spillmask [Op_VecX] = NULL;
3845N/A idealreg2spillmask [Op_VecY] = NULL;
0N/A
1137N/A idealreg2debugmask [Op_RegI] = NULL;
1137N/A idealreg2debugmask [Op_RegN] = NULL;
1137N/A idealreg2debugmask [Op_RegL] = NULL;
1137N/A idealreg2debugmask [Op_RegF] = NULL;
1137N/A idealreg2debugmask [Op_RegD] = NULL;
1137N/A idealreg2debugmask [Op_RegP] = NULL;
3845N/A idealreg2debugmask [Op_VecS] = NULL;
3845N/A idealreg2debugmask [Op_VecD] = NULL;
3845N/A idealreg2debugmask [Op_VecX] = NULL;
3845N/A idealreg2debugmask [Op_VecY] = NULL;
1137N/A
1137N/A idealreg2mhdebugmask[Op_RegI] = NULL;
1137N/A idealreg2mhdebugmask[Op_RegN] = NULL;
1137N/A idealreg2mhdebugmask[Op_RegL] = NULL;
1137N/A idealreg2mhdebugmask[Op_RegF] = NULL;
1137N/A idealreg2mhdebugmask[Op_RegD] = NULL;
1137N/A idealreg2mhdebugmask[Op_RegP] = NULL;
3845N/A idealreg2mhdebugmask[Op_VecS] = NULL;
3845N/A idealreg2mhdebugmask[Op_VecD] = NULL;
3845N/A idealreg2mhdebugmask[Op_VecX] = NULL;
3845N/A idealreg2mhdebugmask[Op_VecY] = NULL;
1137N/A
216N/A debug_only(_mem_node = NULL;) // Ideal memory node consumed by mach node
0N/A}
0N/A
0N/A//------------------------------warp_incoming_stk_arg------------------------
0N/A// This warps a VMReg into an OptoReg::Name
0N/AOptoReg::Name Matcher::warp_incoming_stk_arg( VMReg reg ) {
0N/A OptoReg::Name warped;
0N/A if( reg->is_stack() ) { // Stack slot argument?
0N/A warped = OptoReg::add(_old_SP, reg->reg2stack() );
0N/A warped = OptoReg::add(warped, C->out_preserve_stack_slots());
0N/A if( warped >= _in_arg_limit )
0N/A _in_arg_limit = OptoReg::add(warped, 1); // Bump max stack slot seen
3845N/A if (!RegMask::can_represent_arg(warped)) {
0N/A // the compiler cannot represent this method's calling sequence
0N/A C->record_method_not_compilable_all_tiers("unsupported incoming calling sequence");
0N/A return OptoReg::Bad;
0N/A }
0N/A return warped;
0N/A }
0N/A return OptoReg::as_OptoReg(reg);
0N/A}
0N/A
0N/A//---------------------------compute_old_SP------------------------------------
0N/AOptoReg::Name Compile::compute_old_SP() {
0N/A int fixed = fixed_slots();
0N/A int preserve = in_preserve_stack_slots();
0N/A return OptoReg::stack2reg(round_to(fixed + preserve, Matcher::stack_alignment_in_slots()));
0N/A}
0N/A
0N/A
0N/A
0N/A#ifdef ASSERT
0N/Avoid Matcher::verify_new_nodes_only(Node* xroot) {
0N/A // Make sure that the new graph only references new nodes
0N/A ResourceMark rm;
0N/A Unique_Node_List worklist;
0N/A VectorSet visited(Thread::current()->resource_area());
0N/A worklist.push(xroot);
0N/A while (worklist.size() > 0) {
0N/A Node* n = worklist.pop();
0N/A visited <<= n->_idx;
0N/A assert(C->node_arena()->contains(n), "dead node");
0N/A for (uint j = 0; j < n->req(); j++) {
0N/A Node* in = n->in(j);
0N/A if (in != NULL) {
0N/A assert(C->node_arena()->contains(in), "dead node");
0N/A if (!visited.test(in->_idx)) {
0N/A worklist.push(in);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A
0N/A//---------------------------match---------------------------------------------
0N/Avoid Matcher::match( ) {
823N/A if( MaxLabelRootDepth < 100 ) { // Too small?
823N/A assert(false, "invalid MaxLabelRootDepth, increase it to 100 minimum");
823N/A MaxLabelRootDepth = 100;
823N/A }
0N/A // One-time initialization of some register masks.
0N/A init_spill_mask( C->root()->in(1) );
0N/A _return_addr_mask = return_addr();
0N/A#ifdef _LP64
0N/A // Pointers take 2 slots in 64-bit land
0N/A _return_addr_mask.Insert(OptoReg::add(return_addr(),1));
0N/A#endif
0N/A
0N/A // Map a Java-signature return type into return register-value
0N/A // machine registers for 0, 1 and 2 returned values.
0N/A const TypeTuple *range = C->tf()->range();
0N/A if( range->cnt() > TypeFunc::Parms ) { // If not a void function
0N/A // Get ideal-register return type
0N/A int ireg = base2reg[range->field_at(TypeFunc::Parms)->base()];
0N/A // Get machine return register
0N/A uint sop = C->start()->Opcode();
0N/A OptoRegPair regs = return_value(ireg, false);
0N/A
0N/A // And mask for same
0N/A _return_value_mask = RegMask(regs.first());
0N/A if( OptoReg::is_valid(regs.second()) )
0N/A _return_value_mask.Insert(regs.second());
0N/A }
0N/A
0N/A // ---------------
0N/A // Frame Layout
0N/A
0N/A // Need the method signature to determine the incoming argument types,
0N/A // because the types determine which registers the incoming arguments are
0N/A // in, and this affects the matched code.
0N/A const TypeTuple *domain = C->tf()->domain();
0N/A uint argcnt = domain->cnt() - TypeFunc::Parms;
0N/A BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, argcnt );
0N/A VMRegPair *vm_parm_regs = NEW_RESOURCE_ARRAY( VMRegPair, argcnt );
0N/A _parm_regs = NEW_RESOURCE_ARRAY( OptoRegPair, argcnt );
0N/A _calling_convention_mask = NEW_RESOURCE_ARRAY( RegMask, argcnt );
0N/A uint i;
0N/A for( i = 0; i<argcnt; i++ ) {
0N/A sig_bt[i] = domain->field_at(i+TypeFunc::Parms)->basic_type();
0N/A }
0N/A
0N/A // Pass array of ideal registers and length to USER code (from the AD file)
0N/A // that will convert this to an array of register numbers.
0N/A const StartNode *start = C->start();
0N/A start->calling_convention( sig_bt, vm_parm_regs, argcnt );
0N/A#ifdef ASSERT
0N/A // Sanity check users' calling convention. Real handy while trying to
0N/A // get the initial port correct.
0N/A { for (uint i = 0; i<argcnt; i++) {
0N/A if( !vm_parm_regs[i].first()->is_valid() && !vm_parm_regs[i].second()->is_valid() ) {
0N/A assert(domain->field_at(i+TypeFunc::Parms)==Type::HALF, "only allowed on halve" );
0N/A _parm_regs[i].set_bad();
0N/A continue;
0N/A }
0N/A VMReg parm_reg = vm_parm_regs[i].first();
0N/A assert(parm_reg->is_valid(), "invalid arg?");
0N/A if (parm_reg->is_reg()) {
0N/A OptoReg::Name opto_parm_reg = OptoReg::as_OptoReg(parm_reg);
0N/A assert(can_be_java_arg(opto_parm_reg) ||
0N/A C->stub_function() == CAST_FROM_FN_PTR(address, OptoRuntime::rethrow_C) ||
0N/A opto_parm_reg == inline_cache_reg(),
0N/A "parameters in register must be preserved by runtime stubs");
0N/A }
0N/A for (uint j = 0; j < i; j++) {
0N/A assert(parm_reg != vm_parm_regs[j].first(),
0N/A "calling conv. must produce distinct regs");
0N/A }
0N/A }
0N/A }
0N/A#endif
0N/A
0N/A // Do some initial frame layout.
0N/A
0N/A // Compute the old incoming SP (may be called FP) as
0N/A // OptoReg::stack0() + locks + in_preserve_stack_slots + pad2.
0N/A _old_SP = C->compute_old_SP();
0N/A assert( is_even(_old_SP), "must be even" );
0N/A
0N/A // Compute highest incoming stack argument as
0N/A // _old_SP + out_preserve_stack_slots + incoming argument size.
0N/A _in_arg_limit = OptoReg::add(_old_SP, C->out_preserve_stack_slots());
0N/A assert( is_even(_in_arg_limit), "out_preserve must be even" );
0N/A for( i = 0; i < argcnt; i++ ) {
0N/A // Permit args to have no register
0N/A _calling_convention_mask[i].Clear();
0N/A if( !vm_parm_regs[i].first()->is_valid() && !vm_parm_regs[i].second()->is_valid() ) {
0N/A continue;
0N/A }
0N/A // calling_convention returns stack arguments as a count of
0N/A // slots beyond OptoReg::stack0()/VMRegImpl::stack0. We need to convert this to
0N/A // the allocators point of view, taking into account all the
0N/A // preserve area, locks & pad2.
0N/A
0N/A OptoReg::Name reg1 = warp_incoming_stk_arg(vm_parm_regs[i].first());
0N/A if( OptoReg::is_valid(reg1))
0N/A _calling_convention_mask[i].Insert(reg1);
0N/A
0N/A OptoReg::Name reg2 = warp_incoming_stk_arg(vm_parm_regs[i].second());
0N/A if( OptoReg::is_valid(reg2))
0N/A _calling_convention_mask[i].Insert(reg2);
0N/A
0N/A // Saved biased stack-slot register number
0N/A _parm_regs[i].set_pair(reg2, reg1);
0N/A }
0N/A
0N/A // Finally, make sure the incoming arguments take up an even number of
0N/A // words, in case the arguments or locals need to contain doubleword stack
0N/A // slots. The rest of the system assumes that stack slot pairs (in
0N/A // particular, in the spill area) which look aligned will in fact be
0N/A // aligned relative to the stack pointer in the target machine. Double
0N/A // stack slots will always be allocated aligned.
0N/A _new_SP = OptoReg::Name(round_to(_in_arg_limit, RegMask::SlotsPerLong));
0N/A
0N/A // Compute highest outgoing stack argument as
0N/A // _new_SP + out_preserve_stack_slots + max(outgoing argument size).
0N/A _out_arg_limit = OptoReg::add(_new_SP, C->out_preserve_stack_slots());
0N/A assert( is_even(_out_arg_limit), "out_preserve must be even" );
0N/A
3845N/A if (!RegMask::can_represent_arg(OptoReg::add(_out_arg_limit,-1))) {
0N/A // the compiler cannot represent this method's calling sequence
0N/A C->record_method_not_compilable("must be able to represent all call arguments in reg mask");
0N/A }
0N/A
0N/A if (C->failing()) return; // bailed out on incoming arg failure
0N/A
0N/A // ---------------
0N/A // Collect roots of matcher trees. Every node for which
0N/A // _shared[_idx] is cleared is guaranteed to not be shared, and thus
0N/A // can be a valid interior of some tree.
0N/A find_shared( C->root() );
0N/A find_shared( C->top() );
0N/A
4141N/A C->print_method(PHASE_BEFORE_MATCHING);
0N/A
729N/A // Create new ideal node ConP #NULL even if it does exist in old space
729N/A // to avoid false sharing if the corresponding mach node is not used.
729N/A // The corresponding mach node is only used in rare cases for derived
729N/A // pointers.
729N/A Node* new_ideal_null = ConNode::make(C, TypePtr::NULL_PTR);
729N/A
0N/A // Swap out to old-space; emptying new-space
0N/A Arena *old = C->node_arena()->move_contents(C->old_arena());
0N/A
0N/A // Save debug and profile information for nodes in old space:
0N/A _old_node_note_array = C->node_note_array();
0N/A if (_old_node_note_array != NULL) {
0N/A C->set_node_note_array(new(C->comp_arena()) GrowableArray<Node_Notes*>
0N/A (C->comp_arena(), _old_node_note_array->length(),
0N/A 0, NULL));
0N/A }
0N/A
0N/A // Pre-size the new_node table to avoid the need for range checks.
0N/A grow_new_node_array(C->unique());
0N/A
0N/A // Reset node counter so MachNodes start with _idx at 0
0N/A int nodes = C->unique(); // save value
0N/A C->set_unique(0);
4123N/A C->reset_dead_node_list();
0N/A
0N/A // Recursively match trees from old space into new space.
0N/A // Correct leaves of new-space Nodes; they point to old-space.
0N/A _visited.Clear(); // Clear visit bits for xform call
0N/A C->set_cached_top_node(xform( C->top(), nodes ));
0N/A if (!C->failing()) {
0N/A Node* xroot = xform( C->root(), 1 );
0N/A if (xroot == NULL) {
0N/A Matcher::soft_match_failure(); // recursive matching process failed
0N/A C->record_method_not_compilable("instruction match failed");
0N/A } else {
0N/A // During matching shared constants were attached to C->root()
0N/A // because xroot wasn't available yet, so transfer the uses to
0N/A // the xroot.
0N/A for( DUIterator_Fast jmax, j = C->root()->fast_outs(jmax); j < jmax; j++ ) {
0N/A Node* n = C->root()->fast_out(j);
0N/A if (C->node_arena()->contains(n)) {
0N/A assert(n->in(0) == C->root(), "should be control user");
0N/A n->set_req(0, xroot);
0N/A --j;
0N/A --jmax;
0N/A }
0N/A }
0N/A
729N/A // Generate new mach node for ConP #NULL
729N/A assert(new_ideal_null != NULL, "sanity");
729N/A _mach_null = match_tree(new_ideal_null);
729N/A // Don't set control, it will confuse GCM since there are no uses.
729N/A // The control will be set when this node is used first time
729N/A // in find_base_for_derived().
729N/A assert(_mach_null != NULL, "");
729N/A
0N/A C->set_root(xroot->is_Root() ? xroot->as_Root() : NULL);
729N/A
0N/A#ifdef ASSERT
0N/A verify_new_nodes_only(xroot);
0N/A#endif
0N/A }
0N/A }
0N/A if (C->top() == NULL || C->root() == NULL) {
0N/A C->record_method_not_compilable("graph lost"); // %%% cannot happen?
0N/A }
0N/A if (C->failing()) {
0N/A // delete old;
0N/A old->destruct_contents();
0N/A return;
0N/A }
0N/A assert( C->top(), "" );
0N/A assert( C->root(), "" );
0N/A validate_null_checks();
0N/A
0N/A // Now smoke old-space
0N/A NOT_DEBUG( old->destruct_contents() );
0N/A
0N/A // ------------------------
0N/A // Set up save-on-entry registers
0N/A Fixup_Save_On_Entry( );
0N/A}
0N/A
0N/A
0N/A//------------------------------Fixup_Save_On_Entry----------------------------
0N/A// The stated purpose of this routine is to take care of save-on-entry
0N/A// registers. However, the overall goal of the Match phase is to convert into
0N/A// machine-specific instructions which have RegMasks to guide allocation.
0N/A// So what this procedure really does is put a valid RegMask on each input
0N/A// to the machine-specific variations of all Return, TailCall and Halt
0N/A// instructions. It also adds edgs to define the save-on-entry values (and of
0N/A// course gives them a mask).
0N/A
0N/Astatic RegMask *init_input_masks( uint size, RegMask &ret_adr, RegMask &fp ) {
0N/A RegMask *rms = NEW_RESOURCE_ARRAY( RegMask, size );
0N/A // Do all the pre-defined register masks
0N/A rms[TypeFunc::Control ] = RegMask::Empty;
0N/A rms[TypeFunc::I_O ] = RegMask::Empty;
0N/A rms[TypeFunc::Memory ] = RegMask::Empty;
0N/A rms[TypeFunc::ReturnAdr] = ret_adr;
0N/A rms[TypeFunc::FramePtr ] = fp;
0N/A return rms;
0N/A}
0N/A
0N/A//---------------------------init_first_stack_mask-----------------------------
0N/A// Create the initial stack mask used by values spilling to the stack.
0N/A// Disallow any debug info in outgoing argument areas by setting the
0N/A// initial mask accordingly.
0N/Avoid Matcher::init_first_stack_mask() {
0N/A
0N/A // Allocate storage for spill masks as masks for the appropriate load type.
3845N/A RegMask *rms = (RegMask*)C->comp_arena()->Amalloc_D(sizeof(RegMask) * (3*6+4));
1137N/A
1137N/A idealreg2spillmask [Op_RegN] = &rms[0];
1137N/A idealreg2spillmask [Op_RegI] = &rms[1];
1137N/A idealreg2spillmask [Op_RegL] = &rms[2];
1137N/A idealreg2spillmask [Op_RegF] = &rms[3];
1137N/A idealreg2spillmask [Op_RegD] = &rms[4];
1137N/A idealreg2spillmask [Op_RegP] = &rms[5];
1137N/A
1137N/A idealreg2debugmask [Op_RegN] = &rms[6];
1137N/A idealreg2debugmask [Op_RegI] = &rms[7];
1137N/A idealreg2debugmask [Op_RegL] = &rms[8];
1137N/A idealreg2debugmask [Op_RegF] = &rms[9];
1137N/A idealreg2debugmask [Op_RegD] = &rms[10];
1137N/A idealreg2debugmask [Op_RegP] = &rms[11];
1137N/A
1137N/A idealreg2mhdebugmask[Op_RegN] = &rms[12];
1137N/A idealreg2mhdebugmask[Op_RegI] = &rms[13];
1137N/A idealreg2mhdebugmask[Op_RegL] = &rms[14];
1137N/A idealreg2mhdebugmask[Op_RegF] = &rms[15];
1137N/A idealreg2mhdebugmask[Op_RegD] = &rms[16];
1137N/A idealreg2mhdebugmask[Op_RegP] = &rms[17];
0N/A
3845N/A idealreg2spillmask [Op_VecS] = &rms[18];
3845N/A idealreg2spillmask [Op_VecD] = &rms[19];
3845N/A idealreg2spillmask [Op_VecX] = &rms[20];
3845N/A idealreg2spillmask [Op_VecY] = &rms[21];
3845N/A
0N/A OptoReg::Name i;
0N/A
0N/A // At first, start with the empty mask
0N/A C->FIRST_STACK_mask().Clear();
0N/A
0N/A // Add in the incoming argument area
0N/A OptoReg::Name init = OptoReg::add(_old_SP, C->out_preserve_stack_slots());
0N/A for (i = init; i < _in_arg_limit; i = OptoReg::add(i,1))
0N/A C->FIRST_STACK_mask().Insert(i);
0N/A
0N/A // Add in all bits past the outgoing argument area
3845N/A guarantee(RegMask::can_represent_arg(OptoReg::add(_out_arg_limit,-1)),
0N/A "must be able to represent all call arguments in reg mask");
0N/A init = _out_arg_limit;
0N/A for (i = init; RegMask::can_represent(i); i = OptoReg::add(i,1))
0N/A C->FIRST_STACK_mask().Insert(i);
0N/A
0N/A // Finally, set the "infinite stack" bit.
0N/A C->FIRST_STACK_mask().set_AllStack();
0N/A
0N/A // Make spill masks. Registers for their class, plus FIRST_STACK_mask.
3845N/A RegMask aligned_stack_mask = C->FIRST_STACK_mask();
3845N/A // Keep spill masks aligned.
3845N/A aligned_stack_mask.clear_to_pairs();
3845N/A assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
3845N/A
3845N/A *idealreg2spillmask[Op_RegP] = *idealreg2regmask[Op_RegP];
113N/A#ifdef _LP64
113N/A *idealreg2spillmask[Op_RegN] = *idealreg2regmask[Op_RegN];
113N/A idealreg2spillmask[Op_RegN]->OR(C->FIRST_STACK_mask());
3845N/A idealreg2spillmask[Op_RegP]->OR(aligned_stack_mask);
3845N/A#else
3845N/A idealreg2spillmask[Op_RegP]->OR(C->FIRST_STACK_mask());
113N/A#endif
0N/A *idealreg2spillmask[Op_RegI] = *idealreg2regmask[Op_RegI];
0N/A idealreg2spillmask[Op_RegI]->OR(C->FIRST_STACK_mask());
0N/A *idealreg2spillmask[Op_RegL] = *idealreg2regmask[Op_RegL];
3845N/A idealreg2spillmask[Op_RegL]->OR(aligned_stack_mask);
0N/A *idealreg2spillmask[Op_RegF] = *idealreg2regmask[Op_RegF];
0N/A idealreg2spillmask[Op_RegF]->OR(C->FIRST_STACK_mask());
0N/A *idealreg2spillmask[Op_RegD] = *idealreg2regmask[Op_RegD];
3845N/A idealreg2spillmask[Op_RegD]->OR(aligned_stack_mask);
0N/A
3845N/A if (Matcher::vector_size_supported(T_BYTE,4)) {
3845N/A *idealreg2spillmask[Op_VecS] = *idealreg2regmask[Op_VecS];
3845N/A idealreg2spillmask[Op_VecS]->OR(C->FIRST_STACK_mask());
3845N/A }
3845N/A if (Matcher::vector_size_supported(T_FLOAT,2)) {
3845N/A *idealreg2spillmask[Op_VecD] = *idealreg2regmask[Op_VecD];
3845N/A idealreg2spillmask[Op_VecD]->OR(aligned_stack_mask);
3845N/A }
3845N/A if (Matcher::vector_size_supported(T_FLOAT,4)) {
3845N/A aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecX);
3845N/A assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
3845N/A *idealreg2spillmask[Op_VecX] = *idealreg2regmask[Op_VecX];
3845N/A idealreg2spillmask[Op_VecX]->OR(aligned_stack_mask);
3845N/A }
3845N/A if (Matcher::vector_size_supported(T_FLOAT,8)) {
3845N/A aligned_stack_mask.clear_to_sets(RegMask::SlotsPerVecY);
3845N/A assert(aligned_stack_mask.is_AllStack(), "should be infinite stack");
3845N/A *idealreg2spillmask[Op_VecY] = *idealreg2regmask[Op_VecY];
3845N/A idealreg2spillmask[Op_VecY]->OR(aligned_stack_mask);
3845N/A }
1650N/A if (UseFPUForSpilling) {
1650N/A // This mask logic assumes that the spill operations are
1650N/A // symmetric and that the registers involved are the same size.
1650N/A // On sparc for instance we may have to use 64 bit moves will
1650N/A // kill 2 registers when used with F0-F31.
1650N/A idealreg2spillmask[Op_RegI]->OR(*idealreg2regmask[Op_RegF]);
1650N/A idealreg2spillmask[Op_RegF]->OR(*idealreg2regmask[Op_RegI]);
1650N/A#ifdef _LP64
1650N/A idealreg2spillmask[Op_RegN]->OR(*idealreg2regmask[Op_RegF]);
1650N/A idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]);
1650N/A idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]);
1650N/A idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegD]);
1650N/A#else
1650N/A idealreg2spillmask[Op_RegP]->OR(*idealreg2regmask[Op_RegF]);
2743N/A#ifdef ARM
2743N/A // ARM has support for moving 64bit values between a pair of
2743N/A // integer registers and a double register
2743N/A idealreg2spillmask[Op_RegL]->OR(*idealreg2regmask[Op_RegD]);
2743N/A idealreg2spillmask[Op_RegD]->OR(*idealreg2regmask[Op_RegL]);
2743N/A#endif
1650N/A#endif
1650N/A }
1650N/A
0N/A // Make up debug masks. Any spill slot plus callee-save registers.
0N/A // Caller-save registers are assumed to be trashable by the various
0N/A // inline-cache fixup routines.
1137N/A *idealreg2debugmask [Op_RegN]= *idealreg2spillmask[Op_RegN];
1137N/A *idealreg2debugmask [Op_RegI]= *idealreg2spillmask[Op_RegI];
1137N/A *idealreg2debugmask [Op_RegL]= *idealreg2spillmask[Op_RegL];
1137N/A *idealreg2debugmask [Op_RegF]= *idealreg2spillmask[Op_RegF];
1137N/A *idealreg2debugmask [Op_RegD]= *idealreg2spillmask[Op_RegD];
1137N/A *idealreg2debugmask [Op_RegP]= *idealreg2spillmask[Op_RegP];
1137N/A
1137N/A *idealreg2mhdebugmask[Op_RegN]= *idealreg2spillmask[Op_RegN];
1137N/A *idealreg2mhdebugmask[Op_RegI]= *idealreg2spillmask[Op_RegI];
1137N/A *idealreg2mhdebugmask[Op_RegL]= *idealreg2spillmask[Op_RegL];
1137N/A *idealreg2mhdebugmask[Op_RegF]= *idealreg2spillmask[Op_RegF];
1137N/A *idealreg2mhdebugmask[Op_RegD]= *idealreg2spillmask[Op_RegD];
1137N/A *idealreg2mhdebugmask[Op_RegP]= *idealreg2spillmask[Op_RegP];
0N/A
0N/A // Prevent stub compilations from attempting to reference
0N/A // callee-saved registers from debug info
0N/A bool exclude_soe = !Compile::current()->is_method_compilation();
0N/A
0N/A for( i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
0N/A // registers the caller has to save do not work
0N/A if( _register_save_policy[i] == 'C' ||
0N/A _register_save_policy[i] == 'A' ||
0N/A (_register_save_policy[i] == 'E' && exclude_soe) ) {
1137N/A idealreg2debugmask [Op_RegN]->Remove(i);
1137N/A idealreg2debugmask [Op_RegI]->Remove(i); // Exclude save-on-call
1137N/A idealreg2debugmask [Op_RegL]->Remove(i); // registers from debug
1137N/A idealreg2debugmask [Op_RegF]->Remove(i); // masks
1137N/A idealreg2debugmask [Op_RegD]->Remove(i);
1137N/A idealreg2debugmask [Op_RegP]->Remove(i);
1137N/A
1137N/A idealreg2mhdebugmask[Op_RegN]->Remove(i);
1137N/A idealreg2mhdebugmask[Op_RegI]->Remove(i);
1137N/A idealreg2mhdebugmask[Op_RegL]->Remove(i);
1137N/A idealreg2mhdebugmask[Op_RegF]->Remove(i);
1137N/A idealreg2mhdebugmask[Op_RegD]->Remove(i);
1137N/A idealreg2mhdebugmask[Op_RegP]->Remove(i);
0N/A }
0N/A }
1137N/A
1137N/A // Subtract the register we use to save the SP for MethodHandle
1137N/A // invokes to from the debug mask.
1137N/A const RegMask save_mask = method_handle_invoke_SP_save_mask();
1137N/A idealreg2mhdebugmask[Op_RegN]->SUBTRACT(save_mask);
1137N/A idealreg2mhdebugmask[Op_RegI]->SUBTRACT(save_mask);
1137N/A idealreg2mhdebugmask[Op_RegL]->SUBTRACT(save_mask);
1137N/A idealreg2mhdebugmask[Op_RegF]->SUBTRACT(save_mask);
1137N/A idealreg2mhdebugmask[Op_RegD]->SUBTRACT(save_mask);
1137N/A idealreg2mhdebugmask[Op_RegP]->SUBTRACT(save_mask);
0N/A}
0N/A
0N/A//---------------------------is_save_on_entry----------------------------------
0N/Abool Matcher::is_save_on_entry( int reg ) {
0N/A return
0N/A _register_save_policy[reg] == 'E' ||
0N/A _register_save_policy[reg] == 'A' || // Save-on-entry register?
0N/A // Also save argument registers in the trampolining stubs
0N/A (C->save_argument_registers() && is_spillable_arg(reg));
0N/A}
0N/A
0N/A//---------------------------Fixup_Save_On_Entry-------------------------------
0N/Avoid Matcher::Fixup_Save_On_Entry( ) {
0N/A init_first_stack_mask();
0N/A
0N/A Node *root = C->root(); // Short name for root
0N/A // Count number of save-on-entry registers.
0N/A uint soe_cnt = number_of_saved_registers();
0N/A uint i;
0N/A
0N/A // Find the procedure Start Node
0N/A StartNode *start = C->start();
0N/A assert( start, "Expect a start node" );
0N/A
0N/A // Save argument registers in the trampolining stubs
0N/A if( C->save_argument_registers() )
0N/A for( i = 0; i < _last_Mach_Reg; i++ )
0N/A if( is_spillable_arg(i) )
0N/A soe_cnt++;
0N/A
0N/A // Input RegMask array shared by all Returns.
0N/A // The type for doubles and longs has a count of 2, but
0N/A // there is only 1 returned value
0N/A uint ret_edge_cnt = TypeFunc::Parms + ((C->tf()->range()->cnt() == TypeFunc::Parms) ? 0 : 1);
0N/A RegMask *ret_rms = init_input_masks( ret_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
0N/A // Returns have 0 or 1 returned values depending on call signature.
0N/A // Return register is specified by return_value in the AD file.
0N/A if (ret_edge_cnt > TypeFunc::Parms)
0N/A ret_rms[TypeFunc::Parms+0] = _return_value_mask;
0N/A
0N/A // Input RegMask array shared by all Rethrows.
0N/A uint reth_edge_cnt = TypeFunc::Parms+1;
0N/A RegMask *reth_rms = init_input_masks( reth_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
0N/A // Rethrow takes exception oop only, but in the argument 0 slot.
0N/A reth_rms[TypeFunc::Parms] = mreg2regmask[find_receiver(false)];
0N/A#ifdef _LP64
0N/A // Need two slots for ptrs in 64-bit land
0N/A reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(find_receiver(false)),1));
0N/A#endif
0N/A
0N/A // Input RegMask array shared by all TailCalls
0N/A uint tail_call_edge_cnt = TypeFunc::Parms+2;
0N/A RegMask *tail_call_rms = init_input_masks( tail_call_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
0N/A
0N/A // Input RegMask array shared by all TailJumps
0N/A uint tail_jump_edge_cnt = TypeFunc::Parms+2;
0N/A RegMask *tail_jump_rms = init_input_masks( tail_jump_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
0N/A
0N/A // TailCalls have 2 returned values (target & moop), whose masks come
0N/A // from the usual MachNode/MachOper mechanism. Find a sample
0N/A // TailCall to extract these masks and put the correct masks into
0N/A // the tail_call_rms array.
0N/A for( i=1; i < root->req(); i++ ) {
0N/A MachReturnNode *m = root->in(i)->as_MachReturn();
0N/A if( m->ideal_Opcode() == Op_TailCall ) {
0N/A tail_call_rms[TypeFunc::Parms+0] = m->MachNode::in_RegMask(TypeFunc::Parms+0);
0N/A tail_call_rms[TypeFunc::Parms+1] = m->MachNode::in_RegMask(TypeFunc::Parms+1);
0N/A break;
0N/A }
0N/A }
0N/A
0N/A // TailJumps have 2 returned values (target & ex_oop), whose masks come
0N/A // from the usual MachNode/MachOper mechanism. Find a sample
0N/A // TailJump to extract these masks and put the correct masks into
0N/A // the tail_jump_rms array.
0N/A for( i=1; i < root->req(); i++ ) {
0N/A MachReturnNode *m = root->in(i)->as_MachReturn();
0N/A if( m->ideal_Opcode() == Op_TailJump ) {
0N/A tail_jump_rms[TypeFunc::Parms+0] = m->MachNode::in_RegMask(TypeFunc::Parms+0);
0N/A tail_jump_rms[TypeFunc::Parms+1] = m->MachNode::in_RegMask(TypeFunc::Parms+1);
0N/A break;
0N/A }
0N/A }
0N/A
0N/A // Input RegMask array shared by all Halts
0N/A uint halt_edge_cnt = TypeFunc::Parms;
0N/A RegMask *halt_rms = init_input_masks( halt_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
0N/A
0N/A // Capture the return input masks into each exit flavor
0N/A for( i=1; i < root->req(); i++ ) {
0N/A MachReturnNode *exit = root->in(i)->as_MachReturn();
0N/A switch( exit->ideal_Opcode() ) {
0N/A case Op_Return : exit->_in_rms = ret_rms; break;
0N/A case Op_Rethrow : exit->_in_rms = reth_rms; break;
0N/A case Op_TailCall : exit->_in_rms = tail_call_rms; break;
0N/A case Op_TailJump : exit->_in_rms = tail_jump_rms; break;
0N/A case Op_Halt : exit->_in_rms = halt_rms; break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A }
0N/A
0N/A // Next unused projection number from Start.
0N/A int proj_cnt = C->tf()->domain()->cnt();
0N/A
0N/A // Do all the save-on-entry registers. Make projections from Start for
0N/A // them, and give them a use at the exit points. To the allocator, they
0N/A // look like incoming register arguments.
0N/A for( i = 0; i < _last_Mach_Reg; i++ ) {
0N/A if( is_save_on_entry(i) ) {
0N/A
0N/A // Add the save-on-entry to the mask array
0N/A ret_rms [ ret_edge_cnt] = mreg2regmask[i];
0N/A reth_rms [ reth_edge_cnt] = mreg2regmask[i];
0N/A tail_call_rms[tail_call_edge_cnt] = mreg2regmask[i];
0N/A tail_jump_rms[tail_jump_edge_cnt] = mreg2regmask[i];
0N/A // Halts need the SOE registers, but only in the stack as debug info.
0N/A // A just-prior uncommon-trap or deoptimization will use the SOE regs.
0N/A halt_rms [ halt_edge_cnt] = *idealreg2spillmask[_register_save_type[i]];
0N/A
0N/A Node *mproj;
0N/A
0N/A // Is this a RegF low half of a RegD? Double up 2 adjacent RegF's
0N/A // into a single RegD.
0N/A if( (i&1) == 0 &&
0N/A _register_save_type[i ] == Op_RegF &&
0N/A _register_save_type[i+1] == Op_RegF &&
0N/A is_save_on_entry(i+1) ) {
0N/A // Add other bit for double
0N/A ret_rms [ ret_edge_cnt].Insert(OptoReg::Name(i+1));
0N/A reth_rms [ reth_edge_cnt].Insert(OptoReg::Name(i+1));
0N/A tail_call_rms[tail_call_edge_cnt].Insert(OptoReg::Name(i+1));
0N/A tail_jump_rms[tail_jump_edge_cnt].Insert(OptoReg::Name(i+1));
0N/A halt_rms [ halt_edge_cnt].Insert(OptoReg::Name(i+1));
4022N/A mproj = new (C) MachProjNode( start, proj_cnt, ret_rms[ret_edge_cnt], Op_RegD );
0N/A proj_cnt += 2; // Skip 2 for doubles
0N/A }
0N/A else if( (i&1) == 1 && // Else check for high half of double
0N/A _register_save_type[i-1] == Op_RegF &&
0N/A _register_save_type[i ] == Op_RegF &&
0N/A is_save_on_entry(i-1) ) {
0N/A ret_rms [ ret_edge_cnt] = RegMask::Empty;
0N/A reth_rms [ reth_edge_cnt] = RegMask::Empty;
0N/A tail_call_rms[tail_call_edge_cnt] = RegMask::Empty;
0N/A tail_jump_rms[tail_jump_edge_cnt] = RegMask::Empty;
0N/A halt_rms [ halt_edge_cnt] = RegMask::Empty;
0N/A mproj = C->top();
0N/A }
0N/A // Is this a RegI low half of a RegL? Double up 2 adjacent RegI's
0N/A // into a single RegL.
0N/A else if( (i&1) == 0 &&
0N/A _register_save_type[i ] == Op_RegI &&
0N/A _register_save_type[i+1] == Op_RegI &&
0N/A is_save_on_entry(i+1) ) {
0N/A // Add other bit for long
0N/A ret_rms [ ret_edge_cnt].Insert(OptoReg::Name(i+1));
0N/A reth_rms [ reth_edge_cnt].Insert(OptoReg::Name(i+1));
0N/A tail_call_rms[tail_call_edge_cnt].Insert(OptoReg::Name(i+1));
0N/A tail_jump_rms[tail_jump_edge_cnt].Insert(OptoReg::Name(i+1));
0N/A halt_rms [ halt_edge_cnt].Insert(OptoReg::Name(i+1));
4022N/A mproj = new (C) MachProjNode( start, proj_cnt, ret_rms[ret_edge_cnt], Op_RegL );
0N/A proj_cnt += 2; // Skip 2 for longs
0N/A }
0N/A else if( (i&1) == 1 && // Else check for high half of long
0N/A _register_save_type[i-1] == Op_RegI &&
0N/A _register_save_type[i ] == Op_RegI &&
0N/A is_save_on_entry(i-1) ) {
0N/A ret_rms [ ret_edge_cnt] = RegMask::Empty;
0N/A reth_rms [ reth_edge_cnt] = RegMask::Empty;
0N/A tail_call_rms[tail_call_edge_cnt] = RegMask::Empty;
0N/A tail_jump_rms[tail_jump_edge_cnt] = RegMask::Empty;
0N/A halt_rms [ halt_edge_cnt] = RegMask::Empty;
0N/A mproj = C->top();
0N/A } else {
0N/A // Make a projection for it off the Start
4022N/A mproj = new (C) MachProjNode( start, proj_cnt++, ret_rms[ret_edge_cnt], _register_save_type[i] );
0N/A }
0N/A
0N/A ret_edge_cnt ++;
0N/A reth_edge_cnt ++;
0N/A tail_call_edge_cnt ++;
0N/A tail_jump_edge_cnt ++;
0N/A halt_edge_cnt ++;
0N/A
0N/A // Add a use of the SOE register to all exit paths
0N/A for( uint j=1; j < root->req(); j++ )
0N/A root->in(j)->add_req(mproj);
0N/A } // End of if a save-on-entry register
0N/A } // End of for all machine registers
0N/A}
0N/A
0N/A//------------------------------init_spill_mask--------------------------------
0N/Avoid Matcher::init_spill_mask( Node *ret ) {
0N/A if( idealreg2regmask[Op_RegI] ) return; // One time only init
0N/A
0N/A OptoReg::c_frame_pointer = c_frame_pointer();
0N/A c_frame_ptr_mask = c_frame_pointer();
0N/A#ifdef _LP64
0N/A // pointers are twice as big
0N/A c_frame_ptr_mask.Insert(OptoReg::add(c_frame_pointer(),1));
0N/A#endif
0N/A
0N/A // Start at OptoReg::stack0()
0N/A STACK_ONLY_mask.Clear();
0N/A OptoReg::Name init = OptoReg::stack2reg(0);
0N/A // STACK_ONLY_mask is all stack bits
0N/A OptoReg::Name i;
0N/A for (i = init; RegMask::can_represent(i); i = OptoReg::add(i,1))
0N/A STACK_ONLY_mask.Insert(i);
0N/A // Also set the "infinite stack" bit.
0N/A STACK_ONLY_mask.set_AllStack();
0N/A
0N/A // Copy the register names over into the shared world
0N/A for( i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
0N/A // SharedInfo::regName[i] = regName[i];
0N/A // Handy RegMasks per machine register
0N/A mreg2regmask[i].Insert(i);
0N/A }
0N/A
0N/A // Grab the Frame Pointer
0N/A Node *fp = ret->in(TypeFunc::FramePtr);
0N/A Node *mem = ret->in(TypeFunc::Memory);
0N/A const TypePtr* atp = TypePtr::BOTTOM;
0N/A // Share frame pointer while making spill ops
0N/A set_shared(fp);
0N/A
0N/A // Compute generic short-offset Loads
113N/A#ifdef _LP64
4022N/A MachNode *spillCP = match_tree(new (C) LoadNNode(NULL,mem,fp,atp,TypeInstPtr::BOTTOM));
113N/A#endif
4022N/A MachNode *spillI = match_tree(new (C) LoadINode(NULL,mem,fp,atp));
4022N/A MachNode *spillL = match_tree(new (C) LoadLNode(NULL,mem,fp,atp));
4022N/A MachNode *spillF = match_tree(new (C) LoadFNode(NULL,mem,fp,atp));
4022N/A MachNode *spillD = match_tree(new (C) LoadDNode(NULL,mem,fp,atp));
4022N/A MachNode *spillP = match_tree(new (C) LoadPNode(NULL,mem,fp,atp,TypeInstPtr::BOTTOM));
0N/A assert(spillI != NULL && spillL != NULL && spillF != NULL &&
0N/A spillD != NULL && spillP != NULL, "");
0N/A
0N/A // Get the ADLC notion of the right regmask, for each basic type.
113N/A#ifdef _LP64
113N/A idealreg2regmask[Op_RegN] = &spillCP->out_RegMask();
113N/A#endif
0N/A idealreg2regmask[Op_RegI] = &spillI->out_RegMask();
0N/A idealreg2regmask[Op_RegL] = &spillL->out_RegMask();
0N/A idealreg2regmask[Op_RegF] = &spillF->out_RegMask();
0N/A idealreg2regmask[Op_RegD] = &spillD->out_RegMask();
0N/A idealreg2regmask[Op_RegP] = &spillP->out_RegMask();
3845N/A
3845N/A // Vector regmasks.
3845N/A if (Matcher::vector_size_supported(T_BYTE,4)) {
3845N/A TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
4022N/A MachNode *spillVectS = match_tree(new (C) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTS));
3845N/A idealreg2regmask[Op_VecS] = &spillVectS->out_RegMask();
3845N/A }
3845N/A if (Matcher::vector_size_supported(T_FLOAT,2)) {
4022N/A MachNode *spillVectD = match_tree(new (C) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTD));
3845N/A idealreg2regmask[Op_VecD] = &spillVectD->out_RegMask();
3845N/A }
3845N/A if (Matcher::vector_size_supported(T_FLOAT,4)) {
4022N/A MachNode *spillVectX = match_tree(new (C) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTX));
3845N/A idealreg2regmask[Op_VecX] = &spillVectX->out_RegMask();
3845N/A }
3845N/A if (Matcher::vector_size_supported(T_FLOAT,8)) {
4022N/A MachNode *spillVectY = match_tree(new (C) LoadVectorNode(NULL,mem,fp,atp,TypeVect::VECTY));
3845N/A idealreg2regmask[Op_VecY] = &spillVectY->out_RegMask();
3845N/A }
0N/A}
0N/A
0N/A#ifdef ASSERT
0N/Astatic void match_alias_type(Compile* C, Node* n, Node* m) {
0N/A if (!VerifyAliases) return; // do not go looking for trouble by default
0N/A const TypePtr* nat = n->adr_type();
0N/A const TypePtr* mat = m->adr_type();
0N/A int nidx = C->get_alias_index(nat);
0N/A int midx = C->get_alias_index(mat);
0N/A // Detune the assert for cases like (AndI 0xFF (LoadB p)).
0N/A if (nidx == Compile::AliasIdxTop && midx >= Compile::AliasIdxRaw) {
0N/A for (uint i = 1; i < n->req(); i++) {
0N/A Node* n1 = n->in(i);
0N/A const TypePtr* n1at = n1->adr_type();
0N/A if (n1at != NULL) {
0N/A nat = n1at;
0N/A nidx = C->get_alias_index(n1at);
0N/A }
0N/A }
0N/A }
0N/A // %%% Kludgery. Instead, fix ideal adr_type methods for all these cases:
0N/A if (nidx == Compile::AliasIdxTop && midx == Compile::AliasIdxRaw) {
0N/A switch (n->Opcode()) {
0N/A case Op_PrefetchRead:
0N/A case Op_PrefetchWrite:
2679N/A case Op_PrefetchAllocation:
0N/A nidx = Compile::AliasIdxRaw;
0N/A nat = TypeRawPtr::BOTTOM;
0N/A break;
0N/A }
0N/A }
0N/A if (nidx == Compile::AliasIdxRaw && midx == Compile::AliasIdxTop) {
0N/A switch (n->Opcode()) {
0N/A case Op_ClearArray:
0N/A midx = Compile::AliasIdxRaw;
0N/A mat = TypeRawPtr::BOTTOM;
0N/A break;
0N/A }
0N/A }
0N/A if (nidx == Compile::AliasIdxTop && midx == Compile::AliasIdxBot) {
0N/A switch (n->Opcode()) {
0N/A case Op_Return:
0N/A case Op_Rethrow:
0N/A case Op_Halt:
0N/A case Op_TailCall:
0N/A case Op_TailJump:
0N/A nidx = Compile::AliasIdxBot;
0N/A nat = TypePtr::BOTTOM;
0N/A break;
0N/A }
0N/A }
0N/A if (nidx == Compile::AliasIdxBot && midx == Compile::AliasIdxTop) {
0N/A switch (n->Opcode()) {
0N/A case Op_StrComp:
681N/A case Op_StrEquals:
681N/A case Op_StrIndexOf:
169N/A case Op_AryEq:
0N/A case Op_MemBarVolatile:
0N/A case Op_MemBarCPUOrder: // %%% these ideals should have narrower adr_type?
0N/A nidx = Compile::AliasIdxTop;
0N/A nat = NULL;
0N/A break;
0N/A }
0N/A }
0N/A if (nidx != midx) {
0N/A if (PrintOpto || (PrintMiscellaneous && (WizardMode || Verbose))) {
0N/A tty->print_cr("==== Matcher alias shift %d => %d", nidx, midx);
0N/A n->dump();
0N/A m->dump();
0N/A }
0N/A assert(C->subsume_loads() && C->must_alias(nat, midx),
0N/A "must not lose alias info when matching");
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A
0N/A//------------------------------MStack-----------------------------------------
0N/A// State and MStack class used in xform() and find_shared() iterative methods.
0N/Aenum Node_State { Pre_Visit, // node has to be pre-visited
0N/A Visit, // visit node
0N/A Post_Visit, // post-visit node
0N/A Alt_Post_Visit // alternative post-visit path
0N/A };
0N/A
0N/Aclass MStack: public Node_Stack {
0N/A public:
0N/A MStack(int size) : Node_Stack(size) { }
0N/A
0N/A void push(Node *n, Node_State ns) {
0N/A Node_Stack::push(n, (uint)ns);
0N/A }
0N/A void push(Node *n, Node_State ns, Node *parent, int indx) {
0N/A ++_inode_top;
0N/A if ((_inode_top + 1) >= _inode_max) grow();
0N/A _inode_top->node = parent;
0N/A _inode_top->indx = (uint)indx;
0N/A ++_inode_top;
0N/A _inode_top->node = n;
0N/A _inode_top->indx = (uint)ns;
0N/A }
0N/A Node *parent() {
0N/A pop();
0N/A return node();
0N/A }
0N/A Node_State state() const {
0N/A return (Node_State)index();
0N/A }
0N/A void set_state(Node_State ns) {
0N/A set_index((uint)ns);
0N/A }
0N/A};
0N/A
0N/A
0N/A//------------------------------xform------------------------------------------
0N/A// Given a Node in old-space, Match him (Label/Reduce) to produce a machine
0N/A// Node in new-space. Given a new-space Node, recursively walk his children.
0N/ANode *Matcher::transform( Node *n ) { ShouldNotCallThis(); return n; }
0N/ANode *Matcher::xform( Node *n, int max_stack ) {
0N/A // Use one stack to keep both: child's node/state and parent's node/index
0N/A MStack mstack(max_stack * 2 * 2); // C->unique() * 2 * 2
0N/A mstack.push(n, Visit, NULL, -1); // set NULL as parent to indicate root
0N/A
0N/A while (mstack.is_nonempty()) {
0N/A n = mstack.node(); // Leave node on stack
0N/A Node_State nstate = mstack.state();
0N/A if (nstate == Visit) {
0N/A mstack.set_state(Post_Visit);
0N/A Node *oldn = n;
0N/A // Old-space or new-space check
0N/A if (!C->node_arena()->contains(n)) {
0N/A // Old space!
0N/A Node* m;
0N/A if (has_new_node(n)) { // Not yet Label/Reduced
0N/A m = new_node(n);
0N/A } else {
0N/A if (!is_dontcare(n)) { // Matcher can match this guy
0N/A // Calls match special. They match alone with no children.
0N/A // Their children, the incoming arguments, match normally.
0N/A m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n);
0N/A if (C->failing()) return NULL;
0N/A if (m == NULL) { Matcher::soft_match_failure(); return NULL; }
0N/A } else { // Nothing the matcher cares about
0N/A if( n->is_Proj() && n->in(0)->is_Multi()) { // Projections?
0N/A // Convert to machine-dependent projection
0N/A m = n->in(0)->as_Multi()->match( n->as_Proj(), this );
222N/A#ifdef ASSERT
222N/A _new2old_map.map(m->_idx, n);
222N/A#endif
0N/A if (m->in(0) != NULL) // m might be top
368N/A collect_null_checks(m, n);
0N/A } else { // Else just a regular 'ol guy
0N/A m = n->clone(); // So just clone into new-space
222N/A#ifdef ASSERT
222N/A _new2old_map.map(m->_idx, n);
222N/A#endif
0N/A // Def-Use edges will be added incrementally as Uses
0N/A // of this node are matched.
0N/A assert(m->outcnt() == 0, "no Uses of this clone yet");
0N/A }
0N/A }
0N/A
0N/A set_new_node(n, m); // Map old to new
0N/A if (_old_node_note_array != NULL) {
0N/A Node_Notes* nn = C->locate_node_notes(_old_node_note_array,
0N/A n->_idx);
0N/A C->set_node_notes_at(m->_idx, nn);
0N/A }
0N/A debug_only(match_alias_type(C, n, m));
0N/A }
0N/A n = m; // n is now a new-space node
0N/A mstack.set_node(n);
0N/A }
0N/A
0N/A // New space!
0N/A if (_visited.test_set(n->_idx)) continue; // while(mstack.is_nonempty())
0N/A
0N/A int i;
0N/A // Put precedence edges on stack first (match them last).
0N/A for (i = oldn->req(); (uint)i < oldn->len(); i++) {
0N/A Node *m = oldn->in(i);
0N/A if (m == NULL) break;
0N/A // set -1 to call add_prec() instead of set_req() during Step1
0N/A mstack.push(m, Visit, n, -1);
0N/A }
0N/A
0N/A // For constant debug info, I'd rather have unmatched constants.
0N/A int cnt = n->req();
0N/A JVMState* jvms = n->jvms();
0N/A int debug_cnt = jvms ? jvms->debug_start() : cnt;
0N/A
0N/A // Now do only debug info. Clone constants rather than matching.
0N/A // Constants are represented directly in the debug info without
0N/A // the need for executable machine instructions.
0N/A // Monitor boxes are also represented directly.
0N/A for (i = cnt - 1; i >= debug_cnt; --i) { // For all debug inputs do
0N/A Node *m = n->in(i); // Get input
0N/A int op = m->Opcode();
0N/A assert((op == Op_BoxLock) == jvms->is_monitor_use(i), "boxes only at monitor sites");
163N/A if( op == Op_ConI || op == Op_ConP || op == Op_ConN ||
0N/A op == Op_ConF || op == Op_ConD || op == Op_ConL
0N/A // || op == Op_BoxLock // %%%% enable this and remove (+++) in chaitin.cpp
0N/A ) {
0N/A m = m->clone();
222N/A#ifdef ASSERT
222N/A _new2old_map.map(m->_idx, n);
222N/A#endif
605N/A mstack.push(m, Post_Visit, n, i); // Don't need to visit
0N/A mstack.push(m->in(0), Visit, m, 0);
0N/A } else {
0N/A mstack.push(m, Visit, n, i);
0N/A }
0N/A }
0N/A
0N/A // And now walk his children, and convert his inputs to new-space.
0N/A for( ; i >= 0; --i ) { // For all normal inputs do
0N/A Node *m = n->in(i); // Get input
0N/A if(m != NULL)
0N/A mstack.push(m, Visit, n, i);
0N/A }
0N/A
0N/A }
0N/A else if (nstate == Post_Visit) {
0N/A // Set xformed input
0N/A Node *p = mstack.parent();
0N/A if (p != NULL) { // root doesn't have parent
0N/A int i = (int)mstack.index();
0N/A if (i >= 0)
0N/A p->set_req(i, n); // required input
0N/A else if (i == -1)
0N/A p->add_prec(n); // precedence input
0N/A else
0N/A ShouldNotReachHere();
0N/A }
0N/A mstack.pop(); // remove processed node from stack
0N/A }
0N/A else {
0N/A ShouldNotReachHere();
0N/A }
0N/A } // while (mstack.is_nonempty())
0N/A return n; // Return new-space Node
0N/A}
0N/A
0N/A//------------------------------warp_outgoing_stk_arg------------------------
0N/AOptoReg::Name Matcher::warp_outgoing_stk_arg( VMReg reg, OptoReg::Name begin_out_arg_area, OptoReg::Name &out_arg_limit_per_call ) {
0N/A // Convert outgoing argument location to a pre-biased stack offset
0N/A if (reg->is_stack()) {
0N/A OptoReg::Name warped = reg->reg2stack();
0N/A // Adjust the stack slot offset to be the register number used
0N/A // by the allocator.
0N/A warped = OptoReg::add(begin_out_arg_area, warped);
0N/A // Keep track of the largest numbered stack slot used for an arg.
0N/A // Largest used slot per call-site indicates the amount of stack
0N/A // that is killed by the call.
0N/A if( warped >= out_arg_limit_per_call )
0N/A out_arg_limit_per_call = OptoReg::add(warped,1);
3845N/A if (!RegMask::can_represent_arg(warped)) {
0N/A C->record_method_not_compilable_all_tiers("unsupported calling sequence");
0N/A return OptoReg::Bad;
0N/A }
0N/A return warped;
0N/A }
0N/A return OptoReg::as_OptoReg(reg);
0N/A}
0N/A
0N/A
0N/A//------------------------------match_sfpt-------------------------------------
0N/A// Helper function to match call instructions. Calls match special.
0N/A// They match alone with no children. Their children, the incoming
0N/A// arguments, match normally.
0N/AMachNode *Matcher::match_sfpt( SafePointNode *sfpt ) {
0N/A MachSafePointNode *msfpt = NULL;
0N/A MachCallNode *mcall = NULL;
0N/A uint cnt;
0N/A // Split out case for SafePoint vs Call
0N/A CallNode *call;
0N/A const TypeTuple *domain;
0N/A ciMethod* method = NULL;
1137N/A bool is_method_handle_invoke = false; // for special kill effects
0N/A if( sfpt->is_Call() ) {
0N/A call = sfpt->as_Call();
0N/A domain = call->tf()->domain();
0N/A cnt = domain->cnt();
0N/A
0N/A // Match just the call, nothing else
0N/A MachNode *m = match_tree(call);
0N/A if (C->failing()) return NULL;
0N/A if( m == NULL ) { Matcher::soft_match_failure(); return NULL; }
0N/A
0N/A // Copy data from the Ideal SafePoint to the machine version
0N/A mcall = m->as_MachCall();
0N/A
0N/A mcall->set_tf( call->tf());
0N/A mcall->set_entry_point(call->entry_point());
0N/A mcall->set_cnt( call->cnt());
0N/A
0N/A if( mcall->is_MachCallJava() ) {
0N/A MachCallJavaNode *mcall_java = mcall->as_MachCallJava();
0N/A const CallJavaNode *call_java = call->as_CallJava();
0N/A method = call_java->method();
0N/A mcall_java->_method = method;
0N/A mcall_java->_bci = call_java->_bci;
0N/A mcall_java->_optimized_virtual = call_java->is_optimized_virtual();
1137N/A is_method_handle_invoke = call_java->is_method_handle_invoke();
1137N/A mcall_java->_method_handle_invoke = is_method_handle_invoke;
2739N/A if (is_method_handle_invoke) {
2739N/A C->set_has_method_handle_invokes(true);
2739N/A }
0N/A if( mcall_java->is_MachCallStaticJava() )
0N/A mcall_java->as_MachCallStaticJava()->_name =
0N/A call_java->as_CallStaticJava()->_name;
0N/A if( mcall_java->is_MachCallDynamicJava() )
0N/A mcall_java->as_MachCallDynamicJava()->_vtable_index =
0N/A call_java->as_CallDynamicJava()->_vtable_index;
0N/A }
0N/A else if( mcall->is_MachCallRuntime() ) {
0N/A mcall->as_MachCallRuntime()->_name = call->as_CallRuntime()->_name;
0N/A }
0N/A msfpt = mcall;
0N/A }
0N/A // This is a non-call safepoint
0N/A else {
0N/A call = NULL;
0N/A domain = NULL;
0N/A MachNode *mn = match_tree(sfpt);
0N/A if (C->failing()) return NULL;
0N/A msfpt = mn->as_MachSafePoint();
0N/A cnt = TypeFunc::Parms;
0N/A }
0N/A
0N/A // Advertise the correct memory effects (for anti-dependence computation).
0N/A msfpt->set_adr_type(sfpt->adr_type());
0N/A
0N/A // Allocate a private array of RegMasks. These RegMasks are not shared.
0N/A msfpt->_in_rms = NEW_RESOURCE_ARRAY( RegMask, cnt );
0N/A // Empty them all.
0N/A memset( msfpt->_in_rms, 0, sizeof(RegMask)*cnt );
0N/A
0N/A // Do all the pre-defined non-Empty register masks
0N/A msfpt->_in_rms[TypeFunc::ReturnAdr] = _return_addr_mask;
0N/A msfpt->_in_rms[TypeFunc::FramePtr ] = c_frame_ptr_mask;
0N/A
0N/A // Place first outgoing argument can possibly be put.
0N/A OptoReg::Name begin_out_arg_area = OptoReg::add(_new_SP, C->out_preserve_stack_slots());
0N/A assert( is_even(begin_out_arg_area), "" );
0N/A // Compute max outgoing register number per call site.
0N/A OptoReg::Name out_arg_limit_per_call = begin_out_arg_area;
0N/A // Calls to C may hammer extra stack slots above and beyond any arguments.
0N/A // These are usually backing store for register arguments for varargs.
0N/A if( call != NULL && call->is_CallRuntime() )
0N/A out_arg_limit_per_call = OptoReg::add(out_arg_limit_per_call,C->varargs_C_out_slots_killed());
0N/A
0N/A
0N/A // Do the normal argument list (parameters) register masks
0N/A int argcnt = cnt - TypeFunc::Parms;
0N/A if( argcnt > 0 ) { // Skip it all if we have no args
0N/A BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, argcnt );
0N/A VMRegPair *parm_regs = NEW_RESOURCE_ARRAY( VMRegPair, argcnt );
0N/A int i;
0N/A for( i = 0; i < argcnt; i++ ) {
0N/A sig_bt[i] = domain->field_at(i+TypeFunc::Parms)->basic_type();
0N/A }
0N/A // V-call to pick proper calling convention
0N/A call->calling_convention( sig_bt, parm_regs, argcnt );
0N/A
0N/A#ifdef ASSERT
0N/A // Sanity check users' calling convention. Really handy during
0N/A // the initial porting effort. Fairly expensive otherwise.
0N/A { for (int i = 0; i<argcnt; i++) {
0N/A if( !parm_regs[i].first()->is_valid() &&
0N/A !parm_regs[i].second()->is_valid() ) continue;
0N/A VMReg reg1 = parm_regs[i].first();
0N/A VMReg reg2 = parm_regs[i].second();
0N/A for (int j = 0; j < i; j++) {
0N/A if( !parm_regs[j].first()->is_valid() &&
0N/A !parm_regs[j].second()->is_valid() ) continue;
0N/A VMReg reg3 = parm_regs[j].first();
0N/A VMReg reg4 = parm_regs[j].second();
0N/A if( !reg1->is_valid() ) {
0N/A assert( !reg2->is_valid(), "valid halvsies" );
0N/A } else if( !reg3->is_valid() ) {
0N/A assert( !reg4->is_valid(), "valid halvsies" );
0N/A } else {
0N/A assert( reg1 != reg2, "calling conv. must produce distinct regs");
0N/A assert( reg1 != reg3, "calling conv. must produce distinct regs");
0N/A assert( reg1 != reg4, "calling conv. must produce distinct regs");
0N/A assert( reg2 != reg3, "calling conv. must produce distinct regs");
0N/A assert( reg2 != reg4 || !reg2->is_valid(), "calling conv. must produce distinct regs");
0N/A assert( reg3 != reg4, "calling conv. must produce distinct regs");
0N/A }
0N/A }
0N/A }
0N/A }
0N/A#endif
0N/A
0N/A // Visit each argument. Compute its outgoing register mask.
0N/A // Return results now can have 2 bits returned.
0N/A // Compute max over all outgoing arguments both per call-site
0N/A // and over the entire method.
0N/A for( i = 0; i < argcnt; i++ ) {
0N/A // Address of incoming argument mask to fill in
0N/A RegMask *rm = &mcall->_in_rms[i+TypeFunc::Parms];
0N/A if( !parm_regs[i].first()->is_valid() &&
0N/A !parm_regs[i].second()->is_valid() ) {
0N/A continue; // Avoid Halves
0N/A }
0N/A // Grab first register, adjust stack slots and insert in mask.
0N/A OptoReg::Name reg1 = warp_outgoing_stk_arg(parm_regs[i].first(), begin_out_arg_area, out_arg_limit_per_call );
0N/A if (OptoReg::is_valid(reg1))
0N/A rm->Insert( reg1 );
0N/A // Grab second register (if any), adjust stack slots and insert in mask.
0N/A OptoReg::Name reg2 = warp_outgoing_stk_arg(parm_regs[i].second(), begin_out_arg_area, out_arg_limit_per_call );
0N/A if (OptoReg::is_valid(reg2))
0N/A rm->Insert( reg2 );
0N/A } // End of for all arguments
0N/A
0N/A // Compute number of stack slots needed to restore stack in case of
0N/A // Pascal-style argument popping.
0N/A mcall->_argsize = out_arg_limit_per_call - begin_out_arg_area;
0N/A }
0N/A
1137N/A if (is_method_handle_invoke) {
1137N/A // Kill some extra stack space in case method handles want to do
1137N/A // a little in-place argument insertion.
3932N/A // FIXME: Is this still necessary?
1137N/A int regs_per_word = NOT_LP64(1) LP64_ONLY(2); // %%% make a global const!
3932N/A out_arg_limit_per_call += methodOopDesc::extra_stack_entries() * regs_per_word;
1137N/A // Do not update mcall->_argsize because (a) the extra space is not
1137N/A // pushed as arguments and (b) _argsize is dead (not used anywhere).
1137N/A }
1137N/A
0N/A // Compute the max stack slot killed by any call. These will not be
0N/A // available for debug info, and will be used to adjust FIRST_STACK_mask
0N/A // after all call sites have been visited.
0N/A if( _out_arg_limit < out_arg_limit_per_call)
0N/A _out_arg_limit = out_arg_limit_per_call;
0N/A
0N/A if (mcall) {
0N/A // Kill the outgoing argument area, including any non-argument holes and
0N/A // any legacy C-killed slots. Use Fat-Projections to do the killing.
0N/A // Since the max-per-method covers the max-per-call-site and debug info
0N/A // is excluded on the max-per-method basis, debug info cannot land in
0N/A // this killed area.
0N/A uint r_cnt = mcall->tf()->range()->cnt();
4022N/A MachProjNode *proj = new (C) MachProjNode( mcall, r_cnt+10000, RegMask::Empty, MachProjNode::fat_proj );
3845N/A if (!RegMask::can_represent_arg(OptoReg::Name(out_arg_limit_per_call-1))) {
0N/A C->record_method_not_compilable_all_tiers("unsupported outgoing calling sequence");
0N/A } else {
0N/A for (int i = begin_out_arg_area; i < out_arg_limit_per_call; i++)
0N/A proj->_rout.Insert(OptoReg::Name(i));
0N/A }
0N/A if( proj->_rout.is_NotEmpty() )
0N/A _proj_list.push(proj);
0N/A }
0N/A // Transfer the safepoint information from the call to the mcall
0N/A // Move the JVMState list
0N/A msfpt->set_jvms(sfpt->jvms());
0N/A for (JVMState* jvms = msfpt->jvms(); jvms; jvms = jvms->caller()) {
0N/A jvms->set_map(sfpt);
0N/A }
0N/A
0N/A // Debug inputs begin just after the last incoming parameter
0N/A assert( (mcall == NULL) || (mcall->jvms() == NULL) ||
0N/A (mcall->jvms()->debug_start() + mcall->_jvmadj == mcall->tf()->domain()->cnt()), "" );
0N/A
0N/A // Move the OopMap
0N/A msfpt->_oop_map = sfpt->_oop_map;
0N/A
0N/A // Registers killed by the call are set in the local scheduling pass
0N/A // of Global Code Motion.
0N/A return msfpt;
0N/A}
0N/A
0N/A//---------------------------match_tree----------------------------------------
0N/A// Match a Ideal Node DAG - turn it into a tree; Label & Reduce. Used as part
0N/A// of the whole-sale conversion from Ideal to Mach Nodes. Also used for
0N/A// making GotoNodes while building the CFG and in init_spill_mask() to identify
0N/A// a Load's result RegMask for memoization in idealreg2regmask[]
0N/AMachNode *Matcher::match_tree( const Node *n ) {
0N/A assert( n->Opcode() != Op_Phi, "cannot match" );
0N/A assert( !n->is_block_start(), "cannot match" );
0N/A // Set the mark for all locally allocated State objects.
0N/A // When this call returns, the _states_arena arena will be reset
0N/A // freeing all State objects.
0N/A ResourceMark rm( &_states_arena );
0N/A
0N/A LabelRootDepth = 0;
0N/A
0N/A // StoreNodes require their Memory input to match any LoadNodes
0N/A Node *mem = n->is_Store() ? n->in(MemNode::Memory) : (Node*)1 ;
216N/A#ifdef ASSERT
216N/A Node* save_mem_node = _mem_node;
216N/A _mem_node = n->is_Store() ? (Node*)n : NULL;
216N/A#endif
0N/A // State object for root node of match tree
0N/A // Allocate it on _states_arena - stack allocation can cause stack overflow.
0N/A State *s = new (&_states_arena) State;
0N/A s->_kids[0] = NULL;
0N/A s->_kids[1] = NULL;
0N/A s->_leaf = (Node*)n;
0N/A // Label the input tree, allocating labels from top-level arena
0N/A Label_Root( n, s, n->in(0), mem );
0N/A if (C->failing()) return NULL;
0N/A
0N/A // The minimum cost match for the whole tree is found at the root State
0N/A uint mincost = max_juint;
0N/A uint cost = max_juint;
0N/A uint i;
0N/A for( i = 0; i < NUM_OPERANDS; i++ ) {
0N/A if( s->valid(i) && // valid entry and
0N/A s->_cost[i] < cost && // low cost and
0N/A s->_rule[i] >= NUM_OPERANDS ) // not an operand
0N/A cost = s->_cost[mincost=i];
0N/A }
0N/A if (mincost == max_juint) {
0N/A#ifndef PRODUCT
0N/A tty->print("No matching rule for:");
0N/A s->dump();
0N/A#endif
0N/A Matcher::soft_match_failure();
0N/A return NULL;
0N/A }
0N/A // Reduce input tree based upon the state labels to machine Nodes
0N/A MachNode *m = ReduceInst( s, s->_rule[mincost], mem );
0N/A#ifdef ASSERT
0N/A _old2new_map.map(n->_idx, m);
222N/A _new2old_map.map(m->_idx, (Node*)n);
0N/A#endif
0N/A
0N/A // Add any Matcher-ignored edges
0N/A uint cnt = n->req();
0N/A uint start = 1;
0N/A if( mem != (Node*)1 ) start = MemNode::Memory+1;
168N/A if( n->is_AddP() ) {
0N/A assert( mem == (Node*)1, "" );
0N/A start = AddPNode::Base+1;
0N/A }
0N/A for( i = start; i < cnt; i++ ) {
0N/A if( !n->match_edge(i) ) {
0N/A if( i < m->req() )
0N/A m->ins_req( i, n->in(i) );
0N/A else
0N/A m->add_req( n->in(i) );
0N/A }
0N/A }
0N/A
216N/A debug_only( _mem_node = save_mem_node; )
0N/A return m;
0N/A}
0N/A
0N/A
0N/A//------------------------------match_into_reg---------------------------------
0N/A// Choose to either match this Node in a register or part of the current
0N/A// match tree. Return true for requiring a register and false for matching
0N/A// as part of the current match tree.
0N/Astatic bool match_into_reg( const Node *n, Node *m, Node *control, int i, bool shared ) {
0N/A
0N/A const Type *t = m->bottom_type();
0N/A
3041N/A if (t->singleton()) {
0N/A // Never force constants into registers. Allow them to match as
0N/A // constants or registers. Copies of the same value will share
168N/A // the same register. See find_shared_node.
0N/A return false;
0N/A } else { // Not a constant
0N/A // Stop recursion if they have different Controls.
3041N/A Node* m_control = m->in(0);
3041N/A // Control of load's memory can post-dominates load's control.
3041N/A // So use it since load can't float above its memory.
3041N/A Node* mem_control = (m->is_Load()) ? m->in(MemNode::Memory)->in(0) : NULL;
3041N/A if (control && m_control && control != m_control && control != mem_control) {
0N/A
0N/A // Actually, we can live with the most conservative control we
0N/A // find, if it post-dominates the others. This allows us to
0N/A // pick up load/op/store trees where the load can float a little
0N/A // above the store.
0N/A Node *x = control;
3041N/A const uint max_scan = 6; // Arbitrary scan cutoff
0N/A uint j;
3041N/A for (j=0; j<max_scan; j++) {
3041N/A if (x->is_Region()) // Bail out at merge points
0N/A return true;
0N/A x = x->in(0);
3041N/A if (x == m_control) // Does 'control' post-dominate
0N/A break; // m->in(0)? If so, we can use it
3041N/A if (x == mem_control) // Does 'control' post-dominate
3041N/A break; // mem_control? If so, we can use it
0N/A }
3041N/A if (j == max_scan) // No post-domination before scan end?
0N/A return true; // Then break the match tree up
0N/A }
1495N/A if (m->is_DecodeN() && Matcher::narrow_oop_use_complex_address()) {
113N/A // These are commonly used in address expressions and can
168N/A // efficiently fold into them on X64 in some cases.
168N/A return false;
113N/A }
0N/A }
0N/A
605N/A // Not forceable cloning. If shared, put it into a register.
0N/A return shared;
0N/A}
0N/A
0N/A
0N/A//------------------------------Instruction Selection--------------------------
0N/A// Label method walks a "tree" of nodes, using the ADLC generated DFA to match
0N/A// ideal nodes to machine instructions. Trees are delimited by shared Nodes,
0N/A// things the Matcher does not match (e.g., Memory), and things with different
0N/A// Controls (hence forced into different blocks). We pass in the Control
0N/A// selected for this entire State tree.
0N/A
0N/A// The Matcher works on Trees, but an Intel add-to-memory requires a DAG: the
0N/A// Store and the Load must have identical Memories (as well as identical
0N/A// pointers). Since the Matcher does not have anything for Memory (and
0N/A// does not handle DAGs), I have to match the Memory input myself. If the
0N/A// Tree root is a Store, I require all Loads to have the identical memory.
0N/ANode *Matcher::Label_Root( const Node *n, State *svec, Node *control, const Node *mem){
0N/A // Since Label_Root is a recursive function, its possible that we might run
0N/A // out of stack space. See bugs 6272980 & 6227033 for more info.
0N/A LabelRootDepth++;
0N/A if (LabelRootDepth > MaxLabelRootDepth) {
0N/A C->record_method_not_compilable_all_tiers("Out of stack space, increase MaxLabelRootDepth");
0N/A return NULL;
0N/A }
0N/A uint care = 0; // Edges matcher cares about
0N/A uint cnt = n->req();
0N/A uint i = 0;
0N/A
0N/A // Examine children for memory state
0N/A // Can only subsume a child into your match-tree if that child's memory state
0N/A // is not modified along the path to another input.
0N/A // It is unsafe even if the other inputs are separate roots.
0N/A Node *input_mem = NULL;
0N/A for( i = 1; i < cnt; i++ ) {
0N/A if( !n->match_edge(i) ) continue;
0N/A Node *m = n->in(i); // Get ith input
0N/A assert( m, "expect non-null children" );
0N/A if( m->is_Load() ) {
0N/A if( input_mem == NULL ) {
0N/A input_mem = m->in(MemNode::Memory);
0N/A } else if( input_mem != m->in(MemNode::Memory) ) {
0N/A input_mem = NodeSentinel;
0N/A }
0N/A }
0N/A }
0N/A
0N/A for( i = 1; i < cnt; i++ ){// For my children
0N/A if( !n->match_edge(i) ) continue;
0N/A Node *m = n->in(i); // Get ith input
0N/A // Allocate states out of a private arena
0N/A State *s = new (&_states_arena) State;
0N/A svec->_kids[care++] = s;
0N/A assert( care <= 2, "binary only for now" );
0N/A
0N/A // Recursively label the State tree.
0N/A s->_kids[0] = NULL;
0N/A s->_kids[1] = NULL;
0N/A s->_leaf = m;
0N/A
0N/A // Check for leaves of the State Tree; things that cannot be a part of
0N/A // the current tree. If it finds any, that value is matched as a
0N/A // register operand. If not, then the normal matching is used.
0N/A if( match_into_reg(n, m, control, i, is_shared(m)) ||
0N/A //
0N/A // Stop recursion if this is LoadNode and the root of this tree is a
0N/A // StoreNode and the load & store have different memories.
0N/A ((mem!=(Node*)1) && m->is_Load() && m->in(MemNode::Memory) != mem) ||
0N/A // Can NOT include the match of a subtree when its memory state
0N/A // is used by any of the other subtrees
0N/A (input_mem == NodeSentinel) ) {
0N/A#ifndef PRODUCT
0N/A // Print when we exclude matching due to different memory states at input-loads
0N/A if( PrintOpto && (Verbose && WizardMode) && (input_mem == NodeSentinel)
0N/A && !((mem!=(Node*)1) && m->is_Load() && m->in(MemNode::Memory) != mem) ) {
0N/A tty->print_cr("invalid input_mem");
0N/A }
0N/A#endif
0N/A // Switch to a register-only opcode; this value must be in a register
0N/A // and cannot be subsumed as part of a larger instruction.
0N/A s->DFA( m->ideal_reg(), m );
0N/A
0N/A } else {
0N/A // If match tree has no control and we do, adopt it for entire tree
0N/A if( control == NULL && m->in(0) != NULL && m->req() > 1 )
0N/A control = m->in(0); // Pick up control
0N/A // Else match as a normal part of the match tree.
0N/A control = Label_Root(m,s,control,mem);
0N/A if (C->failing()) return NULL;
0N/A }
0N/A }
0N/A
0N/A
0N/A // Call DFA to match this node, and return
0N/A svec->DFA( n->Opcode(), n );
0N/A
0N/A#ifdef ASSERT
0N/A uint x;
0N/A for( x = 0; x < _LAST_MACH_OPER; x++ )
0N/A if( svec->valid(x) )
0N/A break;
0N/A
0N/A if (x >= _LAST_MACH_OPER) {
0N/A n->dump();
0N/A svec->dump();
0N/A assert( false, "bad AD file" );
0N/A }
0N/A#endif
0N/A return control;
0N/A}
0N/A
0N/A
0N/A// Con nodes reduced using the same rule can share their MachNode
0N/A// which reduces the number of copies of a constant in the final
0N/A// program. The register allocator is free to split uses later to
0N/A// split live ranges.
168N/AMachNode* Matcher::find_shared_node(Node* leaf, uint rule) {
168N/A if (!leaf->is_Con() && !leaf->is_DecodeN()) return NULL;
0N/A
0N/A // See if this Con has already been reduced using this rule.
168N/A if (_shared_nodes.Size() <= leaf->_idx) return NULL;
168N/A MachNode* last = (MachNode*)_shared_nodes.at(leaf->_idx);
0N/A if (last != NULL && rule == last->rule()) {
168N/A // Don't expect control change for DecodeN
168N/A if (leaf->is_DecodeN())
168N/A return last;
0N/A // Get the new space root.
0N/A Node* xroot = new_node(C->root());
0N/A if (xroot == NULL) {
0N/A // This shouldn't happen give the order of matching.
0N/A return NULL;
0N/A }
0N/A
0N/A // Shared constants need to have their control be root so they
0N/A // can be scheduled properly.
0N/A Node* control = last->in(0);
0N/A if (control != xroot) {
0N/A if (control == NULL || control == C->root()) {
0N/A last->set_req(0, xroot);
0N/A } else {
0N/A assert(false, "unexpected control");
0N/A return NULL;
0N/A }
0N/A }
0N/A return last;
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/A//------------------------------ReduceInst-------------------------------------
0N/A// Reduce a State tree (with given Control) into a tree of MachNodes.
0N/A// This routine (and it's cohort ReduceOper) convert Ideal Nodes into
0N/A// complicated machine Nodes. Each MachNode covers some tree of Ideal Nodes.
0N/A// Each MachNode has a number of complicated MachOper operands; each
0N/A// MachOper also covers a further tree of Ideal Nodes.
0N/A
0N/A// The root of the Ideal match tree is always an instruction, so we enter
0N/A// the recursion here. After building the MachNode, we need to recurse
0N/A// the tree checking for these cases:
0N/A// (1) Child is an instruction -
0N/A// Build the instruction (recursively), add it as an edge.
0N/A// Build a simple operand (register) to hold the result of the instruction.
0N/A// (2) Child is an interior part of an instruction -
0N/A// Skip over it (do nothing)
0N/A// (3) Child is the start of a operand -
0N/A// Build the operand, place it inside the instruction
0N/A// Call ReduceOper.
0N/AMachNode *Matcher::ReduceInst( State *s, int rule, Node *&mem ) {
0N/A assert( rule >= NUM_OPERANDS, "called with operand rule" );
0N/A
168N/A MachNode* shared_node = find_shared_node(s->_leaf, rule);
168N/A if (shared_node != NULL) {
168N/A return shared_node;
0N/A }
0N/A
0N/A // Build the object to represent this state & prepare for recursive calls
0N/A MachNode *mach = s->MachNodeGenerator( rule, C );
0N/A mach->_opnds[0] = s->MachOperGenerator( _reduceOp[rule], C );
0N/A assert( mach->_opnds[0] != NULL, "Missing result operand" );
0N/A Node *leaf = s->_leaf;
0N/A // Check for instruction or instruction chain rule
0N/A if( rule >= _END_INST_CHAIN_RULE || rule < _BEGIN_INST_CHAIN_RULE ) {
309N/A assert(C->node_arena()->contains(s->_leaf) || !has_new_node(s->_leaf),
309N/A "duplicating node that's already been matched");
0N/A // Instruction
0N/A mach->add_req( leaf->in(0) ); // Set initial control
0N/A // Reduce interior of complex instruction
0N/A ReduceInst_Interior( s, rule, mem, mach, 1 );
0N/A } else {
0N/A // Instruction chain rules are data-dependent on their inputs
0N/A mach->add_req(0); // Set initial control to none
0N/A ReduceInst_Chain_Rule( s, rule, mem, mach );
0N/A }
0N/A
0N/A // If a Memory was used, insert a Memory edge
216N/A if( mem != (Node*)1 ) {
0N/A mach->ins_req(MemNode::Memory,mem);
216N/A#ifdef ASSERT
216N/A // Verify adr type after matching memory operation
216N/A const MachOper* oper = mach->memory_operand();
851N/A if (oper != NULL && oper != (MachOper*)-1) {
216N/A // It has a unique memory operand. Find corresponding ideal mem node.
216N/A Node* m = NULL;
216N/A if (leaf->is_Mem()) {
216N/A m = leaf;
216N/A } else {
216N/A m = _mem_node;
216N/A assert(m != NULL && m->is_Mem(), "expecting memory node");
216N/A }
368N/A const Type* mach_at = mach->adr_type();
368N/A // DecodeN node consumed by an address may have different type
368N/A // then its input. Don't compare types for such case.
642N/A if (m->adr_type() != mach_at &&
642N/A (m->in(MemNode::Address)->is_DecodeN() ||
642N/A m->in(MemNode::Address)->is_AddP() &&
642N/A m->in(MemNode::Address)->in(AddPNode::Address)->is_DecodeN() ||
642N/A m->in(MemNode::Address)->is_AddP() &&
642N/A m->in(MemNode::Address)->in(AddPNode::Address)->is_AddP() &&
642N/A m->in(MemNode::Address)->in(AddPNode::Address)->in(AddPNode::Address)->is_DecodeN())) {
368N/A mach_at = m->adr_type();
368N/A }
368N/A if (m->adr_type() != mach_at) {
216N/A m->dump();
216N/A tty->print_cr("mach:");
216N/A mach->dump(1);
216N/A }
368N/A assert(m->adr_type() == mach_at, "matcher should not change adr type");
216N/A }
216N/A#endif
216N/A }
0N/A
0N/A // If the _leaf is an AddP, insert the base edge
168N/A if( leaf->is_AddP() )
0N/A mach->ins_req(AddPNode::Base,leaf->in(AddPNode::Base));
0N/A
0N/A uint num_proj = _proj_list.size();
0N/A
0N/A // Perform any 1-to-many expansions required
1203N/A MachNode *ex = mach->Expand(s,_proj_list, mem);
0N/A if( ex != mach ) {
0N/A assert(ex->ideal_reg() == mach->ideal_reg(), "ideal types should match");
0N/A if( ex->in(1)->is_Con() )
0N/A ex->in(1)->set_req(0, C->root());
0N/A // Remove old node from the graph
0N/A for( uint i=0; i<mach->req(); i++ ) {
0N/A mach->set_req(i,NULL);
0N/A }
222N/A#ifdef ASSERT
222N/A _new2old_map.map(ex->_idx, s->_leaf);
222N/A#endif
0N/A }
0N/A
0N/A // PhaseChaitin::fixup_spills will sometimes generate spill code
0N/A // via the matcher. By the time, nodes have been wired into the CFG,
0N/A // and any further nodes generated by expand rules will be left hanging
0N/A // in space, and will not get emitted as output code. Catch this.
0N/A // Also, catch any new register allocation constraints ("projections")
0N/A // generated belatedly during spill code generation.
0N/A if (_allocation_started) {
0N/A guarantee(ex == mach, "no expand rules during spill generation");
0N/A guarantee(_proj_list.size() == num_proj, "no allocation during spill generation");
0N/A }
0N/A
168N/A if (leaf->is_Con() || leaf->is_DecodeN()) {
0N/A // Record the con for sharing
168N/A _shared_nodes.map(leaf->_idx, ex);
0N/A }
0N/A
0N/A return ex;
0N/A}
0N/A
0N/Avoid Matcher::ReduceInst_Chain_Rule( State *s, int rule, Node *&mem, MachNode *mach ) {
0N/A // 'op' is what I am expecting to receive
0N/A int op = _leftOp[rule];
0N/A // Operand type to catch childs result
0N/A // This is what my child will give me.
0N/A int opnd_class_instance = s->_rule[op];
0N/A // Choose between operand class or not.
605N/A // This is what I will receive.
0N/A int catch_op = (FIRST_OPERAND_CLASS <= op && op < NUM_OPERANDS) ? opnd_class_instance : op;
0N/A // New rule for child. Chase operand classes to get the actual rule.
0N/A int newrule = s->_rule[catch_op];
0N/A
0N/A if( newrule < NUM_OPERANDS ) {
0N/A // Chain from operand or operand class, may be output of shared node
0N/A assert( 0 <= opnd_class_instance && opnd_class_instance < NUM_OPERANDS,
0N/A "Bad AD file: Instruction chain rule must chain from operand");
0N/A // Insert operand into array of operands for this instruction
0N/A mach->_opnds[1] = s->MachOperGenerator( opnd_class_instance, C );
0N/A
0N/A ReduceOper( s, newrule, mem, mach );
0N/A } else {
0N/A // Chain from the result of an instruction
0N/A assert( newrule >= _LAST_MACH_OPER, "Do NOT chain from internal operand");
0N/A mach->_opnds[1] = s->MachOperGenerator( _reduceOp[catch_op], C );
0N/A Node *mem1 = (Node*)1;
216N/A debug_only(Node *save_mem_node = _mem_node;)
0N/A mach->add_req( ReduceInst(s, newrule, mem1) );
216N/A debug_only(_mem_node = save_mem_node;)
0N/A }
0N/A return;
0N/A}
0N/A
0N/A
0N/Auint Matcher::ReduceInst_Interior( State *s, int rule, Node *&mem, MachNode *mach, uint num_opnds ) {
0N/A if( s->_leaf->is_Load() ) {
0N/A Node *mem2 = s->_leaf->in(MemNode::Memory);
0N/A assert( mem == (Node*)1 || mem == mem2, "multiple Memories being matched at once?" );
216N/A debug_only( if( mem == (Node*)1 ) _mem_node = s->_leaf;)
0N/A mem = mem2;
0N/A }
0N/A if( s->_leaf->in(0) != NULL && s->_leaf->req() > 1) {
0N/A if( mach->in(0) == NULL )
0N/A mach->set_req(0, s->_leaf->in(0));
0N/A }
0N/A
0N/A // Now recursively walk the state tree & add operand list.
0N/A for( uint i=0; i<2; i++ ) { // binary tree
0N/A State *newstate = s->_kids[i];
0N/A if( newstate == NULL ) break; // Might only have 1 child
0N/A // 'op' is what I am expecting to receive
0N/A int op;
0N/A if( i == 0 ) {
0N/A op = _leftOp[rule];
0N/A } else {
0N/A op = _rightOp[rule];
0N/A }
0N/A // Operand type to catch childs result
0N/A // This is what my child will give me.
0N/A int opnd_class_instance = newstate->_rule[op];
0N/A // Choose between operand class or not.
0N/A // This is what I will receive.
0N/A int catch_op = (op >= FIRST_OPERAND_CLASS && op < NUM_OPERANDS) ? opnd_class_instance : op;
0N/A // New rule for child. Chase operand classes to get the actual rule.
0N/A int newrule = newstate->_rule[catch_op];
0N/A
0N/A if( newrule < NUM_OPERANDS ) { // Operand/operandClass or internalOp/instruction?
0N/A // Operand/operandClass
0N/A // Insert operand into array of operands for this instruction
0N/A mach->_opnds[num_opnds++] = newstate->MachOperGenerator( opnd_class_instance, C );
0N/A ReduceOper( newstate, newrule, mem, mach );
0N/A
0N/A } else { // Child is internal operand or new instruction
0N/A if( newrule < _LAST_MACH_OPER ) { // internal operand or instruction?
0N/A // internal operand --> call ReduceInst_Interior
0N/A // Interior of complex instruction. Do nothing but recurse.
0N/A num_opnds = ReduceInst_Interior( newstate, newrule, mem, mach, num_opnds );
0N/A } else {
0N/A // instruction --> call build operand( ) to catch result
0N/A // --> ReduceInst( newrule )
0N/A mach->_opnds[num_opnds++] = s->MachOperGenerator( _reduceOp[catch_op], C );
0N/A Node *mem1 = (Node*)1;
216N/A debug_only(Node *save_mem_node = _mem_node;)
0N/A mach->add_req( ReduceInst( newstate, newrule, mem1 ) );
216N/A debug_only(_mem_node = save_mem_node;)
0N/A }
0N/A }
0N/A assert( mach->_opnds[num_opnds-1], "" );
0N/A }
0N/A return num_opnds;
0N/A}
0N/A
0N/A// This routine walks the interior of possible complex operands.
0N/A// At each point we check our children in the match tree:
0N/A// (1) No children -
0N/A// We are a leaf; add _leaf field as an input to the MachNode
0N/A// (2) Child is an internal operand -
0N/A// Skip over it ( do nothing )
0N/A// (3) Child is an instruction -
0N/A// Call ReduceInst recursively and
0N/A// and instruction as an input to the MachNode
0N/Avoid Matcher::ReduceOper( State *s, int rule, Node *&mem, MachNode *mach ) {
0N/A assert( rule < _LAST_MACH_OPER, "called with operand rule" );
0N/A State *kid = s->_kids[0];
0N/A assert( kid == NULL || s->_leaf->in(0) == NULL, "internal operands have no control" );
0N/A
0N/A // Leaf? And not subsumed?
0N/A if( kid == NULL && !_swallowed[rule] ) {
0N/A mach->add_req( s->_leaf ); // Add leaf pointer
0N/A return; // Bail out
0N/A }
0N/A
0N/A if( s->_leaf->is_Load() ) {
0N/A assert( mem == (Node*)1, "multiple Memories being matched at once?" );
0N/A mem = s->_leaf->in(MemNode::Memory);
216N/A debug_only(_mem_node = s->_leaf;)
0N/A }
0N/A if( s->_leaf->in(0) && s->_leaf->req() > 1) {
0N/A if( !mach->in(0) )
0N/A mach->set_req(0,s->_leaf->in(0));
0N/A else {
0N/A assert( s->_leaf->in(0) == mach->in(0), "same instruction, differing controls?" );
0N/A }
0N/A }
0N/A
0N/A for( uint i=0; kid != NULL && i<2; kid = s->_kids[1], i++ ) { // binary tree
0N/A int newrule;
4141N/A if( i == 0)
0N/A newrule = kid->_rule[_leftOp[rule]];
0N/A else
0N/A newrule = kid->_rule[_rightOp[rule]];
0N/A
0N/A if( newrule < _LAST_MACH_OPER ) { // Operand or instruction?
0N/A // Internal operand; recurse but do nothing else
0N/A ReduceOper( kid, newrule, mem, mach );
0N/A
0N/A } else { // Child is a new instruction
0N/A // Reduce the instruction, and add a direct pointer from this
0N/A // machine instruction to the newly reduced one.
0N/A Node *mem1 = (Node*)1;
216N/A debug_only(Node *save_mem_node = _mem_node;)
0N/A mach->add_req( ReduceInst( kid, newrule, mem1 ) );
216N/A debug_only(_mem_node = save_mem_node;)
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/A// -------------------------------------------------------------------------
0N/A// Java-Java calling convention
0N/A// (what you use when Java calls Java)
0N/A
0N/A//------------------------------find_receiver----------------------------------
0N/A// For a given signature, return the OptoReg for parameter 0.
0N/AOptoReg::Name Matcher::find_receiver( bool is_outgoing ) {
0N/A VMRegPair regs;
0N/A BasicType sig_bt = T_OBJECT;
0N/A calling_convention(&sig_bt, &regs, 1, is_outgoing);
0N/A // Return argument 0 register. In the LP64 build pointers
0N/A // take 2 registers, but the VM wants only the 'main' name.
0N/A return OptoReg::as_OptoReg(regs.first());
0N/A}
0N/A
0N/A// A method-klass-holder may be passed in the inline_cache_reg
0N/A// and then expanded into the inline_cache_reg and a method_oop register
0N/A// defined in ad_<arch>.cpp
0N/A
0N/A
0N/A//------------------------------find_shared------------------------------------
0N/A// Set bits if Node is shared or otherwise a root
0N/Avoid Matcher::find_shared( Node *n ) {
0N/A // Allocate stack of size C->unique() * 2 to avoid frequent realloc
0N/A MStack mstack(C->unique() * 2);
586N/A // Mark nodes as address_visited if they are inputs to an address expression
586N/A VectorSet address_visited(Thread::current()->resource_area());
0N/A mstack.push(n, Visit); // Don't need to pre-visit root node
0N/A while (mstack.is_nonempty()) {
0N/A n = mstack.node(); // Leave node on stack
0N/A Node_State nstate = mstack.state();
586N/A uint nop = n->Opcode();
0N/A if (nstate == Pre_Visit) {
586N/A if (address_visited.test(n->_idx)) { // Visited in address already?
586N/A // Flag as visited and shared now.
586N/A set_visited(n);
586N/A }
0N/A if (is_visited(n)) { // Visited already?
0N/A // Node is shared and has no reason to clone. Flag it as shared.
0N/A // This causes it to match into a register for the sharing.
0N/A set_shared(n); // Flag as shared and
0N/A mstack.pop(); // remove node from stack
0N/A continue;
0N/A }
0N/A nstate = Visit; // Not already visited; so visit now
0N/A }
0N/A if (nstate == Visit) {
0N/A mstack.set_state(Post_Visit);
0N/A set_visited(n); // Flag as visited now
0N/A bool mem_op = false;
0N/A
586N/A switch( nop ) { // Handle some opcodes special
0N/A case Op_Phi: // Treat Phis as shared roots
0N/A case Op_Parm:
0N/A case Op_Proj: // All handled specially during matching
63N/A case Op_SafePointScalarObject:
0N/A set_shared(n);
0N/A set_dontcare(n);
0N/A break;
0N/A case Op_If:
0N/A case Op_CountedLoopEnd:
0N/A mstack.set_state(Alt_Post_Visit); // Alternative way
0N/A // Convert (If (Bool (CmpX A B))) into (If (Bool) (CmpX A B)). Helps
0N/A // with matching cmp/branch in 1 instruction. The Matcher needs the
0N/A // Bool and CmpX side-by-side, because it can only get at constants
0N/A // that are at the leaves of Match trees, and the Bool's condition acts
0N/A // as a constant here.
0N/A mstack.push(n->in(1), Visit); // Clone the Bool
0N/A mstack.push(n->in(0), Pre_Visit); // Visit control input
0N/A continue; // while (mstack.is_nonempty())
0N/A case Op_ConvI2D: // These forms efficiently match with a prior
0N/A case Op_ConvI2F: // Load but not a following Store
0N/A if( n->in(1)->is_Load() && // Prior load
0N/A n->outcnt() == 1 && // Not already shared
0N/A n->unique_out()->is_Store() ) // Following store
0N/A set_shared(n); // Force it to be a root
0N/A break;
0N/A case Op_ReverseBytesI:
0N/A case Op_ReverseBytesL:
0N/A if( n->in(1)->is_Load() && // Prior load
0N/A n->outcnt() == 1 ) // Not already shared
0N/A set_shared(n); // Force it to be a root
0N/A break;
0N/A case Op_BoxLock: // Cant match until we get stack-regs in ADLC
0N/A case Op_IfFalse:
0N/A case Op_IfTrue:
0N/A case Op_MachProj:
0N/A case Op_MergeMem:
0N/A case Op_Catch:
0N/A case Op_CatchProj:
0N/A case Op_CProj:
0N/A case Op_JumpProj:
0N/A case Op_JProj:
0N/A case Op_NeverBranch:
0N/A set_dontcare(n);
0N/A break;
0N/A case Op_Jump:
2902N/A mstack.push(n->in(1), Pre_Visit); // Switch Value (could be shared)
0N/A mstack.push(n->in(0), Pre_Visit); // Visit Control input
0N/A continue; // while (mstack.is_nonempty())
0N/A case Op_StrComp:
681N/A case Op_StrEquals:
681N/A case Op_StrIndexOf:
169N/A case Op_AryEq:
0N/A set_shared(n); // Force result into register (it will be anyways)
0N/A break;
0N/A case Op_ConP: { // Convert pointers above the centerline to NUL
0N/A TypeNode *tn = n->as_Type(); // Constants derive from type nodes
0N/A const TypePtr* tp = tn->type()->is_ptr();
0N/A if (tp->_ptr == TypePtr::AnyNull) {
0N/A tn->set_type(TypePtr::NULL_PTR);
0N/A }
0N/A break;
0N/A }
163N/A case Op_ConN: { // Convert narrow pointers above the centerline to NUL
163N/A TypeNode *tn = n->as_Type(); // Constants derive from type nodes
221N/A const TypePtr* tp = tn->type()->make_ptr();
221N/A if (tp && tp->_ptr == TypePtr::AnyNull) {
163N/A tn->set_type(TypeNarrowOop::NULL_PTR);
163N/A }
163N/A break;
163N/A }
0N/A case Op_Binary: // These are introduced in the Post_Visit state.
0N/A ShouldNotReachHere();
0N/A break;
0N/A case Op_ClearArray:
0N/A case Op_SafePoint:
0N/A mem_op = true;
0N/A break;
1061N/A default:
1061N/A if( n->is_Store() ) {
1061N/A // Do match stores, despite no ideal reg
1061N/A mem_op = true;
1061N/A break;
1061N/A }
1061N/A if( n->is_Mem() ) { // Loads and LoadStores
1061N/A mem_op = true;
1061N/A // Loads must be root of match tree due to prior load conflict
1061N/A if( C->subsume_loads() == false )
1061N/A set_shared(n);
0N/A }
0N/A // Fall into default case
0N/A if( !n->ideal_reg() )
0N/A set_dontcare(n); // Unmatchable Nodes
0N/A } // end_switch
0N/A
0N/A for(int i = n->req() - 1; i >= 0; --i) { // For my children
0N/A Node *m = n->in(i); // Get ith input
0N/A if (m == NULL) continue; // Ignore NULLs
0N/A uint mop = m->Opcode();
0N/A
0N/A // Must clone all producers of flags, or we will not match correctly.
0N/A // Suppose a compare setting int-flags is shared (e.g., a switch-tree)
0N/A // then it will match into an ideal Op_RegFlags. Alas, the fp-flags
0N/A // are also there, so we may match a float-branch to int-flags and
0N/A // expect the allocator to haul the flags from the int-side to the
0N/A // fp-side. No can do.
0N/A if( _must_clone[mop] ) {
0N/A mstack.push(m, Visit);
0N/A continue; // for(int i = ...)
0N/A }
0N/A
1061N/A if( mop == Op_AddP && m->in(AddPNode::Base)->Opcode() == Op_DecodeN ) {
1061N/A // Bases used in addresses must be shared but since
1061N/A // they are shared through a DecodeN they may appear
1061N/A // to have a single use so force sharing here.
1061N/A set_shared(m->in(AddPNode::Base)->in(1));
1061N/A }
1061N/A
1061N/A // Clone addressing expressions as they are "free" in memory access instructions
0N/A if( mem_op && i == MemNode::Address && mop == Op_AddP ) {
586N/A // Some inputs for address expression are not put on stack
586N/A // to avoid marking them as shared and forcing them into register
586N/A // if they are used only in address expressions.
586N/A // But they should be marked as shared if there are other uses
586N/A // besides address expressions.
586N/A
0N/A Node *off = m->in(AddPNode::Offset);
586N/A if( off->is_Con() &&
586N/A // When there are other uses besides address expressions
586N/A // put it on stack and mark as shared.
586N/A !is_visited(m) ) {
586N/A address_visited.test_set(m->_idx); // Flag as address_visited
0N/A Node *adr = m->in(AddPNode::Address);
0N/A
0N/A // Intel, ARM and friends can handle 2 adds in addressing mode
168N/A if( clone_shift_expressions && adr->is_AddP() &&
0N/A // AtomicAdd is not an addressing expression.
0N/A // Cheap to find it by looking for screwy base.
586N/A !adr->in(AddPNode::Base)->is_top() &&
586N/A // Are there other uses besides address expressions?
586N/A !is_visited(adr) ) {
586N/A address_visited.set(adr->_idx); // Flag as address_visited
0N/A Node *shift = adr->in(AddPNode::Offset);
0N/A // Check for shift by small constant as well
0N/A if( shift->Opcode() == Op_LShiftX && shift->in(2)->is_Con() &&
586N/A shift->in(2)->get_int() <= 3 &&
586N/A // Are there other uses besides address expressions?
586N/A !is_visited(shift) ) {
586N/A address_visited.set(shift->_idx); // Flag as address_visited
0N/A mstack.push(shift->in(2), Visit);
586N/A Node *conv = shift->in(1);
0N/A#ifdef _LP64
0N/A // Allow Matcher to match the rule which bypass
0N/A // ConvI2L operation for an array index on LP64
0N/A // if the index value is positive.
586N/A if( conv->Opcode() == Op_ConvI2L &&
586N/A conv->as_Type()->type()->is_long()->_lo >= 0 &&
586N/A // Are there other uses besides address expressions?
586N/A !is_visited(conv) ) {
586N/A address_visited.set(conv->_idx); // Flag as address_visited
586N/A mstack.push(conv->in(1), Pre_Visit);
0N/A } else
0N/A#endif
586N/A mstack.push(conv, Pre_Visit);
0N/A } else {
0N/A mstack.push(shift, Pre_Visit);
0N/A }
0N/A mstack.push(adr->in(AddPNode::Address), Pre_Visit);
0N/A mstack.push(adr->in(AddPNode::Base), Pre_Visit);
0N/A } else { // Sparc, Alpha, PPC and friends
0N/A mstack.push(adr, Pre_Visit);
0N/A }
0N/A
0N/A // Clone X+offset as it also folds into most addressing expressions
0N/A mstack.push(off, Visit);
0N/A mstack.push(m->in(AddPNode::Base), Pre_Visit);
0N/A continue; // for(int i = ...)
0N/A } // if( off->is_Con() )
0N/A } // if( mem_op &&
0N/A mstack.push(m, Pre_Visit);
0N/A } // for(int i = ...)
0N/A }
0N/A else if (nstate == Alt_Post_Visit) {
0N/A mstack.pop(); // Remove node from stack
0N/A // We cannot remove the Cmp input from the Bool here, as the Bool may be
0N/A // shared and all users of the Bool need to move the Cmp in parallel.
0N/A // This leaves both the Bool and the If pointing at the Cmp. To
0N/A // prevent the Matcher from trying to Match the Cmp along both paths
0N/A // BoolNode::match_edge always returns a zero.
0N/A
0N/A // We reorder the Op_If in a pre-order manner, so we can visit without
605N/A // accidentally sharing the Cmp (the Bool and the If make 2 users).
0N/A n->add_req( n->in(1)->in(1) ); // Add the Cmp next to the Bool
0N/A }
0N/A else if (nstate == Post_Visit) {
0N/A mstack.pop(); // Remove node from stack
0N/A
0N/A // Now hack a few special opcodes
0N/A switch( n->Opcode() ) { // Handle some opcodes special
0N/A case Op_StorePConditional:
420N/A case Op_StoreIConditional:
0N/A case Op_StoreLConditional:
0N/A case Op_CompareAndSwapI:
0N/A case Op_CompareAndSwapL:
113N/A case Op_CompareAndSwapP:
113N/A case Op_CompareAndSwapN: { // Convert trinary to binary-tree
0N/A Node *newval = n->in(MemNode::ValueIn );
4015N/A Node *oldval = n->in(LoadStoreConditionalNode::ExpectedIn);
4022N/A Node *pair = new (C) BinaryNode( oldval, newval );
0N/A n->set_req(MemNode::ValueIn,pair);
4015N/A n->del_req(LoadStoreConditionalNode::ExpectedIn);
0N/A break;
0N/A }
0N/A case Op_CMoveD: // Convert trinary to binary-tree
0N/A case Op_CMoveF:
0N/A case Op_CMoveI:
0N/A case Op_CMoveL:
164N/A case Op_CMoveN:
0N/A case Op_CMoveP: {
0N/A // Restructure into a binary tree for Matching. It's possible that
0N/A // we could move this code up next to the graph reshaping for IfNodes
0N/A // or vice-versa, but I do not want to debug this for Ladybird.
0N/A // 10/2/2000 CNC.
4022N/A Node *pair1 = new (C) BinaryNode(n->in(1),n->in(1)->in(1));
0N/A n->set_req(1,pair1);
4022N/A Node *pair2 = new (C) BinaryNode(n->in(2),n->in(3));
0N/A n->set_req(2,pair2);
0N/A n->del_req(3);
0N/A break;
0N/A }
2442N/A case Op_LoopLimit: {
4022N/A Node *pair1 = new (C) BinaryNode(n->in(1),n->in(2));
2442N/A n->set_req(1,pair1);
2442N/A n->set_req(2,n->in(3));
2442N/A n->del_req(3);
2442N/A break;
2442N/A }
986N/A case Op_StrEquals: {
4022N/A Node *pair1 = new (C) BinaryNode(n->in(2),n->in(3));
986N/A n->set_req(2,pair1);
986N/A n->set_req(3,n->in(4));
986N/A n->del_req(4);
986N/A break;
986N/A }
986N/A case Op_StrComp:
986N/A case Op_StrIndexOf: {
4022N/A Node *pair1 = new (C) BinaryNode(n->in(2),n->in(3));
986N/A n->set_req(2,pair1);
4022N/A Node *pair2 = new (C) BinaryNode(n->in(4),n->in(5));
986N/A n->set_req(3,pair2);
986N/A n->del_req(5);
986N/A n->del_req(4);
986N/A break;
986N/A }
0N/A default:
0N/A break;
0N/A }
0N/A }
0N/A else {
0N/A ShouldNotReachHere();
0N/A }
0N/A } // end of while (mstack.is_nonempty())
0N/A}
0N/A
0N/A#ifdef ASSERT
0N/A// machine-independent root to machine-dependent root
0N/Avoid Matcher::dump_old2new_map() {
0N/A _old2new_map.dump();
0N/A}
0N/A#endif
0N/A
0N/A//---------------------------collect_null_checks-------------------------------
0N/A// Find null checks in the ideal graph; write a machine-specific node for
0N/A// it. Used by later implicit-null-check handling. Actually collects
0N/A// either an IfTrue or IfFalse for the common NOT-null path, AND the ideal
0N/A// value being tested.
368N/Avoid Matcher::collect_null_checks( Node *proj, Node *orig_proj ) {
0N/A Node *iff = proj->in(0);
0N/A if( iff->Opcode() == Op_If ) {
0N/A // During matching If's have Bool & Cmp side-by-side
0N/A BoolNode *b = iff->in(1)->as_Bool();
0N/A Node *cmp = iff->in(2);
113N/A int opc = cmp->Opcode();
113N/A if (opc != Op_CmpP && opc != Op_CmpN) return;
113N/A
113N/A const Type* ct = cmp->in(2)->bottom_type();
113N/A if (ct == TypePtr::NULL_PTR ||
113N/A (opc == Op_CmpN && ct == TypeNarrowOop::NULL_PTR)) {
0N/A
368N/A bool push_it = false;
113N/A if( proj->Opcode() == Op_IfTrue ) {
113N/A extern int all_null_checks_found;
113N/A all_null_checks_found++;
113N/A if( b->_test._test == BoolTest::ne ) {
368N/A push_it = true;
113N/A }
113N/A } else {
113N/A assert( proj->Opcode() == Op_IfFalse, "" );
113N/A if( b->_test._test == BoolTest::eq ) {
368N/A push_it = true;
0N/A }
0N/A }
368N/A if( push_it ) {
368N/A _null_check_tests.push(proj);
368N/A Node* val = cmp->in(1);
368N/A#ifdef _LP64
1495N/A if (val->bottom_type()->isa_narrowoop() &&
1495N/A !Matcher::narrow_oop_use_complex_address()) {
368N/A //
368N/A // Look for DecodeN node which should be pinned to orig_proj.
368N/A // On platforms (Sparc) which can not handle 2 adds
368N/A // in addressing mode we have to keep a DecodeN node and
368N/A // use it to do implicit NULL check in address.
368N/A //
368N/A // DecodeN node was pinned to non-null path (orig_proj) during
368N/A // CastPP transformation in final_graph_reshaping_impl().
368N/A //
368N/A uint cnt = orig_proj->outcnt();
368N/A for (uint i = 0; i < orig_proj->outcnt(); i++) {
368N/A Node* d = orig_proj->raw_out(i);
368N/A if (d->is_DecodeN() && d->in(1) == val) {
368N/A val = d;
368N/A val->set_req(0, NULL); // Unpin now.
1495N/A // Mark this as special case to distinguish from
1495N/A // a regular case: CmpP(DecodeN, NULL).
1495N/A val = (Node*)(((intptr_t)val) | 1);
368N/A break;
368N/A }
368N/A }
368N/A }
368N/A#endif
368N/A _null_check_tests.push(val);
368N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/A//---------------------------validate_null_checks------------------------------
0N/A// Its possible that the value being NULL checked is not the root of a match
0N/A// tree. If so, I cannot use the value in an implicit null check.
0N/Avoid Matcher::validate_null_checks( ) {
0N/A uint cnt = _null_check_tests.size();
0N/A for( uint i=0; i < cnt; i+=2 ) {
0N/A Node *test = _null_check_tests[i];
0N/A Node *val = _null_check_tests[i+1];
1495N/A bool is_decoden = ((intptr_t)val) & 1;
1495N/A val = (Node*)(((intptr_t)val) & ~1);
0N/A if (has_new_node(val)) {
1495N/A Node* new_val = new_node(val);
1495N/A if (is_decoden) {
1495N/A assert(val->is_DecodeN() && val->in(0) == NULL, "sanity");
1495N/A // Note: new_val may have a control edge if
1495N/A // the original ideal node DecodeN was matched before
1495N/A // it was unpinned in Matcher::collect_null_checks().
1495N/A // Unpin the mach node and mark it.
1495N/A new_val->set_req(0, NULL);
1495N/A new_val = (Node*)(((intptr_t)new_val) | 1);
1495N/A }
0N/A // Is a match-tree root, so replace with the matched value
1495N/A _null_check_tests.map(i+1, new_val);
0N/A } else {
0N/A // Yank from candidate list
0N/A _null_check_tests.map(i+1,_null_check_tests[--cnt]);
0N/A _null_check_tests.map(i,_null_check_tests[--cnt]);
0N/A _null_check_tests.pop();
0N/A _null_check_tests.pop();
0N/A i-=2;
0N/A }
0N/A }
0N/A}
0N/A
0N/A// Used by the DFA in dfa_xxx.cpp. Check for a following barrier or
0N/A// atomic instruction acting as a store_load barrier without any
0N/A// intervening volatile load, and thus we don't need a barrier here.
0N/A// We retain the Node to act as a compiler ordering barrier.
0N/Abool Matcher::post_store_load_barrier(const Node *vmb) {
0N/A Compile *C = Compile::current();
0N/A assert( vmb->is_MemBar(), "" );
0N/A assert( vmb->Opcode() != Op_MemBarAcquire, "" );
0N/A const MemBarNode *mem = (const MemBarNode*)vmb;
0N/A
0N/A // Get the Proj node, ctrl, that can be used to iterate forward
0N/A Node *ctrl = NULL;
0N/A DUIterator_Fast imax, i = mem->fast_outs(imax);
0N/A while( true ) {
0N/A ctrl = mem->fast_out(i); // Throw out-of-bounds if proj not found
0N/A assert( ctrl->is_Proj(), "only projections here" );
0N/A ProjNode *proj = (ProjNode*)ctrl;
0N/A if( proj->_con == TypeFunc::Control &&
0N/A !C->node_arena()->contains(ctrl) ) // Unmatched old-space only
0N/A break;
0N/A i++;
0N/A }
0N/A
0N/A for( DUIterator_Fast jmax, j = ctrl->fast_outs(jmax); j < jmax; j++ ) {
0N/A Node *x = ctrl->fast_out(j);
0N/A int xop = x->Opcode();
0N/A
0N/A // We don't need current barrier if we see another or a lock
0N/A // before seeing volatile load.
0N/A //
0N/A // Op_Fastunlock previously appeared in the Op_* list below.
0N/A // With the advent of 1-0 lock operations we're no longer guaranteed
0N/A // that a monitor exit operation contains a serializing instruction.
0N/A
0N/A if (xop == Op_MemBarVolatile ||
0N/A xop == Op_FastLock ||
0N/A xop == Op_CompareAndSwapL ||
0N/A xop == Op_CompareAndSwapP ||
113N/A xop == Op_CompareAndSwapN ||
0N/A xop == Op_CompareAndSwapI)
0N/A return true;
0N/A
0N/A if (x->is_MemBar()) {
0N/A // We must retain this membar if there is an upcoming volatile
0N/A // load, which will be preceded by acquire membar.
0N/A if (xop == Op_MemBarAcquire)
0N/A return false;
0N/A // For other kinds of barriers, check by pretending we
0N/A // are them, and seeing if we can be removed.
0N/A else
0N/A return post_store_load_barrier((const MemBarNode*)x);
0N/A }
0N/A
0N/A // Delicate code to detect case of an upcoming fastlock block
0N/A if( x->is_If() && x->req() > 1 &&
0N/A !C->node_arena()->contains(x) ) { // Unmatched old-space only
0N/A Node *iff = x;
0N/A Node *bol = iff->in(1);
0N/A // The iff might be some random subclass of If or bol might be Con-Top
0N/A if (!bol->is_Bool()) return false;
0N/A assert( bol->req() > 1, "" );
0N/A return (bol->in(1)->Opcode() == Op_FastUnlock);
0N/A }
0N/A // probably not necessary to check for these
0N/A if (x->is_Call() || x->is_SafePoint() || x->is_block_proj())
0N/A return false;
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A//=============================================================================
0N/A//---------------------------State---------------------------------------------
0N/AState::State(void) {
0N/A#ifdef ASSERT
0N/A _id = 0;
0N/A _kids[0] = _kids[1] = (State*)(intptr_t) CONST64(0xcafebabecafebabe);
0N/A _leaf = (Node*)(intptr_t) CONST64(0xbaadf00dbaadf00d);
0N/A //memset(_cost, -1, sizeof(_cost));
0N/A //memset(_rule, -1, sizeof(_rule));
0N/A#endif
0N/A memset(_valid, 0, sizeof(_valid));
0N/A}
0N/A
0N/A#ifdef ASSERT
0N/AState::~State() {
0N/A _id = 99;
0N/A _kids[0] = _kids[1] = (State*)(intptr_t) CONST64(0xcafebabecafebabe);
0N/A _leaf = (Node*)(intptr_t) CONST64(0xbaadf00dbaadf00d);
0N/A memset(_cost, -3, sizeof(_cost));
0N/A memset(_rule, -3, sizeof(_rule));
0N/A}
0N/A#endif
0N/A
0N/A#ifndef PRODUCT
0N/A//---------------------------dump----------------------------------------------
0N/Avoid State::dump() {
0N/A tty->print("\n");
0N/A dump(0);
0N/A}
0N/A
0N/Avoid State::dump(int depth) {
0N/A for( int j = 0; j < depth; j++ )
0N/A tty->print(" ");
0N/A tty->print("--N: ");
0N/A _leaf->dump();
0N/A uint i;
0N/A for( i = 0; i < _LAST_MACH_OPER; i++ )
0N/A // Check for valid entry
0N/A if( valid(i) ) {
0N/A for( int j = 0; j < depth; j++ )
0N/A tty->print(" ");
0N/A assert(_cost[i] != max_juint, "cost must be a valid value");
0N/A assert(_rule[i] < _last_Mach_Node, "rule[i] must be valid rule");
0N/A tty->print_cr("%s %d %s",
0N/A ruleName[i], _cost[i], ruleName[_rule[i]] );
0N/A }
0N/A tty->print_cr("");
0N/A
0N/A for( i=0; i<2; i++ )
0N/A if( _kids[i] )
0N/A _kids[i]->dump(depth+1);
0N/A}
0N/A#endif