From f64bb19b37769b04f53777117148cf4f2d60dcba Mon Sep 17 00:00:00 2001 From: Jeremy Kun Date: Sat, 10 Feb 2024 15:55:50 -0800 Subject: [PATCH 1/5] add symlink_inputs --- .../mlir/python/symlink_inputs.bzl | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 utils/bazel/llvm-project-overlay/mlir/python/symlink_inputs.bzl diff --git a/utils/bazel/llvm-project-overlay/mlir/python/symlink_inputs.bzl b/utils/bazel/llvm-project-overlay/mlir/python/symlink_inputs.bzl new file mode 100644 index 0000000000000..7fcadb652a32c --- /dev/null +++ b/utils/bazel/llvm-project-overlay/mlir/python/symlink_inputs.bzl @@ -0,0 +1,173 @@ +"""Macros for symlinking files into certain directories at build time. + +This appeases rules that require certain directory structures (e.g. Bazel +Python rules) while allowing the use of filegroups and globs. This doesn't use +Fileset because that creates entire directories and therefore prevents multiple +rules from writing into the same directory (necessary for tests, among other +things). Basic usage: + +```build +# foo/bar/BUILD + +filegroup( + name = "all_bar_files", + srcs = glob(["*"]), +) +``` + +```build +biz/baz/BUILD + +symlink_files( + name = "all_bar_files", + dst = "bar", + srcs = ["//foo/bar:all_bar_files"], + flatten = True, +) + +py_library( + name = "bar", + srcs = [":all_bar_files"] +) +``` + +Or if you want to preserve the directory structure of the origin: + +```build +# foo/bar/BUILD + +filegroup( + name = "bar_tree", + srcs = glob(["**/*"]), +) +``` + +```build +biz/baz/BUILD + +symlink_files( + name = "bar_tree", + dst = "bar", + srcs = ["//foo/bar:bar_tree"], + strip_prefix = "foo/bar", +) + +py_library( + name = "bar", + srcs = [":bar_tree"] +) +``` + +A single macro `symlink_inputs` can also be used to wrap an arbitrary rule and +remap any of its inputs that takes a list of labels to be symlinked into some +directory relative to the current one, flattening all the files into a single +directory (as with the `flatten` option to symlink_files). + +symlink_inputs( + name = "bar" + rule = py_library, + symlinked_inputs = {"srcs", {"bar": ["//foo/bar:all_bar_files"]}}, +) +""" + +def _symlink_files_impl(ctx): + flatten = ctx.attr.flatten + strip_prefix = ctx.attr.strip_prefix + mapping = ctx.attr.mapping + outputs = [] + for src in ctx.files.srcs: + src_path = src.short_path + if src_path in mapping: + file_dst = mapping[src_path] + else: + file_dst = src.basename if flatten else src_path + if not file_dst.startswith(strip_prefix): + fail(("File {} has destination {} that does not begin with" + + " strip_prefix {}").format( + src, + file_dst, + strip_prefix, + )) + file_dst = file_dst[len(strip_prefix):] + outfile = ctx.attr.dst + "/" + file_dst + out = ctx.actions.declare_file(outfile) + outputs.append(out) + ctx.actions.symlink(output = out, target_file = src) + outputs = depset(outputs) + return [DefaultInfo( + files = outputs, + runfiles = ctx.runfiles(transitive_files = outputs), + )] + +symlink_files = rule( + implementation = _symlink_files_impl, + attrs = { + "dst": attr.string( + default = ".", + doc = "Destination directory into which to symlink `srcs`." + + " Relative to current directory.", + ), + "srcs": attr.label_list( + allow_files = True, + doc = "Files to symlink into `dst`.", + ), + "flatten": attr.bool( + default = False, + doc = "Whether files in `srcs` should all be flattened to be" + + " direct children of `dst` or preserve their existing" + + " directory structure.", + ), + "strip_prefix": attr.string( + default = "", + doc = "Literal string prefix to strip from the paths of all files" + + " in `srcs`. All files in `srcs` must begin with this" + + " prefix or be present mapping. Generally they would not be" + + " used together, but prefix stripping happens after flattening.", + ), + "mapping": attr.string_dict( + default = {}, + doc = "Dictionary indicating where individual files in `srcs`" + + " should be mapped to under `dst`. Keys are the origin" + + " path of the file (relative to the build system root) and" + + " values are the destination relative to `dst`. Files" + + " present in `mapping` ignore the `flatten` and" + + " `strip_prefix` attributes: their destination is based" + + " only on `dst` and the value for their key in `mapping`.", + ), + }, +) + +def symlink_inputs(name, rule, symlinked_inputs, **kwargs): + """Wraps a rule and symlinks input files into the current directory tree. + + Args: + rule: the rule (or macro) being wrapped. + name: name for the generated rule. + symlinked_inputs: a dictionary of dictionaries indicating label-list + arguments labels that should be passed to the generated rule after + being symlinked into the specified directory. For example: + {"srcs": {"bar": ["//foo/bar:bar.txt"]}} + **kwargs: additional keyword arguments to forward to the generated rule. + """ + for kwarg, mapping in symlinked_inputs.items(): + for dst, files in mapping.items(): + if kwarg in kwargs: + fail( + "key %s is already present in this rule" % (kwarg,), + attr = "symlinked_inputs", + ) + if dst == None: + kwargs[kwarg] = files + else: + symlinked_target_name = "_{}_{}".format(name, kwarg) + symlink_files( + name = symlinked_target_name, + dst = dst, + srcs = files, + flatten = True, + ) + kwargs[kwarg] = [":" + symlinked_target_name] + rule( + name = name, + **kwargs + ) From e989a99f4184336330de3d470c192dd298c9807b Mon Sep 17 00:00:00 2001 From: max Date: Sat, 10 Feb 2024 12:30:25 -0600 Subject: [PATCH 2/5] [mlir][bazel] refactor python bindings --- .../llvm-project-overlay/mlir/BUILD.bazel | 259 ------------------ .../mlir/python/mlir/_mlir_libs/BUILD.bazel | 258 +++++++++++++++++ 2 files changed, 258 insertions(+), 259 deletions(-) create mode 100644 utils/bazel/llvm-project-overlay/mlir/python/mlir/_mlir_libs/BUILD.bazel diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel index e9e7fe3b35b7e..97373af06e5bf 100644 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -862,265 +862,6 @@ mlir_c_api_cc_library( ], ) -##---------------------------------------------------------------------------## -# Sources of Python bindings. -#----------------------------------------------------------------------------## - -exports_files( - glob(["lib/Bindings/Python/**/*.cpp"]), -) - -# In the targets related to Python bindings, the projects @pybind11 and -# @local_config_python are defined by @pybind11_bazel. The latter contains -# python headers, and can be configured in an out-of-tree bazel project via -# -# load("@pybind11_bazel//:python_configure.bzl", "python_configure") -# python_configure(name = "local_config_python") -# -# For more up-to-date instructions, see -# https://github.com/pybind/pybind11_bazel -# -# Some out-of-tree projects alias @python_runtime//:headers to -# @local_config_python//:python_headers. - -MLIR_BINDINGS_PYTHON_HEADERS = [ - "lib/Bindings/Python/*.h", - "include/mlir-c/Bindings/Python/*.h", - "include/mlir/Bindings/Python/*.h", -] - -cc_library( - name = "MLIRBindingsPythonHeaders", - includes = [ - "include", - "lib/Bindings/Python", - ], - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), - deps = [ - ":CAPIIRHeaders", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -cc_library( - name = "MLIRBindingsPythonHeadersAndDeps", - includes = [ - "include", - "lib/Bindings/Python", - ], - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), - deps = [ - ":CAPIIR", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -# These flags are needed for pybind11 to work. -PYBIND11_COPTS = [ - "-fexceptions", - "-frtti", -] - -PYBIND11_FEATURES = [ - # Cannot use header_modules (parse_headers feature fails). - "-use_header_modules", -] - -MLIR_PYTHON_BINDINGS_SOURCES = [ - "lib/Bindings/Python/IRAffine.cpp", - "lib/Bindings/Python/IRAttributes.cpp", - "lib/Bindings/Python/IRCore.cpp", - "lib/Bindings/Python/IRInterfaces.cpp", - "lib/Bindings/Python/IRModule.cpp", - "lib/Bindings/Python/IRTypes.cpp", - "lib/Bindings/Python/Pass.cpp", -] - -cc_library( - name = "MLIRBindingsPythonCore", - srcs = MLIR_PYTHON_BINDINGS_SOURCES, - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsync", - ":CAPIDebug", - ":CAPIIR", - ":CAPIInterfaces", - ":MLIRBindingsPythonHeadersAndDeps", - ":Support", - "//llvm:Support", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -cc_library( - name = "MLIRBindingsPythonCoreNoCAPI", - srcs = MLIR_PYTHON_BINDINGS_SOURCES, - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsyncHeaders", - ":CAPIDebugHeaders", - ":CAPIIRHeaders", - ":MLIRBindingsPythonHeaders", - "//llvm:Support", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -# Target that bundles together the CAPI objects needed for -# MLIRBindingsPythonCoreNoCAPI. -cc_library( - name = "MLIRBindingsPythonCAPIObjects", - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsyncObjects", - ":CAPIDebugObjects", - ":CAPIIRObjects", - ":CAPIInterfacesObjects", - ], -) - -# Dynamic library with the MLIR Python extension. -cc_binary( - name = "_mlir.so", - srcs = ["lib/Bindings/Python/MainModule.cpp"], - # These flags are needed for pybind11 to work. - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":MLIRBindingsPythonCore", - ":MLIRBindingsPythonHeadersAndDeps", - ], -) - -cc_binary( - name = "_mlirDialectsLinalg.so", - srcs = ["lib/Bindings/Python/DialectLinalg.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPILinalg", - ":MLIRBindingsPythonHeadersAndDeps", - ], -) - -cc_binary( - name = "_mlirDialectsQuant.so", - srcs = ["lib/Bindings/Python/DialectQuant.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPIQuant", - ":MLIRBindingsPythonHeadersAndDeps", - "@pybind11", - ], -) - -cc_binary( - name = "_mlirDialectsSparseTensor.so", - srcs = ["lib/Bindings/Python/DialectSparseTensor.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPISparseTensor", - ":MLIRBindingsPythonHeadersAndDeps", - "@pybind11", - ], -) - -# Dynamic library with the MLIR Conversions Python extension. -cc_binary( - name = "_mlirExecutionEngine.so", - srcs = ["lib/Bindings/Python/ExecutionEngineModule.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIExecutionEngine", - ":MLIRBindingsPythonHeadersAndDeps", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -# Dynamic library with the MLIR Linalg dialect+passes Python extension. -cc_binary( - name = "_mlirLinalgPasses.so", - srcs = ["lib/Bindings/Python/LinalgPasses.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPILinalg", - ":MLIRBindingsPythonHeadersAndDeps", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -##---------------------------------------------------------------------------## - td_library( name = "AttrTdFiles", srcs = [ diff --git a/utils/bazel/llvm-project-overlay/mlir/python/mlir/_mlir_libs/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/python/mlir/_mlir_libs/BUILD.bazel new file mode 100644 index 0000000000000..8219c70f032b5 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/mlir/python/mlir/_mlir_libs/BUILD.bazel @@ -0,0 +1,258 @@ +##---------------------------------------------------------------------------## +# Sources of Python bindings. +#----------------------------------------------------------------------------## + +package(default_visibility = ["//visibility:public"]) + +exports_files( + glob(["lib/Bindings/Python/**/*.cpp"]), +) + +# In the targets related to Python bindings, the projects @pybind11 and +# @local_config_python are defined by @pybind11_bazel. The latter contains +# python headers, and can be configured in an out-of-tree bazel project via +# +# load("@pybind11_bazel//:python_configure.bzl", "python_configure") +# python_configure(name = "local_config_python") +# +# For more up-to-date instructions, see +# https://github.com/pybind/pybind11_bazel +# +# Some out-of-tree projects alias @python_runtime//:headers to +# @local_config_python//:python_headers. + +MLIR_BINDINGS_PYTHON_HEADERS = [ + "lib/Bindings/Python/*.h", + "include/mlir-c/Bindings/Python/*.h", + "include/mlir/Bindings/Python/*.h", +] + +cc_library( + name = "MLIRBindingsPythonHeaders", + includes = [ + "include", + "lib/Bindings/Python", + ], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), + deps = [ + ":CAPIIRHeaders", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +cc_library( + name = "MLIRBindingsPythonHeadersAndDeps", + includes = [ + "include", + "lib/Bindings/Python", + ], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), + deps = [ + ":CAPIIR", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +# These flags are needed for pybind11 to work. +PYBIND11_COPTS = [ + "-fexceptions", + "-frtti", +] + +PYBIND11_FEATURES = [ + # Cannot use header_modules (parse_headers feature fails). + "-use_header_modules", +] + +MLIR_PYTHON_BINDINGS_SOURCES = [ + "lib/Bindings/Python/IRAffine.cpp", + "lib/Bindings/Python/IRAttributes.cpp", + "lib/Bindings/Python/IRCore.cpp", + "lib/Bindings/Python/IRInterfaces.cpp", + "lib/Bindings/Python/IRModule.cpp", + "lib/Bindings/Python/IRTypes.cpp", + "lib/Bindings/Python/Pass.cpp", +] + +cc_library( + name = "MLIRBindingsPythonCore", + srcs = MLIR_PYTHON_BINDINGS_SOURCES, + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIAsync", + ":CAPIDebug", + ":CAPIIR", + ":CAPIInterfaces", + ":MLIRBindingsPythonHeadersAndDeps", + ":Support", + "//llvm:Support", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +cc_library( + name = "MLIRBindingsPythonCoreNoCAPI", + srcs = MLIR_PYTHON_BINDINGS_SOURCES, + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIAsyncHeaders", + ":CAPIDebugHeaders", + ":CAPIIRHeaders", + ":MLIRBindingsPythonHeaders", + "//llvm:Support", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +# Target that bundles together the CAPI objects needed for +# MLIRBindingsPythonCoreNoCAPI. +cc_library( + name = "MLIRBindingsPythonCAPIObjects", + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIAsyncObjects", + ":CAPIDebugObjects", + ":CAPIIRObjects", + ":CAPIInterfacesObjects", + ], +) + +# Dynamic library with the MLIR Python extension. +cc_binary( + name = "_mlir.so", + srcs = ["lib/Bindings/Python/MainModule.cpp"], + # These flags are needed for pybind11 to work. + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + linkshared = 1, + linkstatic = 0, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":MLIRBindingsPythonCore", + ":MLIRBindingsPythonHeadersAndDeps", + ], +) + +cc_binary( + name = "_mlirDialectsLinalg.so", + srcs = ["lib/Bindings/Python/DialectLinalg.cpp"], + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + linkshared = 1, + linkstatic = 0, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIIR", + ":CAPILinalg", + ":MLIRBindingsPythonHeadersAndDeps", + ], +) + +cc_binary( + name = "_mlirDialectsQuant.so", + srcs = ["lib/Bindings/Python/DialectQuant.cpp"], + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + linkshared = 1, + linkstatic = 0, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIIR", + ":CAPIQuant", + ":MLIRBindingsPythonHeadersAndDeps", + "@pybind11", + ], +) + +cc_binary( + name = "_mlirDialectsSparseTensor.so", + srcs = ["lib/Bindings/Python/DialectSparseTensor.cpp"], + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + linkshared = 1, + linkstatic = 0, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIIR", + ":CAPISparseTensor", + ":MLIRBindingsPythonHeadersAndDeps", + "@pybind11", + ], +) + +# Dynamic library with the MLIR Conversions Python extension. +cc_binary( + name = "_mlirExecutionEngine.so", + srcs = ["lib/Bindings/Python/ExecutionEngineModule.cpp"], + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + linkshared = 1, + linkstatic = 0, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIExecutionEngine", + ":MLIRBindingsPythonHeadersAndDeps", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +# Dynamic library with the MLIR Linalg dialect+passes Python extension. +cc_binary( + name = "_mlirLinalgPasses.so", + srcs = ["lib/Bindings/Python/LinalgPasses.cpp"], + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + linkshared = 1, + linkstatic = 0, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPILinalg", + ":MLIRBindingsPythonHeadersAndDeps", + "@local_config_python//:python_headers", + "@pybind11", + ], +) \ No newline at end of file From a4e203674cc35a0037dbea53a597cdd898dc7ed6 Mon Sep 17 00:00:00 2001 From: max Date: Sat, 10 Feb 2024 12:43:22 -0600 Subject: [PATCH 3/5] hacks --- .../llvm-project-overlay/mlir/BUILD.bazel | 131 +++++++++ .../mlir/python/BUILD.bazel | 75 +++++ .../mlir/python/mlir/_mlir_libs/BUILD.bazel | 258 ------------------ 3 files changed, 206 insertions(+), 258 deletions(-) delete mode 100644 utils/bazel/llvm-project-overlay/mlir/python/mlir/_mlir_libs/BUILD.bazel diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel index 97373af06e5bf..16355b8206b5c 100644 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -862,6 +862,137 @@ mlir_c_api_cc_library( ], ) +##---------------------------------------------------------------------------## +# Sources of Python bindings. +#----------------------------------------------------------------------------## + +exports_files( + glob(["lib/Bindings/Python/**/*.cpp"]), +) + +MLIR_BINDINGS_PYTHON_HEADERS = [ + "lib/Bindings/Python/*.h", + "include/mlir-c/Bindings/Python/*.h", + "include/mlir/Bindings/Python/*.h", +] + +cc_library( + name = "MLIRBindingsPythonHeaders", + includes = [ + "include", + "lib/Bindings/Python", + ], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), + deps = [ + ":CAPIIRHeaders", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +cc_library( + name = "MLIRBindingsPythonHeadersAndDeps", + includes = [ + "include", + "lib/Bindings/Python", + ], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), + deps = [ + ":CAPIIR", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +# These flags are needed for pybind11 to work. +PYBIND11_COPTS = [ + "-fexceptions", + "-frtti", +] + +PYBIND11_FEATURES = [ + # Cannot use header_modules (parse_headers feature fails). + "-use_header_modules", +] + +MLIR_PYTHON_BINDINGS_SOURCES = [ + "lib/Bindings/Python/IRAffine.cpp", + "lib/Bindings/Python/IRAttributes.cpp", + "lib/Bindings/Python/IRCore.cpp", + "lib/Bindings/Python/IRInterfaces.cpp", + "lib/Bindings/Python/IRModule.cpp", + "lib/Bindings/Python/IRTypes.cpp", + "lib/Bindings/Python/Pass.cpp", +] + +cc_library( + name = "MLIRBindingsPythonCore", + srcs = MLIR_PYTHON_BINDINGS_SOURCES, + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIAsync", + ":CAPIDebug", + ":CAPIIR", + ":CAPIInterfaces", + ":MLIRBindingsPythonHeadersAndDeps", + ":Support", + "//llvm:Support", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +cc_library( + name = "MLIRBindingsPythonCoreNoCAPI", + srcs = MLIR_PYTHON_BINDINGS_SOURCES, + copts = PYBIND11_COPTS, + features = PYBIND11_FEATURES, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIAsyncHeaders", + ":CAPIDebugHeaders", + ":CAPIIRHeaders", + ":MLIRBindingsPythonHeaders", + "//llvm:Support", + "@local_config_python//:python_headers", + "@pybind11", + ], +) + +# Target that bundles together the CAPI objects needed for +# MLIRBindingsPythonCoreNoCAPI. +cc_library( + name = "MLIRBindingsPythonCAPIObjects", + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIAsyncObjects", + ":CAPIDebugObjects", + ":CAPIIRObjects", + ":CAPIInterfacesObjects", + ], +) + +##---------------------------------------------------------------------------## + td_library( name = "AttrTdFiles", srcs = [ diff --git a/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel index f19c2336e6bcb..71002881dfb5f 100644 --- a/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel @@ -8,12 +8,87 @@ # We define separate filegroups for files in different directories so # that downstream users can mirror the tree in their own py_library() rules. +load("@pybind11_bazel//:build_defs.bzl", "pybind_extension") load("//mlir:tblgen.bzl", "gentbl_filegroup", "td_library") package(default_visibility = ["//visibility:public"]) licenses(["notice"]) +##---------------------------------------------------------------------------## +# Sources of Python bindings. +#----------------------------------------------------------------------------## + +# Dynamic library with the MLIR Python extension. +pybind_extension( + name = "mlir/_mlir_libs/_mlir", + srcs = ["//mlir:lib/Bindings/Python/MainModule.cpp"], + deps = [ + "//mlir:MLIRBindingsPythonCore", + ], +) + +pybind_extension( + name = "mlir/_mlir_libs/_mlirDialectsLinalg", + srcs = ["//mlir:lib/Bindings/Python/DialectLinalg.cpp"], + deps = [ + "//mlir:CAPIIR", + "//mlir:CAPILinalg", + "//mlir:MLIRBindingsPythonHeadersAndDeps", + ], +) + +pybind_extension( + name = "mlir/_mlir_libs/_mlirDialectsQuant", + srcs = ["//mlir:lib/Bindings/Python/DialectQuant.cpp"], + deps = [ + "//mlir:CAPIIR", + "//mlir:CAPIQuant", + "//mlir:MLIRBindingsPythonHeadersAndDeps", + ], +) + +pybind_extension( + name = "mlir/_mlir_libs/_mlirDialectsSparseTensor", + srcs = ["//mlir:lib/Bindings/Python/DialectSparseTensor.cpp"], + deps = [ + "//mlir:CAPIIR", + "//mlir:CAPISparseTensor", + "//mlir:MLIRBindingsPythonHeadersAndDeps", + ], +) + +# Dynamic library with the MLIR Conversions Python extension. +pybind_extension( + name = "mlir/_mlir_libs/_mlirExecutionEngine", + srcs = ["//mlir:lib/Bindings/Python/ExecutionEngineModule.cpp"], + deps = [ + "//mlir:CAPIExecutionEngine", + "//mlir:MLIRBindingsPythonHeadersAndDeps", + ], +) + +# Dynamic library with the MLIR Linalg dialect+passes Python extension. +pybind_extension( + name = "mlir/_mlir_libs/_mlirLinalgPasses", + srcs = ["//mlir:lib/Bindings/Python/LinalgPasses.cpp"], + deps = [ + "//mlir:CAPILinalg", + "//mlir:MLIRBindingsPythonHeadersAndDeps", + ], +) + +pybind_extension( + name = "mlir/_mlir_libs/_mlirRegisterEverything", + srcs = ["//mlir:lib/Bindings/Python/RegisterEverything.cpp"], + deps = [ + "//mlir:CAPIConversion", + "//mlir:CAPITransforms", + "//mlir:CAPIRegisterEverything", + "//mlir:MLIRBindingsPythonHeadersAndDeps", + ], +) + ##---------------------------------------------------------------------------## # Core IR modules. ##---------------------------------------------------------------------------## diff --git a/utils/bazel/llvm-project-overlay/mlir/python/mlir/_mlir_libs/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/python/mlir/_mlir_libs/BUILD.bazel deleted file mode 100644 index 8219c70f032b5..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/python/mlir/_mlir_libs/BUILD.bazel +++ /dev/null @@ -1,258 +0,0 @@ -##---------------------------------------------------------------------------## -# Sources of Python bindings. -#----------------------------------------------------------------------------## - -package(default_visibility = ["//visibility:public"]) - -exports_files( - glob(["lib/Bindings/Python/**/*.cpp"]), -) - -# In the targets related to Python bindings, the projects @pybind11 and -# @local_config_python are defined by @pybind11_bazel. The latter contains -# python headers, and can be configured in an out-of-tree bazel project via -# -# load("@pybind11_bazel//:python_configure.bzl", "python_configure") -# python_configure(name = "local_config_python") -# -# For more up-to-date instructions, see -# https://github.com/pybind/pybind11_bazel -# -# Some out-of-tree projects alias @python_runtime//:headers to -# @local_config_python//:python_headers. - -MLIR_BINDINGS_PYTHON_HEADERS = [ - "lib/Bindings/Python/*.h", - "include/mlir-c/Bindings/Python/*.h", - "include/mlir/Bindings/Python/*.h", -] - -cc_library( - name = "MLIRBindingsPythonHeaders", - includes = [ - "include", - "lib/Bindings/Python", - ], - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), - deps = [ - ":CAPIIRHeaders", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -cc_library( - name = "MLIRBindingsPythonHeadersAndDeps", - includes = [ - "include", - "lib/Bindings/Python", - ], - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), - deps = [ - ":CAPIIR", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -# These flags are needed for pybind11 to work. -PYBIND11_COPTS = [ - "-fexceptions", - "-frtti", -] - -PYBIND11_FEATURES = [ - # Cannot use header_modules (parse_headers feature fails). - "-use_header_modules", -] - -MLIR_PYTHON_BINDINGS_SOURCES = [ - "lib/Bindings/Python/IRAffine.cpp", - "lib/Bindings/Python/IRAttributes.cpp", - "lib/Bindings/Python/IRCore.cpp", - "lib/Bindings/Python/IRInterfaces.cpp", - "lib/Bindings/Python/IRModule.cpp", - "lib/Bindings/Python/IRTypes.cpp", - "lib/Bindings/Python/Pass.cpp", -] - -cc_library( - name = "MLIRBindingsPythonCore", - srcs = MLIR_PYTHON_BINDINGS_SOURCES, - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsync", - ":CAPIDebug", - ":CAPIIR", - ":CAPIInterfaces", - ":MLIRBindingsPythonHeadersAndDeps", - ":Support", - "//llvm:Support", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -cc_library( - name = "MLIRBindingsPythonCoreNoCAPI", - srcs = MLIR_PYTHON_BINDINGS_SOURCES, - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsyncHeaders", - ":CAPIDebugHeaders", - ":CAPIIRHeaders", - ":MLIRBindingsPythonHeaders", - "//llvm:Support", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -# Target that bundles together the CAPI objects needed for -# MLIRBindingsPythonCoreNoCAPI. -cc_library( - name = "MLIRBindingsPythonCAPIObjects", - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsyncObjects", - ":CAPIDebugObjects", - ":CAPIIRObjects", - ":CAPIInterfacesObjects", - ], -) - -# Dynamic library with the MLIR Python extension. -cc_binary( - name = "_mlir.so", - srcs = ["lib/Bindings/Python/MainModule.cpp"], - # These flags are needed for pybind11 to work. - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":MLIRBindingsPythonCore", - ":MLIRBindingsPythonHeadersAndDeps", - ], -) - -cc_binary( - name = "_mlirDialectsLinalg.so", - srcs = ["lib/Bindings/Python/DialectLinalg.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPILinalg", - ":MLIRBindingsPythonHeadersAndDeps", - ], -) - -cc_binary( - name = "_mlirDialectsQuant.so", - srcs = ["lib/Bindings/Python/DialectQuant.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPIQuant", - ":MLIRBindingsPythonHeadersAndDeps", - "@pybind11", - ], -) - -cc_binary( - name = "_mlirDialectsSparseTensor.so", - srcs = ["lib/Bindings/Python/DialectSparseTensor.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPISparseTensor", - ":MLIRBindingsPythonHeadersAndDeps", - "@pybind11", - ], -) - -# Dynamic library with the MLIR Conversions Python extension. -cc_binary( - name = "_mlirExecutionEngine.so", - srcs = ["lib/Bindings/Python/ExecutionEngineModule.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIExecutionEngine", - ":MLIRBindingsPythonHeadersAndDeps", - "@local_config_python//:python_headers", - "@pybind11", - ], -) - -# Dynamic library with the MLIR Linalg dialect+passes Python extension. -cc_binary( - name = "_mlirLinalgPasses.so", - srcs = ["lib/Bindings/Python/LinalgPasses.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPILinalg", - ":MLIRBindingsPythonHeadersAndDeps", - "@local_config_python//:python_headers", - "@pybind11", - ], -) \ No newline at end of file From 370cf184dcf5088a7e2fd65d034479d099f52eab Mon Sep 17 00:00:00 2001 From: Jeremy Kun Date: Fri, 16 Feb 2024 06:34:36 -0800 Subject: [PATCH 4/5] add glob python rules --- .../mlir/python/BUILD.bazel | 140 ++++++++++-------- .../llvm-project-overlay/mlir/tblgen.bzl | 1 + 2 files changed, 79 insertions(+), 62 deletions(-) diff --git a/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel index 71002881dfb5f..220cf6d6a2c8d 100644 --- a/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel @@ -83,87 +83,103 @@ pybind_extension( srcs = ["//mlir:lib/Bindings/Python/RegisterEverything.cpp"], deps = [ "//mlir:CAPIConversion", - "//mlir:CAPITransforms", "//mlir:CAPIRegisterEverything", + "//mlir:CAPITransforms", "//mlir:MLIRBindingsPythonHeadersAndDeps", ], ) -##---------------------------------------------------------------------------## -# Core IR modules. -##---------------------------------------------------------------------------## - -filegroup( - name = "DialectCorePyFiles", - srcs = [ - "mlir/dialects/_ods_common.py", - ], +py_library( + name = "mlir", + srcs = glob(["mlir/*.py"]), ) -filegroup( - name = "ExecutionEnginePyFiles", - srcs = [ - "mlir/execution_engine.py", - ], +py_library( + name = "dialects", + srcs = glob(["mlir/dialects/**/*.py"]), ) -filegroup( - name = "ExecutionEnginePyIFiles", - srcs = [ - "mlir/_mlir_libs/_mlirExecutionEngine.pyi", - ], +py_library( + name = "extras", + srcs = glob(["mlir/extras/**/*.py"]), ) -filegroup( - name = "IRPyFiles", - srcs = [ - "mlir/ir.py", - ], +py_library( + name = "runtime", + srcs = glob(["mlir/runtime/**/*.py"]), ) -filegroup( - name = "ExtrasPyFiles", - srcs = glob([ - "mlir/extras/*.py", - ]), +py_library( + name = "_mlir_libs", + srcs = glob(["mlir/_mlir_libs/**/*.py"]), + data = glob(["mlir/_mlir_libs/**/*.pyi"]), ) -filegroup( - name = "IRPyIFiles", - srcs = [ - "mlir/_mlir_libs/_mlir/__init__.pyi", - "mlir/_mlir_libs/_mlir/ir.pyi", - ], -) - -filegroup( - name = "MlirLibsPyFiles", - srcs = [ - "mlir/_mlir_libs/__init__.py", - ], -) - -filegroup( - name = "PassManagerPyFiles", - srcs = [ - "mlir/passmanager.py", +py_library( + name = "PythonBindings", + data = [ + "mlir/_mlir_libs/_mlir.so", + "mlir/_mlir_libs/_mlirDialectsLinalg.so", + "mlir/_mlir_libs/_mlirDialectsQuant.so", + "mlir/_mlir_libs/_mlirDialectsSparseTensor.so", + "mlir/_mlir_libs/_mlirExecutionEngine.so", + "mlir/_mlir_libs/_mlirLinalgPasses.so", + "mlir/_mlir_libs/_mlirRegisterEverything.so", + # these need to be data because gentbl_filegroup doesn't create a py_library + ":AMDGPUOpsPyGen", + ":AffineOpsPyGen", + ":ArithOpsPyGen", + ":BufferizationEnumPyGen", + ":BufferizationOpsPyGen", + ":BufferizationTransformOpsPyGen", + ":BuiltinOpsPyGen", + ":ComplexOpsPyGen", + ":ControlFlowOpsPyGen", + ":FuncPyGen", + ":GPUOpsPyGen", + ":GPUTransformOpsPyGen", + ":LLVMOpsPyGen", + ":LinalgOpsPyGen", + ":LoopTransformOpsPyGen", + ":MLProgramOpsPyGen", + ":MathOpsPyGen", + ":MemRefOpsPyGen", + ":MemRefTransformOpsPyGen", + ":NVGPUOpsPyGen", + ":NVGPUTransformOpsPyGen", + ":NVVMOpsPyGen", + ":OpenMPOpsPyGen", + ":PDLPyGen", + ":PDLTransformOpsPyGen", + ":PythonTestPyGen", + ":ROCDLOpsPyGen", + ":SCFPyGen", + ":SPIRVOpsPyGen", + ":ShapeOpsPyGen", + ":SparseTensorEnumPyGen", + ":SparseTensorOpsPyGen", + ":SparseTensorTransformOpsPyGen", + ":StructureTransformEnumPyGen", + ":StructuredTransformOpsPyGen", + ":TensorOpsPyGen", + ":TensorTransformOpsPyGen", + ":TosaOpsPyGen", + ":TransformEnumPyGen", + ":TransformOpsPyGen", + ":VectorAttributesPyGen", + ":VectorOpsPyGen", + ":VectorTransformEnumPyGen", + ":VectorTransformOpsPyGen", ], -) - -filegroup( - name = "PassManagerPyIFiles", - srcs = [ - "mlir/_mlir_libs/_mlir/passmanager.pyi", + deps = [ + ":_mlir_libs", + ":dialects", + ":extras", + ":mlir", + ":runtime", ], ) -filegroup( - name = "RuntimePyFiles", - srcs = glob([ - "mlir/runtime/*.py", - ]), -) - ##---------------------------------------------------------------------------## # Affine dialect. ##---------------------------------------------------------------------------## diff --git a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl index 9d26822ac1638..ab77937c344c4 100644 --- a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl +++ b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl @@ -373,6 +373,7 @@ def gentbl_filegroup( ) included_srcs = [f for (opts, f) in tbl_outs if not any([skip_opt in opts for skip_opt in skip_opts])] + print("making filegroup with name, included_srcs: ", name, included_srcs) native.filegroup( name = name, srcs = included_srcs, From 5cb680cd03757b385a76be2a3fd797c1d3b56eb8 Mon Sep 17 00:00:00 2001 From: Jeremy Kun Date: Fri, 16 Feb 2024 06:34:49 -0800 Subject: [PATCH 5/5] print statements to figure out what is going on with registry --- mlir/include/mlir/IR/DialectRegistry.h | 4 ++++ mlir/include/mlir/IR/OpDefinition.h | 2 ++ mlir/include/mlir/IR/StorageUniquerSupport.h | 8 ++++++-- mlir/include/mlir/InitAllDialects.h | 4 ++++ mlir/lib/IR/MLIRContext.cpp | 15 ++++++++++++++- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/mlir/include/mlir/IR/DialectRegistry.h b/mlir/include/mlir/IR/DialectRegistry.h index c13a1a1858eb1..67f4fa27a827f 100644 --- a/mlir/include/mlir/IR/DialectRegistry.h +++ b/mlir/include/mlir/IR/DialectRegistry.h @@ -18,6 +18,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include #include #include @@ -242,6 +243,9 @@ class DialectRegistry { ~Extension() override = default; void apply(MLIRContext *context, DialectsT *...dialects) const final { + for (auto *dialect : {dialects...}) + std::cerr << "Applying extension to dialect: " + << dialect->getNamespace().str() << "\n"; extensionFn(context, dialects...); } ExtensionFnT extensionFn; diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index bd68c27445744..e2ef419fb00ed 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -24,6 +24,7 @@ #include "mlir/IR/Operation.h" #include "llvm/Support/PointerLikeTypeTraits.h" +#include #include #include @@ -1735,6 +1736,7 @@ class Op : public OpState, public Traits... { llvm::report_fatal_error( "Attempting to attach an interface to an unregistered operation " + ConcreteType::getOperationName() + "."); + std::cerr << "attachInterface: " << info->getStringRef().str() << "\n"; (checkInterfaceTarget(), ...); info->attachInterface(); } diff --git a/mlir/include/mlir/IR/StorageUniquerSupport.h b/mlir/include/mlir/IR/StorageUniquerSupport.h index 982d5220ab52c..8b62bf3aa3283 100644 --- a/mlir/include/mlir/IR/StorageUniquerSupport.h +++ b/mlir/include/mlir/IR/StorageUniquerSupport.h @@ -13,6 +13,8 @@ #ifndef MLIR_IR_STORAGEUNIQUERSUPPORT_H #define MLIR_IR_STORAGEUNIQUERSUPPORT_H +#include + #include "mlir/IR/AttrTypeSubElements.h" #include "mlir/IR/DialectRegistry.h" #include "mlir/Support/InterfaceSupport.h" @@ -154,12 +156,14 @@ class StorageUserBase : public BaseT, public Traits... { /// call will abort otherwise. template static void attachInterface(MLIRContext &context) { + std::cerr << "attachInterface\n"; typename ConcreteT::AbstractTy *abstract = ConcreteT::AbstractTy::lookupMutable(TypeID::get(), &context); - if (!abstract) - llvm::report_fatal_error("Registering an interface for an attribute/type " + if (!abstract) { + llvm::report_fatal_error("HERE! Registering an interface for an attribute/type " "that is not itself registered."); + } // Handle the case where the models resolve a promised interface. (dialect_extension_detail::handleAdditionOfUndefinedPromisedInterface( diff --git a/mlir/include/mlir/InitAllDialects.h b/mlir/include/mlir/InitAllDialects.h index 3c145540356bd..10f4ea0c70c60 100644 --- a/mlir/include/mlir/InitAllDialects.h +++ b/mlir/include/mlir/InitAllDialects.h @@ -14,6 +14,8 @@ #ifndef MLIR_INITALLDIALECTS_H_ #define MLIR_INITALLDIALECTS_H_ +#include + #include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h" #include "mlir/Dialect/AMX/AMXDialect.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" @@ -98,6 +100,7 @@ namespace mlir { /// Add all the MLIR dialects to the provided registry. inline void registerAllDialects(DialectRegistry ®istry) { + std::cerr << "Starting to register dialects!\n"; // clang-format off registry.insert + #include "AffineExprDetail.h" #include "AffineMapDetail.h" #include "AttributeDetail.h" @@ -23,6 +24,7 @@ #include "mlir/IR/ExtensibleDialect.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/Location.h" +#include "mlir/IR/MLIRContext.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/OperationSupport.h" #include "mlir/IR/Types.h" @@ -749,6 +751,11 @@ const AbstractAttribute &AbstractAttribute::lookup(TypeID typeID, AbstractAttribute *AbstractAttribute::lookupMutable(TypeID typeID, MLIRContext *context) { auto &impl = context->getImpl(); + llvm::errs() << "REGISTERED Attributes:\n"; + for (auto &attr : impl.registeredAttributes) { + llvm::errs() << attr.second->getDialect().getNamespace() << "." + << attr.second->getName() << "\n"; + } return impl.registeredAttributes.lookup(typeID); } @@ -973,6 +980,12 @@ const AbstractType &AbstractType::lookup(TypeID typeID, MLIRContext *context) { AbstractType *AbstractType::lookupMutable(TypeID typeID, MLIRContext *context) { auto &impl = context->getImpl(); + // Print out all register dialect names + llvm::errs() << "REGISTERED Types:\n"; + for (auto &ty : impl.registeredTypes) { + llvm::errs() << ty.second->getDialect().getNamespace() << "." + << ty.second->getName() << "\n"; + } return impl.registeredTypes.lookup(typeID); }