Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/opto/cfgnode.cpp
83404 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/systemDictionary.hpp"26#include "memory/allocation.inline.hpp"27#include "oops/objArrayKlass.hpp"28#include "opto/addnode.hpp"29#include "opto/cfgnode.hpp"30#include "opto/connode.hpp"31#include "opto/loopnode.hpp"32#include "opto/machnode.hpp"33#include "opto/mulnode.hpp"34#include "opto/phaseX.hpp"35#include "opto/regmask.hpp"36#include "opto/runtime.hpp"37#include "opto/subnode.hpp"3839// Portions of code courtesy of Clifford Click4041// Optimization - Graph Style4243//=============================================================================44//------------------------------Value------------------------------------------45// Compute the type of the RegionNode.46const Type *RegionNode::Value( PhaseTransform *phase ) const {47for( uint i=1; i<req(); ++i ) { // For all paths in48Node *n = in(i); // Get Control source49if( !n ) continue; // Missing inputs are TOP50if( phase->type(n) == Type::CONTROL )51return Type::CONTROL;52}53return Type::TOP; // All paths dead? Then so are we54}5556//------------------------------Identity---------------------------------------57// Check for Region being Identity.58Node *RegionNode::Identity( PhaseTransform *phase ) {59// Cannot have Region be an identity, even if it has only 1 input.60// Phi users cannot have their Region input folded away for them,61// since they need to select the proper data input62return this;63}6465//------------------------------merge_region-----------------------------------66// If a Region flows into a Region, merge into one big happy merge. This is67// hard to do if there is stuff that has to happen68static Node *merge_region(RegionNode *region, PhaseGVN *phase) {69if( region->Opcode() != Op_Region ) // Do not do to LoopNodes70return NULL;71Node *progress = NULL; // Progress flag72PhaseIterGVN *igvn = phase->is_IterGVN();7374uint rreq = region->req();75for( uint i = 1; i < rreq; i++ ) {76Node *r = region->in(i);77if( r && r->Opcode() == Op_Region && // Found a region?78r->in(0) == r && // Not already collapsed?79r != region && // Avoid stupid situations80r->outcnt() == 2 ) { // Self user and 'region' user only?81assert(!r->as_Region()->has_phi(), "no phi users");82if( !progress ) { // No progress83if (region->has_phi()) {84return NULL; // Only flatten if no Phi users85// igvn->hash_delete( phi );86}87igvn->hash_delete( region );88progress = region; // Making progress89}90igvn->hash_delete( r );9192// Append inputs to 'r' onto 'region'93for( uint j = 1; j < r->req(); j++ ) {94// Move an input from 'r' to 'region'95region->add_req(r->in(j));96r->set_req(j, phase->C->top());97// Update phis of 'region'98//for( uint k = 0; k < max; k++ ) {99// Node *phi = region->out(k);100// if( phi->is_Phi() ) {101// phi->add_req(phi->in(i));102// }103//}104105rreq++; // One more input to Region106} // Found a region to merge into Region107// Clobber pointer to the now dead 'r'108region->set_req(i, phase->C->top());109}110}111112return progress;113}114115116117//--------------------------------has_phi--------------------------------------118// Helper function: Return any PhiNode that uses this region or NULL119PhiNode* RegionNode::has_phi() const {120for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {121Node* phi = fast_out(i);122if (phi->is_Phi()) { // Check for Phi users123assert(phi->in(0) == (Node*)this, "phi uses region only via in(0)");124return phi->as_Phi(); // this one is good enough125}126}127128return NULL;129}130131132//-----------------------------has_unique_phi----------------------------------133// Helper function: Return the only PhiNode that uses this region or NULL134PhiNode* RegionNode::has_unique_phi() const {135// Check that only one use is a Phi136PhiNode* only_phi = NULL;137for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {138Node* phi = fast_out(i);139if (phi->is_Phi()) { // Check for Phi users140assert(phi->in(0) == (Node*)this, "phi uses region only via in(0)");141if (only_phi == NULL) {142only_phi = phi->as_Phi();143} else {144return NULL; // multiple phis145}146}147}148149return only_phi;150}151152153//------------------------------check_phi_clipping-----------------------------154// Helper function for RegionNode's identification of FP clipping155// Check inputs to the Phi156static bool check_phi_clipping( PhiNode *phi, ConNode * &min, uint &min_idx, ConNode * &max, uint &max_idx, Node * &val, uint &val_idx ) {157min = NULL;158max = NULL;159val = NULL;160min_idx = 0;161max_idx = 0;162val_idx = 0;163uint phi_max = phi->req();164if( phi_max == 4 ) {165for( uint j = 1; j < phi_max; ++j ) {166Node *n = phi->in(j);167int opcode = n->Opcode();168switch( opcode ) {169case Op_ConI:170{171if( min == NULL ) {172min = n->Opcode() == Op_ConI ? (ConNode*)n : NULL;173min_idx = j;174} else {175max = n->Opcode() == Op_ConI ? (ConNode*)n : NULL;176max_idx = j;177if( min->get_int() > max->get_int() ) {178// Swap min and max179ConNode *temp;180uint temp_idx;181temp = min; min = max; max = temp;182temp_idx = min_idx; min_idx = max_idx; max_idx = temp_idx;183}184}185}186break;187default:188{189val = n;190val_idx = j;191}192break;193}194}195}196return ( min && max && val && (min->get_int() <= 0) && (max->get_int() >=0) );197}198199200//------------------------------check_if_clipping------------------------------201// Helper function for RegionNode's identification of FP clipping202// Check that inputs to Region come from two IfNodes,203//204// If205// False True206// If |207// False True |208// | | |209// RegionNode_inputs210//211static bool check_if_clipping( const RegionNode *region, IfNode * &bot_if, IfNode * &top_if ) {212top_if = NULL;213bot_if = NULL;214215// Check control structure above RegionNode for (if ( if ) )216Node *in1 = region->in(1);217Node *in2 = region->in(2);218Node *in3 = region->in(3);219// Check that all inputs are projections220if( in1->is_Proj() && in2->is_Proj() && in3->is_Proj() ) {221Node *in10 = in1->in(0);222Node *in20 = in2->in(0);223Node *in30 = in3->in(0);224// Check that #1 and #2 are ifTrue and ifFalse from same If225if( in10 != NULL && in10->is_If() &&226in20 != NULL && in20->is_If() &&227in30 != NULL && in30->is_If() && in10 == in20 &&228(in1->Opcode() != in2->Opcode()) ) {229Node *in100 = in10->in(0);230Node *in1000 = (in100 != NULL && in100->is_Proj()) ? in100->in(0) : NULL;231// Check that control for in10 comes from other branch of IF from in3232if( in1000 != NULL && in1000->is_If() &&233in30 == in1000 && (in3->Opcode() != in100->Opcode()) ) {234// Control pattern checks235top_if = (IfNode*)in1000;236bot_if = (IfNode*)in10;237}238}239}240241return (top_if != NULL);242}243244245//------------------------------check_convf2i_clipping-------------------------246// Helper function for RegionNode's identification of FP clipping247// Verify that the value input to the phi comes from "ConvF2I; LShift; RShift"248static bool check_convf2i_clipping( PhiNode *phi, uint idx, ConvF2INode * &convf2i, Node *min, Node *max) {249convf2i = NULL;250251// Check for the RShiftNode252Node *rshift = phi->in(idx);253assert( rshift, "Previous checks ensure phi input is present");254if( rshift->Opcode() != Op_RShiftI ) { return false; }255256// Check for the LShiftNode257Node *lshift = rshift->in(1);258assert( lshift, "Previous checks ensure phi input is present");259if( lshift->Opcode() != Op_LShiftI ) { return false; }260261// Check for the ConvF2INode262Node *conv = lshift->in(1);263if( conv->Opcode() != Op_ConvF2I ) { return false; }264265// Check that shift amounts are only to get sign bits set after F2I266jint max_cutoff = max->get_int();267jint min_cutoff = min->get_int();268jint left_shift = lshift->in(2)->get_int();269jint right_shift = rshift->in(2)->get_int();270jint max_post_shift = nth_bit(BitsPerJavaInteger - left_shift - 1);271if( left_shift != right_shift ||2720 > left_shift || left_shift >= BitsPerJavaInteger ||273max_post_shift < max_cutoff ||274max_post_shift < -min_cutoff ) {275// Shifts are necessary but current transformation eliminates them276return false;277}278279// OK to return the result of ConvF2I without shifting280convf2i = (ConvF2INode*)conv;281return true;282}283284285//------------------------------check_compare_clipping-------------------------286// Helper function for RegionNode's identification of FP clipping287static bool check_compare_clipping( bool less_than, IfNode *iff, ConNode *limit, Node * & input ) {288Node *i1 = iff->in(1);289if ( !i1->is_Bool() ) { return false; }290BoolNode *bool1 = i1->as_Bool();291if( less_than && bool1->_test._test != BoolTest::le ) { return false; }292else if( !less_than && bool1->_test._test != BoolTest::lt ) { return false; }293const Node *cmpF = bool1->in(1);294if( cmpF->Opcode() != Op_CmpF ) { return false; }295// Test that the float value being compared against296// is equivalent to the int value used as a limit297Node *nodef = cmpF->in(2);298if( nodef->Opcode() != Op_ConF ) { return false; }299jfloat conf = nodef->getf();300jint coni = limit->get_int();301if( ((int)conf) != coni ) { return false; }302input = cmpF->in(1);303return true;304}305306//------------------------------is_unreachable_region--------------------------307// Find if the Region node is reachable from the root.308bool RegionNode::is_unreachable_region(PhaseGVN *phase) const {309assert(req() == 2, "");310311// First, cut the simple case of fallthrough region when NONE of312// region's phis references itself directly or through a data node.313uint max = outcnt();314uint i;315for (i = 0; i < max; i++) {316Node* phi = raw_out(i);317if (phi != NULL && phi->is_Phi()) {318assert(phase->eqv(phi->in(0), this) && phi->req() == 2, "");319if (phi->outcnt() == 0)320continue; // Safe case - no loops321if (phi->outcnt() == 1) {322Node* u = phi->raw_out(0);323// Skip if only one use is an other Phi or Call or Uncommon trap.324// It is safe to consider this case as fallthrough.325if (u != NULL && (u->is_Phi() || u->is_CFG()))326continue;327}328// Check when phi references itself directly or through an other node.329if (phi->as_Phi()->simple_data_loop_check(phi->in(1)) >= PhiNode::Unsafe)330break; // Found possible unsafe data loop.331}332}333if (i >= max)334return false; // An unsafe case was NOT found - don't need graph walk.335336// Unsafe case - check if the Region node is reachable from root.337ResourceMark rm;338339Arena *a = Thread::current()->resource_area();340Node_List nstack(a);341VectorSet visited(a);342343// Mark all control nodes reachable from root outputs344Node *n = (Node*)phase->C->root();345nstack.push(n);346visited.set(n->_idx);347while (nstack.size() != 0) {348n = nstack.pop();349uint max = n->outcnt();350for (uint i = 0; i < max; i++) {351Node* m = n->raw_out(i);352if (m != NULL && m->is_CFG()) {353if (phase->eqv(m, this)) {354return false; // We reached the Region node - it is not dead.355}356if (!visited.test_set(m->_idx))357nstack.push(m);358}359}360}361362return true; // The Region node is unreachable - it is dead.363}364365bool RegionNode::try_clean_mem_phi(PhaseGVN *phase) {366// Incremental inlining + PhaseStringOpts sometimes produce:367//368// cmpP with 1 top input369// |370// If371// / \372// IfFalse IfTrue /- Some Node373// \ / / /374// Region / /-MergeMem375// \---Phi376//377//378// It's expected by PhaseStringOpts that the Region goes away and is379// replaced by If's control input but because there's still a Phi,380// the Region stays in the graph. The top input from the cmpP is381// propagated forward and a subgraph that is useful goes away. The382// code below replaces the Phi with the MergeMem so that the Region383// is simplified.384385PhiNode* phi = has_unique_phi();386if (phi && phi->type() == Type::MEMORY && req() == 3 && phi->is_diamond_phi(true)) {387MergeMemNode* m = NULL;388assert(phi->req() == 3, "same as region");389for (uint i = 1; i < 3; ++i) {390Node *mem = phi->in(i);391if (mem && mem->is_MergeMem() && in(i)->outcnt() == 1) {392// Nothing is control-dependent on path #i except the region itself.393m = mem->as_MergeMem();394uint j = 3 - i;395Node* other = phi->in(j);396if (other && other == m->base_memory()) {397// m is a successor memory to other, and is not pinned inside the diamond, so push it out.398// This will allow the diamond to collapse completely.399phase->is_IterGVN()->replace_node(phi, m);400return true;401}402}403}404}405return false;406}407408//------------------------------Ideal------------------------------------------409// Return a node which is more "ideal" than the current node. Must preserve410// the CFG, but we can still strip out dead paths.411Node *RegionNode::Ideal(PhaseGVN *phase, bool can_reshape) {412if( !can_reshape && !in(0) ) return NULL; // Already degraded to a Copy413assert(!in(0) || !in(0)->is_Root(), "not a specially hidden merge");414415// Check for RegionNode with no Phi users and both inputs come from either416// arm of the same IF. If found, then the control-flow split is useless.417bool has_phis = false;418if (can_reshape) { // Need DU info to check for Phi users419has_phis = (has_phi() != NULL); // Cache result420if (has_phis && try_clean_mem_phi(phase)) {421has_phis = false;422}423424if (!has_phis) { // No Phi users? Nothing merging?425for (uint i = 1; i < req()-1; i++) {426Node *if1 = in(i);427if( !if1 ) continue;428Node *iff = if1->in(0);429if( !iff || !iff->is_If() ) continue;430for( uint j=i+1; j<req(); j++ ) {431if( in(j) && in(j)->in(0) == iff &&432if1->Opcode() != in(j)->Opcode() ) {433// Add the IF Projections to the worklist. They (and the IF itself)434// will be eliminated if dead.435phase->is_IterGVN()->add_users_to_worklist(iff);436set_req(i, iff->in(0));// Skip around the useless IF diamond437set_req(j, NULL);438return this; // Record progress439}440}441}442}443}444445// Remove TOP or NULL input paths. If only 1 input path remains, this Region446// degrades to a copy.447bool add_to_worklist = false;448int cnt = 0; // Count of values merging449DEBUG_ONLY( int cnt_orig = req(); ) // Save original inputs count450int del_it = 0; // The last input path we delete451// For all inputs...452for( uint i=1; i<req(); ++i ){// For all paths in453Node *n = in(i); // Get the input454if( n != NULL ) {455// Remove useless control copy inputs456if( n->is_Region() && n->as_Region()->is_copy() ) {457set_req(i, n->nonnull_req());458i--;459continue;460}461if( n->is_Proj() ) { // Remove useless rethrows462Node *call = n->in(0);463if (call->is_Call() && call->as_Call()->entry_point() == OptoRuntime::rethrow_stub()) {464set_req(i, call->in(0));465i--;466continue;467}468}469if( phase->type(n) == Type::TOP ) {470set_req(i, NULL); // Ignore TOP inputs471i--;472continue;473}474cnt++; // One more value merging475476} else if (can_reshape) { // Else found dead path with DU info477PhaseIterGVN *igvn = phase->is_IterGVN();478del_req(i); // Yank path from self479del_it = i;480uint max = outcnt();481DUIterator j;482bool progress = true;483while(progress) { // Need to establish property over all users484progress = false;485for (j = outs(); has_out(j); j++) {486Node *n = out(j);487if( n->req() != req() && n->is_Phi() ) {488assert( n->in(0) == this, "" );489igvn->hash_delete(n); // Yank from hash before hacking edges490n->set_req_X(i,NULL,igvn);// Correct DU info491n->del_req(i); // Yank path from Phis492if( max != outcnt() ) {493progress = true;494j = refresh_out_pos(j);495max = outcnt();496}497}498}499}500add_to_worklist = true;501i--;502}503}504505if (can_reshape && cnt == 1) {506// Is it dead loop?507// If it is LoopNopde it had 2 (+1 itself) inputs and508// one of them was cut. The loop is dead if it was EntryContol.509// Loop node may have only one input because entry path510// is removed in PhaseIdealLoop::Dominators().511assert(!this->is_Loop() || cnt_orig <= 3, "Loop node should have 3 or less inputs");512if (this->is_Loop() && (del_it == LoopNode::EntryControl ||513del_it == 0 && is_unreachable_region(phase)) ||514!this->is_Loop() && has_phis && is_unreachable_region(phase)) {515// Yes, the region will be removed during the next step below.516// Cut the backedge input and remove phis since no data paths left.517// We don't cut outputs to other nodes here since we need to put them518// on the worklist.519del_req(1);520cnt = 0;521assert( req() == 1, "no more inputs expected" );522uint max = outcnt();523bool progress = true;524Node *top = phase->C->top();525PhaseIterGVN *igvn = phase->is_IterGVN();526DUIterator j;527while(progress) {528progress = false;529for (j = outs(); has_out(j); j++) {530Node *n = out(j);531if( n->is_Phi() ) {532assert( igvn->eqv(n->in(0), this), "" );533assert( n->req() == 2 && n->in(1) != NULL, "Only one data input expected" );534// Break dead loop data path.535// Eagerly replace phis with top to avoid phis copies generation.536igvn->replace_node(n, top);537if( max != outcnt() ) {538progress = true;539j = refresh_out_pos(j);540max = outcnt();541}542}543}544}545add_to_worklist = true;546}547}548if (add_to_worklist) {549phase->is_IterGVN()->add_users_to_worklist(this); // Revisit collapsed Phis550}551552if( cnt <= 1 ) { // Only 1 path in?553set_req(0, NULL); // Null control input for region copy554if( cnt == 0 && !can_reshape) { // Parse phase - leave the node as it is.555// No inputs or all inputs are NULL.556return NULL;557} else if (can_reshape) { // Optimization phase - remove the node558PhaseIterGVN *igvn = phase->is_IterGVN();559Node *parent_ctrl;560if( cnt == 0 ) {561assert( req() == 1, "no inputs expected" );562// During IGVN phase such region will be subsumed by TOP node563// so region's phis will have TOP as control node.564// Kill phis here to avoid it. PhiNode::is_copy() will be always false.565// Also set other user's input to top.566parent_ctrl = phase->C->top();567} else {568// The fallthrough case since we already checked dead loops above.569parent_ctrl = in(1);570assert(parent_ctrl != NULL, "Region is a copy of some non-null control");571assert(!igvn->eqv(parent_ctrl, this), "Close dead loop");572}573if (!add_to_worklist)574igvn->add_users_to_worklist(this); // Check for further allowed opts575for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {576Node* n = last_out(i);577igvn->hash_delete(n); // Remove from worklist before modifying edges578if( n->is_Phi() ) { // Collapse all Phis579// Eagerly replace phis to avoid copies generation.580Node* in;581if( cnt == 0 ) {582assert( n->req() == 1, "No data inputs expected" );583in = parent_ctrl; // replaced by top584} else {585assert( n->req() == 2 && n->in(1) != NULL, "Only one data input expected" );586in = n->in(1); // replaced by unique input587if( n->as_Phi()->is_unsafe_data_reference(in) )588in = phase->C->top(); // replaced by top589}590igvn->replace_node(n, in);591}592else if( n->is_Region() ) { // Update all incoming edges593assert( !igvn->eqv(n, this), "Must be removed from DefUse edges");594uint uses_found = 0;595for( uint k=1; k < n->req(); k++ ) {596if( n->in(k) == this ) {597n->set_req(k, parent_ctrl);598uses_found++;599}600}601if( uses_found > 1 ) { // (--i) done at the end of the loop.602i -= (uses_found - 1);603}604}605else {606assert( igvn->eqv(n->in(0), this), "Expect RegionNode to be control parent");607n->set_req(0, parent_ctrl);608}609#ifdef ASSERT610for( uint k=0; k < n->req(); k++ ) {611assert( !igvn->eqv(n->in(k), this), "All uses of RegionNode should be gone");612}613#endif614}615// Remove the RegionNode itself from DefUse info616igvn->remove_dead_node(this);617return NULL;618}619return this; // Record progress620}621622623// If a Region flows into a Region, merge into one big happy merge.624if (can_reshape) {625Node *m = merge_region(this, phase);626if (m != NULL) return m;627}628629// Check if this region is the root of a clipping idiom on floats630if( ConvertFloat2IntClipping && can_reshape && req() == 4 ) {631// Check that only one use is a Phi and that it simplifies to two constants +632PhiNode* phi = has_unique_phi();633if (phi != NULL) { // One Phi user634// Check inputs to the Phi635ConNode *min;636ConNode *max;637Node *val;638uint min_idx;639uint max_idx;640uint val_idx;641if( check_phi_clipping( phi, min, min_idx, max, max_idx, val, val_idx ) ) {642IfNode *top_if;643IfNode *bot_if;644if( check_if_clipping( this, bot_if, top_if ) ) {645// Control pattern checks, now verify compares646Node *top_in = NULL; // value being compared against647Node *bot_in = NULL;648if( check_compare_clipping( true, bot_if, min, bot_in ) &&649check_compare_clipping( false, top_if, max, top_in ) ) {650if( bot_in == top_in ) {651PhaseIterGVN *gvn = phase->is_IterGVN();652assert( gvn != NULL, "Only had DefUse info in IterGVN");653// Only remaining check is that bot_in == top_in == (Phi's val + mods)654655// Check for the ConvF2INode656ConvF2INode *convf2i;657if( check_convf2i_clipping( phi, val_idx, convf2i, min, max ) &&658convf2i->in(1) == bot_in ) {659// Matched pattern, including LShiftI; RShiftI, replace with integer compares660// max test661Node *cmp = gvn->register_new_node_with_optimizer(new (phase->C) CmpINode( convf2i, min ));662Node *boo = gvn->register_new_node_with_optimizer(new (phase->C) BoolNode( cmp, BoolTest::lt ));663IfNode *iff = (IfNode*)gvn->register_new_node_with_optimizer(new (phase->C) IfNode( top_if->in(0), boo, PROB_UNLIKELY_MAG(5), top_if->_fcnt ));664Node *if_min= gvn->register_new_node_with_optimizer(new (phase->C) IfTrueNode (iff));665Node *ifF = gvn->register_new_node_with_optimizer(new (phase->C) IfFalseNode(iff));666// min test667cmp = gvn->register_new_node_with_optimizer(new (phase->C) CmpINode( convf2i, max ));668boo = gvn->register_new_node_with_optimizer(new (phase->C) BoolNode( cmp, BoolTest::gt ));669iff = (IfNode*)gvn->register_new_node_with_optimizer(new (phase->C) IfNode( ifF, boo, PROB_UNLIKELY_MAG(5), bot_if->_fcnt ));670Node *if_max= gvn->register_new_node_with_optimizer(new (phase->C) IfTrueNode (iff));671ifF = gvn->register_new_node_with_optimizer(new (phase->C) IfFalseNode(iff));672// update input edges to region node673set_req_X( min_idx, if_min, gvn );674set_req_X( max_idx, if_max, gvn );675set_req_X( val_idx, ifF, gvn );676// remove unnecessary 'LShiftI; RShiftI' idiom677gvn->hash_delete(phi);678phi->set_req_X( val_idx, convf2i, gvn );679gvn->hash_find_insert(phi);680// Return transformed region node681return this;682}683}684}685}686}687}688}689690return NULL;691}692693694695const RegMask &RegionNode::out_RegMask() const {696return RegMask::Empty;697}698699// Find the one non-null required input. RegionNode only700Node *Node::nonnull_req() const {701assert( is_Region(), "" );702for( uint i = 1; i < _cnt; i++ )703if( in(i) )704return in(i);705ShouldNotReachHere();706return NULL;707}708709710//=============================================================================711// note that these functions assume that the _adr_type field is flattened712uint PhiNode::hash() const {713const Type* at = _adr_type;714return TypeNode::hash() + (at ? at->hash() : 0);715}716uint PhiNode::cmp( const Node &n ) const {717return TypeNode::cmp(n) && _adr_type == ((PhiNode&)n)._adr_type;718}719static inline720const TypePtr* flatten_phi_adr_type(const TypePtr* at) {721if (at == NULL || at == TypePtr::BOTTOM) return at;722return Compile::current()->alias_type(at)->adr_type();723}724725//----------------------------make---------------------------------------------726// create a new phi with edges matching r and set (initially) to x727PhiNode* PhiNode::make(Node* r, Node* x, const Type *t, const TypePtr* at) {728uint preds = r->req(); // Number of predecessor paths729assert(t != Type::MEMORY || at == flatten_phi_adr_type(at), "flatten at");730PhiNode* p = new (Compile::current()) PhiNode(r, t, at);731for (uint j = 1; j < preds; j++) {732// Fill in all inputs, except those which the region does not yet have733if (r->in(j) != NULL)734p->init_req(j, x);735}736return p;737}738PhiNode* PhiNode::make(Node* r, Node* x) {739const Type* t = x->bottom_type();740const TypePtr* at = NULL;741if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());742return make(r, x, t, at);743}744PhiNode* PhiNode::make_blank(Node* r, Node* x) {745const Type* t = x->bottom_type();746const TypePtr* at = NULL;747if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());748return new (Compile::current()) PhiNode(r, t, at);749}750751752//------------------------slice_memory-----------------------------------------753// create a new phi with narrowed memory type754PhiNode* PhiNode::slice_memory(const TypePtr* adr_type) const {755PhiNode* mem = (PhiNode*) clone();756*(const TypePtr**)&mem->_adr_type = adr_type;757// convert self-loops, or else we get a bad graph758for (uint i = 1; i < req(); i++) {759if ((const Node*)in(i) == this) mem->set_req(i, mem);760}761mem->verify_adr_type();762return mem;763}764765//------------------------split_out_instance-----------------------------------766// Split out an instance type from a bottom phi.767PhiNode* PhiNode::split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const {768const TypeOopPtr *t_oop = at->isa_oopptr();769assert(t_oop != NULL && t_oop->is_known_instance(), "expecting instance oopptr");770const TypePtr *t = adr_type();771assert(type() == Type::MEMORY &&772(t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM ||773t->isa_oopptr() && !t->is_oopptr()->is_known_instance() &&774t->is_oopptr()->cast_to_exactness(true)775->is_oopptr()->cast_to_ptr_type(t_oop->ptr())776->is_oopptr()->cast_to_instance_id(t_oop->instance_id()) == t_oop),777"bottom or raw memory required");778779// Check if an appropriate node already exists.780Node *region = in(0);781for (DUIterator_Fast kmax, k = region->fast_outs(kmax); k < kmax; k++) {782Node* use = region->fast_out(k);783if( use->is_Phi()) {784PhiNode *phi2 = use->as_Phi();785if (phi2->type() == Type::MEMORY && phi2->adr_type() == at) {786return phi2;787}788}789}790Compile *C = igvn->C;791Arena *a = Thread::current()->resource_area();792Node_Array node_map = new Node_Array(a);793Node_Stack stack(a, C->live_nodes() >> 4);794PhiNode *nphi = slice_memory(at);795igvn->register_new_node_with_optimizer( nphi );796node_map.map(_idx, nphi);797stack.push((Node *)this, 1);798while(!stack.is_empty()) {799PhiNode *ophi = stack.node()->as_Phi();800uint i = stack.index();801assert(i >= 1, "not control edge");802stack.pop();803nphi = node_map[ophi->_idx]->as_Phi();804for (; i < ophi->req(); i++) {805Node *in = ophi->in(i);806if (in == NULL || igvn->type(in) == Type::TOP)807continue;808Node *opt = MemNode::optimize_simple_memory_chain(in, t_oop, NULL, igvn);809PhiNode *optphi = opt->is_Phi() ? opt->as_Phi() : NULL;810if (optphi != NULL && optphi->adr_type() == TypePtr::BOTTOM) {811opt = node_map[optphi->_idx];812if (opt == NULL) {813stack.push(ophi, i);814nphi = optphi->slice_memory(at);815igvn->register_new_node_with_optimizer( nphi );816node_map.map(optphi->_idx, nphi);817ophi = optphi;818i = 0; // will get incremented at top of loop819continue;820}821}822nphi->set_req(i, opt);823}824}825return nphi;826}827828//------------------------verify_adr_type--------------------------------------829#ifdef ASSERT830void PhiNode::verify_adr_type(VectorSet& visited, const TypePtr* at) const {831if (visited.test_set(_idx)) return; //already visited832833// recheck constructor invariants:834verify_adr_type(false);835836// recheck local phi/phi consistency:837assert(_adr_type == at || _adr_type == TypePtr::BOTTOM,838"adr_type must be consistent across phi nest");839840// walk around841for (uint i = 1; i < req(); i++) {842Node* n = in(i);843if (n == NULL) continue;844const Node* np = in(i);845if (np->is_Phi()) {846np->as_Phi()->verify_adr_type(visited, at);847} else if (n->bottom_type() == Type::TOP848|| (n->is_Mem() && n->in(MemNode::Address)->bottom_type() == Type::TOP)) {849// ignore top inputs850} else {851const TypePtr* nat = flatten_phi_adr_type(n->adr_type());852// recheck phi/non-phi consistency at leaves:853assert((nat != NULL) == (at != NULL), "");854assert(nat == at || nat == TypePtr::BOTTOM,855"adr_type must be consistent at leaves of phi nest");856}857}858}859860// Verify a whole nest of phis rooted at this one.861void PhiNode::verify_adr_type(bool recursive) const {862if (is_error_reported()) return; // muzzle asserts when debugging an error863if (Node::in_dump()) return; // muzzle asserts when printing864865assert((_type == Type::MEMORY) == (_adr_type != NULL), "adr_type for memory phis only");866867if (!VerifyAliases) return; // verify thoroughly only if requested868869assert(_adr_type == flatten_phi_adr_type(_adr_type),870"Phi::adr_type must be pre-normalized");871872if (recursive) {873VectorSet visited(Thread::current()->resource_area());874verify_adr_type(visited, _adr_type);875}876}877#endif878879880//------------------------------Value------------------------------------------881// Compute the type of the PhiNode882const Type *PhiNode::Value( PhaseTransform *phase ) const {883Node *r = in(0); // RegionNode884if( !r ) // Copy or dead885return in(1) ? phase->type(in(1)) : Type::TOP;886887// Note: During parsing, phis are often transformed before their regions.888// This means we have to use type_or_null to defend against untyped regions.889if( phase->type_or_null(r) == Type::TOP ) // Dead code?890return Type::TOP;891892// Check for trip-counted loop. If so, be smarter.893CountedLoopNode *l = r->is_CountedLoop() ? r->as_CountedLoop() : NULL;894if( l && l->can_be_counted_loop(phase) &&895((const Node*)l->phi() == this) ) { // Trip counted loop!896// protect against init_trip() or limit() returning NULL897const Node *init = l->init_trip();898const Node *limit = l->limit();899if( init != NULL && limit != NULL && l->stride_is_con() ) {900const TypeInt *lo = init ->bottom_type()->isa_int();901const TypeInt *hi = limit->bottom_type()->isa_int();902if( lo && hi ) { // Dying loops might have TOP here903int stride = l->stride_con();904if( stride < 0 ) { // Down-counter loop905const TypeInt *tmp = lo; lo = hi; hi = tmp;906stride = -stride;907}908if( lo->_hi < hi->_lo ) // Reversed endpoints are well defined :-(909return TypeInt::make(lo->_lo,hi->_hi,3);910}911}912}913914// Until we have harmony between classes and interfaces in the type915// lattice, we must tread carefully around phis which implicitly916// convert the one to the other.917const TypePtr* ttp = _type->make_ptr();918const TypeInstPtr* ttip = (ttp != NULL) ? ttp->isa_instptr() : NULL;919const TypeKlassPtr* ttkp = (ttp != NULL) ? ttp->isa_klassptr() : NULL;920bool is_intf = false;921if (ttip != NULL) {922ciKlass* k = ttip->klass();923if (k->is_loaded() && k->is_interface())924is_intf = true;925}926if (ttkp != NULL) {927ciKlass* k = ttkp->klass();928if (k->is_loaded() && k->is_interface())929is_intf = true;930}931932// Default case: merge all inputs933const Type *t = Type::TOP; // Merged type starting value934for (uint i = 1; i < req(); ++i) {// For all paths in935// Reachable control path?936if (r->in(i) && phase->type(r->in(i)) == Type::CONTROL) {937const Type* ti = phase->type(in(i));938// We assume that each input of an interface-valued Phi is a true939// subtype of that interface. This might not be true of the meet940// of all the input types. The lattice is not distributive in941// such cases. Ward off asserts in type.cpp by refusing to do942// meets between interfaces and proper classes.943const TypePtr* tip = ti->make_ptr();944const TypeInstPtr* tiip = (tip != NULL) ? tip->isa_instptr() : NULL;945if (tiip) {946bool ti_is_intf = false;947ciKlass* k = tiip->klass();948if (k->is_loaded() && k->is_interface())949ti_is_intf = true;950if (is_intf != ti_is_intf)951{ t = _type; break; }952}953t = t->meet_speculative(ti);954}955}956957// The worst-case type (from ciTypeFlow) should be consistent with "t".958// That is, we expect that "t->higher_equal(_type)" holds true.959// There are various exceptions:960// - Inputs which are phis might in fact be widened unnecessarily.961// For example, an input might be a widened int while the phi is a short.962// - Inputs might be BotPtrs but this phi is dependent on a null check,963// and postCCP has removed the cast which encodes the result of the check.964// - The type of this phi is an interface, and the inputs are classes.965// - Value calls on inputs might produce fuzzy results.966// (Occurrences of this case suggest improvements to Value methods.)967//968// It is not possible to see Type::BOTTOM values as phi inputs,969// because the ciTypeFlow pre-pass produces verifier-quality types.970const Type* ft = t->filter_speculative(_type); // Worst case type971972#ifdef ASSERT973// The following logic has been moved into TypeOopPtr::filter.974const Type* jt = t->join_speculative(_type);975if (jt->empty()) { // Emptied out???976977// Check for evil case of 't' being a class and '_type' expecting an978// interface. This can happen because the bytecodes do not contain979// enough type info to distinguish a Java-level interface variable980// from a Java-level object variable. If we meet 2 classes which981// both implement interface I, but their meet is at 'j/l/O' which982// doesn't implement I, we have no way to tell if the result should983// be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows984// into a Phi which "knows" it's an Interface type we'll have to985// uplift the type.986if (!t->empty() && ttip && ttip->is_loaded() && ttip->klass()->is_interface()) {987assert(ft == _type, ""); // Uplift to interface988} else if (!t->empty() && ttkp && ttkp->is_loaded() && ttkp->klass()->is_interface()) {989assert(ft == _type, ""); // Uplift to interface990} else {991// We also have to handle 'evil cases' of interface- vs. class-arrays992Type::get_arrays_base_elements(jt, _type, NULL, &ttip);993if (!t->empty() && ttip != NULL && ttip->is_loaded() && ttip->klass()->is_interface()) {994assert(ft == _type, ""); // Uplift to array of interface995} else {996// Otherwise it's something stupid like non-overlapping int ranges997// found on dying counted loops.998assert(ft == Type::TOP, ""); // Canonical empty value999}1000}1001}10021003else {10041005// If we have an interface-typed Phi and we narrow to a class type, the join1006// should report back the class. However, if we have a J/L/Object1007// class-typed Phi and an interface flows in, it's possible that the meet &1008// join report an interface back out. This isn't possible but happens1009// because the type system doesn't interact well with interfaces.1010const TypePtr *jtp = jt->make_ptr();1011const TypeInstPtr *jtip = (jtp != NULL) ? jtp->isa_instptr() : NULL;1012const TypeKlassPtr *jtkp = (jtp != NULL) ? jtp->isa_klassptr() : NULL;1013if( jtip && ttip ) {1014if( jtip->is_loaded() && jtip->klass()->is_interface() &&1015ttip->is_loaded() && !ttip->klass()->is_interface() ) {1016// Happens in a CTW of rt.jar, 320-341, no extra flags1017assert(ft == ttip->cast_to_ptr_type(jtip->ptr()) ||1018ft->isa_narrowoop() && ft->make_ptr() == ttip->cast_to_ptr_type(jtip->ptr()), "");1019jt = ft;1020}1021}1022if( jtkp && ttkp ) {1023if( jtkp->is_loaded() && jtkp->klass()->is_interface() &&1024!jtkp->klass_is_exact() && // Keep exact interface klass (6894807)1025ttkp->is_loaded() && !ttkp->klass()->is_interface() ) {1026assert(ft == ttkp->cast_to_ptr_type(jtkp->ptr()) ||1027ft->isa_narrowklass() && ft->make_ptr() == ttkp->cast_to_ptr_type(jtkp->ptr()), "");1028jt = ft;1029}1030}1031if (jt != ft && jt->base() == ft->base()) {1032if (jt->isa_int() &&1033jt->is_int()->_lo == ft->is_int()->_lo &&1034jt->is_int()->_hi == ft->is_int()->_hi)1035jt = ft;1036if (jt->isa_long() &&1037jt->is_long()->_lo == ft->is_long()->_lo &&1038jt->is_long()->_hi == ft->is_long()->_hi)1039jt = ft;1040}1041if (jt != ft) {1042tty->print("merge type: "); t->dump(); tty->cr();1043tty->print("kill type: "); _type->dump(); tty->cr();1044tty->print("join type: "); jt->dump(); tty->cr();1045tty->print("filter type: "); ft->dump(); tty->cr();1046}1047assert(jt == ft, "");1048}1049#endif //ASSERT10501051// Deal with conversion problems found in data loops.1052ft = phase->saturate(ft, phase->type_or_null(this), _type);10531054return ft;1055}105610571058//------------------------------is_diamond_phi---------------------------------1059// Does this Phi represent a simple well-shaped diamond merge? Return the1060// index of the true path or 0 otherwise.1061// If check_control_only is true, do not inspect the If node at the1062// top, and return -1 (not an edge number) on success.1063int PhiNode::is_diamond_phi(bool check_control_only) const {1064// Check for a 2-path merge1065Node *region = in(0);1066if( !region ) return 0;1067if( region->req() != 3 ) return 0;1068if( req() != 3 ) return 0;1069// Check that both paths come from the same If1070Node *ifp1 = region->in(1);1071Node *ifp2 = region->in(2);1072if( !ifp1 || !ifp2 ) return 0;1073Node *iff = ifp1->in(0);1074if( !iff || !iff->is_If() ) return 0;1075if( iff != ifp2->in(0) ) return 0;1076if (check_control_only) return -1;1077// Check for a proper bool/cmp1078const Node *b = iff->in(1);1079if( !b->is_Bool() ) return 0;1080const Node *cmp = b->in(1);1081if( !cmp->is_Cmp() ) return 0;10821083// Check for branching opposite expected1084if( ifp2->Opcode() == Op_IfTrue ) {1085assert( ifp1->Opcode() == Op_IfFalse, "" );1086return 2;1087} else {1088assert( ifp1->Opcode() == Op_IfTrue, "" );1089return 1;1090}1091}10921093//----------------------------check_cmove_id-----------------------------------1094// Check for CMove'ing a constant after comparing against the constant.1095// Happens all the time now, since if we compare equality vs a constant in1096// the parser, we "know" the variable is constant on one path and we force1097// it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a1098// conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more1099// general in that we don't need constants. Since CMove's are only inserted1100// in very special circumstances, we do it here on generic Phi's.1101Node* PhiNode::is_cmove_id(PhaseTransform* phase, int true_path) {1102assert(true_path !=0, "only diamond shape graph expected");11031104// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1105// phi->region->if_proj->ifnode->bool->cmp1106Node* region = in(0);1107Node* iff = region->in(1)->in(0);1108BoolNode* b = iff->in(1)->as_Bool();1109Node* cmp = b->in(1);1110Node* tval = in(true_path);1111Node* fval = in(3-true_path);1112Node* id = CMoveNode::is_cmove_id(phase, cmp, tval, fval, b);1113if (id == NULL)1114return NULL;11151116// Either value might be a cast that depends on a branch of 'iff'.1117// Since the 'id' value will float free of the diamond, either1118// decast or return failure.1119Node* ctl = id->in(0);1120if (ctl != NULL && ctl->in(0) == iff) {1121if (id->is_ConstraintCast()) {1122return id->in(1);1123} else {1124// Don't know how to disentangle this value.1125return NULL;1126}1127}11281129return id;1130}11311132//------------------------------Identity---------------------------------------1133// Check for Region being Identity.1134Node *PhiNode::Identity( PhaseTransform *phase ) {1135// Check for no merging going on1136// (There used to be special-case code here when this->region->is_Loop.1137// It would check for a tributary phi on the backedge that the main phi1138// trivially, perhaps with a single cast. The unique_input method1139// does all this and more, by reducing such tributaries to 'this'.)1140Node* uin = unique_input(phase);1141if (uin != NULL) {1142return uin;1143}11441145int true_path = is_diamond_phi();1146if (true_path != 0) {1147Node* id = is_cmove_id(phase, true_path);1148if (id != NULL) return id;1149}11501151return this; // No identity1152}11531154//-----------------------------unique_input------------------------------------1155// Find the unique value, discounting top, self-loops, and casts.1156// Return top if there are no inputs, and self if there are multiple.1157Node* PhiNode::unique_input(PhaseTransform* phase) {1158// 1) One unique direct input, or1159// 2) some of the inputs have an intervening ConstraintCast and1160// the type of input is the same or sharper (more specific)1161// than the phi's type.1162// 3) an input is a self loop1163//1164// 1) input or 2) input or 3) input __1165// / \ / \ \ / \1166// \ / | cast phi cast1167// phi \ / / \ /1168// phi / --11691170Node* r = in(0); // RegionNode1171if (r == NULL) return in(1); // Already degraded to a Copy1172Node* uncasted_input = NULL; // The unique uncasted input (ConstraintCasts removed)1173Node* direct_input = NULL; // The unique direct input11741175for (uint i = 1, cnt = req(); i < cnt; ++i) {1176Node* rc = r->in(i);1177if (rc == NULL || phase->type(rc) == Type::TOP)1178continue; // ignore unreachable control path1179Node* n = in(i);1180if (n == NULL)1181continue;1182Node* un = n->uncast();1183if (un == NULL || un == this || phase->type(un) == Type::TOP) {1184continue; // ignore if top, or in(i) and "this" are in a data cycle1185}1186// Check for a unique uncasted input1187if (uncasted_input == NULL) {1188uncasted_input = un;1189} else if (uncasted_input != un) {1190uncasted_input = NodeSentinel; // no unique uncasted input1191}1192// Check for a unique direct input1193if (direct_input == NULL) {1194direct_input = n;1195} else if (direct_input != n) {1196direct_input = NodeSentinel; // no unique direct input1197}1198}1199if (direct_input == NULL) {1200return phase->C->top(); // no inputs1201}1202assert(uncasted_input != NULL,"");12031204if (direct_input != NodeSentinel) {1205return direct_input; // one unique direct input1206}1207if (uncasted_input != NodeSentinel &&1208phase->type(uncasted_input)->higher_equal(type())) {1209return uncasted_input; // one unique uncasted input1210}12111212// Nothing.1213return NULL;1214}12151216//------------------------------is_x2logic-------------------------------------1217// Check for simple convert-to-boolean pattern1218// If:(C Bool) Region:(IfF IfT) Phi:(Region 0 1)1219// Convert Phi to an ConvIB.1220static Node *is_x2logic( PhaseGVN *phase, PhiNode *phi, int true_path ) {1221assert(true_path !=0, "only diamond shape graph expected");1222// Convert the true/false index into an expected 0/1 return.1223// Map 2->0 and 1->1.1224int flipped = 2-true_path;12251226// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1227// phi->region->if_proj->ifnode->bool->cmp1228Node *region = phi->in(0);1229Node *iff = region->in(1)->in(0);1230BoolNode *b = (BoolNode*)iff->in(1);1231const CmpNode *cmp = (CmpNode*)b->in(1);12321233Node *zero = phi->in(1);1234Node *one = phi->in(2);1235const Type *tzero = phase->type( zero );1236const Type *tone = phase->type( one );12371238// Check for compare vs 01239const Type *tcmp = phase->type(cmp->in(2));1240if( tcmp != TypeInt::ZERO && tcmp != TypePtr::NULL_PTR ) {1241// Allow cmp-vs-1 if the other input is bounded by 0-11242if( !(tcmp == TypeInt::ONE && phase->type(cmp->in(1)) == TypeInt::BOOL) )1243return NULL;1244flipped = 1-flipped; // Test is vs 1 instead of 0!1245}12461247// Check for setting zero/one opposite expected1248if( tzero == TypeInt::ZERO ) {1249if( tone == TypeInt::ONE ) {1250} else return NULL;1251} else if( tzero == TypeInt::ONE ) {1252if( tone == TypeInt::ZERO ) {1253flipped = 1-flipped;1254} else return NULL;1255} else return NULL;12561257// Check for boolean test backwards1258if( b->_test._test == BoolTest::ne ) {1259} else if( b->_test._test == BoolTest::eq ) {1260flipped = 1-flipped;1261} else return NULL;12621263// Build int->bool conversion1264Node *n = new (phase->C) Conv2BNode( cmp->in(1) );1265if( flipped )1266n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );12671268return n;1269}12701271//------------------------------is_cond_add------------------------------------1272// Check for simple conditional add pattern: "(P < Q) ? X+Y : X;"1273// To be profitable the control flow has to disappear; there can be no other1274// values merging here. We replace the test-and-branch with:1275// "(sgn(P-Q))&Y) + X". Basically, convert "(P < Q)" into 0 or -1 by1276// moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.1277// Then convert Y to 0-or-Y and finally add.1278// This is a key transform for SpecJava _201_compress.1279static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {1280assert(true_path !=0, "only diamond shape graph expected");12811282// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1283// phi->region->if_proj->ifnode->bool->cmp1284RegionNode *region = (RegionNode*)phi->in(0);1285Node *iff = region->in(1)->in(0);1286BoolNode* b = iff->in(1)->as_Bool();1287const CmpNode *cmp = (CmpNode*)b->in(1);12881289// Make sure only merging this one phi here1290if (region->has_unique_phi() != phi) return NULL;12911292// Make sure each arm of the diamond has exactly one output, which we assume1293// is the region. Otherwise, the control flow won't disappear.1294if (region->in(1)->outcnt() != 1) return NULL;1295if (region->in(2)->outcnt() != 1) return NULL;12961297// Check for "(P < Q)" of type signed int1298if (b->_test._test != BoolTest::lt) return NULL;1299if (cmp->Opcode() != Op_CmpI) return NULL;13001301Node *p = cmp->in(1);1302Node *q = cmp->in(2);1303Node *n1 = phi->in( true_path);1304Node *n2 = phi->in(3-true_path);13051306int op = n1->Opcode();1307if( op != Op_AddI // Need zero as additive identity1308/*&&op != Op_SubI &&1309op != Op_AddP &&1310op != Op_XorI &&1311op != Op_OrI*/ )1312return NULL;13131314Node *x = n2;1315Node *y = NULL;1316if( x == n1->in(1) ) {1317y = n1->in(2);1318} else if( x == n1->in(2) ) {1319y = n1->in(1);1320} else return NULL;13211322// Not so profitable if compare and add are constants1323if( q->is_Con() && phase->type(q) != TypeInt::ZERO && y->is_Con() )1324return NULL;13251326Node *cmplt = phase->transform( new (phase->C) CmpLTMaskNode(p,q) );1327Node *j_and = phase->transform( new (phase->C) AndINode(cmplt,y) );1328return new (phase->C) AddINode(j_and,x);1329}13301331//------------------------------is_absolute------------------------------------1332// Check for absolute value.1333static Node* is_absolute( PhaseGVN *phase, PhiNode *phi_root, int true_path) {1334assert(true_path !=0, "only diamond shape graph expected");13351336int cmp_zero_idx = 0; // Index of compare input where to look for zero1337int phi_x_idx = 0; // Index of phi input where to find naked x13381339// ABS ends with the merge of 2 control flow paths.1340// Find the false path from the true path. With only 2 inputs, 3 - x works nicely.1341int false_path = 3 - true_path;13421343// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1344// phi->region->if_proj->ifnode->bool->cmp1345BoolNode *bol = phi_root->in(0)->in(1)->in(0)->in(1)->as_Bool();13461347// Check bool sense1348switch( bol->_test._test ) {1349case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = true_path; break;1350case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = false_path; break;1351case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = true_path; break;1352case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = false_path; break;1353default: return NULL; break;1354}13551356// Test is next1357Node *cmp = bol->in(1);1358const Type *tzero = NULL;1359switch( cmp->Opcode() ) {1360case Op_CmpF: tzero = TypeF::ZERO; break; // Float ABS1361case Op_CmpD: tzero = TypeD::ZERO; break; // Double ABS1362default: return NULL;1363}13641365// Find zero input of compare; the other input is being abs'd1366Node *x = NULL;1367bool flip = false;1368if( phase->type(cmp->in(cmp_zero_idx)) == tzero ) {1369x = cmp->in(3 - cmp_zero_idx);1370} else if( phase->type(cmp->in(3 - cmp_zero_idx)) == tzero ) {1371// The test is inverted, we should invert the result...1372x = cmp->in(cmp_zero_idx);1373flip = true;1374} else {1375return NULL;1376}13771378// Next get the 2 pieces being selected, one is the original value1379// and the other is the negated value.1380if( phi_root->in(phi_x_idx) != x ) return NULL;13811382// Check other phi input for subtract node1383Node *sub = phi_root->in(3 - phi_x_idx);13841385// Allow only Sub(0,X) and fail out for all others; Neg is not OK1386if( tzero == TypeF::ZERO ) {1387if( sub->Opcode() != Op_SubF ||1388sub->in(2) != x ||1389phase->type(sub->in(1)) != tzero ) return NULL;1390x = new (phase->C) AbsFNode(x);1391if (flip) {1392x = new (phase->C) SubFNode(sub->in(1), phase->transform(x));1393}1394} else {1395if( sub->Opcode() != Op_SubD ||1396sub->in(2) != x ||1397phase->type(sub->in(1)) != tzero ) return NULL;1398x = new (phase->C) AbsDNode(x);1399if (flip) {1400x = new (phase->C) SubDNode(sub->in(1), phase->transform(x));1401}1402}14031404return x;1405}14061407//------------------------------split_once-------------------------------------1408// Helper for split_flow_path1409static void split_once(PhaseIterGVN *igvn, Node *phi, Node *val, Node *n, Node *newn) {1410igvn->hash_delete(n); // Remove from hash before hacking edges14111412uint j = 1;1413for (uint i = phi->req()-1; i > 0; i--) {1414if (phi->in(i) == val) { // Found a path with val?1415// Add to NEW Region/Phi, no DU info1416newn->set_req( j++, n->in(i) );1417// Remove from OLD Region/Phi1418n->del_req(i);1419}1420}14211422// Register the new node but do not transform it. Cannot transform until the1423// entire Region/Phi conglomerate has been hacked as a single huge transform.1424igvn->register_new_node_with_optimizer( newn );14251426// Now I can point to the new node.1427n->add_req(newn);1428igvn->_worklist.push(n);1429}14301431//------------------------------split_flow_path--------------------------------1432// Check for merging identical values and split flow paths1433static Node* split_flow_path(PhaseGVN *phase, PhiNode *phi) {1434BasicType bt = phi->type()->basic_type();1435if( bt == T_ILLEGAL || type2size[bt] <= 0 )1436return NULL; // Bail out on funny non-value stuff1437if( phi->req() <= 3 ) // Need at least 2 matched inputs and a1438return NULL; // third unequal input to be worth doing14391440// Scan for a constant1441uint i;1442for( i = 1; i < phi->req()-1; i++ ) {1443Node *n = phi->in(i);1444if( !n ) return NULL;1445if( phase->type(n) == Type::TOP ) return NULL;1446if( n->Opcode() == Op_ConP || n->Opcode() == Op_ConN || n->Opcode() == Op_ConNKlass )1447break;1448}1449if( i >= phi->req() ) // Only split for constants1450return NULL;14511452Node *val = phi->in(i); // Constant to split for1453uint hit = 0; // Number of times it occurs1454Node *r = phi->region();14551456for( ; i < phi->req(); i++ ){ // Count occurrences of constant1457Node *n = phi->in(i);1458if( !n ) return NULL;1459if( phase->type(n) == Type::TOP ) return NULL;1460if( phi->in(i) == val ) {1461hit++;1462if (PhaseIdealLoop::find_predicate(r->in(i)) != NULL) {1463return NULL; // don't split loop entry path1464}1465}1466}14671468if( hit <= 1 || // Make sure we find 2 or more1469hit == phi->req()-1 ) // and not ALL the same value1470return NULL;14711472// Now start splitting out the flow paths that merge the same value.1473// Split first the RegionNode.1474PhaseIterGVN *igvn = phase->is_IterGVN();1475RegionNode *newr = new (phase->C) RegionNode(hit+1);1476split_once(igvn, phi, val, r, newr);14771478// Now split all other Phis than this one1479for (DUIterator_Fast kmax, k = r->fast_outs(kmax); k < kmax; k++) {1480Node* phi2 = r->fast_out(k);1481if( phi2->is_Phi() && phi2->as_Phi() != phi ) {1482PhiNode *newphi = PhiNode::make_blank(newr, phi2);1483split_once(igvn, phi, val, phi2, newphi);1484}1485}14861487// Clean up this guy1488igvn->hash_delete(phi);1489for( i = phi->req()-1; i > 0; i-- ) {1490if( phi->in(i) == val ) {1491phi->del_req(i);1492}1493}1494phi->add_req(val);14951496return phi;1497}14981499//=============================================================================1500//------------------------------simple_data_loop_check-------------------------1501// Try to determining if the phi node in a simple safe/unsafe data loop.1502// Returns:1503// enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };1504// Safe - safe case when the phi and it's inputs reference only safe data1505// nodes;1506// Unsafe - the phi and it's inputs reference unsafe data nodes but there1507// is no reference back to the phi - need a graph walk1508// to determine if it is in a loop;1509// UnsafeLoop - unsafe case when the phi references itself directly or through1510// unsafe data node.1511// Note: a safe data node is a node which could/never reference itself during1512// GVN transformations. For now it is Con, Proj, Phi, CastPP, CheckCastPP.1513// I mark Phi nodes as safe node not only because they can reference itself1514// but also to prevent mistaking the fallthrough case inside an outer loop1515// as dead loop when the phi references itselfs through an other phi.1516PhiNode::LoopSafety PhiNode::simple_data_loop_check(Node *in) const {1517// It is unsafe loop if the phi node references itself directly.1518if (in == (Node*)this)1519return UnsafeLoop; // Unsafe loop1520// Unsafe loop if the phi node references itself through an unsafe data node.1521// Exclude cases with null inputs or data nodes which could reference1522// itself (safe for dead loops).1523if (in != NULL && !in->is_dead_loop_safe()) {1524// Check inputs of phi's inputs also.1525// It is much less expensive then full graph walk.1526uint cnt = in->req();1527uint i = (in->is_Proj() && !in->is_CFG()) ? 0 : 1;1528for (; i < cnt; ++i) {1529Node* m = in->in(i);1530if (m == (Node*)this)1531return UnsafeLoop; // Unsafe loop1532if (m != NULL && !m->is_dead_loop_safe()) {1533// Check the most common case (about 30% of all cases):1534// phi->Load/Store->AddP->(ConP ConP Con)/(Parm Parm Con).1535Node *m1 = (m->is_AddP() && m->req() > 3) ? m->in(1) : NULL;1536if (m1 == (Node*)this)1537return UnsafeLoop; // Unsafe loop1538if (m1 != NULL && m1 == m->in(2) &&1539m1->is_dead_loop_safe() && m->in(3)->is_Con()) {1540continue; // Safe case1541}1542// The phi references an unsafe node - need full analysis.1543return Unsafe;1544}1545}1546}1547return Safe; // Safe case - we can optimize the phi node.1548}15491550//------------------------------is_unsafe_data_reference-----------------------1551// If phi can be reached through the data input - it is data loop.1552bool PhiNode::is_unsafe_data_reference(Node *in) const {1553assert(req() > 1, "");1554// First, check simple cases when phi references itself directly or1555// through an other node.1556LoopSafety safety = simple_data_loop_check(in);1557if (safety == UnsafeLoop)1558return true; // phi references itself - unsafe loop1559else if (safety == Safe)1560return false; // Safe case - phi could be replaced with the unique input.15611562// Unsafe case when we should go through data graph to determine1563// if the phi references itself.15641565ResourceMark rm;15661567Arena *a = Thread::current()->resource_area();1568Node_List nstack(a);1569VectorSet visited(a);15701571nstack.push(in); // Start with unique input.1572visited.set(in->_idx);1573while (nstack.size() != 0) {1574Node* n = nstack.pop();1575uint cnt = n->req();1576uint i = (n->is_Proj() && !n->is_CFG()) ? 0 : 1;1577for (; i < cnt; i++) {1578Node* m = n->in(i);1579if (m == (Node*)this) {1580return true; // Data loop1581}1582if (m != NULL && !m->is_dead_loop_safe()) { // Only look for unsafe cases.1583if (!visited.test_set(m->_idx))1584nstack.push(m);1585}1586}1587}1588return false; // The phi is not reachable from its inputs1589}159015911592//------------------------------Ideal------------------------------------------1593// Return a node which is more "ideal" than the current node. Must preserve1594// the CFG, but we can still strip out dead paths.1595Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {1596// The next should never happen after 6297035 fix.1597if( is_copy() ) // Already degraded to a Copy ?1598return NULL; // No change15991600Node *r = in(0); // RegionNode1601assert(r->in(0) == NULL || !r->in(0)->is_Root(), "not a specially hidden merge");16021603// Note: During parsing, phis are often transformed before their regions.1604// This means we have to use type_or_null to defend against untyped regions.1605if( phase->type_or_null(r) == Type::TOP ) // Dead code?1606return NULL; // No change16071608Node *top = phase->C->top();1609bool new_phi = (outcnt() == 0); // transforming new Phi1610// No change for igvn if new phi is not hooked1611if (new_phi && can_reshape)1612return NULL;16131614// The are 2 situations when only one valid phi's input is left1615// (in addition to Region input).1616// One: region is not loop - replace phi with this input.1617// Two: region is loop - replace phi with top since this data path is dead1618// and we need to break the dead data loop.1619Node* progress = NULL; // Record if any progress made1620for( uint j = 1; j < req(); ++j ){ // For all paths in1621// Check unreachable control paths1622Node* rc = r->in(j);1623Node* n = in(j); // Get the input1624if (rc == NULL || phase->type(rc) == Type::TOP) {1625if (n != top) { // Not already top?1626PhaseIterGVN *igvn = phase->is_IterGVN();1627if (can_reshape && igvn != NULL) {1628igvn->_worklist.push(r);1629}1630set_req(j, top); // Nuke it down1631progress = this; // Record progress1632}1633}1634}16351636if (can_reshape && outcnt() == 0) {1637// set_req() above may kill outputs if Phi is referenced1638// only by itself on the dead (top) control path.1639return top;1640}16411642Node* uin = unique_input(phase);1643if (uin == top) { // Simplest case: no alive inputs.1644if (can_reshape) // IGVN transformation1645return top;1646else1647return NULL; // Identity will return TOP1648} else if (uin != NULL) {1649// Only one not-NULL unique input path is left.1650// Determine if this input is backedge of a loop.1651// (Skip new phis which have no uses and dead regions).1652if (outcnt() > 0 && r->in(0) != NULL) {1653// First, take the short cut when we know it is a loop and1654// the EntryControl data path is dead.1655// Loop node may have only one input because entry path1656// is removed in PhaseIdealLoop::Dominators().1657assert(!r->is_Loop() || r->req() <= 3, "Loop node should have 3 or less inputs");1658bool is_loop = (r->is_Loop() && r->req() == 3);1659// Then, check if there is a data loop when phi references itself directly1660// or through other data nodes.1661if (is_loop && !uin->eqv_uncast(in(LoopNode::EntryControl)) ||1662!is_loop && is_unsafe_data_reference(uin)) {1663// Break this data loop to avoid creation of a dead loop.1664if (can_reshape) {1665return top;1666} else {1667// We can't return top if we are in Parse phase - cut inputs only1668// let Identity to handle the case.1669replace_edge(uin, top);1670return NULL;1671}1672}1673}16741675// One unique input.1676debug_only(Node* ident = Identity(phase));1677// The unique input must eventually be detected by the Identity call.1678#ifdef ASSERT1679if (ident != uin && !ident->is_top()) {1680// print this output before failing assert1681r->dump(3);1682this->dump(3);1683ident->dump();1684uin->dump();1685}1686#endif1687assert(ident == uin || ident->is_top(), "Identity must clean this up");1688return NULL;1689}169016911692Node* opt = NULL;1693int true_path = is_diamond_phi();1694if( true_path != 0 ) {1695// Check for CMove'ing identity. If it would be unsafe,1696// handle it here. In the safe case, let Identity handle it.1697Node* unsafe_id = is_cmove_id(phase, true_path);1698if( unsafe_id != NULL && is_unsafe_data_reference(unsafe_id) )1699opt = unsafe_id;17001701// Check for simple convert-to-boolean pattern1702if( opt == NULL )1703opt = is_x2logic(phase, this, true_path);17041705// Check for absolute value1706if( opt == NULL )1707opt = is_absolute(phase, this, true_path);17081709// Check for conditional add1710if( opt == NULL && can_reshape )1711opt = is_cond_add(phase, this, true_path);17121713// These 4 optimizations could subsume the phi:1714// have to check for a dead data loop creation.1715if( opt != NULL ) {1716if( opt == unsafe_id || is_unsafe_data_reference(opt) ) {1717// Found dead loop.1718if( can_reshape )1719return top;1720// We can't return top if we are in Parse phase - cut inputs only1721// to stop further optimizations for this phi. Identity will return TOP.1722assert(req() == 3, "only diamond merge phi here");1723set_req(1, top);1724set_req(2, top);1725return NULL;1726} else {1727return opt;1728}1729}1730}17311732// Check for merging identical values and split flow paths1733if (can_reshape) {1734opt = split_flow_path(phase, this);1735// This optimization only modifies phi - don't need to check for dead loop.1736assert(opt == NULL || phase->eqv(opt, this), "do not elide phi");1737if (opt != NULL) return opt;1738}17391740if (in(1) != NULL && in(1)->Opcode() == Op_AddP && can_reshape) {1741// Try to undo Phi of AddP:1742// (Phi (AddP base base y) (AddP base2 base2 y))1743// becomes:1744// newbase := (Phi base base2)1745// (AddP newbase newbase y)1746//1747// This occurs as a result of unsuccessful split_thru_phi and1748// interferes with taking advantage of addressing modes. See the1749// clone_shift_expressions code in matcher.cpp1750Node* addp = in(1);1751const Type* type = addp->in(AddPNode::Base)->bottom_type();1752Node* y = addp->in(AddPNode::Offset);1753if (y != NULL && addp->in(AddPNode::Base) == addp->in(AddPNode::Address)) {1754// make sure that all the inputs are similar to the first one,1755// i.e. AddP with base == address and same offset as first AddP1756bool doit = true;1757for (uint i = 2; i < req(); i++) {1758if (in(i) == NULL ||1759in(i)->Opcode() != Op_AddP ||1760in(i)->in(AddPNode::Base) != in(i)->in(AddPNode::Address) ||1761in(i)->in(AddPNode::Offset) != y) {1762doit = false;1763break;1764}1765// Accumulate type for resulting Phi1766type = type->meet_speculative(in(i)->in(AddPNode::Base)->bottom_type());1767}1768Node* base = NULL;1769if (doit) {1770// Check for neighboring AddP nodes in a tree.1771// If they have a base, use that it.1772for (DUIterator_Fast kmax, k = this->fast_outs(kmax); k < kmax; k++) {1773Node* u = this->fast_out(k);1774if (u->is_AddP()) {1775Node* base2 = u->in(AddPNode::Base);1776if (base2 != NULL && !base2->is_top()) {1777if (base == NULL)1778base = base2;1779else if (base != base2)1780{ doit = false; break; }1781}1782}1783}1784}1785if (doit) {1786if (base == NULL) {1787base = new (phase->C) PhiNode(in(0), type, NULL);1788for (uint i = 1; i < req(); i++) {1789base->init_req(i, in(i)->in(AddPNode::Base));1790}1791phase->is_IterGVN()->register_new_node_with_optimizer(base);1792}1793return new (phase->C) AddPNode(base, base, y);1794}1795}1796}17971798// Split phis through memory merges, so that the memory merges will go away.1799// Piggy-back this transformation on the search for a unique input....1800// It will be as if the merged memory is the unique value of the phi.1801// (Do not attempt this optimization unless parsing is complete.1802// It would make the parser's memory-merge logic sick.)1803// (MergeMemNode is not dead_loop_safe - need to check for dead loop.)1804if (progress == NULL && can_reshape && type() == Type::MEMORY) {1805// see if this phi should be sliced1806uint merge_width = 0;1807bool saw_self = false;1808for( uint i=1; i<req(); ++i ) {// For all paths in1809Node *ii = in(i);1810if (ii->is_MergeMem()) {1811MergeMemNode* n = ii->as_MergeMem();1812merge_width = MAX2(merge_width, n->req());1813saw_self = saw_self || phase->eqv(n->base_memory(), this);1814}1815}18161817// This restriction is temporarily necessary to ensure termination:1818if (!saw_self && adr_type() == TypePtr::BOTTOM) merge_width = 0;18191820if (merge_width > Compile::AliasIdxRaw) {1821// found at least one non-empty MergeMem1822const TypePtr* at = adr_type();1823if (at != TypePtr::BOTTOM) {1824// Patch the existing phi to select an input from the merge:1825// Phi:AT1(...MergeMem(m0, m1, m2)...) into1826// Phi:AT1(...m1...)1827int alias_idx = phase->C->get_alias_index(at);1828for (uint i=1; i<req(); ++i) {1829Node *ii = in(i);1830if (ii->is_MergeMem()) {1831MergeMemNode* n = ii->as_MergeMem();1832// compress paths and change unreachable cycles to TOP1833// If not, we can update the input infinitely along a MergeMem cycle1834// Equivalent code is in MemNode::Ideal_common1835Node *m = phase->transform(n);1836if (outcnt() == 0) { // Above transform() may kill us!1837return top;1838}1839// If transformed to a MergeMem, get the desired slice1840// Otherwise the returned node represents memory for every slice1841Node *new_mem = (m->is_MergeMem()) ?1842m->as_MergeMem()->memory_at(alias_idx) : m;1843// Update input if it is progress over what we have now1844if (new_mem != ii) {1845set_req(i, new_mem);1846progress = this;1847}1848}1849}1850} else {1851// We know that at least one MergeMem->base_memory() == this1852// (saw_self == true). If all other inputs also references this phi1853// (directly or through data nodes) - it is dead loop.1854bool saw_safe_input = false;1855for (uint j = 1; j < req(); ++j) {1856Node *n = in(j);1857if (n->is_MergeMem() && n->as_MergeMem()->base_memory() == this)1858continue; // skip known cases1859if (!is_unsafe_data_reference(n)) {1860saw_safe_input = true; // found safe input1861break;1862}1863}1864if (!saw_safe_input)1865return top; // all inputs reference back to this phi - dead loop18661867// Phi(...MergeMem(m0, m1:AT1, m2:AT2)...) into1868// MergeMem(Phi(...m0...), Phi:AT1(...m1...), Phi:AT2(...m2...))1869PhaseIterGVN *igvn = phase->is_IterGVN();1870Node* hook = new (phase->C) Node(1);1871PhiNode* new_base = (PhiNode*) clone();1872// Must eagerly register phis, since they participate in loops.1873if (igvn) {1874igvn->register_new_node_with_optimizer(new_base);1875hook->add_req(new_base);1876}1877MergeMemNode* result = MergeMemNode::make(phase->C, new_base);1878for (uint i = 1; i < req(); ++i) {1879Node *ii = in(i);1880if (ii->is_MergeMem()) {1881MergeMemNode* n = ii->as_MergeMem();1882for (MergeMemStream mms(result, n); mms.next_non_empty2(); ) {1883// If we have not seen this slice yet, make a phi for it.1884bool made_new_phi = false;1885if (mms.is_empty()) {1886Node* new_phi = new_base->slice_memory(mms.adr_type(phase->C));1887made_new_phi = true;1888if (igvn) {1889igvn->register_new_node_with_optimizer(new_phi);1890hook->add_req(new_phi);1891}1892mms.set_memory(new_phi);1893}1894Node* phi = mms.memory();1895assert(made_new_phi || phi->in(i) == n, "replace the i-th merge by a slice");1896phi->set_req(i, mms.memory2());1897}1898}1899}1900// Distribute all self-loops.1901{ // (Extra braces to hide mms.)1902for (MergeMemStream mms(result); mms.next_non_empty(); ) {1903Node* phi = mms.memory();1904for (uint i = 1; i < req(); ++i) {1905if (phi->in(i) == this) phi->set_req(i, phi);1906}1907}1908}1909// now transform the new nodes, and return the mergemem1910for (MergeMemStream mms(result); mms.next_non_empty(); ) {1911Node* phi = mms.memory();1912mms.set_memory(phase->transform(phi));1913}1914if (igvn) { // Unhook.1915igvn->hash_delete(hook);1916for (uint i = 1; i < hook->req(); i++) {1917hook->set_req(i, NULL);1918}1919}1920// Replace self with the result.1921return result;1922}1923}1924//1925// Other optimizations on the memory chain1926//1927const TypePtr* at = adr_type();1928for( uint i=1; i<req(); ++i ) {// For all paths in1929Node *ii = in(i);1930Node *new_in = MemNode::optimize_memory_chain(ii, at, NULL, phase);1931if (ii != new_in ) {1932set_req(i, new_in);1933progress = this;1934}1935}1936}19371938#ifdef _LP641939// Push DecodeN/DecodeNKlass down through phi.1940// The rest of phi graph will transform by split EncodeP node though phis up.1941if ((UseCompressedOops || UseCompressedClassPointers) && can_reshape && progress == NULL) {1942bool may_push = true;1943bool has_decodeN = false;1944bool is_decodeN = false;1945for (uint i=1; i<req(); ++i) {// For all paths in1946Node *ii = in(i);1947if (ii->is_DecodeNarrowPtr() && ii->bottom_type() == bottom_type()) {1948// Do optimization if a non dead path exist.1949if (ii->in(1)->bottom_type() != Type::TOP) {1950has_decodeN = true;1951is_decodeN = ii->is_DecodeN();1952}1953} else if (!ii->is_Phi()) {1954may_push = false;1955}1956}19571958if (has_decodeN && may_push) {1959PhaseIterGVN *igvn = phase->is_IterGVN();1960// Make narrow type for new phi.1961const Type* narrow_t;1962if (is_decodeN) {1963narrow_t = TypeNarrowOop::make(this->bottom_type()->is_ptr());1964} else {1965narrow_t = TypeNarrowKlass::make(this->bottom_type()->is_ptr());1966}1967PhiNode* new_phi = new (phase->C) PhiNode(r, narrow_t);1968uint orig_cnt = req();1969for (uint i=1; i<req(); ++i) {// For all paths in1970Node *ii = in(i);1971Node* new_ii = NULL;1972if (ii->is_DecodeNarrowPtr()) {1973assert(ii->bottom_type() == bottom_type(), "sanity");1974new_ii = ii->in(1);1975} else {1976assert(ii->is_Phi(), "sanity");1977if (ii->as_Phi() == this) {1978new_ii = new_phi;1979} else {1980if (is_decodeN) {1981new_ii = new (phase->C) EncodePNode(ii, narrow_t);1982} else {1983new_ii = new (phase->C) EncodePKlassNode(ii, narrow_t);1984}1985igvn->register_new_node_with_optimizer(new_ii);1986}1987}1988new_phi->set_req(i, new_ii);1989}1990igvn->register_new_node_with_optimizer(new_phi, this);1991if (is_decodeN) {1992progress = new (phase->C) DecodeNNode(new_phi, bottom_type());1993} else {1994progress = new (phase->C) DecodeNKlassNode(new_phi, bottom_type());1995}1996}1997}1998#endif19992000return progress; // Return any progress2001}20022003//------------------------------is_tripcount-----------------------------------2004bool PhiNode::is_tripcount() const {2005return (in(0) != NULL && in(0)->is_CountedLoop() &&2006in(0)->as_CountedLoop()->phi() == this);2007}20082009//------------------------------out_RegMask------------------------------------2010const RegMask &PhiNode::in_RegMask(uint i) const {2011return i ? out_RegMask() : RegMask::Empty;2012}20132014const RegMask &PhiNode::out_RegMask() const {2015uint ideal_reg = _type->ideal_reg();2016assert( ideal_reg != Node::NotAMachineReg, "invalid type at Phi" );2017if( ideal_reg == 0 ) return RegMask::Empty;2018assert(ideal_reg != Op_RegFlags, "flags register is not spillable");2019return *(Compile::current()->matcher()->idealreg2spillmask[ideal_reg]);2020}20212022#ifndef PRODUCT2023void PhiNode::dump_spec(outputStream *st) const {2024TypeNode::dump_spec(st);2025if (is_tripcount()) {2026st->print(" #tripcount");2027}2028}2029#endif203020312032//=============================================================================2033const Type *GotoNode::Value( PhaseTransform *phase ) const {2034// If the input is reachable, then we are executed.2035// If the input is not reachable, then we are not executed.2036return phase->type(in(0));2037}20382039Node *GotoNode::Identity( PhaseTransform *phase ) {2040return in(0); // Simple copy of incoming control2041}20422043const RegMask &GotoNode::out_RegMask() const {2044return RegMask::Empty;2045}20462047//=============================================================================2048const RegMask &JumpNode::out_RegMask() const {2049return RegMask::Empty;2050}20512052//=============================================================================2053const RegMask &JProjNode::out_RegMask() const {2054return RegMask::Empty;2055}20562057//=============================================================================2058const RegMask &CProjNode::out_RegMask() const {2059return RegMask::Empty;2060}2061206220632064//=============================================================================20652066uint PCTableNode::hash() const { return Node::hash() + _size; }2067uint PCTableNode::cmp( const Node &n ) const2068{ return _size == ((PCTableNode&)n)._size; }20692070const Type *PCTableNode::bottom_type() const {2071const Type** f = TypeTuple::fields(_size);2072for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;2073return TypeTuple::make(_size, f);2074}20752076//------------------------------Value------------------------------------------2077// Compute the type of the PCTableNode. If reachable it is a tuple of2078// Control, otherwise the table targets are not reachable2079const Type *PCTableNode::Value( PhaseTransform *phase ) const {2080if( phase->type(in(0)) == Type::CONTROL )2081return bottom_type();2082return Type::TOP; // All paths dead? Then so are we2083}20842085//------------------------------Ideal------------------------------------------2086// Return a node which is more "ideal" than the current node. Strip out2087// control copies2088Node *PCTableNode::Ideal(PhaseGVN *phase, bool can_reshape) {2089return remove_dead_region(phase, can_reshape) ? this : NULL;2090}20912092//=============================================================================2093uint JumpProjNode::hash() const {2094return Node::hash() + _dest_bci;2095}20962097uint JumpProjNode::cmp( const Node &n ) const {2098return ProjNode::cmp(n) &&2099_dest_bci == ((JumpProjNode&)n)._dest_bci;2100}21012102#ifndef PRODUCT2103void JumpProjNode::dump_spec(outputStream *st) const {2104ProjNode::dump_spec(st);2105st->print("@bci %d ",_dest_bci);2106}2107#endif21082109//=============================================================================2110//------------------------------Value------------------------------------------2111// Check for being unreachable, or for coming from a Rethrow. Rethrow's cannot2112// have the default "fall_through_index" path.2113const Type *CatchNode::Value( PhaseTransform *phase ) const {2114// Unreachable? Then so are all paths from here.2115if( phase->type(in(0)) == Type::TOP ) return Type::TOP;2116// First assume all paths are reachable2117const Type** f = TypeTuple::fields(_size);2118for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;2119// Identify cases that will always throw an exception2120// () rethrow call2121// () virtual or interface call with NULL receiver2122// () call is a check cast with incompatible arguments2123if( in(1)->is_Proj() ) {2124Node *i10 = in(1)->in(0);2125if( i10->is_Call() ) {2126CallNode *call = i10->as_Call();2127// Rethrows always throw exceptions, never return2128if (call->entry_point() == OptoRuntime::rethrow_stub()) {2129f[CatchProjNode::fall_through_index] = Type::TOP;2130} else if( call->req() > TypeFunc::Parms ) {2131const Type *arg0 = phase->type( call->in(TypeFunc::Parms) );2132// Check for null receiver to virtual or interface calls2133if( call->is_CallDynamicJava() &&2134arg0->higher_equal(TypePtr::NULL_PTR) ) {2135f[CatchProjNode::fall_through_index] = Type::TOP;2136}2137} // End of if not a runtime stub2138} // End of if have call above me2139} // End of slot 1 is not a projection2140return TypeTuple::make(_size, f);2141}21422143//=============================================================================2144uint CatchProjNode::hash() const {2145return Node::hash() + _handler_bci;2146}214721482149uint CatchProjNode::cmp( const Node &n ) const {2150return ProjNode::cmp(n) &&2151_handler_bci == ((CatchProjNode&)n)._handler_bci;2152}215321542155//------------------------------Identity---------------------------------------2156// If only 1 target is possible, choose it if it is the main control2157Node *CatchProjNode::Identity( PhaseTransform *phase ) {2158// If my value is control and no other value is, then treat as ID2159const TypeTuple *t = phase->type(in(0))->is_tuple();2160if (t->field_at(_con) != Type::CONTROL) return this;2161// If we remove the last CatchProj and elide the Catch/CatchProj, then we2162// also remove any exception table entry. Thus we must know the call2163// feeding the Catch will not really throw an exception. This is ok for2164// the main fall-thru control (happens when we know a call can never throw2165// an exception) or for "rethrow", because a further optimization will2166// yank the rethrow (happens when we inline a function that can throw an2167// exception and the caller has no handler). Not legal, e.g., for passing2168// a NULL receiver to a v-call, or passing bad types to a slow-check-cast.2169// These cases MUST throw an exception via the runtime system, so the VM2170// will be looking for a table entry.2171Node *proj = in(0)->in(1); // Expect a proj feeding CatchNode2172CallNode *call;2173if (_con != TypeFunc::Control && // Bail out if not the main control.2174!(proj->is_Proj() && // AND NOT a rethrow2175proj->in(0)->is_Call() &&2176(call = proj->in(0)->as_Call()) &&2177call->entry_point() == OptoRuntime::rethrow_stub()))2178return this;21792180// Search for any other path being control2181for (uint i = 0; i < t->cnt(); i++) {2182if (i != _con && t->field_at(i) == Type::CONTROL)2183return this;2184}2185// Only my path is possible; I am identity on control to the jump2186return in(0)->in(0);2187}218821892190#ifndef PRODUCT2191void CatchProjNode::dump_spec(outputStream *st) const {2192ProjNode::dump_spec(st);2193st->print("@bci %d ",_handler_bci);2194}2195#endif21962197//=============================================================================2198//------------------------------Identity---------------------------------------2199// Check for CreateEx being Identity.2200Node *CreateExNode::Identity( PhaseTransform *phase ) {2201if( phase->type(in(1)) == Type::TOP ) return in(1);2202if( phase->type(in(0)) == Type::TOP ) return in(0);2203// We only come from CatchProj, unless the CatchProj goes away.2204// If the CatchProj is optimized away, then we just carry the2205// exception oop through.2206CallNode *call = in(1)->in(0)->as_Call();22072208return ( in(0)->is_CatchProj() && in(0)->in(0)->in(1) == in(1) )2209? this2210: call->in(TypeFunc::Parms);2211}22122213//=============================================================================2214//------------------------------Value------------------------------------------2215// Check for being unreachable.2216const Type *NeverBranchNode::Value( PhaseTransform *phase ) const {2217if (!in(0) || in(0)->is_top()) return Type::TOP;2218return bottom_type();2219}22202221//------------------------------Ideal------------------------------------------2222// Check for no longer being part of a loop2223Node *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) {2224if (can_reshape && !in(0)->is_Loop()) {2225// Dead code elimination can sometimes delete this projection so2226// if it's not there, there's nothing to do.2227Node* fallthru = proj_out(0);2228if (fallthru != NULL) {2229phase->is_IterGVN()->replace_node(fallthru, in(0));2230}2231return phase->C->top();2232}2233return NULL;2234}22352236#ifndef PRODUCT2237void NeverBranchNode::format( PhaseRegAlloc *ra_, outputStream *st) const {2238st->print("%s", Name());2239}2240#endif224122422243