llvm-project/mlir/tools/mlir-tblgen
Stella Laurenzo 80fe2f61fa [mlir][CAPI] Proposal: Always building a libMLIRPublicAPI.so.
We were discussing on discord regarding the need for extension-based systems like Python to dynamically link against MLIR (or else you can only have one extension that depends on it). Currently, when I set that up, I piggy-backed off of the flag that enables build libLLVM.so and libMLIR.so and depended on libMLIR.so from the python extension if shared library building was enabled. However, this is less than ideal.

In the current setup, libMLIR.so exports both all symbols from the C++ API and the C-API. The former is a kitchen sink and the latter is curated. We should be splitting them and for things that are properly factored to depend on the C-API, they should have the option to *only* depend on the C-API, and we should build that shared library no matter what. Its presence isn't just an optimization: it is a key part of the system.

To do this right, I needed to:

* Introduce visibility macros into mlir-c/Support.h. These should work on both *nix and windows as-is.
* Create a new libMLIRPublicAPI.so with just the mlir-c object files.
* Compile the C-API with -fvisibility=hidden.
* Conditionally depend on the libMLIR.so from libMLIRPublicAPI.so if building libMLIR.so (otherwise, also links against the static libs and will produce a mondo libMLIRPublicAPI.so).
* Disable re-exporting of static library symbols that come in as transitive deps.

This gives us a dynamic linked C-API layer that is minimal and should work as-is on all platforms. Since we don't support libMLIR.so building on Windows yet (and it is not very DLL friendly), this will fall back to a mondo build of libMLIRPublicAPI.so, which has its uses (it is also the most size conscious way to go if you happen to know exactly what you need).

Sizes (release/stripped, Ubuntu 20.04):

Shared library build:
	libMLIRPublicAPI.so: 121Kb
	_mlir.cpython-38-x86_64-linux-gnu.so: 1.4Mb
	mlir-capi-ir-test: 135Kb
	libMLIR.so: 21Mb

Static build:
	libMLIRPublicAPI.so: 5.5Mb (since this is a "static" build, this includes the MLIR implementation as non-exported code).
	_mlir.cpython-38-x86_64-linux-gnu.so: 1.4Mb
	mlir-capi-ir-test: 44Kb

Things like npcomp and circt which bring their own dialects/transforms/etc would still need the shared library build and code that links against libMLIR.so (since it is all C++ interop stuff), but hopefully things that only depend on the public C-API can just have the one narrow dep.

I spot checked everything with nm, and it looks good in terms of what is exporting/importing from each layer.

I'm not in a hurry to land this, but if it is controversial, I'll probably split off the Support.h and API visibility macro changes, since we should set that pattern regardless.

Reviewed By: mehdi_amini, benvanik

Differential Revision: https://reviews.llvm.org/D90824
2020-11-06 09:00:56 -08:00
..
CMakeLists.txt Add a basic C API for the MLIR PassManager as well as a basic TableGen backend for creating passes 2020-11-04 06:36:31 +00:00
DialectGen.cpp Common code preparation for tblgen-types patch 2020-09-26 02:47:48 +00:00
DocGenUtilities.h Mass update the MLIR license header to mention "Part of the LLVM project" 2020-01-26 03:58:30 +00:00
EnumsGen.cpp [mlir-tblgen] Use fully qualified names in generated code files 2020-06-26 15:05:33 +02:00
LLVMIRConversionGen.cpp [mlir] LLVMType: make getUnderlyingType private 2020-07-29 13:43:38 +02:00
LLVMIRIntrinsicGen.cpp [MLIR] Rename SideEffects.td -> SideEffectInterfaces.td 2020-05-12 12:21:42 -07:00
OpDefinitionsGen.cpp [mlir] NFC: fix trivial typos 2020-10-29 04:05:22 +09:00
OpDocGen.cpp [MLIR] Add support for defining Types in tblgen 2020-10-14 00:32:18 +00:00
OpFormatGen.cpp [MLIR] [ODS] Allowing attr-dict in custom directive 2020-10-28 01:24:16 +00:00
OpFormatGen.h [mlir] Add initial support for parsing a declarative operation assembly format 2020-01-30 11:43:40 -08:00
OpInterfacesGen.cpp [mlir][Interfaces] Generate a struct containing function pointers instead of a class with vtables 2020-10-27 16:16:51 -07:00
OpenMPCommonGen.cpp [NFC][MLIR][OpenMP] Add comments and test for OpenMP enum declaration utility 2020-08-14 23:22:23 +01:00
PassCAPIGen.cpp [mlir][CAPI] Proposal: Always building a libMLIRPublicAPI.so. 2020-11-06 09:00:56 -08:00
PassDocGen.cpp [mlir][Pass] Update the PassGen to generate base classes instead of utilities 2020-04-07 14:08:52 -07:00
PassGen.cpp Separate the Registration from Loading dialects in the Context 2020-08-19 01:19:03 +00:00
RewriterGen.cpp Fixed a failure when const matcher fails, added a test to catch 2020-10-16 15:02:24 -07:00
SPIRVUtilsGen.cpp [mlir][spirv] Fix extended insts deserialization generation 2020-10-06 13:34:58 -04:00
StructsGen.cpp [mlir] Support default valued attribute in StructsGen 2020-09-03 09:46:44 -04:00
TypeDefGen.cpp [MLIR] ODS TypeDefs: getChecked() and internal enhancements 2020-10-19 01:10:05 +00:00
mlir-tblgen.cpp Mass update the MLIR license header to mention "Part of the LLVM project" 2020-01-26 03:58:30 +00:00