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;
|
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 uint i = _cnt;
802 Node *last = NULL;
803 for (; i < len()-1; ++i) {
804 Node *next = _in[i+1];
805 if (next == NULL) break;
806 last = next;
807 }
808 _in[_cnt] = last; // Move last slot to empty one.
809 _in[i] = NULL; // NULL out last slot.
810 Compile::current()->record_modified_node(this);
811 }
812
813 //------------------------------del_req_ordered--------------------------------
814 // Delete the required edge and compact the edge array with preserved order
815 void Node::del_req_ordered( uint idx ) {
816 assert( idx < _cnt, "oob");
817 assert( !VerifyHashTableKeys || _hash_lock == 0,
818 "remove node from hash table before modifying it");
819 // First remove corresponding def-use edge
820 Node *n = in(idx);
821 if (n != NULL) n->del_out((Node *)this);
822 if (idx < --_cnt) { // Not last edge ?
823 Copy::conjoint_words_to_lower((HeapWord*)&_in[idx+1], (HeapWord*)&_in[idx], ((_cnt-idx)*sizeof(Node*)));
824 }
825 // Avoid spec violation: Gap in prec edges.
826 uint i = _cnt;
827 Node *last = NULL;
828 for (; i < len()-1; ++i) {
829 Node *next = _in[i+1];
830 if (next == NULL) break;
831 last = next;
832 }
833 _in[_cnt] = last; // Move last slot to empty one.
834 _in[i] = NULL; // NULL out last slot.
835 Compile::current()->record_modified_node(this);
836 }
837
838 //------------------------------ins_req----------------------------------------
839 // Insert a new required input at the end
840 void Node::ins_req( uint idx, Node *n ) {
841 assert( is_not_dead(n), "can not use dead node");
842 add_req(NULL); // Make space
843 assert( idx < _max, "Must have allocated enough space");
844 // Slide over
845 if(_cnt-idx-1 > 0) {
846 Copy::conjoint_words_to_higher((HeapWord*)&_in[idx], (HeapWord*)&_in[idx+1], ((_cnt-idx-1)*sizeof(Node*)));
847 }
848 _in[idx] = n; // Stuff over old required edge
849 if (n != NULL) n->add_out((Node *)this); // Add reciprocal def-use edge
850 }
851
852 //-----------------------------find_edge---------------------------------------
853 int Node::find_edge(Node* n) {
854 for (uint i = 0; i < len(); i++) {
855 if (_in[i] == n) return i;
856 }
857 return -1;
858 }
859
860 //----------------------------replace_edge-------------------------------------
861 int Node::replace_edge(Node* old, Node* neww) {
862 if (old == neww) return 0; // nothing to do
863 uint nrep = 0;
864 for (uint i = 0; i < len(); i++) {
865 if (in(i) == old) {
866 if (i < req()) {
867 set_req(i, neww);
868 } else {
869 assert(find_prec_edge(neww) == -1, "spec violation: multiple prec edge (node %d -> %d)", _idx, neww->_idx);
870 set_prec(i, neww);
871 }
872 nrep++;
873 }
874 }
875 return nrep;
876 }
877
878 /**
879 * Replace input edges in the range pointing to 'old' node.
880 */
881 int Node::replace_edges_in_range(Node* old, Node* neww, int start, int end) {
882 if (old == neww) return 0; // nothing to do
883 uint nrep = 0;
884 for (int i = start; i < end; i++) {
885 if (in(i) == old) {
886 set_req(i, neww);
887 nrep++;
888 }
889 }
890 return nrep;
891 }
985 p = p->in(1);
986 } else {
987 break;
988 }
989 }
990 return (Node*) p;
991 }
992
993 //------------------------------add_prec---------------------------------------
994 // Add a new precedence input. Precedence inputs are unordered, with
995 // duplicates removed and NULLs packed down at the end.
996 void Node::add_prec( Node *n ) {
997 assert( is_not_dead(n), "can not use dead node");
998
999 // Check for NULL at end
1000 if( _cnt >= _max || in(_max-1) )
1001 grow( _max+1 );
1002
1003 // Find a precedence edge to move
1004 uint i = _cnt;
1005 while( in(i) != NULL ) {
1006 if (in(i) == n) return; // Avoid spec violation: multiple prec edge.
1007 i++;
1008 }
1009 _in[i] = n; // Stuff prec edge over NULL
1010 if ( n != NULL) n->add_out((Node *)this); // Add mirror edge
1011
1012 #ifdef ASSERT
1013 while ((++i)<_max) { assert(_in[i] == NULL, "spec violation: Gap in prec edges (node %d)", _idx); }
1014 #endif
1015 }
1016
1017 //------------------------------rm_prec----------------------------------------
1018 // Remove a precedence input. Precedence inputs are unordered, with
1019 // duplicates removed and NULLs packed down at the end.
1020 void Node::rm_prec( uint j ) {
1021 if (_in[j] == NULL) return; // Avoid spec violation: Gap in prec edges.
1022
1023 // Find end of precedence list to pack NULLs
1024 uint i;
1025 for( i=j+1; i<_max; i++ ) {
1026 if( !_in[i] ) // Find the NULL at end of prec edge list
1027 break;
1028 }
1029 _in[j]->del_out((Node *)this);
1030 _in[j] = _in[--i]; // Move last element over removed guy
1031 _in[i] = NULL; // NULL out last element
1032 }
1033
1034 //------------------------------size_of----------------------------------------
1035 uint Node::size_of() const { return sizeof(*this); }
1036
1037 //------------------------------ideal_reg--------------------------------------
1038 uint Node::ideal_reg() const { return 0; }
1039
1040 //------------------------------jvms-------------------------------------------
1041 JVMState* Node::jvms() const { return NULL; }
1042
1043 #ifdef ASSERT
1044 //------------------------------jvms-------------------------------------------
1045 bool Node::verify_jvms(const JVMState* using_jvms) const {
1046 for (JVMState* jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {
1047 if (jvms == using_jvms) return true;
1048 }
1049 return false;
|