1# This file is licensed 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# Description:
6#   Python bindings for MLIR.
7#
8# We define separate filegroups for files in different directories so
9# that downstream users can mirror the tree in their own py_library() rules.
10
11load("//mlir:tblgen.bzl", "gentbl_filegroup", "td_library")
12
13package(
14    default_visibility = [
15        "//visibility:public",
16    ],
17    licenses = ["notice"],
18)
19
20##---------------------------------------------------------------------------##
21# Core IR modules.
22##---------------------------------------------------------------------------##
23
24filegroup(
25    name = "ConversionsPyFiles",
26    srcs = glob([
27        "mlir/conversions/*.py",
28    ]),
29)
30
31filegroup(
32    name = "DialectCorePyFiles",
33    srcs = [
34        "mlir/dialects/_ods_common.py",
35    ],
36)
37
38filegroup(
39    name = "ExecutionEnginePyFiles",
40    srcs = [
41        "mlir/execution_engine.py",
42    ],
43)
44
45filegroup(
46    name = "ExecutionEnginePyIFiles",
47    srcs = [
48        "mlir/_mlir_libs/_mlirExecutionEngine.pyi",
49    ],
50)
51
52filegroup(
53    name = "IRPyFiles",
54    srcs = [
55        "mlir/ir.py",
56    ],
57)
58
59filegroup(
60    name = "IRPyIFiles",
61    srcs = [
62        "mlir/_mlir_libs/_mlir/__init__.pyi",
63        "mlir/_mlir_libs/_mlir/ir.pyi",
64    ],
65)
66
67filegroup(
68    name = "PassManagerPyFiles",
69    srcs = [
70        "mlir/passmanager.py",
71    ],
72)
73
74filegroup(
75    name = "PassManagerPyIFiles",
76    srcs = [
77        "mlir/_mlir_libs/_mlir/passmanager.pyi",
78    ],
79)
80
81filegroup(
82    name = "RuntimePyFiles",
83    srcs = glob([
84        "mlir/runtime/*.py",
85    ]),
86)
87
88filegroup(
89    name = "TransformsPyFiles",
90    srcs = glob([
91        "mlir/transforms/*.py",
92    ]),
93)
94
95filegroup(
96    name = "AllPassesRegistrationPyFiles",
97    srcs = glob([
98        "mlir/all_passes_registration/*.py",
99    ]),
100)
101
102##---------------------------------------------------------------------------##
103# Builtin dialect.
104##---------------------------------------------------------------------------##
105
106td_library(
107    name = "BuiltinOpsPyTdFiles",
108    srcs = [
109        "mlir/dialects/BuiltinOps.td",
110        "//mlir:include/mlir/Bindings/Python/Attributes.td",
111    ],
112    deps = [
113        "//mlir:BuiltinDialectTdFiles",
114        "//mlir:FunctionInterfacesTdFiles",
115        "//mlir:OpBaseTdFiles",
116    ],
117)
118
119gentbl_filegroup(
120    name = "BuiltinOpsPyGen",
121    tbl_outs = [
122        (
123            [
124                "-gen-python-op-bindings",
125                "-bind-dialect=builtin",
126            ],
127            "mlir/dialects/_builtin_ops_gen.py",
128        ),
129    ],
130    tblgen = "//mlir:mlir-tblgen",
131    td_file = "mlir/dialects/BuiltinOps.td",
132    deps = [
133        ":BuiltinOpsPyTdFiles",
134    ],
135)
136
137filegroup(
138    name = "BuiltinOpsPyFiles",
139    srcs = [
140        "mlir/dialects/_builtin_ops_ext.py",
141        "mlir/dialects/builtin.py",
142        ":BuiltinOpsPyGen",
143    ],
144)
145
146##---------------------------------------------------------------------------##
147# Linalg dialect.
148##---------------------------------------------------------------------------##
149
150td_library(
151    name = "LinalgOpsPyTdFiles",
152    srcs = [
153        "mlir/dialects/LinalgOps.td",
154        "//mlir:include/mlir/Bindings/Python/Attributes.td",
155    ],
156    deps = [
157        "//mlir:LinalgOpsTdFiles",
158        "//mlir:LinalgStructuredOpsTdFiles",
159        "//mlir:OpBaseTdFiles",
160    ],
161)
162
163gentbl_filegroup(
164    name = "LinalgOpsPyGen",
165    tbl_outs = [
166        (
167            [
168                "-gen-python-op-bindings",
169                "-bind-dialect=linalg",
170            ],
171            "mlir/dialects/_linalg_ops_gen.py",
172        ),
173    ],
174    tblgen = "//mlir:mlir-tblgen",
175    td_file = "mlir/dialects/LinalgOps.td",
176    deps = [
177        ":LinalgOpsPyTdFiles",
178    ],
179)
180
181filegroup(
182    name = "LinalgOpsPyFiles",
183    srcs = [
184        "mlir/dialects/_linalg_ops_ext.py",
185        ":LinalgOpsPyGen",
186    ],
187)
188
189filegroup(
190    name = "LinalgOpsPackagePyFiles",
191    srcs = glob(["mlir/dialects/linalg/*.py"]),
192)
193
194filegroup(
195    name = "LinalgOpsPackageOpDSLPyFiles",
196    srcs = glob(["mlir/dialects/linalg/opdsl/*.py"]),
197)
198
199filegroup(
200    name = "LinalgOpsPackageOpDSLLangPyFiles",
201    srcs = glob(["mlir/dialects/linalg/opdsl/lang/*.py"]),
202)
203
204filegroup(
205    name = "LinalgOpsPackageOpDSLOpsPyFiles",
206    srcs = glob(["mlir/dialects/linalg/opdsl/ops/*.py"]),
207)
208
209filegroup(
210    name = "LinalgOpsPackagePassesPyFiles",
211    srcs = glob(["mlir/dialects/linalg/passes/*.py"]),
212)
213
214##---------------------------------------------------------------------------##
215# Arithmetic dialect.
216##---------------------------------------------------------------------------##
217
218td_library(
219    name = "ArithmeticOpsPyTdFiles",
220    srcs = [
221        "//mlir:include/mlir/Bindings/Python/Attributes.td",
222    ],
223    includes = ["../include"],
224    deps = [
225        "//mlir:ArithmeticOpsTdFiles",
226        "//mlir:OpBaseTdFiles",
227    ],
228)
229
230gentbl_filegroup(
231    name = "ArithmeticOpsPyGen",
232    tbl_outs = [
233        (
234            [
235                "-gen-python-op-bindings",
236                "-bind-dialect=arith",
237            ],
238            "mlir/dialects/_arith_ops_gen.py",
239        ),
240    ],
241    tblgen = "//mlir:mlir-tblgen",
242    td_file = "mlir/dialects/ArithmeticOps.td",
243    deps = [
244        ":ArithmeticOpsPyTdFiles",
245    ],
246)
247
248filegroup(
249    name = "ArithmeticOpsPyFiles",
250    srcs = [
251        "mlir/dialects/_arith_ops_ext.py",
252        "mlir/dialects/arith.py",
253        ":ArithmeticOpsPyGen",
254    ],
255)
256
257##---------------------------------------------------------------------------##
258# Math dialect.
259##---------------------------------------------------------------------------##
260
261td_library(
262    name = "MathOpsPyTdFiles",
263    srcs = [
264        "//mlir:include/mlir/Bindings/Python/Attributes.td",
265    ],
266    includes = ["../include"],
267    deps = [
268        "//mlir:MathOpsTdFiles",
269        "//mlir:OpBaseTdFiles",
270    ],
271)
272
273gentbl_filegroup(
274    name = "MathOpsPyGen",
275    tbl_outs = [
276        (
277            [
278                "-gen-python-op-bindings",
279                "-bind-dialect=math",
280            ],
281            "mlir/dialects/_math_ops_gen.py",
282        ),
283    ],
284    tblgen = "//mlir:mlir-tblgen",
285    td_file = "mlir/dialects/MathOps.td",
286    deps = [
287        ":MathOpsPyTdFiles",
288    ],
289)
290
291filegroup(
292    name = "MathOpsPyFiles",
293    srcs = [
294        "mlir/dialects/math.py",
295        ":MathOpsPyGen",
296    ],
297)
298
299##---------------------------------------------------------------------------##
300# MemRef dialect.
301##---------------------------------------------------------------------------##
302
303td_library(
304    name = "MemRefOpsPyTdFiles",
305    srcs = [
306        "//mlir:include/mlir/Bindings/Python/Attributes.td",
307    ],
308    includes = ["../include"],
309    deps = [
310        "//mlir:MemRefOpsTdFiles",
311        "//mlir:OpBaseTdFiles",
312    ],
313)
314
315gentbl_filegroup(
316    name = "MemRefOpsPyGen",
317    tbl_outs = [
318        (
319            [
320                "-gen-python-op-bindings",
321                "-bind-dialect=memref",
322            ],
323            "mlir/dialects/_memref_ops_gen.py",
324        ),
325    ],
326    tblgen = "//mlir:mlir-tblgen",
327    td_file = "mlir/dialects/MemRefOps.td",
328    deps = [
329        ":MemRefOpsPyTdFiles",
330    ],
331)
332
333filegroup(
334    name = "MemRefOpsPyFiles",
335    srcs = [
336        "mlir/dialects/_memref_ops_ext.py",
337        "mlir/dialects/memref.py",
338        ":MemRefOpsPyGen",
339    ],
340)
341
342##---------------------------------------------------------------------------##
343# PDL dialect.
344##---------------------------------------------------------------------------##
345
346td_library(
347    name = "PDLPyTdFiles",
348    srcs = [
349        "//mlir:include/mlir/Bindings/Python/Attributes.td",
350    ],
351    includes = ["../include"],
352    deps = [
353        "//mlir:OpBaseTdFiles",
354        "//mlir:PDLDialectTdFiles",
355    ],
356)
357
358gentbl_filegroup(
359    name = "PDLPyGen",
360    tbl_outs = [
361        (
362            [
363                "-gen-python-op-bindings",
364                "-bind-dialect=pdl",
365            ],
366            "mlir/dialects/_pdl_ops_gen.py",
367        ),
368    ],
369    tblgen = "//mlir:mlir-tblgen",
370    td_file = "mlir/dialects/PDLOps.td",
371    deps = [
372        ":PDLPyTdFiles",
373    ],
374)
375
376filegroup(
377    name = "PDLPyIFiles",
378    srcs = [
379        "mlir/_mlir_libs/_mlir/dialects/pdl.pyi",
380    ],
381)
382
383filegroup(
384    name = "PDLPyFiles",
385    srcs = [
386        "mlir/dialects/_pdl_ops_ext.py",
387        "mlir/dialects/pdl.py",
388        ":PDLPyGen",
389    ],
390)
391
392
393##---------------------------------------------------------------------------##
394# PythonTest dialect.
395##---------------------------------------------------------------------------##
396
397td_library(
398    name = "PythonTestPyTdFiles",
399    srcs = [
400        "//mlir:include/mlir/Bindings/Python/Attributes.td",
401    ],
402    deps = [
403        "//mlir:InferTypeOpInterfaceTdFiles",
404        "//mlir:OpBaseTdFiles",
405    ],
406)
407
408gentbl_filegroup(
409    name = "PythonTestPyGen",
410    tbl_outs = [
411        (
412            [
413                "-gen-python-op-bindings",
414                "-bind-dialect=python_test",
415            ],
416            "mlir/dialects/_python_test_ops_gen.py",
417        ),
418    ],
419    tblgen = "//mlir:mlir-tblgen",
420    td_file = "//mlir/test/python:python_test_ops.td",
421    deps = [
422        ":PythonTestPyTdFiles",
423    ],
424)
425
426filegroup(
427    name = "PythonTestPyFiles",
428    srcs = [
429        "mlir/dialects/python_test.py",
430        ":PythonTestPyGen",
431    ],
432)
433
434##---------------------------------------------------------------------------##
435# Quant dialect.
436##---------------------------------------------------------------------------##
437
438filegroup(
439    name = "QuantPyIFiles",
440    srcs = [
441        "mlir/_mlir_libs/_mlir/dialects/quant.pyi",
442    ],
443)
444
445filegroup(
446    name = "QuantPyFiles",
447    srcs = [
448        "mlir/dialects/quant.py",
449    ],
450)
451
452
453##---------------------------------------------------------------------------##
454# SCF dialect.
455##---------------------------------------------------------------------------##
456
457td_library(
458    name = "SCFPyTdFiles",
459    srcs = [
460        "//mlir:include/mlir/Bindings/Python/Attributes.td",
461    ],
462    includes = ["../include"],
463    deps = [
464        "//mlir:OpBaseTdFiles",
465        "//mlir:SCFTdFiles",
466    ],
467)
468
469gentbl_filegroup(
470    name = "SCFPyGen",
471    tbl_outs = [
472        (
473            [
474                "-gen-python-op-bindings",
475                "-bind-dialect=scf",
476            ],
477            "mlir/dialects/_scf_ops_gen.py",
478        ),
479    ],
480    tblgen = "//mlir:mlir-tblgen",
481    td_file = "mlir/dialects/SCFOps.td",
482    deps = [
483        ":SCFPyTdFiles",
484    ],
485)
486
487filegroup(
488    name = "SCFPyFiles",
489    srcs = [
490        "mlir/dialects/_scf_ops_ext.py",
491        "mlir/dialects/scf.py",
492        ":SCFPyGen",
493    ],
494)
495
496##---------------------------------------------------------------------------##
497# Shape dialect.
498##---------------------------------------------------------------------------##
499
500td_library(
501    name = "ShapeOpsPyTdFiles",
502    srcs = [
503        "//mlir:include/mlir/Bindings/Python/Attributes.td",
504    ],
505    includes = ["../include"],
506    deps = [
507        "//mlir:OpBaseTdFiles",
508        "//mlir:ShapeOpsTdFiles",
509    ],
510)
511
512gentbl_filegroup(
513    name = "ShapeOpsPyGen",
514    tbl_outs = [
515        (
516            [
517                "-gen-python-op-bindings",
518                "-bind-dialect=shape",
519            ],
520            "mlir/dialects/_shape_ops_gen.py",
521        ),
522    ],
523    tblgen = "//mlir:mlir-tblgen",
524    td_file = "mlir/dialects/ShapeOps.td",
525    deps = [
526        ":ShapeOpsPyTdFiles",
527    ],
528)
529
530filegroup(
531    name = "ShapeOpsPyFiles",
532    srcs = [
533        "mlir/dialects/shape.py",
534        ":ShapeOpsPyGen",
535    ],
536)
537
538##---------------------------------------------------------------------------##
539# Func dialect.
540##---------------------------------------------------------------------------##
541
542td_library(
543    name = "FuncPyTdFiles",
544    srcs = [
545        "//mlir:include/mlir/Bindings/Python/Attributes.td",
546    ],
547    deps = [
548        "//mlir:FuncTdFiles",
549        "//mlir:OpBaseTdFiles",
550    ],
551)
552
553gentbl_filegroup(
554    name = "FuncPyGen",
555    tbl_outs = [
556        (
557            [
558                "-gen-python-op-bindings",
559                "-bind-dialect=func",
560            ],
561            "mlir/dialects/_func_ops_gen.py",
562        ),
563    ],
564    tblgen = "//mlir:mlir-tblgen",
565    td_file = "mlir/dialects/FuncOps.td",
566    deps = [
567        ":FuncPyTdFiles",
568    ],
569)
570
571filegroup(
572    name = "FuncPyFiles",
573    srcs = [
574        "mlir/dialects/_func_ops_ext.py",
575        "mlir/dialects/func.py",
576        ":FuncPyGen",
577    ],
578)
579
580##---------------------------------------------------------------------------##
581# SparseTensor dialect.
582##---------------------------------------------------------------------------##
583
584td_library(
585    name = "SparseTensorOpsPyTdFiles",
586    srcs = [
587        "//mlir:include/mlir/Bindings/Python/Attributes.td",
588    ],
589    deps = [
590        "//mlir:OpBaseTdFiles",
591        "//mlir:SparseTensorTdFiles",
592    ],
593)
594
595gentbl_filegroup(
596    name = "SparseTensorOpsPyGen",
597    tbl_outs = [
598        (
599            [
600                "-gen-python-op-bindings",
601                "-bind-dialect=sparse_tensor",
602            ],
603            "mlir/dialects/_sparse_tensor_ops_gen.py",
604        ),
605    ],
606    tblgen = "//mlir:mlir-tblgen",
607    td_file = "mlir/dialects/SparseTensorOps.td",
608    deps = [
609        ":SparseTensorOpsPyTdFiles",
610    ],
611)
612
613filegroup(
614    name = "SparseTensorOpsPyFiles",
615    srcs = [
616        "mlir/dialects/sparse_tensor.py",
617        ":SparseTensorOpsPyGen",
618    ],
619)
620
621##---------------------------------------------------------------------------##
622# Tosa dialect.
623##---------------------------------------------------------------------------##
624
625td_library(
626    name = "TosaOpsPyTdFiles",
627    srcs = [
628        "//mlir:include/mlir/Bindings/Python/Attributes.td",
629    ],
630    deps = [
631        "//mlir:OpBaseTdFiles",
632        "//mlir:TosaDialectTdFiles",
633    ],
634)
635
636gentbl_filegroup(
637    name = "TosaOpsPyGen",
638    tbl_outs = [
639        (
640            [
641                "-gen-python-op-bindings",
642                "-bind-dialect=tosa",
643            ],
644            "mlir/dialects/_tosa_ops_gen.py",
645        ),
646    ],
647    tblgen = "//mlir:mlir-tblgen",
648    td_file = "mlir/dialects/TosaOps.td",
649    deps = [
650        ":TosaOpsPyTdFiles",
651    ],
652)
653
654filegroup(
655    name = "TosaOpsPyFiles",
656    srcs = [
657        "mlir/dialects/tosa.py",
658        ":TosaOpsPyGen",
659    ],
660)
661
662##---------------------------------------------------------------------------##
663# Vector dialect.
664##---------------------------------------------------------------------------##
665
666td_library(
667    name = "VectorOpsPyTdFiles",
668    srcs = [
669        "//mlir:include/mlir/Bindings/Python/Attributes.td",
670    ],
671    includes = ["../include"],
672    deps = [
673        "//mlir:OpBaseTdFiles",
674        "//mlir:VectorOpsTdFiles",
675    ],
676)
677
678gentbl_filegroup(
679    name = "VectorOpsPyGen",
680    tbl_outs = [
681        (
682            [
683                "-gen-python-op-bindings",
684                "-bind-dialect=vector",
685            ],
686            "mlir/dialects/_vector_ops_gen.py",
687        ),
688    ],
689    tblgen = "//mlir:mlir-tblgen",
690    td_file = "mlir/dialects/VectorOps.td",
691    deps = [
692        ":VectorOpsPyTdFiles",
693    ],
694)
695
696filegroup(
697    name = "VectorOpsPyFiles",
698    srcs = [
699        "mlir/dialects/vector.py",
700        ":VectorOpsPyGen",
701    ],
702)
703