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][CAPI] Add more functions for discriminating and querying type #7960

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

SpriteOvO
Copy link
Member

This PR adds functions:

  • for const firrtlTypeIsConst, firrtlTypeGetConstType
  • for bit width firrtlTypeGetBitWidth
  • for discriminating firrtlTypeIsA{UInt,SInt,Clock,Reset,...}
  • for vector firrtlTypeGetVectorElement, firrtlTypeGetVectorNumElements
  • for bundle firrtlTypeGetBundleNumFields, firrtlTypeGetBundleFieldByIndex

CC @sequencer, could you check if there are any missing?

Copy link
Contributor

@sequencer sequencer left a 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
Copy link
Contributor

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

Copy link
Member Author

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

// 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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated~

@SpriteOvO SpriteOvO force-pushed the firrtl-more-c-api branch 2 times, most recently from acd784b to 49274fb Compare December 7, 2024 21:34
Copy link
Contributor

@mikeurbach mikeurbach left a 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!

@@ -186,6 +186,131 @@ void testAttrGetIntegerFromString(MlirContext ctx) {
mlirStringRefCreateFromCString("114514"), 10));
}

void testTypeDiscriminantsAndQuarries(MlirContext ctx) {
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, right. Fixed

@SpriteOvO SpriteOvO merged commit 1462269 into llvm:main Dec 11, 2024
4 checks passed
@SpriteOvO
Copy link
Member Author

@mikeurbach Thank you for reviewing this!

@SpriteOvO SpriteOvO deleted the firrtl-more-c-api branch December 11, 2024 06:07
Copy link
Member

@seldridge seldridge left a 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.

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.

4 participants