[FIRRTL] Support Prefixing of Grand Central Interfaces#2020
Merged
Conversation
seldridge
force-pushed
the
dev/seldridge/gct-interface-prefix-modules
branch
from
October 21, 2021 03:54
37188a3 to
f3d79e6
Compare
seldridge
marked this pull request as ready for review
October 21, 2021 03:56
Update Grand Central Interfaces with a prefix if one is set during the PrefixModules pass. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add one test to the PrefixModules test that annotations associated with a Grand Central interface are updated if they are in a module prefix scope. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add a getter to retrieve the "prefix" field of an AugmentedBundleType. This is a utility to provides easy access to a new field that PrefixModules is adding to the outermost AugmentedBundleType. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Change the Grand Central Views/Interfaces pass to apply an outer module-level prefix (derived from a NestedPrefixModulesAnnotation that was handled by the PrefixModules pass) and an inner prefix set by an optional PrefixInterfacesAnnotation. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add a test that the Grand Central Views/Interfaces pass properly consumes a PrefixInterfacesAnnotation, removes it, and uses its information to apply a prefix to all interfaces in a circuit. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Update FIRRTL rationale document with information about how Grand Central-generated interfaces can be prefixed. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
seldridge
force-pushed
the
dev/seldridge/gct-interface-prefix-modules
branch
from
October 21, 2021 04:57
f3d79e6 to
366b687
Compare
fabianschuiki
approved these changes
Oct 21, 2021
fabianschuiki
left a comment
Contributor
There was a problem hiding this comment.
As far as my understanding of the Scala implementation goes, this looks really nice!
Comment on lines
+196
to
+226
| AnnotationSet annotations(module); | ||
| if (!annotations.hasAnnotation( | ||
| "sifive.enterprise.grandcentral.ViewAnnotation")) | ||
| return; | ||
| auto prefixFull = (outerPrefix + innerPrefix).str(); | ||
| SmallVector<Attribute> newAnnotations; | ||
| for (auto anno : annotations) { | ||
| if (!anno.isClass("sifive.enterprise.grandcentral.ViewAnnotation")) { | ||
| newAnnotations.push_back(anno.getDict()); | ||
| continue; | ||
| } | ||
|
|
||
| NamedAttrList newAnno; | ||
| for (auto pair : anno.getDict()) { | ||
| if (pair.first == "name") { | ||
| newAnno.append( | ||
| pair.first, | ||
| builder.getStringAttr(Twine(prefixFull) + | ||
| pair.second.cast<StringAttr>().getValue())); | ||
| continue; | ||
| } | ||
| newAnno.append(pair.first, pair.second); | ||
| } | ||
| newAnnotations.push_back( | ||
| DictionaryAttr::getWithSorted(builder.getContext(), newAnno)); | ||
|
|
||
| // Record that we need to apply this prefix to the interface definition. | ||
| if (anno.getMember<StringAttr>("type").getValue() == "parent") | ||
| interfacePrefixMap[anno.getMember<IntegerAttr>("id")] = prefixFull; | ||
| } | ||
| AnnotationSet(newAnnotations, builder.getContext()).applyToOperation(module); |
Contributor
There was a problem hiding this comment.
It's sad that there is no better way to do dictionary attr mutation in MLIR yet. I totally see why you'd want something like AnnotationSet::map or filter_map here. Maybe we should start to curate a list of "nice-to-have refactorings" that people can pick up if they're bored or want to jump in. Maybe as some "help wanted" issue?
Member
Author
There was a problem hiding this comment.
Yes, this rewrite just to mutate one value feels bad. I've seen this come up twice so far: (1) annotation scattering does this type of transformation and (2) this pass. I can open up some help wanted issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for prefixing Grand Central Interfaces with both a module-level, outer prefix (as set by the
PrefixModulespass) and with an innerPrefixInterfacesAnnotation.This is implemented by adding an optional field to the bundle type called "prefix" that is set by
PrefixModulesbased on where the interface is instantiated. This prefix is also applied to the name of the parent and companion modules.During the Grand Central interfaces pass, this prefix is combined with an optional prefix read from a
PrefixInterfacesAnnotationto prefix each interface.