| 1303 | } |
| 1304 | |
| 1305 | Status FunctionalizeCond::DetermineAncestorState(Node* dst) { |
| 1306 | StateMap::AncestorId id = nullptr; |
| 1307 | StateMap::AncestorState state; |
| 1308 | |
| 1309 | auto insert = [&](StateMap::AncestorId id, Node* src) { |
| 1310 | auto other_id = state_map_.LookupAncestorId(src); |
| 1311 | if (other_id != id && other_id != nullptr) { |
| 1312 | state.insert(other_id->begin(), other_id->end()); |
| 1313 | } |
| 1314 | if (IsMerge(src)) { |
| 1315 | state.insert({{src, 0}, AncestorNode::AncestorNodeType::kMerge}); |
| 1316 | } else if (IsSwitch(src)) { |
| 1317 | OutputTensor pred; |
| 1318 | // For dead switch nodes, GetSwitchPredicate() will fail, and we use |
| 1319 | // the switch node directly as ancestor. |
| 1320 | if (GetSwitchPredicate(*src, &pred).ok()) { |
| 1321 | state.insert({pred, AncestorNode::AncestorNodeType::kPred}); |
| 1322 | } else { |
| 1323 | state.insert({{src, 0}, AncestorNode::AncestorNodeType::kSwitch}); |
| 1324 | } |
| 1325 | } |
| 1326 | return state_map_.GetAncestorId(state); |
| 1327 | }; |
| 1328 | |
| 1329 | // Compute the union of all the switch/merge nodes that affects the input of |
| 1330 | // dst. |
| 1331 | for (auto e : dst->in_edges()) { |
| 1332 | Node* src = e->src(); |
| 1333 | id = insert(id, src); |
| 1334 | } |
| 1335 | state_map_.ResetAncestorId(dst, id); |
| 1336 | return Status::OK(); |
| 1337 | } |
| 1338 | |
| 1339 | void FunctionalizeCond::DeleteReachableAndDeadNodes( |
| 1340 | const std::vector<Node*>& merge_order) { |
nothing calls this directly
no test coverage detected