Skip to content
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

[ModuleInliner] Donot retop a HierPathOp if flattening the root #6515

Merged
merged 1 commit into from
Dec 22, 2023

Conversation

prithayan
Copy link
Contributor

@prithayan prithayan commented Dec 12, 2023

If a HierPathOp has a root module that is flattened and inlined, then donot
retop the root module, this results in incorrect HierPathOp that as stale
symbols.
This commit fixes the issue.

@dtzSiFive
Copy link
Contributor

The test case is addressed by -symbol-dce, is there something here that wouldn't be handled by that (possibly + inner-sym-dce)?

@prithayan
Copy link
Contributor Author

The test case is addressed by -symbol-dce, is there something here that wouldn't be handled by that (possibly + inner-sym-dce)?

No, this is expected to do what the symbol-dce would do. But, do we want to run the dce before module-inliner.
My thought was that, if an unused HierPathOp is legal in the IR, then the module-inliner must be able to handle it independently, instead of crashing or being dependent on the dce pass.

@prithayan prithayan force-pushed the dev/pbarua/inliner_unused_nla branch 2 times, most recently from 9697ce0 to 42a037b Compare December 12, 2023 02:25
@dtzSiFive
Copy link
Contributor

Thanks, yes this should not turn legal IR into illegal IR 👍 .

@uenoku
Copy link
Member

uenoku commented Dec 12, 2023

Thank you for investigating the issue and the fix makes sense to me:) I’m a bit concerned about partially duplicating symbol dce logic into inliner. Liveness of symbols is not solely determined by annotations users so this implementation could incorrectly erase hier path ops that are used by other operations such as XMRRef or Verbatim (though I think it won’t happen in the current pass ordering). Instead can we fix the issue by properly updating every hierpath in the IR, or tentatively regard symbol dce as a prepass of inliner? WDYT?

@prithayan
Copy link
Contributor Author

Thank you for investigating the issue and the fix makes sense to me:) I’m a bit concerned about partially duplicating symbol dce logic into inliner. Liveness of symbols is not solely determined by annotations users so this implementation could incorrectly erase hier path ops that are used by other operations such as XMRRef or Verbatim (though I think it won’t happen in the current pass ordering). Instead can we fix the issue by properly updating every hierpath in the IR, or tentatively regard symbol dce as a prepass of inliner? WDYT?

I agree, the correct solution here is to update the inlining algorithm to not rely on the circt.nonlocal annotations, I will try to fix the algorithm, instead of the duplicate dce logic.

@dtzSiFive
Copy link
Contributor

cc #4462

@prithayan prithayan changed the title [ModuleInliner] Remove HierPathOp if not used [ModuleInliner] Donot retop a HierPathOp if flattening the root Dec 22, 2023
@prithayan
Copy link
Contributor Author

After spending hours staring at the code, I realized this is not the issue of removing dead NLAs, this issue exists even if the NLA is referenced from a circt.nonlocal. Seems like a simple fix. I will do some more testing and merge the fix.

@prithayan prithayan merged commit 81543a1 into main Dec 22, 2023
4 checks passed
@prithayan prithayan deleted the dev/pbarua/inliner_unused_nla branch December 22, 2023 05:22
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.

3 participants