Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/opto/cfgnode.cpp
32285 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/systemDictionary.hpp"26#include "memory/allocation.inline.hpp"27#include "oops/objArrayKlass.hpp"28#include "opto/addnode.hpp"29#include "opto/cfgnode.hpp"30#include "opto/connode.hpp"31#include "opto/loopnode.hpp"32#include "opto/machnode.hpp"33#include "opto/mulnode.hpp"34#include "opto/phaseX.hpp"35#include "opto/regmask.hpp"36#include "opto/runtime.hpp"37#include "opto/subnode.hpp"38#if INCLUDE_ALL_GCS39#include "gc_implementation/shenandoah/c2/shenandoahBarrierSetC2.hpp"40#include "gc_implementation/shenandoah/c2/shenandoahSupport.hpp"41#endif4243// Portions of code courtesy of Clifford Click4445// Optimization - Graph Style4647//=============================================================================48//------------------------------Value------------------------------------------49// Compute the type of the RegionNode.50const Type *RegionNode::Value( PhaseTransform *phase ) const {51for( uint i=1; i<req(); ++i ) { // For all paths in52Node *n = in(i); // Get Control source53if( !n ) continue; // Missing inputs are TOP54if( phase->type(n) == Type::CONTROL )55return Type::CONTROL;56}57return Type::TOP; // All paths dead? Then so are we58}5960//------------------------------Identity---------------------------------------61// Check for Region being Identity.62Node *RegionNode::Identity( PhaseTransform *phase ) {63// Cannot have Region be an identity, even if it has only 1 input.64// Phi users cannot have their Region input folded away for them,65// since they need to select the proper data input66return this;67}6869//------------------------------merge_region-----------------------------------70// If a Region flows into a Region, merge into one big happy merge. This is71// hard to do if there is stuff that has to happen72static Node *merge_region(RegionNode *region, PhaseGVN *phase) {73if( region->Opcode() != Op_Region ) // Do not do to LoopNodes74return NULL;75Node *progress = NULL; // Progress flag76PhaseIterGVN *igvn = phase->is_IterGVN();7778uint rreq = region->req();79for( uint i = 1; i < rreq; i++ ) {80Node *r = region->in(i);81if( r && r->Opcode() == Op_Region && // Found a region?82r->in(0) == r && // Not already collapsed?83r != region && // Avoid stupid situations84r->outcnt() == 2 ) { // Self user and 'region' user only?85assert(!r->as_Region()->has_phi(), "no phi users");86if( !progress ) { // No progress87if (region->has_phi()) {88return NULL; // Only flatten if no Phi users89// igvn->hash_delete( phi );90}91igvn->hash_delete( region );92progress = region; // Making progress93}94igvn->hash_delete( r );9596// Append inputs to 'r' onto 'region'97for( uint j = 1; j < r->req(); j++ ) {98// Move an input from 'r' to 'region'99region->add_req(r->in(j));100r->set_req(j, phase->C->top());101// Update phis of 'region'102//for( uint k = 0; k < max; k++ ) {103// Node *phi = region->out(k);104// if( phi->is_Phi() ) {105// phi->add_req(phi->in(i));106// }107//}108109rreq++; // One more input to Region110} // Found a region to merge into Region111// Clobber pointer to the now dead 'r'112region->set_req(i, phase->C->top());113}114}115116return progress;117}118119120121//--------------------------------has_phi--------------------------------------122// Helper function: Return any PhiNode that uses this region or NULL123PhiNode* RegionNode::has_phi() const {124for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {125Node* phi = fast_out(i);126if (phi->is_Phi()) { // Check for Phi users127assert(phi->in(0) == (Node*)this, "phi uses region only via in(0)");128return phi->as_Phi(); // this one is good enough129}130}131132return NULL;133}134135136//-----------------------------has_unique_phi----------------------------------137// Helper function: Return the only PhiNode that uses this region or NULL138PhiNode* RegionNode::has_unique_phi() const {139// Check that only one use is a Phi140PhiNode* only_phi = NULL;141for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {142Node* phi = fast_out(i);143if (phi->is_Phi()) { // Check for Phi users144assert(phi->in(0) == (Node*)this, "phi uses region only via in(0)");145if (only_phi == NULL) {146only_phi = phi->as_Phi();147} else {148return NULL; // multiple phis149}150}151}152153return only_phi;154}155156157//------------------------------check_phi_clipping-----------------------------158// Helper function for RegionNode's identification of FP clipping159// Check inputs to the Phi160static bool check_phi_clipping( PhiNode *phi, ConNode * &min, uint &min_idx, ConNode * &max, uint &max_idx, Node * &val, uint &val_idx ) {161min = NULL;162max = NULL;163val = NULL;164min_idx = 0;165max_idx = 0;166val_idx = 0;167uint phi_max = phi->req();168if( phi_max == 4 ) {169for( uint j = 1; j < phi_max; ++j ) {170Node *n = phi->in(j);171int opcode = n->Opcode();172switch( opcode ) {173case Op_ConI:174{175if( min == NULL ) {176min = n->Opcode() == Op_ConI ? (ConNode*)n : NULL;177min_idx = j;178} else {179max = n->Opcode() == Op_ConI ? (ConNode*)n : NULL;180max_idx = j;181if( min->get_int() > max->get_int() ) {182// Swap min and max183ConNode *temp;184uint temp_idx;185temp = min; min = max; max = temp;186temp_idx = min_idx; min_idx = max_idx; max_idx = temp_idx;187}188}189}190break;191default:192{193val = n;194val_idx = j;195}196break;197}198}199}200return ( min && max && val && (min->get_int() <= 0) && (max->get_int() >=0) );201}202203204//------------------------------check_if_clipping------------------------------205// Helper function for RegionNode's identification of FP clipping206// Check that inputs to Region come from two IfNodes,207//208// If209// False True210// If |211// False True |212// | | |213// RegionNode_inputs214//215static bool check_if_clipping( const RegionNode *region, IfNode * &bot_if, IfNode * &top_if ) {216top_if = NULL;217bot_if = NULL;218219// Check control structure above RegionNode for (if ( if ) )220Node *in1 = region->in(1);221Node *in2 = region->in(2);222Node *in3 = region->in(3);223// Check that all inputs are projections224if( in1->is_Proj() && in2->is_Proj() && in3->is_Proj() ) {225Node *in10 = in1->in(0);226Node *in20 = in2->in(0);227Node *in30 = in3->in(0);228// Check that #1 and #2 are ifTrue and ifFalse from same If229if( in10 != NULL && in10->is_If() &&230in20 != NULL && in20->is_If() &&231in30 != NULL && in30->is_If() && in10 == in20 &&232(in1->Opcode() != in2->Opcode()) ) {233Node *in100 = in10->in(0);234Node *in1000 = (in100 != NULL && in100->is_Proj()) ? in100->in(0) : NULL;235// Check that control for in10 comes from other branch of IF from in3236if( in1000 != NULL && in1000->is_If() &&237in30 == in1000 && (in3->Opcode() != in100->Opcode()) ) {238// Control pattern checks239top_if = (IfNode*)in1000;240bot_if = (IfNode*)in10;241}242}243}244245return (top_if != NULL);246}247248249//------------------------------check_convf2i_clipping-------------------------250// Helper function for RegionNode's identification of FP clipping251// Verify that the value input to the phi comes from "ConvF2I; LShift; RShift"252static bool check_convf2i_clipping( PhiNode *phi, uint idx, ConvF2INode * &convf2i, Node *min, Node *max) {253convf2i = NULL;254255// Check for the RShiftNode256Node *rshift = phi->in(idx);257assert( rshift, "Previous checks ensure phi input is present");258if( rshift->Opcode() != Op_RShiftI ) { return false; }259260// Check for the LShiftNode261Node *lshift = rshift->in(1);262assert( lshift, "Previous checks ensure phi input is present");263if( lshift->Opcode() != Op_LShiftI ) { return false; }264265// Check for the ConvF2INode266Node *conv = lshift->in(1);267if( conv->Opcode() != Op_ConvF2I ) { return false; }268269// Check that shift amounts are only to get sign bits set after F2I270jint max_cutoff = max->get_int();271jint min_cutoff = min->get_int();272jint left_shift = lshift->in(2)->get_int();273jint right_shift = rshift->in(2)->get_int();274jint max_post_shift = nth_bit(BitsPerJavaInteger - left_shift - 1);275if( left_shift != right_shift ||2760 > left_shift || left_shift >= BitsPerJavaInteger ||277max_post_shift < max_cutoff ||278max_post_shift < -min_cutoff ) {279// Shifts are necessary but current transformation eliminates them280return false;281}282283// OK to return the result of ConvF2I without shifting284convf2i = (ConvF2INode*)conv;285return true;286}287288289//------------------------------check_compare_clipping-------------------------290// Helper function for RegionNode's identification of FP clipping291static bool check_compare_clipping( bool less_than, IfNode *iff, ConNode *limit, Node * & input ) {292Node *i1 = iff->in(1);293if ( !i1->is_Bool() ) { return false; }294BoolNode *bool1 = i1->as_Bool();295if( less_than && bool1->_test._test != BoolTest::le ) { return false; }296else if( !less_than && bool1->_test._test != BoolTest::lt ) { return false; }297const Node *cmpF = bool1->in(1);298if( cmpF->Opcode() != Op_CmpF ) { return false; }299// Test that the float value being compared against300// is equivalent to the int value used as a limit301Node *nodef = cmpF->in(2);302if( nodef->Opcode() != Op_ConF ) { return false; }303jfloat conf = nodef->getf();304jint coni = limit->get_int();305if( ((int)conf) != coni ) { return false; }306input = cmpF->in(1);307return true;308}309310//------------------------------is_unreachable_region--------------------------311// Find if the Region node is reachable from the root.312bool RegionNode::is_unreachable_region(PhaseGVN *phase) const {313assert(req() == 2, "");314315// First, cut the simple case of fallthrough region when NONE of316// region's phis references itself directly or through a data node.317uint max = outcnt();318uint i;319for (i = 0; i < max; i++) {320Node* phi = raw_out(i);321if (phi != NULL && phi->is_Phi()) {322assert(phase->eqv(phi->in(0), this) && phi->req() == 2, "");323if (phi->outcnt() == 0)324continue; // Safe case - no loops325if (phi->outcnt() == 1) {326Node* u = phi->raw_out(0);327// Skip if only one use is an other Phi or Call or Uncommon trap.328// It is safe to consider this case as fallthrough.329if (u != NULL && (u->is_Phi() || u->is_CFG()))330continue;331}332// Check when phi references itself directly or through an other node.333if (phi->as_Phi()->simple_data_loop_check(phi->in(1)) >= PhiNode::Unsafe)334break; // Found possible unsafe data loop.335}336}337if (i >= max)338return false; // An unsafe case was NOT found - don't need graph walk.339340// Unsafe case - check if the Region node is reachable from root.341ResourceMark rm;342343Arena *a = Thread::current()->resource_area();344Node_List nstack(a);345VectorSet visited(a);346347// Mark all control nodes reachable from root outputs348Node *n = (Node*)phase->C->root();349nstack.push(n);350visited.set(n->_idx);351while (nstack.size() != 0) {352n = nstack.pop();353uint max = n->outcnt();354for (uint i = 0; i < max; i++) {355Node* m = n->raw_out(i);356if (m != NULL && m->is_CFG()) {357if (phase->eqv(m, this)) {358return false; // We reached the Region node - it is not dead.359}360if (!visited.test_set(m->_idx))361nstack.push(m);362}363}364}365366return true; // The Region node is unreachable - it is dead.367}368369bool RegionNode::try_clean_mem_phi(PhaseGVN *phase) {370// Incremental inlining + PhaseStringOpts sometimes produce:371//372// cmpP with 1 top input373// |374// If375// / \376// IfFalse IfTrue /- Some Node377// \ / / /378// Region / /-MergeMem379// \---Phi380//381//382// It's expected by PhaseStringOpts that the Region goes away and is383// replaced by If's control input but because there's still a Phi,384// the Region stays in the graph. The top input from the cmpP is385// propagated forward and a subgraph that is useful goes away. The386// code below replaces the Phi with the MergeMem so that the Region387// is simplified.388389PhiNode* phi = has_unique_phi();390if (phi && phi->type() == Type::MEMORY && req() == 3 && phi->is_diamond_phi(true)) {391MergeMemNode* m = NULL;392assert(phi->req() == 3, "same as region");393for (uint i = 1; i < 3; ++i) {394Node *mem = phi->in(i);395if (mem && mem->is_MergeMem() && in(i)->outcnt() == 1) {396// Nothing is control-dependent on path #i except the region itself.397m = mem->as_MergeMem();398uint j = 3 - i;399Node* other = phi->in(j);400if (other && other == m->base_memory()) {401// m is a successor memory to other, and is not pinned inside the diamond, so push it out.402// This will allow the diamond to collapse completely.403phase->is_IterGVN()->replace_node(phi, m);404return true;405}406}407}408}409return false;410}411412//------------------------------Ideal------------------------------------------413// Return a node which is more "ideal" than the current node. Must preserve414// the CFG, but we can still strip out dead paths.415Node *RegionNode::Ideal(PhaseGVN *phase, bool can_reshape) {416if( !can_reshape && !in(0) ) return NULL; // Already degraded to a Copy417assert(!in(0) || !in(0)->is_Root(), "not a specially hidden merge");418419// Check for RegionNode with no Phi users and both inputs come from either420// arm of the same IF. If found, then the control-flow split is useless.421bool has_phis = false;422if (can_reshape) { // Need DU info to check for Phi users423has_phis = (has_phi() != NULL); // Cache result424if (has_phis && try_clean_mem_phi(phase)) {425has_phis = false;426}427428if (!has_phis) { // No Phi users? Nothing merging?429for (uint i = 1; i < req()-1; i++) {430Node *if1 = in(i);431if( !if1 ) continue;432Node *iff = if1->in(0);433if( !iff || !iff->is_If() ) continue;434for( uint j=i+1; j<req(); j++ ) {435if( in(j) && in(j)->in(0) == iff &&436if1->Opcode() != in(j)->Opcode() ) {437// Add the IF Projections to the worklist. They (and the IF itself)438// will be eliminated if dead.439phase->is_IterGVN()->add_users_to_worklist(iff);440set_req(i, iff->in(0));// Skip around the useless IF diamond441set_req(j, NULL);442return this; // Record progress443}444}445}446}447}448449// Remove TOP or NULL input paths. If only 1 input path remains, this Region450// degrades to a copy.451bool add_to_worklist = false;452int cnt = 0; // Count of values merging453DEBUG_ONLY( int cnt_orig = req(); ) // Save original inputs count454int del_it = 0; // The last input path we delete455// For all inputs...456for( uint i=1; i<req(); ++i ){// For all paths in457Node *n = in(i); // Get the input458if( n != NULL ) {459// Remove useless control copy inputs460if( n->is_Region() && n->as_Region()->is_copy() ) {461set_req(i, n->nonnull_req());462i--;463continue;464}465if( n->is_Proj() ) { // Remove useless rethrows466Node *call = n->in(0);467if (call->is_Call() && call->as_Call()->entry_point() == OptoRuntime::rethrow_stub()) {468set_req(i, call->in(0));469i--;470continue;471}472}473if( phase->type(n) == Type::TOP ) {474set_req(i, NULL); // Ignore TOP inputs475i--;476continue;477}478cnt++; // One more value merging479480} else if (can_reshape) { // Else found dead path with DU info481PhaseIterGVN *igvn = phase->is_IterGVN();482del_req(i); // Yank path from self483del_it = i;484uint max = outcnt();485DUIterator j;486bool progress = true;487while(progress) { // Need to establish property over all users488progress = false;489for (j = outs(); has_out(j); j++) {490Node *n = out(j);491if( n->req() != req() && n->is_Phi() ) {492assert( n->in(0) == this, "" );493igvn->hash_delete(n); // Yank from hash before hacking edges494n->set_req_X(i,NULL,igvn);// Correct DU info495n->del_req(i); // Yank path from Phis496if( max != outcnt() ) {497progress = true;498j = refresh_out_pos(j);499max = outcnt();500}501}502}503}504add_to_worklist = true;505i--;506}507}508509if (can_reshape && cnt == 1) {510// Is it dead loop?511// If it is LoopNopde it had 2 (+1 itself) inputs and512// one of them was cut. The loop is dead if it was EntryContol.513// Loop node may have only one input because entry path514// is removed in PhaseIdealLoop::Dominators().515assert(!this->is_Loop() || cnt_orig <= 3, "Loop node should have 3 or less inputs");516if (this->is_Loop() && (del_it == LoopNode::EntryControl ||517del_it == 0 && is_unreachable_region(phase)) ||518!this->is_Loop() && has_phis && is_unreachable_region(phase)) {519// Yes, the region will be removed during the next step below.520// Cut the backedge input and remove phis since no data paths left.521// We don't cut outputs to other nodes here since we need to put them522// on the worklist.523del_req(1);524cnt = 0;525assert( req() == 1, "no more inputs expected" );526uint max = outcnt();527bool progress = true;528Node *top = phase->C->top();529PhaseIterGVN *igvn = phase->is_IterGVN();530DUIterator j;531while(progress) {532progress = false;533for (j = outs(); has_out(j); j++) {534Node *n = out(j);535if( n->is_Phi() ) {536assert( igvn->eqv(n->in(0), this), "" );537assert( n->req() == 2 && n->in(1) != NULL, "Only one data input expected" );538// Break dead loop data path.539// Eagerly replace phis with top to avoid phis copies generation.540igvn->replace_node(n, top);541if( max != outcnt() ) {542progress = true;543j = refresh_out_pos(j);544max = outcnt();545}546}547}548}549add_to_worklist = true;550}551}552if (add_to_worklist) {553phase->is_IterGVN()->add_users_to_worklist(this); // Revisit collapsed Phis554}555556if( cnt <= 1 ) { // Only 1 path in?557set_req(0, NULL); // Null control input for region copy558if( cnt == 0 && !can_reshape) { // Parse phase - leave the node as it is.559// No inputs or all inputs are NULL.560return NULL;561} else if (can_reshape) { // Optimization phase - remove the node562PhaseIterGVN *igvn = phase->is_IterGVN();563Node *parent_ctrl;564if( cnt == 0 ) {565assert( req() == 1, "no inputs expected" );566// During IGVN phase such region will be subsumed by TOP node567// so region's phis will have TOP as control node.568// Kill phis here to avoid it. PhiNode::is_copy() will be always false.569// Also set other user's input to top.570parent_ctrl = phase->C->top();571} else {572// The fallthrough case since we already checked dead loops above.573parent_ctrl = in(1);574assert(parent_ctrl != NULL, "Region is a copy of some non-null control");575assert(!igvn->eqv(parent_ctrl, this), "Close dead loop");576}577if (!add_to_worklist)578igvn->add_users_to_worklist(this); // Check for further allowed opts579for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {580Node* n = last_out(i);581igvn->hash_delete(n); // Remove from worklist before modifying edges582if( n->is_Phi() ) { // Collapse all Phis583// Eagerly replace phis to avoid copies generation.584Node* in;585if( cnt == 0 ) {586assert( n->req() == 1, "No data inputs expected" );587in = parent_ctrl; // replaced by top588} else {589assert( n->req() == 2 && n->in(1) != NULL, "Only one data input expected" );590in = n->in(1); // replaced by unique input591if( n->as_Phi()->is_unsafe_data_reference(in) )592in = phase->C->top(); // replaced by top593}594if (n->outcnt() == 0) {595in = phase->C->top();596}597igvn->replace_node(n, in);598}599else if( n->is_Region() ) { // Update all incoming edges600assert( !igvn->eqv(n, this), "Must be removed from DefUse edges");601uint uses_found = 0;602for( uint k=1; k < n->req(); k++ ) {603if( n->in(k) == this ) {604n->set_req(k, parent_ctrl);605uses_found++;606}607}608if( uses_found > 1 ) { // (--i) done at the end of the loop.609i -= (uses_found - 1);610}611}612else {613assert( igvn->eqv(n->in(0), this), "Expect RegionNode to be control parent");614n->set_req(0, parent_ctrl);615}616#ifdef ASSERT617for( uint k=0; k < n->req(); k++ ) {618assert( !igvn->eqv(n->in(k), this), "All uses of RegionNode should be gone");619}620#endif621}622// Remove the RegionNode itself from DefUse info623igvn->remove_dead_node(this);624return NULL;625}626return this; // Record progress627}628629630// If a Region flows into a Region, merge into one big happy merge.631if (can_reshape) {632Node *m = merge_region(this, phase);633if (m != NULL) return m;634}635636// Check if this region is the root of a clipping idiom on floats637if( ConvertFloat2IntClipping && can_reshape && req() == 4 ) {638// Check that only one use is a Phi and that it simplifies to two constants +639PhiNode* phi = has_unique_phi();640if (phi != NULL) { // One Phi user641// Check inputs to the Phi642ConNode *min;643ConNode *max;644Node *val;645uint min_idx;646uint max_idx;647uint val_idx;648if( check_phi_clipping( phi, min, min_idx, max, max_idx, val, val_idx ) ) {649IfNode *top_if;650IfNode *bot_if;651if( check_if_clipping( this, bot_if, top_if ) ) {652// Control pattern checks, now verify compares653Node *top_in = NULL; // value being compared against654Node *bot_in = NULL;655if( check_compare_clipping( true, bot_if, min, bot_in ) &&656check_compare_clipping( false, top_if, max, top_in ) ) {657if( bot_in == top_in ) {658PhaseIterGVN *gvn = phase->is_IterGVN();659assert( gvn != NULL, "Only had DefUse info in IterGVN");660// Only remaining check is that bot_in == top_in == (Phi's val + mods)661662// Check for the ConvF2INode663ConvF2INode *convf2i;664if( check_convf2i_clipping( phi, val_idx, convf2i, min, max ) &&665convf2i->in(1) == bot_in ) {666// Matched pattern, including LShiftI; RShiftI, replace with integer compares667// max test668Node *cmp = gvn->register_new_node_with_optimizer(new (phase->C) CmpINode( convf2i, min ));669Node *boo = gvn->register_new_node_with_optimizer(new (phase->C) BoolNode( cmp, BoolTest::lt ));670IfNode *iff = (IfNode*)gvn->register_new_node_with_optimizer(new (phase->C) IfNode( top_if->in(0), boo, PROB_UNLIKELY_MAG(5), top_if->_fcnt ));671Node *if_min= gvn->register_new_node_with_optimizer(new (phase->C) IfTrueNode (iff));672Node *ifF = gvn->register_new_node_with_optimizer(new (phase->C) IfFalseNode(iff));673// min test674cmp = gvn->register_new_node_with_optimizer(new (phase->C) CmpINode( convf2i, max ));675boo = gvn->register_new_node_with_optimizer(new (phase->C) BoolNode( cmp, BoolTest::gt ));676iff = (IfNode*)gvn->register_new_node_with_optimizer(new (phase->C) IfNode( ifF, boo, PROB_UNLIKELY_MAG(5), bot_if->_fcnt ));677Node *if_max= gvn->register_new_node_with_optimizer(new (phase->C) IfTrueNode (iff));678ifF = gvn->register_new_node_with_optimizer(new (phase->C) IfFalseNode(iff));679// update input edges to region node680set_req_X( min_idx, if_min, gvn );681set_req_X( max_idx, if_max, gvn );682set_req_X( val_idx, ifF, gvn );683// remove unnecessary 'LShiftI; RShiftI' idiom684gvn->hash_delete(phi);685phi->set_req_X( val_idx, convf2i, gvn );686gvn->hash_find_insert(phi);687// Return transformed region node688return this;689}690}691}692}693}694}695}696697return NULL;698}699700701702const RegMask &RegionNode::out_RegMask() const {703return RegMask::Empty;704}705706// Find the one non-null required input. RegionNode only707Node *Node::nonnull_req() const {708assert( is_Region(), "" );709for( uint i = 1; i < _cnt; i++ )710if( in(i) )711return in(i);712ShouldNotReachHere();713return NULL;714}715716717//=============================================================================718// note that these functions assume that the _adr_type field is flattened719uint PhiNode::hash() const {720const Type* at = _adr_type;721return TypeNode::hash() + (at ? at->hash() : 0);722}723uint PhiNode::cmp( const Node &n ) const {724return TypeNode::cmp(n) && _adr_type == ((PhiNode&)n)._adr_type;725}726static inline727const TypePtr* flatten_phi_adr_type(const TypePtr* at) {728if (at == NULL || at == TypePtr::BOTTOM) return at;729return Compile::current()->alias_type(at)->adr_type();730}731732//----------------------------make---------------------------------------------733// create a new phi with edges matching r and set (initially) to x734PhiNode* PhiNode::make(Node* r, Node* x, const Type *t, const TypePtr* at) {735uint preds = r->req(); // Number of predecessor paths736assert(t != Type::MEMORY || at == flatten_phi_adr_type(at), "flatten at");737PhiNode* p = new (Compile::current()) PhiNode(r, t, at);738for (uint j = 1; j < preds; j++) {739// Fill in all inputs, except those which the region does not yet have740if (r->in(j) != NULL)741p->init_req(j, x);742}743return p;744}745PhiNode* PhiNode::make(Node* r, Node* x) {746const Type* t = x->bottom_type();747const TypePtr* at = NULL;748if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());749return make(r, x, t, at);750}751PhiNode* PhiNode::make_blank(Node* r, Node* x) {752const Type* t = x->bottom_type();753const TypePtr* at = NULL;754if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());755return new (Compile::current()) PhiNode(r, t, at);756}757758759//------------------------slice_memory-----------------------------------------760// create a new phi with narrowed memory type761PhiNode* PhiNode::slice_memory(const TypePtr* adr_type) const {762PhiNode* mem = (PhiNode*) clone();763*(const TypePtr**)&mem->_adr_type = adr_type;764// convert self-loops, or else we get a bad graph765for (uint i = 1; i < req(); i++) {766if ((const Node*)in(i) == this) mem->set_req(i, mem);767}768mem->verify_adr_type();769return mem;770}771772//------------------------split_out_instance-----------------------------------773// Split out an instance type from a bottom phi.774PhiNode* PhiNode::split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const {775const TypeOopPtr *t_oop = at->isa_oopptr();776assert(t_oop != NULL && t_oop->is_known_instance(), "expecting instance oopptr");777const TypePtr *t = adr_type();778assert(type() == Type::MEMORY &&779(t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM ||780t->isa_oopptr() && !t->is_oopptr()->is_known_instance() &&781t->is_oopptr()->cast_to_exactness(true)782->is_oopptr()->cast_to_ptr_type(t_oop->ptr())783->is_oopptr()->cast_to_instance_id(t_oop->instance_id()) == t_oop),784"bottom or raw memory required");785786// Check if an appropriate node already exists.787Node *region = in(0);788for (DUIterator_Fast kmax, k = region->fast_outs(kmax); k < kmax; k++) {789Node* use = region->fast_out(k);790if( use->is_Phi()) {791PhiNode *phi2 = use->as_Phi();792if (phi2->type() == Type::MEMORY && phi2->adr_type() == at) {793return phi2;794}795}796}797Compile *C = igvn->C;798Arena *a = Thread::current()->resource_area();799Node_Array node_map = new Node_Array(a);800Node_Stack stack(a, C->live_nodes() >> 4);801PhiNode *nphi = slice_memory(at);802igvn->register_new_node_with_optimizer( nphi );803node_map.map(_idx, nphi);804stack.push((Node *)this, 1);805while(!stack.is_empty()) {806PhiNode *ophi = stack.node()->as_Phi();807uint i = stack.index();808assert(i >= 1, "not control edge");809stack.pop();810nphi = node_map[ophi->_idx]->as_Phi();811for (; i < ophi->req(); i++) {812Node *in = ophi->in(i);813if (in == NULL || igvn->type(in) == Type::TOP)814continue;815Node *opt = MemNode::optimize_simple_memory_chain(in, t_oop, NULL, igvn);816PhiNode *optphi = opt->is_Phi() ? opt->as_Phi() : NULL;817if (optphi != NULL && optphi->adr_type() == TypePtr::BOTTOM) {818opt = node_map[optphi->_idx];819if (opt == NULL) {820stack.push(ophi, i);821nphi = optphi->slice_memory(at);822igvn->register_new_node_with_optimizer( nphi );823node_map.map(optphi->_idx, nphi);824ophi = optphi;825i = 0; // will get incremented at top of loop826continue;827}828}829nphi->set_req(i, opt);830}831}832return nphi;833}834835//------------------------verify_adr_type--------------------------------------836#ifdef ASSERT837void PhiNode::verify_adr_type(VectorSet& visited, const TypePtr* at) const {838if (visited.test_set(_idx)) return; //already visited839840// recheck constructor invariants:841verify_adr_type(false);842843// recheck local phi/phi consistency:844assert(_adr_type == at || _adr_type == TypePtr::BOTTOM,845"adr_type must be consistent across phi nest");846847// walk around848for (uint i = 1; i < req(); i++) {849Node* n = in(i);850if (n == NULL) continue;851const Node* np = in(i);852if (np->is_Phi()) {853np->as_Phi()->verify_adr_type(visited, at);854} else if (n->bottom_type() == Type::TOP855|| (n->is_Mem() && n->in(MemNode::Address)->bottom_type() == Type::TOP)) {856// ignore top inputs857} else {858const TypePtr* nat = flatten_phi_adr_type(n->adr_type());859// recheck phi/non-phi consistency at leaves:860assert((nat != NULL) == (at != NULL), "");861assert(nat == at || nat == TypePtr::BOTTOM,862"adr_type must be consistent at leaves of phi nest");863}864}865}866867// Verify a whole nest of phis rooted at this one.868void PhiNode::verify_adr_type(bool recursive) const {869if (is_error_reported()) return; // muzzle asserts when debugging an error870if (Node::in_dump()) return; // muzzle asserts when printing871872assert((_type == Type::MEMORY) == (_adr_type != NULL), "adr_type for memory phis only");873874if (!VerifyAliases) return; // verify thoroughly only if requested875876assert(_adr_type == flatten_phi_adr_type(_adr_type),877"Phi::adr_type must be pre-normalized");878879if (recursive) {880VectorSet visited(Thread::current()->resource_area());881verify_adr_type(visited, _adr_type);882}883}884#endif885886887//------------------------------Value------------------------------------------888// Compute the type of the PhiNode889const Type *PhiNode::Value( PhaseTransform *phase ) const {890Node *r = in(0); // RegionNode891if( !r ) // Copy or dead892return in(1) ? phase->type(in(1)) : Type::TOP;893894// Note: During parsing, phis are often transformed before their regions.895// This means we have to use type_or_null to defend against untyped regions.896if( phase->type_or_null(r) == Type::TOP ) // Dead code?897return Type::TOP;898899// Check for trip-counted loop. If so, be smarter.900CountedLoopNode *l = r->is_CountedLoop() ? r->as_CountedLoop() : NULL;901if( l && l->can_be_counted_loop(phase) &&902((const Node*)l->phi() == this) ) { // Trip counted loop!903// protect against init_trip() or limit() returning NULL904const Node *init = l->init_trip();905const Node *limit = l->limit();906if( init != NULL && limit != NULL && l->stride_is_con() ) {907const TypeInt *lo = init ->bottom_type()->isa_int();908const TypeInt *hi = limit->bottom_type()->isa_int();909if( lo && hi ) { // Dying loops might have TOP here910int stride = l->stride_con();911if( stride < 0 ) { // Down-counter loop912const TypeInt *tmp = lo; lo = hi; hi = tmp;913stride = -stride;914}915if( lo->_hi < hi->_lo ) // Reversed endpoints are well defined :-(916return TypeInt::make(lo->_lo,hi->_hi,3);917}918}919}920921// Until we have harmony between classes and interfaces in the type922// lattice, we must tread carefully around phis which implicitly923// convert the one to the other.924const TypePtr* ttp = _type->make_ptr();925const TypeInstPtr* ttip = (ttp != NULL) ? ttp->isa_instptr() : NULL;926const TypeKlassPtr* ttkp = (ttp != NULL) ? ttp->isa_klassptr() : NULL;927bool is_intf = false;928if (ttip != NULL) {929ciKlass* k = ttip->klass();930if (k->is_loaded() && k->is_interface())931is_intf = true;932}933if (ttkp != NULL) {934ciKlass* k = ttkp->klass();935if (k->is_loaded() && k->is_interface())936is_intf = true;937}938939// Default case: merge all inputs940const Type *t = Type::TOP; // Merged type starting value941for (uint i = 1; i < req(); ++i) {// For all paths in942// Reachable control path?943if (r->in(i) && phase->type(r->in(i)) == Type::CONTROL) {944const Type* ti = phase->type(in(i));945// We assume that each input of an interface-valued Phi is a true946// subtype of that interface. This might not be true of the meet947// of all the input types. The lattice is not distributive in948// such cases. Ward off asserts in type.cpp by refusing to do949// meets between interfaces and proper classes.950const TypePtr* tip = ti->make_ptr();951const TypeInstPtr* tiip = (tip != NULL) ? tip->isa_instptr() : NULL;952if (tiip) {953bool ti_is_intf = false;954ciKlass* k = tiip->klass();955if (k->is_loaded() && k->is_interface())956ti_is_intf = true;957if (is_intf != ti_is_intf)958{ t = _type; break; }959}960t = t->meet_speculative(ti);961}962}963964// The worst-case type (from ciTypeFlow) should be consistent with "t".965// That is, we expect that "t->higher_equal(_type)" holds true.966// There are various exceptions:967// - Inputs which are phis might in fact be widened unnecessarily.968// For example, an input might be a widened int while the phi is a short.969// - Inputs might be BotPtrs but this phi is dependent on a null check,970// and postCCP has removed the cast which encodes the result of the check.971// - The type of this phi is an interface, and the inputs are classes.972// - Value calls on inputs might produce fuzzy results.973// (Occurrences of this case suggest improvements to Value methods.)974//975// It is not possible to see Type::BOTTOM values as phi inputs,976// because the ciTypeFlow pre-pass produces verifier-quality types.977const Type* ft = t->filter_speculative(_type); // Worst case type978979#ifdef ASSERT980// The following logic has been moved into TypeOopPtr::filter.981const Type* jt = t->join_speculative(_type);982if (jt->empty()) { // Emptied out???983984// Check for evil case of 't' being a class and '_type' expecting an985// interface. This can happen because the bytecodes do not contain986// enough type info to distinguish a Java-level interface variable987// from a Java-level object variable. If we meet 2 classes which988// both implement interface I, but their meet is at 'j/l/O' which989// doesn't implement I, we have no way to tell if the result should990// be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows991// into a Phi which "knows" it's an Interface type we'll have to992// uplift the type.993if (!t->empty() && ttip && ttip->is_loaded() && ttip->klass()->is_interface()) {994assert(ft == _type, ""); // Uplift to interface995} else if (!t->empty() && ttkp && ttkp->is_loaded() && ttkp->klass()->is_interface()) {996assert(ft == _type, ""); // Uplift to interface997} else {998// We also have to handle 'evil cases' of interface- vs. class-arrays999Type::get_arrays_base_elements(jt, _type, NULL, &ttip);1000if (!t->empty() && ttip != NULL && ttip->is_loaded() && ttip->klass()->is_interface()) {1001assert(ft == _type, ""); // Uplift to array of interface1002} else {1003// Otherwise it's something stupid like non-overlapping int ranges1004// found on dying counted loops.1005assert(ft == Type::TOP, ""); // Canonical empty value1006}1007}1008}10091010else {10111012// If we have an interface-typed Phi and we narrow to a class type, the join1013// should report back the class. However, if we have a J/L/Object1014// class-typed Phi and an interface flows in, it's possible that the meet &1015// join report an interface back out. This isn't possible but happens1016// because the type system doesn't interact well with interfaces.1017const TypePtr *jtp = jt->make_ptr();1018const TypeInstPtr *jtip = (jtp != NULL) ? jtp->isa_instptr() : NULL;1019const TypeKlassPtr *jtkp = (jtp != NULL) ? jtp->isa_klassptr() : NULL;1020if( jtip && ttip ) {1021if( jtip->is_loaded() && jtip->klass()->is_interface() &&1022ttip->is_loaded() && !ttip->klass()->is_interface() ) {1023// Happens in a CTW of rt.jar, 320-341, no extra flags1024assert(ft == ttip->cast_to_ptr_type(jtip->ptr()) ||1025ft->isa_narrowoop() && ft->make_ptr() == ttip->cast_to_ptr_type(jtip->ptr()), "");1026jt = ft;1027}1028}1029if( jtkp && ttkp ) {1030if( jtkp->is_loaded() && jtkp->klass()->is_interface() &&1031!jtkp->klass_is_exact() && // Keep exact interface klass (6894807)1032ttkp->is_loaded() && !ttkp->klass()->is_interface() ) {1033assert(ft == ttkp->cast_to_ptr_type(jtkp->ptr()) ||1034ft->isa_narrowklass() && ft->make_ptr() == ttkp->cast_to_ptr_type(jtkp->ptr()), "");1035jt = ft;1036}1037}1038if (jt != ft && jt->base() == ft->base()) {1039if (jt->isa_int() &&1040jt->is_int()->_lo == ft->is_int()->_lo &&1041jt->is_int()->_hi == ft->is_int()->_hi)1042jt = ft;1043if (jt->isa_long() &&1044jt->is_long()->_lo == ft->is_long()->_lo &&1045jt->is_long()->_hi == ft->is_long()->_hi)1046jt = ft;1047}1048if (jt != ft) {1049tty->print("merge type: "); t->dump(); tty->cr();1050tty->print("kill type: "); _type->dump(); tty->cr();1051tty->print("join type: "); jt->dump(); tty->cr();1052tty->print("filter type: "); ft->dump(); tty->cr();1053}1054assert(jt == ft, "");1055}1056#endif //ASSERT10571058// Deal with conversion problems found in data loops.1059ft = phase->saturate(ft, phase->type_or_null(this), _type);10601061return ft;1062}106310641065//------------------------------is_diamond_phi---------------------------------1066// Does this Phi represent a simple well-shaped diamond merge? Return the1067// index of the true path or 0 otherwise.1068// If check_control_only is true, do not inspect the If node at the1069// top, and return -1 (not an edge number) on success.1070int PhiNode::is_diamond_phi(bool check_control_only) const {1071// Check for a 2-path merge1072Node *region = in(0);1073if( !region ) return 0;1074if( region->req() != 3 ) return 0;1075if( req() != 3 ) return 0;1076// Check that both paths come from the same If1077Node *ifp1 = region->in(1);1078Node *ifp2 = region->in(2);1079if( !ifp1 || !ifp2 ) return 0;1080Node *iff = ifp1->in(0);1081if( !iff || !iff->is_If() ) return 0;1082if( iff != ifp2->in(0) ) return 0;1083if (check_control_only) return -1;1084// Check for a proper bool/cmp1085const Node *b = iff->in(1);1086if( !b->is_Bool() ) return 0;1087const Node *cmp = b->in(1);1088if( !cmp->is_Cmp() ) return 0;10891090// Check for branching opposite expected1091if( ifp2->Opcode() == Op_IfTrue ) {1092assert( ifp1->Opcode() == Op_IfFalse, "" );1093return 2;1094} else {1095assert( ifp1->Opcode() == Op_IfTrue, "" );1096return 1;1097}1098}10991100//----------------------------check_cmove_id-----------------------------------1101// Check for CMove'ing a constant after comparing against the constant.1102// Happens all the time now, since if we compare equality vs a constant in1103// the parser, we "know" the variable is constant on one path and we force1104// it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a1105// conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more1106// general in that we don't need constants. Since CMove's are only inserted1107// in very special circumstances, we do it here on generic Phi's.1108Node* PhiNode::is_cmove_id(PhaseTransform* phase, int true_path) {1109assert(true_path !=0, "only diamond shape graph expected");11101111// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1112// phi->region->if_proj->ifnode->bool->cmp1113Node* region = in(0);1114Node* iff = region->in(1)->in(0);1115BoolNode* b = iff->in(1)->as_Bool();1116Node* cmp = b->in(1);1117Node* tval = in(true_path);1118Node* fval = in(3-true_path);1119Node* id = CMoveNode::is_cmove_id(phase, cmp, tval, fval, b);1120if (id == NULL)1121return NULL;11221123// Either value might be a cast that depends on a branch of 'iff'.1124// Since the 'id' value will float free of the diamond, either1125// decast or return failure.1126Node* ctl = id->in(0);1127if (ctl != NULL && ctl->in(0) == iff) {1128if (id->is_ConstraintCast()) {1129return id->in(1);1130} else {1131// Don't know how to disentangle this value.1132return NULL;1133}1134}11351136return id;1137}11381139//------------------------------Identity---------------------------------------1140// Check for Region being Identity.1141Node *PhiNode::Identity( PhaseTransform *phase ) {1142// Check for no merging going on1143// (There used to be special-case code here when this->region->is_Loop.1144// It would check for a tributary phi on the backedge that the main phi1145// trivially, perhaps with a single cast. The unique_input method1146// does all this and more, by reducing such tributaries to 'this'.)1147Node* uin = unique_input(phase);1148if (uin != NULL) {1149return uin;1150}11511152int true_path = is_diamond_phi();1153if (true_path != 0) {1154Node* id = is_cmove_id(phase, true_path);1155if (id != NULL) return id;1156}11571158return this; // No identity1159}11601161//-----------------------------unique_input------------------------------------1162// Find the unique value, discounting top, self-loops, and casts.1163// Return top if there are no inputs, and self if there are multiple.1164Node* PhiNode::unique_input(PhaseTransform* phase) {1165// 1) One unique direct input, or1166// 2) some of the inputs have an intervening ConstraintCast and1167// the type of input is the same or sharper (more specific)1168// than the phi's type.1169// 3) an input is a self loop1170//1171// 1) input or 2) input or 3) input __1172// / \ / \ \ / \1173// \ / | cast phi cast1174// phi \ / / \ /1175// phi / --11761177Node* r = in(0); // RegionNode1178if (r == NULL) return in(1); // Already degraded to a Copy1179Node* uncasted_input = NULL; // The unique uncasted input (ConstraintCasts removed)1180Node* direct_input = NULL; // The unique direct input11811182for (uint i = 1, cnt = req(); i < cnt; ++i) {1183Node* rc = r->in(i);1184if (rc == NULL || phase->type(rc) == Type::TOP)1185continue; // ignore unreachable control path1186Node* n = in(i);1187if (n == NULL)1188continue;1189Node* un = n->uncast();1190if (un == NULL || un == this || phase->type(un) == Type::TOP) {1191continue; // ignore if top, or in(i) and "this" are in a data cycle1192}1193// Check for a unique uncasted input1194if (uncasted_input == NULL) {1195uncasted_input = un;1196} else if (uncasted_input != un) {1197uncasted_input = NodeSentinel; // no unique uncasted input1198}1199// Check for a unique direct input1200if (direct_input == NULL) {1201direct_input = n;1202} else if (direct_input != n) {1203direct_input = NodeSentinel; // no unique direct input1204}1205}1206if (direct_input == NULL) {1207return phase->C->top(); // no inputs1208}1209assert(uncasted_input != NULL,"");12101211if (direct_input != NodeSentinel) {1212return direct_input; // one unique direct input1213}1214if (uncasted_input != NodeSentinel &&1215phase->type(uncasted_input)->higher_equal(type())) {1216return uncasted_input; // one unique uncasted input1217}12181219// Nothing.1220return NULL;1221}12221223//------------------------------is_x2logic-------------------------------------1224// Check for simple convert-to-boolean pattern1225// If:(C Bool) Region:(IfF IfT) Phi:(Region 0 1)1226// Convert Phi to an ConvIB.1227static Node *is_x2logic( PhaseGVN *phase, PhiNode *phi, int true_path ) {1228assert(true_path !=0, "only diamond shape graph expected");1229// Convert the true/false index into an expected 0/1 return.1230// Map 2->0 and 1->1.1231int flipped = 2-true_path;12321233// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1234// phi->region->if_proj->ifnode->bool->cmp1235Node *region = phi->in(0);1236Node *iff = region->in(1)->in(0);1237BoolNode *b = (BoolNode*)iff->in(1);1238const CmpNode *cmp = (CmpNode*)b->in(1);12391240Node *zero = phi->in(1);1241Node *one = phi->in(2);1242const Type *tzero = phase->type( zero );1243const Type *tone = phase->type( one );12441245// Check for compare vs 01246const Type *tcmp = phase->type(cmp->in(2));1247if( tcmp != TypeInt::ZERO && tcmp != TypePtr::NULL_PTR ) {1248// Allow cmp-vs-1 if the other input is bounded by 0-11249if( !(tcmp == TypeInt::ONE && phase->type(cmp->in(1)) == TypeInt::BOOL) )1250return NULL;1251flipped = 1-flipped; // Test is vs 1 instead of 0!1252}12531254// Check for setting zero/one opposite expected1255if( tzero == TypeInt::ZERO ) {1256if( tone == TypeInt::ONE ) {1257} else return NULL;1258} else if( tzero == TypeInt::ONE ) {1259if( tone == TypeInt::ZERO ) {1260flipped = 1-flipped;1261} else return NULL;1262} else return NULL;12631264// Check for boolean test backwards1265if( b->_test._test == BoolTest::ne ) {1266} else if( b->_test._test == BoolTest::eq ) {1267flipped = 1-flipped;1268} else return NULL;12691270// Build int->bool conversion1271Node *n = new (phase->C) Conv2BNode( cmp->in(1) );1272if( flipped )1273n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );12741275return n;1276}12771278//------------------------------is_cond_add------------------------------------1279// Check for simple conditional add pattern: "(P < Q) ? X+Y : X;"1280// To be profitable the control flow has to disappear; there can be no other1281// values merging here. We replace the test-and-branch with:1282// "(sgn(P-Q))&Y) + X". Basically, convert "(P < Q)" into 0 or -1 by1283// moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.1284// Then convert Y to 0-or-Y and finally add.1285// This is a key transform for SpecJava _201_compress.1286static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {1287assert(true_path !=0, "only diamond shape graph expected");12881289// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1290// phi->region->if_proj->ifnode->bool->cmp1291RegionNode *region = (RegionNode*)phi->in(0);1292Node *iff = region->in(1)->in(0);1293BoolNode* b = iff->in(1)->as_Bool();1294const CmpNode *cmp = (CmpNode*)b->in(1);12951296// Make sure only merging this one phi here1297if (region->has_unique_phi() != phi) return NULL;12981299// Make sure each arm of the diamond has exactly one output, which we assume1300// is the region. Otherwise, the control flow won't disappear.1301if (region->in(1)->outcnt() != 1) return NULL;1302if (region->in(2)->outcnt() != 1) return NULL;13031304// Check for "(P < Q)" of type signed int1305if (b->_test._test != BoolTest::lt) return NULL;1306if (cmp->Opcode() != Op_CmpI) return NULL;13071308Node *p = cmp->in(1);1309Node *q = cmp->in(2);1310Node *n1 = phi->in( true_path);1311Node *n2 = phi->in(3-true_path);13121313int op = n1->Opcode();1314if( op != Op_AddI // Need zero as additive identity1315/*&&op != Op_SubI &&1316op != Op_AddP &&1317op != Op_XorI &&1318op != Op_OrI*/ )1319return NULL;13201321Node *x = n2;1322Node *y = NULL;1323if( x == n1->in(1) ) {1324y = n1->in(2);1325} else if( x == n1->in(2) ) {1326y = n1->in(1);1327} else return NULL;13281329// Not so profitable if compare and add are constants1330if( q->is_Con() && phase->type(q) != TypeInt::ZERO && y->is_Con() )1331return NULL;13321333Node *cmplt = phase->transform( new (phase->C) CmpLTMaskNode(p,q) );1334Node *j_and = phase->transform( new (phase->C) AndINode(cmplt,y) );1335return new (phase->C) AddINode(j_and,x);1336}13371338//------------------------------is_absolute------------------------------------1339// Check for absolute value.1340static Node* is_absolute( PhaseGVN *phase, PhiNode *phi_root, int true_path) {1341assert(true_path !=0, "only diamond shape graph expected");13421343int cmp_zero_idx = 0; // Index of compare input where to look for zero1344int phi_x_idx = 0; // Index of phi input where to find naked x13451346// ABS ends with the merge of 2 control flow paths.1347// Find the false path from the true path. With only 2 inputs, 3 - x works nicely.1348int false_path = 3 - true_path;13491350// is_diamond_phi() has guaranteed the correctness of the nodes sequence:1351// phi->region->if_proj->ifnode->bool->cmp1352BoolNode *bol = phi_root->in(0)->in(1)->in(0)->in(1)->as_Bool();13531354// Check bool sense1355switch( bol->_test._test ) {1356case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = true_path; break;1357case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = false_path; break;1358case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = true_path; break;1359case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = false_path; break;1360default: return NULL; break;1361}13621363// Test is next1364Node *cmp = bol->in(1);1365const Type *tzero = NULL;1366switch( cmp->Opcode() ) {1367case Op_CmpF: tzero = TypeF::ZERO; break; // Float ABS1368case Op_CmpD: tzero = TypeD::ZERO; break; // Double ABS1369default: return NULL;1370}13711372// Find zero input of compare; the other input is being abs'd1373Node *x = NULL;1374bool flip = false;1375if( phase->type(cmp->in(cmp_zero_idx)) == tzero ) {1376x = cmp->in(3 - cmp_zero_idx);1377} else if( phase->type(cmp->in(3 - cmp_zero_idx)) == tzero ) {1378// The test is inverted, we should invert the result...1379x = cmp->in(cmp_zero_idx);1380flip = true;1381} else {1382return NULL;1383}13841385// Next get the 2 pieces being selected, one is the original value1386// and the other is the negated value.1387if( phi_root->in(phi_x_idx) != x ) return NULL;13881389// Check other phi input for subtract node1390Node *sub = phi_root->in(3 - phi_x_idx);13911392// Allow only Sub(0,X) and fail out for all others; Neg is not OK1393if( tzero == TypeF::ZERO ) {1394if( sub->Opcode() != Op_SubF ||1395sub->in(2) != x ||1396phase->type(sub->in(1)) != tzero ) return NULL;1397x = new (phase->C) AbsFNode(x);1398if (flip) {1399x = new (phase->C) SubFNode(sub->in(1), phase->transform(x));1400}1401} else {1402if( sub->Opcode() != Op_SubD ||1403sub->in(2) != x ||1404phase->type(sub->in(1)) != tzero ) return NULL;1405x = new (phase->C) AbsDNode(x);1406if (flip) {1407x = new (phase->C) SubDNode(sub->in(1), phase->transform(x));1408}1409}14101411return x;1412}14131414//------------------------------split_once-------------------------------------1415// Helper for split_flow_path1416static void split_once(PhaseIterGVN *igvn, Node *phi, Node *val, Node *n, Node *newn) {1417igvn->hash_delete(n); // Remove from hash before hacking edges14181419uint j = 1;1420for (uint i = phi->req()-1; i > 0; i--) {1421if (phi->in(i) == val) { // Found a path with val?1422// Add to NEW Region/Phi, no DU info1423newn->set_req( j++, n->in(i) );1424// Remove from OLD Region/Phi1425n->del_req(i);1426}1427}14281429// Register the new node but do not transform it. Cannot transform until the1430// entire Region/Phi conglomerate has been hacked as a single huge transform.1431igvn->register_new_node_with_optimizer( newn );14321433// Now I can point to the new node.1434n->add_req(newn);1435igvn->_worklist.push(n);1436}14371438//------------------------------split_flow_path--------------------------------1439// Check for merging identical values and split flow paths1440static Node* split_flow_path(PhaseGVN *phase, PhiNode *phi) {1441BasicType bt = phi->type()->basic_type();1442if( bt == T_ILLEGAL || type2size[bt] <= 0 )1443return NULL; // Bail out on funny non-value stuff1444if( phi->req() <= 3 ) // Need at least 2 matched inputs and a1445return NULL; // third unequal input to be worth doing14461447// Scan for a constant1448uint i;1449for( i = 1; i < phi->req()-1; i++ ) {1450Node *n = phi->in(i);1451if( !n ) return NULL;1452if( phase->type(n) == Type::TOP ) return NULL;1453if( n->Opcode() == Op_ConP || n->Opcode() == Op_ConN || n->Opcode() == Op_ConNKlass )1454break;1455}1456if( i >= phi->req() ) // Only split for constants1457return NULL;14581459Node *val = phi->in(i); // Constant to split for1460uint hit = 0; // Number of times it occurs1461Node *r = phi->region();14621463for( ; i < phi->req(); i++ ){ // Count occurrences of constant1464Node *n = phi->in(i);1465if( !n ) return NULL;1466if( phase->type(n) == Type::TOP ) return NULL;1467if( phi->in(i) == val ) {1468hit++;1469if (PhaseIdealLoop::find_predicate(r->in(i)) != NULL) {1470return NULL; // don't split loop entry path1471}1472}1473}14741475if( hit <= 1 || // Make sure we find 2 or more1476hit == phi->req()-1 ) // and not ALL the same value1477return NULL;14781479// Now start splitting out the flow paths that merge the same value.1480// Split first the RegionNode.1481PhaseIterGVN *igvn = phase->is_IterGVN();1482RegionNode *newr = new (phase->C) RegionNode(hit+1);1483split_once(igvn, phi, val, r, newr);14841485// Now split all other Phis than this one1486for (DUIterator_Fast kmax, k = r->fast_outs(kmax); k < kmax; k++) {1487Node* phi2 = r->fast_out(k);1488if( phi2->is_Phi() && phi2->as_Phi() != phi ) {1489PhiNode *newphi = PhiNode::make_blank(newr, phi2);1490split_once(igvn, phi, val, phi2, newphi);1491}1492}14931494// Clean up this guy1495igvn->hash_delete(phi);1496for( i = phi->req()-1; i > 0; i-- ) {1497if( phi->in(i) == val ) {1498phi->del_req(i);1499}1500}1501phi->add_req(val);15021503return phi;1504}15051506//=============================================================================1507//------------------------------simple_data_loop_check-------------------------1508// Try to determining if the phi node in a simple safe/unsafe data loop.1509// Returns:1510// enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };1511// Safe - safe case when the phi and it's inputs reference only safe data1512// nodes;1513// Unsafe - the phi and it's inputs reference unsafe data nodes but there1514// is no reference back to the phi - need a graph walk1515// to determine if it is in a loop;1516// UnsafeLoop - unsafe case when the phi references itself directly or through1517// unsafe data node.1518// Note: a safe data node is a node which could/never reference itself during1519// GVN transformations. For now it is Con, Proj, Phi, CastPP, CheckCastPP.1520// I mark Phi nodes as safe node not only because they can reference itself1521// but also to prevent mistaking the fallthrough case inside an outer loop1522// as dead loop when the phi references itselfs through an other phi.1523PhiNode::LoopSafety PhiNode::simple_data_loop_check(Node *in) const {1524// It is unsafe loop if the phi node references itself directly.1525if (in == (Node*)this)1526return UnsafeLoop; // Unsafe loop1527// Unsafe loop if the phi node references itself through an unsafe data node.1528// Exclude cases with null inputs or data nodes which could reference1529// itself (safe for dead loops).1530if (in != NULL && !in->is_dead_loop_safe()) {1531// Check inputs of phi's inputs also.1532// It is much less expensive then full graph walk.1533uint cnt = in->req();1534uint i = (in->is_Proj() && !in->is_CFG()) ? 0 : 1;1535for (; i < cnt; ++i) {1536Node* m = in->in(i);1537if (m == (Node*)this)1538return UnsafeLoop; // Unsafe loop1539if (m != NULL && !m->is_dead_loop_safe()) {1540// Check the most common case (about 30% of all cases):1541// phi->Load/Store->AddP->(ConP ConP Con)/(Parm Parm Con).1542Node *m1 = (m->is_AddP() && m->req() > 3) ? m->in(1) : NULL;1543if (m1 == (Node*)this)1544return UnsafeLoop; // Unsafe loop1545if (m1 != NULL && m1 == m->in(2) &&1546m1->is_dead_loop_safe() && m->in(3)->is_Con()) {1547continue; // Safe case1548}1549// The phi references an unsafe node - need full analysis.1550return Unsafe;1551}1552}1553}1554return Safe; // Safe case - we can optimize the phi node.1555}15561557//------------------------------is_unsafe_data_reference-----------------------1558// If phi can be reached through the data input - it is data loop.1559bool PhiNode::is_unsafe_data_reference(Node *in) const {1560assert(req() > 1, "");1561// First, check simple cases when phi references itself directly or1562// through an other node.1563LoopSafety safety = simple_data_loop_check(in);1564if (safety == UnsafeLoop)1565return true; // phi references itself - unsafe loop1566else if (safety == Safe)1567return false; // Safe case - phi could be replaced with the unique input.15681569// Unsafe case when we should go through data graph to determine1570// if the phi references itself.15711572ResourceMark rm;15731574Arena *a = Thread::current()->resource_area();1575Node_List nstack(a);1576VectorSet visited(a);15771578nstack.push(in); // Start with unique input.1579visited.set(in->_idx);1580while (nstack.size() != 0) {1581Node* n = nstack.pop();1582uint cnt = n->req();1583uint i = (n->is_Proj() && !n->is_CFG()) ? 0 : 1;1584for (; i < cnt; i++) {1585Node* m = n->in(i);1586if (m == (Node*)this) {1587return true; // Data loop1588}1589if (m != NULL && !m->is_dead_loop_safe()) { // Only look for unsafe cases.1590if (!visited.test_set(m->_idx))1591nstack.push(m);1592}1593}1594}1595return false; // The phi is not reachable from its inputs1596}159715981599//------------------------------Ideal------------------------------------------1600// Return a node which is more "ideal" than the current node. Must preserve1601// the CFG, but we can still strip out dead paths.1602Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {1603// The next should never happen after 6297035 fix.1604if( is_copy() ) // Already degraded to a Copy ?1605return NULL; // No change16061607Node *r = in(0); // RegionNode1608assert(r->in(0) == NULL || !r->in(0)->is_Root(), "not a specially hidden merge");16091610// Note: During parsing, phis are often transformed before their regions.1611// This means we have to use type_or_null to defend against untyped regions.1612if( phase->type_or_null(r) == Type::TOP ) // Dead code?1613return NULL; // No change16141615Node *top = phase->C->top();1616bool new_phi = (outcnt() == 0); // transforming new Phi1617// No change for igvn if new phi is not hooked1618if (new_phi && can_reshape)1619return NULL;16201621// The are 2 situations when only one valid phi's input is left1622// (in addition to Region input).1623// One: region is not loop - replace phi with this input.1624// Two: region is loop - replace phi with top since this data path is dead1625// and we need to break the dead data loop.1626Node* progress = NULL; // Record if any progress made1627for( uint j = 1; j < req(); ++j ){ // For all paths in1628// Check unreachable control paths1629Node* rc = r->in(j);1630Node* n = in(j); // Get the input1631if (rc == NULL || phase->type(rc) == Type::TOP) {1632if (n != top) { // Not already top?1633PhaseIterGVN *igvn = phase->is_IterGVN();1634if (can_reshape && igvn != NULL) {1635igvn->_worklist.push(r);1636}1637// Nuke it down1638if (can_reshape) {1639set_req_X(j, top, igvn);1640} else {1641set_req(j, top);1642}1643progress = this; // Record progress1644}1645}1646}16471648if (can_reshape && outcnt() == 0) {1649// set_req() above may kill outputs if Phi is referenced1650// only by itself on the dead (top) control path.1651return top;1652}16531654Node* uin = unique_input(phase);1655if (uin == top) { // Simplest case: no alive inputs.1656if (can_reshape) // IGVN transformation1657return top;1658else1659return NULL; // Identity will return TOP1660} else if (uin != NULL) {1661// Only one not-NULL unique input path is left.1662// Determine if this input is backedge of a loop.1663// (Skip new phis which have no uses and dead regions).1664if (outcnt() > 0 && r->in(0) != NULL) {1665// First, take the short cut when we know it is a loop and1666// the EntryControl data path is dead.1667// Loop node may have only one input because entry path1668// is removed in PhaseIdealLoop::Dominators().1669assert(!r->is_Loop() || r->req() <= 3, "Loop node should have 3 or less inputs");1670bool is_loop = (r->is_Loop() && r->req() == 3);1671// Then, check if there is a data loop when phi references itself directly1672// or through other data nodes.1673if (is_loop && !uin->eqv_uncast(in(LoopNode::EntryControl)) ||1674!is_loop && is_unsafe_data_reference(uin)) {1675// Break this data loop to avoid creation of a dead loop.1676if (can_reshape) {1677return top;1678} else {1679// We can't return top if we are in Parse phase - cut inputs only1680// let Identity to handle the case.1681replace_edge(uin, top);1682return NULL;1683}1684}1685}16861687// One unique input.1688debug_only(Node* ident = Identity(phase));1689// The unique input must eventually be detected by the Identity call.1690#ifdef ASSERT1691if (ident != uin && !ident->is_top()) {1692// print this output before failing assert1693r->dump(3);1694this->dump(3);1695ident->dump();1696uin->dump();1697}1698#endif1699assert(ident == uin || ident->is_top(), "Identity must clean this up");1700return NULL;1701}170217031704Node* opt = NULL;1705int true_path = is_diamond_phi();1706if( true_path != 0 ) {1707// Check for CMove'ing identity. If it would be unsafe,1708// handle it here. In the safe case, let Identity handle it.1709Node* unsafe_id = is_cmove_id(phase, true_path);1710if( unsafe_id != NULL && is_unsafe_data_reference(unsafe_id) )1711opt = unsafe_id;17121713// Check for simple convert-to-boolean pattern1714if( opt == NULL )1715opt = is_x2logic(phase, this, true_path);17161717// Check for absolute value1718if( opt == NULL )1719opt = is_absolute(phase, this, true_path);17201721// Check for conditional add1722if( opt == NULL && can_reshape )1723opt = is_cond_add(phase, this, true_path);17241725// These 4 optimizations could subsume the phi:1726// have to check for a dead data loop creation.1727if( opt != NULL ) {1728if( opt == unsafe_id || is_unsafe_data_reference(opt) ) {1729// Found dead loop.1730if( can_reshape )1731return top;1732// We can't return top if we are in Parse phase - cut inputs only1733// to stop further optimizations for this phi. Identity will return TOP.1734assert(req() == 3, "only diamond merge phi here");1735set_req(1, top);1736set_req(2, top);1737return NULL;1738} else {1739return opt;1740}1741}1742}17431744// Check for merging identical values and split flow paths1745if (can_reshape) {1746opt = split_flow_path(phase, this);1747// This optimization only modifies phi - don't need to check for dead loop.1748assert(opt == NULL || phase->eqv(opt, this), "do not elide phi");1749if (opt != NULL) return opt;1750}17511752if (in(1) != NULL && in(1)->Opcode() == Op_AddP && can_reshape) {1753// Try to undo Phi of AddP:1754// (Phi (AddP base base y) (AddP base2 base2 y))1755// becomes:1756// newbase := (Phi base base2)1757// (AddP newbase newbase y)1758//1759// This occurs as a result of unsuccessful split_thru_phi and1760// interferes with taking advantage of addressing modes. See the1761// clone_shift_expressions code in matcher.cpp1762Node* addp = in(1);1763const Type* type = addp->in(AddPNode::Base)->bottom_type();1764Node* y = addp->in(AddPNode::Offset);1765if (y != NULL && addp->in(AddPNode::Base) == addp->in(AddPNode::Address)) {1766// make sure that all the inputs are similar to the first one,1767// i.e. AddP with base == address and same offset as first AddP1768bool doit = true;1769for (uint i = 2; i < req(); i++) {1770if (in(i) == NULL ||1771in(i)->Opcode() != Op_AddP ||1772in(i)->in(AddPNode::Base) != in(i)->in(AddPNode::Address) ||1773in(i)->in(AddPNode::Offset) != y) {1774doit = false;1775break;1776}1777// Accumulate type for resulting Phi1778type = type->meet_speculative(in(i)->in(AddPNode::Base)->bottom_type());1779}1780Node* base = NULL;1781if (doit) {1782// Check for neighboring AddP nodes in a tree.1783// If they have a base, use that it.1784for (DUIterator_Fast kmax, k = this->fast_outs(kmax); k < kmax; k++) {1785Node* u = this->fast_out(k);1786if (u->is_AddP()) {1787Node* base2 = u->in(AddPNode::Base);1788if (base2 != NULL && !base2->is_top()) {1789if (base == NULL)1790base = base2;1791else if (base != base2)1792{ doit = false; break; }1793}1794}1795}1796}1797if (doit) {1798if (base == NULL) {1799base = new (phase->C) PhiNode(in(0), type, NULL);1800for (uint i = 1; i < req(); i++) {1801base->init_req(i, in(i)->in(AddPNode::Base));1802}1803phase->is_IterGVN()->register_new_node_with_optimizer(base);1804}1805return new (phase->C) AddPNode(base, base, y);1806}1807}1808}18091810// Split phis through memory merges, so that the memory merges will go away.1811// Piggy-back this transformation on the search for a unique input....1812// It will be as if the merged memory is the unique value of the phi.1813// (Do not attempt this optimization unless parsing is complete.1814// It would make the parser's memory-merge logic sick.)1815// (MergeMemNode is not dead_loop_safe - need to check for dead loop.)1816if (progress == NULL && can_reshape && type() == Type::MEMORY) {1817// see if this phi should be sliced1818uint merge_width = 0;1819bool saw_self = false;1820for( uint i=1; i<req(); ++i ) {// For all paths in1821Node *ii = in(i);1822if (ii->is_MergeMem()) {1823MergeMemNode* n = ii->as_MergeMem();1824merge_width = MAX2(merge_width, n->req());1825saw_self = saw_self || phase->eqv(n->base_memory(), this);1826}1827}18281829// This restriction is temporarily necessary to ensure termination:1830if (!saw_self && adr_type() == TypePtr::BOTTOM) merge_width = 0;18311832if (merge_width > Compile::AliasIdxRaw) {1833// found at least one non-empty MergeMem1834const TypePtr* at = adr_type();1835if (at != TypePtr::BOTTOM) {1836// Patch the existing phi to select an input from the merge:1837// Phi:AT1(...MergeMem(m0, m1, m2)...) into1838// Phi:AT1(...m1...)1839int alias_idx = phase->C->get_alias_index(at);1840for (uint i=1; i<req(); ++i) {1841Node *ii = in(i);1842if (ii->is_MergeMem()) {1843MergeMemNode* n = ii->as_MergeMem();1844// compress paths and change unreachable cycles to TOP1845// If not, we can update the input infinitely along a MergeMem cycle1846// Equivalent code is in MemNode::Ideal_common1847Node *m = phase->transform(n);1848if (outcnt() == 0) { // Above transform() may kill us!1849return top;1850}1851// If transformed to a MergeMem, get the desired slice1852// Otherwise the returned node represents memory for every slice1853Node *new_mem = (m->is_MergeMem()) ?1854m->as_MergeMem()->memory_at(alias_idx) : m;1855// Update input if it is progress over what we have now1856if (new_mem != ii) {1857set_req(i, new_mem);1858progress = this;1859}1860}1861}1862} else {1863// We know that at least one MergeMem->base_memory() == this1864// (saw_self == true). If all other inputs also references this phi1865// (directly or through data nodes) - it is dead loop.1866bool saw_safe_input = false;1867for (uint j = 1; j < req(); ++j) {1868Node *n = in(j);1869if (n->is_MergeMem() && n->as_MergeMem()->base_memory() == this)1870continue; // skip known cases1871if (!is_unsafe_data_reference(n)) {1872saw_safe_input = true; // found safe input1873break;1874}1875}1876if (!saw_safe_input)1877return top; // all inputs reference back to this phi - dead loop18781879// Phi(...MergeMem(m0, m1:AT1, m2:AT2)...) into1880// MergeMem(Phi(...m0...), Phi:AT1(...m1...), Phi:AT2(...m2...))1881PhaseIterGVN *igvn = phase->is_IterGVN();1882Node* hook = new (phase->C) Node(1);1883PhiNode* new_base = (PhiNode*) clone();1884// Must eagerly register phis, since they participate in loops.1885if (igvn) {1886igvn->register_new_node_with_optimizer(new_base);1887hook->add_req(new_base);1888}1889MergeMemNode* result = MergeMemNode::make(phase->C, new_base);1890for (uint i = 1; i < req(); ++i) {1891Node *ii = in(i);1892if (ii->is_MergeMem()) {1893MergeMemNode* n = ii->as_MergeMem();1894for (MergeMemStream mms(result, n); mms.next_non_empty2(); ) {1895// If we have not seen this slice yet, make a phi for it.1896bool made_new_phi = false;1897if (mms.is_empty()) {1898Node* new_phi = new_base->slice_memory(mms.adr_type(phase->C));1899made_new_phi = true;1900if (igvn) {1901igvn->register_new_node_with_optimizer(new_phi);1902hook->add_req(new_phi);1903}1904mms.set_memory(new_phi);1905}1906Node* phi = mms.memory();1907assert(made_new_phi || phi->in(i) == n, "replace the i-th merge by a slice");1908phi->set_req(i, mms.memory2());1909}1910}1911}1912// Distribute all self-loops.1913{ // (Extra braces to hide mms.)1914for (MergeMemStream mms(result); mms.next_non_empty(); ) {1915Node* phi = mms.memory();1916for (uint i = 1; i < req(); ++i) {1917if (phi->in(i) == this) phi->set_req(i, phi);1918}1919}1920}1921// now transform the new nodes, and return the mergemem1922for (MergeMemStream mms(result); mms.next_non_empty(); ) {1923Node* phi = mms.memory();1924mms.set_memory(phase->transform(phi));1925}1926if (igvn) { // Unhook.1927igvn->hash_delete(hook);1928for (uint i = 1; i < hook->req(); i++) {1929hook->set_req(i, NULL);1930}1931}1932// Replace self with the result.1933return result;1934}1935}1936//1937// Other optimizations on the memory chain1938//1939const TypePtr* at = adr_type();1940for( uint i=1; i<req(); ++i ) {// For all paths in1941Node *ii = in(i);1942Node *new_in = MemNode::optimize_memory_chain(ii, at, NULL, phase);1943if (ii != new_in ) {1944set_req(i, new_in);1945progress = this;1946}1947}1948}19491950#ifdef _LP641951// Push DecodeN/DecodeNKlass down through phi.1952// The rest of phi graph will transform by split EncodeP node though phis up.1953if ((UseCompressedOops || UseCompressedClassPointers) && can_reshape && progress == NULL) {1954bool may_push = true;1955bool has_decodeN = false;1956bool is_decodeN = false;1957for (uint i=1; i<req(); ++i) {// For all paths in1958Node *ii = in(i);1959if (ii->is_DecodeNarrowPtr() && ii->bottom_type() == bottom_type()) {1960// Do optimization if a non dead path exist.1961if (ii->in(1)->bottom_type() != Type::TOP) {1962has_decodeN = true;1963is_decodeN = ii->is_DecodeN();1964}1965} else if (!ii->is_Phi()) {1966may_push = false;1967}1968}19691970if (has_decodeN && may_push) {1971PhaseIterGVN *igvn = phase->is_IterGVN();1972// Make narrow type for new phi.1973const Type* narrow_t;1974if (is_decodeN) {1975narrow_t = TypeNarrowOop::make(this->bottom_type()->is_ptr());1976} else {1977narrow_t = TypeNarrowKlass::make(this->bottom_type()->is_ptr());1978}1979PhiNode* new_phi = new (phase->C) PhiNode(r, narrow_t);1980uint orig_cnt = req();1981for (uint i=1; i<req(); ++i) {// For all paths in1982Node *ii = in(i);1983Node* new_ii = NULL;1984if (ii->is_DecodeNarrowPtr()) {1985assert(ii->bottom_type() == bottom_type(), "sanity");1986new_ii = ii->in(1);1987} else {1988assert(ii->is_Phi(), "sanity");1989if (ii->as_Phi() == this) {1990new_ii = new_phi;1991} else {1992if (is_decodeN) {1993new_ii = new (phase->C) EncodePNode(ii, narrow_t);1994} else {1995new_ii = new (phase->C) EncodePKlassNode(ii, narrow_t);1996}1997igvn->register_new_node_with_optimizer(new_ii);1998}1999}2000new_phi->set_req(i, new_ii);2001}2002igvn->register_new_node_with_optimizer(new_phi, this);2003if (is_decodeN) {2004progress = new (phase->C) DecodeNNode(new_phi, bottom_type());2005} else {2006progress = new (phase->C) DecodeNKlassNode(new_phi, bottom_type());2007}2008}2009}2010#endif20112012return progress; // Return any progress2013}20142015//------------------------------is_tripcount-----------------------------------2016bool PhiNode::is_tripcount() const {2017return (in(0) != NULL && in(0)->is_CountedLoop() &&2018in(0)->as_CountedLoop()->phi() == this);2019}20202021//------------------------------out_RegMask------------------------------------2022const RegMask &PhiNode::in_RegMask(uint i) const {2023return i ? out_RegMask() : RegMask::Empty;2024}20252026const RegMask &PhiNode::out_RegMask() const {2027uint ideal_reg = _type->ideal_reg();2028assert( ideal_reg != Node::NotAMachineReg, "invalid type at Phi" );2029if( ideal_reg == 0 ) return RegMask::Empty;2030assert(ideal_reg != Op_RegFlags, "flags register is not spillable");2031return *(Compile::current()->matcher()->idealreg2spillmask[ideal_reg]);2032}20332034#ifndef PRODUCT2035void PhiNode::dump_spec(outputStream *st) const {2036TypeNode::dump_spec(st);2037if (is_tripcount()) {2038st->print(" #tripcount");2039}2040}2041#endif204220432044//=============================================================================2045const Type *GotoNode::Value( PhaseTransform *phase ) const {2046// If the input is reachable, then we are executed.2047// If the input is not reachable, then we are not executed.2048return phase->type(in(0));2049}20502051Node *GotoNode::Identity( PhaseTransform *phase ) {2052return in(0); // Simple copy of incoming control2053}20542055const RegMask &GotoNode::out_RegMask() const {2056return RegMask::Empty;2057}20582059//=============================================================================2060const RegMask &JumpNode::out_RegMask() const {2061return RegMask::Empty;2062}20632064//=============================================================================2065const RegMask &JProjNode::out_RegMask() const {2066return RegMask::Empty;2067}20682069//=============================================================================2070const RegMask &CProjNode::out_RegMask() const {2071return RegMask::Empty;2072}2073207420752076//=============================================================================20772078uint PCTableNode::hash() const { return Node::hash() + _size; }2079uint PCTableNode::cmp( const Node &n ) const2080{ return _size == ((PCTableNode&)n)._size; }20812082const Type *PCTableNode::bottom_type() const {2083const Type** f = TypeTuple::fields(_size);2084for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;2085return TypeTuple::make(_size, f);2086}20872088//------------------------------Value------------------------------------------2089// Compute the type of the PCTableNode. If reachable it is a tuple of2090// Control, otherwise the table targets are not reachable2091const Type *PCTableNode::Value( PhaseTransform *phase ) const {2092if( phase->type(in(0)) == Type::CONTROL )2093return bottom_type();2094return Type::TOP; // All paths dead? Then so are we2095}20962097//------------------------------Ideal------------------------------------------2098// Return a node which is more "ideal" than the current node. Strip out2099// control copies2100Node *PCTableNode::Ideal(PhaseGVN *phase, bool can_reshape) {2101return remove_dead_region(phase, can_reshape) ? this : NULL;2102}21032104//=============================================================================2105uint JumpProjNode::hash() const {2106return Node::hash() + _dest_bci;2107}21082109uint JumpProjNode::cmp( const Node &n ) const {2110return ProjNode::cmp(n) &&2111_dest_bci == ((JumpProjNode&)n)._dest_bci;2112}21132114#ifndef PRODUCT2115void JumpProjNode::dump_spec(outputStream *st) const {2116ProjNode::dump_spec(st);2117st->print("@bci %d ",_dest_bci);2118}2119#endif21202121//=============================================================================2122//------------------------------Value------------------------------------------2123// Check for being unreachable, or for coming from a Rethrow. Rethrow's cannot2124// have the default "fall_through_index" path.2125const Type *CatchNode::Value( PhaseTransform *phase ) const {2126// Unreachable? Then so are all paths from here.2127if( phase->type(in(0)) == Type::TOP ) return Type::TOP;2128// First assume all paths are reachable2129const Type** f = TypeTuple::fields(_size);2130for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;2131// Identify cases that will always throw an exception2132// () rethrow call2133// () virtual or interface call with NULL receiver2134// () call is a check cast with incompatible arguments2135if( in(1)->is_Proj() ) {2136Node *i10 = in(1)->in(0);2137if( i10->is_Call() ) {2138CallNode *call = i10->as_Call();2139// Rethrows always throw exceptions, never return2140if (call->entry_point() == OptoRuntime::rethrow_stub()) {2141f[CatchProjNode::fall_through_index] = Type::TOP;2142} else if( call->req() > TypeFunc::Parms ) {2143const Type *arg0 = phase->type( call->in(TypeFunc::Parms) );2144// Check for null receiver to virtual or interface calls2145if( call->is_CallDynamicJava() &&2146arg0->higher_equal(TypePtr::NULL_PTR) ) {2147f[CatchProjNode::fall_through_index] = Type::TOP;2148}2149} // End of if not a runtime stub2150} // End of if have call above me2151} // End of slot 1 is not a projection2152return TypeTuple::make(_size, f);2153}21542155//=============================================================================2156uint CatchProjNode::hash() const {2157return Node::hash() + _handler_bci;2158}215921602161uint CatchProjNode::cmp( const Node &n ) const {2162return ProjNode::cmp(n) &&2163_handler_bci == ((CatchProjNode&)n)._handler_bci;2164}216521662167//------------------------------Identity---------------------------------------2168// If only 1 target is possible, choose it if it is the main control2169Node *CatchProjNode::Identity( PhaseTransform *phase ) {2170// If my value is control and no other value is, then treat as ID2171const TypeTuple *t = phase->type(in(0))->is_tuple();2172if (t->field_at(_con) != Type::CONTROL) return this;2173// If we remove the last CatchProj and elide the Catch/CatchProj, then we2174// also remove any exception table entry. Thus we must know the call2175// feeding the Catch will not really throw an exception. This is ok for2176// the main fall-thru control (happens when we know a call can never throw2177// an exception) or for "rethrow", because a further optimization will2178// yank the rethrow (happens when we inline a function that can throw an2179// exception and the caller has no handler). Not legal, e.g., for passing2180// a NULL receiver to a v-call, or passing bad types to a slow-check-cast.2181// These cases MUST throw an exception via the runtime system, so the VM2182// will be looking for a table entry.2183Node *proj = in(0)->in(1); // Expect a proj feeding CatchNode2184CallNode *call;2185if (_con != TypeFunc::Control && // Bail out if not the main control.2186!(proj->is_Proj() && // AND NOT a rethrow2187proj->in(0)->is_Call() &&2188(call = proj->in(0)->as_Call()) &&2189call->entry_point() == OptoRuntime::rethrow_stub()))2190return this;21912192// Search for any other path being control2193for (uint i = 0; i < t->cnt(); i++) {2194if (i != _con && t->field_at(i) == Type::CONTROL)2195return this;2196}2197// Only my path is possible; I am identity on control to the jump2198return in(0)->in(0);2199}220022012202#ifndef PRODUCT2203void CatchProjNode::dump_spec(outputStream *st) const {2204ProjNode::dump_spec(st);2205st->print("@bci %d ",_handler_bci);2206}2207#endif22082209//=============================================================================2210//------------------------------Identity---------------------------------------2211// Check for CreateEx being Identity.2212Node *CreateExNode::Identity( PhaseTransform *phase ) {2213if( phase->type(in(1)) == Type::TOP ) return in(1);2214if( phase->type(in(0)) == Type::TOP ) return in(0);2215// We only come from CatchProj, unless the CatchProj goes away.2216// If the CatchProj is optimized away, then we just carry the2217// exception oop through.2218CallNode *call = in(1)->in(0)->as_Call();22192220return ( in(0)->is_CatchProj() && in(0)->in(0)->in(1) == in(1) )2221? this2222: call->in(TypeFunc::Parms);2223}22242225//=============================================================================2226//------------------------------Value------------------------------------------2227// Check for being unreachable.2228const Type *NeverBranchNode::Value( PhaseTransform *phase ) const {2229if (!in(0) || in(0)->is_top()) return Type::TOP;2230return bottom_type();2231}22322233//------------------------------Ideal------------------------------------------2234// Check for no longer being part of a loop2235Node *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) {2236if (can_reshape && !in(0)->is_Loop()) {2237// Dead code elimination can sometimes delete this projection so2238// if it's not there, there's nothing to do.2239Node* fallthru = proj_out(0);2240if (fallthru != NULL) {2241phase->is_IterGVN()->replace_node(fallthru, in(0));2242}2243return phase->C->top();2244}2245return NULL;2246}22472248#ifndef PRODUCT2249void NeverBranchNode::format( PhaseRegAlloc *ra_, outputStream *st) const {2250st->print("%s", Name());2251}2252#endif225322542255