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 GCT Data/Mem Tap Prefixing to PrefixModules #2031

Merged
merged 2 commits into from
Oct 26, 2021

Conversation

seldridge
Copy link
Member

@seldridge seldridge commented Oct 23, 2021

Change PrefixModules to rename external modules that are Grand Central
data or memory taps. This is done to align the behavior of CIRCT with
the Scala FIRRTL Compiler.

Fixes #2027.

Copy link
Contributor

@prithayan prithayan left a comment

Choose a reason for hiding this comment

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

Looks good.
I think next we need to update extern modules in NLAs too.

@seldridge
Copy link
Member Author

I tried this with the test case you added for NLAs. The actual logic should be fine, but the rename of external modules needs to clone modules if there are multiple prefixes. I erroneously thought that the prefixes array was "all the prefixes that need to be applied" instead of a list of different prefixes which require duplicating the module. I'll update this and ask for re-review.

@seldridge
Copy link
Member Author

I fixed this to actually do the right thing (clone the external module if there are multiple prefixes). I would be surprised if any Grand Central code exercises this, but we'll future proof what we're doing here. This copies the behavior for how normal, non-external modules are duplicated if they have multiple prefixes.

I don't think there is any update needed for this to work with NLAs. All the NLA handling logic happens in either runOnOperation or in renameModuleBody. This PR only modified renameModuleBody to stop excluding external modules from renaming, so any NLA updates are then picked up by renameModuleBody and things appear to just work. Or: modifying the test case you added, @prithayan, to have NLAs target a GCT data tap seems to "just work":

firrtl.circuit "NLATop" {
  firrtl.nla @nla [@NLATop, @Aardvark, @Zebra] ["test", "test", "Zebra"]
  firrtl.nla @nla_1 [@NLATop, @Aardvark, @Zebra] ["test", "test_1", "Zebra"]
  firrtl.module @NLATop()
    attributes {annotations = [{
      class = "sifive.enterprise.firrtl.NestedPrefixModulesAnnotation",
      prefix = "T_",
      inclusive = true
    }]} {
    firrtl.instance test  {annotations = [{circt.nonlocal = @nla, class = "circt.nonlocal"}, {circt.nonlocal = @nla_1, class = "circt.nonlocal"} ]}@Aardvark()
    firrtl.instance test2 @Zebra()
  }
  firrtl.module @Aardvark()
    attributes {annotations = [{
      class = "sifive.enterprise.firrtl.NestedPrefixModulesAnnotation",
      prefix = "A_",
      inclusive = false
    }]} {
    firrtl.instance test {annotations = [{circt.nonlocal = @nla, class = "circt.nonlocal"}]}@Zebra()
    firrtl.instance test1 {annotations = [{circt.nonlocal = @nla_1, class = "circt.nonlocal"}]}@Zebra()
  }
  firrtl.extmodule @Zebra()
    attributes {annotations = [{
      class = "sifive.enterprise.grandcentral.DataTapsAnnotation"}],
      defname = "DataTap"}
}

Produces:

module  {
  firrtl.circuit "T_NLATop"   {
    firrtl.nla @nla [@T_NLATop, @T_Aardvark, @T_A_Zebra] ["test", "test", "Zebra"]
    firrtl.nla @nla_1 [@T_NLATop, @T_Aardvark, @T_A_Zebra] ["test", "test_1", "Zebra"]
    firrtl.module @T_NLATop() {
      firrtl.instance test  {annotations = [{circt.nonlocal = @nla, class = "circt.nonlocal"}, {circt.nonlocal = @nla_1, class = "circt.nonlocal"}]} @T_Aardvark()
      firrtl.instance test2  @T_Zebra()
    }
    firrtl.module @T_Aardvark() {
      firrtl.instance test  {annotations = [{circt.nonlocal = @nla, class = "circt.nonlocal"}]} @T_A_Zebra()
      firrtl.instance test1  {annotations = [{circt.nonlocal = @nla_1, class = "circt.nonlocal"}]} @T_A_Zebra()
    }
    firrtl.extmodule @T_Zebra() attributes {annotations = [{class = "sifive.enterprise.grandcentral.DataTapsAnnotation"}], defname = "T_DataTap"}
    firrtl.extmodule @T_A_Zebra() attributes {annotations = [{class = "sifive.enterprise.grandcentral.DataTapsAnnotation"}], defname = "T_A_DataTap"}
  }
}

Change PrefixModules to rename external modules that are Grand Central
data or memory taps.  External modules that have more than one prefix
will be cloned ("duplicated" in Scala FIRRTL Compiler terminology) to
create new external modules for prefixes after the first.  This is the
same behavior as how PrefixModules works for non-external modules.

Note: it is unexpected that Grand Central will produce (or work?) with
multiply instantiated Data/Mem taps.  However, the behavior added here
is sane.

This change aligns the prefixing behavior of CIRCT with the Scala FIRRTL
Compiler for Grand Central Data/Mem taps.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge merged commit 035fd38 into main Oct 26, 2021
@seldridge seldridge deleted the dev/seldridge/issue-2027 branch October 26, 2021 01:09
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.

[FIRRTL] Prefix Grand Central Data/Mem Taps
4 participants