823 if (!C->node_arena()->contains(n)) {
824 // Old space!
825 Node* m;
826 if (has_new_node(n)) { // Not yet Label/Reduced
827 m = new_node(n);
828 } else {
829 if (!is_dontcare(n)) { // Matcher can match this guy
830 // Calls match special. They match alone with no children.
831 // Their children, the incoming arguments, match normally.
832 m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n);
833 if (C->failing()) return NULL;
834 if (m == NULL) { Matcher::soft_match_failure(); return NULL; }
835 } else { // Nothing the matcher cares about
836 if( n->is_Proj() && n->in(0)->is_Multi()) { // Projections?
837 // Convert to machine-dependent projection
838 m = n->in(0)->as_Multi()->match( n->as_Proj(), this );
839 #ifdef ASSERT
840 _new2old_map.map(m->_idx, n);
841 #endif
842 if (m->in(0) != NULL) // m might be top
843 collect_null_checks(m);
844 } else { // Else just a regular 'ol guy
845 m = n->clone(); // So just clone into new-space
846 #ifdef ASSERT
847 _new2old_map.map(m->_idx, n);
848 #endif
849 // Def-Use edges will be added incrementally as Uses
850 // of this node are matched.
851 assert(m->outcnt() == 0, "no Uses of this clone yet");
852 }
853 }
854
855 set_new_node(n, m); // Map old to new
856 if (_old_node_note_array != NULL) {
857 Node_Notes* nn = C->locate_node_notes(_old_node_note_array,
858 n->_idx);
859 C->set_node_notes_at(m->_idx, nn);
860 }
861 debug_only(match_alias_type(C, n, m));
862 }
863 n = m; // n is now a new-space node
1461 mach->add_req(0); // Set initial control to none
1462 ReduceInst_Chain_Rule( s, rule, mem, mach );
1463 }
1464
1465 // If a Memory was used, insert a Memory edge
1466 if( mem != (Node*)1 ) {
1467 mach->ins_req(MemNode::Memory,mem);
1468 #ifdef ASSERT
1469 // Verify adr type after matching memory operation
1470 const MachOper* oper = mach->memory_operand();
1471 if (oper != NULL && oper != (MachOper*)-1 &&
1472 mach->adr_type() != TypeRawPtr::BOTTOM) { // non-direct addressing mode
1473 // It has a unique memory operand. Find corresponding ideal mem node.
1474 Node* m = NULL;
1475 if (leaf->is_Mem()) {
1476 m = leaf;
1477 } else {
1478 m = _mem_node;
1479 assert(m != NULL && m->is_Mem(), "expecting memory node");
1480 }
1481 if (m->adr_type() != mach->adr_type()) {
1482 m->dump();
1483 tty->print_cr("mach:");
1484 mach->dump(1);
1485 }
1486 assert(m->adr_type() == mach->adr_type(), "matcher should not change adr type");
1487 }
1488 #endif
1489 }
1490
1491 // If the _leaf is an AddP, insert the base edge
1492 if( leaf->is_AddP() )
1493 mach->ins_req(AddPNode::Base,leaf->in(AddPNode::Base));
1494
1495 uint num_proj = _proj_list.size();
1496
1497 // Perform any 1-to-many expansions required
1498 MachNode *ex = mach->Expand(s,_proj_list);
1499 if( ex != mach ) {
1500 assert(ex->ideal_reg() == mach->ideal_reg(), "ideal types should match");
1501 if( ex->in(1)->is_Con() )
1502 ex->in(1)->set_req(0, C->root());
1503 // Remove old node from the graph
1504 for( uint i=0; i<mach->req(); i++ ) {
1505 mach->set_req(i,NULL);
1506 }
1978 }
1979 }
1980 else {
1981 ShouldNotReachHere();
1982 }
1983 } // end of while (mstack.is_nonempty())
1984 }
1985
1986 #ifdef ASSERT
1987 // machine-independent root to machine-dependent root
1988 void Matcher::dump_old2new_map() {
1989 _old2new_map.dump();
1990 }
1991 #endif
1992
1993 //---------------------------collect_null_checks-------------------------------
1994 // Find null checks in the ideal graph; write a machine-specific node for
1995 // it. Used by later implicit-null-check handling. Actually collects
1996 // either an IfTrue or IfFalse for the common NOT-null path, AND the ideal
1997 // value being tested.
1998 void Matcher::collect_null_checks( Node *proj ) {
1999 Node *iff = proj->in(0);
2000 if( iff->Opcode() == Op_If ) {
2001 // During matching If's have Bool & Cmp side-by-side
2002 BoolNode *b = iff->in(1)->as_Bool();
2003 Node *cmp = iff->in(2);
2004 int opc = cmp->Opcode();
2005 if (opc != Op_CmpP && opc != Op_CmpN) return;
2006
2007 const Type* ct = cmp->in(2)->bottom_type();
2008 if (ct == TypePtr::NULL_PTR ||
2009 (opc == Op_CmpN && ct == TypeNarrowOop::NULL_PTR)) {
2010
2011 if( proj->Opcode() == Op_IfTrue ) {
2012 extern int all_null_checks_found;
2013 all_null_checks_found++;
2014 if( b->_test._test == BoolTest::ne ) {
2015 _null_check_tests.push(proj);
2016 _null_check_tests.push(cmp->in(1));
2017 }
2018 } else {
2019 assert( proj->Opcode() == Op_IfFalse, "" );
2020 if( b->_test._test == BoolTest::eq ) {
2021 _null_check_tests.push(proj);
2022 _null_check_tests.push(cmp->in(1));
2023 }
2024 }
2025 }
2026 }
2027 }
2028
2029 //---------------------------validate_null_checks------------------------------
2030 // Its possible that the value being NULL checked is not the root of a match
2031 // tree. If so, I cannot use the value in an implicit null check.
2032 void Matcher::validate_null_checks( ) {
2033 uint cnt = _null_check_tests.size();
2034 for( uint i=0; i < cnt; i+=2 ) {
2035 Node *test = _null_check_tests[i];
2036 Node *val = _null_check_tests[i+1];
2037 if (has_new_node(val)) {
2038 // Is a match-tree root, so replace with the matched value
2039 _null_check_tests.map(i+1, new_node(val));
2040 } else {
2041 // Yank from candidate list
2042 _null_check_tests.map(i+1,_null_check_tests[--cnt]);
2043 _null_check_tests.map(i,_null_check_tests[--cnt]);
2044 _null_check_tests.pop();
2045 _null_check_tests.pop();
|
823 if (!C->node_arena()->contains(n)) {
824 // Old space!
825 Node* m;
826 if (has_new_node(n)) { // Not yet Label/Reduced
827 m = new_node(n);
828 } else {
829 if (!is_dontcare(n)) { // Matcher can match this guy
830 // Calls match special. They match alone with no children.
831 // Their children, the incoming arguments, match normally.
832 m = n->is_SafePoint() ? match_sfpt(n->as_SafePoint()):match_tree(n);
833 if (C->failing()) return NULL;
834 if (m == NULL) { Matcher::soft_match_failure(); return NULL; }
835 } else { // Nothing the matcher cares about
836 if( n->is_Proj() && n->in(0)->is_Multi()) { // Projections?
837 // Convert to machine-dependent projection
838 m = n->in(0)->as_Multi()->match( n->as_Proj(), this );
839 #ifdef ASSERT
840 _new2old_map.map(m->_idx, n);
841 #endif
842 if (m->in(0) != NULL) // m might be top
843 collect_null_checks(m, n);
844 } else { // Else just a regular 'ol guy
845 m = n->clone(); // So just clone into new-space
846 #ifdef ASSERT
847 _new2old_map.map(m->_idx, n);
848 #endif
849 // Def-Use edges will be added incrementally as Uses
850 // of this node are matched.
851 assert(m->outcnt() == 0, "no Uses of this clone yet");
852 }
853 }
854
855 set_new_node(n, m); // Map old to new
856 if (_old_node_note_array != NULL) {
857 Node_Notes* nn = C->locate_node_notes(_old_node_note_array,
858 n->_idx);
859 C->set_node_notes_at(m->_idx, nn);
860 }
861 debug_only(match_alias_type(C, n, m));
862 }
863 n = m; // n is now a new-space node
1461 mach->add_req(0); // Set initial control to none
1462 ReduceInst_Chain_Rule( s, rule, mem, mach );
1463 }
1464
1465 // If a Memory was used, insert a Memory edge
1466 if( mem != (Node*)1 ) {
1467 mach->ins_req(MemNode::Memory,mem);
1468 #ifdef ASSERT
1469 // Verify adr type after matching memory operation
1470 const MachOper* oper = mach->memory_operand();
1471 if (oper != NULL && oper != (MachOper*)-1 &&
1472 mach->adr_type() != TypeRawPtr::BOTTOM) { // non-direct addressing mode
1473 // It has a unique memory operand. Find corresponding ideal mem node.
1474 Node* m = NULL;
1475 if (leaf->is_Mem()) {
1476 m = leaf;
1477 } else {
1478 m = _mem_node;
1479 assert(m != NULL && m->is_Mem(), "expecting memory node");
1480 }
1481 const Type* mach_at = mach->adr_type();
1482 // DecodeN node consumed by an address may have different type
1483 // then its input. Don't compare types for such case.
1484 if (m->adr_type() != mach_at && m->in(MemNode::Address)->is_AddP() &&
1485 m->in(MemNode::Address)->in(AddPNode::Address)->is_DecodeN()) {
1486 mach_at = m->adr_type();
1487 }
1488 if (m->adr_type() != mach_at) {
1489 m->dump();
1490 tty->print_cr("mach:");
1491 mach->dump(1);
1492 }
1493 assert(m->adr_type() == mach_at, "matcher should not change adr type");
1494 }
1495 #endif
1496 }
1497
1498 // If the _leaf is an AddP, insert the base edge
1499 if( leaf->is_AddP() )
1500 mach->ins_req(AddPNode::Base,leaf->in(AddPNode::Base));
1501
1502 uint num_proj = _proj_list.size();
1503
1504 // Perform any 1-to-many expansions required
1505 MachNode *ex = mach->Expand(s,_proj_list);
1506 if( ex != mach ) {
1507 assert(ex->ideal_reg() == mach->ideal_reg(), "ideal types should match");
1508 if( ex->in(1)->is_Con() )
1509 ex->in(1)->set_req(0, C->root());
1510 // Remove old node from the graph
1511 for( uint i=0; i<mach->req(); i++ ) {
1512 mach->set_req(i,NULL);
1513 }
1985 }
1986 }
1987 else {
1988 ShouldNotReachHere();
1989 }
1990 } // end of while (mstack.is_nonempty())
1991 }
1992
1993 #ifdef ASSERT
1994 // machine-independent root to machine-dependent root
1995 void Matcher::dump_old2new_map() {
1996 _old2new_map.dump();
1997 }
1998 #endif
1999
2000 //---------------------------collect_null_checks-------------------------------
2001 // Find null checks in the ideal graph; write a machine-specific node for
2002 // it. Used by later implicit-null-check handling. Actually collects
2003 // either an IfTrue or IfFalse for the common NOT-null path, AND the ideal
2004 // value being tested.
2005 void Matcher::collect_null_checks( Node *proj, Node *orig_proj ) {
2006 Node *iff = proj->in(0);
2007 if( iff->Opcode() == Op_If ) {
2008 // During matching If's have Bool & Cmp side-by-side
2009 BoolNode *b = iff->in(1)->as_Bool();
2010 Node *cmp = iff->in(2);
2011 int opc = cmp->Opcode();
2012 if (opc != Op_CmpP && opc != Op_CmpN) return;
2013
2014 const Type* ct = cmp->in(2)->bottom_type();
2015 if (ct == TypePtr::NULL_PTR ||
2016 (opc == Op_CmpN && ct == TypeNarrowOop::NULL_PTR)) {
2017
2018 bool push_it = false;
2019 if( proj->Opcode() == Op_IfTrue ) {
2020 extern int all_null_checks_found;
2021 all_null_checks_found++;
2022 if( b->_test._test == BoolTest::ne ) {
2023 push_it = true;
2024 }
2025 } else {
2026 assert( proj->Opcode() == Op_IfFalse, "" );
2027 if( b->_test._test == BoolTest::eq ) {
2028 push_it = true;
2029 }
2030 }
2031 if( push_it ) {
2032 _null_check_tests.push(proj);
2033 Node* val = cmp->in(1);
2034 #ifdef _LP64
2035 if (UseCompressedOops && !Matcher::clone_shift_expressions &&
2036 val->bottom_type()->isa_narrowoop()) {
2037 //
2038 // Look for DecodeN node which should be pinned to orig_proj.
2039 // On platforms (Sparc) which can not handle 2 adds
2040 // in addressing mode we have to keep a DecodeN node and
2041 // use it to do implicit NULL check in address.
2042 //
2043 // DecodeN node was pinned to non-null path (orig_proj) during
2044 // CastPP transformation in final_graph_reshaping_impl().
2045 //
2046 uint cnt = orig_proj->outcnt();
2047 for (uint i = 0; i < orig_proj->outcnt(); i++) {
2048 Node* d = orig_proj->raw_out(i);
2049 if (d->is_DecodeN() && d->in(1) == val) {
2050 val = d;
2051 val->set_req(0, NULL); // Unpin now.
2052 break;
2053 }
2054 }
2055 }
2056 #endif
2057 _null_check_tests.push(val);
2058 }
2059 }
2060 }
2061 }
2062
2063 //---------------------------validate_null_checks------------------------------
2064 // Its possible that the value being NULL checked is not the root of a match
2065 // tree. If so, I cannot use the value in an implicit null check.
2066 void Matcher::validate_null_checks( ) {
2067 uint cnt = _null_check_tests.size();
2068 for( uint i=0; i < cnt; i+=2 ) {
2069 Node *test = _null_check_tests[i];
2070 Node *val = _null_check_tests[i+1];
2071 if (has_new_node(val)) {
2072 // Is a match-tree root, so replace with the matched value
2073 _null_check_tests.map(i+1, new_node(val));
2074 } else {
2075 // Yank from candidate list
2076 _null_check_tests.map(i+1,_null_check_tests[--cnt]);
2077 _null_check_tests.map(i,_null_check_tests[--cnt]);
2078 _null_check_tests.pop();
2079 _null_check_tests.pop();
|