template <bool is_const>
void Graph::PostDfsIterator<is_const>::iterate(GraphRef graph, const IterFn &fn) const
{
+ assert(!graph.isBuildingPhase()); // Restrict iteration condition
+
std::vector<bool> visited(graph._operations.size(), false);
std::function<void(const operation::Index &, NodeRef)> dfs_recursive =
return;
visited[index.asInt()] = true;
- auto outputs = node.getOutputs();
- for (auto output : outputs)
+ for (auto output : node.getOutputs())
{
- // TODO Fix traversing algorithm
- // Every time need to search for operations that has `outgoing` as incoming from all
- // operations but we can hold that info cached
- graph._operations.iterate([&](const operation::Index &cand_index, NodeRef cand_node) -> void {
- auto inputs = cand_node.getInputs();
- for (auto input : inputs)
- {
- if (output == input)
- {
- dfs_recursive(cand_index, cand_node);
- }
- }
- });
+ const auto &operand = graph._operands.at(output);
+ for (const auto &use : operand.getUses().list())
+ {
+ dfs_recursive(use, graph._operations.at(use));
+ }
}
fn(node);
void finishBuilding(void);
void lower(void);
std::unique_ptr<linear::Linear> linearize(void);
- bool isBuildingPhase(void) { return _phase == Phase::BUILDING; }
+ bool isBuildingPhase(void) const { return _phase == Phase::BUILDING; }
private:
void initializeUseDef();