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

[SV][Prepare] Improve a namehint propagation and spilling logic #4261

Merged
merged 2 commits into from
Nov 9, 2022

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented Nov 7, 2022

This implements a name hint propagation to a wire op canonicalization.

%foo = sv.wire
%0 = comb.add ....
sv.assign %foo, %0
...

will be converted into

%0 = comb.add {sv.namehint = "foo"}
...

This also improves wire spilling logic by allowing expressions used only procedural assignments.

@uenoku uenoku force-pushed the dev/uenoku/improve-namehints-prop2 branch from 7e0e830 to b5844c2 Compare November 7, 2022 17:38
Copy link
Contributor

@mikeurbach mikeurbach 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 not sure about the change to PrepareForEmission, but the update in the wire canonicalizer looks great. I think this is always going to be an improvement, but I do wonder what about if the existing expression already had a namehint. I guess the name of the wire is a "stronger" hint, so I think what you have here looks good.

@@ -615,8 +615,7 @@ bool EmittedExpressionStateManager::shouldSpillWireBasedOnState(Operation &op) {
// If the operation is only used by an assignment, the op is already spilled
// to a wire.
if (op.hasOneUse() &&
isa<hw::OutputOp, sv::AssignOp, sv::BPAssignOp, sv::PAssignOp>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was sv::PAssignOp removed here? Is this maybe an unrelated change that snuck in? I wouldn't think this is required for this change.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is unrelated to the PR but it's necessary for name propagation improvement. I'll split a PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't have to be a separate PR if it's related, I'm just curious why it is necessary here, since we are only updating the canonicalizer or wires.

Copy link
Member Author

Choose a reason for hiding this comment

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

The condition was intended to avoid spilling same expressions twice by skipping expressions that have single use of assignments. Therefore an expression used by procedural assignments was not spilled to a wire. For example,

%0 = comb.add {sv.namehint = "good_name"}
sv.always .. {
   sv.passign %reg, %0 : ..
}

In this case %0 was inlined to the assignment, but we want to create a wire for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, so I think this makes sense then. In general, I guess it's all about tradeoffs, so trading off some inlining for better names sounds good to me.

lib/Dialect/SV/SVOps.cpp Outdated Show resolved Hide resolved
@uenoku
Copy link
Member Author

uenoku commented Nov 8, 2022

I do wonder what about if the existing expression already had a namehint. I guess the name of the wire is a "stronger" hint, so I think what you have here looks good.

Right, currently a name on a wire overwrites expressions's namehint. The intention is that the name on the wire is generally better than a namehint. I agree we might want to introduce a notion of priority of names.

@uenoku uenoku changed the title [SV] Propagate a namehint through wire canonicalization [SV]{Prepare] Improve a namehint propagation and spilling heuristic Nov 8, 2022
@uenoku uenoku changed the title [SV]{Prepare] Improve a namehint propagation and spilling heuristic [SV]{Prepare] Improve a namehint propagation and spilling logic Nov 8, 2022
@uenoku uenoku changed the title [SV]{Prepare] Improve a namehint propagation and spilling logic [SV][Prepare] Improve a namehint propagation and spilling logic Nov 9, 2022
@uenoku uenoku merged commit cf770ec into main Nov 9, 2022
@uenoku uenoku deleted the dev/uenoku/improve-namehints-prop2 branch November 9, 2022 09:00
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.

2 participants