< prev index next >

src/share/vm/opto/node.cpp

Print this page




  26 #include "libadt/vectset.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "opto/castnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/loopnode.hpp"
  33 #include "opto/machnode.hpp"
  34 #include "opto/matcher.hpp"
  35 #include "opto/node.hpp"
  36 #include "opto/opcodes.hpp"
  37 #include "opto/regmask.hpp"
  38 #include "opto/type.hpp"
  39 #include "utilities/copy.hpp"
  40 
  41 class RegMask;
  42 // #include "phase.hpp"
  43 class PhaseTransform;
  44 class PhaseGVN;
  45 
  46 // Arena we are currently building Nodes in
  47 const uint Node::NotAMachineReg = 0xffff0000;
  48 
  49 #ifndef PRODUCT
  50 extern int nodes_created;
  51 #endif
  52 #ifdef __clang__
  53 #pragma clang diagnostic push
  54 #pragma GCC diagnostic ignored "-Wuninitialized"
  55 #endif
  56 
  57 #ifdef ASSERT
  58 
  59 //-------------------------- construct_node------------------------------------
  60 // Set a breakpoint here to identify where a particular node index is built.
  61 void Node::verify_construction() {
  62   _debug_orig = NULL;
  63   int old_debug_idx = Compile::debug_idx();
  64   int new_debug_idx = old_debug_idx+1;
  65   if (new_debug_idx > 0) {
  66     // Arrange that the lowest five decimal digits of _debug_idx
  67     // will repeat those of _idx. In case this is somehow pathological,
  68     // we continue to assign negative numbers (!) consecutively.


 682     _out = (Node **)arena->Amalloc(4*sizeof(Node*));
 683     return;
 684   }
 685   while( new_max <= len ) new_max <<= 1; // Find next power-of-2
 686   // Trimming to limit allows a uint8 to handle up to 255 edges.
 687   // Previously I was using only powers-of-2 which peaked at 128 edges.
 688   //if( new_max >= limit ) new_max = limit-1;
 689   assert(_out != NULL && _out != NO_OUT_ARRAY, "out must have sensible value");
 690   _out = (Node**)arena->Arealloc(_out,_outmax*sizeof(Node*),new_max*sizeof(Node*));
 691   //Copy::zero_to_bytes(&_out[_outmax], (new_max-_outmax)*sizeof(Node*)); // NULL all new space
 692   _outmax = new_max;               // Record new max length
 693   // This assertion makes sure that Node::_max is wide enough to
 694   // represent the numerical value of new_max.
 695   assert(_outmax == new_max && _outmax > len, "int width of _outmax is too small");
 696 }
 697 
 698 #ifdef ASSERT
 699 //------------------------------is_dead----------------------------------------
 700 bool Node::is_dead() const {
 701   // Mach and pinch point nodes may look like dead.
 702   if( is_top() || is_Mach() || (Opcode() == Op_Node && _outcnt > 0) )
 703     return false;
 704   for( uint i = 0; i < _max; i++ )
 705     if( _in[i] != NULL )
 706       return false;
 707   dump();
 708   return true;
 709 }
 710 #endif
 711 
 712 
 713 //------------------------------is_unreachable---------------------------------
 714 bool Node::is_unreachable(PhaseIterGVN &igvn) const {
 715   assert(!is_Mach(), "doesn't work with MachNodes");
 716   return outcnt() == 0 || igvn.type(this) == Type::TOP || in(0)->is_top();
 717 }
 718 
 719 //------------------------------add_req----------------------------------------
 720 // Add a new required input at the end
 721 void Node::add_req( Node *n ) {
 722   assert( is_not_dead(n), "can not use dead node");


 889   // debug_only(destruct();)   // no reuse benefit expected
 890   if (edges_to_n == 0) {
 891     C->record_dead_node(_idx);
 892   }
 893   return edges_to_n;
 894 }
 895 
 896 //-----------------------------uncast---------------------------------------
 897 // %%% Temporary, until we sort out CheckCastPP vs. CastPP.
 898 // Strip away casting.  (It is depth-limited.)
 899 Node* Node::uncast() const {
 900   // Should be inline:
 901   //return is_ConstraintCast() ? uncast_helper(this) : (Node*) this;
 902   if (is_ConstraintCast())
 903     return uncast_helper(this);
 904   else
 905     return (Node*) this;
 906 }
 907 
 908 // Find out of current node that matches opcode.
 909 Node* Node::find_out_with(int opcode) {
 910   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 911     Node* use = fast_out(i);
 912     if (use->Opcode() == opcode) {
 913       return use;
 914     }
 915   }
 916   return NULL;
 917 }
 918 
 919 // Return true if the current node has an out that matches opcode.
 920 bool Node::has_out_with(int opcode) {
 921   return (find_out_with(opcode) != NULL);
 922 }
 923 
 924 // Return true if the current node has an out that matches any of the opcodes.
 925 bool Node::has_out_with(int opcode1, int opcode2, int opcode3, int opcode4) {
 926   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 927       int opcode = fast_out(i)->Opcode();
 928       if (opcode == opcode1 || opcode == opcode2 || opcode == opcode3 || opcode == opcode4) {
 929         return true;
 930       }
 931   }
 932   return false;
 933 }
 934 
 935 
 936 //---------------------------uncast_helper-------------------------------------
 937 Node* Node::uncast_helper(const Node* p) {
 938 #ifdef ASSERT
 939   uint depth_count = 0;
 940   const Node* orig_p = p;
 941 #endif
 942 
 943   while (true) {
 944 #ifdef ASSERT
 945     if (depth_count >= K) {
 946       orig_p->dump(4);
 947       if (p != orig_p)


 982 #ifdef ASSERT
 983   while ((++i)<_max) { assert(_in[i] == NULL, "spec violation: Gap in prec edges (node %d)", _idx); }
 984 #endif
 985 }
 986 
 987 //------------------------------rm_prec----------------------------------------
 988 // Remove a precedence input.  Precedence inputs are unordered, with
 989 // duplicates removed and NULLs packed down at the end.
 990 void Node::rm_prec( uint j ) {
 991   assert(j < _max, "oob: i=%d, _max=%d", j, _max);
 992   assert(j >= _cnt, "not a precedence edge");
 993   if (_in[j] == NULL) return;   // Avoid spec violation: Gap in prec edges.
 994   _in[j]->del_out((Node *)this);
 995   close_prec_gap_at(j);
 996 }
 997 
 998 //------------------------------size_of----------------------------------------
 999 uint Node::size_of() const { return sizeof(*this); }
1000 
1001 //------------------------------ideal_reg--------------------------------------
1002 uint Node::ideal_reg() const { return 0; }
1003 
1004 //------------------------------jvms-------------------------------------------
1005 JVMState* Node::jvms() const { return NULL; }
1006 
1007 #ifdef ASSERT
1008 //------------------------------jvms-------------------------------------------
1009 bool Node::verify_jvms(const JVMState* using_jvms) const {
1010   for (JVMState* jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {
1011     if (jvms == using_jvms)  return true;
1012   }
1013   return false;
1014 }
1015 
1016 //------------------------------init_NodeProperty------------------------------
1017 void Node::init_NodeProperty() {
1018   assert(_max_classes <= max_jushort, "too many NodeProperty classes");
1019   assert(_max_flags <= max_jushort, "too many NodeProperty flags");
1020 }
1021 #endif
1022 


1115 //    return new AddINode(shift, in(1));
1116 //
1117 // When making a Node for a constant use 'phase->makecon' or 'phase->intcon'.
1118 // These forms are faster than 'phase->transform(new ConNode())' and Do
1119 // The Right Thing with def-use info.
1120 //
1121 // You cannot bury the 'this' Node inside of a graph reshape.  If the reshaped
1122 // graph uses the 'this' Node it must be the root.  If you want a Node with
1123 // the same Opcode as the 'this' pointer use 'clone'.
1124 //
1125 Node *Node::Ideal(PhaseGVN *phase, bool can_reshape) {
1126   return NULL;                  // Default to being Ideal already
1127 }
1128 
1129 // Some nodes have specific Ideal subgraph transformations only if they are
1130 // unique users of specific nodes. Such nodes should be put on IGVN worklist
1131 // for the transformations to happen.
1132 bool Node::has_special_unique_user() const {
1133   assert(outcnt() == 1, "match only for unique out");
1134   Node* n = unique_out();
1135   int op  = Opcode();
1136   if (this->is_Store()) {
1137     // Condition for back-to-back stores folding.
1138     return n->Opcode() == op && n->in(MemNode::Memory) == this;
1139   } else if (this->is_Load()) {
1140     // Condition for removing an unused LoadNode from the MemBarAcquire precedence input
1141     return n->Opcode() == Op_MemBarAcquire;
1142   } else if (op == Op_AddL) {
1143     // Condition for convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
1144     return n->Opcode() == Op_ConvL2I && n->in(1) == this;
1145   } else if (op == Op_SubI || op == Op_SubL) {
1146     // Condition for subI(x,subI(y,z)) ==> subI(addI(x,z),y)
1147     return n->Opcode() == op && n->in(2) == this;
1148   } else if (is_If() && (n->is_IfFalse() || n->is_IfTrue())) {
1149     // See IfProjNode::Identity()
1150     return true;
1151   }
1152   return false;
1153 };
1154 
1155 //--------------------------find_exact_control---------------------------------
1156 // Skip Proj and CatchProj nodes chains. Check for Null and Top.
1157 Node* Node::find_exact_control(Node* ctrl) {
1158   if (ctrl == NULL && this->is_Region())
1159     ctrl = this->as_Region()->is_copy();
1160 
1161   if (ctrl != NULL && ctrl->is_CatchProj()) {
1162     if (ctrl->as_CatchProj()->_con == CatchProjNode::fall_through_index)
1163       ctrl = ctrl->in(0);
1164     if (ctrl != NULL && !ctrl->is_top())
1165       ctrl = ctrl->in(0);


1405   // Aggressively kill all unreachable code.
1406   if (can_reshape && n->is_top()) {
1407     kill_dead_code(this, phase->is_IterGVN());
1408     return false; // Node is dead.
1409   }
1410 
1411   if( n->is_Region() && n->as_Region()->is_copy() ) {
1412     Node *m = n->nonnull_req();
1413     set_req(0, m);
1414     return true;
1415   }
1416   return false;
1417 }
1418 
1419 //------------------------------hash-------------------------------------------
1420 // Hash function over Nodes.
1421 uint Node::hash() const {
1422   uint sum = 0;
1423   for( uint i=0; i<_cnt; i++ )  // Add in all inputs
1424     sum = (sum<<1)-(uintptr_t)in(i);        // Ignore embedded NULLs
1425   return (sum>>2) + _cnt + Opcode();
1426 }
1427 
1428 //------------------------------cmp--------------------------------------------
1429 // Compare special parts of simple Nodes
1430 uint Node::cmp( const Node &n ) const {
1431   return 1;                     // Must be same
1432 }
1433 
1434 //------------------------------rematerialize-----------------------------------
1435 // Should we clone rather than spill this instruction?
1436 bool Node::rematerialize() const {
1437   if ( is_Mach() )
1438     return this->as_Mach()->rematerialize();
1439   else
1440     return (_flags & Flag_rematerialize) != 0;
1441 }
1442 
1443 //------------------------------needs_anti_dependence_check---------------------
1444 // Nodes which use memory without consuming it, hence need antidependences.
1445 bool Node::needs_anti_dependence_check() const {


1448   else
1449     return in(1)->bottom_type()->has_memory();
1450 }
1451 
1452 
1453 // Get an integer constant from a ConNode (or CastIINode).
1454 // Return a default value if there is no apparent constant here.
1455 const TypeInt* Node::find_int_type() const {
1456   if (this->is_Type()) {
1457     return this->as_Type()->type()->isa_int();
1458   } else if (this->is_Con()) {
1459     assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode");
1460     return this->bottom_type()->isa_int();
1461   }
1462   return NULL;
1463 }
1464 
1465 // Get a pointer constant from a ConstNode.
1466 // Returns the constant if it is a pointer ConstNode
1467 intptr_t Node::get_ptr() const {
1468   assert( Opcode() == Op_ConP, "" );
1469   return ((ConPNode*)this)->type()->is_ptr()->get_con();
1470 }
1471 
1472 // Get a narrow oop constant from a ConNNode.
1473 intptr_t Node::get_narrowcon() const {
1474   assert( Opcode() == Op_ConN, "" );
1475   return ((ConNNode*)this)->type()->is_narrowoop()->get_con();
1476 }
1477 
1478 // Get a long constant from a ConNode.
1479 // Return a default value if there is no apparent constant here.
1480 const TypeLong* Node::find_long_type() const {
1481   if (this->is_Type()) {
1482     return this->as_Type()->type()->isa_long();
1483   } else if (this->is_Con()) {
1484     assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode");
1485     return this->bottom_type()->isa_long();
1486   }
1487   return NULL;
1488 }
1489 
1490 
1491 /**
1492  * Return a ptr type for nodes which should have it.
1493  */
1494 const TypePtr* Node::get_ptr_type() const {
1495   const TypePtr* tp = this->bottom_type()->make_ptr();
1496 #ifdef ASSERT
1497   if (tp == NULL) {
1498     this->dump(1);
1499     assert((tp != NULL), "unexpected node type");
1500   }
1501 #endif
1502   return tp;
1503 }
1504 
1505 // Get a double constant from a ConstNode.
1506 // Returns the constant if it is a double ConstNode
1507 jdouble Node::getd() const {
1508   assert( Opcode() == Op_ConD, "" );
1509   return ((ConDNode*)this)->type()->is_double_constant()->getd();
1510 }
1511 
1512 // Get a float constant from a ConstNode.
1513 // Returns the constant if it is a float ConstNode
1514 jfloat Node::getf() const {
1515   assert( Opcode() == Op_ConF, "" );
1516   return ((ConFNode*)this)->type()->is_float_constant()->getf();
1517 }
1518 
1519 #ifndef PRODUCT
1520 
1521 //------------------------------find------------------------------------------
1522 // Find a neighbor of this Node with the given _idx
1523 // If idx is negative, find its absolute value, following both _in and _out.
1524 static void find_recur(Compile* C,  Node* &result, Node *n, int idx, bool only_ctrl,
1525                         VectorSet* old_space, VectorSet* new_space ) {
1526   int node_idx = (idx >= 0) ? idx : -idx;
1527   if (NotANode(n))  return;  // Gracefully handle NULL, -1, 0xabababab, etc.
1528   // Contained in new_space or old_space?   Check old_arena first since it's mostly empty.
1529   VectorSet *v = C->old_arena()->contains(n) ? old_space : new_space;
1530   if( v->test(n->_idx) ) return;
1531   if( (int)n->_idx == node_idx
1532       debug_only(|| n->debug_idx() == node_idx) ) {
1533     if (result != NULL)
1534       tty->print("find: " INTPTR_FORMAT " and " INTPTR_FORMAT " both have idx==%d\n",
1535                  (uintptr_t)result, (uintptr_t)n, node_idx);
1536     result = n;
1537   }
1538   v->set(n->_idx);
1539   for( uint i=0; i<n->len(); i++ ) {
1540     if( only_ctrl && !(n->is_Region()) && (n->Opcode() != Op_Root) && (i != TypeFunc::Control) ) continue;
1541     find_recur(C, result, n->in(i), idx, only_ctrl, old_space, new_space );
1542   }
1543   // Search along forward edges also:
1544   if (idx < 0 && !only_ctrl) {
1545     for( uint j=0; j<n->outcnt(); j++ ) {
1546       find_recur(C, result, n->raw_out(j), idx, only_ctrl, old_space, new_space );
1547     }
1548   }
1549 #ifdef ASSERT
1550   // Search along debug_orig edges last, checking for cycles
1551   Node* orig = n->debug_orig();
1552   if (orig != NULL) {
1553     do {
1554       if (NotANode(orig))  break;
1555       find_recur(C, result, orig, idx, only_ctrl, old_space, new_space );
1556       orig = orig->debug_orig();
1557     } while (orig != NULL && orig != n->debug_orig());
1558   }
1559 #endif //ASSERT
1560 }


1573   return result;
1574 }
1575 
1576 //------------------------------find_ctrl--------------------------------------
1577 // Find an ancestor to this node in the control history with given _idx
1578 Node* Node::find_ctrl(int idx) const {
1579   ResourceArea *area = Thread::current()->resource_area();
1580   VectorSet old_space(area), new_space(area);
1581   Node* result = NULL;
1582   find_recur(Compile::current(), result, (Node*) this, idx, true, &old_space, &new_space );
1583   return result;
1584 }
1585 #endif
1586 
1587 
1588 
1589 #ifndef PRODUCT
1590 
1591 // -----------------------------Name-------------------------------------------
1592 extern const char *NodeClassNames[];
1593 const char *Node::Name() const { return NodeClassNames[Opcode()]; }
1594 
1595 static bool is_disconnected(const Node* n) {
1596   for (uint i = 0; i < n->req(); i++) {
1597     if (n->in(i) != NULL)  return false;
1598   }
1599   return true;
1600 }
1601 
1602 #ifdef ASSERT
1603 static void dump_orig(Node* orig, outputStream *st) {
1604   Compile* C = Compile::current();
1605   if (NotANode(orig)) orig = NULL;
1606   if (orig != NULL && !C->node_arena()->contains(orig)) orig = NULL;
1607   if (orig == NULL) return;
1608   st->print(" !orig=");
1609   Node* fast = orig->debug_orig(); // tortoise & hare algorithm to detect loops
1610   if (NotANode(fast)) fast = NULL;
1611   while (orig != NULL) {
1612     bool discon = is_disconnected(orig);  // if discon, print [123] else 123
1613     if (discon) st->print("[");


2256   qsort( _nodes, _max, sizeof( Node* ), func );
2257 }
2258 
2259 //-----------------------------------------------------------------------------
2260 void Node_Array::dump() const {
2261 #ifndef PRODUCT
2262   for( uint i = 0; i < _max; i++ ) {
2263     Node *nn = _nodes[i];
2264     if( nn != NULL ) {
2265       tty->print("%5d--> ",i); nn->dump();
2266     }
2267   }
2268 #endif
2269 }
2270 
2271 //--------------------------is_iteratively_computed------------------------------
2272 // Operation appears to be iteratively computed (such as an induction variable)
2273 // It is possible for this operation to return false for a loop-varying
2274 // value, if it appears (by local graph inspection) to be computed by a simple conditional.
2275 bool Node::is_iteratively_computed() {
2276   if (ideal_reg()) { // does operation have a result register?
2277     for (uint i = 1; i < req(); i++) {
2278       Node* n = in(i);
2279       if (n != NULL && n->is_Phi()) {
2280         for (uint j = 1; j < n->req(); j++) {
2281           if (n->in(j) == this) {
2282             return true;
2283           }
2284         }
2285       }
2286     }
2287   }
2288   return false;
2289 }
2290 
2291 //--------------------------find_similar------------------------------
2292 // Return a node with opcode "opc" and same inputs as "this" if one can
2293 // be found; Otherwise return NULL;
2294 Node* Node::find_similar(int opc) {
2295   if (req() >= 2) {
2296     Node* def = in(1);
2297     if (def && def->outcnt() >= 2) {
2298       for (DUIterator_Fast dmax, i = def->fast_outs(dmax); i < dmax; i++) {
2299         Node* use = def->fast_out(i);
2300         if (use != this &&
2301             use->Opcode() == opc &&
2302             use->req() == req()) {
2303           uint j;
2304           for (j = 0; j < use->req(); j++) {
2305             if (use->in(j) != in(j)) {
2306               break;
2307             }
2308           }
2309           if (j == use->req()) {
2310             return use;
2311           }
2312         }
2313       }
2314     }


2435   if( !Verbose && !WizardMode ) {
2436     // standard dump does this in Verbose and WizardMode
2437     st->print(" #"); _type->dump_on(st);
2438   }
2439 }
2440 
2441 void TypeNode::dump_compact_spec(outputStream *st) const {
2442   st->print("#");
2443   _type->dump_on(st);
2444 }
2445 #endif
2446 uint TypeNode::hash() const {
2447   return Node::hash() + _type->hash();
2448 }
2449 uint TypeNode::cmp( const Node &n ) const
2450 { return !Type::cmp( _type, ((TypeNode&)n)._type ); }
2451 const Type *TypeNode::bottom_type() const { return _type; }
2452 const Type* TypeNode::Value(PhaseGVN* phase) const { return _type; }
2453 
2454 //------------------------------ideal_reg--------------------------------------
2455 uint TypeNode::ideal_reg() const {
2456   return _type->ideal_reg();
2457 }


  26 #include "libadt/vectset.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "opto/castnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/loopnode.hpp"
  33 #include "opto/machnode.hpp"
  34 #include "opto/matcher.hpp"
  35 #include "opto/node.hpp"
  36 #include "opto/opcodes.hpp"
  37 #include "opto/regmask.hpp"
  38 #include "opto/type.hpp"
  39 #include "utilities/copy.hpp"
  40 
  41 class RegMask;
  42 // #include "phase.hpp"
  43 class PhaseTransform;
  44 class PhaseGVN;
  45 



  46 #ifndef PRODUCT
  47 extern int nodes_created;
  48 #endif
  49 #ifdef __clang__
  50 #pragma clang diagnostic push
  51 #pragma GCC diagnostic ignored "-Wuninitialized"
  52 #endif
  53 
  54 #ifdef ASSERT
  55 
  56 //-------------------------- construct_node------------------------------------
  57 // Set a breakpoint here to identify where a particular node index is built.
  58 void Node::verify_construction() {
  59   _debug_orig = NULL;
  60   int old_debug_idx = Compile::debug_idx();
  61   int new_debug_idx = old_debug_idx+1;
  62   if (new_debug_idx > 0) {
  63     // Arrange that the lowest five decimal digits of _debug_idx
  64     // will repeat those of _idx. In case this is somehow pathological,
  65     // we continue to assign negative numbers (!) consecutively.


 679     _out = (Node **)arena->Amalloc(4*sizeof(Node*));
 680     return;
 681   }
 682   while( new_max <= len ) new_max <<= 1; // Find next power-of-2
 683   // Trimming to limit allows a uint8 to handle up to 255 edges.
 684   // Previously I was using only powers-of-2 which peaked at 128 edges.
 685   //if( new_max >= limit ) new_max = limit-1;
 686   assert(_out != NULL && _out != NO_OUT_ARRAY, "out must have sensible value");
 687   _out = (Node**)arena->Arealloc(_out,_outmax*sizeof(Node*),new_max*sizeof(Node*));
 688   //Copy::zero_to_bytes(&_out[_outmax], (new_max-_outmax)*sizeof(Node*)); // NULL all new space
 689   _outmax = new_max;               // Record new max length
 690   // This assertion makes sure that Node::_max is wide enough to
 691   // represent the numerical value of new_max.
 692   assert(_outmax == new_max && _outmax > len, "int width of _outmax is too small");
 693 }
 694 
 695 #ifdef ASSERT
 696 //------------------------------is_dead----------------------------------------
 697 bool Node::is_dead() const {
 698   // Mach and pinch point nodes may look like dead.
 699   if( is_top() || is_Mach() || (Opcode() == Opcodes::Op_Node && _outcnt > 0) )
 700     return false;
 701   for( uint i = 0; i < _max; i++ )
 702     if( _in[i] != NULL )
 703       return false;
 704   dump();
 705   return true;
 706 }
 707 #endif
 708 
 709 
 710 //------------------------------is_unreachable---------------------------------
 711 bool Node::is_unreachable(PhaseIterGVN &igvn) const {
 712   assert(!is_Mach(), "doesn't work with MachNodes");
 713   return outcnt() == 0 || igvn.type(this) == Type::TOP || in(0)->is_top();
 714 }
 715 
 716 //------------------------------add_req----------------------------------------
 717 // Add a new required input at the end
 718 void Node::add_req( Node *n ) {
 719   assert( is_not_dead(n), "can not use dead node");


 886   // debug_only(destruct();)   // no reuse benefit expected
 887   if (edges_to_n == 0) {
 888     C->record_dead_node(_idx);
 889   }
 890   return edges_to_n;
 891 }
 892 
 893 //-----------------------------uncast---------------------------------------
 894 // %%% Temporary, until we sort out CheckCastPP vs. CastPP.
 895 // Strip away casting.  (It is depth-limited.)
 896 Node* Node::uncast() const {
 897   // Should be inline:
 898   //return is_ConstraintCast() ? uncast_helper(this) : (Node*) this;
 899   if (is_ConstraintCast())
 900     return uncast_helper(this);
 901   else
 902     return (Node*) this;
 903 }
 904 
 905 // Find out of current node that matches opcode.
 906 Node* Node::find_out_with(Opcodes opcode) {
 907   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 908     Node* use = fast_out(i);
 909     if (use->Opcode() == opcode) {
 910       return use;
 911     }
 912   }
 913   return NULL;
 914 }
 915 
 916 // Return true if the current node has an out that matches opcode.
 917 bool Node::has_out_with(Opcodes opcode) {
 918   return (find_out_with(opcode) != NULL);
 919 }
 920 
 921 // Return true if the current node has an out that matches any of the opcodes.
 922 bool Node::has_out_with(Opcodes opcode1, Opcodes opcode2, Opcodes opcode3, Opcodes opcode4) {
 923   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 924       Opcodes opcode = fast_out(i)->Opcode();
 925       if (opcode == opcode1 || opcode == opcode2 || opcode == opcode3 || opcode == opcode4) {
 926         return true;
 927       }
 928   }
 929   return false;
 930 }
 931 
 932 
 933 //---------------------------uncast_helper-------------------------------------
 934 Node* Node::uncast_helper(const Node* p) {
 935 #ifdef ASSERT
 936   uint depth_count = 0;
 937   const Node* orig_p = p;
 938 #endif
 939 
 940   while (true) {
 941 #ifdef ASSERT
 942     if (depth_count >= K) {
 943       orig_p->dump(4);
 944       if (p != orig_p)


 979 #ifdef ASSERT
 980   while ((++i)<_max) { assert(_in[i] == NULL, "spec violation: Gap in prec edges (node %d)", _idx); }
 981 #endif
 982 }
 983 
 984 //------------------------------rm_prec----------------------------------------
 985 // Remove a precedence input.  Precedence inputs are unordered, with
 986 // duplicates removed and NULLs packed down at the end.
 987 void Node::rm_prec( uint j ) {
 988   assert(j < _max, "oob: i=%d, _max=%d", j, _max);
 989   assert(j >= _cnt, "not a precedence edge");
 990   if (_in[j] == NULL) return;   // Avoid spec violation: Gap in prec edges.
 991   _in[j]->del_out((Node *)this);
 992   close_prec_gap_at(j);
 993 }
 994 
 995 //------------------------------size_of----------------------------------------
 996 uint Node::size_of() const { return sizeof(*this); }
 997 
 998 //------------------------------ideal_reg--------------------------------------
 999 Opcodes Node::ideal_reg() const { return Opcodes::Op_Node; }
1000 
1001 //------------------------------jvms-------------------------------------------
1002 JVMState* Node::jvms() const { return NULL; }
1003 
1004 #ifdef ASSERT
1005 //------------------------------jvms-------------------------------------------
1006 bool Node::verify_jvms(const JVMState* using_jvms) const {
1007   for (JVMState* jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {
1008     if (jvms == using_jvms)  return true;
1009   }
1010   return false;
1011 }
1012 
1013 //------------------------------init_NodeProperty------------------------------
1014 void Node::init_NodeProperty() {
1015   assert(_max_classes <= max_jushort, "too many NodeProperty classes");
1016   assert(_max_flags <= max_jushort, "too many NodeProperty flags");
1017 }
1018 #endif
1019 


1112 //    return new AddINode(shift, in(1));
1113 //
1114 // When making a Node for a constant use 'phase->makecon' or 'phase->intcon'.
1115 // These forms are faster than 'phase->transform(new ConNode())' and Do
1116 // The Right Thing with def-use info.
1117 //
1118 // You cannot bury the 'this' Node inside of a graph reshape.  If the reshaped
1119 // graph uses the 'this' Node it must be the root.  If you want a Node with
1120 // the same Opcode as the 'this' pointer use 'clone'.
1121 //
1122 Node *Node::Ideal(PhaseGVN *phase, bool can_reshape) {
1123   return NULL;                  // Default to being Ideal already
1124 }
1125 
1126 // Some nodes have specific Ideal subgraph transformations only if they are
1127 // unique users of specific nodes. Such nodes should be put on IGVN worklist
1128 // for the transformations to happen.
1129 bool Node::has_special_unique_user() const {
1130   assert(outcnt() == 1, "match only for unique out");
1131   Node* n = unique_out();
1132   Opcodes op  = Opcode();
1133   if (this->is_Store()) {
1134     // Condition for back-to-back stores folding.
1135     return n->Opcode() == op && n->in(MemNode::Memory) == this;
1136   } else if (this->is_Load()) {
1137     // Condition for removing an unused LoadNode from the MemBarAcquire precedence input
1138     return n->Opcode() == Opcodes::Op_MemBarAcquire;
1139   } else if (op == Opcodes::Op_AddL) {
1140     // Condition for convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
1141     return n->Opcode() == Opcodes::Op_ConvL2I && n->in(1) == this;
1142   } else if (op == Opcodes::Op_SubI || op == Opcodes::Op_SubL) {
1143     // Condition for subI(x,subI(y,z)) ==> subI(addI(x,z),y)
1144     return n->Opcode() == op && n->in(2) == this;
1145   } else if (is_If() && (n->is_IfFalse() || n->is_IfTrue())) {
1146     // See IfProjNode::Identity()
1147     return true;
1148   }
1149   return false;
1150 };
1151 
1152 //--------------------------find_exact_control---------------------------------
1153 // Skip Proj and CatchProj nodes chains. Check for Null and Top.
1154 Node* Node::find_exact_control(Node* ctrl) {
1155   if (ctrl == NULL && this->is_Region())
1156     ctrl = this->as_Region()->is_copy();
1157 
1158   if (ctrl != NULL && ctrl->is_CatchProj()) {
1159     if (ctrl->as_CatchProj()->_con == CatchProjNode::fall_through_index)
1160       ctrl = ctrl->in(0);
1161     if (ctrl != NULL && !ctrl->is_top())
1162       ctrl = ctrl->in(0);


1402   // Aggressively kill all unreachable code.
1403   if (can_reshape && n->is_top()) {
1404     kill_dead_code(this, phase->is_IterGVN());
1405     return false; // Node is dead.
1406   }
1407 
1408   if( n->is_Region() && n->as_Region()->is_copy() ) {
1409     Node *m = n->nonnull_req();
1410     set_req(0, m);
1411     return true;
1412   }
1413   return false;
1414 }
1415 
1416 //------------------------------hash-------------------------------------------
1417 // Hash function over Nodes.
1418 uint Node::hash() const {
1419   uint sum = 0;
1420   for( uint i=0; i<_cnt; i++ )  // Add in all inputs
1421     sum = (sum<<1)-(uintptr_t)in(i);        // Ignore embedded NULLs
1422   return (sum>>2) + _cnt + static_cast<uint>(Opcode());
1423 }
1424 
1425 //------------------------------cmp--------------------------------------------
1426 // Compare special parts of simple Nodes
1427 uint Node::cmp( const Node &n ) const {
1428   return 1;                     // Must be same
1429 }
1430 
1431 //------------------------------rematerialize-----------------------------------
1432 // Should we clone rather than spill this instruction?
1433 bool Node::rematerialize() const {
1434   if ( is_Mach() )
1435     return this->as_Mach()->rematerialize();
1436   else
1437     return (_flags & Flag_rematerialize) != 0;
1438 }
1439 
1440 //------------------------------needs_anti_dependence_check---------------------
1441 // Nodes which use memory without consuming it, hence need antidependences.
1442 bool Node::needs_anti_dependence_check() const {


1445   else
1446     return in(1)->bottom_type()->has_memory();
1447 }
1448 
1449 
1450 // Get an integer constant from a ConNode (or CastIINode).
1451 // Return a default value if there is no apparent constant here.
1452 const TypeInt* Node::find_int_type() const {
1453   if (this->is_Type()) {
1454     return this->as_Type()->type()->isa_int();
1455   } else if (this->is_Con()) {
1456     assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode");
1457     return this->bottom_type()->isa_int();
1458   }
1459   return NULL;
1460 }
1461 
1462 // Get a pointer constant from a ConstNode.
1463 // Returns the constant if it is a pointer ConstNode
1464 intptr_t Node::get_ptr() const {
1465   assert( Opcode() == Opcodes::Op_ConP, "" );
1466   return ((ConPNode*)this)->type()->is_ptr()->get_con();
1467 }
1468 
1469 // Get a narrow oop constant from a ConNNode.
1470 intptr_t Node::get_narrowcon() const {
1471   assert( Opcode() == Opcodes::Op_ConN, "" );
1472   return ((ConNNode*)this)->type()->is_narrowoop()->get_con();
1473 }
1474 
1475 // Get a long constant from a ConNode.
1476 // Return a default value if there is no apparent constant here.
1477 const TypeLong* Node::find_long_type() const {
1478   if (this->is_Type()) {
1479     return this->as_Type()->type()->isa_long();
1480   } else if (this->is_Con()) {
1481     assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode");
1482     return this->bottom_type()->isa_long();
1483   }
1484   return NULL;
1485 }
1486 
1487 
1488 /**
1489  * Return a ptr type for nodes which should have it.
1490  */
1491 const TypePtr* Node::get_ptr_type() const {
1492   const TypePtr* tp = this->bottom_type()->make_ptr();
1493 #ifdef ASSERT
1494   if (tp == NULL) {
1495     this->dump(1);
1496     assert((tp != NULL), "unexpected node type");
1497   }
1498 #endif
1499   return tp;
1500 }
1501 
1502 // Get a double constant from a ConstNode.
1503 // Returns the constant if it is a double ConstNode
1504 jdouble Node::getd() const {
1505   assert( Opcode() == Opcodes::Op_ConD, "" );
1506   return ((ConDNode*)this)->type()->is_double_constant()->getd();
1507 }
1508 
1509 // Get a float constant from a ConstNode.
1510 // Returns the constant if it is a float ConstNode
1511 jfloat Node::getf() const {
1512   assert( Opcode() == Opcodes::Op_ConF, "" );
1513   return ((ConFNode*)this)->type()->is_float_constant()->getf();
1514 }
1515 
1516 #ifndef PRODUCT
1517 
1518 //------------------------------find------------------------------------------
1519 // Find a neighbor of this Node with the given _idx
1520 // If idx is negative, find its absolute value, following both _in and _out.
1521 static void find_recur(Compile* C,  Node* &result, Node *n, int idx, bool only_ctrl,
1522                         VectorSet* old_space, VectorSet* new_space ) {
1523   int node_idx = (idx >= 0) ? idx : -idx;
1524   if (NotANode(n))  return;  // Gracefully handle NULL, -1, 0xabababab, etc.
1525   // Contained in new_space or old_space?   Check old_arena first since it's mostly empty.
1526   VectorSet *v = C->old_arena()->contains(n) ? old_space : new_space;
1527   if( v->test(n->_idx) ) return;
1528   if( (int)n->_idx == node_idx
1529       debug_only(|| n->debug_idx() == node_idx) ) {
1530     if (result != NULL)
1531       tty->print("find: " INTPTR_FORMAT " and " INTPTR_FORMAT " both have idx==%d\n",
1532                  (uintptr_t)result, (uintptr_t)n, node_idx);
1533     result = n;
1534   }
1535   v->set(n->_idx);
1536   for( uint i=0; i<n->len(); i++ ) {
1537     if( only_ctrl && !(n->is_Region()) && (n->Opcode() != Opcodes::Op_Root) && (i != TypeFunc::Control) ) continue;
1538     find_recur(C, result, n->in(i), idx, only_ctrl, old_space, new_space );
1539   }
1540   // Search along forward edges also:
1541   if (idx < 0 && !only_ctrl) {
1542     for( uint j=0; j<n->outcnt(); j++ ) {
1543       find_recur(C, result, n->raw_out(j), idx, only_ctrl, old_space, new_space );
1544     }
1545   }
1546 #ifdef ASSERT
1547   // Search along debug_orig edges last, checking for cycles
1548   Node* orig = n->debug_orig();
1549   if (orig != NULL) {
1550     do {
1551       if (NotANode(orig))  break;
1552       find_recur(C, result, orig, idx, only_ctrl, old_space, new_space );
1553       orig = orig->debug_orig();
1554     } while (orig != NULL && orig != n->debug_orig());
1555   }
1556 #endif //ASSERT
1557 }


1570   return result;
1571 }
1572 
1573 //------------------------------find_ctrl--------------------------------------
1574 // Find an ancestor to this node in the control history with given _idx
1575 Node* Node::find_ctrl(int idx) const {
1576   ResourceArea *area = Thread::current()->resource_area();
1577   VectorSet old_space(area), new_space(area);
1578   Node* result = NULL;
1579   find_recur(Compile::current(), result, (Node*) this, idx, true, &old_space, &new_space );
1580   return result;
1581 }
1582 #endif
1583 
1584 
1585 
1586 #ifndef PRODUCT
1587 
1588 // -----------------------------Name-------------------------------------------
1589 extern const char *NodeClassNames[];
1590 const char *Node::Name() const { return NodeClassNames[static_cast<uint>(Opcode())]; }
1591 
1592 static bool is_disconnected(const Node* n) {
1593   for (uint i = 0; i < n->req(); i++) {
1594     if (n->in(i) != NULL)  return false;
1595   }
1596   return true;
1597 }
1598 
1599 #ifdef ASSERT
1600 static void dump_orig(Node* orig, outputStream *st) {
1601   Compile* C = Compile::current();
1602   if (NotANode(orig)) orig = NULL;
1603   if (orig != NULL && !C->node_arena()->contains(orig)) orig = NULL;
1604   if (orig == NULL) return;
1605   st->print(" !orig=");
1606   Node* fast = orig->debug_orig(); // tortoise & hare algorithm to detect loops
1607   if (NotANode(fast)) fast = NULL;
1608   while (orig != NULL) {
1609     bool discon = is_disconnected(orig);  // if discon, print [123] else 123
1610     if (discon) st->print("[");


2253   qsort( _nodes, _max, sizeof( Node* ), func );
2254 }
2255 
2256 //-----------------------------------------------------------------------------
2257 void Node_Array::dump() const {
2258 #ifndef PRODUCT
2259   for( uint i = 0; i < _max; i++ ) {
2260     Node *nn = _nodes[i];
2261     if( nn != NULL ) {
2262       tty->print("%5d--> ",i); nn->dump();
2263     }
2264   }
2265 #endif
2266 }
2267 
2268 //--------------------------is_iteratively_computed------------------------------
2269 // Operation appears to be iteratively computed (such as an induction variable)
2270 // It is possible for this operation to return false for a loop-varying
2271 // value, if it appears (by local graph inspection) to be computed by a simple conditional.
2272 bool Node::is_iteratively_computed() {
2273   if (ideal_reg() != Opcodes::Op_Node) { // does operation have a result register?
2274     for (uint i = 1; i < req(); i++) {
2275       Node* n = in(i);
2276       if (n != NULL && n->is_Phi()) {
2277         for (uint j = 1; j < n->req(); j++) {
2278           if (n->in(j) == this) {
2279             return true;
2280           }
2281         }
2282       }
2283     }
2284   }
2285   return false;
2286 }
2287 
2288 //--------------------------find_similar------------------------------
2289 // Return a node with opcode "opc" and same inputs as "this" if one can
2290 // be found; Otherwise return NULL;
2291 Node* Node::find_similar(Opcodes opc) {
2292   if (req() >= 2) {
2293     Node* def = in(1);
2294     if (def && def->outcnt() >= 2) {
2295       for (DUIterator_Fast dmax, i = def->fast_outs(dmax); i < dmax; i++) {
2296         Node* use = def->fast_out(i);
2297         if (use != this &&
2298             use->Opcode() == opc &&
2299             use->req() == req()) {
2300           uint j;
2301           for (j = 0; j < use->req(); j++) {
2302             if (use->in(j) != in(j)) {
2303               break;
2304             }
2305           }
2306           if (j == use->req()) {
2307             return use;
2308           }
2309         }
2310       }
2311     }


2432   if( !Verbose && !WizardMode ) {
2433     // standard dump does this in Verbose and WizardMode
2434     st->print(" #"); _type->dump_on(st);
2435   }
2436 }
2437 
2438 void TypeNode::dump_compact_spec(outputStream *st) const {
2439   st->print("#");
2440   _type->dump_on(st);
2441 }
2442 #endif
2443 uint TypeNode::hash() const {
2444   return Node::hash() + _type->hash();
2445 }
2446 uint TypeNode::cmp( const Node &n ) const
2447 { return !Type::cmp( _type, ((TypeNode&)n)._type ); }
2448 const Type *TypeNode::bottom_type() const { return _type; }
2449 const Type* TypeNode::Value(PhaseGVN* phase) const { return _type; }
2450 
2451 //------------------------------ideal_reg--------------------------------------
2452 Opcodes TypeNode::ideal_reg() const {
2453   return _type->ideal_reg();
2454 }
< prev index next >