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