diff --git a/.bazelrc b/.bazelrc index 2c2270d..b301198 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,4 @@ +common --enable_bzlmod common --action_env=BAZEL_CXXOPTS=-std=c++17 common --cxxopt='-std=c++17' common --deleted_packages=externals diff --git a/.bazelversion b/.bazelversion index 19b860c..56b6be4 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.4.0 +8.3.1 diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 60f482c..abe4bfa 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -19,10 +19,10 @@ jobs: with: path: | ~/.cache/bazel - # add import_llvm.bzl so that a new build occurs after an LLVM commit hash update - key: ${{ runner.os }}-bazel-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE') }} + # add extensions.bzl so that a new build occurs after an LLVM commit hash update + key: ${{ runner.os }}-bazel-${{ hashFiles('extensions.bzl') }}-${{ hashFiles('.bazelversion', '.bazelrc', 'MODULE.bazel') }} restore-keys: | - ${{ runner.os }}-bazel-${{ hashFiles('bazel/import_llvm.bzl') }} + ${{ runner.os }}-bazel-${{ hashFiles('extensions.bzl') }} - name: "Run `bazel build`" run: | diff --git a/.github/workflows/build_and_test_cmake.yml b/.github/workflows/build_and_test_cmake.yml index f224c76..1b9f49c 100644 --- a/.github/workflows/build_and_test_cmake.yml +++ b/.github/workflows/build_and_test_cmake.yml @@ -27,7 +27,7 @@ jobs: with: path: | ./externals/llvm-project - key: ${{ runner.os }}-cmake-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }} + key: ${{ runner.os }}-cmake-${{ hashFiles('extensions.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }} - name: Cache mlir-tutorial build id: cache-mlir-tutorial @@ -35,7 +35,7 @@ jobs: with: path: | ./build - key: ${{ runner.os }}-cmake-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }} + key: ${{ runner.os }}-cmake-${{ hashFiles('extensions.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }} - name: Git config run: | @@ -44,7 +44,7 @@ jobs: - name: Build LLVM if: steps.cache-llvm.outputs.cache-hit != 'true' run: | - LLVM_COMMIT=$(grep LLVM_COMMIT ${GITHUB_WORKSPACE}/bazel/import_llvm.bzl | head -n 1 | cut -d'"' -f 2 ) + LLVM_COMMIT=$(grep 'commit = ' ${GITHUB_WORKSPACE}/extensions.bzl | head -n 1 | cut -d'"' -f 2) git submodule update --init --recursive cd externals/llvm-project git checkout ${LLVM_COMMIT} diff --git a/.gitignore b/.gitignore index 258a6a8..372ca16 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ bazel-bin bazel-mlir-tutorial bazel-out bazel-testlogs +MODULE.bazel.lock # cmake related files # ignore the user specified CMake presets in subproject directories. diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..4c6bca2 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,85 @@ +############################################################################### +# Bazel now uses Bzlmod by default to manage external dependencies. +# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. +# +# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 +############################################################################### + +module( + name = "mlir_tutorial", + version = "1.0.0", + repo_name = "mlir_tutorial", +) + +# Dependencies available in BCR +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_python", version = "1.2.0") +bazel_dep(name = "platforms", version = "0.0.11") +bazel_dep(name = "rules_cc", version = "0.1.1") +bazel_dep(name = "rules_java", version = "8.12.0") +bazel_dep(name = "protobuf", version = "30.1") +bazel_dep(name = "rules_proto", version = "7.1.0") +bazel_dep(name = "rules_pkg", version = "1.1.0") +bazel_dep(name = "re2", version = "2024-07-02.bcr.1") +bazel_dep(name = "abseil-cpp", version = "20250512.1") +bazel_dep(name = "or-tools", version = "9.12") +bazel_dep(name = "eigen", version = "4.0.0-20241125.bcr.2") +bazel_dep(name = "highs", version = "1.11.0") +bazel_dep(name = "pcre2", version = "10.46-DEV") +bazel_dep(name = "glpk", version = "5.0.bcr.4") +bazel_dep(name = "bliss", version = "0.73") +bazel_dep(name = "scip", version = "9.2.0.bcr.3") +bazel_dep(name = "zlib-ng", version = "2.0.7") + +# Hedron's Compile Commands Extractor for Bazel +# https://github.com/hedronvision/bazel-compile-commands-extractor +bazel_dep(name = "hedron_compile_commands", dev_dependency = True) +git_override( + module_name = "hedron_compile_commands", + remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git", + commit = "0e990032f3c5a866e72615cf67e5ce22186dcb97", + # Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main). + # Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README). +) + +# Use module extensions for LLVM and other dependencies that aren't in BCR +mlir_tutorial_deps = use_extension("//:extensions.bzl", "mlir_tutorial_deps") +use_repo(mlir_tutorial_deps, + "llvm-raw", + "llvm_zstd", + "llvm_zlib" +) + +# The subset of LLVM backend targets that should be compiled +_LLVM_TARGETS = [ + "X86", + # The bazel dependency graph for mlir-opt fails to load (at the analysis + # step) without the NVPTX target in this list, because mlir/test:TestGPU + # depends on the //llvm:NVPTXCodeGen target, which is not defined unless this + # is included. @j2kun asked the LLVM maintiners for tips on how to fix this, + # see https://github.com/llvm/llvm-project/issues/63135 + "NVPTX", + # Needed for Apple M1 targets, see + # https://github.com/j2kun/mlir-tutorial/issues/11 + "AArch64", +] + +# Configure LLVM project using use_repo_rule +llvm_configure = use_repo_rule("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") +llvm_configure( + name = "llvm-project", + targets = _LLVM_TARGETS, +) + +# Configure Python dependencies +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain(python_version = "3.13") +use_repo(python, "python_3_13") + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") +pip.parse( + hub_name = "mlir_tutorial_pip_deps", + python_version = "3.13", + requirements_lock = "//:requirements.txt", +) +use_repo(pip, "mlir_tutorial_pip_deps") \ No newline at end of file diff --git a/README.md b/README.md index 5e5452d..2ac2f23 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,11 @@ the tutorial series and explained in the first article, The CMake build is maintained, but was added at article 10 (Dialect Conversion) and will not be explained in the articles. +**Note**: This project has been upgraded to Bazel 8.3.1 and migrated to use +Bzlmod for dependency management, replacing the traditional WORKSPACE file +approach. Dependencies are now managed through `MODULE.bazel` using the +Bazel Central Registry (BCR) where possible. + ### Prerequisites Install Bazelisk via instructions at @@ -39,6 +44,9 @@ This should create the `bazel` command on your system. You should also have a modern C++ compiler on your system, either `gcc` or `clang`, which Bazel will detect. +**Bazel Version**: This project requires Bazel 8.3.1 or newer. The specific +version is pinned in `.bazelversion`. + ### Build and test Run @@ -48,6 +56,19 @@ bazel build ...:all bazel test ...:all ``` +### Dependency Management + +The project uses Bzlmod (MODULE.bazel) for dependency management: + +- **Core dependencies**: Managed through Bazel Central Registry (BCR) + - rules_python, rules_java, protobuf, abseil-cpp, or-tools, etc. +- **LLVM dependencies**: Managed through custom module extension + - LLVM/MLIR source code via git repository +- **Development tools**: hedron_compile_commands via git_override + +This approach provides better dependency resolution, versioning, and +compatibility compared to the legacy WORKSPACE approach. + ## CMake build CMake is one of two supported build systems for this tutorial. The other is diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index ed24794..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,231 +0,0 @@ -workspace(name = "mlir_tutorial") - -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") - -# Bazel skylib is a collection of bazel tools that are a required dependency of -# the LLVM/MLIR bazel build overlay. -http_archive( - name = "bazel_skylib", - sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", - ], -) - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -load("@bazel_skylib//lib:versions.bzl", "versions") - -versions.check(minimum_bazel_version = "6.3.2") - -# A two-step process for buliding LLVM/MLIR with bazel. First the raw source -# code is downloaded and imported into this workspace as a git repository, -# called `llvm-raw`. Then the build files defined in the LLVM monorepo are -# overlaid using llvm_configure in the setup script below. This defines the -# @llvm-project bazel project which is can be built and depended on. -load("//bazel:import_llvm.bzl", "import_llvm") - -import_llvm("llvm-raw") - -load("//bazel:setup_llvm.bzl", "setup_llvm") - -setup_llvm("llvm-project") - -# LLVM doesn't have proper support for excluding the optional llvm_zstd and -# llvm_zlib dependencies but it is supposed to make LLVM faster, so why not -# include it. See https://reviews.llvm.org/D143344#4232172 -maybe( - http_archive, - name = "llvm_zstd", - build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD", - sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0", - strip_prefix = "zstd-1.5.2", - urls = [ - "https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz", - ], -) - -maybe( - http_archive, - name = "llvm_zlib", - build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD", - sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731", - strip_prefix = "zlib-ng-2.0.7", - urls = [ - "https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip", - ], -) - -# compile_commands extracts the relevant compile data from bazel into -# `compile_commands.json` so that clangd, clang-tidy, etc., can use it. -# Whenever a build file changes, you must re-run -# -# bazel run @hedron_compile_commands//:refresh_all -# -# to ingest new data into these tools. -# -# See the project repo for more details and configuration options -# https://github.com/hedronvision/bazel-compile-commands-extractor -http_archive( - name = "hedron_compile_commands", - sha256 = "3cd0e49f0f4a6d406c1d74b53b7616f5e24f5fd319eafc1bf8eee6e14124d115", - strip_prefix = "bazel-compile-commands-extractor-3dddf205a1f5cde20faf2444c1757abe0564ff4c", - url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/3dddf205a1f5cde20faf2444c1757abe0564ff4c.tar.gz", -) - -load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup") - -hedron_compile_commands_setup() - -# Depend on a hermetic python version -new_git_repository( - name = "rules_python", - commit = "9ffb1ecd9b4e46d2a0bca838ac80d7128a352f9f", # v0.23.1 - remote = "https://github.com/bazelbuild/rules_python.git", -) - -load("@rules_python//python:repositories.bzl", "python_register_toolchains") - -python_register_toolchains( - name = "python3_10", - # Available versions are listed at - # https://github.com/bazelbuild/rules_python/blob/main/python/versions.bzl - python_version = "3.10", -) - -load("@python3_10//:defs.bzl", "interpreter") -load("@rules_python//python:pip.bzl", "pip_parse") - -pip_parse( - name = "mlir_tutorial_pip_deps", - python_interpreter_target = interpreter, - requirements_lock = "//:requirements.txt", -) - -load("@mlir_tutorial_pip_deps//:requirements.bzl", "install_deps") - -install_deps() - -##### Deps for or-tools ##### - -## Bazel rules. -git_repository( - name = "platforms", - commit = "380c85cc2c7b126c6e354f517dc16d89fe760c9f", - remote = "https://github.com/bazelbuild/platforms.git", -) - -git_repository( - name = "rules_proto", - commit = "3f1ab99b718e3e7dd86ebdc49c580aa6a126b1cd", - remote = "https://github.com/bazelbuild/rules_proto.git", -) - -## ZLIB -new_git_repository( - name = "zlib", - build_file = "@com_google_protobuf//:third_party/zlib.BUILD", - commit = "04f42ceca40f73e2978b50e93806c2a18c1281fc", - remote = "https://github.com/madler/zlib.git", -) - -## Re2 -git_repository( - name = "com_google_re2", - remote = "https://github.com/google/re2.git", - tag = "2023-07-01", -) - -## Abseil-cpp -git_repository( - name = "com_google_absl", - commit = "c2435f8342c2d0ed8101cb43adfd605fdc52dca2", - patch_args = ["-p1"], - patches = ["@com_google_ortools//patches:abseil-cpp-20230125.3.patch"], - remote = "https://github.com/abseil/abseil-cpp.git", -) - -## Protobuf -git_repository( - name = "com_google_protobuf", - # there's a patch for the CMake build in protobuf, ignoring - # patches = ["@com_google_ortools//patches:protobuf-v23.3.patch"], - commit = "4dd15db6eb3955745f379d28fb4a2fcfb6753de3", - patch_args = ["-p1"], - remote = "https://github.com/protocolbuffers/protobuf.git", -) - -# Load common dependencies. -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - -## Solvers -http_archive( - name = "glpk", - build_file = "@com_google_ortools//bazel:glpk.BUILD", - sha256 = "4a1013eebb50f728fc601bdd833b0b2870333c3b3e5a816eeba921d95bec6f15", - url = "http://ftp.gnu.org/gnu/glpk/glpk-5.0.tar.gz", -) - -http_archive( - name = "bliss", - build_file = "@com_google_ortools//bazel:bliss.BUILD", - patches = ["@com_google_ortools//bazel:bliss-0.73.patch"], - sha256 = "f57bf32804140cad58b1240b804e0dbd68f7e6bf67eba8e0c0fa3a62fd7f0f84", - url = "https://github.com/google/or-tools/releases/download/v9.0/bliss-0.73.zip", - #url = "http://www.tcs.hut.fi/Software/bliss/bliss-0.73.zip", -) - -new_git_repository( - name = "scip", - build_file = "@com_google_ortools//bazel:scip.BUILD", - commit = "62fab8a2e3708f3452fad473a6f48715c367316b", - patch_args = ["-p1"], - patches = ["@com_google_ortools//bazel:scip.patch"], - remote = "https://github.com/scipopt/scip.git", -) - -# Eigen has no Bazel build. -new_git_repository( - name = "eigen", - build_file_content = - """ -cc_library( - name = 'eigen3', - srcs = [], - includes = ['.'], - hdrs = glob(['Eigen/**']), - visibility = ['//visibility:public'], -) -""", - commit = "3147391d946bb4b6c68edd901f2add6ac1f31f8c", - remote = "https://gitlab.com/libeigen/eigen.git", -) - -git_repository( - name = "highs", - branch = "bazel", - remote = "https://github.com/ERGO-Code/HiGHS.git", -) - -## Swig support -# pcre source code repository -new_git_repository( - name = "pcre2", - build_file = "@com_google_ortools//bazel:pcre2.BUILD", - remote = "https://github.com/PCRE2Project/pcre2.git", - tag = "pcre2-10.42", -) - -git_repository( - name = "com_google_ortools", - commit = "1d696f9108a0ebfd99feb73b9211e2f5a6b0812b", - remote = "https://github.com/google/or-tools.git", - shallow_since = "1647023481 +0100", -) diff --git a/bazel/import_llvm.bzl b/bazel/import_llvm.bzl deleted file mode 100644 index df11299..0000000 --- a/bazel/import_llvm.bzl +++ /dev/null @@ -1,22 +0,0 @@ -"""Provides the repository macro to import LLVM.""" - -load( - "@bazel_tools//tools/build_defs/repo:git.bzl", - "new_git_repository", -) - -def import_llvm(name): - """Imports LLVM.""" - - # 2025-02-01 - LLVM_COMMIT = "16d4453f2f5d9554ce39507fda0f33ce9066007b" - - new_git_repository( - name = name, - # this BUILD file is intentionally empty, because the LLVM project - # internally contains a set of bazel BUILD files overlaying the project. - build_file_content = "# empty", - commit = LLVM_COMMIT, - init_submodules = False, - remote = "https://github.com/llvm/llvm-project.git", - ) diff --git a/bazel/lit.bzl b/bazel/lit.bzl index 8adb209..b5fe9c3 100644 --- a/bazel/lit.bzl +++ b/bazel/lit.bzl @@ -51,8 +51,10 @@ def lit_test(name = None, src = None, size = "small", tags = None): # -v ensures lit outputs useful info during test failures args = ["-v", paths.join(native.package_name(), src)], data = ["@mlir_tutorial//tests:test_utilities", filegroup_name], + deps = ["@mlir_tutorial_pip_deps//lit"], srcs = ["@llvm-project//llvm:lit"], main = "lit.py", + python_version = "PY3", tags = tags, ) diff --git a/bazel/setup_llvm.bzl b/bazel/setup_llvm.bzl deleted file mode 100644 index c833fc4..0000000 --- a/bazel/setup_llvm.bzl +++ /dev/null @@ -1,24 +0,0 @@ -"""Configure LLVM Bazel overlays from a 'raw' imported llvm repository""" - -load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") - -# The subset of LLVM backend targets that should be compiled -_LLVM_TARGETS = [ - "X86", - # The bazel dependency graph for mlir-opt fails to load (at the analysis - # step) without the NVPTX target in this list, because mlir/test:TestGPU - # depends on the //llvm:NVPTXCodeGen target, which is not defined unless this - # is included. @j2kun asked the LLVM maintiners for tips on how to fix this, - # see https://github.com/llvm/llvm-project/issues/63135 - "NVPTX", - # Needed for Apple M1 targets, see - # https://github.com/j2kun/mlir-tutorial/issues/11 - "AArch64", -] - -def setup_llvm(name): - """Build @llvm-project from @llvm-raw using the upstream bazel overlays.""" - llvm_configure( - name = name, - targets = _LLVM_TARGETS, - ) diff --git a/extensions.bzl b/extensions.bzl new file mode 100644 index 0000000..445b7b7 --- /dev/null +++ b/extensions.bzl @@ -0,0 +1,44 @@ +"""Module extensions for MLIR Tutorial dependencies.""" + +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +def _mlir_tutorial_deps_impl(module_ctx): + """Implementation of the mlir_tutorial_deps module extension.""" + + # Download LLVM/MLIR using a git repository + new_git_repository( + name = "llvm-raw", + build_file_content = "# empty", + commit = "d9190f8141661bd6120dea61d28ae8940fd775d0", + init_submodules = False, + remote = "https://github.com/llvm/llvm-project.git", + ) + + # Optional LLVM dependencies for performance + maybe( + http_archive, + name = "llvm_zstd", + build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD", + sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0", + strip_prefix = "zstd-1.5.2", + urls = [ + "https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz", + ], + ) + + maybe( + http_archive, + name = "llvm_zlib", + build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD", + sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731", + strip_prefix = "zlib-ng-2.0.7", + urls = [ + "https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip", + ], + ) + +mlir_tutorial_deps = module_extension( + implementation = _mlir_tutorial_deps_impl, +) diff --git a/externals/llvm-project b/externals/llvm-project index 16d4453..d9190f8 160000 --- a/externals/llvm-project +++ b/externals/llvm-project @@ -1 +1 @@ -Subproject commit 16d4453f2f5d9554ce39507fda0f33ce9066007b +Subproject commit d9190f8141661bd6120dea61d28ae8940fd775d0 diff --git a/lib/Analysis/ReduceNoiseAnalysis/BUILD b/lib/Analysis/ReduceNoiseAnalysis/BUILD index 90981d0..6df5387 100644 --- a/lib/Analysis/ReduceNoiseAnalysis/BUILD +++ b/lib/Analysis/ReduceNoiseAnalysis/BUILD @@ -8,8 +8,8 @@ cc_library( hdrs = ["ReduceNoiseAnalysis.h"], deps = [ "//lib/Dialect/Noisy", - "@com_google_ortools//ortools/base", - "@com_google_ortools//ortools/linear_solver", + "@or-tools//ortools/base", + "@or-tools//ortools/linear_solver", "@llvm-project//llvm:Support", "@llvm-project//mlir:IR", ], diff --git a/lib/Dialect/Poly/PolyOps.td b/lib/Dialect/Poly/PolyOps.td index 76cb2f9..230b2f4 100644 --- a/lib/Dialect/Poly/PolyOps.td +++ b/lib/Dialect/Poly/PolyOps.td @@ -10,7 +10,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td" // Type constraint for poly binop arguments: polys, vectors of polys, or // tensors of polys. -def PolyOrContainer : TypeOrContainer; +def PolyOrContainer : TypeOrValueSemanticsContainer; // Inject verification that all integer-like arguments are 32-bits def Has32BitArguments : NativeOpTrait<"Has32BitArguments"> { diff --git a/requirements.txt b/requirements.txt index ea9fd76..b382aeb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -lit==16.0.6 +lit==18.1.8 diff --git a/tests/BUILD b/tests/BUILD index b7dfc45..2df8ffd 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -16,7 +16,7 @@ filegroup( "@llvm-project//mlir:mlir-runner", "@llvm-project//mlir:mlir-opt", "@llvm-project//mlir:mlir-translate", - "@mlir_tutorial_pip_deps_lit//:pkg", + "@mlir_tutorial_pip_deps//lit", ], ) diff --git a/tests/lit.cfg.py b/tests/lit.cfg.py index 15ca568..b2897be 100644 --- a/tests/lit.cfg.py +++ b/tests/lit.cfg.py @@ -12,7 +12,7 @@ # lit executes relative to the directory # -# bazel-bin/tests/.runfiles/mlir_tutorial/ +# bazel-bin/tests/.runfiles/_main/ # # which contains all the binary targets included in via the `data` attribute in # the lit.bzl macro, which in turn gets them from the filegroup //tests:test_utilities. @@ -25,14 +25,16 @@ # print(subprocess.run(["ls", "-l", os.environ["RUNFILES_DIR"]]).stdout) # print(subprocess.run([ "env", ]).stdout) # -# Bazel defines RUNFILES_DIR which includes mlir_tutorial/ and third party +# Bazel defines RUNFILES_DIR which includes _main/ and third party # dependencies as their own directory. Generally, it seems that $PWD == -# $RUNFILES_DIR/mlir_tutorial/ +# $RUNFILES_DIR/_main/ runfiles_dir = Path(os.environ["RUNFILES_DIR"]) + +# Fix tool paths to use _main instead of mlir_tutorial tool_relpaths = [ - "llvm-project/mlir", - "llvm-project/llvm", - "mlir_tutorial/tools", + "+_repo_rules+llvm-project/mlir", + "+_repo_rules+llvm-project/llvm", + "_main/tools", ] config.environment["PATH"] = ( @@ -42,6 +44,6 @@ ) substitutions = { - "%project_source_dir": str(runfiles_dir.joinpath(Path('mlir_tutorial'))), + "%project_source_dir": str(runfiles_dir.joinpath(Path('_main'))), } config.substitutions.extend(substitutions.items()) diff --git a/tools/tutorial-opt.cpp b/tools/tutorial-opt.cpp index 87f213d..e1f2de8 100644 --- a/tools/tutorial-opt.cpp +++ b/tools/tutorial-opt.cpp @@ -29,7 +29,7 @@ void polyToLLVMPipelineBuilder(mlir::OpPassManager &manager) { // One-shot bufferize, from // https://mlir.llvm.org/docs/Bufferization/#ownership-based-buffer-deallocation - mlir::bufferization::OneShotBufferizationOptions bufferizationOptions; + mlir::bufferization::OneShotBufferizePassOptions bufferizationOptions; bufferizationOptions.bufferizeFunctionBoundaries = true; manager.addPass( mlir::bufferization::createOneShotBufferizePass(bufferizationOptions)); @@ -42,7 +42,7 @@ void polyToLLVMPipelineBuilder(mlir::OpPassManager &manager) { // Needed to lower memref.subview manager.addPass(mlir::memref::createExpandStridedMetadataPass()); - manager.addPass(mlir::createConvertSCFToCFPass()); + manager.addPass(mlir::createSCFToControlFlowPass()); manager.addPass(mlir::createConvertControlFlowToLLVMPass()); manager.addPass(mlir::createArithToLLVMConversionPass()); manager.addPass(mlir::createConvertFuncToLLVMPass());