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

[LLHD] Add dedicated Mem2Reg pass #8244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fabianschuiki
Copy link
Contributor

@fabianschuiki fabianschuiki commented Feb 15, 2025

Implement a dedicated LLHD pass that promotes signal/memory slots to SSA values and forwards drives to probes. The pass is distinct from MLIR's upstream Mem2Reg pass in that it also works for regions where the memory slots are defined outside the region. It also understands llhd.wait and llhd.halt operations which may suspend execution of a process and therefore allows the values of signals to change before execution resumes. To deal with this, the pass uses a lattice to propagate the need for slot definitions backwards from probes, and to propagate reaching definitions for slots forward from drives and initial probes. Using the lattice, the pass can forward driven values to probes as long as there is no process suspension in between (llhd.wait), and it will insert probes immediately after and drives immediately before suspension points. This moves most intra-process data flow into SSA values and block arguments, and retains probes and drives around the suspension point to interact with ops outside the process.

This first implementation only supports unconditional blocking drives, and only probes and drives that interact with a llhd.sig directly without any field projections or aliasing. The pass is designed to deal with these in the future though: a more detailed aliasing analysis can determine which definitions are invalidated by drives, drives to field projections can be converted into field insertions on the whole definition, and drive conditions can be propagated along definitions to the drives inserted by the pass ahead of suspension points.

Fixes #8245
Fixes #8246

@fabianschuiki fabianschuiki force-pushed the fschuiki/llhd-mem2reg branch 2 times, most recently from ec0efb7 to def82d0 Compare February 18, 2025 22:14
Implement a dedicated LLHD pass that promotes signal/memory slots to SSA
values and forwards drives to probes. The pass is distinct from MLIR's
upstream Mem2Reg pass in that it also works for regions where the memory
slots are defined outside the region. It also understands `llhd.wait`
and `llhd.halt` operations which may suspend execution of a process and
therefore allows the values of signals to change before execution
resumes. To deal with this, the pass uses a lattice to propagate the
need for slot definitions backwards from probes, and to propagate
reaching definitions for slots forward from drives and initial probes.
Using the lattice, the pass can forward driven values to probes as long
as there is no process suspension in between (`llhd.wait`), and it will
insert probes immediately after and drives immediately before suspension
points. This moves most intra-process data flow into SSA values and
block arguments, and retains probes and drives around the suspension
point to interact with ops outside the process.

This first implementation only supports unconditional blocking drives,
and only probes and drives that interact with a `llhd.sig` directly
without any field projections or aliasing. The pass is designed to deal
with these in the future though: a more detailed aliasing analysis can
determine which definitions are invalidated by drives, drives to field
projections can be converted into field insertions on the whole
definition, and drive conditions can be propagated along definitions to
the drives inserted by the pass ahead of suspension points.

Fixes #8245
Fixes #8246
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.

[LLHD] Mem2Reg creates drives to read-only signals [LLHD] Mem2Reg crash on reasonable input
1 participant