| 963 | } |
| 964 | |
| 965 | Status FunctionalizeCond::PropagateUpdatedState(const Node* replacee) { |
| 966 | VLOG(2) << "Propagating update state for " << replacee->name() << " " |
| 967 | << state_map_.CondStateToString(replacee); |
| 968 | // Redo topological sort as the order could have changed. |
| 969 | // TODO(jpienaar): The original topological order could also be updated |
| 970 | // dynamically if needed. |
| 971 | std::vector<Node*> rev_topo_order; |
| 972 | GetPostOrder(*graph_, &rev_topo_order); |
| 973 | |
| 974 | // All the outputs of the new node could potentially be updated. |
| 975 | std::unordered_set<Node*> changed; |
| 976 | for (auto n : replacee->out_nodes()) |
| 977 | if (n->IsOp()) changed.insert(n); |
| 978 | |
| 979 | // Iterate through the changed/possible changed nodes in topological order. |
| 980 | for (auto it = rev_topo_order.rbegin(); |
| 981 | it != rev_topo_order.rend() && !changed.empty(); ++it) { |
| 982 | if (changed.find(*it) != changed.end()) { |
| 983 | // Update the node state. |
| 984 | Node* n = *it; |
| 985 | StateMap::CondId old_state = state_map_.LookupCondId(n); |
| 986 | state_map_.ResetCondId(n, nullptr); |
| 987 | TF_RETURN_IF_ERROR(DetermineCondState(n)); |
| 988 | if (state_map_.LookupCondId(n) != old_state) { |
| 989 | for (auto out : n->out_nodes()) |
| 990 | if (out->IsOp()) changed.insert(out); |
| 991 | } |
| 992 | changed.erase(n); |
| 993 | } |
| 994 | } |
| 995 | return Status::OK(); |
| 996 | } |
| 997 | |
| 998 | // Returns the most restrictive branch of two branches or neither. This is the |
| 999 | // meet operator of the BranchType lattice. |
no test coverage detected