Skip to content

Conversation

@fdxmw
Copy link
Member

@fdxmw fdxmw commented Jul 18, 2025

GateGraph is an alternative PyRTL logic representation that attempts to address several issues with PyRTL's standard WireVector and LogicNet representation:

  1. A GateGraph can be directly traversed, without the help of side data structures like the wire_src_dict and wire_sink_dict returned by net_connections.

  2. GateGraph builds a graph where each node is a Gate, and the edges are all references to other Gates. By using only one node type, rather than two (WireVector, LogicNet), it becomes easier to work with the nodes in a GateGraph, because every node is the same type, with the same interface.

  3. GateGraph decouples the user interface and the internal representation. Users directly instantiate WireVectors as they build circuits. A user that is only building circuits should never interact with a GateGraph or a Gate. Users should only interact with GateGraph when they need reflection, which typically happens when writing an analysis or optimization pass.

    Another advantage of this decoupling is that Gate does not need to support WireVector's quality-of-life features for users, like inferring bitwidth from assignment.

I'm migrating output_to_verilog to use this GateGraph representation in a separate change.

…resentation:

`GateGraph` attempts to address several issues with PyRTL's standard
`WireVector` and `LogicNet` representation:

1. A `GateGraph` can be directly traversed, without the help of side data
   structures like the `wire_src_dict` and `wire_sink_dict` returned by
   `net_connections`.

2. `GateGraph` builds a graph where each node is a `Gate`, and the edges are
   all references to other `Gates`. By using only one node type, rather than
   two (`WireVector`, `LogicNet`), it becomes easier to work with the nodes in
   a `GateGraph`, because every node is the same type, with the same interface.

3. `GateGraph` decouples the user interface and the internal representation.
   Users directly instantiate `WireVectors` as they build circuits. A user that
   is only building circuits should never interact with a `GateGraph` or a
   `Gate`. Users should only interact with `GateGraph` when they need
   reflection, which typically happens when writing an analysis or optimization
   pass.

   Another advantage of this decoupling is that `Gate` does not need to support
   `WireVector`'s quality-of-life features for users, like inferring bitwidth
   from assignment.
@codecov
Copy link

codecov bot commented Jul 18, 2025

Codecov Report

❌ Patch coverage is 92.26519% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.3%. Comparing base (370aa4b) to head (875f56a).
⚠️ Report is 7 commits behind head on development.

Files with missing lines Patch % Lines
pyrtl/gate_graph.py 92.3% 14 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           development    #470     +/-   ##
=============================================
+ Coverage         91.3%   91.3%   +0.1%     
=============================================
  Files               24      25      +1     
  Lines             6786    6967    +181     
=============================================
+ Hits              6193    6359    +166     
- Misses             593     608     +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

fdxmw added 4 commits July 18, 2025 16:06
* `dest_fanout` -> `dests`
* `dest_name` -> `name`
* `dest_bitwidth` -> `bitwidth`
* `dest_is_output` -> `is_output

Add documentation on the differences between `LogicNet.dests` and `Gate.dests`.
Minor other documentation improvements.
@fdxmw
Copy link
Member Author

fdxmw commented Jul 21, 2025

I'm planning to merge this pull request tomorrow, so let me know soon if you have comments.

fdxmw added 5 commits July 21, 2025 09:07
…s to.

I'd rather not have this bridge between the two representations, if possible.
It should (eventually) be possible to do everything with only the new `Gate`
representation.

This also adds some more documentation pointers to `GateGraph`.
…'s easier to perform unions and intersections. Add more useful sets of `Gates` like `inputs`, `registers`, etc.
…mem_writes`. Also improve documentation:

- Explain why `Gate` is implemented separately, rather than as a part of `WireVector`.
- Don't publish documentation for `Gate.__init__`, as it should only be called by `GateGraph`.
- Add more examples.
…es between `LogicNet.dests` and `Gate.dests`.
@fdxmw fdxmw merged commit 3deeedd into UCSBarchlab:development Jul 22, 2025
5 checks passed
@fdxmw fdxmw deleted the gate branch July 22, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant