0N/A/*
4449N/A * Copyright (c) 1997, 2013, 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 "classfile/systemDictionary.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "oops/objArrayKlass.hpp"
1879N/A#include "opto/addnode.hpp"
1879N/A#include "opto/cfgnode.hpp"
1879N/A#include "opto/connode.hpp"
1879N/A#include "opto/loopnode.hpp"
1879N/A#include "opto/machnode.hpp"
1879N/A#include "opto/mulnode.hpp"
1879N/A#include "opto/phaseX.hpp"
1879N/A#include "opto/regmask.hpp"
1879N/A#include "opto/runtime.hpp"
1879N/A#include "opto/subnode.hpp"
1879N/A
0N/A// Portions of code courtesy of Clifford Click
0N/A
0N/A// Optimization - Graph Style
0N/A
0N/A//=============================================================================
0N/A//------------------------------Value------------------------------------------
0N/A// Compute the type of the RegionNode.
0N/Aconst Type *RegionNode::Value( PhaseTransform *phase ) const {
0N/A for( uint i=1; i<req(); ++i ) { // For all paths in
0N/A Node *n = in(i); // Get Control source
0N/A if( !n ) continue; // Missing inputs are TOP
0N/A if( phase->type(n) == Type::CONTROL )
0N/A return Type::CONTROL;
0N/A }
0N/A return Type::TOP; // All paths dead? Then so are we
0N/A}
0N/A
0N/A//------------------------------Identity---------------------------------------
0N/A// Check for Region being Identity.
0N/ANode *RegionNode::Identity( PhaseTransform *phase ) {
0N/A // Cannot have Region be an identity, even if it has only 1 input.
0N/A // Phi users cannot have their Region input folded away for them,
0N/A // since they need to select the proper data input
0N/A return this;
0N/A}
0N/A
0N/A//------------------------------merge_region-----------------------------------
0N/A// If a Region flows into a Region, merge into one big happy merge. This is
0N/A// hard to do if there is stuff that has to happen
0N/Astatic Node *merge_region(RegionNode *region, PhaseGVN *phase) {
0N/A if( region->Opcode() != Op_Region ) // Do not do to LoopNodes
0N/A return NULL;
0N/A Node *progress = NULL; // Progress flag
0N/A PhaseIterGVN *igvn = phase->is_IterGVN();
0N/A
0N/A uint rreq = region->req();
0N/A for( uint i = 1; i < rreq; i++ ) {
0N/A Node *r = region->in(i);
0N/A if( r && r->Opcode() == Op_Region && // Found a region?
0N/A r->in(0) == r && // Not already collapsed?
0N/A r != region && // Avoid stupid situations
0N/A r->outcnt() == 2 ) { // Self user and 'region' user only?
0N/A assert(!r->as_Region()->has_phi(), "no phi users");
0N/A if( !progress ) { // No progress
0N/A if (region->has_phi()) {
0N/A return NULL; // Only flatten if no Phi users
0N/A // igvn->hash_delete( phi );
0N/A }
0N/A igvn->hash_delete( region );
0N/A progress = region; // Making progress
0N/A }
0N/A igvn->hash_delete( r );
0N/A
0N/A // Append inputs to 'r' onto 'region'
0N/A for( uint j = 1; j < r->req(); j++ ) {
0N/A // Move an input from 'r' to 'region'
0N/A region->add_req(r->in(j));
0N/A r->set_req(j, phase->C->top());
0N/A // Update phis of 'region'
0N/A //for( uint k = 0; k < max; k++ ) {
0N/A // Node *phi = region->out(k);
0N/A // if( phi->is_Phi() ) {
0N/A // phi->add_req(phi->in(i));
0N/A // }
0N/A //}
0N/A
0N/A rreq++; // One more input to Region
0N/A } // Found a region to merge into Region
0N/A // Clobber pointer to the now dead 'r'
0N/A region->set_req(i, phase->C->top());
0N/A }
0N/A }
0N/A
0N/A return progress;
0N/A}
0N/A
0N/A
0N/A
0N/A//--------------------------------has_phi--------------------------------------
0N/A// Helper function: Return any PhiNode that uses this region or NULL
0N/APhiNode* RegionNode::has_phi() const {
0N/A for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
0N/A Node* phi = fast_out(i);
0N/A if (phi->is_Phi()) { // Check for Phi users
0N/A assert(phi->in(0) == (Node*)this, "phi uses region only via in(0)");
0N/A return phi->as_Phi(); // this one is good enough
0N/A }
0N/A }
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/A//-----------------------------has_unique_phi----------------------------------
0N/A// Helper function: Return the only PhiNode that uses this region or NULL
0N/APhiNode* RegionNode::has_unique_phi() const {
0N/A // Check that only one use is a Phi
0N/A PhiNode* only_phi = NULL;
0N/A for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
0N/A Node* phi = fast_out(i);
0N/A if (phi->is_Phi()) { // Check for Phi users
0N/A assert(phi->in(0) == (Node*)this, "phi uses region only via in(0)");
0N/A if (only_phi == NULL) {
0N/A only_phi = phi->as_Phi();
0N/A } else {
0N/A return NULL; // multiple phis
0N/A }
0N/A }
0N/A }
0N/A
0N/A return only_phi;
0N/A}
0N/A
0N/A
0N/A//------------------------------check_phi_clipping-----------------------------
0N/A// Helper function for RegionNode's identification of FP clipping
0N/A// Check inputs to the Phi
0N/Astatic bool check_phi_clipping( PhiNode *phi, ConNode * &min, uint &min_idx, ConNode * &max, uint &max_idx, Node * &val, uint &val_idx ) {
0N/A min = NULL;
0N/A max = NULL;
0N/A val = NULL;
0N/A min_idx = 0;
0N/A max_idx = 0;
0N/A val_idx = 0;
0N/A uint phi_max = phi->req();
0N/A if( phi_max == 4 ) {
0N/A for( uint j = 1; j < phi_max; ++j ) {
0N/A Node *n = phi->in(j);
0N/A int opcode = n->Opcode();
0N/A switch( opcode ) {
0N/A case Op_ConI:
0N/A {
0N/A if( min == NULL ) {
0N/A min = n->Opcode() == Op_ConI ? (ConNode*)n : NULL;
0N/A min_idx = j;
0N/A } else {
0N/A max = n->Opcode() == Op_ConI ? (ConNode*)n : NULL;
0N/A max_idx = j;
0N/A if( min->get_int() > max->get_int() ) {
0N/A // Swap min and max
0N/A ConNode *temp;
0N/A uint temp_idx;
0N/A temp = min; min = max; max = temp;
0N/A temp_idx = min_idx; min_idx = max_idx; max_idx = temp_idx;
0N/A }
0N/A }
0N/A }
0N/A break;
0N/A default:
0N/A {
0N/A val = n;
0N/A val_idx = j;
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A return ( min && max && val && (min->get_int() <= 0) && (max->get_int() >=0) );
0N/A}
0N/A
0N/A
0N/A//------------------------------check_if_clipping------------------------------
0N/A// Helper function for RegionNode's identification of FP clipping
0N/A// Check that inputs to Region come from two IfNodes,
0N/A//
0N/A// If
0N/A// False True
0N/A// If |
0N/A// False True |
0N/A// | | |
0N/A// RegionNode_inputs
0N/A//
0N/Astatic bool check_if_clipping( const RegionNode *region, IfNode * &bot_if, IfNode * &top_if ) {
0N/A top_if = NULL;
0N/A bot_if = NULL;
0N/A
0N/A // Check control structure above RegionNode for (if ( if ) )
0N/A Node *in1 = region->in(1);
0N/A Node *in2 = region->in(2);
0N/A Node *in3 = region->in(3);
0N/A // Check that all inputs are projections
0N/A if( in1->is_Proj() && in2->is_Proj() && in3->is_Proj() ) {
0N/A Node *in10 = in1->in(0);
0N/A Node *in20 = in2->in(0);
0N/A Node *in30 = in3->in(0);
0N/A // Check that #1 and #2 are ifTrue and ifFalse from same If
0N/A if( in10 != NULL && in10->is_If() &&
0N/A in20 != NULL && in20->is_If() &&
0N/A in30 != NULL && in30->is_If() && in10 == in20 &&
0N/A (in1->Opcode() != in2->Opcode()) ) {
0N/A Node *in100 = in10->in(0);
0N/A Node *in1000 = (in100 != NULL && in100->is_Proj()) ? in100->in(0) : NULL;
0N/A // Check that control for in10 comes from other branch of IF from in3
0N/A if( in1000 != NULL && in1000->is_If() &&
0N/A in30 == in1000 && (in3->Opcode() != in100->Opcode()) ) {
0N/A // Control pattern checks
0N/A top_if = (IfNode*)in1000;
0N/A bot_if = (IfNode*)in10;
0N/A }
0N/A }
0N/A }
0N/A
0N/A return (top_if != NULL);
0N/A}
0N/A
0N/A
0N/A//------------------------------check_convf2i_clipping-------------------------
0N/A// Helper function for RegionNode's identification of FP clipping
0N/A// Verify that the value input to the phi comes from "ConvF2I; LShift; RShift"
0N/Astatic bool check_convf2i_clipping( PhiNode *phi, uint idx, ConvF2INode * &convf2i, Node *min, Node *max) {
0N/A convf2i = NULL;
0N/A
0N/A // Check for the RShiftNode
0N/A Node *rshift = phi->in(idx);
0N/A assert( rshift, "Previous checks ensure phi input is present");
0N/A if( rshift->Opcode() != Op_RShiftI ) { return false; }
0N/A
0N/A // Check for the LShiftNode
0N/A Node *lshift = rshift->in(1);
0N/A assert( lshift, "Previous checks ensure phi input is present");
0N/A if( lshift->Opcode() != Op_LShiftI ) { return false; }
0N/A
0N/A // Check for the ConvF2INode
0N/A Node *conv = lshift->in(1);
0N/A if( conv->Opcode() != Op_ConvF2I ) { return false; }
0N/A
0N/A // Check that shift amounts are only to get sign bits set after F2I
0N/A jint max_cutoff = max->get_int();
0N/A jint min_cutoff = min->get_int();
0N/A jint left_shift = lshift->in(2)->get_int();
0N/A jint right_shift = rshift->in(2)->get_int();
0N/A jint max_post_shift = nth_bit(BitsPerJavaInteger - left_shift - 1);
0N/A if( left_shift != right_shift ||
0N/A 0 > left_shift || left_shift >= BitsPerJavaInteger ||
0N/A max_post_shift < max_cutoff ||
0N/A max_post_shift < -min_cutoff ) {
0N/A // Shifts are necessary but current transformation eliminates them
0N/A return false;
0N/A }
0N/A
0N/A // OK to return the result of ConvF2I without shifting
0N/A convf2i = (ConvF2INode*)conv;
0N/A return true;
0N/A}
0N/A
0N/A
0N/A//------------------------------check_compare_clipping-------------------------
0N/A// Helper function for RegionNode's identification of FP clipping
0N/Astatic bool check_compare_clipping( bool less_than, IfNode *iff, ConNode *limit, Node * & input ) {
0N/A Node *i1 = iff->in(1);
0N/A if ( !i1->is_Bool() ) { return false; }
0N/A BoolNode *bool1 = i1->as_Bool();
0N/A if( less_than && bool1->_test._test != BoolTest::le ) { return false; }
0N/A else if( !less_than && bool1->_test._test != BoolTest::lt ) { return false; }
0N/A const Node *cmpF = bool1->in(1);
0N/A if( cmpF->Opcode() != Op_CmpF ) { return false; }
0N/A // Test that the float value being compared against
0N/A // is equivalent to the int value used as a limit
0N/A Node *nodef = cmpF->in(2);
0N/A if( nodef->Opcode() != Op_ConF ) { return false; }
0N/A jfloat conf = nodef->getf();
0N/A jint coni = limit->get_int();
0N/A if( ((int)conf) != coni ) { return false; }
0N/A input = cmpF->in(1);
0N/A return true;
0N/A}
0N/A
0N/A//------------------------------is_unreachable_region--------------------------
0N/A// Find if the Region node is reachable from the root.
0N/Abool RegionNode::is_unreachable_region(PhaseGVN *phase) const {
0N/A assert(req() == 2, "");
0N/A
0N/A // First, cut the simple case of fallthrough region when NONE of
0N/A // region's phis references itself directly or through a data node.
0N/A uint max = outcnt();
0N/A uint i;
0N/A for (i = 0; i < max; i++) {
0N/A Node* phi = raw_out(i);
0N/A if (phi != NULL && phi->is_Phi()) {
0N/A assert(phase->eqv(phi->in(0), this) && phi->req() == 2, "");
0N/A if (phi->outcnt() == 0)
0N/A continue; // Safe case - no loops
0N/A if (phi->outcnt() == 1) {
0N/A Node* u = phi->raw_out(0);
0N/A // Skip if only one use is an other Phi or Call or Uncommon trap.
0N/A // It is safe to consider this case as fallthrough.
0N/A if (u != NULL && (u->is_Phi() || u->is_CFG()))
0N/A continue;
0N/A }
0N/A // Check when phi references itself directly or through an other node.
0N/A if (phi->as_Phi()->simple_data_loop_check(phi->in(1)) >= PhiNode::Unsafe)
0N/A break; // Found possible unsafe data loop.
0N/A }
0N/A }
0N/A if (i >= max)
0N/A return false; // An unsafe case was NOT found - don't need graph walk.
0N/A
0N/A // Unsafe case - check if the Region node is reachable from root.
0N/A ResourceMark rm;
0N/A
0N/A Arena *a = Thread::current()->resource_area();
0N/A Node_List nstack(a);
0N/A VectorSet visited(a);
0N/A
0N/A // Mark all control nodes reachable from root outputs
0N/A Node *n = (Node*)phase->C->root();
0N/A nstack.push(n);
0N/A visited.set(n->_idx);
0N/A while (nstack.size() != 0) {
0N/A n = nstack.pop();
0N/A uint max = n->outcnt();
0N/A for (uint i = 0; i < max; i++) {
0N/A Node* m = n->raw_out(i);
0N/A if (m != NULL && m->is_CFG()) {
0N/A if (phase->eqv(m, this)) {
0N/A return false; // We reached the Region node - it is not dead.
0N/A }
0N/A if (!visited.test_set(m->_idx))
0N/A nstack.push(m);
0N/A }
0N/A }
0N/A }
0N/A
0N/A return true; // The Region node is unreachable - it is dead.
0N/A}
0N/A
4132N/Abool RegionNode::try_clean_mem_phi(PhaseGVN *phase) {
4132N/A // Incremental inlining + PhaseStringOpts sometimes produce:
4132N/A //
4132N/A // cmpP with 1 top input
4132N/A // |
4132N/A // If
4132N/A // / \
4132N/A // IfFalse IfTrue /- Some Node
4132N/A // \ / / /
4132N/A // Region / /-MergeMem
4132N/A // \---Phi
4132N/A //
4132N/A //
4132N/A // It's expected by PhaseStringOpts that the Region goes away and is
4132N/A // replaced by If's control input but because there's still a Phi,
4132N/A // the Region stays in the graph. The top input from the cmpP is
4132N/A // propagated forward and a subgraph that is useful goes away. The
4132N/A // code below replaces the Phi with the MergeMem so that the Region
4132N/A // is simplified.
4132N/A
4132N/A PhiNode* phi = has_unique_phi();
4132N/A if (phi && phi->type() == Type::MEMORY && req() == 3 && phi->is_diamond_phi(true)) {
4132N/A MergeMemNode* m = NULL;
4132N/A assert(phi->req() == 3, "same as region");
4132N/A for (uint i = 1; i < 3; ++i) {
4132N/A Node *mem = phi->in(i);
4132N/A if (mem && mem->is_MergeMem() && in(i)->outcnt() == 1) {
4132N/A // Nothing is control-dependent on path #i except the region itself.
4132N/A m = mem->as_MergeMem();
4132N/A uint j = 3 - i;
4132N/A Node* other = phi->in(j);
4132N/A if (other && other == m->base_memory()) {
4132N/A // m is a successor memory to other, and is not pinned inside the diamond, so push it out.
4132N/A // This will allow the diamond to collapse completely.
4132N/A phase->is_IterGVN()->replace_node(phi, m);
4132N/A return true;
4132N/A }
4132N/A }
4132N/A }
4132N/A }
4132N/A return false;
4132N/A}
4132N/A
0N/A//------------------------------Ideal------------------------------------------
0N/A// Return a node which is more "ideal" than the current node. Must preserve
0N/A// the CFG, but we can still strip out dead paths.
0N/ANode *RegionNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A if( !can_reshape && !in(0) ) return NULL; // Already degraded to a Copy
0N/A assert(!in(0) || !in(0)->is_Root(), "not a specially hidden merge");
0N/A
0N/A // Check for RegionNode with no Phi users and both inputs come from either
0N/A // arm of the same IF. If found, then the control-flow split is useless.
0N/A bool has_phis = false;
0N/A if (can_reshape) { // Need DU info to check for Phi users
0N/A has_phis = (has_phi() != NULL); // Cache result
4132N/A if (has_phis && try_clean_mem_phi(phase)) {
4132N/A has_phis = false;
4132N/A }
4132N/A
0N/A if (!has_phis) { // No Phi users? Nothing merging?
0N/A for (uint i = 1; i < req()-1; i++) {
0N/A Node *if1 = in(i);
0N/A if( !if1 ) continue;
0N/A Node *iff = if1->in(0);
0N/A if( !iff || !iff->is_If() ) continue;
0N/A for( uint j=i+1; j<req(); j++ ) {
0N/A if( in(j) && in(j)->in(0) == iff &&
0N/A if1->Opcode() != in(j)->Opcode() ) {
0N/A // Add the IF Projections to the worklist. They (and the IF itself)
0N/A // will be eliminated if dead.
0N/A phase->is_IterGVN()->add_users_to_worklist(iff);
0N/A set_req(i, iff->in(0));// Skip around the useless IF diamond
0N/A set_req(j, NULL);
0N/A return this; // Record progress
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Remove TOP or NULL input paths. If only 1 input path remains, this Region
0N/A // degrades to a copy.
0N/A bool add_to_worklist = false;
0N/A int cnt = 0; // Count of values merging
0N/A DEBUG_ONLY( int cnt_orig = req(); ) // Save original inputs count
0N/A int del_it = 0; // The last input path we delete
0N/A // For all inputs...
0N/A for( uint i=1; i<req(); ++i ){// For all paths in
0N/A Node *n = in(i); // Get the input
0N/A if( n != NULL ) {
0N/A // Remove useless control copy inputs
0N/A if( n->is_Region() && n->as_Region()->is_copy() ) {
0N/A set_req(i, n->nonnull_req());
0N/A i--;
0N/A continue;
0N/A }
0N/A if( n->is_Proj() ) { // Remove useless rethrows
0N/A Node *call = n->in(0);
0N/A if (call->is_Call() && call->as_Call()->entry_point() == OptoRuntime::rethrow_stub()) {
0N/A set_req(i, call->in(0));
0N/A i--;
0N/A continue;
0N/A }
0N/A }
0N/A if( phase->type(n) == Type::TOP ) {
0N/A set_req(i, NULL); // Ignore TOP inputs
0N/A i--;
0N/A continue;
0N/A }
0N/A cnt++; // One more value merging
0N/A
0N/A } else if (can_reshape) { // Else found dead path with DU info
0N/A PhaseIterGVN *igvn = phase->is_IterGVN();
0N/A del_req(i); // Yank path from self
0N/A del_it = i;
0N/A uint max = outcnt();
0N/A DUIterator j;
0N/A bool progress = true;
0N/A while(progress) { // Need to establish property over all users
0N/A progress = false;
0N/A for (j = outs(); has_out(j); j++) {
0N/A Node *n = out(j);
0N/A if( n->req() != req() && n->is_Phi() ) {
0N/A assert( n->in(0) == this, "" );
0N/A igvn->hash_delete(n); // Yank from hash before hacking edges
0N/A n->set_req_X(i,NULL,igvn);// Correct DU info
0N/A n->del_req(i); // Yank path from Phis
0N/A if( max != outcnt() ) {
0N/A progress = true;
0N/A j = refresh_out_pos(j);
0N/A max = outcnt();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A add_to_worklist = true;
0N/A i--;
0N/A }
0N/A }
0N/A
0N/A if (can_reshape && cnt == 1) {
0N/A // Is it dead loop?
0N/A // If it is LoopNopde it had 2 (+1 itself) inputs and
0N/A // one of them was cut. The loop is dead if it was EntryContol.
2956N/A // Loop node may have only one input because entry path
2956N/A // is removed in PhaseIdealLoop::Dominators().
2956N/A assert(!this->is_Loop() || cnt_orig <= 3, "Loop node should have 3 or less inputs");
2956N/A if (this->is_Loop() && (del_it == LoopNode::EntryControl ||
2956N/A del_it == 0 && is_unreachable_region(phase)) ||
0N/A !this->is_Loop() && has_phis && is_unreachable_region(phase)) {
0N/A // Yes, the region will be removed during the next step below.
0N/A // Cut the backedge input and remove phis since no data paths left.
0N/A // We don't cut outputs to other nodes here since we need to put them
0N/A // on the worklist.
0N/A del_req(1);
0N/A cnt = 0;
0N/A assert( req() == 1, "no more inputs expected" );
0N/A uint max = outcnt();
0N/A bool progress = true;
0N/A Node *top = phase->C->top();
0N/A PhaseIterGVN *igvn = phase->is_IterGVN();
0N/A DUIterator j;
0N/A while(progress) {
0N/A progress = false;
0N/A for (j = outs(); has_out(j); j++) {
0N/A Node *n = out(j);
0N/A if( n->is_Phi() ) {
0N/A assert( igvn->eqv(n->in(0), this), "" );
0N/A assert( n->req() == 2 && n->in(1) != NULL, "Only one data input expected" );
0N/A // Break dead loop data path.
0N/A // Eagerly replace phis with top to avoid phis copies generation.
1541N/A igvn->replace_node(n, top);
0N/A if( max != outcnt() ) {
0N/A progress = true;
0N/A j = refresh_out_pos(j);
0N/A max = outcnt();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A add_to_worklist = true;
0N/A }
0N/A }
0N/A if (add_to_worklist) {
0N/A phase->is_IterGVN()->add_users_to_worklist(this); // Revisit collapsed Phis
0N/A }
0N/A
0N/A if( cnt <= 1 ) { // Only 1 path in?
0N/A set_req(0, NULL); // Null control input for region copy
0N/A if( cnt == 0 && !can_reshape) { // Parse phase - leave the node as it is.
0N/A // No inputs or all inputs are NULL.
0N/A return NULL;
0N/A } else if (can_reshape) { // Optimization phase - remove the node
0N/A PhaseIterGVN *igvn = phase->is_IterGVN();
0N/A Node *parent_ctrl;
0N/A if( cnt == 0 ) {
0N/A assert( req() == 1, "no inputs expected" );
0N/A // During IGVN phase such region will be subsumed by TOP node
0N/A // so region's phis will have TOP as control node.
0N/A // Kill phis here to avoid it. PhiNode::is_copy() will be always false.
0N/A // Also set other user's input to top.
0N/A parent_ctrl = phase->C->top();
0N/A } else {
0N/A // The fallthrough case since we already checked dead loops above.
0N/A parent_ctrl = in(1);
0N/A assert(parent_ctrl != NULL, "Region is a copy of some non-null control");
0N/A assert(!igvn->eqv(parent_ctrl, this), "Close dead loop");
0N/A }
0N/A if (!add_to_worklist)
0N/A igvn->add_users_to_worklist(this); // Check for further allowed opts
0N/A for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {
0N/A Node* n = last_out(i);
0N/A igvn->hash_delete(n); // Remove from worklist before modifying edges
0N/A if( n->is_Phi() ) { // Collapse all Phis
0N/A // Eagerly replace phis to avoid copies generation.
1541N/A Node* in;
0N/A if( cnt == 0 ) {
0N/A assert( n->req() == 1, "No data inputs expected" );
1541N/A in = parent_ctrl; // replaced by top
0N/A } else {
0N/A assert( n->req() == 2 && n->in(1) != NULL, "Only one data input expected" );
1541N/A in = n->in(1); // replaced by unique input
1541N/A if( n->as_Phi()->is_unsafe_data_reference(in) )
1541N/A in = phase->C->top(); // replaced by top
0N/A }
1541N/A igvn->replace_node(n, in);
0N/A }
0N/A else if( n->is_Region() ) { // Update all incoming edges
0N/A assert( !igvn->eqv(n, this), "Must be removed from DefUse edges");
0N/A uint uses_found = 0;
0N/A for( uint k=1; k < n->req(); k++ ) {
0N/A if( n->in(k) == this ) {
0N/A n->set_req(k, parent_ctrl);
0N/A uses_found++;
0N/A }
0N/A }
0N/A if( uses_found > 1 ) { // (--i) done at the end of the loop.
0N/A i -= (uses_found - 1);
0N/A }
0N/A }
0N/A else {
0N/A assert( igvn->eqv(n->in(0), this), "Expect RegionNode to be control parent");
0N/A n->set_req(0, parent_ctrl);
0N/A }
0N/A#ifdef ASSERT
0N/A for( uint k=0; k < n->req(); k++ ) {
0N/A assert( !igvn->eqv(n->in(k), this), "All uses of RegionNode should be gone");
0N/A }
0N/A#endif
0N/A }
0N/A // Remove the RegionNode itself from DefUse info
0N/A igvn->remove_dead_node(this);
0N/A return NULL;
0N/A }
0N/A return this; // Record progress
0N/A }
0N/A
0N/A
0N/A // If a Region flows into a Region, merge into one big happy merge.
0N/A if (can_reshape) {
0N/A Node *m = merge_region(this, phase);
0N/A if (m != NULL) return m;
0N/A }
0N/A
0N/A // Check if this region is the root of a clipping idiom on floats
0N/A if( ConvertFloat2IntClipping && can_reshape && req() == 4 ) {
0N/A // Check that only one use is a Phi and that it simplifies to two constants +
0N/A PhiNode* phi = has_unique_phi();
0N/A if (phi != NULL) { // One Phi user
0N/A // Check inputs to the Phi
0N/A ConNode *min;
0N/A ConNode *max;
0N/A Node *val;
0N/A uint min_idx;
0N/A uint max_idx;
0N/A uint val_idx;
0N/A if( check_phi_clipping( phi, min, min_idx, max, max_idx, val, val_idx ) ) {
0N/A IfNode *top_if;
0N/A IfNode *bot_if;
0N/A if( check_if_clipping( this, bot_if, top_if ) ) {
0N/A // Control pattern checks, now verify compares
0N/A Node *top_in = NULL; // value being compared against
0N/A Node *bot_in = NULL;
0N/A if( check_compare_clipping( true, bot_if, min, bot_in ) &&
0N/A check_compare_clipping( false, top_if, max, top_in ) ) {
0N/A if( bot_in == top_in ) {
0N/A PhaseIterGVN *gvn = phase->is_IterGVN();
0N/A assert( gvn != NULL, "Only had DefUse info in IterGVN");
0N/A // Only remaining check is that bot_in == top_in == (Phi's val + mods)
0N/A
0N/A // Check for the ConvF2INode
0N/A ConvF2INode *convf2i;
0N/A if( check_convf2i_clipping( phi, val_idx, convf2i, min, max ) &&
0N/A convf2i->in(1) == bot_in ) {
0N/A // Matched pattern, including LShiftI; RShiftI, replace with integer compares
0N/A // max test
4022N/A Node *cmp = gvn->register_new_node_with_optimizer(new (phase->C) CmpINode( convf2i, min ));
4022N/A Node *boo = gvn->register_new_node_with_optimizer(new (phase->C) BoolNode( cmp, BoolTest::lt ));
4022N/A IfNode *iff = (IfNode*)gvn->register_new_node_with_optimizer(new (phase->C) IfNode( top_if->in(0), boo, PROB_UNLIKELY_MAG(5), top_if->_fcnt ));
4022N/A Node *if_min= gvn->register_new_node_with_optimizer(new (phase->C) IfTrueNode (iff));
4022N/A Node *ifF = gvn->register_new_node_with_optimizer(new (phase->C) IfFalseNode(iff));
0N/A // min test
4022N/A cmp = gvn->register_new_node_with_optimizer(new (phase->C) CmpINode( convf2i, max ));
4022N/A boo = gvn->register_new_node_with_optimizer(new (phase->C) BoolNode( cmp, BoolTest::gt ));
4022N/A iff = (IfNode*)gvn->register_new_node_with_optimizer(new (phase->C) IfNode( ifF, boo, PROB_UNLIKELY_MAG(5), bot_if->_fcnt ));
4022N/A Node *if_max= gvn->register_new_node_with_optimizer(new (phase->C) IfTrueNode (iff));
4022N/A ifF = gvn->register_new_node_with_optimizer(new (phase->C) IfFalseNode(iff));
0N/A // update input edges to region node
0N/A set_req_X( min_idx, if_min, gvn );
0N/A set_req_X( max_idx, if_max, gvn );
0N/A set_req_X( val_idx, ifF, gvn );
0N/A // remove unnecessary 'LShiftI; RShiftI' idiom
0N/A gvn->hash_delete(phi);
0N/A phi->set_req_X( val_idx, convf2i, gvn );
0N/A gvn->hash_find_insert(phi);
0N/A // Return transformed region node
0N/A return this;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/A
0N/Aconst RegMask &RegionNode::out_RegMask() const {
0N/A return RegMask::Empty;
0N/A}
0N/A
0N/A// Find the one non-null required input. RegionNode only
0N/ANode *Node::nonnull_req() const {
0N/A assert( is_Region(), "" );
0N/A for( uint i = 1; i < _cnt; i++ )
0N/A if( in(i) )
0N/A return in(i);
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A// note that these functions assume that the _adr_type field is flattened
0N/Auint PhiNode::hash() const {
0N/A const Type* at = _adr_type;
0N/A return TypeNode::hash() + (at ? at->hash() : 0);
0N/A}
0N/Auint PhiNode::cmp( const Node &n ) const {
0N/A return TypeNode::cmp(n) && _adr_type == ((PhiNode&)n)._adr_type;
0N/A}
0N/Astatic inline
0N/Aconst TypePtr* flatten_phi_adr_type(const TypePtr* at) {
0N/A if (at == NULL || at == TypePtr::BOTTOM) return at;
0N/A return Compile::current()->alias_type(at)->adr_type();
0N/A}
0N/A
0N/A//----------------------------make---------------------------------------------
0N/A// create a new phi with edges matching r and set (initially) to x
0N/APhiNode* PhiNode::make(Node* r, Node* x, const Type *t, const TypePtr* at) {
0N/A uint preds = r->req(); // Number of predecessor paths
0N/A assert(t != Type::MEMORY || at == flatten_phi_adr_type(at), "flatten at");
4022N/A PhiNode* p = new (Compile::current()) PhiNode(r, t, at);
0N/A for (uint j = 1; j < preds; j++) {
0N/A // Fill in all inputs, except those which the region does not yet have
0N/A if (r->in(j) != NULL)
0N/A p->init_req(j, x);
0N/A }
0N/A return p;
0N/A}
0N/APhiNode* PhiNode::make(Node* r, Node* x) {
0N/A const Type* t = x->bottom_type();
0N/A const TypePtr* at = NULL;
0N/A if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());
0N/A return make(r, x, t, at);
0N/A}
0N/APhiNode* PhiNode::make_blank(Node* r, Node* x) {
0N/A const Type* t = x->bottom_type();
0N/A const TypePtr* at = NULL;
0N/A if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());
4022N/A return new (Compile::current()) PhiNode(r, t, at);
0N/A}
0N/A
0N/A
0N/A//------------------------slice_memory-----------------------------------------
0N/A// create a new phi with narrowed memory type
0N/APhiNode* PhiNode::slice_memory(const TypePtr* adr_type) const {
0N/A PhiNode* mem = (PhiNode*) clone();
0N/A *(const TypePtr**)&mem->_adr_type = adr_type;
0N/A // convert self-loops, or else we get a bad graph
0N/A for (uint i = 1; i < req(); i++) {
0N/A if ((const Node*)in(i) == this) mem->set_req(i, mem);
0N/A }
0N/A mem->verify_adr_type();
0N/A return mem;
0N/A}
0N/A
74N/A//------------------------split_out_instance-----------------------------------
74N/A// Split out an instance type from a bottom phi.
74N/APhiNode* PhiNode::split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const {
163N/A const TypeOopPtr *t_oop = at->isa_oopptr();
223N/A assert(t_oop != NULL && t_oop->is_known_instance(), "expecting instance oopptr");
163N/A const TypePtr *t = adr_type();
163N/A assert(type() == Type::MEMORY &&
163N/A (t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM ||
223N/A t->isa_oopptr() && !t->is_oopptr()->is_known_instance() &&
247N/A t->is_oopptr()->cast_to_exactness(true)
247N/A ->is_oopptr()->cast_to_ptr_type(t_oop->ptr())
247N/A ->is_oopptr()->cast_to_instance_id(t_oop->instance_id()) == t_oop),
163N/A "bottom or raw memory required");
74N/A
74N/A // Check if an appropriate node already exists.
74N/A Node *region = in(0);
74N/A for (DUIterator_Fast kmax, k = region->fast_outs(kmax); k < kmax; k++) {
74N/A Node* use = region->fast_out(k);
74N/A if( use->is_Phi()) {
74N/A PhiNode *phi2 = use->as_Phi();
74N/A if (phi2->type() == Type::MEMORY && phi2->adr_type() == at) {
74N/A return phi2;
74N/A }
74N/A }
74N/A }
74N/A Compile *C = igvn->C;
74N/A Arena *a = Thread::current()->resource_area();
74N/A Node_Array node_map = new Node_Array(a);
74N/A Node_Stack stack(a, C->unique() >> 4);
74N/A PhiNode *nphi = slice_memory(at);
74N/A igvn->register_new_node_with_optimizer( nphi );
74N/A node_map.map(_idx, nphi);
74N/A stack.push((Node *)this, 1);
74N/A while(!stack.is_empty()) {
74N/A PhiNode *ophi = stack.node()->as_Phi();
74N/A uint i = stack.index();
74N/A assert(i >= 1, "not control edge");
74N/A stack.pop();
74N/A nphi = node_map[ophi->_idx]->as_Phi();
74N/A for (; i < ophi->req(); i++) {
74N/A Node *in = ophi->in(i);
74N/A if (in == NULL || igvn->type(in) == Type::TOP)
74N/A continue;
74N/A Node *opt = MemNode::optimize_simple_memory_chain(in, at, igvn);
74N/A PhiNode *optphi = opt->is_Phi() ? opt->as_Phi() : NULL;
74N/A if (optphi != NULL && optphi->adr_type() == TypePtr::BOTTOM) {
74N/A opt = node_map[optphi->_idx];
74N/A if (opt == NULL) {
74N/A stack.push(ophi, i);
74N/A nphi = optphi->slice_memory(at);
74N/A igvn->register_new_node_with_optimizer( nphi );
74N/A node_map.map(optphi->_idx, nphi);
74N/A ophi = optphi;
74N/A i = 0; // will get incremented at top of loop
74N/A continue;
74N/A }
74N/A }
74N/A nphi->set_req(i, opt);
74N/A }
74N/A }
74N/A return nphi;
74N/A}
74N/A
0N/A//------------------------verify_adr_type--------------------------------------
0N/A#ifdef ASSERT
0N/Avoid PhiNode::verify_adr_type(VectorSet& visited, const TypePtr* at) const {
0N/A if (visited.test_set(_idx)) return; //already visited
0N/A
0N/A // recheck constructor invariants:
0N/A verify_adr_type(false);
0N/A
0N/A // recheck local phi/phi consistency:
0N/A assert(_adr_type == at || _adr_type == TypePtr::BOTTOM,
0N/A "adr_type must be consistent across phi nest");
0N/A
0N/A // walk around
0N/A for (uint i = 1; i < req(); i++) {
0N/A Node* n = in(i);
0N/A if (n == NULL) continue;
0N/A const Node* np = in(i);
0N/A if (np->is_Phi()) {
0N/A np->as_Phi()->verify_adr_type(visited, at);
0N/A } else if (n->bottom_type() == Type::TOP
0N/A || (n->is_Mem() && n->in(MemNode::Address)->bottom_type() == Type::TOP)) {
0N/A // ignore top inputs
0N/A } else {
0N/A const TypePtr* nat = flatten_phi_adr_type(n->adr_type());
0N/A // recheck phi/non-phi consistency at leaves:
0N/A assert((nat != NULL) == (at != NULL), "");
0N/A assert(nat == at || nat == TypePtr::BOTTOM,
0N/A "adr_type must be consistent at leaves of phi nest");
0N/A }
0N/A }
0N/A}
0N/A
0N/A// Verify a whole nest of phis rooted at this one.
0N/Avoid PhiNode::verify_adr_type(bool recursive) const {
0N/A if (is_error_reported()) return; // muzzle asserts when debugging an error
0N/A if (Node::in_dump()) return; // muzzle asserts when printing
0N/A
0N/A assert((_type == Type::MEMORY) == (_adr_type != NULL), "adr_type for memory phis only");
0N/A
0N/A if (!VerifyAliases) return; // verify thoroughly only if requested
0N/A
0N/A assert(_adr_type == flatten_phi_adr_type(_adr_type),
0N/A "Phi::adr_type must be pre-normalized");
0N/A
0N/A if (recursive) {
0N/A VectorSet visited(Thread::current()->resource_area());
0N/A verify_adr_type(visited, _adr_type);
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A
0N/A//------------------------------Value------------------------------------------
0N/A// Compute the type of the PhiNode
0N/Aconst Type *PhiNode::Value( PhaseTransform *phase ) const {
0N/A Node *r = in(0); // RegionNode
0N/A if( !r ) // Copy or dead
0N/A return in(1) ? phase->type(in(1)) : Type::TOP;
0N/A
0N/A // Note: During parsing, phis are often transformed before their regions.
0N/A // This means we have to use type_or_null to defend against untyped regions.
0N/A if( phase->type_or_null(r) == Type::TOP ) // Dead code?
0N/A return Type::TOP;
0N/A
0N/A // Check for trip-counted loop. If so, be smarter.
0N/A CountedLoopNode *l = r->is_CountedLoop() ? r->as_CountedLoop() : NULL;
0N/A if( l && l->can_be_counted_loop(phase) &&
0N/A ((const Node*)l->phi() == this) ) { // Trip counted loop!
0N/A // protect against init_trip() or limit() returning NULL
0N/A const Node *init = l->init_trip();
0N/A const Node *limit = l->limit();
0N/A if( init != NULL && limit != NULL && l->stride_is_con() ) {
0N/A const TypeInt *lo = init ->bottom_type()->isa_int();
0N/A const TypeInt *hi = limit->bottom_type()->isa_int();
0N/A if( lo && hi ) { // Dying loops might have TOP here
0N/A int stride = l->stride_con();
0N/A if( stride < 0 ) { // Down-counter loop
0N/A const TypeInt *tmp = lo; lo = hi; hi = tmp;
0N/A stride = -stride;
0N/A }
0N/A if( lo->_hi < hi->_lo ) // Reversed endpoints are well defined :-(
0N/A return TypeInt::make(lo->_lo,hi->_hi,3);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Until we have harmony between classes and interfaces in the type
0N/A // lattice, we must tread carefully around phis which implicitly
0N/A // convert the one to the other.
221N/A const TypePtr* ttp = _type->make_ptr();
221N/A const TypeInstPtr* ttip = (ttp != NULL) ? ttp->isa_instptr() : NULL;
555N/A const TypeKlassPtr* ttkp = (ttp != NULL) ? ttp->isa_klassptr() : NULL;
0N/A bool is_intf = false;
0N/A if (ttip != NULL) {
0N/A ciKlass* k = ttip->klass();
0N/A if (k->is_loaded() && k->is_interface())
0N/A is_intf = true;
0N/A }
555N/A if (ttkp != NULL) {
555N/A ciKlass* k = ttkp->klass();
555N/A if (k->is_loaded() && k->is_interface())
555N/A is_intf = true;
555N/A }
0N/A
0N/A // Default case: merge all inputs
0N/A const Type *t = Type::TOP; // Merged type starting value
0N/A for (uint i = 1; i < req(); ++i) {// For all paths in
0N/A // Reachable control path?
0N/A if (r->in(i) && phase->type(r->in(i)) == Type::CONTROL) {
0N/A const Type* ti = phase->type(in(i));
0N/A // We assume that each input of an interface-valued Phi is a true
0N/A // subtype of that interface. This might not be true of the meet
0N/A // of all the input types. The lattice is not distributive in
0N/A // such cases. Ward off asserts in type.cpp by refusing to do
0N/A // meets between interfaces and proper classes.
221N/A const TypePtr* tip = ti->make_ptr();
221N/A const TypeInstPtr* tiip = (tip != NULL) ? tip->isa_instptr() : NULL;
0N/A if (tiip) {
0N/A bool ti_is_intf = false;
0N/A ciKlass* k = tiip->klass();
0N/A if (k->is_loaded() && k->is_interface())
0N/A ti_is_intf = true;
0N/A if (is_intf != ti_is_intf)
0N/A { t = _type; break; }
0N/A }
0N/A t = t->meet(ti);
0N/A }
0N/A }
0N/A
0N/A // The worst-case type (from ciTypeFlow) should be consistent with "t".
0N/A // That is, we expect that "t->higher_equal(_type)" holds true.
0N/A // There are various exceptions:
0N/A // - Inputs which are phis might in fact be widened unnecessarily.
0N/A // For example, an input might be a widened int while the phi is a short.
0N/A // - Inputs might be BotPtrs but this phi is dependent on a null check,
0N/A // and postCCP has removed the cast which encodes the result of the check.
0N/A // - The type of this phi is an interface, and the inputs are classes.
0N/A // - Value calls on inputs might produce fuzzy results.
0N/A // (Occurrences of this case suggest improvements to Value methods.)
0N/A //
0N/A // It is not possible to see Type::BOTTOM values as phi inputs,
0N/A // because the ciTypeFlow pre-pass produces verifier-quality types.
0N/A const Type* ft = t->filter(_type); // Worst case type
0N/A
0N/A#ifdef ASSERT
0N/A // The following logic has been moved into TypeOopPtr::filter.
0N/A const Type* jt = t->join(_type);
0N/A if( jt->empty() ) { // Emptied out???
0N/A
0N/A // Check for evil case of 't' being a class and '_type' expecting an
0N/A // interface. This can happen because the bytecodes do not contain
0N/A // enough type info to distinguish a Java-level interface variable
0N/A // from a Java-level object variable. If we meet 2 classes which
0N/A // both implement interface I, but their meet is at 'j/l/O' which
0N/A // doesn't implement I, we have no way to tell if the result should
0N/A // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
0N/A // into a Phi which "knows" it's an Interface type we'll have to
0N/A // uplift the type.
0N/A if( !t->empty() && ttip && ttip->is_loaded() && ttip->klass()->is_interface() )
0N/A { assert(ft == _type, ""); } // Uplift to interface
555N/A else if( !t->empty() && ttkp && ttkp->is_loaded() && ttkp->klass()->is_interface() )
555N/A { assert(ft == _type, ""); } // Uplift to interface
0N/A // Otherwise it's something stupid like non-overlapping int ranges
0N/A // found on dying counted loops.
0N/A else
0N/A { assert(ft == Type::TOP, ""); } // Canonical empty value
0N/A }
0N/A
0N/A else {
0N/A
0N/A // If we have an interface-typed Phi and we narrow to a class type, the join
0N/A // should report back the class. However, if we have a J/L/Object
0N/A // class-typed Phi and an interface flows in, it's possible that the meet &
0N/A // join report an interface back out. This isn't possible but happens
0N/A // because the type system doesn't interact well with interfaces.
221N/A const TypePtr *jtp = jt->make_ptr();
221N/A const TypeInstPtr *jtip = (jtp != NULL) ? jtp->isa_instptr() : NULL;
555N/A const TypeKlassPtr *jtkp = (jtp != NULL) ? jtp->isa_klassptr() : NULL;
0N/A if( jtip && ttip ) {
0N/A if( jtip->is_loaded() && jtip->klass()->is_interface() &&
113N/A ttip->is_loaded() && !ttip->klass()->is_interface() ) {
0N/A // Happens in a CTW of rt.jar, 320-341, no extra flags
113N/A assert(ft == ttip->cast_to_ptr_type(jtip->ptr()) ||
221N/A ft->isa_narrowoop() && ft->make_ptr() == ttip->cast_to_ptr_type(jtip->ptr()), "");
113N/A jt = ft;
113N/A }
0N/A }
555N/A if( jtkp && ttkp ) {
555N/A if( jtkp->is_loaded() && jtkp->klass()->is_interface() &&
1335N/A !jtkp->klass_is_exact() && // Keep exact interface klass (6894807)
555N/A ttkp->is_loaded() && !ttkp->klass()->is_interface() ) {
555N/A assert(ft == ttkp->cast_to_ptr_type(jtkp->ptr()) ||
555N/A ft->isa_narrowoop() && ft->make_ptr() == ttkp->cast_to_ptr_type(jtkp->ptr()), "");
555N/A jt = ft;
555N/A }
555N/A }
0N/A if (jt != ft && jt->base() == ft->base()) {
0N/A if (jt->isa_int() &&
0N/A jt->is_int()->_lo == ft->is_int()->_lo &&
0N/A jt->is_int()->_hi == ft->is_int()->_hi)
0N/A jt = ft;
0N/A if (jt->isa_long() &&
0N/A jt->is_long()->_lo == ft->is_long()->_lo &&
0N/A jt->is_long()->_hi == ft->is_long()->_hi)
0N/A jt = ft;
0N/A }
0N/A if (jt != ft) {
0N/A tty->print("merge type: "); t->dump(); tty->cr();
0N/A tty->print("kill type: "); _type->dump(); tty->cr();
0N/A tty->print("join type: "); jt->dump(); tty->cr();
0N/A tty->print("filter type: "); ft->dump(); tty->cr();
0N/A }
0N/A assert(jt == ft, "");
0N/A }
0N/A#endif //ASSERT
0N/A
0N/A // Deal with conversion problems found in data loops.
0N/A ft = phase->saturate(ft, phase->type_or_null(this), _type);
0N/A
0N/A return ft;
0N/A}
0N/A
0N/A
0N/A//------------------------------is_diamond_phi---------------------------------
0N/A// Does this Phi represent a simple well-shaped diamond merge? Return the
0N/A// index of the true path or 0 otherwise.
4132N/A// If check_control_only is true, do not inspect the If node at the
4132N/A// top, and return -1 (not an edge number) on success.
4132N/Aint PhiNode::is_diamond_phi(bool check_control_only) const {
0N/A // Check for a 2-path merge
0N/A Node *region = in(0);
0N/A if( !region ) return 0;
0N/A if( region->req() != 3 ) return 0;
0N/A if( req() != 3 ) return 0;
0N/A // Check that both paths come from the same If
0N/A Node *ifp1 = region->in(1);
0N/A Node *ifp2 = region->in(2);
0N/A if( !ifp1 || !ifp2 ) return 0;
0N/A Node *iff = ifp1->in(0);
0N/A if( !iff || !iff->is_If() ) return 0;
0N/A if( iff != ifp2->in(0) ) return 0;
4132N/A if (check_control_only) return -1;
0N/A // Check for a proper bool/cmp
0N/A const Node *b = iff->in(1);
0N/A if( !b->is_Bool() ) return 0;
0N/A const Node *cmp = b->in(1);
0N/A if( !cmp->is_Cmp() ) return 0;
0N/A
0N/A // Check for branching opposite expected
0N/A if( ifp2->Opcode() == Op_IfTrue ) {
0N/A assert( ifp1->Opcode() == Op_IfFalse, "" );
0N/A return 2;
0N/A } else {
0N/A assert( ifp1->Opcode() == Op_IfTrue, "" );
0N/A return 1;
0N/A }
0N/A}
0N/A
0N/A//----------------------------check_cmove_id-----------------------------------
0N/A// Check for CMove'ing a constant after comparing against the constant.
0N/A// Happens all the time now, since if we compare equality vs a constant in
0N/A// the parser, we "know" the variable is constant on one path and we force
0N/A// it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a
0N/A// conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more
0N/A// general in that we don't need constants. Since CMove's are only inserted
0N/A// in very special circumstances, we do it here on generic Phi's.
0N/ANode* PhiNode::is_cmove_id(PhaseTransform* phase, int true_path) {
0N/A assert(true_path !=0, "only diamond shape graph expected");
0N/A
0N/A // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
0N/A // phi->region->if_proj->ifnode->bool->cmp
0N/A Node* region = in(0);
0N/A Node* iff = region->in(1)->in(0);
0N/A BoolNode* b = iff->in(1)->as_Bool();
0N/A Node* cmp = b->in(1);
0N/A Node* tval = in(true_path);
0N/A Node* fval = in(3-true_path);
0N/A Node* id = CMoveNode::is_cmove_id(phase, cmp, tval, fval, b);
0N/A if (id == NULL)
0N/A return NULL;
0N/A
0N/A // Either value might be a cast that depends on a branch of 'iff'.
0N/A // Since the 'id' value will float free of the diamond, either
0N/A // decast or return failure.
0N/A Node* ctl = id->in(0);
0N/A if (ctl != NULL && ctl->in(0) == iff) {
0N/A if (id->is_ConstraintCast()) {
0N/A return id->in(1);
0N/A } else {
0N/A // Don't know how to disentangle this value.
0N/A return NULL;
0N/A }
0N/A }
0N/A
0N/A return id;
0N/A}
0N/A
0N/A//------------------------------Identity---------------------------------------
0N/A// Check for Region being Identity.
0N/ANode *PhiNode::Identity( PhaseTransform *phase ) {
0N/A // Check for no merging going on
0N/A // (There used to be special-case code here when this->region->is_Loop.
0N/A // It would check for a tributary phi on the backedge that the main phi
0N/A // trivially, perhaps with a single cast. The unique_input method
0N/A // does all this and more, by reducing such tributaries to 'this'.)
0N/A Node* uin = unique_input(phase);
0N/A if (uin != NULL) {
0N/A return uin;
0N/A }
0N/A
0N/A int true_path = is_diamond_phi();
0N/A if (true_path != 0) {
0N/A Node* id = is_cmove_id(phase, true_path);
0N/A if (id != NULL) return id;
0N/A }
0N/A
0N/A return this; // No identity
0N/A}
0N/A
0N/A//-----------------------------unique_input------------------------------------
0N/A// Find the unique value, discounting top, self-loops, and casts.
0N/A// Return top if there are no inputs, and self if there are multiple.
0N/ANode* PhiNode::unique_input(PhaseTransform* phase) {
0N/A // 1) One unique direct input, or
0N/A // 2) some of the inputs have an intervening ConstraintCast and
0N/A // the type of input is the same or sharper (more specific)
0N/A // than the phi's type.
0N/A // 3) an input is a self loop
0N/A //
0N/A // 1) input or 2) input or 3) input __
0N/A // / \ / \ \ / \
0N/A // \ / | cast phi cast
0N/A // phi \ / / \ /
0N/A // phi / --
0N/A
0N/A Node* r = in(0); // RegionNode
0N/A if (r == NULL) return in(1); // Already degraded to a Copy
0N/A Node* uncasted_input = NULL; // The unique uncasted input (ConstraintCasts removed)
0N/A Node* direct_input = NULL; // The unique direct input
0N/A
0N/A for (uint i = 1, cnt = req(); i < cnt; ++i) {
0N/A Node* rc = r->in(i);
0N/A if (rc == NULL || phase->type(rc) == Type::TOP)
0N/A continue; // ignore unreachable control path
0N/A Node* n = in(i);
247N/A if (n == NULL)
247N/A continue;
0N/A Node* un = n->uncast();
0N/A if (un == NULL || un == this || phase->type(un) == Type::TOP) {
0N/A continue; // ignore if top, or in(i) and "this" are in a data cycle
0N/A }
0N/A // Check for a unique uncasted input
0N/A if (uncasted_input == NULL) {
0N/A uncasted_input = un;
0N/A } else if (uncasted_input != un) {
0N/A uncasted_input = NodeSentinel; // no unique uncasted input
0N/A }
0N/A // Check for a unique direct input
0N/A if (direct_input == NULL) {
0N/A direct_input = n;
0N/A } else if (direct_input != n) {
0N/A direct_input = NodeSentinel; // no unique direct input
0N/A }
0N/A }
0N/A if (direct_input == NULL) {
0N/A return phase->C->top(); // no inputs
0N/A }
0N/A assert(uncasted_input != NULL,"");
0N/A
0N/A if (direct_input != NodeSentinel) {
0N/A return direct_input; // one unique direct input
0N/A }
0N/A if (uncasted_input != NodeSentinel &&
0N/A phase->type(uncasted_input)->higher_equal(type())) {
0N/A return uncasted_input; // one unique uncasted input
0N/A }
0N/A
0N/A // Nothing.
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------is_x2logic-------------------------------------
0N/A// Check for simple convert-to-boolean pattern
0N/A// If:(C Bool) Region:(IfF IfT) Phi:(Region 0 1)
0N/A// Convert Phi to an ConvIB.
0N/Astatic Node *is_x2logic( PhaseGVN *phase, PhiNode *phi, int true_path ) {
0N/A assert(true_path !=0, "only diamond shape graph expected");
0N/A // Convert the true/false index into an expected 0/1 return.
0N/A // Map 2->0 and 1->1.
0N/A int flipped = 2-true_path;
0N/A
0N/A // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
0N/A // phi->region->if_proj->ifnode->bool->cmp
0N/A Node *region = phi->in(0);
0N/A Node *iff = region->in(1)->in(0);
0N/A BoolNode *b = (BoolNode*)iff->in(1);
0N/A const CmpNode *cmp = (CmpNode*)b->in(1);
0N/A
0N/A Node *zero = phi->in(1);
0N/A Node *one = phi->in(2);
0N/A const Type *tzero = phase->type( zero );
0N/A const Type *tone = phase->type( one );
0N/A
0N/A // Check for compare vs 0
0N/A const Type *tcmp = phase->type(cmp->in(2));
0N/A if( tcmp != TypeInt::ZERO && tcmp != TypePtr::NULL_PTR ) {
0N/A // Allow cmp-vs-1 if the other input is bounded by 0-1
0N/A if( !(tcmp == TypeInt::ONE && phase->type(cmp->in(1)) == TypeInt::BOOL) )
0N/A return NULL;
0N/A flipped = 1-flipped; // Test is vs 1 instead of 0!
0N/A }
0N/A
0N/A // Check for setting zero/one opposite expected
0N/A if( tzero == TypeInt::ZERO ) {
0N/A if( tone == TypeInt::ONE ) {
0N/A } else return NULL;
0N/A } else if( tzero == TypeInt::ONE ) {
0N/A if( tone == TypeInt::ZERO ) {
0N/A flipped = 1-flipped;
0N/A } else return NULL;
0N/A } else return NULL;
0N/A
0N/A // Check for boolean test backwards
0N/A if( b->_test._test == BoolTest::ne ) {
0N/A } else if( b->_test._test == BoolTest::eq ) {
0N/A flipped = 1-flipped;
0N/A } else return NULL;
0N/A
0N/A // Build int->bool conversion
4022N/A Node *n = new (phase->C) Conv2BNode( cmp->in(1) );
0N/A if( flipped )
4022N/A n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );
0N/A
0N/A return n;
0N/A}
0N/A
0N/A//------------------------------is_cond_add------------------------------------
0N/A// Check for simple conditional add pattern: "(P < Q) ? X+Y : X;"
0N/A// To be profitable the control flow has to disappear; there can be no other
0N/A// values merging here. We replace the test-and-branch with:
0N/A// "(sgn(P-Q))&Y) + X". Basically, convert "(P < Q)" into 0 or -1 by
0N/A// moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.
0N/A// Then convert Y to 0-or-Y and finally add.
0N/A// This is a key transform for SpecJava _201_compress.
0N/Astatic Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {
0N/A assert(true_path !=0, "only diamond shape graph expected");
0N/A
0N/A // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
0N/A // phi->region->if_proj->ifnode->bool->cmp
0N/A RegionNode *region = (RegionNode*)phi->in(0);
0N/A Node *iff = region->in(1)->in(0);
0N/A BoolNode* b = iff->in(1)->as_Bool();
0N/A const CmpNode *cmp = (CmpNode*)b->in(1);
0N/A
0N/A // Make sure only merging this one phi here
0N/A if (region->has_unique_phi() != phi) return NULL;
0N/A
0N/A // Make sure each arm of the diamond has exactly one output, which we assume
0N/A // is the region. Otherwise, the control flow won't disappear.
0N/A if (region->in(1)->outcnt() != 1) return NULL;
0N/A if (region->in(2)->outcnt() != 1) return NULL;
0N/A
0N/A // Check for "(P < Q)" of type signed int
0N/A if (b->_test._test != BoolTest::lt) return NULL;
0N/A if (cmp->Opcode() != Op_CmpI) return NULL;
0N/A
0N/A Node *p = cmp->in(1);
0N/A Node *q = cmp->in(2);
0N/A Node *n1 = phi->in( true_path);
0N/A Node *n2 = phi->in(3-true_path);
0N/A
0N/A int op = n1->Opcode();
0N/A if( op != Op_AddI // Need zero as additive identity
0N/A /*&&op != Op_SubI &&
0N/A op != Op_AddP &&
0N/A op != Op_XorI &&
0N/A op != Op_OrI*/ )
0N/A return NULL;
0N/A
0N/A Node *x = n2;
4449N/A Node *y = NULL;
4449N/A if( x == n1->in(1) ) {
0N/A y = n1->in(2);
4449N/A } else if( x == n1->in(2) ) {
4449N/A y = n1->in(1);
0N/A } else return NULL;
0N/A
0N/A // Not so profitable if compare and add are constants
0N/A if( q->is_Con() && phase->type(q) != TypeInt::ZERO && y->is_Con() )
0N/A return NULL;
0N/A
4022N/A Node *cmplt = phase->transform( new (phase->C) CmpLTMaskNode(p,q) );
4022N/A Node *j_and = phase->transform( new (phase->C) AndINode(cmplt,y) );
4022N/A return new (phase->C) AddINode(j_and,x);
0N/A}
0N/A
0N/A//------------------------------is_absolute------------------------------------
0N/A// Check for absolute value.
0N/Astatic Node* is_absolute( PhaseGVN *phase, PhiNode *phi_root, int true_path) {
0N/A assert(true_path !=0, "only diamond shape graph expected");
0N/A
0N/A int cmp_zero_idx = 0; // Index of compare input where to look for zero
0N/A int phi_x_idx = 0; // Index of phi input where to find naked x
0N/A
0N/A // ABS ends with the merge of 2 control flow paths.
0N/A // Find the false path from the true path. With only 2 inputs, 3 - x works nicely.
0N/A int false_path = 3 - true_path;
0N/A
0N/A // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
0N/A // phi->region->if_proj->ifnode->bool->cmp
0N/A BoolNode *bol = phi_root->in(0)->in(1)->in(0)->in(1)->as_Bool();
0N/A
0N/A // Check bool sense
0N/A switch( bol->_test._test ) {
0N/A case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = true_path; break;
0N/A case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = false_path; break;
0N/A case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = true_path; break;
0N/A case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = false_path; break;
0N/A default: return NULL; break;
0N/A }
0N/A
0N/A // Test is next
0N/A Node *cmp = bol->in(1);
0N/A const Type *tzero = NULL;
0N/A switch( cmp->Opcode() ) {
0N/A case Op_CmpF: tzero = TypeF::ZERO; break; // Float ABS
0N/A case Op_CmpD: tzero = TypeD::ZERO; break; // Double ABS
0N/A default: return NULL;
0N/A }
0N/A
0N/A // Find zero input of compare; the other input is being abs'd
0N/A Node *x = NULL;
0N/A bool flip = false;
0N/A if( phase->type(cmp->in(cmp_zero_idx)) == tzero ) {
0N/A x = cmp->in(3 - cmp_zero_idx);
0N/A } else if( phase->type(cmp->in(3 - cmp_zero_idx)) == tzero ) {
0N/A // The test is inverted, we should invert the result...
0N/A x = cmp->in(cmp_zero_idx);
0N/A flip = true;
0N/A } else {
0N/A return NULL;
0N/A }
0N/A
0N/A // Next get the 2 pieces being selected, one is the original value
0N/A // and the other is the negated value.
0N/A if( phi_root->in(phi_x_idx) != x ) return NULL;
0N/A
0N/A // Check other phi input for subtract node
0N/A Node *sub = phi_root->in(3 - phi_x_idx);
0N/A
0N/A // Allow only Sub(0,X) and fail out for all others; Neg is not OK
0N/A if( tzero == TypeF::ZERO ) {
0N/A if( sub->Opcode() != Op_SubF ||
0N/A sub->in(2) != x ||
0N/A phase->type(sub->in(1)) != tzero ) return NULL;
4022N/A x = new (phase->C) AbsFNode(x);
0N/A if (flip) {
4022N/A x = new (phase->C) SubFNode(sub->in(1), phase->transform(x));
0N/A }
0N/A } else {
0N/A if( sub->Opcode() != Op_SubD ||
0N/A sub->in(2) != x ||
0N/A phase->type(sub->in(1)) != tzero ) return NULL;
4022N/A x = new (phase->C) AbsDNode(x);
0N/A if (flip) {
4022N/A x = new (phase->C) SubDNode(sub->in(1), phase->transform(x));
0N/A }
0N/A }
0N/A
0N/A return x;
0N/A}
0N/A
0N/A//------------------------------split_once-------------------------------------
0N/A// Helper for split_flow_path
0N/Astatic void split_once(PhaseIterGVN *igvn, Node *phi, Node *val, Node *n, Node *newn) {
0N/A igvn->hash_delete(n); // Remove from hash before hacking edges
0N/A
0N/A uint j = 1;
2292N/A for (uint i = phi->req()-1; i > 0; i--) {
2292N/A if (phi->in(i) == val) { // Found a path with val?
0N/A // Add to NEW Region/Phi, no DU info
0N/A newn->set_req( j++, n->in(i) );
0N/A // Remove from OLD Region/Phi
0N/A n->del_req(i);
0N/A }
0N/A }
0N/A
0N/A // Register the new node but do not transform it. Cannot transform until the
605N/A // entire Region/Phi conglomerate has been hacked as a single huge transform.
0N/A igvn->register_new_node_with_optimizer( newn );
2292N/A
0N/A // Now I can point to the new node.
0N/A n->add_req(newn);
0N/A igvn->_worklist.push(n);
0N/A}
0N/A
0N/A//------------------------------split_flow_path--------------------------------
0N/A// Check for merging identical values and split flow paths
0N/Astatic Node* split_flow_path(PhaseGVN *phase, PhiNode *phi) {
0N/A BasicType bt = phi->type()->basic_type();
0N/A if( bt == T_ILLEGAL || type2size[bt] <= 0 )
0N/A return NULL; // Bail out on funny non-value stuff
0N/A if( phi->req() <= 3 ) // Need at least 2 matched inputs and a
0N/A return NULL; // third unequal input to be worth doing
0N/A
0N/A // Scan for a constant
0N/A uint i;
0N/A for( i = 1; i < phi->req()-1; i++ ) {
0N/A Node *n = phi->in(i);
0N/A if( !n ) return NULL;
0N/A if( phase->type(n) == Type::TOP ) return NULL;
163N/A if( n->Opcode() == Op_ConP || n->Opcode() == Op_ConN )
0N/A break;
0N/A }
0N/A if( i >= phi->req() ) // Only split for constants
0N/A return NULL;
0N/A
0N/A Node *val = phi->in(i); // Constant to split for
0N/A uint hit = 0; // Number of times it occurs
2670N/A Node *r = phi->region();
0N/A
605N/A for( ; i < phi->req(); i++ ){ // Count occurrences of constant
0N/A Node *n = phi->in(i);
0N/A if( !n ) return NULL;
0N/A if( phase->type(n) == Type::TOP ) return NULL;
2670N/A if( phi->in(i) == val ) {
0N/A hit++;
2670N/A if (PhaseIdealLoop::find_predicate(r->in(i)) != NULL) {
2670N/A return NULL; // don't split loop entry path
2670N/A }
2670N/A }
0N/A }
0N/A
0N/A if( hit <= 1 || // Make sure we find 2 or more
0N/A hit == phi->req()-1 ) // and not ALL the same value
0N/A return NULL;
0N/A
0N/A // Now start splitting out the flow paths that merge the same value.
0N/A // Split first the RegionNode.
0N/A PhaseIterGVN *igvn = phase->is_IterGVN();
4022N/A RegionNode *newr = new (phase->C) RegionNode(hit+1);
0N/A split_once(igvn, phi, val, r, newr);
0N/A
0N/A // Now split all other Phis than this one
0N/A for (DUIterator_Fast kmax, k = r->fast_outs(kmax); k < kmax; k++) {
0N/A Node* phi2 = r->fast_out(k);
0N/A if( phi2->is_Phi() && phi2->as_Phi() != phi ) {
0N/A PhiNode *newphi = PhiNode::make_blank(newr, phi2);
0N/A split_once(igvn, phi, val, phi2, newphi);
0N/A }
0N/A }
0N/A
0N/A // Clean up this guy
0N/A igvn->hash_delete(phi);
0N/A for( i = phi->req()-1; i > 0; i-- ) {
0N/A if( phi->in(i) == val ) {
0N/A phi->del_req(i);
0N/A }
0N/A }
0N/A phi->add_req(val);
0N/A
0N/A return phi;
0N/A}
0N/A
0N/A//=============================================================================
0N/A//------------------------------simple_data_loop_check-------------------------
605N/A// Try to determining if the phi node in a simple safe/unsafe data loop.
0N/A// Returns:
0N/A// enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };
0N/A// Safe - safe case when the phi and it's inputs reference only safe data
0N/A// nodes;
0N/A// Unsafe - the phi and it's inputs reference unsafe data nodes but there
0N/A// is no reference back to the phi - need a graph walk
0N/A// to determine if it is in a loop;
0N/A// UnsafeLoop - unsafe case when the phi references itself directly or through
0N/A// unsafe data node.
0N/A// Note: a safe data node is a node which could/never reference itself during
0N/A// GVN transformations. For now it is Con, Proj, Phi, CastPP, CheckCastPP.
0N/A// I mark Phi nodes as safe node not only because they can reference itself
0N/A// but also to prevent mistaking the fallthrough case inside an outer loop
0N/A// as dead loop when the phi references itselfs through an other phi.
0N/APhiNode::LoopSafety PhiNode::simple_data_loop_check(Node *in) const {
0N/A // It is unsafe loop if the phi node references itself directly.
0N/A if (in == (Node*)this)
0N/A return UnsafeLoop; // Unsafe loop
0N/A // Unsafe loop if the phi node references itself through an unsafe data node.
0N/A // Exclude cases with null inputs or data nodes which could reference
0N/A // itself (safe for dead loops).
0N/A if (in != NULL && !in->is_dead_loop_safe()) {
0N/A // Check inputs of phi's inputs also.
0N/A // It is much less expensive then full graph walk.
0N/A uint cnt = in->req();
126N/A uint i = (in->is_Proj() && !in->is_CFG()) ? 0 : 1;
126N/A for (; i < cnt; ++i) {
0N/A Node* m = in->in(i);
0N/A if (m == (Node*)this)
0N/A return UnsafeLoop; // Unsafe loop
0N/A if (m != NULL && !m->is_dead_loop_safe()) {
0N/A // Check the most common case (about 30% of all cases):
0N/A // phi->Load/Store->AddP->(ConP ConP Con)/(Parm Parm Con).
0N/A Node *m1 = (m->is_AddP() && m->req() > 3) ? m->in(1) : NULL;
0N/A if (m1 == (Node*)this)
0N/A return UnsafeLoop; // Unsafe loop
0N/A if (m1 != NULL && m1 == m->in(2) &&
0N/A m1->is_dead_loop_safe() && m->in(3)->is_Con()) {
0N/A continue; // Safe case
0N/A }
0N/A // The phi references an unsafe node - need full analysis.
0N/A return Unsafe;
0N/A }
0N/A }
0N/A }
0N/A return Safe; // Safe case - we can optimize the phi node.
0N/A}
0N/A
0N/A//------------------------------is_unsafe_data_reference-----------------------
0N/A// If phi can be reached through the data input - it is data loop.
0N/Abool PhiNode::is_unsafe_data_reference(Node *in) const {
0N/A assert(req() > 1, "");
0N/A // First, check simple cases when phi references itself directly or
0N/A // through an other node.
0N/A LoopSafety safety = simple_data_loop_check(in);
0N/A if (safety == UnsafeLoop)
0N/A return true; // phi references itself - unsafe loop
0N/A else if (safety == Safe)
0N/A return false; // Safe case - phi could be replaced with the unique input.
0N/A
0N/A // Unsafe case when we should go through data graph to determine
0N/A // if the phi references itself.
0N/A
0N/A ResourceMark rm;
0N/A
0N/A Arena *a = Thread::current()->resource_area();
0N/A Node_List nstack(a);
0N/A VectorSet visited(a);
0N/A
0N/A nstack.push(in); // Start with unique input.
0N/A visited.set(in->_idx);
0N/A while (nstack.size() != 0) {
0N/A Node* n = nstack.pop();
0N/A uint cnt = n->req();
126N/A uint i = (n->is_Proj() && !n->is_CFG()) ? 0 : 1;
126N/A for (; i < cnt; i++) {
0N/A Node* m = n->in(i);
0N/A if (m == (Node*)this) {
0N/A return true; // Data loop
0N/A }
0N/A if (m != NULL && !m->is_dead_loop_safe()) { // Only look for unsafe cases.
0N/A if (!visited.test_set(m->_idx))
0N/A nstack.push(m);
0N/A }
0N/A }
0N/A }
0N/A return false; // The phi is not reachable from its inputs
0N/A}
0N/A
0N/A
0N/A//------------------------------Ideal------------------------------------------
0N/A// Return a node which is more "ideal" than the current node. Must preserve
0N/A// the CFG, but we can still strip out dead paths.
0N/ANode *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A // The next should never happen after 6297035 fix.
0N/A if( is_copy() ) // Already degraded to a Copy ?
0N/A return NULL; // No change
0N/A
0N/A Node *r = in(0); // RegionNode
0N/A assert(r->in(0) == NULL || !r->in(0)->is_Root(), "not a specially hidden merge");
0N/A
0N/A // Note: During parsing, phis are often transformed before their regions.
0N/A // This means we have to use type_or_null to defend against untyped regions.
0N/A if( phase->type_or_null(r) == Type::TOP ) // Dead code?
0N/A return NULL; // No change
0N/A
0N/A Node *top = phase->C->top();
1013N/A bool new_phi = (outcnt() == 0); // transforming new Phi
2496N/A // No change for igvn if new phi is not hooked
2496N/A if (new_phi && can_reshape)
2496N/A return NULL;
0N/A
0N/A // The are 2 situations when only one valid phi's input is left
0N/A // (in addition to Region input).
0N/A // One: region is not loop - replace phi with this input.
0N/A // Two: region is loop - replace phi with top since this data path is dead
0N/A // and we need to break the dead data loop.
0N/A Node* progress = NULL; // Record if any progress made
0N/A for( uint j = 1; j < req(); ++j ){ // For all paths in
0N/A // Check unreachable control paths
0N/A Node* rc = r->in(j);
0N/A Node* n = in(j); // Get the input
0N/A if (rc == NULL || phase->type(rc) == Type::TOP) {
0N/A if (n != top) { // Not already top?
4127N/A PhaseIterGVN *igvn = phase->is_IterGVN();
4127N/A if (can_reshape && igvn != NULL) {
4127N/A igvn->_worklist.push(r);
4127N/A }
0N/A set_req(j, top); // Nuke it down
0N/A progress = this; // Record progress
0N/A }
0N/A }
0N/A }
0N/A
1013N/A if (can_reshape && outcnt() == 0) {
1013N/A // set_req() above may kill outputs if Phi is referenced
1013N/A // only by itself on the dead (top) control path.
1013N/A return top;
1013N/A }
1013N/A
0N/A Node* uin = unique_input(phase);
0N/A if (uin == top) { // Simplest case: no alive inputs.
0N/A if (can_reshape) // IGVN transformation
0N/A return top;
0N/A else
0N/A return NULL; // Identity will return TOP
0N/A } else if (uin != NULL) {
0N/A // Only one not-NULL unique input path is left.
0N/A // Determine if this input is backedge of a loop.
0N/A // (Skip new phis which have no uses and dead regions).
2956N/A if (outcnt() > 0 && r->in(0) != NULL) {
0N/A // First, take the short cut when we know it is a loop and
0N/A // the EntryControl data path is dead.
2956N/A // Loop node may have only one input because entry path
2956N/A // is removed in PhaseIdealLoop::Dominators().
2956N/A assert(!r->is_Loop() || r->req() <= 3, "Loop node should have 3 or less inputs");
2956N/A bool is_loop = (r->is_Loop() && r->req() == 3);
0N/A // Then, check if there is a data loop when phi references itself directly
0N/A // or through other data nodes.
3058N/A if (is_loop && !uin->eqv_uncast(in(LoopNode::EntryControl)) ||
2956N/A !is_loop && is_unsafe_data_reference(uin)) {
0N/A // Break this data loop to avoid creation of a dead loop.
0N/A if (can_reshape) {
0N/A return top;
0N/A } else {
0N/A // We can't return top if we are in Parse phase - cut inputs only
0N/A // let Identity to handle the case.
0N/A replace_edge(uin, top);
0N/A return NULL;
0N/A }
0N/A }
0N/A }
0N/A
0N/A // One unique input.
0N/A debug_only(Node* ident = Identity(phase));
0N/A // The unique input must eventually be detected by the Identity call.
0N/A#ifdef ASSERT
0N/A if (ident != uin && !ident->is_top()) {
0N/A // print this output before failing assert
0N/A r->dump(3);
0N/A this->dump(3);
0N/A ident->dump();
0N/A uin->dump();
0N/A }
0N/A#endif
0N/A assert(ident == uin || ident->is_top(), "Identity must clean this up");
0N/A return NULL;
0N/A }
0N/A
0N/A
0N/A Node* opt = NULL;
0N/A int true_path = is_diamond_phi();
0N/A if( true_path != 0 ) {
0N/A // Check for CMove'ing identity. If it would be unsafe,
0N/A // handle it here. In the safe case, let Identity handle it.
0N/A Node* unsafe_id = is_cmove_id(phase, true_path);
0N/A if( unsafe_id != NULL && is_unsafe_data_reference(unsafe_id) )
0N/A opt = unsafe_id;
0N/A
0N/A // Check for simple convert-to-boolean pattern
0N/A if( opt == NULL )
0N/A opt = is_x2logic(phase, this, true_path);
0N/A
0N/A // Check for absolute value
0N/A if( opt == NULL )
0N/A opt = is_absolute(phase, this, true_path);
0N/A
0N/A // Check for conditional add
0N/A if( opt == NULL && can_reshape )
0N/A opt = is_cond_add(phase, this, true_path);
0N/A
0N/A // These 4 optimizations could subsume the phi:
0N/A // have to check for a dead data loop creation.
0N/A if( opt != NULL ) {
0N/A if( opt == unsafe_id || is_unsafe_data_reference(opt) ) {
0N/A // Found dead loop.
0N/A if( can_reshape )
0N/A return top;
0N/A // We can't return top if we are in Parse phase - cut inputs only
0N/A // to stop further optimizations for this phi. Identity will return TOP.
0N/A assert(req() == 3, "only diamond merge phi here");
0N/A set_req(1, top);
0N/A set_req(2, top);
0N/A return NULL;
0N/A } else {
0N/A return opt;
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Check for merging identical values and split flow paths
0N/A if (can_reshape) {
0N/A opt = split_flow_path(phase, this);
0N/A // This optimization only modifies phi - don't need to check for dead loop.
0N/A assert(opt == NULL || phase->eqv(opt, this), "do not elide phi");
0N/A if (opt != NULL) return opt;
0N/A }
0N/A
1462N/A if (in(1) != NULL && in(1)->Opcode() == Op_AddP && can_reshape) {
1462N/A // Try to undo Phi of AddP:
1462N/A // (Phi (AddP base base y) (AddP base2 base2 y))
1462N/A // becomes:
1462N/A // newbase := (Phi base base2)
1462N/A // (AddP newbase newbase y)
1462N/A //
1462N/A // This occurs as a result of unsuccessful split_thru_phi and
1462N/A // interferes with taking advantage of addressing modes. See the
1462N/A // clone_shift_expressions code in matcher.cpp
1462N/A Node* addp = in(1);
1462N/A const Type* type = addp->in(AddPNode::Base)->bottom_type();
1462N/A Node* y = addp->in(AddPNode::Offset);
1462N/A if (y != NULL && addp->in(AddPNode::Base) == addp->in(AddPNode::Address)) {
1462N/A // make sure that all the inputs are similar to the first one,
1462N/A // i.e. AddP with base == address and same offset as first AddP
1462N/A bool doit = true;
1462N/A for (uint i = 2; i < req(); i++) {
1462N/A if (in(i) == NULL ||
1462N/A in(i)->Opcode() != Op_AddP ||
1462N/A in(i)->in(AddPNode::Base) != in(i)->in(AddPNode::Address) ||
1462N/A in(i)->in(AddPNode::Offset) != y) {
1462N/A doit = false;
1462N/A break;
1462N/A }
1462N/A // Accumulate type for resulting Phi
1462N/A type = type->meet(in(i)->in(AddPNode::Base)->bottom_type());
1462N/A }
1462N/A Node* base = NULL;
1462N/A if (doit) {
1462N/A // Check for neighboring AddP nodes in a tree.
1462N/A // If they have a base, use that it.
1462N/A for (DUIterator_Fast kmax, k = this->fast_outs(kmax); k < kmax; k++) {
1462N/A Node* u = this->fast_out(k);
1462N/A if (u->is_AddP()) {
1462N/A Node* base2 = u->in(AddPNode::Base);
1462N/A if (base2 != NULL && !base2->is_top()) {
1462N/A if (base == NULL)
1462N/A base = base2;
1462N/A else if (base != base2)
1462N/A { doit = false; break; }
1462N/A }
1462N/A }
1462N/A }
1462N/A }
1462N/A if (doit) {
1462N/A if (base == NULL) {
4022N/A base = new (phase->C) PhiNode(in(0), type, NULL);
1462N/A for (uint i = 1; i < req(); i++) {
1462N/A base->init_req(i, in(i)->in(AddPNode::Base));
1462N/A }
1462N/A phase->is_IterGVN()->register_new_node_with_optimizer(base);
1462N/A }
4022N/A return new (phase->C) AddPNode(base, base, y);
1462N/A }
1462N/A }
1462N/A }
1462N/A
0N/A // Split phis through memory merges, so that the memory merges will go away.
0N/A // Piggy-back this transformation on the search for a unique input....
0N/A // It will be as if the merged memory is the unique value of the phi.
0N/A // (Do not attempt this optimization unless parsing is complete.
0N/A // It would make the parser's memory-merge logic sick.)
0N/A // (MergeMemNode is not dead_loop_safe - need to check for dead loop.)
0N/A if (progress == NULL && can_reshape && type() == Type::MEMORY) {
0N/A // see if this phi should be sliced
0N/A uint merge_width = 0;
0N/A bool saw_self = false;
0N/A for( uint i=1; i<req(); ++i ) {// For all paths in
0N/A Node *ii = in(i);
0N/A if (ii->is_MergeMem()) {
0N/A MergeMemNode* n = ii->as_MergeMem();
0N/A merge_width = MAX2(merge_width, n->req());
0N/A saw_self = saw_self || phase->eqv(n->base_memory(), this);
0N/A }
0N/A }
0N/A
0N/A // This restriction is temporarily necessary to ensure termination:
0N/A if (!saw_self && adr_type() == TypePtr::BOTTOM) merge_width = 0;
0N/A
0N/A if (merge_width > Compile::AliasIdxRaw) {
0N/A // found at least one non-empty MergeMem
0N/A const TypePtr* at = adr_type();
0N/A if (at != TypePtr::BOTTOM) {
0N/A // Patch the existing phi to select an input from the merge:
0N/A // Phi:AT1(...MergeMem(m0, m1, m2)...) into
0N/A // Phi:AT1(...m1...)
0N/A int alias_idx = phase->C->get_alias_index(at);
0N/A for (uint i=1; i<req(); ++i) {
0N/A Node *ii = in(i);
0N/A if (ii->is_MergeMem()) {
0N/A MergeMemNode* n = ii->as_MergeMem();
0N/A // compress paths and change unreachable cycles to TOP
0N/A // If not, we can update the input infinitely along a MergeMem cycle
0N/A // Equivalent code is in MemNode::Ideal_common
367N/A Node *m = phase->transform(n);
367N/A if (outcnt() == 0) { // Above transform() may kill us!
1013N/A return top;
367N/A }
605N/A // If transformed to a MergeMem, get the desired slice
0N/A // Otherwise the returned node represents memory for every slice
0N/A Node *new_mem = (m->is_MergeMem()) ?
0N/A m->as_MergeMem()->memory_at(alias_idx) : m;
0N/A // Update input if it is progress over what we have now
0N/A if (new_mem != ii) {
0N/A set_req(i, new_mem);
0N/A progress = this;
0N/A }
0N/A }
0N/A }
0N/A } else {
0N/A // We know that at least one MergeMem->base_memory() == this
0N/A // (saw_self == true). If all other inputs also references this phi
0N/A // (directly or through data nodes) - it is dead loop.
0N/A bool saw_safe_input = false;
0N/A for (uint j = 1; j < req(); ++j) {
0N/A Node *n = in(j);
0N/A if (n->is_MergeMem() && n->as_MergeMem()->base_memory() == this)
0N/A continue; // skip known cases
0N/A if (!is_unsafe_data_reference(n)) {
0N/A saw_safe_input = true; // found safe input
0N/A break;
0N/A }
0N/A }
0N/A if (!saw_safe_input)
0N/A return top; // all inputs reference back to this phi - dead loop
0N/A
0N/A // Phi(...MergeMem(m0, m1:AT1, m2:AT2)...) into
0N/A // MergeMem(Phi(...m0...), Phi:AT1(...m1...), Phi:AT2(...m2...))
0N/A PhaseIterGVN *igvn = phase->is_IterGVN();
4022N/A Node* hook = new (phase->C) Node(1);
0N/A PhiNode* new_base = (PhiNode*) clone();
0N/A // Must eagerly register phis, since they participate in loops.
0N/A if (igvn) {
0N/A igvn->register_new_node_with_optimizer(new_base);
0N/A hook->add_req(new_base);
0N/A }
0N/A MergeMemNode* result = MergeMemNode::make(phase->C, new_base);
0N/A for (uint i = 1; i < req(); ++i) {
0N/A Node *ii = in(i);
0N/A if (ii->is_MergeMem()) {
0N/A MergeMemNode* n = ii->as_MergeMem();
0N/A for (MergeMemStream mms(result, n); mms.next_non_empty2(); ) {
0N/A // If we have not seen this slice yet, make a phi for it.
0N/A bool made_new_phi = false;
0N/A if (mms.is_empty()) {
0N/A Node* new_phi = new_base->slice_memory(mms.adr_type(phase->C));
0N/A made_new_phi = true;
0N/A if (igvn) {
0N/A igvn->register_new_node_with_optimizer(new_phi);
0N/A hook->add_req(new_phi);
0N/A }
0N/A mms.set_memory(new_phi);
0N/A }
0N/A Node* phi = mms.memory();
0N/A assert(made_new_phi || phi->in(i) == n, "replace the i-th merge by a slice");
0N/A phi->set_req(i, mms.memory2());
0N/A }
0N/A }
0N/A }
0N/A // Distribute all self-loops.
0N/A { // (Extra braces to hide mms.)
0N/A for (MergeMemStream mms(result); mms.next_non_empty(); ) {
0N/A Node* phi = mms.memory();
0N/A for (uint i = 1; i < req(); ++i) {
0N/A if (phi->in(i) == this) phi->set_req(i, phi);
0N/A }
0N/A }
0N/A }
0N/A // now transform the new nodes, and return the mergemem
0N/A for (MergeMemStream mms(result); mms.next_non_empty(); ) {
0N/A Node* phi = mms.memory();
0N/A mms.set_memory(phase->transform(phi));
0N/A }
0N/A if (igvn) { // Unhook.
0N/A igvn->hash_delete(hook);
0N/A for (uint i = 1; i < hook->req(); i++) {
0N/A hook->set_req(i, NULL);
0N/A }
0N/A }
0N/A // Replace self with the result.
0N/A return result;
0N/A }
0N/A }
74N/A //
74N/A // Other optimizations on the memory chain
74N/A //
74N/A const TypePtr* at = adr_type();
74N/A for( uint i=1; i<req(); ++i ) {// For all paths in
74N/A Node *ii = in(i);
74N/A Node *new_in = MemNode::optimize_memory_chain(ii, at, phase);
74N/A if (ii != new_in ) {
74N/A set_req(i, new_in);
74N/A progress = this;
74N/A }
74N/A }
0N/A }
0N/A
368N/A#ifdef _LP64
368N/A // Push DecodeN down through phi.
368N/A // The rest of phi graph will transform by split EncodeP node though phis up.
368N/A if (UseCompressedOops && can_reshape && progress == NULL) {
368N/A bool may_push = true;
368N/A bool has_decodeN = false;
368N/A for (uint i=1; i<req(); ++i) {// For all paths in
368N/A Node *ii = in(i);
368N/A if (ii->is_DecodeN() && ii->bottom_type() == bottom_type()) {
899N/A // Do optimization if a non dead path exist.
853N/A if (ii->in(1)->bottom_type() != Type::TOP) {
853N/A has_decodeN = true;
853N/A }
368N/A } else if (!ii->is_Phi()) {
368N/A may_push = false;
368N/A }
368N/A }
368N/A
368N/A if (has_decodeN && may_push) {
368N/A PhaseIterGVN *igvn = phase->is_IterGVN();
899N/A // Make narrow type for new phi.
899N/A const Type* narrow_t = TypeNarrowOop::make(this->bottom_type()->is_ptr());
4022N/A PhiNode* new_phi = new (phase->C) PhiNode(r, narrow_t);
368N/A uint orig_cnt = req();
368N/A for (uint i=1; i<req(); ++i) {// For all paths in
368N/A Node *ii = in(i);
368N/A Node* new_ii = NULL;
368N/A if (ii->is_DecodeN()) {
368N/A assert(ii->bottom_type() == bottom_type(), "sanity");
368N/A new_ii = ii->in(1);
368N/A } else {
368N/A assert(ii->is_Phi(), "sanity");
368N/A if (ii->as_Phi() == this) {
368N/A new_ii = new_phi;
368N/A } else {
4022N/A new_ii = new (phase->C) EncodePNode(ii, narrow_t);
368N/A igvn->register_new_node_with_optimizer(new_ii);
368N/A }
368N/A }
368N/A new_phi->set_req(i, new_ii);
368N/A }
368N/A igvn->register_new_node_with_optimizer(new_phi, this);
4022N/A progress = new (phase->C) DecodeNNode(new_phi, bottom_type());
368N/A }
368N/A }
368N/A#endif
368N/A
0N/A return progress; // Return any progress
0N/A}
0N/A
400N/A//------------------------------is_tripcount-----------------------------------
400N/Abool PhiNode::is_tripcount() const {
400N/A return (in(0) != NULL && in(0)->is_CountedLoop() &&
400N/A in(0)->as_CountedLoop()->phi() == this);
400N/A}
400N/A
0N/A//------------------------------out_RegMask------------------------------------
0N/Aconst RegMask &PhiNode::in_RegMask(uint i) const {
0N/A return i ? out_RegMask() : RegMask::Empty;
0N/A}
0N/A
0N/Aconst RegMask &PhiNode::out_RegMask() const {
0N/A uint ideal_reg = Matcher::base2reg[_type->base()];
0N/A assert( ideal_reg != Node::NotAMachineReg, "invalid type at Phi" );
0N/A if( ideal_reg == 0 ) return RegMask::Empty;
0N/A return *(Compile::current()->matcher()->idealreg2spillmask[ideal_reg]);
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid PhiNode::dump_spec(outputStream *st) const {
0N/A TypeNode::dump_spec(st);
400N/A if (is_tripcount()) {
0N/A st->print(" #tripcount");
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A
0N/A//=============================================================================
0N/Aconst Type *GotoNode::Value( PhaseTransform *phase ) const {
0N/A // If the input is reachable, then we are executed.
0N/A // If the input is not reachable, then we are not executed.
0N/A return phase->type(in(0));
0N/A}
0N/A
0N/ANode *GotoNode::Identity( PhaseTransform *phase ) {
0N/A return in(0); // Simple copy of incoming control
0N/A}
0N/A
0N/Aconst RegMask &GotoNode::out_RegMask() const {
0N/A return RegMask::Empty;
0N/A}
0N/A
0N/A//=============================================================================
0N/Aconst RegMask &JumpNode::out_RegMask() const {
0N/A return RegMask::Empty;
0N/A}
0N/A
0N/A//=============================================================================
0N/Aconst RegMask &JProjNode::out_RegMask() const {
0N/A return RegMask::Empty;
0N/A}
0N/A
0N/A//=============================================================================
0N/Aconst RegMask &CProjNode::out_RegMask() const {
0N/A return RegMask::Empty;
0N/A}
0N/A
0N/A
0N/A
0N/A//=============================================================================
0N/A
0N/Auint PCTableNode::hash() const { return Node::hash() + _size; }
0N/Auint PCTableNode::cmp( const Node &n ) const
0N/A{ return _size == ((PCTableNode&)n)._size; }
0N/A
0N/Aconst Type *PCTableNode::bottom_type() const {
0N/A const Type** f = TypeTuple::fields(_size);
0N/A for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;
0N/A return TypeTuple::make(_size, f);
0N/A}
0N/A
0N/A//------------------------------Value------------------------------------------
0N/A// Compute the type of the PCTableNode. If reachable it is a tuple of
0N/A// Control, otherwise the table targets are not reachable
0N/Aconst Type *PCTableNode::Value( PhaseTransform *phase ) const {
0N/A if( phase->type(in(0)) == Type::CONTROL )
0N/A return bottom_type();
0N/A return Type::TOP; // All paths dead? Then so are we
0N/A}
0N/A
0N/A//------------------------------Ideal------------------------------------------
0N/A// Return a node which is more "ideal" than the current node. Strip out
0N/A// control copies
0N/ANode *PCTableNode::Ideal(PhaseGVN *phase, bool can_reshape) {
0N/A return remove_dead_region(phase, can_reshape) ? this : NULL;
0N/A}
0N/A
0N/A//=============================================================================
0N/Auint JumpProjNode::hash() const {
0N/A return Node::hash() + _dest_bci;
0N/A}
0N/A
0N/Auint JumpProjNode::cmp( const Node &n ) const {
0N/A return ProjNode::cmp(n) &&
0N/A _dest_bci == ((JumpProjNode&)n)._dest_bci;
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid JumpProjNode::dump_spec(outputStream *st) const {
0N/A ProjNode::dump_spec(st);
0N/A st->print("@bci %d ",_dest_bci);
0N/A}
0N/A#endif
0N/A
0N/A//=============================================================================
0N/A//------------------------------Value------------------------------------------
0N/A// Check for being unreachable, or for coming from a Rethrow. Rethrow's cannot
0N/A// have the default "fall_through_index" path.
0N/Aconst Type *CatchNode::Value( PhaseTransform *phase ) const {
0N/A // Unreachable? Then so are all paths from here.
0N/A if( phase->type(in(0)) == Type::TOP ) return Type::TOP;
0N/A // First assume all paths are reachable
0N/A const Type** f = TypeTuple::fields(_size);
0N/A for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;
0N/A // Identify cases that will always throw an exception
0N/A // () rethrow call
0N/A // () virtual or interface call with NULL receiver
0N/A // () call is a check cast with incompatible arguments
0N/A if( in(1)->is_Proj() ) {
0N/A Node *i10 = in(1)->in(0);
0N/A if( i10->is_Call() ) {
0N/A CallNode *call = i10->as_Call();
0N/A // Rethrows always throw exceptions, never return
0N/A if (call->entry_point() == OptoRuntime::rethrow_stub()) {
0N/A f[CatchProjNode::fall_through_index] = Type::TOP;
0N/A } else if( call->req() > TypeFunc::Parms ) {
0N/A const Type *arg0 = phase->type( call->in(TypeFunc::Parms) );
605N/A // Check for null receiver to virtual or interface calls
0N/A if( call->is_CallDynamicJava() &&
0N/A arg0->higher_equal(TypePtr::NULL_PTR) ) {
0N/A f[CatchProjNode::fall_through_index] = Type::TOP;
0N/A }
0N/A } // End of if not a runtime stub
0N/A } // End of if have call above me
0N/A } // End of slot 1 is not a projection
0N/A return TypeTuple::make(_size, f);
0N/A}
0N/A
0N/A//=============================================================================
0N/Auint CatchProjNode::hash() const {
0N/A return Node::hash() + _handler_bci;
0N/A}
0N/A
0N/A
0N/Auint CatchProjNode::cmp( const Node &n ) const {
0N/A return ProjNode::cmp(n) &&
0N/A _handler_bci == ((CatchProjNode&)n)._handler_bci;
0N/A}
0N/A
0N/A
0N/A//------------------------------Identity---------------------------------------
0N/A// If only 1 target is possible, choose it if it is the main control
0N/ANode *CatchProjNode::Identity( PhaseTransform *phase ) {
0N/A // If my value is control and no other value is, then treat as ID
0N/A const TypeTuple *t = phase->type(in(0))->is_tuple();
0N/A if (t->field_at(_con) != Type::CONTROL) return this;
0N/A // If we remove the last CatchProj and elide the Catch/CatchProj, then we
0N/A // also remove any exception table entry. Thus we must know the call
0N/A // feeding the Catch will not really throw an exception. This is ok for
0N/A // the main fall-thru control (happens when we know a call can never throw
605N/A // an exception) or for "rethrow", because a further optimization will
0N/A // yank the rethrow (happens when we inline a function that can throw an
0N/A // exception and the caller has no handler). Not legal, e.g., for passing
0N/A // a NULL receiver to a v-call, or passing bad types to a slow-check-cast.
0N/A // These cases MUST throw an exception via the runtime system, so the VM
0N/A // will be looking for a table entry.
0N/A Node *proj = in(0)->in(1); // Expect a proj feeding CatchNode
0N/A CallNode *call;
0N/A if (_con != TypeFunc::Control && // Bail out if not the main control.
0N/A !(proj->is_Proj() && // AND NOT a rethrow
0N/A proj->in(0)->is_Call() &&
0N/A (call = proj->in(0)->as_Call()) &&
0N/A call->entry_point() == OptoRuntime::rethrow_stub()))
0N/A return this;
0N/A
0N/A // Search for any other path being control
0N/A for (uint i = 0; i < t->cnt(); i++) {
0N/A if (i != _con && t->field_at(i) == Type::CONTROL)
0N/A return this;
0N/A }
0N/A // Only my path is possible; I am identity on control to the jump
0N/A return in(0)->in(0);
0N/A}
0N/A
0N/A
0N/A#ifndef PRODUCT
0N/Avoid CatchProjNode::dump_spec(outputStream *st) const {
0N/A ProjNode::dump_spec(st);
0N/A st->print("@bci %d ",_handler_bci);
0N/A}
0N/A#endif
0N/A
0N/A//=============================================================================
0N/A//------------------------------Identity---------------------------------------
0N/A// Check for CreateEx being Identity.
0N/ANode *CreateExNode::Identity( PhaseTransform *phase ) {
0N/A if( phase->type(in(1)) == Type::TOP ) return in(1);
0N/A if( phase->type(in(0)) == Type::TOP ) return in(0);
0N/A // We only come from CatchProj, unless the CatchProj goes away.
0N/A // If the CatchProj is optimized away, then we just carry the
0N/A // exception oop through.
0N/A CallNode *call = in(1)->in(0)->as_Call();
0N/A
0N/A return ( in(0)->is_CatchProj() && in(0)->in(0)->in(1) == in(1) )
0N/A ? this
0N/A : call->in(TypeFunc::Parms);
0N/A}
0N/A
0N/A//=============================================================================
127N/A//------------------------------Value------------------------------------------
127N/A// Check for being unreachable.
127N/Aconst Type *NeverBranchNode::Value( PhaseTransform *phase ) const {
127N/A if (!in(0) || in(0)->is_top()) return Type::TOP;
127N/A return bottom_type();
127N/A}
127N/A
127N/A//------------------------------Ideal------------------------------------------
127N/A// Check for no longer being part of a loop
127N/ANode *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) {
127N/A if (can_reshape && !in(0)->is_Loop()) {
127N/A // Dead code elimination can sometimes delete this projection so
127N/A // if it's not there, there's nothing to do.
127N/A Node* fallthru = proj_out(0);
127N/A if (fallthru != NULL) {
1541N/A phase->is_IterGVN()->replace_node(fallthru, in(0));
127N/A }
127N/A return phase->C->top();
127N/A }
127N/A return NULL;
127N/A}
127N/A
0N/A#ifndef PRODUCT
0N/Avoid NeverBranchNode::format( PhaseRegAlloc *ra_, outputStream *st) const {
0N/A st->print("%s", Name());
0N/A}
0N/A#endif