-
Notifications
You must be signed in to change notification settings - Fork 305
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][CAPI] Add more functions for discriminating and querying type #7960
Conversation
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.
The capi definition basically looks good to me.
/// | ||
/// It recursively compute the bit width of aggregate types. For bundle and | ||
/// vectors, recursively get the width of each field element and return the | ||
/// total bit width of the aggregate type. This returns -1, if any of the bundle |
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 returns -1, if any of the bundle fields is a flip type
why
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 the design of
circt/include/circt/Dialect/FIRRTL/FIRRTLTypes.h
Lines 376 to 383 in cd02a73
// Get the bit width for this type, return None if unknown. Unlike | |
// getBitWidthOrSentinel(), this can recursively compute the bitwidth of | |
// aggregate types. For bundle and vectors, recursively get the width of each | |
// field element and return the total bit width of the aggregate type. This | |
// returns None, if any of the bundle fields is a flip type, or ground type with | |
// unknown bit width. | |
std::optional<int64_t> getBitWidth(FIRRTLBaseType type, | |
bool ignoreFlip = false); |
But I forgot to present the ignoreFlip
parameter in C-API, I should add it as well.
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.
Updated~
acd784b
to
49274fb
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.
One minor nitpick on the name of the test function, but this looks good to me. Thanks for these new C APIs... it's annoying but this is still the best way to implement them. And thanks for including unit tests!
test/CAPI/firrtl.c
Outdated
@@ -186,6 +186,131 @@ void testAttrGetIntegerFromString(MlirContext ctx) { | |||
mlirStringRefCreateFromCString("114514"), 10)); | |||
} | |||
|
|||
void testTypeDiscriminantsAndQuarries(MlirContext ctx) { |
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.
nit: I think you meant ...AndQueries
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.
Yeah, right. Fixed
49274fb
to
be90de2
Compare
@mikeurbach Thank you for reviewing this! |
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.
Windows builds are failing with this for a reason that wasn't immediately obvious to me.
This PR adds functions:
firrtlTypeIsConst
,firrtlTypeGetConstType
firrtlTypeGetBitWidth
firrtlTypeIsA{UInt,SInt,Clock,Reset,...}
firrtlTypeGetVectorElement
,firrtlTypeGetVectorNumElements
firrtlTypeGetBundleNumFields
,firrtlTypeGetBundleFieldByIndex
CC @sequencer, could you check if there are any missing?