1 /*
2 * Copyright (c) 1997, 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 *
780 }
781
782 // Insert multiple out edges on the node.
783 if (n != NULL && !n->is_top()) {
784 for(uint i=0; i<m; i++ ) {
785 n->add_out((Node *)this);
786 }
787 }
788 }
789
790 //------------------------------del_req----------------------------------------
791 // Delete the required edge and compact the edge array
792 void Node::del_req( uint idx ) {
793 assert( idx < _cnt, "oob");
794 assert( !VerifyHashTableKeys || _hash_lock == 0,
795 "remove node from hash table before modifying it");
796 // First remove corresponding def-use edge
797 Node *n = in(idx);
798 if (n != NULL) n->del_out((Node *)this);
799 _in[idx] = in(--_cnt); // Compact the array
800 _in[_cnt] = NULL; // NULL out emptied slot
801 Compile::current()->record_modified_node(this);
802 }
803
804 //------------------------------del_req_ordered--------------------------------
805 // Delete the required edge and compact the edge array with preserved order
806 void Node::del_req_ordered( uint idx ) {
807 assert( idx < _cnt, "oob");
808 assert( !VerifyHashTableKeys || _hash_lock == 0,
809 "remove node from hash table before modifying it");
810 // First remove corresponding def-use edge
811 Node *n = in(idx);
812 if (n != NULL) n->del_out((Node *)this);
813 if (idx < _cnt - 1) { // Not last edge ?
814 Copy::conjoint_words_to_lower((HeapWord*)&_in[idx+1], (HeapWord*)&_in[idx], ((_cnt-idx-1)*sizeof(Node*)));
815 }
816 _in[--_cnt] = NULL; // NULL out emptied slot
817 Compile::current()->record_modified_node(this);
818 }
819
820 //------------------------------ins_req----------------------------------------
821 // Insert a new required input at the end
822 void Node::ins_req( uint idx, Node *n ) {
823 assert( is_not_dead(n), "can not use dead node");
824 add_req(NULL); // Make space
825 assert( idx < _max, "Must have allocated enough space");
826 // Slide over
827 if(_cnt-idx-1 > 0) {
828 Copy::conjoint_words_to_higher((HeapWord*)&_in[idx], (HeapWord*)&_in[idx+1], ((_cnt-idx-1)*sizeof(Node*)));
829 }
830 _in[idx] = n; // Stuff over old required edge
831 if (n != NULL) n->add_out((Node *)this); // Add reciprocal def-use edge
832 }
833
834 //-----------------------------find_edge---------------------------------------
835 int Node::find_edge(Node* n) {
836 for (uint i = 0; i < len(); i++) {
837 if (_in[i] == n) return i;
838 }
839 return -1;
840 }
841
842 //----------------------------replace_edge-------------------------------------
843 int Node::replace_edge(Node* old, Node* neww) {
844 if (old == neww) return 0; // nothing to do
845 uint nrep = 0;
846 for (uint i = 0; i < len(); i++) {
847 if (in(i) == old) {
848 if (i < req())
849 set_req(i, neww);
850 else
851 set_prec(i, neww);
852 nrep++;
853 }
854 }
855 return nrep;
856 }
857
858 /**
859 * Replace input edges in the range pointing to 'old' node.
860 */
861 int Node::replace_edges_in_range(Node* old, Node* neww, int start, int end) {
862 if (old == neww) return 0; // nothing to do
863 uint nrep = 0;
864 for (int i = start; i < end; i++) {
865 if (in(i) == old) {
866 set_req(i, neww);
867 nrep++;
868 }
869 }
870 return nrep;
871 }
965 p = p->in(1);
966 } else {
967 break;
968 }
969 }
970 return (Node*) p;
971 }
972
973 //------------------------------add_prec---------------------------------------
974 // Add a new precedence input. Precedence inputs are unordered, with
975 // duplicates removed and NULLs packed down at the end.
976 void Node::add_prec( Node *n ) {
977 assert( is_not_dead(n), "can not use dead node");
978
979 // Check for NULL at end
980 if( _cnt >= _max || in(_max-1) )
981 grow( _max+1 );
982
983 // Find a precedence edge to move
984 uint i = _cnt;
985 while( in(i) != NULL ) i++;
986 _in[i] = n; // Stuff prec edge over NULL
987 if ( n != NULL) n->add_out((Node *)this); // Add mirror edge
988 }
989
990 //------------------------------rm_prec----------------------------------------
991 // Remove a precedence input. Precedence inputs are unordered, with
992 // duplicates removed and NULLs packed down at the end.
993 void Node::rm_prec( uint j ) {
994
995 // Find end of precedence list to pack NULLs
996 uint i;
997 for( i=j; i<_max; i++ )
998 if( !_in[i] ) // Find the NULL at end of prec edge list
999 break;
1000 if (_in[j] != NULL) _in[j]->del_out((Node *)this);
1001 _in[j] = _in[--i]; // Move last element over removed guy
1002 _in[i] = NULL; // NULL out last element
1003 }
1004
1005 //------------------------------size_of----------------------------------------
1006 uint Node::size_of() const { return sizeof(*this); }
1007
1008 //------------------------------ideal_reg--------------------------------------
1009 uint Node::ideal_reg() const { return 0; }
1010
1011 //------------------------------jvms-------------------------------------------
1012 JVMState* Node::jvms() const { return NULL; }
1013
1014 #ifdef ASSERT
1015 //------------------------------jvms-------------------------------------------
1016 bool Node::verify_jvms(const JVMState* using_jvms) const {
1017 for (JVMState* jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {
1018 if (jvms == using_jvms) return true;
1019 }
1020 return false;
1021 }
1022
|
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 *
780 }
781
782 // Insert multiple out edges on the node.
783 if (n != NULL && !n->is_top()) {
784 for(uint i=0; i<m; i++ ) {
785 n->add_out((Node *)this);
786 }
787 }
788 }
789
790 //------------------------------del_req----------------------------------------
791 // Delete the required edge and compact the edge array
792 void Node::del_req( uint idx ) {
793 assert( idx < _cnt, "oob");
794 assert( !VerifyHashTableKeys || _hash_lock == 0,
795 "remove node from hash table before modifying it");
796 // First remove corresponding def-use edge
797 Node *n = in(idx);
798 if (n != NULL) n->del_out((Node *)this);
799 _in[idx] = in(--_cnt); // Compact the array
800 // Avoid spec violation: Gap in prec edges.
801 close_prec_gap_at(_cnt);
802 Compile::current()->record_modified_node(this);
803 }
804
805 //------------------------------del_req_ordered--------------------------------
806 // Delete the required edge and compact the edge array with preserved order
807 void Node::del_req_ordered( uint idx ) {
808 assert( idx < _cnt, "oob");
809 assert( !VerifyHashTableKeys || _hash_lock == 0,
810 "remove node from hash table before modifying it");
811 // First remove corresponding def-use edge
812 Node *n = in(idx);
813 if (n != NULL) n->del_out((Node *)this);
814 if (idx < --_cnt) { // Not last edge ?
815 Copy::conjoint_words_to_lower((HeapWord*)&_in[idx+1], (HeapWord*)&_in[idx], ((_cnt-idx)*sizeof(Node*)));
816 }
817 // Avoid spec violation: Gap in prec edges.
818 close_prec_gap_at(_cnt);
819 Compile::current()->record_modified_node(this);
820 }
821
822 //------------------------------ins_req----------------------------------------
823 // Insert a new required input at the end
824 void Node::ins_req( uint idx, Node *n ) {
825 assert( is_not_dead(n), "can not use dead node");
826 add_req(NULL); // Make space
827 assert( idx < _max, "Must have allocated enough space");
828 // Slide over
829 if(_cnt-idx-1 > 0) {
830 Copy::conjoint_words_to_higher((HeapWord*)&_in[idx], (HeapWord*)&_in[idx+1], ((_cnt-idx-1)*sizeof(Node*)));
831 }
832 _in[idx] = n; // Stuff over old required edge
833 if (n != NULL) n->add_out((Node *)this); // Add reciprocal def-use edge
834 }
835
836 //-----------------------------find_edge---------------------------------------
837 int Node::find_edge(Node* n) {
838 for (uint i = 0; i < len(); i++) {
839 if (_in[i] == n) return i;
840 }
841 return -1;
842 }
843
844 //----------------------------replace_edge-------------------------------------
845 int Node::replace_edge(Node* old, Node* neww) {
846 if (old == neww) return 0; // nothing to do
847 uint nrep = 0;
848 for (uint i = 0; i < len(); i++) {
849 if (in(i) == old) {
850 if (i < req()) {
851 set_req(i, neww);
852 } else {
853 assert(find_prec_edge(neww) == -1, "spec violation: duplicated prec edge (node %d -> %d)", _idx, neww->_idx);
854 set_prec(i, neww);
855 }
856 nrep++;
857 }
858 }
859 return nrep;
860 }
861
862 /**
863 * Replace input edges in the range pointing to 'old' node.
864 */
865 int Node::replace_edges_in_range(Node* old, Node* neww, int start, int end) {
866 if (old == neww) return 0; // nothing to do
867 uint nrep = 0;
868 for (int i = start; i < end; i++) {
869 if (in(i) == old) {
870 set_req(i, neww);
871 nrep++;
872 }
873 }
874 return nrep;
875 }
969 p = p->in(1);
970 } else {
971 break;
972 }
973 }
974 return (Node*) p;
975 }
976
977 //------------------------------add_prec---------------------------------------
978 // Add a new precedence input. Precedence inputs are unordered, with
979 // duplicates removed and NULLs packed down at the end.
980 void Node::add_prec( Node *n ) {
981 assert( is_not_dead(n), "can not use dead node");
982
983 // Check for NULL at end
984 if( _cnt >= _max || in(_max-1) )
985 grow( _max+1 );
986
987 // Find a precedence edge to move
988 uint i = _cnt;
989 while( in(i) != NULL ) {
990 if (in(i) == n) return; // Avoid spec violation: duplicated prec edge.
991 i++;
992 }
993 _in[i] = n; // Stuff prec edge over NULL
994 if ( n != NULL) n->add_out((Node *)this); // Add mirror edge
995
996 #ifdef ASSERT
997 while ((++i)<_max) { assert(_in[i] == NULL, "spec violation: Gap in prec edges (node %d)", _idx); }
998 #endif
999 }
1000
1001 //------------------------------rm_prec----------------------------------------
1002 // Remove a precedence input. Precedence inputs are unordered, with
1003 // duplicates removed and NULLs packed down at the end.
1004 void Node::rm_prec( uint j ) {
1005 assert(j < _max, "oob: i=%d, _max=%d", j, _max);
1006 assert(j >= _cnt, "not a precedence edge");
1007 if (_in[j] == NULL) return; // Avoid spec violation: Gap in prec edges.
1008 _in[j]->del_out((Node *)this);
1009 close_prec_gap_at(j);
1010 }
1011
1012 //------------------------------size_of----------------------------------------
1013 uint Node::size_of() const { return sizeof(*this); }
1014
1015 //------------------------------ideal_reg--------------------------------------
1016 uint Node::ideal_reg() const { return 0; }
1017
1018 //------------------------------jvms-------------------------------------------
1019 JVMState* Node::jvms() const { return NULL; }
1020
1021 #ifdef ASSERT
1022 //------------------------------jvms-------------------------------------------
1023 bool Node::verify_jvms(const JVMState* using_jvms) const {
1024 for (JVMState* jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {
1025 if (jvms == using_jvms) return true;
1026 }
1027 return false;
1028 }
1029
|