-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cxxrtl: Fix liveness checking for debug wires #2541
Conversation
Currently, it seems that this fix can generate unused variables in the output source when on -g4 with a design that fails without the commit. I'm not positive what causes this and will have the follow the liveness checking logic in more detail to see where truely unused signals are getting reintroduced into the design. |
This comment has been minimized.
This comment has been minimized.
BackgroundAfter much effort I think I've fully determined the scope of the issue. During the first pass of debug info generation, public wires are tagged with initial types to use during the debug path, however, when a wire is tagged as yosys/backends/cxxrtl/cxxrtl_backend.cc Lines 2600 to 2610 in 339848b
The second condition is only done when debug eval is enabled (which is where this issue occurs i.e. The problem comes when we try to later use these aliases. Due to the way the code is structured, these aliased wires will be generated, but if they alias a member wire, it won't be tagged as "live". This is because we don't want to change non-debug state members in Not being tagged as live means that they'll skip the second phase of assigning The FixMy original fix was to consider all the wires that were live for the optimized We shouldn't have unused variables though, since we know all the cells being generated and what their inputs and outputs are, this should be enough to only emit the used portions. So this solution isn't ideal. The revised solution accomplishes this by also checking if the wire is a member variable from the optimized design and considering those variables to be live also. This will result in this logic being run: yosys/backends/cxxrtl/cxxrtl_backend.cc Lines 2668 to 2671 in 339848b
Which will accomplish the task of assigning member variables in the design as "used" by debug, but no more. This gets rid of the extra locals and seems to completely solve the problem. |
I'm sorry I don't have the expertise to review your PR (that will have to wait for @whitequark), but please write a better header line than "fix #bugnumber" and rename the PR appropriately — something like "cxxrtl: fix liveness checking for debug wires" would be perfect. |
Sorry about that, at the time I was trying to focus the discussion down into the issue itself since at first I had written an explanation there and thought it was going to be a quick simple patch. It ends up that it's not quite so straightforward and I never updated it later. I see you updated the title for me already, so I went ahead and gave a more meaningful summary in the description too. |
Superseded by #2871. |
The current liveness checking for cxxrtl breaks in certain esoteric cases. Notably when signals that were completely optimized out get reintroduced into the design (so called "outline wires") those wires are wholly calculated inside the debug pass, this is because we want to keep the optimized code for the main eval pass and only do the full computation if the debug state is requested explicitly.
Due to some annoyances of yosys itself, it's actually somewhat difficult to have public wires in a design that are unused, as at some point earlier (likely the flatten pass?) yosys has essentially renamed the public signal into a internal unnamed signal, since cxxrtl only generates this additional debug information for used public signals (i.e. ones that are optimized out but not completely unused), this feature currently mostly goes to waste.
Issue #2540 managed to find a test case that actually triggered the generation of these "compute on demand" outline wires, revealing that it wasn't tagging all the proper wires as "live" and used during debug that it should have, causing asserts to fail while generating the debug pass. The details of the problem and proposed fix are explained further in a comment below.