You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
XLS fails to detect hierarchical combinational ready/valid loops (cycles that cross instantiation boundaries) when using Codegen 1.5. This allows XLS to compile the design successfully and output Verilog, which subsequently fails synthesis in downstream EDA tools (like Yosys) due to logic loops.
The cycle is correctly detected by Codegen 1.0, but is missed in Codegen 1.5 because the Codegen 1.5 entry point (codegen::Codegen in xls/codegen_v_1_5/codegen.cc) does not execute VerifyPackage or any invariant checkers on the final block hierarchy. Note it's possible other checkers that aren't being run through VerifyPackage may manifest as other issues but they are not analyzed here.
To Reproduce
Steps to reproduce the behavior:
Create a DSLX file hierarchical_cycle.x with the following content:
// Toy example to reproduce cross-proc combinational ready/valid cycles.
proc B {
x_in: chan<u32> in;
y_out: chan<u32> out;
config(x_in: chan<u32> in, y_out: chan<u32> out) { (x_in, y_out) }
init { }
next(_: ()) {
let (tok, x) = recv(join(), x_in);
send(tok, y_out, x);
}
}
proc A {
x_in: chan<u32> in;
x_out: chan<u32> out;
y_in: chan<u32> in;
y_out: chan<u32> out;
config(x_in: chan<u32> in, y_out: chan<u32> out) {
let (x_s, x_r) = chan<u32>("x_internal");
let (y_s, y_r) = chan<u32>("y_internal");
spawn B(x_r, y_s);
(x_in, x_s, y_r, y_out)
}
init { }
next(_: ()) {
let (tok_in, x) = recv(join(), x_in);
send(tok_in, x_out, x);
let (tok_out, y) = recv(join(), y_in); // Independent token to bypass SendThenRecvConstraint
send(tok_out, y_out, y);
}
}
Configure the Bazel targets in your BUILD file. Note that lower_to_proc_scoped_channels is set to false to use package-scoped channels to factor it out of the equation but the same issue is present with PSC. fifo_module is set to "" to materialize the FIFO logic inline but you can also replace it with a handwritten FIFO wrapper:
This correctly fails during XLS compilation with the expected cycle error:
Error: INVALID_ARGUMENT: Cycle detected involving the following components (in flow order):
* Proc: `__hierarchical_cycle__A_0_next` (instance: `hierarchical_cycle__1 [hierarchical_cycle::hierarchical_cycle__1_inst1->hierarchical_cycle__1]`)
Combinational path: `p0_all_active_inputs_valid` -> ... -> `__hierarchical_cycle__x_internal_valid_and_not_has_been_sent` -> output `hierarchical_cycle__x_internal_vld`
...
Expected behavior
XLS should fail compilation during codegen when a combinational loop is present in the design, regardless of the codegen version. Codegen 1.5 should execute VerifyPackage(..., codegen=true) to catch hierarchical cycles before generating Verilog.
Additional Context
SystemVerilog vs Verilog: The reproduction targets use "use_system_verilog": "false" and output .v files. This is to ensure the generated materialized FIFO logic uses standard Verilog-2001 (element-by-element array assignment) instead of SystemVerilog array patterns ('{...}), allowing the open-source Yosys parser to parse the file without syntax errors. The bug itself is present regardless of this setting (Codegen 1.5 misses the cycle in both SV and non-SV modes). The materialized FIFOs work in SystemVerilog with the Verific parser.
Proc-Scoped Channels: The reproduction has proc-scoped channels disabled (lower_to_proc_scoped_channels = "false") to simplify the reproduction because PSC implicitly forces codegen 1.5 (Proc-scoped channels should not silently force codegen version 1.5 #4554) . The bug occurs in both configurations.
Describe the bug
XLS fails to detect hierarchical combinational ready/valid loops (cycles that cross instantiation boundaries) when using Codegen 1.5. This allows XLS to compile the design successfully and output Verilog, which subsequently fails synthesis in downstream EDA tools (like Yosys) due to logic loops.
The cycle is correctly detected by Codegen 1.0, but is missed in Codegen 1.5 because the Codegen 1.5 entry point (
codegen::Codegeninxls/codegen_v_1_5/codegen.cc) does not executeVerifyPackageor any invariant checkers on the final block hierarchy. Note it's possible other checkers that aren't being run throughVerifyPackagemay manifest as other issues but they are not analyzed here.To Reproduce
Steps to reproduce the behavior:
hierarchical_cycle.xwith the following content:BUILDfile. Note thatlower_to_proc_scoped_channelsis set tofalseto use package-scoped channels to factor it out of the equation but the same issue is present with PSC.fifo_moduleis set to""to materialize the FIFO logic inline but you can also replace it with a handwritten FIFO wrapper:Output:
To verify it is caught by Codegen 1.0:
Update the
hierarchical_cycle_codegentarget inBUILDto use Codegen 1.0:codegen_versionto"1.0"Then run codegen again:
This correctly fails during XLS compilation with the expected cycle error:
Expected behavior
XLS should fail compilation during codegen when a combinational loop is present in the design, regardless of the codegen version. Codegen 1.5 should execute
VerifyPackage(..., codegen=true)to catch hierarchical cycles before generating Verilog.Additional Context
"use_system_verilog": "false"and output.vfiles. This is to ensure the generated materialized FIFO logic uses standard Verilog-2001 (element-by-element array assignment) instead of SystemVerilog array patterns ('{...}), allowing the open-source Yosys parser to parse the file without syntax errors. The bug itself is present regardless of this setting (Codegen 1.5 misses the cycle in both SV and non-SV modes). The materialized FIFOs work in SystemVerilog with the Verific parser.lower_to_proc_scoped_channels = "false") to simplify the reproduction because PSC implicitly forces codegen 1.5 (Proc-scoped channels should not silently force codegen version 1.5 #4554) . The bug occurs in both configurations.