< prev index next >

src/share/vm/opto/ifnode.cpp

Print this page
rev 8739 : 8004073: Implement C2 Ideal node specific dump() method
Summary: add Node::dump_rel() to dump a node and its related nodes (the notion of "related" depends on the node at hand); add Node::dump_comp() to dump a node in compact representation; add Node::dump_rel_comp() to dump a node and its related nodes in compact representation; add the required machinery; extend some C2 IR nodes with compact and related dumping
Reviewed-by:
   1 /*
   2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


1584 
1585 //------------------------------Identity---------------------------------------
1586 // If the test is constant & we match, then we are the input Control
1587 Node *IfProjNode::Identity(PhaseTransform *phase) {
1588   // Can only optimize if cannot go the other way
1589   const TypeTuple *t = phase->type(in(0))->is_tuple();
1590   if (t == TypeTuple::IFNEITHER ||
1591       // kill dead branch first otherwise the IfNode's control will
1592       // have 2 control uses (the IfNode that doesn't go away because
1593       // it still has uses and this branch of the
1594       // If). Node::has_special_unique_user() will cause this node to
1595       // be reprocessed once the dead branch is killed.
1596       (always_taken(t) && in(0)->outcnt() == 1)) {
1597     // IfNode control
1598     return in(0)->in(0);
1599   }
1600   // no progress
1601   return this;
1602 }
1603 
1604 //------------------------------dump_spec--------------------------------------
1605 #ifndef PRODUCT
















1606 void IfNode::dump_spec(outputStream *st) const {
1607   st->print("P=%f, C=%f",_prob,_fcnt);
1608 }















1609 #endif
1610 
1611 //------------------------------idealize_test----------------------------------
1612 // Try to canonicalize tests better.  Peek at the Cmp/Bool/If sequence and
1613 // come up with a canonical sequence.  Bools getting 'eq', 'gt' and 'ge' forms
1614 // converted to 'ne', 'le' and 'lt' forms.  IfTrue/IfFalse get swapped as
1615 // needed.
1616 static IfNode* idealize_test(PhaseGVN* phase, IfNode* iff) {
1617   assert(iff->in(0) != NULL, "If must be live");
1618 
1619   if (iff->outcnt() != 2)  return NULL; // Malformed projections.
1620   Node* old_if_f = iff->proj_out(false);
1621   Node* old_if_t = iff->proj_out(true);
1622 
1623   // CountedLoopEnds want the back-control test to be TRUE, irregardless of
1624   // whether they are testing a 'gt' or 'lt' condition.  The 'gt' condition
1625   // happens in count-down loops
1626   if (iff->is_CountedLoopEnd())  return NULL;
1627   if (!iff->in(1)->is_Bool())  return NULL; // Happens for partially optimized IF tests
1628   BoolNode *b = iff->in(1)->as_Bool();


   1 /*
   2  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


1584 
1585 //------------------------------Identity---------------------------------------
1586 // If the test is constant & we match, then we are the input Control
1587 Node *IfProjNode::Identity(PhaseTransform *phase) {
1588   // Can only optimize if cannot go the other way
1589   const TypeTuple *t = phase->type(in(0))->is_tuple();
1590   if (t == TypeTuple::IFNEITHER ||
1591       // kill dead branch first otherwise the IfNode's control will
1592       // have 2 control uses (the IfNode that doesn't go away because
1593       // it still has uses and this branch of the
1594       // If). Node::has_special_unique_user() will cause this node to
1595       // be reprocessed once the dead branch is killed.
1596       (always_taken(t) && in(0)->outcnt() == 1)) {
1597     // IfNode control
1598     return in(0)->in(0);
1599   }
1600   // no progress
1601   return this;
1602 }
1603 

1604 #ifndef PRODUCT
1605 //---------------------------------rel-----------------------------------------
1606 // An IfProjNode's related node set consists of its input (an IfNode) including
1607 // the IfNode's condition, plus all of its outputs at level 1. In compact mode,
1608 // the restrictions for IfNode apply (see IfNode::rel).
1609 void IfProjNode::rel(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
1610   Node* ifNode = this->in(0);
1611   in_rel->append(ifNode);
1612   if (compact) {
1613     ifNode->collect_nodes(in_rel, 3, false, true);
1614   } else {
1615     ifNode->collect_nodes_in_all_data(in_rel, false);
1616   }
1617   this->collect_nodes(out_rel, -1, false, false);
1618 }
1619 
1620 //------------------------------dump_spec--------------------------------------
1621 void IfNode::dump_spec(outputStream *st) const {
1622   st->print("P=%f, C=%f",_prob,_fcnt);
1623 }
1624 
1625 //---------------------------------rel-----------------------------------------
1626 // For an IfNode, the set of related output nodes is just the output nodes till
1627 // depth 2, i.e, the IfTrue/IfFalse projection nodes plus the nodes they refer.
1628 // The related input nodes contain no control nodes, but all data nodes
1629 // pertaining to the condition. In compact mode, the input nodes are collected
1630 // up to a depth of 3.
1631 void IfNode::rel(GrowableArray <Node *> *in_rel, GrowableArray <Node *> *out_rel, bool compact) const {
1632   if (compact) {
1633     this->collect_nodes(in_rel, 3, false, true);
1634   } else {
1635     this->collect_nodes_in_all_data(in_rel, false);
1636   }
1637   this->collect_nodes(out_rel, -2, false, false);
1638 }
1639 #endif
1640 
1641 //------------------------------idealize_test----------------------------------
1642 // Try to canonicalize tests better.  Peek at the Cmp/Bool/If sequence and
1643 // come up with a canonical sequence.  Bools getting 'eq', 'gt' and 'ge' forms
1644 // converted to 'ne', 'le' and 'lt' forms.  IfTrue/IfFalse get swapped as
1645 // needed.
1646 static IfNode* idealize_test(PhaseGVN* phase, IfNode* iff) {
1647   assert(iff->in(0) != NULL, "If must be live");
1648 
1649   if (iff->outcnt() != 2)  return NULL; // Malformed projections.
1650   Node* old_if_f = iff->proj_out(false);
1651   Node* old_if_t = iff->proj_out(true);
1652 
1653   // CountedLoopEnds want the back-control test to be TRUE, irregardless of
1654   // whether they are testing a 'gt' or 'lt' condition.  The 'gt' condition
1655   // happens in count-down loops
1656   if (iff->is_CountedLoopEnd())  return NULL;
1657   if (!iff->in(1)->is_Bool())  return NULL; // Happens for partially optimized IF tests
1658   BoolNode *b = iff->in(1)->as_Bool();


< prev index next >