Skip to content

Conversation

@Scheremo
Copy link
Contributor

This patch teaches the ImportVerilog conversion to detect and plumb captured references from enclosing scopes into lowered MLIR functions.

  • FunctionLowering
    • Added captures and captureIndex to record refs captured from outer scopes.
  • Context
    • Added finalizeFunctionBodyCaptures to extend the function signature with captured moore::RefType inputs and replace their in-body uses with the new block arguments.
    • convertFunction now installs a temporary rvalueReadCallback that collects refs read from outside the function’s body.
  • Expressions
    • When lowering subroutine calls, the visitor now appends any captured operands to the call argument list. Captures are verified to be moore::RefType values originating from the enclosing (module) region.

Together these changes allow nested or free functions to reference module-level signals (logic, etc.) correctly in the generated MLIR, with explicit function parameters modeling captured variables.

@Scheremo Scheremo marked this pull request as ready for review October 17, 2025 22:03
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

Really cool! LGTM!

This patch teaches the ImportVerilog conversion to detect and plumb captured
references from enclosing scopes into lowered MLIR functions.

- **FunctionLowering**
  - Added `captures` and `captureIndex` to record refs captured from outer
    scopes.
- **Context**
  - Added `finalizeFunctionBodyCaptures` to extend the function signature with
    captured `moore::RefType` inputs and replace their in-body uses with the
    new block arguments.
  - `convertFunction` now installs a temporary `rvalueReadCallback` that
    collects refs read from outside the function’s body.
- **Expressions**
  - When lowering subroutine calls, the visitor now appends any captured
    operands to the call argument list. Captures are verified to be
    `moore::RefType` values originating from the enclosing (module) region.

Together these changes allow nested or free functions to reference module-level
signals (`logic`, etc.) correctly in the generated MLIR, with explicit
function parameters modeling captured variables.
@Scheremo Scheremo force-pushed the pr-function-captures branch from 27eb57c to 92550f5 Compare October 18, 2025 10:11
@Scheremo Scheremo merged commit 8c321f9 into llvm:main Oct 18, 2025
7 checks passed
@Scheremo Scheremo deleted the pr-function-captures branch October 21, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants