This is an archive of the discontinued LLVM Phabricator instance.

Add SCF Dialect C API
AbandonedPublic

Authored by GeorgeLyon on Nov 29 2020, 10:15 AM.

Diff Detail

Event Timeline

GeorgeLyon created this revision.Nov 29 2020, 10:15 AM
GeorgeLyon requested review of this revision.Nov 29 2020, 10:15 AM
mlir/include/mlir-c/SCFDialect.h
29

I would like to discuss more how we scale dialect registration: three loose entryoints for such things makes it really awkward to treat generically on any way. Personally, I'd rather see a MlirDialectRegistration struct that provides function pointers for load/register and the namespace. Then I'd like to see one function for obtaining a pointer to that struct. This would help interop with other APIs, allowing us to have simple, opaque calls to get the registration info and then an API to apply it generically. It would also get us closer to being able to do dynamic discovery of dialects.

In any case: I'm not opposed to doing this one more this way but would like to bump this up to discuss approach before we go much further.

I very much agree @stellaraccident. I would even go one step further and say there should be an mlirGetDialectByNamespace(MlirStringRef) function to return this structure, which we can enable using static constructors (even though they are evil, this would be a very nice way to not have to create a CAPI for every dialect). For the record, in the Swift bindings I use "Dialect" to mean what you refer to as "Dialect Registration" and "Dialect Instance" to refer to the thing returned by getOrLoad. I also don't currently understand how Dialect Instances are useful (and why we can't just have "Dialect Registration" be the only thing (hence "Dialect")

That said, I think it would be nice to include a second dialect in the bindings as we work our way to a better system (and I need it for my test cases :-)

mehdi_amini requested changes to this revision.Nov 29 2020, 4:15 PM

The code in this revision should all be part of the TableGen generated code and not manually written.

I would even go one step further and say there should be an mlirGetDialectByNamespace(MlirStringRef) function to return this structure, which we can enable using static constructors (even though they are evil, this would be a very nice way to not have to create a CAPI for every dialect).

I am quite strongly opposed to bringing global constructor based registration now that we eliminated it all from MLIR. I rather push this to the client if they want it and never provide this or relying on this kind of things with upstream APIs.

This revision now requires changes to proceed.Nov 29 2020, 4:15 PM

The code in this revision should all be part of the TableGen generated code and not manually written.

I agree, but this isn't the case now. I (selfishly) don't think we should hold up this revision while we figure out a better system (since I would love to only use Standard and SCF in my Swift bindings and avoid pulling in every other dialect). We can continue searching for a better solution here: https://llvm.discourse.group/t/dialects-and-the-c-api/2306

I'll have to disagree here: it isn't clear why we're in a rush right now, unless we think it through and there is a significant amount of work to implement "the right thing", we shouldn't just move forward with something that we already know isn't right.

GeorgeLyon abandoned this revision.Dec 3 2020, 3:26 PM