21#include <unordered_map>
34 assert(op->getNumOutputs() == with->getNumOutputs());
35 for (std::size_t i = 0; i < op->getNumOutputs(); ++i)
37 Operation::Output *
output = op->getOutput(i);
38 output->replaceAllUsesWith(with->getOutput(i));
44 std::deque<Operation *> ready_nodes;
45 std::unordered_map<Operation *, std::size_t> num_visited_input_edges;
50 ready_nodes.push_back(op);
56 if ((op->getNumInputs() == 0) && (op->getType() != Operation::Type::input))
58 ready_nodes.push_back(op);
62 std::vector<Operation *> sorted_nodes;
63 while (!ready_nodes.empty())
65 Operation *src_node = ready_nodes.front();
66 ready_nodes.pop_front();
67 sorted_nodes.push_back(src_node);
68 for (Operation::Output &output : src_node->
getOutputs())
70 for (
const auto use : output.getUses())
73 if (++num_visited_input_edges[dst_node] == dst_node->
getNumInputs())
75 ready_nodes.push_back(dst_node);
94 for (
auto &node : _ops)
105 _inputs.emplace_back(input_op);
108 _outputs.emplace_back(output_op);
113 replaceUsages(op, with);
122 assert(output.getUses().empty() &&
"Trying to remove a node that has uses.");
131 if (op->
getType() == Operation::Type::input)
133 std::remove(_inputs.begin(), _inputs.end(), op));
135 if (op->
getType() == Operation::Type::output)
137 std::remove(_outputs.begin(), _outputs.end(), op));
void replaceNode(Operation *op, Operation *with)
Subsitude node in graph with another keeping all edges.
void removeNode(Operation *op)
remove node from graph, along with its links in other nodes
void accept(IVisitor *visitor)
Interface for visitors Use in MIR component if you want to enforce to implement visits for all operat...
void removeUse(Use use)
Removes the specified use from the uses of this output.
std::size_t getNumInputs() const
Output * getInput(std::size_t index)
std::deque< Output > & getOutputs()
std::vector< Operation * > getSortedNodes(Graph *graph)
Returns nodes of the graph sorted topologically.