This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Expose Dialect class and registration/loading to C API
ClosedPublic

Authored by ftynse on Sep 23 2020, 9:34 AM.

Details

Summary
  • Add a minimalist C API for mlir::Dialect.
  • Allow one to query the context about registered and loaded dialects.
  • Add API for loading dialects.
  • Provide functions to register the Standard dialect.

When used naively, this will require to separately register each dialect. When
we have more than one exposed, we can add variadic macros that expand to
individual calls.

Diff Detail

Event Timeline

ftynse created this revision.Sep 23 2020, 9:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 23 2020, 9:34 AM
ftynse requested review of this revision.Sep 23 2020, 9:34 AM
mehdi_amini added inline comments.Sep 23 2020, 10:01 AM
mlir/include/mlir-c/IR.h
99

Dialects don't need to be registered for pass dependency or to be loaded explicitly.

The *only* purpose of the registry is the MLIR textual parser at this point.

102

(Typo on operations)

106

(Typo on constructs)

122

Clarify if the same dialect in different context would compare equal or not

126

Seems like a useful clang-tidy warning here? (same below)

mlir/lib/CAPI/IR/IR.cpp
47

What is the use for the two APIs above?
(edit: maybe you just need these because of your unit-tests?)

mlir/lib/CAPI/Standard/StandardDialect.cpp
18

Is the plan that someone that would want to create operations in the standard dialect using the C API to first register it and then explicitly load it with its name?
Is this just to reduce the API surface compared to adding a Load entry point as well here?

ftynse updated this revision to Diff 294000.Sep 24 2020, 3:16 AM
ftynse marked 4 inline comments as done.

review and more questions

ftynse added inline comments.Sep 24 2020, 3:18 AM
mlir/include/mlir-c/IR.h
99

What's the longer-term plan? Do you see value in exposing the registration/loading dichotomy to the C API or should the registration + auto-loading be restricted to "testing" tools like mlir-opt?

mlir/lib/CAPI/IR/IR.cpp
47

We eventually need a way to obtain lists that are returned as std::vector in C++. Having a cheap way to query the size makes different styles of reallocation- and copy-minimizing APIs possible.

mlir/lib/CAPI/Standard/StandardDialect.cpp
18

I actually don't have a strong preference here, hesitating to even expose registration at all.

mehdi_amini accepted this revision.Sep 24 2020, 4:16 PM
mehdi_amini added inline comments.
mlir/include/mlir-c/IR.h
99

I don't see a problem with exposing registration to the C API, it should just be documented what is it intended to be used for.

This revision is now accepted and ready to land.Sep 24 2020, 4:16 PM
ftynse updated this revision to Diff 294978.Sep 29 2020, 7:23 AM

Expose both registration and loading + clarify docs

This revision was landed with ongoing or failed builds.Sep 29 2020, 7:30 AM
This revision was automatically updated to reflect the committed changes.