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

[Verif] Add StripContracts pass #8144

Merged
merged 1 commit into from
Jan 31, 2025
Merged

Conversation

fabianschuiki
Copy link
Contributor

Add a simple pass that removes all contracts from the IR, treating them as passthroughs. Run the pass in firtool's HW-to-SV pipeline early on to add additional optimization opportunities. ExportVerilog will eventually ignore contracts anyway.

Comment on lines 29 to 41
getOperation()->walk([](ContractOp op) {
op.replaceAllUsesWith(op.getInputs());
op.erase();
});
Copy link
Member

Choose a reason for hiding this comment

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

Pretty degenerate case but does this work in the following case?

%0 = verif.contract %1 : i32 {}
%1 = verif.contract %0 : i32 {}

Copy link
Contributor Author

@fabianschuiki fabianschuiki Jan 29, 2025

Choose a reason for hiding this comment

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

Good thinking. Should work. Let me add this to the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually needed a tweak to avoid an assert in replaceAllUsesWith and to allow op.erase to work if the operation is cycle.

Base automatically changed from fschuiki/verilog-ignore-contracts to main January 29, 2025 23:22
@fabianschuiki fabianschuiki force-pushed the fschuiki/strip-contracts branch from 0ae9834 to 86c1ef0 Compare January 29, 2025 23:31
lib/Firtool/Firtool.cpp Outdated Show resolved Hide resolved
@fabianschuiki fabianschuiki force-pushed the fschuiki/strip-contracts branch from 86c1ef0 to 1c83d54 Compare January 30, 2025 20:08
@fabianschuiki fabianschuiki requested a review from uenoku January 30, 2025 22:02
hw.module @bar() {
// CHECK-NOT: verif.contract
%0 = verif.contract %1 : i42 {}
%1 = verif.contract %0 : i42 {}
Copy link
Member

Choose a reason for hiding this comment

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

What's actually the semantics if we return %1 as an output of the module? Also, the pass would still crash in that case, right? Not really important to fix here though. We have similar issues with comb.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great point, that would still crash. It would be better if it didn't, though. I think in that case we'd want to just not remove the contract. But the semantics are the same as in %0 = comb.add %0, %0; hw.output %0 -- hard to define. Maybe some undefined or poison value, or unknown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this for now by just not removing cyclical contracts.

Add a simple pass that removes all contracts from the IR, treating them
as passthroughs. Run the pass in firtool's HW-to-SV pipeline early on to
add additional optimization opportunities. ExportVerilog will eventually
ignore contracts anyway.
@fabianschuiki fabianschuiki force-pushed the fschuiki/strip-contracts branch from 1c83d54 to cb6bd01 Compare January 30, 2025 22:47
@fabianschuiki fabianschuiki merged commit c4e458f into main Jan 31, 2025
5 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/strip-contracts branch January 31, 2025 01:49
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.

3 participants