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

[FIRRTL] Add a BindOp #8384

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

[FIRRTL] Add a BindOp #8384

wants to merge 4 commits into from

Conversation

rwy7
Copy link
Contributor

@rwy7 rwy7 commented Apr 2, 2025

The PR adds a firrtl.bind op. This new bind op is lowered directly to an sv.bind op in LowerToHW.

Today, we create binds by marking firrtl.instance ops as "lowerToBind", which cues LowerToHW to create an SV BindOp for us in the top-level scope, once the marked instance has been lowered to hw.

The reason for a bind op in the FIRRTL dialect, is so that FIRRTL passes can choose the placement of the bind op, such as under an sv.ifdef or emit.file op (which is required for the lowering of bound-in layerblocks). The sv.bind op can only target hw.modules ops, while this new firrtl.bind op targets firrtl.module ops. There are no plans to add bind statements to the FIRRTL surface language. This is just an intermediate lowering for layers.

@rwy7 rwy7 added the FIRRTL Involving the `firrtl` dialect label Apr 2, 2025
rwy7 added 3 commits April 2, 2025 14:36
Currently, FIRRTL instances may be marked as "lowerToBind", which is then
lowered to a HW instance marked "doNotPrint", along with a bind op in the
global scope.

This PR adds a bind op to FIRRTL, which in conjunction with the "doNotPrint"
flag on FIRRTL instances, allows us to choose precisely where the bind
operation goes, rather than having lowerToHW choose for us.
@rwy7 rwy7 marked this pull request as ready for review April 2, 2025 18:37
@rwy7 rwy7 requested review from darthscsi and seldridge as code owners April 2, 2025 18:37
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

I'm good with the approach. I have a question about efficient verification.

Comment on lines +6425 to +6426
if (!inst.getDoNotPrint())
return emitError("Referenced instance isn't marked as doNotPrint");
Copy link
Member

Choose a reason for hiding this comment

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

Fantastic.

Comment on lines +6403 to +6410
Op findInnerSym(StringAttr name, Block *body) {
for (auto &op : llvm::reverse(body->getOperations()))
if (auto target = dyn_cast<Op>(op))
if (auto innerSym = target.getInnerSym())
if (innerSym->getSymName() == name)
return target;
return {};
}
Copy link
Member

Choose a reason for hiding this comment

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

This is very expensive.

Can this be changed to use verifyInnerRefs so that this is done efficiently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FIRRTL Involving the `firrtl` dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants