-
Notifications
You must be signed in to change notification settings - Fork 298
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 Port Direction #992
Conversation
2893871
to
6905893
Compare
2672222
to
3610154
Compare
3610154
to
bacb100
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great, but i'd recommend dropping the input
keyword from the port list syntax. The default can be input and we can mark outputs explicitly.
lib/Dialect/FIRRTL/FIRRTLOps.cpp
Outdated
return parser.emitError(loc, "expected type instead of SSA identifier"); | ||
argNames.push_back(argument); | ||
argDirections.push_back( | ||
direction::add(direction::Input, direction == "output")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems more clear if it called something like direction::get(bool isOutput)
I didn't see this - can you explain more of the rationale? The .mlir syntax diverges wildly from the fir syntax -- I don't see a reason that "similarity" would tip the scale. Dropping the keyword eliminates a bunch of verbosity. |
To me it's more about "clarity" than "similarity". It obviously depends though; if the preferred MLIR-style is to prefer terseness over clarity then I think it makes sense to remove |
Makes sense, I also love clarity in API design, but IR design is a bit of a different art. We stare at these dumps and hand write them a lot. I'd recommend going with "just output". But seldridge gets to make the final call, I'm good either way! |
I gave this some thought and combining both suggestions (improved terseness and improved clarity) would be to use Barring no last-minute objections, I'll update this and land it later tonight. |
sgtm |
280b316
to
69f93ad
Compare
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Store FIRRTL Dialect module/extmodule port directionality in a "portDirections" integer attribute. The bit position in the attribute indicates directionality (a zero is an input, a one is an output). Previously directionality was encoded as an outer flip on ports. (Output ports had an outer flip, input ports had no outer flip.) Module ports are now verified to require that no outer flip is applied. Directionality is printed/parsed as a leading "in" or "out" before the port identifier. E.g., a module with one input and one output now looks like: firrtl.module(in %a: firrtl.uint<1>, out %b: firrtl.uint<1>) Previously, this would look like: firrtl.module(%a: firrtl.uint<1>, %b: firrtl.flip<uint<1>>) Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
69f93ad
to
eb0586b
Compare
Add port direction information to the FIRRTL Dialect. Stop using an outer
FlipType
to mark a module output port. All modules now include anIntegerAttribute
with key"portDirections"
which densely stores the direction of each port as a bit. Block argument zero is in bit zero, arg one is in bit one, etc.This is printed/parsed in a special format which has inputs looking like
input %a: uint<1>
and outputs looking likeoutput %b: uint<1>
. This is extremely close to the existing FIRRTL syntax.@lattner suggested to remove
input
(an input isn't specially marked) and just useoutput
to mark outputs. @jackkoenig and @azidar were in favor of keeping theinput
andoutput
. Having both is closer to the spirit of FIRRTL IR, so I went with the latter approach.After this PR, the only place a flip can show up is:
(2) is kind of weird, but technically correct since FIRRTL IR treats the "type" of a memory or instance as a bundle. We, instead, split this up into its constituent first-level subfields. An even cleaner representation would be to either revert to a bundle representation or to strip these flips and store directionality somewhere else (in the parent module, in a
portDirections
attribute on an instance, or, for memories, just make it implicit).Example
The following FIRRTL text:
Is parsed into:
After lowering, the ports get split up into separate input and output ports:
For the above, the port encoding can be inspected using the default printer. Both modules have port directions of
0b10
:Metadata
Fixes #989.