< prev index next >

src/hotspot/share/opto/node.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2016, 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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "libadt/vectset.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "opto/castnode.hpp"
  32 #include "opto/cfgnode.hpp"
  33 #include "opto/connode.hpp"
  34 #include "opto/loopnode.hpp"
  35 #include "opto/machnode.hpp"
  36 #include "opto/matcher.hpp"
  37 #include "opto/node.hpp"
  38 #include "opto/opcodes.hpp"
  39 #include "opto/regmask.hpp"
  40 #include "opto/type.hpp"
  41 #include "utilities/copy.hpp"
  42 #include "utilities/macros.hpp"



  43 
  44 class RegMask;
  45 // #include "phase.hpp"
  46 class PhaseTransform;
  47 class PhaseGVN;
  48 
  49 // Arena we are currently building Nodes in
  50 const uint Node::NotAMachineReg = 0xffff0000;
  51 
  52 #ifndef PRODUCT
  53 extern int nodes_created;
  54 #endif
  55 #ifdef __clang__
  56 #pragma clang diagnostic push
  57 #pragma GCC diagnostic ignored "-Wuninitialized"
  58 #endif
  59 
  60 #ifdef ASSERT
  61 
  62 //-------------------------- construct_node------------------------------------


1125 // for the transformations to happen.
1126 bool Node::has_special_unique_user() const {
1127   assert(outcnt() == 1, "match only for unique out");
1128   Node* n = unique_out();
1129   int op  = Opcode();
1130   if (this->is_Store()) {
1131     // Condition for back-to-back stores folding.
1132     return n->Opcode() == op && n->in(MemNode::Memory) == this;
1133   } else if (this->is_Load() || this->is_DecodeN() || this->is_Phi()) {
1134     // Condition for removing an unused LoadNode or DecodeNNode from the MemBarAcquire precedence input
1135     return n->Opcode() == Op_MemBarAcquire;
1136   } else if (op == Op_AddL) {
1137     // Condition for convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
1138     return n->Opcode() == Op_ConvL2I && n->in(1) == this;
1139   } else if (op == Op_SubI || op == Op_SubL) {
1140     // Condition for subI(x,subI(y,z)) ==> subI(addI(x,z),y)
1141     return n->Opcode() == op && n->in(2) == this;
1142   } else if (is_If() && (n->is_IfFalse() || n->is_IfTrue())) {
1143     // See IfProjNode::Identity()
1144     return true;




1145   }
1146   return false;
1147 };
1148 
1149 //--------------------------find_exact_control---------------------------------
1150 // Skip Proj and CatchProj nodes chains. Check for Null and Top.
1151 Node* Node::find_exact_control(Node* ctrl) {
1152   if (ctrl == NULL && this->is_Region())
1153     ctrl = this->as_Region()->is_copy();
1154 
1155   if (ctrl != NULL && ctrl->is_CatchProj()) {
1156     if (ctrl->as_CatchProj()->_con == CatchProjNode::fall_through_index)
1157       ctrl = ctrl->in(0);
1158     if (ctrl != NULL && !ctrl->is_top())
1159       ctrl = ctrl->in(0);
1160   }
1161 
1162   if (ctrl != NULL && ctrl->is_Proj())
1163     ctrl = ctrl->in(0);
1164 


1371       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1372       bs->unregister_potential_barrier_node(dead);
1373       igvn->C->record_dead_node(dead->_idx);
1374       // Kill all inputs to the dead guy
1375       for (uint i=0; i < dead->req(); i++) {
1376         Node *n = dead->in(i);      // Get input to dead guy
1377         if (n != NULL && !n->is_top()) { // Input is valid?
1378           dead->set_req(i, top);    // Smash input away
1379           if (n->outcnt() == 0) {   // Input also goes dead?
1380             if (!n->is_Con())
1381               nstack.push(n);       // Clear it out as well
1382           } else if (n->outcnt() == 1 &&
1383                      n->has_special_unique_user()) {
1384             igvn->add_users_to_worklist( n );
1385           } else if (n->outcnt() <= 2 && n->is_Store()) {
1386             // Push store's uses on worklist to enable folding optimization for
1387             // store/store and store/load to the same address.
1388             // The restriction (outcnt() <= 2) is the same as in set_req_X()
1389             // and remove_globally_dead_node().
1390             igvn->add_users_to_worklist( n );





1391           } else {
1392             BarrierSet::barrier_set()->barrier_set_c2()->enqueue_useful_gc_barrier(igvn->_worklist, n);
1393           }
1394         }
1395       }
1396     } // (dead->outcnt() == 0)
1397   }   // while (nstack.size() > 0) for outputs
1398   return;
1399 }
1400 
1401 //------------------------------remove_dead_region-----------------------------
1402 bool Node::remove_dead_region(PhaseGVN *phase, bool can_reshape) {
1403   Node *n = in(0);
1404   if( !n ) return false;
1405   // Lost control into this guy?  I.e., it became unreachable?
1406   // Aggressively kill all unreachable code.
1407   if (can_reshape && n->is_top()) {
1408     kill_dead_code(this, phase->is_IterGVN());
1409     return false; // Node is dead.
1410   }


   1 /*
   2  * Copyright (c) 1997, 2018, 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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "libadt/vectset.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "opto/castnode.hpp"
  32 #include "opto/cfgnode.hpp"
  33 #include "opto/connode.hpp"
  34 #include "opto/loopnode.hpp"
  35 #include "opto/machnode.hpp"
  36 #include "opto/matcher.hpp"
  37 #include "opto/node.hpp"
  38 #include "opto/opcodes.hpp"
  39 #include "opto/regmask.hpp"
  40 #include "opto/type.hpp"
  41 #include "utilities/copy.hpp"
  42 #include "utilities/macros.hpp"
  43 #if INCLUDE_SHENANDOAHGC
  44 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  45 #endif
  46 
  47 class RegMask;
  48 // #include "phase.hpp"
  49 class PhaseTransform;
  50 class PhaseGVN;
  51 
  52 // Arena we are currently building Nodes in
  53 const uint Node::NotAMachineReg = 0xffff0000;
  54 
  55 #ifndef PRODUCT
  56 extern int nodes_created;
  57 #endif
  58 #ifdef __clang__
  59 #pragma clang diagnostic push
  60 #pragma GCC diagnostic ignored "-Wuninitialized"
  61 #endif
  62 
  63 #ifdef ASSERT
  64 
  65 //-------------------------- construct_node------------------------------------


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   int 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() || this->is_DecodeN() || this->is_Phi()) {
1137     // Condition for removing an unused LoadNode or DecodeNNode from the MemBarAcquire precedence input
1138     return n->Opcode() == Op_MemBarAcquire;
1139   } else if (op == Op_AddL) {
1140     // Condition for convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
1141     return n->Opcode() == Op_ConvL2I && n->in(1) == this;
1142   } else if (op == Op_SubI || op == 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 #if INCLUDE_SHENANDOAHGC
1149   } else if (op == Op_ShenandoahWriteBarrier) {
1150     return n->Opcode() == Op_ShenandoahWBMemProj;
1151 #endif
1152   }
1153   return false;
1154 };
1155 
1156 //--------------------------find_exact_control---------------------------------
1157 // Skip Proj and CatchProj nodes chains. Check for Null and Top.
1158 Node* Node::find_exact_control(Node* ctrl) {
1159   if (ctrl == NULL && this->is_Region())
1160     ctrl = this->as_Region()->is_copy();
1161 
1162   if (ctrl != NULL && ctrl->is_CatchProj()) {
1163     if (ctrl->as_CatchProj()->_con == CatchProjNode::fall_through_index)
1164       ctrl = ctrl->in(0);
1165     if (ctrl != NULL && !ctrl->is_top())
1166       ctrl = ctrl->in(0);
1167   }
1168 
1169   if (ctrl != NULL && ctrl->is_Proj())
1170     ctrl = ctrl->in(0);
1171 


1378       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1379       bs->unregister_potential_barrier_node(dead);
1380       igvn->C->record_dead_node(dead->_idx);
1381       // Kill all inputs to the dead guy
1382       for (uint i=0; i < dead->req(); i++) {
1383         Node *n = dead->in(i);      // Get input to dead guy
1384         if (n != NULL && !n->is_top()) { // Input is valid?
1385           dead->set_req(i, top);    // Smash input away
1386           if (n->outcnt() == 0) {   // Input also goes dead?
1387             if (!n->is_Con())
1388               nstack.push(n);       // Clear it out as well
1389           } else if (n->outcnt() == 1 &&
1390                      n->has_special_unique_user()) {
1391             igvn->add_users_to_worklist( n );
1392           } else if (n->outcnt() <= 2 && n->is_Store()) {
1393             // Push store's uses on worklist to enable folding optimization for
1394             // store/store and store/load to the same address.
1395             // The restriction (outcnt() <= 2) is the same as in set_req_X()
1396             // and remove_globally_dead_node().
1397             igvn->add_users_to_worklist( n );
1398 #if INCLUDE_SHENANDOAHGC
1399           // TODO: Move into below enqueue_useful_gc_barrier() call
1400           } else if (n->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(n)) {
1401             igvn->add_users_to_worklist(n);
1402 #endif
1403           } else {
1404             BarrierSet::barrier_set()->barrier_set_c2()->enqueue_useful_gc_barrier(igvn->_worklist, n);
1405           }
1406         }
1407       }
1408     } // (dead->outcnt() == 0)
1409   }   // while (nstack.size() > 0) for outputs
1410   return;
1411 }
1412 
1413 //------------------------------remove_dead_region-----------------------------
1414 bool Node::remove_dead_region(PhaseGVN *phase, bool can_reshape) {
1415   Node *n = in(0);
1416   if( !n ) return false;
1417   // Lost control into this guy?  I.e., it became unreachable?
1418   // Aggressively kill all unreachable code.
1419   if (can_reshape && n->is_top()) {
1420     kill_dead_code(this, phase->is_IterGVN());
1421     return false; // Node is dead.
1422   }


< prev index next >