Skip to content

[circt-verilog][llhd][arcilator] Verilog-to-LLVM lowering issues #8286

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

Open
likeamahoney opened this issue Mar 3, 2025 · 2 comments
Open

Comments

@likeamahoney
Copy link
Contributor

likeamahoney commented Mar 3, 2025

Hi all!

There are a few issues related to moore to llvm lowering pipeline.

Currently there is no possibility to lower combination logic with control flow operators into LLVM. For example:

module  top  (
    input           clk ,
    input           rstn ,
    input      in
    output     out
    );

    parameter            P1   = 3'd0 ;
    parameter            P2  = 3'd3 ;

    reg [2:0]            r1 = 3'd1;

    always_comb begin
        if (in)
            r1 = P1;
        else
            r1 = P2;
    end
endmodule

because it fails with this : error: failed to legalize operation 'llhd.constant_time'

And also arcilator fails to lower sequential logic which contains both blocking and nonblocking assignments like this example:

module  top  (
    input           clk ,
    input           rstn ,
    input      in
    output     out
    );

    parameter            P1   = 3'd0 ;
    parameter            P2  = 3'd3 ;

    reg [2:0]            r1 = 3'd1;

    always @(posedge clk or negedge rstn) begin
        r1 = P1;
        r1 <= P2 + r1;
    end

endmodule

because it fails with that:

 error: body contains non-pure operation
    %2 = comb.add %1, %c3_i3 : i3

I'm using to lower a such cmd:

circt-verilog sample.sv | arcilator 

Also I tried to add into "populate LLHD" pipeline a newly added passes -- "llhd-hoist-signals" and "llhd-mem2reg". It didn't help.

Maybe I'm doing something wrong or what could be the issue?

  1. What are the plans for improving verilog-to-llvm lowering and do they exist at all?
  2. Will the "llhd-hoist-signals" and "llhd-mem2reg" passes be added to the circt-verilog tool or will they stay standalone?

@fabianschuiki @maerhart

@fabianschuiki
Copy link
Contributor

Thanks for the fantastic issue report @likeamahoney! 🥳 The HoistSignals and Mem2Reg passes are an effort to make the Verilog lowering to HW and Arcilator/LLVM more reliable. The idea is to run Mem2Reg and then HoistSignals to simplify processes, then run an improved version of Desequentialize to detect registers/latches and factor them out, and then convert the LLHD processes to scf.execute_regions. At that point Arcilator should be able to simulate basic synthesizable structures. A bit later, we'll want to add support for the LLHD dialect to Arcilator, such that it can simulate the progression of physical time and maintain an event queue where it's needed.

So the idea is definitely to get this into a shape where it can deal with any Verilog you throw at it 😁

@likeamahoney
Copy link
Contributor Author

Thanks for the fantastic issue report @likeamahoney! 🥳 The HoistSignals and Mem2Reg passes are an effort to make the Verilog lowering to HW and Arcilator/LLVM more reliable. The idea is to run Mem2Reg and then HoistSignals to simplify processes, then run an improved version of Desequentialize to detect registers/latches and factor them out, and then convert the LLHD processes to scf.execute_regions. At that point Arcilator should be able to simulate basic synthesizable structures. A bit later, we'll want to add support for the LLHD dialect to Arcilator, such that it can simulate the progression of physical time and maintain an event queue where it's needed.

So the idea is definitely to get this into a shape where it can deal with any Verilog you throw at it 😁

Thank you very much for writing a detailed roadmap. I really hope that soon it will be possible to simulate large SystemVerilog designs on the arcilator.

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

No branches or pull requests

2 participants