diff --git a/utils/bazel/.bazelignore b/utils/bazel/.bazelignore new file mode 100644 --- /dev/null +++ b/utils/bazel/.bazelignore @@ -0,0 +1 @@ +llvm-project-overlay diff --git a/utils/bazel/.bazelrc b/utils/bazel/.bazelrc new file mode 100644 --- /dev/null +++ b/utils/bazel/.bazelrc @@ -0,0 +1,149 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +############################################################################### +# Common flags that apply to all configurations. +# Use sparingly for things common to all compilers and platforms. +############################################################################### +# Prevent invalid caching if input files are modified during a build. +build --experimental_guard_against_concurrent_changes + +############################################################################### +# Options to select different strategies for linking potential dependent +# libraries. The default leaves it disabled. +############################################################################### + +build:zlib_external --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=external +build:zlib_system --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=system + +build:terminfo_external --repo_env=BAZEL_LLVM_TERMINFO_STRATEGY=external +build:terminfo_system --repo_env=BAZEL_LLVM_TERMINFO_STRATEGY=system + +############################################################################### +# Options for "generic_clang" builds: these options should generally apply to +# builds using a Clang-based compiler, and default to the `clang` executable on +# the `PATH`. While these are provided for convenience and may serve as a +# reference, it would be preferable for users to configure an explicit C++ +# toolchain instead of relying on `.bazelrc` files. +############################################################################### + +# Set the default compiler to the `clang` binary on the `PATH`. +build:generic_clang --repo_env=CC=clang + +# C++14 standard version is required. +build:generic_clang --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 + +# The Clang available on MacOS has a warning that isn't clean on MLIR code. The +# warning doesn't show up with more recent Clangs, so just disable for now. +build:generic_clang --cxxopt=-Wno-range-loop-analysis --host_cxxopt=-Wno-range-loop-analysis + +# Use `-Wall` and `-Werror` for Clang. +build:generic_clang --copt=-Wall --copt=-Werror --host_copt=-Wall --host_copt=-Werror + +############################################################################### +# Options for "generic_gcc" builds: these options should generally apply to +# builds using a GCC-based compiler, and default to the `gcc` executable on +# the `PATH`. While these are provided for convenience and may serve as a +# reference, it would be preferable for users to configure an explicit C++ +# toolchain instead of relying on `.bazelrc` files. +############################################################################### + +# Set the default compiler to the `gcc` binary on the `PATH`. +build:generic_gcc --repo_env=CC=gcc + +# C++14 standard version is required. +build:generic_gcc --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 + +# Disable GCC warnings that are noisy and/or false positives on LLVM code. +# These need to be global as some code triggering these is in header files. +build:generic_gcc --copt=-Wno-unused-parameter --host_copt=-Wno-unused-parameter +build:generic_gcc --copt=-Wno-comment --host_copt=-Wno-comment +build:generic_gcc --cxxopt=-Wno-class-memaccess --host_cxxopt=-Wno-class-memaccess +build:generic_gcc --copt=-Wno-maybe-uninitialized --host_copt=-Wno-maybe-uninitialized +build:generic_gcc --copt=-Wno-misleading-indentation --host_copt=-Wno-misleading-indentation + +# Use `-Werror` for GCC to make sure warnings don't slip past. +build:generic_gcc --copt=-Werror --host_copt=-Werror + +############################################################################### +# Windows specific flags for building with VC. +############################################################################### + +build:msvc --copt=/WX --host_copt=/WX # Treat warnings as errors... +# ...but disable the ones that are violated +build:msvc --copt=/wd4141 --host_copt=/wd4141 # inline used more than once +build:msvc --copt=/wd4244 --host_copt=/wd4244 # conversion type -> type +build:msvc --copt=/wd4267 --host_copt=/wd4267 # conversion size_t -> type +build:msvc --copt=/wd4273 --host_copt=/wd4273 # multiple definitions with different dllimport +build:msvc --copt=/wd4319 --host_copt=/wd4319 # zero-extending after complement +build:msvc --copt=/wd4624 --host_copt=/wd4624 # destructor was implicitly defined as deleted +build:msvc --copt=/wd4804 --host_copt=/wd4804 # comparisons between bool and int +build:msvc --copt=/wd4805 --host_copt=/wd4805 # comparisons between bool and int + +build:msvc --linkopt=/WX --host_linkopt=/WX # Treat warnings as errors... +# ...but disable the ones that are violated. +build:msvc --linkopt=/IGNORE:4001 --host_linkopt=/IGNORE:4001 # no object files + +# Yay for security warnings. Boo for non-standard. +build:msvc --copt=/D_CRT_SECURE_NO_WARNINGS --host_copt=/D_CRT_SECURE_NO_WARNINGS + +############################################################################### + +############################################################################### +# Configuration for building remotely using Remote Build Execution (RBE) +# Based on +# https://github.com/bazelbuild/bazel-toolchains/blob/master/bazelrc/bazel-1.0.0.bazelrc +############################################################################### + +build:rbe --remote_instance_name=projects/llvm-bazel/instances/default_instance + +# Depending on how many machines are in the remote execution instance, setting +# this higher can make builds faster by allowing more jobs to run in parallel. +# Setting it too high can result in jobs that timeout, however, while waiting +# for a remote machine to execute them. +build:rbe --jobs=150 + +# Set several flags related to specifying the platform, toolchain and java +# properties. +# These flags should only be used as is for the rbe-ubuntu16-04 container +# and need to be adapted to work with other toolchain containers. +build:rbe --host_javabase=@rbe_default//java:jdk +build:rbe --javabase=@rbe_default//java:jdk +build:rbe --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 +build:rbe --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 +build:rbe --crosstool_top=@rbe_default//cc:toolchain +build:rbe --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 +# Platform flags: +# The toolchain container used for execution is defined in the target indicated +# by "extra_execution_platforms", "host_platform" and "platforms". +# More about platforms: https://docs.bazel.build/versions/master/platforms.html +build:rbe --extra_toolchains=@rbe_default//config:cc-toolchain +build:rbe --extra_execution_platforms=@rbe_default//config:platform +build:rbe --host_platform=@rbe_default//config:platform +build:rbe --platforms=@rbe_default//config:platform + +build:rbe --define=EXECUTOR=remote + +# Enable remote execution so actions are performed on the remote systems. +build:rbe --remote_executor=grpcs://remotebuildexecution.googleapis.com + +# Enforce stricter environment rules, which eliminates some non-hermetic +# behavior and therefore improves both the remote cache hit rate and the +# correctness and repeatability of the build. +build:rbe --incompatible_strict_action_env=true + +# Set a higher timeout value, just in case. +build:rbe --remote_timeout=3600 + +# Local disk cache is incompatible with remote execution. +build:rbe --disk_cache="" + +# Enable authentication. This will pick up application default credentials by +# default. You can use --google_credentials=some_file.json to use a service +# account credential instead. +build:rbe --google_default_credentials=true + +# The user.bazelrc file is not checked in but available for local mods. +# Always keep this at the end of the file so that user flags override. +try-import %workspace%/user.bazelrc diff --git a/utils/bazel/.bazelversion b/utils/bazel/.bazelversion new file mode 100644 --- /dev/null +++ b/utils/bazel/.bazelversion @@ -0,0 +1 @@ +3.3.1 diff --git a/utils/bazel/.gitignore b/utils/bazel/.gitignore new file mode 100644 --- /dev/null +++ b/utils/bazel/.gitignore @@ -0,0 +1,5 @@ +# Bazel artifacts +/bazel-* + +# Per-user bazelrc files +user.bazelrc diff --git a/utils/bazel/BUILD b/utils/bazel/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/BUILD @@ -0,0 +1,5 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Required to reference .bzl files in this package diff --git a/utils/bazel/README.md b/utils/bazel/README.md new file mode 100644 --- /dev/null +++ b/utils/bazel/README.md @@ -0,0 +1,128 @@ +# Introduction + +*Warning* The Bazel build is experimental and best-effort, supported in line +with the policy for +[LLVM's peripheral support tier](https://llvm.org/docs/SupportPolicy.html). +LLVM's official build system is CMake, if in doubt use that. If you add files, +you're expected to update the CMake build but you don't need to update Bazel +build files. Reviewers should not ask authors to update Bazel build files unless +the author has opted in to support Bazel. Keeping the Bazel build files +up-to-date is on the people who use the Bazel build. + +[Bazel](https://bazel.build/) is a multi-language build system focused on +reproducible builds to enable dependency analysis and caching for fast +incremental builds. + +The main motivation behind the existence of an LLVM Bazel build is that a number +of projects that depend on LLVM use Bazel, and Bazel works best when it knows +about the whole source tree (as opposed to installing artifacts coming from +another build system). Community members are also welcome to use Bazel for their +own development as long as they continue to maintain the official CMake build +system. + +# Quick Start + +1. `git clone https://github.com/llvm/llvm-project.git; cd llvm-project` if + you don't have a checkout yet. +2. Install Bazel at the version indicated by [.bazelversion](./bazelversion), + following the official instructions, if you don't have it installed yet: + https://docs.bazel.build/versions/master/install.html. +3. `cd utils/bazel` +4. `bazel build --config=generic_clang @llvm-project//...` (if building on Unix + with Clang). `--config=generic_gcc` and `--config=msvc` are also available. + + +# Configuration + +The repository `.bazelrc` will import user-specific settings from a +`user.bazelrc` file (in addition to the standard locations). Adding your typical +config setting is recommended. + +```.bazelrc +build --config=generic_clang +``` + +You can enable +[disk caching](https://docs.bazel.build/versions/master/remote-caching.html#disk-cache), +which will cache build results + +```.bazelrc +build --disk_cache=~/.cache/bazel-disk-cache +``` + +You can instruct Bazel to use a ramdisk for its sandboxing operations via +[--sandbox_base](https://docs.bazel.build/versions/master/command-line-reference.html#flag--sandbox_base), +which can help avoid IO bottlenecks for the symlink stragegy used for +sandboxing. This is especially important with many inputs and many cores (see +https://github.com/bazelbuild/bazel/issues/11868): + +```.bazelrc +build --sandbox_base=/dev/shm +``` + +Bear in mind that this requires that your ramdisk is of sufficient size to hold +any temporary files. Anecdotally, 1GB should be sufficient. + +# Coverage + +The LLVM, MLIR, and Clang subprojects have configurations for Linux (Clang and +GCC), Mac (Clang and GCC), and Windows (MSVC). Configuration options that are +platform-specific are selected for in defines. Many are also hardcoded to the +values currently used by all supported configurations. If there is a +configuration you'd like to use that isn't supported, please send a patch. + +# Usage + +To use in dependent projects using Bazel, you can import LLVM (e.g. as a +submodule or using `http_archive`) and then use the provided configuration rule. + +FIXME: This needs to be updated to a commit that exists once such a commit +exists. +FIXME: It shouldn't be necessary to configure `http_archive` twice for the same +archive (though caching means this isn't too expensive). + +```starlark +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +LLVM_COMMIT = "0a1f0ee78122fc0642e8a1a18e1b2bc89c813387" + +LLVM_SHA256 = "4f59737ccfdad2cfb4587d796ce97c1eb5433de7ea0f57f248554b83e92d81d2" + +http_archive( + name = "llvm-project-raw", + build_file_content = "#empty", + sha256 = LLVM_SHA256, + strip_prefix = "llvm-project-" + LLVM_COMMIT, + urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)], +) + +http_archive( + name = "llvm-bazel", + sha256 = LLVM_SHA256, + strip_prefix = "llvm-project-{}/utils/bazel".format(LLVM_COMMIT), + urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)], +) + +load("@llvm-bazel//:configure.bzl", "llvm_configure") + +llvm_configure( + name = "llvm-project", + src_path = ".", + src_workspace = "@llvm-project-raw//:WORKSPACE", +) + +load("@llvm-bazel//:terminfo.bzl", "llvm_terminfo_system") + +maybe( + llvm_terminfo_system, + name = "llvm_terminfo", +) + +load("@llvm-bazel//:zlib.bzl", "llvm_zlib_system") + +maybe( + llvm_zlib_system, + name = "llvm_zlib", +) +``` diff --git a/utils/bazel/WORKSPACE b/utils/bazel/WORKSPACE new file mode 100644 --- /dev/null +++ b/utils/bazel/WORKSPACE @@ -0,0 +1,84 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +load(":configure.bzl", "llvm_configure") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +llvm_configure( + name = "llvm-project", + overlay_path = "llvm-project-overlay", + src_path = "../third_party/llvm-project", +) + +load(":terminfo.bzl", "llvm_terminfo_from_env") + +maybe( + llvm_terminfo_from_env, + name = "llvm_terminfo", +) + +maybe( + http_archive, + name = "zlib", + build_file = "//third_party_build:zlib.BUILD", + sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", + strip_prefix = "zlib-1.2.11", + urls = [ + "https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.11.tar.gz", + "https://zlib.net/zlib-1.2.11.tar.gz", + ], +) + +load(":zlib.bzl", "llvm_zlib_from_env") + +maybe( + llvm_zlib_from_env, + name = "llvm_zlib", + external_zlib = "@zlib", +) + +maybe( + http_archive, + name = "vulkan_headers", + build_file = "//third_party_build:vulkan_headers.BUILD", + sha256 = "19f491784ef0bc73caff877d11c96a48b946b5a1c805079d9006e3fbaa5c1895", + strip_prefix = "Vulkan-Headers-9bd3f561bcee3f01d22912de10bb07ce4e23d378", + urls = [ + "https://github.com/KhronosGroup/Vulkan-Headers/archive/9bd3f561bcee3f01d22912de10bb07ce4e23d378.tar.gz", + ], +) + +load(":vulkan_sdk.bzl", "vulkan_sdk_setup") + +maybe( + vulkan_sdk_setup, + name = "vulkan_sdk", +) + +http_archive( + name = "bazel_skylib", + sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + ], +) + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +http_archive( + name = "bazel_toolchains", + sha256 = "2431088b38fd8e2878db17e3c5babb431de9e5c52b6d8b509d3070fa279a5be2", + strip_prefix = "bazel-toolchains-3.3.1", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/releases/download/3.3.1/bazel-toolchains-3.3.1.tar.gz", + "https://github.com/bazelbuild/bazel-toolchains/releases/download/3.3.1/bazel-toolchains-3.3.1.tar.gz", + ], +) + +load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig") +rbe_autoconfig(name = "rbe_default") diff --git a/utils/bazel/configure.bzl b/utils/bazel/configure.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/configure.bzl @@ -0,0 +1,13 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Configures an LLVM overlay project.""" + +load(":overlay_directories.bzl", "overlay_directories") + +# Directory of overlay files relative to WORKSPACE +OVERLAY_DIR = "llvm-project-overlay" + +def llvm_configure(name, overlay_path = OVERLAY_DIR, **kwargs): + overlay_directories(name = name, overlay_path = overlay_path, **kwargs) diff --git a/utils/bazel/deps_impl/BUILD b/utils/bazel/deps_impl/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/deps_impl/BUILD @@ -0,0 +1,5 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Required to reference files in this package diff --git a/utils/bazel/deps_impl/terminfo_disable.BUILD b/utils/bazel/deps_impl/terminfo_disable.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/deps_impl/terminfo_disable.BUILD @@ -0,0 +1,10 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Empty stub library. This doesn't include any terminfo library and doesn't set +# the LLVM `#define`s to enable usage of terminfo. +cc_library( + name = "terminfo", + visibility = ["//visibility:public"], +) diff --git a/utils/bazel/deps_impl/terminfo_system.BUILD b/utils/bazel/deps_impl/terminfo_system.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/deps_impl/terminfo_system.BUILD @@ -0,0 +1,15 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Wrapper library for some system terminfo. Using this only works if the +# toolchain already has the relevant library search paths configured. It also +# sets the relevant LLVM `#define`s to enoble using terminfo. +cc_library( + name = "terminfo", + defines = ["LLVM_ENABLE_TERMINFO=1"], + # Note that we will replace these link options with ones needed to + # effectively link against a terminfo providing library on the system. + linkopts = {TERMINFO_LINKOPTS}, + visibility = ["//visibility:public"], +) diff --git a/utils/bazel/deps_impl/terminfo_test.c b/utils/bazel/deps_impl/terminfo_test.c new file mode 100644 --- /dev/null +++ b/utils/bazel/deps_impl/terminfo_test.c @@ -0,0 +1,17 @@ +/* +This file is licensed under the Apache License v2.0 with LLVM Exceptions. +See https://llvm.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ + +extern int setupterm(char *term, int filedes, int *errret); +extern struct term *set_curterm(struct term *termp); +extern int del_curterm(struct term *termp); +extern int tigetnum(char *capname); + +int main() { + setupterm(0, 0, 0); + set_curterm(0); + del_curterm(0); + tigetnum(0); +} diff --git a/utils/bazel/deps_impl/zlib_disable.BUILD b/utils/bazel/deps_impl/zlib_disable.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/deps_impl/zlib_disable.BUILD @@ -0,0 +1,10 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Empty stub library. This doesn't include zlib and doesn't set the LLVM +# `#define`s to enable it. +cc_library( + name = "zlib", + visibility = ["//visibility:public"], +) diff --git a/utils/bazel/deps_impl/zlib_external.BUILD b/utils/bazel/deps_impl/zlib_external.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/deps_impl/zlib_external.BUILD @@ -0,0 +1,11 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Wrapper around an external zlib library to add the relevant LLVM `#define`s. +cc_library( + name = "zlib", + defines = ["LLVM_ENABLE_ZLIB=1"], + visibility = ["//visibility:public"], + deps = ["@external_zlib_repo//:zlib_rule"], +) diff --git a/utils/bazel/deps_impl/zlib_system.BUILD b/utils/bazel/deps_impl/zlib_system.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/deps_impl/zlib_system.BUILD @@ -0,0 +1,13 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Wrapper library for the system's zlib. Using this only works if the toolchain +# already has the relevant header search and library search paths configured. +# It also sets the relevant LLVM `#define`s to enable zlib. +cc_library( + name = "zlib", + defines = ["LLVM_ENABLE_ZLIB=1"], + linkopts = ["-lz"], + visibility = ["//visibility:public"], +) diff --git a/utils/bazel/llvm-project-overlay/.bazelignore b/utils/bazel/llvm-project-overlay/.bazelignore new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/.bazelignore @@ -0,0 +1,3 @@ +# When this is symlinked in, don't treat the Bazel configuration as normal BUILD +# files and BUILD them. Everything will get very confused. +utils/bazel diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD b/utils/bazel/llvm-project-overlay/clang/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/clang/BUILD @@ -0,0 +1,2000 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +load("//llvm:tblgen.bzl", "gentbl") +load("//llvm:binary_alias.bzl", "binary_alias") + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +exports_files([ + "tools/clang-format/clang-format.el", + "tools/clang-format/clang-format-test.el", + "tools/clang-format/clang-format.py", + "tools/clang-rename/clang-rename.el", + "tools/extra/clang-include-fixer/tool/clang-include-fixer.el", + "tools/extra/clang-include-fixer/tool/clang-include-fixer-test.el", +]) + +cc_binary( + name = "clang-tblgen", + srcs = glob([ + "utils/TableGen/*.cpp", + "utils/TableGen/*.h", + ]), + copts = [ + "$(STACK_FRAME_UNLIMITED)", + ], + linkopts = ["-ldl"], + stamp = 0, + deps = [ + "//llvm:Support", + "//llvm:TableGen", + "//llvm:config", + ], +) + +gentbl( + name = "diagnostic_defs_gen", + tbl_outs = [( + "-gen-clang-diags-defs -clang-component=%s" % c, + "include/clang/Basic/Diagnostic%sKinds.inc" % c, + ) for c in [ + "AST", + "Analysis", + "Comment", + "Common", + "CrossTU", + "Driver", + "Frontend", + "Lex", + "Parse", + "Refactoring", + "Sema", + "Serialization", + ]] + [ + ( + "-gen-clang-diag-groups", + "include/clang/Basic/DiagnosticGroups.inc", + ), + ( + "-gen-clang-diags-index-name", + "include/clang/Basic/DiagnosticIndexName.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/Diagnostic.td", + td_srcs = glob(["include/clang/Basic/*.td"]), +) + +gentbl( + name = "basic_arm_neon_inc_gen", + tbl_outs = [( + "-gen-arm-neon-sema", + "include/clang/Basic/arm_neon.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_neon.td", + td_srcs = [ + "include/clang/Basic/arm_neon.td", + "include/clang/Basic/arm_neon_incl.td", + ], +) + +gentbl( + name = "basic_arm_fp16_inc_gen", + tbl_outs = [( + "-gen-arm-neon-sema", + "include/clang/Basic/arm_fp16.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_fp16.td", + td_srcs = [ + "include/clang/Basic/arm_fp16.td", + "include/clang/Basic/arm_neon_incl.td", + ], +) + +gentbl( + name = "basic_arm_mve_aliases_gen", + tbl_outs = [( + "-gen-arm-mve-builtin-aliases", + "include/clang/Basic/arm_mve_builtin_aliases.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_mve.td", + td_srcs = [ + "include/clang/Basic/arm_mve.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "basic_arm_sve_builtins_gen", + tbl_outs = [( + "-gen-arm-sve-builtins", + "include/clang/Basic/arm_sve_builtins.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_sve.td", + td_srcs = [ + "include/clang/Basic/arm_sve.td", + ], +) + +gentbl( + name = "basic_arm_sve_builtin_cg_gen", + tbl_outs = [( + "-gen-arm-sve-builtin-codegen", + "include/clang/Basic/arm_sve_builtin_cg.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_sve.td", + td_srcs = [ + "include/clang/Basic/arm_sve.td", + ], +) + +gentbl( + name = "basic_arm_sve_typeflags_gen", + tbl_outs = [( + "-gen-arm-sve-typeflags", + "include/clang/Basic/arm_sve_typeflags.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_sve.td", + td_srcs = [ + "include/clang/Basic/arm_sve.td", + ], +) + +gentbl( + name = "basic_arm_sve_sema_rangechecks_gen", + tbl_outs = [( + "-gen-arm-sve-sema-rangechecks", + "include/clang/Basic/arm_sve_sema_rangechecks.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_sve.td", + td_srcs = [ + "include/clang/Basic/arm_sve.td", + ], +) + +gentbl( + name = "basic_arm_mve_cg_gen", + tbl_outs = [( + "-gen-arm-mve-builtin-codegen", + "include/clang/Basic/arm_mve_builtin_cg.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_mve.td", + td_srcs = [ + "include/clang/Basic/arm_mve.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "basic_arm_mve_inc_gen", + tbl_outs = [( + "-gen-arm-mve-builtin-def", + "include/clang/Basic/arm_mve_builtins.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_mve.td", + td_srcs = [ + "include/clang/Basic/arm_mve.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "basic_arm_mve_sema_gen", + tbl_outs = [( + "-gen-arm-mve-builtin-sema", + "include/clang/Basic/arm_mve_builtin_sema.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_mve.td", + td_srcs = [ + "include/clang/Basic/arm_mve.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "basic_arm_cde_gen", + tbl_outs = [( + "-gen-arm-cde-builtin-def", + "include/clang/Basic/arm_cde_builtins.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_cde.td", + td_srcs = [ + "include/clang/Basic/arm_cde.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "basic_arm_cde_aliases_gen", + tbl_outs = [( + "-gen-arm-cde-builtin-aliases", + "include/clang/Basic/arm_cde_builtin_aliases.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_cde.td", + td_srcs = [ + "include/clang/Basic/arm_cde.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "basic_arm_cde_cg_gen", + tbl_outs = [( + "-gen-arm-cde-builtin-codegen", + "include/clang/Basic/arm_cde_builtin_cg.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_cde.td", + td_srcs = [ + "include/clang/Basic/arm_cde.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "basic_arm_cde_sema_gen", + tbl_outs = [( + "-gen-arm-cde-builtin-sema", + "include/clang/Basic/arm_cde_builtin_sema.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_cde.td", + td_srcs = [ + "include/clang/Basic/arm_cde.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "basic_attr_gen", + tbl_outs = [ + ( + "-gen-clang-attr-has-attribute-impl", + "include/clang/Basic/AttrHasAttributeImpl.inc", + ), + ( + "-gen-clang-attr-list", + "include/clang/Basic/AttrList.inc", + ), + ( + "-gen-clang-attr-subject-match-rule-list", + "include/clang/Basic/AttrSubMatchRulesList.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/Attr.td", + td_srcs = [ + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/Attr.td", + "include/clang/Basic/AttrDocs.td", + "include/clang/Basic/DeclNodes.td", + "include/clang/Basic/StmtNodes.td", + ], +) + +gentbl( + name = "libsema_openclbuiltins_inc_gen", + strip_include_prefix = "lib/Sema", + tbl_outs = [( + "-gen-clang-opencl-builtins", + "lib/Sema/OpenCLBuiltins.inc", + )], + tblgen = ":clang-tblgen", + td_file = "lib/Sema/OpenCLBuiltins.td", + td_srcs = [ + "lib/Sema/OpenCLBuiltins.td", + ], +) + +# Table definition files can be used for documentation: +filegroup( + name = "all_table_defs", + srcs = glob(["include/**/*.td"]), +) + +exports_files( + glob(["include/**/*.td"]), +) + +genrule( + name = "basic_version_gen", + outs = ["include/clang/Basic/Version.inc"], + cmd = ("printf " + + "\"#define CLANG_VERSION 12.0\n\"" + + "\"#define CLANG_VERSION_MAJOR 12\n\"" + + "\"#define CLANG_VERSION_MINOR 0\n\"" + + "\"#define CLANG_VERSION_PATCHLEVEL 0\n\"" + + "\"#define CLANG_VERSION_STRING \\\"git\\\"\n\" > $@"), +) + +cc_library( + name = "config", + hdrs = [ + "include/clang/Basic/Version.inc", + "include/clang/Config/config.h", + ], + includes = ["include"], + deps = [ + # We rely on the LLVM config library to provide configuration defines. + "//llvm:config", + ], +) + +# TODO: This should get replaced with something that actually generates the +# correct version number. +genrule( + name = "vcs_version_gen", + # This should be under lib/Basic, but because of how the include paths + # are passed through bazel, it's easier to drop generated files next to + # the other includes. + outs = ["include/VCSVersion.inc"], + cmd = "echo \"#define CLANG_REVISION \\\"git\\\"\" > $@", +) + +# A hacky library to expose some internal headers of the `basic` library to its +# own implementation source files using a stripped include prefix rather than +# file-relative-inclusion. This is inherently non-modular as these headers will +# be repeated in the sources below for file-relative-inclusion. +cc_library( + name = "basic_internal_headers", + hdrs = glob([ + "lib/Basic/*.h", + ]), + features = ["-header_modules"], + strip_include_prefix = "lib/Basic", +) + +cc_library( + name = "basic", + srcs = [ + "include/clang/Basic/Version.inc", + "include/VCSVersion.inc", + ] + glob([ + "lib/Basic/*.cpp", + "lib/Basic/*.c", + "lib/Basic/*.h", + "lib/Basic/Targets/*.cpp", + "lib/Basic/Targets/*.h", + ]), + hdrs = glob([ + "include/clang/Basic/*.h", + ]), + copts = [ + "-DHAVE_VCS_VERSION_INC", + "$(STACK_FRAME_UNLIMITED)", + ], + includes = ["include"], + textual_hdrs = [ + "include/clang/Basic/arm_fp16.inc", + "include/clang/Basic/arm_mve_builtins.inc", + "include/clang/Basic/arm_mve_builtin_aliases.inc", + "include/clang/Basic/arm_mve_builtin_cg.inc", + "include/clang/Basic/arm_mve_builtin_sema.inc", + "include/clang/Basic/arm_neon.inc", + "include/clang/Basic/AttrHasAttributeImpl.inc", + "include/clang/Basic/AttrList.inc", + "include/clang/Basic/AttrSubMatchRulesList.inc", + "include/clang/Basic/DiagnosticASTKinds.inc", + "include/clang/Basic/DiagnosticGroups.inc", + "include/clang/Basic/DiagnosticRefactoringKinds.inc", + "include/clang/Basic/DiagnosticAnalysisKinds.inc", + "include/clang/Basic/DiagnosticSemaKinds.inc", + "include/clang/Basic/DiagnosticCommentKinds.inc", + "include/clang/Basic/DiagnosticParseKinds.inc", + "include/clang/Basic/DiagnosticLexKinds.inc", + "include/clang/Basic/DiagnosticSerializationKinds.inc", + "include/clang/Basic/DiagnosticFrontendKinds.inc", + "include/clang/Basic/DiagnosticDriverKinds.inc", + "include/clang/Basic/DiagnosticCrossTUKinds.inc", + "include/clang/Basic/DiagnosticCommonKinds.inc", + "include/clang/Basic/DiagnosticIndexName.inc", + ] + glob([ + "include/clang/Basic/*.def", + ]), + deps = [ + ":basic_arm_cde_gen", + ":basic_arm_fp16_inc_gen", + ":basic_arm_mve_aliases_gen", + ":basic_arm_mve_cg_gen", + ":basic_arm_mve_inc_gen", + ":basic_arm_mve_sema_gen", + ":basic_arm_neon_inc_gen", + ":basic_arm_sve_builtins_gen", + ":basic_arm_sve_typeflags_gen", + ":basic_attr_gen", + ":basic_internal_headers", + ":config", + ":diagnostic_defs_gen", + ":sema_attr_gen", + "//llvm:Core", + "//llvm:FrontendOpenMP", + "//llvm:MC", + "//llvm:Support", + "//llvm:Target", + "//llvm:config", + ], +) + +cc_library( + name = "lex", + srcs = glob([ + "lib/Lex/*.cpp", + "lib/Lex/*.h", + ]), + hdrs = glob([ + "include/clang/Lex/*.h", + ]), + includes = ["include"], + deps = [ + ":basic", + "//llvm:Support", + ], +) + +gentbl( + name = "ast_attr_gen", + tbl_outs = [ + ( + "-gen-clang-attr-ast-visitor", + "include/clang/AST/AttrVisitor.inc", + ), + ( + "-gen-clang-attr-classes", + "include/clang/AST/Attrs.inc", + ), + ( + "-gen-clang-attr-text-node-dump", + "include/clang/AST/AttrTextNodeDump.inc", + ), + ( + "-gen-clang-attr-node-traverse", + "include/clang/AST/AttrNodeTraverse.inc", + ), + ( + "-gen-clang-attr-impl", + "include/clang/AST/AttrImpl.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/Attr.td", + td_srcs = [ + "include/clang/Basic/Attr.td", + "include/clang/Basic/AttrDocs.td", + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/DeclNodes.td", + "include/clang/Basic/StmtNodes.td", + ], +) + +gentbl( + name = "ast_decl_nodes_gen", + tbl_outs = [( + "-gen-clang-decl-nodes", + "include/clang/AST/DeclNodes.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/DeclNodes.td", + td_srcs = [ + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/DeclNodes.td", + ], +) + +gentbl( + name = "ast_stmt_nodes_gen", + tbl_outs = [( + "-gen-clang-stmt-nodes", + "include/clang/AST/StmtNodes.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/StmtNodes.td", + td_srcs = [ + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/StmtNodes.td", + ], +) + +gentbl( + name = "ast_comment_nodes_gen", + tbl_outs = [( + "-gen-clang-comment-nodes", + "include/clang/AST/CommentNodes.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/CommentNodes.td", + td_srcs = [ + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/CommentNodes.td", + ], +) + +gentbl( + name = "ast_comment_command_info_gen", + tbl_outs = [ + ( + "-gen-clang-comment-command-info", + "include/clang/AST/CommentCommandInfo.inc", + ), + ( + "-gen-clang-comment-command-list", + "include/clang/AST/CommentCommandList.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/AST/CommentCommands.td", + td_srcs = ["include/clang/AST/CommentCommands.td"], +) + +gentbl( + name = "ast_comment_html_tags_gen", + tbl_outs = [( + "-gen-clang-comment-html-tags", + "include/clang/AST/CommentHTMLTags.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/AST/CommentHTMLTags.td", + td_srcs = ["include/clang/AST/CommentHTMLTags.td"], +) + +gentbl( + name = "ast_comment_html_tags_properties_gen", + tbl_outs = [( + "-gen-clang-comment-html-tags-properties", + "include/clang/AST/CommentHTMLTagsProperties.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/AST/CommentHTMLTags.td", + td_srcs = ["include/clang/AST/CommentHTMLTags.td"], +) + +gentbl( + name = "ast_comment_html_named_character_references_gen", + tbl_outs = [( + "-gen-clang-comment-html-named-character-references", + "include/clang/AST/CommentHTMLNamedCharacterReferences.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/AST/CommentHTMLNamedCharacterReferences.td", + td_srcs = ["include/clang/AST/CommentHTMLNamedCharacterReferences.td"], +) + +gentbl( + name = "ast_stmt_data_collectors_gen", + tbl_outs = [( + "-gen-clang-data-collectors", + "include/clang/AST/StmtDataCollectors.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/AST/StmtDataCollectors.td", + td_srcs = ["include/clang/AST/StmtDataCollectors.td"], +) + +gentbl( + name = "ast_interp_opcodes_gen", + tbl_outs = [( + "-gen-clang-opcodes", + "lib/AST/Interp/Opcodes.inc", + )], + tblgen = ":clang-tblgen", + td_file = "lib/AST/Interp/Opcodes.td", + td_srcs = ["lib/AST/Interp/Opcodes.td"], +) + +gentbl( + name = "ast_properties_base_gen", + tbl_outs = [ + ( + "-gen-clang-basic-reader", + "include/clang/AST/AbstractBasicReader.inc", + ), + ( + "-gen-clang-basic-writer", + "include/clang/AST/AbstractBasicWriter.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/AST/PropertiesBase.td", + td_srcs = ["include/clang/AST/PropertiesBase.td"], +) + +gentbl( + name = "ast_type_properties_gen", + tbl_outs = [ + ( + "-gen-clang-type-reader", + "include/clang/AST/AbstractTypeReader.inc", + ), + ( + "-gen-clang-type-writer", + "include/clang/AST/AbstractTypeWriter.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/AST/TypeProperties.td", + td_srcs = [ + "include/clang/AST/PropertiesBase.td", + "include/clang/AST/TypeProperties.td", + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/TypeNodes.td", + ], +) + +gentbl( + name = "type_nodes_gen", + tbl_outs = [( + "-gen-clang-type-nodes", + "include/clang/AST/TypeNodes.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/TypeNodes.td", + td_srcs = [ + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/TypeNodes.td", + ], +) + +cc_library( + name = "ast", + srcs = glob([ + "lib/AST/*.cpp", + "lib/AST/*.h", + "lib/AST/Interp/*.cpp", + "lib/AST/Interp/*.h", + ]), + hdrs = glob([ + "include/clang/AST/*.h", + ]), + includes = [ + "include", + "lib/AST/Interp", + ], + textual_hdrs = [ + "include/clang/AST/AttrImpl.inc", + "include/clang/AST/AttrNodeTraverse.inc", + "include/clang/AST/Attrs.inc", + "include/clang/AST/AttrTextNodeDump.inc", + "include/clang/AST/AttrVisitor.inc", + "include/clang/AST/CommentCommandInfo.inc", + "include/clang/AST/CommentCommandList.inc", + "include/clang/AST/CommentHTMLNamedCharacterReferences.inc", + "include/clang/AST/CommentHTMLTags.inc", + "include/clang/AST/CommentHTMLTagsProperties.inc", + "include/clang/AST/CommentNodes.inc", + "include/clang/AST/DeclNodes.inc", + "include/clang/AST/StmtDataCollectors.inc", + "include/clang/AST/StmtNodes.inc", + "lib/AST/Interp/Opcodes.inc", + ] + glob([ + "include/clang/AST/*.def", + ]), + deps = [ + ":ast_attr_gen", + ":ast_comment_command_info_gen", + ":ast_comment_html_named_character_references_gen", + ":ast_comment_html_tags_gen", + ":ast_comment_html_tags_properties_gen", + ":ast_comment_nodes_gen", + ":ast_decl_nodes_gen", + ":ast_interp_opcodes_gen", + ":ast_properties_base_gen", + ":ast_stmt_data_collectors_gen", + ":ast_stmt_nodes_gen", + ":ast_type_properties_gen", + ":basic", + ":lex", + ":type_nodes_gen", + "//llvm:BinaryFormat", + "//llvm:Core", + "//llvm:FrontendOpenMP", + "//llvm:Support", + ], +) + +cc_library( + name = "index", + srcs = glob([ + "lib/Index/*.cpp", + "lib/Index/*.h", + ]), + hdrs = glob([ + "include/clang/Index/*.h", + "include/clang-c/*.h", + ]), + includes = ["include"], + deps = [ + ":ast", + ":basic", + ":format", + ":frontend", + ":lex", + ":rewrite", + ":serialization", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "analysis", + srcs = glob([ + "lib/Analysis/*.cpp", + "lib/Analysis/*.h", + ]), + hdrs = glob([ + "include/clang/Analysis/**/*.h", + ]), + includes = ["include"], + textual_hdrs = glob([ + "include/clang/Analysis/**/*.def", + ]), + deps = [ + ":ast", + ":ast_matchers", + ":basic", + ":lex", + "//llvm:Support", + ], +) + +gentbl( + name = "sema_attr_gen", + tbl_outs = [ + ( + "-gen-clang-attr-parsed-attr-impl", + "include/clang/Sema/AttrParsedAttrImpl.inc", + ), + ( + "-gen-clang-attr-parsed-attr-kinds", + "include/clang/Sema/AttrParsedAttrKinds.inc", + ), + ( + "-gen-clang-attr-parsed-attr-list", + "include/clang/Sema/AttrParsedAttrList.inc", + ), + ( + "-gen-clang-attr-spelling-index", + "include/clang/Sema/AttrSpellingListIndex.inc", + ), + ( + "-gen-clang-attr-template-instantiate", + "include/clang/Sema/AttrTemplateInstantiate.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/Attr.td", + td_srcs = [ + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/Attr.td", + "include/clang/Basic/AttrDocs.td", + "include/clang/Basic/DeclNodes.td", + "include/clang/Basic/StmtNodes.td", + ], +) + +cc_library( + name = "sema", + srcs = glob([ + "lib/Sema/*.cpp", + "lib/Sema/*.h", + ]), + hdrs = glob([ + "include/clang/Sema/*.h", + "include/clang-c/*.h", + ]), + copts = ["$(STACK_FRAME_UNLIMITED)"], + includes = ["include"], + textual_hdrs = glob([ + "include/clang/Sema/AttrParsedAttrImpl.inc", + "include/clang/Sema/AttrParsedAttrKinds.inc", + "include/clang/Sema/AttrParsedAttrList.inc", + "include/clang/Sema/AttrSpellingListIndex.inc", + "include/clang/Sema/AttrTemplateInstantiate.inc", + "lib/Sema/OpenCLBuiltins.inc", + ]), + deps = [ + ":analysis", + ":ast", + ":basic", + ":basic_arm_cde_aliases_gen", + ":basic_arm_cde_sema_gen", + ":basic_arm_sve_builtins_gen", + ":basic_arm_sve_sema_rangechecks_gen", + ":edit", + ":lex", + ":libsema_openclbuiltins_inc_gen", + ":sema_attr_gen", + ":type_nodes_gen", + "//llvm:AllTargetsAsmParsers", + "//llvm:AllTargetsCodeGens", + "//llvm:Core", + "//llvm:FrontendOpenMP", + "//llvm:MCParser", + "//llvm:Support", + ], +) + +gentbl( + name = "parse_attr_gen", + tbl_outs = [ + ( + "-gen-clang-attr-parser-string-switches", + "include/clang/Parse/AttrParserStringSwitches.inc", + ), + ( + "-gen-clang-attr-subject-match-rules-parser-string-switches", + "include/clang/Parse/AttrSubMatchRulesParserStringSwitches.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/Attr.td", + td_srcs = [ + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/Attr.td", + "include/clang/Basic/AttrDocs.td", + "include/clang/Basic/DeclNodes.td", + "include/clang/Basic/StmtNodes.td", + ], +) + +cc_library( + name = "parse", + srcs = [ + ] + glob([ + "lib/Parse/*.cpp", + "lib/Parse/*.h", + ]), + hdrs = [ + "include/clang/Parse/AttrParserStringSwitches.inc", + "include/clang/Parse/AttrSubMatchRulesParserStringSwitches.inc", + ] + glob(["include/clang/Parse/*.h"]), + includes = ["include"], + deps = [ + ":ast", + ":basic", + ":lex", + ":parse_attr_gen", + ":sema", + "//llvm:FrontendOpenMP", + "//llvm:MC", + "//llvm:MCParser", + "//llvm:Support", + ], +) + +cc_library( + name = "ast_matchers", + srcs = glob([ + "lib/ASTMatchers/*.cpp", + "lib/ASTMatchers/*.h", + ]), + hdrs = glob(["include/clang/ASTMatchers/*.h"]), + includes = ["include"], + deps = [ + ":ast", + ":basic", + ":lex", + "//llvm:Support", + ], +) + +cc_library( + name = "ast_matchers_dynamic", + srcs = glob([ + "lib/ASTMatchers/Dynamic/*.cpp", + "lib/ASTMatchers/Dynamic/*.h", + ]), + hdrs = glob(["include/clang/ASTMatchers/Dynamic/*.h"]), + copts = ["$(STACK_FRAME_UNLIMITED)"], + includes = ["include"], + deps = [ + ":ast", + ":ast_matchers", + ":basic", + "//llvm:FrontendOpenMP", + "//llvm:Support", + ], +) + +cc_library( + name = "rewrite", + srcs = glob([ + "lib/Rewrite/*.cpp", + "lib/Rewrite/*.h", + ]), + hdrs = glob(["include/clang/Rewrite/Core/*.h"]), + includes = ["include"], + deps = [ + ":ast", + ":basic", + ":edit", + ":lex", + "//llvm:Support", + ], +) + +cc_library( + name = "testing", + srcs = glob([ + "lib/Testing/*.cpp", + ]), + hdrs = glob(["include/clang/Testing/*.h"]), + includes = ["include"], + deps = [ + ":basic", + "//llvm:Support", + ], +) + +cc_library( + name = "tooling_core", + srcs = glob([ + "lib/Tooling/Core/*.cpp", + "lib/Tooling/Core/*.h", + ]), + hdrs = glob(["include/clang/Tooling/Core/*.h"]), + includes = ["include"], + deps = [ + ":ast", + ":basic", + ":lex", + ":rewrite", + "//llvm:Support", + ], +) + +cc_library( + name = "tooling", + srcs = glob([ + "lib/Tooling/*.cpp", + ]), + hdrs = glob([ + "include/clang/Tooling/*.h", + ]), + includes = ["include"], + deps = [ + ":ast", + ":ast_matchers", + ":basic", + ":driver", + ":format", + ":frontend", + ":lex", + ":rewrite", + ":tooling_core", + "//llvm:Option", + "//llvm:Support", + ], +) + +cc_library( + name = "tooling_inclusions", + srcs = glob([ + "lib/Tooling/Inclusions/**/*.cpp", + ]), + hdrs = glob([ + "include/clang/Tooling/Inclusions/**/*.h", + ]), + deps = [ + ":basic", + ":lex", + ":rewrite", + ":tooling_core", + "//llvm:Support", + ], +) + +cc_library( + name = "tooling_refactoring", + srcs = glob([ + "lib/Tooling/Refactoring/**/*.cpp", + "lib/Tooling/Refactoring/**/*.h", + ]), + hdrs = glob([ + "include/clang/Tooling/Refactoring/**/*.h", + "include/clang/Tooling/Refactoring/**/*.def", + ]), + deps = [ + ":ast", + ":ast_matchers", + ":basic", + ":format", + ":frontend", + ":index", + ":lex", + ":rewrite", + ":tooling", + ":tooling_core", + "//llvm:Support", + ], +) + +gentbl( + name = "tooling_syntax_gen", + tbl_outs = [ + ("-gen-clang-syntax-node-list", "include/clang/Tooling/Syntax/Nodes.inc"), + ("-gen-clang-syntax-node-classes", "include/clang/Tooling/Syntax/NodeClasses.inc"), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/Tooling/Syntax/Nodes.td", + td_srcs = [ + "include/clang/Tooling/Syntax/Nodes.td", + "include/clang/Tooling/Syntax/Syntax.td", + ], +) + +cc_library( + name = "tooling_syntax", + srcs = glob(["lib/Tooling/Syntax/**/*.cpp"]), + hdrs = glob(["include/clang/Tooling/Syntax/**/*.h"]), + deps = [ + ":ast", + ":basic", + ":lex", + ":tooling_core", + ":tooling_syntax_gen", + "//llvm:Support", + ], +) + +cc_library( + name = "tooling_dependency_scanning", + srcs = glob(["lib/Tooling/DependencyScanning/**/*.cpp"]), + hdrs = glob(["include/clang/Tooling/DependencyScanning/**/*.h"]), + deps = [ + ":basic", + ":frontend", + ":lex", + ":serialization", + ":tooling", + "//llvm:Support", + ], +) + +cc_library( + name = "transformer", + srcs = glob(["lib/Tooling/Transformer/**/*.cpp"]), + hdrs = glob(["include/clang/Tooling/Transformer/**/*.h"]), + deps = [ + ":ast", + ":ast_matchers", + ":basic", + ":lex", + ":rewrite", + ":tooling_refactoring", + "//llvm:Support", + ], +) + +cc_library( + name = "ast-diff", + srcs = glob(["lib/Tooling/ASTDiff/*.cpp"]), + hdrs = glob(["include/clang/Tooling/ASTDiff/*.h"]), + deps = [ + ":ast", + ":basic", + ":lex", + "//llvm:Support", + ], +) + +cc_library( + name = "crosstu", + srcs = glob(["lib/CrossTU/*.cpp"]), + hdrs = glob(["include/clang/CrossTU/*.h"]), + deps = [ + ":ast", + ":basic", + ":frontend", + ":index", + "//llvm:Option", + "//llvm:Support", + ], +) + +cc_library( + name = "format", + srcs = glob( + [ + "lib/Format/*.cpp", + "lib/Format/*.h", + ], + ), + hdrs = glob([ + "include/clang/Format/*.h", + "lib/Format/FormatTokenLexer.h", + "lib/Format/Macros.h", + ]), + includes = ["include"], + deps = [ + ":basic", + ":lex", + ":tooling_core", + ":tooling_inclusions", + "//llvm:Support", + ], +) + +cc_library( + name = "edit", + srcs = glob(["lib/Edit/*.cpp"]), + hdrs = glob(["include/clang/Edit/*.h"]), + includes = ["include"], + deps = [ + ":ast", + ":basic", + ":lex", + "//llvm:Support", + ], +) + +cc_library( + name = "static_analyzer_core_options", + hdrs = [ + "include/clang/StaticAnalyzer/Core/AnalyzerOptions.h", + ], + textual_hdrs = [ + "include/clang/StaticAnalyzer/Core/Analyses.def", + "include/clang/StaticAnalyzer/Core/AnalyzerOptions.def", + ], + deps = [ + ":basic", + ":static_analyzer_checkers_gen", + "//llvm:Support", + ], +) + +cc_library( + name = "static_analyzer_core", + srcs = glob([ + "lib/StaticAnalyzer/Core/**/*.cpp", + "lib/StaticAnalyzer/Core/**/*.h", + ]), + hdrs = glob([ + "include/clang/StaticAnalyzer/Core/**/*.h", + ]), + includes = ["include"], + textual_hdrs = glob([ + "include/clang/StaticAnalyzer/Core/**/*.def", + ]), + deps = [ + ":analysis", + ":ast", + ":ast_matchers", + ":basic", + ":crosstu", + ":driver", + ":frontend", + ":lex", + ":rewrite", + ":static_analyzer_checkers_gen", + ":tooling", + ":tooling_core", + "//llvm:Support", + ], +) + +gentbl( + name = "static_analyzer_checkers_gen", + tbl_outs = [( + "-gen-clang-sa-checkers", + "include/clang/StaticAnalyzer/Checkers/Checkers.inc", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/StaticAnalyzer/Checkers/Checkers.td", + td_srcs = [ + "include/clang/StaticAnalyzer/Checkers/CheckerBase.td", + "include/clang/StaticAnalyzer/Checkers/Checkers.td", + ], +) + +cc_library( + name = "static_analyzer_checkers", + srcs = glob([ + "lib/StaticAnalyzer/Checkers/**/*.cpp", + "lib/StaticAnalyzer/Checkers/**/*.h", + ]), + hdrs = [ + "include/clang/StaticAnalyzer/Checkers/Checkers.inc", + ] + glob([ + "include/clang/StaticAnalyzer/Checkers/**/*.h", + ]), + copts = ["$(STACK_FRAME_UNLIMITED)"], + includes = ["include"], + deps = [ + ":analysis", + ":ast", + ":ast_matchers", + ":basic", + ":driver", + ":lex", + ":static_analyzer_checkers_gen", + ":static_analyzer_core", + "//llvm:Support", + ], +) + +gentbl( + name = "driver_options_inc_gen", + tbl_outs = [( + "-gen-opt-parser-defs", + "include/clang/Driver/Options.inc", + )], + tblgen = "//llvm:llvm-tblgen", + td_file = "include/clang/Driver/Options.td", + td_srcs = [ + "//llvm:include/llvm/Option/OptParser.td", + ], +) + +cc_library( + name = "driver", + srcs = glob( + [ + "lib/Driver/*.cpp", + "lib/Driver/*.h", + "lib/Driver/Arch/*.cpp", + "lib/Driver/Arch/*.h", + "lib/Driver/ToolChains/*.cpp", + "lib/Driver/ToolChains/*.h", + "lib/Driver/ToolChains/Arch/*.cpp", + "lib/Driver/ToolChains/Arch/*.h", + ], + exclude = [ + "lib/Driver/ToolChains/MSVCSetupApi.h", + ], + ), + hdrs = glob([ + "include/clang/Driver/*.h", + ]), + copts = ["$(STACK_FRAME_UNLIMITED)"], + includes = [ + "include", + # TODO: This is likely a layering issue, but files in Arch are currently + # directly #including "Tools.h". + "lib/Driver", + ], + textual_hdrs = glob([ + "include/clang/Driver/*.def", + ]), + deps = [ + ":ast", + ":basic", + ":config", + ":driver_options_inc_gen", + ":parse", + ":static_analyzer_checkers_gen", + "//llvm:BinaryFormat", + "//llvm:MC", + "//llvm:Option", + "//llvm:ProfileData", + "//llvm:Support", + "//llvm:Target", + "//llvm:config", + ], +) + +gentbl( + name = "headers_arm_neon_gen", + tbl_outs = [( + "-gen-arm-neon", + "lib/Headers/arm_neon.h", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_neon.td", + td_srcs = [ + "include/clang/Basic/arm_neon.td", + "include/clang/Basic/arm_neon_incl.td", + ], +) + +gentbl( + name = "headers_arm_fp16_gen", + tbl_outs = [( + "-gen-arm-fp16", + "lib/Headers/arm_fp16.h", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_fp16.td", + td_srcs = [ + "include/clang/Basic/arm_fp16.td", + "include/clang/Basic/arm_neon_incl.td", + ], +) + +gentbl( + name = "headers_arm_mve_gen", + tbl_outs = [( + "-gen-arm-mve-header", + "lib/Headers/arm_mve.h", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_mve.td", + td_srcs = [ + "include/clang/Basic/arm_mve.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "headers_arm_cde_gen", + tbl_outs = [( + "-gen-arm-cde-header", + "lib/Headers/arm_cde.h", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_cde.td", + td_srcs = [ + "include/clang/Basic/arm_cde.td", + "include/clang/Basic/arm_mve_defs.td", + ], +) + +gentbl( + name = "headers_arm_sve_gen", + tbl_outs = [( + "-gen-arm-sve-header", + "lib/Headers/arm_sve.h", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_sve.td", + td_srcs = [ + "include/clang/Basic/arm_sve.td", + ], +) + +gentbl( + name = "headers_arm_bf16_gen", + tbl_outs = [( + "-gen-arm-bf16", + "lib/Headers/arm_bf16.h", + )], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/arm_bf16.td", + td_srcs = [ + "include/clang/Basic/arm_bf16.td", + "include/clang/Basic/arm_neon_incl.td", + ], +) + +# We generate the set of builtin headers under a special subdirectory in the +# 'bin' section of the bazel output so that they can be used as data +# dependencies. It requires listing explicitly all the generated inputs here. +builtin_headers = glob(["lib/Headers/**/*.h"]) + [ + "lib/Headers/arm_cde.h", + "lib/Headers/arm_fp16.h", + "lib/Headers/arm_mve.h", + "lib/Headers/arm_neon.h", + "lib/Headers/arm_sve.h", + "lib/Headers/arm_bf16.h", +] + +genrule( + name = "builtin_headers_gen", + srcs = builtin_headers, + outs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in builtin_headers], + cmd = """ + for src in $(SRCS); do + relsrc=$${src/*external\\/llvm-project\\/clang\\/lib\\/Headers\\/} + target=$(@D)/staging/include/$$relsrc + mkdir -p $$(dirname $$target) + cp $$src $$target + done""", + output_to_bindir = 1, +) + +cc_library( + name = "frontend", + srcs = glob([ + "lib/Frontend/*.cpp", + "lib/Frontend/*.h", + ]), + hdrs = glob([ + "include/clang/Frontend/*.h", + ]), + copts = ["$(STACK_FRAME_UNLIMITED)"], + data = [":builtin_headers_gen"], + includes = ["include"], + textual_hdrs = glob([ + "include/clang/Frontend/*.def", + ]), + deps = [ + ":ast", + ":basic", + ":config", + ":driver", + ":driver_options_inc_gen", + ":edit", + ":lex", + ":parse", + ":sema", + ":serialization", + ":static_analyzer_core_options", + "//llvm:BinaryFormat", + "//llvm:BitReader", + "//llvm:BitstreamReader", + "//llvm:BitstreamWriter", + "//llvm:Core", + "//llvm:Linker", + "//llvm:MC", + "//llvm:Option", + "//llvm:ProfileData", + "//llvm:Support", + "//llvm:Target", + "//llvm:config", + ], +) + +cc_library( + name = "frontend_rewrite", + srcs = glob([ + "lib/Frontend/Rewrite/*.cpp", + "lib/Frontend/Rewrite/*.h", + ]), + hdrs = glob(["include/clang/Rewrite/Frontend/*.h"]), + includes = ["include"], + deps = [ + ":ast", + ":basic", + ":config", + ":edit", + ":frontend", + ":lex", + ":parse", + ":rewrite", + ":serialization", + "//llvm:Support", + ], +) + +cc_library( + name = "codegen", + srcs = glob([ + "lib/CodeGen/*.cpp", + "lib/CodeGen/*.h", + ]), + hdrs = glob(["include/clang/CodeGen/*.h"]), + copts = ["$(STACK_FRAME_UNLIMITED)"], + includes = ["include"], + deps = [ + ":analysis", + ":ast", + ":basic", + ":basic_arm_cde_cg_gen", + ":basic_arm_sve_builtin_cg_gen", + ":driver", + ":frontend", + ":lex", + ":sema", + ":type_nodes_gen", + "//llvm:AllTargetsAsmParsers", + "//llvm:Analysis", + "//llvm:BitReader", + "//llvm:BitWriter", + "//llvm:BitstreamReader", + "//llvm:CodeGen", + "//llvm:Core", + "//llvm:Coroutines", + "//llvm:Coverage", + "//llvm:DebugInfoDWARF", + "//llvm:FrontendOpenMP", + "//llvm:IPO", + "//llvm:IRReader", + "//llvm:InstCombine", + "//llvm:Instrumentation", + "//llvm:LTO", + "//llvm:Linker", + "//llvm:MC", + "//llvm:ObjCARC", + "//llvm:Object", + "//llvm:Passes", + "//llvm:ProfileData", + "//llvm:Scalar", + "//llvm:Support", + "//llvm:Target", + "//llvm:TransformUtils", + ], +) + +cc_library( + name = "static_analyzer_frontend", + srcs = glob([ + "lib/StaticAnalyzer/Frontend/**/*.cpp", + "lib/StaticAnalyzer/Frontend/**/*.h", + ]), + hdrs = glob(["include/clang/StaticAnalyzer/Frontend/**/*.h"]), + includes = ["include"], + deps = [ + ":analysis", + ":ast", + ":basic", + ":crosstu", + ":driver", + ":frontend", + ":lex", + ":rewrite", + ":serialization", + ":static_analyzer_checkers", + ":static_analyzer_core", + ":tooling", + ":tooling_core", + "//llvm:Support", + ], +) + +gentbl( + name = "serialization_attr_gen", + tbl_outs = [ + ( + "-gen-clang-attr-pch-read", + "include/clang/Serialization/AttrPCHRead.inc", + ), + ( + "-gen-clang-attr-pch-write", + "include/clang/Serialization/AttrPCHWrite.inc", + ), + ], + tblgen = ":clang-tblgen", + td_file = "include/clang/Basic/Attr.td", + td_srcs = [ + "include/clang/Basic/ASTNode.td", + "include/clang/Basic/Attr.td", + "include/clang/Basic/AttrDocs.td", + "include/clang/Basic/DeclNodes.td", + "include/clang/Basic/StmtNodes.td", + ], +) + +cc_library( + name = "serialization", + srcs = glob([ + "lib/Serialization/*.cp" + "p", + "lib/Serialization/*.h", + "include/clang/Serialization/AttrPCHRead.inc", + "include/clang/Serialization/AttrPCHWrite.inc", + ]), + hdrs = glob([ + "include/clang/Serialization/*.h", + ]), + includes = ["include"], + textual_hdrs = glob([ + "include/clang/Serialization/*.def", + ]), + deps = [ + ":ast", + ":basic", + ":lex", + ":sema", + ":serialization_attr_gen", + ":type_nodes_gen", + "//llvm:BitReader", + "//llvm:BitWriter", + "//llvm:BitstreamReader", + "//llvm:BitstreamWriter", + "//llvm:FrontendOpenMP", + "//llvm:Support", + ], +) + +cc_library( + name = "frontend_tool", + srcs = glob([ + "lib/FrontendTool/*.cpp", + "lib/FrontendTool/*.h", + ]), + hdrs = glob(["include/clang/FrontendTool/*.h"]), + includes = ["include"], + deps = [ + ":arc_migrate", + ":codegen", + ":config", + ":driver", + ":frontend", + ":frontend_rewrite", + ":static_analyzer_frontend", + "//llvm:Option", + "//llvm:Support", + ], +) + +cc_library( + name = "arc_migrate", + srcs = glob([ + "lib/ARCMigrate/*.cpp", + "lib/ARCMigrate/*.h", + ]), + hdrs = glob(["include/clang/ARCMigrate/*.h"]), + includes = ["include"], + deps = [ + ":analysis", + ":ast", + ":basic", + ":edit", + ":frontend", + ":frontend_rewrite", + ":lex", + ":parse", + ":rewrite", + ":sema", + ":serialization", + ":static_analyzer_checkers", + ":static_analyzer_core", + "//llvm:Support", + ], +) + +cc_library( + name = "libclang", + srcs = glob([ + "tools/libclang/*.cpp", + "tools/libclang/*.h", + ]), + hdrs = glob(["include/clang-c/*.h"]), + deps = [ + ":arc_migrate", + ":ast", + ":basic", + ":codegen", + ":config", + ":driver", + ":frontend", + ":index", + ":lex", + ":rewrite", + ":sema", + ":tooling", + "//llvm:BitstreamReader", + "//llvm:FrontendOpenMP", + "//llvm:Support", + "//llvm:config", + ], +) + +cc_library( + name = "c-bindings", + hdrs = glob(["include/clang-c/*.h"]), + deps = [ + ":libclang", + ], + alwayslink = 1, +) + +cc_binary( + name = "libclang.so", + linkopts = [ + "-nodefaultlibs", + "-lc_nonshared", + "-lgcc", + "-lgcc_eh", + "-Wno-unused-command-line-argument", + ], + linkshared = 1, + deps = [":c-bindings"], +) + +filegroup( + name = "python-sources", + srcs = [ + "bindings/python/clang/cindex.py", + "bindings/python/clang/enumerations.py", + ], +) + +filegroup( + name = "python-cindex-examples", + srcs = [ + "bindings/python/examples/cindex/cindex-dump.py", + "bindings/python/examples/cindex/cindex-includes.py", + ], +) + +cc_binary( + name = "c-index-test", + testonly = 1, + srcs = [ + "tools/c-index-test/c-index-test.c", + "tools/c-index-test/core_main.cpp", + ], + copts = [ + "-Wno-uninitialized", + ], + stamp = 0, + deps = [ + ":ast", + ":basic", + ":c-bindings", + ":codegen", + ":config", + ":frontend", + ":index", + ":lex", + ":parse", + ":sema", + ":serialization", + "//llvm:Core", + "//llvm:MC", + "//llvm:Support", + ], +) + +cc_binary( + name = "arcmt-test", + testonly = 1, + srcs = ["tools/arcmt-test/arcmt-test.cpp"], + stamp = 0, + deps = [ + ":arc_migrate", + ":ast", + ":basic", + ":frontend", + ":frontend_rewrite", + ":lex", + "//llvm:Support", + ], +) + +cc_binary( + name = "c-arcmt-test", + testonly = 1, + srcs = ["tools/c-arcmt-test/c-arcmt-test.c"], + copts = ["-std=gnu99"], + stamp = 0, + deps = [ + ":c-bindings", + ":codegen", + "//llvm:MC", + "//llvm:Support", + ], +) + +cc_binary( + name = "clang-import-test", + testonly = 1, + srcs = glob([ + "tools/clang-import-test/*.cpp", + "tools/clang-import-test/*.h", + ]), + stamp = 0, + deps = [ + ":ast", + ":basic", + ":codegen", + ":driver", + ":frontend", + ":lex", + ":parse", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "clang-driver", + srcs = glob([ + "tools/driver/*.cpp", + "tools/driver/*.h", + ]), + copts = [ + # Disable stack frame size checks in the driver because + # clang::ensureStackAddressSpace allocates a large array on the stack. + "$(STACK_FRAME_UNLIMITED)", + ], + deps = [ + ":analysis", + ":ast", + ":basic", + ":codegen", + ":config", + ":driver", + ":frontend", + ":frontend_rewrite", + ":frontend_tool", + ":lex", + ":parse", + ":sema", + ":serialization", + ":static_analyzer_frontend", + "//llvm:AllTargetsAsmParsers", + "//llvm:AllTargetsCodeGens", + "//llvm:BitReader", + "//llvm:BitWriter", + "//llvm:CodeGen", + "//llvm:Core", + "//llvm:IPO", + "//llvm:MC", + "//llvm:MCParser", + "//llvm:Option", + "//llvm:Support", + "//llvm:Target", + "//llvm:config", + ], +) + +cc_binary( + name = "clang", + srcs = [], + stamp = 0, + deps = [ + ":clang-driver", + ], +) + +cc_binary( + name = "diagtool", + srcs = glob([ + "tools/diagtool/*.cpp", + "tools/diagtool/*.h", + ]), + stamp = 0, + deps = [ + ":basic", + ":frontend", + ":lex", + ":sema", + "//llvm:Support", + ], +) + +filegroup( + name = "exploded_graph_rewriter", + testonly = 1, + data = ["utils/analyzer/exploded-graph-rewriter.py"], +) + +filegroup( + name = "hmaptool", + testonly = 1, + data = ["utils/hmaptool/hmaptool"], +) + +binary_alias( + name = "clang++", + binary = ":clang", +) + +cc_binary( + name = "clang-check", + srcs = ["tools/clang-check/ClangCheck.cpp"], + stamp = 0, + deps = [ + ":ast", + ":codegen", + ":driver", + ":frontend", + ":frontend_rewrite", + ":serialization", + ":static_analyzer_frontend", + ":tooling", + "//llvm:Option", + "//llvm:Support", + ], +) + +cc_binary( + name = "clang-format", + srcs = [ + "tools/clang-format/ClangFormat.cpp", + ], + stamp = 0, + deps = [ + ":basic", + ":format", + ":frontend", + ":rewrite", + "//llvm:Support", + ], +) + +cc_binary( + name = "clang-diff", + srcs = glob(["tools/clang-diff/*.cpp"]), + stamp = 0, + deps = [ + ":ast-diff", + ":tooling", + "//llvm:Support", + ], +) + +cc_binary( + name = "clang-offload-bundler", + srcs = glob(["tools/clang-offload-bundler/*.cpp"]), + stamp = 0, + deps = [ + ":basic", + ":tooling", + "//llvm:BitWriter", + "//llvm:Core", + "//llvm:Object", + "//llvm:Support", + ], +) + +cc_binary( + name = "clang-offload-wrapper", + srcs = glob(["tools/clang-offload-wrapper/*.cpp"]), + stamp = 0, + deps = [ + ":basic", + "//llvm:BitWriter", + "//llvm:Support", + "//llvm:TransformUtils", + "//llvm:ir_headers", + ], +) + +cc_binary( + name = "clang-refactor", + srcs = glob([ + "tools/clang-refactor/*.cpp", + "tools/clang-refactor/*.h", + ]), + stamp = 0, + deps = [ + ":ast", + ":basic", + ":format", + ":frontend", + ":lex", + ":rewrite", + ":tooling", + ":tooling_refactoring", + "//llvm:Support", + ], +) + +cc_binary( + name = "clang-rename", + srcs = glob(["tools/clang-rename/*.cpp"]), + stamp = 0, + deps = [ + ":basic", + ":frontend", + ":rewrite", + ":tooling", + ":tooling_refactoring", + "//llvm:Support", + ], +) + +cc_binary( + name = "clang-extdef-mapping", + srcs = glob(["tools/clang-extdef-mapping/*.cpp"]), + stamp = 0, + deps = [ + ":ast", + ":basic", + ":crosstu", + ":frontend", + ":tooling", + "//llvm:Support", + ], +) + +cc_binary( + name = "clang-scan-deps", + srcs = glob(["tools/clang-scan-deps/*.cpp"]), + stamp = 0, + deps = [ + ":frontend", + ":tooling", + ":tooling_dependency_scanning", + "//llvm:Support", + ], +) diff --git a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h @@ -0,0 +1,103 @@ +/*===------- clang/Config/config.h - llvm configuration -----------*- C -*-===*/ +/* */ +/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ +/* Exceptions. */ +/* See https://llvm.org/LICENSE.txt for license information. */ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* */ +/*===----------------------------------------------------------------------===*/ + +/* This is a manual port of config.h.cmake for the symbols that do not change + based on platform. Those that do change should not be defined here and + instead use Bazel cc_library defines. Some attempt has been made to extract + such symbols that do vary based on platform (for the platforms we care about) + into Bazel defines, but it is by no means complete, so if you see something + that looks wrong, it probably is. */ + +#ifdef CLANG_CONFIG_H +#error config.h can only be included once +#else +#define CLANG_CONFIG_H + +/* Bug report URL. */ +#define BUG_REPORT_URL "https://bugs.llvm.org/" + +/* Default linker to use. */ +#define CLANG_DEFAULT_LINKER "" + +/* Default C/ObjC standard to use. */ +/* #undef CLANG_DEFAULT_STD_C */ + +/* Default C++/ObjC++ standard to use. */ +/* #undef CLANG_DEFAULT_STD_CXX */ + +/* Default C++ stdlib to use. */ +#define CLANG_DEFAULT_CXX_STDLIB "" + +/* Default runtime library to use. */ +#define CLANG_DEFAULT_RTLIB "" + +/* Default unwind library to use. */ +#define CLANG_DEFAULT_UNWINDLIB "" + +/* Default objcopy to use */ +#define CLANG_DEFAULT_OBJCOPY "objcopy" + +/* Default OpenMP runtime used by -fopenmp. */ +#define CLANG_DEFAULT_OPENMP_RUNTIME "libomp" + +/* Default architecture for OpenMP offloading to Nvidia GPUs. */ +#define CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_35" + +/* Default architecture for SystemZ. */ +#define CLANG_SYSTEMZ_DEFAULT_ARCH "z10" + +/* Multilib suffix for libdir. */ +#define CLANG_LIBDIR_SUFFIX "" + +/* Relative directory for resource files */ +#define CLANG_RESOURCE_DIR "" + +/* Directories clang will search for headers */ +#define C_INCLUDE_DIRS "" + +/* Directories clang will search for configuration files */ +/* #undef CLANG_CONFIG_FILE_SYSTEM_DIR */ +/* #undef CLANG_CONFIG_FILE_USER_DIR */ + +/* Default to all compiler invocations for --sysroot=. */ +#define DEFAULT_SYSROOT "" + +/* Directory where gcc is installed. */ +#define GCC_INSTALL_PREFIX "" + +/* Define if we have libxml2 */ +/* #undef CLANG_HAVE_LIBXML */ + +/* Define if we have sys/resource.h (rlimits) */ +#define CLANG_HAVE_RLIMITS 1 + +/* The LLVM product name and version */ +#define BACKEND_PACKAGE_STRING "LLVM 12.0.0git" + +/* Linker version detected at compile time. */ +/* #undef HOST_LINK_VERSION */ + +/* pass --build-id to ld */ +/* #undef ENABLE_LINKER_BUILD_ID */ + +/* enable x86 relax relocations by default */ +#define ENABLE_X86_RELAX_RELOCATIONS 1 + +/* Enable the experimental new pass manager by default */ +#define ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER 0 + +/* Enable each functionality of modules */ +#define CLANG_ENABLE_ARCMT 1 +#define CLANG_ENABLE_OBJC_REWRITER 1 +#define CLANG_ENABLE_STATIC_ANALYZER 1 + +/* Spawn a new process clang.exe for the CC1 tool invocation, when necessary */ +#define CLANG_SPAWN_CC1 0 + +#endif diff --git a/utils/bazel/llvm-project-overlay/clang/unittests/BUILD b/utils/bazel/llvm-project-overlay/clang/unittests/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/clang/unittests/BUILD @@ -0,0 +1,422 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +cc_test( + name = "ast_tests", + size = "medium", + srcs = glob([ + "AST/*.cpp", + "AST/*.h", + ]), + shard_count = 20, + deps = [ + "//clang:ast", + "//clang:ast_matchers", + "//clang:basic", + "//clang:frontend", + "//clang:lex", + "//clang:testing", + "//clang:tooling", + "//llvm:Core", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_library( + name = "ast_matchers_tests_hdrs", + testonly = 1, + hdrs = glob(["ASTMatchers/*.h"]), + deps = [ + "//clang:ast_matchers", + "//clang:frontend", + "//clang:testing", + "//clang:tooling", + "//llvm:gtest", + ], +) + +cc_test( + name = "ast_matchers_tests", + size = "medium", + srcs = glob(["ASTMatchers/*.cpp"]), + shard_count = 20, + deps = [ + ":ast_matchers_tests_hdrs", + "//clang:ast", + "//clang:ast_matchers", + "//clang:frontend", + "//clang:tooling", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "ast_matchers_dynamic_tests", + size = "small", + srcs = glob(["ASTMatchers/Dynamic/*.cpp"]), + deps = [ + ":ast_matchers_tests_hdrs", + "//clang:ast_matchers", + "//clang:ast_matchers_dynamic", + "//clang:frontend", + "//clang:tooling", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "analysis_tests", + size = "small", + srcs = glob([ + "Analysis/*.cpp", + "Analysis/*.h", + ]), + deps = [ + "//clang:analysis", + "//clang:ast", + "//clang:ast_matchers", + "//clang:tooling", + "//llvm:Support", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "basic_tests", + size = "small", + srcs = glob(["Basic/*.cpp"]), + deps = [ + "//clang:basic", + "//clang:frontend", + "//clang:lex", + "//llvm:Support", + "//llvm:config", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "codegen_tests", + size = "small", + srcs = glob([ + "CodeGen/*.cpp", + "CodeGen/*.h", + ]), + deps = [ + "//clang:ast", + "//clang:basic", + "//clang:codegen", + "//clang:frontend", + "//clang:lex", + "//clang:parse", + "//clang:sema", + "//llvm:Core", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "format_tests", + size = "medium", + srcs = glob([ + "Format/*.cpp", + "Format/*.h", + "Tooling/*.h", + ]), + copts = ["$(STACK_FRAME_UNLIMITED)"], + shard_count = 20, + deps = [ + "//clang:basic", + "//clang:format", + "//clang:frontend", + "//clang:tooling_core", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "frontend_tests", + size = "small", + srcs = glob( + ["Frontend/*.cpp"], + ), + deps = [ + "//clang:ast", + "//clang:basic", + "//clang:codegen", + "//clang:driver_options_inc_gen", + "//clang:frontend", + "//clang:frontend_tool", + "//clang:lex", + "//clang:sema", + "//clang:serialization", + "//llvm:Support", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "lex_tests", + size = "small", + srcs = glob(["Lex/*.cpp"]), + copts = ["$(STACK_FRAME_UNLIMITED)"], + deps = [ + "//clang:ast", + "//clang:basic", + "//clang:lex", + "//clang:parse", + "//clang:sema", + "//clang:serialization", + "//llvm:Support", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +# A library to carefully expose the tooling headers using the include prefix +# expected by the `rename_tests`. +cc_library( + name = "rename_tests_tooling_hdrs", + testonly = 1, + hdrs = glob(["Tooling/*.h"]), + include_prefix = "unittests", + deps = [ + "//clang:ast", + "//clang:basic", + "//clang:frontend", + "//clang:rewrite", + "//clang:tooling", + "//clang:tooling_core", + "//llvm:Support", + "//llvm:gtest", + ], +) + +cc_test( + name = "rename_tests", + size = "small", + timeout = "moderate", + srcs = glob([ + "Rename/*.cpp", + "Rename/*.h", + ]), + shard_count = 20, + deps = [ + ":rename_tests_tooling_hdrs", + "//clang:ast_matchers", + "//clang:basic", + "//clang:format", + "//clang:frontend", + "//clang:tooling", + "//clang:tooling_refactoring", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "rewrite_tests", + size = "small", + srcs = glob(["Rewrite/*.cpp"]), + deps = [ + "//clang:rewrite", + "//clang:tooling", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "sema_tests", + size = "small", + srcs = glob(["Sema/*.cpp"]), + deps = [ + ":ast_matchers_tests_hdrs", + "//clang:ast", + "//clang:ast_matchers", + "//clang:frontend", + "//clang:lex", + "//clang:parse", + "//clang:sema", + "//clang:tooling", + "//llvm:TestingSupport", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_library( + name = "static_analyzer_test_headers", + testonly = 1, + hdrs = glob(["StaticAnalyzer/*.h"]), + deps = [ + "//clang:ast_matchers", + "//clang:crosstu", + "//clang:frontend", + "//clang:static_analyzer_core", + "//clang:static_analyzer_frontend", + "//clang:tooling", + "//llvm:gtest", + ], +) + +cc_test( + name = "static_analyzer_tests", + size = "small", + srcs = glob( + ["StaticAnalyzer/*.cpp"], + exclude = [ + # New test has unused-variable warnings. + "StaticAnalyzer/ParamRegionTest.cpp", + ], + ), + deps = [ + ":static_analyzer_test_headers", + "//clang:basic", + "//clang:frontend", + "//clang:static_analyzer_core", + "//clang:static_analyzer_frontend", + "//clang:tooling", + "//llvm:Support", + "//llvm:config", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "tooling_tests", + size = "medium", + srcs = glob([ + "Tooling/*.cpp", + "Tooling/*.h", + ]), + shard_count = 20, + deps = [ + "//clang:ast", + "//clang:ast_matchers", + "//clang:basic", + "//clang:format", + "//clang:frontend", + "//clang:lex", + "//clang:rewrite", + "//clang:tooling", + "//clang:tooling_core", + "//clang:tooling_inclusions", + "//clang:tooling_refactoring", + "//clang:transformer", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +# A library to carefully expose the tooling headers using the include prefix +# expected by the `tooling_recursive_ast_visitor_tests`. +cc_library( + name = "tooling_recursive_ast_visitor_tests_tooling_hdrs", + testonly = 1, + hdrs = glob(["Tooling/*.h"]), + strip_include_prefix = "Tooling", + deps = [ + "//clang:ast", + "//clang:basic", + "//clang:frontend", + "//clang:rewrite", + "//clang:tooling", + "//clang:tooling_core", + "//llvm:Support", + "//llvm:gtest", + ], +) + +cc_test( + name = "tooling_recursive_ast_visitor_tests", + size = "medium", + srcs = glob(["Tooling/RecursiveASTVisitorTests/*.cpp"]) + [ + "Tooling/RecursiveASTVisitorTests/CallbacksCommon.h", + ], + deps = [ + ":tooling_recursive_ast_visitor_tests_tooling_hdrs", + "//clang:ast", + "//clang:basic", + "//clang:frontend", + "//clang:lex", + "//clang:tooling", + "//clang:tooling_syntax", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "tooling_syntax_tests", + size = "medium", + srcs = glob([ + "Tooling/Syntax/*.cpp", + "Tooling/Syntax/*.h", + ]), + shard_count = 20, + deps = [ + "//clang:ast", + "//clang:basic", + "//clang:frontend", + "//clang:lex", + "//clang:testing", + "//clang:tooling", + "//clang:tooling_core", + "//clang:tooling_syntax", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gmock", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "libclang_tests", + size = "small", + srcs = glob(["libclang/*.cpp"]) + [ + "libclang/TestUtils.h", + ], + deps = [ + "//clang:c-bindings", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD b/utils/bazel/llvm-project-overlay/llvm/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/BUILD @@ -0,0 +1,3913 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +load(":template_rule.bzl", "template_rule") +load(":tblgen.bzl", "gentbl") +load(":config.bzl", "llvm_config_defines") +load(":binary_alias.bzl", "binary_alias") + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +exports_files(["LICENSE.TXT"]) + +# It may be tempting to add compiler flags here, but that should be avoided. +# The necessary warnings and other compile flags should be provided by the +# toolchain or the `.bazelrc` file. This is just a workaround until we have a +# widely available feature to enable unlimited stack frame instead of using +# this `Make` variable. +llvm_copts = [ + "$(STACK_FRAME_UNLIMITED)", +] + +llvm_targets = [ + "AArch64", + "AMDGPU", + "ARM", + "BPF", + "Hexagon", + "Lanai", + "NVPTX", + "PowerPC", + "RISCV", + "Sparc", + "WebAssembly", + "X86", +] + +template_rule( + name = "targets_def_gen", + src = "include/llvm/Config/Targets.def.in", + out = "include/llvm/Config/Targets.def", + substitutions = { + "@LLVM_ENUM_TARGETS@": "\n".join(["LLVM_TARGET({})".format(t) for t in llvm_targets]), + }, +) + +template_rule( + name = "asm_printers_def_gen", + src = "include/llvm/Config/AsmPrinters.def.in", + out = "include/llvm/Config/AsmPrinters.def", + substitutions = { + "@LLVM_ENUM_ASM_PRINTERS@": "\n".join(["LLVM_ASM_PRINTER({})".format(t) for t in llvm_targets]), + }, +) + +llvm_target_asm_parsers = [ + "AArch64", + "AMDGPU", + "ARM", + "BPF", + "Hexagon", + "Lanai", + "PowerPC", + "RISCV", + "Sparc", + "WebAssembly", + "X86", +] + +template_rule( + name = "asm_parsers_def_gen", + src = "include/llvm/Config/AsmParsers.def.in", + out = "include/llvm/Config/AsmParsers.def", + substitutions = { + "@LLVM_ENUM_ASM_PARSERS@": "\n".join(["LLVM_ASM_PARSER({})".format(t) for t in llvm_target_asm_parsers]), + }, +) + +llvm_target_disassemblers = [ + "AArch64", + "AMDGPU", + "ARM", + "BPF", + "Hexagon", + "Lanai", + "PowerPC", + "RISCV", + "Sparc", + "WebAssembly", + "X86", +] + +template_rule( + name = "disassemblers_def_gen", + src = "include/llvm/Config/Disassemblers.def.in", + out = "include/llvm/Config/Disassemblers.def", + substitutions = { + "@LLVM_ENUM_DISASSEMBLERS@": "\n".join(["LLVM_DISASSEMBLER({})".format(t) for t in llvm_target_disassemblers]), + }, +) + +# TODO: Need to replace this with something that actually extracts the git +# commit from the LLVM source (submodule or http_archive). +genrule( + name = "version_info_gen", + outs = ["include/llvm/Config/VersionInfo.h"], + cmd = "echo \"#define LLVM_VERSION_INFO \\\"git\\\"\" > $@", +) + +template_rule( + name = "abi_breaking_h_gen", + src = "include/llvm/Config/abi-breaking.h.cmake", + out = "include/llvm/Config/abi-breaking.h", + substitutions = { + # Define to enable checks that alter the LLVM C++ ABI + "#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS": "#define LLVM_ENABLE_ABI_BREAKING_CHECKS 0", + + # Define to enable reverse iteration of unordered llvm containers + "#cmakedefine01 LLVM_ENABLE_REVERSE_ITERATION": "#define LLVM_ENABLE_REVERSE_ITERATION 0", + }, +) + +# To enable diff testing out of tree +exports_files([ + "include/llvm/Config/config.h.cmake", + "include/llvm/Config/llvm-config.h.cmake", + "include/llvm/Config/abi-breaking.h.cmake", +]) + +cc_library( + name = "config", + hdrs = [ + "include/llvm/Config/VersionInfo.h", + "include/llvm/Config/abi-breaking.h", + "include/llvm/Config/llvm-config.h", + ], + copts = llvm_copts, + defines = llvm_config_defines, + includes = ["include"], + textual_hdrs = [ + "include/llvm/Config/AsmParsers.def", + "include/llvm/Config/AsmPrinters.def", + "include/llvm/Config/Disassemblers.def", + "include/llvm/Config/Targets.def", + # Needed for include scanner to find execinfo.h + "include/llvm/Config/config.h", + ], +) + +cc_library( + name = "Demangle", + srcs = glob([ + "lib/Demangle/*.cpp", + "lib/Demangle/*.h", + ]), + hdrs = glob(["include/llvm/Demangle/*.h"]), + copts = llvm_copts, + deps = [":config"], +) + +genrule( + name = "generate_vcs_revision", + outs = ["include/llvm/Support/VCSRevision.h"], + cmd = "echo '#define LLVM_REVISION \"git\"' >> $@\n" + + "echo '#undef LLVM_REPOSITORY' >> $@\n", +) + +genrule( + name = "generate_static_extension_registry", + outs = ["include/llvm/Support/Extension.def"], + cmd = "echo -e '// extension handlers' >> $@\n" + + "echo -e '#undef HANDLE_EXTENSION' >> $@\n", +) + +cc_library( + name = "Support", + srcs = glob([ + "lib/Support/*.c", + "lib/Support/*.cpp", + "lib/Support/*.h", + "lib/Support/*.inc", + ]) + select({ + "@bazel_tools//src/conditions:windows": glob([ + "lib/Support/Windows/*.h", + "lib/Support/Windows/*.inc", + ]), + "//conditions:default": glob([ + "lib/Support/Unix/*.h", + "lib/Support/Unix/*.inc", + ]), + }), + hdrs = glob([ + "include/llvm/Support/**/*.h", + "include/llvm/ADT/*.h", + ]) + [ + "include/llvm/Support/VCSRevision.h", + "include/llvm/Support/Extension.def", + "include/llvm-c/Core.h", + "include/llvm-c/DataTypes.h", + "include/llvm-c/DisassemblerTypes.h", + "include/llvm-c/Error.h", + "include/llvm-c/ExternC.h", + "include/llvm-c/ErrorHandling.h", + "include/llvm-c/Support.h", + "include/llvm-c/Types.h", + ], + copts = llvm_copts, + includes = ["include"], + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "//conditions:default": [ + "-pthread", + "-ldl", + ], + }), + textual_hdrs = glob([ + "include/llvm/Support/*.def", + ]), + deps = [ + ":config", + ":Demangle", + # We unconditionally depend on the custom LLVM terminfo wrapper. This + # will be an empty library unless terminfo is enabled, in which case it + # will both provide the necessary dependencies and configuration + # defines. + "@llvm_terminfo//:terminfo", + # We unconditionally depend on the custom LLVM zlib wrapper. This will + # be an empty library unless zlib is enabled, in which case it will + # both provide the necessary dependencies and configuration defines. + "@llvm_zlib//:zlib", + ], +) + +cc_library( + name = "FileCheckLib", + srcs = glob([ + "lib/FileCheck/*.cpp", + "lib/FileCheck/*.h", + ]), + hdrs = glob(["include/llvm/FileCheck/*.h"]), + copts = llvm_copts, + deps = [":Support"], +) + +cc_library( + name = "LineEditor", + srcs = glob([ + "lib/LineEditor/*.cpp", + "lib/LineEditor/*.h", + ]), + hdrs = glob(["include/llvm/LineEditor/*.h"]), + copts = llvm_copts, + deps = [ + ":Support", + ":config", + ], +) + +cc_library( + name = "Option", + srcs = glob([ + "lib/Option/*.cpp", + "lib/Option/*.h", + ]), + hdrs = glob(["include/llvm/Option/*.h"]), + copts = llvm_copts, + deps = [ + ":Support", + ":config", + ], +) + +cc_library( + name = "TableGen", + srcs = glob([ + "lib/TableGen/*.cpp", + "lib/TableGen/*.h", + ]), + hdrs = glob(["include/llvm/TableGen/*.h"]), + copts = llvm_copts, + deps = [ + ":Support", + ":config", + ], +) + +# This exists to avoid circular dependencies. +cc_library( + name = "ir_headers", + hdrs = glob( + [ + "include/llvm/*.h", + "include/llvm/IR/*.h", + ], + exclude = [ + "include/llvm/LinkAllPasses.h", + ], + ) + [ + "include/llvm/IR/Value.def", + "include/llvm-c/Comdat.h", + "include/llvm-c/DebugInfo.h", + ], + copts = llvm_copts, +) + +cc_library( + name = "BinaryFormat", + srcs = glob([ + "lib/BinaryFormat/*.cpp", + "lib/BinaryFormat/*.def", + "lib/BinaryFormat/*.h", + ]), + hdrs = glob([ + "include/llvm/BinaryFormat/*.h", + ]), + copts = llvm_copts, + includes = ["include"], + textual_hdrs = glob([ + "include/llvm/BinaryFormat/*.def", + "include/llvm/BinaryFormat/ELFRelocs/*.def", + ]), + deps = [ + ":Support", + ], +) + +cc_library( + name = "DebugInfo", + hdrs = glob(["include/llvm/DebugInfo/*.h"]), + copts = llvm_copts, + deps = [ + ":Object", + ":Support", + ], +) + +cc_library( + name = "DebugInfoMSF", + srcs = glob([ + "lib/DebugInfo/MSF/*.cpp", + "lib/DebugInfo/MSF/*.h", + ]), + hdrs = glob(["include/llvm/DebugInfo/MSF/*.h"]), + copts = llvm_copts, + deps = [":Support"], +) + +cc_library( + name = "DebugInfoCodeView", + srcs = glob([ + "lib/DebugInfo/CodeView/*.cpp", + "lib/DebugInfo/CodeView/*.h", + ]), + hdrs = glob([ + "include/llvm/DebugInfo/CodeView/*.h", + ]), + copts = llvm_copts, + textual_hdrs = glob([ + "include/llvm/DebugInfo/CodeView/*.def", + ]), + deps = [ + ":BinaryFormat", + ":DebugInfoMSF", + ":Support", + ], +) + +cc_library( + name = "DebugInfoPDB", + srcs = glob([ + "lib/DebugInfo/PDB/*.cpp", + "lib/DebugInfo/PDB/*.h", + "lib/DebugInfo/PDB/Native/*.cpp", + "lib/DebugInfo/PDB/Native/*.h", + ]), + hdrs = glob([ + "include/llvm/DebugInfo/PDB/*.h", + "include/llvm/DebugInfo/PDB/Native/*.h", + ]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":DebugInfo", + ":DebugInfoCodeView", + ":DebugInfoMSF", + ":Object", + ":Support", + ":config", + ], +) + +cc_library( + name = "MC", + srcs = glob([ + "lib/MC/*.cpp", + "lib/MC/*.h", + ]), + hdrs = glob([ + "include/llvm/MC/*.h", + "include/llvm/MC/*.def", + "include/llvm/MC/*.inc", + ]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":DebugInfoCodeView", + ":Support", + ":config", + ":ir_headers", + ], +) + +cc_library( + name = "DebugInfoDWARF", + srcs = glob([ + "lib/DebugInfo/DWARF/*.cpp", + "lib/DebugInfo/DWARF/*.h", + ]), + hdrs = glob(["include/llvm/DebugInfo/DWARF/*.h"]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":DebugInfo", + ":MC", + ":Object", + ":Support", + ], +) + +cc_library( + name = "Symbolize", + srcs = glob([ + "lib/DebugInfo/Symbolize/*.cpp", + "lib/DebugInfo/Symbolize/*.h", + ]), + hdrs = glob(["include/llvm/DebugInfo/Symbolize/*.h"]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":DebugInfo", + ":DebugInfoDWARF", + ":DebugInfoPDB", + ":Demangle", + ":Object", + ":Support", + ], +) + +cc_library( + name = "tblgen", + srcs = glob([ + "utils/TableGen/*.cpp", + "utils/TableGen/GlobalISel/*.cpp", + + # We have to include these headers here as well as in the `hdrs` below + # to allow the `.cpp` files to use file-relative-inclusion to find + # them, even though consumers of this library use inclusion relative to + # `utils/TableGen` with the `strip_includes_prefix` of this library. + # This mixture appears to be incompatible with header modules. + "utils/TableGen/*.h", + "utils/TableGen/GlobalISel/*.h", + ]), + hdrs = glob([ + "utils/TableGen/*.h", + "utils/TableGen/GlobalISel/*.h", + ]), + copts = llvm_copts, + features = ["-header_modules"], + strip_include_prefix = "utils/TableGen", + deps = [ + ":MC", + ":Support", + ":TableGen", + ":config", + ], +) + +cc_binary( + name = "llvm-tblgen", + copts = llvm_copts, + stamp = 0, + deps = [ + ":tblgen", + ], +) + +gentbl( + name = "intrinsic_enums_gen", + tbl_outs = [("-gen-intrinsic-enums", "include/llvm/IR/IntrinsicEnums.inc")], + tblgen = ":llvm-tblgen", + td_file = "include/llvm/IR/Intrinsics.td", + td_srcs = glob([ + "include/llvm/CodeGen/*.td", + "include/llvm/IR/Intrinsics*.td", + ]), +) + +gentbl( + name = "intrinsics_impl_gen", + tbl_outs = [("-gen-intrinsic-impl", "include/llvm/IR/IntrinsicImpl.inc")], + tblgen = ":llvm-tblgen", + td_file = "include/llvm/IR/Intrinsics.td", + td_srcs = glob([ + "include/llvm/CodeGen/*.td", + "include/llvm/IR/Intrinsics*.td", + ]), +) + +llvm_target_intrinsics_list = [ + { + "name": "AArch64", + "intrinsic_prefix": "aarch64", + }, + { + "name": "AMDGPU", + "intrinsic_prefix": "amdgcn", + }, + { + "name": "ARM", + "intrinsic_prefix": "arm", + }, + { + "name": "BPF", + "intrinsic_prefix": "bpf", + }, + { + "name": "Hexagon", + "intrinsic_prefix": "hexagon", + }, + { + "name": "Mips", + "intrinsic_prefix": "mips", + }, + { + "name": "NVPTX", + "intrinsic_prefix": "nvvm", + }, + { + "name": "PowerPC", + "intrinsic_prefix": "ppc", + }, + { + "name": "R600", + "intrinsic_prefix": "r600", + }, + { + "name": "VE", + "intrinsic_prefix": "ve", + }, + { + "name": "RISCV", + "intrinsic_prefix": "riscv", + }, + { + "name": "S390", + "intrinsic_prefix": "s390", + }, + { + "name": "WebAssembly", + "intrinsic_prefix": "wasm", + }, + { + "name": "X86", + "intrinsic_prefix": "x86", + }, + { + "name": "XCore", + "intrinsic_prefix": "xcore", + }, +] + +[[ + gentbl( + name = "intrinsic_" + target["name"] + "_gen", + tbl_outs = [( + "-gen-intrinsic-enums -intrinsic-prefix=" + target["intrinsic_prefix"], + "include/llvm/IR/Intrinsics" + target["name"] + ".h", + )], + tblgen = ":llvm-tblgen", + td_file = "include/llvm/IR/Intrinsics.td", + td_srcs = glob([ + "include/llvm/CodeGen/*.td", + "include/llvm/IR/*.td", + ]), + ), +] for target in llvm_target_intrinsics_list] + +gentbl( + name = "attributes_gen", + tbl_outs = [("-gen-attrs", "include/llvm/IR/Attributes.inc")], + tblgen = ":llvm-tblgen", + td_file = "include/llvm/IR/Attributes.td", + td_srcs = ["include/llvm/IR/Attributes.td"], +) + +cc_library( + name = "BitstreamReader", + srcs = glob([ + "lib/Bitstream/Reader/*.cpp", + "lib/Bitstream/Reader/*.h", + ]), + hdrs = [ + "include/llvm/Bitstream/BitCodes.h", + "include/llvm/Bitstream/BitstreamReader.h", + ], + copts = llvm_copts, + deps = [ + ":Support", + ], +) + +cc_library( + name = "BitstreamWriter", + srcs = glob([ + "lib/Bitstream/Writer/*.h", + ]), + hdrs = [ + "include/llvm/Bitstream/BitCodes.h", + "include/llvm/Bitstream/BitstreamWriter.h", + ], + copts = llvm_copts, + deps = [ + ":Support", + ], +) + +cc_library( + name = "Remarks", + srcs = glob( + [ + "lib/Remarks/*.cpp", + "lib/Remarks/*.h", + ], + exclude = ["lib/Remarks/RemarkLinker.cpp"], + ), + hdrs = glob( + [ + "include/llvm/Remarks/*.h", + ], + exclude = ["include/llvm/Remarks/RemarkLinker.h"], + ) + [ + "include/llvm-c/Remarks.h", + ], + copts = llvm_copts, + deps = [ + ":BitstreamReader", + ":BitstreamWriter", + ":Support", + ], +) + +cc_library( + name = "remark_linker", + srcs = ["lib/Remarks/RemarkLinker.cpp"], + hdrs = ["include/llvm/Remarks/RemarkLinker.h"], + copts = llvm_copts, + deps = [ + ":Object", + ":Support", + ], +) + +filegroup( + name = "llvm_intrinsics_headers", + srcs = [ + "include/llvm/IR/Intrinsics" + target["name"] + ".h" + for target in llvm_target_intrinsics_list + ], +) + +cc_library( + name = "Core", + srcs = glob([ + "lib/IR/*.cpp", + "lib/IR/*.h", + ]), + hdrs = glob( + [ + "include/llvm/*.h", + "include/llvm/IR/*.h", + ], + exclude = [ + "include/llvm/LinkAllPasses.h", + ], + ) + [ + "include/llvm-c/Comdat.h", + "include/llvm-c/DebugInfo.h", + ] + [":llvm_intrinsics_headers"], + copts = llvm_copts, + textual_hdrs = glob(["include/llvm/IR/*.def"]), + deps = [ + ":BinaryFormat", + ":Remarks", + ":Support", + ":attributes_gen", + ":config", + ":intrinsic_enums_gen", + ":intrinsics_impl_gen", + ], +) + +cc_library( + name = "BitReader", + srcs = glob([ + "lib/Bitcode/Reader/*.cpp", + "lib/Bitcode/Reader/*.h", + ]), + hdrs = [ + "include/llvm-c/BitReader.h", + "include/llvm/Bitcode/BitcodeAnalyzer.h", + "include/llvm/Bitcode/BitcodeCommon.h", + "include/llvm/Bitcode/BitcodeReader.h", + "include/llvm/Bitcode/LLVMBitCodes.h", + ], + copts = llvm_copts, + deps = [ + ":BitstreamReader", + ":Core", + ":Support", + ":config", + ], +) + +cc_library( + name = "MCParser", + srcs = glob([ + "lib/MC/MCParser/*.cpp", + "lib/MC/MCParser/*.h", + ]), + hdrs = glob(["include/llvm/MC/MCParser/*.h"]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":MC", + ":Support", + ":config", + ], +) + +cc_library( + name = "TextAPI", + srcs = glob([ + "lib/TextAPI/**/*.cpp", + ]), + hdrs = glob([ + "include/llvm/TextAPI/**/*.h", + "include/llvm/TextAPI/**/*.def", + "lib/TextAPI/MachO/*.h", + ]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":Support", + ], +) + +cc_library( + name = "Object", + srcs = glob([ + "lib/Object/*.cpp", + "lib/Object/*.h", + ]), + hdrs = glob([ + "include/llvm/Object/*.h", + ]) + [ + "include/llvm-c/Object.h", + ], + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":BitReader", + ":Core", + ":MC", + ":MCParser", + ":Support", + ":TextAPI", + ":config", + ], +) + +cc_library( + name = "ObjectYAML", + srcs = glob([ + "lib/ObjectYAML/*.cpp", + "lib/ObjectYAML/*.h", + ]), + hdrs = glob(["include/llvm/ObjectYAML/*.h"]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":DebugInfoCodeView", + ":Object", + ":Support", + ], +) + +cc_library( + name = "ProfileData", + srcs = glob([ + "lib/ProfileData/*.cpp", + "lib/ProfileData/*.h", + ]), + hdrs = glob([ + "include/llvm/ProfileData/*.h", + "include/llvm/ProfileData/*.inc", + ]), + copts = llvm_copts, + deps = [ + ":Core", + ":Support", + ":config", + ], +) + +cc_library( + name = "Coverage", + srcs = glob([ + "lib/ProfileData/Coverage/*.cpp", + "lib/ProfileData/Coverage/*.h", + ]), + hdrs = glob(["include/llvm/ProfileData/Coverage/*.h"]), + copts = llvm_copts, + deps = [ + ":Object", + ":ProfileData", + ":Support", + ], +) + +cc_library( + name = "Analysis", + srcs = glob( + [ + "lib/Analysis/*.cpp", + "lib/Analysis/*.h", + "lib/Analysis/*.def", + ], + exclude = [ + # TODO: Add these files to the build. + "lib/Analysis/MLInlineAdvisor.cpp", + "lib/Analysis/DevelopmentModeInlineAdvisor.cpp", + "lib/Analysis/ReleaseModeModelRunner.cpp", + "lib/Analysis/TFUtils.cpp", + ], + ), + hdrs = glob( + [ + "include/llvm/Analysis/*.h", + "include/llvm/Analysis/Utils/*.h", + ], + exclude = [ + # TODO: Add this file to the build. + "include/llvm/Analysis/Utils/TFUtils.h", + ], + ) + [ + "include/llvm-c/Analysis.h", + "include/llvm-c/Initialization.h", + ], + copts = llvm_copts, + textual_hdrs = glob([ + "include/llvm/Analysis/*.def", + ]), + deps = [ + ":BinaryFormat", + ":Core", + ":Object", + ":ProfileData", + ":Support", + ":config", + ], +) + +cc_library( + name = "BitWriter", + srcs = glob([ + "lib/Bitcode/Writer/*.cpp", + "lib/Bitcode/Writer/*.h", + ]), + hdrs = [ + "include/llvm-c/BitWriter.h", + "include/llvm/Bitcode/BitcodeCommon.h", + "include/llvm/Bitcode/BitcodeWriter.h", + "include/llvm/Bitcode/BitcodeWriterPass.h", + "include/llvm/Bitcode/LLVMBitCodes.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":BitstreamWriter", + ":Core", + ":MC", + ":Object", + ":Support", + ":config", + ], +) + +cc_library( + name = "Target", + srcs = glob([ + "lib/Target/*.cpp", + "lib/Target/*.h", + ]), + hdrs = glob([ + "include/llvm/Target/*.h", + ]) + [ + "include/llvm-c/Target.h", + "include/llvm-c/TargetMachine.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":BinaryFormat", + ":Core", + ":MC", + ":Support", + ":config", + ], +) + +cc_library( + name = "TransformUtils", + srcs = glob([ + "lib/Transforms/Utils/*.cpp", + "lib/Transforms/Utils/*.h", + ]), + hdrs = glob(["include/llvm/Transforms/Utils/*.h"]) + [ + "include/llvm/Transforms/Utils.h", + "include/llvm-c/Transforms/Utils.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":BinaryFormat", + ":BitWriter", + ":Core", + ":Support", + ":Target", + ":config", + ], +) + +gentbl( + name = "InstCombineTableGen", + strip_include_prefix = "lib/Target/AMDGPU", + tbl_outs = [( + "-gen-searchable-tables", + "lib/Target/AMDGPU/InstCombineTables.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "lib/Target/AMDGPU/InstCombineTables.td", + td_srcs = glob([ + "include/llvm/CodeGen/*.td", + "include/llvm/IR/Intrinsics*.td", + ]) + [ + "include/llvm/TableGen/SearchableTable.td", + ], +) + +cc_library( + name = "InstCombine", + srcs = glob([ + "lib/Transforms/InstCombine/*.cpp", + "lib/Transforms/InstCombine/*.h", + ]), + hdrs = glob(["include/llvm/Transforms/InstCombine/*.h"]) + [ + "include/llvm-c/Transforms/InstCombine.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":Core", + ":InstCombineTableGen", + ":Support", + ":Target", + ":TransformUtils", + ":config", + ], +) + +cc_library( + name = "AggressiveInstCombine", + srcs = glob([ + "lib/Transforms/AggressiveInstCombine/*.cpp", + "lib/Transforms/AggressiveInstCombine/*.h", + ]), + hdrs = [ + "include/llvm-c/Transforms/AggressiveInstCombine.h", + "include/llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":Core", + ":Support", + ":TransformUtils", + ], +) + +cc_library( + name = "Instrumentation", + srcs = glob([ + "lib/Transforms/Instrumentation/*.cpp", + "lib/Transforms/Instrumentation/*.h", + "lib/Transforms/Instrumentation/*.inc", + ]), + hdrs = glob(["include/llvm/Transforms/Instrumentation/*.h"]) + [ + "include/llvm/Transforms/Instrumentation.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":BinaryFormat", + ":Core", + ":MC", + ":ProfileData", + ":Support", + ":TransformUtils", + ":config", + ], +) + +cc_library( + name = "ObjCARC", + srcs = glob([ + "lib/Transforms/ObjCARC/*.cpp", + "lib/Transforms/ObjCARC/*.h", + ]), + hdrs = ["include/llvm/Transforms/ObjCARC.h"], + copts = llvm_copts, + deps = [ + ":Analysis", + ":Core", + ":Support", + ":Target", + ":TransformUtils", + ":config", + ], +) + +cc_library( + name = "Scalar", + srcs = glob([ + "lib/Transforms/Scalar/*.cpp", + "lib/Transforms/Scalar/*.h", + ]), + hdrs = glob(["include/llvm/Transforms/Scalar/*.h"]) + [ + "include/llvm-c/Transforms/Scalar.h", + "include/llvm/Transforms/Scalar.h", + ], + copts = llvm_copts, + deps = [ + ":AggressiveInstCombine", + ":Analysis", + ":Core", + ":InstCombine", + ":ProfileData", + ":Support", + ":Target", + ":TransformUtils", + ":config", + ], +) + +cc_library( + name = "Vectorize", + srcs = glob([ + "lib/Transforms/Vectorize/*.cpp", + "lib/Transforms/Vectorize/*.h", + ]), + hdrs = glob([ + "include/llvm/Transforms/Vectorize/*.h", + ]) + [ + "include/llvm-c/Transforms/Vectorize.h", + "include/llvm/Transforms/Vectorize.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":Core", + ":Support", + ":Target", + ":TransformUtils", + ":config", + ], +) + +filegroup( + name = "omp_td_files", + srcs = glob([ + "include/llvm/Frontend/OpenMP/*.td", + "include/llvm/Frontend/Directive/*.td", + ]), +) + +gentbl( + name = "omp_gen", + library = False, + tbl_outs = [ + ("--gen-directive-decl", "include/llvm/Frontend/OpenMP/OMP.h.inc"), + ], + tblgen = ":llvm-tblgen", + td_file = "include/llvm/Frontend/OpenMP/OMP.td", + td_srcs = [":omp_td_files"], +) + +gentbl( + name = "omp_gen_impl", + library = False, + tbl_outs = [ + ("--gen-directive-gen", "include/llvm/Frontend/OpenMP/OMP.cpp.inc"), + ("--gen-directive-impl", "lib/Frontend/OpenMP/OMP.cpp"), + ], + tblgen = ":llvm-tblgen", + td_file = "include/llvm/Frontend/OpenMP/OMP.td", + td_srcs = [":omp_td_files"], +) + +cc_library( + name = "FrontendOpenMP", + srcs = glob([ + "lib/Frontend/OpenMP/*.cpp", + ]) + [ + "include/llvm/Frontend/OpenMP/OMP.cpp.inc", + "lib/Frontend/OpenMP/OMP.cpp", + ], + hdrs = glob([ + "include/llvm/Frontend/OpenMP/*.h", + "include/llvm/Frontend/OpenMP/OMP/*.h", + "include/llvm/Frontend/*.h", + ]) + ["include/llvm/Frontend/OpenMP/OMP.h.inc"], + copts = llvm_copts, + textual_hdrs = glob([ + "include/llvm/Frontend/OpenMP/*.def", + ]), + deps = [ + ":Analysis", + ":Core", + ":Support", + ":TransformUtils", + ], +) + +cc_library( + name = "AsmParser", + srcs = glob([ + "lib/AsmParser/*.cpp", + "lib/AsmParser/*.h", + ]), + hdrs = [ + "include/llvm/AsmParser/Parser.h", + "include/llvm/AsmParser/SlotMapping.h", + ], + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":Core", + ":Support", + ], +) + +cc_library( + name = "IRReader", + srcs = glob([ + "lib/IRReader/*.cpp", + "lib/IRReader/*.h", + ]), + hdrs = glob([ + "include/llvm/IRReader/*.h", + ]) + [ + "include/llvm-c/IRReader.h", + ], + copts = llvm_copts, + deps = [ + ":AsmParser", + ":BitReader", + ":Core", + ":Support", + ":config", + ], +) + +cc_library( + name = "Linker", + srcs = glob([ + "lib/Linker/*.cpp", + "lib/Linker/*.h", + ]), + hdrs = glob([ + "include/llvm/Linker/*.h", + ]) + [ + "include/llvm-c/Linker.h", + ], + copts = llvm_copts, + deps = [ + ":Core", + ":Support", + ":TransformUtils", + ":config", + ], +) + +cc_library( + name = "IPO", + srcs = glob([ + "lib/Transforms/IPO/*.cpp", + "lib/Transforms/IPO/*.h", + ]), + hdrs = glob([ + "include/llvm/Transforms/IPO/*.h", + ]) + [ + "include/llvm-c/Transforms/IPO.h", + "include/llvm-c/Transforms/PassManagerBuilder.h", + "include/llvm/Transforms/IPO.h", + ], + copts = llvm_copts, + deps = [ + ":AggressiveInstCombine", + ":Analysis", + ":BinaryFormat", + ":BitReader", + ":BitWriter", + ":Core", + ":FrontendOpenMP", + ":IRReader", + ":InstCombine", + ":Instrumentation", + ":Linker", + ":ObjCARC", + ":Object", + ":ProfileData", + ":Scalar", + ":Support", + ":Target", + ":TransformUtils", + ":Vectorize", + ":config", + ], +) + +cc_library( + name = "CFGuard", + srcs = glob([ + "lib/Transforms/CFGuard/*.cpp", + "lib/Transforms/CFGuard/*.h", + ]), + hdrs = ["include/llvm/Transforms/CFGuard.h"], + copts = llvm_copts, + deps = [ + ":Core", + ":Support", + ], +) + +cc_library( + name = "Coroutines", + srcs = glob([ + "lib/Transforms/Coroutines/*.cpp", + "lib/Transforms/Coroutines/*.h", + ]), + hdrs = [ + "include/llvm-c/Transforms/Coroutines.h", + "include/llvm/Transforms/Coroutines.h", + "include/llvm/Transforms/Coroutines/CoroCleanup.h", + "include/llvm/Transforms/Coroutines/CoroEarly.h", + "include/llvm/Transforms/Coroutines/CoroElide.h", + "include/llvm/Transforms/Coroutines/CoroSplit.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":Core", + ":IPO", + ":Scalar", + ":Support", + ":TransformUtils", + ":config", + ], +) + +cc_library( + name = "HelloNew", + srcs = glob([ + "lib/Transforms/HelloNew/*.cpp", + "lib/Transforms/HelloNew/*.h", + ]), + hdrs = ["include/llvm/Transforms/HelloNew/HelloWorld.h"], + copts = llvm_copts, + includes = ["include"], + deps = [ + ":Core", + ":Support", + ], +) + +# Meta-target for clients which depend on all of the transforms libraries. +cc_library( + name = "common_transforms", + deps = [ + ":AggressiveInstCombine", + ":CFGuard", + ":Coroutines", + ":IPO", + ":InstCombine", + ":Instrumentation", + ":ObjCARC", + ":Scalar", + ":Vectorize", + ], +) + +cc_library( + name = "asm_printer_defs", + copts = llvm_copts, + textual_hdrs = glob(["lib/CodeGen/AsmPrinter/*.def"]), +) + +cc_library( + name = "CodeGen", + srcs = glob( + [ + "lib/CodeGen/**/*.cpp", + "lib/CodeGen/**/*.h", + "lib/CodeGen/SelectionDAG/*.cpp", + "lib/CodeGen/SelectionDAG/*.h", + ], + ), + hdrs = [ + "include/llvm/LinkAllPasses.h", + ] + glob( + [ + "include/llvm/CodeGen/**/*.h", + ], + ), + copts = llvm_copts, + textual_hdrs = glob([ + "include/llvm/CodeGen/**/*.def", + "include/llvm/CodeGen/**/*.inc", + ]), + deps = [ + ":Analysis", + ":AsmParser", + ":BinaryFormat", + ":BitReader", + ":BitWriter", + ":Core", + ":DebugInfoCodeView", + ":DebugInfoDWARF", + ":IPO", + ":MC", + ":MCParser", + ":ProfileData", + ":Remarks", + ":Scalar", + ":Support", + ":Target", + ":TransformUtils", + ":asm_printer_defs", + ":config", + ], +) + +cc_library( + name = "MCDisassembler", + srcs = glob([ + "lib/MC/MCDisassembler/*.cpp", + "lib/MC/MCDisassembler/*.h", + ]), + hdrs = glob([ + "include/llvm/MC/MCDisassembler/*.h", + ]) + [ + "include/llvm-c/Disassembler.h", + ], + copts = llvm_copts, + deps = [ + ":MC", + ":Support", + ":config", + ], +) + +llvm_target_list = [ + { + "name": "AArch64", + "short_name": "AArch64", + "tbl_outs": [ + ("-gen-register-bank", "lib/Target/AArch64/AArch64GenRegisterBank.inc"), + ("-gen-register-info", "lib/Target/AArch64/AArch64GenRegisterInfo.inc"), + ("-gen-instr-info", "lib/Target/AArch64/AArch64GenInstrInfo.inc"), + ("-gen-emitter", "lib/Target/AArch64/AArch64GenMCCodeEmitter.inc"), + ("-gen-pseudo-lowering", "lib/Target/AArch64/AArch64GenMCPseudoLowering.inc"), + ("-gen-asm-writer", "lib/Target/AArch64/AArch64GenAsmWriter.inc"), + ("-gen-asm-writer -asmwriternum=1", "lib/Target/AArch64/AArch64GenAsmWriter1.inc"), + ("-gen-asm-matcher", "lib/Target/AArch64/AArch64GenAsmMatcher.inc"), + ("-gen-dag-isel", "lib/Target/AArch64/AArch64GenDAGISel.inc"), + ("-gen-fast-isel", "lib/Target/AArch64/AArch64GenFastISel.inc"), + ("-gen-global-isel", "lib/Target/AArch64/AArch64GenGlobalISel.inc"), + ("-gen-global-isel-combiner -combiners=AArch64PreLegalizerCombinerHelper", "lib/Target/AArch64/AArch64GenPreLegalizeGICombiner.inc"), + ("-gen-global-isel-combiner -combiners=AArch64PostLegalizerCombinerHelper", "lib/Target/AArch64/AArch64GenPostLegalizeGICombiner.inc"), + ("-gen-global-isel-combiner -combiners=AArch64PostLegalizerLoweringHelper", "lib/Target/AArch64/AArch64GenPostLegalizeGILowering.inc"), + ("-gen-callingconv", "lib/Target/AArch64/AArch64GenCallingConv.inc"), + ("-gen-subtarget", "lib/Target/AArch64/AArch64GenSubtargetInfo.inc"), + ("-gen-disassembler", "lib/Target/AArch64/AArch64GenDisassemblerTables.inc"), + ("-gen-searchable-tables", "lib/Target/AArch64/AArch64GenSystemOperands.inc"), + ], + }, + { + "name": "ARM", + "short_name": "ARM", + "tbl_outs": [ + ("-gen-register-bank", "lib/Target/ARM/ARMGenRegisterBank.inc"), + ("-gen-register-info", "lib/Target/ARM/ARMGenRegisterInfo.inc"), + ("-gen-searchable-tables", "lib/Target/ARM/ARMGenSystemRegister.inc"), + ("-gen-instr-info", "lib/Target/ARM/ARMGenInstrInfo.inc"), + ("-gen-emitter", "lib/Target/ARM/ARMGenMCCodeEmitter.inc"), + ("-gen-pseudo-lowering", "lib/Target/ARM/ARMGenMCPseudoLowering.inc"), + ("-gen-asm-writer", "lib/Target/ARM/ARMGenAsmWriter.inc"), + ("-gen-asm-matcher", "lib/Target/ARM/ARMGenAsmMatcher.inc"), + ("-gen-dag-isel", "lib/Target/ARM/ARMGenDAGISel.inc"), + ("-gen-fast-isel", "lib/Target/ARM/ARMGenFastISel.inc"), + ("-gen-global-isel", "lib/Target/ARM/ARMGenGlobalISel.inc"), + ("-gen-callingconv", "lib/Target/ARM/ARMGenCallingConv.inc"), + ("-gen-subtarget", "lib/Target/ARM/ARMGenSubtargetInfo.inc"), + ("-gen-disassembler", "lib/Target/ARM/ARMGenDisassemblerTables.inc"), + ], + }, + { + "name": "AMDGPU", + "short_name": "AMDGPU", + "tbl_outs": [ + ("-gen-register-bank", "lib/Target/AMDGPU/AMDGPUGenRegisterBank.inc"), + ("-gen-register-info", "lib/Target/AMDGPU/AMDGPUGenRegisterInfo.inc"), + ("-gen-instr-info", "lib/Target/AMDGPU/AMDGPUGenInstrInfo.inc"), + ("-gen-emitter", "lib/Target/AMDGPU/AMDGPUGenMCCodeEmitter.inc"), + ("-gen-pseudo-lowering", "lib/Target/AMDGPU/AMDGPUGenMCPseudoLowering.inc"), + ("-gen-asm-writer", "lib/Target/AMDGPU/AMDGPUGenAsmWriter.inc"), + ("-gen-asm-matcher", "lib/Target/AMDGPU/AMDGPUGenAsmMatcher.inc"), + ("-gen-dag-isel", "lib/Target/AMDGPU/AMDGPUGenDAGISel.inc"), + ("-gen-callingconv", "lib/Target/AMDGPU/AMDGPUGenCallingConv.inc"), + ("-gen-subtarget", "lib/Target/AMDGPU/AMDGPUGenSubtargetInfo.inc"), + ("-gen-disassembler", "lib/Target/AMDGPU/AMDGPUGenDisassemblerTables.inc"), + ("-gen-searchable-tables", "lib/Target/AMDGPU/AMDGPUGenSearchableTables.inc"), + ], + "tbl_deps": [ + ":amdgpu_isel_target_gen", + ":r600_target_gen", + ], + }, + { + "name": "BPF", + "short_name": "BPF", + "tbl_outs": [ + ("-gen-asm-writer", "lib/Target/BPF/BPFGenAsmWriter.inc"), + ("-gen-asm-matcher", "lib/Target/BPF/BPFGenAsmMatcher.inc"), + ("-gen-callingconv", "lib/Target/BPF/BPFGenCallingConv.inc"), + ("-gen-dag-isel", "lib/Target/BPF/BPFGenDAGISel.inc"), + ("-gen-disassembler", "lib/Target/BPF/BPFGenDisassemblerTables.inc"), + ("-gen-emitter", "lib/Target/BPF/BPFGenMCCodeEmitter.inc"), + ("-gen-instr-info", "lib/Target/BPF/BPFGenInstrInfo.inc"), + ("-gen-register-info", "lib/Target/BPF/BPFGenRegisterInfo.inc"), + ("-gen-subtarget", "lib/Target/BPF/BPFGenSubtargetInfo.inc"), + ], + }, + { + "name": "Hexagon", + "short_name": "Hexagon", + "tbl_outs": [ + ("-gen-asm-matcher", "lib/Target/Hexagon/HexagonGenAsmMatcher.inc"), + ("-gen-asm-writer", "lib/Target/Hexagon/HexagonGenAsmWriter.inc"), + ("-gen-callingconv", "lib/Target/Hexagon/HexagonGenCallingConv.inc"), + ("-gen-dag-isel", "lib/Target/Hexagon/HexagonGenDAGISel.inc"), + ("-gen-dfa-packetizer", "lib/Target/Hexagon/HexagonGenDFAPacketizer.inc"), + ("-gen-disassembler", "lib/Target/Hexagon/HexagonGenDisassemblerTables.inc"), + ("-gen-instr-info", "lib/Target/Hexagon/HexagonGenInstrInfo.inc"), + ("-gen-emitter", "lib/Target/Hexagon/HexagonGenMCCodeEmitter.inc"), + ("-gen-register-info", "lib/Target/Hexagon/HexagonGenRegisterInfo.inc"), + ("-gen-subtarget", "lib/Target/Hexagon/HexagonGenSubtargetInfo.inc"), + ], + }, + { + "name": "Lanai", + "short_name": "Lanai", + "tbl_outs": [ + ("-gen-asm-matcher", "lib/Target/Lanai/LanaiGenAsmMatcher.inc"), + ("-gen-asm-writer", "lib/Target/Lanai/LanaiGenAsmWriter.inc"), + ("-gen-callingconv", "lib/Target/Lanai/LanaiGenCallingConv.inc"), + ("-gen-dag-isel", "lib/Target/Lanai/LanaiGenDAGISel.inc"), + ("-gen-disassembler", "lib/Target/Lanai/LanaiGenDisassemblerTables.inc"), + ("-gen-emitter", "lib/Target/Lanai/LanaiGenMCCodeEmitter.inc"), + ("-gen-instr-info", "lib/Target/Lanai/LanaiGenInstrInfo.inc"), + ("-gen-register-info", "lib/Target/Lanai/LanaiGenRegisterInfo.inc"), + ("-gen-subtarget", "lib/Target/Lanai/LanaiGenSubtargetInfo.inc"), + ], + }, + { + "name": "NVPTX", + "short_name": "NVPTX", + "tbl_outs": [ + ("-gen-register-info", "lib/Target/NVPTX/NVPTXGenRegisterInfo.inc"), + ("-gen-instr-info", "lib/Target/NVPTX/NVPTXGenInstrInfo.inc"), + ("-gen-asm-writer", "lib/Target/NVPTX/NVPTXGenAsmWriter.inc"), + ("-gen-dag-isel", "lib/Target/NVPTX/NVPTXGenDAGISel.inc"), + ("-gen-subtarget", "lib/Target/NVPTX/NVPTXGenSubtargetInfo.inc"), + ], + }, + { + "name": "PowerPC", + "short_name": "PPC", + "tbl_outs": [ + ("-gen-asm-writer", "lib/Target/PowerPC/PPCGenAsmWriter.inc"), + ("-gen-asm-matcher", "lib/Target/PowerPC/PPCGenAsmMatcher.inc"), + ("-gen-emitter", "lib/Target/PowerPC/PPCGenMCCodeEmitter.inc"), + ("-gen-register-info", "lib/Target/PowerPC/PPCGenRegisterInfo.inc"), + ("-gen-instr-info", "lib/Target/PowerPC/PPCGenInstrInfo.inc"), + ("-gen-dag-isel", "lib/Target/PowerPC/PPCGenDAGISel.inc"), + ("-gen-fast-isel", "lib/Target/PowerPC/PPCGenFastISel.inc"), + ("-gen-callingconv", "lib/Target/PowerPC/PPCGenCallingConv.inc"), + ("-gen-subtarget", "lib/Target/PowerPC/PPCGenSubtargetInfo.inc"), + ("-gen-disassembler", "lib/Target/PowerPC/PPCGenDisassemblerTables.inc"), + ("-gen-register-bank", "lib/Target/PowerPC/PPCGenRegisterBank.inc"), + ("-gen-global-isel", "lib/Target/PowerPC/PPCGenGlobalISel.inc"), + ], + }, + { + "name": "Sparc", + "short_name": "Sparc", + "tbl_outs": [ + ("-gen-asm-writer", "lib/Target/Sparc/SparcGenAsmWriter.inc"), + ("-gen-asm-matcher", "lib/Target/Sparc/SparcGenAsmMatcher.inc"), + ("-gen-emitter", "lib/Target/Sparc/SparcGenMCCodeEmitter.inc"), + ("-gen-register-info", "lib/Target/Sparc/SparcGenRegisterInfo.inc"), + ("-gen-instr-info", "lib/Target/Sparc/SparcGenInstrInfo.inc"), + ("-gen-dag-isel", "lib/Target/Sparc/SparcGenDAGISel.inc"), + ("-gen-callingconv", "lib/Target/Sparc/SparcGenCallingConv.inc"), + ("-gen-subtarget", "lib/Target/Sparc/SparcGenSubtargetInfo.inc"), + ("-gen-disassembler", "lib/Target/Sparc/SparcGenDisassemblerTables.inc"), + ], + }, + { + "name": "RISCV", + "short_name": "RISCV", + "tbl_outs": [ + ("-gen-asm-matcher", "lib/Target/RISCV/RISCVGenAsmMatcher.inc"), + ("-gen-asm-writer", "lib/Target/RISCV/RISCVGenAsmWriter.inc"), + ("-gen-compress-inst-emitter", "lib/Target/RISCV/RISCVGenCompressInstEmitter.inc"), + ("-gen-dag-isel", "lib/Target/RISCV/RISCVGenDAGISel.inc"), + ("-gen-disassembler", "lib/Target/RISCV/RISCVGenDisassemblerTables.inc"), + ("-gen-global-isel", "lib/Target/RISCV/RISCVGenGlobalISel.inc"), + ("-gen-instr-info", "lib/Target/RISCV/RISCVGenInstrInfo.inc"), + ("-gen-emitter", "lib/Target/RISCV/RISCVGenMCCodeEmitter.inc"), + ("-gen-pseudo-lowering", "lib/Target/RISCV/RISCVGenMCPseudoLowering.inc"), + ("-gen-register-bank", "lib/Target/RISCV/RISCVGenRegisterBank.inc"), + ("-gen-register-info", "lib/Target/RISCV/RISCVGenRegisterInfo.inc"), + ("-gen-subtarget", "lib/Target/RISCV/RISCVGenSubtargetInfo.inc"), + ("-gen-searchable-tables", "lib/Target/RISCV/RISCVGenSystemOperands.inc"), + ], + }, + { + "name": "WebAssembly", + "short_name": "WebAssembly", + "tbl_outs": [ + ("-gen-disassembler", "lib/Target/WebAssembly/WebAssemblyGenDisassemblerTables.inc"), + ("-gen-asm-writer", "lib/Target/WebAssembly/WebAssemblyGenAsmWriter.inc"), + ("-gen-instr-info", "lib/Target/WebAssembly/WebAssemblyGenInstrInfo.inc"), + ("-gen-dag-isel", "lib/Target/WebAssembly/WebAssemblyGenDAGISel.inc"), + ("-gen-fast-isel", "lib/Target/WebAssembly/WebAssemblyGenFastISel.inc"), + ("-gen-emitter", "lib/Target/WebAssembly/WebAssemblyGenMCCodeEmitter.inc"), + ("-gen-register-info", "lib/Target/WebAssembly/WebAssemblyGenRegisterInfo.inc"), + ("-gen-subtarget", "lib/Target/WebAssembly/WebAssemblyGenSubtargetInfo.inc"), + ("-gen-asm-matcher", "lib/Target/WebAssembly/WebAssemblyGenAsmMatcher.inc"), + ], + }, + { + "name": "X86", + "short_name": "X86", + "tbl_outs": [ + ("-gen-register-bank", "lib/Target/X86/X86GenRegisterBank.inc"), + ("-gen-register-info", "lib/Target/X86/X86GenRegisterInfo.inc"), + ("-gen-disassembler", "lib/Target/X86/X86GenDisassemblerTables.inc"), + ("-gen-instr-info", "lib/Target/X86/X86GenInstrInfo.inc"), + ("-gen-asm-writer", "lib/Target/X86/X86GenAsmWriter.inc"), + ("-gen-asm-writer -asmwriternum=1", "lib/Target/X86/X86GenAsmWriter1.inc"), + ("-gen-asm-matcher", "lib/Target/X86/X86GenAsmMatcher.inc"), + ("-gen-dag-isel", "lib/Target/X86/X86GenDAGISel.inc"), + ("-gen-fast-isel", "lib/Target/X86/X86GenFastISel.inc"), + ("-gen-global-isel", "lib/Target/X86/X86GenGlobalISel.inc"), + ("-gen-callingconv", "lib/Target/X86/X86GenCallingConv.inc"), + ("-gen-subtarget", "lib/Target/X86/X86GenSubtargetInfo.inc"), + ("-gen-x86-EVEX2VEX-tables", "lib/Target/X86/X86GenEVEX2VEXTables.inc"), + ("-gen-exegesis", "lib/Target/X86/X86GenExegesis.inc"), + ], + }, +] + +cc_library( + name = "x86_target_layering_problem_hdrs", + textual_hdrs = ["lib/Target/X86/X86InstrInfo.h"], +) + +filegroup( + name = "common_target_td_sources", + srcs = glob([ + "include/llvm/CodeGen/*.td", + "include/llvm/Frontend/Directive/*.td", + "include/llvm/IR/Intrinsics*.td", + "include/llvm/TableGen/*.td", + "include/llvm/Target/*.td", + "include/llvm/Target/GlobalISel/*.td", + ]), +) + +gentbl( + name = "amdgpu_isel_target_gen", + strip_include_prefix = "lib/Target/AMDGPU", + tbl_outs = [ + ("-gen-global-isel", "lib/Target/AMDGPU/AMDGPUGenGlobalISel.inc"), + ("-gen-global-isel-combiner -combiners=AMDGPUPreLegalizerCombinerHelper", "lib/Target/AMDGPU/AMDGPUGenPreLegalizeGICombiner.inc"), + ("-gen-global-isel-combiner -combiners=AMDGPUPostLegalizerCombinerHelper", "lib/Target/AMDGPU/AMDGPUGenPostLegalizeGICombiner.inc"), + ("-gen-global-isel-combiner -combiners=AMDGPURegBankCombinerHelper", "lib/Target/AMDGPU/AMDGPUGenRegBankGICombiner.inc"), + ], + tblgen = ":llvm-tblgen", + td_file = "lib/Target/AMDGPU/AMDGPUGISel.td", + td_srcs = [ + ":common_target_td_sources", + ] + glob([ + "lib/Target/AMDGPU/*.td", + ]), +) + +gentbl( + name = "r600_target_gen", + strip_include_prefix = "lib/Target/AMDGPU", + tbl_outs = [ + ("-gen-asm-writer", "lib/Target/AMDGPU/R600GenAsmWriter.inc"), + ("-gen-callingconv", "lib/Target/AMDGPU/R600GenCallingConv.inc"), + ("-gen-dag-isel", "lib/Target/AMDGPU/R600GenDAGISel.inc"), + ("-gen-dfa-packetizer", "lib/Target/AMDGPU/R600GenDFAPacketizer.inc"), + ("-gen-instr-info", "lib/Target/AMDGPU/R600GenInstrInfo.inc"), + ("-gen-emitter", "lib/Target/AMDGPU/R600GenMCCodeEmitter.inc"), + ("-gen-register-info", "lib/Target/AMDGPU/R600GenRegisterInfo.inc"), + ("-gen-subtarget", "lib/Target/AMDGPU/R600GenSubtargetInfo.inc"), + ], + tblgen = ":llvm-tblgen", + td_file = "lib/Target/AMDGPU/R600.td", + td_srcs = [ + ":common_target_td_sources", + ] + glob([ + "lib/Target/AMDGPU/*.td", + ]), +) + +[[ + [gentbl( + name = target["name"] + "CommonTableGen", + strip_include_prefix = "lib/Target/" + target["name"], + tbl_outs = target["tbl_outs"], + tblgen = ":llvm-tblgen", + # MSVC isn't happy with long string literals, while other compilers + # which support them get significant compile time improvements with + # them enabled. Ideally this flag would only be enabled on Windows via + # a select() on `@bazel_tools//src/conditions:windows,`, but that would + # require refactoring gentbl from a macro into a rule. + # TODO(#92): Refactor gentbl to support this use + tblgen_args = "--long-string-literals=0", + td_file = "lib/Target/" + target["name"] + "/" + target["short_name"] + ".td", + td_srcs = [ + ":common_target_td_sources", + ] + glob([ + "lib/Target/" + target["name"] + "/*.td", + "lib/Target/" + target["name"] + "/GISel/*.td", + ]), + deps = target.get("tbl_deps", []), + )], + [cc_library( + name = target["name"] + "Info", + srcs = ["lib/Target/" + target["name"] + "/TargetInfo/" + target["name"] + "TargetInfo.cpp"], + hdrs = glob(["lib/Target/" + target["name"] + "/TargetInfo/*.h"]), + copts = llvm_copts, + strip_include_prefix = "lib/Target/" + target["name"], + deps = [ + ":" + target["name"] + "CommonTableGen", + ":Support", + ":Target", + ], + )], + # We cannot separate the `Utils` and `MCTargetDesc` sublibraries of + # a number of targets due to crisscrossing inclusion of headers. + [cc_library( + name = target["name"] + "UtilsAndDesc", + srcs = glob([ + "lib/Target/" + target["name"] + "/MCTargetDesc/*.cpp", + "lib/Target/" + target["name"] + "/Utils/*.cpp", + + # We have to include these headers here as well as in the `hdrs` + # below to allow the `.cpp` files to use file-relative-inclusion to + # find them, even though consumers of this library use inclusion + # relative to the target with the `strip_includes_prefix` of this + # library. This mixture is likely incompatible with header modules. + "lib/Target/" + target["name"] + "/MCTargetDesc/*.h", + "lib/Target/" + target["name"] + "/Utils/*.h", + ]), + hdrs = glob([ + "lib/Target/" + target["name"] + "/MCTargetDesc/*.h", + "lib/Target/" + target["name"] + "/Utils/*.h", + + # This a bit of a hack to allow us to expose common, internal + # target header files to other libraries within the target via + # target-relative includes. This usage of headers is inherently + # non-modular as there is a mixture of target-relative inclusion + # using this rule and file-relative inclusion using the repeated + # listing of these headers in the `srcs` of subsequent rules. + "lib/Target/" + target["name"] + "/*.h", + + # FIXME: The entries below should be `textual_hdrs` instead of + # `hdrs`, but unfortunately that doesn't work with + # `strip_include_prefix`: + # https://github.com/bazelbuild/bazel/issues/12424 + # + # Once that issue is fixed and released, we can switch this to + # `textual_hdrs` and remove the feature disabling the various Bazel + # features (both current and under-development) that motivated the + # distinction between these two. + "lib/Target/" + target["name"] + "/*.def", + "lib/Target/" + target["name"] + "/*.inc", + ]), + copts = llvm_copts, + features = [ + "-parse_headers", + "-header_modules", + ], + strip_include_prefix = "lib/Target/" + target["name"], + deps = [ + ":BinaryFormat", + # Depending on `:CodeGen` headers in this library is almost + # certainly a layering problem in numerous targets. + ":CodeGen", + ":DebugInfoCodeView", + ":MC", + ":MCDisassembler", + ":Support", + ":Target", + ":config", + ":" + target["name"] + "CommonTableGen", + ":" + target["name"] + "Info", + ], + )], + [cc_library( + name = target["name"] + "CodeGen", + srcs = glob([ + "lib/Target/" + target["name"] + "/GISel/*.cpp", + "lib/Target/" + target["name"] + "/GISel/*.h", + "lib/Target/" + target["name"] + "/*.cpp", + "lib/Target/" + target["name"] + "/*.h", + ]), + hdrs = ["lib/Target/" + target["name"] + "/" + target["short_name"] + ".h"], + copts = llvm_copts, + strip_include_prefix = "lib/Target/" + target["name"], + textual_hdrs = glob([ + "lib/Target/" + target["name"] + "/*.def", + "lib/Target/" + target["name"] + "/*.inc", + ]), + deps = [ + ":Analysis", + ":BinaryFormat", + ":CFGuard", + ":CodeGen", + ":Core", + ":IPO", + ":MC", + ":Passes", # TODO(chandlerc): Likely a layering violation. + ":ProfileData", + ":Scalar", + ":Support", + ":Target", + ":TransformUtils", + ":Vectorize", + ":config", + ":" + target["name"] + "CommonTableGen", + ":" + target["name"] + "Info", + ":" + target["name"] + "UtilsAndDesc", + ], + )], + [cc_library( + name = target["name"] + "AsmParser", + srcs = glob([ + "lib/Target/" + target["name"] + "/AsmParser/*.cpp", + "lib/Target/" + target["name"] + "/AsmParser/*.h", + ]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":MC", + ":MCParser", + ":Support", + ":Target", + ":" + target["name"] + "CodeGen", + ":" + target["name"] + "CommonTableGen", + ":" + target["name"] + "UtilsAndDesc", + ], + )], + # This target is a bit of a hack to allow us to expose internal + # disassembler header files via internal target-relative include paths. + # This usage of headers is inherently non-modular as there is a mixture of + # target-relative inclusion using this rule and same-directory inclusion + # using the repeated listing of these headers in the `srcs` below. + [cc_library( + name = target["name"] + "DisassemblerInternalHeaders", + # FIXME: This should be `textual_hdrs` instead of `hdrs`, but + # unfortunately that doesn't work with `strip_include_prefix`: + # https://github.com/bazelbuild/bazel/issues/12424 + # + # Once that issue is fixed and released, we can switch this to + # `textual_hdrs` and remove the feature disabling the various Bazel + # features (both current and under-development) that motivated the + # distinction between these two. + hdrs = glob([ + "lib/Target/" + target["name"] + "/Disassembler/*.h", + ]), + features = [ + "-parse_headers", + "-header_modules", + ], + strip_include_prefix = "lib/Target/" + target["name"], + )], + [cc_library( + name = target["name"] + "Disassembler", + srcs = glob([ + "lib/Target/" + target["name"] + "/Disassembler/*.cpp", + "lib/Target/" + target["name"] + "/Disassembler/*.c", + "lib/Target/" + target["name"] + "/Disassembler/*.h", + ]), + copts = llvm_copts, + deps = [ + ":CodeGen", + ":Core", + ":MC", + ":MCDisassembler", + ":Support", + ":Target", + ":" + target["name"] + "CodeGen", + ":" + target["name"] + "DisassemblerInternalHeaders", + ":" + target["name"] + "CommonTableGen", + ":" + target["name"] + "UtilsAndDesc", + ], + )], +] for target in llvm_target_list] + +cc_library( + name = "AllTargetsCodeGens", + copts = llvm_copts, + deps = [ + target["name"] + "CodeGen" + for target in llvm_target_list + ], +) + +cc_library( + name = "AllTargetsAsmParsers", + copts = llvm_copts, + deps = [ + target["name"] + "AsmParser" + for target in llvm_target_list + ], +) + +cc_library( + name = "AllTargetsDisassemblers", + copts = llvm_copts, + deps = [ + target["name"] + "Disassembler" + for target in llvm_target_list + ], +) + +cc_library( + name = "pass_registry_def", + copts = llvm_copts, + textual_hdrs = ["lib/Passes/PassRegistry.def"], +) + +cc_library( + name = "MLPolicies", + srcs = glob([ + "lib/Analysis/ML/*.cpp", + "lib/Analysis/ML/*.h", + ]), + hdrs = glob([ + "include/llvm/Analysis/ML/*.h", + ]), + copts = llvm_copts, + deps = [ + ":Analysis", + ":Core", + ":Support", + ], +) + +cc_library( + name = "Passes", + srcs = glob([ + "lib/Passes/*.cpp", + "lib/Passes/*.h", + ]), + hdrs = glob(["include/llvm/Passes/*.h"]), + copts = llvm_copts, + deps = [ + ":Analysis", + ":CodeGen", + ":Core", + ":Coroutines", + ":HelloNew", + ":MLPolicies", + ":Support", + ":Target", + ":TransformUtils", + ":common_transforms", + ":config", + ":pass_registry_def", + ], +) + +cc_library( + name = "LTO", + srcs = glob([ + "lib/LTO/*.cpp", + "lib/LTO/*.h", + ]), + hdrs = glob([ + "include/llvm/LTO/*.h", + "include/llvm/LTO/legacy/*.h", + ]) + [ + "include/llvm-c/LinkTimeOptimizer.h", + "include/llvm-c/lto.h", + ], + copts = llvm_copts, + deps = [ + ":Analysis", + ":BitReader", + ":BitWriter", + ":CodeGen", + ":Core", + ":IRReader", + ":Linker", + ":MC", + ":MCParser", + ":Object", + ":Passes", + ":Support", + ":Target", + ":TransformUtils", + ":common_transforms", + ":config", + ], +) + +cc_library( + name = "ExecutionEngine", + srcs = glob([ + "lib/ExecutionEngine/*.cpp", + "lib/ExecutionEngine/*.h", + "lib/ExecutionEngine/RuntimeDyld/*.cpp", + "lib/ExecutionEngine/RuntimeDyld/*.h", + "lib/ExecutionEngine/RuntimeDyld/Targets/*.cpp", + "lib/ExecutionEngine/RuntimeDyld/Targets/*.h", + ]), + hdrs = glob( + [ + "include/llvm/ExecutionEngine/*.h", + ], + exclude = [ + "include/llvm/ExecutionEngine/MCJIT*.h", + "include/llvm/ExecutionEngine/OProfileWrapper.h", + ], + ) + [ + "include/llvm-c/ExecutionEngine.h", + ], + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":CodeGen", + ":Core", + ":DebugInfo", + ":MC", + ":MCDisassembler", + ":Object", + ":Passes", + ":Support", + ":Target", + ":config", + ], +) + +cc_library( + name = "Interpreter", + srcs = glob([ + "lib/ExecutionEngine/Interpreter/*.cpp", + "lib/ExecutionEngine/Interpreter/*.h", + ]), + hdrs = ["include/llvm/ExecutionEngine/Interpreter.h"], + copts = llvm_copts, + deps = [ + ":CodeGen", + ":Core", + ":ExecutionEngine", + ":Support", + ":Target", + ":config", + ], +) + +cc_library( + name = "JITLink", + srcs = glob([ + "lib/ExecutionEngine/JITLink/*.cpp", + "lib/ExecutionEngine/JITLink/*.h", + ]), + hdrs = glob([ + "include/llvm/ExecutionEngine/JITLink/*.h", + ]), + copts = llvm_copts, + deps = [ + ":ExecutionEngine", + ":Object", + ":OrcTargetProcess", + ":Support", + ":config", + ], +) + +cc_library( + name = "MCJIT", + srcs = glob([ + "lib/ExecutionEngine/MCJIT/*.cpp", + "lib/ExecutionEngine/MCJIT/*.h", + ]), + hdrs = glob(["include/llvm/ExecutionEngine/MCJIT*.h"]), + copts = llvm_copts, + deps = [ + ":CodeGen", + ":Core", + ":ExecutionEngine", + ":MC", + ":Object", + ":Support", + ":Target", + ":config", + ], +) + +cc_library( + name = "OrcJIT", + srcs = glob([ + "lib/ExecutionEngine/Orc/*.cpp", + "lib/ExecutionEngine/Orc/*.h", + "lib/ExecutionEngine/Orc/RPC/*.cpp", + "lib/ExecutionEngine/OrcError/*.cpp", + ]), + hdrs = glob([ + "include/llvm/ExecutionEngine/Orc/*.h", + ]) + [ + "include/llvm-c/LLJIT.h", + "include/llvm-c/Orc.h", + "include/llvm-c/OrcEE.h", + ], + copts = llvm_copts, + deps = [ + ":BitReader", + ":BitWriter", + ":Core", + ":ExecutionEngine", + ":JITLink", + ":MC", + ":Object", + ":OrcTargetProcess", + ":Support", + ":Target", + ":TransformUtils", + ":config", + ], +) + +cc_library( + name = "OrcShared", + srcs = glob([ + "lib/ExecutionEngine/Orc/Shared/*.cpp", + ]), + hdrs = glob([ + "include/llvm/ExecutionEngine/Orc/RPC/*.h", + "include/llvm/ExecutionEngine/Orc/Shared/*.h", + "include/llvm/ExecutionEngine/Orc/*.h", + ]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":CodeGen", + ":Core", + ":DebugInfo", + ":ExecutionEngine", + ":MC", + ":MCDisassembler", + ":Object", + ":Passes", + ":Support", + ":Target", + ":config", + ], +) + +cc_library( + name = "OrcTargetProcess", + srcs = glob([ + "lib/ExecutionEngine/Orc/TargetProcess/*.cpp", + ]), + hdrs = glob([ + "include/llvm/ExecutionEngine/Orc/TargetProcess/*.h", + "include/llvm/ExecutionEngine/Orc/*.h", + ]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":CodeGen", + ":Core", + ":DebugInfo", + ":ExecutionEngine", + ":MC", + ":MCDisassembler", + ":Object", + ":OrcShared", + ":Passes", + ":Support", + ":Target", + ":config", + ], +) + +cc_library( + name = "DWARFLinker", + srcs = glob([ + "lib/DWARFLinker/*.cpp", + "lib/DWARFLinker/*.h", + ]), + hdrs = glob(["include/llvm/DWARFLinker/*.h"]), + copts = llvm_copts, + deps = [ + ":CodeGen", + ":DebugInfoDWARF", + ":Support", + ], +) + +gentbl( + name = "DllOptionsTableGen", + strip_include_prefix = "lib/ToolDrivers/llvm-dlltool", + tbl_outs = [( + "-gen-opt-parser-defs", + "lib/ToolDrivers/llvm-dlltool/Options.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "lib/ToolDrivers/llvm-dlltool/Options.td", + td_srcs = ["include/llvm/Option/OptParser.td"], +) + +cc_library( + name = "DlltoolDriver", + srcs = glob(["lib/ToolDrivers/llvm-dlltool/*.cpp"]), + hdrs = glob(["include/llvm/ToolDrivers/llvm-dlltool/*.h"]), + copts = llvm_copts, + deps = [ + ":DllOptionsTableGen", + ":Object", + ":Option", + ":Support", + ], +) + +gentbl( + name = "LibOptionsTableGen", + strip_include_prefix = "lib/ToolDrivers/llvm-lib", + tbl_outs = [( + "-gen-opt-parser-defs", + "lib/ToolDrivers/llvm-lib/Options.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "lib/ToolDrivers/llvm-lib/Options.td", + td_srcs = ["include/llvm/Option/OptParser.td"], +) + +cc_library( + name = "LibDriver", + srcs = glob(["lib/ToolDrivers/llvm-lib/*.cpp"]), + hdrs = glob(["include/llvm/ToolDrivers/llvm-lib/*.h"]), + copts = llvm_copts, + deps = [ + ":BinaryFormat", + ":LibOptionsTableGen", + ":Object", + ":Option", + ":Support", + ], +) + +cc_library( + name = "InterfaceStub", + srcs = glob([ + "lib/InterfaceStub/*.cpp", + "lib/InterfaceStub/*.h", + ]), + hdrs = glob([ + "include/llvm/InterfaceStub/*.h", + ]), + copts = llvm_copts, + deps = [ + ":Object", + ":Support", + ":config", + ], +) + +cc_library( + name = "WindowsManifest", + srcs = glob([ + "lib/WindowsManifest/*.cpp", + ]), + hdrs = glob([ + "include/llvm/WindowsManifest/*.h", + ]), + copts = llvm_copts, + linkopts = [ + # Libxml2 is required to process Windows manifests. Without this, + # lld uses Microsoft mt.exe instead, which is not cross-platform. + "-lxml2", + ], + tags = [ + "manual", # External dependency (libxml) + "nobuildkite", # TODO(gcmn): Fix remote execution and re-enable + ], + deps = [ + ":Support", + ":config", + ], +) + +# FIXME: This library should use `textual_hdrs` instead of `hdrs` as we don't +# want to parse or build modules for them (and haven't duplicated the necessary +# dependencies), but unfortunately that doesn't work with +# `strip_include_prefix`: https://github.com/bazelbuild/bazel/issues/12424 +# +# For now, we simply disable features that might rely on the headers parsing. +cc_library( + name = "llvm-objcopy-headers", + hdrs = glob(["tools/llvm-objcopy/**/*.h"]), + features = [ + "-parse_headers", + "-header_modules", + ], + strip_include_prefix = "tools/llvm-objcopy", +) + +cc_library( + name = "MCA", + srcs = glob([ + "lib/MCA/**/*.cpp", + "lib/MCA/**/*.h", + ]), + hdrs = glob([ + "include/llvm/MCA/**/*.h", + ]), + copts = llvm_copts, + deps = [ + ":MC", + ":MCDisassembler", + ":Object", + ":Support", + ], +) + +cc_library( + name = "llvm-mca-headers", + hdrs = glob([ + "tools/llvm-mca/*.h", + "tools/llvm-mca/Views/*.h", + ]), + strip_include_prefix = "tools/llvm-mca", +) + +cc_library( + name = "XRay", + srcs = glob([ + "lib/XRay/*.cpp", + "lib/XRay/*.h", + ]), + hdrs = glob(["include/llvm/XRay/*.h"]), + copts = llvm_copts, + deps = [ + ":Object", + ":Support", + ], +) + +cc_library( + name = "llvm-exegesis-lib", + srcs = glob([ + "tools/llvm-exegesis/lib/*.cpp", + "tools/llvm-exegesis/lib/X86/*.cpp", + "tools/llvm-exegesis/lib/X86/*.h", + + # We have to include these headers here as well as in the `hdrs` below + # to allow the `.cpp` files to use file-relative-inclusion to find + # them, even though consumers of this library use inclusion relative to + # `tools/llvm-exegesis/lib` with the `strip_includes_prefix` of this + # library. This mixture appears to be incompatible with header modules. + "tools/llvm-exegesis/lib/*.h", + ]), + hdrs = glob(["tools/llvm-exegesis/lib/*.h"]), + copts = llvm_copts + ["-DHAVE_LIBPFM=1"], + defines = ["LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET=InitializeX86ExegesisTarget"], + features = ["-header_modules"], + strip_include_prefix = "tools/llvm-exegesis/lib", + tags = [ + "manual", # External dependency (libpfm4) + "nobuildkite", # TODO(chandlerc): Add support for fetching and building libpfm4 and enable this. + ], + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":CodeGen", + ":Core", + ":ExecutionEngine", + ":MC", + ":MCDisassembler", + ":MCJIT", + ":Object", + ":ObjectYAML", + ":Support", + ":Target", + ":config", + ], +) + +################################################################################ +# LLVM toolchain and development binaries + +gentbl( + name = "DsymutilTableGen", + strip_include_prefix = "tools/dsymutil", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/dsymutil/Options.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/dsymutil/Options.td", + td_srcs = ["include/llvm/Option/OptParser.td"], +) + +cc_binary( + name = "dsymutil", + srcs = glob([ + "tools/dsymutil/*.cpp", + "tools/dsymutil/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":BinaryFormat", + ":CodeGen", + ":DWARFLinker", + ":DebugInfo", + ":DebugInfoDWARF", + ":DsymutilTableGen", + ":MC", + ":Object", + ":Option", + ":Support", + ":Target", + ":config", + ":remark_linker", + ], +) + +cc_binary( + name = "llc", + srcs = glob([ + "tools/llc/*.cpp", + "tools/llc/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":Analysis", + ":AsmParser", + ":BitReader", + ":CodeGen", + ":Core", + ":IRReader", + ":MC", + ":Support", + ":Target", + ":TransformUtils", + ], +) + +cc_binary( + name = "lli", + srcs = glob([ + "tools/lli/*.cpp", + "tools/lli/*.h", + ]), + copts = llvm_copts, + # ll scripts rely on symbols from dependent + # libraries being resolvable. + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "@bazel_tools//src/conditions:darwin": [], + "//conditions:default": [ + "-Wl,--undefined=_ZTIi", + "-Wl,--export-dynamic-symbol=_ZTIi", + "-Wl,--export-dynamic-symbol=__cxa_begin_catch", + "-Wl,--export-dynamic-symbol=__cxa_end_catch", + "-Wl,--export-dynamic-symbol=__gxx_personality_v0", + "-Wl,--export-dynamic-symbol=__cxa_allocate_exception", + "-Wl,--export-dynamic-symbol=__cxa_throw", + ], + }), + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AsmParser", + ":BitReader", + ":CodeGen", + ":Core", + ":ExecutionEngine", + ":IRReader", + ":Instrumentation", + ":Interpreter", + ":MCJIT", + ":Object", + ":OrcJIT", + ":Support", + ":config", + ], +) + +cc_binary( + name = "llvm-ar", + srcs = glob([ + "tools/llvm-ar/*.cpp", + "tools/llvm-ar/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":Core", + ":DlltoolDriver", + ":LibDriver", + ":Object", + ":Support", + ], +) + +# We need to run llvm-ar with different basenames to make it run with +# different behavior. +binary_alias( + name = "llvm-dlltool", + binary = ":llvm-ar", +) + +binary_alias( + name = "llvm-lib", + binary = ":llvm-ar", +) + +binary_alias( + name = "llvm-ranlib", + binary = ":llvm-ar", +) + +cc_binary( + name = "llvm-as", + srcs = glob([ + "tools/llvm-as/*.cpp", + "tools/llvm-as/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Analysis", + ":AsmParser", + ":BitWriter", + ":Core", + ":Support", + ], +) + +cc_binary( + name = "llvm-bcanalyzer", + srcs = glob([ + "tools/llvm-bcanalyzer/*.cpp", + "tools/llvm-bcanalyzer/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BitReader", + ":Support", + ], +) + +cc_binary( + name = "llvm-cat", + srcs = glob([ + "tools/llvm-cat/*.cpp", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BitReader", + ":BitWriter", + ":Core", + ":IRReader", + ":Support", + ], +) + +cc_binary( + name = "llvm-cfi-verify", + srcs = glob([ + "tools/llvm-cfi-verify/*.cpp", + "tools/llvm-cfi-verify/lib/*.cpp", + "tools/llvm-cfi-verify/lib/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":BinaryFormat", + ":DebugInfoDWARF", + ":MC", + ":MCDisassembler", + ":MCParser", + ":Object", + ":Support", + ":Symbolize", + ], +) + +cc_binary( + name = "llvm-cov", + srcs = glob([ + "tools/llvm-cov/*.cpp", + "tools/llvm-cov/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Coverage", + ":Instrumentation", + ":Object", + ":ProfileData", + ":Support", + ], +) + +gentbl( + name = "CvtResTableGen", + strip_include_prefix = "tools/llvm-cvtres", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-cvtres/Opts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-cvtres/Opts.td", + td_srcs = ["include/llvm/Option/OptParser.td"], +) + +cc_binary( + name = "llvm-cvtres", + srcs = glob([ + "tools/llvm-cvtres/*.cpp", + "tools/llvm-cvtres/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":CvtResTableGen", + ":Object", + ":Option", + ":Support", + ], +) + +cc_binary( + name = "llvm-cxxdump", + srcs = glob([ + "tools/llvm-cxxdump/*.cpp", + "tools/llvm-cxxdump/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":BitReader", + ":Object", + ":Support", + ], +) + +cc_binary( + name = "llvm-cxxmap", + srcs = glob([ + "tools/llvm-cxxmap/*.cpp", + "tools/llvm-cxxmap/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Support", + ], +) + +cc_binary( + name = "llvm-cxxfilt", + srcs = glob([ + "tools/llvm-cxxfilt/*.cpp", + "tools/llvm-cxxfilt/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Demangle", + ":Support", + ], +) + +cc_binary( + name = "llvm-dis", + srcs = glob([ + "tools/llvm-dis/*.cpp", + "tools/llvm-dis/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Analysis", + ":BitReader", + ":Core", + ":Support", + ], +) + +cc_binary( + name = "llvm-dwarfdump", + srcs = glob([ + "tools/llvm-dwarfdump/*.cpp", + "tools/llvm-dwarfdump/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":BinaryFormat", + ":DebugInfo", + ":DebugInfoDWARF", + ":MC", + ":Object", + ":Support", + ], +) + +cc_binary( + name = "llvm-dwp", + srcs = glob([ + "tools/llvm-dwp/*.cpp", + "tools/llvm-dwp/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":DebugInfoDWARF", + ":MC", + ":Object", + ":Support", + ":Target", + ], +) + +cc_binary( + name = "llvm-elfabi", + srcs = glob([ + "tools/llvm-elfabi/*.cpp", + "tools/llvm-elfabi/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":InterfaceStub", + ":Object", + ":Support", + ":TextAPI", + ], +) + +cc_binary( + name = "llvm-exegesis", + srcs = [ + "tools/llvm-exegesis/llvm-exegesis.cpp", + ], + copts = llvm_copts + ["-DHAVE_LIBPFM=0"], + linkopts = ["-lpfm"], + stamp = 0, + tags = [ + "manual", # TODO(chandlerc): Enable when the library builds. + "nobuildkite", # TODO(chandlerc): Enable when the library builds. + ], + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":MC", + ":MCParser", + ":Object", + ":Support", + ":config", + ":llvm-exegesis-lib", + ], +) + +cc_binary( + name = "llvm-extract", + srcs = glob([ + "tools/llvm-extract/*.cpp", + "tools/llvm-extract/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AsmParser", + ":BitReader", + ":BitWriter", + ":Core", + ":IPO", + ":IRReader", + ":Support", + ], +) + +cc_binary( + name = "llvm-ifs", + srcs = glob([ + "tools/llvm-ifs/*.cpp", + "tools/llvm-ifs/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":ObjectYAML", + ":Support", + ":TextAPI", + ], +) + +cc_binary( + name = "llvm-jitlink", + srcs = glob([ + "tools/llvm-jitlink/*.cpp", + "tools/llvm-jitlink/*.h", + ]), + copts = llvm_copts, + # Make symbols from the standard library dynamically resolvable. + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "@bazel_tools//src/conditions:darwin": [], + "//conditions:default": [ + "-Wl,--undefined=_ZTIi", + "-Wl,--export-dynamic-symbol=_ZTIi", + "-Wl,--export-dynamic-symbol=__cxa_begin_catch", + "-Wl,--export-dynamic-symbol=__cxa_end_catch", + "-Wl,--export-dynamic-symbol=__gxx_personality_v0", + "-Wl,--export-dynamic-symbol=__cxa_allocate_exception", + "-Wl,--export-dynamic-symbol=__cxa_throw", + ], + }), + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":AsmParser", + ":BitReader", + ":CodeGen", + ":ExecutionEngine", + ":MCJIT", + ":Object", + ":OrcJIT", + ":Support", + ":config", + ], +) + +cc_binary( + name = "llvm-libtool-darwin", + srcs = glob([ + "tools/llvm-libtool-darwin/*.cpp", + "tools/llvm-libtool-darwin/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BinaryFormat", + ":Object", + ":Support", + ], +) + +cc_binary( + name = "llvm-link", + srcs = glob([ + "tools/llvm-link/*.cpp", + "tools/llvm-link/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AsmParser", + ":BitReader", + ":BitWriter", + ":Core", + ":IPO", + ":IRReader", + ":Linker", + ":Object", + ":Support", + ":TransformUtils", + ], +) + +gentbl( + name = "LipoOptsTableGen", + strip_include_prefix = "tools/llvm-lipo", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-lipo/LipoOpts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-lipo/LipoOpts.td", + td_srcs = ["include/llvm/Option/OptParser.td"], +) + +cc_binary( + name = "llvm-lipo", + srcs = [ + "tools/llvm-lipo/llvm-lipo.cpp", + ], + copts = llvm_copts, + stamp = 0, + deps = [ + ":LipoOptsTableGen", + ":Object", + ":Option", + ":Support", + ], +) + +cc_binary( + name = "llvm-lto", + srcs = glob([ + "tools/llvm-lto/*.cpp", + "tools/llvm-lto/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":BitReader", + ":BitWriter", + ":CodeGen", + ":Core", + ":IRReader", + ":LTO", + ":Support", + ":Target", + ], +) + +cc_binary( + name = "llvm-lto2", + srcs = glob([ + "tools/llvm-lto2/*.cpp", + "tools/llvm-lto2/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":BitReader", + ":CodeGen", + ":Core", + ":LTO", + ":Support", + ], +) + +cc_binary( + name = "llvm-mc", + srcs = glob([ + "tools/llvm-mc/*.cpp", + "tools/llvm-mc/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":MC", + ":MCDisassembler", + ":MCParser", + ":Object", + ":Support", + ], +) + +cc_binary( + name = "llvm-mca", + srcs = glob([ + "tools/llvm-mca/*.cpp", + "tools/llvm-mca/Views/*.cpp", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":MC", + ":MCA", + ":MCParser", + ":Support", + ":llvm-mca-headers", + ], +) + +cc_binary( + name = "llvm-ml", + srcs = glob([ + "tools/llvm-ml/*.cpp", + "tools/llvm-ml/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":MC", + ":MCParser", + ":Support", + ], +) + +cc_binary( + name = "llvm-modextract", + srcs = glob([ + "tools/llvm-modextract/*.cpp", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BitReader", + ":BitWriter", + ":IRReader", + ":Support", + ], +) + +gentbl( + name = "MtTableGen", + strip_include_prefix = "tools/llvm-mt", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-mt/Opts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-mt/Opts.td", + td_srcs = ["include/llvm/Option/OptParser.td"], +) + +cc_binary( + name = "llvm-mt", + srcs = glob([ + "tools/llvm-mt/*.cpp", + "tools/llvm-mt/*.h", + ]), + copts = llvm_copts, + stamp = 0, + tags = [ + "manual", # TODO(gcmn): External dependency (through WindowsManifest) + "nobuildkite", # TODO(gcmn): Re-enable when WindowsManifest builds + ], + deps = [ + ":MtTableGen", + ":Option", + ":Support", + ":WindowsManifest", + ], +) + +cc_binary( + name = "llvm-nm", + srcs = glob([ + "tools/llvm-nm/*.cpp", + "tools/llvm-nm/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":BinaryFormat", + ":BitReader", + ":Core", + ":Demangle", + ":Object", + ":Support", + ], +) + +gentbl( + name = "llvm-objcopy-opts", + strip_include_prefix = "tools/llvm-objcopy", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-objcopy/ObjcopyOpts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-objcopy/ObjcopyOpts.td", + td_srcs = [ + "include/llvm/Option/OptParser.td", + "tools/llvm-objcopy/CommonOpts.td", + ], +) + +gentbl( + name = "llvm-installnametool-opts", + strip_include_prefix = "tools/llvm-objcopy", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-objcopy/InstallNameToolOpts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-objcopy/InstallNameToolOpts.td", + td_srcs = [ + "include/llvm/Option/OptParser.td", + "tools/llvm-objcopy/CommonOpts.td", + ], +) + +gentbl( + name = "llvm-strip-opts", + strip_include_prefix = "tools/llvm-objcopy", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-objcopy/StripOpts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-objcopy/StripOpts.td", + td_srcs = [ + "include/llvm/Option/OptParser.td", + "tools/llvm-objcopy/CommonOpts.td", + ], +) + +gentbl( + name = "llvm-bitcode-strip-opts", + strip_include_prefix = "tools/llvm-objcopy", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-objcopy/BitcodeStripOpts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-objcopy/BitcodeStripOpts.td", + td_srcs = [ + "include/llvm/Option/OptParser.td", + "tools/llvm-objcopy/CommonOpts.td", + ], +) + +cc_binary( + name = "llvm-objcopy", + srcs = glob([ + "tools/llvm-objcopy/**/*.cpp", + # Note that we redundantly include the headers here to allow files to + # include same-directory headers in addition to including headers via + # the `llvm-objcopy-headers` rule's stripped include prefix. + "tools/llvm-objcopy/**/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BinaryFormat", + ":MC", + ":Object", + ":ObjectYAML", + ":Option", + ":Support", + ":Target", + ":llvm-bitcode-strip-opts", + ":llvm-installnametool-opts", + ":llvm-objcopy-headers", + ":llvm-objcopy-opts", + ":llvm-strip-opts", + ], +) + +binary_alias( + name = "llvm-strip", + binary = ":llvm-objcopy", +) + +binary_alias( + name = "llvm-bitcode-strip", + binary = ":llvm-objcopy", +) + +binary_alias( + name = "llvm-install-name-tool", + binary = ":llvm-objcopy", +) + +cc_binary( + name = "llvm-objdump", + srcs = glob([ + "tools/llvm-objdump/*.cpp", + "tools/llvm-objdump/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":BinaryFormat", + ":CodeGen", + ":DebugInfo", + ":DebugInfoDWARF", + ":Demangle", + ":MC", + ":MCDisassembler", + ":Object", + ":Support", + ":Symbolize", + ":config", + ], +) + +cc_binary( + name = "llvm-opt-report", + srcs = glob([ + "tools/llvm-opt-report/*.cpp", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":Demangle", + ":Remarks", + ":Support", + ], +) + +cc_binary( + name = "llvm-pdbutil", + srcs = glob([ + "tools/llvm-pdbutil/*.cpp", + "tools/llvm-pdbutil/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BinaryFormat", + ":DebugInfoCodeView", + ":DebugInfoMSF", + ":DebugInfoPDB", + ":Object", + ":ObjectYAML", + ":Support", + ":config", + ], +) + +cc_binary( + name = "llvm-profdata", + srcs = glob([ + "tools/llvm-profdata/*.cpp", + "tools/llvm-profdata/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Core", + ":ProfileData", + ":Support", + ], +) + +gentbl( + name = "RcTableGen", + strip_include_prefix = "tools/llvm-rc", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-rc/Opts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-rc/Opts.td", + td_srcs = ["include/llvm/Option/OptParser.td"], +) + +# Workaround inability to put `.def` files into `srcs` with a library. +cc_library( + name = "llvm-rc-defs-lib", + textual_hdrs = glob([ + "tools/llvm-rc/*.def", + ]), +) + +cc_binary( + name = "llvm-rc", + srcs = glob([ + "tools/llvm-rc/*.cpp", + "tools/llvm-rc/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Object", + ":Option", + ":RcTableGen", + ":Support", + ":llvm-rc-defs-lib", + ], +) + +cc_binary( + name = "llvm-readobj", + srcs = glob([ + "tools/llvm-readobj/*.cpp", + "tools/llvm-readobj/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":BinaryFormat", + ":BitReader", + ":DebugInfoCodeView", + ":DebugInfoDWARF", + ":Demangle", + ":Object", + ":Support", + ], +) + +# Create an 'llvm-readelf' named binary from the 'llvm-readobj' tool. +binary_alias( + name = "llvm-readelf", + binary = ":llvm-readobj", +) + +cc_binary( + name = "llvm-reduce", + srcs = glob([ + "tools/llvm-reduce/**/*.cpp", + "tools/llvm-reduce/**/*.h", + ]), + copts = llvm_copts, + includes = ["tools/llvm-reduce"], + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":BitReader", + ":Core", + ], +) + +cc_binary( + name = "llvm-rtdyld", + srcs = glob([ + "tools/llvm-rtdyld/*.cpp", + "tools/llvm-rtdyld/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":DebugInfo", + ":DebugInfoDWARF", + ":ExecutionEngine", + ":MC", + ":MCDisassembler", + ":Object", + ":Support", + ], +) + +cc_binary( + name = "llvm-size", + srcs = glob([ + "tools/llvm-size/*.cpp", + "tools/llvm-size/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Object", + ":Support", + ], +) + +cc_binary( + name = "llvm-split", + srcs = glob([ + "tools/llvm-split/*.cpp", + "tools/llvm-split/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BitWriter", + ":Core", + ":IRReader", + ":Support", + ":TransformUtils", + ], +) + +cc_binary( + name = "llvm-strings", + srcs = glob([ + "tools/llvm-strings/*.cpp", + "tools/llvm-strings/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Object", + ":Support", + ], +) + +gentbl( + name = "SymbolizerOptsTableGen", + strip_include_prefix = "tools/llvm-symbolizer", + tbl_outs = [( + "-gen-opt-parser-defs", + "tools/llvm-symbolizer/Opts.inc", + )], + tblgen = ":llvm-tblgen", + td_file = "tools/llvm-symbolizer/Opts.td", + td_srcs = ["include/llvm/Option/OptParser.td"], +) + +cc_binary( + name = "llvm-symbolizer", + srcs = glob([ + "tools/llvm-symbolizer/*.cpp", + "tools/llvm-symbolizer/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":DebugInfoDWARF", + ":DebugInfoPDB", + ":Object", + ":Option", + ":Support", + ":Symbolize", + ":SymbolizerOptsTableGen", + ], +) + +binary_alias( + name = "llvm-addr2line", + binary = ":llvm-symbolizer", +) + +cc_binary( + name = "llvm-undname", + srcs = glob([ + "tools/llvm-undname/*.cpp", + "tools/llvm-undname/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Demangle", + ":Support", + ], +) + +cc_binary( + name = "llvm-xray", + srcs = glob([ + "tools/llvm-xray/*.cpp", + "tools/llvm-xray/*.cc", + "tools/llvm-xray/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":DebugInfoDWARF", + ":Object", + ":Support", + ":Symbolize", + ":XRay", + ], +) + +cc_binary( + name = "opt", + srcs = glob([ + "tools/opt/*.cpp", + "tools/opt/*.h", + ]), + copts = llvm_copts, + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "@bazel_tools//src/conditions:darwin": [], + "//conditions:default": ["-Wl,--export-dynamic"], + }), + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":Analysis", + ":AsmParser", + ":BitReader", + ":BitWriter", + ":CodeGen", + ":Core", + ":IRReader", + ":MC", + ":Passes", + ":Support", + ":Target", + ":TransformUtils", + ":common_transforms", + ":config", + ], +) + +cc_binary( + name = "sancov", + srcs = glob([ + "tools/sancov/*.cpp", + "tools/sancov/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":DebugInfoDWARF", + ":DebugInfoPDB", + ":MC", + ":MCDisassembler", + ":Object", + ":Support", + ":Symbolize", + ], +) + +cc_binary( + name = "sanstats", + srcs = glob([ + "tools/sanstats/*.cpp", + "tools/sanstats/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Support", + ":Symbolize", + ":TransformUtils", + ], +) + +cc_binary( + name = "split-file", + srcs = glob([ + "tools/split-file/*.cpp", + "tools/split-file/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Support", + ], +) + +################################################################################ +# Begin testonly libraries + +cc_library( + name = "FuzzMutate", + testonly = True, + srcs = glob(["lib/FuzzMutate/*.cpp"]), + hdrs = glob(["include/llvm/FuzzMutate/*.h"]), + copts = llvm_copts, + includes = ["include"], + deps = [ + ":Analysis", + ":BitReader", + ":BitWriter", + ":Core", + ":Scalar", + ":Support", + ], +) + +# A hacky library to expose some internal headers of gtest to its own +# implementation source files using a stripped include prefix rather than +# file-relative-inclusion. +# +# FIXME: This file should be in `textual_hdrs` instead of `hdrs`, but +# unfortunately that doesn't work with `strip_include_prefix`: +# https://github.com/bazelbuild/bazel/issues/12424 +# +# For now, simply disable parsing and header modules. +cc_library( + name = "gtest_internal_headers", + testonly = True, + hdrs = ["utils/unittest/googletest/src/gtest-internal-inl.h"], + features = [ + "-parse_headers", + "-header_modules", + ], + strip_include_prefix = "utils/unittest/googletest", +) + +cc_library( + name = "gtest", + testonly = True, + srcs = glob( + [ + "utils/unittest/googletest/include/**/*.h", + "utils/unittest/googletest/src/*.cc", + ], + exclude = [ + "utils/unittest/googletest/src/gtest-all.cc", + "utils/unittest/googletest/include/gtest/gtest_pred_impl.h", + ], + ) + [ + ], + hdrs = ["utils/unittest/googletest/include/gtest/gtest.h"], + copts = llvm_copts, + defines = [ + "GTEST_HAS_RTTI=0", + "__STDC_LIMIT_MACROS", + "__STDC_CONSTANT_MACROS", + ] + select({ + "@bazel_tools//src/conditions:windows": ["GTEST_USE_OWN_TR1_TUPLE=0"], + "//conditions:default": ["GTEST_USE_OWN_TR1_TUPLE=1"], + }), + includes = [ + "include", + "utils/unittest/googletest/include", + ], + textual_hdrs = [ + "utils/unittest/googletest/include/gtest/gtest_pred_impl.h", + ], + deps = [ + ":Support", + ":gtest_internal_headers", + ], +) + +cc_library( + name = "gtest_main", + testonly = True, + srcs = ["utils/unittest/UnitTestMain/TestMain.cpp"], + copts = llvm_copts, + deps = [ + ":Support", + ":gmock", + ":gtest", + ], +) + +cc_library( + name = "gmock", + testonly = True, + srcs = glob( + [ + "utils/unittest/googlemock/include/**/*.h", + "utils/unittest/googlemock/src/*.cc", + ], + exclude = ["utils/unittest/googlemock/src/gmock-all.cc"], + ), + hdrs = ["utils/unittest/googlemock/include/gmock/gmock.h"], + copts = llvm_copts, + includes = [ + "include", + "utils/unittest/googlemock/include", + ], + deps = [":gtest"], +) + +cc_library( + name = "TestingSupport", + testonly = True, + srcs = glob([ + "lib/Testing/Support/*.cpp", + "lib/Testing/Support/*.h", + ]), + hdrs = glob([ + "include/llvm/Testing/Support/*.h", + ]), + copts = llvm_copts, + deps = [ + ":Support", + ":config", + ":gmock", + ":gtest", + ], +) + +################################################################################ +# Begin testonly binary utilities + +cc_binary( + name = "FileCheck", + testonly = True, + srcs = glob([ + "utils/FileCheck/*.cpp", + "utils/FileCheck/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [":FileCheckLib"], +) + +cc_binary( + name = "bugpoint", + srcs = glob([ + "tools/bugpoint/*.cpp", + "tools/bugpoint/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":Analysis", + ":AsmParser", + ":BitReader", + ":BitWriter", + ":CodeGen", + ":Core", + ":IRReader", + ":Linker", + ":Passes", + ":Support", + ":TransformUtils", + ":common_transforms", + ":config", + ], +) + +cc_binary( + name = "count", + testonly = True, + srcs = glob([ + "utils/count/*.c", + "utils/count/*.h", + ]), + stamp = 0, +) + +cc_binary( + name = "lli-child-target", + testonly = True, + srcs = glob([ + "tools/lli/ChildTarget/*.cpp", + "tools/lli/ChildTarget/*.h", + ]) + [ + "tools/lli/RemoteJITUtils.h", + ], + copts = llvm_copts, + # The tests load code into this binary that expect to see symbols + # from libstdc++ such as __cxa_begin_catch and _ZTIi. The latter + # isn't even used in the main binary, so we also need to force it + # to be included. + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "@bazel_tools//src/conditions:darwin": [], + "//conditions:default": [ + "-rdynamic", + "-u_ZTIi", + ], + }), + stamp = 0, + deps = [ + ":OrcJIT", + ":Support", + ":attributes_gen", + ":config", + ":intrinsic_enums_gen", + ], +) + +cc_binary( + name = "llvm-c-test", + testonly = True, + srcs = glob([ + "tools/llvm-c-test/*.c", + "tools/llvm-c-test/*.cpp", + "tools/llvm-c-test/*.h", + ]), + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":AllTargetsDisassemblers", + ":Analysis", + ":BitReader", + ":BitWriter", + ":Core", + ":ExecutionEngine", + ":IPO", + ":LTO", + ":Linker", + ":MCDisassembler", + ":Object", + ":OrcJIT", + ":Scalar", + ":Support", + ":Target", + ":Vectorize", + ], +) + +cc_binary( + name = "llvm-diff", + testonly = True, + srcs = glob([ + "tools/llvm-diff/*.cpp", + "tools/llvm-diff/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AsmParser", + ":BitReader", + ":Core", + ":IRReader", + ":Support", + ], +) + +cc_binary( + name = "llvm-isel-fuzzer", + testonly = True, + srcs = glob([ + "tools/llvm-isel-fuzzer/*.cpp", + "tools/llvm-isel-fuzzer/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsAsmParsers", + ":AllTargetsCodeGens", + ":Analysis", + ":BitReader", + ":BitWriter", + ":CodeGen", + ":Core", + ":FuzzMutate", + ":IRReader", + ":Support", + ":Target", + ], +) + +# This is really a Python script, but call it sh_binary to ignore the hyphen in +# the path, which py_binary does not allow. +# Also, note: llvm-locstats expects llvm-dwarfdump to be in the same directory +# when executed. +sh_binary( + name = "llvm-locstats", + testonly = True, + srcs = glob([ + "utils/llvm-locstats/*.py", + ]), + # llvm-locstats is a thin wrapper around llvm-dwarfdump. + data = [":llvm-dwarfdump"], +) + +cc_binary( + name = "not", + testonly = True, + srcs = glob([ + "utils/not/*.cpp", + "utils/not/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [":Support"], +) + +cc_binary( + name = "llvm-opt-fuzzer", + testonly = True, + srcs = glob([ + "tools/llvm-opt-fuzzer/*.cpp", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AllTargetsCodeGens", + ":Analysis", + ":BitReader", + ":BitWriter", + ":CodeGen", + ":Core", + ":Coroutines", + ":FuzzMutate", + ":Passes", + ":Support", + ], +) + +cc_binary( + name = "obj2yaml", + testonly = True, + srcs = glob([ + "tools/obj2yaml/*.cpp", + "tools/obj2yaml/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BinaryFormat", + ":DebugInfoCodeView", + ":DebugInfoDWARF", + ":Object", + ":ObjectYAML", + ":Support", + ], +) + +cc_binary( + name = "verify-uselistorder", + srcs = glob([ + "tools/verify-uselistorder/*.cpp", + "tools/verify-uselistorder/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":AsmParser", + ":BitReader", + ":BitWriter", + ":Core", + ":IRReader", + ":Support", + ], +) + +cc_binary( + name = "yaml2obj", + testonly = True, + srcs = glob([ + "tools/yaml2obj/*.cpp", + "tools/yaml2obj/*.h", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":BinaryFormat", + ":DebugInfoCodeView", + ":MC", + ":Object", + ":ObjectYAML", + ":Support", + ], +) + +cc_binary( + name = "yaml-bench", + testonly = True, + srcs = glob([ + "utils/yaml-bench/*.cpp", + ]), + copts = llvm_copts, + stamp = 0, + deps = [ + ":Support", + ], +) diff --git a/utils/bazel/llvm-project-overlay/llvm/binary_alias.bzl b/utils/bazel/llvm-project-overlay/llvm/binary_alias.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/binary_alias.bzl @@ -0,0 +1,35 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Creates a copy of a binary, giving it a different basename. + +binary_alias( + name = "my_binary_other_name", + binary = ":some_cc_binary", +) +""" + +def _binary_alias_impl(ctx): + ctx.actions.symlink( + target_file = ctx.executable.binary, + output = ctx.outputs.executable, + is_executable = True, + ) + + return [DefaultInfo( + executable = ctx.outputs.executable, + runfiles = ctx.attr.binary[DefaultInfo].default_runfiles, + )] + +binary_alias = rule( + _binary_alias_impl, + attrs = { + "binary": attr.label( + mandatory = True, + executable = True, + cfg = "target", + ), + }, + executable = True, +) diff --git a/utils/bazel/llvm-project-overlay/llvm/config.bzl b/utils/bazel/llvm-project-overlay/llvm/config.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/config.bzl @@ -0,0 +1,73 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Defines variables that use selects to configure LLVM based on platform.""" + +def native_arch_defines(arch, triple): + return [ + "LLVM_NATIVE_ARCH=\\\"{}\\\"".format(arch), + "LLVM_NATIVE_ASMPARSER=LLVMInitialize{}AsmParser".format(arch), + "LLVM_NATIVE_ASMPRINTER=LLVMInitialize{}AsmPrinter".format(arch), + "LLVM_NATIVE_DISASSEMBLER=LLVMInitialize{}Disassembler".format(arch), + "LLVM_NATIVE_TARGET=LLVMInitialize{}Target".format(arch), + "LLVM_NATIVE_TARGETINFO=LLVMInitialize{}TargetInfo".format(arch), + "LLVM_NATIVE_TARGETMC=LLVMInitialize{}TargetMC".format(arch), + "LLVM_HOST_TRIPLE=\\\"{}\\\"".format(triple), + "LLVM_DEFAULT_TARGET_TRIPLE=\\\"{}\\\"".format(triple), + ] + +posix_defines = [ + "LLVM_ON_UNIX=1", + "HAVE_BACKTRACE=1", + "BACKTRACE_HEADER=", + "LTDL_SHLIB_EXT=\\\".so\\\"", + "LLVM_ENABLE_THREADS=1", + "HAVE_SYSEXITS_H=1", + "HAVE_UNISTD_H=1", + "HAVE_STRERROR_R=1", + "HAVE_LIBPTHREAD=1", + "HAVE_PTHREAD_GETNAME_NP=1", + "HAVE_PTHREAD_SETNAME_NP=1", + "HAVE_PTHREAD_GETSPECIFIC=1", +] + +linux_defines = posix_defines + [ + "_GNU_SOURCE", + "HAVE_LINK_H=1", + "HAVE_LSEEK64=1", + "HAVE_MALLINFO=1", + "HAVE_POSIX_FALLOCATE=1", + "HAVE_SBRK=1", + "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1", +] + +macos_defines = posix_defines + [ + "HAVE_MACH_MACH_H=1", + "HAVE_MALLOC_MALLOC_H=1", + "HAVE_MALLOC_ZONE_STATISTICS=1", +] + +win32_defines = [ + # MSVC specific + "stricmp=_stricmp", + "strdup=_strdup", + + # LLVM features + "LTDL_SHLIB_EXT=\\\".dll\\\"", +] + +# TODO: We should switch to platforms-based config settings to make this easier +# to express. +os_defines = select({ + "@bazel_tools//src/conditions:windows": win32_defines, + "@bazel_tools//src/conditions:darwin": macos_defines, + "//conditions:default": linux_defines, +}) + +# TODO: We should split out host vs. target here. +llvm_config_defines = os_defines + select({ + "@bazel_tools//src/conditions:windows": native_arch_defines("X86", "x86_64-pc-win32"), + "@bazel_tools//src/conditions:darwin": native_arch_defines("X86", "x86_64-unknown-darwin"), + "//conditions:default": native_arch_defines("X86", "x86_64-unknown-linux-gnu"), +}) diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h @@ -0,0 +1,369 @@ +/*===------- llvm/Config/config.h - llvm configuration ------------*- C -*-===*/ +/* */ +/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ +/* Exceptions. */ +/* See https://llvm.org/LICENSE.txt for license information. */ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* */ +/*===----------------------------------------------------------------------===*/ + +/* This is a manual port of config.h.cmake for the symbols that do not change + based on platform. Those that do change should not be defined here and + instead use Bazel cc_library defines. Some attempt has been made to extract + such symbols that do vary based on platform (for the platforms we care about) + into Bazel defines, but it is by no means complete, so if you see something + that looks wrong, it probably is. */ + +#ifndef CONFIG_H +#define CONFIG_H + +// Include this header only under the llvm source tree. +// This is a private header. + +/* Exported configuration */ +#include "llvm/Config/llvm-config.h" + +/* Bug report URL. */ +#define BUG_REPORT_URL "https://bugs.llvm.org/" + +/* Define to 1 to enable backtraces, and to 0 otherwise. */ +#define ENABLE_BACKTRACES 1 + +/* Define to 1 to enable crash overrides, and to 0 otherwise. */ +#define ENABLE_CRASH_OVERRIDES 1 + +/* Define to 1 to enable crash memory dumps, and to 0 otherwise. */ +#define LLVM_ENABLE_CRASH_DUMPS 0 + +/* Define to 1 if you have the `backtrace' function. */ +/* HAVE_BACKTRACE defined in Bazel */ + +/* BACKTRACE_HEADER defined in Bazel */ + +/* Define to 1 if you have the header file. */ +/* HAVE_CRASHREPORTERCLIENT_H defined in Bazel */ + +/* can use __crashreporter_info__ */ +/* HAVE_CRASHREPORTER_INFO defined in Bazel */ + +/* Define to 1 if you have the declaration of `arc4random', and to 0 if you + don't. */ +#define HAVE_DECL_ARC4RANDOM 0 + +/* Define to 1 if you have the declaration of `FE_ALL_EXCEPT', and to 0 if you + don't. */ +#define HAVE_DECL_FE_ALL_EXCEPT 1 + +/* Define to 1 if you have the declaration of `FE_INEXACT', and to 0 if you + don't. */ +#define HAVE_DECL_FE_INEXACT 1 + +/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you + don't. */ +#define HAVE_DECL_STRERROR_S 0 + +/* Define to 1 if you have the DIA SDK installed, and to 0 if you don't. */ +#define LLVM_ENABLE_DIA_SDK 0 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define if dlopen() is available on this platform. */ +#define HAVE_DLOPEN 1 + +/* Define if dladdr() is available on this platform. */ +/* #undef HAVE_DLADDR */ + +/* Define to 1 if we can register EH frames on this platform. */ +#define HAVE_REGISTER_FRAME 1 + +/* Define to 1 if we can deregister EH frames on this platform. */ +#define HAVE_DEREGISTER_FRAME 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FENV_H 1 + +/* Define if libffi is available on this platform. */ +/* #undef HAVE_FFI_CALL */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FFI_FFI_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FFI_H */ + +/* Define to 1 if you have the `futimens' function. */ +#define HAVE_FUTIMENS 1 + +/* Define to 1 if you have the `futimes' function. */ +#define HAVE_FUTIMES 1 + +/* Define to 1 if you have the `getpagesize' function. */ +#define HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the `getrlimit' function. */ +#define HAVE_GETRLIMIT 1 + +/* Define to 1 if you have the `getrusage' function. */ +#define HAVE_GETRUSAGE 1 + +/* Define to 1 if you have the `isatty' function. */ +#define HAVE_ISATTY 1 + +/* Define to 1 if you have the `edit' library (-ledit). */ +/* #undef HAVE_LIBEDIT */ + +/* Define to 1 if you have the `pfm' library (-lpfm). */ +/* #undef HAVE_LIBPFM */ + +/* Define to 1 if the `perf_branch_entry' struct has field cycles. */ +/* #undef LIBPFM_HAS_FIELD_CYCLES */ + +/* Define to 1 if you have the `psapi' library (-lpsapi). */ +/* #undef HAVE_LIBPSAPI */ + +/* Define to 1 if you have the `pthread' library (-lpthread). */ +#define HAVE_LIBPTHREAD 1 + +/* Define to 1 if you have the `pthread_getname_np' function. */ +#define HAVE_PTHREAD_GETNAME_NP 1 + +/* Define to 1 if you have the `pthread_setname_np' function. */ +#define HAVE_PTHREAD_SETNAME_NP 1 + +/* Define to 1 if you have the header file. */ +/* HAVE_LINK_H defined in Bazel */ + +/* Define to 1 if you have the `lseek64' function. */ +/* HAVE_LSEEK64 defined in Bazel */ + +/* Define to 1 if you have the header file. */ +/* HAVE_MACH_MACH_H defined in Bazel */ + +/* Define to 1 if you have the `mallctl' function. */ +/* #undef HAVE_MALLCTL */ + +/* Define to 1 if you have the `mallinfo' function. */ +/* HAVE_MALLINFO defined in Bazel */ + +/* Define to 1 if you have the header file. */ +/* HAVE_MALLOC_MALLOC_H defined in Bazel */ + +/* Define to 1 if you have the `malloc_zone_statistics' function. */ +/* HAVE_MALLOC_ZONE_STATISTICS defined in Bazel */ + +/* Define to 1 if you have the `posix_fallocate' function. */ +/* HAVE_POSIX_FALLOCATE defined in Bazel */ + +/* Define to 1 if you have the `posix_spawn' function. */ +#define HAVE_POSIX_SPAWN 1 + +/* Define to 1 if you have the `pread' function. */ +#define HAVE_PREAD 1 + +/* Have pthread_getspecific */ +#define HAVE_PTHREAD_GETSPECIFIC 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_PTHREAD_H 1 + +/* Have pthread_mutex_lock */ +#define HAVE_PTHREAD_MUTEX_LOCK 1 + +/* Have pthread_rwlock_init */ +#define HAVE_PTHREAD_RWLOCK_INIT 1 + +/* Define to 1 if you have the `sbrk' function. */ +/* HAVE_SBRK defined in Bazel */ + +/* Define to 1 if you have the `setenv' function. */ +#define HAVE_SETENV 1 + +/* Define to 1 if you have the `setrlimit' function. */ +#define HAVE_SETRLIMIT 1 + +/* Define to 1 if you have the `sigaltstack' function. */ +#define HAVE_SIGALTSTACK 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the `strerror_r' function. */ +/* HAVE_STRERROR_R defined in Bazel */ + +/* Define to 1 if you have the `sysconf' function. */ +#define HAVE_SYSCONF 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if stat struct has st_mtimespec member .*/ +/* #undef HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC */ + +/* Define to 1 if stat struct has st_mtim member. */ +/* HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC defined in Bazel */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define if the setupterm() function is supported this platform. */ +/* LLVM_ENABLE_TERMINFO defined in Bazel */ + +/* Define if the xar_open() function is supported this platform. */ +/* #undef HAVE_LIBXAR */ + +/* Define to 1 if you have the header file. */ +#define HAVE_TERMIOS_H 1 + +/* Define to 1 if you have the header file. */ +/* HAVE_UNISTD_H defined in Bazel */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_VALGRIND_VALGRIND_H */ + +/* Have host's _alloca */ +/* #undef HAVE__ALLOCA */ + +/* Define to 1 if you have the `_chsize_s' function. */ +/* #undef HAVE__CHSIZE_S */ + +/* Define to 1 if you have the `_Unwind_Backtrace' function. */ +#define HAVE__UNWIND_BACKTRACE 1 + +/* Have host's __alloca */ +/* #undef HAVE___ALLOCA */ + +/* Have host's __ashldi3 */ +/* #undef HAVE___ASHLDI3 */ + +/* Have host's __ashrdi3 */ +/* #undef HAVE___ASHRDI3 */ + +/* Have host's __chkstk */ +/* #undef HAVE___CHKSTK */ + +/* Have host's __chkstk_ms */ +/* #undef HAVE___CHKSTK_MS */ + +/* Have host's __cmpdi2 */ +/* #undef HAVE___CMPDI2 */ + +/* Have host's __divdi3 */ +/* #undef HAVE___DIVDI3 */ + +/* Have host's __fixdfdi */ +/* #undef HAVE___FIXDFDI */ + +/* Have host's __fixsfdi */ +/* #undef HAVE___FIXSFDI */ + +/* Have host's __floatdidf */ +/* #undef HAVE___FLOATDIDF */ + +/* Have host's __lshrdi3 */ +/* #undef HAVE___LSHRDI3 */ + +/* Have host's __main */ +/* #undef HAVE___MAIN */ + +/* Have host's __moddi3 */ +/* #undef HAVE___MODDI3 */ + +/* Have host's __udivdi3 */ +/* #undef HAVE___UDIVDI3 */ + +/* Have host's __umoddi3 */ +/* #undef HAVE___UMODDI3 */ + +/* Have host's ___chkstk */ +/* #undef HAVE____CHKSTK */ + +/* Have host's ___chkstk_ms */ +/* #undef HAVE____CHKSTK_MS */ + +/* Linker version detected at compile time. */ +/* #undef HOST_LINK_VERSION */ + +/* Target triple LLVM will generate code for by default */ +/* Doesn't use `cmakedefine` because it is allowed to be empty. */ +/* LLVM_DEFAULT_TARGET_TRIPLE defined in Bazel */ + +/* Define if zlib compression is available */ +/* LLVM_ENABLE_ZLIB defined in Bazel */ + +/* Define if overriding target triple is enabled */ +/* #undef LLVM_TARGET_TRIPLE_ENV */ + +/* LLVM version information */ +/* #undef LLVM_VERSION_INFO */ + +/* Whether tools show host and target info when invoked with --version */ +#define LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO 1 + +/* Define if libxml2 is supported on this platform. */ +/* #undef LLVM_ENABLE_LIBXML2 */ + +/* Define to the extension used for shared libraries, say, ".so". */ +/* LTDL_SHLIB_EXT defined in Bazel */ + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "https://bugs.llvm.org/" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "LLVM" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING PACKAGE_NAME " " LLVM_VERSION_STRING + +/* Define to the version of this package. */ +#define PACKAGE_VERSION LLVM_VERSION_STRING + +/* Define to the vendor of this package. */ +/* #undef PACKAGE_VENDOR */ + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define if std::is_trivially_copyable is supported */ +#define HAVE_STD_IS_TRIVIALLY_COPYABLE 1 + +/* Define to a function implementing stricmp */ +/* stricmp defined in Bazel */ + +/* Define to a function implementing strdup */ +/* strdup defined in Bazel */ + +/* Whether GlobalISel rule coverage is being collected */ +#define LLVM_GISEL_COV_ENABLED 0 + +/* Define to the default GlobalISel coverage file prefix */ +/* #undef LLVM_GISEL_COV_PREFIX */ + +/* Whether Timers signpost passes in Xcode Instruments */ +#define LLVM_SUPPORT_XCODE_SIGNPOSTS 0 + +#endif diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h @@ -0,0 +1,102 @@ +/*===------- llvm/Config/llvm-config.h - llvm configuration -------*- C -*-===*/ +/* */ +/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ +/* Exceptions. */ +/* See https://llvm.org/LICENSE.txt for license information. */ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* */ +/*===----------------------------------------------------------------------===*/ + +/* This is a manual port of config.h.cmake for the symbols that do not change + based on platform. Those that do change should not be defined here and + instead use Bazel cc_library defines. Some attempt has been made to extract + such symbols that do vary based on platform (for the platforms we care about) + into Bazel defines, but it is by no means complete, so if you see something + that looks wrong, it probably is. */ + + +/* This file enumerates variables from the LLVM configuration so that they + can be in exported headers and won't override package specific directives. + This is a C header that can be included in the llvm-c headers. */ + +#ifndef LLVM_CONFIG_H +#define LLVM_CONFIG_H + +/* Define if LLVM_ENABLE_DUMP is enabled */ +/* #undef LLVM_ENABLE_DUMP */ + +/* Target triple LLVM will generate code for by default */ +/* LLVM_DEFAULT_TARGET_TRIPLE defined in Bazel */ + +/* Define if threads enabled */ +#define LLVM_ENABLE_THREADS 1 + +/* Has gcc/MSVC atomic intrinsics */ +#define LLVM_HAS_ATOMICS 1 + +/* Host triple LLVM will be executed on */ +/* LLVM_HOST_TRIPLE defined in Bazel */ + +/* LLVM architecture name for the native architecture, if available */ +/* LLVM_NATIVE_ARCH defined in Bazel */ + +/* LLVM name for the native AsmParser init function, if available */ +/* LLVM_NATIVE_ASMPARSER defined in Bazel */ + +/* LLVM name for the native AsmPrinter init function, if available */ +/* LLVM_NATIVE_ASMPRINTER defined in Bazel */ + +/* LLVM name for the native Disassembler init function, if available */ +/* LLVM_NATIVE_DISASSEMBLER defined in Bazel */ + +/* LLVM name for the native Target init function, if available */ +/* LLVM_NATIVE_TARGET defined in Bazel */ + +/* LLVM name for the native TargetInfo init function, if available */ +/* LLVM_NATIVE_TARGETINFO defined in Bazel */ + +/* LLVM name for the native target MC init function, if available */ +/* LLVM_NATIVE_TARGETMC defined in Bazel */ + +/* Define if this is Unixish platform */ +/* LLVM_ON_UNIX defined in Bazel */ + +/* Define if we have the Intel JIT API runtime support library */ +#define LLVM_USE_INTEL_JITEVENTS 0 + +/* Define if we have the oprofile JIT-support library */ +#define LLVM_USE_OPROFILE 0 + +/* Define if we have the perf JIT-support library */ +#define LLVM_USE_PERF 0 + +/* Major version of the LLVM API */ +#define LLVM_VERSION_MAJOR 12 + +/* Minor version of the LLVM API */ +#define LLVM_VERSION_MINOR 0 + +/* Patch version of the LLVM API */ +#define LLVM_VERSION_PATCH 0 + +/* LLVM version string */ +#define LLVM_VERSION_STRING "12.0.0git" + +/* Whether LLVM records statistics for use with GetStatistics(), + * PrintStatistics() or PrintStatisticsJSON() + */ +#define LLVM_FORCE_ENABLE_STATS 0 + +/* Define if we have z3 and want to build it */ +/* #undef LLVM_WITH_Z3 */ + +/* Define if LLVM was built with a dependency to the libtensorflow dynamic library */ +/* #undef LLVM_HAVE_TF_API */ + +/* Define if LLVM was built with a dependency to the tensorflow compiler */ +/* #undef LLVM_HAVE_TF_AOT */ + +/* Define to 1 if you have the header file. */ +/* HAVE_SYSEXITS_H defined in Bazel */ + +#endif diff --git a/utils/bazel/llvm-project-overlay/llvm/tblgen.bzl b/utils/bazel/llvm-project-overlay/llvm/tblgen.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/tblgen.bzl @@ -0,0 +1,77 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""This file contains BUILD extensions for generating source code from LLVM's +table definition files using the TableGen tool. + +See http://llvm.org/cmds/tblgen.html for more information on the TableGen +tool. +TODO(chandlerc): Currently this expresses include-based dependencies as +"sources", and has no transitive understanding due to these files not being +correctly understood by the build system. +""" + +def gentbl( + name, + tblgen, + td_file, + td_srcs, + tbl_outs, + library = True, + tblgen_args = "", + **kwargs): + """gentbl() generates tabular code from a table definition file. + + Args: + name: The name of the build rule for use in dependencies. + tblgen: The binary used to produce the output. + td_file: The primary table definitions file. + td_srcs: A list of table definition files included transitively. + tbl_outs: A list of tuples (opts, out), where each opts is a string of + options passed to tblgen, and the out is the corresponding output file + produced. + library: Whether to bundle the generated files into a library. + tblgen_args: Extra arguments string to pass to the tblgen binary. + **kwargs: Keyword arguments to pass to subsidiary cc_library() rule. + """ + if td_file not in td_srcs: + td_srcs += [td_file] + for (opts, out) in tbl_outs: + rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" ")) + native.genrule( + name = "%s_%s_genrule" % (name, rule_suffix), + srcs = td_srcs, + outs = [out], + tools = [tblgen], + message = "Generating code from table: %s" % td_file, + cmd = (("$(location %s) -I external/llvm-project/llvm/include " + + "-I external/llvm-project/clang/include " + + "-I $$(dirname $(location %s)) " + + "%s $(location %s) %s -o $@") % ( + tblgen, + td_file, + opts, + td_file, + tblgen_args, + )), + ) + + # For now, all generated files can be assumed to comprise public interfaces. + # If this is not true, you should specify library = False + # and list the generated '.inc' files in "srcs". + if library: + native.cc_library( + name = name, + # FIXME: This should be `textual_hdrs` instead of `hdrs`, but + # unfortunately that doesn't work with `strip_include_prefix`: + # https://github.com/bazelbuild/bazel/issues/12424 + # + # Once that issue is fixed and released, we can switch this to + # `textual_hdrs` and remove the feature disabling the various Bazel + # features (both current and under-development) that motivated the + # distinction between these two. + hdrs = [f for (_, f) in tbl_outs], + features = ["-parse_headers", "-header_modules"], + **kwargs + ) diff --git a/utils/bazel/llvm-project-overlay/llvm/template_rule.bzl b/utils/bazel/llvm-project-overlay/llvm/template_rule.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/template_rule.bzl @@ -0,0 +1,46 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Rule for simple expansion of template files. This performs a simple +# search over the template file for the keys in substitutions, +# and replaces them with the corresponding values. +# +# Typical usage: +# load("/tools/build_rules/template_rule", "expand_header_template") +# template_rule( +# name = "ExpandMyTemplate", +# src = "my.template", +# out = "my.txt", +# substitutions = { +# "$VAR1": "foo", +# "$VAR2": "bar", +# } +# ) +# +# Args: +# name: The name of the rule. +# template: The template file to expand +# out: The destination of the expanded file +# substitutions: A dictionary mapping strings to their substitutions + +def template_rule_impl(ctx): + ctx.actions.expand_template( + template = ctx.file.src, + output = ctx.outputs.out, + substitutions = ctx.attr.substitutions, + ) + +template_rule = rule( + attrs = { + "src": attr.label( + mandatory = True, + allow_single_file = True, + ), + "substitutions": attr.string_dict(mandatory = True), + "out": attr.output(mandatory = True), + }, + # output_to_genfiles is required for header files. + output_to_genfiles = True, + implementation = template_rule_impl, +) diff --git a/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD b/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD @@ -0,0 +1,587 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +load("//llvm:tblgen.bzl", "gentbl") + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +cc_test( + name = "adt_tests", + size = "medium", + srcs = glob([ + "ADT/*.cpp", + "ADT/*.h", + ]), + shard_count = 20, + deps = [ + "//llvm:Core", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "analysis_tests", + size = "small", + srcs = glob( + ["Analysis/*.cpp"], + exclude = [ + # TODO: Add this file to the build. + "Analysis/TFUtilsTest.cpp", + ], + ), + deps = [ + "//llvm:Analysis", + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:TransformUtils", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "asm_parser_tests", + size = "small", + srcs = glob(["AsmParser/*.cpp"]), + deps = [ + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "bitcode_tests", + size = "small", + srcs = glob(["Bitcode/*.cpp"]), + deps = [ + "//llvm:AsmParser", + "//llvm:BitReader", + "//llvm:BitWriter", + "//llvm:Core", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "bitstream_tests", + size = "small", + srcs = glob(["Bitstream/*.cpp"]), + deps = [ + "//llvm:BitstreamReader", + "//llvm:BitstreamWriter", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_library( + name = "codegen_tests_includes", + textual_hdrs = glob(["CodeGen/*.inc"]), +) + +cc_test( + name = "codegen_tests", + size = "small", + srcs = glob([ + "CodeGen/*.cpp", + "CodeGen/*.h", + ]), + deps = [ + ":codegen_tests_includes", + "//llvm:AllTargetsAsmParsers", + "//llvm:AllTargetsCodeGens", + "//llvm:Analysis", + "//llvm:AsmParser", + "//llvm:BinaryFormat", + "//llvm:CodeGen", + "//llvm:Core", + "//llvm:MC", + "//llvm:Passes", + "//llvm:Support", + "//llvm:Target", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "codegen_globalisel_tests", + size = "small", + srcs = glob([ + "CodeGen/GlobalISel/*.cpp", + "CodeGen/GlobalISel/*.h", + ]), + copts = [ + "$(STACK_FRAME_UNLIMITED)", + ], + deps = [ + "//llvm:AllTargetsAsmParsers", + "//llvm:AllTargetsCodeGens", + "//llvm:CodeGen", + "//llvm:Core", + "//llvm:FileCheckLib", + "//llvm:Support", + "//llvm:Target", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "debuginfo_tests", + size = "small", + srcs = glob([ + "DebugInfo/DWARF/*.cpp", + "DebugInfo/DWARF/*.h", + # TODO: Re-enable these when they stop crashing. + #"DebugInfo/PDB/*.cpp", + #"DebugInfo/PDB/*.h", + ]), + args = [ + # Skip a test that relies on reading files in a way that doesn't easily + # work with Bazel. + "--gtest_filter=-NativeSymbolReuseTest.*", + ], + deps = [ + "//llvm:AllTargetsAsmParsers", + "//llvm:AllTargetsCodeGens", + "//llvm:CodeGen", + "//llvm:Core", + "//llvm:DebugInfoDWARF", + "//llvm:DebugInfoPDB", + "//llvm:ObjectYAML", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "execution_engine_tests", + size = "small", + srcs = glob(["ExecutionEngine/*.cpp"]), + deps = [ + "//llvm:AllTargetsCodeGens", + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:ExecutionEngine", + "//llvm:Interpreter", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "execution_engine_mcjit_tests", + size = "small", + srcs = glob([ + "ExecutionEngine/MCJIT/*.cpp", + "ExecutionEngine/MCJIT/*.h", + ]), + copts = [ + "$(STACK_FRAME_UNLIMITED)", + ], + deps = [ + "//llvm:AllTargetsCodeGens", + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:ExecutionEngine", + "//llvm:MCJIT", + "//llvm:Passes", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "execution_engine_orc_tests", + size = "small", + srcs = glob([ + "ExecutionEngine/Orc/*.cpp", + "ExecutionEngine/Orc/*.h", + ]), + args = ["--gtest_filter=-ObjectLinkingLayerTest.TestSetProcessAllSections"], + deps = [ + "//llvm:AllTargetsAsmParsers", + "//llvm:AllTargetsCodeGens", + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:ExecutionEngine", + "//llvm:OrcJIT", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "filecheck_tests", + size = "small", + srcs = glob(["FileCheck/*.cpp"]), + deps = [ + "//llvm:FileCheckLib", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "ir_tests", + size = "medium", # ConstantRangeTest cases may take several seconds each. + srcs = glob([ + "IR/*.cpp", + "IR/*.h", + "Support/KnownBitsTest.h", + ]), + shard_count = 20, + deps = [ + "//llvm:Analysis", + "//llvm:AsmParser", + "//llvm:BinaryFormat", + "//llvm:Core", + "//llvm:Passes", + "//llvm:Scalar", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:config", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "line_editor_tests", + size = "small", + srcs = glob(["LineEditor/*.cpp"]), + deps = [ + "//llvm:LineEditor", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "frontend_tests", + size = "small", + srcs = glob(["FrontEnd/*.cpp"]), + deps = [ + "//llvm:Analysis", + "//llvm:FrontendOpenMP", + "//llvm:Passes", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "linker_tests", + size = "small", + srcs = glob(["Linker/*.cpp"]), + deps = [ + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:Linker", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "mc_tests", + size = "small", + srcs = glob(["MC/*.cpp"]), + deps = [ + "//llvm:AllTargetsCodeGens", + "//llvm:AllTargetsDisassemblers", + "//llvm:MC", + "//llvm:MCDisassembler", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "mi_tests", + size = "small", + srcs = glob(["MI/*.cpp"]), + deps = [ + "//llvm:AllTargetsAsmParsers", + "//llvm:AllTargetsCodeGens", + "//llvm:CodeGen", + "//llvm:Core", + "//llvm:Support", + "//llvm:Target", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "object_tests", + size = "small", + srcs = glob(["Object/*.cpp"]), + deps = [ + "//llvm:Object", + "//llvm:ObjectYAML", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "object_yaml_tests", + size = "small", + srcs = glob(["ObjectYAML/*.cpp"]), + deps = [ + "//llvm:DebugInfoCodeView", + "//llvm:Object", + "//llvm:ObjectYAML", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +gentbl( + name = "option_tests_gen", + strip_include_prefix = "Option", + tbl_outs = [( + "-gen-opt-parser-defs", + "Option/Opts.inc", + )], + tblgen = "//llvm:llvm-tblgen", + td_file = "Option/Opts.td", + td_srcs = [ + "//llvm:include/llvm/Option/OptParser.td", + ], +) + +gentbl( + name = "automata_automata_gen", + strip_include_prefix = "TableGen", + tbl_outs = [( + "-gen-automata", + "TableGen/AutomataAutomata.inc", + )], + tblgen = "//llvm:llvm-tblgen", + td_file = "TableGen/Automata.td", + td_srcs = ["//llvm:common_target_td_sources"] + [ + "TableGen/Automata.td", + ], +) + +gentbl( + name = "automata_tables_gen", + strip_include_prefix = "TableGen", + tbl_outs = [( + "-gen-searchable-tables", + "TableGen/AutomataTables.inc", + )], + tblgen = "//llvm:llvm-tblgen", + td_file = "TableGen/Automata.td", + td_srcs = ["//llvm:common_target_td_sources"] + [ + "TableGen/Automata.td", + ], +) + +cc_test( + name = "option_tests", + size = "small", + srcs = glob(["Option/*.cpp"]), + deps = [ + ":option_tests_gen", + "//llvm:Option", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "remarks_tests", + size = "small", + srcs = glob(["Remarks/*.cpp"]), + deps = [ + "//llvm:BitReader", + "//llvm:Remarks", + "//llvm:Support", + "//llvm:gtest", + "//llvm:gtest_main", + "//llvm:remark_linker", + ], +) + +cc_test( + name = "profile_data_tests", + size = "small", + srcs = glob(["ProfileData/*.cpp"]), + deps = [ + "//llvm:Core", + "//llvm:Coverage", + "//llvm:ProfileData", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "support_tests", + size = "small", + srcs = glob( + [ + "Support/*.cpp", + "Support/*.h", + ], + exclude = [ + "Support/ParallelTest.cpp", + ], + ), + args = ["--gtest_filter=-ProgramTest.CreateProcessTrailingSlash"], + copts = [ + "$(STACK_FRAME_UNLIMITED)", + ], + linkstatic = 1, + tags = [ + "local", # Not compatible with the sandbox on MacOS + ], + visibility = ["//visibility:private"], + deps = [ + "//llvm:AllTargetsCodeGens", + "//llvm:BinaryFormat", + "//llvm:Core", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:config", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "support_parallel_tests", + size = "small", + srcs = ["Support/ParallelTest.cpp"], + copts = [ + "$(STACK_FRAME_UNLIMITED)", + ], + linkstatic = 1, + deps = [ + "//llvm:AllTargetsCodeGens", + "//llvm:Support", + "//llvm:config", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "tablegen_tests", + size = "small", + srcs = glob([ + "TableGen/*.cpp", + ]), + deps = [ + ":automata_automata_gen", + ":automata_tables_gen", + "//llvm:Support", + "//llvm:TableGen", + "//llvm:gtest", + "//llvm:gtest_main", + "//llvm:tblgen", + ], +) + +cc_test( + name = "target_aarch64_tests", + size = "small", + srcs = glob(["Target/AArch64/*.cpp"]), + copts = [ + "$(STACK_FRAME_UNLIMITED)", + ], + deps = [ + "//llvm:AArch64CodeGen", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "transforms_tests", + size = "small", + srcs = glob([ + "Transforms/IPO/*.cpp", + "Transforms/IPO/*.h", + "Transforms/Utils/*.cpp", + ]), + deps = [ + "//llvm:Analysis", + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:IPO", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:TransformUtils", + "//llvm:gtest", + "//llvm:gtest_main", + ], +) + +cc_test( + name = "llvm_exegesis_tests", + size = "small", + srcs = glob([ + "tools/llvm-exegesis/*.cpp", + "tools/llvm-exegesis/*.h", + "tools/llvm-exegesis/X86/*.cpp", + "tools/llvm-exegesis/X86/*.h", + ]) + [ + "tools/llvm-exegesis/Common/AssemblerUtils.h", + ], + copts = ["-DHAVE_LIBPFM=1"], + linkopts = ["-lpfm"], + tags = [ + "manual", # External dependency (libpfm4) + "nobuildkite", # TODO(chandlerc): Add support for fetching and building libpfm4 and enable this. + ], + deps = [ + "//llvm:AllTargetsCodeGens", + "//llvm:AllTargetsDisassemblers", + "//llvm:MC", + "//llvm:MCDisassembler", + "//llvm:Support", + "//llvm:TestingSupport", + "//llvm:gtest", + "//llvm:gtest_main", + "//llvm:llvm-exegesis-lib", + ], +) diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD b/utils/bazel/llvm-project-overlay/mlir/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD @@ -0,0 +1,4466 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Description: +# The MLIR "Multi-Level Intermediate Representation" Compiler Infrastructure + +load(":tblgen.bzl", "gentbl") +load(":linalggen.bzl", "genlinalg") + +package( + default_visibility = [":friends"], + licenses = ["notice"], +) + +package_group( + name = "subpackages", + packages = ["//mlir/..."], +) + +package_group( + name = "friends", + packages = ["//..."], +) + +exports_files([ + "LICENSE.TXT", + "include/mlir/Dialect/LLVMIR/LLVMOps.td", + "run_lit.sh", +]) + +[ + gentbl( + name = name + "IncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/IR/" + name + ".h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/IR/" + name + ".cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/IR/" + name + ".td", + td_srcs = [ + ":OpBaseTdFiles", + ], + ) + for name in [ + "OpAsmInterface", + "RegionKindInterface", + "SymbolInterfaces", + ] +] + +cc_library( + name = "IR", + srcs = glob([ + "lib/IR/*.cpp", + "lib/IR/*.h", + ]), + hdrs = glob([ + "include/mlir/IR/*.h", + ]) + [ + "include/mlir/Interfaces/CallInterfaces.h", + "include/mlir/Interfaces/DecodeAttributesInterfaces.h", + "include/mlir/Interfaces/FoldInterfaces.h", + ], + includes = ["include"], + deps = [ + ":CallOpInterfacesIncGen", + ":InferTypeOpInterfaceIncGen", + ":OpAsmInterfaceIncGen", + ":RegionKindInterfaceIncGen", + ":SideEffectInterfacesIncGen", + ":Support", + ":SymbolInterfacesIncGen", + "//llvm:Support", + ], +) + +cc_library( + name = "Pass", + srcs = glob([ + "lib/Pass/*.cpp", + "lib/Pass/*.h", + ]), + hdrs = glob([ + "include/mlir/Pass/*.h", + ]), + includes = ["include"], + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "//conditions:default": [ + "-lpthread", + "-ldl", + ], + }), + deps = [ + ":IR", + ":Support", + "//llvm:Support", + ], +) + +# TODO(ntv): Update these to enable simplifying the cmake and build files. +cc_library( + name = "EDSC", + srcs = [ + "lib/EDSC/Builders.cpp", + ], + hdrs = [ + "include/mlir/EDSC/Builders.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "CAPIIR", + srcs = [ + "lib/CAPI/IR/AffineExpr.cpp", + "lib/CAPI/IR/AffineMap.cpp", + "lib/CAPI/IR/Diagnostics.cpp", + "lib/CAPI/IR/IR.cpp", + "lib/CAPI/IR/Pass.cpp", + "lib/CAPI/IR/StandardAttributes.cpp", + "lib/CAPI/IR/StandardTypes.cpp", + "lib/CAPI/IR/Support.cpp", + "lib/CAPI/Standard/StandardDialect.cpp", + ], + hdrs = [ + "include/mlir-c/AffineExpr.h", + "include/mlir-c/AffineMap.h", + "include/mlir-c/Diagnostics.h", + "include/mlir-c/IR.h", + "include/mlir-c/Pass.h", + "include/mlir-c/StandardAttributes.h", + "include/mlir-c/StandardDialect.h", + "include/mlir-c/StandardTypes.h", + "include/mlir-c/Support.h", + "include/mlir/CAPI/AffineExpr.h", + "include/mlir/CAPI/AffineMap.h", + "include/mlir/CAPI/Diagnostics.h", + "include/mlir/CAPI/IR.h", + "include/mlir/CAPI/Pass.h", + "include/mlir/CAPI/Support.h", + "include/mlir/CAPI/Utils.h", + "include/mlir/CAPI/Wrap.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":Parser", + ":Pass", + ":StandardOps", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "CAPITransforms", + srcs = [ + "lib/CAPI/Transforms/Passes.cpp", + ], + hdrs = [ + "include/mlir-c/Transforms.h", + ], + includes = ["include"], + deps = [ + ":CAPIIR", + ":Pass", + ":Transforms", + ":TransformsPassIncGen", + ], +) + +cc_library( + name = "MLIRBindingsPythonExtension", + hdrs = [ + "include/mlir-c/Bindings/Python/Interop.h", + ], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":CAPIIR", + "@python_runtime//:headers", + ], +) + +cc_library( + name = "CAPIRegistration", + srcs = [ + "lib/CAPI/Registration/Registration.cpp", + ], + hdrs = [ + "include/mlir-c/Registration.h", + ], + includes = ["include"], + deps = [ + ":AllPassesAndDialectsNoRegistration", + ":CAPIIR", + ], +) + +filegroup( + name = "OpBaseTdFiles", + srcs = [ + "include/mlir/Dialect/StandardOps/IR/StandardOpsBase.td", + "include/mlir/IR/OpBase.td", + ], +) + +##---------------------------------------------------------------------------## +# Affine dialect. +##---------------------------------------------------------------------------## + +filegroup( + name = "PassBaseTdFiles", + srcs = [ + "include/mlir/Pass/PassBase.td", + ], +) + +filegroup( + name = "AffineOpsTdFiles", + srcs = [ + "include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td", + "include/mlir/Dialect/Affine/IR/AffineOps.td", + "include/mlir/Interfaces/ControlFlowInterfaces.td", + "include/mlir/Interfaces/LoopLikeInterface.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "AffineOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/Affine/IR/AffineOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/Affine/IR/AffineOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/Affine/IR/AffineOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Affine/IR/AffineOps.td", + td_srcs = [ + ":AffineOpsTdFiles", + ], +) + +gentbl( + name = "AffineMemoryOpInterfacesIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td", + td_srcs = [ + ":AffineOpsTdFiles", + ], +) + +##---------------------------------------------------------------------------## +# Async dialect. +##---------------------------------------------------------------------------## + +filegroup( + name = "AsyncOpsTdFiles", + srcs = [ + "include/mlir/Dialect/Async/IR/AsyncBase.td", + "include/mlir/Dialect/Async/IR/AsyncOps.td", + "include/mlir/Interfaces/ControlFlowInterfaces.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "AsyncOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/Async/IR/AsyncOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/Async/IR/AsyncOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/Async/IR/AsyncOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Async/IR/AsyncOps.td", + td_srcs = [ + ":AsyncOpsTdFiles", + ], +) + +##---------------------------------------------------------------------------## +# AVX512 dialect. +##---------------------------------------------------------------------------## + +filegroup( + name = "AVX512TdFiles", + srcs = [ + "include/mlir/Dialect/AVX512/AVX512.td", + "include/mlir/Dialect/LLVMIR/LLVMOpBase.td", + "include/mlir/IR/OpBase.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ], +) + +gentbl( + name = "AVX512IncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-dialect-decls -dialect=avx512", + "include/mlir/Dialect/AVX512/AVX512Dialect.h.inc", + ), + ( + "-gen-op-decls", + "include/mlir/Dialect/AVX512/AVX512.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/AVX512/AVX512.cpp.inc", + ), + ( + "-gen-op-doc", + "g3doc/Dialects/AVX512/AVX512.md", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/AVX512/AVX512.td", + td_srcs = [ + ":AVX512TdFiles", + ], +) + +cc_library( + name = "AVX512", + srcs = [ + "lib/Dialect/AVX512/IR/AVX512Dialect.cpp", + ], + hdrs = [ + "include/mlir/Dialect/AVX512/AVX512Dialect.h", + ], + includes = ["include"], + deps = [ + ":AVX512IncGen", + ":IR", + ":SideEffectInterfaces", + ":VectorOps", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "AVX512ToLLVM", + srcs = glob([ + "lib/Conversion/AVX512ToLLVM/*.cpp", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/AVX512ToLLVM/*.h", + ]), + includes = ["include"], + deps = [ + ":AVX512", + ":ConversionPassIncGen", + ":EDSC", + ":IR", + ":LLVMAVX512", + ":LLVMDialect", + ":Pass", + ":StandardOps", + ":StandardToLLVM", + ":Support", + ":Transforms", + ":VectorOps", + ":VectorToLLVM", + ":VectorToSCF", + "//llvm:Core", + "//llvm:Support", + ], +) + +filegroup( + name = "SCFTdFiles", + srcs = [ + "include/mlir/Dialect/SCF/SCFOps.td", + "include/mlir/Interfaces/ControlFlowInterfaces.td", + "include/mlir/Interfaces/LoopLikeInterface.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "SCFIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/SCF/SCFOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/SCF/SCFOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/SCF/SCFOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/SCF/SCFOps.td", + td_srcs = [ + ":SCFTdFiles", + ], +) + +gentbl( + name = "SCFPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name SCF", + "include/mlir/Dialect/SCF/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/SCF/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "SCFTransforms", + srcs = glob([ + "lib/Dialect/SCF/Transforms/*.cpp", + "lib/Dialect/SCF/Transforms/*.h", + ]), + hdrs = ["include/mlir/Dialect/SCF/Passes.h"], + includes = ["include"], + deps = [ + ":Affine", + ":IR", + ":Pass", + ":SCFDialect", + ":SCFPassIncGen", + ":StandardOps", + ":Transforms", + "//llvm:Support", + ], +) + +filegroup( + name = "StdOpsTdFiles", + srcs = [ + "include/mlir/Dialect/StandardOps/IR/Ops.td", + "include/mlir/IR/OpAsmInterface.td", + "include/mlir/IR/SymbolInterfaces.td", + "include/mlir/Interfaces/CallInterfaces.td", + "include/mlir/Interfaces/ControlFlowInterfaces.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + "include/mlir/Interfaces/VectorInterfaces.td", + "include/mlir/Interfaces/ViewLikeInterface.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "StandardOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/StandardOps/IR/Ops.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/StandardOps/IR/Ops.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/StandardOps/IR/OpsDialect.h.inc", + ), + ( + "-gen-enum-decls", + "include/mlir/Dialect/StandardOps/IR/OpsEnums.h.inc", + ), + ( + "-gen-enum-defs", + "include/mlir/Dialect/StandardOps/IR/OpsEnums.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/StandardOps/IR/Ops.td", + td_srcs = [ + ":StdOpsTdFiles", + ], +) + +cc_library( + name = "Dialect", + srcs = glob([ + "lib/Dialect/*.cpp", + "lib/Dialect/*.h", + ]), + hdrs = glob([ + "include/mlir/Dialect/*.h", + ]), + includes = ["include"], + deps = [ + ":IR", + "//llvm:Support", + ], +) + +cc_library( + name = "DialectUtils", + srcs = glob([ + "lib/Dialect/Utils/*.cpp", + "lib/Dialect/Utils/*.h", + ]), + hdrs = glob([ + "include/mlir/Dialect/Utils/*.h", + ]), + includes = ["include"], + deps = [ + ":IR", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "Affine", + srcs = glob( + [ + "lib/Dialect/Affine/IR/*.cpp", + "lib/Dialect/Affine/IR/*.h", + "lib/Dialect/Affine/EDSC/*.cpp", + ], + ) + [ + "include/mlir/Transforms/InliningUtils.h", + ], + hdrs = glob([ + "include/mlir/Dialect/Affine/IR/*.h", + "include/mlir/Dialect/Affine/EDSC/*.h", + ]), + includes = ["include"], + deps = [ + ":AffineMemoryOpInterfacesIncGen", + ":AffineOpsIncGen", + ":EDSC", + ":IR", + ":LoopLikeInterface", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "Async", + srcs = glob([ + "lib/Dialect/Async/IR/*.cpp", + ]), + hdrs = glob([ + "include/mlir/Dialect/Async/IR/*.h", + ]), + includes = ["include"], + deps = [ + ":AsyncOpsIncGen", + ":ControlFlowInterfaces", + ":Dialect", + ":IR", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + "//llvm:Support", + ], +) + +gentbl( + name = "AsyncPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name Async", + "include/mlir/Dialect/Async/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Async/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "AsyncTransforms", + srcs = glob([ + "lib/Dialect/Async/Transforms/*.cpp", + "lib/Dialect/Async/Transforms/*.h", + ]), + hdrs = ["include/mlir/Dialect/Async/Passes.h"], + includes = ["include"], + deps = [ + ":Async", + ":AsyncPassIncGen", + ":IR", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":Support", + ":TransformUtils", + ":Transforms", + ":TransformsPassIncGen", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "AffineUtils", + srcs = glob( + [ + "lib/Dialect/Affine/Utils/*.cpp", + "lib/Dialect/Affine/Utils/*.h", + ], + ), + hdrs = ["include/mlir/Dialect/Affine/Utils.h"], + includes = ["include"], + deps = [ + ":Affine", + ":IR", + ":Support", + ":TransformUtils", + "//llvm:Support", + ], +) + +gentbl( + name = "AffinePassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name Affine", + "include/mlir/Dialect/Affine/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Affine/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "AffineTransforms", + srcs = glob([ + "lib/Dialect/Affine/Transforms/*.cpp", + "lib/Dialect/Affine/Transforms/*.h", + ]), + hdrs = [ + "include/mlir/Dialect/Affine/Passes.h", + ], + includes = ["include"], + deps = [ + ":Affine", + ":AffinePassIncGen", + ":AffineUtils", + ":Analysis", + ":IR", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":Support", + ":Transforms", + ":VectorOps", + "//llvm:Support", + ], +) + +gentbl( + name = "ConversionPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name Conversion", + "include/mlir/Conversion/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Conversion/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "ConversionPasses", + hdrs = ["include/mlir/Conversion/Passes.h"], + includes = ["include"], + deps = [ + ":AVX512ToLLVM", + ":AffineToStandard", + ":AsyncToLLVM", + ":ConversionPassIncGen", + ":GPUToGPURuntimeTransforms", + ":GPUToNVVMTransforms", + ":GPUToROCDLTransforms", + ":GPUToSPIRVTransforms", + ":GPUToVulkanTransforms", + ":LinalgToLLVM", + ":LinalgToSPIRV", + ":LinalgToStandard", + ":OpenMPToLLVM", + ":PDLToPDLInterp", + ":SCFToGPUPass", + ":SCFToStandard", + ":SPIRVToLLVM", + ":ShapeToStandard", + ":StandardToLLVM", + ":StandardToSPIRVTransforms", + ":VectorToLLVM", + ":VectorToROCDL", + ":VectorToSCF", + ":VectorToSPIRV", + ], +) + +cc_library( + name = "AsyncToLLVM", + srcs = glob([ + "lib/Conversion/AsyncToLLVM/*.cpp", + "lib/Conversion/AsyncToLLVM/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob(["include/mlir/Conversion/AsyncToLLVM/*.h"]), + includes = ["include"], + deps = [ + ":Async", + ":ConversionPassIncGen", + ":IR", + ":LLVMDialect", + ":Pass", + ":StandardOps", + ":Support", + ":Transforms", + "//llvm:Support", + ], +) + +cc_library( + name = "AffineToStandard", + srcs = glob([ + "lib/Conversion/AffineToStandard/*.cpp", + "lib/Conversion/AffineToStandard/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob(["include/mlir/Conversion/AffineToStandard/*.h"]), + includes = ["include"], + deps = [ + ":Affine", + ":ConversionPassIncGen", + ":IR", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":Support", + ":Transforms", + ":VectorOps", + ], +) + +alias( + name = "AffineToStandardTransforms", + actual = "AffineToStandard", +) + +# SDBM dialect only contains attribute components that can be constructed given +# a dialect object, so whenever it is used it must also be registered. Therefore +# we don't split out the registration library for it. +cc_library( + name = "SDBM", + srcs = glob([ + "lib/Dialect/SDBM/*.cpp", + "lib/Dialect/SDBM/*.h", + ]), + hdrs = glob([ + "include/mlir/Dialect/SDBM/*.h", + ]), + includes = ["include"], + deps = [ + ":IR", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "SCFDialect", + srcs = glob( + [ + "lib/Dialect/SCF/*.cpp", + "lib/Dialect/SCF/*.h", + "lib/Dialect/SCF/EDSC/*.cpp", + ], + ), + hdrs = glob([ + "include/mlir/Dialect/SCF/*.h", + "include/mlir/Dialect/SCF/EDSC/*.h", + ]), + includes = ["include"], + deps = [ + ":ControlFlowInterfaces", + ":EDSC", + ":IR", + ":LoopLikeInterface", + ":Pass", + ":SCFIncGen", + ":SCFPassIncGen", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "LoopLikeInterface", + srcs = ["lib/Interfaces/LoopLikeInterface.cpp"], + hdrs = ["include/mlir/Interfaces/LoopLikeInterface.h"], + includes = ["include"], + deps = [ + ":IR", + ":LoopLikeInterfaceIncGen", + ], +) + +cc_library( + name = "VectorInterfaces", + srcs = ["lib/Interfaces/VectorInterfaces.cpp"], + hdrs = ["include/mlir/Interfaces/VectorInterfaces.h"], + includes = ["include"], + deps = [ + ":IR", + ":VectorInterfacesIncGen", + ], +) + +cc_library( + name = "ViewLikeInterface", + srcs = ["lib/Interfaces/ViewLikeInterface.cpp"], + hdrs = ["include/mlir/Interfaces/ViewLikeInterface.h"], + includes = ["include"], + deps = [ + ":IR", + ":ViewLikeInterfaceIncGen", + ], +) + +cc_library( + name = "CopyOpInterface", + srcs = ["lib/Interfaces/CopyOpInterface.cpp"], + hdrs = ["include/mlir/Interfaces/CopyOpInterface.h"], + includes = ["include"], + deps = [ + ":CopyOpInterfaceIncGen", + ":IR", + ], +) + +filegroup( + name = "ShapeOpsTdFiles", + srcs = [ + ":StdOpsTdFiles", + "include/mlir/Dialect/Shape/IR/ShapeBase.td", + "include/mlir/Dialect/Shape/IR/ShapeOps.td", + "include/mlir/Interfaces/InferTypeOpInterface.td", + ], +) + +gentbl( + name = "ShapeOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/Shape/IR/ShapeOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/Shape/IR/ShapeOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/Shape/IR/ShapeOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Shape/IR/ShapeOps.td", + td_srcs = [ + ":StdOpsTdFiles", + "include/mlir/Dialect/Shape/IR/ShapeBase.td", + "include/mlir/Interfaces/InferTypeOpInterface.td", + ], +) + +gentbl( + name = "MLIRShapeCanonicalizationIncGen", + strip_include_prefix = "include/mlir/Dialect/Shape/IR", + tbl_outs = [ + ( + "-gen-rewriters", + "include/mlir/Dialect/Shape/IR/ShapeCanonicalization.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "lib/Dialect/Shape/IR/ShapeCanonicalization.td", + td_srcs = [ + ":StdOpsTdFiles", + "include/mlir/Dialect/Shape/IR/ShapeBase.td", + "include/mlir/Dialect/Shape/IR/ShapeOps.td", + "include/mlir/Interfaces/InferTypeOpInterface.td", + ], +) + +cc_library( + name = "Shape", + srcs = glob(["lib/Dialect/Shape/IR/*.cpp"]), + hdrs = ["include/mlir/Dialect/Shape/IR/Shape.h"], + includes = ["include"], + deps = [ + ":CallOpInterfaces", + ":CommonFolders", + ":ControlFlowInterfaces", + ":Dialect", + ":IR", + ":InferTypeOpInterface", + ":MLIRShapeCanonicalizationIncGen", + ":ShapeOpsIncGen", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + "//llvm:Support", + ], +) + +gentbl( + name = "ShapeToStandardGen", + strip_include_prefix = "lib/Conversion/ShapeToStandard", + tbl_outs = [ + ( + "-gen-rewriters", + "lib/Conversion/ShapeToStandard/ShapeToStandard.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "lib/Conversion/ShapeToStandard/ShapeToStandard.td", + td_srcs = [ + ":ShapeOpsTdFiles", + ], +) + +cc_library( + name = "ShapeToStandard", + srcs = glob([ + "lib/Conversion/ShapeToStandard/*.cpp", + "lib/Conversion/ShapeToStandard/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = ["include/mlir/Conversion/ShapeToStandard/ShapeToStandard.h"], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":IR", + ":Pass", + ":SCFDialect", + ":Shape", + ":ShapeToStandardGen", + ":StandardOps", + ":Support", + ":Transforms", + ], +) + +gentbl( + name = "ShapeTransformsPassIncGen", + strip_include_prefix = "include", + tbl_outs = [( + "-gen-pass-decls -name Shape", + "include/mlir/Dialect/Shape/Transforms/Passes.h.inc", + )], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Shape/Transforms/Passes.td", + td_srcs = [":PassBaseTdFiles"], +) + +cc_library( + name = "ShapeTransforms", + srcs = glob([ + "lib/Dialect/Shape/Transforms/*.cpp", + "lib/Dialect/Shape/Transforms/*.h", + ]), + hdrs = ["include/mlir/Dialect/Shape/Transforms/Passes.h"], + includes = ["include"], + deps = [ + ":IR", + ":Pass", + ":Shape", + ":ShapeTransformsPassIncGen", + ":StandardOps", + ":Transforms", + ], +) + +cc_library( + name = "StandardOps", + srcs = glob( + [ + "lib/Dialect/StandardOps/IR/*.cpp", + "lib/Dialect/StandardOps/IR/*.h", + "lib/Dialect/StandardOps/EDSC/*.cpp", + ], + ), + hdrs = glob([ + "include/mlir/Dialect/StandardOps/IR/*.h", + "include/mlir/Dialect/StandardOps/EDSC/*.h", + ]) + ["include/mlir/Transforms/InliningUtils.h"], + includes = ["include"], + deps = [ + ":CallOpInterfaces", + ":CommonFolders", + ":ControlFlowInterfaces", + ":EDSC", + ":IR", + ":SideEffectInterfaces", + ":StandardOpsIncGen", + ":Support", + ":VectorInterfaces", + ":ViewLikeInterface", + "//llvm:Support", + ], +) + +gentbl( + name = "StandardOpsTransformsPassIncGen", + strip_include_prefix = "include", + tbl_outs = [( + "-gen-pass-decls -name Standard", + "include/mlir/Dialect/StandardOps/Transforms/Passes.h.inc", + )], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/StandardOps/Transforms/Passes.td", + td_srcs = [":PassBaseTdFiles"], +) + +cc_library( + name = "StandardOpsTransforms", + srcs = glob([ + "lib/Dialect/StandardOps/Transforms/*.cpp", + "lib/Dialect/StandardOps/Transforms/*.h", + ]), + hdrs = glob(["include/mlir/Dialect/StandardOps/Transforms/*.h"]), + includes = ["include"], + deps = [ + ":Analysis", + ":ControlFlowInterfaces", + ":IR", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":StandardOpsTransformsPassIncGen", + ":Support", + ":Transforms", + "//llvm:Support", + ], +) + +cc_library( + name = "VectorOps", + srcs = glob( + [ + "lib/Dialect/Vector/*.cpp", + "lib/Dialect/Vector/*.h", + "lib/Dialect/Vector/EDSC/*.cpp", + "lib/Dialect/Vector/EDSC/*.h", + ], + ), + hdrs = glob([ + "include/mlir/Dialect/Vector/*.h", + "include/mlir/Dialect/Vector/EDSC/*.h", + ]), + includes = ["include"], + deps = [ + ":Affine", + ":Analysis", + ":DialectUtils", + ":EDSC", + ":IR", + ":LinalgOps", + ":SCFDialect", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + ":VectorInterfaces", + ":VectorOpsIncGen", + ":ViewLikeInterface", + "//llvm:Support", + ], +) + +cc_library( + name = "Support", + srcs = glob( + [ + "lib/Support/*.cpp", + "lib/Support/*.h", + ], + exclude = [ + # TODO(jpienaar): Move this out, else Support depends on Analysis/ + "lib/Support/MlirOptMain.cpp", + ], + ), + hdrs = glob( + [ + "include/mlir/Support/*.h", + ], + exclude = [ + "include/mlir/Support/MlirOptMain.h", + ], + ), + includes = ["include"], + deps = [ + "//llvm:Support", + ], +) + +cc_library( + name = "ParserTokenKinds", + # strip_include_prefix does not apply to textual_hdrs. + hdrs = ["lib/Parser/TokenKinds.def"], + strip_include_prefix = "lib/Parser", + textual_hdrs = ["lib/Parser/TokenKinds.def"], +) + +cc_library( + name = "Parser", + srcs = glob([ + "lib/Parser/*.cpp", + "lib/Parser/*.h", + ]), + hdrs = [ + "include/mlir/Parser.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":ParserTokenKinds", + ":Support", + "//llvm:Support", + ], +) + +filegroup( + name = "LLVMAVX512TdFiles", + srcs = [ + "include/mlir/Dialect/LLVMIR/LLVMAVX512.td", + ":LLVMOpsTdFiles", + ], +) + +gentbl( + name = "LLVMAVX512IncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-dialect-decls -dialect=llvm_avx512", + "include/mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h.inc", + ), + ( + "-gen-op-decls", + "include/mlir/Dialect/LLVMIR/LLVMAVX512.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/LLVMIR/LLVMAVX512.cpp.inc", + ), + ( + "-gen-op-doc", + "g3doc/Dialects/LLVMIR/LLVMAVX512.md", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/LLVMAVX512.td", + td_srcs = [ + ":LLVMAVX512TdFiles", + ], +) + +cc_library( + name = "LLVMAVX512", + srcs = [ + "lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp", + ], + hdrs = [ + "include/mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":LLVMAVX512IncGen", + ":LLVMDialect", + "//llvm:Core", + "//llvm:Support", + ], +) + +gentbl( + name = "LLVMAVX512ConversionIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-llvmir-conversions", + "include/mlir/Dialect/LLVMIR/LLVMAVX512Conversions.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/LLVMAVX512.td", + td_srcs = [ + ":LLVMAVX512TdFiles", + ], +) + +cc_library( + name = "TargetLLVMAVX512Intr", + srcs = [ + "lib/Target/LLVMIR/LLVMAVX512Intr.cpp", + ], + includes = ["include"], + deps = [ + ":IR", + ":LLVMAVX512", + ":LLVMAVX512ConversionIncGen", + ":LLVMIRModuleTranslation", + ":Translation", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "LLVMDialect", + srcs = glob( + [ + "lib/Dialect/LLVMIR/IR/*.cpp", + "lib/Dialect/LLVMIR/IR/*.h", + ], + exclude = [ + "lib/Dialect/LLVMIR/IR/*AVX512*.cpp", + "lib/Dialect/LLVMIR/IR/*AVX512*.h", + "lib/Dialect/LLVMIR/IR/NVVM*.cpp", + "lib/Dialect/LLVMIR/IR/NVVM*.h", + "lib/Dialect/LLVMIR/IR/ROCDL*.cpp", + "lib/Dialect/LLVMIR/IR/ROCDL*.h", + ], + ), + hdrs = glob( + [ + "include/mlir/Dialect/LLVMIR/*.h", + ], + exclude = [ + "include/mlir/Dialect/LLVMIR/*AVX512*.h", + "include/mlir/Dialect/LLVMIR/NVVM*.h", + "include/mlir/Dialect/LLVMIR/ROCDL*.h", + ], + ), + includes = ["include"], + deps = [ + ":ControlFlowInterfaces", + ":IR", + ":LLVMOpsIncGen", + ":SideEffectInterfaces", + ":Support", + "//llvm:AsmParser", + "//llvm:BitReader", + "//llvm:BitWriter", + "//llvm:Core", + "//llvm:Support", + ], +) + +gentbl( + name = "LLVMPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name LLVM", + "include/mlir/Dialect/LLVMIR/Transforms/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/Transforms/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "LLVMIRTransforms", + srcs = glob([ + "lib/Dialect/LLVMIR/Transforms/*.cpp", + "lib/Dialect/LLVMIR/Transforms/*.h", + ]), + hdrs = glob(["include/mlir/Dialect/LLVMIR/Transforms/*.h"]), + includes = ["include"], + deps = [ + ":IR", + ":LLVMDialect", + ":LLVMPassIncGen", + ":Pass", + ], +) + +filegroup( + name = "GPUOpsTdFiles", + srcs = [ + "include/mlir/Dialect/GPU/GPUBase.td", + "include/mlir/Dialect/GPU/GPUOps.td", + "include/mlir/Dialect/LLVMIR/LLVMOpBase.td", + "include/mlir/IR/SymbolInterfaces.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "ParallelLoopMapperAttrGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-struct-attr-decls", + "include/mlir/Dialect/GPU/ParallelLoopMapperAttr.h.inc", + ), + ( + "-gen-struct-attr-defs", + "include/mlir/Dialect/GPU/ParallelLoopMapperAttr.cpp.inc", + ), + ( + "-gen-enum-decls", + "include/mlir/Dialect/GPU/ParallelLoopMapperEnums.h.inc", + ), + ( + "-gen-enum-defs", + "include/mlir/Dialect/GPU/ParallelLoopMapperEnums.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/GPU/ParallelLoopMapperAttr.td", + td_srcs = [ + ":GPUOpsTdFiles", + ":AffineOpsTdFiles", + ], +) + +gentbl( + name = "GPUBaseIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-dialect-decls -dialect=gpu", + "include/mlir/Dialect/GPU/GPUOpsDialect.h.inc", + ), + ( + "-gen-op-interface-decls", + "include/mlir/Dialect/GPU/GPUOpInterfaces.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Dialect/GPU/GPUOpInterfaces.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/GPU/GPUBase.td", + td_srcs = [ + ":GPUOpsTdFiles", + ], +) + +gentbl( + name = "GPUOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/GPU/GPUOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/GPU/GPUOps.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/GPU/GPUOps.td", + td_srcs = [ + ":GPUOpsTdFiles", + ], +) + +cc_library( + name = "GPUDialect", + srcs = glob( + [ + "lib/Dialect/GPU/IR/*.cpp", + "lib/Dialect/GPU/IR/*.h", + ], + ), + hdrs = glob([ + "include/mlir/Dialect/GPU/GPUDialect.h", + ]), + includes = ["include"], + deps = [ + ":GPUBaseIncGen", + ":GPUOpsIncGen", + ":IR", + ":LLVMDialect", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + "//llvm:Support", + ], +) + +gentbl( + name = "GPUPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name GPU", + "include/mlir/Dialect/GPU/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/GPU/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "GPUTransforms", + srcs = glob( + [ + "lib/Dialect/GPU/Transforms/*.cpp", + "lib/Dialect/GPU/Transforms/*.h", + ], + ), + hdrs = [ + "include/mlir/Dialect/GPU/MemoryPromotion.h", + "include/mlir/Dialect/GPU/ParallelLoopMapper.h", + "include/mlir/Dialect/GPU/Passes.h", + "include/mlir/Dialect/GPU/Utils.h", + ], + includes = ["include"], + deps = [ + ":EDSC", + ":GPUDialect", + ":GPUPassIncGen", + ":IR", + ":ParallelLoopMapperAttrGen", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":Support", + ":Transforms", + "//llvm:Support", + ], +) + +filegroup( + name = "LLVMOpsTdFiles", + srcs = [ + "include/mlir/Dialect/LLVMIR/LLVMOpBase.td", + "include/mlir/Dialect/LLVMIR/LLVMOps.td", + "include/mlir/IR/SymbolInterfaces.td", + "include/mlir/Interfaces/ControlFlowInterfaces.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +cc_library( + name = "GPUCommonTransforms", + hdrs = [ + "lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h", + "lib/Conversion/GPUCommon/OpToFuncCallLowering.h", + ], + # TODO(b/155492113): Move back to hdrs once fixed. + textual_hdrs = [ + "lib/Conversion/GPUCommon/GPUOpsLowering.h", + ], + deps = [ + ":GPUDialect", + ":IR", + ":LLVMDialect", + ":StandardOps", + ":StandardToLLVM", + "//llvm:Support", + ], +) + +gentbl( + name = "GPUToNVVMGen", + strip_include_prefix = "lib/Conversion/GPUToNVVM", + tbl_outs = [ + ( + "-gen-rewriters", + "lib/Conversion/GPUToNVVM/GPUToNVVM.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "lib/Conversion/GPUToNVVM/GPUToNVVM.td", + td_srcs = [ + ":GPUOpsTdFiles", + ":NVVMOpsTdFiles", + ], +) + +cc_library( + name = "GPUToNVVMTransforms", + srcs = glob([ + "lib/Conversion/GPUToNVVM/*.cpp", + "lib/Conversion/GPUToNVVM/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/GPUToNVVM/*.h", + ]), + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":GPUCommonTransforms", + ":GPUDialect", + ":GPUToNVVMGen", + ":GPUTransforms", + ":IR", + ":NVVMDialect", + ":Pass", + ":StandardToLLVM", + ":Transforms", + "//llvm:Support", + ], +) + +cc_library( + name = "VectorToROCDL", + srcs = [ + "lib/Conversion/PassDetail.h", + "lib/Conversion/VectorToROCDL/VectorToROCDL.cpp", + ], + hdrs = [ + "include/mlir/Conversion/VectorToROCDL/VectorToROCDL.h", + ], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":GPUDialect", + ":LLVMDialect", + ":Pass", + ":ROCDLDialect", + ":StandardOps", + ":StandardToLLVM", + ":Transforms", + ":VectorOps", + ], +) + +cc_library( + name = "VectorToSPIRV", + srcs = [ + "lib/Conversion/PassDetail.h", + "lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp", + ], + hdrs = [ + "include/mlir/Conversion/VectorToSPIRV/ConvertVectorToSPIRV.h", + "include/mlir/Conversion/VectorToSPIRV/ConvertVectorToSPIRVPass.h", + ], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":Pass", + ":SPIRVDialect", + ":SPIRVLowering", + ":Transforms", + ":VectorOps", + ], +) + +gentbl( + name = "GPUToROCDLTGen", + strip_include_prefix = "lib/Conversion/GPUToROCDL", + tbl_outs = [ + ( + "-gen-rewriters", + "lib/Conversion/GPUToROCDL/GPUToROCDL.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "lib/Conversion/GPUToROCDL/GPUToROCDL.td", + td_srcs = [ + ":GPUOpsTdFiles", + ":ROCDLOpsTdFiles", + ], +) + +cc_library( + name = "GPUToROCDLTransforms", + srcs = [ + "lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp", + "lib/Conversion/PassDetail.h", + ], + hdrs = [ + "include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h", + ], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":GPUCommonTransforms", + ":GPUDialect", + ":GPUToROCDLTGen", + ":GPUTransforms", + ":Pass", + ":ROCDLDialect", + ":StandardToLLVM", + ":Transforms", + ":VectorOps", + ":VectorToLLVM", + ":VectorToROCDL", + ":VectorToSCF", + "//llvm:Support", + ], +) + +cc_library( + name = "GPUToVulkanTransforms", + srcs = [ + "lib/Conversion/GPUToVulkan/ConvertGPULaunchFuncToVulkanLaunchFunc.cpp", + "lib/Conversion/GPUToVulkan/ConvertLaunchFuncToVulkanCalls.cpp", + "lib/Conversion/PassDetail.h", + ], + hdrs = ["include/mlir/Conversion/GPUToVulkan/ConvertGPUToVulkanPass.h"], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":GPUDialect", + ":IR", + ":LLVMDialect", + ":Pass", + ":SPIRVDialect", + ":SPIRVSerialization", + ":StandardOps", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "GPUToGPURuntimeTransforms", + srcs = [ + "lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp", + "lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp", + "lib/Conversion/PassDetail.h", + ], + hdrs = ["include/mlir/Conversion/GPUCommon/GPUCommonPass.h"], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":GPUDialect", + ":IR", + ":LLVMDialect", + ":Pass", + ":SPIRVToLLVM", + ":StandardToLLVM", + ":Support", + ":TargetNVVMIR", + "//llvm:Core", + "//llvm:NVPTXCodeGen", + "//llvm:Support", + "//llvm:Target", + ], +) + +gentbl( + name = "GPUToSPIRVIncGen", + strip_include_prefix = "lib/Conversion/GPUToSPIRV", + tbl_outs = [ + ( + "-gen-rewriters", + "lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "lib/Conversion/GPUToSPIRV/GPUToSPIRV.td", + td_srcs = [ + ":GPUOpsTdFiles", + ":SPIRVOpsTdFiles", + ], +) + +cc_library( + name = "GPUToSPIRVTransforms", + srcs = [ + "lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp", + "lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.cpp", + "lib/Conversion/PassDetail.h", + ], + hdrs = [ + "include/mlir/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.h", + "include/mlir/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.h", + ], + includes = [ + "include", + "lib/Conversions/GPUToSPIRV", + ], + deps = [ + ":ConversionPassIncGen", + ":GPUDialect", + ":GPUToSPIRVIncGen", + ":IR", + ":Pass", + ":SCFDialect", + ":SCFToSPIRV", + ":SPIRVDialect", + ":SPIRVLowering", + ":StandardToSPIRVTransforms", + ":Support", + ":Transforms", + ":VectorToSPIRV", + ], +) + +cc_library( + name = "PDLToPDLInterp", + srcs = glob([ + "lib/Conversion/PDLToPDLInterp/*.cpp", + "lib/Conversion/PDLToPDLInterp/*.h", + ]) + [ + "lib/Conversion/PassDetail.h", + ], + hdrs = [ + "include/mlir/Conversion/PDLToPDLInterp/PDLToPDLInterp.h", + ], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":IR", + ":InferTypeOpInterface", + ":PDLDialect", + ":PDLInterpDialect", + ":Pass", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "SPIRVToLLVM", + srcs = glob([ + "lib/Conversion/SPIRVToLLVM/*.cpp", + ]) + [ + "lib/Conversion/PassDetail.h", + ], + hdrs = glob([ + "include/mlir/Conversion/SPIRVToLLVM/*.h", + ]), + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":GPUDialect", + ":IR", + ":LLVMDialect", + ":Pass", + ":SPIRVDialect", + ":StandardOps", + ":StandardToLLVM", + ":Support", + ":Transforms", + "//llvm:Support", + ], +) + +gentbl( + name = "LLVMOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/LLVMIR/LLVMOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/LLVMIR/LLVMOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc", + ), + ( + "-gen-enum-decls", + "include/mlir/Dialect/LLVMIR/LLVMOpsEnums.h.inc", + ), + ( + "-gen-enum-defs", + "include/mlir/Dialect/LLVMIR/LLVMOpsEnums.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/LLVMOps.td", + td_srcs = [ + ":LLVMOpsTdFiles", + ], +) + +gentbl( + name = "LLVMConversionIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-llvmir-conversions", + "include/mlir/Dialect/LLVMIR/LLVMConversions.inc", + ), + ( + "-gen-enum-to-llvmir-conversions", + "include/mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc", + ), + ( + "-gen-enum-from-llvmir-conversions", + "include/mlir/Dialect/LLVMIR/LLVMConversionEnumsFromLLVM.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/LLVMOps.td", + td_srcs = [ + ":LLVMOpsTdFiles", + ], +) + +cc_library( + name = "NVVMDialect", + srcs = [ + "lib/Dialect/LLVMIR/IR/NVVMDialect.cpp", + ], + hdrs = [ + "include/mlir/Dialect/LLVMIR/NVVMDialect.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":LLVMDialect", + ":NVVMOpsIncGen", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:Support", + ], +) + +filegroup( + name = "NVVMOpsTdFiles", + srcs = [ + "include/mlir/Dialect/LLVMIR/LLVMOpBase.td", + "include/mlir/Dialect/LLVMIR/NVVMOps.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "NVVMOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/LLVMIR/NVVMOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/LLVMIR/NVVMOps.cpp.inc", + ), + ( + "-gen-dialect-decls -dialect=nvvm", + "include/mlir/Dialect/LLVMIR/NVVMOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/NVVMOps.td", + td_srcs = [ + ":NVVMOpsTdFiles", + ], +) + +gentbl( + name = "NVVMConversionIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-llvmir-conversions", + "include/mlir/Dialect/LLVMIR/NVVMConversions.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/NVVMOps.td", + td_srcs = [ + ":NVVMOpsTdFiles", + ], +) + +cc_library( + name = "ROCDLDialect", + srcs = [ + "lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp", + ], + hdrs = [ + "include/mlir/Dialect/LLVMIR/ROCDLDialect.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":LLVMDialect", + ":ROCDLOpsIncGen", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + "//llvm:AsmParser", + "//llvm:Core", + "//llvm:Support", + ], +) + +filegroup( + name = "ROCDLOpsTdFiles", + srcs = [ + "include/mlir/Dialect/LLVMIR/LLVMOpBase.td", + "include/mlir/Dialect/LLVMIR/ROCDLOps.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "ROCDLOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/LLVMIR/ROCDLOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc", + ), + ( + "-gen-dialect-decls -dialect=rocdl", + "include/mlir/Dialect/LLVMIR/ROCDLOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/ROCDLOps.td", + td_srcs = [ + ":ROCDLOpsTdFiles", + ], +) + +gentbl( + name = "ROCDLConversionIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-llvmir-conversions", + "include/mlir/Dialect/LLVMIR/ROCDLConversions.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/LLVMIR/ROCDLOps.td", + td_srcs = [ + ":ROCDLOpsTdFiles", + ], +) + +cc_library( + name = "PDLDialect", + srcs = glob([ + "lib/Dialect/PDL/IR/*.cpp", + "lib/Dialect/PDL/IR/*.h", + ]), + hdrs = glob([ + "include/mlir/Dialect/PDL/IR/*.h", + ]), + includes = ["include"], + deps = [ + ":IR", + ":InferTypeOpInterface", + ":PDLOpsIncGen", + ":SideEffects", + ":Support", + "//llvm:Support", + ], +) + +filegroup( + name = "PDLOpsTdFiles", + srcs = [ + "include/mlir/Dialect/PDL/IR/PDLBase.td", + "include/mlir/Dialect/PDL/IR/PDLOps.td", + "include/mlir/IR/SymbolInterfaces.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "PDLOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/PDL/IR/PDLOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/PDL/IR/PDLOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/PDL/IR/PDLOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/PDL/IR/PDLOps.td", + td_srcs = [ + ":PDLOpsTdFiles", + ], +) + +cc_library( + name = "PDLInterpDialect", + srcs = glob([ + "lib/Dialect/PDLInterp/IR/*.cpp", + "lib/Dialect/PDLInterp/IR/*.h", + ]), + hdrs = glob([ + "include/mlir/Dialect/PDLInterp/IR/*.h", + ]), + includes = ["include"], + deps = [ + ":IR", + ":InferTypeOpInterface", + ":PDLDialect", + ":PDLInterpOpsIncGen", + ":SideEffects", + ":Support", + "//llvm:Support", + ], +) + +filegroup( + name = "PDLInterpOpsTdFiles", + srcs = [ + "include/mlir/Dialect/PDL/IR/PDLBase.td", + "include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "PDLInterpOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.cpp.inc", + ), + ( + "-gen-dialect-decls -dialect=pdl_interp", + "include/mlir/Dialect/PDLInterp/IR/PDLInterpOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td", + td_srcs = [ + ":PDLInterpOpsTdFiles", + ], +) + +# TODO(gcmn): Update SPIRV dependencies so that they map better to cmake files. +filegroup( + name = "SPIRVOpsTdFiles", + srcs = [ + "include/mlir/IR/SymbolInterfaces.td", + "include/mlir/Interfaces/CallInterfaces.td", + "include/mlir/Interfaces/ControlFlowInterfaces.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ] + glob(["include/mlir/Dialect/SPIRV/*.td"]), +) + +gentbl( + name = "SPIRVOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/SPIRV/SPIRVOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/SPIRV/SPIRVOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/SPIRV/SPIRVOpsDialect.h.inc", + ), + ( + "-gen-op-doc", + "g3doc/Dialects/SPIRV/SPIRVOps.md", + ), + ( + "-gen-enum-decls", + "include/mlir/Dialect/SPIRV/SPIRVEnums.h.inc", + ), + ( + "-gen-enum-defs", + "include/mlir/Dialect/SPIRV/SPIRVEnums.cpp.inc", + ), + ( + "-gen-spirv-enum-avail-decls", + "include/mlir/Dialect/SPIRV/SPIRVEnumAvailability.h.inc", + ), + ( + "-gen-spirv-enum-avail-defs", + "include/mlir/Dialect/SPIRV/SPIRVEnumAvailability.cpp.inc", + ), + ( + "-gen-spirv-capability-implication", + "include/mlir/Dialect/SPIRV/SPIRVCapabilityImplication.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/SPIRV/SPIRVOps.td", + td_srcs = [ + ":SPIRVOpsTdFiles", + ], +) + +gentbl( + name = "SPIRVCanonicalizationIncGen", + strip_include_prefix = "lib/Dialect/SPIRV", + tbl_outs = [ + ( + "-gen-rewriters", + "lib/Dialect/SPIRV/SPIRVCanonicalization.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "lib/Dialect/SPIRV/SPIRVCanonicalization.td", + td_srcs = [ + ":SPIRVOpsTdFiles", + "lib/Dialect/SPIRV/SPIRVCanonicalization.td", + ], +) + +gentbl( + name = "SPIRVAvailabilityIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-avail-interface-decls", + "include/mlir/Dialect/SPIRV/SPIRVAvailability.h.inc", + ), + ( + "-gen-avail-interface-defs", + "include/mlir/Dialect/SPIRV/SPIRVAvailability.cpp.inc", + ), + ( + "-gen-spirv-avail-impls", + "include/mlir/Dialect/SPIRV/SPIRVOpAvailabilityImpl.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/SPIRV/SPIRVOps.td", + td_srcs = [ + ":SPIRVOpsTdFiles", + ], +) + +gentbl( + name = "SPIRVTargetAndABIStructGen", + tbl_outs = [ + ( + "-gen-struct-attr-decls", + "include/mlir/Dialect/SPIRV/TargetAndABI.h.inc", + ), + ( + "-gen-struct-attr-defs", + "include/mlir/Dialect/SPIRV/TargetAndABI.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/SPIRV/TargetAndABI.td", + td_srcs = [ + ":SPIRVOpsTdFiles", + ":StdOpsTdFiles", + ], +) + +gentbl( + name = "SPIRVOpUtilsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-spirv-op-utils", + "include/mlir/Dialect/SPIRV/SPIRVOpUtils.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/SPIRV/SPIRVBase.td", + td_srcs = [ + ":SPIRVOpsTdFiles", + ":SPIRVAvailabilityIncGen", + ], +) + +gentbl( + name = "SPIRVSerializationGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-spirv-serialization", + "include/mlir/Dialect/SPIRV/SPIRVSerialization.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/SPIRV/SPIRVOps.td", + td_srcs = [ + ":SPIRVOpsTdFiles", + ], +) + +cc_library( + name = "SPIRVDialect", + srcs = glob( + [ + "lib/Dialect/SPIRV/*.cpp", + "lib/Dialect/SPIRV/*.h", + ], + exclude = [ + "lib/Dialect/SPIRV/SPIRVLowering.cpp", + ], + ) + [ + "include/mlir/Transforms/InliningUtils.h", + ], + hdrs = glob( + [ + "include/mlir/Dialect/SPIRV/*.h", + ], + exclude = [ + "include/mlir/Dialect/SPIRV/SPIRVBinaryUtils.h", + "include/mlir/Dialect/SPIRV/SPIRVLowering.h", + ], + ), + includes = ["include"], + deps = [ + ":CommonFolders", + ":ControlFlowInterfaces", + ":IR", + ":Parser", + ":Pass", + ":SPIRVAvailabilityIncGen", + ":SPIRVCanonicalizationIncGen", + ":SPIRVOpUtilsIncGen", + ":SPIRVOpsIncGen", + ":SPIRVPassIncGen", + ":SPIRVSerializationGen", + ":SPIRVTargetAndABIStructGen", + ":SideEffectInterfaces", + ":Support", + ":Transforms", + "//llvm:Support", + ], +) + +gentbl( + name = "SPIRVPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name SPIRV", + "include/mlir/Dialect/SPIRV/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/SPIRV/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "SPIRVLowering", + srcs = glob([ + "lib/Dialect/SPIRV/Transforms/*.cpp", + "lib/Dialect/SPIRV/Transforms/*.h", + ]) + [ + "lib/Dialect/SPIRV/SPIRVLowering.cpp", + ], + hdrs = [ + "include/mlir/Dialect/SPIRV/Passes.h", + "include/mlir/Dialect/SPIRV/SPIRVLowering.h", + "include/mlir/Dialect/SPIRV/TargetAndABI.h", + ], + includes = [ + "include", + ], + deps = [ + ":IR", + ":Pass", + ":SPIRVDialect", + ":SPIRVPassIncGen", + ":SPIRVTargetAndABIStructGen", + ":StandardOps", + ":Support", + ":Transforms", + "//llvm:Support", + ], +) + +cc_library( + name = "StandardToSPIRVTransforms", + srcs = glob([ + "lib/Conversion/StandardToSPIRV/*.cpp", + "lib/Conversion/StandardToSPIRV/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/StandardToSPIRV/*.h", + ]), + includes = [ + "include", + "lib/Conversion/StandardToSPIRV", + ], + deps = [ + ":ConversionPassIncGen", + ":IR", + ":Pass", + ":SPIRVDialect", + ":SPIRVLowering", + ":StandardOps", + ":Support", + ":Transforms", + ":VectorOps", + "//llvm:Support", + ], +) + +alias( + name = "StandardToSPIRVConversions", + actual = "StandardToSPIRVTransforms", +) + +cc_library( + name = "SPIRVSerialization", + srcs = glob( + [ + "lib/Dialect/SPIRV/Serialization/*.cpp", + ], + exclude = [ + "lib/Dialect/SPIRV/Serialization/TranslateRegistration.cpp", + ], + ), + hdrs = [ + "include/mlir/Dialect/SPIRV/SPIRVBinaryUtils.h", + "include/mlir/Dialect/SPIRV/Serialization.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":SPIRVDialect", + ":SPIRVOpUtilsIncGen", + ":SPIRVOpsIncGen", + ":SPIRVSerializationGen", + ":Support", + ":Transforms", + "//llvm:Support", + ], +) + +cc_library( + name = "SPIRVLinking", + srcs = glob( + [ + "lib/Dialect/SPIRV/Linking/ModuleCombiner/*.cpp", + ], + ), + hdrs = [ + "include/mlir/Dialect/SPIRV/ModuleCombiner.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":SPIRVDialect", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "SPIRVTranslateRegistration", + srcs = [ + "lib/Dialect/SPIRV/Serialization/TranslateRegistration.cpp", + ], + includes = ["include"], + deps = [ + ":IR", + ":Parser", + ":SPIRVDialect", + ":SPIRVSerialization", + ":Support", + ":Translation", + "//llvm:Support", + ], +) + +cc_library( + name = "Rewrite", + srcs = glob([ + "lib/Rewrite/*.cpp", + "lib/Rewrite/*.h", + ]), + hdrs = glob(["include/mlir/Rewrite/*.h"]), + includes = ["include"], + deps = [ + ":IR", + ":Pass", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "TransformUtils", + srcs = glob([ + "lib/Transforms/Utils/*.cpp", + "lib/Transforms/Utils/*.h", + ]), + hdrs = glob([ + "include/mlir/Transforms/*.h", + ]), + includes = ["include"], + deps = [ + ":Affine", + ":Analysis", + ":ControlFlowInterfaces", + ":IR", + ":Pass", + ":Rewrite", + ":SCFDialect", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + ":TransformsPassIncGen", + "//llvm:Support", + ], +) + +gentbl( + name = "DerivedAttributeOpInterfaceIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/DerivedAttributeOpInterface.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/DerivedAttributeOpInterface.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/DerivedAttributeOpInterface.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +cc_library( + name = "DerivedAttributeOpInterface", + srcs = [ + "lib/Interfaces/DerivedAttributeOpInterface.cpp", + ], + hdrs = [ + "include/mlir/Interfaces/DerivedAttributeOpInterface.h", + ], + includes = ["include"], + deps = [ + ":DerivedAttributeOpInterfaceIncGen", + ":IR", + ":Support", + "//llvm:Support", + ], +) + +gentbl( + name = "LoopLikeInterfaceIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/LoopLikeInterface.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/LoopLikeInterface.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/LoopLikeInterface.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "VectorInterfacesIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/VectorInterfaces.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/VectorInterfaces.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/VectorInterfaces.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "ViewLikeInterfaceIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/ViewLikeInterface.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/ViewLikeInterface.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/ViewLikeInterface.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "CopyOpInterfaceIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/CopyOpInterface.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/CopyOpInterface.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/CopyOpInterface.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "TransformsPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name Transforms", + "include/mlir/Transforms/Passes.h.inc", + ), + ( + "-gen-pass-capi-header --prefix Transforms", + "include/mlir/Transforms/Transforms.capi.h.inc", + ), + ( + "-gen-pass-capi-impl --prefix Transforms", + "include/mlir/Transforms/Transforms.capi.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Transforms/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "Transforms", + srcs = glob([ + "lib/Transforms/*.cpp", + "lib/Transforms/*.h", + ]), + hdrs = glob(["include/mlir/Transforms/*.h"]), + includes = ["include"], + deps = [ + ":Affine", + ":Analysis", + ":ControlFlowInterfaces", + ":CopyOpInterface", + ":IR", + ":LinalgOps", + ":LoopLikeInterface", + ":Pass", + ":Rewrite", + ":SCFDialect", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + ":TransformUtils", + ":TransformsPassIncGen", + "//llvm:Support", + ], +) + +cc_library( + name = "CommonFolders", + srcs = [ + ], + hdrs = [ + "include/mlir/Dialect/CommonFolders.h", + ], + includes = ["include"], + deps = [ + ":IR", + "//llvm:Support", + ], +) + +cc_library( + name = "SCFToGPU", + srcs = ["lib/Conversion/SCFToGPU/SCFToGPU.cpp"], + hdrs = ["include/mlir/Conversion/SCFToGPU/SCFToGPU.h"], + includes = ["include"], + deps = [ + ":Affine", + ":AffineToStandard", + ":ConversionPassIncGen", + ":GPUDialect", + ":GPUTransforms", + ":IR", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":Support", + ":TransformUtils", + ":Transforms", + "//llvm:Support", + ], +) + +cc_library( + name = "SCFToGPUPass", + srcs = [ + "lib/Conversion/PassDetail.h", + "lib/Conversion/SCFToGPU/SCFToGPUPass.cpp", + ], + hdrs = [ + "include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h", + ], + includes = ["include"], + deps = [ + ":Affine", + ":ConversionPassIncGen", + ":GPUDialect", + ":Pass", + ":SCFDialect", + ":SCFToGPU", + ":StandardOps", + ":Support", + ":Transforms", + "//llvm:Support", + ], +) + +cc_library( + name = "SCFToSPIRV", + srcs = ["lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp"], + hdrs = ["include/mlir/Conversion/SCFToSPIRV/SCFToSPIRV.h"], + includes = ["include"], + deps = [ + ":Affine", + ":AffineToStandard", + ":ConversionPassIncGen", + ":IR", + ":Pass", + ":SCFDialect", + ":SPIRVDialect", + ":SPIRVLowering", + ":StandardOps", + ":Support", + ":TransformUtils", + ":Transforms", + "//llvm:Support", + ], +) + +cc_library( + name = "SCFToStandard", + srcs = [ + "lib/Conversion/PassDetail.h", + "lib/Conversion/SCFToStandard/SCFToStandard.cpp", + ], + hdrs = [ + "include/mlir/Conversion/SCFToStandard/SCFToStandard.h", + ], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":IR", + ":LLVMDialect", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":Support", + ":TransformUtils", + ":Transforms", + ], +) + +alias( + name = "CFGTransforms", + actual = "SCFToStandard", +) + +cc_library( + name = "StandardToLLVM", + srcs = [ + "lib/Conversion/PassDetail.h", + "lib/Conversion/StandardToLLVM/StandardToLLVM.cpp", + ], + hdrs = [ + "include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h", + "include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h", + ], + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":IR", + ":LLVMDialect", + ":Parser", + ":Pass", + ":StandardOps", + ":StandardOpsTransforms", + ":Support", + ":TransformUtils", + ":Transforms", + "//llvm:Core", + "//llvm:Support", + ], +) + +alias( + name = "LLVMTransforms", + actual = "StandardToLLVM", +) + +gentbl( + name = "CallOpInterfacesIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/CallInterfaces.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/CallInterfaces.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/CallInterfaces.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +cc_library( + name = "CallOpInterfaces", + srcs = [ + "lib/Interfaces/CallInterfaces.cpp", + ], + hdrs = [ + "include/mlir/Interfaces/CallInterfaces.h", + ], + includes = ["include"], + deps = [ + ":CallOpInterfacesIncGen", + ":IR", + ":Support", + "//llvm:Support", + ], +) + +gentbl( + name = "ControlFlowInterfacesIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/ControlFlowInterfaces.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/ControlFlowInterfaces.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/ControlFlowInterfaces.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +cc_library( + name = "ControlFlowInterfaces", + srcs = [ + "lib/Interfaces/ControlFlowInterfaces.cpp", + ], + hdrs = [ + "include/mlir/Interfaces/ControlFlowInterfaces.h", + ], + includes = ["include"], + deps = [ + ":ControlFlowInterfacesIncGen", + ":IR", + ":Support", + "//llvm:Support", + ], +) + +gentbl( + name = "InferTypeOpInterfaceIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/InferTypeOpInterface.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/InferTypeOpInterface.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/InferTypeOpInterface.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +cc_library( + name = "InferTypeOpInterface", + srcs = [ + "lib/Interfaces/InferTypeOpInterface.cpp", + ], + hdrs = [ + "include/mlir/Interfaces/InferTypeOpInterface.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":InferTypeOpInterfaceIncGen", + ":Support", + "//llvm:Support", + ], +) + +gentbl( + name = "SideEffectInterfacesIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Interfaces/SideEffectInterfaces.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Interfaces/SideEffectInterfaces.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Interfaces/SideEffectInterfaces.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +cc_library( + name = "SideEffectInterfaces", + srcs = [ + "lib/Interfaces/SideEffectInterfaces.cpp", + ], + hdrs = [ + "include/mlir/Interfaces/SideEffectInterfaces.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":SideEffectInterfacesIncGen", + ":Support", + "//llvm:Support", + ], +) + +alias( + name = "SideEffects", + actual = "SideEffectInterfaces", +) + +cc_library( + name = "Analysis", + srcs = glob( + [ + "lib/Analysis/*.cpp", + "lib/Analysis/*.h", + "lib/Analysis/*/*.cpp", + "lib/Analysis/*/*.h", + ], + exclude = [ + "lib/Analysis/Vector*.cpp", + "lib/Analysis/Vector*.h", + ], + ), + hdrs = glob( + [ + "include/mlir/Analysis/*.h", + "include/mlir/Analysis/*/*.h", + ], + exclude = [ + "include/mlir/Analysis/Vector*.h", + ], + ), + includes = ["include"], + deps = [ + ":Affine", + ":CallOpInterfaces", + ":ControlFlowInterfaces", + ":IR", + ":LinalgOps", + ":SCFDialect", + ":StandardOps", + ":Support", + ":ViewLikeInterface", + "//llvm:Support", + ], +) + +cc_library( + name = "Translation", + srcs = glob([ + "lib/Translation/*.cpp", + "lib/Translation/*.h", + ]), + hdrs = [ + "include/mlir/Translation.h", + ], + includes = ["include"], + deps = [ + ":Analysis", + ":IR", + ":Parser", + ":Support", + "//llvm:Support", + ], +) + +cc_library( + name = "LLVMIRModuleTranslation", + srcs = [ + "lib/Target/LLVMIR/DebugTranslation.cpp", + "lib/Target/LLVMIR/DebugTranslation.h", + "lib/Target/LLVMIR/ModuleTranslation.cpp", + "lib/Target/LLVMIR/TypeTranslation.cpp", + ], + hdrs = [ + "include/mlir/Target/LLVMIR/ModuleTranslation.h", + "include/mlir/Target/LLVMIR/TypeTranslation.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":LLVMConversionIncGen", + ":LLVMDialect", + ":LLVMIRTransforms", + ":OpenMPDialect", + ":Support", + "//llvm:Core", + "//llvm:FrontendOpenMP", + "//llvm:Support", + "//llvm:TransformUtils", + ], +) + +cc_library( + name = "TargetLLVMIR", + srcs = [ + "lib/Target/LLVMIR/ConvertFromLLVMIR.cpp", + "lib/Target/LLVMIR/ConvertToLLVMIR.cpp", + ], + hdrs = [ + "include/mlir/Target/LLVMIR.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":LLVMConversionIncGen", + ":LLVMDialect", + ":LLVMIRModuleTranslation", + ":OpenMPDialect", + ":Support", + ":TargetLLVMAVX512Intr", + ":Translation", + "//llvm:Core", + "//llvm:IRReader", + "//llvm:Support", + ], +) + +cc_library( + name = "TargetNVVMIR", + srcs = [ + "lib/Target/LLVMIR/ConvertToNVVMIR.cpp", + ], + hdrs = [ + "include/mlir/Target/NVVMIR.h", + ], + includes = ["include"], + deps = [ + ":GPUDialect", + ":IR", + ":LLVMDialect", + ":LLVMIRModuleTranslation", + ":NVVMConversionIncGen", + ":NVVMDialect", + ":Support", + ":Translation", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "TargetROCDLIR", + srcs = [ + "lib/Target/LLVMIR/ConvertToROCDLIR.cpp", + ], + hdrs = [ + "include/mlir/Target/ROCDLIR.h", + ], + includes = ["include"], + deps = [ + ":GPUDialect", + ":IR", + ":LLVMDialect", + ":LLVMIRModuleTranslation", + ":ROCDLConversionIncGen", + ":ROCDLDialect", + ":Support", + ":Translation", + "//llvm:Core", + "//llvm:Support", + ], +) + +# TODO(zinenko): Update these so that we can simplify mapping to cmake. +cc_library( + name = "ExecutionEngine", + srcs = [ + "lib/ExecutionEngine/ExecutionEngine.cpp", + ], + hdrs = [ + "include/mlir/ExecutionEngine/ExecutionEngine.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":LLVMDialect", + ":Support", + ":TargetLLVMIR", + ":Translation", + "//llvm:BitReader", + "//llvm:BitWriter", + "//llvm:Core", + "//llvm:ExecutionEngine", + "//llvm:MC", + "//llvm:OrcJIT", + "//llvm:Support", + "//llvm:Target", # fixdeps: keep + "//llvm:TransformUtils", + "//llvm:X86CodeGen", # fixdeps: keep + "//llvm:X86Disassembler", # fixdeps: keep + ], +) + +cc_library( + name = "ExecutionEngineUtils", + srcs = [ + "lib/ExecutionEngine/OptUtils.cpp", + ], + hdrs = [ + "include/mlir/ExecutionEngine/OptUtils.h", + ], + includes = ["include"], + deps = [ + "//llvm:Analysis", + "//llvm:Core", + "//llvm:Coroutines", + "//llvm:IPO", + "//llvm:Support", + "//llvm:Target", + "//llvm:common_transforms", + ], +) + +# TODO(jpienaar): Update this. +cc_library( + name = "MlirOptLib", + srcs = [ + "lib/Support/MlirOptMain.cpp", + ], + hdrs = [ + "include/mlir/Support/MlirOptMain.h", + ], + includes = ["include"], + deps = [ + ":Analysis", + ":ConversionPasses", + ":GPUToGPURuntimeTransforms", + ":GPUToNVVMTransforms", + ":GPUToROCDLTransforms", + ":GPUToSPIRVTransforms", + ":GPUTransforms", + ":IR", + ":LLVMDialect", + ":LinalgToLLVM", + ":LinalgToSPIRV", + ":LinalgToStandard", + ":NVVMDialect", + ":Parser", + ":Pass", + ":SCFTransforms", + ":ShapeToStandard", + ":ShapeTransforms", + ":StandardOpsTransforms", + ":StandardToLLVM", + ":StandardToSPIRVTransforms", + ":Support", + ":Transforms", + ":VectorToLLVM", + ":VectorToSCF", + "//llvm:Support", + "//mlir/test:TestAffine", + "//mlir/test:TestDialect", + "//mlir/test:TestIR", + "//mlir/test:TestPass", + "//mlir/test:TestReducer", + "//mlir/test:TestSPIRV", + "//mlir/test:TestTransforms", + "//mlir/test:TestTypeDialect", + ], +) + +cc_library( + name = "AllTranslations", + hdrs = ["include/mlir/InitAllTranslations.h"], + deps = [ + ":SPIRVTranslateRegistration", + ":TargetLLVMIR", + ":TargetNVVMIR", + ":TargetROCDLIR", + ], +) + +cc_library( + name = "MlirTranslateMain", + srcs = ["tools/mlir-translate/mlir-translate.cpp"], + deps = [ + ":AllPassesAndDialectsNoRegistration", + ":AllTranslations", + ":IR", + ":Parser", + ":Support", + ":Translation", + "//llvm:Support", + ], +) + +cc_binary( + name = "mlir-translate", + deps = [ + ":MlirTranslateMain", + ], +) + +cc_library( + name = "AllPassesAndDialectsNoRegistration", + hdrs = [ + "include/mlir/InitAllDialects.h", + "include/mlir/InitAllPasses.h", + ], + defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], + deps = [ + ":AVX512", + ":AVX512ToLLVM", + ":Affine", + ":AffinePassIncGen", + ":AffineToStandard", + ":AffineTransforms", + ":Async", + ":AsyncPassIncGen", + ":AsyncToLLVM", + ":AsyncTransforms", + ":ConversionPasses", + ":GPUDialect", + ":GPUPassIncGen", + ":GPUToGPURuntimeTransforms", + ":GPUToNVVMTransforms", + ":GPUToROCDLTransforms", + ":GPUToSPIRVTransforms", + ":GPUToVulkanTransforms", + ":GPUTransforms", + ":IR", + ":LLVMAVX512", + ":LLVMDialect", + ":LLVMIRTransforms", + ":LLVMPassIncGen", + ":LinalgOps", + ":LinalgPassIncGen", + ":LinalgToLLVM", + ":LinalgToSPIRV", + ":LinalgToStandard", + ":LinalgTransforms", + ":NVVMDialect", + ":OpenACCDialect", + ":OpenMPDialect", + ":OpenMPToLLVM", + ":PDLDialect", + ":PDLInterpDialect", + ":PDLToPDLInterp", + ":QuantOps", + ":QuantPassIncGen", + ":ROCDLDialect", + ":SCFDialect", + ":SCFPassIncGen", + ":SCFToGPUPass", + ":SCFToStandard", + ":SCFTransforms", + ":SDBM", + ":SPIRVDialect", + ":SPIRVLowering", + ":SPIRVPassIncGen", + ":SPIRVToLLVM", + ":Shape", + ":ShapeToStandard", + ":ShapeTransforms", + ":ShapeTransformsPassIncGen", + ":StandardOps", + ":StandardOpsTransforms", + ":StandardOpsTransformsPassIncGen", + ":StandardToLLVM", + ":StandardToSPIRVTransforms", + ":TosaDialect", + ":Transforms", + ":TransformsPassIncGen", + ":VectorOps", + ":VectorToLLVM", + ":VectorToROCDL", + ":VectorToSCF", + ":VectorToSPIRV", + ], +) + +cc_library( + name = "AllPassesAndDialects", + deps = [ + ":AllPassesAndDialectsNoRegistration", + ], +) + +cc_binary( + name = "mlir-opt", + srcs = [ + "tools/mlir-opt/mlir-opt.cpp", + ], + copts = ["-DMLIR_INCLUDE_TESTS"], + deps = [ + ":AllPassesAndDialectsNoRegistration", + ":Analysis", + ":IR", + ":MlirOptLib", + ":OpenMPDialect", + ":Pass", + ":QuantOps", + ":SCFToGPUPass", + ":Support", + ":Transforms", + "//llvm:AllTargetsCodeGens", + "//llvm:Support", + "//mlir/test:TestAffine", + "//mlir/test:TestDialect", + "//mlir/test:TestIR", + "//mlir/test:TestPass", + "//mlir/test:TestReducer", + "//mlir/test:TestSPIRV", + "//mlir/test:TestTosaDialect", + "//mlir/test:TestTransforms", + "//mlir/test:TestTypeDialect", + ], +) + +cc_library( + name = "MlirJitRunner", + srcs = ["lib/ExecutionEngine/JitRunner.cpp"], + hdrs = ["include/mlir/ExecutionEngine/JitRunner.h"], + includes = ["include"], + deps = [ + ":AllPassesAndDialectsNoRegistration", + ":ExecutionEngine", + ":ExecutionEngineUtils", + ":IR", + ":LLVMDialect", + ":Parser", + ":Pass", + ":SCFToStandard", + ":Support", + "//llvm:Core", + "//llvm:OrcJIT", + "//llvm:Support", + ], +) + +cc_library( + name = "mlir_c_runner_utils", + srcs = [ + "lib/ExecutionEngine/CRunnerUtils.cpp", + "lib/ExecutionEngine/SparseUtils.cpp", + ], + hdrs = [ + "include/mlir/ExecutionEngine/CRunnerUtils.h", + ], + includes = ["include"], +) + +cc_library( + name = "mlir_async_runtime", + srcs = [ + "lib/ExecutionEngine/AsyncRuntime.cpp", + ], + hdrs = [ + "include/mlir/ExecutionEngine/AsyncRuntime.h", + ], + includes = ["include"], +) + +cc_library( + name = "mlir_runner_utils", + srcs = [ + "lib/ExecutionEngine/RunnerUtils.cpp", + ], + hdrs = [ + "include/mlir/ExecutionEngine/RunnerUtils.h", + ], + includes = ["include"], + deps = [ + ":mlir_c_runner_utils", + ], +) + +cc_binary( + name = "mlir-cpu-runner", + srcs = ["tools/mlir-cpu-runner/mlir-cpu-runner.cpp"], + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "//conditions:default": ["-ldl"], + }), + deps = [ + ":AllPassesAndDialectsNoRegistration", + ":ExecutionEngineUtils", + ":MlirJitRunner", + "//llvm:Support", + ], +) + +cc_library( + name = "tools/libcuda-runtime-wrappers", + srcs = ["tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp"], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":mlir_c_runner_utils", + "//llvm:Support", + "@cuda//:cuda_headers", + "@cuda//:cuda_runtime", + "@cuda//:libcuda", + ], +) + +cc_binary( + name = "tools/libcuda-runtime-wrappers.so", + linkshared = True, + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [":tools/libcuda-runtime-wrappers"], +) + +cc_library( + name = "VulkanRuntime", + srcs = [ + "tools/mlir-vulkan-runner/VulkanRuntime.cpp", + ], + hdrs = [ + "tools/mlir-vulkan-runner/VulkanRuntime.h", + ], + tags = [ + "manual", # External dependency + ], + deps = [ + ":IR", + ":Pass", + ":SPIRVDialect", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + "//llvm:Support", + "@vulkan_headers", + "@vulkan_sdk//:sdk", + ], +) + +cc_binary( + name = "tools/libvulkan-runtime-wrappers.so", + srcs = ["tools/mlir-vulkan-runner/vulkan-runtime-wrappers.cpp"], + linkshared = True, + tags = [ + "manual", # External dependency (through VulkanRuntime) + ], + deps = [ + ":VulkanRuntime", + "//llvm:Support", + ], +) + +cc_binary( + name = "mlir-cuda-runner", + srcs = ["tools/mlir-cuda-runner/mlir-cuda-runner.cpp"], + data = [":tools/libcuda-runtime-wrappers.so"], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":AllPassesAndDialectsNoRegistration", + ":ExecutionEngineUtils", + ":GPUDialect", + ":GPUToGPURuntimeTransforms", + ":GPUToNVVMTransforms", + ":GPUToROCDLTransforms", + ":GPUTransforms", + ":IR", + ":LLVMDialect", + ":MlirJitRunner", + ":NVVMDialect", + ":Pass", + ":StandardToLLVM", + ":TargetNVVMIR", + ":Transforms", + "//devtools/build/runtime:get_runfiles_dir", + "//llvm:Support", + "@cuda//:cuda_headers", + "@cuda//:cuda_runtime", + "@cuda//:libcuda", + ], +) + +cc_binary( + name = "mlir-vulkan-runner", + srcs = ["tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp"], + data = [ + ":tools/libvulkan-runtime-wrappers.so", + "//mlir/test/mlir-cpu-runner:libmlir_runner_utils.so", + ], + tags = [ + "manual", # External dependency + "nobuildkite", # TODO(gcmn): Add support for this target + ], + deps = [ + ":AllPassesAndDialectsNoRegistration", + ":ExecutionEngineUtils", + ":GPUToSPIRVTransforms", + ":GPUToVulkanTransforms", + ":GPUTransforms", + ":MlirJitRunner", + ":Pass", + ":SPIRVDialect", + ":StandardToLLVM", + ":StandardToSPIRVTransforms", + "//llvm:Support", + ], +) + +cc_binary( + name = "mlir-spirv-cpu-runner", + srcs = ["tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp"], + deps = [ + ":AllPassesAndDialectsNoRegistration", + ":ExecutionEngineUtils", + ":GPUDialect", + ":GPUToSPIRVTransforms", + ":GPUTransforms", + ":IR", + ":LLVMDialect", + ":MlirJitRunner", + ":Pass", + ":SPIRVDialect", + ":SPIRVLowering", + ":SPIRVToLLVM", + ":StandardToLLVM", + ":TargetLLVMIR", + "//llvm:Core", + "//llvm:Linker", + "//llvm:Support", + ], +) + +cc_library( + name = "TableGen", + srcs = glob(["lib/TableGen/*.cpp"]), + hdrs = glob(["include/mlir/TableGen/*.h"]), + includes = ["include"], + deps = [ + ":Support", + "//llvm:Support", + "//llvm:TableGen", + ], +) + +cc_library( + name = "MlirTableGenMain", + srcs = [ + "tools/mlir-tblgen/mlir-tblgen.cpp", + ], + includes = ["include"], + deps = [ + ":Support", + ":TableGen", + "//llvm:Support", + "//llvm:TableGen", + "//llvm:config", + ], +) + +cc_binary( + name = "mlir-tblgen", + srcs = glob([ + "tools/mlir-tblgen/*.h", + "tools/mlir-tblgen/*.cpp", + ]), + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "//conditions:default": [ + "-lm", + "-lpthread", + ], + }), + deps = [ + ":MlirTableGenMain", + ":Support", + ":TableGen", + "//llvm:Support", + "//llvm:TableGen", + "//llvm:config", + ], +) + +cc_binary( + name = "mlir-linalg-ods-gen", + srcs = glob([ + "tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp", + ]), + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "//conditions:default": [ + "-lm", + "-lpthread", + ], + }), + deps = [ + ":IR", + ":Support", + "//llvm:Support", + "//llvm:TableGen", + "//llvm:config", + ], +) + +## OpenACC dialect + +gentbl( + name = "OpenACCOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-dialect-decls -dialect=acc", + "include/mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc", + ), + ( + "-gen-op-decls", + "include/mlir/Dialect/OpenACC/OpenACCOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/OpenACC/OpenACCOps.cpp.inc", + ), + ( + "-gen-enum-decls", + "include/mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc", + ), + ( + "-gen-enum-defs", + "include/mlir/Dialect/OpenACC/OpenACCOpsEnums.cpp.inc", + ), + ( + "-gen-op-doc", + "g3doc/Dialects/OpenACC/OpenACCOps.md", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/OpenACC/OpenACCOps.td", + td_srcs = [ + ":OpBaseTdFiles", + ":OmpCommonTdGen", + ], +) + +cc_library( + name = "OpenACCDialect", + srcs = glob( + [ + "lib/Dialect/OpenACC/IR/*.cpp", + "lib/Dialect/OpenACC/IR/*.h", + ], + ), + hdrs = glob([ + "include/mlir/Dialect/OpenACC/*.h", + ]), + includes = ["include"], + deps = [ + ":IR", + ":OpenACCOpsIncGen", + ":StandardOps", + "//llvm:Support", + ], +) + +## OpenMP dialect +gentbl( + name = "OmpCommonTdGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-directive-decl", + "include/mlir/Dialect/OpenMP/OmpCommon.td", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "//llvm:include/llvm/Frontend/OpenMP/OMP.td", + td_includes = ["external/llvm-project/llvm/include"], + td_srcs = [ + "//llvm:omp_td_files", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "OpenMPOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/OpenMP/OpenMPOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/OpenMP/OpenMPOps.cpp.inc", + ), + ( + "-gen-enum-decls", + "include/mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc", + ), + ( + "-gen-enum-defs", + "include/mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc", + ), + ( + "-gen-dialect-decls -dialect=omp", + "include/mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc", + ), + ( + "-gen-op-doc", + "g3doc/Dialects/OpenMP/OpenMPOps.md", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/OpenMP/OpenMPOps.td", + td_srcs = [ + ":OpBaseTdFiles", + ":OmpCommonTdGen", + "include/mlir/Dialect/LLVMIR/LLVMOpBase.td", + "include/mlir/Dialect/OpenMP/OmpCommon.td", + "include/mlir/Interfaces/ControlFlowInterfaces.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ], +) + +cc_library( + name = "OpenMPDialect", + srcs = glob( + [ + "lib/Dialect/OpenMP/IR/*.cpp", + "lib/Dialect/OpenMP/IR/*.h", + ], + ), + hdrs = glob([ + "include/mlir/Dialect/OpenMP/*.h", + ]), + includes = ["include"], + deps = [ + ":IR", + ":LLVMDialect", + ":OpenMPOpsIncGen", + ":StandardOps", + "//llvm:Support", + ], +) + +cc_library( + name = "OpenMPToLLVM", + srcs = glob([ + "lib/Conversion/OpenMPToLLVM/*.cpp", + "lib/Conversion/OpenMPToLLVM/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/OpenMPToLLVM/*.h", + ]), + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":IR", + ":LLVMDialect", + ":OpenMPDialect", + ":Pass", + ":StandardOps", + ":StandardToLLVM", + ":Transforms", + "//llvm:Core", + "//llvm:Support", + ], +) + +## QuantOps dialect +filegroup( + name = "QuantizationOpsTdFiles", + srcs = [ + "include/mlir/Dialect/Quant/QuantOps.td", + "include/mlir/Dialect/Quant/QuantOpsBase.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "QuantOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/Quant/QuantOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/Quant/QuantOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/Quant/QuantOpsDialect.h.inc", + ), + ( + "-gen-op-doc", + "g3doc/Dialects/QuantOps/QuantOps.md", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Quant/QuantOps.td", + td_srcs = [ + ":QuantizationOpsTdFiles", + ], +) + +gentbl( + name = "QuantPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name Quant", + "include/mlir/Dialect/Quant/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Quant/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "QuantOps", + srcs = [ + "lib/Dialect/Quant/IR/QuantOps.cpp", + "lib/Dialect/Quant/IR/QuantTypes.cpp", + "lib/Dialect/Quant/IR/TypeDetail.h", + "lib/Dialect/Quant/IR/TypeParser.cpp", + "lib/Dialect/Quant/Transforms/ConvertConst.cpp", + "lib/Dialect/Quant/Transforms/ConvertSimQuant.cpp", + "lib/Dialect/Quant/Transforms/PassDetail.h", + "lib/Dialect/Quant/Utils/FakeQuantSupport.cpp", + "lib/Dialect/Quant/Utils/QuantizeUtils.cpp", + "lib/Dialect/Quant/Utils/UniformSupport.cpp", + ], + hdrs = [ + "include/mlir/Dialect/Quant/FakeQuantSupport.h", + "include/mlir/Dialect/Quant/Passes.h", + "include/mlir/Dialect/Quant/QuantOps.h", + "include/mlir/Dialect/Quant/QuantTypes.h", + "include/mlir/Dialect/Quant/QuantizeUtils.h", + "include/mlir/Dialect/Quant/UniformSupport.h", + ], + includes = ["include"], + deps = [ + ":IR", + ":Pass", + ":QuantOpsIncGen", + ":QuantPassIncGen", + ":SideEffectInterfaces", + ":StandardOps", + ":TransformUtils", + "//llvm:Support", + ], +) + +filegroup( + name = "LinalgOpsTdFiles", + srcs = [ + "include/mlir/Dialect/Linalg/IR/LinalgBase.td", + "include/mlir/Dialect/Linalg/IR/LinalgOps.td", + "include/mlir/Interfaces/CopyOpInterface.td", + "include/mlir/Interfaces/ViewLikeInterface.td", + ":AffineOpsTdFiles", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "LinalgOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/Linalg/IR/LinalgOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/Linalg/IR/LinalgOps.cpp.inc", + ), + ( + "-gen-dialect-decls -dialect=linalg", + "include/mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Linalg/IR/LinalgOps.td", + td_srcs = [ + ":LinalgOpsTdFiles", + ], +) + +genlinalg( + name = "LinalgNamedStructuredOpsIncGen", + src = "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOpsSpec.tc", + linalg_outs = [ + ( + "-gen-impl", + "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.cpp.inc", + ), + ( + "-gen-ods-decl", + "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.td", + ), + ], + linalggen = ":mlir-linalg-ods-gen", +) + +filegroup( + name = "LinalgStructuredOpsTdFiles", + srcs = [ + "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.td", + "include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td", + "include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td", + "include/mlir/Interfaces/CopyOpInterface.td", + "include/mlir/Interfaces/ViewLikeInterface.td", + ":AffineOpsTdFiles", + ":LinalgOpsTdFiles", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "LinalgStructuredOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td", + td_srcs = [ + ":LinalgStructuredOpsTdFiles", + "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.td", + ], +) + +gentbl( + name = "LinalgStructuredInterfacesIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td", + td_srcs = [ + ":LinalgStructuredOpsTdFiles", + ], +) + +filegroup( + name = "LinalgDocTdFiles", + srcs = [ + "include/mlir/Dialect/Linalg/IR/LinalgDoc.td", + ":LinalgOpsTdFiles", + ":LinalgStructuredOpsTdFiles", + ], +) + +gentbl( + name = "LinalgDocIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-doc", + "g3doc/Dialects/Linalg/LinalgOps.md", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Linalg/IR/LinalgDoc.td", + td_srcs = [ + ":LinalgDocTdFiles", + ], +) + +cc_library( + name = "LinalgToLLVM", + srcs = glob([ + "lib/Conversion/LinalgToLLVM/*.cpp", + "lib/Conversion/LinalgToLLVM/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/LinalgToLLVM/*.h", + ]), + includes = ["include"], + deps = [ + ":AffineToStandard", + ":Analysis", + ":ConversionPassIncGen", + ":EDSC", + ":IR", + ":LLVMDialect", + ":LinalgOps", + ":LinalgTransforms", + ":Pass", + ":SCFDialect", + ":SCFToStandard", + ":StandardOps", + ":StandardToLLVM", + ":Support", + ":Transforms", + ":VectorToLLVM", + ":VectorToSCF", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "LinalgToStandard", + srcs = glob([ + "lib/Conversion/LinalgToStandard/*.cpp", + "lib/Conversion/LinalgToStandard/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/LinalgToStandard/*.h", + ]), + includes = ["include"], + deps = [ + ":Affine", + ":ConversionPassIncGen", + ":IR", + ":LinalgOps", + ":LinalgTransforms", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":Support", + ":Transforms", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "LinalgToSPIRV", + srcs = glob([ + "lib/Conversion/LinalgToSPIRV/*.cpp", + "lib/Conversion/LinalgToSPIRV/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/LinalgToSPIRV/*.h", + ]), + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":DialectUtils", + ":IR", + ":LinalgOps", + ":LinalgTransforms", + ":Pass", + ":SPIRVDialect", + ":SPIRVLowering", + ":StandardOps", + ], +) + +cc_library( + name = "LinalgOps", + srcs = [ + "lib/Dialect/Linalg/IR/LinalgOps.cpp", + "lib/Dialect/Linalg/IR/LinalgTypes.cpp", + ], + hdrs = [ + "include/mlir/Dialect/Linalg/EDSC/Intrinsics.h", + "include/mlir/Dialect/Linalg/IR/LinalgOps.h", + "include/mlir/Dialect/Linalg/IR/LinalgTraits.h", + "include/mlir/Dialect/Linalg/IR/LinalgTypes.h", + ], + includes = ["include"], + deps = [ + ":Affine", + ":CopyOpInterface", + ":DialectUtils", + ":EDSC", + ":IR", + ":LinalgNamedStructuredOpsIncGen", + ":LinalgOpsIncGen", + ":LinalgStructuredInterfacesIncGen", + ":LinalgStructuredOpsIncGen", + ":Parser", + ":SideEffectInterfaces", + ":StandardOps", + ":Support", + ":ViewLikeInterface", + "//llvm:Support", + ], +) + +gentbl( + name = "LinalgPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name Linalg", + "include/mlir/Dialect/Linalg/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Linalg/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "LinalgTransforms", + srcs = glob([ + "lib/Dialect/Linalg/Transforms/*.cpp", + "lib/Dialect/Linalg/Transforms/*.h", + ]) + [ + "lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp", + "lib/Dialect/Linalg/EDSC/Builders.cpp", + "lib/Dialect/Linalg/Utils/Utils.cpp", + ], + hdrs = [ + "include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h", + "include/mlir/Dialect/Linalg/EDSC/Builders.h", + "include/mlir/Dialect/Linalg/EDSC/FoldedIntrinsics.h", + "include/mlir/Dialect/Linalg/Passes.h", + "include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h", + "include/mlir/Dialect/Linalg/Transforms/Hoisting.h", + "include/mlir/Dialect/Linalg/Transforms/Transforms.h", + "include/mlir/Dialect/Linalg/Utils/Utils.h", + ], + includes = ["include"], + deps = [ + ":Affine", + ":AffineToStandard", + ":Analysis", + ":DialectUtils", + ":EDSC", + ":IR", + ":LLVMDialect", + ":LinalgOps", + ":LinalgPassIncGen", + ":LinalgStructuredOpsIncGen", + ":Pass", + ":SCFDialect", + ":SCFToStandard", + ":SCFTransforms", + ":StandardOps", + ":StandardOpsTransforms", + ":StandardToLLVM", + ":Support", + ":TransformUtils", + ":Transforms", + ":TransformsPassIncGen", + ":VectorOps", + ":VectorToSCF", + "//llvm:Core", + "//llvm:Support", + ], +) + +filegroup( + name = "VectorOpsTdFiles", + srcs = [ + "include/mlir/Dialect/Vector/VectorOps.td", + "include/mlir/Interfaces/VectorInterfaces.td", + "include/mlir/Interfaces/ViewLikeInterface.td", + ":AffineOpsTdFiles", + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "VectorOpsIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/Vector/VectorOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/Vector/VectorOps.cpp.inc", + ), + ( + "-gen-dialect-decls -dialect=vector", + "include/mlir/Dialect/Vector/VectorOpsDialect.h.inc", + ), + ( + "-gen-op-doc", + "g3doc/Dialects/Vector/VectorOps.md", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Vector/VectorOps.td", + td_srcs = [ + ":VectorOpsTdFiles", + ], +) + +cc_library( + name = "VectorToLLVM", + srcs = glob([ + "lib/Conversion/VectorToLLVM/*.cpp", + "lib/Conversion/VectorToLLVM/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/VectorToLLVM/*.h", + ]), + includes = ["include"], + deps = [ + ":ConversionPassIncGen", + ":DialectUtils", + ":EDSC", + ":IR", + ":LLVMDialect", + ":LLVMIRModuleTranslation", + ":Pass", + ":StandardOps", + ":StandardToLLVM", + ":Support", + ":Transforms", + ":VectorOps", + "//llvm:Core", + "//llvm:Support", + ], +) + +cc_library( + name = "VectorToSCF", + srcs = glob([ + "lib/Conversion/VectorToSCF/*.cpp", + "lib/Conversion/VectorToSCF/*.h", + ]) + ["lib/Conversion/PassDetail.h"], + hdrs = glob([ + "include/mlir/Conversion/VectorToSCF/*.h", + ]), + includes = ["include"], + deps = [ + ":Affine", + ":ConversionPassIncGen", + ":EDSC", + ":IR", + ":LLVMDialect", + ":Pass", + ":SCFDialect", + ":StandardOps", + ":StandardToLLVM", + ":Support", + ":Transforms", + ":VectorOps", + "//llvm:Core", + "//llvm:Support", + ], +) + +gentbl( + name = "TosaDialectIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-decls", + "include/mlir/Dialect/Tosa/IR/TosaOps.h.inc", + ), + ( + "-gen-op-defs", + "include/mlir/Dialect/Tosa/IR/TosaOps.cpp.inc", + ), + ( + "-gen-struct-attr-decls", + "include/mlir/Dialect/Tosa/IR/TosaStructs.h.inc", + ), + ( + "-gen-struct-attr-defs", + "include/mlir/Dialect/Tosa/IR/TosaStructs.cpp.inc", + ), + ( + "-gen-dialect-decls", + "include/mlir/Dialect/Tosa/IR/TosaOpsDialect.h.inc", + ), + ( + "-gen-op-doc", + "g3doc/Dialects/Tosa/TosaOps.md", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Tosa/IR/TosaOps.td", + td_srcs = [ + ":OpBaseTdFiles", + "include/mlir/Dialect/Tosa/IR/TosaOpBase.td", + "include/mlir/Dialect/Tosa/IR/TosaInterfaces.td", + "include/mlir/Dialect/Tosa/IR/TosaTypesBase.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + "include/mlir/Interfaces/LoopLikeInterface.td", + ], +) + +gentbl( + name = "TosaInterfacesIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-op-interface-decls", + "include/mlir/Dialect/Tosa/IR/TosaInterfaces.h.inc", + ), + ( + "-gen-op-interface-defs", + "include/mlir/Dialect/Tosa/IR/TosaInterfaces.cpp.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Tosa/IR/TosaInterfaces.td", + td_srcs = [ + ":OpBaseTdFiles", + ], +) + +gentbl( + name = "TosaPassIncGen", + strip_include_prefix = "include", + tbl_outs = [ + ( + "-gen-pass-decls -name TosaOpt", + "include/mlir/Dialect/Tosa/Transforms/Passes.h.inc", + ), + ], + tblgen = ":mlir-tblgen", + td_file = "include/mlir/Dialect/Tosa/Transforms/Passes.td", + td_srcs = [ + ":PassBaseTdFiles", + ], +) + +cc_library( + name = "TosaDialect", + srcs = glob([ + "lib/Dialect/Tosa/IR/*.cpp", + "lib/Dialect/Tosa/IR/*.h", + "lib/Dialect/Tosa/Utils/*.cpp", + "lib/Dialect/Tosa/Transforms/*.cpp", + ]), + hdrs = glob([ + "include/mlir/Dialect/Tosa/IR/*.h", + "include/mlir/Dialect/Tosa/Utils/*.h", + "include/mlir/Dialect/Tosa/Transforms/*.h", + ]), + includes = ["include"], + deps = [ + ":Dialect", + ":IR", + ":LoopLikeInterface", + ":Pass", + ":QuantOps", + ":SideEffectInterfaces", + ":StandardOps", + ":TosaDialectIncGen", + ":TosaInterfacesIncGen", + ":TosaPassIncGen", + ":TransformUtils", + ], +) + +# To reference all tablegen files here when checking for updates to them. +filegroup( + name = "TdFiles", + srcs = glob(["**/*.td"]), +) + +exports_files( + [ + "include/mlir/Interfaces/CallInterfaces.h", + "include/mlir/Interfaces/CallInterfaces.td", + "include/mlir/Interfaces/ControlFlowInterfaces.h", + "include/mlir/Interfaces/ControlFlowInterfaces.td", + "include/mlir/Interfaces/CopyOpInterface.td", + "include/mlir/Interfaces/SideEffectInterfaces.td", + "include/mlir/Interfaces/VectorInterfaces.td", + "include/mlir/Interfaces/ViewLikeInterface.td", + "include/mlir/Dialect/LLVMIR/LLVMOpBase.td", + "include/mlir/Dialect/StandardOps/IR/Ops.td", + "include/mlir/Dialect/Shape/IR/ShapeOps.td", + "include/mlir/Dialect/Shape/IR/ShapeBase.td", + "include/mlir/IR/OpAsmInterface.td", + "include/mlir/IR/OpBase.td", + "include/mlir/IR/RegionKindInterface.td", + "include/mlir/IR/SymbolInterfaces.td", + "include/mlir/Transforms/InliningUtils.h", + "include/mlir/Interfaces/InferTypeOpInterface.td", + "include/mlir/Interfaces/LoopLikeInterface.td", + ], + visibility = [":friends"], +) diff --git a/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl b/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl @@ -0,0 +1,43 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""BUILD extensions for MLIR linalg generation.""" + +def genlinalg(name, linalggen, src, linalg_outs): + """genlinalg() generates code from a tc spec file. + + Args: + name: The name of the build rule for use in dependencies. + linalggen: The binary used to produce the output. + src: The tc spec file. + linalg_outs: A list of tuples (opts, out), where each opts is a string of + options passed to linalggen, and the out is the corresponding output file + produced. + """ + + for (opts, out) in linalg_outs: + # All arguments to generate the output except output destination. + base_args = [ + "$(location %s)" % linalggen, + "%s" % opts, + "$(location %s)" % src, + ] + rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" ")) + + # Rule to generate code using generated shell script. + native.genrule( + name = "%s_%s_genrule" % (name, rule_suffix), + srcs = [src], + outs = [out], + tools = [linalggen], + cmd = ("echo " + " ".join(base_args) + " -o $@; " + " ".join(base_args) + " -o $@"), + ) + + # List of opts that do not generate cc files. + hdrs = [f for (opts, f) in linalg_outs] + native.cc_library( + name = name, + hdrs = hdrs, + textual_hdrs = hdrs, + ) diff --git a/utils/bazel/llvm-project-overlay/mlir/mlir-auto-init.cpp b/utils/bazel/llvm-project-overlay/mlir/mlir-auto-init.cpp new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/mlir/mlir-auto-init.cpp @@ -0,0 +1,18 @@ +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "mlir/InitAllDialects.h" +#include "mlir/InitAllPasses.h" + +namespace mlir { +// This target is a convenient dependency for users to auto-initialize MLIR +// internals. +static bool auto_init = []() { + registerAllDialects(); + registerAllPasses(); + + return true; +}(); + +} // namespace mlir diff --git a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl @@ -0,0 +1,98 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""BUILD extensions for MLIR table generation.""" + +def gentbl(name, tblgen, td_file, tbl_outs, td_srcs = [], td_includes = [], td_relative_includes = [], strip_include_prefix = None, test = False): + """gentbl() generates tabular code from a table definition file. + + Args: + name: The name of the build rule for use in dependencies. + tblgen: The binary used to produce the output. + td_file: The primary table definitions file. + tbl_outs: A list of tuples (opts, out), where each opts is a string of + options passed to tblgen, and the out is the corresponding output file + produced. + td_srcs: A list of table definition files included transitively. + td_includes: A list of include paths for relative includes, provided as build targets. + td_relative_includes: A list of include paths for relative includes, provided as relative path. + strip_include_prefix: attribute to pass through to cc_library. + test: whether to create a test to invoke the tool too. + """ + srcs = [] + srcs += td_srcs + if td_file not in td_srcs: + srcs.append(td_file) + + td_includes_cmd = [ + "-I external/llvm-project/mlir/include", + "-I $(GENDIR)/external/llvm-project/mlir/include", + ] + for td_include in td_includes: + td_includes_cmd += [ + "-I%s" % td_include, + "-I$(GENDIR)/%s" % td_include, + ] + for td_include in td_relative_includes: + td_includes_cmd += [ + "-I%s/%s" % (native.package_name(), td_include), + "-I$(GENDIR)/%s/%s" % (native.package_name(), td_include), + ] + + local_inc = "-I $$(dirname $(location %s))" % td_file + + if test: + # Rule to generate shell script to invoke tblgen. This generates a very + # bare shell file which the sh_test uses. + native.genrule( + name = "%s_genrule_sh" % name, + srcs = srcs, + outs = ["%s.gen.sh" % name], + cmd = ("echo \"\\$$1\" %s \\$${@:2} -o /dev/null > $@" % local_inc), + executable = 1, + ) + + for (opts, out) in tbl_outs: + # All arguments to generate the output except output destination. + base_args = [ + "$(location %s)" % tblgen, + "%s" % opts, + "$(location %s)" % td_file, + "-I$(GENDIR)", + ] + td_includes_cmd + first_opt = opts.split(" ", 1)[0] + rule_suffix = "_{}_{}".format(first_opt.replace("-", "_").replace("=", "_"), str(hash(opts))) + + # Rule to generate code using generated shell script. + native.genrule( + name = "%s_%s_genrule" % (name, rule_suffix), + srcs = srcs, + outs = [out], + tools = [tblgen], + message = "Generating code from table: %s" % td_file, + cmd = (" ".join(base_args) + " %s -o $@" % local_inc), + ) + + # Optionally generate rule to test tblgen invocation. + # Disable these on windows, because $(location ...) does not seem to + # work as expected on windows. + if test: + native.sh_test( + name = "%s_%s_genrule_test" % (name, rule_suffix), + srcs = ["%s.gen.sh" % name], + args = base_args, + data = srcs + [tblgen], + tags = ["no_windows"], + ) + + # List of opts that do not generate cc files. + skip_opts = ["-gen-op-doc"] + hdrs = [f for (opts, f) in tbl_outs if opts not in skip_opts] + native.cc_library( + name = name, + # include_prefix does not apply to textual_hdrs. + hdrs = hdrs if strip_include_prefix else [], + strip_include_prefix = strip_include_prefix, + textual_hdrs = hdrs, + ) diff --git a/utils/bazel/llvm-project-overlay/mlir/test/BUILD b/utils/bazel/llvm-project-overlay/mlir/test/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/mlir/test/BUILD @@ -0,0 +1,306 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +load("//mlir:tblgen.bzl", "gentbl") + +package( + default_visibility = [":test_friends"], + licenses = ["notice"], +) + +# Please only depend on this from MLIR tests. +package_group( + name = "test_friends", + packages = ["//..."], +) + +cc_library( + name = "IRProducingAPITest", + hdrs = ["APITest.h"], + includes = ["."], +) + +filegroup( + name = "TestOpTdFiles", + srcs = [ + "lib/Dialect/Test/TestOps.td", + "//mlir:OpBaseTdFiles", + "//mlir:include/mlir/IR/OpAsmInterface.td", + "//mlir:include/mlir/IR/RegionKindInterface.td", + "//mlir:include/mlir/IR/SymbolInterfaces.td", + "//mlir:include/mlir/Interfaces/CallInterfaces.td", + "//mlir:include/mlir/Interfaces/ControlFlowInterfaces.td", + "//mlir:include/mlir/Interfaces/CopyOpInterface.td", + "//mlir:include/mlir/Interfaces/InferTypeOpInterface.td", + "//mlir:include/mlir/Interfaces/SideEffectInterfaces.td", + ], +) + +gentbl( + name = "TestOpsIncGen", + strip_include_prefix = "lib/Dialect/Test", + tbl_outs = [ + ( + "-gen-op-decls", + "lib/Dialect/Test/TestOps.h.inc", + ), + ( + "-gen-op-defs", + "lib/Dialect/Test/TestOps.cpp.inc", + ), + ( + "-gen-dialect-decls", + "lib/Dialect/Test/TestOpsDialect.h.inc", + ), + ( + "-gen-enum-decls", + "lib/Dialect/Test/TestOpEnums.h.inc", + ), + ( + "-gen-enum-defs", + "lib/Dialect/Test/TestOpEnums.cpp.inc", + ), + ( + "-gen-struct-attr-decls", + "lib/Dialect/Test/TestOpStructs.h.inc", + ), + ( + "-gen-struct-attr-defs", + "lib/Dialect/Test/TestOpStructs.cpp.inc", + ), + ( + "-gen-rewriters", + "lib/Dialect/Test/TestPatterns.inc", + ), + ], + tblgen = "//mlir:mlir-tblgen", + td_file = "lib/Dialect/Test/TestOps.td", + td_srcs = [ + ":TestOpTdFiles", + ], + test = True, +) + +gentbl( + name = "TestInterfacesIncGen", + strip_include_prefix = "lib/Dialect/Test", + tbl_outs = [ + ( + "-gen-type-interface-decls", + "lib/Dialect/Test/TestTypeInterfaces.h.inc", + ), + ( + "-gen-type-interface-defs", + "lib/Dialect/Test/TestTypeInterfaces.cpp.inc", + ), + ], + tblgen = "//mlir:mlir-tblgen", + td_file = "lib/Dialect/Test/TestInterfaces.td", + td_srcs = [ + "//mlir:OpBaseTdFiles", + ], + test = True, +) + +gentbl( + name = "TestTypeDefsIncGen", + strip_include_prefix = "lib/Dialect/Test", + tbl_outs = [ + ( + "-gen-typedef-decls", + "lib/Dialect/Test/TestTypeDefs.h.inc", + ), + ( + "-gen-typedef-defs", + "lib/Dialect/Test/TestTypeDefs.cpp.inc", + ), + ], + tblgen = "//mlir:mlir-tblgen", + td_file = "lib/Dialect/Test/TestTypeDefs.td", + td_srcs = [ + ":TestOpTdFiles", + ], + test = True, +) + +cc_library( + name = "TestDialect", + srcs = [ + "lib/Dialect/Test/TestDialect.cpp", + "lib/Dialect/Test/TestPatterns.cpp", + "lib/Dialect/Test/TestTraits.cpp", + "lib/Dialect/Test/TestTypes.cpp", + ], + hdrs = [ + "lib/Dialect/Test/TestDialect.h", + "lib/Dialect/Test/TestTypes.h", + ], + includes = [ + "lib/Dialect/Test", + ], + deps = [ + ":TestInterfacesIncGen", + ":TestOpsIncGen", + ":TestTypeDefsIncGen", + "//llvm:Support", + "//mlir:ControlFlowInterfaces", + "//mlir:CopyOpInterface", + "//mlir:DerivedAttributeOpInterface", + "//mlir:Dialect", + "//mlir:IR", + "//mlir:InferTypeOpInterface", + "//mlir:Pass", + "//mlir:SideEffects", + "//mlir:StandardOps", + "//mlir:StandardOpsTransforms", + "//mlir:TransformUtils", + "//mlir:Transforms", + ], +) + +cc_library( + name = "TestIR", + srcs = [ + "lib/IR/TestFunc.cpp", + "lib/IR/TestInterfaces.cpp", + "lib/IR/TestMatchers.cpp", + "lib/IR/TestPrintDefUse.cpp", + "lib/IR/TestPrintNesting.cpp", + "lib/IR/TestSideEffects.cpp", + "lib/IR/TestSlicing.cpp", + "lib/IR/TestSymbolUses.cpp", + "lib/IR/TestTypes.cpp", + ], + deps = [ + ":TestDialect", + "//llvm:Support", + "//mlir:Analysis", + "//mlir:IR", + "//mlir:LinalgOps", + "//mlir:Pass", + "//mlir:StandardOps", + "//mlir:Support", + ], +) + +cc_library( + name = "TestPass", + srcs = [ + "lib/Pass/TestPassManager.cpp", + ], + deps = [ + "//llvm:Support", + "//mlir:IR", + "//mlir:Pass", + "//mlir:Support", + ], +) + +cc_library( + name = "TestReducer", + srcs = [ + "lib/Reducer/MLIRTestReducer.cpp", + ], + deps = [ + "//mlir:IR", + "//mlir:Pass", + "//mlir:Support", + ], +) + +cc_library( + name = "TestTransforms", + srcs = glob(["lib/Transforms/*.cpp"]), + defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], + includes = ["lib/Dialect/Test"], + deps = [ + ":TestDialect", + "//llvm:Support", + "//mlir:Affine", + "//mlir:AffineTransforms", + "//mlir:Analysis", + "//mlir:EDSC", + "//mlir:GPUDialect", + "//mlir:GPUToGPURuntimeTransforms", + "//mlir:GPUTransforms", + "//mlir:IR", + "//mlir:LLVMDialect", + "//mlir:LLVMTransforms", + "//mlir:LinalgOps", + "//mlir:LinalgTransforms", + "//mlir:Pass", + "//mlir:SCFDialect", + "//mlir:SPIRVDialect", + "//mlir:StandardOps", + "//mlir:StandardOpsTransforms", + "//mlir:Support", + "//mlir:TargetNVVMIR", + "//mlir:TargetROCDLIR", + "//mlir:TransformUtils", + "//mlir:Transforms", + "//mlir:VectorOps", + "//mlir:VectorToLLVM", + "//mlir:VectorToSCF", + ], +) + +cc_library( + name = "TestAffine", + srcs = glob([ + "lib/Dialect/Affine/*.cpp", + ]), + deps = [ + "//llvm:Support", + "//mlir:Affine", + "//mlir:AffineTransforms", + "//mlir:AffineUtils", + "//mlir:Analysis", + "//mlir:IR", + "//mlir:Pass", + "//mlir:Support", + "//mlir:Transforms", + "//mlir:VectorOps", + ], +) + +cc_library( + name = "TestSPIRV", + srcs = glob([ + "lib/Dialect/SPIRV/*.cpp", + ]), + deps = [ + "//mlir:GPUDialect", + "//mlir:IR", + "//mlir:Pass", + "//mlir:SPIRVDialect", + "//mlir:SPIRVLinking", + "//mlir:SPIRVLowering", + ], +) + +cc_library( + name = "TestTypeDialect", + srcs = glob([ + "lib/Dialect/LLVMIR/*.cpp", + ]), + deps = [ + ":TestDialect", + "//mlir:IR", + "//mlir:LLVMDialect", + ], +) + +cc_library( + name = "TestTosaDialect", + srcs = glob([ + "lib/Dialect/Tosa/*.cpp", + ]), + deps = [ + "//mlir:IR", + "//mlir:Pass", + "//mlir:StandardOps", + "//mlir:TosaDialect", + "//mlir:Transforms", + ], +) diff --git a/utils/bazel/llvm_configs/BUILD b/utils/bazel/llvm_configs/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm_configs/BUILD @@ -0,0 +1,29 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# We perform diff testing here to avoid any in-tree BUILD files depending on +# bazel_sklyib. These diff tests ensure that the current Bazel configuration +# does not drift from the configuration in the .cmake files, since we don't +# alway use them directly (and even if we did we wouldn't necessarily pick up +# changes there). These are literal change-detector tests. + +load("@bazel_skylib//rules:diff_test.bzl", "diff_test") + +diff_test( + name = "diff_config.h.cmake", + file1 = "@llvm-project//llvm:include/llvm/Config/config.h.cmake", + file2 = "config.h.cmake", +) + +diff_test( + name = "diff_llvm-config.h.cmake", + file1 = "@llvm-project//llvm:include/llvm/Config/llvm-config.h.cmake", + file2 = "llvm-config.h.cmake", +) + +diff_test( + name = "diff_abi-breaking.h.cmake", + file1 = "@llvm-project//llvm:include/llvm/Config/abi-breaking.h.cmake", + file2 = "abi-breaking.h.cmake", +) diff --git a/utils/bazel/llvm_configs/abi-breaking.h.cmake b/utils/bazel/llvm_configs/abi-breaking.h.cmake new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm_configs/abi-breaking.h.cmake @@ -0,0 +1,62 @@ +/*===------- llvm/Config/abi-breaking.h - llvm configuration -------*- C -*-===*/ +/* */ +/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ +/* Exceptions. */ +/* See https://llvm.org/LICENSE.txt for license information. */ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* */ +/*===----------------------------------------------------------------------===*/ + +/* This file controls the C++ ABI break introduced in LLVM public header. */ + +#ifndef LLVM_ABI_BREAKING_CHECKS_H +#define LLVM_ABI_BREAKING_CHECKS_H + +/* Define to enable checks that alter the LLVM C++ ABI */ +#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS + +/* Define to enable reverse iteration of unordered llvm containers */ +#cmakedefine01 LLVM_ENABLE_REVERSE_ITERATION + +/* Allow selectively disabling link-time mismatch checking so that header-only + ADT content from LLVM can be used without linking libSupport. */ +#if !LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING + +// ABI_BREAKING_CHECKS protection: provides link-time failure when clients build +// mismatch with LLVM +#if defined(_MSC_VER) +// Use pragma with MSVC +#define LLVM_XSTR(s) LLVM_STR(s) +#define LLVM_STR(s) #s +#pragma detect_mismatch("LLVM_ENABLE_ABI_BREAKING_CHECKS", LLVM_XSTR(LLVM_ENABLE_ABI_BREAKING_CHECKS)) +#undef LLVM_XSTR +#undef LLVM_STR +#elif defined(_WIN32) || defined(__CYGWIN__) // Win32 w/o #pragma detect_mismatch +// FIXME: Implement checks without weak. +#elif defined(__cplusplus) +#if !(defined(_AIX) && defined(__GNUC__) && !defined(__clang__)) +#define LLVM_HIDDEN_VISIBILITY __attribute__ ((visibility("hidden"))) +#else +// GCC on AIX does not support visibility attributes. Symbols are not +// exported by default on AIX. +#define LLVM_HIDDEN_VISIBILITY +#endif +namespace llvm { +#if LLVM_ENABLE_ABI_BREAKING_CHECKS +extern int EnableABIBreakingChecks; +LLVM_HIDDEN_VISIBILITY +__attribute__((weak)) int *VerifyEnableABIBreakingChecks = + &EnableABIBreakingChecks; +#else +extern int DisableABIBreakingChecks; +LLVM_HIDDEN_VISIBILITY +__attribute__((weak)) int *VerifyDisableABIBreakingChecks = + &DisableABIBreakingChecks; +#endif +} +#undef LLVM_HIDDEN_VISIBILITY +#endif // _MSC_VER + +#endif // LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING + +#endif diff --git a/utils/bazel/llvm_configs/config.h.cmake b/utils/bazel/llvm_configs/config.h.cmake new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm_configs/config.h.cmake @@ -0,0 +1,353 @@ +#ifndef CONFIG_H +#define CONFIG_H + +// Include this header only under the llvm source tree. +// This is a private header. + +/* Exported configuration */ +#include "llvm/Config/llvm-config.h" + +/* Bug report URL. */ +#define BUG_REPORT_URL "${BUG_REPORT_URL}" + +/* Define to 1 to enable backtraces, and to 0 otherwise. */ +#cmakedefine01 ENABLE_BACKTRACES + +/* Define to 1 to enable crash overrides, and to 0 otherwise. */ +#cmakedefine01 ENABLE_CRASH_OVERRIDES + +/* Define to 1 to enable crash memory dumps, and to 0 otherwise. */ +#cmakedefine01 LLVM_ENABLE_CRASH_DUMPS + +/* Define to 1 if you have the `backtrace' function. */ +#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE} + +#define BACKTRACE_HEADER <${BACKTRACE_HEADER}> + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_CRASHREPORTERCLIENT_H + +/* can use __crashreporter_info__ */ +#cmakedefine01 HAVE_CRASHREPORTER_INFO + +/* Define to 1 if you have the declaration of `arc4random', and to 0 if you + don't. */ +#cmakedefine01 HAVE_DECL_ARC4RANDOM + +/* Define to 1 if you have the declaration of `FE_ALL_EXCEPT', and to 0 if you + don't. */ +#cmakedefine01 HAVE_DECL_FE_ALL_EXCEPT + +/* Define to 1 if you have the declaration of `FE_INEXACT', and to 0 if you + don't. */ +#cmakedefine01 HAVE_DECL_FE_INEXACT + +/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you + don't. */ +#cmakedefine01 HAVE_DECL_STRERROR_S + +/* Define to 1 if you have the DIA SDK installed, and to 0 if you don't. */ +#cmakedefine01 LLVM_ENABLE_DIA_SDK + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} + +/* Define if dlopen() is available on this platform. */ +#cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN} + +/* Define if dladdr() is available on this platform. */ +#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} + +/* Define to 1 if we can register EH frames on this platform. */ +#cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME} + +/* Define to 1 if we can deregister EH frames on this platform. */ +#cmakedefine HAVE_DEREGISTER_FRAME ${HAVE_DEREGISTER_FRAME} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ERRNO_H ${HAVE_ERRNO_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FCNTL_H ${HAVE_FCNTL_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FENV_H ${HAVE_FENV_H} + +/* Define if libffi is available on this platform. */ +#cmakedefine HAVE_FFI_CALL ${HAVE_FFI_CALL} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FFI_FFI_H ${HAVE_FFI_FFI_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FFI_H ${HAVE_FFI_H} + +/* Define to 1 if you have the `futimens' function. */ +#cmakedefine HAVE_FUTIMENS ${HAVE_FUTIMENS} + +/* Define to 1 if you have the `futimes' function. */ +#cmakedefine HAVE_FUTIMES ${HAVE_FUTIMES} + +/* Define to 1 if you have the `getpagesize' function. */ +#cmakedefine HAVE_GETPAGESIZE ${HAVE_GETPAGESIZE} + +/* Define to 1 if you have the `getrlimit' function. */ +#cmakedefine HAVE_GETRLIMIT ${HAVE_GETRLIMIT} + +/* Define to 1 if you have the `getrusage' function. */ +#cmakedefine HAVE_GETRUSAGE ${HAVE_GETRUSAGE} + +/* Define to 1 if you have the `isatty' function. */ +#cmakedefine HAVE_ISATTY 1 + +/* Define to 1 if you have the `edit' library (-ledit). */ +#cmakedefine HAVE_LIBEDIT ${HAVE_LIBEDIT} + +/* Define to 1 if you have the `pfm' library (-lpfm). */ +#cmakedefine HAVE_LIBPFM ${HAVE_LIBPFM} + +/* Define to 1 if the `perf_branch_entry' struct has field cycles. */ +#cmakedefine LIBPFM_HAS_FIELD_CYCLES ${LIBPFM_HAS_FIELD_CYCLES} + +/* Define to 1 if you have the `psapi' library (-lpsapi). */ +#cmakedefine HAVE_LIBPSAPI ${HAVE_LIBPSAPI} + +/* Define to 1 if you have the `pthread' library (-lpthread). */ +#cmakedefine HAVE_LIBPTHREAD ${HAVE_LIBPTHREAD} + +/* Define to 1 if you have the `pthread_getname_np' function. */ +#cmakedefine HAVE_PTHREAD_GETNAME_NP ${HAVE_PTHREAD_GETNAME_NP} + +/* Define to 1 if you have the `pthread_setname_np' function. */ +#cmakedefine HAVE_PTHREAD_SETNAME_NP ${HAVE_PTHREAD_SETNAME_NP} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINK_H ${HAVE_LINK_H} + +/* Define to 1 if you have the `lseek64' function. */ +#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H} + +/* Define to 1 if you have the `mallctl' function. */ +#cmakedefine HAVE_MALLCTL ${HAVE_MALLCTL} + +/* Define to 1 if you have the `mallinfo' function. */ +#cmakedefine HAVE_MALLINFO ${HAVE_MALLINFO} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MALLOC_MALLOC_H ${HAVE_MALLOC_MALLOC_H} + +/* Define to 1 if you have the `malloc_zone_statistics' function. */ +#cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS} + +/* Define to 1 if you have the `posix_fallocate' function. */ +#cmakedefine HAVE_POSIX_FALLOCATE ${HAVE_POSIX_FALLOCATE} + +/* Define to 1 if you have the `posix_spawn' function. */ +#cmakedefine HAVE_POSIX_SPAWN ${HAVE_POSIX_SPAWN} + +/* Define to 1 if you have the `pread' function. */ +#cmakedefine HAVE_PREAD ${HAVE_PREAD} + +/* Have pthread_getspecific */ +#cmakedefine HAVE_PTHREAD_GETSPECIFIC ${HAVE_PTHREAD_GETSPECIFIC} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PTHREAD_H ${HAVE_PTHREAD_H} + +/* Have pthread_mutex_lock */ +#cmakedefine HAVE_PTHREAD_MUTEX_LOCK ${HAVE_PTHREAD_MUTEX_LOCK} + +/* Have pthread_rwlock_init */ +#cmakedefine HAVE_PTHREAD_RWLOCK_INIT ${HAVE_PTHREAD_RWLOCK_INIT} + +/* Define to 1 if you have the `sbrk' function. */ +#cmakedefine HAVE_SBRK ${HAVE_SBRK} + +/* Define to 1 if you have the `setenv' function. */ +#cmakedefine HAVE_SETENV ${HAVE_SETENV} + +/* Define to 1 if you have the `setrlimit' function. */ +#cmakedefine HAVE_SETRLIMIT ${HAVE_SETRLIMIT} + +/* Define to 1 if you have the `sigaltstack' function. */ +#cmakedefine HAVE_SIGALTSTACK ${HAVE_SIGALTSTACK} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SIGNAL_H ${HAVE_SIGNAL_H} + +/* Define to 1 if you have the `strerror' function. */ +#cmakedefine HAVE_STRERROR ${HAVE_STRERROR} + +/* Define to 1 if you have the `strerror_r' function. */ +#cmakedefine HAVE_STRERROR_R ${HAVE_STRERROR_R} + +/* Define to 1 if you have the `sysconf' function. */ +#cmakedefine HAVE_SYSCONF ${HAVE_SYSCONF} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_MMAN_H ${HAVE_SYS_MMAN_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_PARAM_H ${HAVE_SYS_PARAM_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H} + +/* Define to 1 if stat struct has st_mtimespec member .*/ +#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC} + +/* Define to 1 if stat struct has st_mtim member. */ +#cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H} + +/* Define if the setupterm() function is supported this platform. */ +#cmakedefine LLVM_ENABLE_TERMINFO ${LLVM_ENABLE_TERMINFO} + +/* Define if the xar_open() function is supported this platform. */ +#cmakedefine HAVE_LIBXAR ${HAVE_LIBXAR} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H} + +/* Have host's _alloca */ +#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA} + +/* Define to 1 if you have the `_chsize_s' function. */ +#cmakedefine HAVE__CHSIZE_S ${HAVE__CHSIZE_S} + +/* Define to 1 if you have the `_Unwind_Backtrace' function. */ +#cmakedefine HAVE__UNWIND_BACKTRACE ${HAVE__UNWIND_BACKTRACE} + +/* Have host's __alloca */ +#cmakedefine HAVE___ALLOCA ${HAVE___ALLOCA} + +/* Have host's __ashldi3 */ +#cmakedefine HAVE___ASHLDI3 ${HAVE___ASHLDI3} + +/* Have host's __ashrdi3 */ +#cmakedefine HAVE___ASHRDI3 ${HAVE___ASHRDI3} + +/* Have host's __chkstk */ +#cmakedefine HAVE___CHKSTK ${HAVE___CHKSTK} + +/* Have host's __chkstk_ms */ +#cmakedefine HAVE___CHKSTK_MS ${HAVE___CHKSTK_MS} + +/* Have host's __cmpdi2 */ +#cmakedefine HAVE___CMPDI2 ${HAVE___CMPDI2} + +/* Have host's __divdi3 */ +#cmakedefine HAVE___DIVDI3 ${HAVE___DIVDI3} + +/* Have host's __fixdfdi */ +#cmakedefine HAVE___FIXDFDI ${HAVE___FIXDFDI} + +/* Have host's __fixsfdi */ +#cmakedefine HAVE___FIXSFDI ${HAVE___FIXSFDI} + +/* Have host's __floatdidf */ +#cmakedefine HAVE___FLOATDIDF ${HAVE___FLOATDIDF} + +/* Have host's __lshrdi3 */ +#cmakedefine HAVE___LSHRDI3 ${HAVE___LSHRDI3} + +/* Have host's __main */ +#cmakedefine HAVE___MAIN ${HAVE___MAIN} + +/* Have host's __moddi3 */ +#cmakedefine HAVE___MODDI3 ${HAVE___MODDI3} + +/* Have host's __udivdi3 */ +#cmakedefine HAVE___UDIVDI3 ${HAVE___UDIVDI3} + +/* Have host's __umoddi3 */ +#cmakedefine HAVE___UMODDI3 ${HAVE___UMODDI3} + +/* Have host's ___chkstk */ +#cmakedefine HAVE____CHKSTK ${HAVE____CHKSTK} + +/* Have host's ___chkstk_ms */ +#cmakedefine HAVE____CHKSTK_MS ${HAVE____CHKSTK_MS} + +/* Linker version detected at compile time. */ +#cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" + +/* Target triple LLVM will generate code for by default */ +/* Doesn't use `cmakedefine` because it is allowed to be empty. */ +#define LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" + +/* Define if zlib compression is available */ +#cmakedefine01 LLVM_ENABLE_ZLIB + +/* Define if overriding target triple is enabled */ +#cmakedefine LLVM_TARGET_TRIPLE_ENV "${LLVM_TARGET_TRIPLE_ENV}" + +/* LLVM version information */ +#cmakedefine LLVM_VERSION_INFO "${LLVM_VERSION_INFO}" + +/* Whether tools show host and target info when invoked with --version */ +#cmakedefine01 LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO + +/* Define if libxml2 is supported on this platform. */ +#cmakedefine LLVM_ENABLE_LIBXML2 ${LLVM_ENABLE_LIBXML2} + +/* Define to the extension used for shared libraries, say, ".so". */ +#cmakedefine LTDL_SHLIB_EXT "${LTDL_SHLIB_EXT}" + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT "${PACKAGE_BUGREPORT}" + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME "${PACKAGE_NAME}" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING "${PACKAGE_STRING}" + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "${PACKAGE_VERSION}" + +/* Define to the vendor of this package. */ +#cmakedefine PACKAGE_VENDOR "${PACKAGE_VENDOR}" + +/* Define as the return type of signal handlers (`int' or `void'). */ +#cmakedefine RETSIGTYPE ${RETSIGTYPE} + +/* Define if std::is_trivially_copyable is supported */ +#cmakedefine HAVE_STD_IS_TRIVIALLY_COPYABLE ${HAVE_STD_IS_TRIVIALLY_COPYABLE} + +/* Define to a function implementing stricmp */ +#cmakedefine stricmp ${stricmp} + +/* Define to a function implementing strdup */ +#cmakedefine strdup ${strdup} + +/* Whether GlobalISel rule coverage is being collected */ +#cmakedefine01 LLVM_GISEL_COV_ENABLED + +/* Define to the default GlobalISel coverage file prefix */ +#cmakedefine LLVM_GISEL_COV_PREFIX "${LLVM_GISEL_COV_PREFIX}" + +/* Whether Timers signpost passes in Xcode Instruments */ +#cmakedefine01 LLVM_SUPPORT_XCODE_SIGNPOSTS + +#endif diff --git a/utils/bazel/llvm_configs/llvm-config.h.cmake b/utils/bazel/llvm_configs/llvm-config.h.cmake new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm_configs/llvm-config.h.cmake @@ -0,0 +1,94 @@ +/*===------- llvm/Config/llvm-config.h - llvm configuration -------*- C -*-===*/ +/* */ +/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ +/* Exceptions. */ +/* See https://llvm.org/LICENSE.txt for license information. */ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* */ +/*===----------------------------------------------------------------------===*/ + +/* This file enumerates variables from the LLVM configuration so that they + can be in exported headers and won't override package specific directives. + This is a C header that can be included in the llvm-c headers. */ + +#ifndef LLVM_CONFIG_H +#define LLVM_CONFIG_H + +/* Define if LLVM_ENABLE_DUMP is enabled */ +#cmakedefine LLVM_ENABLE_DUMP + +/* Target triple LLVM will generate code for by default */ +#cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" + +/* Define if threads enabled */ +#cmakedefine01 LLVM_ENABLE_THREADS + +/* Has gcc/MSVC atomic intrinsics */ +#cmakedefine01 LLVM_HAS_ATOMICS + +/* Host triple LLVM will be executed on */ +#cmakedefine LLVM_HOST_TRIPLE "${LLVM_HOST_TRIPLE}" + +/* LLVM architecture name for the native architecture, if available */ +#cmakedefine LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH} + +/* LLVM name for the native AsmParser init function, if available */ +#cmakedefine LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser + +/* LLVM name for the native AsmPrinter init function, if available */ +#cmakedefine LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter + +/* LLVM name for the native Disassembler init function, if available */ +#cmakedefine LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler + +/* LLVM name for the native Target init function, if available */ +#cmakedefine LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target + +/* LLVM name for the native TargetInfo init function, if available */ +#cmakedefine LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo + +/* LLVM name for the native target MC init function, if available */ +#cmakedefine LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC + +/* Define if this is Unixish platform */ +#cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX} + +/* Define if we have the Intel JIT API runtime support library */ +#cmakedefine01 LLVM_USE_INTEL_JITEVENTS + +/* Define if we have the oprofile JIT-support library */ +#cmakedefine01 LLVM_USE_OPROFILE + +/* Define if we have the perf JIT-support library */ +#cmakedefine01 LLVM_USE_PERF + +/* Major version of the LLVM API */ +#define LLVM_VERSION_MAJOR ${LLVM_VERSION_MAJOR} + +/* Minor version of the LLVM API */ +#define LLVM_VERSION_MINOR ${LLVM_VERSION_MINOR} + +/* Patch version of the LLVM API */ +#define LLVM_VERSION_PATCH ${LLVM_VERSION_PATCH} + +/* LLVM version string */ +#define LLVM_VERSION_STRING "${PACKAGE_VERSION}" + +/* Whether LLVM records statistics for use with GetStatistics(), + * PrintStatistics() or PrintStatisticsJSON() + */ +#cmakedefine01 LLVM_FORCE_ENABLE_STATS + +/* Define if we have z3 and want to build it */ +#cmakedefine LLVM_WITH_Z3 ${LLVM_WITH_Z3} + +/* Define if LLVM was built with a dependency to the libtensorflow dynamic library */ +#cmakedefine LLVM_HAVE_TF_API + +/* Define if LLVM was built with a dependency to the tensorflow compiler */ +#cmakedefine LLVM_HAVE_TF_AOT + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYSEXITS_H ${HAVE_SYSEXITS_H} + +#endif diff --git a/utils/bazel/overlay_directories.bzl b/utils/bazel/overlay_directories.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/overlay_directories.bzl @@ -0,0 +1,84 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +def _is_absolute(path): + """Returns `True` if `path` is an absolute path. + + Args: + path: A path (which is a string). + Returns: + `True` if `path` is an absolute path. + """ + return path.startswith("/") or (len(path) > 2 and path[1] == ":") + +def _join_path(a, b): + if _is_absolute(b): + return b + return str(a) + "/" + str(b) + +def _overlay_directories_impl(repository_ctx): + src_workspace_path = repository_ctx.path( + repository_ctx.attr.src_workspace, + ).dirname + + src_path = _join_path(src_workspace_path, repository_ctx.attr.src_path) + + overlay_workspace_path = repository_ctx.path( + repository_ctx.attr.overlay_workspace, + ).dirname + overlay_path = _join_path( + overlay_workspace_path, + repository_ctx.attr.overlay_path, + ) + + overlay_script = repository_ctx.path( + repository_ctx.attr._overlay_script, + ) + python_bin = repository_ctx.which("python3") + if not python_bin: + # Windows typically just defines "python" as python3. The script itself + # contains a check to ensure python3. + python_bin = repository_ctx.which("python") + + if not python_bin: + fail("Failed to find python3 binary") + + cmd = [ + python_bin, + overlay_script, + "--src", + src_path, + "--overlay", + overlay_path, + "--target", + ".", + ] + exec_result = repository_ctx.execute(cmd, timeout = 20) + + if exec_result.return_code != 0: + fail(("Failed to execute overlay script: '{cmd}'\n" + + "Exited with code {return_code}\n" + + "stdout:\n{stdout}\n" + + "stderr:\n{stderr}\n").format( + cmd = " ".join([str(arg) for arg in cmd]), + return_code = exec_result.return_code, + stdout = exec_result.stdout, + stderr = exec_result.stderr, + )) + +overlay_directories = repository_rule( + implementation = _overlay_directories_impl, + local = True, + configure = True, + attrs = { + "_overlay_script": attr.label( + default = Label("//:overlay_directories.py"), + allow_single_file = True, + ), + "overlay_workspace": attr.label(default = Label("//:WORKSPACE")), + "overlay_path": attr.string(mandatory = True), + "src_workspace": attr.label(default = Label("//:WORKSPACE")), + "src_path": attr.string(mandatory = True), + }, +) diff --git a/utils/bazel/overlay_directories.py b/utils/bazel/overlay_directories.py new file mode 100755 --- /dev/null +++ b/utils/bazel/overlay_directories.py @@ -0,0 +1,92 @@ +#!/bin/python3 + +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +"""Overlays two directories into a target directory using symlinks. + +Tries to minimize the number of symlinks created (that is, does not symlink +every single file). Symlinks every file in the overlay directory. Only symlinks +individual files in the source directory if their parent directory is also +contained in the overlay directory tree. +""" + +import argparse +import errno +import os +import sys + + +def _check_python_version(): + if sys.version_info[0] < 3: + raise RuntimeError( + "Must be invoked with a python 3 interpreter but was %s" % + sys.executable) + + +def _check_dir_exists(path): + if not os.path.isdir(path): + raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), path) + + +def parse_arguments(): + parser = argparse.ArgumentParser(description=""" + Overlays two directories into a target directory using symlinks. + + Tries to minimize the number of symlinks created (that is, does not symlink + every single file). Symlinks every file in the overlay directory. Only + symlinks individual files in the source directory if their parent directory + is also contained in the overlay directory tree. + """) + parser.add_argument( + "--src", + required=True, + help="Directory that contains most of the content to symlink.") + parser.add_argument( + "--overlay", + required=True, + help="Directory to overlay on top of the source directory.") + parser.add_argument( + "--target", + required=True, + help="Directory in which to place the fused symlink directories.") + + args = parser.parse_args() + + _check_dir_exists(args.target) + _check_dir_exists(args.overlay) + _check_dir_exists(args.src) + + return args + + +def _symlink_abs(from_path, to_path): + os.symlink(os.path.abspath(from_path), os.path.abspath(to_path)) + + +def main(args): + for root, dirs, files in os.walk(args.overlay): + # We could do something more intelligent here and only symlink individual + # files if the directory is present in both overlay and src. This could also + # be generalized to an arbitrary number of directories without any + # "src/overlay" distinction. In the current use case we only have two and + # the overlay directory is always small, so putting that off for now. + rel_root = os.path.relpath(root, start=args.overlay) + if rel_root != ".": + os.mkdir(os.path.join(args.target, rel_root)) + + for file in files: + relpath = os.path.join(rel_root, file) + _symlink_abs(os.path.join(args.overlay, relpath), + os.path.join(args.target, relpath)) + + for src_entry in os.listdir(os.path.join(args.src, rel_root)): + if src_entry not in dirs: + relpath = os.path.join(rel_root, src_entry) + _symlink_abs(os.path.join(args.src, relpath), + os.path.join(args.target, relpath)) + + +if __name__ == "__main__": + _check_python_version() + main(parse_arguments()) diff --git a/utils/bazel/terminfo.bzl b/utils/bazel/terminfo.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/terminfo.bzl @@ -0,0 +1,202 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Repository rules to configure the terminfo used by LLVM. + +Most users should pick one of the explicit rules to configure their use of terminfo +with LLVM: +- `llvm_terminfo_system` will detect and link against a terminfo-implementing + system library (non-hermetically). +- 'llvm_terminfo_disable` will disable terminfo completely. + +If you would like to make your build configurable, you can use +`llvm_terminfo_from_env`. By default, this will disable terminfo, but will +inspect the environment variable (most easily set with a `--repo_env` flag to +the Bazel invocation) `BAZEL_LLVM_TERMINFO_STRATEGY`. If it is set to +`system` then it will behave the same as `llvm_terminfo_system`. Any other +setting will disable terminfo the same as not setting it at all. +""" + +def _llvm_terminfo_disable_impl(repository_ctx): + repository_ctx.template( + "BUILD", + repository_ctx.attr._disable_build_template, + executable = False, + ) + +_terminfo_disable_attrs = { + "_disable_build_template": attr.label( + default = Label("//deps_impl:terminfo_disable.BUILD"), + allow_single_file = True, + ), +} + +llvm_terminfo_disable = repository_rule( + implementation = _llvm_terminfo_disable_impl, + attrs = _terminfo_disable_attrs, +) + +def _find_c_compiler(repository_ctx): + """Returns the path to a plausible C compiler. + + This routine will only reliably work on roughly POSIX-y systems as it + ultimately falls back on the `cc` binary. Fortunately, the thing we are + trying to use it for (detecting if a trivial source file can compile and + link against a particular library) requires very little. + """ + cc_env = repository_ctx.os.environ.get("CC") + cc = None + if cc_env: + if "/" in cc_env: + return repository_ctx.path(cc_env) + else: + return repository_ctx.which(cc_env) + + # Look for Clang, GCC, and the POSIX / UNIX specified C compiler + # binaries. + for compiler in ["clang", "gcc", "c99", "c89", "cc"]: + cc = repository_ctx.which(compiler) + if cc: + return cc + + return None + +def _try_link(repository_ctx, cc, source, linker_flags): + """Returns `True` if able to link the source with the linker flag. + + Given a source file that contains references to library routines, this + will check that when linked with the provided linker flag, those + references are successfully resolved. This routine assumes a generally + POSIX-y and GCC-ish compiler and environment and shouldn't be expected to + work outside of that. + """ + cmd = [ + cc, + # Force discard the linked executable. + "-o", + "/dev/null", + # Leave language detection to the compiler. + source, + ] + + # The linker flag must be valid for a compiler invocation of the link step, + # so just append them to the command. + cmd += linker_flags + exec_result = repository_ctx.execute(cmd, timeout = 20) + return exec_result.return_code == 0 + +def _llvm_terminfo_system_impl(repository_ctx): + # LLVM doesn't need terminfo support on Windows, so just disable it. + if repository_ctx.os.name.lower().find("windows") != -1: + _llvm_terminfo_disable_impl(repository_ctx) + return + + if len(repository_ctx.attr.system_linkopts) > 0: + linkopts = repository_ctx.attr.system_linkopts + else: + required = repository_ctx.attr.system_required + + # Find a C compiler we can use to detect viable linkopts on this system. + cc = _find_c_compiler(repository_ctx) + if not cc: + if required: + fail("Failed to find a C compiler executable") + else: + _llvm_terminfo_disable_impl(repository_ctx) + return + + # Get the source file we use to detect successful linking of terminfo. + source = repository_ctx.path(repository_ctx.attr._terminfo_test_source) + + # Collect the candidate linkopts and wrap them into a list. Ideally, + # these would be provided as lists, but Bazel doesn't currently + # support that. See: https://github.com/bazelbuild/bazel/issues/12178 + linkopts_candidates = [[x] for x in repository_ctx.attr.candidate_system_linkopts] + + # For each candidate, try to use it to link our test source file. + for linkopts_candidate in linkopts_candidates: + if _try_link(repository_ctx, cc, source, linkopts_candidate): + linkopts = linkopts_candidate + break + + # If we never found a viable linkopts candidate, either error or disable + # terminfo for LLVM. + if not linkopts: + if required: + fail("Failed to detect which linkopt would successfully provide the " + + "necessary terminfo functionality") + else: + _llvm_terminfo_disable_impl(repository_ctx) + return + + repository_ctx.template( + "BUILD", + repository_ctx.attr._system_build_template, + substitutions = { + "{TERMINFO_LINKOPTS}": str(linkopts), + }, + executable = False, + ) + +def _merge_attrs(attrs_list): + attrs = {} + for input_attrs in attrs_list: + attrs.update(input_attrs) + return attrs + +_terminfo_system_attrs = _merge_attrs([_terminfo_disable_attrs, { + "_system_build_template": attr.label( + default = Label("//deps_impl:terminfo_system.BUILD"), + allow_single_file = True, + ), + "_terminfo_test_source": attr.label( + default = Label("//deps_impl:terminfo_test.c"), + allow_single_file = True, + ), + "candidate_system_linkopts": attr.string_list( + default = [ + "-lterminfo", + "-ltinfo", + "-lcurses", + "-lncurses", + "-lncursesw", + ], + doc = "Candidate linkopts to test and see if they can link " + + "successfully.", + ), + "system_required": attr.bool( + default = False, + doc = "Require that one of the candidates is detected successfully on POSIX platforms where it is needed.", + ), + "system_linkopts": attr.string_list( + default = [], + doc = "If non-empty, a specific array of linkopts to use to " + + "successfully link against the terminfo library. No " + + "detection is performed if this option is provided, it " + + "directly forces the use of these link options. No test is " + + "run to determine if they are valid or work correctly either.", + ), +}]) + +llvm_terminfo_system = repository_rule( + implementation = _llvm_terminfo_system_impl, + configure = True, + local = True, + attrs = _terminfo_system_attrs, +) + +def _llvm_terminfo_from_env_impl(repository_ctx): + terminfo_strategy = repository_ctx.os.environ.get("BAZEL_LLVM_TERMINFO_STRATEGY") + if terminfo_strategy == "system": + _llvm_terminfo_system_impl(repository_ctx) + else: + _llvm_terminfo_disable_impl(repository_ctx) + +llvm_terminfo_from_env = repository_rule( + implementation = _llvm_terminfo_from_env_impl, + configure = True, + local = True, + attrs = _merge_attrs([_terminfo_disable_attrs, _terminfo_system_attrs]), + environ = ["BAZEL_LLVM_TERMINFO_STRATEGY", "CC"], +) diff --git a/utils/bazel/third_party_build/BUILD b/utils/bazel/third_party_build/BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/third_party_build/BUILD @@ -0,0 +1,5 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +licenses(["notice"]) diff --git a/utils/bazel/third_party_build/vulkan_headers.BUILD b/utils/bazel/third_party_build/vulkan_headers.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/third_party_build/vulkan_headers.BUILD @@ -0,0 +1,30 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +# Exports all headers but defining VK_NO_PROTOTYPES to disable the +# inclusion of C function prototypes. Useful if dynamically loading +# all symbols via dlopen/etc. +# Not all headers are hermetic, so they are just included as textual +# headers to disable additional validation. +cc_library( + name = "vulkan_headers_no_prototypes", + defines = ["VK_NO_PROTOTYPES"], + includes = ["include"], + textual_hdrs = glob(["include/vulkan/*.h"]), +) + +# Exports all headers, including C function prototypes. Useful if statically +# linking against the Vulkan SDK. +# Not all headers are hermetic, so they are just included as textual +# headers to disable additional validation. +cc_library( + name = "vulkan_headers", + includes = ["include"], + textual_hdrs = glob(["include/vulkan/*.h"]), +) diff --git a/utils/bazel/third_party_build/zlib.BUILD b/utils/bazel/third_party_build/zlib.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/third_party_build/zlib.BUILD @@ -0,0 +1,46 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +package( + default_visibility = ["//visibility:public"], + # BSD/MIT-like license (for zlib) + licenses = ["notice"], +) + +cc_library( + name = "zlib", + srcs = [ + "adler32.c", + "compress.c", + "crc32.c", + "crc32.h", + "deflate.c", + "deflate.h", + "gzclose.c", + "gzguts.h", + "gzlib.c", + "gzread.c", + "gzwrite.c", + "infback.c", + "inffast.c", + "inffast.h", + "inffixed.h", + "inflate.c", + "inflate.h", + "inftrees.c", + "inftrees.h", + "trees.c", + "trees.h", + "uncompr.c", + "zconf.h", + "zutil.c", + "zutil.h", + ], + hdrs = ["zlib.h"], + copts = [ + "-Wno-shift-negative-value", + "-DZ_HAVE_UNISTD_H", + ], + includes = ["."], +) diff --git a/utils/bazel/vulkan_sdk.bzl b/utils/bazel/vulkan_sdk.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/vulkan_sdk.bzl @@ -0,0 +1,43 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Repository rule to statically link against the Vulkan SDK. + +Requires installing the Vulkan SDK from https://vulkan.lunarg.com/. + +If the Vulkan SDK is not installed, this generates an empty rule and you may +encounter linker errors like `error: undefined reference to 'vkCreateInstance'`. +""" + +def _impl(repository_ctx): + if "VULKAN_SDK" in repository_ctx.os.environ: + sdk_path = repository_ctx.os.environ["VULKAN_SDK"] + repository_ctx.symlink(sdk_path, "vulkan-sdk") + + repository_ctx.file("BUILD", """ +cc_library( + name = "sdk", + srcs = select({ + "@bazel_tools//src/conditions:windows": [ + "vulkan-sdk/Lib/vulkan-1.lib" + ], + "//conditions:default": [ + "vulkan-sdk/lib/libvulkan.so.1", + ], + }), + visibility = ["//visibility:public"], +)""") + else: + # Empty rule. Will fail to link for just targets that use Vulkan. + repository_ctx.file("BUILD", """ +cc_library( + name = "sdk", + srcs = [], + visibility = ["//visibility:public"], +)""") + +vulkan_sdk_setup = repository_rule( + implementation = _impl, + local = True, +) diff --git a/utils/bazel/zlib.bzl b/utils/bazel/zlib.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/zlib.bzl @@ -0,0 +1,112 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Repository rules to configure the zlib used by LLVM. + +Most users should pick one of the explicit rules to configure their use of zlib +with LLVM: +- `llvm_zlib_external` will link against an external Bazel zlib repository. +- `llvm_zlib_system` will link against the system zlib (non-hermetically). +- 'llvm_zlib_disable` will disable zlib completely. + +If you would like to make your build configurable, you can use +`llvm_zlib_from_env`. By default, this will disable zlib, but will inspect +the environment variable (most easily set with a `--repo_env` flag to the +Bazel invocation) `BAZEL_LLVM_ZLIB_STRATEGY`. If it is set to `external`, +then it will behave the same as `llvm_zlib_external`. If it is set to +`system` then it will behave the same as `llvm_zlib_system`. Any other +setting will disable zlib the same as not setting it at all. +""" + +def _llvm_zlib_external_impl(repository_ctx): + repository_ctx.template( + "BUILD", + repository_ctx.attr._external_build_template, + substitutions = { + "@external_zlib_repo//:zlib_rule": str(repository_ctx.attr.external_zlib), + }, + executable = False, + ) + +llvm_zlib_external = repository_rule( + implementation = _llvm_zlib_external_impl, + attrs = { + "_external_build_template": attr.label( + default = Label("//deps_impl:zlib_external.BUILD"), + allow_single_file = True, + ), + "external_zlib": attr.label( + doc = "The dependency that should be used for the external zlib library.", + mandatory = True, + ), + }, +) + +def _llvm_zlib_system_impl(repository_ctx): + repository_ctx.template( + "BUILD", + repository_ctx.attr._system_build_template, + executable = False, + ) + +# While it may seem like this needs to be local, it doesn't actually inspect +# any local state, it just configures to build against that local state. +llvm_zlib_system = repository_rule( + implementation = _llvm_zlib_system_impl, + attrs = { + "_system_build_template": attr.label( + default = Label("//deps_impl:zlib_system.BUILD"), + allow_single_file = True, + ), + }, +) + +def _llvm_zlib_disable_impl(repository_ctx): + repository_ctx.template( + "BUILD", + repository_ctx.attr._disable_build_template, + executable = False, + ) + +llvm_zlib_disable = repository_rule( + implementation = _llvm_zlib_disable_impl, + attrs = { + "_disable_build_template": attr.label( + default = Label("//deps_impl:zlib_disable.BUILD"), + allow_single_file = True, + ), + }, +) + +def _llvm_zlib_from_env_impl(repository_ctx): + zlib_strategy = repository_ctx.os.environ.get("BAZEL_LLVM_ZLIB_STRATEGY") + if zlib_strategy == "external": + _llvm_zlib_external_impl(repository_ctx) + elif zlib_strategy == "system": + _llvm_zlib_system_impl(repository_ctx) + else: + _llvm_zlib_disable_impl(repository_ctx) + +llvm_zlib_from_env = repository_rule( + implementation = _llvm_zlib_from_env_impl, + attrs = { + "_disable_build_template": attr.label( + default = Label("//deps_impl:zlib_disable.BUILD"), + allow_single_file = True, + ), + "_external_build_template": attr.label( + default = Label("//deps_impl:zlib_external.BUILD"), + allow_single_file = True, + ), + "_system_build_template": attr.label( + default = Label("//deps_impl:zlib_system.BUILD"), + allow_single_file = True, + ), + "external_zlib": attr.label( + doc = "The dependency that should be used for the external zlib library.", + mandatory = True, + ), + }, + environ = ["BAZEL_LLVM_ZLIB_STRATEGY"], +)