copapy.backend.canonicalize#

copapy.backend.canonicalize(roots)#

Rebuild a DAG with all equivalent nodes merged (common subexpression elimination). The identity of each node is looked up in an id table.

The given DAG is not changed: nodes are copied if their arguments are replaced, otherwise the nodes and nets are reused. In the returned DAG each node has exactly one result net.

Parameters:

roots (Iterable[Node]) – End nodes of the DAG

Return type:

tuple[list[Node], dict[Net, Net]]

Returns:

Tuple of the end nodes of the canonical DAG and a dict to look up the canonical net for each net of the given DAG