fabianschuiki / llhd

Low Level Hardware Description — A foundation for building hardware design tools.
http://www.llhd.io
Apache License 2.0
392 stars 30 forks source link

TCM causes inst-already-inserted panic #146

Closed fabianschuiki closed 3 years ago

fabianschuiki commented 3 years ago
proc %always_ff (i1$ %clk_i, i1$ %rst_i, i32$ %pc_d) -> (i32$ %pc_q) {
0:
    br %init
init:
    %clk_i1 = prb i1$ %clk_i
    wait %check, %clk_i
check:
    %clk_i2 = prb i1$ %clk_i
    %1 = const i1 0
    %2 = eq i1 %clk_i1, %1
    %3 = neq i1 %clk_i2, %1
    %posedge = and i1 %2, %3
    br %posedge, %init, %event
event:
    %rst_i1 = prb i1$ %rst_i
    %4 = const i32 65536
    %pc_d1 = prb i32$ %pc_d
    %5 = [i32 %pc_d1, %4]
    %6 = mux [2 x i32] %5, i1 %rst_i1
    %7 = const time 0s 1d
    drv i32$ %pc_q, %6, %7
    br %0
}

causes llhd-opt to panic with inst i0 already inserted in bb0, now being inserted into bb0, with the following backtrace:

  13: llhd::ir::layout::FunctionLayout::map_inst
             at src/ir/layout.rs:54
  14: llhd::ir::unit::UnitBuilder::append_inst
             at src/ir/unit.rs:1298
  15: llhd::ir::unit::UnitBuilder::build_inst
             at src/ir/unit.rs:736
  16: llhd::ir::inst::InstBuilder::build
             at src/ir/inst.rs:660
  17: llhd::ir::inst::InstBuilder::br
             at src/ir/inst.rs:567
  18: llhd::pass::tcm::add_aux_blocks
             at src/pass/tcm.rs:180
  19: <llhd::pass::tcm::TemporalCodeMotion as llhd::opt::pass::Pass>::run_on_cfg
             at src/pass/tcm.rs:131