8000 [LLHD] Add support for `llhd.sig.array_get` projections to Mem2Reg by fabianschuiki · Pull Request #8509 · llvm/circt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[LLHD] Add support for llhd.sig.array_get projections to Mem2Reg #8509

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

Merged
merged 1 commit into from
May 23, 2025

Conversation

fabianschuiki
Copy link
Contributor

Extend the Mem2Reg pass to support drives to llhd.sig.array_get projections into a promotable signal. This requires a few changes:

  • When checking whether a signal is promotable, we have to recursively check its users and look through llhd.sig.array_get ops to see if all uses are safe for promotion.

  • The lattice used to propagate needed and reaching definitions has to track the projection being driven separately from the underlying root slot being driven.

  • A new set of helpers to unpack and pack stacks of projections help probes and drives take a promotable slot and its value, descend into subfields as indicated by a set of projection ops ("unpack"), and then optionally mutate the value of a subfield and zip the updated value back up to the promotable slot ("pack").

  • During backward and forward propagation across the lattice, drives to projections have to create the need for a definition of the slot to be available because they have to take the slot's current value in order to mutate the projected field.

  • The functions that resolve definitions have to unpack a slot's value according to the projections between the probe and the slot. In case of a drive they also have to mutate the projected field value after unpacking and then pack everything back op in order to create a new reaching definition for the entire slot to be forwarded to readers.

This commit also drops slotOrder in favor of a promotable set of values. The actual order of slots was never used.

llhd.halt
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add tests for the following scenarios:

  • Projected signal value is passed via block argument within a process (make sure it doesn't crash)
  • Multiple projection ops refer to the same part of the original signal (make sure multiple drives to these different projections that refer to the same part update to the correct value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops good idea, that's definitely missing from the tests. Let me add that.

// as any of their users.
if (isa<SigArrayGetOp>(user)) {
for (auto *projectionUser : user->getUsers()) {
if (projectionUser->getBlock() != user->getBlock())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that too restrictive for many practical cases due to CSE of projection ops? (not blocking)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's a good point 👍. We should be able to relax this by only requiring that the projection op dominates its users. That would also allow projections in dominating predecessor blocks and in the module to be covered, but still allow us to not reason about signals references through block arguments (that'll be a mighty headache).

@fabianschuiki fabianschuiki force-pushed the fschuiki/mem2reg-projections branch from 1d733ad to a59ef60 Compare May 23, 2025 17:29
Extend the Mem2Reg pass to support drives to `llhd.sig.array_get`
projections into a promotable signal. This requires a few changes:

- When checking whether a signal is promotable, we have to recursively
  check its users and look through `llhd.sig.array_get` ops to see if
  all uses are safe for promotion.

- The lattice used to propagate needed and reaching definitions has to
  track the projection being driven separately from the underlying root
  slot being driven.

- A new set of helpers to unpack and pack stacks of projections help
  probes and drives take a promotable slot and its value, descend into
  subfields as indicated by a set of projection ops ("unpack"), and then
  optionally mutate the value of a subfield and zip the updated value
  back up to the promotable slot ("pack").

- During backward and forward propagation across the lattice, drives to
  projections have to create the need for a definition of the slot to be
  available because they have to take the slot's current value in order
  to mutate the projected field.

- The functions that resolve definitions have to unpack a slot's value
  according to the projections between the probe and the slot. In case
  of a drive they also have to mutate the projected field value after
  unpacking and then pack everything back op in order to create a new
  reaching definition for the entire slot to be forwarded to readers.

This commit also drops `slotOrder` in favor of a `promotable` set of
values. The actual order of slots was never used.
@fabianschuiki fabianschuiki force-pushed the fschuiki/mem2reg-projections branch from a59ef60 to f8bba03 Compare May 23, 2025 17:41
@fabianschuiki fabianschuiki merged commit 0d8106e into main May 23, 2025
5 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/mem2reg-projections branch May 23, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0