google / xls

XLS: Accelerated HW Synthesis
http://google.github.io/xls/
Apache License 2.0
1.21k stars 179 forks source link

Mutual Exclusion Pass Creates Cycles #1716

Open grebe opened 1 week ago

grebe commented 1 week ago

Describe the bug The mutual exclusion pass can create cycles when merging channel operations.

To Reproduce

proc A {
  cin0: chan<u32> in;
  cin1: chan<u32> in;

  config(cin0: chan<u32> in, cin1: chan<u32> in) {
    (cin0, cin1)
  }

  init { false }

  next(s: bool) {
    let (tok0, data) = recv_if(join(), cin0, !s, u32:0);
    let (tok_cin1, _) = recv_if(join(), cin1, !s, u32:0);

    let (tok1, _) = recv_if(tok_cin1, cin0, s, u32:0);
    let (tok_cin1, _) = recv_if(tok0, cin1, s, u32:0);

    data == u32:0
  }
}

This gives Cycle detected: [tuple_index.87 -> receive.86 -> after_all.83 -> tok0 -> tuple.102 -> tuple_index.98 -> receive.97 -> after_all.94 -> tuple_index.87];

Expected behavior It should either fail to merge one of the receive pairs, or it should correctly merge them without adding a cycle.