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

[HWToBTOR2] Generate register initial constant before state declaration #7939

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

TaoBi22
Copy link
Contributor

@TaoBi22 TaoBi22 commented Dec 3, 2024

The BTOR2 parser in btor2tools (which seems to be the standard implementation) requires that in an init statement, the ID of the state must be higher than the ID of the initial value. Currently we don't adhere to this, so we generate BTOR2 that's not digestible by most tools.

E.g. we currently emit

hw.module @breaks(in %clk: !seq.clock, in %in: i32) {
    %c0_i32 = seq.initial() {
        %0 = hw.constant 0 : i32
        seq.yield %0 : i32
    } : () -> !seq.immutable<i32>
    %reg = seq.compreg %input, %clk initial %c0_i32 : i32
    %input = comb.add %in, %in : i32
}

as

1 sort bitvec 1
2 input 1 reset
3 state 1 reg
4 constd 1 0
5 init 1 3 4
6 constd 1 0
7 eq 1 3 6
8 not 1 7
9 bad 8
10 ite 1 2 6 6
11 next 1 3 10

and btormc throws the error btormc: parse error in 'breaking.btor2' line 5: state id must be greater than id of second operand. After this PR we generate

1 sort bitvec 1
2 input 1 reset
3 constd 1 0
4 state 1 reg
5 init 1 4 3
6 constd 1 0
7 eq 1 4 6
8 not 1 7
9 bad 8
10 ite 1 2 6 6
11 next 1 4 10

which parses fine. This breaks a couple of tests that the PR also fixes (might be worth swapping the firtool BTOR2 tests to the normal regexed format at some point to make changes like this less painful).

@TaoBi22 TaoBi22 requested a review from dobios December 3, 2024 13:34
Copy link
Member

@dobios dobios left a comment

Choose a reason for hiding this comment

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

I ran into this issue a few times and it was on my list of things to fix ^^" Thanks for fixing that!

@TaoBi22 TaoBi22 merged commit 3004ca1 into llvm:main Dec 3, 2024
4 checks passed
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