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

[CAPI] disambiguate mlirRegisterConversionPasses #8072

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

makslevental
Copy link
Contributor

There's a bug in the way Conversion.capi (and Transforms.capi) is generated; without the CIRCT prefix there's a collision with upstream's registerConversionPasses (and registerTransformsPasses) which causes an ODR violation if one actually tries to link in upstream's registerConversionPasses (e.g., by adding MLIRPythonExtension.RegisterEverything to CIRCTBindingsPythonCAPI).

Note, it's not clear to me whether the intent was to use CIRCT's transform C APIs or in fact upstream's transform C APIs so I added CIRCTCAPITransforms and added a corresponding call to mlirRegisterCIRCTTransformsPasses in CIRCTModule.cpp.

@makslevental makslevental force-pushed the users/makslevental/fix-capi branch from 3d12463 to e9e8397 Compare January 12, 2025 23:12
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.

Thanks for this, it's been a while since I thought about the generated C API stuff, but it makes sense we were generating conflicting things (probably copy pasted from upstream without thinking about it). I think we only intend to include CIRCT's conversion and transform libs in the Python module; the only thing we want from upstream is the "core" library:

MLIRPythonSources.Core

@@ -52,7 +53,8 @@ static void registerPasses() {
registerHWArithPasses();
registerHWPasses();
registerHandshakePasses();
mlirRegisterConversionPasses();
mlirRegisterCIRCTConversionPasses();
mlirRegisterCIRCTTransformsPasses();
mlirRegisterTransformsPasses();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove the upstream mlirRegisterTransformsPasses, like mlirRegisterConversionPasses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like that was load bearing for cse. I think you can just do registerCSE but I'm wondering if there are any other such pass uses and whether adding them one by one is worth it. Your call @mikeurbach .

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, hmm, I guess we should just add back mlirRegisterTransformsPasses if it was load bearing, sorry for the churn. Now that I look again, we did explicitly link the upstream lib, presumably for this:

MLIRCAPITransforms

So if I understand, this means we were actually registering the upstream transforms here previously, but not CIRCT's transforms? I guess no one needed to use one of CIRCT's transforms or else they'd have noticed this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not registration that's just linkage right - the mlirRegisterTransformsPasses does the actual registration (MLIRPythonSources.RegisterEverything is a different story because it does a lot of stuff on initialization). But yea prior to the rename and me adding CAPI/Transforms.h that call was definitely going to upstream's mlirRegisterTransformsPasses, not CIRCT's (even though they were named the same).

I guess no one needed to use one of CIRCT's transforms or else they'd have noticed this.

That's my read on it too. But there's no reason to preserve this flaw I think? I dunno do y'all have internal users that might be depending on mlirRegisterTransformsPasses being upstream's in a way that's not reflected in the tests here in OSS?

Copy link
Contributor

Choose a reason for hiding this comment

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

Any use cases for running passes through the Python bindings should be tested in the OSS repo here, like the failure you encountered. So I think it was just the CSE pass we seemed to care about, and what's in this PR looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool then I'll narrow the registration calls (MLIRCAPITransforms is actually needed for mlirFrozenRewritePattern*; thanks @jpienaar!).

@makslevental makslevental force-pushed the users/makslevental/fix-capi branch from 6761001 to d8afd3a Compare January 13, 2025 21:18
@makslevental makslevental force-pushed the users/makslevental/fix-capi branch from d8afd3a to 678f938 Compare January 13, 2025 21:26
@makslevental makslevental merged commit ca92024 into main Jan 13, 2025
4 checks passed
@makslevental makslevental deleted the users/makslevental/fix-capi branch January 13, 2025 21:40
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.

2 participants