< prev index next >

src/hotspot/share/opto/memnode.cpp

Print this page




  33 #include "opto/cfgnode.hpp"
  34 #include "opto/compile.hpp"
  35 #include "opto/connode.hpp"
  36 #include "opto/convertnode.hpp"
  37 #include "opto/loopnode.hpp"
  38 #include "opto/machnode.hpp"
  39 #include "opto/matcher.hpp"
  40 #include "opto/memnode.hpp"
  41 #include "opto/mulnode.hpp"
  42 #include "opto/narrowptrnode.hpp"
  43 #include "opto/phaseX.hpp"
  44 #include "opto/regmask.hpp"
  45 #include "opto/rootnode.hpp"
  46 #include "utilities/align.hpp"
  47 #include "utilities/copy.hpp"
  48 #include "utilities/macros.hpp"
  49 #include "utilities/vmError.hpp"
  50 #if INCLUDE_ZGC
  51 #include "gc/z/c2/zBarrierSetC2.hpp"
  52 #endif



  53 
  54 // Portions of code courtesy of Clifford Click
  55 
  56 // Optimization - Graph Style
  57 
  58 static Node *step_through_mergemem(PhaseGVN *phase, MergeMemNode *mmem,  const TypePtr *tp, const TypePtr *adr_check, outputStream *st);
  59 
  60 //=============================================================================
  61 uint MemNode::size_of() const { return sizeof(*this); }
  62 
  63 const TypePtr *MemNode::adr_type() const {
  64   Node* adr = in(Address);
  65   if (adr == NULL)  return NULL; // node is dead
  66   const TypePtr* cross_check = NULL;
  67   DEBUG_ONLY(cross_check = _adr_type);
  68   return calculate_adr_type(adr->bottom_type(), cross_check);
  69 }
  70 
  71 bool MemNode::check_if_adr_maybe_raw(Node* adr) {
  72   if (adr != NULL) {


 936   Node* ld_adr = in(MemNode::Address);
 937   intptr_t ld_off = 0;
 938   AllocateNode* ld_alloc = AllocateNode::Ideal_allocation(ld_adr, phase, ld_off);
 939   Node* ac = find_previous_arraycopy(phase, ld_alloc, st, true);
 940   if (ac != NULL) {
 941     assert(ac->is_ArrayCopy(), "what kind of node can this be?");
 942 
 943     Node* mem = ac->in(TypeFunc::Memory);
 944     Node* ctl = ac->in(0);
 945     Node* src = ac->in(ArrayCopyNode::Src);
 946 
 947     if (!ac->as_ArrayCopy()->is_clonebasic() && !phase->type(src)->isa_aryptr()) {
 948       return NULL;
 949     }
 950 
 951     LoadNode* ld = clone()->as_Load();
 952     Node* addp = in(MemNode::Address)->clone();
 953     if (ac->as_ArrayCopy()->is_clonebasic()) {
 954       assert(ld_alloc != NULL, "need an alloc");
 955       assert(addp->is_AddP(), "address must be addp");
 956       assert(addp->in(AddPNode::Base) == ac->in(ArrayCopyNode::Dest)->in(AddPNode::Base), "strange pattern");
 957       assert(addp->in(AddPNode::Address) == ac->in(ArrayCopyNode::Dest)->in(AddPNode::Address), "strange pattern");







 958       addp->set_req(AddPNode::Base, src->in(AddPNode::Base));
 959       addp->set_req(AddPNode::Address, src->in(AddPNode::Address));
 960     } else {
 961       assert(ac->as_ArrayCopy()->is_arraycopy_validated() ||
 962              ac->as_ArrayCopy()->is_copyof_validated() ||
 963              ac->as_ArrayCopy()->is_copyofrange_validated(), "only supported cases");
 964       assert(addp->in(AddPNode::Base) == addp->in(AddPNode::Address), "should be");
 965       addp->set_req(AddPNode::Base, src);
 966       addp->set_req(AddPNode::Address, src);
 967 
 968       const TypeAryPtr* ary_t = phase->type(in(MemNode::Address))->isa_aryptr();
 969       BasicType ary_elem  = ary_t->klass()->as_array_klass()->element_type()->basic_type();
 970       uint header = arrayOopDesc::base_offset_in_bytes(ary_elem);
 971       uint shift  = exact_log2(type2aelembytes(ary_elem));
 972 
 973       Node* diff = phase->transform(new SubINode(ac->in(ArrayCopyNode::SrcPos), ac->in(ArrayCopyNode::DestPos)));
 974 #ifdef _LP64
 975       diff = phase->transform(new ConvI2LNode(diff));
 976 #endif
 977       diff = phase->transform(new LShiftXNode(diff, phase->intcon(shift)));


1093     }
1094 
1095     // A load from an initialization barrier can match a captured store.
1096     if (st->is_Proj() && st->in(0)->is_Initialize()) {
1097       InitializeNode* init = st->in(0)->as_Initialize();
1098       AllocateNode* alloc = init->allocation();
1099       if ((alloc != NULL) && (alloc == ld_alloc)) {
1100         // examine a captured store value
1101         st = init->find_captured_store(ld_off, memory_size(), phase);
1102         if (st != NULL) {
1103           continue;             // take one more trip around
1104         }
1105       }
1106     }
1107 
1108     // Load boxed value from result of valueOf() call is input parameter.
1109     if (this->is_Load() && ld_adr->is_AddP() &&
1110         (tp != NULL) && tp->is_ptr_to_boxed_value()) {
1111       intptr_t ignore = 0;
1112       Node* base = AddPNode::Ideal_base_and_offset(ld_adr, phase, ignore);





1113       if (base != NULL && base->is_Proj() &&
1114           base->as_Proj()->_con == TypeFunc::Parms &&
1115           base->in(0)->is_CallStaticJava() &&
1116           base->in(0)->as_CallStaticJava()->is_boxing_method()) {
1117         return base->in(0)->in(TypeFunc::Parms);
1118       }
1119     }
1120 
1121     break;
1122   }
1123 
1124   return NULL;
1125 }
1126 
1127 //----------------------is_instance_field_load_with_local_phi------------------
1128 bool LoadNode::is_instance_field_load_with_local_phi(Node* ctrl) {
1129   if( in(Memory)->is_Phi() && in(Memory)->in(0) == ctrl &&
1130       in(Address)->is_AddP() ) {
1131     const TypeOopPtr* t_oop = in(Address)->bottom_type()->isa_oopptr();
1132     // Only instances and boxed values.


1420       return NULL; // Wait stable graph
1421     }
1422     uint cnt = base->req();
1423     // Check for loop invariant memory.
1424     if (cnt == 3) {
1425       for (uint i = 1; i < cnt; i++) {
1426         if (base->in(i) == base) {
1427           return NULL; // Wait stable graph
1428         }
1429       }
1430     }
1431   }
1432 
1433   bool load_boxed_phi = load_boxed_values && base_is_phi && (base->in(0) == mem->in(0));
1434 
1435   // Split through Phi (see original code in loopopts.cpp).
1436   assert(C->have_alias_type(t_oop), "instance should have alias type");
1437 
1438   // Do nothing here if Identity will find a value
1439   // (to avoid infinite chain of value phis generation).
1440   if (!phase->eqv(this, this->Identity(phase)))
1441     return NULL;
1442 
1443   // Select Region to split through.
1444   Node* region;
1445   if (!base_is_phi) {
1446     assert(mem->is_Phi(), "sanity");
1447     region = mem->in(0);
1448     // Skip if the region dominates some control edge of the address.
1449     if (!MemNode::all_controls_dominate(address, region))
1450       return NULL;
1451   } else if (!mem->is_Phi()) {
1452     assert(base_is_phi, "sanity");
1453     region = base->in(0);
1454     // Skip if the region dominates some control edge of the memory.
1455     if (!MemNode::all_controls_dominate(mem, region))
1456       return NULL;
1457   } else if (base->in(0) != mem->in(0)) {
1458     assert(base_is_phi && mem->is_Phi(), "sanity");
1459     if (MemNode::all_controls_dominate(mem, base->in(0))) {
1460       region = base->in(0);


1510     bool singleton = t->singleton();
1511 
1512     // See comments in PhaseIdealLoop::split_thru_phi().
1513     if (singleton && t == Type::TOP) {
1514       singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
1515     }
1516 
1517     if (singleton) {
1518       x = igvn->makecon(t);
1519     } else {
1520       // We now call Identity to try to simplify the cloned node.
1521       // Note that some Identity methods call phase->type(this).
1522       // Make sure that the type array is big enough for
1523       // our new node, even though we may throw the node away.
1524       // (This tweaking with igvn only works because x is a new node.)
1525       igvn->set_type(x, t);
1526       // If x is a TypeNode, capture any more-precise type permanently into Node
1527       // otherwise it will be not updated during igvn->transform since
1528       // igvn->type(x) is set to x->Value() already.
1529       x->raise_bottom_type(t);
1530       Node *y = x->Identity(igvn);
1531       if (y != x) {
1532         x = y;
1533       } else {
1534         y = igvn->hash_find_insert(x);
1535         if (y) {
1536           x = y;
1537         } else {
1538           // Else x is a new node we are keeping
1539           // We do not need register_new_node_with_optimizer
1540           // because set_type has already been called.
1541           igvn->_worklist.push(x);
1542         }
1543       }
1544     }
1545     if (x != the_clone && the_clone != NULL) {
1546       igvn->remove_dead_node(the_clone);
1547     }
1548     phi->set_req(i, x);
1549   }
1550   // Record Phi




  33 #include "opto/cfgnode.hpp"
  34 #include "opto/compile.hpp"
  35 #include "opto/connode.hpp"
  36 #include "opto/convertnode.hpp"
  37 #include "opto/loopnode.hpp"
  38 #include "opto/machnode.hpp"
  39 #include "opto/matcher.hpp"
  40 #include "opto/memnode.hpp"
  41 #include "opto/mulnode.hpp"
  42 #include "opto/narrowptrnode.hpp"
  43 #include "opto/phaseX.hpp"
  44 #include "opto/regmask.hpp"
  45 #include "opto/rootnode.hpp"
  46 #include "utilities/align.hpp"
  47 #include "utilities/copy.hpp"
  48 #include "utilities/macros.hpp"
  49 #include "utilities/vmError.hpp"
  50 #if INCLUDE_ZGC
  51 #include "gc/z/c2/zBarrierSetC2.hpp"
  52 #endif
  53 #if INCLUDE_SHENANDOAHGC
  54 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  55 #endif
  56 
  57 // Portions of code courtesy of Clifford Click
  58 
  59 // Optimization - Graph Style
  60 
  61 static Node *step_through_mergemem(PhaseGVN *phase, MergeMemNode *mmem,  const TypePtr *tp, const TypePtr *adr_check, outputStream *st);
  62 
  63 //=============================================================================
  64 uint MemNode::size_of() const { return sizeof(*this); }
  65 
  66 const TypePtr *MemNode::adr_type() const {
  67   Node* adr = in(Address);
  68   if (adr == NULL)  return NULL; // node is dead
  69   const TypePtr* cross_check = NULL;
  70   DEBUG_ONLY(cross_check = _adr_type);
  71   return calculate_adr_type(adr->bottom_type(), cross_check);
  72 }
  73 
  74 bool MemNode::check_if_adr_maybe_raw(Node* adr) {
  75   if (adr != NULL) {


 939   Node* ld_adr = in(MemNode::Address);
 940   intptr_t ld_off = 0;
 941   AllocateNode* ld_alloc = AllocateNode::Ideal_allocation(ld_adr, phase, ld_off);
 942   Node* ac = find_previous_arraycopy(phase, ld_alloc, st, true);
 943   if (ac != NULL) {
 944     assert(ac->is_ArrayCopy(), "what kind of node can this be?");
 945 
 946     Node* mem = ac->in(TypeFunc::Memory);
 947     Node* ctl = ac->in(0);
 948     Node* src = ac->in(ArrayCopyNode::Src);
 949 
 950     if (!ac->as_ArrayCopy()->is_clonebasic() && !phase->type(src)->isa_aryptr()) {
 951       return NULL;
 952     }
 953 
 954     LoadNode* ld = clone()->as_Load();
 955     Node* addp = in(MemNode::Address)->clone();
 956     if (ac->as_ArrayCopy()->is_clonebasic()) {
 957       assert(ld_alloc != NULL, "need an alloc");
 958       assert(addp->is_AddP(), "address must be addp");
 959       assert(ac->in(ArrayCopyNode::Dest)->is_AddP(), "dest must be an address");
 960 #if INCLUDE_SHENANDOAHGC
 961       if (UseShenandoahGC) {
 962         assert(((ShenandoahBarrierSetC2*)BarrierSet::barrier_set()->barrier_set_c2())->step_over_gc_barrier(addp->in(AddPNode::Base)) ==
 963                ((ShenandoahBarrierSetC2*)BarrierSet::barrier_set()->barrier_set_c2())->step_over_gc_barrier(ac->in(ArrayCopyNode::Dest)->in(AddPNode::Base)), "strange pattern");
 964         assert(((ShenandoahBarrierSetC2*)BarrierSet::barrier_set()->barrier_set_c2())->step_over_gc_barrier(addp->in(AddPNode::Address)) ==
 965                ((ShenandoahBarrierSetC2*)BarrierSet::barrier_set()->barrier_set_c2())->step_over_gc_barrier(ac->in(ArrayCopyNode::Dest)->in(AddPNode::Address)), "strange pattern");
 966       }
 967 #endif
 968       addp->set_req(AddPNode::Base, src->in(AddPNode::Base));
 969       addp->set_req(AddPNode::Address, src->in(AddPNode::Address));
 970     } else {
 971       assert(ac->as_ArrayCopy()->is_arraycopy_validated() ||
 972              ac->as_ArrayCopy()->is_copyof_validated() ||
 973              ac->as_ArrayCopy()->is_copyofrange_validated(), "only supported cases");
 974       assert(addp->in(AddPNode::Base) == addp->in(AddPNode::Address), "should be");
 975       addp->set_req(AddPNode::Base, src);
 976       addp->set_req(AddPNode::Address, src);
 977 
 978       const TypeAryPtr* ary_t = phase->type(in(MemNode::Address))->isa_aryptr();
 979       BasicType ary_elem  = ary_t->klass()->as_array_klass()->element_type()->basic_type();
 980       uint header = arrayOopDesc::base_offset_in_bytes(ary_elem);
 981       uint shift  = exact_log2(type2aelembytes(ary_elem));
 982 
 983       Node* diff = phase->transform(new SubINode(ac->in(ArrayCopyNode::SrcPos), ac->in(ArrayCopyNode::DestPos)));
 984 #ifdef _LP64
 985       diff = phase->transform(new ConvI2LNode(diff));
 986 #endif
 987       diff = phase->transform(new LShiftXNode(diff, phase->intcon(shift)));


1103     }
1104 
1105     // A load from an initialization barrier can match a captured store.
1106     if (st->is_Proj() && st->in(0)->is_Initialize()) {
1107       InitializeNode* init = st->in(0)->as_Initialize();
1108       AllocateNode* alloc = init->allocation();
1109       if ((alloc != NULL) && (alloc == ld_alloc)) {
1110         // examine a captured store value
1111         st = init->find_captured_store(ld_off, memory_size(), phase);
1112         if (st != NULL) {
1113           continue;             // take one more trip around
1114         }
1115       }
1116     }
1117 
1118     // Load boxed value from result of valueOf() call is input parameter.
1119     if (this->is_Load() && ld_adr->is_AddP() &&
1120         (tp != NULL) && tp->is_ptr_to_boxed_value()) {
1121       intptr_t ignore = 0;
1122       Node* base = AddPNode::Ideal_base_and_offset(ld_adr, phase, ignore);
1123 #if INCLUDE_SHENANDOAHGC
1124       if (UseShenandoahGC) {
1125         base = ((ShenandoahBarrierSetC2*) BarrierSet::barrier_set()->barrier_set_c2())->step_over_gc_barrier(base);
1126       }
1127 #endif
1128       if (base != NULL && base->is_Proj() &&
1129           base->as_Proj()->_con == TypeFunc::Parms &&
1130           base->in(0)->is_CallStaticJava() &&
1131           base->in(0)->as_CallStaticJava()->is_boxing_method()) {
1132         return base->in(0)->in(TypeFunc::Parms);
1133       }
1134     }
1135 
1136     break;
1137   }
1138 
1139   return NULL;
1140 }
1141 
1142 //----------------------is_instance_field_load_with_local_phi------------------
1143 bool LoadNode::is_instance_field_load_with_local_phi(Node* ctrl) {
1144   if( in(Memory)->is_Phi() && in(Memory)->in(0) == ctrl &&
1145       in(Address)->is_AddP() ) {
1146     const TypeOopPtr* t_oop = in(Address)->bottom_type()->isa_oopptr();
1147     // Only instances and boxed values.


1435       return NULL; // Wait stable graph
1436     }
1437     uint cnt = base->req();
1438     // Check for loop invariant memory.
1439     if (cnt == 3) {
1440       for (uint i = 1; i < cnt; i++) {
1441         if (base->in(i) == base) {
1442           return NULL; // Wait stable graph
1443         }
1444       }
1445     }
1446   }
1447 
1448   bool load_boxed_phi = load_boxed_values && base_is_phi && (base->in(0) == mem->in(0));
1449 
1450   // Split through Phi (see original code in loopopts.cpp).
1451   assert(C->have_alias_type(t_oop), "instance should have alias type");
1452 
1453   // Do nothing here if Identity will find a value
1454   // (to avoid infinite chain of value phis generation).
1455   if (!phase->eqv(this, phase->apply_identity(this)))
1456     return NULL;
1457 
1458   // Select Region to split through.
1459   Node* region;
1460   if (!base_is_phi) {
1461     assert(mem->is_Phi(), "sanity");
1462     region = mem->in(0);
1463     // Skip if the region dominates some control edge of the address.
1464     if (!MemNode::all_controls_dominate(address, region))
1465       return NULL;
1466   } else if (!mem->is_Phi()) {
1467     assert(base_is_phi, "sanity");
1468     region = base->in(0);
1469     // Skip if the region dominates some control edge of the memory.
1470     if (!MemNode::all_controls_dominate(mem, region))
1471       return NULL;
1472   } else if (base->in(0) != mem->in(0)) {
1473     assert(base_is_phi && mem->is_Phi(), "sanity");
1474     if (MemNode::all_controls_dominate(mem, base->in(0))) {
1475       region = base->in(0);


1525     bool singleton = t->singleton();
1526 
1527     // See comments in PhaseIdealLoop::split_thru_phi().
1528     if (singleton && t == Type::TOP) {
1529       singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
1530     }
1531 
1532     if (singleton) {
1533       x = igvn->makecon(t);
1534     } else {
1535       // We now call Identity to try to simplify the cloned node.
1536       // Note that some Identity methods call phase->type(this).
1537       // Make sure that the type array is big enough for
1538       // our new node, even though we may throw the node away.
1539       // (This tweaking with igvn only works because x is a new node.)
1540       igvn->set_type(x, t);
1541       // If x is a TypeNode, capture any more-precise type permanently into Node
1542       // otherwise it will be not updated during igvn->transform since
1543       // igvn->type(x) is set to x->Value() already.
1544       x->raise_bottom_type(t);
1545       Node *y = igvn->apply_identity(x);
1546       if (y != x) {
1547         x = y;
1548       } else {
1549         y = igvn->hash_find_insert(x);
1550         if (y) {
1551           x = y;
1552         } else {
1553           // Else x is a new node we are keeping
1554           // We do not need register_new_node_with_optimizer
1555           // because set_type has already been called.
1556           igvn->_worklist.push(x);
1557         }
1558       }
1559     }
1560     if (x != the_clone && the_clone != NULL) {
1561       igvn->remove_dead_node(the_clone);
1562     }
1563     phi->set_req(i, x);
1564   }
1565   // Record Phi


< prev index next >