-
Notifications
You must be signed in to change notification settings - Fork 604
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
Emit FIRRTL BulkConnect
s for Record
s, Vec
s when possible
#2073
Conversation
@@ -178,6 +188,35 @@ private[chisel3] object MonoConnect { | |||
case (sink, source) => throw MismatchedException(sink.toString, source.toString) | |||
} | |||
|
|||
/** Check whether two [[Vec]]s can be bulk connected (<-) in FIRRTL. */ | |||
private[chisel3] def canBulkConnectVecs(sink_v: Vec[Data @unchecked], |
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 function and canBulkConnectRecords
are also used in BiConnect
. Is there a better place I should move these out to, or can they just live in MonoConnect
?
@@ -308,4 +308,19 @@ class VecSpec extends ChiselPropSpec with Utils { | |||
}} | |||
} | |||
} | |||
|
|||
property("Vec connections should emit FIRRTL bulk connects when possible") { |
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.
should we include some of the "when not possible" cases in the tests?
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.
Yes we should
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.
Some cases we should test:
import chisel3._
Bundle that instantiates animport Chisel._
Bundle that relies on the Stringly-typed connections for the connect to be legal, this should not emit a bulk connect. Some inspiration -- this example is a little weird because I'm surprised thatout.buzz.foo <= in.buzz.foo
in the emitted CHIRRTL uses<=
instead of<-
)- A case where
<>
will magically work but the FIRRTL types would be wrong for<=
, eg. https://scastie.scala-lang.org/9xV1AAU0SFq1UvQLVbGFFw --enq <= deq
is illegal while Chisel can do the connecting by splitting it up.
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.
Similar principles apply in Vecs, in fact you could make Vecs of these Bundles
case _ => true | ||
} | ||
val elemsMatch = CheckTypes.validConnect( | ||
Converter.extractType(sink_v, sourceInfo), |
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.
do the Vecs need to be parameterized exactly in order to be bulk connected? is that what is captured in extractType
?
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.
They need not be exact, implicit truncation remains the law of the land and that is correctly handled by validConnect
.
@debs-sifive One thing that we also need to check is the Flows. The method needed for this is not exposed from FIRRTL so we might need to make some utility methods in FIRRTL: https://github.com/chipsalliance/firrtl/blob/4991ee209b4ae179afcb3e043bbe7ba92006931d/src/main/scala/firrtl/passes/CheckFlows.scala#L64. This is a bit tricky because those seem to require Kind and throw exceptions so we can't just reuse out of the box anyway
For development purposes, we can just write these utilities in Chisel and then migrate them to FIRRTL.
We also need to check "visibility" (eg. https://github.com/chipsalliance/chisel3/blob/b6929c9ad438db26055707b8ec5c66e4f70a22b8/core/src/main/scala/chisel3/internal/MonoConnect.scala#L217, need to make sure we're not issuing connects if one of the sides is not part of the current module).
}) | ||
chirrtl should include ("io.outMono <- io.inMono @[MixedVecSpec.scala") | ||
chirrtl should include ("io.outBi <- io.inBi @[MixedVecSpec.scala") | ||
} |
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.
It would be nice to see a case where the MixedVecs are parameterized differently. Can they be bulk connected in that case? If not it would be nice to see the check that they are NOT bulk connected.
@@ -178,6 +188,168 @@ private[chisel3] object MonoConnect { | |||
case (sink, source) => throw MismatchedException(sink.toString, source.toString) | |||
} | |||
|
|||
/** Check [[Aggregate]] visibility. */ | |||
private def aggregateConnectContextCheck(implicit sourceInfo: SourceInfo, connectCompileOptions: CompileOptions, |
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.
@jackkoenig I changed this to do aggregate-level checking, but am following the format of elemConnect()
: https://github.com/chipsalliance/chisel3/blob/b6929c9ad438db26055707b8ec5c66e4f70a22b8/core/src/main/scala/chisel3/internal/MonoConnect.scala#L193
It's a lot of copy/paste code, but it seems like the elemConnect
function was purposely written that way for clarity. Not sure if you recommend simplifying the code to be more straightforward?
Like from
if( (context_mod == sink_mod) && (context_mod == source_mod) ) {
((sink_direction, source_direction): @unchecked) match {
// SINK SOURCE
// CURRENT MOD CURRENT MOD
case (Output, _) => true
case (Internal, _) => true
case (Input, _) => false
}
}
To:
if( (context_mod == sink_mod) && (context_mod == source_mod) ) {
sink_direction != Input
}
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.
I wonder whether that will affect error message granularity - I found that the way it's laid out right now is nice for pointing out exactly which error condition was hit. Though I think it probably won't matter for this particular example when there's only one exception case
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.
Ideally you should get the same error message — if we fail to emit a FIRRTL BulkConnect, we should try emitting as we did before (element-wise connect). And if that also fails, you should get the same element-wise failure message.
Has this been replaced by #2381 , and shoudl this be closed? |
Yes, looks like it. |
Contributor Checklist
docs/src
?cc @jackkoenig
Type of Improvement
API Impact
No visible impact to user.
Backend Code Generation Impact
FIRRTL BulkConnects (
<-
) are emitted when possible forRecord
s andVec
s, instead of element-wise connections. This should decrease the FIRRTL emission size.No impact on generated Verilog.
Desired Merge Strategy
Release Notes
FIRRTL
BulkConnect
s forRecord
s,Vec
s are emitted when possible, decreasing FIRRTL code emission size.Reviewer Checklist (only modified by reviewer)
Please Merge
?