Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Add GroupSink pass #6184

Merged
merged 2 commits into from
Sep 26, 2023
Merged

Conversation

seldridge
Copy link
Member

Add a new pass, GroupSink/firrtl-group-sink, which will sink operations that are only used by optional groups into optional groups.

@seldridge
Copy link
Member Author

This is currently a very basic implementation that relies on MLIR's controlFlowSink to sink operations into specified regions (the groups!). This works for nodes and primitive operations. It expectedly misses all the fun stuff that SVExtractTestCode does related to wires/registers and instances. This needs to be beefed up with support for backedge analysis to figure out how to move any operation which isn't used outside a root group into a group.

@seldridge seldridge force-pushed the dev/seldridge/firrtl-sink-groups branch from 85cbe9d to 070970d Compare September 22, 2023 21:59
@seldridge seldridge marked this pull request as ready for review September 22, 2023 22:05
@seldridge
Copy link
Member Author

I was originally going to keep this in draft until this had a more advanced sinking approach (SVExtractTestCode's backedge tracking). However, it's useful to get something in on top of which I or others can jump in and iterate.

Here is a simple end-to-end example showing what this can do:

Input:

FIRRTL version 3.1.0
circuit Foo: %[[
  {"class":"firrtl.transforms.DontTouchAnnotation", "target":"~Foo|Foo>b"},
  {"class":"firrtl.transforms.DontTouchAnnotation", "target":"~Foo|Foo>c"}
]]
  declgroup A, bind:

  module Foo:
    input a: UInt<1>

    node b = a

    group A:
      node c = b

Output is below. Notice how wire b is moved inside Foo_A:

// Generated by CIRCT firtool-1.53.0-205-g070970d77-dirty
module Foo_A(
  input _a
);

  wire b = _a;
  wire c = b;
endmodule

module Foo(
  input a
);

endmodule


// ----- 8< ----- FILE "groups_Foo_A.sv" ----- 8< -----

// Generated by CIRCT firtool-1.53.0-205-g070970d77-dirty
`ifndef groups_Foo_A
`define groups_Foo_A
bind Foo Foo_A foo_A (
  ._a (a)
);
`endif // groups_Foo_A

numSunk = controlFlowSink(
regionsToSink, domInfo, [](Operation *op, Region *) {
return !hasDontTouch(op);
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will block sinking of any operation which has an inner symbol or DontTouchAnnotation. This behavior is conservative and likely can be relaxed.

Add a new pass, GroupSink/firrtl-group-sink, which will sink operations
that are only used by optional groups into optional groups.  This is very
simple at present.  This pass uses `mlir::controlFlowSink` to sink ops
into regions.  This only works for very simple things in FIRRTL which have
normal SSA dominance, e.g., nodes, constants, or primitive operations.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add the GroupSink pass (basic sinking of operations into groups) to the
firtool pipeline just before LowerGroups.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge force-pushed the dev/seldridge/firrtl-sink-groups branch from 4019d64 to 16f4f76 Compare September 26, 2023 19:23
@seldridge seldridge merged commit 16f4f76 into main Sep 26, 2023
5 checks passed
@seldridge seldridge deleted the dev/seldridge/firrtl-sink-groups branch September 28, 2023 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant