< prev index next >

src/share/vm/opto/parse1.cpp

Print this page




1728             } else if (!check_elide_phi || !target->can_elide_SEL_phi(j)) {
1729               phi = ensure_phi(j, nophi);
1730             }
1731           }
1732           break;
1733         }
1734       }
1735       // At this point, n might be top if:
1736       //  - there is no phi (because TypeFlow detected a conflict), or
1737       //  - the corresponding control edges is top (a dead incoming path)
1738       // It is a bug if we create a phi which sees a garbage value on a live path.
1739 
1740       // Merging two value types?
1741       if (n->isa_ValueType() && m != n) {
1742         assert(phi == NULL, "Value types should not have Phis");
1743         // Reload current state because it may have been updated by ensure_phi
1744         m = map()->in(j);
1745         ValueTypeNode* vtm = m->as_ValueType(); // Current value type
1746         ValueTypeNode* vtn = n->as_ValueType(); // Incoming value type
1747         if (TraceOptoParse) {
1748           tty->print_cr("Merging value types");
1749 #ifdef ASSERT

1750           tty->print_cr("Current:");
1751           vtm->dump(1);
1752           tty->print_cr("Incoming:");
1753           vtn->dump(1);

1754 #endif
1755         }
1756         // Merge oop inputs
1757         phi = vtm->get_oop()->as_Phi();
1758         phi->set_req(pnum, vtn->get_oop());
1759         if (pnum == PhiNode::Input) {
1760           // Last merge
1761           vtm->set_oop(_gvn.transform_no_reclaim(phi));
1762           record_for_igvn(phi);
1763         }
1764         // Merge field values
1765         for (uint index = 0; index < vtm->field_count(); ++index) {
1766           phi = vtm->get_field_value(index)->as_Phi();
1767           phi->set_req(pnum, vtn->get_field_value(index));
1768           if (pnum == PhiNode::Input) {
1769             // Last merge
1770             vtm->set_field_value(index, _gvn.transform_no_reclaim(phi));
1771             record_for_igvn(phi);
1772           }
1773         }
1774       } else if (phi != NULL) {
1775         assert(n != top() || r->in(pnum) == top(), "live value must not be garbage");
1776         assert(phi->region() == r, "");
1777         phi->set_req(pnum, n);  // Then add 'n' to the merge
1778         if (pnum == PhiNode::Input) {
1779           // Last merge for this Phi.
1780           // So far, Phis have had a reasonable type from ciTypeFlow.
1781           // Now _gvn will join that with the meet of current inputs.
1782           // BOTTOM is never permissible here, 'cause pessimistically
1783           // Phis of pointers cannot lose the basic pointer type.
1784           debug_only(const Type* bt1 = phi->bottom_type());
1785           assert(bt1 != Type::BOTTOM, "should not be building conflict phis");
1786           map()->set_req(j, _gvn.transform_no_reclaim(phi));
1787           debug_only(const Type* bt2 = phi->bottom_type());
1788           assert(bt2->higher_equal_speculative(bt1), "must be consistent with type-flow");
1789           record_for_igvn(phi);
1790         }
1791       }
1792     } // End of for all values to be merged
1793 


1951   return pnum;
1952 }
1953 
1954 //------------------------------ensure_phi-------------------------------------
1955 // Turn the idx'th entry of the current map into a Phi
1956 PhiNode *Parse::ensure_phi(int idx, bool nocreate) {
1957   SafePointNode* map = this->map();
1958   Node* region = map->control();
1959   assert(region->is_Region(), "");
1960 
1961   Node* o = map->in(idx);
1962   assert(o != NULL, "");
1963 
1964   if (o == top())  return NULL; // TOP always merges into TOP
1965 
1966   if (o->is_Phi() && o->as_Phi()->region() == region) {
1967     return o->as_Phi();
1968   }
1969 
1970   ValueTypeNode* vt = o->isa_ValueType();
1971   if (vt != NULL && vt->get_oop()->is_Phi() && vt->get_oop()->as_Phi()->region() == region) {


1972     // ValueTypeNode already has Phi inputs
1973     return NULL;
1974   }






1975 
1976   // Now use a Phi here for merging
1977   assert(!nocreate, "Cannot build a phi for a block already parsed.");
1978   const JVMState* jvms = map->jvms();
1979   const Type* t = NULL;
1980   if (jvms->is_loc(idx)) {
1981     t = block()->local_type_at(idx - jvms->locoff());
1982   } else if (jvms->is_stk(idx)) {
1983     t = block()->stack_type_at(idx - jvms->stkoff());
1984   } else if (jvms->is_mon(idx)) {
1985     assert(!jvms->is_monitor_box(idx), "no phis for boxes");
1986     t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object
1987   } else if ((uint)idx < TypeFunc::Parms) {
1988     t = o->bottom_type();  // Type::RETURN_ADDRESS or such-like.
1989   } else {
1990     assert(false, "no type information for this phi");
1991   }
1992 
1993   // If the type falls to bottom, then this must be a local that
1994   // is mixing ints and oops or some such.  Forcing it to top
1995   // makes it go dead.
1996   if (t == Type::BOTTOM) {
1997     map->set_req(idx, top());
1998     return NULL;
1999   }
2000 
2001   // Do not create phis for top either.
2002   // A top on a non-null control flow must be an unused even after the.phi.
2003   if (t == Type::TOP || t == Type::HALF) {
2004     map->set_req(idx, top());
2005     return NULL;
2006   }
2007 
2008   // Value types are merged by merging their field values
2009   if (vt != NULL) {
2010     // Create new ValueTypeNode that represents the merged value type
2011     vt = vt->clone()->as_ValueType();
2012 
2013     // Create a PhiNode for merging the oop
2014     const TypeValueTypePtr* vtptr = TypeValueTypePtr::make(t->is_valuetype());
2015     PhiNode* oop = PhiNode::make(region, vt->get_oop(), vtptr);
2016     gvn().set_type(oop, vtptr);
2017     vt->set_oop(oop);
2018 
2019     // Create a PhiNode for merging each field value
2020     for (uint i = 0; i < vt->field_count(); ++i) {
2021       const Type* field_type = Type::get_const_basic_type(vt->get_field_type(i));
2022       PhiNode* phi = PhiNode::make(region, vt->get_field_value(i), field_type);
2023       gvn().set_type(phi, field_type);
2024       vt->set_field_value(i, phi);
2025     }
2026 
2027     // Update map to use cloned value type
2028     gvn().set_type(vt, t);
2029     map->set_req(idx, vt);
2030     return NULL;
2031   }
2032 
2033   PhiNode* phi = PhiNode::make(region, o, t);
2034   gvn().set_type(phi, t);
2035   if (C->do_escape_analysis()) record_for_igvn(phi);
2036   map->set_req(idx, phi);
2037   return phi;
2038 }
2039 
2040 //--------------------------ensure_memory_phi----------------------------------
2041 // Turn the idx'th slice of the current memory into a Phi
2042 PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) {
2043   MergeMemNode* mem = merged_memory();
2044   Node* region = control();
2045   assert(region->is_Region(), "");
2046 
2047   Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx);
2048   assert(o != NULL && o != top(), "");
2049 




1728             } else if (!check_elide_phi || !target->can_elide_SEL_phi(j)) {
1729               phi = ensure_phi(j, nophi);
1730             }
1731           }
1732           break;
1733         }
1734       }
1735       // At this point, n might be top if:
1736       //  - there is no phi (because TypeFlow detected a conflict), or
1737       //  - the corresponding control edges is top (a dead incoming path)
1738       // It is a bug if we create a phi which sees a garbage value on a live path.
1739 
1740       // Merging two value types?
1741       if (n->isa_ValueType() && m != n) {
1742         assert(phi == NULL, "Value types should not have Phis");
1743         // Reload current state because it may have been updated by ensure_phi
1744         m = map()->in(j);
1745         ValueTypeNode* vtm = m->as_ValueType(); // Current value type
1746         ValueTypeNode* vtn = n->as_ValueType(); // Incoming value type
1747         if (TraceOptoParse) {

1748 #ifdef ASSERT
1749           tty->print_cr("\nMerging value types");
1750           tty->print_cr("Current:");
1751           vtm->dump(2);
1752           tty->print_cr("Incoming:");
1753           vtn->dump(2);
1754           tty->cr();
1755 #endif
1756         }
1757         // Do the merge
1758         map()->set_req(j, vtm->merge_with(this, vtn, pnum));
















1759       } else if (phi != NULL) {
1760         assert(n != top() || r->in(pnum) == top(), "live value must not be garbage");
1761         assert(phi->region() == r, "");
1762         phi->set_req(pnum, n);  // Then add 'n' to the merge
1763         if (pnum == PhiNode::Input) {
1764           // Last merge for this Phi.
1765           // So far, Phis have had a reasonable type from ciTypeFlow.
1766           // Now _gvn will join that with the meet of current inputs.
1767           // BOTTOM is never permissible here, 'cause pessimistically
1768           // Phis of pointers cannot lose the basic pointer type.
1769           debug_only(const Type* bt1 = phi->bottom_type());
1770           assert(bt1 != Type::BOTTOM, "should not be building conflict phis");
1771           map()->set_req(j, _gvn.transform_no_reclaim(phi));
1772           debug_only(const Type* bt2 = phi->bottom_type());
1773           assert(bt2->higher_equal_speculative(bt1), "must be consistent with type-flow");
1774           record_for_igvn(phi);
1775         }
1776       }
1777     } // End of for all values to be merged
1778 


1936   return pnum;
1937 }
1938 
1939 //------------------------------ensure_phi-------------------------------------
1940 // Turn the idx'th entry of the current map into a Phi
1941 PhiNode *Parse::ensure_phi(int idx, bool nocreate) {
1942   SafePointNode* map = this->map();
1943   Node* region = map->control();
1944   assert(region->is_Region(), "");
1945 
1946   Node* o = map->in(idx);
1947   assert(o != NULL, "");
1948 
1949   if (o == top())  return NULL; // TOP always merges into TOP
1950 
1951   if (o->is_Phi() && o->as_Phi()->region() == region) {
1952     return o->as_Phi();
1953   }
1954 
1955   ValueTypeNode* vt = o->isa_ValueType();
1956   if (vt != NULL) {
1957     // Value types are merged by merging their field values
1958     if (vt->get_oop()->is_Phi() && vt->get_oop()->as_Phi()->region() == region) {
1959       // ValueTypeNode already has Phi inputs
1960       return NULL;
1961     }
1962     // Create a cloned ValueTypeNode with phi inputs that
1963     // represents the merged value type and update the map.
1964     vt = vt->clone_with_phis(gvn(), region);
1965     map->set_req(idx, vt);
1966     return NULL;
1967   }
1968 
1969   // Now use a Phi here for merging
1970   assert(!nocreate, "Cannot build a phi for a block already parsed.");
1971   const JVMState* jvms = map->jvms();
1972   const Type* t = NULL;
1973   if (jvms->is_loc(idx)) {
1974     t = block()->local_type_at(idx - jvms->locoff());
1975   } else if (jvms->is_stk(idx)) {
1976     t = block()->stack_type_at(idx - jvms->stkoff());
1977   } else if (jvms->is_mon(idx)) {
1978     assert(!jvms->is_monitor_box(idx), "no phis for boxes");
1979     t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object
1980   } else if ((uint)idx < TypeFunc::Parms) {
1981     t = o->bottom_type();  // Type::RETURN_ADDRESS or such-like.
1982   } else {
1983     assert(false, "no type information for this phi");
1984   }
1985 
1986   // If the type falls to bottom, then this must be a local that
1987   // is mixing ints and oops or some such.  Forcing it to top
1988   // makes it go dead.
1989   if (t == Type::BOTTOM) {
1990     map->set_req(idx, top());
1991     return NULL;
1992   }
1993 
1994   // Do not create phis for top either.
1995   // A top on a non-null control flow must be an unused even after the.phi.
1996   if (t == Type::TOP || t == Type::HALF) {
1997     map->set_req(idx, top());

























1998     return NULL;
1999   }
2000 
2001   PhiNode* phi = PhiNode::make(region, o, t);
2002   gvn().set_type(phi, t);
2003   if (C->do_escape_analysis()) record_for_igvn(phi);
2004   map->set_req(idx, phi);
2005   return phi;
2006 }
2007 
2008 //--------------------------ensure_memory_phi----------------------------------
2009 // Turn the idx'th slice of the current memory into a Phi
2010 PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) {
2011   MergeMemNode* mem = merged_memory();
2012   Node* region = control();
2013   assert(region->is_Region(), "");
2014 
2015   Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx);
2016   assert(o != NULL && o != top(), "");
2017 


< prev index next >