llvm/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

# 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("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("//mlir:tblgen.bzl", "td_library")
load(":binary_alias.bzl", "binary_alias")
load(":config.bzl", "llvm_config_defines")
load(":driver.bzl", "generate_driver_selects", "generate_driver_tools_def", "llvm_driver_cc_binary", "select_driver_tools")
load(":enum_targets_gen.bzl", "enum_targets_gen")
load(":targets.bzl", "llvm_targets")
load(":tblgen.bzl", "gentbl")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
)

licenses(["notice"])

exports_files([
    "LICENSE.TXT",
    "cmake/modules/llvm-driver-template.cpp.in",
    "include/llvm/BinaryFormat/Dwarf.def",
    "include/llvm/CodeGen/SDNodeProperties.td",
    "include/llvm/CodeGen/ValueTypes.td",
    "include/llvm/Frontend/Directive/DirectiveBase.td",
    "include/llvm/Frontend/OpenACC/ACC.td",
    "include/llvm/Frontend/OpenMP/OMP.td",
    "include/llvm/IR/Intrinsics.td",
    "include/llvm/Option/OptParser.td",
    "utils/lit/lit.py",
    "utils/lldbDataFormatters.py",
])

# 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)",
]

enum_targets_gen(
    name = "targets_def_gen",
    src = "include/llvm/Config/Targets.def.in",
    out = "include/llvm/Config/Targets.def",
    macro_name = "TARGET",
    targets = llvm_targets,
)

# Enabled targets with ASM printers.
llvm_target_asm_printers = [
    t
    for t in llvm_targets
    if glob(["lib/Target/{}/*AsmPrinter.cpp".format(t)])
]

enum_targets_gen(
    name = "asm_printers_def_gen",
    src = "include/llvm/Config/AsmPrinters.def.in",
    out = "include/llvm/Config/AsmPrinters.def",
    macro_name = "ASM_PRINTER",
    targets = llvm_target_asm_printers,
)

# Enabled targets with ASM parsers.
llvm_target_asm_parsers = [
    t
    for t in llvm_targets
    if glob(
        ["lib/Target/{}/AsmParser/CMakeLists.txt".format(t)],
        allow_empty = True,
    )
]

enum_targets_gen(
    name = "asm_parsers_def_gen",
    src = "include/llvm/Config/AsmParsers.def.in",
    out = "include/llvm/Config/AsmParsers.def",
    macro_name = "ASM_PARSER",
    targets = llvm_target_asm_parsers,
)

# Enabled targets with disassemblers.
llvm_target_disassemblers = [
    t
    for t in llvm_targets
    if glob(
        ["lib/Target/{}/Disassembler/CMakeLists.txt".format(t)],
        allow_empty = True,
    )
]

enum_targets_gen(
    name = "disassemblers_def_gen",
    src = "include/llvm/Config/Disassemblers.def.in",
    out = "include/llvm/Config/Disassemblers.def",
    macro_name = "DISASSEMBLER",
    targets = llvm_target_disassemblers,
)

# Enabled targets with MCA.
llvm_target_mcas = [
    t
    for t in llvm_targets
    if glob(
        ["lib/Target/{}/MCA/CMakeLists.txt".format(t)],
        allow_empty = True,
    )
]

enum_targets_gen(
    name = "target_mca_def_gen",
    src = "include/llvm/Config/TargetMCAs.def.in",
    out = "include/llvm/Config/TargetMCAs.def",
    macro_name = "TARGETMCA",
    targets = llvm_target_mcas,
)

# Enabled targets with exegesis.
llvm_target_exegesis = [
    t
    for t in llvm_targets
    if glob(
        ["tools/llvm-exegesis/lib/{}/CMakeLists.txt".format(t)],
        allow_empty = True,
    )
]

enum_targets_gen(
    name = "target_exegesis_def_gen",
    src = "include/llvm/Config/TargetExegesis.def.in",
    out = "include/llvm/Config/TargetExegesis.def",
    macro_name = "EXEGESIS",
    placeholder_name = "@LLVM_ENUM_EXEGESIS@",
    targets = llvm_target_exegesis,
)

expand_template(
    name = "abi_breaking_h_gen",
    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",
    },
    template = "include/llvm/Config/abi-breaking.h.cmake",
)

# 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",
])

td_library(
    name = "OptParserTdFiles",
    srcs = ["include/llvm/Option/OptParser.td"],
    includes = ["include"],
)

llvm_config_target_defines = [
    "LLVM_HAS_{}_TARGET=1".format(t)
    for t in llvm_targets
]

cc_library(
    name = "config",
    hdrs = [
        "include/llvm/Config/abi-breaking.h",
        "include/llvm/Config/llvm-config.h",
    ],
    copts = llvm_copts,
    defines = llvm_config_defines + llvm_config_target_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",
        "include/llvm/Config/TargetExegesis.def",
        "include/llvm/Config/TargetMCAs.def",
        # Needed for include scanner to find execinfo.h
        "include/llvm/Config/config.h",
    ],
)

cc_library(
    name = "Demangle",
    srcs = glob([
        "lib/Demangle/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/Demangle/*.h",
        "include/llvm/Demangle/*.def",
    ]),
    copts = llvm_copts,
    deps = [":config"],
)

genrule(
    name = "generate_vcs_revision",
    outs = ["include/llvm/Support/VCSRevision.h"],
    cmd = "echo '#undef LLVM_REVISION' >> $@\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",
        # To avoid a dependency cycle.
        "include/llvm/Option/*.h",
    ]) + select({
        "@platforms//os:windows": glob([
            "lib/Support/Windows/*.inc",
        ]),
        "//conditions:default": glob([
            "lib/Support/Unix/*.h",
            "lib/Support/Unix/*.inc",
        ]),
    }) + [
        "lib/Support/BLAKE3/blake3.c",
        "lib/Support/BLAKE3/blake3_dispatch.c",
        "lib/Support/BLAKE3/blake3_impl.h",
        "lib/Support/BLAKE3/blake3_portable.c",
        "lib/Support/BLAKE3/llvm_blake3_prefix.h",
    ] + select({
        "@platforms//cpu:aarch64": [
            "lib/Support/BLAKE3/blake3_neon.c",
        ],
        "@platforms//cpu:x86_64": [
            "lib/Support/BLAKE3/blake3_avx2_x86-64_unix.S",
            "lib/Support/BLAKE3/blake3_avx512_x86-64_unix.S",
            "lib/Support/BLAKE3/blake3_sse2_x86-64_unix.S",
            "lib/Support/BLAKE3/blake3_sse41_x86-64_unix.S",
        ],
        "//conditions:default": [
        ],
    }),
    hdrs = glob([
        "include/llvm/Support/**/*.h",
        "include/llvm/ADT/*.h",
    ]) + [
        "include/llvm-c/Core.h",
        "include/llvm-c/DataTypes.h",
        "include/llvm-c/Deprecated.h",
        "include/llvm-c/DisassemblerTypes.h",
        "include/llvm-c/Error.h",
        "include/llvm-c/ErrorHandling.h",
        "include/llvm-c/ExternC.h",
        "include/llvm-c/Support.h",
        "include/llvm-c/Types.h",
        "include/llvm-c/blake3.h",
        "include/llvm/ExecutionEngine/JITSymbol.h",
        "include/llvm/Support/Extension.def",
        "include/llvm/Support/VCSRevision.h",
    ],
    copts = llvm_copts,
    defines = select({
        "@platforms//cpu:aarch64": [
        ],
        "//conditions:default": [
            "BLAKE3_USE_NEON=0",
        ],
    }) + select({
        "@platforms//cpu:x86_64": [
        ],
        "//conditions:default": [
            "BLAKE3_NO_AVX2",
            "BLAKE3_NO_AVX512",
            "BLAKE3_NO_SSE2",
            "BLAKE3_NO_SSE41",
        ],
    }),
    includes = ["include"],
    linkopts = select({
        "@platforms//os:windows": [
            "ws2_32.lib",
            "ntdll.lib",
        ],
        "@platforms//os:freebsd": [
            "-pthread",
            "-lexecinfo",
            "-ldl",
            "-lm",
        ],
        "@platforms//os:macos": [
            "-pthread",
            "-ldl",
        ],
        "//conditions:default": [
            "-pthread",
            "-ldl",
            "-lm",
        ],
    }),
    textual_hdrs = glob([
        "include/llvm/Support/*.def",
    ]),
    deps = [
        ":config",
        ":Demangle",
        # 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",
        # We unconditionally depend on the custom LLVM zstd wrapper. This will
        # be an empty library unless zstd is enabled, in which case it will
        # both provide the necessary dependencies and configuration defines.
        "@llvm_zstd//:zstd",
    ],
)

# Note: although FileCheck (the binary) is a test utility, some non-test
# targets depend on the FileCheck library target.
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",
    ]),
    hdrs = glob(["include/llvm/LineEditor/*.h"]),
    copts = llvm_copts,
    deps = [
        ":Support",
        ":config",
    ],
)

cc_library(
    name = "Option",
    srcs = glob([
        "lib/Option/*.cpp",
    ]),
    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-c/Comdat.h",
        "include/llvm-c/DebugInfo.h",
        "include/llvm/IR/Value.def",
    ],
    copts = llvm_copts,
)

cc_library(
    name = "BinaryFormat",
    srcs = glob([
        "lib/BinaryFormat/*.cpp",
    ]),
    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",
        ":TargetParser",
    ],
)

cc_library(
    name = "DebugInfo",
    hdrs = glob(["include/llvm/DebugInfo/**/*.h"]),
    copts = llvm_copts,
    textual_hdrs = glob(["include/llvm/DebugInfo/**/*.def"]),
    deps = [
        ":Object",
        ":Support",
    ],
)

cc_library(
    name = "DebugInfoMSF",
    srcs = glob([
        "lib/DebugInfo/MSF/*.cpp",
    ]),
    hdrs = glob(["include/llvm/DebugInfo/MSF/*.h"]),
    copts = llvm_copts,
    deps = [":Support"],
)

cc_library(
    name = "DebugInfoBTF",
    srcs = glob([
        "lib/DebugInfo/BTF/*.cpp",
    ]),
    hdrs = glob(["include/llvm/DebugInfo/BTF/*.h"]) + [
        "include/llvm/DebugInfo/BTF/BTF.def",
    ],
    copts = llvm_copts,
    deps = [
        ":DebugInfo",
        ":Object",
        ":Support",
    ],
)

cc_library(
    name = "DebugInfoCodeView",
    srcs = glob([
        "lib/DebugInfo/CodeView/*.cpp",
    ]),
    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 = "DebugInfoLogicalView",
    srcs = glob([
        "lib/DebugInfo/LogicalView/**/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/DebugInfo/LogicalView/**/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfo",
        ":DebugInfoCodeView",
        ":DebugInfoDWARF",
        ":DebugInfoPDB",
        ":Demangle",
        ":MC",
        ":MCDisassembler",
        ":Object",
        ":Support",
    ],
)

cc_library(
    name = "DebugInfoPDB",
    srcs = glob([
        "lib/DebugInfo/PDB/*.cpp",
        "lib/DebugInfo/PDB/Native/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/DebugInfo/PDB/*.h",
        "include/llvm/DebugInfo/PDB/Native/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfo",
        ":DebugInfoBTF",
        ":DebugInfoCodeView",
        ":DebugInfoMSF",
        ":Object",
        ":Support",
        ":config",
    ],
)

cc_library(
    name = "Debuginfod",
    srcs = glob([
        "lib/Debuginfod/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/Debuginfod/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfoDWARF",
        ":Object",
        ":Support",
        ":Symbolize",
    ],
)

cc_library(
    name = "MC",
    srcs = glob([
        "lib/MC/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/MC/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfoCodeView",
        ":Support",
        ":TargetParser",
        ":config",
        ":ir_headers",
    ],
)

cc_library(
    name = "DebugInfoDWARF",
    srcs = glob([
        "lib/DebugInfo/DWARF/*.cpp",
    ]),
    hdrs = glob(["include/llvm/DebugInfo/DWARF/*.h"]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfo",
        ":MC",
        ":Object",
        ":Support",
        ":TargetParser",
    ],
)

cc_library(
    name = "DebugInfoGSYM",
    srcs = glob([
        "lib/DebugInfo/GSYM/*.cpp",
    ]),
    hdrs = glob(["include/llvm/DebugInfo/GSYM/*.h"]),
    copts = llvm_copts,
    deps = [
        ":DebugInfo",
        ":DebugInfoDWARF",
        ":MC",
        ":Object",
        ":Support",
    ],
)

cc_library(
    name = "Symbolize",
    srcs = glob([
        "lib/DebugInfo/Symbolize/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/DebugInfo/Symbolize/*.h",
        "include/llvm/Debuginfod/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfo",
        ":DebugInfoDWARF",
        ":DebugInfoPDB",
        ":Demangle",
        ":Object",
        ":Support",
        ":TargetParser",
    ],
)

# Command line flag to control which tools get included in the llvm driver binary.
# The macro also generates config_setting targets used by select_driver_tools().
generate_driver_selects(name = "driver-tools")

generate_driver_tools_def(
    name = "gen_llvm_driver_tools_def",
    out = "LLVMDriverTools.def",
    driver_tools = select_driver_tools(":driver-tools"),
)

# Workaround inability to put `.def` files into `srcs` with a library
cc_library(
    name = "llvm_driver_tools_def_lib",
    includes = ["."],
    textual_hdrs = ["LLVMDriverTools.def"],
)

cc_binary(
    name = "llvm",
    srcs = glob(["tools/llvm-driver/*.cpp"]),
    deps = [
        ":Support",
        ":llvm_driver_tools_def_lib",
    ] + select_driver_tools(":driver-tools"),
)

cc_binary(
    name = "llvm-min-tblgen",
    srcs = [
        "utils/TableGen/ARMTargetDefEmitter.cpp",
        "utils/TableGen/Attributes.cpp",
        "utils/TableGen/Basic/CodeGenIntrinsics.cpp",
        "utils/TableGen/Basic/CodeGenIntrinsics.h",
        "utils/TableGen/Basic/SDNodeProperties.cpp",
        "utils/TableGen/Basic/SDNodeProperties.h",
        "utils/TableGen/Basic/SequenceToOffsetTable.h",
        "utils/TableGen/DirectiveEmitter.cpp",
        "utils/TableGen/IntrinsicEmitter.cpp",
        "utils/TableGen/RISCVTargetDefEmitter.cpp",
        "utils/TableGen/TableGen.cpp",
        "utils/TableGen/VTEmitter.cpp",
    ],
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":Support",
        ":TableGen",
        ":config",
    ],
)

cc_library(
    name = "TableGenGlobalISel",
    srcs = [
        "utils/TableGen/Common/GlobalISel/CodeExpander.cpp",
    ],
    hdrs = [
        # 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/Common/GlobalISel/CodeExpander.h",
        "utils/TableGen/Common/GlobalISel/CodeExpansions.h",
    ],
    copts = llvm_copts,
    features = ["-header_modules"],
    strip_include_prefix = "utils/TableGen",
    deps = [
        ":CodeGenTypes",
        ":Support",
        ":TableGen",
        ":config",
    ],
)

cc_library(
    name = "llvm-tblgen-headers",
    textual_hdrs = glob(["utils/TableGen/*.def"]),
)

cc_binary(
    name = "llvm-tblgen",
    srcs = glob(
        [
            "utils/TableGen/*.cpp",
            "utils/TableGen/*.h",
            "utils/TableGen/Basic/*.cpp",
            "utils/TableGen/Basic/*.h",
            "utils/TableGen/Common/*.cpp",
            "utils/TableGen/Common/*.h",
            "utils/TableGen/Common/GlobalISel/*.cpp",
            "utils/TableGen/Common/GlobalISel/*.h",

            # Some tablegen sources include headers from MC, so these have to be
            # listed here. MC uses headers produced by tablegen, so it cannot be a
            # regular dependency.
            "include/llvm/MC/*.h",
        ],
        exclude = ["utils/TableGen/Common/GlobalISel/CodeExpander.cpp"],
    ) + [
        "include/llvm/TargetParser/SubtargetFeature.h",
    ],
    copts = llvm_copts,
    includes = ["utils/TableGen"],
    stamp = 0,
    deps = [
        ":CodeGenTypes",
        ":Support",
        ":TableGen",
        ":TableGenGlobalISel",
        ":TargetParser",
        ":config",
        ":llvm-tblgen-headers",
        ":vt_gen",
    ],
)

gentbl(
    name = "intrinsic_enums_gen",
    tbl_outs = [("-gen-intrinsic-enums", "include/llvm/IR/IntrinsicEnums.inc")],
    tblgen = ":llvm-min-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-min-tblgen",
    td_file = "include/llvm/IR/Intrinsics.td",
    td_srcs = glob([
        "include/llvm/CodeGen/*.td",
        "include/llvm/IR/Intrinsics*.td",
    ]),
)

gentbl(
    name = "vt_gen",
    tbl_outs = [("-gen-vt", "include/llvm/CodeGen/GenVT.inc")],
    tblgen = ":llvm-min-tblgen",
    td_file = "include/llvm/CodeGen/ValueTypes.td",
    td_srcs = [
        "include/llvm/CodeGen/ValueTypes.td",
    ],
)

# Note that the intrinsics are not currently set up so they can be pruned for
# disabled targets.
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": "DirectX",
        "intrinsic_prefix": "dx",
    },
    {
        "name": "Hexagon",
        "intrinsic_prefix": "hexagon",
    },
    {
        "name": "LoongArch",
        "intrinsic_prefix": "loongarch",
    },
    {
        "name": "Mips",
        "intrinsic_prefix": "mips",
    },
    {
        "name": "NVPTX",
        "intrinsic_prefix": "nvvm",
    },
    {
        "name": "PowerPC",
        "intrinsic_prefix": "ppc",
    },
    {
        "name": "R600",
        "intrinsic_prefix": "r600",
    },
    {
        "name": "RISCV",
        "intrinsic_prefix": "riscv",
    },
    {
        "name": "S390",
        "intrinsic_prefix": "s390",
    },
    {
        "name": "SPIRV",
        "intrinsic_prefix": "spv",
    },
    {
        "name": "VE",
        "intrinsic_prefix": "ve",
    },
    {
        "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-min-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-min-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",
    ]),
    hdrs = [
        "include/llvm/Bitstream/BitCodeEnums.h",
        "include/llvm/Bitstream/BitCodes.h",
        "include/llvm/Bitstream/BitstreamReader.h",
    ],
    copts = llvm_copts,
    deps = [
        ":Support",
    ],
)

cc_library(
    name = "BitstreamWriter",
    hdrs = [
        "include/llvm/Bitstream/BitCodeEnums.h",
        "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",
        ":Remarks",
        ":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",
        "include/llvm/Analysis/ValueTracking.h",
        "include/llvm/Analysis/SimplifyQuery.h",
        "include/llvm/Analysis/WithCache.h",
    ] + [":llvm_intrinsics_headers"],
    copts = llvm_copts,
    textual_hdrs = glob(["include/llvm/IR/*.def"]),
    deps = [
        ":BinaryFormat",
        ":Demangle",
        ":Remarks",
        ":Support",
        ":TargetParser",
        ":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 = [
        ":BinaryFormat",
        ":BitstreamReader",
        ":Core",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

cc_library(
    name = "MCParser",
    srcs = glob([
        "lib/MC/MCParser/*.cpp",
    ]),
    hdrs = glob(["include/llvm/MC/MCParser/*.h"]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfoCodeView",
        ":MC",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

cc_library(
    name = "TextAPI",
    srcs = glob(
        [
            "lib/TextAPI/**/*.cpp",
        ],
        exclude = ["lib/TextAPI/BinaryReader/**"],
    ),
    hdrs = glob(
        [
            "include/llvm/TextAPI/**/*.h",
            "include/llvm/TextAPI/**/*.def",
            "lib/TextAPI/**/*.h",
        ],
        exclude = [
            "lib/TextAPI/BinaryReader/**",
            "include/llvm/TextAPI/DylibReader.h",
        ],
    ),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":Support",
        ":TargetParser",
    ],
)

cc_library(
    name = "TextAPIBinaryReader",
    srcs = glob([
        "lib/TextAPI/BinaryReader/**/*.cpp",
    ]),
    hdrs = ["include/llvm/TextAPI/DylibReader.h"],
    copts = llvm_copts,
    deps = [
        ":DebugInfoDWARF",
        ":Object",
        ":Support",
        ":TargetParser",
        ":TextAPI",
    ],
)

cc_library(
    name = "ObjCopy",
    srcs = glob([
        "lib/ObjCopy/**/*.cpp",
        "lib/ObjCopy/**/*.h",
    ]),
    hdrs = glob([
        "include/llvm/ObjCopy/**/*.h",
    ]),
    copts = llvm_copts,
    includes = ["lib/ObjCopy"],
    deps = [
        ":BinaryFormat",
        ":MC",
        ":Object",
        ":ObjectYAML",
        ":Option",
        ":Support",
        ":Target",
        ":intrinsics_impl_gen",
    ],
)

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",
        ":IRReader",
        ":MC",
        ":MCParser",
        ":Support",
        ":TargetParser",
        ":TextAPI",
        ":config",
    ],
)

cc_library(
    name = "ObjectYAML",
    srcs = glob([
        "lib/ObjectYAML/*.cpp",
    ]),
    hdrs = glob(["include/llvm/ObjectYAML/*.h"]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfoCodeView",
        ":MC",
        ":Object",
        ":Support",
        ":TargetParser",
    ],
)

cc_library(
    name = "ProfileData",
    srcs = glob([
        "lib/ProfileData/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/ProfileData/*.h",
        "include/llvm/ProfileData/*.inc",
    ]),
    copts = llvm_copts,
    deps = [
        ":BitstreamReader",
        ":BitstreamWriter",
        ":Core",
        ":DebugInfo",
        ":DebugInfoDWARF",
        ":Demangle",
        ":Object",
        ":Support",
        ":Symbolize",
        ":TargetParser",
        ":config",
    ],
)

cc_library(
    name = "Coverage",
    srcs = glob([
        "lib/ProfileData/Coverage/*.cpp",
    ]),
    hdrs = glob(["include/llvm/ProfileData/Coverage/*.h"]),
    copts = llvm_copts,
    deps = [
        ":Object",
        ":ProfileData",
        ":Support",
        ":TargetParser",
    ],
)

cc_library(
    name = "Analysis",
    srcs = glob(
        [
            "lib/Analysis/*.cpp",
        ],
    ),
    hdrs = glob(
        [
            "include/llvm/Analysis/*.h",
            "include/llvm/Analysis/Utils/*.h",
        ],
    ) + [
        "include/llvm-c/Analysis.h",
    ],
    copts = llvm_copts,
    textual_hdrs = glob([
        "include/llvm/Analysis/*.def",
    ]),
    deps = [
        ":BinaryFormat",
        ":Core",
        ":Object",
        ":ProfileData",
        ":Support",
        ":TargetParser",
        ":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/BitcodeConvenience.h",
        "include/llvm/Bitcode/BitcodeWriter.h",
        "include/llvm/Bitcode/BitcodeWriterPass.h",
        "include/llvm/Bitcode/LLVMBitCodes.h",
    ],
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":BitReader",
        ":BitstreamWriter",
        ":Core",
        ":MC",
        ":Object",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

cc_library(
    name = "Target",
    srcs = glob([
        "lib/Target/*.cpp",
    ]),
    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",
        ":TargetParser",
        ":config",
    ],
)

gentbl(
    name = "ARMTargetParserDefGen",
    tbl_outs = [("-gen-arm-target-def", "include/llvm/TargetParser/ARMTargetParserDef.inc")],
    tblgen = ":llvm-min-tblgen",
    td_file = "lib/Target/ARM/ARM.td",
    td_srcs = [
        ":common_target_td_sources",
    ] + glob([
        "lib/Target/ARM/**/*.td",
    ]),
)

gentbl(
    name = "AArch64TargetParserDefGen",
    tbl_outs = [("-gen-arm-target-def", "include/llvm/TargetParser/AArch64TargetParserDef.inc")],
    tblgen = ":llvm-min-tblgen",
    td_file = "lib/Target/AArch64/AArch64.td",
    td_srcs = [
        ":common_target_td_sources",
    ] + glob([
        "lib/Target/AArch64/**/*.td",
    ]),
)

gentbl(
    name = "RISCVTargetParserDefGen",
    tbl_outs = [("-gen-riscv-target-def", "include/llvm/TargetParser/RISCVTargetParserDef.inc")],
    tblgen = ":llvm-min-tblgen",
    td_file = "lib/Target/RISCV/RISCV.td",
    td_srcs = [
        ":common_target_td_sources",
    ] + glob([
        "lib/Target/RISCV/**/*.td",
    ]),
)

cc_library(
    name = "TargetParser",
    srcs = glob([
        "lib/TargetParser/*.cpp",
    ]) + select({
        "@platforms//os:windows": glob([
            "lib/TargetParser/Windows/*.inc",
        ]),
        "//conditions:default": glob([
            "lib/TargetParser/Unix/*.inc",
        ]),
    }),
    hdrs = glob([
        "include/llvm/TargetParser/*.h",
    ]),
    copts = llvm_copts,
    includes = ["include"],
    textual_hdrs = [
        "include/llvm/TargetParser/AArch64CPUFeatures.inc",
        "include/llvm/TargetParser/AArch64TargetParserDef.inc",
        "include/llvm/TargetParser/ARMTargetParserDef.inc",
        "include/llvm/TargetParser/RISCVTargetParserDef.inc",
    ] + glob([
        "include/llvm/TargetParser/*.def",
    ]),
    deps = [
        ":Support",
        ":config",
    ],
)

cc_library(
    name = "DWP",
    srcs = glob([
        "lib/DWP/*.cpp",
    ]),
    hdrs = glob(["include/llvm/DWP/*.h"]),
    copts = llvm_copts,
    deps = [
        ":DebugInfoDWARF",
        ":MC",
        ":Object",
        ":Support",
        ":Target",
    ],
)

cc_library(
    name = "TransformUtils",
    srcs = glob([
        "lib/Transforms/Utils/*.cpp",
    ]),
    hdrs = glob(["include/llvm/Transforms/Utils/*.h"]) + [
        "include/llvm/Transforms/Utils.h",
    ],
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":BinaryFormat",
        ":BitWriter",
        ":Core",
        ":ProfileData",
        ":Support",
        ":Target",
        ":TargetParser",
        ":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([
        "lib/Target/AMDGPU/*.td",
    ]) + [
        ":common_target_td_sources",
    ],
)

cc_library(
    name = "InstCombine",
    srcs = glob([
        "lib/Transforms/InstCombine/*.cpp",
        "lib/Transforms/InstCombine/*.h",
    ]),
    hdrs = glob(["include/llvm/Transforms/InstCombine/*.h"]),
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":Core",
        ":Support",
        ":Target",
        ":TransformUtils",
        ":config",
    ],
)

cc_library(
    name = "AggressiveInstCombine",
    srcs = glob([
        "lib/Transforms/AggressiveInstCombine/*.cpp",
        "lib/Transforms/AggressiveInstCombine/*.h",
    ]),
    hdrs = [
        "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/Utils/Instrumentation.h",
    ],
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":BinaryFormat",
        ":Core",
        ":Demangle",
        ":MC",
        ":ProfileData",
        ":Scalar",
        ":Support",
        ":Target",
        ":TargetParser",
        ":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 = "SandboxIR",
    srcs = glob([
        "lib/SandboxIR/*.cpp",
    ]),
    hdrs = glob(["include/llvm/SandboxIR/*.h"]),
    copts = llvm_copts,
    textual_hdrs = ["include/llvm/SandboxIR/Values.def"],
    deps = [
        ":Analysis",
        ":Core",
        ":Support",
    ],
)

cc_library(
    name = "Scalar",
    srcs = glob([
        "lib/Transforms/Scalar/*.cpp",
    ]),
    hdrs = glob(["include/llvm/Transforms/Scalar/*.h"]) + [
        "include/llvm/Transforms/Scalar.h",
    ],
    copts = llvm_copts,
    deps = [
        ":AggressiveInstCombine",
        ":Analysis",
        ":BinaryFormat",
        ":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",
    ]),
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":Core",
        ":SandboxIR",
        ":Scalar",
        ":Support",
        ":Target",
        ":TransformUtils",
        ":config",
    ],
)

cc_library(
    name = "FrontendDebug",
    hdrs = glob([
        "include/llvm/Frontend/Debug/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Support",
    ],
)

cc_library(
    name = "FrontendDriver",
    srcs = glob([
        "lib/Frontend/Driver/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/Frontend/Driver/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":TargetParser",
    ],
)

cc_library(
    name = "FrontendHLSL",
    srcs = glob([
        "lib/Frontend/HLSL/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/Frontend/HLSL/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Core",
        ":Support",
    ],
)

cc_library(
    name = "FrontendOffloading",
    srcs = glob([
        "lib/Frontend/Offloading/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/Frontend/Offloading/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":Core",
        ":Object",
        ":Support",
        ":TargetParser",
        ":TransformUtils",
    ],
)

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-min-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-impl", "include/llvm/Frontend/OpenMP/OMP.inc"),
    ],
    tblgen = ":llvm-min-tblgen",
    td_file = "include/llvm/Frontend/OpenMP/OMP.td",
    td_srcs = [":omp_td_files"],
)

cc_library(
    name = "FrontendOpenMP",
    srcs = glob([
        "lib/Frontend/OpenMP/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/Frontend/OpenMP/*.h",
    ]) + [
        "include/llvm/Frontend/OpenMP/OMP.h.inc",
        "include/llvm/Frontend/OpenMP/OMP.inc",
    ],
    copts = llvm_copts,
    textual_hdrs = glob([
        "include/llvm/Frontend/OpenMP/*.def",
    ]),
    deps = [
        ":Analysis",
        ":BitReader",
        ":Core",
        ":Demangle",
        ":FrontendOffloading",
        ":MC",
        ":Scalar",
        ":Support",
        ":Target",
        ":TargetParser",
        ":TransformUtils",
    ],
)

filegroup(
    name = "acc_td_files",
    srcs = glob([
        "include/llvm/Frontend/OpenACC/*.td",
        "include/llvm/Frontend/Directive/*.td",
    ]),
)

gentbl(
    name = "acc_gen",
    library = False,
    tbl_outs = [
        ("--gen-directive-decl", "include/llvm/Frontend/OpenACC/ACC.h.inc"),
    ],
    tblgen = ":llvm-min-tblgen",
    td_file = "include/llvm/Frontend/OpenACC/ACC.td",
    td_srcs = [":acc_td_files"],
)

gentbl(
    name = "acc_gen_impl",
    library = False,
    tbl_outs = [
        ("--gen-directive-impl", "include/llvm/Frontend/OpenACC/ACC.inc"),
    ],
    tblgen = ":llvm-min-tblgen",
    td_file = "include/llvm/Frontend/OpenACC/ACC.td",
    td_srcs = [":acc_td_files"],
)

cc_library(
    name = "FrontendOpenACC",
    srcs = glob([
        "lib/Frontend/OpenACC/*.cpp",
    ]) + [
        "include/llvm/Frontend/OpenACC/ACC.inc",
    ],
    hdrs = ["include/llvm/Frontend/OpenACC/ACC.h.inc"],
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":Core",
        ":Support",
        ":TransformUtils",
    ],
)

cc_library(
    name = "AsmParser",
    srcs = glob([
        "lib/AsmParser/*.cpp",
    ]),
    hdrs = glob(["include/llvm/AsmParser/*.h"]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":Core",
        ":Support",
        ":attributes_gen",
    ],
)

cc_library(
    name = "IRPrinter",
    srcs = glob([
        "lib/IRPrinter/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/IRPrinter/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":Core",
        ":Support",
    ],
)

cc_library(
    name = "IRReader",
    srcs = glob([
        "lib/IRReader/*.cpp",
    ]),
    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",
        ":Object",
        ":Support",
        ":TargetParser",
        ":TransformUtils",
        ":config",
    ],
)

cc_library(
    name = "IPO",
    srcs = glob([
        "lib/Transforms/IPO/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/Transforms/IPO/*.h",
    ]) + [
        "include/llvm/Transforms/IPO.h",
    ],
    copts = llvm_copts,
    deps = [
        ":AggressiveInstCombine",
        ":Analysis",
        ":BinaryFormat",
        ":BitReader",
        ":BitWriter",
        ":Core",
        ":FrontendOpenMP",
        ":IRPrinter",
        ":IRReader",
        ":InstCombine",
        ":Instrumentation",
        ":Linker",
        ":ObjCARC",
        ":Object",
        ":ProfileData",
        ":Scalar",
        ":Support",
        ":Target",
        ":TargetParser",
        ":TransformUtils",
        ":Vectorize",
        ":config",
        ":ir_headers",
    ],
)

cc_library(
    name = "CFGuard",
    srcs = glob([
        "lib/Transforms/CFGuard/*.cpp",
    ]),
    hdrs = ["include/llvm/Transforms/CFGuard.h"],
    copts = llvm_copts,
    deps = [
        ":Core",
        ":Support",
        ":TargetParser",
    ],
)

cc_library(
    name = "HipStdPar",
    srcs = glob([
        "lib/Transforms/HipStdPar/*.cpp",
    ]),
    hdrs = ["include/llvm/Transforms/HipStdPar/HipStdPar.h"],
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":Core",
        ":Support",
        ":TargetParser",
        ":TransformUtils",
    ],
)

cc_library(
    name = "Coroutines",
    srcs = glob([
        "lib/Transforms/Coroutines/*.cpp",
        "lib/Transforms/Coroutines/*.h",
    ]),
    hdrs = glob(["include/llvm/Transforms/Coroutines/*.h"]),
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":BinaryFormat",
        ":Core",
        ":IPO",
        ":Scalar",
        ":Support",
        ":TransformUtils",
        ":config",
    ],
)

# 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 = "CodeGenTypes",
    srcs = glob([
        "lib/CodeGenTypes/**/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/CodeGenTypes/**/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Support",
        ":vt_gen",
    ],
)

cc_library(
    name = "CGData",
    srcs = glob(["lib/CGData/**/*.cpp"]),
    hdrs = glob([
        "include/llvm/CGData/**/*.h",
        "include/llvm/CGData/**/*.inc",
    ]),
    copts = llvm_copts,
    deps = [
        ":BitReader",
        ":BitWriter",
        ":Core",
        ":Object",
        ":ObjectYAML",
        ":Support",
        ":TargetParser",
    ],
)

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",
    ]),
    deps = [
        ":AggressiveInstCombine",
        ":Analysis",
        ":AsmParser",
        ":BinaryFormat",
        ":BitReader",
        ":BitWriter",
        ":CFGuard",
        ":CGData",
        ":CodeGenTypes",
        ":Core",
        ":DebugInfoCodeView",
        ":DebugInfoDWARF",
        ":IPO",
        ":IRPrinter",
        ":Instrumentation",
        ":MC",
        ":MCParser",
        ":ObjCARC",
        ":Object",
        ":ProfileData",
        ":Remarks",
        ":Scalar",
        ":Support",
        ":Target",
        ":TargetParser",
        ":TransformUtils",
        ":asm_printer_defs",
        ":config",
        ":vt_gen",
    ],
)

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 = [
        ":BinaryFormat",
        ":MC",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

llvm_target_lib_list = [lib for lib in [
    {
        "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=AArch64O0PreLegalizerCombiner", "lib/Target/AArch64/AArch64GenO0PreLegalizeGICombiner.inc"),
            ("-gen-global-isel-combiner -combiners=AArch64PreLegalizerCombiner", "lib/Target/AArch64/AArch64GenPreLegalizeGICombiner.inc"),
            ("-gen-global-isel-combiner -combiners=AArch64PostLegalizerCombiner", "lib/Target/AArch64/AArch64GenPostLegalizeGICombiner.inc"),
            ("-gen-global-isel-combiner -combiners=AArch64PostLegalizerLowering", "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"),
            ("-gen-exegesis", "lib/Target/AArch64/AArch64GenExegesis.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": [
            ":InstCombineTableGen",
            ":amdgpu_isel_target_gen",
            ":r600_target_gen",
        ],
    },
    {
        "name": "AVR",
        "short_name": "AVR",
        "tbl_outs": [
            ("-gen-asm-matcher", "lib/Target/AVR/AVRGenAsmMatcher.inc"),
            ("-gen-asm-writer", "lib/Target/AVR/AVRGenAsmWriter.inc"),
            ("-gen-callingconv", "lib/Target/AVR/AVRGenCallingConv.inc"),
            ("-gen-dag-isel", "lib/Target/AVR/AVRGenDAGISel.inc"),
            ("-gen-disassembler", "lib/Target/AVR/AVRGenDisassemblerTables.inc"),
            ("-gen-emitter", "lib/Target/AVR/AVRGenMCCodeEmitter.inc"),
            ("-gen-instr-info", "lib/Target/AVR/AVRGenInstrInfo.inc"),
            ("-gen-register-info", "lib/Target/AVR/AVRGenRegisterInfo.inc"),
            ("-gen-subtarget", "lib/Target/AVR/AVRGenSubtargetInfo.inc"),
        ],
    },
    {
        "name": "BPF",
        "short_name": "BPF",
        "tbl_outs": [
            ("-gen-register-bank", "lib/Target/BPF/BPFGenRegisterBank.inc"),
            ("-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-global-isel", "lib/Target/BPF/BPFGenGlobalISel.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": "LoongArch",
        "short_name": "LoongArch",
        "tbl_outs": [
            ("-gen-asm-matcher", "lib/Target/LoongArch/LoongArchGenAsmMatcher.inc"),
            ("-gen-asm-writer", "lib/Target/LoongArch/LoongArchGenAsmWriter.inc"),
            ("-gen-dag-isel", "lib/Target/LoongArch/LoongArchGenDAGISel.inc"),
            ("-gen-disassembler", "lib/Target/LoongArch/LoongArchGenDisassemblerTables.inc"),
            ("-gen-emitter", "lib/Target/LoongArch/LoongArchGenMCCodeEmitter.inc"),
            ("-gen-instr-info", "lib/Target/LoongArch/LoongArchGenInstrInfo.inc"),
            ("-gen-pseudo-lowering", "lib/Target/LoongArch/LoongArchGenMCPseudoLowering.inc"),
            ("-gen-register-info", "lib/Target/LoongArch/LoongArchGenRegisterInfo.inc"),
            ("-gen-subtarget", "lib/Target/LoongArch/LoongArchGenSubtargetInfo.inc"),
        ],
    },
    {
        "name": "Mips",
        "short_name": "Mips",
        "tbl_outs": [
            ("-gen-asm-matcher", "lib/Target/Mips/MipsGenAsmMatcher.inc"),
            ("-gen-asm-writer", "lib/Target/Mips/MipsGenAsmWriter.inc"),
            ("-gen-callingconv", "lib/Target/Mips/MipsGenCallingConv.inc"),
            ("-gen-dag-isel", "lib/Target/Mips/MipsGenDAGISel.inc"),
            ("-gen-disassembler", "lib/Target/Mips/MipsGenDisassemblerTables.inc"),
            ("-gen-emitter", "lib/Target/Mips/MipsGenMCCodeEmitter.inc"),
            ("-gen-exegesis", "lib/Target/Mips/MipsGenExegesis.inc"),
            ("-gen-fast-isel", "lib/Target/Mips/MipsGenFastISel.inc"),
            ("-gen-global-isel", "lib/Target/Mips/MipsGenGlobalISel.inc"),
            ("-gen-global-isel-combiner -combiners=MipsPostLegalizerCombiner", "lib/Target/Mips/MipsGenPostLegalizeGICombiner.inc"),
            ("-gen-instr-info", "lib/Target/Mips/MipsGenInstrInfo.inc"),
            ("-gen-pseudo-lowering", "lib/Target/Mips/MipsGenMCPseudoLowering.inc"),
            ("-gen-register-bank", "lib/Target/Mips/MipsGenRegisterBank.inc"),
            ("-gen-register-info", "lib/Target/Mips/MipsGenRegisterInfo.inc"),
            ("-gen-subtarget", "lib/Target/Mips/MipsGenSubtargetInfo.inc"),
        ],
    },
    {
        "name": "MSP430",
        "short_name": "MSP430",
        "tbl_outs": [
            ("-gen-asm-matcher", "lib/Target/MSP430/MSP430GenAsmMatcher.inc"),
            ("-gen-asm-writer", "lib/Target/MSP430/MSP430GenAsmWriter.inc"),
            ("-gen-callingconv", "lib/Target/MSP430/MSP430GenCallingConv.inc"),
            ("-gen-dag-isel", "lib/Target/MSP430/MSP430GenDAGISel.inc"),
            ("-gen-disassembler", "lib/Target/MSP430/MSP430GenDisassemblerTables.inc"),
            ("-gen-emitter", "lib/Target/MSP430/MSP430GenMCCodeEmitter.inc"),
            ("-gen-instr-info", "lib/Target/MSP430/MSP430GenInstrInfo.inc"),
            ("-gen-register-info", "lib/Target/MSP430/MSP430GenRegisterInfo.inc"),
            ("-gen-subtarget", "lib/Target/MSP430/MSP430GenSubtargetInfo.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"),
            ("-gen-exegesis", "lib/Target/PowerPC/PPCGenExegesis.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"),
            ("-gen-searchable-tables", "lib/Target/Sparc/SparcGenSearchableTables.inc"),
        ],
    },
    {
        "name": "SystemZ",
        "short_name": "SystemZ",
        "tbl_outs": [
            ("-gen-asm-matcher", "lib/Target/SystemZ/SystemZGenAsmMatcher.inc"),
            ("-gen-asm-writer", "lib/Target/SystemZ/SystemZGenAsmWriter.inc"),
            ("-gen-callingconv", "lib/Target/SystemZ/SystemZGenCallingConv.inc"),
            ("-gen-dag-isel", "lib/Target/SystemZ/SystemZGenDAGISel.inc"),
            ("-gen-disassembler", "lib/Target/SystemZ/SystemZGenDisassemblerTables.inc"),
            ("-gen-emitter", "lib/Target/SystemZ/SystemZGenMCCodeEmitter.inc"),
            ("-gen-instr-info", "lib/Target/SystemZ/SystemZGenInstrInfo.inc"),
            ("-gen-register-info", "lib/Target/SystemZ/SystemZGenRegisterInfo.inc"),
            ("-gen-subtarget", "lib/Target/SystemZ/SystemZGenSubtargetInfo.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-instr-info", "lib/Target/RISCV/RISCVGenInstrInfo.inc"),
            ("-gen-macro-fusion-pred", "lib/Target/RISCV/RISCVGenMacroFusion.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/RISCVGenSearchableTables.inc"),
        ],
        "tbl_deps": [
            ":riscv_isel_target_gen",
        ],
    },
    {
        "name": "VE",
        "short_name": "VE",
        "tbl_outs": [
            ("-gen-asm-matcher", "lib/Target/VE/VEGenAsmMatcher.inc"),
            ("-gen-asm-writer", "lib/Target/VE/VEGenAsmWriter.inc"),
            ("-gen-callingconv", "lib/Target/VE/VEGenCallingConv.inc"),
            ("-gen-dag-isel", "lib/Target/VE/VEGenDAGISel.inc"),
            ("-gen-disassembler", "lib/Target/VE/VEGenDisassemblerTables.inc"),
            ("-gen-emitter", "lib/Target/VE/VEGenMCCodeEmitter.inc"),
            ("-gen-instr-info", "lib/Target/VE/VEGenInstrInfo.inc"),
            ("-gen-register-info", "lib/Target/VE/VEGenRegisterInfo.inc"),
            ("-gen-subtarget", "lib/Target/VE/VEGenSubtargetInfo.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-fold-tables -asmwriternum=1", "lib/Target/X86/X86GenFoldTables.inc"),
            ("-gen-x86-instr-mapping", "lib/Target/X86/X86GenInstrMapping.inc"),
            ("-gen-exegesis", "lib/Target/X86/X86GenExegesis.inc"),
            ("-gen-x86-mnemonic-tables -asmwriternum=1", "lib/Target/X86/X86GenMnemonicTables.inc"),
        ],
    },
    {
        "name": "XCore",
        "short_name": "XCore",
        "tbl_outs": [
            ("-gen-asm-writer", "lib/Target/XCore/XCoreGenAsmWriter.inc"),
            ("-gen-callingconv", "lib/Target/XCore/XCoreGenCallingConv.inc"),
            ("-gen-dag-isel", "lib/Target/XCore/XCoreGenDAGISel.inc"),
            ("-gen-disassembler", "lib/Target/XCore/XCoreGenDisassemblerTables.inc"),
            ("-gen-instr-info", "lib/Target/XCore/XCoreGenInstrInfo.inc"),
            ("-gen-register-info", "lib/Target/XCore/XCoreGenRegisterInfo.inc"),
            ("-gen-subtarget", "lib/Target/XCore/XCoreGenSubtargetInfo.inc"),
        ],
    },
] if lib["name"] in llvm_targets]

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=AMDGPUPreLegalizerCombiner", "lib/Target/AMDGPU/AMDGPUGenPreLegalizeGICombiner.inc"),
        ("-gen-global-isel-combiner -combiners=AMDGPUPostLegalizerCombiner", "lib/Target/AMDGPU/AMDGPUGenPostLegalizeGICombiner.inc"),
        ("-gen-global-isel-combiner -combiners=AMDGPURegBankCombiner", "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 = "riscv_isel_target_gen",
    strip_include_prefix = "lib/Target/RISCV",
    tbl_outs = [
        ("-gen-global-isel", "lib/Target/RISCV/RISCVGenGlobalISel.inc"),
        ("-gen-global-isel-combiner -combiners=RISCVO0PreLegalizerCombiner", "lib/Target/RISCV/RISCVGenO0PreLegalizeGICombiner.inc"),
        ("-gen-global-isel-combiner -combiners=RISCVPostLegalizerCombiner", "lib/Target/RISCV/RISCVGenPostLegalizeGICombiner.inc"),
        ("-gen-global-isel-combiner -combiners=RISCVPreLegalizerCombiner", "lib/Target/RISCV/RISCVGenPreLegalizeGICombiner.inc"),
    ],
    tblgen = ":llvm-tblgen",
    td_file = "lib/Target/RISCV/RISCVGISel.td",
    td_srcs = [
        ":common_target_td_sources",
    ] + glob([
        "lib/Target/RISCV/**/*.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 `@platforms//os: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",
            ],
            allow_empty = True,
        ),
        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,
        # Workaround for https://github.com/bazelbuild/bazel/issues/3828
        # TODO(gcmn): Remove this when upgrading to a Bazel version containing
        # https://github.com/bazelbuild/bazel/commit/e3b7e17b05f1
        includes = ["lib/Target/" + target["name"]],
        strip_include_prefix = "lib/Target/" + target["name"],
        deps = [
            ":" + target["name"] + "CommonTableGen",
            ":MC",
            ":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",
            ],
            allow_empty = True,
        ),
        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",
                "lib/Target/" + target["name"] + "/MCTargetDesc/*.def",
            ],
            allow_empty = True,
        ),
        copts = llvm_copts,
        features = [
            "-parse_headers",
            "-header_modules",
            "-layering_check",
        ],
        strip_include_prefix = "lib/Target/" + target["name"],
        deps = [
            ":BinaryFormat",
            ":CodeGen",
            ":CodeGenTypes",
            ":Core",
            ":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",
            ],
            allow_empty = True,
        ),
        hdrs = ["lib/Target/" + target["name"] + "/" + target["short_name"] + ".h"],
        copts = llvm_copts,
        features = ["-layering_check"],
        strip_include_prefix = "lib/Target/" + target["name"],
        textual_hdrs = glob(
            [
                "lib/Target/" + target["name"] + "/*.def",
                "lib/Target/" + target["name"] + "/*.inc",
            ],
            allow_empty = True,
        ),
        deps = [
            ":Analysis",
            ":BinaryFormat",
            ":CFGuard",
            ":CodeGen",
            ":CodeGenTypes",
            ":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",
            ],
            allow_empty = True,
        ),
        copts = llvm_copts,
        deps = [
            ":BinaryFormat",
            ":CodeGenTypes",
            ":MC",
            ":MCParser",
            ":Support",
            ":Target",
            ":TargetParser",
            ":" + target["name"] + "CodeGen",
            ":" + target["name"] + "CommonTableGen",
            ":" + target["name"] + "Info",
            ":" + 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",
            ],
            allow_empty = True,
        ),
        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",
            ],
            allow_empty = True,
        ),
        copts = llvm_copts,
        features = ["-layering_check"],
        deps = [
            ":CodeGenTypes",
            ":Core",
            ":MC",
            ":MCDisassembler",
            ":Support",
            ":Target",
            ":" + target["name"] + "CodeGen",
            ":" + target["name"] + "DisassemblerInternalHeaders",
            ":" + target["name"] + "CommonTableGen",
            ":" + target["name"] + "UtilsAndDesc",
        ],
    )],
    [cc_library(
        name = target["name"] + "TargetMCA",
        srcs = glob(
            [
                "lib/Target/" + target["name"] + "/MCA/*.cpp",
                "lib/Target/" + target["name"] + "/MCA/*.c",
                "lib/Target/" + target["name"] + "/MCA/*.h",
            ],
            allow_empty = True,
        ),
        copts = llvm_copts,
        features = ["-layering_check"],
        deps = [
            ":CodeGenTypes",
            ":MC",
            ":MCA",
            ":MCParser",
            ":Support",
            ":" + target["name"] + "DisassemblerInternalHeaders",
            ":" + target["name"] + "Info",
            ":" + target["name"] + "UtilsAndDesc",
        ],
    )],
] for target in llvm_target_lib_list]

cc_library(
    name = "AllTargetsCodeGens",
    copts = llvm_copts,
    deps = [
        target["name"] + "CodeGen"
        for target in llvm_target_lib_list
    ],
)

cc_library(
    name = "AllTargetsAsmParsers",
    copts = llvm_copts,
    deps = [
        target["name"] + "AsmParser"
        for target in llvm_target_lib_list
    ],
)

cc_library(
    name = "AllTargetsDisassemblers",
    copts = llvm_copts,
    deps = [
        target["name"] + "Disassembler"
        for target in llvm_target_lib_list
    ],
)

cc_library(
    name = "AllTargetsMCAs",
    copts = llvm_copts,
    deps = [
        target["name"] + "TargetMCA"
        for target in llvm_target_lib_list
    ],
)

cc_library(
    name = "pass_registry_def",
    copts = llvm_copts,
    textual_hdrs = ["lib/Passes/PassRegistry.def"],
)

cc_library(
    name = "Passes",
    srcs = glob([
        "lib/Passes/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/Passes/*.h",
        "include/llvm/Passes/*.def",
        "include/llvm/Passes/*.inc",
    ]) + ["include/llvm-c/Transforms/PassBuilder.h"],
    copts = llvm_copts,
    deps = [
        ":AggressiveInstCombine",
        ":Analysis",
        ":CFGuard",
        ":CodeGen",
        ":Core",
        ":Coroutines",
        ":HipStdPar",
        ":IPO",
        ":IRPrinter",
        ":InstCombine",
        ":Instrumentation",
        ":MC",
        ":ObjCARC",
        ":Scalar",
        ":Support",
        ":Target",
        ":TransformUtils",
        ":Vectorize",
        ":common_transforms",
        ":config",
        ":pass_registry_def",
    ],
)

cc_library(
    name = "LTO",
    srcs = glob([
        "lib/LTO/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/LTO/*.h",
        "include/llvm/LTO/legacy/*.h",
    ]) + [
        "include/llvm-c/lto.h",
    ],
    copts = llvm_copts,
    deps = [
        ":Analysis",
        ":BitReader",
        ":BitWriter",
        ":CodeGen",
        ":CodeGenTypes",
        ":Core",
        ":IPO",
        ":IRPrinter",
        ":IRReader",
        ":Linker",
        ":MC",
        ":MCParser",
        ":ObjCARC",
        ":Object",
        ":Passes",
        ":Remarks",
        ":Scalar",
        ":Support",
        ":Target",
        ":TargetParser",
        ":TransformUtils",
        ":common_transforms",
        ":config",
    ],
)

cc_library(
    name = "ExecutionEngine",
    srcs = glob([
        "lib/ExecutionEngine/*.cpp",
        "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",
        ":OrcTargetProcess",
        ":Passes",
        ":Support",
        ":Target",
        ":TargetParser",
        ":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",
    ],
)

gentbl(
    name = "JITLinkTableGen",
    strip_include_prefix = "lib/ExecutionEngine/JITLink",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "lib/ExecutionEngine/JITLink/COFFOptions.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "lib/ExecutionEngine/JITLink/COFFOptions.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "JITLink",
    srcs = glob([
        "lib/ExecutionEngine/JITLink/*.cpp",
        "lib/ExecutionEngine/JITLink/*.h",
    ]),
    hdrs = glob([
        "include/llvm/ExecutionEngine/JITLink/*.h",
        "include/llvm/ExecutionEngine/Orc/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":ExecutionEngine",
        ":JITLinkTableGen",
        ":Object",
        ":Option",
        ":OrcShared",
        ":OrcTargetProcess",
        ":Support",
        ":TargetParser",
        ":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",
    ]),
    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,
    linkopts = select({
        "@platforms//os:android": [],
        "@platforms//os:windows": [],
        "@platforms//os:freebsd": [],
        "@platforms//os:macos": [],
        "//conditions:default": [
            "-lrt",
        ],
    }),
    deps = [
        ":Analysis",
        ":BinaryFormat",
        ":BitReader",
        ":BitWriter",
        ":Core",
        ":DebugInfoDWARF",
        ":ExecutionEngine",
        ":JITLink",
        ":MC",
        ":MCDisassembler",
        ":Object",
        ":OrcShared",
        ":OrcTargetProcess",
        ":Passes",
        ":Support",
        ":Target",
        ":TargetParser",
        ":TransformUtils",
        ":WindowsDriver",
        ":config",
    ],
)

cc_library(
    name = "OrcShared",
    srcs = glob([
        "lib/ExecutionEngine/Orc/Shared/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/ExecutionEngine/Orc/Shared/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":CodeGen",
        ":Core",
        ":DebugInfo",
        ":MC",
        ":MCDisassembler",
        ":Object",
        ":Passes",
        ":Support",
        ":Target",
        ":config",
    ],
)

cc_library(
    name = "OrcDebugging",
    srcs = glob([
        "lib/ExecutionEngine/Orc/Debugging/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/ExecutionEngine/Orc/Debugging/*.h",
    ]) + ["include/llvm-c/LLJITUtils.h"],
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":DebugInfo",
        ":JITLink",
        ":OrcJIT",
        ":OrcShared",
        ":Support",
        ":TargetParser",
    ],
)

cc_library(
    name = "OrcTargetProcess",
    srcs = glob([
        "lib/ExecutionEngine/Orc/TargetProcess/*.cpp",
        "lib/ExecutionEngine/Orc/TargetProcess/*.h",
    ]),
    hdrs = glob([
        "include/llvm/ExecutionEngine/Orc/TargetProcess/*.h",
    ]),
    copts = llvm_copts,
    linkopts = select({
        "@platforms//os:android": [],
        "@platforms//os:windows": [],
        "@platforms//os:freebsd": [],
        "@platforms//os:macos": [],
        "//conditions:default": [
            "-lrt",
        ],
    }),
    deps = [
        ":BinaryFormat",
        ":CodeGen",
        ":Core",
        ":DebugInfo",
        ":MC",
        ":MCDisassembler",
        ":Object",
        ":OrcShared",
        ":Passes",
        ":Support",
        ":Target",
        ":TargetParser",
        ":config",
    ],
)

cc_library(
    name = "DWARFLinker",
    srcs = glob([
        "lib/DWARFLinker/Classic/*.cpp",
    ]),
    hdrs = glob(["include/llvm/DWARFLinker/Classic/*.h"]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":CodeGen",
        ":CodeGenTypes",
        ":DWARFLinkerBase",
        ":DebugInfoDWARF",
        ":MC",
        ":Support",
        ":Target",
        ":TargetParser",
    ],
)

cc_library(
    name = "DWARFLinkerBase",
    srcs = glob([
        "lib/DWARFLinker/*.cpp",
    ]),
    hdrs = glob(["include/llvm/DWARFLinker/*.h"]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":CodeGen",
        ":DebugInfoDWARF",
        ":Support",
        ":Target",
    ],
)

cc_library(
    name = "DWARFLinkerParallel",
    srcs = glob([
        "lib/DWARFLinker/Parallel/*.cpp",
        "lib/DWARFLinker/Parallel/*.h",
    ]),
    hdrs = glob(["include/llvm/DWARFLinker/Parallel/*.h"]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":CodeGen",
        ":DWARFLinkerBase",
        ":DebugInfoDWARF",
        ":MC",
        ":Object",
        ":Support",
        ":Target",
        ":TargetParser",
    ],
)

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",
        ":TargetParser",
    ],
)

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",
        ":BitReader",
        ":LibOptionsTableGen",
        ":Object",
        ":Option",
        ":Support",
    ],
)

cc_library(
    name = "InterfaceStub",
    srcs = glob([
        "lib/InterfaceStub/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/InterfaceStub/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":MC",
        ":Object",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

cc_library(
    name = "WindowsDriver",
    srcs = glob([
        "lib/WindowsDriver/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/WindowsDriver/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Option",
        ":Support",
        ":TargetParser",
    ],
)

cc_library(
    name = "WindowsManifest",
    srcs = glob([
        "lib/WindowsManifest/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/WindowsManifest/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Support",
        ":config",
    ],
)

cc_library(
    name = "MCA",
    srcs = glob([
        "lib/MCA/**/*.cpp",
    ]),
    hdrs = glob([
        "include/llvm/MCA/**/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":MC",
        ":MCDisassembler",
        ":Object",
        ":Support",
    ],
)

cc_library(
    name = "MCAApplication",
    srcs = glob([
        "tools/llvm-mca/Views/*.cpp",
    ]) + [
        mca_source
        for mca_source in glob(["tools/llvm-mca/*.cpp"])
        if mca_source != "tools/llvm-mca/llvm-mca.cpp"
    ],
    hdrs = glob([
        "tools/llvm-mca/*.h",
        "tools/llvm-mca/Views/*.h",
    ]),
    strip_include_prefix = "tools/llvm-mca",
    deps = [
        ":MC",
        ":MCA",
        ":MCParser",
        ":Support",
        ":TargetParser",
    ],
)

cc_library(
    name = "XRay",
    srcs = glob([
        "lib/XRay/*.cpp",
    ]),
    hdrs = glob(["include/llvm/XRay/*.h"]),
    copts = llvm_copts,
    deps = [
        ":Object",
        ":Support",
        ":TargetParser",
    ],
)

# A flag to pick which `pfm` to use for Exegesis.
# Usage: `--@llvm-project//llvm:pfm=<disable|external|system>`.
# Flag documentation: https://bazel.build/extending/config
string_flag(
    name = "pfm",
    build_setting_default = "external",
    values = [
        "disable",  # Don't include pfm at all
        "external",  # Build pfm from source
        "system",  # Use system pfm (non hermetic)
    ],
)

config_setting(
    name = "pfm_disable",
    flag_values = {":pfm": "disable"},
)

config_setting(
    name = "pfm_external",
    flag_values = {":pfm": "external"},
)

config_setting(
    name = "pfm_system",
    flag_values = {":pfm": "system"},
)

cc_library(
    name = "maybe_pfm",
    # We want dependencies of this library to have -DHAVE_LIBPFM conditionally
    # defined, so we set `defines` instead of `copts`.
    defines = select({
        ":pfm_external": ["HAVE_LIBPFM=1"],
        ":pfm_system": ["HAVE_LIBPFM=1"],
        "//conditions:default": [],
    }),
    deps = select({
        ":pfm_external": ["@pfm//:pfm_external"],
        ":pfm_system": ["@pfm//:pfm_system"],
        "//conditions:default": [],
    }),
)

cc_library(
    name = "Exegesis",
    srcs = glob(
        [
            "tools/llvm-exegesis/lib/*.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
            # `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",
        ] + [
            "tools/llvm-exegesis/lib/{}/*.cpp".format(t)
            for t in llvm_target_exegesis
        ] + [
            "tools/llvm-exegesis/lib/{}/*.h".format(t)
            for t in llvm_target_exegesis
        ],
        allow_empty = True,
    ),
    hdrs = glob(["tools/llvm-exegesis/lib/*.h"]),
    copts = llvm_copts,
    features = [
        "-header_modules",
        "-layering_check",
    ],
    strip_include_prefix = "tools/llvm-exegesis/lib",
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":CodeGen",
        ":CodeGenTypes",
        ":Core",
        ":ExecutionEngine",
        ":MC",
        ":MCA",
        ":MCDisassembler",
        ":Object",
        ":ObjectYAML",
        ":OrcJIT",
        ":Support",
        ":Target",
        ":config",
    ] + select({
        "@platforms//os:linux": [":maybe_pfm"],
        "//conditions:default": [],
    }),
)

################################################################################
# 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_library(
    name = "dsymutil-lib",
    srcs = glob([
        "tools/dsymutil/*.cpp",
        "tools/dsymutil/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsCodeGens",
        ":BinaryFormat",
        ":CodeGen",
        ":CodeGenTypes",
        ":DWARFLinker",
        ":DWARFLinkerParallel",
        ":DebugInfo",
        ":DebugInfoDWARF",
        ":DsymutilTableGen",
        ":MC",
        ":Object",
        ":Option",
        ":Remarks",
        ":Support",
        ":Target",
        ":TargetParser",
        ":config",
        ":remark_linker",
    ],
)

llvm_driver_cc_binary(
    name = "dsymutil",
    stamp = 0,
    deps = [":dsymutil-lib"],
)

cc_binary(
    name = "llc",
    srcs = glob([
        "tools/llc/*.cpp",
        "tools/llc/*.h",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":Analysis",
        ":AsmParser",
        ":BitReader",
        ":CodeGen",
        ":CodeGenTypes",
        ":Core",
        ":IRPrinter",
        ":IRReader",
        ":MC",
        ":Passes",
        ":Remarks",
        ":Scalar",
        ":Support",
        ":Target",
        ":TargetParser",
        ":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({
        "@platforms//os:windows": [],
        "@platforms//os:macos": [],
        "//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",
            "-Wl,--export-dynamic-symbol=llvm_orc_registerJITLoaderGDBWrapper",
            "-Wl,--export-dynamic-symbol=llvm_orc_registerEHFrameSectionWrapper",
            "-Wl,--export-dynamic-symbol=llvm_orc_deregisterEHFrameSectionWrapper",
        ],
    }),
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":AsmParser",
        ":BitReader",
        ":CodeGen",
        ":Core",
        ":ExecutionEngine",
        ":IRPrinter",
        ":IRReader",
        ":Instrumentation",
        ":Interpreter",
        ":MCJIT",
        ":Object",
        ":OrcDebugging",
        ":OrcJIT",
        ":OrcTargetProcess",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

cc_library(
    name = "llvm-ar-lib",
    srcs = glob(["tools/llvm-ar/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":BinaryFormat",
        ":Core",
        ":DlltoolDriver",
        ":LibDriver",
        ":Object",
        ":Support",
        ":TargetParser",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-ar",
    stamp = 0,
    deps = [":llvm-ar-lib"],
)

# 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",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":Analysis",
        ":AsmParser",
        ":BitWriter",
        ":Core",
        ":Support",
    ],
)

cc_binary(
    name = "llvm-bcanalyzer",
    srcs = glob([
        "tools/llvm-bcanalyzer/*.cpp",
    ]),
    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",
        ":IRPrinter",
        ":IRReader",
        ":Support",
    ],
)

gentbl(
    name = "CGDataOptsTableGen",
    strip_include_prefix = "tools/llvm-cgdata",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-cgdata/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-cgdata/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-cgdata-lib",
    srcs = glob(["tools/llvm-cgdata/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":CGData",
        ":CGDataOptsTableGen",
        ":CodeGen",
        ":Core",
        ":Object",
        ":Option",
        ":Support",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-cgdata",
    stamp = 0,
    deps = [":llvm-cgdata-lib"],
)

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",
        ":Debuginfod",
        ":Instrumentation",
        ":Object",
        ":ProfileData",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

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",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":BinaryFormat",
        ":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",
        ":MC",
        ":Object",
        ":Support",
    ],
)

cc_binary(
    name = "llvm-cxxmap",
    srcs = glob([
        "tools/llvm-cxxmap/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":ProfileData",
        ":Support",
    ],
)

gentbl(
    name = "CxxfiltOptsTableGen",
    strip_include_prefix = "tools/llvm-cxxfilt",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-cxxfilt/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-cxxfilt/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-cxxfilt-lib",
    srcs = glob(["tools/llvm-cxxfilt/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":CxxfiltOptsTableGen",
        ":Demangle",
        ":Option",
        ":Support",
        ":TargetParser",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-cxxfilt",
    stamp = 0,
    deps = [":llvm-cxxfilt-lib"],
)

cc_binary(
    name = "llvm-debuginfo-analyzer",
    srcs = glob([
        "tools/llvm-debuginfo-analyzer/*.cpp",
        "tools/llvm-debuginfo-analyzer/*.h",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":DebugInfoLogicalView",
        ":Support",
    ],
)

gentbl(
    name = "DebugInfodFindOptsTableGen",
    strip_include_prefix = "tools/llvm-debuginfod-find",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-debuginfod-find/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-debuginfod-find/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-debuginfod-find-lib",
    srcs = glob([
        "tools/llvm-debuginfod-find/*.cpp",
    ]),
    copts = llvm_copts,
    deps = [
        ":BitReader",
        ":Core",
        ":DebugInfodFindOptsTableGen",
        ":Debuginfod",
        ":Option",
        ":Support",
        ":Symbolize",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-debuginfod-find",
    stamp = 0,
    deps = [":llvm-debuginfod-find-lib"],
)

cc_binary(
    name = "llvm-dis",
    srcs = glob([
        "tools/llvm-dis/*.cpp",
    ]),
    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",
        ":TargetParser",
    ],
)

gentbl(
    name = "DwarfutilOptionsTableGen",
    strip_include_prefix = "tools/llvm-dwarfutil",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-dwarfutil/Options.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-dwarfutil/Options.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_binary(
    name = "llvm-dwarfutil",
    srcs = glob([
        "tools/llvm-dwarfutil/*.cpp",
        "tools/llvm-dwarfutil/*.h",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":CodeGenTypes",
        ":DWARFLinker",
        ":DWARFLinkerParallel",
        ":DebugInfoDWARF",
        ":DwarfutilOptionsTableGen",
        ":MC",
        ":ObjCopy",
        ":Object",
        ":Option",
        ":Support",
        ":Target",
        ":TargetParser",
    ],
)

gentbl(
    name = "DwpOptionsTableGen",
    strip_include_prefix = "tools/llvm-dwp",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-dwp/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-dwp/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-dwp-lib",
    srcs = glob(["tools/llvm-dwp/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsCodeGens",
        ":DWP",
        ":DwpOptionsTableGen",
        ":MC",
        ":Option",
        ":Support",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-dwp",
    stamp = 0,
    deps = [":llvm-dwp-lib"],
)

cc_binary(
    name = "llvm-exegesis",
    srcs = [
        "tools/llvm-exegesis/llvm-exegesis.cpp",
    ],
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":CodeGenTypes",
        ":Exegesis",
        ":MC",
        ":MCParser",
        ":Object",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

cc_binary(
    name = "llvm-extract",
    srcs = glob([
        "tools/llvm-extract/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AsmParser",
        ":BitReader",
        ":BitWriter",
        ":Core",
        ":IPO",
        ":IRPrinter",
        ":IRReader",
        ":Passes",
        ":Support",
    ],
)

gentbl(
    name = "GSYMUtilOptionsTableGen",
    strip_include_prefix = "tools/llvm-gsymutil",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-gsymutil/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-gsymutil/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-gsymutil-lib",
    srcs = glob(["tools/llvm-gsymutil/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsCodeGens",
        ":DebugInfo",
        ":DebugInfoDWARF",
        ":DebugInfoGSYM",
        ":GSYMUtilOptionsTableGen",
        ":MC",
        ":Object",
        ":Option",
        ":Support",
        ":Target",
        ":TargetParser",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-gsymutil",
    stamp = 0,
    deps = [":llvm-gsymutil-lib"],
)

gentbl(
    name = "IfsOptionsTableGen",
    strip_include_prefix = "tools/llvm-ifs",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-ifs/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-ifs/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-ifs-lib",
    srcs = glob([
        "tools/llvm-ifs/*.cpp",
        "tools/llvm-ifs/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":IfsOptionsTableGen",
        ":InterfaceStub",
        ":ObjectYAML",
        ":Option",
        ":Support",
        ":TargetParser",
        ":TextAPI",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-ifs",
    stamp = 0,
    deps = [":llvm-ifs-lib"],
)

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({
        "@platforms//os:windows": [],
        "@platforms//os:macos": [],
        "//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",
            "-Wl,--export-dynamic-symbol=llvm_orc_registerJITLoaderGDBWrapper",
        ],
    }),
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":AsmParser",
        ":BinaryFormat",
        ":BitReader",
        ":CodeGen",
        ":ExecutionEngine",
        ":MC",
        ":MCDisassembler",
        ":MCJIT",
        ":Object",
        ":OrcDebugging",
        ":OrcJIT",
        ":OrcShared",
        ":OrcTargetProcess",
        ":Support",
        ":TargetParser",
        ":config",
    ],
)

gentbl(
    name = "LibtoolDarwinOptionsTableGen",
    strip_include_prefix = "tools/llvm-libtool-darwin",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-libtool-darwin/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-libtool-darwin/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-libtool-darwin-lib",
    srcs = glob([
        "tools/llvm-libtool-darwin/*.cpp",
        "tools/llvm-libtool-darwin/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":BinaryFormat",
        ":Core",
        ":LibtoolDarwinOptionsTableGen",
        ":Object",
        ":Option",
        ":Support",
        ":TextAPI",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-libtool-darwin",
    stamp = 0,
    deps = [":llvm-libtool-darwin-lib"],
)

cc_binary(
    name = "llvm-link",
    srcs = glob([
        "tools/llvm-link/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AsmParser",
        ":BinaryFormat",
        ":BitReader",
        ":BitWriter",
        ":Core",
        ":IPO",
        ":IRPrinter",
        ":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_library(
    name = "llvm-lipo-lib",
    srcs = ["tools/llvm-lipo/llvm-lipo.cpp"],
    copts = llvm_copts,
    deps = [
        ":AllTargetsAsmParsers",
        ":BinaryFormat",
        ":Core",
        ":LipoOptsTableGen",
        ":Object",
        ":Option",
        ":Support",
        ":TargetParser",
        ":TextAPI",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-lipo",
    stamp = 0,
    deps = [":llvm-lipo-lib"],
)

cc_binary(
    name = "llvm-lto",
    srcs = glob([
        "tools/llvm-lto/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":BitReader",
        ":BitWriter",
        ":CodeGen",
        ":Core",
        ":IRPrinter",
        ":IRReader",
        ":LTO",
        ":Support",
        ":Target",
    ],
)

cc_binary(
    name = "llvm-lto2",
    srcs = glob([
        "tools/llvm-lto2/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":BitReader",
        ":CodeGen",
        ":Core",
        ":LTO",
        ":Passes",
        ":Remarks",
        ":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",
        ":TargetParser",
    ],
)

cc_binary(
    name = "llvm-mca",
    srcs = [
        "tools/llvm-mca/llvm-mca.cpp",
    ],
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":AllTargetsMCAs",
        ":MC",
        ":MCA",
        ":MCAApplication",
        ":MCParser",
        ":Support",
        ":TargetParser",
    ],
)

gentbl(
    name = "MlTableGen",
    strip_include_prefix = "tools/llvm-ml",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-ml/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-ml/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-ml-lib",
    srcs = glob([
        "tools/llvm-ml/*.cpp",
        "tools/llvm-ml/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":MC",
        ":MCDisassembler",
        ":MCParser",
        ":MlTableGen",
        ":Option",
        ":Support",
        ":TargetParser",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-ml",
    stamp = 0,
    deps = [":llvm-ml-lib"],
)

cc_binary(
    name = "llvm-modextract",
    srcs = glob([
        "tools/llvm-modextract/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":BitReader",
        ":BitWriter",
        ":IRPrinter",
        ":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_library(
    name = "llvm-mt-lib",
    srcs = glob(["tools/llvm-mt/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":MtTableGen",
        ":Option",
        ":Support",
        ":WindowsManifest",
        ":config",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-mt",
    stamp = 0,
    deps = [":llvm-mt-lib"],
)

gentbl(
    name = "NmOptsTableGen",
    strip_include_prefix = "tools/llvm-nm",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-nm/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-nm/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-nm-lib",
    srcs = glob(["tools/llvm-nm/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":BinaryFormat",
        ":BitReader",
        ":Core",
        ":Demangle",
        ":NmOptsTableGen",
        ":Object",
        ":Option",
        ":Support",
        ":Symbolize",
        ":TargetParser",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-nm",
    stamp = 0,
    deps = [":llvm-nm-lib"],
)

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-stress",
    srcs = glob([
        "tools/llvm-stress/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":Core",
        ":Support",
    ],
)

cc_library(
    name = "llvm-objcopy-lib",
    srcs = glob([
        "tools/llvm-objcopy/*.cpp",
        "tools/llvm-objcopy/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":BinaryFormat",
        ":MC",
        ":ObjCopy",
        ":Object",
        ":ObjectYAML",
        ":Option",
        ":Support",
        ":Target",
        ":TargetParser",
        ":llvm-bitcode-strip-opts",
        ":llvm-installnametool-opts",
        ":llvm-objcopy-opts",
        ":llvm-strip-opts",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-objcopy",
    stamp = 0,
    deps = [":llvm-objcopy-lib"],
)

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_library(
    name = "llvm-objdump-lib",
    srcs = glob([
        "tools/llvm-objdump/*.cpp",
        "tools/llvm-objdump/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":BinaryFormat",
        ":CodeGen",
        ":DebugInfo",
        ":DebugInfoDWARF",
        ":Debuginfod",
        ":Demangle",
        ":MC",
        ":MCDisassembler",
        ":ObjdumpOptsTableGen",
        ":Object",
        ":Option",
        ":OtoolOptsTableGen",
        ":Support",
        ":Symbolize",
        ":TargetParser",
        ":config",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-objdump",
    stamp = 0,
    deps = [":llvm-objdump-lib"],
)

gentbl(
    name = "ObjdumpOptsTableGen",
    strip_include_prefix = "tools/llvm-objdump",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-objdump/ObjdumpOpts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-objdump/ObjdumpOpts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

binary_alias(
    name = "llvm-otool",
    binary = ":llvm-objdump",
)

gentbl(
    name = "OtoolOptsTableGen",
    strip_include_prefix = "tools/llvm-objdump",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-objdump/OtoolOpts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-objdump/OtoolOpts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

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",
        ":DebugInfoBTF",
        ":DebugInfoCodeView",
        ":DebugInfoMSF",
        ":DebugInfoPDB",
        ":Object",
        ":ObjectYAML",
        ":Support",
        ":config",
    ],
)

cc_library(
    name = "llvm-profdata-lib",
    srcs = glob(["tools/llvm-profdata/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":Core",
        ":Debuginfod",
        ":Object",
        ":ProfileData",
        ":Support",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-profdata",
    stamp = 0,
    deps = [":llvm-profdata-lib"],
)

cc_binary(
    name = "llvm-profgen",
    srcs = glob([
        "tools/llvm-profgen/*.cpp",
        "tools/llvm-profgen/*.h",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":Core",
        ":DebugInfoDWARF",
        ":Demangle",
        ":IPO",
        ":MC",
        ":MCDisassembler",
        ":Object",
        ":ProfileData",
        ":Support",
        ":Symbolize",
        ":TargetParser",
    ],
)

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"],
)

gentbl(
    name = "WindresTableGen",
    strip_include_prefix = "tools/llvm-rc",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-rc/WindresOpts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-rc/WindresOpts.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_library(
    name = "llvm-rc-lib",
    srcs = glob([
        "tools/llvm-rc/*.cpp",
        "tools/llvm-rc/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Object",
        ":Option",
        ":RcTableGen",
        ":Support",
        ":TargetParser",
        ":WindresTableGen",
        ":config",
        ":llvm-rc-defs-lib",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-rc",
    stamp = 0,
    deps = [":llvm-rc-lib"],
)

binary_alias(
    name = "llvm-windres",
    binary = ":llvm-rc",
)

gentbl(
    name = "ReadobjOptsTableGen",
    strip_include_prefix = "tools/llvm-readobj",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-readobj/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-readobj/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-readobj-lib",
    srcs = glob([
        "tools/llvm-readobj/*.cpp",
        "tools/llvm-readobj/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsCodeGens",
        ":BinaryFormat",
        ":BitReader",
        ":DebugInfoCodeView",
        ":DebugInfoDWARF",
        ":Demangle",
        ":MC",
        ":Object",
        ":Option",
        ":ReadobjOptsTableGen",
        ":Support",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-readobj",
    stamp = 0,
    deps = [":llvm-readobj-lib"],
)

# 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 = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":Analysis",
        ":BitReader",
        ":BitWriter",
        ":CodeGen",
        ":CodeGenTypes",
        ":Core",
        ":IPO",
        ":IRReader",
        ":MC",
        ":Passes",
        ":Support",
        ":Target",
        ":TargetParser",
        ":TransformUtils",
        ":config",
    ],
)

cc_binary(
    name = "llvm-rtdyld",
    srcs = glob([
        "tools/llvm-rtdyld/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":DebugInfo",
        ":DebugInfoDWARF",
        ":ExecutionEngine",
        ":MC",
        ":MCDisassembler",
        ":Object",
        ":Support",
    ],
)

gentbl(
    name = "SizeOptsTableGen",
    strip_include_prefix = "tools/llvm-size",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-size/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-size/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "llvm-size-lib",
    srcs = glob(["tools/llvm-size/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":Object",
        ":Option",
        ":SizeOptsTableGen",
        ":Support",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-size",
    stamp = 0,
    deps = [":llvm-size-lib"],
)

cc_binary(
    name = "llvm-split",
    srcs = glob([
        "tools/llvm-split/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":BitWriter",
        ":Core",
        ":IRPrinter",
        ":IRReader",
        ":MC",
        ":Support",
        ":Target",
        ":TargetParser",
        ":TransformUtils",
    ],
)

gentbl(
    name = "StringsOptsTableGen",
    strip_include_prefix = "tools/llvm-strings",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-strings/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-strings/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_binary(
    name = "llvm-strings",
    srcs = glob([
        "tools/llvm-strings/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":Object",
        ":Option",
        ":StringsOptsTableGen",
        ":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_library(
    name = "llvm-symbolizer-lib",
    srcs = glob(["tools/llvm-symbolizer/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":DebugInfoDWARF",
        ":DebugInfoPDB",
        ":Debuginfod",
        ":Object",
        ":Option",
        ":Support",
        ":Symbolize",
        ":SymbolizerOptsTableGen",
        ":config",
    ],
)

llvm_driver_cc_binary(
    name = "llvm-symbolizer",
    stamp = 0,
    deps = [":llvm-symbolizer-lib"],
)

binary_alias(
    name = "llvm-addr2line",
    binary = ":llvm-symbolizer",
)

cc_binary(
    name = "llvm-undname",
    srcs = glob([
        "tools/llvm-undname/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":Demangle",
        ":Support",
    ],
)

cc_binary(
    name = "llvm-xray",
    srcs = glob([
        "tools/llvm-xray/*.cpp",
        "tools/llvm-xray/*.h",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":DebugInfoDWARF",
        ":Object",
        ":Support",
        ":Symbolize",
        ":XRay",
    ],
)

cc_library(
    name = "opt-driver",
    srcs = glob([
        "tools/opt/*.cpp",
        "tools/opt/*.h",
    ]),
    copts = llvm_copts,
    linkopts = select({
        "@platforms//os:windows": [],
        "@platforms//os:macos": [],
        "//conditions:default": ["-Wl,--export-dynamic"],
    }),
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":Analysis",
        ":AsmParser",
        ":BitReader",
        ":BitWriter",
        ":CodeGen",
        ":Core",
        ":IPO",
        ":IRPrinter",
        ":IRReader",
        ":Instrumentation",
        ":MC",
        ":Passes",
        ":Remarks",
        ":Scalar",
        ":Support",
        ":Target",
        ":TargetParser",
        ":TransformUtils",
        ":common_transforms",
        ":config",
    ],
)

cc_binary(
    name = "opt",
    stamp = 0,
    deps = [":opt-driver"],
)

gentbl(
    name = "SancovOptsTableGen",
    strip_include_prefix = "tools/sancov",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/sancov/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/sancov/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_library(
    name = "sancov-lib",
    srcs = glob(["tools/sancov/*.cpp"]),
    copts = llvm_copts,
    deps = [
        ":AllTargetsCodeGens",
        ":AllTargetsDisassemblers",
        ":DebugInfoDWARF",
        ":DebugInfoPDB",
        ":MC",
        ":MCDisassembler",
        ":Object",
        ":Option",
        ":SancovOptsTableGen",
        ":Support",
        ":Symbolize",
    ],
)

llvm_driver_cc_binary(
    name = "sancov",
    stamp = 0,
    deps = [":sancov-lib"],
)

cc_binary(
    name = "sanstats",
    srcs = glob([
        "tools/sanstats/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":Support",
        ":Symbolize",
        ":TransformUtils",
    ],
)

cc_binary(
    name = "split-file",
    srcs = glob([
        "utils/split-file/*.cpp",
    ]),
    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",
        ":TargetParser",
        ":TransformUtils",
    ],
)

cc_library(
    name = "Diff",
    testonly = True,
    srcs = glob(["tools/llvm-diff/lib/*.cpp"]),
    hdrs = glob(["tools/llvm-diff/lib/*.h"]),
    deps = [
        ":Core",
        ":Support",
    ],
)

py_binary(
    name = "lit",
    testonly = True,
    srcs = ["utils/lit/lit.py"] + glob(["utils/lit/lit/**/*.py"]),
    imports = ["utils/lit"],
)

py_binary(
    name = "extract_ir",
    srcs = [
        "utils/mlgo-utils/mlgo/__init__.py",
        "utils/mlgo-utils/mlgo/corpus/extract_ir.py",
        "utils/mlgo-utils/mlgo/corpus/extract_ir_lib.py",
    ],
    imports = ["utils/mlgo-utils"],
)

py_binary(
    name = "combine_training_corpus",
    srcs = [
        "utils/mlgo-utils/mlgo/__init__.py",
        "utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py",
        "utils/mlgo-utils/mlgo/corpus/combine_training_corpus_lib.py",
    ],
    imports = ["utils/mlgo-utils"],
)

py_binary(
    name = "make_corpus",
    srcs = [
        "utils/mlgo-utils/mlgo/__init__.py",
        "utils/mlgo-utils/mlgo/corpus/make_corpus.py",
        "utils/mlgo-utils/mlgo/corpus/make_corpus_lib.py",
    ],
    imports = ["utils/mlgo-utils"],
)

cc_library(
    name = "TestingADT",
    testonly = True,
    hdrs = glob([
        "include/llvm/Testing/ADT/*.h",
    ]),
    copts = llvm_copts,
    deps = [
        ":Support",
        "//third-party/unittest:gmock",
    ],
)

cc_library(
    name = "TestingSupport",
    testonly = True,
    srcs = glob([
        "lib/Testing/Support/*.cpp",
    ]),
    hdrs = glob(["include/llvm/Testing/Support/*.h"]),
    copts = llvm_copts,
    deps = [
        ":Support",
        ":config",
        "//third-party/unittest:gmock",
        "//third-party/unittest:gtest",
    ],
)

cc_library(
    name = "TestingAnnotations",
    testonly = True,
    srcs = ["lib/Testing/Annotations/Annotations.cpp"],
    hdrs = ["include/llvm/Testing/Annotations/Annotations.h"],
    copts = llvm_copts,
    deps = [":Support"],
)

################################################################################
# Begin testonly binary utilities

cc_binary(
    name = "FileCheck",
    testonly = True,
    srcs = glob([
        "utils/FileCheck/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":FileCheckLib",
        ":Support",
    ],
)

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",
        ":IPO",
        ":IRPrinter",
        ":IRReader",
        ":Linker",
        ":Passes",
        ":Scalar",
        ":Support",
        ":TargetParser",
        ":TransformUtils",
        ":common_transforms",
        ":config",
    ],
)

cc_binary(
    name = "count",
    testonly = True,
    srcs = glob([
        "utils/count/*.c",
    ]),
    stamp = 0,
    deps = [":Support"],
)

cc_binary(
    name = "lli-child-target",
    testonly = True,
    srcs = glob([
        "tools/lli/ChildTarget/*.cpp",
    ]),
    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({
        "@platforms//os:windows": [],
        "@platforms//os:macos": [],
        "//conditions:default": [
            "-rdynamic",
            "-u_ZTIi",
        ],
    }),
    stamp = 0,
    deps = [
        ":OrcJIT",
        ":OrcTargetProcess",
        ":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",
        ":IRReader",
        ":InstCombine",
        ":LTO",
        ":Linker",
        ":MCDisassembler",
        ":Object",
        ":OrcJIT",
        ":Passes",
        ":Remarks",
        ":Scalar",
        ":Support",
        ":Target",
        ":TransformUtils",
        ":Vectorize",
    ],
)

cc_binary(
    name = "llvm-diff",
    testonly = True,
    srcs = glob([
        "tools/llvm-diff/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":Core",
        ":Diff",
        ":IRPrinter",
        ":IRReader",
        ":Support",
    ],
)

cc_binary(
    name = "llvm-isel-fuzzer",
    testonly = True,
    srcs = glob([
        "tools/llvm-isel-fuzzer/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AllTargetsAsmParsers",
        ":AllTargetsCodeGens",
        ":Analysis",
        ":BitReader",
        ":BitWriter",
        ":CodeGen",
        ":Core",
        ":FuzzMutate",
        ":IRPrinter",
        ":IRReader",
        ":MC",
        ":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"],
)

sh_binary(
    name = "llvm-original-di-preservation",
    testonly = True,
    srcs = ["utils/llvm-original-di-preservation.py"],
)

cc_binary(
    name = "not",
    testonly = True,
    srcs = glob([
        "utils/not/*.cpp",
    ]),
    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",
        ":MC",
        ":Passes",
        ":Support",
        ":Target",
    ],
)

gentbl(
    name = "ReadTAPIOptsTableGen",
    strip_include_prefix = "tools/llvm-readtapi",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-readtapi/TapiOpts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-readtapi/TapiOpts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_binary(
    name = "llvm-readtapi",
    testonly = True,
    srcs = glob([
        "tools/llvm-readtapi/*.cpp",
        "tools/llvm-readtapi/*.h",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":BinaryFormat",
        ":Object",
        ":Option",
        ":ReadTAPIOptsTableGen",
        ":Support",
        ":TextAPI",
        ":TextAPIBinaryReader",
    ],
)

gentbl(
    name = "TLICheckerOptsTableGen",
    strip_include_prefix = "tools/llvm-tli-checker",
    tbl_outs = [(
        "-gen-opt-parser-defs",
        "tools/llvm-tli-checker/Opts.inc",
    )],
    tblgen = ":llvm-tblgen",
    td_file = "tools/llvm-tli-checker/Opts.td",
    td_srcs = ["include/llvm/Option/OptParser.td"],
)

cc_binary(
    name = "llvm-tli-checker",
    testonly = True,
    srcs = glob([
        "tools/llvm-tli-checker/*.cpp",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":Analysis",
        ":BinaryFormat",
        ":BitReader",
        ":BitstreamReader",
        ":Core",
        ":Demangle",
        ":MC",
        ":MCParser",
        ":Object",
        ":Option",
        ":Remarks",
        ":Support",
        ":TLICheckerOptsTableGen",
        ":TargetParser",
        ":TextAPI",
        ":config",
    ],
)

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",
    ]),
    copts = llvm_copts,
    stamp = 0,
    deps = [
        ":AsmParser",
        ":BitReader",
        ":BitWriter",
        ":Core",
        ":IRPrinter",
        ":IRReader",
        ":Support",
    ],
)

cc_binary(
    name = "yaml2obj",
    testonly = True,
    srcs = glob([
        "tools/yaml2obj/*.cpp",
    ]),
    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",
    ],
)