1# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 2# See https://llvm.org/LICENSE.txt for license information. 3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 4 5# Note that the only function of this module is currently to load the 6# native module and re-export its symbols. In the future, this file is 7# reserved as a trampoline to handle environment specific loading needs 8# and arbitrate any one-time initialization needed in various shared-library 9# scenarios. 10 11__all__ = [ 12 "ir", 13 "passmanager", 14] 15 16# The _dlloader takes care of platform specific setup before we try to 17# load a shared library. 18from . import _dlloader 19_dlloader.preload_dependency("MLIRPublicAPI") 20 21# Expose the corresponding C-Extension module with a well-known name at this 22# top-level module. This allows relative imports like the following to 23# function: 24# from .. import _cext 25# This reduces coupling, allowing embedding of the python sources into another 26# project that can just vary based on this top-level loader module. 27import _mlir as _cext 28 29def _reexport_cext(cext_module_name, target_module_name): 30 """Re-exports a named sub-module of the C-Extension into another module. 31 32 Typically: 33 from . import _reexport_cext 34 _reexport_cext("ir", __name__) 35 del _reexport_cext 36 """ 37 import sys 38 target_module = sys.modules[target_module_name] 39 source_module = getattr(_cext, cext_module_name) 40 for attr_name in dir(source_module): 41 if not attr_name.startswith("__"): 42 setattr(target_module, attr_name, getattr(source_module, attr_name)) 43 44 45# Import sub-modules. Since these may import from here, this must come after 46# any exported definitions. 47from . import ir, passmanager 48 49# Add our 'dialects' parent module to the search path for implementations. 50_cext.globals.append_dialect_search_prefix("mlir.dialects") 51