| 1286 | } |
| 1287 | |
| 1288 | void MutableGraphView::RemoveNodesInternal( |
| 1289 | const std::vector<RenamedOrOverwrittenNode>& renamed_nodes, |
| 1290 | const std::vector<bool>& overwritten_name_removed_nodes) { |
| 1291 | // Get all nodes overwritten by renamed nodes and remove their fanins. |
| 1292 | std::vector<int> overwritten_nodes; |
| 1293 | overwritten_nodes.reserve(renamed_nodes.size()); |
| 1294 | for (const auto& renamed : renamed_nodes) { |
| 1295 | if (renamed.overwritten_node_index_ != internal::kMissingIndex) { |
| 1296 | auto& node = nodes_[renamed.overwritten_node_index_]; |
| 1297 | RemoveAllFaninFanoutInternal(&node); |
| 1298 | overwritten_nodes.emplace_back(renamed.overwritten_node_index_); |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | // Get all nodes explicitly marked for removal and remove their fanins. |
| 1303 | std::vector<int> node_indices_to_remove; |
| 1304 | node_indices_to_remove.reserve(mutation_.updated_nodes_.size() + |
| 1305 | overwritten_nodes.size()); |
| 1306 | for (int i = 0; i < mutation_.removed_nodes_.size(); ++i) { |
| 1307 | if (mutation_.removed_nodes_[i]) { |
| 1308 | auto& node = nodes_[i]; |
| 1309 | RemoveAllFaninFanoutInternal(&node); |
| 1310 | node_indices_to_remove.push_back(i); |
| 1311 | if (!overwritten_name_removed_nodes[i]) { |
| 1312 | node_index_by_name_.erase(node.GetName()); |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | node_indices_to_remove.insert(node_indices_to_remove.end(), |
| 1317 | overwritten_nodes.begin(), |
| 1318 | overwritten_nodes.end()); |
| 1319 | std::set<int> sorted_node_indices_to_remove(node_indices_to_remove.begin(), |
| 1320 | node_indices_to_remove.end()); |
| 1321 | |
| 1322 | // Iterate in descending order so indices stay consistent. |
| 1323 | for (auto rit = sorted_node_indices_to_remove.rbegin(); |
| 1324 | rit != sorted_node_indices_to_remove.rend(); ++rit) { |
| 1325 | const int removed_node_index = *rit; |
| 1326 | MutableNodeView& last_node = nodes_.back(); |
| 1327 | if (last_node.node_index_ > removed_node_index) { |
| 1328 | last_node.node_index_ = removed_node_index; |
| 1329 | for (auto& regular_fanin : last_node.regular_fanins_) { |
| 1330 | // Update fanouts of regular fanins with new index. |
| 1331 | regular_fanin.node_view() |
| 1332 | ->regular_fanouts_by_port_[regular_fanin.index()] |
| 1333 | [regular_fanin.fanout_index_] |
| 1334 | .node_index_ = removed_node_index; |
| 1335 | } |
| 1336 | for (auto& controlling_fanin : last_node.controlling_fanins_) { |
| 1337 | // Update fanouts of controlling fanins with new index. |
| 1338 | controlling_fanin.node_view() |
| 1339 | ->controlled_fanouts_[controlling_fanin.fanout_index_] |
| 1340 | .node_index_ = removed_node_index; |
| 1341 | } |
| 1342 | for (auto& regular_fanouts : last_node.regular_fanouts_by_port_) { |
| 1343 | for (auto& regular_fanout : regular_fanouts) { |
| 1344 | // Update fanins of regular fanouts. |
| 1345 | MutableNodeView* fanout_node_view = regular_fanout.node_view(); |
nothing calls this directly
no test coverage detected