brintos

brintos / llvm-project-archived public Read only

0
0
Text · 31.5 KiB · 2acb6ee Raw
1016 lines · plain
1include(AddMLIRPython)2 3# Specifies that all MLIR packages are co-located under the `MLIR_PYTHON_PACKAGE_PREFIX.`4# top level package (the API has been embedded in a relocatable way).5add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=${MLIR_PYTHON_PACKAGE_PREFIX}.")6 7################################################################################8# Structural groupings.9################################################################################10 11declare_mlir_python_sources(MLIRPythonSources)12declare_mlir_python_sources(MLIRPythonSources.Dialects13  ADD_TO_PARENT MLIRPythonSources)14declare_mlir_python_sources(MLIRPythonSources.Core15  ADD_TO_PARENT MLIRPythonSources)16 17################################################################################18# Pure python sources and generated code19################################################################################20 21declare_mlir_python_sources(MLIRPythonSources.Core.Python22  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"23  ADD_TO_PARENT MLIRPythonSources.Core24  SOURCES25    _mlir_libs/__init__.py26    _mlir_libs/_mlir/py.typed27    ir.py28    passmanager.py29    rewrite.py30    dialects/_ods_common.py31)32 33declare_mlir_python_sources(MLIRPythonSources.Core.Python.Extras34  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"35  ADD_TO_PARENT MLIRPythonSources.Core.Python36  SOURCES37    extras/types.py38    extras/meta.py39)40 41declare_mlir_python_sources(MLIRPythonSources.ExecutionEngine42  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"43  ADD_TO_PARENT MLIRPythonSources44  SOURCES45    execution_engine.py46    _mlir_libs/_mlirExecutionEngine.pyi47  SOURCES_GLOB48    runtime/*.py49)50 51declare_mlir_python_sources(MLIRPythonCAPI.HeaderSources52  ROOT_DIR "${MLIR_SOURCE_DIR}/include"53  SOURCES_GLOB "mlir-c/*.h"54)55 56################################################################################57# Dialect bindings58################################################################################59 60declare_mlir_dialect_python_bindings(61  ADD_TO_PARENT MLIRPythonSources.Dialects62  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"63  TD_FILE dialects/AffineOps.td64  SOURCES65    dialects/affine.py66  DIALECT_NAME affine67  GEN_ENUM_BINDINGS)68 69declare_mlir_dialect_python_bindings(70  ADD_TO_PARENT MLIRPythonSources.Dialects71  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"72  TD_FILE dialects/AMDGPUOps.td73  SOURCES74    dialects/amdgpu.py75  DIALECT_NAME amdgpu76  GEN_ENUM_BINDINGS)77 78declare_mlir_dialect_python_bindings(79  ADD_TO_PARENT MLIRPythonSources.Dialects80  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"81  TD_FILE dialects/AsyncOps.td82  SOURCES_GLOB dialects/async_dialect/*.py83  DIALECT_NAME async)84 85declare_mlir_dialect_python_bindings(86  ADD_TO_PARENT MLIRPythonSources.Dialects87  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"88  TD_FILE dialects/BufferizationOps.td89  SOURCES90    dialects/bufferization.py91  DIALECT_NAME bufferization92  GEN_ENUM_BINDINGS_TD_FILE93    "../../include/mlir/Dialect/Bufferization/IR/BufferizationEnums.td"94)95 96declare_mlir_dialect_python_bindings(97  ADD_TO_PARENT MLIRPythonSources.Dialects98  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"99  TD_FILE dialects/BuiltinOps.td100  SOURCES101    dialects/builtin.py102  DIALECT_NAME builtin)103 104declare_mlir_dialect_python_bindings(105  ADD_TO_PARENT MLIRPythonSources.Dialects106  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"107  TD_FILE dialects/ComplexOps.td108  SOURCES109    dialects/complex.py110  DIALECT_NAME complex)111 112declare_mlir_dialect_python_bindings(113  ADD_TO_PARENT MLIRPythonSources.Dialects114  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"115  TD_FILE dialects/IndexOps.td116  SOURCES117    dialects/index.py118  DIALECT_NAME index119  GEN_ENUM_BINDINGS)120 121declare_mlir_dialect_python_bindings(122  ADD_TO_PARENT MLIRPythonSources.Dialects123  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"124  TD_FILE dialects/ControlFlowOps.td125  SOURCES126    dialects/cf.py127  DIALECT_NAME cf)128 129declare_mlir_dialect_python_bindings(130  ADD_TO_PARENT MLIRPythonSources.Dialects131  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"132  TD_FILE dialects/FuncOps.td133  SOURCES134    dialects/func.py135  DIALECT_NAME func)136 137declare_mlir_dialect_python_bindings(138  ADD_TO_PARENT MLIRPythonSources.Dialects139  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"140  TD_FILE dialects/OpenACCOps.td141  SOURCES142    dialects/openacc.py143  DIALECT_NAME acc144  DEPENDS acc_common_td145  )146 147declare_mlir_dialect_python_bindings(148  ADD_TO_PARENT MLIRPythonSources.Dialects149  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"150  TD_FILE dialects/GPUOps.td151  SOURCES_GLOB dialects/gpu/*.py152  DIALECT_NAME gpu153  GEN_ENUM_BINDINGS)154 155declare_mlir_dialect_python_bindings(156  ADD_TO_PARENT MLIRPythonSources.Dialects157  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"158  TD_FILE dialects/LinalgOps.td159  SOURCES160  SOURCES_GLOB161    dialects/linalg/*.py162  DIALECT_NAME linalg163  DEPENDS LinalgOdsGen164  GEN_ENUM_BINDINGS)165 166declare_mlir_dialect_python_bindings(167  ADD_TO_PARENT MLIRPythonSources.Dialects168  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"169  TD_FILE dialects/LLVMOps.td170  SOURCES171    dialects/llvm.py172  DIALECT_NAME llvm173  GEN_ENUM_BINDINGS)174 175declare_mlir_dialect_extension_python_bindings(176ADD_TO_PARENT MLIRPythonSources.Dialects177ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"178  TD_FILE dialects/TransformPDLExtensionOps.td179  SOURCES180    dialects/transform/pdl.py181  DIALECT_NAME transform182  EXTENSION_NAME transform_pdl_extension)183 184declare_mlir_dialect_extension_python_bindings(185ADD_TO_PARENT MLIRPythonSources.Dialects186ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"187  TD_FILE dialects/TransformSMTExtensionOps.td188  SOURCES189    dialects/transform/smt.py190  DIALECT_NAME transform191  EXTENSION_NAME transform_smt_extension)192 193declare_mlir_dialect_extension_python_bindings(194ADD_TO_PARENT MLIRPythonSources.Dialects195ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"196  TD_FILE dialects/TransformDebugExtensionOps.td197  SOURCES198    dialects/transform/debug.py199  DIALECT_NAME transform200  EXTENSION_NAME transform_debug_extension)201 202declare_mlir_dialect_extension_python_bindings(203ADD_TO_PARENT MLIRPythonSources.Dialects204ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"205  TD_FILE dialects/TransformTuneExtensionOps.td206  SOURCES207    dialects/transform/tune.py208  DIALECT_NAME transform209  EXTENSION_NAME transform_tune_extension)210 211declare_mlir_dialect_python_bindings(212  ADD_TO_PARENT MLIRPythonSources.Dialects213  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"214  TD_FILE dialects/TransformOps.td215  SOURCES216    dialects/transform/__init__.py217    _mlir_libs/_mlir/dialects/transform/__init__.pyi218  DIALECT_NAME transform219  GEN_ENUM_BINDINGS_TD_FILE220    "../../include/mlir/Dialect/Transform/IR/TransformAttrs.td"221)222 223declare_mlir_python_sources(224  MLIRPythonSources.Dialects.transform.extras225  ADD_TO_PARENT MLIRPythonSources.Dialects226  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"227  GEN_ENUM_BINDINGS228  SOURCES229    dialects/transform/extras/__init__.py)230 231declare_mlir_python_sources(232  MLIRPythonSources.Dialects.transform.interpreter233  ADD_TO_PARENT MLIRPythonSources.Dialects234  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"235  SOURCES236    dialects/transform/interpreter/__init__.py)237 238declare_mlir_dialect_extension_python_bindings(239  ADD_TO_PARENT MLIRPythonSources.Dialects240  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"241  TD_FILE dialects/BufferizationTransformOps.td242  SOURCES243    dialects/transform/bufferization.py244  DIALECT_NAME transform245  EXTENSION_NAME bufferization_transform)246 247declare_mlir_dialect_extension_python_bindings(248  ADD_TO_PARENT MLIRPythonSources.Dialects249  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"250  TD_FILE dialects/GPUTransformOps.td251  SOURCES252    dialects/transform/gpu.py253  DIALECT_NAME transform254  EXTENSION_NAME gpu_transform)255 256declare_mlir_dialect_extension_python_bindings(257  ADD_TO_PARENT MLIRPythonSources.Dialects258  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"259  TD_FILE dialects/SCFLoopTransformOps.td260  SOURCES261    dialects/transform/loop.py262  DIALECT_NAME transform263  EXTENSION_NAME loop_transform)264 265declare_mlir_dialect_extension_python_bindings(266  ADD_TO_PARENT MLIRPythonSources.Dialects267  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"268  TD_FILE dialects/MemRefTransformOps.td269  SOURCES270    dialects/transform/memref.py271  DIALECT_NAME transform272  EXTENSION_NAME memref_transform)273 274declare_mlir_dialect_extension_python_bindings(275  ADD_TO_PARENT MLIRPythonSources.Dialects276  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"277  TD_FILE dialects/NVGPUTransformOps.td278  SOURCES279    dialects/transform/nvgpu.py280  DIALECT_NAME transform281  EXTENSION_NAME nvgpu_transform)282 283declare_mlir_dialect_extension_python_bindings(284  ADD_TO_PARENT MLIRPythonSources.Dialects285  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"286  TD_FILE dialects/LinalgStructuredTransformOps.td287  SOURCES288    dialects/transform/structured.py289  DIALECT_NAME transform290  EXTENSION_NAME structured_transform291  GEN_ENUM_BINDINGS_TD_FILE292    "../../include/mlir/Dialect/Linalg/TransformOps/LinalgTransformEnums.td"293)294 295declare_mlir_dialect_extension_python_bindings(296  ADD_TO_PARENT MLIRPythonSources.Dialects297  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"298  TD_FILE dialects/SparseTensorTransformOps.td299  SOURCES300    dialects/transform/sparse_tensor.py301  DIALECT_NAME transform302  EXTENSION_NAME sparse_tensor_transform)303 304declare_mlir_dialect_extension_python_bindings(305  ADD_TO_PARENT MLIRPythonSources.Dialects306  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"307  TD_FILE dialects/TensorTransformOps.td308  SOURCES309    dialects/transform/tensor.py310  DIALECT_NAME transform311  EXTENSION_NAME tensor_transform)312 313declare_mlir_dialect_extension_python_bindings(314  ADD_TO_PARENT MLIRPythonSources.Dialects315  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"316  TD_FILE dialects/VectorTransformOps.td317  SOURCES318    dialects/transform/vector.py319  DIALECT_NAME transform320  EXTENSION_NAME vector_transform321  GEN_ENUM_BINDINGS_TD_FILE322    "../../include/mlir/Dialect/Vector/Transforms/VectorTransformsBase.td"323)324 325declare_mlir_dialect_extension_python_bindings(326  ADD_TO_PARENT MLIRPythonSources.Dialects327  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"328  TD_FILE dialects/XeGPUTransformOps.td329  SOURCES330    dialects/transform/xegpu.py331  DIALECT_NAME transform332  EXTENSION_NAME xegpu_transform)333 334declare_mlir_dialect_python_bindings(335  ADD_TO_PARENT MLIRPythonSources.Dialects336  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"337  TD_FILE dialects/MathOps.td338  SOURCES dialects/math.py339  DIALECT_NAME math)340 341declare_mlir_dialect_python_bindings(342  ADD_TO_PARENT MLIRPythonSources.Dialects343  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"344  TD_FILE dialects/ArithOps.td345  SOURCES346    dialects/arith.py347  DIALECT_NAME arith348  GEN_ENUM_BINDINGS)349 350declare_mlir_dialect_python_bindings(351  ADD_TO_PARENT MLIRPythonSources.Dialects352  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"353  TD_FILE dialects/MemRefOps.td354  SOURCES355    dialects/memref.py356  DIALECT_NAME memref)357 358declare_mlir_dialect_python_bindings(359  ADD_TO_PARENT MLIRPythonSources.Dialects360  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"361  TD_FILE dialects/ShardOps.td362  SOURCES363    dialects/shard.py364  DIALECT_NAME shard365  GEN_ENUM_BINDINGS)366 367declare_mlir_dialect_python_bindings(368  ADD_TO_PARENT MLIRPythonSources.Dialects369  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"370  TD_FILE dialects/MLProgramOps.td371  SOURCES372    dialects/ml_program.py373  DIALECT_NAME ml_program)374 375declare_mlir_dialect_python_bindings(376  ADD_TO_PARENT MLIRPythonSources.Dialects377  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"378  TD_FILE dialects/NVGPUOps.td379  SOURCES380    dialects/nvgpu.py381  DIALECT_NAME nvgpu382  GEN_ENUM_BINDINGS)383 384declare_mlir_dialect_python_bindings(385  ADD_TO_PARENT MLIRPythonSources.Dialects386  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"387  TD_FILE dialects/NVVMOps.td388  SOURCES389    dialects/nvvm.py390  DIALECT_NAME nvvm391  GEN_ENUM_BINDINGS)392 393declare_mlir_dialect_python_bindings(394  ADD_TO_PARENT MLIRPythonSources.Dialects395  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"396  TD_FILE dialects/ROCDLOps.td397  SOURCES398    dialects/rocdl.py399  DIALECT_NAME rocdl)400 401declare_mlir_python_sources(402  MLIRPythonSources.Dialects.quant403  ADD_TO_PARENT MLIRPythonSources.Dialects404  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"405  GEN_ENUM_BINDINGS406  SOURCES407    dialects/quant.py408    _mlir_libs/_mlir/dialects/quant.pyi)409 410declare_mlir_dialect_python_bindings(411  ADD_TO_PARENT MLIRPythonSources.Dialects412  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"413  TD_FILE dialects/EmitC.td414  SOURCES415    dialects/emitc.py416  DIALECT_NAME emitc)417 418declare_mlir_dialect_python_bindings(419  ADD_TO_PARENT MLIRPythonSources.Dialects420  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"421  TD_FILE dialects/PDLOps.td422  SOURCES423    dialects/pdl.py424    _mlir_libs/_mlir/dialects/pdl.pyi425  DIALECT_NAME pdl)426 427declare_mlir_dialect_python_bindings(428  ADD_TO_PARENT MLIRPythonSources.Dialects429  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"430  TD_FILE dialects/OpenMPOps.td431  SOURCES432    dialects/openmp.py433  DIALECT_NAME omp434  DEPENDS omp_common_td)435 436declare_mlir_dialect_python_bindings(437  ADD_TO_PARENT MLIRPythonSources.Dialects438  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"439  TD_FILE dialects/SCFOps.td440  SOURCES441    dialects/scf.py442  DIALECT_NAME scf)443 444declare_mlir_dialect_python_bindings(445  ADD_TO_PARENT MLIRPythonSources.Dialects446  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"447  TD_FILE dialects/ShapeOps.td448  SOURCES dialects/shape.py449  DIALECT_NAME shape)450 451declare_mlir_dialect_python_bindings(452  ADD_TO_PARENT MLIRPythonSources.Dialects453  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"454  TD_FILE dialects/SparseTensorOps.td455  SOURCES dialects/sparse_tensor.py456  DIALECT_NAME sparse_tensor457  GEN_ENUM_BINDINGS_TD_FILE458    "../../include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td"459)460 461declare_mlir_dialect_python_bindings(462  ADD_TO_PARENT MLIRPythonSources.Dialects463  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"464  TD_FILE dialects/SMTOps.td465  GEN_ENUM_BINDINGS466  SOURCES467    dialects/smt.py468  DIALECT_NAME smt)469 470declare_mlir_dialect_python_bindings(471    ADD_TO_PARENT MLIRPythonSources.Dialects472    ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"473    TD_FILE dialects/SPIRVOps.td474    SOURCES dialects/spirv.py475    DIALECT_NAME spirv)476 477declare_mlir_dialect_python_bindings(478  ADD_TO_PARENT MLIRPythonSources.Dialects479  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"480  TD_FILE dialects/TensorOps.td481  SOURCES482    dialects/tensor.py483  DIALECT_NAME tensor)484 485declare_mlir_dialect_python_bindings(486  ADD_TO_PARENT MLIRPythonSources.Dialects487  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"488  TD_FILE dialects/TosaOps.td489  SOURCES dialects/tosa.py490  DIALECT_NAME tosa491)492 493declare_mlir_dialect_python_bindings(494  ADD_TO_PARENT MLIRPythonSources.Dialects495  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"496  TD_FILE dialects/UBOps.td497  SOURCES dialects/ub.py498  DIALECT_NAME ub499)500 501declare_mlir_dialect_python_bindings(502  ADD_TO_PARENT MLIRPythonSources.Dialects503  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"504  TD_FILE dialects/VectorOps.td505  SOURCES dialects/vector.py506  DIALECT_NAME vector507  GEN_ENUM_BINDINGS_TD_FILE508    "dialects/VectorAttributes.td")509 510declare_mlir_dialect_python_bindings(511  ADD_TO_PARENT MLIRPythonSources.Dialects512  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"513  TD_FILE dialects/IRDLOps.td514  SOURCES dialects/irdl.py515  DIALECT_NAME irdl516  GEN_ENUM_BINDINGS517)518 519################################################################################520# Python extensions.521# The sources for these are all in lib/Bindings/Python, but since they have to522# be rebuilt for each package and integrate with the source setup here, we523# just reference them here instead of having ordered, cross package target524# dependencies.525################################################################################526 527set(PYTHON_SOURCE_DIR "${MLIR_SOURCE_DIR}/lib/Bindings/Python")528declare_mlir_python_extension(MLIRPythonExtension.Core529  MODULE_NAME _mlir530  ADD_TO_PARENT MLIRPythonSources.Core531  ROOT_DIR "${PYTHON_SOURCE_DIR}"532  PYTHON_BINDINGS_LIBRARY nanobind533  SOURCES534    MainModule.cpp535    IRAffine.cpp536    IRAttributes.cpp537    IRCore.cpp538    IRInterfaces.cpp539    IRModule.cpp540    IRTypes.cpp541    Pass.cpp542    Rewrite.cpp543 544    # Headers must be included explicitly so they are installed.545    Globals.h546    IRModule.h547    Pass.h548    NanobindUtils.h549    Rewrite.h550  PRIVATE_LINK_LIBS551    LLVMSupport552  EMBED_CAPI_LINK_LIBS553    MLIRCAPIDebug554    MLIRCAPIIR555    MLIRCAPIInterfaces556 557    # Dialects558    MLIRCAPIFunc559)560 561# This extension exposes an API to register all dialects, extensions, and passes562# packaged in upstream MLIR and it is used for the upstream "mlir" Python563# package. Downstreams will likely want to provide their own and not depend564# on this one, since it links in the world.565# Note that this is not added to any top-level source target for transitive566# inclusion: It must be included explicitly by downstreams if desired. Note that567# this has a very large impact on what gets built/packaged.568declare_mlir_python_extension(MLIRPythonExtension.RegisterEverything569  MODULE_NAME _mlirRegisterEverything570  ROOT_DIR "${PYTHON_SOURCE_DIR}"571  PYTHON_BINDINGS_LIBRARY nanobind572  SOURCES573    RegisterEverything.cpp574  PRIVATE_LINK_LIBS575    LLVMSupport576  EMBED_CAPI_LINK_LIBS577    MLIRCAPIConversion578    MLIRCAPITransforms579    MLIRCAPIRegisterEverything580)581 582declare_mlir_python_extension(MLIRPythonExtension.Dialects.Linalg.Pybind583  MODULE_NAME _mlirDialectsLinalg584  ADD_TO_PARENT MLIRPythonSources.Dialects.linalg585  ROOT_DIR "${PYTHON_SOURCE_DIR}"586  PYTHON_BINDINGS_LIBRARY nanobind587  SOURCES588    DialectLinalg.cpp589  PRIVATE_LINK_LIBS590    LLVMSupport591  EMBED_CAPI_LINK_LIBS592    MLIRCAPIIR593    MLIRCAPILinalg594)595 596declare_mlir_python_extension(MLIRPythonExtension.Dialects.GPU.Pybind597  MODULE_NAME _mlirDialectsGPU598  ADD_TO_PARENT MLIRPythonSources.Dialects.gpu599  ROOT_DIR "${PYTHON_SOURCE_DIR}"600  PYTHON_BINDINGS_LIBRARY nanobind601  SOURCES602    DialectGPU.cpp603  PRIVATE_LINK_LIBS604    LLVMSupport605  EMBED_CAPI_LINK_LIBS606    MLIRCAPIIR607    MLIRCAPIGPU608)609 610declare_mlir_python_extension(MLIRPythonExtension.Dialects.LLVM.Pybind611  MODULE_NAME _mlirDialectsLLVM612  ADD_TO_PARENT MLIRPythonSources.Dialects.llvm613  ROOT_DIR "${PYTHON_SOURCE_DIR}"614  PYTHON_BINDINGS_LIBRARY nanobind615  SOURCES616    DialectLLVM.cpp617  PRIVATE_LINK_LIBS618    LLVMSupport619  EMBED_CAPI_LINK_LIBS620    MLIRCAPIIR621    MLIRCAPILLVM622    # Misnomer - this is only the LLVMIR translation target.623    MLIRCAPITarget624)625 626declare_mlir_python_extension(MLIRPythonExtension.Dialects.Quant.Pybind627  MODULE_NAME _mlirDialectsQuant628  ADD_TO_PARENT MLIRPythonSources.Dialects.quant629  ROOT_DIR "${PYTHON_SOURCE_DIR}"630  PYTHON_BINDINGS_LIBRARY nanobind631  SOURCES632    DialectQuant.cpp633  PRIVATE_LINK_LIBS634    LLVMSupport635  EMBED_CAPI_LINK_LIBS636    MLIRCAPIIR637    MLIRCAPIQuant638)639 640declare_mlir_python_extension(MLIRPythonExtension.Dialects.NVGPU.Pybind641  MODULE_NAME _mlirDialectsNVGPU642  ADD_TO_PARENT MLIRPythonSources.Dialects.nvgpu643  ROOT_DIR "${PYTHON_SOURCE_DIR}"644  PYTHON_BINDINGS_LIBRARY nanobind645  SOURCES646    DialectNVGPU.cpp647  PRIVATE_LINK_LIBS648    LLVMSupport649  EMBED_CAPI_LINK_LIBS650    MLIRCAPIIR651    MLIRCAPINVGPU652)653 654declare_mlir_python_extension(MLIRPythonExtension.Dialects.PDL.Pybind655  MODULE_NAME _mlirDialectsPDL656  ADD_TO_PARENT MLIRPythonSources.Dialects.pdl657  ROOT_DIR "${PYTHON_SOURCE_DIR}"658  PYTHON_BINDINGS_LIBRARY nanobind659  SOURCES660    DialectPDL.cpp661  PRIVATE_LINK_LIBS662    LLVMSupport663  EMBED_CAPI_LINK_LIBS664    MLIRCAPIIR665    MLIRCAPIPDL666)667 668declare_mlir_python_extension(MLIRPythonExtension.Dialects.SparseTensor.Pybind669  MODULE_NAME _mlirDialectsSparseTensor670  ADD_TO_PARENT MLIRPythonSources.Dialects.sparse_tensor671  ROOT_DIR "${PYTHON_SOURCE_DIR}"672  PYTHON_BINDINGS_LIBRARY nanobind673  SOURCES674    DialectSparseTensor.cpp675  PRIVATE_LINK_LIBS676    LLVMSupport677  EMBED_CAPI_LINK_LIBS678    MLIRCAPIIR679    MLIRCAPISparseTensor680)681 682declare_mlir_python_extension(MLIRPythonExtension.Dialects.Transform.Pybind683  MODULE_NAME _mlirDialectsTransform684  ADD_TO_PARENT MLIRPythonSources.Dialects.transform685  ROOT_DIR "${PYTHON_SOURCE_DIR}"686  PYTHON_BINDINGS_LIBRARY nanobind687  SOURCES688    DialectTransform.cpp689  PRIVATE_LINK_LIBS690    LLVMSupport691  EMBED_CAPI_LINK_LIBS692    MLIRCAPIIR693    MLIRCAPITransformDialect694)695 696declare_mlir_python_extension(MLIRPythonExtension.Dialects.IRDL.Pybind697  MODULE_NAME _mlirDialectsIRDL698  ADD_TO_PARENT MLIRPythonSources.Dialects.irdl699  ROOT_DIR "${PYTHON_SOURCE_DIR}"700  PYTHON_BINDINGS_LIBRARY nanobind701  SOURCES702    DialectIRDL.cpp703  PRIVATE_LINK_LIBS704    LLVMSupport705  EMBED_CAPI_LINK_LIBS706    MLIRCAPIIR707    MLIRCAPIIRDL708)709 710declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses711  MODULE_NAME _mlirAsyncPasses712  ADD_TO_PARENT MLIRPythonSources.Dialects.async713  ROOT_DIR "${PYTHON_SOURCE_DIR}"714  PYTHON_BINDINGS_LIBRARY nanobind715  SOURCES716    AsyncPasses.cpp717  PRIVATE_LINK_LIBS718    LLVMSupport719  EMBED_CAPI_LINK_LIBS720    MLIRCAPIAsync721)722 723if(MLIR_ENABLE_EXECUTION_ENGINE)724  declare_mlir_python_extension(MLIRPythonExtension.ExecutionEngine725    MODULE_NAME _mlirExecutionEngine726    ADD_TO_PARENT MLIRPythonSources.ExecutionEngine727    ROOT_DIR "${PYTHON_SOURCE_DIR}"728    PYTHON_BINDINGS_LIBRARY nanobind729    SOURCES730      ExecutionEngineModule.cpp731    PRIVATE_LINK_LIBS732      LLVMSupport733    EMBED_CAPI_LINK_LIBS734      MLIRCAPIExecutionEngine735  )736endif()737 738declare_mlir_python_extension(MLIRPythonExtension.GPUDialectPasses739  MODULE_NAME _mlirGPUPasses740  ADD_TO_PARENT MLIRPythonSources.Dialects.gpu741  ROOT_DIR "${PYTHON_SOURCE_DIR}"742  PYTHON_BINDINGS_LIBRARY nanobind743  SOURCES744    GPUPasses.cpp745  PRIVATE_LINK_LIBS746    LLVMSupport747  EMBED_CAPI_LINK_LIBS748    MLIRCAPIGPU749)750 751declare_mlir_python_extension(MLIRPythonExtension.LinalgPasses752  MODULE_NAME _mlirLinalgPasses753  ADD_TO_PARENT MLIRPythonSources.Dialects.linalg754  ROOT_DIR "${PYTHON_SOURCE_DIR}"755  PYTHON_BINDINGS_LIBRARY nanobind756  SOURCES757    LinalgPasses.cpp758  PRIVATE_LINK_LIBS759    LLVMSupport760  EMBED_CAPI_LINK_LIBS761    MLIRCAPILinalg762)763 764declare_mlir_python_extension(MLIRPythonExtension.Dialects.SMT.Pybind765  MODULE_NAME _mlirDialectsSMT766  ADD_TO_PARENT MLIRPythonSources.Dialects.smt767  ROOT_DIR "${PYTHON_SOURCE_DIR}"768  PYTHON_BINDINGS_LIBRARY nanobind769  SOURCES770    DialectSMT.cpp771    # Headers must be included explicitly so they are installed.772    NanobindUtils.h773  PRIVATE_LINK_LIBS774    LLVMSupport775  EMBED_CAPI_LINK_LIBS776    MLIRCAPIIR777    MLIRCAPISMT778    MLIRCAPIExportSMTLIB779)780 781declare_mlir_python_extension(MLIRPythonExtension.SparseTensorDialectPasses782  MODULE_NAME _mlirSparseTensorPasses783  ADD_TO_PARENT MLIRPythonSources.Dialects.sparse_tensor784  ROOT_DIR "${PYTHON_SOURCE_DIR}"785  PYTHON_BINDINGS_LIBRARY nanobind786  SOURCES787    SparseTensorPasses.cpp788  PRIVATE_LINK_LIBS789    LLVMSupport790  EMBED_CAPI_LINK_LIBS791    MLIRCAPISparseTensor792)793 794declare_mlir_python_extension(MLIRPythonExtension.TransformInterpreter795  MODULE_NAME _mlirTransformInterpreter796  ADD_TO_PARENT MLIRPythonSources.Dialects.transform797  ROOT_DIR "${PYTHON_SOURCE_DIR}"798  PYTHON_BINDINGS_LIBRARY nanobind799  SOURCES800    TransformInterpreter.cpp801  PRIVATE_LINK_LIBS802    LLVMSupport803  EMBED_CAPI_LINK_LIBS804    MLIRCAPITransformDialectTransforms805)806 807# TODO: Figure out how to put this in the test tree.808# This should not be included in the main Python extension. However,809# putting it into MLIRPythonTestSources along with the dialect declaration810# above confuses Python module loader when running under lit.811set(_ADDL_TEST_SOURCES)812if(MLIR_INCLUDE_TESTS)813  set(_ADDL_TEST_SOURCES MLIRPythonTestSources)814  declare_mlir_python_sources(MLIRPythonTestSources)815  declare_mlir_python_sources(MLIRPythonTestSources.Dialects816    ADD_TO_PARENT MLIRPythonTestSources)817 818  # TODO: this uses a tablegen file from the test directory and should be819  # decoupled from here.820  declare_mlir_python_sources(821    MLIRPythonTestSources.Dialects.PythonTest822    ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"823    ADD_TO_PARENT MLIRPythonTestSources.Dialects824    SOURCES825      dialects/python_test.py826  )827  set(LLVM_TARGET_DEFINITIONS828    "${MLIR_MAIN_SRC_DIR}/test/python/python_test_ops.td")829  mlir_tablegen(830    "dialects/_python_test_ops_gen.py"831    -gen-python-op-bindings832    -bind-dialect=python_test)833  add_public_tablegen_target(PythonTestDialectPyIncGen)834  declare_mlir_python_sources(835    MLIRPythonTestSources.Dialects.PythonTest.ops_gen836    ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}"837    ADD_TO_PARENT MLIRPythonTestSources.Dialects.PythonTest838    SOURCES "dialects/_python_test_ops_gen.py")839 840  declare_mlir_python_extension(MLIRPythonTestSources.PythonTestExtensionPybind11841    MODULE_NAME _mlirPythonTestPybind11842    ADD_TO_PARENT MLIRPythonTestSources.Dialects843    ROOT_DIR "${MLIR_SOURCE_DIR}/test/python/lib"844    PYTHON_BINDINGS_LIBRARY pybind11845    SOURCES846      PythonTestModulePybind11.cpp847    PRIVATE_LINK_LIBS848      LLVMSupport849    EMBED_CAPI_LINK_LIBS850      MLIRCAPIPythonTestDialect851  )852  declare_mlir_python_extension(MLIRPythonTestSources.PythonTestExtensionNanobind853    MODULE_NAME _mlirPythonTestNanobind854    ADD_TO_PARENT MLIRPythonTestSources.Dialects855    ROOT_DIR "${MLIR_SOURCE_DIR}/test/python/lib"856    PYTHON_BINDINGS_LIBRARY nanobind857    SOURCES858      PythonTestModuleNanobind.cpp859    PRIVATE_LINK_LIBS860      LLVMSupport861    EMBED_CAPI_LINK_LIBS862      MLIRCAPIPythonTestDialect863  )864endif()865 866################################################################################867# Common CAPI dependency DSO.868# All python extensions must link through one DSO which exports the CAPI, and869# this must have a globally unique name amongst all embeddors of the python870# library since it will effectively have global scope.871#872# The presence of this aggregate library is part of the long term plan, but its873# use needs to be made more flexible.874#875# TODO: Upgrade to the aggregate utility in https://reviews.llvm.org/D106419876# once ready.877################################################################################878 879set(MLIRPythonModules_ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}")880add_mlir_python_common_capi_library(MLIRPythonCAPI881  INSTALL_COMPONENT MLIRPythonModules882  INSTALL_DESTINATION "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/_mlir_libs"883  OUTPUT_DIRECTORY "${MLIRPythonModules_ROOT_PREFIX}/_mlir_libs"884  RELATIVE_INSTALL_ROOT "../../../.."885  DECLARED_HEADERS886    MLIRPythonCAPI.HeaderSources887  DECLARED_SOURCES888    MLIRPythonSources889    MLIRPythonExtension.RegisterEverything890    ${_ADDL_TEST_SOURCES}891)892 893################################################################################894# Custom targets.895################################################################################896 897_flatten_mlir_python_targets(mlir_python_sources_deps MLIRPythonSources)898 899if(MLIR_PYTHON_STUBGEN_ENABLED)900  # _mlir stubgen901  # Note: All this needs to come before add_mlir_python_modules(MLIRPythonModules so that the install targets for the902  # generated type stubs get created.903 904  set(_core_type_stub_sources905    _mlir/__init__.pyi906    _mlir/ir.pyi907    _mlir/passmanager.pyi908    _mlir/rewrite.pyi909  )910 911  # Note 1: INTERFACE_SOURCES is a genex ($<BUILD_INTERFACE> $<INSTALL_INTERFACE>)912  # which will be evaluated by file(GENERATE ...) inside mlir_generate_type_stubs. This will evaluate to the correct913  # thing in the build dir (i.e., actual source dir paths) and in the install dir914  # (where it's a conventional path; see install/lib/cmake/mlir/MLIRTargets.cmake).915  #916  # Note 2: MLIRPythonExtension.Core is the target that is defined using target_sources(INTERFACE)917  # **NOT** MLIRPythonModules.extension._mlir.dso. So be sure to use the correct target!918  get_target_property(_core_extension_srcs MLIRPythonExtension.Core INTERFACE_SOURCES)919 920  # Why is MODULE_NAME _mlir here but mlir._mlir_libs._mlirPythonTestNanobind below???921  # The _mlir extension can be imported independently of any other python code and/or extension modules.922  # I.e., you could do `cd $MLIRPythonModules_ROOT_PREFIX/_mlir_libs && python -c "import _mlir"` (try it!).923  # _mlir is also (currently) the only extension for which this is possible because dialect extensions modules,924  # which generally make use of `mlir_value_subclass/mlir_type_subclass/mlir_attribute_subclass`, perform an925  # `import mlir` right when they're loaded (see the mlir_*_subclass ctors in NanobindAdaptors.h).926  # Note, this also why IMPORT_PATHS "${MLIRPythonModules_ROOT_PREFIX}/_mlir_libs" here while below927  # "${MLIRPythonModules_ROOT_PREFIX}/.." (because MLIR_BINDINGS_PYTHON_INSTALL_PREFIX, by default, ends at mlir).928  #929  # Further note: this function creates file targets like930  # "${CMAKE_CURRENT_BINARY_DIR}/type_stubs/_mlir_libs/_mlir/__init__.pyi". These must match the file targets931  # that declare_mlir_python_sources expects, which are like "${ROOT_DIR}/${WHATEVER_SOURCE}".932  # This is why _mlir_libs is prepended below.933  mlir_generate_type_stubs(934    MODULE_NAME _mlir935    DEPENDS_TARGETS MLIRPythonModules.extension._mlir.dso936    OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs/_mlir_libs"937    OUTPUTS "${_core_type_stub_sources}"938    DEPENDS_TARGET_SRC_DEPS "${_core_extension_srcs}"939    IMPORT_PATHS "${MLIRPythonModules_ROOT_PREFIX}/_mlir_libs"940  )941  set(_mlir_typestub_gen_target "${NB_STUBGEN_CUSTOM_TARGET}")942 943  list(TRANSFORM _core_type_stub_sources PREPEND "_mlir_libs/")944  # Note, we do not do ADD_TO_PARENT here so that the type stubs are not associated (as mlir_DEPENDS) with945  # MLIRPythonSources.Core (or something) when a distro is installed/created. Otherwise they would not be regenerated946  # by users of the distro (the stubs are still installed in the distro - they are just not added to mlir_DEPENDS).947  declare_mlir_python_sources(948    MLIRPythonExtension.Core.type_stub_gen949    ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs"950    SOURCES "${_core_type_stub_sources}"951  )952  list(APPEND mlir_python_sources_deps MLIRPythonExtension.Core.type_stub_gen)953 954  # _mlirPythonTestNanobind stubgen955 956  if(MLIR_INCLUDE_TESTS)957    get_target_property(_test_extension_srcs MLIRPythonTestSources.PythonTestExtensionNanobind INTERFACE_SOURCES)958    mlir_generate_type_stubs(959      # This is the FQN path because dialect modules import _mlir when loaded. See above.960      MODULE_NAME mlir._mlir_libs._mlirPythonTestNanobind961      DEPENDS_TARGETS962        # You need both _mlir and _mlirPythonTestNanobind because dialect modules import _mlir when loaded963        # (so _mlir needs to be built before calling stubgen).964        MLIRPythonModules.extension._mlir.dso965        MLIRPythonModules.extension._mlirPythonTestNanobind.dso966        # You need this one so that ir.py "built" because mlir._mlir_libs.__init__.py import mlir.ir in _site_initialize.967        MLIRPythonModules.sources.MLIRPythonSources.Core.Python968      OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs/_mlir_libs"969      OUTPUTS _mlirPythonTestNanobind.pyi970      DEPENDS_TARGET_SRC_DEPS "${_test_extension_srcs}"971      IMPORT_PATHS "${MLIRPythonModules_ROOT_PREFIX}/.."972    )973    set(_mlirPythonTestNanobind_typestub_gen_target "${NB_STUBGEN_CUSTOM_TARGET}")974    declare_mlir_python_sources(975      MLIRPythonTestSources.PythonTestExtensionNanobind.type_stub_gen976      ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs"977      ADD_TO_PARENT MLIRPythonTestSources.Dialects978      SOURCES _mlir_libs/_mlirPythonTestNanobind.pyi979    )980  endif()981endif()982 983add_custom_target("mlir-python-sources" DEPENDS ${mlir_python_sources_deps})984if(NOT LLVM_ENABLE_IDE)985  add_llvm_install_targets(install-mlir-python-sources986    DEPENDS mlir-python-sources987    COMPONENT mlir-python-sources988  )989endif()990 991################################################################################992# The fully assembled package of modules.993# This must come last.994################################################################################995 996set(_declared_sources MLIRPythonSources MLIRPythonExtension.RegisterEverything)997if(MLIR_PYTHON_STUBGEN_ENABLED)998  list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)999endif()1000 1001add_mlir_python_modules(MLIRPythonModules1002  ROOT_PREFIX ${MLIRPythonModules_ROOT_PREFIX}1003  INSTALL_PREFIX "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"1004  DECLARED_SOURCES1005    ${_declared_sources}1006    ${_ADDL_TEST_SOURCES}1007  COMMON_CAPI_LINK_LIBS1008    MLIRPythonCAPI1009)1010if(MLIR_PYTHON_STUBGEN_ENABLED)1011  add_dependencies(MLIRPythonModules "${_mlir_typestub_gen_target}")1012  if(MLIR_INCLUDE_TESTS)1013    add_dependencies(MLIRPythonModules "${_mlirPythonTestNanobind_typestub_gen_target}")1014  endif()1015endif()1016