aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "opto/callnode.hpp" aoqi@0: #include "opto/cfgnode.hpp" aoqi@0: #include "opto/matcher.hpp" aoqi@0: #include "opto/mathexactnode.hpp" aoqi@0: #include "opto/multnode.hpp" aoqi@0: #include "opto/opcodes.hpp" aoqi@0: #include "opto/phaseX.hpp" aoqi@0: #include "opto/regmask.hpp" aoqi@0: #include "opto/type.hpp" aoqi@0: aoqi@0: //============================================================================= aoqi@0: //------------------------------MultiNode-------------------------------------- aoqi@0: const RegMask &MultiNode::out_RegMask() const { aoqi@0: return RegMask::Empty; aoqi@0: } aoqi@0: aoqi@0: Node *MultiNode::match( const ProjNode *proj, const Matcher *m ) { return proj->clone(); } aoqi@0: aoqi@0: //------------------------------proj_out--------------------------------------- aoqi@0: // Get a named projection aoqi@0: ProjNode* MultiNode::proj_out(uint which_proj) const { aoqi@0: assert(Opcode() != Op_If || which_proj == (uint)true || which_proj == (uint)false, "must be 1 or 0"); aoqi@0: assert(Opcode() != Op_If || outcnt() == 2, "bad if #1"); aoqi@0: for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) { aoqi@0: Node *p = fast_out(i); aoqi@0: if (p->is_Proj()) { aoqi@0: ProjNode *proj = p->as_Proj(); aoqi@0: if (proj->_con == which_proj) { aoqi@0: assert(Opcode() != Op_If || proj->Opcode() == (which_proj?Op_IfTrue:Op_IfFalse), "bad if #2"); aoqi@0: return proj; aoqi@0: } aoqi@0: } else { aoqi@0: assert(p == this && this->is_Start(), "else must be proj"); aoqi@0: continue; aoqi@0: } aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: //============================================================================= aoqi@0: //------------------------------ProjNode--------------------------------------- aoqi@0: uint ProjNode::hash() const { aoqi@0: // only one input aoqi@0: return (uintptr_t)in(TypeFunc::Control) + (_con << 1) + (_is_io_use ? 1 : 0); aoqi@0: } aoqi@0: uint ProjNode::cmp( const Node &n ) const { return _con == ((ProjNode&)n)._con && ((ProjNode&)n)._is_io_use == _is_io_use; } aoqi@0: uint ProjNode::size_of() const { return sizeof(ProjNode); } aoqi@0: aoqi@0: // Test if we propagate interesting control along this projection aoqi@0: bool ProjNode::is_CFG() const { aoqi@0: Node *def = in(0); aoqi@0: return (_con == TypeFunc::Control && def->is_CFG()); aoqi@0: } aoqi@0: aoqi@0: const Type* ProjNode::proj_type(const Type* t) const { aoqi@0: if (t == Type::TOP) { aoqi@0: return Type::TOP; aoqi@0: } aoqi@0: if (t == Type::BOTTOM) { aoqi@0: return Type::BOTTOM; aoqi@0: } aoqi@0: t = t->is_tuple()->field_at(_con); aoqi@0: Node* n = in(0); aoqi@0: if ((_con == TypeFunc::Parms) && aoqi@0: n->is_CallStaticJava() && n->as_CallStaticJava()->is_boxing_method()) { aoqi@0: // The result of autoboxing is always non-null on normal path. aoqi@0: t = t->join_speculative(TypePtr::NOTNULL); aoqi@0: } aoqi@0: return t; aoqi@0: } aoqi@0: aoqi@0: const Type *ProjNode::bottom_type() const { aoqi@0: if (in(0) == NULL) return Type::TOP; aoqi@0: return proj_type(in(0)->bottom_type()); aoqi@0: } aoqi@0: aoqi@0: const TypePtr *ProjNode::adr_type() const { aoqi@0: if (bottom_type() == Type::MEMORY) { aoqi@0: // in(0) might be a narrow MemBar; otherwise we will report TypePtr::BOTTOM aoqi@0: const TypePtr* adr_type = in(0)->adr_type(); aoqi@0: #ifdef ASSERT aoqi@0: if (!is_error_reported() && !Node::in_dump()) aoqi@0: assert(adr_type != NULL, "source must have adr_type"); aoqi@0: #endif aoqi@0: return adr_type; aoqi@0: } aoqi@0: assert(bottom_type()->base() != Type::Memory, "no other memories?"); aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: bool ProjNode::pinned() const { return in(0)->pinned(); } aoqi@0: #ifndef PRODUCT aoqi@0: void ProjNode::dump_spec(outputStream *st) const { st->print("#%d",_con); if(_is_io_use) st->print(" (i_o_use)");} aoqi@0: #endif aoqi@0: aoqi@0: //----------------------------check_con---------------------------------------- aoqi@0: void ProjNode::check_con() const { aoqi@0: Node* n = in(0); aoqi@0: if (n == NULL) return; // should be assert, but NodeHash makes bogons aoqi@0: if (n->is_Mach()) return; // mach. projs. are not type-safe aoqi@0: if (n->is_Start()) return; // alas, starts can have mach. projs. also aoqi@0: if (_con == SCMemProjNode::SCMEMPROJCON ) return; aoqi@0: const Type* t = n->bottom_type(); aoqi@0: if (t == Type::TOP) return; // multi is dead aoqi@0: assert(_con < t->is_tuple()->cnt(), "ProjNode::_con must be in range"); aoqi@0: } aoqi@0: aoqi@0: //------------------------------Value------------------------------------------ aoqi@0: const Type *ProjNode::Value( PhaseTransform *phase ) const { aoqi@0: if (in(0) == NULL) return Type::TOP; aoqi@0: return proj_type(phase->type(in(0))); aoqi@0: } aoqi@0: aoqi@0: //------------------------------out_RegMask------------------------------------ aoqi@0: // Pass the buck uphill aoqi@0: const RegMask &ProjNode::out_RegMask() const { aoqi@0: return RegMask::Empty; aoqi@0: } aoqi@0: aoqi@0: //------------------------------ideal_reg-------------------------------------- aoqi@0: uint ProjNode::ideal_reg() const { aoqi@0: return bottom_type()->ideal_reg(); aoqi@0: } aoqi@0: aoqi@0: //-------------------------------is_uncommon_trap_proj---------------------------- aoqi@0: // Return true if proj is the form of "proj->[region->..]call_uct" aoqi@0: bool ProjNode::is_uncommon_trap_proj(Deoptimization::DeoptReason reason) { aoqi@0: int path_limit = 10; aoqi@0: Node* out = this; aoqi@0: for (int ct = 0; ct < path_limit; ct++) { aoqi@0: out = out->unique_ctrl_out(); aoqi@0: if (out == NULL) aoqi@0: return false; aoqi@0: if (out->is_CallStaticJava()) { aoqi@0: int req = out->as_CallStaticJava()->uncommon_trap_request(); aoqi@0: if (req != 0) { aoqi@0: Deoptimization::DeoptReason trap_reason = Deoptimization::trap_request_reason(req); aoqi@0: if (trap_reason == reason || reason == Deoptimization::Reason_none) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; // don't do further after call aoqi@0: } aoqi@0: if (out->Opcode() != Op_Region) aoqi@0: return false; aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: //-------------------------------is_uncommon_trap_if_pattern------------------------- aoqi@0: // Return true for "if(test)-> proj -> ... aoqi@0: // | aoqi@0: // V aoqi@0: // other_proj->[region->..]call_uct" aoqi@0: // aoqi@0: // "must_reason_predicate" means the uct reason must be Reason_predicate aoqi@0: bool ProjNode::is_uncommon_trap_if_pattern(Deoptimization::DeoptReason reason) { aoqi@0: Node *in0 = in(0); aoqi@0: if (!in0->is_If()) return false; aoqi@0: // Variation of a dead If node. aoqi@0: if (in0->outcnt() < 2) return false; aoqi@0: IfNode* iff = in0->as_If(); aoqi@0: aoqi@0: // we need "If(Conv2B(Opaque1(...)))" pattern for reason_predicate aoqi@0: if (reason != Deoptimization::Reason_none) { aoqi@0: if (iff->in(1)->Opcode() != Op_Conv2B || aoqi@0: iff->in(1)->in(1)->Opcode() != Op_Opaque1) { aoqi@0: return false; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: ProjNode* other_proj = iff->proj_out(1-_con)->as_Proj(); aoqi@0: if (other_proj->is_uncommon_trap_proj(reason)) { aoqi@0: assert(reason == Deoptimization::Reason_none || aoqi@0: Compile::current()->is_predicate_opaq(iff->in(1)->in(1)), "should be on the list"); aoqi@0: return true; aoqi@0: } aoqi@0: return false; aoqi@0: }