740 if (in == n) { 741 no_dead_loop = false; 742 } else if (in != NULL && !in->is_dead_loop_safe()) { 743 uint icnt = in->req(); 744 for (uint j = 1; j < icnt && no_dead_loop; j++) { 745 if (in->in(j) == n || in->in(j) == in) 746 no_dead_loop = false; 747 } 748 } 749 } 750 if (!no_dead_loop) n->dump(3); 751 assert(no_dead_loop, "dead loop detected"); 752 } 753 } 754 #endif 755 756 //============================================================================= 757 //------------------------------PhaseIterGVN----------------------------------- 758 // Initialize hash table to fresh and clean for +VerifyOpto 759 PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn, const char *dummy ) : PhaseGVN(igvn,dummy), _worklist( ), 760 _delay_transform(false) { 761 } 762 763 //------------------------------PhaseIterGVN----------------------------------- 764 // Initialize with previous PhaseIterGVN info; used by PhaseCCP 765 PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn ) : PhaseGVN(igvn), 766 _worklist( igvn->_worklist ), 767 _delay_transform(igvn->_delay_transform) 768 { 769 } 770 771 //------------------------------PhaseIterGVN----------------------------------- 772 // Initialize with previous PhaseGVN info from Parser 773 PhaseIterGVN::PhaseIterGVN( PhaseGVN *gvn ) : PhaseGVN(gvn), 774 _worklist(*C->for_igvn()), 775 _delay_transform(false) 776 { 777 uint max; 778 779 // Dead nodes in the hash table inherited from GVN were not treated as 780 // roots during def-use info creation; hence they represent an invisible 781 // use. Clear them out. 782 max = _table.size(); 783 for( uint i = 0; i < max; ++i ) { 784 Node *n = _table.at(i); 785 if(n != NULL && n != _table.sentinel() && n->outcnt() == 0) { 786 if( n->is_top() ) continue; 787 assert( false, "Parse::remove_useless_nodes missed this node"); 788 hash_delete(n); 789 } 790 } 791 792 // Any Phis or Regions on the worklist probably had uses that could not 793 // make more progress because the uses were made while the Phis and Regions 794 // were in half-built states. Put all uses of Phis and Regions on worklist. 1121 NOT_PRODUCT( set_progress(); ) 1122 add_users_to_worklist( k ); 1123 subsume_node( k, i ); // Everybody using k now uses i 1124 return i; 1125 } 1126 1127 // Return Idealized original 1128 return k; 1129 } 1130 1131 //---------------------------------saturate------------------------------------ 1132 const Type* PhaseIterGVN::saturate(const Type* new_type, const Type* old_type, 1133 const Type* limit_type) const { 1134 return new_type->narrow(old_type); 1135 } 1136 1137 //------------------------------remove_globally_dead_node---------------------- 1138 // Kill a globally dead Node. All uses are also globally dead and are 1139 // aggressively trimmed. 1140 void PhaseIterGVN::remove_globally_dead_node( Node *dead ) { 1141 assert(dead != C->root(), "killing root, eh?"); 1142 if (dead->is_top()) return; 1143 NOT_PRODUCT( set_progress(); ) 1144 // Remove from iterative worklist 1145 _worklist.remove(dead); 1146 if (!dead->is_Con()) { // Don't kill cons but uses 1147 // Remove from hash table 1148 _table.hash_delete( dead ); 1149 // Smash all inputs to 'dead', isolating him completely 1150 for( uint i = 0; i < dead->req(); i++ ) { 1151 Node *in = dead->in(i); 1152 if( in ) { // Points to something? 1153 dead->set_req(i,NULL); // Kill the edge 1154 if (in->outcnt() == 0 && in != C->top()) {// Made input go dead? 1155 remove_dead_node(in); // Recursively remove 1156 } else if (in->outcnt() == 1 && 1157 in->has_special_unique_user()) { 1158 _worklist.push(in->unique_out()); 1159 } else if (in->outcnt() <= 2 && dead->is_Phi()) { 1160 if( in->Opcode() == Op_Region ) 1161 _worklist.push(in); 1162 else if( in->is_Store() ) { 1163 DUIterator_Fast imax, i = in->fast_outs(imax); 1164 _worklist.push(in->fast_out(i)); 1165 i++; 1166 if(in->outcnt() == 2) { 1167 _worklist.push(in->fast_out(i)); 1168 i++; 1169 } 1170 assert(!(i < imax), "sanity"); 1171 } 1172 } 1173 } 1174 } 1175 1176 if (dead->is_macro()) { 1177 C->remove_macro_node(dead); 1178 } 1179 } 1180 // Aggressively kill globally dead uses 1181 // (Cannot use DUIterator_Last because of the indefinite number 1182 // of edge deletions per loop trip.) 1183 while (dead->outcnt() > 0) { 1184 remove_globally_dead_node(dead->raw_out(0)); 1185 } 1186 } 1187 1188 //------------------------------subsume_node----------------------------------- 1189 // Remove users from node 'old' and add them to node 'nn'. 1190 void PhaseIterGVN::subsume_node( Node *old, Node *nn ) { 1191 assert( old != hash_find(old), "should already been removed" ); 1192 assert( old != C->top(), "cannot subsume top node"); 1193 // Copy debug or profile information to the new version: 1194 C->copy_node_notes_to(nn, old); 1195 // Move users of node 'old' to node 'nn' 1196 for (DUIterator_Last imin, i = old->last_outs(imin); i >= imin; ) { 1197 Node* use = old->last_out(i); // for each use... 1198 // use might need re-hashing (but it won't if it's a new node) 1199 bool is_in_table = _table.hash_delete( use ); 1200 // Update use-def info as well 1201 // We remove all occurrences of old within use->in, 1202 // so as to avoid rehashing any node more than once. 1203 // The hash table probe swamps any outer loop overhead. 1204 uint num_edges = 0; | 740 if (in == n) { 741 no_dead_loop = false; 742 } else if (in != NULL && !in->is_dead_loop_safe()) { 743 uint icnt = in->req(); 744 for (uint j = 1; j < icnt && no_dead_loop; j++) { 745 if (in->in(j) == n || in->in(j) == in) 746 no_dead_loop = false; 747 } 748 } 749 } 750 if (!no_dead_loop) n->dump(3); 751 assert(no_dead_loop, "dead loop detected"); 752 } 753 } 754 #endif 755 756 //============================================================================= 757 //------------------------------PhaseIterGVN----------------------------------- 758 // Initialize hash table to fresh and clean for +VerifyOpto 759 PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn, const char *dummy ) : PhaseGVN(igvn,dummy), _worklist( ), 760 _stack(C->unique() >> 1), 761 _delay_transform(false) { 762 } 763 764 //------------------------------PhaseIterGVN----------------------------------- 765 // Initialize with previous PhaseIterGVN info; used by PhaseCCP 766 PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn ) : PhaseGVN(igvn), 767 _worklist( igvn->_worklist ), 768 _stack( igvn->_stack ), 769 _delay_transform(igvn->_delay_transform) 770 { 771 } 772 773 //------------------------------PhaseIterGVN----------------------------------- 774 // Initialize with previous PhaseGVN info from Parser 775 PhaseIterGVN::PhaseIterGVN( PhaseGVN *gvn ) : PhaseGVN(gvn), 776 _worklist(*C->for_igvn()), 777 _stack(C->unique() >> 1), 778 _delay_transform(false) 779 { 780 uint max; 781 782 // Dead nodes in the hash table inherited from GVN were not treated as 783 // roots during def-use info creation; hence they represent an invisible 784 // use. Clear them out. 785 max = _table.size(); 786 for( uint i = 0; i < max; ++i ) { 787 Node *n = _table.at(i); 788 if(n != NULL && n != _table.sentinel() && n->outcnt() == 0) { 789 if( n->is_top() ) continue; 790 assert( false, "Parse::remove_useless_nodes missed this node"); 791 hash_delete(n); 792 } 793 } 794 795 // Any Phis or Regions on the worklist probably had uses that could not 796 // make more progress because the uses were made while the Phis and Regions 797 // were in half-built states. Put all uses of Phis and Regions on worklist. 1124 NOT_PRODUCT( set_progress(); ) 1125 add_users_to_worklist( k ); 1126 subsume_node( k, i ); // Everybody using k now uses i 1127 return i; 1128 } 1129 1130 // Return Idealized original 1131 return k; 1132 } 1133 1134 //---------------------------------saturate------------------------------------ 1135 const Type* PhaseIterGVN::saturate(const Type* new_type, const Type* old_type, 1136 const Type* limit_type) const { 1137 return new_type->narrow(old_type); 1138 } 1139 1140 //------------------------------remove_globally_dead_node---------------------- 1141 // Kill a globally dead Node. All uses are also globally dead and are 1142 // aggressively trimmed. 1143 void PhaseIterGVN::remove_globally_dead_node( Node *dead ) { 1144 enum DeleteProgress { 1145 PROCESS_INPUTS, 1146 PROCESS_OUTPUTS 1147 }; 1148 assert(_stack.is_empty(), "not empty"); 1149 _stack.push(dead, PROCESS_INPUTS); 1150 1151 while (_stack.is_nonempty()) { 1152 dead = _stack.node(); 1153 uint progress_state = _stack.index(); 1154 assert(dead != C->root(), "killing root, eh?"); 1155 assert(!dead->is_top(), "add check for top when pushing"); 1156 NOT_PRODUCT( set_progress(); ) 1157 if (progress_state == PROCESS_INPUTS) { 1158 // After following inputs, continue to outputs 1159 _stack.set_index(PROCESS_OUTPUTS); 1160 // Remove from iterative worklist 1161 _worklist.remove(dead); 1162 if (!dead->is_Con()) { // Don't kill cons but uses 1163 bool recurse = false; 1164 // Remove from hash table 1165 _table.hash_delete( dead ); 1166 // Smash all inputs to 'dead', isolating him completely 1167 for( uint i = 0; i < dead->req(); i++ ) { 1168 Node *in = dead->in(i); 1169 if( in ) { // Points to something? 1170 dead->set_req(i,NULL); // Kill the edge 1171 if (in->outcnt() == 0 && in != C->top()) {// Made input go dead? 1172 _stack.push(in, PROCESS_INPUTS); // Recursively remove 1173 recurse = true; 1174 } else if (in->outcnt() == 1 && 1175 in->has_special_unique_user()) { 1176 _worklist.push(in->unique_out()); 1177 } else if (in->outcnt() <= 2 && dead->is_Phi()) { 1178 if( in->Opcode() == Op_Region ) 1179 _worklist.push(in); 1180 else if( in->is_Store() ) { 1181 DUIterator_Fast imax, i = in->fast_outs(imax); 1182 _worklist.push(in->fast_out(i)); 1183 i++; 1184 if(in->outcnt() == 2) { 1185 _worklist.push(in->fast_out(i)); 1186 i++; 1187 } 1188 assert(!(i < imax), "sanity"); 1189 } 1190 } 1191 } 1192 } 1193 1194 if (dead->is_macro()) { 1195 C->remove_macro_node(dead); 1196 } 1197 1198 if (recurse) { 1199 continue; 1200 } 1201 } 1202 } 1203 1204 // Aggressively kill globally dead uses 1205 // (Rather than pushing all the outs at once, we push one at a time, 1206 // plus the parent to resume later, because of the indefinite number 1207 // of edge deletions per loop trip.) 1208 if (dead->outcnt() > 0) { 1209 // Recursively remove 1210 _stack.push(dead->raw_out(0), PROCESS_INPUTS); 1211 } else { 1212 _stack.pop(); 1213 } 1214 } 1215 } 1216 1217 //------------------------------subsume_node----------------------------------- 1218 // Remove users from node 'old' and add them to node 'nn'. 1219 void PhaseIterGVN::subsume_node( Node *old, Node *nn ) { 1220 assert( old != hash_find(old), "should already been removed" ); 1221 assert( old != C->top(), "cannot subsume top node"); 1222 // Copy debug or profile information to the new version: 1223 C->copy_node_notes_to(nn, old); 1224 // Move users of node 'old' to node 'nn' 1225 for (DUIterator_Last imin, i = old->last_outs(imin); i >= imin; ) { 1226 Node* use = old->last_out(i); // for each use... 1227 // use might need re-hashing (but it won't if it's a new node) 1228 bool is_in_table = _table.hash_delete( use ); 1229 // Update use-def info as well 1230 // We remove all occurrences of old within use->in, 1231 // so as to avoid rehashing any node more than once. 1232 // The hash table probe swamps any outer loop overhead. 1233 uint num_edges = 0; |