llvm / circt

Circuit IR Compilers and Tools
https://circt.org
Other
1.64k stars 285 forks source link

[Moore] Fix the stacking fault caused by cast and remove unused headers #7219

Closed hailongSun2000 closed 3 months ago

hailongSun2000 commented 3 months ago

Because every variable/net has been used by other ops. We must first read it. For example:

module foo(input clk, en, cin);
  reg q;
  always@(posedge clk) begin
          if(en) begin
             q <= cin;
          end
  end
endmodule      
moore.module @foo(in %clk : !moore.l1, in %en : !moore.l1, in %cin : !moore.l1) {
    %clk_0 = moore.net name "clk" wire : <l1>
    %en_1 = moore.net name "en" wire : <l1>
    %cin_2 = moore.net name "cin" wire : <l1>
    %q = moore.variable : <l1>
    moore.procedure always {
      %0 = moore.read %clk_0 : l1
      moore.wait_event posedge %0 : l1
      %1 = moore.read %en_1 : l1
      %2 = moore.conversion %1 : !moore.l1 -> i1
      scf.if %2 {
        %3 = moore.read %cin_2 : l1
        moore.nonblocking_assign %q, %3 : l1
      }
    }
    moore.assign %clk_0, %clk : l1
    moore.assign %en_1, %en : l1
    moore.assign %cin_2, %cin : l1
    moore.output
  }

SimplifyProcedures is through visit moore.read to get the user, but the user may be moore.net such as "clk". This situation will cause a segmentation fault.