0

I am trying to write a procedure to put each Strongly Connected Component of the given circuit into a distinct sub-module.

So, I tried to add a function to SCC pass in Yosys to add each SCC into a submod. The function is:

  void putSelectionIntoParition (RTLIL::Design *design, 
                 std::vector<pair<std::string,RTLIL::Selection>>& SelectionVector)
  {
    int p_count = 0;
    for (std::vector<pair<std::string,RTLIL::Selection>>::iterator it = SelectionVector.begin();
     it != SelectionVector.end(); ++it) 
      {
    design->selection_stack[0] = it->second;
    design->selection_stack[0].optimize(design);
    std::string command = "submod -name ";
    command.append(it->first);
    Pass::call_on_selection(design, it->second, command); 
    ++p_count;
    } 
  }

However, my code does not work properly. I guess the problem is with "selection" process that I use. I was wondering if there is any utility/API inside the yosys source that accept vector of cells (as well and a name submodule) and put them into a sub-module.

Mehrdad
  • 107
  • 8

1 Answers1

1

The following should work just fine:

void putSelectionIntoParition(RTLIL::Design *design,
    std::vector<pair<std::string, RTLIL::Selection>> &SelectionVector)
{
    for (auto it : SelectionVector) {
        std::string command = "submod -name " + it.first;
        Pass::call_on_selection(design, it.second, command);
    }
}

You definitely don't need (nor should) modify selection_stack.

I was wondering if there is any utility/API inside the yosys source that accept vector of cells (as well and a name submodule) and put them into a sub-module.

You would do this by setting the submod="<name>" attribute on the cells. Then simply run the submod command.

You might have seen that the scc documentation mentions a -set_attr option that is yet unimplemented. I have now implemented this option in commit ef603c6 (commit 914aa8a contains a bugfix for scc).

With this feature you can now accomplished what you have described using something like the following yosys script.

read_verilog test.v
prep
scc -set_attr submod scc{}
submod
show test

I have tested this with the folling test.v file:

module test(input A, B, output X, Y);
assign X = (A & B) ^ X, Y = A | (B ^ Y);
endmodule

enter image description here

3. Executing SCC pass (detecting logic loops).
Found an SCC: $xor$test.v:2$2
Found an SCC: $or$test.v:2$4 $xor$test.v:2$3
Found 2 SCCs in module test.
Found 2 SCCs.
CliffordVienna
  • 7,995
  • 1
  • 37
  • 57
  • I guess I found a bug there. I explained it in my main post. Please let me know if you want more explanations or examples. – Mehrdad Nov 06 '16 at 17:39
  • @Mehrdad in its default mode, `scc` does not consider FF cells or hierarchical cells, thus your `up_counter` does not contain a loop as far as `scc` is concerned. Use `-all_cell_types` to overwrite (see `help scc`). Flatten your design (e.g. using `prep -flatten`) if you'd like to find logic loops that span multiple hierarchical cells with `scc`. – CliffordVienna Nov 06 '16 at 17:51
  • @Mehrdad I did try it and it works just fine here. Please edit your question and state what exactly you are doing, what the expected result is and how the result you get differs from that. – CliffordVienna Nov 07 '16 at 09:30
  • I have update my post and added more details of the steps I am taking. (this is done by latest yosys). I really appreciate your help. – Mehrdad Nov 08 '16 at 15:28
  • @Mehrdad afaics this is exactly the expected result. Please state in what way you would have expected a different result. Your `top_counter` module does not contain any scc. I'm sure `scc` found the scc in `up_counter` as expected. Just run `show` on that module or look at the output produced by the SCC pass. – CliffordVienna Nov 08 '16 at 15:52
  • PS @Mehrdad: You should always try to amend your question with additional information, never get rid of your original question. Otherwise this will break the question-answer format of stack overflow. For the same reason you should post a new question if a new question comes up as result of a previous question, not just tack on more and more questions in the comments to an answer. Also make sure to always include a Minimal, Complete, and Verifiable example in your question (see http://stackoverflow.com/help/mcve). – CliffordVienna Nov 08 '16 at 15:58
  • 1
    My fault. Sorry! I will adhere to the rules of stackoverflow next time. I will post it as a new question. and retract this one to the original one. – Mehrdad Nov 08 '16 at 16:09
  • I guess there is a corner case that scc does not encapsulate the SCCs. I have simplified the design and reported the issue in GitHub. – Mehrdad Nov 09 '16 at 04:47