Path: blob/master/src/hotspot/share/opto/cfgnode.cpp
40930 views
/*1* Copyright (c) 1997, 2021, 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 "gc/shared/barrierSet.hpp"26#include "gc/shared/c2/barrierSetC2.hpp"27#include "memory/allocation.inline.hpp"28#include "memory/resourceArea.hpp"29#include "oops/objArrayKlass.hpp"30#include "opto/addnode.hpp"31#include "opto/castnode.hpp"32#include "opto/cfgnode.hpp"33#include "opto/connode.hpp"34#include "opto/convertnode.hpp"35#include "opto/loopnode.hpp"36#include "opto/machnode.hpp"37#include "opto/movenode.hpp"38#include "opto/narrowptrnode.hpp"39#include "opto/mulnode.hpp"40#include "opto/phaseX.hpp"41#include "opto/regmask.hpp"42#include "opto/runtime.hpp"43#include "opto/subnode.hpp"44#include "opto/vectornode.hpp"45#include "utilities/vmError.hpp"4647// Portions of code courtesy of Clifford Click4849// Optimization - Graph Style5051//=============================================================================52//------------------------------Value------------------------------------------53// Compute the type of the RegionNode.54const Type* RegionNode::Value(PhaseGVN* phase) const {55for( uint i=1; i<req(); ++i ) { // For all paths in56Node *n = in(i); // Get Control source57if( !n ) continue; // Missing inputs are TOP58if( phase->type(n) == Type::CONTROL )59return Type::CONTROL;60}61return Type::TOP; // All paths dead? Then so are we62}6364//------------------------------Identity---------------------------------------65// Check for Region being Identity.66Node* RegionNode::Identity(PhaseGVN* phase) {67// Cannot have Region be an identity, even if it has only 1 input.68// Phi users cannot have their Region input folded away for them,69// since they need to select the proper data input70return this;71}7273//------------------------------merge_region-----------------------------------74// If a Region flows into a Region, merge into one big happy merge. This is75// hard to do if there is stuff that has to happen76static Node *merge_region(RegionNode *region, PhaseGVN *phase) {77if( region->Opcode() != Op_Region ) // Do not do to LoopNodes78return NULL;79Node *progress = NULL; // Progress flag80PhaseIterGVN *igvn = phase->is_IterGVN();8182uint rreq = region->req();83for( uint i = 1; i < rreq; i++ ) {84Node *r = region->in(i);85if( r && r->Opcode() == Op_Region && // Found a region?86r->in(0) == r && // Not already collapsed?87r != region && // Avoid stupid situations88r->outcnt() == 2 ) { // Self user and 'region' user only?89assert(!r->as_Region()->has_phi(), "no phi users");90if( !progress ) { // No progress91if (region->has_phi()) {92return NULL; // Only flatten if no Phi users93// igvn->hash_delete( phi );94}95igvn->hash_delete( region );96progress = region; // Making progress97}98igvn->hash_delete( r );99100// Append inputs to 'r' onto 'region'101for( uint j = 1; j < r->req(); j++ ) {102// Move an input from 'r' to 'region'103region->add_req(r->in(j));104r->set_req(j, phase->C->top());105// Update phis of 'region'106//for( uint k = 0; k < max; k++ ) {107// Node *phi = region->out(k);108// if( phi->is_Phi() ) {109// phi->add_req(phi->in(i));110// }111//}112113rreq++; // One more input to Region114} // Found a region to merge into Region115igvn->_worklist.push(r);116// Clobber pointer to the now dead 'r'117region->set_req(i, phase->C->top());118}119}120121return progress;122}123124125126//--------------------------------has_phi--------------------------------------127// Helper function: Return any PhiNode that uses this region or NULL128PhiNode* RegionNode::has_phi() const {129for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {130Node* phi = fast_out(i);131if (phi->is_Phi()) { // Check for Phi users132assert(phi->in(0) == (Node*)this, "phi uses region only via in(0)");133return phi->as_Phi(); // this one is good enough134}135}136137return NULL;138}139140141//-----------------------------has_unique_phi----------------------------------142// Helper function: Return the only PhiNode that uses this region or NULL143PhiNode* RegionNode::has_unique_phi() const {144// Check that only one use is a Phi145PhiNode* only_phi = NULL;146for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {147Node* phi = fast_out(i);148if (phi->is_Phi()) { // Check for Phi users149assert(phi->in(0) == (Node*)this, "phi uses region only via in(0)");150if (only_phi == NULL) {151only_phi = phi->as_Phi();152} else {153return NULL; // multiple phis154}155}156}157158return only_phi;159}160161162//------------------------------check_phi_clipping-----------------------------163// Helper function for RegionNode's identification of FP clipping164// Check inputs to the Phi165static bool check_phi_clipping( PhiNode *phi, ConNode * &min, uint &min_idx, ConNode * &max, uint &max_idx, Node * &val, uint &val_idx ) {166min = NULL;167max = NULL;168val = NULL;169min_idx = 0;170max_idx = 0;171val_idx = 0;172uint phi_max = phi->req();173if( phi_max == 4 ) {174for( uint j = 1; j < phi_max; ++j ) {175Node *n = phi->in(j);176int opcode = n->Opcode();177switch( opcode ) {178case Op_ConI:179{180if( min == NULL ) {181min = n->Opcode() == Op_ConI ? (ConNode*)n : NULL;182min_idx = j;183} else {184max = n->Opcode() == Op_ConI ? (ConNode*)n : NULL;185max_idx = j;186if( min->get_int() > max->get_int() ) {187// Swap min and max188ConNode *temp;189uint temp_idx;190temp = min; min = max; max = temp;191temp_idx = min_idx; min_idx = max_idx; max_idx = temp_idx;192}193}194}195break;196default:197{198val = n;199val_idx = j;200}201break;202}203}204}205return ( min && max && val && (min->get_int() <= 0) && (max->get_int() >=0) );206}207208209//------------------------------check_if_clipping------------------------------210// Helper function for RegionNode's identification of FP clipping211// Check that inputs to Region come from two IfNodes,212//213// If214// False True215// If |216// False True |217// | | |218// RegionNode_inputs219//220static bool check_if_clipping( const RegionNode *region, IfNode * &bot_if, IfNode * &top_if ) {221top_if = NULL;222bot_if = NULL;223224// Check control structure above RegionNode for (if ( if ) )225Node *in1 = region->in(1);226Node *in2 = region->in(2);227Node *in3 = region->in(3);228// Check that all inputs are projections229if( in1->is_Proj() && in2->is_Proj() && in3->is_Proj() ) {230Node *in10 = in1->in(0);231Node *in20 = in2->in(0);232Node *in30 = in3->in(0);233// Check that #1 and #2 are ifTrue and ifFalse from same If234if( in10 != NULL && in10->is_If() &&235in20 != NULL && in20->is_If() &&236in30 != NULL && in30->is_If() && in10 == in20 &&237(in1->Opcode() != in2->Opcode()) ) {238Node *in100 = in10->in(0);239Node *in1000 = (in100 != NULL && in100->is_Proj()) ? in100->in(0) : NULL;240// Check that control for in10 comes from other branch of IF from in3241if( in1000 != NULL && in1000->is_If() &&242in30 == in1000 && (in3->Opcode() != in100->Opcode()) ) {243// Control pattern checks244top_if = (IfNode*)in1000;245bot_if = (IfNode*)in10;246}247}248}249250return (top_if != NULL);251}252253254//------------------------------check_convf2i_clipping-------------------------255// Helper function for RegionNode's identification of FP clipping256// Verify that the value input to the phi comes from "ConvF2I; LShift; RShift"257static bool check_convf2i_clipping( PhiNode *phi, uint idx, ConvF2INode * &convf2i, Node *min, Node *max) {258convf2i = NULL;259260// Check for the RShiftNode261Node *rshift = phi->in(idx);262assert( rshift, "Previous checks ensure phi input is present");263if( rshift->Opcode() != Op_RShiftI ) { return false; }264265// Check for the LShiftNode266Node *lshift = rshift->in(1);267assert( lshift, "Previous checks ensure phi input is present");268if( lshift->Opcode() != Op_LShiftI ) { return false; }269270// Check for the ConvF2INode271Node *conv = lshift->in(1);272if( conv->Opcode() != Op_ConvF2I ) { return false; }273274// Check that shift amounts are only to get sign bits set after F2I275jint max_cutoff = max->get_int();276jint min_cutoff = min->get_int();277jint left_shift = lshift->in(2)->get_int();278jint right_shift = rshift->in(2)->get_int();279jint max_post_shift = nth_bit(BitsPerJavaInteger - left_shift - 1);280if( left_shift != right_shift ||2810 > left_shift || left_shift >= BitsPerJavaInteger ||282max_post_shift < max_cutoff ||283max_post_shift < -min_cutoff ) {284// Shifts are necessary but current transformation eliminates them285return false;286}287288// OK to return the result of ConvF2I without shifting289convf2i = (ConvF2INode*)conv;290return true;291}292293294//------------------------------check_compare_clipping-------------------------295// Helper function for RegionNode's identification of FP clipping296static bool check_compare_clipping( bool less_than, IfNode *iff, ConNode *limit, Node * & input ) {297Node *i1 = iff->in(1);298if ( !i1->is_Bool() ) { return false; }299BoolNode *bool1 = i1->as_Bool();300if( less_than && bool1->_test._test != BoolTest::le ) { return false; }301else if( !less_than && bool1->_test._test != BoolTest::lt ) { return false; }302const Node *cmpF = bool1->in(1);303if( cmpF->Opcode() != Op_CmpF ) { return false; }304// Test that the float value being compared against305// is equivalent to the int value used as a limit306Node *nodef = cmpF->in(2);307if( nodef->Opcode() != Op_ConF ) { return false; }308jfloat conf = nodef->getf();309jint coni = limit->get_int();310if( ((int)conf) != coni ) { return false; }311input = cmpF->in(1);312return true;313}314315//------------------------------is_unreachable_region--------------------------316// Find if the Region node is reachable from the root.317bool RegionNode::is_unreachable_region(const PhaseGVN* phase) {318Node* top = phase->C->top();319assert(req() == 2 || (req() == 3 && in(1) != NULL && in(2) == top), "sanity check arguments");320if (_is_unreachable_region) {321// Return cached result from previous evaluation which should still be valid322assert(is_unreachable_from_root(phase), "walk the graph again and check if its indeed unreachable");323return true;324}325326// First, cut the simple case of fallthrough region when NONE of327// region's phis references itself directly or through a data node.328if (is_possible_unsafe_loop(phase)) {329// If we have a possible unsafe loop, check if the region node is actually unreachable from root.330if (is_unreachable_from_root(phase)) {331_is_unreachable_region = true;332return true;333}334}335return false;336}337338bool RegionNode::is_possible_unsafe_loop(const PhaseGVN* phase) const {339uint max = outcnt();340uint i;341for (i = 0; i < max; i++) {342Node* n = raw_out(i);343if (n != NULL && n->is_Phi()) {344PhiNode* phi = n->as_Phi();345assert(phi->in(0) == this, "sanity check phi");346if (phi->outcnt() == 0) {347continue; // Safe case - no loops348}349if (phi->outcnt() == 1) {350Node* u = phi->raw_out(0);351// Skip if only one use is an other Phi or Call or Uncommon trap.352// It is safe to consider this case as fallthrough.353if (u != NULL && (u->is_Phi() || u->is_CFG())) {354continue;355}356}357// Check when phi references itself directly or through an other node.358if (phi->as_Phi()->simple_data_loop_check(phi->in(1)) >= PhiNode::Unsafe) {359break; // Found possible unsafe data loop.360}361}362}363if (i >= max) {364return false; // An unsafe case was NOT found - don't need graph walk.365}366return true;367}368369bool RegionNode::is_unreachable_from_root(const PhaseGVN* phase) const {370ResourceMark rm;371Node_List nstack;372VectorSet visited;373374// Mark all control nodes reachable from root outputs375Node *n = (Node*)phase->C->root();376nstack.push(n);377visited.set(n->_idx);378while (nstack.size() != 0) {379n = nstack.pop();380uint max = n->outcnt();381for (uint i = 0; i < max; i++) {382Node* m = n->raw_out(i);383if (m != NULL && m->is_CFG()) {384if (m == this) {385return false; // We reached the Region node - it is not dead.386}387if (!visited.test_set(m->_idx))388nstack.push(m);389}390}391}392return true; // The Region node is unreachable - it is dead.393}394395bool RegionNode::try_clean_mem_phi(PhaseGVN *phase) {396// Incremental inlining + PhaseStringOpts sometimes produce:397//398// cmpP with 1 top input399// |400// If401// / \402// IfFalse IfTrue /- Some Node403// \ / / /404// Region / /-MergeMem405// \---Phi406//407//408// It's expected by PhaseStringOpts that the Region goes away and is409// replaced by If's control input but because there's still a Phi,410// the Region stays in the graph. The top input from the cmpP is411// propagated forward and a subgraph that is useful goes away. The412// code below replaces the Phi with the MergeMem so that the Region413// is simplified.414415PhiNode* phi = has_unique_phi();416if (phi && phi->type() == Type::MEMORY && req() == 3 && phi->is_diamond_phi(true)) {417MergeMemNode* m = NULL;418assert(phi->req() == 3, "same as region");419for (uint i = 1; i < 3; ++i) {420Node *mem = phi->in(i);421if (mem && mem->is_MergeMem() && in(i)->outcnt() == 1) {422// Nothing is control-dependent on path #i except the region itself.423m = mem->as_MergeMem();424uint j = 3 - i;425Node* other = phi->in(j);426if (other && other == m->base_memory()) {427// m is a successor memory to other, and is not pinned inside the diamond, so push it out.428// This will allow the diamond to collapse completely.429phase->is_IterGVN()->replace_node(phi, m);430return true;431}432}433}434}435return false;436}437438//------------------------------Ideal------------------------------------------439// Return a node which is more "ideal" than the current node. Must preserve440// the CFG, but we can still strip out dead paths.441Node *RegionNode::Ideal(PhaseGVN *phase, bool can_reshape) {442if( !can_reshape && !in(0) ) return NULL; // Already degraded to a Copy443assert(!in(0) || !in(0)->is_Root(), "not a specially hidden merge");444445// Check for RegionNode with no Phi users and both inputs come from either446// arm of the same IF. If found, then the control-flow split is useless.447bool has_phis = false;448if (can_reshape) { // Need DU info to check for Phi users449has_phis = (has_phi() != NULL); // Cache result450if (has_phis && try_clean_mem_phi(phase)) {451has_phis = false;452}453454if (!has_phis) { // No Phi users? Nothing merging?455for (uint i = 1; i < req()-1; i++) {456Node *if1 = in(i);457if( !if1 ) continue;458Node *iff = if1->in(0);459if( !iff || !iff->is_If() ) continue;460for( uint j=i+1; j<req(); j++ ) {461if( in(j) && in(j)->in(0) == iff &&462if1->Opcode() != in(j)->Opcode() ) {463// Add the IF Projections to the worklist. They (and the IF itself)464// will be eliminated if dead.465phase->is_IterGVN()->add_users_to_worklist(iff);466set_req(i, iff->in(0));// Skip around the useless IF diamond467set_req(j, NULL);468return this; // Record progress469}470}471}472}473}474475// Remove TOP or NULL input paths. If only 1 input path remains, this Region476// degrades to a copy.477bool add_to_worklist = false;478bool modified = false;479int cnt = 0; // Count of values merging480DEBUG_ONLY( int cnt_orig = req(); ) // Save original inputs count481int del_it = 0; // The last input path we delete482// For all inputs...483for( uint i=1; i<req(); ++i ){// For all paths in484Node *n = in(i); // Get the input485if( n != NULL ) {486// Remove useless control copy inputs487if( n->is_Region() && n->as_Region()->is_copy() ) {488set_req(i, n->nonnull_req());489modified = true;490i--;491continue;492}493if( n->is_Proj() ) { // Remove useless rethrows494Node *call = n->in(0);495if (call->is_Call() && call->as_Call()->entry_point() == OptoRuntime::rethrow_stub()) {496set_req(i, call->in(0));497modified = true;498i--;499continue;500}501}502if( phase->type(n) == Type::TOP ) {503set_req(i, NULL); // Ignore TOP inputs504modified = true;505i--;506continue;507}508cnt++; // One more value merging509510} else if (can_reshape) { // Else found dead path with DU info511PhaseIterGVN *igvn = phase->is_IterGVN();512del_req(i); // Yank path from self513del_it = i;514uint max = outcnt();515DUIterator j;516bool progress = true;517while(progress) { // Need to establish property over all users518progress = false;519for (j = outs(); has_out(j); j++) {520Node *n = out(j);521if( n->req() != req() && n->is_Phi() ) {522assert( n->in(0) == this, "" );523igvn->hash_delete(n); // Yank from hash before hacking edges524n->set_req_X(i,NULL,igvn);// Correct DU info525n->del_req(i); // Yank path from Phis526if( max != outcnt() ) {527progress = true;528j = refresh_out_pos(j);529max = outcnt();530}531}532}533}534add_to_worklist = true;535i--;536}537}538539if (can_reshape && cnt == 1) {540// Is it dead loop?541// If it is LoopNopde it had 2 (+1 itself) inputs and542// one of them was cut. The loop is dead if it was EntryContol.543// Loop node may have only one input because entry path544// is removed in PhaseIdealLoop::Dominators().545assert(!this->is_Loop() || cnt_orig <= 3, "Loop node should have 3 or less inputs");546if ((this->is_Loop() && (del_it == LoopNode::EntryControl ||547(del_it == 0 && is_unreachable_region(phase)))) ||548(!this->is_Loop() && has_phis && is_unreachable_region(phase))) {549// Yes, the region will be removed during the next step below.550// Cut the backedge input and remove phis since no data paths left.551// We don't cut outputs to other nodes here since we need to put them552// on the worklist.553PhaseIterGVN *igvn = phase->is_IterGVN();554if (in(1)->outcnt() == 1) {555igvn->_worklist.push(in(1));556}557del_req(1);558cnt = 0;559assert( req() == 1, "no more inputs expected" );560uint max = outcnt();561bool progress = true;562Node *top = phase->C->top();563DUIterator j;564while(progress) {565progress = false;566for (j = outs(); has_out(j); j++) {567Node *n = out(j);568if( n->is_Phi() ) {569assert(n->in(0) == this, "");570assert( n->req() == 2 && n->in(1) != NULL, "Only one data input expected" );571// Break dead loop data path.572// Eagerly replace phis with top to avoid regionless phis.573igvn->replace_node(n, top);574if( max != outcnt() ) {575progress = true;576j = refresh_out_pos(j);577max = outcnt();578}579}580}581}582add_to_worklist = true;583}584}585if (add_to_worklist) {586phase->is_IterGVN()->add_users_to_worklist(this); // Revisit collapsed Phis587}588589if( cnt <= 1 ) { // Only 1 path in?590set_req(0, NULL); // Null control input for region copy591if( cnt == 0 && !can_reshape) { // Parse phase - leave the node as it is.592// No inputs or all inputs are NULL.593return NULL;594} else if (can_reshape) { // Optimization phase - remove the node595PhaseIterGVN *igvn = phase->is_IterGVN();596// Strip mined (inner) loop is going away, remove outer loop.597if (is_CountedLoop() &&598as_Loop()->is_strip_mined()) {599Node* outer_sfpt = as_CountedLoop()->outer_safepoint();600Node* outer_out = as_CountedLoop()->outer_loop_exit();601if (outer_sfpt != NULL && outer_out != NULL) {602Node* in = outer_sfpt->in(0);603igvn->replace_node(outer_out, in);604LoopNode* outer = as_CountedLoop()->outer_loop();605igvn->replace_input_of(outer, LoopNode::LoopBackControl, igvn->C->top());606}607}608Node *parent_ctrl;609if( cnt == 0 ) {610assert( req() == 1, "no inputs expected" );611// During IGVN phase such region will be subsumed by TOP node612// so region's phis will have TOP as control node.613// Kill phis here to avoid it.614// Also set other user's input to top.615parent_ctrl = phase->C->top();616} else {617// The fallthrough case since we already checked dead loops above.618parent_ctrl = in(1);619assert(parent_ctrl != NULL, "Region is a copy of some non-null control");620assert(parent_ctrl != this, "Close dead loop");621}622if (!add_to_worklist)623igvn->add_users_to_worklist(this); // Check for further allowed opts624for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {625Node* n = last_out(i);626igvn->hash_delete(n); // Remove from worklist before modifying edges627if (n->outcnt() == 0) {628int uses_found = n->replace_edge(this, phase->C->top(), igvn);629if (uses_found > 1) { // (--i) done at the end of the loop.630i -= (uses_found - 1);631}632continue;633}634if( n->is_Phi() ) { // Collapse all Phis635// Eagerly replace phis to avoid regionless phis.636Node* in;637if( cnt == 0 ) {638assert( n->req() == 1, "No data inputs expected" );639in = parent_ctrl; // replaced by top640} else {641assert( n->req() == 2 && n->in(1) != NULL, "Only one data input expected" );642in = n->in(1); // replaced by unique input643if( n->as_Phi()->is_unsafe_data_reference(in) )644in = phase->C->top(); // replaced by top645}646igvn->replace_node(n, in);647}648else if( n->is_Region() ) { // Update all incoming edges649assert(n != this, "Must be removed from DefUse edges");650int uses_found = n->replace_edge(this, parent_ctrl, igvn);651if (uses_found > 1) { // (--i) done at the end of the loop.652i -= (uses_found - 1);653}654}655else {656assert(n->in(0) == this, "Expect RegionNode to be control parent");657n->set_req(0, parent_ctrl);658}659#ifdef ASSERT660for( uint k=0; k < n->req(); k++ ) {661assert(n->in(k) != this, "All uses of RegionNode should be gone");662}663#endif664}665// Remove the RegionNode itself from DefUse info666igvn->remove_dead_node(this);667return NULL;668}669return this; // Record progress670}671672673// If a Region flows into a Region, merge into one big happy merge.674if (can_reshape) {675Node *m = merge_region(this, phase);676if (m != NULL) return m;677}678679// Check if this region is the root of a clipping idiom on floats680if( ConvertFloat2IntClipping && can_reshape && req() == 4 ) {681// Check that only one use is a Phi and that it simplifies to two constants +682PhiNode* phi = has_unique_phi();683if (phi != NULL) { // One Phi user684// Check inputs to the Phi685ConNode *min;686ConNode *max;687Node *val;688uint min_idx;689uint max_idx;690uint val_idx;691if( check_phi_clipping( phi, min, min_idx, max, max_idx, val, val_idx ) ) {692IfNode *top_if;693IfNode *bot_if;694if( check_if_clipping( this, bot_if, top_if ) ) {695// Control pattern checks, now verify compares696Node *top_in = NULL; // value being compared against697Node *bot_in = NULL;698if( check_compare_clipping( true, bot_if, min, bot_in ) &&699check_compare_clipping( false, top_if, max, top_in ) ) {700if( bot_in == top_in ) {701PhaseIterGVN *gvn = phase->is_IterGVN();702assert( gvn != NULL, "Only had DefUse info in IterGVN");703// Only remaining check is that bot_in == top_in == (Phi's val + mods)704705// Check for the ConvF2INode706ConvF2INode *convf2i;707if( check_convf2i_clipping( phi, val_idx, convf2i, min, max ) &&708convf2i->in(1) == bot_in ) {709// Matched pattern, including LShiftI; RShiftI, replace with integer compares710// max test711Node *cmp = gvn->register_new_node_with_optimizer(new CmpINode( convf2i, min ));712Node *boo = gvn->register_new_node_with_optimizer(new BoolNode( cmp, BoolTest::lt ));713IfNode *iff = (IfNode*)gvn->register_new_node_with_optimizer(new IfNode( top_if->in(0), boo, PROB_UNLIKELY_MAG(5), top_if->_fcnt ));714Node *if_min= gvn->register_new_node_with_optimizer(new IfTrueNode (iff));715Node *ifF = gvn->register_new_node_with_optimizer(new IfFalseNode(iff));716// min test717cmp = gvn->register_new_node_with_optimizer(new CmpINode( convf2i, max ));718boo = gvn->register_new_node_with_optimizer(new BoolNode( cmp, BoolTest::gt ));719iff = (IfNode*)gvn->register_new_node_with_optimizer(new IfNode( ifF, boo, PROB_UNLIKELY_MAG(5), bot_if->_fcnt ));720Node *if_max= gvn->register_new_node_with_optimizer(new IfTrueNode (iff));721ifF = gvn->register_new_node_with_optimizer(new IfFalseNode(iff));722// update input edges to region node723set_req_X( min_idx, if_min, gvn );724set_req_X( max_idx, if_max, gvn );725set_req_X( val_idx, ifF, gvn );726// remove unnecessary 'LShiftI; RShiftI' idiom727gvn->hash_delete(phi);728phi->set_req_X( val_idx, convf2i, gvn );729gvn->hash_find_insert(phi);730// Return transformed region node731return this;732}733}734}735}736}737}738}739740if (can_reshape) {741modified |= optimize_trichotomy(phase->is_IterGVN());742}743744return modified ? this : NULL;745}746747//------------------------------optimize_trichotomy--------------------------748// Optimize nested comparisons of the following kind:749//750// int compare(int a, int b) {751// return (a < b) ? -1 : (a == b) ? 0 : 1;752// }753//754// Shape 1:755// if (compare(a, b) == 1) { ... } -> if (a > b) { ... }756//757// Shape 2:758// if (compare(a, b) == 0) { ... } -> if (a == b) { ... }759//760// Above code leads to the following IR shapes where both Ifs compare the761// same value and two out of three region inputs idx1 and idx2 map to762// the same value and control flow.763//764// (1) If (2) If765// / \ / \766// Proj Proj Proj Proj767// | \ | \768// | If | If If769// | / \ | / \ / \770// | Proj Proj | Proj Proj ==> Proj Proj771// | / / \ | / | /772// Region / \ | / | /773// \ / \ | / | /774// Region Region Region775//776// The method returns true if 'this' is modified and false otherwise.777bool RegionNode::optimize_trichotomy(PhaseIterGVN* igvn) {778int idx1 = 1, idx2 = 2;779Node* region = NULL;780if (req() == 3 && in(1) != NULL && in(2) != NULL) {781// Shape 1: Check if one of the inputs is a region that merges two control782// inputs and has no other users (especially no Phi users).783region = in(1)->isa_Region() ? in(1) : in(2)->isa_Region();784if (region == NULL || region->outcnt() != 2 || region->req() != 3) {785return false; // No suitable region input found786}787} else if (req() == 4) {788// Shape 2: Check if two control inputs map to the same value of the unique phi789// user and treat these as if they would come from another region (shape (1)).790PhiNode* phi = has_unique_phi();791if (phi == NULL) {792return false; // No unique phi user793}794if (phi->in(idx1) != phi->in(idx2)) {795idx2 = 3;796if (phi->in(idx1) != phi->in(idx2)) {797idx1 = 2;798if (phi->in(idx1) != phi->in(idx2)) {799return false; // No equal phi inputs found800}801}802}803assert(phi->in(idx1) == phi->in(idx2), "must be"); // Region is merging same value804region = this;805}806if (region == NULL || region->in(idx1) == NULL || region->in(idx2) == NULL) {807return false; // Region does not merge two control inputs808}809// At this point we know that region->in(idx1) and region->(idx2) map to the same810// value and control flow. Now search for ifs that feed into these region inputs.811ProjNode* proj1 = region->in(idx1)->isa_Proj();812ProjNode* proj2 = region->in(idx2)->isa_Proj();813if (proj1 == NULL || proj1->outcnt() != 1 ||814proj2 == NULL || proj2->outcnt() != 1) {815return false; // No projection inputs with region as unique user found816}817assert(proj1 != proj2, "should be different projections");818IfNode* iff1 = proj1->in(0)->isa_If();819IfNode* iff2 = proj2->in(0)->isa_If();820if (iff1 == NULL || iff1->outcnt() != 2 ||821iff2 == NULL || iff2->outcnt() != 2) {822return false; // No ifs found823}824if (iff1 == iff2) {825igvn->add_users_to_worklist(iff1); // Make sure dead if is eliminated826igvn->replace_input_of(region, idx1, iff1->in(0));827igvn->replace_input_of(region, idx2, igvn->C->top());828return (region == this); // Remove useless if (both projections map to the same control/value)829}830BoolNode* bol1 = iff1->in(1)->isa_Bool();831BoolNode* bol2 = iff2->in(1)->isa_Bool();832if (bol1 == NULL || bol2 == NULL) {833return false; // No bool inputs found834}835Node* cmp1 = bol1->in(1);836Node* cmp2 = bol2->in(1);837bool commute = false;838if (!cmp1->is_Cmp() || !cmp2->is_Cmp()) {839return false; // No comparison840} else if (cmp1->Opcode() == Op_CmpF || cmp1->Opcode() == Op_CmpD ||841cmp2->Opcode() == Op_CmpF || cmp2->Opcode() == Op_CmpD ||842cmp1->Opcode() == Op_CmpP || cmp1->Opcode() == Op_CmpN ||843cmp2->Opcode() == Op_CmpP || cmp2->Opcode() == Op_CmpN ||844cmp1->is_SubTypeCheck() || cmp2->is_SubTypeCheck()) {845// Floats and pointers don't exactly obey trichotomy. To be on the safe side, don't transform their tests.846// SubTypeCheck is not commutative847return false;848} else if (cmp1 != cmp2) {849if (cmp1->in(1) == cmp2->in(2) &&850cmp1->in(2) == cmp2->in(1)) {851commute = true; // Same but swapped inputs, commute the test852} else {853return false; // Ifs are not comparing the same values854}855}856proj1 = proj1->other_if_proj();857proj2 = proj2->other_if_proj();858if (!((proj1->unique_ctrl_out() == iff2 &&859proj2->unique_ctrl_out() == this) ||860(proj2->unique_ctrl_out() == iff1 &&861proj1->unique_ctrl_out() == this))) {862return false; // Ifs are not connected through other projs863}864// Found 'iff -> proj -> iff -> proj -> this' shape where all other projs are merged865// through 'region' and map to the same value. Merge the boolean tests and replace866// the ifs by a single comparison.867BoolTest test1 = (proj1->_con == 1) ? bol1->_test : bol1->_test.negate();868BoolTest test2 = (proj2->_con == 1) ? bol2->_test : bol2->_test.negate();869test1 = commute ? test1.commute() : test1;870// After possibly commuting test1, if we can merge test1 & test2, then proj2/iff2/bol2 are the nodes to refine.871BoolTest::mask res = test1.merge(test2);872if (res == BoolTest::illegal) {873return false; // Unable to merge tests874}875// Adjust iff1 to always pass (only iff2 will remain)876igvn->replace_input_of(iff1, 1, igvn->intcon(proj1->_con));877if (res == BoolTest::never) {878// Merged test is always false, adjust iff2 to always fail879igvn->replace_input_of(iff2, 1, igvn->intcon(1 - proj2->_con));880} else {881// Replace bool input of iff2 with merged test882BoolNode* new_bol = new BoolNode(bol2->in(1), res);883igvn->replace_input_of(iff2, 1, igvn->transform((proj2->_con == 1) ? new_bol : new_bol->negate(igvn)));884if (new_bol->outcnt() == 0) {885igvn->remove_dead_node(new_bol);886}887}888return false;889}890891const RegMask &RegionNode::out_RegMask() const {892return RegMask::Empty;893}894895// Find the one non-null required input. RegionNode only896Node *Node::nonnull_req() const {897assert( is_Region(), "" );898for( uint i = 1; i < _cnt; i++ )899if( in(i) )900return in(i);901ShouldNotReachHere();902return NULL;903}904905906//=============================================================================907// note that these functions assume that the _adr_type field is flattened908uint PhiNode::hash() const {909const Type* at = _adr_type;910return TypeNode::hash() + (at ? at->hash() : 0);911}912bool PhiNode::cmp( const Node &n ) const {913return TypeNode::cmp(n) && _adr_type == ((PhiNode&)n)._adr_type;914}915static inline916const TypePtr* flatten_phi_adr_type(const TypePtr* at) {917if (at == NULL || at == TypePtr::BOTTOM) return at;918return Compile::current()->alias_type(at)->adr_type();919}920921//----------------------------make---------------------------------------------922// create a new phi with edges matching r and set (initially) to x923PhiNode* PhiNode::make(Node* r, Node* x, const Type *t, const TypePtr* at) {924uint preds = r->req(); // Number of predecessor paths925assert(t != Type::MEMORY || at == flatten_phi_adr_type(at), "flatten at");926PhiNode* p = new PhiNode(r, t, at);927for (uint j = 1; j < preds; j++) {928// Fill in all inputs, except those which the region does not yet have929if (r->in(j) != NULL)930p->init_req(j, x);931}932return p;933}934PhiNode* PhiNode::make(Node* r, Node* x) {935const Type* t = x->bottom_type();936const TypePtr* at = NULL;937if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());938return make(r, x, t, at);939}940PhiNode* PhiNode::make_blank(Node* r, Node* x) {941const Type* t = x->bottom_type();942const TypePtr* at = NULL;943if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());944return new PhiNode(r, t, at);945}946947948//------------------------slice_memory-----------------------------------------949// create a new phi with narrowed memory type950PhiNode* PhiNode::slice_memory(const TypePtr* adr_type) const {951PhiNode* mem = (PhiNode*) clone();952*(const TypePtr**)&mem->_adr_type = adr_type;953// convert self-loops, or else we get a bad graph954for (uint i = 1; i < req(); i++) {955if ((const Node*)in(i) == this) mem->set_req(i, mem);956}957mem->verify_adr_type();958return mem;959}960961//------------------------split_out_instance-----------------------------------962// Split out an instance type from a bottom phi.963PhiNode* PhiNode::split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const {964const TypeOopPtr *t_oop = at->isa_oopptr();965assert(t_oop != NULL && t_oop->is_known_instance(), "expecting instance oopptr");966const TypePtr *t = adr_type();967assert(type() == Type::MEMORY &&968(t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM ||969t->isa_oopptr() && !t->is_oopptr()->is_known_instance() &&970t->is_oopptr()->cast_to_exactness(true)971->is_oopptr()->cast_to_ptr_type(t_oop->ptr())972->is_oopptr()->cast_to_instance_id(t_oop->instance_id()) == t_oop),973"bottom or raw memory required");974975// Check if an appropriate node already exists.976Node *region = in(0);977for (DUIterator_Fast kmax, k = region->fast_outs(kmax); k < kmax; k++) {978Node* use = region->fast_out(k);979if( use->is_Phi()) {980PhiNode *phi2 = use->as_Phi();981if (phi2->type() == Type::MEMORY && phi2->adr_type() == at) {982return phi2;983}984}985}986Compile *C = igvn->C;987Arena *a = Thread::current()->resource_area();988Node_Array node_map = new Node_Array(a);989Node_Stack stack(a, C->live_nodes() >> 4);990PhiNode *nphi = slice_memory(at);991igvn->register_new_node_with_optimizer( nphi );992node_map.map(_idx, nphi);993stack.push((Node *)this, 1);994while(!stack.is_empty()) {995PhiNode *ophi = stack.node()->as_Phi();996uint i = stack.index();997assert(i >= 1, "not control edge");998stack.pop();999nphi = node_map[ophi->_idx]->as_Phi();1000for (; i < ophi->req(); i++) {1001Node *in = ophi->in(i);1002if (in == NULL || igvn->type(in) == Type::TOP)1003continue;1004Node *opt = MemNode::optimize_simple_memory_chain(in, t_oop, NULL, igvn);1005PhiNode *optphi = opt->is_Phi() ? opt->as_Phi() : NULL;1006if (optphi != NULL && optphi->adr_type() == TypePtr::BOTTOM) {1007opt = node_map[optphi->_idx];1008if (opt == NULL) {1009stack.push(ophi, i);1010nphi = optphi->slice_memory(at);1011igvn->register_new_node_with_optimizer( nphi );1012node_map.map(optphi->_idx, nphi);1013ophi = optphi;1014i = 0; // will get incremented at top of loop1015continue;1016}1017}1018nphi->set_req(i, opt);1019}1020}1021return nphi;1022}10231024//------------------------verify_adr_type--------------------------------------1025#ifdef ASSERT1026void PhiNode::verify_adr_type(VectorSet& visited, const TypePtr* at) const {1027if (visited.test_set(_idx)) return; //already visited10281029// recheck constructor invariants:1030verify_adr_type(false);10311032// recheck local phi/phi consistency:1033assert(_adr_type == at || _adr_type == TypePtr::BOTTOM,1034"adr_type must be consistent across phi nest");10351036// walk around1037for (uint i = 1; i < req(); i++) {1038Node* n = in(i);1039if (n == NULL) continue;1040const Node* np = in(i);1041if (np->is_Phi()) {1042np->as_Phi()->verify_adr_type(visited, at);1043} else if (n->bottom_type() == Type::TOP1044|| (n->is_Mem() && n->in(MemNode::Address)->bottom_type() == Type::TOP)) {1045// ignore top inputs1046} else {1047const TypePtr* nat = flatten_phi_adr_type(n->adr_type());1048// recheck phi/non-phi consistency at leaves:1049assert((nat != NULL) == (at != NULL), "");1050assert(nat == at || nat == TypePtr::BOTTOM,1051"adr_type must be consistent at leaves of phi nest");1052}1053}1054}10551056// Verify a whole nest of phis rooted at this one.1057void PhiNode::verify_adr_type(bool recursive) const {1058if (VMError::is_error_reported()) return; // muzzle asserts when debugging an error1059if (Node::in_dump()) return; // muzzle asserts when printing10601061assert((_type == Type::MEMORY) == (_adr_type != NULL), "adr_type for memory phis only");10621063if (!VerifyAliases) return; // verify thoroughly only if requested10641065assert(_adr_type == flatten_phi_adr_type(_adr_type),1066"Phi::adr_type must be pre-normalized");10671068if (recursive) {1069VectorSet visited;1070verify_adr_type(visited, _adr_type);1071}1072}1073#endif107410751076//------------------------------Value------------------------------------------1077// Compute the type of the PhiNode1078const Type* PhiNode::Value(PhaseGVN* phase) const {1079Node *r = in(0); // RegionNode1080if( !r ) // Copy or dead1081return in(1) ? phase->type(in(1)) : Type::TOP;10821083// Note: During parsing, phis are often transformed before their regions.1084// This means we have to use type_or_null to defend against untyped regions.1085if( phase->type_or_null(r) == Type::TOP ) // Dead code?1086return Type::TOP;10871088// Check for trip-counted loop. If so, be smarter.1089BaseCountedLoopNode* l = r->is_BaseCountedLoop() ? r->as_BaseCountedLoop() : NULL;1090if (l && ((const Node*)l->phi() == this)) { // Trip counted loop!1091// protect against init_trip() or limit() returning NULL1092if (l->can_be_counted_loop(phase)) {1093const Node* init = l->init_trip();1094const Node* limit = l->limit();1095const Node* stride = l->stride();1096if (init != NULL && limit != NULL && stride != NULL) {1097const TypeInteger* lo = phase->type(init)->isa_integer(l->bt());1098const TypeInteger* hi = phase->type(limit)->isa_integer(l->bt());1099const TypeInteger* stride_t = phase->type(stride)->isa_integer(l->bt());1100if (lo != NULL && hi != NULL && stride_t != NULL) { // Dying loops might have TOP here1101assert(stride_t->hi_as_long() >= stride_t->lo_as_long(), "bad stride type");1102BoolTest::mask bt = l->loopexit()->test_trip();1103// If the loop exit condition is "not equal", the condition1104// would not trigger if init > limit (if stride > 0) or if1105// init < limit if (stride > 0) so we can't deduce bounds1106// for the iv from the exit condition.1107if (bt != BoolTest::ne) {1108if (stride_t->hi_as_long() < 0) { // Down-counter loop1109swap(lo, hi);1110return TypeInteger::make(MIN2(lo->lo_as_long(), hi->lo_as_long()), hi->hi_as_long(), 3, l->bt())->filter_speculative(_type);1111} else if (stride_t->lo_as_long() >= 0) {1112return TypeInteger::make(lo->lo_as_long(), MAX2(lo->hi_as_long(), hi->hi_as_long()), 3, l->bt())->filter_speculative(_type);1113}1114}1115}1116}1117} else if (l->in(LoopNode::LoopBackControl) != NULL &&1118in(LoopNode::EntryControl) != NULL &&1119phase->type(l->in(LoopNode::LoopBackControl)) == Type::TOP) {1120// During CCP, if we saturate the type of a counted loop's Phi1121// before the special code for counted loop above has a chance1122// to run (that is as long as the type of the backedge's control1123// is top), we might end up with non monotonic types1124return phase->type(in(LoopNode::EntryControl))->filter_speculative(_type);1125}1126}11271128// Until we have harmony between classes and interfaces in the type1129// lattice, we must tread carefully around phis which implicitly1130// convert the one to the other.1131const TypePtr* ttp = _type->make_ptr();1132const TypeInstPtr* ttip = (ttp != NULL) ? ttp->isa_instptr() : NULL;1133const TypeKlassPtr* ttkp = (ttp != NULL) ? ttp->isa_klassptr() : NULL;1134bool is_intf = false;1135if (ttip != NULL) {1136ciKlass* k = ttip->klass();1137if (k->is_loaded() && k->is_interface())1138is_intf = true;1139}1140if (ttkp != NULL) {1141ciKlass* k = ttkp->klass();1142if (k->is_loaded() && k->is_interface())1143is_intf = true;1144}11451146// Default case: merge all inputs1147const Type *t = Type::TOP; // Merged type starting value1148for (uint i = 1; i < req(); ++i) {// For all paths in1149// Reachable control path?1150if (r->in(i) && phase->type(r->in(i)) == Type::CONTROL) {1151const Type* ti = phase->type(in(i));1152// We assume that each input of an interface-valued Phi is a true1153// subtype of that interface. This might not be true of the meet1154// of all the input types. The lattice is not distributive in1155// such cases. Ward off asserts in type.cpp by refusing to do1156// meets between interfaces and proper classes.1157const TypePtr* tip = ti->make_ptr();1158const TypeInstPtr* tiip = (tip != NULL) ? tip->isa_instptr() : NULL;1159if (tiip) {1160bool ti_is_intf = false;1161ciKlass* k = tiip->klass();1162if (k->is_loaded() && k->is_interface())1163ti_is_intf = true;1164if (is_intf != ti_is_intf)1165{ t = _type; break; }1166}1167t = t->meet_speculative(ti);1168}1169}11701171// The worst-case type (from ciTypeFlow) should be consistent with "t".1172// That is, we expect that "t->higher_equal(_type)" holds true.1173// There are various exceptions:1174// - Inputs which are phis might in fact be widened unnecessarily.1175// For example, an input might be a widened int while the phi is a short.1176// - Inputs might be BotPtrs but this phi is dependent on a null check,1177// and postCCP has removed the cast which encodes the result of the check.1178// - The type of this phi is an interface, and the inputs are classes.1179// - Value calls on inputs might produce fuzzy results.1180// (Occurrences of this case suggest improvements to Value methods.)1181//1182// It is not possible to see Type::BOTTOM values as phi inputs,1183// because the ciTypeFlow pre-pass produces verifier-quality types.1184const Type* ft = t->filter_speculative(_type); // Worst case type11851186#ifdef ASSERT1187// The following logic has been moved into TypeOopPtr::filter.1188const Type* jt = t->join_speculative(_type);1189if (jt->empty()) { // Emptied out???11901191// Check for evil case of 't' being a class and '_type' expecting an1192// interface. This can happen because the bytecodes do not contain1193// enough type info to distinguish a Java-level interface variable1194// from a Java-level object variable. If we meet 2 classes which1195// both implement interface I, but their meet is at 'j/l/O' which1196// doesn't implement I, we have no way to tell if the result should1197// be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows1198// into a Phi which "knows" it's an Interface type we'll have to1199// uplift the type.1200if (!t->empty() && ttip && ttip->is_loaded() && ttip->klass()->is_interface()) {1201assert(ft == _type, ""); // Uplift to interface1202} else if (!t->empty() && ttkp && ttkp->is_loaded() && ttkp->klass()->is_interface()) {1203assert(ft == _type, ""); // Uplift to interface1204} else {1205// We also have to handle 'evil cases' of interface- vs. class-arrays1206Type::get_arrays_base_elements(jt, _type, NULL, &ttip);1207if (!t->empty() && ttip != NULL && ttip->is_loaded() && ttip->klass()->is_interface()) {1208assert(ft == _type, ""); // Uplift to array of interface1209} else {1210// Otherwise it's something stupid like non-overlapping int ranges1211// found on dying counted loops.1212assert(ft == Type::TOP, ""); // Canonical empty value1213}1214}1215}12161217else {12181219// If we have an interface-typed Phi and we narrow to a class type, the join1220// should report back the class. However, if we have a J/L/Object1221// class-typed Phi and an interface flows in, it's possible that the meet &1222// join report an interface back out. This isn't possible but happens1223// because the type system doesn't interact well with interfaces.1224const TypePtr *jtp = jt->make_ptr();1225const TypeInstPtr *jtip = (jtp != NULL) ? jtp->isa_instptr() : NULL;1226const TypeKlassPtr *jtkp = (jtp != NULL) ? jtp->isa_klassptr() : NULL;1227if( jtip && ttip ) {1228if( jtip->is_loaded() && jtip->klass()->is_interface() &&1229ttip->is_loaded() && !ttip->klass()->is_interface() ) {1230assert(ft == ttip->cast_to_ptr_type(jtip->ptr()) ||1231ft->isa_narrowoop() && ft->make_ptr() == ttip->cast_to_ptr_type(jtip->ptr()), "");1232jt = ft;1233}1234}1235if( jtkp && ttkp ) {1236if( jtkp->is_loaded() && jtkp->klass()->is_interface() &&1237!jtkp->klass_is_exact() && // Keep exact interface klass (6894807)1238ttkp->is_loaded() && !ttkp->klass()->is_interface() ) {1239assert(ft == ttkp->cast_to_ptr_type(jtkp->ptr()) ||1240ft->isa_narrowklass() && ft->make_ptr() == ttkp->cast_to_ptr_type(jtkp->ptr()), "");1241jt = ft;1242}1243}1244if (jt != ft && jt->base() == ft->base()) {1245if (jt->isa_int() &&1246jt->is_int()->_lo == ft->is_int()->_lo &&1247jt->is_int()->_hi == ft->is_int()->_hi)1248jt = ft;1249if (jt->isa_long() &&1250jt->is_long()->_lo == ft->is_long()->_lo &&1251jt->is_long()->_hi == ft->is_long()->_hi)1252jt = ft;1253}1254if (jt != ft) {1255tty->print("merge type: "); t->dump(); tty->cr();1256tty->print("kill type: "); _type->dump(); tty->cr();1257tty->print("join type: "); jt->dump(); tty->cr();1258tty->print("filter type: "); ft->dump(); tty->cr();1259}1260assert(jt == ft, "");1261}1262#endif //ASSERT12631264// Deal with conversion problems found in data loops.1265ft = phase->saturate(ft, phase->type_or_null(this), _type);12661267return ft;1268}126912701271//------------------------------is_diamond_phi---------------------------------1272// Does this Phi represent a simple well-shaped diamond merge? Return the1273// index of the true path or 0 otherwise.1274// If check_control_only is true, do not inspect the If node at the1275// top, and return -1 (not an edge number) on success.1276int PhiNode::is_diamond_phi(bool check_control_only) const {1277// Check for a 2-path merge1278Node *region = in(0);1279if( !region ) return 0;1280if( region->req() != 3 ) return 0;1281if( req() != 3 ) return 0;1282// Check that both paths come from the same If1283Node *ifp1 = region->in(1);1284Node *ifp2 = region->in(2);1285if( !ifp1 || !ifp2 ) return 0;1286Node *iff = ifp1->in(0);1287if( !iff || !iff->is_If() ) return 0;1288if( iff != ifp2->in(0) ) return 0;1289if (check_control_only) return -1;1290// Check for a proper bool/cmp1291const Node *b = iff->in(1);1292if( !b->is_Bool() ) return 0;1293const Node *cmp = b->in(1);1294if( !cmp->is_Cmp() ) return 0;12951296// Check for branching opposite expected1297if( ifp2->Opcode() == Op_IfTrue ) {1298assert( ifp1->Opcode() == Op_IfFalse, "" );1299return 2;1300} else {1301assert( ifp1->Opcode() == Op_IfTrue, "" );1302return 1;1303}1304}13051306//----------------------------check_cmove_id-----------------------------------1307// Check for CMove'ing a constant after comparing against the constant.1308// Happens all the time now, since if we compare equality vs a constant in1309// the parser, we "know" the variable is constant on one path and we force1310// it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a1311// conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more1312// general in that we don't need constants. Since CMove's are only inserted1313// in very special circumstances, we do it here on generic Phi's.1314Node* PhiNode::is_cmove_id(PhaseTransform* phase, int true_path) {1315assert(true_path !=0, "only diamond shape graph expected");13161317// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1318// phi->region->if_proj->ifnode->bool->cmp1319Node* region = in(0);1320Node* iff = region->in(1)->in(0);1321BoolNode* b = iff->in(1)->as_Bool();1322Node* cmp = b->in(1);1323Node* tval = in(true_path);1324Node* fval = in(3-true_path);1325Node* id = CMoveNode::is_cmove_id(phase, cmp, tval, fval, b);1326if (id == NULL)1327return NULL;13281329// Either value might be a cast that depends on a branch of 'iff'.1330// Since the 'id' value will float free of the diamond, either1331// decast or return failure.1332Node* ctl = id->in(0);1333if (ctl != NULL && ctl->in(0) == iff) {1334if (id->is_ConstraintCast()) {1335return id->in(1);1336} else {1337// Don't know how to disentangle this value.1338return NULL;1339}1340}13411342return id;1343}13441345//------------------------------Identity---------------------------------------1346// Check for Region being Identity.1347Node* PhiNode::Identity(PhaseGVN* phase) {1348// Check for no merging going on1349// (There used to be special-case code here when this->region->is_Loop.1350// It would check for a tributary phi on the backedge that the main phi1351// trivially, perhaps with a single cast. The unique_input method1352// does all this and more, by reducing such tributaries to 'this'.)1353Node* uin = unique_input(phase, false);1354if (uin != NULL) {1355return uin;1356}13571358int true_path = is_diamond_phi();1359if (true_path != 0) {1360Node* id = is_cmove_id(phase, true_path);1361if (id != NULL) return id;1362}13631364// Looking for phis with identical inputs. If we find one that has1365// type TypePtr::BOTTOM, replace the current phi with the bottom phi.1366if (phase->is_IterGVN() && type() == Type::MEMORY && adr_type() !=1367TypePtr::BOTTOM && !adr_type()->is_known_instance()) {1368uint phi_len = req();1369Node* phi_reg = region();1370for (DUIterator_Fast imax, i = phi_reg->fast_outs(imax); i < imax; i++) {1371Node* u = phi_reg->fast_out(i);1372if (u->is_Phi() && u->as_Phi()->type() == Type::MEMORY &&1373u->adr_type() == TypePtr::BOTTOM && u->in(0) == phi_reg &&1374u->req() == phi_len) {1375for (uint j = 1; j < phi_len; j++) {1376if (in(j) != u->in(j)) {1377u = NULL;1378break;1379}1380}1381if (u != NULL) {1382return u;1383}1384}1385}1386}13871388return this; // No identity1389}13901391//-----------------------------unique_input------------------------------------1392// Find the unique value, discounting top, self-loops, and casts.1393// Return top if there are no inputs, and self if there are multiple.1394Node* PhiNode::unique_input(PhaseTransform* phase, bool uncast) {1395// 1) One unique direct input,1396// or if uncast is true:1397// 2) some of the inputs have an intervening ConstraintCast1398// 3) an input is a self loop1399//1400// 1) input or 2) input or 3) input __1401// / \ / \ \ / \1402// \ / | cast phi cast1403// phi \ / / \ /1404// phi / --14051406Node* r = in(0); // RegionNode1407Node* input = NULL; // The unique direct input (maybe uncasted = ConstraintCasts removed)14081409for (uint i = 1, cnt = req(); i < cnt; ++i) {1410Node* rc = r->in(i);1411if (rc == NULL || phase->type(rc) == Type::TOP)1412continue; // ignore unreachable control path1413Node* n = in(i);1414if (n == NULL)1415continue;1416Node* un = n;1417if (uncast) {1418#ifdef ASSERT1419Node* m = un->uncast();1420#endif1421while (un != NULL && un->req() == 2 && un->is_ConstraintCast()) {1422Node* next = un->in(1);1423if (phase->type(next)->isa_rawptr() && phase->type(un)->isa_oopptr()) {1424// risk exposing raw ptr at safepoint1425break;1426}1427un = next;1428}1429assert(m == un || un->in(1) == m, "Only expected at CheckCastPP from allocation");1430}1431if (un == NULL || un == this || phase->type(un) == Type::TOP) {1432continue; // ignore if top, or in(i) and "this" are in a data cycle1433}1434// Check for a unique input (maybe uncasted)1435if (input == NULL) {1436input = un;1437} else if (input != un) {1438input = NodeSentinel; // no unique input1439}1440}1441if (input == NULL) {1442return phase->C->top(); // no inputs1443}14441445if (input != NodeSentinel) {1446return input; // one unique direct input1447}14481449// Nothing.1450return NULL;1451}14521453//------------------------------is_x2logic-------------------------------------1454// Check for simple convert-to-boolean pattern1455// If:(C Bool) Region:(IfF IfT) Phi:(Region 0 1)1456// Convert Phi to an ConvIB.1457static Node *is_x2logic( PhaseGVN *phase, PhiNode *phi, int true_path ) {1458assert(true_path !=0, "only diamond shape graph expected");1459// Convert the true/false index into an expected 0/1 return.1460// Map 2->0 and 1->1.1461int flipped = 2-true_path;14621463// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1464// phi->region->if_proj->ifnode->bool->cmp1465Node *region = phi->in(0);1466Node *iff = region->in(1)->in(0);1467BoolNode *b = (BoolNode*)iff->in(1);1468const CmpNode *cmp = (CmpNode*)b->in(1);14691470Node *zero = phi->in(1);1471Node *one = phi->in(2);1472const Type *tzero = phase->type( zero );1473const Type *tone = phase->type( one );14741475// Check for compare vs 01476const Type *tcmp = phase->type(cmp->in(2));1477if( tcmp != TypeInt::ZERO && tcmp != TypePtr::NULL_PTR ) {1478// Allow cmp-vs-1 if the other input is bounded by 0-11479if( !(tcmp == TypeInt::ONE && phase->type(cmp->in(1)) == TypeInt::BOOL) )1480return NULL;1481flipped = 1-flipped; // Test is vs 1 instead of 0!1482}14831484// Check for setting zero/one opposite expected1485if( tzero == TypeInt::ZERO ) {1486if( tone == TypeInt::ONE ) {1487} else return NULL;1488} else if( tzero == TypeInt::ONE ) {1489if( tone == TypeInt::ZERO ) {1490flipped = 1-flipped;1491} else return NULL;1492} else return NULL;14931494// Check for boolean test backwards1495if( b->_test._test == BoolTest::ne ) {1496} else if( b->_test._test == BoolTest::eq ) {1497flipped = 1-flipped;1498} else return NULL;14991500// Build int->bool conversion1501Node *n = new Conv2BNode(cmp->in(1));1502if( flipped )1503n = new XorINode( phase->transform(n), phase->intcon(1) );15041505return n;1506}15071508//------------------------------is_cond_add------------------------------------1509// Check for simple conditional add pattern: "(P < Q) ? X+Y : X;"1510// To be profitable the control flow has to disappear; there can be no other1511// values merging here. We replace the test-and-branch with:1512// "(sgn(P-Q))&Y) + X". Basically, convert "(P < Q)" into 0 or -1 by1513// moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.1514// Then convert Y to 0-or-Y and finally add.1515// This is a key transform for SpecJava _201_compress.1516static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {1517assert(true_path !=0, "only diamond shape graph expected");15181519// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1520// phi->region->if_proj->ifnode->bool->cmp1521RegionNode *region = (RegionNode*)phi->in(0);1522Node *iff = region->in(1)->in(0);1523BoolNode* b = iff->in(1)->as_Bool();1524const CmpNode *cmp = (CmpNode*)b->in(1);15251526// Make sure only merging this one phi here1527if (region->has_unique_phi() != phi) return NULL;15281529// Make sure each arm of the diamond has exactly one output, which we assume1530// is the region. Otherwise, the control flow won't disappear.1531if (region->in(1)->outcnt() != 1) return NULL;1532if (region->in(2)->outcnt() != 1) return NULL;15331534// Check for "(P < Q)" of type signed int1535if (b->_test._test != BoolTest::lt) return NULL;1536if (cmp->Opcode() != Op_CmpI) return NULL;15371538Node *p = cmp->in(1);1539Node *q = cmp->in(2);1540Node *n1 = phi->in( true_path);1541Node *n2 = phi->in(3-true_path);15421543int op = n1->Opcode();1544if( op != Op_AddI // Need zero as additive identity1545/*&&op != Op_SubI &&1546op != Op_AddP &&1547op != Op_XorI &&1548op != Op_OrI*/ )1549return NULL;15501551Node *x = n2;1552Node *y = NULL;1553if( x == n1->in(1) ) {1554y = n1->in(2);1555} else if( x == n1->in(2) ) {1556y = n1->in(1);1557} else return NULL;15581559// Not so profitable if compare and add are constants1560if( q->is_Con() && phase->type(q) != TypeInt::ZERO && y->is_Con() )1561return NULL;15621563Node *cmplt = phase->transform( new CmpLTMaskNode(p,q) );1564Node *j_and = phase->transform( new AndINode(cmplt,y) );1565return new AddINode(j_and,x);1566}15671568//------------------------------is_absolute------------------------------------1569// Check for absolute value.1570static Node* is_absolute( PhaseGVN *phase, PhiNode *phi_root, int true_path) {1571assert(true_path !=0, "only diamond shape graph expected");15721573int cmp_zero_idx = 0; // Index of compare input where to look for zero1574int phi_x_idx = 0; // Index of phi input where to find naked x15751576// ABS ends with the merge of 2 control flow paths.1577// Find the false path from the true path. With only 2 inputs, 3 - x works nicely.1578int false_path = 3 - true_path;15791580// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1581// phi->region->if_proj->ifnode->bool->cmp1582BoolNode *bol = phi_root->in(0)->in(1)->in(0)->in(1)->as_Bool();1583Node *cmp = bol->in(1);15841585// Check bool sense1586if (cmp->Opcode() == Op_CmpF || cmp->Opcode() == Op_CmpD) {1587switch (bol->_test._test) {1588case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = true_path; break;1589case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = false_path; break;1590case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = true_path; break;1591case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = false_path; break;1592default: return NULL; break;1593}1594} else if (cmp->Opcode() == Op_CmpI || cmp->Opcode() == Op_CmpL) {1595switch (bol->_test._test) {1596case BoolTest::lt:1597case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = false_path; break;1598case BoolTest::gt:1599case BoolTest::ge: cmp_zero_idx = 2; phi_x_idx = true_path; break;1600default: return NULL; break;1601}1602}16031604// Test is next1605const Type *tzero = NULL;1606switch (cmp->Opcode()) {1607case Op_CmpI: tzero = TypeInt::ZERO; break; // Integer ABS1608case Op_CmpL: tzero = TypeLong::ZERO; break; // Long ABS1609case Op_CmpF: tzero = TypeF::ZERO; break; // Float ABS1610case Op_CmpD: tzero = TypeD::ZERO; break; // Double ABS1611default: return NULL;1612}16131614// Find zero input of compare; the other input is being abs'd1615Node *x = NULL;1616bool flip = false;1617if( phase->type(cmp->in(cmp_zero_idx)) == tzero ) {1618x = cmp->in(3 - cmp_zero_idx);1619} else if( phase->type(cmp->in(3 - cmp_zero_idx)) == tzero ) {1620// The test is inverted, we should invert the result...1621x = cmp->in(cmp_zero_idx);1622flip = true;1623} else {1624return NULL;1625}16261627// Next get the 2 pieces being selected, one is the original value1628// and the other is the negated value.1629if( phi_root->in(phi_x_idx) != x ) return NULL;16301631// Check other phi input for subtract node1632Node *sub = phi_root->in(3 - phi_x_idx);16331634bool is_sub = sub->Opcode() == Op_SubF || sub->Opcode() == Op_SubD ||1635sub->Opcode() == Op_SubI || sub->Opcode() == Op_SubL;16361637// Allow only Sub(0,X) and fail out for all others; Neg is not OK1638if (!is_sub || phase->type(sub->in(1)) != tzero || sub->in(2) != x) return NULL;16391640if (tzero == TypeF::ZERO) {1641x = new AbsFNode(x);1642if (flip) {1643x = new SubFNode(sub->in(1), phase->transform(x));1644}1645} else if (tzero == TypeD::ZERO) {1646x = new AbsDNode(x);1647if (flip) {1648x = new SubDNode(sub->in(1), phase->transform(x));1649}1650} else if (tzero == TypeInt::ZERO && Matcher::match_rule_supported(Op_AbsI)) {1651x = new AbsINode(x);1652if (flip) {1653x = new SubINode(sub->in(1), phase->transform(x));1654}1655} else if (tzero == TypeLong::ZERO && Matcher::match_rule_supported(Op_AbsL)) {1656x = new AbsLNode(x);1657if (flip) {1658x = new SubLNode(sub->in(1), phase->transform(x));1659}1660} else return NULL;16611662return x;1663}16641665//------------------------------split_once-------------------------------------1666// Helper for split_flow_path1667static void split_once(PhaseIterGVN *igvn, Node *phi, Node *val, Node *n, Node *newn) {1668igvn->hash_delete(n); // Remove from hash before hacking edges16691670uint j = 1;1671for (uint i = phi->req()-1; i > 0; i--) {1672if (phi->in(i) == val) { // Found a path with val?1673// Add to NEW Region/Phi, no DU info1674newn->set_req( j++, n->in(i) );1675// Remove from OLD Region/Phi1676n->del_req(i);1677}1678}16791680// Register the new node but do not transform it. Cannot transform until the1681// entire Region/Phi conglomerate has been hacked as a single huge transform.1682igvn->register_new_node_with_optimizer( newn );16831684// Now I can point to the new node.1685n->add_req(newn);1686igvn->_worklist.push(n);1687}16881689//------------------------------split_flow_path--------------------------------1690// Check for merging identical values and split flow paths1691static Node* split_flow_path(PhaseGVN *phase, PhiNode *phi) {1692BasicType bt = phi->type()->basic_type();1693if( bt == T_ILLEGAL || type2size[bt] <= 0 )1694return NULL; // Bail out on funny non-value stuff1695if( phi->req() <= 3 ) // Need at least 2 matched inputs and a1696return NULL; // third unequal input to be worth doing16971698// Scan for a constant1699uint i;1700for( i = 1; i < phi->req()-1; i++ ) {1701Node *n = phi->in(i);1702if( !n ) return NULL;1703if( phase->type(n) == Type::TOP ) return NULL;1704if( n->Opcode() == Op_ConP || n->Opcode() == Op_ConN || n->Opcode() == Op_ConNKlass )1705break;1706}1707if( i >= phi->req() ) // Only split for constants1708return NULL;17091710Node *val = phi->in(i); // Constant to split for1711uint hit = 0; // Number of times it occurs1712Node *r = phi->region();17131714for( ; i < phi->req(); i++ ){ // Count occurrences of constant1715Node *n = phi->in(i);1716if( !n ) return NULL;1717if( phase->type(n) == Type::TOP ) return NULL;1718if( phi->in(i) == val ) {1719hit++;1720if (PhaseIdealLoop::find_predicate(r->in(i)) != NULL) {1721return NULL; // don't split loop entry path1722}1723}1724}17251726if( hit <= 1 || // Make sure we find 2 or more1727hit == phi->req()-1 ) // and not ALL the same value1728return NULL;17291730// Now start splitting out the flow paths that merge the same value.1731// Split first the RegionNode.1732PhaseIterGVN *igvn = phase->is_IterGVN();1733RegionNode *newr = new RegionNode(hit+1);1734split_once(igvn, phi, val, r, newr);17351736// Now split all other Phis than this one1737for (DUIterator_Fast kmax, k = r->fast_outs(kmax); k < kmax; k++) {1738Node* phi2 = r->fast_out(k);1739if( phi2->is_Phi() && phi2->as_Phi() != phi ) {1740PhiNode *newphi = PhiNode::make_blank(newr, phi2);1741split_once(igvn, phi, val, phi2, newphi);1742}1743}17441745// Clean up this guy1746igvn->hash_delete(phi);1747for( i = phi->req()-1; i > 0; i-- ) {1748if( phi->in(i) == val ) {1749phi->del_req(i);1750}1751}1752phi->add_req(val);17531754return phi;1755}17561757//=============================================================================1758//------------------------------simple_data_loop_check-------------------------1759// Try to determining if the phi node in a simple safe/unsafe data loop.1760// Returns:1761// enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };1762// Safe - safe case when the phi and it's inputs reference only safe data1763// nodes;1764// Unsafe - the phi and it's inputs reference unsafe data nodes but there1765// is no reference back to the phi - need a graph walk1766// to determine if it is in a loop;1767// UnsafeLoop - unsafe case when the phi references itself directly or through1768// unsafe data node.1769// Note: a safe data node is a node which could/never reference itself during1770// GVN transformations. For now it is Con, Proj, Phi, CastPP, CheckCastPP.1771// I mark Phi nodes as safe node not only because they can reference itself1772// but also to prevent mistaking the fallthrough case inside an outer loop1773// as dead loop when the phi references itselfs through an other phi.1774PhiNode::LoopSafety PhiNode::simple_data_loop_check(Node *in) const {1775// It is unsafe loop if the phi node references itself directly.1776if (in == (Node*)this)1777return UnsafeLoop; // Unsafe loop1778// Unsafe loop if the phi node references itself through an unsafe data node.1779// Exclude cases with null inputs or data nodes which could reference1780// itself (safe for dead loops).1781if (in != NULL && !in->is_dead_loop_safe()) {1782// Check inputs of phi's inputs also.1783// It is much less expensive then full graph walk.1784uint cnt = in->req();1785uint i = (in->is_Proj() && !in->is_CFG()) ? 0 : 1;1786for (; i < cnt; ++i) {1787Node* m = in->in(i);1788if (m == (Node*)this)1789return UnsafeLoop; // Unsafe loop1790if (m != NULL && !m->is_dead_loop_safe()) {1791// Check the most common case (about 30% of all cases):1792// phi->Load/Store->AddP->(ConP ConP Con)/(Parm Parm Con).1793Node *m1 = (m->is_AddP() && m->req() > 3) ? m->in(1) : NULL;1794if (m1 == (Node*)this)1795return UnsafeLoop; // Unsafe loop1796if (m1 != NULL && m1 == m->in(2) &&1797m1->is_dead_loop_safe() && m->in(3)->is_Con()) {1798continue; // Safe case1799}1800// The phi references an unsafe node - need full analysis.1801return Unsafe;1802}1803}1804}1805return Safe; // Safe case - we can optimize the phi node.1806}18071808//------------------------------is_unsafe_data_reference-----------------------1809// If phi can be reached through the data input - it is data loop.1810bool PhiNode::is_unsafe_data_reference(Node *in) const {1811assert(req() > 1, "");1812// First, check simple cases when phi references itself directly or1813// through an other node.1814LoopSafety safety = simple_data_loop_check(in);1815if (safety == UnsafeLoop)1816return true; // phi references itself - unsafe loop1817else if (safety == Safe)1818return false; // Safe case - phi could be replaced with the unique input.18191820// Unsafe case when we should go through data graph to determine1821// if the phi references itself.18221823ResourceMark rm;18241825Node_List nstack;1826VectorSet visited;18271828nstack.push(in); // Start with unique input.1829visited.set(in->_idx);1830while (nstack.size() != 0) {1831Node* n = nstack.pop();1832uint cnt = n->req();1833uint i = (n->is_Proj() && !n->is_CFG()) ? 0 : 1;1834for (; i < cnt; i++) {1835Node* m = n->in(i);1836if (m == (Node*)this) {1837return true; // Data loop1838}1839if (m != NULL && !m->is_dead_loop_safe()) { // Only look for unsafe cases.1840if (!visited.test_set(m->_idx))1841nstack.push(m);1842}1843}1844}1845return false; // The phi is not reachable from its inputs1846}18471848// Is this Phi's region or some inputs to the region enqueued for IGVN1849// and so could cause the region to be optimized out?1850bool PhiNode::wait_for_region_igvn(PhaseGVN* phase) {1851PhaseIterGVN* igvn = phase->is_IterGVN();1852Unique_Node_List& worklist = igvn->_worklist;1853bool delay = false;1854Node* r = in(0);1855for (uint j = 1; j < req(); j++) {1856Node* rc = r->in(j);1857Node* n = in(j);1858if (rc != NULL &&1859rc->is_Proj()) {1860if (worklist.member(rc)) {1861delay = true;1862} else if (rc->in(0) != NULL &&1863rc->in(0)->is_If()) {1864if (worklist.member(rc->in(0))) {1865delay = true;1866} else if (rc->in(0)->in(1) != NULL &&1867rc->in(0)->in(1)->is_Bool()) {1868if (worklist.member(rc->in(0)->in(1))) {1869delay = true;1870} else if (rc->in(0)->in(1)->in(1) != NULL &&1871rc->in(0)->in(1)->in(1)->is_Cmp()) {1872if (worklist.member(rc->in(0)->in(1)->in(1))) {1873delay = true;1874}1875}1876}1877}1878}1879}1880if (delay) {1881worklist.push(this);1882}1883return delay;1884}18851886//------------------------------Ideal------------------------------------------1887// Return a node which is more "ideal" than the current node. Must preserve1888// the CFG, but we can still strip out dead paths.1889Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {1890Node *r = in(0); // RegionNode1891assert(r != NULL && r->is_Region(), "this phi must have a region");1892assert(r->in(0) == NULL || !r->in(0)->is_Root(), "not a specially hidden merge");18931894// Note: During parsing, phis are often transformed before their regions.1895// This means we have to use type_or_null to defend against untyped regions.1896if( phase->type_or_null(r) == Type::TOP ) // Dead code?1897return NULL; // No change18981899Node *top = phase->C->top();1900bool new_phi = (outcnt() == 0); // transforming new Phi1901// No change for igvn if new phi is not hooked1902if (new_phi && can_reshape)1903return NULL;19041905// The are 2 situations when only one valid phi's input is left1906// (in addition to Region input).1907// One: region is not loop - replace phi with this input.1908// Two: region is loop - replace phi with top since this data path is dead1909// and we need to break the dead data loop.1910Node* progress = NULL; // Record if any progress made1911for( uint j = 1; j < req(); ++j ){ // For all paths in1912// Check unreachable control paths1913Node* rc = r->in(j);1914Node* n = in(j); // Get the input1915if (rc == NULL || phase->type(rc) == Type::TOP) {1916if (n != top) { // Not already top?1917PhaseIterGVN *igvn = phase->is_IterGVN();1918if (can_reshape && igvn != NULL) {1919igvn->_worklist.push(r);1920}1921// Nuke it down1922set_req_X(j, top, phase);1923progress = this; // Record progress1924}1925}1926}19271928if (can_reshape && outcnt() == 0) {1929// set_req() above may kill outputs if Phi is referenced1930// only by itself on the dead (top) control path.1931return top;1932}19331934bool uncasted = false;1935Node* uin = unique_input(phase, false);1936if (uin == NULL && can_reshape &&1937// If there is a chance that the region can be optimized out do1938// not add a cast node that we can't remove yet.1939!wait_for_region_igvn(phase)) {1940uncasted = true;1941uin = unique_input(phase, true);1942}1943if (uin == top) { // Simplest case: no alive inputs.1944if (can_reshape) // IGVN transformation1945return top;1946else1947return NULL; // Identity will return TOP1948} else if (uin != NULL) {1949// Only one not-NULL unique input path is left.1950// Determine if this input is backedge of a loop.1951// (Skip new phis which have no uses and dead regions).1952if (outcnt() > 0 && r->in(0) != NULL) {1953if (is_data_loop(r->as_Region(), uin, phase)) {1954// Break this data loop to avoid creation of a dead loop.1955if (can_reshape) {1956return top;1957} else {1958// We can't return top if we are in Parse phase - cut inputs only1959// let Identity to handle the case.1960replace_edge(uin, top, phase);1961return NULL;1962}1963}1964}19651966if (uncasted) {1967// Add cast nodes between the phi to be removed and its unique input.1968// Wait until after parsing for the type information to propagate from the casts.1969assert(can_reshape, "Invalid during parsing");1970const Type* phi_type = bottom_type();1971assert(phi_type->isa_int() || phi_type->isa_ptr() || phi_type->isa_long(), "bad phi type");1972// Add casts to carry the control dependency of the Phi that is1973// going away1974Node* cast = NULL;1975if (phi_type->isa_int()) {1976cast = ConstraintCastNode::make_cast(Op_CastII, r, uin, phi_type, true);1977} else if (phi_type->isa_long()) {1978cast = ConstraintCastNode::make_cast(Op_CastLL, r, uin, phi_type, true);1979} else {1980const Type* uin_type = phase->type(uin);1981if (!phi_type->isa_oopptr() && !uin_type->isa_oopptr()) {1982cast = ConstraintCastNode::make_cast(Op_CastPP, r, uin, phi_type, true);1983} else {1984// Use a CastPP for a cast to not null and a CheckCastPP for1985// a cast to a new klass (and both if both null-ness and1986// klass change).19871988// If the type of phi is not null but the type of uin may be1989// null, uin's type must be casted to not null1990if (phi_type->join(TypePtr::NOTNULL) == phi_type->remove_speculative() &&1991uin_type->join(TypePtr::NOTNULL) != uin_type->remove_speculative()) {1992cast = ConstraintCastNode::make_cast(Op_CastPP, r, uin, TypePtr::NOTNULL, true);1993}19941995// If the type of phi and uin, both casted to not null,1996// differ the klass of uin must be (check)cast'ed to match1997// that of phi1998if (phi_type->join_speculative(TypePtr::NOTNULL) != uin_type->join_speculative(TypePtr::NOTNULL)) {1999Node* n = uin;2000if (cast != NULL) {2001cast = phase->transform(cast);2002n = cast;2003}2004cast = ConstraintCastNode::make_cast(Op_CheckCastPP, r, n, phi_type, true);2005}2006if (cast == NULL) {2007cast = ConstraintCastNode::make_cast(Op_CastPP, r, uin, phi_type, true);2008}2009}2010}2011assert(cast != NULL, "cast should be set");2012cast = phase->transform(cast);2013// set all inputs to the new cast(s) so the Phi is removed by Identity2014PhaseIterGVN* igvn = phase->is_IterGVN();2015for (uint i = 1; i < req(); i++) {2016set_req_X(i, cast, igvn);2017}2018uin = cast;2019}20202021// One unique input.2022debug_only(Node* ident = Identity(phase));2023// The unique input must eventually be detected by the Identity call.2024#ifdef ASSERT2025if (ident != uin && !ident->is_top()) {2026// print this output before failing assert2027r->dump(3);2028this->dump(3);2029ident->dump();2030uin->dump();2031}2032#endif2033assert(ident == uin || ident->is_top(), "Identity must clean this up");2034return NULL;2035}20362037Node* opt = NULL;2038int true_path = is_diamond_phi();2039if( true_path != 0 ) {2040// Check for CMove'ing identity. If it would be unsafe,2041// handle it here. In the safe case, let Identity handle it.2042Node* unsafe_id = is_cmove_id(phase, true_path);2043if( unsafe_id != NULL && is_unsafe_data_reference(unsafe_id) )2044opt = unsafe_id;20452046// Check for simple convert-to-boolean pattern2047if( opt == NULL )2048opt = is_x2logic(phase, this, true_path);20492050// Check for absolute value2051if( opt == NULL )2052opt = is_absolute(phase, this, true_path);20532054// Check for conditional add2055if( opt == NULL && can_reshape )2056opt = is_cond_add(phase, this, true_path);20572058// These 4 optimizations could subsume the phi:2059// have to check for a dead data loop creation.2060if( opt != NULL ) {2061if( opt == unsafe_id || is_unsafe_data_reference(opt) ) {2062// Found dead loop.2063if( can_reshape )2064return top;2065// We can't return top if we are in Parse phase - cut inputs only2066// to stop further optimizations for this phi. Identity will return TOP.2067assert(req() == 3, "only diamond merge phi here");2068set_req(1, top);2069set_req(2, top);2070return NULL;2071} else {2072return opt;2073}2074}2075}20762077// Check for merging identical values and split flow paths2078if (can_reshape) {2079opt = split_flow_path(phase, this);2080// This optimization only modifies phi - don't need to check for dead loop.2081assert(opt == NULL || opt == this, "do not elide phi");2082if (opt != NULL) return opt;2083}20842085if (in(1) != NULL && in(1)->Opcode() == Op_AddP && can_reshape) {2086// Try to undo Phi of AddP:2087// (Phi (AddP base address offset) (AddP base2 address2 offset2))2088// becomes:2089// newbase := (Phi base base2)2090// newaddress := (Phi address address2)2091// newoffset := (Phi offset offset2)2092// (AddP newbase newaddress newoffset)2093//2094// This occurs as a result of unsuccessful split_thru_phi and2095// interferes with taking advantage of addressing modes. See the2096// clone_shift_expressions code in matcher.cpp2097Node* addp = in(1);2098Node* base = addp->in(AddPNode::Base);2099Node* address = addp->in(AddPNode::Address);2100Node* offset = addp->in(AddPNode::Offset);2101if (base != NULL && address != NULL && offset != NULL &&2102!base->is_top() && !address->is_top() && !offset->is_top()) {2103const Type* base_type = base->bottom_type();2104const Type* address_type = address->bottom_type();2105// make sure that all the inputs are similar to the first one,2106// i.e. AddP with base == address and same offset as first AddP2107bool doit = true;2108for (uint i = 2; i < req(); i++) {2109if (in(i) == NULL ||2110in(i)->Opcode() != Op_AddP ||2111in(i)->in(AddPNode::Base) == NULL ||2112in(i)->in(AddPNode::Address) == NULL ||2113in(i)->in(AddPNode::Offset) == NULL ||2114in(i)->in(AddPNode::Base)->is_top() ||2115in(i)->in(AddPNode::Address)->is_top() ||2116in(i)->in(AddPNode::Offset)->is_top()) {2117doit = false;2118break;2119}2120if (in(i)->in(AddPNode::Offset) != base) {2121base = NULL;2122}2123if (in(i)->in(AddPNode::Offset) != offset) {2124offset = NULL;2125}2126if (in(i)->in(AddPNode::Address) != address) {2127address = NULL;2128}2129// Accumulate type for resulting Phi2130base_type = base_type->meet_speculative(in(i)->in(AddPNode::Base)->bottom_type());2131address_type = address_type->meet_speculative(in(i)->in(AddPNode::Address)->bottom_type());2132}2133if (doit && base == NULL) {2134// Check for neighboring AddP nodes in a tree.2135// If they have a base, use that it.2136for (DUIterator_Fast kmax, k = this->fast_outs(kmax); k < kmax; k++) {2137Node* u = this->fast_out(k);2138if (u->is_AddP()) {2139Node* base2 = u->in(AddPNode::Base);2140if (base2 != NULL && !base2->is_top()) {2141if (base == NULL)2142base = base2;2143else if (base != base2)2144{ doit = false; break; }2145}2146}2147}2148}2149if (doit) {2150if (base == NULL) {2151base = new PhiNode(in(0), base_type, NULL);2152for (uint i = 1; i < req(); i++) {2153base->init_req(i, in(i)->in(AddPNode::Base));2154}2155phase->is_IterGVN()->register_new_node_with_optimizer(base);2156}2157if (address == NULL) {2158address = new PhiNode(in(0), address_type, NULL);2159for (uint i = 1; i < req(); i++) {2160address->init_req(i, in(i)->in(AddPNode::Address));2161}2162phase->is_IterGVN()->register_new_node_with_optimizer(address);2163}2164if (offset == NULL) {2165offset = new PhiNode(in(0), TypeX_X, NULL);2166for (uint i = 1; i < req(); i++) {2167offset->init_req(i, in(i)->in(AddPNode::Offset));2168}2169phase->is_IterGVN()->register_new_node_with_optimizer(offset);2170}2171return new AddPNode(base, address, offset);2172}2173}2174}21752176// Split phis through memory merges, so that the memory merges will go away.2177// Piggy-back this transformation on the search for a unique input....2178// It will be as if the merged memory is the unique value of the phi.2179// (Do not attempt this optimization unless parsing is complete.2180// It would make the parser's memory-merge logic sick.)2181// (MergeMemNode is not dead_loop_safe - need to check for dead loop.)2182if (progress == NULL && can_reshape && type() == Type::MEMORY) {2183// see if this phi should be sliced2184uint merge_width = 0;2185bool saw_self = false;2186for( uint i=1; i<req(); ++i ) {// For all paths in2187Node *ii = in(i);2188// TOP inputs should not be counted as safe inputs because if the2189// Phi references itself through all other inputs then splitting the2190// Phi through memory merges would create dead loop at later stage.2191if (ii == top) {2192return NULL; // Delay optimization until graph is cleaned.2193}2194if (ii->is_MergeMem()) {2195MergeMemNode* n = ii->as_MergeMem();2196merge_width = MAX2(merge_width, n->req());2197saw_self = saw_self || (n->base_memory() == this);2198}2199}22002201// This restriction is temporarily necessary to ensure termination:2202if (!saw_self && adr_type() == TypePtr::BOTTOM) merge_width = 0;22032204if (merge_width > Compile::AliasIdxRaw) {2205// found at least one non-empty MergeMem2206const TypePtr* at = adr_type();2207if (at != TypePtr::BOTTOM) {2208// Patch the existing phi to select an input from the merge:2209// Phi:AT1(...MergeMem(m0, m1, m2)...) into2210// Phi:AT1(...m1...)2211int alias_idx = phase->C->get_alias_index(at);2212for (uint i=1; i<req(); ++i) {2213Node *ii = in(i);2214if (ii->is_MergeMem()) {2215MergeMemNode* n = ii->as_MergeMem();2216// compress paths and change unreachable cycles to TOP2217// If not, we can update the input infinitely along a MergeMem cycle2218// Equivalent code is in MemNode::Ideal_common2219Node *m = phase->transform(n);2220if (outcnt() == 0) { // Above transform() may kill us!2221return top;2222}2223// If transformed to a MergeMem, get the desired slice2224// Otherwise the returned node represents memory for every slice2225Node *new_mem = (m->is_MergeMem()) ?2226m->as_MergeMem()->memory_at(alias_idx) : m;2227// Update input if it is progress over what we have now2228if (new_mem != ii) {2229set_req_X(i, new_mem, phase->is_IterGVN());2230progress = this;2231}2232}2233}2234} else {2235// We know that at least one MergeMem->base_memory() == this2236// (saw_self == true). If all other inputs also references this phi2237// (directly or through data nodes) - it is a dead loop.2238bool saw_safe_input = false;2239for (uint j = 1; j < req(); ++j) {2240Node* n = in(j);2241if (n->is_MergeMem()) {2242MergeMemNode* mm = n->as_MergeMem();2243if (mm->base_memory() == this || mm->base_memory() == mm->empty_memory()) {2244// Skip this input if it references back to this phi or if the memory path is dead2245continue;2246}2247}2248if (!is_unsafe_data_reference(n)) {2249saw_safe_input = true; // found safe input2250break;2251}2252}2253if (!saw_safe_input) {2254// There is a dead loop: All inputs are either dead or reference back to this phi2255return top;2256}22572258// Phi(...MergeMem(m0, m1:AT1, m2:AT2)...) into2259// MergeMem(Phi(...m0...), Phi:AT1(...m1...), Phi:AT2(...m2...))2260PhaseIterGVN* igvn = phase->is_IterGVN();2261Node* hook = new Node(1);2262PhiNode* new_base = (PhiNode*) clone();2263// Must eagerly register phis, since they participate in loops.2264if (igvn) {2265igvn->register_new_node_with_optimizer(new_base);2266hook->add_req(new_base);2267}2268MergeMemNode* result = MergeMemNode::make(new_base);2269for (uint i = 1; i < req(); ++i) {2270Node *ii = in(i);2271if (ii->is_MergeMem()) {2272MergeMemNode* n = ii->as_MergeMem();2273for (MergeMemStream mms(result, n); mms.next_non_empty2(); ) {2274// If we have not seen this slice yet, make a phi for it.2275bool made_new_phi = false;2276if (mms.is_empty()) {2277Node* new_phi = new_base->slice_memory(mms.adr_type(phase->C));2278made_new_phi = true;2279if (igvn) {2280igvn->register_new_node_with_optimizer(new_phi);2281hook->add_req(new_phi);2282}2283mms.set_memory(new_phi);2284}2285Node* phi = mms.memory();2286assert(made_new_phi || phi->in(i) == n, "replace the i-th merge by a slice");2287phi->set_req(i, mms.memory2());2288}2289}2290}2291// Distribute all self-loops.2292{ // (Extra braces to hide mms.)2293for (MergeMemStream mms(result); mms.next_non_empty(); ) {2294Node* phi = mms.memory();2295for (uint i = 1; i < req(); ++i) {2296if (phi->in(i) == this) phi->set_req(i, phi);2297}2298}2299}2300// now transform the new nodes, and return the mergemem2301for (MergeMemStream mms(result); mms.next_non_empty(); ) {2302Node* phi = mms.memory();2303mms.set_memory(phase->transform(phi));2304}2305hook->destruct(igvn);2306// Replace self with the result.2307return result;2308}2309}2310//2311// Other optimizations on the memory chain2312//2313const TypePtr* at = adr_type();2314for( uint i=1; i<req(); ++i ) {// For all paths in2315Node *ii = in(i);2316Node *new_in = MemNode::optimize_memory_chain(ii, at, NULL, phase);2317if (ii != new_in ) {2318set_req(i, new_in);2319progress = this;2320}2321}2322}23232324#ifdef _LP642325// Push DecodeN/DecodeNKlass down through phi.2326// The rest of phi graph will transform by split EncodeP node though phis up.2327if ((UseCompressedOops || UseCompressedClassPointers) && can_reshape && progress == NULL) {2328bool may_push = true;2329bool has_decodeN = false;2330bool is_decodeN = false;2331for (uint i=1; i<req(); ++i) {// For all paths in2332Node *ii = in(i);2333if (ii->is_DecodeNarrowPtr() && ii->bottom_type() == bottom_type()) {2334// Do optimization if a non dead path exist.2335if (ii->in(1)->bottom_type() != Type::TOP) {2336has_decodeN = true;2337is_decodeN = ii->is_DecodeN();2338}2339} else if (!ii->is_Phi()) {2340may_push = false;2341}2342}23432344if (has_decodeN && may_push) {2345PhaseIterGVN *igvn = phase->is_IterGVN();2346// Make narrow type for new phi.2347const Type* narrow_t;2348if (is_decodeN) {2349narrow_t = TypeNarrowOop::make(this->bottom_type()->is_ptr());2350} else {2351narrow_t = TypeNarrowKlass::make(this->bottom_type()->is_ptr());2352}2353PhiNode* new_phi = new PhiNode(r, narrow_t);2354uint orig_cnt = req();2355for (uint i=1; i<req(); ++i) {// For all paths in2356Node *ii = in(i);2357Node* new_ii = NULL;2358if (ii->is_DecodeNarrowPtr()) {2359assert(ii->bottom_type() == bottom_type(), "sanity");2360new_ii = ii->in(1);2361} else {2362assert(ii->is_Phi(), "sanity");2363if (ii->as_Phi() == this) {2364new_ii = new_phi;2365} else {2366if (is_decodeN) {2367new_ii = new EncodePNode(ii, narrow_t);2368} else {2369new_ii = new EncodePKlassNode(ii, narrow_t);2370}2371igvn->register_new_node_with_optimizer(new_ii);2372}2373}2374new_phi->set_req(i, new_ii);2375}2376igvn->register_new_node_with_optimizer(new_phi, this);2377if (is_decodeN) {2378progress = new DecodeNNode(new_phi, bottom_type());2379} else {2380progress = new DecodeNKlassNode(new_phi, bottom_type());2381}2382}2383}2384#endif23852386// Phi (VB ... VB) => VB (Phi ...) (Phi ...)2387if (EnableVectorReboxing && can_reshape && progress == NULL) {2388PhaseIterGVN* igvn = phase->is_IterGVN();23892390bool all_inputs_are_equiv_vboxes = true;2391for (uint i = 1; i < req(); ++i) {2392Node* n = in(i);2393if (in(i)->Opcode() != Op_VectorBox) {2394all_inputs_are_equiv_vboxes = false;2395break;2396}2397// Check that vector type of vboxes is equivalent2398if (i != 1) {2399if (Type::cmp(in(i-0)->in(VectorBoxNode::Value)->bottom_type(),2400in(i-1)->in(VectorBoxNode::Value)->bottom_type()) != 0) {2401all_inputs_are_equiv_vboxes = false;2402break;2403}2404if (Type::cmp(in(i-0)->in(VectorBoxNode::Box)->bottom_type(),2405in(i-1)->in(VectorBoxNode::Box)->bottom_type()) != 0) {2406all_inputs_are_equiv_vboxes = false;2407break;2408}2409}2410}24112412if (all_inputs_are_equiv_vboxes) {2413VectorBoxNode* vbox = static_cast<VectorBoxNode*>(in(1));2414PhiNode* new_vbox_phi = new PhiNode(r, vbox->box_type());2415PhiNode* new_vect_phi = new PhiNode(r, vbox->vec_type());2416for (uint i = 1; i < req(); ++i) {2417VectorBoxNode* old_vbox = static_cast<VectorBoxNode*>(in(i));2418new_vbox_phi->set_req(i, old_vbox->in(VectorBoxNode::Box));2419new_vect_phi->set_req(i, old_vbox->in(VectorBoxNode::Value));2420}2421igvn->register_new_node_with_optimizer(new_vbox_phi, this);2422igvn->register_new_node_with_optimizer(new_vect_phi, this);2423progress = new VectorBoxNode(igvn->C, new_vbox_phi, new_vect_phi, vbox->box_type(), vbox->vec_type());2424}2425}24262427return progress; // Return any progress2428}24292430bool PhiNode::is_data_loop(RegionNode* r, Node* uin, const PhaseGVN* phase) {2431// First, take the short cut when we know it is a loop and the EntryControl data path is dead.2432// The loop node may only have one input because the entry path was removed in PhaseIdealLoop::Dominators().2433// Then, check if there is a data loop when the phi references itself directly or through other data nodes.2434assert(!r->is_Loop() || r->req() <= 3, "Loop node should have 3 or less inputs");2435const bool is_loop = (r->is_Loop() && r->req() == 3);2436const Node* top = phase->C->top();2437if (is_loop) {2438return !uin->eqv_uncast(in(LoopNode::EntryControl));2439} else {2440// We have a data loop either with an unsafe data reference or if a region is unreachable.2441return is_unsafe_data_reference(uin)2442|| (r->req() == 3 && (r->in(1) != top && r->in(2) == top && r->is_unreachable_region(phase)));2443}2444}24452446//------------------------------is_tripcount-----------------------------------2447bool PhiNode::is_tripcount(BasicType bt) const {2448return (in(0) != NULL && in(0)->is_BaseCountedLoop() &&2449in(0)->as_BaseCountedLoop()->operates_on(bt, true) &&2450in(0)->as_BaseCountedLoop()->phi() == this);2451}24522453//------------------------------out_RegMask------------------------------------2454const RegMask &PhiNode::in_RegMask(uint i) const {2455return i ? out_RegMask() : RegMask::Empty;2456}24572458const RegMask &PhiNode::out_RegMask() const {2459uint ideal_reg = _type->ideal_reg();2460assert( ideal_reg != Node::NotAMachineReg, "invalid type at Phi" );2461if( ideal_reg == 0 ) return RegMask::Empty;2462assert(ideal_reg != Op_RegFlags, "flags register is not spillable");2463return *(Compile::current()->matcher()->idealreg2spillmask[ideal_reg]);2464}24652466#ifndef PRODUCT2467void PhiNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {2468// For a PhiNode, the set of related nodes includes all inputs till level 2,2469// and all outputs till level 1. In compact mode, inputs till level 1 are2470// collected.2471this->collect_nodes(in_rel, compact ? 1 : 2, false, false);2472this->collect_nodes(out_rel, -1, false, false);2473}24742475void PhiNode::dump_spec(outputStream *st) const {2476TypeNode::dump_spec(st);2477if (is_tripcount(T_INT) || is_tripcount(T_LONG)) {2478st->print(" #tripcount");2479}2480}2481#endif248224832484//=============================================================================2485const Type* GotoNode::Value(PhaseGVN* phase) const {2486// If the input is reachable, then we are executed.2487// If the input is not reachable, then we are not executed.2488return phase->type(in(0));2489}24902491Node* GotoNode::Identity(PhaseGVN* phase) {2492return in(0); // Simple copy of incoming control2493}24942495const RegMask &GotoNode::out_RegMask() const {2496return RegMask::Empty;2497}24982499#ifndef PRODUCT2500//-----------------------------related-----------------------------------------2501// The related nodes of a GotoNode are all inputs at level 1, as well as the2502// outputs at level 1. This is regardless of compact mode.2503void GotoNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {2504this->collect_nodes(in_rel, 1, false, false);2505this->collect_nodes(out_rel, -1, false, false);2506}2507#endif250825092510//=============================================================================2511const RegMask &JumpNode::out_RegMask() const {2512return RegMask::Empty;2513}25142515#ifndef PRODUCT2516//-----------------------------related-----------------------------------------2517// The related nodes of a JumpNode are all inputs at level 1, as well as the2518// outputs at level 2 (to include actual jump targets beyond projection nodes).2519// This is regardless of compact mode.2520void JumpNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {2521this->collect_nodes(in_rel, 1, false, false);2522this->collect_nodes(out_rel, -2, false, false);2523}2524#endif25252526//=============================================================================2527const RegMask &JProjNode::out_RegMask() const {2528return RegMask::Empty;2529}25302531//=============================================================================2532const RegMask &CProjNode::out_RegMask() const {2533return RegMask::Empty;2534}2535253625372538//=============================================================================25392540uint PCTableNode::hash() const { return Node::hash() + _size; }2541bool PCTableNode::cmp( const Node &n ) const2542{ return _size == ((PCTableNode&)n)._size; }25432544const Type *PCTableNode::bottom_type() const {2545const Type** f = TypeTuple::fields(_size);2546for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;2547return TypeTuple::make(_size, f);2548}25492550//------------------------------Value------------------------------------------2551// Compute the type of the PCTableNode. If reachable it is a tuple of2552// Control, otherwise the table targets are not reachable2553const Type* PCTableNode::Value(PhaseGVN* phase) const {2554if( phase->type(in(0)) == Type::CONTROL )2555return bottom_type();2556return Type::TOP; // All paths dead? Then so are we2557}25582559//------------------------------Ideal------------------------------------------2560// Return a node which is more "ideal" than the current node. Strip out2561// control copies2562Node *PCTableNode::Ideal(PhaseGVN *phase, bool can_reshape) {2563return remove_dead_region(phase, can_reshape) ? this : NULL;2564}25652566//=============================================================================2567uint JumpProjNode::hash() const {2568return Node::hash() + _dest_bci;2569}25702571bool JumpProjNode::cmp( const Node &n ) const {2572return ProjNode::cmp(n) &&2573_dest_bci == ((JumpProjNode&)n)._dest_bci;2574}25752576#ifndef PRODUCT2577void JumpProjNode::dump_spec(outputStream *st) const {2578ProjNode::dump_spec(st);2579st->print("@bci %d ",_dest_bci);2580}25812582void JumpProjNode::dump_compact_spec(outputStream *st) const {2583ProjNode::dump_compact_spec(st);2584st->print("(%d)%d@%d", _switch_val, _proj_no, _dest_bci);2585}25862587void JumpProjNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {2588// The related nodes of a JumpProjNode are its inputs and outputs at level 1.2589this->collect_nodes(in_rel, 1, false, false);2590this->collect_nodes(out_rel, -1, false, false);2591}2592#endif25932594//=============================================================================2595//------------------------------Value------------------------------------------2596// Check for being unreachable, or for coming from a Rethrow. Rethrow's cannot2597// have the default "fall_through_index" path.2598const Type* CatchNode::Value(PhaseGVN* phase) const {2599// Unreachable? Then so are all paths from here.2600if( phase->type(in(0)) == Type::TOP ) return Type::TOP;2601// First assume all paths are reachable2602const Type** f = TypeTuple::fields(_size);2603for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;2604// Identify cases that will always throw an exception2605// () rethrow call2606// () virtual or interface call with NULL receiver2607// () call is a check cast with incompatible arguments2608if( in(1)->is_Proj() ) {2609Node *i10 = in(1)->in(0);2610if( i10->is_Call() ) {2611CallNode *call = i10->as_Call();2612// Rethrows always throw exceptions, never return2613if (call->entry_point() == OptoRuntime::rethrow_stub()) {2614f[CatchProjNode::fall_through_index] = Type::TOP;2615} else if( call->req() > TypeFunc::Parms ) {2616const Type *arg0 = phase->type( call->in(TypeFunc::Parms) );2617// Check for null receiver to virtual or interface calls2618if( call->is_CallDynamicJava() &&2619arg0->higher_equal(TypePtr::NULL_PTR) ) {2620f[CatchProjNode::fall_through_index] = Type::TOP;2621}2622} // End of if not a runtime stub2623} // End of if have call above me2624} // End of slot 1 is not a projection2625return TypeTuple::make(_size, f);2626}26272628//=============================================================================2629uint CatchProjNode::hash() const {2630return Node::hash() + _handler_bci;2631}263226332634bool CatchProjNode::cmp( const Node &n ) const {2635return ProjNode::cmp(n) &&2636_handler_bci == ((CatchProjNode&)n)._handler_bci;2637}263826392640//------------------------------Identity---------------------------------------2641// If only 1 target is possible, choose it if it is the main control2642Node* CatchProjNode::Identity(PhaseGVN* phase) {2643// If my value is control and no other value is, then treat as ID2644const TypeTuple *t = phase->type(in(0))->is_tuple();2645if (t->field_at(_con) != Type::CONTROL) return this;2646// If we remove the last CatchProj and elide the Catch/CatchProj, then we2647// also remove any exception table entry. Thus we must know the call2648// feeding the Catch will not really throw an exception. This is ok for2649// the main fall-thru control (happens when we know a call can never throw2650// an exception) or for "rethrow", because a further optimization will2651// yank the rethrow (happens when we inline a function that can throw an2652// exception and the caller has no handler). Not legal, e.g., for passing2653// a NULL receiver to a v-call, or passing bad types to a slow-check-cast.2654// These cases MUST throw an exception via the runtime system, so the VM2655// will be looking for a table entry.2656Node *proj = in(0)->in(1); // Expect a proj feeding CatchNode2657CallNode *call;2658if (_con != TypeFunc::Control && // Bail out if not the main control.2659!(proj->is_Proj() && // AND NOT a rethrow2660proj->in(0)->is_Call() &&2661(call = proj->in(0)->as_Call()) &&2662call->entry_point() == OptoRuntime::rethrow_stub()))2663return this;26642665// Search for any other path being control2666for (uint i = 0; i < t->cnt(); i++) {2667if (i != _con && t->field_at(i) == Type::CONTROL)2668return this;2669}2670// Only my path is possible; I am identity on control to the jump2671return in(0)->in(0);2672}267326742675#ifndef PRODUCT2676void CatchProjNode::dump_spec(outputStream *st) const {2677ProjNode::dump_spec(st);2678st->print("@bci %d ",_handler_bci);2679}2680#endif26812682//=============================================================================2683//------------------------------Identity---------------------------------------2684// Check for CreateEx being Identity.2685Node* CreateExNode::Identity(PhaseGVN* phase) {2686if( phase->type(in(1)) == Type::TOP ) return in(1);2687if( phase->type(in(0)) == Type::TOP ) return in(0);2688// We only come from CatchProj, unless the CatchProj goes away.2689// If the CatchProj is optimized away, then we just carry the2690// exception oop through.2691CallNode *call = in(1)->in(0)->as_Call();26922693return ( in(0)->is_CatchProj() && in(0)->in(0)->in(1) == in(1) )2694? this2695: call->in(TypeFunc::Parms);2696}26972698//=============================================================================2699//------------------------------Value------------------------------------------2700// Check for being unreachable.2701const Type* NeverBranchNode::Value(PhaseGVN* phase) const {2702if (!in(0) || in(0)->is_top()) return Type::TOP;2703return bottom_type();2704}27052706//------------------------------Ideal------------------------------------------2707// Check for no longer being part of a loop2708Node *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) {2709if (can_reshape && !in(0)->is_Loop()) {2710// Dead code elimination can sometimes delete this projection so2711// if it's not there, there's nothing to do.2712Node* fallthru = proj_out_or_null(0);2713if (fallthru != NULL) {2714phase->is_IterGVN()->replace_node(fallthru, in(0));2715}2716return phase->C->top();2717}2718return NULL;2719}27202721#ifndef PRODUCT2722void NeverBranchNode::format( PhaseRegAlloc *ra_, outputStream *st) const {2723st->print("%s", Name());2724}2725#endif272627272728